@orion-js/schema 4.0.0-alpha.3 → 4.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,185 +1,190 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
- export interface FieldTypeOpts {
4
- name: string;
5
- validate?: ValidateFunction;
6
- clean?: CleanFunction;
7
- toGraphQLType?: (GraphQL: any) => any;
8
- meta?: any;
1
+ interface FieldTypeOpts {
2
+ name: string;
3
+ validate?: ValidateFunction;
4
+ clean?: CleanFunction;
5
+ toGraphQLType?: (GraphQL: any) => any;
6
+ meta?: any;
9
7
  }
10
- export interface FieldType {
11
- name: string;
12
- validate: ValidateFunction;
13
- clean: CleanFunction;
14
- meta?: any;
15
- toGraphQLType?: (GraphQL: any) => any;
16
- _isFieldType: boolean;
8
+ interface FieldType {
9
+ name: string;
10
+ validate: ValidateFunction;
11
+ clean: CleanFunction;
12
+ meta?: any;
13
+ toGraphQLType?: (GraphQL: any) => any;
14
+ _isFieldType: boolean;
17
15
  }
18
- export type Constructor<T> = new (...args: any[]) => T;
19
- export type Blackbox = {
20
- [name: string]: any;
16
+
17
+ type Constructor<T> = new (...args: any[]) => T;
18
+ type Blackbox = {
19
+ [name: string]: any;
21
20
  };
22
- export type FieldTypesList = "string" | "date" | "integer" | "number" | "ID" | "boolean" | "email" | "blackbox" | "any";
23
- export type TypedModelOnSchema = Function;
24
- export type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date>;
25
- export type SchemaRecursiveNodeTypeExtras = {
26
- _isFieldType?: boolean;
27
- __clean?: CleanFunction;
28
- __validate?: ValidateFunction;
29
- __skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>;
21
+ type FieldTypesList = 'string' | 'date' | 'integer' | 'number' | 'ID' | 'boolean' | 'email' | 'blackbox' | 'any';
22
+ type TypedModelOnSchema = Function;
23
+ type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date>;
24
+ type SchemaRecursiveNodeTypeExtras = {
25
+ _isFieldType?: boolean;
26
+ __clean?: CleanFunction;
27
+ __validate?: ValidateFunction;
28
+ __skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>;
30
29
  };
31
- export interface Schema {
32
- [key: string]: SchemaNode | Function;
30
+ interface Schema {
31
+ [key: string]: SchemaNode | Function;
33
32
  }
34
- export type SchemaRecursiveNodeType = Schema & SchemaRecursiveNodeTypeExtras;
35
- export type SchemaMetaFieldTypeSingle = FieldTypesList | ConstructorsTypesList | SchemaRecursiveNodeType | FieldType | TypedModelOnSchema;
36
- export type SchemaMetaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[];
37
- export type ValidateFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | void | Promise<object | string | void>;
38
- export type CleanFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => any | Promise<any>;
39
- export interface SchemaNode {
40
- /**
41
- * The type of the field. Used for type validations. Can also contain a subschema.
42
- */
43
- type: SchemaMetaFieldType;
44
- /**
45
- * Defaults to false
46
- */
47
- optional?: boolean;
48
- allowedValues?: Array<any>;
49
- defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>) | any;
50
- /**
51
- * Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
52
- */
53
- validate?: ValidateFunction;
54
- /**
55
- * Function that preprocesses a value before it is set.
56
- */
57
- clean?: CleanFunction;
58
- autoValue?: (value: any, info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>;
59
- /**
60
- * The minimum value if it's a number, the minimum length if it's a string or array.
61
- */
62
- min?: number;
63
- /**
64
- * The maximum value if it's a number, the maximum length if it's a string or array.
65
- */
66
- max?: number;
67
- /**
68
- * Internal use only.
69
- */
70
- isBlackboxChild?: boolean;
71
- /**
72
- * @deprecated
73
- */
74
- custom?: ValidateFunction;
75
- /**
76
- * Used in GraphQL. If true, the field will be omitted from the schema.
77
- */
78
- private?: boolean;
79
- /**
80
- * Used in GraphQL. When in GraphQL, this resolver will replace the static field.
81
- */
82
- graphQLResolver?: (...args: any) => any;
83
- /**
84
- * Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
85
- */
86
- key?: string;
87
- /**
88
- * The name that would be displayed in a front-end form
89
- */
90
- label?: string;
91
- /**
92
- * The description that would be displayed in a front-end form
93
- */
94
- description?: string;
95
- /**
96
- * The placeholder that would be displayed in a front-end form
97
- */
98
- placeholder?: string;
99
- /**
100
- * The field type that would be used in a front-end form
101
- */
102
- fieldType?: string;
103
- /**
104
- * The field options that will be passed as props to the front-end field
105
- */
106
- fieldOptions?: any;
33
+ type SchemaRecursiveNodeType = Schema & SchemaRecursiveNodeTypeExtras;
34
+ type SchemaMetaFieldTypeSingle = FieldTypesList | ConstructorsTypesList | SchemaRecursiveNodeType | FieldType | TypedModelOnSchema;
35
+ type SchemaMetaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[];
36
+ type ValidateFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | void | Promise<object | string | void>;
37
+ type CleanFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => any | Promise<any>;
38
+ interface SchemaNode {
39
+ /**
40
+ * The type of the field. Used for type validations. Can also contain a subschema.
41
+ */
42
+ type: SchemaMetaFieldType;
43
+ /**
44
+ * Defaults to false
45
+ */
46
+ optional?: boolean;
47
+ allowedValues?: Array<any>;
48
+ defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>) | any;
49
+ /**
50
+ * Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
51
+ */
52
+ validate?: ValidateFunction;
53
+ /**
54
+ * Function that preprocesses a value before it is set.
55
+ */
56
+ clean?: CleanFunction;
57
+ autoValue?: (value: any, info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>;
58
+ /**
59
+ * The minimum value if it's a number, the minimum length if it's a string or array.
60
+ */
61
+ min?: number;
62
+ /**
63
+ * The maximum value if it's a number, the maximum length if it's a string or array.
64
+ */
65
+ max?: number;
66
+ /**
67
+ * Internal use only.
68
+ */
69
+ isBlackboxChild?: boolean;
70
+ /**
71
+ * @deprecated
72
+ */
73
+ custom?: ValidateFunction;
74
+ /**
75
+ * Used in GraphQL. If true, the field will be omitted from the schema.
76
+ */
77
+ private?: boolean;
78
+ /**
79
+ * Used in GraphQL. When in GraphQL, this resolver will replace the static field.
80
+ */
81
+ graphQLResolver?: (...args: any) => any;
82
+ /**
83
+ * Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
84
+ */
85
+ key?: string;
86
+ /**
87
+ * The name that would be displayed in a front-end form
88
+ */
89
+ label?: string;
90
+ /**
91
+ * The description that would be displayed in a front-end form
92
+ */
93
+ description?: string;
94
+ /**
95
+ * The placeholder that would be displayed in a front-end form
96
+ */
97
+ placeholder?: string;
98
+ /**
99
+ * The field type that would be used in a front-end form
100
+ */
101
+ fieldType?: string;
102
+ /**
103
+ * The field options that will be passed as props to the front-end field
104
+ */
105
+ fieldOptions?: any;
107
106
  }
108
- export interface CurrentNodeInfoOptions {
109
- autoConvert?: boolean;
110
- filter?: boolean;
111
- trimStrings?: boolean;
112
- removeEmptyStrings?: boolean;
113
- forceDoc?: any;
114
- omitRequired?: boolean;
107
+ interface CurrentNodeInfoOptions {
108
+ autoConvert?: boolean;
109
+ filter?: boolean;
110
+ trimStrings?: boolean;
111
+ removeEmptyStrings?: boolean;
112
+ forceDoc?: any;
113
+ omitRequired?: boolean;
115
114
  }
116
- export interface CurrentNodeInfo {
117
- /**
118
- * The global schema, prefaced by {type: {...}} to be compatible with subschemas
119
- * Sometimes it's given without {type: {...}}. TODO: Normalize this.
120
- */
121
- schema?: SchemaNode | Schema;
122
- /**
123
- * The current node subschema
124
- */
125
- currentSchema?: Partial<SchemaNode>;
126
- value: any;
127
- doc?: any;
128
- currentDoc?: any;
129
- options?: CurrentNodeInfoOptions;
130
- args?: any[];
131
- type?: SchemaMetaFieldType;
132
- keys?: string[];
133
- addError?: (keys: string[], code: string | object) => void;
115
+ interface CurrentNodeInfo {
116
+ /**
117
+ * The global schema, prefaced by {type: {...}} to be compatible with subschemas
118
+ * Sometimes it's given without {type: {...}}. TODO: Normalize this.
119
+ */
120
+ schema?: SchemaNode | Schema;
121
+ /**
122
+ * The current node subschema
123
+ */
124
+ currentSchema?: Partial<SchemaNode>;
125
+ value: any;
126
+ doc?: any;
127
+ currentDoc?: any;
128
+ options?: CurrentNodeInfoOptions;
129
+ args?: any[];
130
+ type?: SchemaMetaFieldType;
131
+ keys?: string[];
132
+ addError?: (keys: string[], code: string | object) => void;
134
133
  }
135
- export function validate(schema: Schema | Function, doc: any, passedOptions?: {}, ...args: any[]): Promise<void>;
136
- export interface ValidationErrorInfo {
137
- error: string;
138
- message: string;
139
- validationErrors: object;
134
+
135
+ declare function validate(schema: Schema | Function, doc: any, passedOptions?: {}, ...args: any[]): Promise<void>;
136
+
137
+ interface ValidationErrorInfo {
138
+ error: string;
139
+ message: string;
140
+ validationErrors: object;
140
141
  }
141
- export declare class ValidationError extends Error {
142
- code: string;
143
- isValidationError: boolean;
144
- isOrionError: boolean;
145
- validationErrors: object;
146
- constructor(validationErrors: object);
147
- getInfo: () => ValidationErrorInfo;
148
- prependKey: (prepend: any) => ValidationError;
142
+ declare class ValidationError extends Error {
143
+ code: string;
144
+ isValidationError: boolean;
145
+ isOrionError: boolean;
146
+ validationErrors: object;
147
+ constructor(validationErrors: object);
148
+ getInfo: () => ValidationErrorInfo;
149
+ prependKey: (prepend: any) => ValidationError;
149
150
  }
150
- export function getValidationErrors(schema: Schema | Function, doc: any, passedOptions?: {}, ...args: any[]): Promise<any>;
151
- export function isValid(schema: Schema, doc: any, passedOptions?: {}, ...args: any[]): Promise<boolean>;
151
+
152
+ declare function getValidationErrors(schema: Schema | Function, doc: any, passedOptions?: {}, ...args: any[]): Promise<any>;
153
+
154
+ declare function isValid(schema: Schema, doc: any, passedOptions?: {}, ...args: any[]): Promise<boolean>;
155
+
152
156
  declare const _default: {
153
- array: FieldType;
154
- plainObject: FieldType;
155
- string: FieldType;
156
- date: FieldType;
157
- integer: FieldType;
158
- number: FieldType;
159
- ID: FieldType;
160
- boolean: FieldType;
161
- email: FieldType;
162
- blackbox: FieldType;
163
- any: FieldType;
157
+ array: FieldType;
158
+ plainObject: FieldType;
159
+ string: FieldType;
160
+ date: FieldType;
161
+ integer: FieldType;
162
+ number: FieldType;
163
+ ID: FieldType;
164
+ boolean: FieldType;
165
+ email: FieldType;
166
+ blackbox: FieldType;
167
+ any: FieldType;
164
168
  };
165
- export type FieldValidatorType = keyof typeof _default | "custom" | "plainObject";
166
- export function getFieldType(type: SchemaMetaFieldType | FieldValidatorType | any): FieldType;
167
- export function clean<TDoc = Blackbox>(schema: Schema | Function, doc: TDoc, opts?: CurrentNodeInfoOptions, ...args: any[]): Promise<TDoc>;
168
- declare function _default$1(schema: any, key: any, value: any, passedOptions?: {}, ...args: any[]): Promise<any>;
169
- declare function _default$2(schema: Schema, key: string, value: any, passedOptions?: CurrentNodeInfoOptions, ...args: any[]): Promise<any>;
170
- declare function _default$3(schema: Schema, path: string): SchemaNode | {
171
- type: string;
172
- optional: boolean;
173
- isBlackboxChild: boolean;
174
- };
175
- export function createEnum<TValues extends readonly string[]>(name: string, values: TValues): FieldType & {
176
- type: TValues[number];
169
+
170
+ type FieldValidatorType = keyof typeof _default | 'custom' | 'plainObject';
171
+
172
+ declare function getFieldType(type: SchemaMetaFieldType | FieldValidatorType | any): FieldType;
173
+
174
+ declare function clean<TDoc = Blackbox>(schema: Schema | Function, doc: TDoc, opts?: CurrentNodeInfoOptions, ...args: any[]): Promise<TDoc>;
175
+
176
+ declare function export_default$2(schema: any, key: any, value: any, passedOptions?: {}, ...args: any[]): Promise<any>;
177
+
178
+ declare function export_default$1(schema: Schema, key: string, value: any, passedOptions?: CurrentNodeInfoOptions, ...args: any[]): Promise<any>;
179
+
180
+ declare function export_default(schema: Schema, path: string): SchemaNode | {
181
+ type: string;
182
+ optional: boolean;
183
+ isBlackboxChild: boolean;
177
184
  };
178
185
 
179
- export {
180
- _default$1 as cleanKey,
181
- _default$2 as validateKey,
182
- _default$3 as dotGetSchema,
186
+ declare function createEnum<TValues extends readonly string[]>(name: string, values: TValues): FieldType & {
187
+ type: TValues[number];
183
188
  };
184
189
 
185
- export {};
190
+ export { type Blackbox, type CleanFunction, type Constructor, type ConstructorsTypesList, type CurrentNodeInfo, type CurrentNodeInfoOptions, type FieldType, type FieldTypeOpts, type FieldTypesList, type FieldValidatorType, type Schema, type SchemaMetaFieldType, type SchemaMetaFieldTypeSingle, type SchemaNode, type SchemaRecursiveNodeType, type SchemaRecursiveNodeTypeExtras, type TypedModelOnSchema, type ValidateFunction, ValidationError, clean, export_default$2 as cleanKey, createEnum, export_default as dotGetSchema, getFieldType, getValidationErrors, isValid, validate, export_default$1 as validateKey };