@orion-js/schema
Advanced tools
| import { FieldValidatorType } from '../types/fieldValidators'; | ||
| import { CurrentNodeInfo, SchemaFieldType, SchemaNode } from '../types/schema'; | ||
| export default function cleanType(type: SchemaFieldType | FieldValidatorType, fieldSchema: Partial<SchemaNode>, value: any, info: CurrentNodeInfo, ...args: any[]): Promise<any>; |
| import { SchemaNode } from '../types/schema'; | ||
| export default function getObjectNode(schema: Partial<SchemaNode>, value: any): SchemaNode; |
| import { InferSchemaType } from '../types'; | ||
| import { CurrentNodeInfoOptions, SchemaFieldType } from '../types/schema'; | ||
| export default function clean<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, opts?: CurrentNodeInfoOptions, ...args: any[]): Promise<InferSchemaType<TSchema>>; |
| import { CurrentNodeInfo } from '../types/schema'; | ||
| declare const clean: (info: CurrentNodeInfo) => Promise<any>; | ||
| export default clean; |
| import { InferSchemaType, SchemaFieldType } from './types'; | ||
| export declare function cleanAndValidate<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>): Promise<InferSchemaType<TSchema>>; |
| export default function (schema: any, key: any, value: any, passedOptions?: {}, ...args: any[]): Promise<any>; |
| export declare function clone<T>(value: T): T; |
| import { Schema, SchemaNode } from './types'; | ||
| export type CloneSchemaOptions<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = { | ||
| /** | ||
| * The schema to clone | ||
| */ | ||
| schema: TSchema; | ||
| /** | ||
| * The name of the cloned schema | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * The schema to extend the cloned schema with | ||
| */ | ||
| extendSchema?: TExtendFields; | ||
| /** | ||
| * A function to map the fields of the cloned schema. | ||
| * Warning: This function will not be applied to the typescript types of this schema. | ||
| */ | ||
| mapFields?: (field: TSchema[keyof TSchema], key: keyof TSchema) => SchemaNode; | ||
| /** | ||
| * The fields to pick from the cloned schema | ||
| */ | ||
| pickFields?: TPickFields; | ||
| /** | ||
| * The fields to omit from the cloned schema | ||
| */ | ||
| omitFields?: TOmitFields; | ||
| }; | ||
| type ExtendFields<TSchema extends Schema, TExtendFields extends Schema | undefined> = TExtendFields extends undefined ? TSchema : { | ||
| [key in keyof (TSchema & TExtendFields)]: key extends keyof TExtendFields ? TExtendFields[key] : key extends keyof TSchema ? TSchema[key] : never; | ||
| }; | ||
| type PickOrOmit<TSchema extends Schema, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = TPickFields extends undefined ? TOmitFields extends undefined ? TSchema : Omit<TSchema, TOmitFields[number]> : Pick<TSchema, TPickFields[number]>; | ||
| export type ClonedSchema<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = ExtendFields<PickOrOmit<TSchema, TPickFields, TOmitFields>, TExtendFields>; | ||
| export declare function cloneSchema<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined>(options: CloneSchemaOptions<TSchema, TExtendFields, TPickFields, TOmitFields>): ClonedSchema<TSchema, TExtendFields, TPickFields, TOmitFields>; | ||
| export {}; |
| import dotGetSchema from './validateKey/dotGetSchema'; | ||
| export default dotGetSchema; |
| declare const _default: { | ||
| NOT_IN_SCHEMA: string; | ||
| REQUIRED: string; | ||
| UNKNOWN_FIELD_TYPE: string; | ||
| NOT_AN_ARRAY: string; | ||
| NOT_AN_OBJECT: string; | ||
| NOT_A_STRING: string; | ||
| NOT_A_DATE: string; | ||
| NOT_AN_INTEGER: string; | ||
| NOT_A_NUMBER: string; | ||
| NOT_AN_ID: string; | ||
| STRING_TOO_SHORT: string; | ||
| STRING_TOO_LONG: string; | ||
| NUMBER_TOO_SMALL: string; | ||
| NUMBER_TOO_BIG: string; | ||
| NOT_A_BOOLEAN: string; | ||
| NOT_AN_EMAIL: string; | ||
| NOT_UNIQUE: string; | ||
| NOT_AN_ALLOWED_VALUE: string; | ||
| }; | ||
| export default _default; |
| import { CleanFunction, SchemaFieldType, SchemaNode, ValidateFunction } from './types/schema'; | ||
| export interface FieldTypeOpts<TType = any> { | ||
| name: string; | ||
| validate?: ValidateFunction<TType>; | ||
| clean?: CleanFunction<TType>; | ||
| toGraphQLType?: (GraphQL: any) => any; | ||
| meta?: any; | ||
| } | ||
| export interface FieldType<TType = any> { | ||
| name: string; | ||
| validate: ValidateFunction; | ||
| clean: CleanFunction; | ||
| meta?: any; | ||
| toGraphQLType?: (GraphQL: any) => any; | ||
| toSerializedType?: (node: SchemaNode) => Promise<SchemaFieldType>; | ||
| __tsFieldType: TType; | ||
| __isFieldType: boolean; | ||
| } | ||
| export default function fieldType<TType>(opts: FieldTypeOpts<TType>): FieldType<TType>; |
| declare const _default: import("..").FieldType<any>; | ||
| export default _default; |
| declare const _default: import("..").FieldType<any[]>; | ||
| export default _default; |
| import { Blackbox } from '../types'; | ||
| declare const _default: import("..").FieldType<Blackbox>; | ||
| export default _default; |
| declare const _default: import("..").FieldType<boolean>; | ||
| export default _default; |
| declare const _default: import("..").FieldType<Date>; | ||
| export default _default; |
| declare const _default: import("..").FieldType<string>; | ||
| export default _default; |
| import { FieldType } from '../fieldType'; | ||
| export default function createEnum<const TValues extends readonly string[]>(name: string, values: TValues): FieldType<TValues[number]>; |
| declare const _default: import("..").FieldType<string>; | ||
| export default _default; |
| declare const _default: { | ||
| array: import("..").FieldType<any[]>; | ||
| plainObject: import("..").FieldType<import("..").Blackbox>; | ||
| string: import("..").FieldType<string>; | ||
| date: import("..").FieldType<Date>; | ||
| integer: import("..").FieldType<number>; | ||
| number: import("..").FieldType<number>; | ||
| ID: import("..").FieldType<string>; | ||
| boolean: import("..").FieldType<boolean>; | ||
| email: import("..").FieldType<string>; | ||
| blackbox: import("..").FieldType<import("..").Blackbox>; | ||
| any: import("..").FieldType<any>; | ||
| }; | ||
| export default _default; |
| declare const _default: import("..").FieldType<number>; | ||
| export default _default; |
| declare const _default: import("..").FieldType<number>; | ||
| export default _default; |
| import { Blackbox } from '../types'; | ||
| declare const _default: import("..").FieldType<Blackbox>; | ||
| export default _default; |
| declare const _default: import("..").FieldType<string>; | ||
| export default _default; |
| import { CurrentNodeInfo } from '../types/schema'; | ||
| export declare const convertTypedSchema: (info: CurrentNodeInfo) => void; |
| import { CurrentNodeInfo } from '../types/schema'; | ||
| export default function doValidation(params: CurrentNodeInfo): Promise<void>; |
| import { SchemaFieldType } from '../../types/schema'; | ||
| import { FieldValidatorType } from '../../types/fieldValidators'; | ||
| import { FieldType } from '../../fieldType'; | ||
| export default function getFieldType(type: SchemaFieldType | FieldValidatorType | any): FieldType; |
| import { FieldValidatorType } from '../../types/fieldValidators'; | ||
| import { SchemaFieldType } from '../../types'; | ||
| export default function getFieldValidator(type: SchemaFieldType): FieldValidatorType; |
| import { CurrentNodeInfo } from '../../types/schema'; | ||
| export default function getValidationErrors(params: CurrentNodeInfo): Promise<object | string | void>; |
| import { SchemaFieldType } from '../types/schema'; | ||
| /** | ||
| * Extracts field labels from a schema, creating a flat object with dot-notation keys | ||
| * matching the validation error keys and their corresponding labels. | ||
| */ | ||
| export default function getFieldLabels(schema: SchemaFieldType, currentKey?: string): Record<string, string>; |
| export default function getValidationErrorsObject(validationErrors: { | ||
| key: string; | ||
| code: string; | ||
| }[]): any; |
| import { InferSchemaType } from '../types'; | ||
| import { SchemaFieldType } from '../types/schema'; | ||
| export default function getValidationErrors<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<any>; |
| import { InferSchemaType } from './types'; | ||
| import { Schema } from './types/schema'; | ||
| export default function isValid<TSchema extends Schema>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<boolean>; |
| import { Schema, SchemaFieldType, SchemaFieldTypeNonSchema, SchemaWithMetadata } from './types'; | ||
| export declare function isSchemaLike(type: any): boolean; | ||
| export declare function isStrictSchemaLike<TType extends Schema | SchemaFieldTypeNonSchema>(type: TType): TType extends Schema ? true : false; | ||
| export declare function isSchemaOrFieldLike(type: any): boolean; | ||
| export declare function getSchemaModelName(type: any): string | null; | ||
| export declare function getSchemaFromAnyOrionForm(type: any): SchemaFieldType; | ||
| export declare function getSchemaWithMetadataFromAnyOrionForm(type: any): SchemaWithMetadata; |
| import { Schema } from '../types'; | ||
| /** | ||
| * Assigns a name to a schema for GraphQL type generation. | ||
| * | ||
| * This function associates a name with a schema object by setting an internal | ||
| * `__modelName` property. This name is used when generating GraphQL types. | ||
| * | ||
| * @param name - The name to assign to the schema | ||
| * @param schema - The schema object to name | ||
| * @returns The same schema object with the internal name property added | ||
| * | ||
| * Note: The schema object is modified in-place, so the name will persist | ||
| * even if you don't use the returned value. | ||
| */ | ||
| export declare function schemaWithName<TModelName extends string, TSchema extends Schema>(name: TModelName, schema: TSchema): TSchema; |
| import { FieldType } from '../fieldType'; | ||
| import { Blackbox, Schema, SchemaMetaFieldTypeSingleNonSchema, TypedSchemaOnSchema } from './schema'; | ||
| type InferSchemaTypeForFieldType<T> = T extends { | ||
| __tsFieldType: infer U; | ||
| } ? U : T extends 'string' ? string : T extends 'date' ? Date : T extends 'integer' ? number : T extends 'number' ? number : T extends 'ID' ? string : T extends 'boolean' ? boolean : T extends 'email' ? string : T extends 'blackbox' ? Blackbox : T extends 'any' ? any : T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : T extends Date ? Date : T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends DateConstructor ? Date : T extends Array<infer U> ? InferSchemaTypeForFieldType<U>[] : T extends Record<string, any> ? InferSchemaTypeForSchema<T> : T; | ||
| type SchemaKeysNotOfSchemaItems = '__isFieldType' | '__GraphQLType' | '__skipChildValidation'; | ||
| type NodeIsOptional<TNode> = TNode extends { | ||
| optional: true; | ||
| } ? true : false; | ||
| type WithoutNotSchemaItems<T extends Record<string, any>> = T extends { | ||
| [key in SchemaKeysNotOfSchemaItems]: any; | ||
| } & Record<string, any> ? Omit<T, SchemaKeysNotOfSchemaItems> : T; | ||
| type InferSchemaTypeForSchema<TSchema extends Record<string, any>> = WithoutNotSchemaItems<{ | ||
| -readonly [K in keyof TSchema as NodeIsOptional<TSchema[K]> extends true ? never : K]: InferSchemaType<TSchema[K]['type']>; | ||
| } & { | ||
| -readonly [K in keyof TSchema as NodeIsOptional<TSchema[K]> extends true ? K : never]?: InferSchemaType<TSchema[K]['type']>; | ||
| }>; | ||
| type IsPossiblyASchema<TType> = TType extends FieldType ? false : TType extends Record<string, any> ? keyof { | ||
| [K in keyof TType as 'type' extends keyof TType[K] ? K : never]: TType[K]; | ||
| } extends never ? false : true : false; | ||
| type AClass<T = any> = abstract new (...args: any) => T; | ||
| /** | ||
| * Returns the type of the schema | ||
| */ | ||
| export type InferSchemaType<TType> = TType extends { | ||
| __isModel: true; | ||
| type: infer U; | ||
| } ? InferSchemaTypeForSchema<U> : TType extends SchemaMetaFieldTypeSingleNonSchema ? InferSchemaTypeForFieldType<TType> : TType extends AClass<infer U> ? U : IsPossiblyASchema<TType> extends true ? InferSchemaTypeForSchema<TType> : InferSchemaTypeForFieldType<TType>; | ||
| /** | ||
| * Returns the type of the schema but only if its a schema | ||
| */ | ||
| export type StrictInferSchemaType<TSchema extends Schema> = InferSchemaTypeForSchema<TSchema>; | ||
| /** | ||
| * Returns the type of the schema but only if its a schema | ||
| */ | ||
| export type InferSchemaTypeFromTypedSchema<TTypedSchema extends TypedSchemaOnSchema> = TTypedSchema; | ||
| export {}; |
| import fieldTypes from '../fieldTypes'; | ||
| export type FieldValidatorType = keyof typeof fieldTypes | 'custom' | 'plainObject'; |
| import { Schema } from './schema'; | ||
| export type MergeSchemas<SchemaA extends Schema, SchemaB extends Schema> = SchemaA & SchemaB; |
| export * from './schema'; | ||
| export * from './fieldValidators'; | ||
| export * from './fields'; | ||
| export * from './helpers'; |
| import { FieldType } from '../fieldType'; | ||
| import { InferSchemaType } from './fields'; | ||
| export type Constructor<T> = new (...args: any[]) => T; | ||
| export type Blackbox = { | ||
| [name: string]: any; | ||
| }; | ||
| export type FieldTypesList = 'string' | 'date' | 'integer' | 'number' | 'ID' | 'boolean' | 'email' | 'blackbox' | 'any'; | ||
| type AClass = abstract new (...args: any) => any; | ||
| export type TypedSchemaOnSchema = AClass; | ||
| export type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date> | StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor | String | Number | Boolean | Date; | ||
| export type SchemaMetaFieldTypeSingleNonSchema = FieldTypesList | ConstructorsTypesList | FieldType; | ||
| export type SchemaMetaFieldTypeSingle = SchemaMetaFieldTypeSingleNonSchema | Schema | TypedSchemaOnSchema; | ||
| export type SchemaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[]; | ||
| export type SchemaFieldTypeNonSchema = SchemaMetaFieldTypeSingleNonSchema | SchemaMetaFieldTypeSingleNonSchema[]; | ||
| export type ValidateFunction<TType = any> = (value: TType, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | null | undefined | void | Promise<object | string | null | undefined | void>; | ||
| export type CleanFunction<TType = any> = (value: TType, info?: Partial<CurrentNodeInfo>, ...args: any[]) => TType | Promise<TType>; | ||
| export type SchemaRecursiveNodeTypeExtras = { | ||
| __isFieldType?: boolean; | ||
| __GraphQLType?: any; | ||
| __skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>; | ||
| }; | ||
| export type SchemaNode<TFieldType extends SchemaFieldType = SchemaFieldType> = { | ||
| /** | ||
| * The type of the field. Used for type validations. Can also contain a subschema. | ||
| */ | ||
| type: TFieldType; | ||
| /** | ||
| * Defaults to false | ||
| */ | ||
| optional?: boolean; | ||
| allowedValues?: Array<InferSchemaType<TFieldType>>; | ||
| defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => InferSchemaType<TFieldType> | Promise<InferSchemaType<TFieldType>>) | InferSchemaType<TFieldType>; | ||
| /** | ||
| * Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise. | ||
| */ | ||
| validate?: ValidateFunction<InferSchemaType<TFieldType>>; | ||
| /** | ||
| * @deprecated Use validate instead. | ||
| */ | ||
| custom?: ValidateFunction<InferSchemaType<TFieldType>>; | ||
| /** | ||
| * Function that preprocesses a value before it is set. | ||
| */ | ||
| clean?: CleanFunction<InferSchemaType<TFieldType>>; | ||
| /** | ||
| * The minimum value if it's a number, the minimum length if it's a string or array. | ||
| */ | ||
| min?: number; | ||
| /** | ||
| * The maximum value if it's a number, the maximum length if it's a string or array. | ||
| */ | ||
| max?: number; | ||
| /** | ||
| * Internal use only. | ||
| */ | ||
| isBlackboxChild?: boolean; | ||
| /** | ||
| * Used in GraphQL. If true, the field will be omitted from the schema. | ||
| */ | ||
| private?: boolean; | ||
| /** | ||
| * Used in GraphQL. When in GraphQL, this resolver will replace the static field. | ||
| */ | ||
| graphQLResolver?: (...args: any) => any; | ||
| /** | ||
| * Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema. | ||
| */ | ||
| key?: string; | ||
| /** | ||
| * The name that would be displayed in a front-end form | ||
| */ | ||
| label?: string; | ||
| /** | ||
| * The description that would be displayed in a front-end form | ||
| */ | ||
| description?: string; | ||
| /** | ||
| * The placeholder that would be displayed in a front-end form | ||
| */ | ||
| placeholder?: string; | ||
| /** | ||
| * The field type that would be used in a front-end form | ||
| */ | ||
| fieldType?: string; | ||
| /** | ||
| * The field options that will be passed as props to the front-end field | ||
| */ | ||
| fieldOptions?: any; | ||
| } & SchemaRecursiveNodeTypeExtras; | ||
| export interface CurrentNodeInfoOptions { | ||
| autoConvert?: boolean; | ||
| filter?: boolean; | ||
| trimStrings?: boolean; | ||
| removeEmptyStrings?: boolean; | ||
| forceDoc?: any; | ||
| omitRequired?: boolean; | ||
| } | ||
| export interface CurrentNodeInfo { | ||
| /** | ||
| * The global schema, prefaced by {type: {...}} to be compatible with subschemas | ||
| * Sometimes it's given without {type: {...}}. TODO: Normalize this. | ||
| */ | ||
| schema?: SchemaFieldType; | ||
| /** | ||
| * The current node subschema | ||
| */ | ||
| currentSchema?: Partial<SchemaNode<SchemaFieldType>>; | ||
| value: InferSchemaType<SchemaFieldType>; | ||
| doc?: any; | ||
| currentDoc?: any; | ||
| options?: CurrentNodeInfoOptions; | ||
| args?: any[]; | ||
| type?: SchemaFieldType; | ||
| keys?: string[]; | ||
| addError?: (keys: string[], code: string | object) => void; | ||
| } | ||
| export type SchemaMetadata = { | ||
| /** | ||
| * The name of the model (to make it compatible with GraphQL) | ||
| */ | ||
| __modelName?: string; | ||
| /** | ||
| * Cleans the whole schema | ||
| */ | ||
| __clean?: CleanFunction; | ||
| /** | ||
| * Validates the whole schema | ||
| */ | ||
| __validate?: ValidateFunction; | ||
| /** | ||
| * The resolvers of the model | ||
| */ | ||
| __resolvers?: any; | ||
| }; | ||
| export type Schema = { | ||
| [K: string]: SchemaNode; | ||
| }; | ||
| export type SingleLevelSchema = { | ||
| [K: string]: SchemaNode<SchemaFieldTypeNonSchema>; | ||
| }; | ||
| export type SchemaInAnyOrionForm = Schema | TypedSchemaOnSchema; | ||
| export type SchemaWithMetadata = { | ||
| [K: string]: SchemaNode | SchemaMetadata[keyof SchemaMetadata]; | ||
| } & SchemaMetadata; | ||
| export {}; |
| import { InferSchemaType } from './types/fields'; | ||
| import { SchemaFieldType } from './types/schema'; | ||
| export default function validate<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<void>; |
| import { Schema, SchemaNode } from '..'; | ||
| export default function (schema: Schema, path: string): SchemaNode; |
| import { CurrentNodeInfoOptions, Schema } from '..'; | ||
| export default function (schema: Schema, key: string, value: any, passedOptions?: CurrentNodeInfoOptions, ...args: any[]): Promise<any>; |
| export interface ValidationErrorInfo { | ||
| error: string; | ||
| message: string; | ||
| validationErrors: Record<string, string>; | ||
| labels: Record<string, string>; | ||
| } | ||
| export default class ValidationError extends Error { | ||
| code: string; | ||
| isValidationError: boolean; | ||
| isOrionError: boolean; | ||
| validationErrors: Record<string, string>; | ||
| labels: Record<string, string>; | ||
| constructor(validationErrors: Record<string, string>, labels?: Record<string, string>); | ||
| getInfo: () => ValidationErrorInfo; | ||
| prependKey: (prepend: any) => ValidationError; | ||
| } |
+21
| MIT License | ||
| Copyright (c) 2022 Orionjs Team | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
+2
-1
@@ -918,3 +918,4 @@ var __create = Object.create; | ||
| const { schema: schema2, args = [], value } = info; | ||
| const currSchema = schema2.type === void 0 ? { type: schema2 } : schema2; | ||
| const schemaValue = schema2; | ||
| const currSchema = typeof schemaValue === "object" && schemaValue !== null && "type" in schemaValue ? schemaValue : { type: schemaValue }; | ||
| const objectSchema = getObjectNode(currSchema, value); | ||
@@ -921,0 +922,0 @@ if (objectSchema) { |
+18
-304
@@ -1,304 +0,18 @@ | ||
| type Constructor<T> = new (...args: any[]) => T; | ||
| type Blackbox = { | ||
| [name: string]: any; | ||
| }; | ||
| type FieldTypesList = 'string' | 'date' | 'integer' | 'number' | 'ID' | 'boolean' | 'email' | 'blackbox' | 'any'; | ||
| type AClass$1 = abstract new (...args: any) => any; | ||
| type TypedSchemaOnSchema = AClass$1; | ||
| type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date> | StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor | String | Number | Boolean | Date; | ||
| type SchemaMetaFieldTypeSingleNonSchema = FieldTypesList | ConstructorsTypesList | FieldType; | ||
| type SchemaMetaFieldTypeSingle = SchemaMetaFieldTypeSingleNonSchema | Schema | TypedSchemaOnSchema; | ||
| type SchemaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[]; | ||
| type SchemaFieldTypeNonSchema = SchemaMetaFieldTypeSingleNonSchema | SchemaMetaFieldTypeSingleNonSchema[]; | ||
| type ValidateFunction<TType = any> = (value: TType, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | null | undefined | void | Promise<object | string | null | undefined | void>; | ||
| type CleanFunction<TType = any> = (value: TType, info?: Partial<CurrentNodeInfo>, ...args: any[]) => TType | Promise<TType>; | ||
| type SchemaRecursiveNodeTypeExtras = { | ||
| __isFieldType?: boolean; | ||
| __GraphQLType?: any; | ||
| __skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>; | ||
| }; | ||
| type SchemaNode<TFieldType extends SchemaFieldType = SchemaFieldType> = { | ||
| /** | ||
| * The type of the field. Used for type validations. Can also contain a subschema. | ||
| */ | ||
| type: TFieldType; | ||
| /** | ||
| * Defaults to false | ||
| */ | ||
| optional?: boolean; | ||
| allowedValues?: Array<InferSchemaType<TFieldType>>; | ||
| defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => InferSchemaType<TFieldType> | Promise<InferSchemaType<TFieldType>>) | InferSchemaType<TFieldType>; | ||
| /** | ||
| * Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise. | ||
| */ | ||
| validate?: ValidateFunction<InferSchemaType<TFieldType>>; | ||
| /** | ||
| * Function that preprocesses a value before it is set. | ||
| */ | ||
| clean?: CleanFunction<InferSchemaType<TFieldType>>; | ||
| /** | ||
| * The minimum value if it's a number, the minimum length if it's a string or array. | ||
| */ | ||
| min?: number; | ||
| /** | ||
| * The maximum value if it's a number, the maximum length if it's a string or array. | ||
| */ | ||
| max?: number; | ||
| /** | ||
| * Internal use only. | ||
| */ | ||
| isBlackboxChild?: boolean; | ||
| /** | ||
| * Used in GraphQL. If true, the field will be omitted from the schema. | ||
| */ | ||
| private?: boolean; | ||
| /** | ||
| * Used in GraphQL. When in GraphQL, this resolver will replace the static field. | ||
| */ | ||
| graphQLResolver?: (...args: any) => any; | ||
| /** | ||
| * Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema. | ||
| */ | ||
| key?: string; | ||
| /** | ||
| * The name that would be displayed in a front-end form | ||
| */ | ||
| label?: string; | ||
| /** | ||
| * The description that would be displayed in a front-end form | ||
| */ | ||
| description?: string; | ||
| /** | ||
| * The placeholder that would be displayed in a front-end form | ||
| */ | ||
| placeholder?: string; | ||
| /** | ||
| * The field type that would be used in a front-end form | ||
| */ | ||
| fieldType?: string; | ||
| /** | ||
| * The field options that will be passed as props to the front-end field | ||
| */ | ||
| fieldOptions?: any; | ||
| } & SchemaRecursiveNodeTypeExtras; | ||
| interface CurrentNodeInfoOptions { | ||
| autoConvert?: boolean; | ||
| filter?: boolean; | ||
| trimStrings?: boolean; | ||
| removeEmptyStrings?: boolean; | ||
| forceDoc?: any; | ||
| omitRequired?: boolean; | ||
| } | ||
| interface CurrentNodeInfo { | ||
| /** | ||
| * The global schema, prefaced by {type: {...}} to be compatible with subschemas | ||
| * Sometimes it's given without {type: {...}}. TODO: Normalize this. | ||
| */ | ||
| schema?: SchemaFieldType; | ||
| /** | ||
| * The current node subschema | ||
| */ | ||
| currentSchema?: Partial<SchemaNode<SchemaFieldType>>; | ||
| value: InferSchemaType<SchemaFieldType>; | ||
| doc?: any; | ||
| currentDoc?: any; | ||
| options?: CurrentNodeInfoOptions; | ||
| args?: any[]; | ||
| type?: SchemaFieldType; | ||
| keys?: string[]; | ||
| addError?: (keys: string[], code: string | object) => void; | ||
| } | ||
| type SchemaMetadata = { | ||
| /** | ||
| * The name of the model (to make it compatible with GraphQL) | ||
| */ | ||
| __modelName?: string; | ||
| /** | ||
| * Cleans the whole schema | ||
| */ | ||
| __clean?: CleanFunction; | ||
| /** | ||
| * Validates the whole schema | ||
| */ | ||
| __validate?: ValidateFunction; | ||
| /** | ||
| * The resolvers of the model | ||
| */ | ||
| __resolvers?: any; | ||
| }; | ||
| type Schema = { | ||
| [K: string]: SchemaNode; | ||
| }; | ||
| type SingleLevelSchema = { | ||
| [K: string]: SchemaNode<SchemaFieldTypeNonSchema>; | ||
| }; | ||
| type SchemaInAnyOrionForm = Schema | TypedSchemaOnSchema; | ||
| type SchemaWithMetadata = { | ||
| [K: string]: SchemaNode | SchemaMetadata[keyof SchemaMetadata]; | ||
| } & SchemaMetadata; | ||
| interface FieldTypeOpts<TType = any> { | ||
| name: string; | ||
| validate?: ValidateFunction<TType>; | ||
| clean?: CleanFunction<TType>; | ||
| toGraphQLType?: (GraphQL: any) => any; | ||
| meta?: any; | ||
| } | ||
| interface FieldType<TType = any> { | ||
| name: string; | ||
| validate: ValidateFunction; | ||
| clean: CleanFunction; | ||
| meta?: any; | ||
| toGraphQLType?: (GraphQL: any) => any; | ||
| toSerializedType?: (node: SchemaNode) => Promise<SchemaFieldType>; | ||
| __tsFieldType: TType; | ||
| __isFieldType: boolean; | ||
| } | ||
| type InferSchemaTypeForFieldType<T> = T extends { | ||
| __tsFieldType: infer U; | ||
| } ? U : T extends 'string' ? string : T extends 'date' ? Date : T extends 'integer' ? number : T extends 'number' ? number : T extends 'ID' ? string : T extends 'boolean' ? boolean : T extends 'email' ? string : T extends 'blackbox' ? Blackbox : T extends 'any' ? any : T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : T extends Date ? Date : T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends DateConstructor ? Date : T extends Array<infer U> ? InferSchemaTypeForFieldType<U>[] : T extends Record<string, any> ? InferSchemaTypeForSchema<T> : T; | ||
| type SchemaKeysNotOfSchemaItems = '__isFieldType' | '__GraphQLType' | '__skipChildValidation'; | ||
| type NodeIsOptional<TNode> = TNode extends { | ||
| optional: true; | ||
| } ? true : false; | ||
| type WithoutNotSchemaItems<T extends Record<string, any>> = T extends { | ||
| [key in SchemaKeysNotOfSchemaItems]: any; | ||
| } & Record<string, any> ? Omit<T, SchemaKeysNotOfSchemaItems> : T; | ||
| type InferSchemaTypeForSchema<TSchema extends Record<string, any>> = WithoutNotSchemaItems<{ | ||
| -readonly [K in keyof TSchema as NodeIsOptional<TSchema[K]> extends true ? never : K]: InferSchemaType<TSchema[K]['type']>; | ||
| } & { | ||
| -readonly [K in keyof TSchema as NodeIsOptional<TSchema[K]> extends true ? K : never]?: InferSchemaType<TSchema[K]['type']>; | ||
| }>; | ||
| type IsPossiblyASchema<TType> = TType extends FieldType ? false : TType extends Record<string, any> ? keyof { | ||
| [K in keyof TType as 'type' extends keyof TType[K] ? K : never]: TType[K]; | ||
| } extends never ? false : true : false; | ||
| type AClass<T = any> = abstract new (...args: any) => T; | ||
| /** | ||
| * Returns the type of the schema | ||
| */ | ||
| type InferSchemaType<TType> = TType extends { | ||
| __isModel: true; | ||
| type: infer U; | ||
| } ? InferSchemaTypeForSchema<U> : TType extends SchemaMetaFieldTypeSingleNonSchema ? InferSchemaTypeForFieldType<TType> : TType extends AClass<infer U> ? U : IsPossiblyASchema<TType> extends true ? InferSchemaTypeForSchema<TType> : InferSchemaTypeForFieldType<TType>; | ||
| /** | ||
| * Returns the type of the schema but only if its a schema | ||
| */ | ||
| type StrictInferSchemaType<TSchema extends Schema> = InferSchemaTypeForSchema<TSchema>; | ||
| /** | ||
| * Returns the type of the schema but only if its a schema | ||
| */ | ||
| type InferSchemaTypeFromTypedSchema<TTypedSchema extends TypedSchemaOnSchema> = TTypedSchema; | ||
| declare function validate<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<void>; | ||
| interface ValidationErrorInfo { | ||
| error: string; | ||
| message: string; | ||
| validationErrors: Record<string, string>; | ||
| labels: Record<string, string>; | ||
| } | ||
| declare class ValidationError extends Error { | ||
| code: string; | ||
| isValidationError: boolean; | ||
| isOrionError: boolean; | ||
| validationErrors: Record<string, string>; | ||
| labels: Record<string, string>; | ||
| constructor(validationErrors: Record<string, string>, labels?: Record<string, string>); | ||
| getInfo: () => ValidationErrorInfo; | ||
| prependKey: (prepend: any) => ValidationError; | ||
| } | ||
| declare const _default: { | ||
| array: FieldType<any[]>; | ||
| plainObject: FieldType<Blackbox>; | ||
| string: FieldType<string>; | ||
| date: FieldType<Date>; | ||
| integer: FieldType<number>; | ||
| number: FieldType<number>; | ||
| ID: FieldType<string>; | ||
| boolean: FieldType<boolean>; | ||
| email: FieldType<string>; | ||
| blackbox: FieldType<Blackbox>; | ||
| any: FieldType<any>; | ||
| }; | ||
| type FieldValidatorType = keyof typeof _default | 'custom' | 'plainObject'; | ||
| type MergeSchemas<SchemaA extends Schema, SchemaB extends Schema> = SchemaA & SchemaB; | ||
| declare function getValidationErrors<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<any>; | ||
| declare function isValid<TSchema extends Schema>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<boolean>; | ||
| declare function getFieldType(type: SchemaFieldType | FieldValidatorType | any): FieldType; | ||
| declare function clean<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, opts?: CurrentNodeInfoOptions, ...args: any[]): Promise<InferSchemaType<TSchema>>; | ||
| declare function export_default$2(schema: any, key: any, value: any, passedOptions?: {}, ...args: any[]): Promise<any>; | ||
| declare function export_default$1(schema: Schema, key: string, value: any, passedOptions?: CurrentNodeInfoOptions, ...args: any[]): Promise<any>; | ||
| declare function export_default(schema: Schema, path: string): SchemaNode; | ||
| declare function createEnum<const TValues extends readonly string[]>(name: string, values: TValues): FieldType<TValues[number]>; | ||
| declare function isSchemaLike(type: any): boolean; | ||
| declare function isStrictSchemaLike<TType extends Schema | SchemaFieldTypeNonSchema>(type: TType): TType extends Schema ? true : false; | ||
| declare function isSchemaOrFieldLike(type: any): boolean; | ||
| declare function getSchemaModelName(type: any): string | null; | ||
| declare function getSchemaFromAnyOrionForm(type: any): SchemaFieldType; | ||
| declare function getSchemaWithMetadataFromAnyOrionForm(type: any): SchemaWithMetadata; | ||
| declare function cleanAndValidate<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>): Promise<InferSchemaType<TSchema>>; | ||
| /** | ||
| * Assigns a name to a schema for GraphQL type generation. | ||
| * | ||
| * This function associates a name with a schema object by setting an internal | ||
| * `__modelName` property. This name is used when generating GraphQL types. | ||
| * | ||
| * @param name - The name to assign to the schema | ||
| * @param schema - The schema object to name | ||
| * @returns The same schema object with the internal name property added | ||
| * | ||
| * Note: The schema object is modified in-place, so the name will persist | ||
| * even if you don't use the returned value. | ||
| */ | ||
| declare function schemaWithName<TModelName extends string, TSchema extends Schema>(name: TModelName, schema: TSchema): TSchema; | ||
| type CloneSchemaOptions<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = { | ||
| /** | ||
| * The schema to clone | ||
| */ | ||
| schema: TSchema; | ||
| /** | ||
| * The name of the cloned schema | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * The schema to extend the cloned schema with | ||
| */ | ||
| extendSchema?: TExtendFields; | ||
| /** | ||
| * A function to map the fields of the cloned schema. | ||
| * Warning: This function will not be applied to the typescript types of this schema. | ||
| */ | ||
| mapFields?: (field: TSchema[keyof TSchema], key: keyof TSchema) => SchemaNode; | ||
| /** | ||
| * The fields to pick from the cloned schema | ||
| */ | ||
| pickFields?: TPickFields; | ||
| /** | ||
| * The fields to omit from the cloned schema | ||
| */ | ||
| omitFields?: TOmitFields; | ||
| }; | ||
| type ExtendFields<TSchema extends Schema, TExtendFields extends Schema | undefined> = TExtendFields extends undefined ? TSchema : { | ||
| [key in keyof (TSchema & TExtendFields)]: key extends keyof TExtendFields ? TExtendFields[key] : key extends keyof TSchema ? TSchema[key] : never; | ||
| }; | ||
| type PickOrOmit<TSchema extends Schema, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = TPickFields extends undefined ? TOmitFields extends undefined ? TSchema : Omit<TSchema, TOmitFields[number]> : Pick<TSchema, TPickFields[number]>; | ||
| type ClonedSchema<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = ExtendFields<PickOrOmit<TSchema, TPickFields, TOmitFields>, TExtendFields>; | ||
| declare function cloneSchema<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined>(options: CloneSchemaOptions<TSchema, TExtendFields, TPickFields, TOmitFields>): ClonedSchema<TSchema, TExtendFields, TPickFields, TOmitFields>; | ||
| export { type Blackbox, type CleanFunction, type CloneSchemaOptions, type ClonedSchema, type Constructor, type ConstructorsTypesList, type CurrentNodeInfo, type CurrentNodeInfoOptions, type FieldType, type FieldTypeOpts, type FieldTypesList, type FieldValidatorType, type InferSchemaType, type InferSchemaTypeFromTypedSchema, type MergeSchemas, type Schema, type SchemaFieldType, type SchemaFieldTypeNonSchema, type SchemaInAnyOrionForm, type SchemaMetaFieldTypeSingle, type SchemaMetaFieldTypeSingleNonSchema, type SchemaMetadata, type SchemaNode, type SchemaRecursiveNodeTypeExtras, type SchemaWithMetadata, type SingleLevelSchema, type StrictInferSchemaType, type TypedSchemaOnSchema, type ValidateFunction, ValidationError, clean, cleanAndValidate, export_default$2 as cleanKey, cloneSchema, createEnum, export_default as dotGetSchema, _default as fieldTypes, getFieldType, getSchemaFromAnyOrionForm, getSchemaModelName, getSchemaWithMetadataFromAnyOrionForm, getValidationErrors, isSchemaLike, isSchemaOrFieldLike, isStrictSchemaLike, isValid, schemaWithName, validate, export_default$1 as validateKey }; | ||
| import validate from './validate'; | ||
| import ValidationError from './ValidationError'; | ||
| import getValidationErrors from './getValidationErrors'; | ||
| import isValid from './isValid'; | ||
| import getFieldType from './getValidationErrors/getError/getFieldType'; | ||
| import clean from './clean'; | ||
| import cleanKey from './cleanKey'; | ||
| import validateKey from './validateKey'; | ||
| import dotGetSchema from './dotGetSchema'; | ||
| import createEnum from './fieldTypes/enum'; | ||
| import fieldTypes from './fieldTypes'; | ||
| export { validate, ValidationError, getValidationErrors, isValid, getFieldType, clean, cleanKey, dotGetSchema, validateKey, createEnum, fieldTypes, }; | ||
| export * from './types'; | ||
| export * from './models'; | ||
| export * from './cleanAndValidate'; | ||
| export * from './fieldType'; | ||
| export * from './schemaWithName'; | ||
| export * from './cloneSchema'; |
+2
-1
@@ -864,3 +864,4 @@ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/type.js | ||
| const { schema: schema2, args = [], value } = info; | ||
| const currSchema = schema2.type === void 0 ? { type: schema2 } : schema2; | ||
| const schemaValue = schema2; | ||
| const currSchema = typeof schemaValue === "object" && schemaValue !== null && "type" in schemaValue ? schemaValue : { type: schemaValue }; | ||
| const objectSchema = getObjectNode(currSchema, value); | ||
@@ -867,0 +868,0 @@ if (objectSchema) { |
+10
-11
| { | ||
| "name": "@orion-js/schema", | ||
| "version": "4.3.1", | ||
| "version": "4.4.0", | ||
| "main": "./dist/index.cjs", | ||
@@ -11,9 +11,2 @@ "types": "./dist/index.d.ts", | ||
| "license": "MIT", | ||
| "scripts": { | ||
| "test": "bun test", | ||
| "prepare": "bun run build", | ||
| "clean": "rm -rf ./dist", | ||
| "build": "tsup", | ||
| "dev": "tsup --watch" | ||
| }, | ||
| "dependencies": { | ||
@@ -23,7 +16,7 @@ "dot-object": "^2.1.4" | ||
| "peerDependencies": { | ||
| "@orion-js/logger": "4.3.1" | ||
| "@orion-js/logger": "4.4.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/dot-object": "^2.1.2", | ||
| "typescript": "^5.4.5", | ||
| "typescript": "^7.0.2", | ||
| "@types/node": "^18.0.0", | ||
@@ -42,3 +35,9 @@ "tsup": "^8.0.1" | ||
| "require": "./dist/index.cjs" | ||
| }, | ||
| "scripts": { | ||
| "test": "bun test", | ||
| "clean": "rm -rf ./dist", | ||
| "build": "tsup && bun run ../../scripts/emit-declarations.ts", | ||
| "dev": "tsup --watch" | ||
| } | ||
| } | ||
| } |
-304
| type Constructor<T> = new (...args: any[]) => T; | ||
| type Blackbox = { | ||
| [name: string]: any; | ||
| }; | ||
| type FieldTypesList = 'string' | 'date' | 'integer' | 'number' | 'ID' | 'boolean' | 'email' | 'blackbox' | 'any'; | ||
| type AClass$1 = abstract new (...args: any) => any; | ||
| type TypedSchemaOnSchema = AClass$1; | ||
| type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date> | StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor | String | Number | Boolean | Date; | ||
| type SchemaMetaFieldTypeSingleNonSchema = FieldTypesList | ConstructorsTypesList | FieldType; | ||
| type SchemaMetaFieldTypeSingle = SchemaMetaFieldTypeSingleNonSchema | Schema | TypedSchemaOnSchema; | ||
| type SchemaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[]; | ||
| type SchemaFieldTypeNonSchema = SchemaMetaFieldTypeSingleNonSchema | SchemaMetaFieldTypeSingleNonSchema[]; | ||
| type ValidateFunction<TType = any> = (value: TType, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | null | undefined | void | Promise<object | string | null | undefined | void>; | ||
| type CleanFunction<TType = any> = (value: TType, info?: Partial<CurrentNodeInfo>, ...args: any[]) => TType | Promise<TType>; | ||
| type SchemaRecursiveNodeTypeExtras = { | ||
| __isFieldType?: boolean; | ||
| __GraphQLType?: any; | ||
| __skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>; | ||
| }; | ||
| type SchemaNode<TFieldType extends SchemaFieldType = SchemaFieldType> = { | ||
| /** | ||
| * The type of the field. Used for type validations. Can also contain a subschema. | ||
| */ | ||
| type: TFieldType; | ||
| /** | ||
| * Defaults to false | ||
| */ | ||
| optional?: boolean; | ||
| allowedValues?: Array<InferSchemaType<TFieldType>>; | ||
| defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => InferSchemaType<TFieldType> | Promise<InferSchemaType<TFieldType>>) | InferSchemaType<TFieldType>; | ||
| /** | ||
| * Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise. | ||
| */ | ||
| validate?: ValidateFunction<InferSchemaType<TFieldType>>; | ||
| /** | ||
| * Function that preprocesses a value before it is set. | ||
| */ | ||
| clean?: CleanFunction<InferSchemaType<TFieldType>>; | ||
| /** | ||
| * The minimum value if it's a number, the minimum length if it's a string or array. | ||
| */ | ||
| min?: number; | ||
| /** | ||
| * The maximum value if it's a number, the maximum length if it's a string or array. | ||
| */ | ||
| max?: number; | ||
| /** | ||
| * Internal use only. | ||
| */ | ||
| isBlackboxChild?: boolean; | ||
| /** | ||
| * Used in GraphQL. If true, the field will be omitted from the schema. | ||
| */ | ||
| private?: boolean; | ||
| /** | ||
| * Used in GraphQL. When in GraphQL, this resolver will replace the static field. | ||
| */ | ||
| graphQLResolver?: (...args: any) => any; | ||
| /** | ||
| * Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema. | ||
| */ | ||
| key?: string; | ||
| /** | ||
| * The name that would be displayed in a front-end form | ||
| */ | ||
| label?: string; | ||
| /** | ||
| * The description that would be displayed in a front-end form | ||
| */ | ||
| description?: string; | ||
| /** | ||
| * The placeholder that would be displayed in a front-end form | ||
| */ | ||
| placeholder?: string; | ||
| /** | ||
| * The field type that would be used in a front-end form | ||
| */ | ||
| fieldType?: string; | ||
| /** | ||
| * The field options that will be passed as props to the front-end field | ||
| */ | ||
| fieldOptions?: any; | ||
| } & SchemaRecursiveNodeTypeExtras; | ||
| interface CurrentNodeInfoOptions { | ||
| autoConvert?: boolean; | ||
| filter?: boolean; | ||
| trimStrings?: boolean; | ||
| removeEmptyStrings?: boolean; | ||
| forceDoc?: any; | ||
| omitRequired?: boolean; | ||
| } | ||
| interface CurrentNodeInfo { | ||
| /** | ||
| * The global schema, prefaced by {type: {...}} to be compatible with subschemas | ||
| * Sometimes it's given without {type: {...}}. TODO: Normalize this. | ||
| */ | ||
| schema?: SchemaFieldType; | ||
| /** | ||
| * The current node subschema | ||
| */ | ||
| currentSchema?: Partial<SchemaNode<SchemaFieldType>>; | ||
| value: InferSchemaType<SchemaFieldType>; | ||
| doc?: any; | ||
| currentDoc?: any; | ||
| options?: CurrentNodeInfoOptions; | ||
| args?: any[]; | ||
| type?: SchemaFieldType; | ||
| keys?: string[]; | ||
| addError?: (keys: string[], code: string | object) => void; | ||
| } | ||
| type SchemaMetadata = { | ||
| /** | ||
| * The name of the model (to make it compatible with GraphQL) | ||
| */ | ||
| __modelName?: string; | ||
| /** | ||
| * Cleans the whole schema | ||
| */ | ||
| __clean?: CleanFunction; | ||
| /** | ||
| * Validates the whole schema | ||
| */ | ||
| __validate?: ValidateFunction; | ||
| /** | ||
| * The resolvers of the model | ||
| */ | ||
| __resolvers?: any; | ||
| }; | ||
| type Schema = { | ||
| [K: string]: SchemaNode; | ||
| }; | ||
| type SingleLevelSchema = { | ||
| [K: string]: SchemaNode<SchemaFieldTypeNonSchema>; | ||
| }; | ||
| type SchemaInAnyOrionForm = Schema | TypedSchemaOnSchema; | ||
| type SchemaWithMetadata = { | ||
| [K: string]: SchemaNode | SchemaMetadata[keyof SchemaMetadata]; | ||
| } & SchemaMetadata; | ||
| interface FieldTypeOpts<TType = any> { | ||
| name: string; | ||
| validate?: ValidateFunction<TType>; | ||
| clean?: CleanFunction<TType>; | ||
| toGraphQLType?: (GraphQL: any) => any; | ||
| meta?: any; | ||
| } | ||
| interface FieldType<TType = any> { | ||
| name: string; | ||
| validate: ValidateFunction; | ||
| clean: CleanFunction; | ||
| meta?: any; | ||
| toGraphQLType?: (GraphQL: any) => any; | ||
| toSerializedType?: (node: SchemaNode) => Promise<SchemaFieldType>; | ||
| __tsFieldType: TType; | ||
| __isFieldType: boolean; | ||
| } | ||
| type InferSchemaTypeForFieldType<T> = T extends { | ||
| __tsFieldType: infer U; | ||
| } ? U : T extends 'string' ? string : T extends 'date' ? Date : T extends 'integer' ? number : T extends 'number' ? number : T extends 'ID' ? string : T extends 'boolean' ? boolean : T extends 'email' ? string : T extends 'blackbox' ? Blackbox : T extends 'any' ? any : T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : T extends Date ? Date : T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends DateConstructor ? Date : T extends Array<infer U> ? InferSchemaTypeForFieldType<U>[] : T extends Record<string, any> ? InferSchemaTypeForSchema<T> : T; | ||
| type SchemaKeysNotOfSchemaItems = '__isFieldType' | '__GraphQLType' | '__skipChildValidation'; | ||
| type NodeIsOptional<TNode> = TNode extends { | ||
| optional: true; | ||
| } ? true : false; | ||
| type WithoutNotSchemaItems<T extends Record<string, any>> = T extends { | ||
| [key in SchemaKeysNotOfSchemaItems]: any; | ||
| } & Record<string, any> ? Omit<T, SchemaKeysNotOfSchemaItems> : T; | ||
| type InferSchemaTypeForSchema<TSchema extends Record<string, any>> = WithoutNotSchemaItems<{ | ||
| -readonly [K in keyof TSchema as NodeIsOptional<TSchema[K]> extends true ? never : K]: InferSchemaType<TSchema[K]['type']>; | ||
| } & { | ||
| -readonly [K in keyof TSchema as NodeIsOptional<TSchema[K]> extends true ? K : never]?: InferSchemaType<TSchema[K]['type']>; | ||
| }>; | ||
| type IsPossiblyASchema<TType> = TType extends FieldType ? false : TType extends Record<string, any> ? keyof { | ||
| [K in keyof TType as 'type' extends keyof TType[K] ? K : never]: TType[K]; | ||
| } extends never ? false : true : false; | ||
| type AClass<T = any> = abstract new (...args: any) => T; | ||
| /** | ||
| * Returns the type of the schema | ||
| */ | ||
| type InferSchemaType<TType> = TType extends { | ||
| __isModel: true; | ||
| type: infer U; | ||
| } ? InferSchemaTypeForSchema<U> : TType extends SchemaMetaFieldTypeSingleNonSchema ? InferSchemaTypeForFieldType<TType> : TType extends AClass<infer U> ? U : IsPossiblyASchema<TType> extends true ? InferSchemaTypeForSchema<TType> : InferSchemaTypeForFieldType<TType>; | ||
| /** | ||
| * Returns the type of the schema but only if its a schema | ||
| */ | ||
| type StrictInferSchemaType<TSchema extends Schema> = InferSchemaTypeForSchema<TSchema>; | ||
| /** | ||
| * Returns the type of the schema but only if its a schema | ||
| */ | ||
| type InferSchemaTypeFromTypedSchema<TTypedSchema extends TypedSchemaOnSchema> = TTypedSchema; | ||
| declare function validate<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<void>; | ||
| interface ValidationErrorInfo { | ||
| error: string; | ||
| message: string; | ||
| validationErrors: Record<string, string>; | ||
| labels: Record<string, string>; | ||
| } | ||
| declare class ValidationError extends Error { | ||
| code: string; | ||
| isValidationError: boolean; | ||
| isOrionError: boolean; | ||
| validationErrors: Record<string, string>; | ||
| labels: Record<string, string>; | ||
| constructor(validationErrors: Record<string, string>, labels?: Record<string, string>); | ||
| getInfo: () => ValidationErrorInfo; | ||
| prependKey: (prepend: any) => ValidationError; | ||
| } | ||
| declare const _default: { | ||
| array: FieldType<any[]>; | ||
| plainObject: FieldType<Blackbox>; | ||
| string: FieldType<string>; | ||
| date: FieldType<Date>; | ||
| integer: FieldType<number>; | ||
| number: FieldType<number>; | ||
| ID: FieldType<string>; | ||
| boolean: FieldType<boolean>; | ||
| email: FieldType<string>; | ||
| blackbox: FieldType<Blackbox>; | ||
| any: FieldType<any>; | ||
| }; | ||
| type FieldValidatorType = keyof typeof _default | 'custom' | 'plainObject'; | ||
| type MergeSchemas<SchemaA extends Schema, SchemaB extends Schema> = SchemaA & SchemaB; | ||
| declare function getValidationErrors<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<any>; | ||
| declare function isValid<TSchema extends Schema>(schema: TSchema, doc: InferSchemaType<TSchema>, passedOptions?: {}, ...args: any[]): Promise<boolean>; | ||
| declare function getFieldType(type: SchemaFieldType | FieldValidatorType | any): FieldType; | ||
| declare function clean<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, opts?: CurrentNodeInfoOptions, ...args: any[]): Promise<InferSchemaType<TSchema>>; | ||
| declare function export_default$2(schema: any, key: any, value: any, passedOptions?: {}, ...args: any[]): Promise<any>; | ||
| declare function export_default$1(schema: Schema, key: string, value: any, passedOptions?: CurrentNodeInfoOptions, ...args: any[]): Promise<any>; | ||
| declare function export_default(schema: Schema, path: string): SchemaNode; | ||
| declare function createEnum<const TValues extends readonly string[]>(name: string, values: TValues): FieldType<TValues[number]>; | ||
| declare function isSchemaLike(type: any): boolean; | ||
| declare function isStrictSchemaLike<TType extends Schema | SchemaFieldTypeNonSchema>(type: TType): TType extends Schema ? true : false; | ||
| declare function isSchemaOrFieldLike(type: any): boolean; | ||
| declare function getSchemaModelName(type: any): string | null; | ||
| declare function getSchemaFromAnyOrionForm(type: any): SchemaFieldType; | ||
| declare function getSchemaWithMetadataFromAnyOrionForm(type: any): SchemaWithMetadata; | ||
| declare function cleanAndValidate<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>): Promise<InferSchemaType<TSchema>>; | ||
| /** | ||
| * Assigns a name to a schema for GraphQL type generation. | ||
| * | ||
| * This function associates a name with a schema object by setting an internal | ||
| * `__modelName` property. This name is used when generating GraphQL types. | ||
| * | ||
| * @param name - The name to assign to the schema | ||
| * @param schema - The schema object to name | ||
| * @returns The same schema object with the internal name property added | ||
| * | ||
| * Note: The schema object is modified in-place, so the name will persist | ||
| * even if you don't use the returned value. | ||
| */ | ||
| declare function schemaWithName<TModelName extends string, TSchema extends Schema>(name: TModelName, schema: TSchema): TSchema; | ||
| type CloneSchemaOptions<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = { | ||
| /** | ||
| * The schema to clone | ||
| */ | ||
| schema: TSchema; | ||
| /** | ||
| * The name of the cloned schema | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * The schema to extend the cloned schema with | ||
| */ | ||
| extendSchema?: TExtendFields; | ||
| /** | ||
| * A function to map the fields of the cloned schema. | ||
| * Warning: This function will not be applied to the typescript types of this schema. | ||
| */ | ||
| mapFields?: (field: TSchema[keyof TSchema], key: keyof TSchema) => SchemaNode; | ||
| /** | ||
| * The fields to pick from the cloned schema | ||
| */ | ||
| pickFields?: TPickFields; | ||
| /** | ||
| * The fields to omit from the cloned schema | ||
| */ | ||
| omitFields?: TOmitFields; | ||
| }; | ||
| type ExtendFields<TSchema extends Schema, TExtendFields extends Schema | undefined> = TExtendFields extends undefined ? TSchema : { | ||
| [key in keyof (TSchema & TExtendFields)]: key extends keyof TExtendFields ? TExtendFields[key] : key extends keyof TSchema ? TSchema[key] : never; | ||
| }; | ||
| type PickOrOmit<TSchema extends Schema, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = TPickFields extends undefined ? TOmitFields extends undefined ? TSchema : Omit<TSchema, TOmitFields[number]> : Pick<TSchema, TPickFields[number]>; | ||
| type ClonedSchema<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = ExtendFields<PickOrOmit<TSchema, TPickFields, TOmitFields>, TExtendFields>; | ||
| declare function cloneSchema<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined>(options: CloneSchemaOptions<TSchema, TExtendFields, TPickFields, TOmitFields>): ClonedSchema<TSchema, TExtendFields, TPickFields, TOmitFields>; | ||
| export { type Blackbox, type CleanFunction, type CloneSchemaOptions, type ClonedSchema, type Constructor, type ConstructorsTypesList, type CurrentNodeInfo, type CurrentNodeInfoOptions, type FieldType, type FieldTypeOpts, type FieldTypesList, type FieldValidatorType, type InferSchemaType, type InferSchemaTypeFromTypedSchema, type MergeSchemas, type Schema, type SchemaFieldType, type SchemaFieldTypeNonSchema, type SchemaInAnyOrionForm, type SchemaMetaFieldTypeSingle, type SchemaMetaFieldTypeSingleNonSchema, type SchemaMetadata, type SchemaNode, type SchemaRecursiveNodeTypeExtras, type SchemaWithMetadata, type SingleLevelSchema, type StrictInferSchemaType, type TypedSchemaOnSchema, type ValidateFunction, ValidationError, clean, cleanAndValidate, export_default$2 as cleanKey, cloneSchema, createEnum, export_default as dotGetSchema, _default as fieldTypes, getFieldType, getSchemaFromAnyOrionForm, getSchemaModelName, getSchemaWithMetadataFromAnyOrionForm, getValidationErrors, isSchemaLike, isSchemaOrFieldLike, isStrictSchemaLike, isValid, schemaWithName, validate, export_default$1 as validateKey }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
51
628.57%2666
5.08%232293
-3.39%