@orion-js/schema 4.0.0-next.0 → 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.cjs +298 -2953
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +190 -0
- package/dist/index.d.ts +174 -169
- package/dist/index.js +258 -2928
- package/dist/index.js.map +1 -0
- package/package.json +11 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,185 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
|
|
17
|
+
type Constructor<T> = new (...args: any[]) => T;
|
|
18
|
+
type Blackbox = {
|
|
19
|
+
[name: string]: any;
|
|
21
20
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
30
|
+
interface Schema {
|
|
31
|
+
[key: string]: SchemaNode | Function;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
interface CurrentNodeInfoOptions {
|
|
108
|
+
autoConvert?: boolean;
|
|
109
|
+
filter?: boolean;
|
|
110
|
+
trimStrings?: boolean;
|
|
111
|
+
removeEmptyStrings?: boolean;
|
|
112
|
+
forceDoc?: any;
|
|
113
|
+
omitRequired?: boolean;
|
|
115
114
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
151
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
declare function
|
|
169
|
-
|
|
170
|
-
declare function
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
180
|
-
|
|
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 };
|