@orion-js/schema 3.11.8 → 4.0.0-alpha.3
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 +3635 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +3607 -0
- package/package.json +19 -13
- package/LICENSE +0 -21
- package/lib/Errors.d.ts +0 -21
- package/lib/Errors.js +0 -22
- package/lib/ValidationError.d.ts +0 -14
- package/lib/ValidationError.js +0 -45
- package/lib/ValidationError.test.d.ts +0 -1
- package/lib/ValidationError.test.js +0 -35
- package/lib/clean/cleanType.d.ts +0 -3
- package/lib/clean/cleanType.js +0 -49
- package/lib/clean/getObjectNode.d.ts +0 -2
- package/lib/clean/getObjectNode.js +0 -14
- package/lib/clean/index.d.ts +0 -2
- package/lib/clean/index.js +0 -30
- package/lib/clean/index.test.d.ts +0 -1
- package/lib/clean/index.test.js +0 -482
- package/lib/clean/recursiveClean.d.ts +0 -3
- package/lib/clean/recursiveClean.js +0 -89
- package/lib/cleanKey.d.ts +0 -1
- package/lib/cleanKey.js +0 -25
- package/lib/cleanKey.test.d.ts +0 -1
- package/lib/cleanKey.test.js +0 -115
- package/lib/dotGetSchema.d.ts +0 -2
- package/lib/dotGetSchema.js +0 -7
- package/lib/fieldType.d.ts +0 -17
- package/lib/fieldType.js +0 -28
- package/lib/fieldTypes/ID.d.ts +0 -2
- package/lib/fieldTypes/ID.js +0 -29
- package/lib/fieldTypes/ID.test.d.ts +0 -1
- package/lib/fieldTypes/ID.test.js +0 -25
- package/lib/fieldTypes/any.d.ts +0 -2
- package/lib/fieldTypes/any.js +0 -10
- package/lib/fieldTypes/any.test.d.ts +0 -1
- package/lib/fieldTypes/any.test.js +0 -13
- package/lib/fieldTypes/array.d.ts +0 -2
- package/lib/fieldTypes/array.js +0 -23
- package/lib/fieldTypes/array.test.d.ts +0 -1
- package/lib/fieldTypes/array.test.js +0 -22
- package/lib/fieldTypes/blackbox.d.ts +0 -2
- package/lib/fieldTypes/blackbox.js +0 -15
- package/lib/fieldTypes/blackbox.test.d.ts +0 -1
- package/lib/fieldTypes/blackbox.test.js +0 -16
- package/lib/fieldTypes/boolean.d.ts +0 -2
- package/lib/fieldTypes/boolean.js +0 -36
- package/lib/fieldTypes/boolean.test.d.ts +0 -1
- package/lib/fieldTypes/boolean.test.js +0 -27
- package/lib/fieldTypes/date.d.ts +0 -2
- package/lib/fieldTypes/date.js +0 -36
- package/lib/fieldTypes/date.test.d.ts +0 -1
- package/lib/fieldTypes/date.test.js +0 -37
- package/lib/fieldTypes/email.d.ts +0 -2
- package/lib/fieldTypes/email.js +0 -29
- package/lib/fieldTypes/email.test.d.ts +0 -1
- package/lib/fieldTypes/email.test.js +0 -20
- package/lib/fieldTypes/enum.d.ts +0 -4
- package/lib/fieldTypes/enum.js +0 -57
- package/lib/fieldTypes/enum.test.d.ts +0 -1
- package/lib/fieldTypes/enum.test.js +0 -41
- package/lib/fieldTypes/index.d.ts +0 -14
- package/lib/fieldTypes/index.js +0 -29
- package/lib/fieldTypes/integer.d.ts +0 -2
- package/lib/fieldTypes/integer.js +0 -17
- package/lib/fieldTypes/integer.test.d.ts +0 -1
- package/lib/fieldTypes/integer.test.js +0 -19
- package/lib/fieldTypes/number.d.ts +0 -2
- package/lib/fieldTypes/number.js +0 -32
- package/lib/fieldTypes/number.test.d.ts +0 -1
- package/lib/fieldTypes/number.test.js +0 -28
- package/lib/fieldTypes/plainObject.d.ts +0 -2
- package/lib/fieldTypes/plainObject.js +0 -29
- package/lib/fieldTypes/plainObject.test.d.ts +0 -1
- package/lib/fieldTypes/plainObject.test.js +0 -42
- package/lib/fieldTypes/string.d.ts +0 -2
- package/lib/fieldTypes/string.js +0 -47
- package/lib/fieldTypes/string.test.d.ts +0 -1
- package/lib/fieldTypes/string.test.js +0 -28
- package/lib/getSchemaFromTypedModel.d.ts +0 -2
- package/lib/getSchemaFromTypedModel.js +0 -15
- package/lib/getValidationErrors/convertTypedModel.d.ts +0 -3
- package/lib/getValidationErrors/convertTypedModel.js +0 -33
- package/lib/getValidationErrors/doValidation.d.ts +0 -2
- package/lib/getValidationErrors/doValidation.js +0 -78
- package/lib/getValidationErrors/getError/getFieldType.d.ts +0 -4
- package/lib/getValidationErrors/getError/getFieldType.js +0 -13
- package/lib/getValidationErrors/getError/getFieldValidator.d.ts +0 -2
- package/lib/getValidationErrors/getError/getFieldValidator.js +0 -38
- package/lib/getValidationErrors/getError/getFieldValidator.test.d.ts +0 -1
- package/lib/getValidationErrors/getError/getFieldValidator.test.js +0 -72
- package/lib/getValidationErrors/getError/index.d.ts +0 -2
- package/lib/getValidationErrors/getError/index.js +0 -44
- package/lib/getValidationErrors/getError/index.test.d.ts +0 -1
- package/lib/getValidationErrors/getError/index.test.js +0 -52
- package/lib/getValidationErrors/getValidationErrorsObject.d.ts +0 -4
- package/lib/getValidationErrors/getValidationErrorsObject.js +0 -17
- package/lib/getValidationErrors/index.d.ts +0 -2
- package/lib/getValidationErrors/index.js +0 -34
- package/lib/getValidationErrors/index.test.d.ts +0 -1
- package/lib/getValidationErrors/index.test.js +0 -416
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -42
- package/lib/isValid.d.ts +0 -2
- package/lib/isValid.js +0 -11
- package/lib/isValid.test.d.ts +0 -1
- package/lib/isValid.test.js +0 -25
- package/lib/types/fieldValidators.d.ts +0 -2
- package/lib/types/fieldValidators.js +0 -2
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -18
- package/lib/types/schema.d.ts +0 -118
- package/lib/types/schema.js +0 -3
- package/lib/types/types.test.d.ts +0 -1
- package/lib/types/types.test.js +0 -17
- package/lib/validate.d.ts +0 -2
- package/lib/validate.js +0 -14
- package/lib/validate.test.d.ts +0 -1
- package/lib/validate.test.js +0 -29
- package/lib/validateKey/dotGetSchema.d.ts +0 -2
- package/lib/validateKey/dotGetSchema.js +0 -32
- package/lib/validateKey/dotGetSchema.test.d.ts +0 -1
- package/lib/validateKey/dotGetSchema.test.js +0 -65
- package/lib/validateKey/index.d.ts +0 -2
- package/lib/validateKey/index.js +0 -31
- package/lib/validateKey/index.test.d.ts +0 -1
- package/lib/validateKey/index.test.js +0 -84
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
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;
|
|
9
|
+
}
|
|
10
|
+
export interface FieldType {
|
|
11
|
+
name: string;
|
|
12
|
+
validate: ValidateFunction;
|
|
13
|
+
clean: CleanFunction;
|
|
14
|
+
meta?: any;
|
|
15
|
+
toGraphQLType?: (GraphQL: any) => any;
|
|
16
|
+
_isFieldType: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type Constructor<T> = new (...args: any[]) => T;
|
|
19
|
+
export type Blackbox = {
|
|
20
|
+
[name: string]: any;
|
|
21
|
+
};
|
|
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>;
|
|
30
|
+
};
|
|
31
|
+
export interface Schema {
|
|
32
|
+
[key: string]: SchemaNode | Function;
|
|
33
|
+
}
|
|
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;
|
|
107
|
+
}
|
|
108
|
+
export interface CurrentNodeInfoOptions {
|
|
109
|
+
autoConvert?: boolean;
|
|
110
|
+
filter?: boolean;
|
|
111
|
+
trimStrings?: boolean;
|
|
112
|
+
removeEmptyStrings?: boolean;
|
|
113
|
+
forceDoc?: any;
|
|
114
|
+
omitRequired?: boolean;
|
|
115
|
+
}
|
|
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;
|
|
134
|
+
}
|
|
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;
|
|
140
|
+
}
|
|
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;
|
|
149
|
+
}
|
|
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>;
|
|
152
|
+
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;
|
|
164
|
+
};
|
|
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];
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export {
|
|
180
|
+
_default$1 as cleanKey,
|
|
181
|
+
_default$2 as validateKey,
|
|
182
|
+
_default$3 as dotGetSchema,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export {};
|