@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.
Files changed (127) hide show
  1. package/dist/index.cjs +3635 -0
  2. package/dist/index.d.ts +185 -0
  3. package/dist/index.js +3607 -0
  4. package/package.json +19 -13
  5. package/LICENSE +0 -21
  6. package/lib/Errors.d.ts +0 -21
  7. package/lib/Errors.js +0 -22
  8. package/lib/ValidationError.d.ts +0 -14
  9. package/lib/ValidationError.js +0 -45
  10. package/lib/ValidationError.test.d.ts +0 -1
  11. package/lib/ValidationError.test.js +0 -35
  12. package/lib/clean/cleanType.d.ts +0 -3
  13. package/lib/clean/cleanType.js +0 -49
  14. package/lib/clean/getObjectNode.d.ts +0 -2
  15. package/lib/clean/getObjectNode.js +0 -14
  16. package/lib/clean/index.d.ts +0 -2
  17. package/lib/clean/index.js +0 -30
  18. package/lib/clean/index.test.d.ts +0 -1
  19. package/lib/clean/index.test.js +0 -482
  20. package/lib/clean/recursiveClean.d.ts +0 -3
  21. package/lib/clean/recursiveClean.js +0 -89
  22. package/lib/cleanKey.d.ts +0 -1
  23. package/lib/cleanKey.js +0 -25
  24. package/lib/cleanKey.test.d.ts +0 -1
  25. package/lib/cleanKey.test.js +0 -115
  26. package/lib/dotGetSchema.d.ts +0 -2
  27. package/lib/dotGetSchema.js +0 -7
  28. package/lib/fieldType.d.ts +0 -17
  29. package/lib/fieldType.js +0 -28
  30. package/lib/fieldTypes/ID.d.ts +0 -2
  31. package/lib/fieldTypes/ID.js +0 -29
  32. package/lib/fieldTypes/ID.test.d.ts +0 -1
  33. package/lib/fieldTypes/ID.test.js +0 -25
  34. package/lib/fieldTypes/any.d.ts +0 -2
  35. package/lib/fieldTypes/any.js +0 -10
  36. package/lib/fieldTypes/any.test.d.ts +0 -1
  37. package/lib/fieldTypes/any.test.js +0 -13
  38. package/lib/fieldTypes/array.d.ts +0 -2
  39. package/lib/fieldTypes/array.js +0 -23
  40. package/lib/fieldTypes/array.test.d.ts +0 -1
  41. package/lib/fieldTypes/array.test.js +0 -22
  42. package/lib/fieldTypes/blackbox.d.ts +0 -2
  43. package/lib/fieldTypes/blackbox.js +0 -15
  44. package/lib/fieldTypes/blackbox.test.d.ts +0 -1
  45. package/lib/fieldTypes/blackbox.test.js +0 -16
  46. package/lib/fieldTypes/boolean.d.ts +0 -2
  47. package/lib/fieldTypes/boolean.js +0 -36
  48. package/lib/fieldTypes/boolean.test.d.ts +0 -1
  49. package/lib/fieldTypes/boolean.test.js +0 -27
  50. package/lib/fieldTypes/date.d.ts +0 -2
  51. package/lib/fieldTypes/date.js +0 -36
  52. package/lib/fieldTypes/date.test.d.ts +0 -1
  53. package/lib/fieldTypes/date.test.js +0 -37
  54. package/lib/fieldTypes/email.d.ts +0 -2
  55. package/lib/fieldTypes/email.js +0 -29
  56. package/lib/fieldTypes/email.test.d.ts +0 -1
  57. package/lib/fieldTypes/email.test.js +0 -20
  58. package/lib/fieldTypes/enum.d.ts +0 -4
  59. package/lib/fieldTypes/enum.js +0 -57
  60. package/lib/fieldTypes/enum.test.d.ts +0 -1
  61. package/lib/fieldTypes/enum.test.js +0 -41
  62. package/lib/fieldTypes/index.d.ts +0 -14
  63. package/lib/fieldTypes/index.js +0 -29
  64. package/lib/fieldTypes/integer.d.ts +0 -2
  65. package/lib/fieldTypes/integer.js +0 -17
  66. package/lib/fieldTypes/integer.test.d.ts +0 -1
  67. package/lib/fieldTypes/integer.test.js +0 -19
  68. package/lib/fieldTypes/number.d.ts +0 -2
  69. package/lib/fieldTypes/number.js +0 -32
  70. package/lib/fieldTypes/number.test.d.ts +0 -1
  71. package/lib/fieldTypes/number.test.js +0 -28
  72. package/lib/fieldTypes/plainObject.d.ts +0 -2
  73. package/lib/fieldTypes/plainObject.js +0 -29
  74. package/lib/fieldTypes/plainObject.test.d.ts +0 -1
  75. package/lib/fieldTypes/plainObject.test.js +0 -42
  76. package/lib/fieldTypes/string.d.ts +0 -2
  77. package/lib/fieldTypes/string.js +0 -47
  78. package/lib/fieldTypes/string.test.d.ts +0 -1
  79. package/lib/fieldTypes/string.test.js +0 -28
  80. package/lib/getSchemaFromTypedModel.d.ts +0 -2
  81. package/lib/getSchemaFromTypedModel.js +0 -15
  82. package/lib/getValidationErrors/convertTypedModel.d.ts +0 -3
  83. package/lib/getValidationErrors/convertTypedModel.js +0 -33
  84. package/lib/getValidationErrors/doValidation.d.ts +0 -2
  85. package/lib/getValidationErrors/doValidation.js +0 -78
  86. package/lib/getValidationErrors/getError/getFieldType.d.ts +0 -4
  87. package/lib/getValidationErrors/getError/getFieldType.js +0 -13
  88. package/lib/getValidationErrors/getError/getFieldValidator.d.ts +0 -2
  89. package/lib/getValidationErrors/getError/getFieldValidator.js +0 -38
  90. package/lib/getValidationErrors/getError/getFieldValidator.test.d.ts +0 -1
  91. package/lib/getValidationErrors/getError/getFieldValidator.test.js +0 -72
  92. package/lib/getValidationErrors/getError/index.d.ts +0 -2
  93. package/lib/getValidationErrors/getError/index.js +0 -44
  94. package/lib/getValidationErrors/getError/index.test.d.ts +0 -1
  95. package/lib/getValidationErrors/getError/index.test.js +0 -52
  96. package/lib/getValidationErrors/getValidationErrorsObject.d.ts +0 -4
  97. package/lib/getValidationErrors/getValidationErrorsObject.js +0 -17
  98. package/lib/getValidationErrors/index.d.ts +0 -2
  99. package/lib/getValidationErrors/index.js +0 -34
  100. package/lib/getValidationErrors/index.test.d.ts +0 -1
  101. package/lib/getValidationErrors/index.test.js +0 -416
  102. package/lib/index.d.ts +0 -13
  103. package/lib/index.js +0 -42
  104. package/lib/isValid.d.ts +0 -2
  105. package/lib/isValid.js +0 -11
  106. package/lib/isValid.test.d.ts +0 -1
  107. package/lib/isValid.test.js +0 -25
  108. package/lib/types/fieldValidators.d.ts +0 -2
  109. package/lib/types/fieldValidators.js +0 -2
  110. package/lib/types/index.d.ts +0 -2
  111. package/lib/types/index.js +0 -18
  112. package/lib/types/schema.d.ts +0 -118
  113. package/lib/types/schema.js +0 -3
  114. package/lib/types/types.test.d.ts +0 -1
  115. package/lib/types/types.test.js +0 -17
  116. package/lib/validate.d.ts +0 -2
  117. package/lib/validate.js +0 -14
  118. package/lib/validate.test.d.ts +0 -1
  119. package/lib/validate.test.js +0 -29
  120. package/lib/validateKey/dotGetSchema.d.ts +0 -2
  121. package/lib/validateKey/dotGetSchema.js +0 -32
  122. package/lib/validateKey/dotGetSchema.test.d.ts +0 -1
  123. package/lib/validateKey/dotGetSchema.test.js +0 -65
  124. package/lib/validateKey/index.d.ts +0 -2
  125. package/lib/validateKey/index.js +0 -31
  126. package/lib/validateKey/index.test.d.ts +0 -1
  127. package/lib/validateKey/index.test.js +0 -84
@@ -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 {};