@orion-js/schema 3.0.0-alpha.11 → 3.0.0
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/lib/clean/cleanType.d.ts +2 -2
- package/lib/clean/cleanType.js +2 -2
- package/lib/clean/getObjectNode.d.ts +2 -2
- package/lib/clean/index.test.js +9 -8
- package/lib/clean/recursiveClean.d.ts +2 -2
- package/lib/cleanKey.test.js +0 -1
- package/lib/fieldType.d.ts +8 -8
- package/lib/fieldTypes/ID.d.ts +1 -1
- package/lib/fieldTypes/array.d.ts +1 -2
- package/lib/fieldTypes/blackbox.d.ts +1 -1
- package/lib/fieldTypes/boolean.d.ts +1 -1
- package/lib/fieldTypes/date.d.ts +1 -1
- package/lib/fieldTypes/email.d.ts +1 -1
- package/lib/fieldTypes/index.d.ts +10 -10
- package/lib/fieldTypes/integer.d.ts +1 -1
- package/lib/fieldTypes/number.d.ts +1 -1
- package/lib/fieldTypes/plainObject.d.ts +1 -1
- package/lib/fieldTypes/string.d.ts +1 -1
- package/lib/getValidationErrors/doValidation.d.ts +2 -2
- package/lib/getValidationErrors/doValidation.js +4 -3
- package/lib/getValidationErrors/getError/getFieldType.d.ts +2 -2
- package/lib/getValidationErrors/getError/index.d.ts +2 -2
- package/lib/getValidationErrors/getError/index.js +3 -2
- package/lib/getValidationErrors/index.d.ts +2 -2
- package/lib/isValid.d.ts +2 -2
- package/lib/types/schema.d.ts +42 -42
- package/lib/types/schema.js +1 -6
- package/lib/types/types.test.d.ts +1 -0
- package/lib/types/types.test.js +17 -0
- package/lib/validate.d.ts +2 -2
- package/lib/validateKey/dotGetSchema.d.ts +2 -1
- package/lib/validateKey/dotGetSchema.js +1 -1
- package/lib/validateKey/dotGetSchema.test.js +3 -0
- package/lib/validateKey/index.d.ts +2 -1
- package/lib/validateKey/index.test.js +3 -4
- package/package.json +6 -4
package/lib/clean/cleanType.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CurrentNodeInfo, SchemaMetaFieldType, SchemaNode
|
|
1
|
+
import { CurrentNodeInfo, SchemaMetaFieldType, SchemaNode } from '../types/schema';
|
|
2
2
|
import { FieldValidatorType } from '../types/fieldValidators';
|
|
3
|
-
export default function cleanType
|
|
3
|
+
export default function cleanType(type: SchemaMetaFieldType | FieldValidatorType, fieldSchema: Partial<SchemaNode>, value: any, info: CurrentNodeInfo, ...args: any[]): Promise<any>;
|
package/lib/clean/cleanType.js
CHANGED
|
@@ -13,7 +13,7 @@ async function cleanType(type, fieldSchema, value, info, ...args) {
|
|
|
13
13
|
}
|
|
14
14
|
const { clean: rootFieldClean } = await (0, getFieldType_1.default)(type);
|
|
15
15
|
if (rootFieldClean && !(0, isNil_1.default)(value)) {
|
|
16
|
-
value =
|
|
16
|
+
value = await rootFieldClean(value, info, ...args);
|
|
17
17
|
}
|
|
18
18
|
let needReClean = false;
|
|
19
19
|
const objectTypeSchema = (0, getObjectNode_1.default)(fieldSchema, value);
|
|
@@ -42,7 +42,7 @@ async function cleanType(type, fieldSchema, value, info, ...args) {
|
|
|
42
42
|
value = await clean(value, info, ...args);
|
|
43
43
|
}
|
|
44
44
|
if (needReClean && rootFieldClean && !(0, isNil_1.default)(value)) {
|
|
45
|
-
value =
|
|
45
|
+
value = await rootFieldClean(value, info, ...args);
|
|
46
46
|
}
|
|
47
47
|
return value;
|
|
48
48
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SchemaNode
|
|
2
|
-
export default function getObjectNode
|
|
1
|
+
import { SchemaNode } from '../types/schema';
|
|
2
|
+
export default function getObjectNode(schema: Partial<SchemaNode>, value: any): SchemaNode | void;
|
package/lib/clean/index.test.js
CHANGED
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const schema_1 = require("../types/schema");
|
|
7
6
|
const index_1 = __importDefault(require("./index"));
|
|
8
7
|
test('autoconverts values', async () => {
|
|
9
8
|
const schema = {
|
|
@@ -125,12 +124,12 @@ test('filter fields not in schema', async () => {
|
|
|
125
124
|
});
|
|
126
125
|
test('runs autovalues with arrays', async () => {
|
|
127
126
|
const schema = {
|
|
128
|
-
texts:
|
|
127
|
+
texts: {
|
|
129
128
|
type: [String],
|
|
130
129
|
autoValue(values) {
|
|
131
130
|
return values.map(val => val + ' world');
|
|
132
131
|
}
|
|
133
|
-
}
|
|
132
|
+
}
|
|
134
133
|
};
|
|
135
134
|
const doc = {
|
|
136
135
|
texts: ['hello', 'good bye']
|
|
@@ -313,22 +312,22 @@ test('pass currentDoc cleaning arrays', async () => {
|
|
|
313
312
|
const aItem = { name: 'Nicolás' };
|
|
314
313
|
const doc = { items: [aItem] };
|
|
315
314
|
const item = {
|
|
316
|
-
name:
|
|
315
|
+
name: {
|
|
317
316
|
type: String,
|
|
318
317
|
async autoValue(name, { currentDoc }) {
|
|
319
318
|
expect(currentDoc).toBe(aItem);
|
|
320
319
|
return name;
|
|
321
320
|
}
|
|
322
|
-
}
|
|
321
|
+
}
|
|
323
322
|
};
|
|
324
323
|
const schema = {
|
|
325
|
-
items:
|
|
324
|
+
items: {
|
|
326
325
|
type: [item],
|
|
327
326
|
async autoValue(items, { currentDoc }) {
|
|
328
327
|
expect(currentDoc).toBe(doc);
|
|
329
328
|
return items;
|
|
330
329
|
}
|
|
331
|
-
}
|
|
330
|
+
}
|
|
332
331
|
};
|
|
333
332
|
expect.assertions(2);
|
|
334
333
|
await (0, index_1.default)(schema, doc);
|
|
@@ -339,7 +338,9 @@ test('omit undefined items in array', async () => {
|
|
|
339
338
|
name: {
|
|
340
339
|
type: String
|
|
341
340
|
},
|
|
342
|
-
__clean() {
|
|
341
|
+
__clean() {
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
343
344
|
};
|
|
344
345
|
const schema = {
|
|
345
346
|
items: {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CurrentNodeInfo
|
|
2
|
-
declare const clean:
|
|
1
|
+
import { CurrentNodeInfo } from '../types/schema';
|
|
2
|
+
declare const clean: (info: CurrentNodeInfo) => Promise<any>;
|
|
3
3
|
export default clean;
|
package/lib/cleanKey.test.js
CHANGED
package/lib/fieldType.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { CleanFunction,
|
|
2
|
-
export interface FieldTypeOpts
|
|
1
|
+
import { CleanFunction, ValidateFunction } from './types/schema';
|
|
2
|
+
export interface FieldTypeOpts {
|
|
3
3
|
name: string;
|
|
4
|
-
validate?: ValidateFunction
|
|
5
|
-
clean?: CleanFunction
|
|
4
|
+
validate?: ValidateFunction;
|
|
5
|
+
clean?: CleanFunction;
|
|
6
6
|
}
|
|
7
|
-
export interface FieldType
|
|
7
|
+
export interface FieldType {
|
|
8
8
|
name: string;
|
|
9
|
-
validate: ValidateFunction
|
|
10
|
-
clean: CleanFunction
|
|
9
|
+
validate: ValidateFunction;
|
|
10
|
+
clean: CleanFunction;
|
|
11
11
|
_isFieldType: boolean;
|
|
12
12
|
}
|
|
13
|
-
export default function fieldType
|
|
13
|
+
export default function fieldType(opts: FieldTypeOpts): FieldType;
|
package/lib/fieldTypes/ID.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
package/lib/fieldTypes/date.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
array: import("../fieldType").FieldType
|
|
3
|
-
plainObject: import("../fieldType").FieldType
|
|
4
|
-
string: import("../fieldType").FieldType
|
|
5
|
-
date: import("../fieldType").FieldType
|
|
6
|
-
integer: import("../fieldType").FieldType
|
|
7
|
-
number: import("../fieldType").FieldType
|
|
8
|
-
ID: import("../fieldType").FieldType
|
|
9
|
-
boolean: import("../fieldType").FieldType
|
|
10
|
-
email: import("../fieldType").FieldType
|
|
11
|
-
blackbox: import("../fieldType").FieldType
|
|
2
|
+
array: import("../fieldType").FieldType;
|
|
3
|
+
plainObject: import("../fieldType").FieldType;
|
|
4
|
+
string: import("../fieldType").FieldType;
|
|
5
|
+
date: import("../fieldType").FieldType;
|
|
6
|
+
integer: import("../fieldType").FieldType;
|
|
7
|
+
number: import("../fieldType").FieldType;
|
|
8
|
+
ID: import("../fieldType").FieldType;
|
|
9
|
+
boolean: import("../fieldType").FieldType;
|
|
10
|
+
email: import("../fieldType").FieldType;
|
|
11
|
+
blackbox: import("../fieldType").FieldType;
|
|
12
12
|
};
|
|
13
13
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../fieldType").FieldType
|
|
1
|
+
declare const _default: import("../fieldType").FieldType;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CurrentNodeInfo
|
|
2
|
-
export default function doValidation
|
|
1
|
+
import { CurrentNodeInfo } from '../types/schema';
|
|
2
|
+
export default function doValidation(params: CurrentNodeInfo): Promise<void>;
|
|
@@ -24,8 +24,9 @@ async function doValidation(params) {
|
|
|
24
24
|
* Deep validation
|
|
25
25
|
*/
|
|
26
26
|
if ((0, isPlainObject_1.default)(currentSchema.type)) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const type = currentSchema.type;
|
|
28
|
+
if (typeof type?.__skipChildValidation === 'function') {
|
|
29
|
+
if (await type?.__skipChildValidation(value, info)) {
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -56,7 +57,7 @@ async function doValidation(params) {
|
|
|
56
57
|
for (let i = 0; i < value.length; i++) {
|
|
57
58
|
const itemValue = value[i];
|
|
58
59
|
const keyItemKeys = (0, clone_1.default)(keys);
|
|
59
|
-
keyItemKeys.push(i);
|
|
60
|
+
keyItemKeys.push(i.toString());
|
|
60
61
|
await doValidation({
|
|
61
62
|
...info,
|
|
62
63
|
currentDoc: value,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaMetaFieldType
|
|
1
|
+
import { SchemaMetaFieldType } from '../../types/schema';
|
|
2
2
|
import { FieldValidatorType } from '../../types/fieldValidators';
|
|
3
3
|
import { FieldType } from '../../fieldType';
|
|
4
|
-
export default function getFieldType
|
|
4
|
+
export default function getFieldType(type: SchemaMetaFieldType | FieldValidatorType | any): FieldType;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CurrentNodeInfo
|
|
2
|
-
export default function getValidationErrors
|
|
1
|
+
import { CurrentNodeInfo } from '../../types/schema';
|
|
2
|
+
export default function getValidationErrors(params: CurrentNodeInfo): Promise<object | string | void>;
|
|
@@ -32,8 +32,9 @@ async function getValidationErrors(params) {
|
|
|
32
32
|
return customError;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const type = currentSchema.type;
|
|
36
|
+
if (type.__validate) {
|
|
37
|
+
const typeError = await type.__validate(value, info, ...args);
|
|
37
38
|
if (typeError) {
|
|
38
39
|
return typeError;
|
|
39
40
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Schema
|
|
2
|
-
export default function getValidationErrors
|
|
1
|
+
import { Schema } from '../types/schema';
|
|
2
|
+
export default function getValidationErrors(schema: Schema, doc: any, passedOptions?: {}, ...args: any[]): Promise<any>;
|
package/lib/isValid.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Schema
|
|
2
|
-
export default function isValid
|
|
1
|
+
import { Schema } from './types/schema';
|
|
2
|
+
export default function isValid(schema: Schema, doc: any, passedOptions?: {}, ...args: any[]): Promise<boolean>;
|
package/lib/types/schema.d.ts
CHANGED
|
@@ -1,47 +1,40 @@
|
|
|
1
|
+
import { FieldType } from '../fieldType';
|
|
1
2
|
export declare type Constructor<T> = new (...args: any[]) => T;
|
|
2
|
-
export declare type
|
|
3
|
-
export declare type
|
|
4
|
-
export declare type SpecialSchemaObject = 'blackbox';
|
|
3
|
+
export declare type FieldTypesList = 'string' | 'date' | 'integer' | 'number' | 'ID' | 'boolean' | 'email' | 'blackbox';
|
|
4
|
+
export declare type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date>;
|
|
5
5
|
export declare type SchemaRecursiveNodeTypeExtras = {
|
|
6
|
-
__clean?: CleanFunction
|
|
7
|
-
__validate?: ValidateFunction
|
|
6
|
+
__clean?: CleanFunction;
|
|
7
|
+
__validate?: ValidateFunction;
|
|
8
|
+
__skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>;
|
|
8
9
|
};
|
|
9
|
-
export
|
|
10
|
-
[key: string]: SchemaNode
|
|
11
|
-
}
|
|
12
|
-
export declare type SchemaRecursiveNodeType =
|
|
13
|
-
export declare type
|
|
14
|
-
export declare type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
export declare type StringAllowedTypeValues = SpecialSchemaString | Constructor<String>;
|
|
20
|
-
export declare type NumberAllowedTypeValues = SpecialSchemaNumber | Constructor<Number>;
|
|
21
|
-
export declare type ObjectAllowedTypeValues = SpecialSchemaObject | SchemaRecursiveNodeType;
|
|
22
|
-
export declare type SchemaMetaFieldType<T> = T extends string ? StringAllowedTypeValues : T extends number ? NumberAllowedTypeValues : T extends boolean ? Constructor<Boolean> : T extends Date ? Constructor<Date> : T extends Array<infer U> ? Array<SchemaMetaFieldType<U>> : T extends object ? ObjectAllowedTypeValues : T;
|
|
23
|
-
export declare type ValidateFunction<T extends SchemaNodeType> = (value: T, info?: Partial<CurrentNodeInfo<T>>, ...args: any[]) => object | string | void | Promise<object | string | void>;
|
|
24
|
-
export declare type CleanFunction<T extends SchemaNodeType> = (value: T, info?: Partial<CurrentNodeInfo<T>>, ...args: any[]) => T | Promise<T>;
|
|
25
|
-
export interface SchemaNode<T extends SchemaNodeType> {
|
|
10
|
+
export interface Schema {
|
|
11
|
+
[key: string]: SchemaNode | Function;
|
|
12
|
+
}
|
|
13
|
+
export declare type SchemaRecursiveNodeType = Schema & SchemaRecursiveNodeTypeExtras;
|
|
14
|
+
export declare type SchemaMetaFieldTypeSingle = FieldTypesList | ConstructorsTypesList | SchemaRecursiveNodeType | FieldType;
|
|
15
|
+
export declare type SchemaMetaFieldType = SchemaMetaFieldTypeSingle | [SchemaMetaFieldTypeSingle];
|
|
16
|
+
export declare type ValidateFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | void | Promise<object | string | void>;
|
|
17
|
+
export declare type CleanFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => any | Promise<any>;
|
|
18
|
+
export interface SchemaNode {
|
|
26
19
|
/**
|
|
27
20
|
* The type of the field. Used for type validations. Can also contain a subschema.
|
|
28
21
|
*/
|
|
29
|
-
type: SchemaMetaFieldType
|
|
22
|
+
type: SchemaMetaFieldType;
|
|
30
23
|
/**
|
|
31
24
|
* Defaults to false
|
|
32
25
|
*/
|
|
33
26
|
optional?: boolean;
|
|
34
|
-
allowedValues?: Array<
|
|
35
|
-
defaultValue?:
|
|
27
|
+
allowedValues?: Array<any>;
|
|
28
|
+
defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>) | any;
|
|
36
29
|
/**
|
|
37
30
|
* Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
|
|
38
31
|
*/
|
|
39
|
-
validate?: ValidateFunction
|
|
32
|
+
validate?: ValidateFunction;
|
|
40
33
|
/**
|
|
41
34
|
* Function that preprocesses a value before it is set.
|
|
42
35
|
*/
|
|
43
|
-
clean?: CleanFunction
|
|
44
|
-
autoValue?: (value:
|
|
36
|
+
clean?: CleanFunction;
|
|
37
|
+
autoValue?: (value: any, info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>;
|
|
45
38
|
/**
|
|
46
39
|
* The minimum value if it's a number, the minimum length if it's a string or array.
|
|
47
40
|
*/
|
|
@@ -55,15 +48,22 @@ export interface SchemaNode<T extends SchemaNodeType> {
|
|
|
55
48
|
*/
|
|
56
49
|
isBlackboxChild?: boolean;
|
|
57
50
|
/**
|
|
58
|
-
*
|
|
51
|
+
* @deprecated
|
|
52
|
+
*/
|
|
53
|
+
custom?: ValidateFunction;
|
|
54
|
+
/**
|
|
55
|
+
* Used in GraphQL. If true, the field will be omitted from the schema.
|
|
56
|
+
*/
|
|
57
|
+
private?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Used in GraphQL. When in GraphQL, this resolver will replace the static field.
|
|
60
|
+
*/
|
|
61
|
+
graphQLResolver?: (...args: any) => any;
|
|
62
|
+
/**
|
|
63
|
+
* Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
|
|
59
64
|
*/
|
|
60
|
-
|
|
65
|
+
key?: string;
|
|
61
66
|
}
|
|
62
|
-
/**
|
|
63
|
-
* It's the same as defining the object directly, but works better with TypeScript for type inference.
|
|
64
|
-
*/
|
|
65
|
-
export declare const asSchemaNode: <T extends SchemaNodeType>(schemaNode: SchemaNode<T>) => SchemaNode<T>;
|
|
66
|
-
export declare type Schema = SchemaRecursiveType;
|
|
67
67
|
export interface CurrentNodeInfoOptions {
|
|
68
68
|
autoConvert?: boolean;
|
|
69
69
|
filter?: boolean;
|
|
@@ -72,22 +72,22 @@ export interface CurrentNodeInfoOptions {
|
|
|
72
72
|
forceDoc?: any;
|
|
73
73
|
omitRequired?: boolean;
|
|
74
74
|
}
|
|
75
|
-
export interface CurrentNodeInfo
|
|
75
|
+
export interface CurrentNodeInfo {
|
|
76
76
|
/**
|
|
77
77
|
* The global schema, prefaced by {type: {...}} to be compatible with subschemas
|
|
78
78
|
* Sometimes it's given without {type: {...}}. TODO: Normalize this.
|
|
79
79
|
*/
|
|
80
|
-
schema?: SchemaNode
|
|
80
|
+
schema?: SchemaNode | Schema;
|
|
81
81
|
/**
|
|
82
82
|
* The current node subschema
|
|
83
83
|
*/
|
|
84
|
-
currentSchema?: Partial<SchemaNode
|
|
85
|
-
value:
|
|
86
|
-
doc?:
|
|
87
|
-
currentDoc?:
|
|
84
|
+
currentSchema?: Partial<SchemaNode>;
|
|
85
|
+
value: any;
|
|
86
|
+
doc?: any;
|
|
87
|
+
currentDoc?: any;
|
|
88
88
|
options?: CurrentNodeInfoOptions;
|
|
89
89
|
args?: any[];
|
|
90
|
-
type?: SchemaMetaFieldType
|
|
90
|
+
type?: SchemaMetaFieldType;
|
|
91
91
|
keys?: string[];
|
|
92
92
|
addError?: (keys: string[], code: string | object) => void;
|
|
93
93
|
}
|
package/lib/types/schema.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.asSchemaNode = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* It's the same as defining the object directly, but works better with TypeScript for type inference.
|
|
6
|
-
*/
|
|
7
|
-
const asSchemaNode = (schemaNode) => schemaNode;
|
|
8
|
-
exports.asSchemaNode = asSchemaNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __1 = require("..");
|
|
4
|
+
test('check ts types for schema', async () => {
|
|
5
|
+
const schema = {
|
|
6
|
+
numbers: {
|
|
7
|
+
type: [Number]
|
|
8
|
+
},
|
|
9
|
+
string: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
optional: true,
|
|
12
|
+
private: true
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const result = await (0, __1.clean)(schema, { numbers: ['2'], string: 1 });
|
|
16
|
+
expect(result).toEqual({ numbers: [2], string: '1' });
|
|
17
|
+
});
|
package/lib/validate.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Schema
|
|
2
|
-
export default function validate
|
|
1
|
+
import { Schema } from './types/schema';
|
|
2
|
+
export default function validate(schema: Schema, doc: any, passedOptions?: {}, ...args: any[]): Promise<void>;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Schema } from '..';
|
|
2
|
+
export default function (schema: Schema, path: string): any;
|
|
@@ -9,7 +9,7 @@ const dotGet = function dotGet(object, path) {
|
|
|
9
9
|
if (path === '')
|
|
10
10
|
return object;
|
|
11
11
|
const pathParts = path.split('.');
|
|
12
|
-
|
|
12
|
+
const first = pathParts.shift();
|
|
13
13
|
const remainingPath = pathParts.join('.');
|
|
14
14
|
const levelObject = object.type;
|
|
15
15
|
if (first === '$' || /^[0-9]+$/.test(first)) {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { CurrentNodeInfoOptions, Schema } from '..';
|
|
2
|
+
export default function (schema: Schema, key: string, value: any, passedOptions?: CurrentNodeInfoOptions, ...args: any[]): Promise<any>;
|
|
@@ -17,12 +17,12 @@ test('autoconvert value', async () => {
|
|
|
17
17
|
test('deep validate fields', async () => {
|
|
18
18
|
const tag = {
|
|
19
19
|
name: {
|
|
20
|
-
type:
|
|
20
|
+
type: 'string'
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
const car = {
|
|
24
24
|
brand: {
|
|
25
|
-
type:
|
|
25
|
+
type: 'string'
|
|
26
26
|
},
|
|
27
27
|
tags: {
|
|
28
28
|
type: [tag]
|
|
@@ -30,7 +30,7 @@ test('deep validate fields', async () => {
|
|
|
30
30
|
};
|
|
31
31
|
const schema = {
|
|
32
32
|
name: {
|
|
33
|
-
type:
|
|
33
|
+
type: 'string'
|
|
34
34
|
},
|
|
35
35
|
car: {
|
|
36
36
|
type: car
|
|
@@ -80,6 +80,5 @@ test('validate blackbox child', async () => {
|
|
|
80
80
|
_id: { type: 'ID' },
|
|
81
81
|
services: { type: 'blackbox' }
|
|
82
82
|
};
|
|
83
|
-
console.log('will validtea blackbox');
|
|
84
83
|
expect(await (0, index_1.default)(schema, 'services.phoneVerification.tries', 1)).toBeNull();
|
|
85
84
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/schema",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"prepare": "yarn run build",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"clean": "rm -rf ./lib",
|
|
14
|
+
"build": "yarn run clean && tsc",
|
|
15
|
+
"watch": "yarn run clean && tsc -w",
|
|
15
16
|
"test": "jest --config jest.config.js"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"@babel/preset-env": "^7.5.5",
|
|
27
28
|
"@types/eslint": "^7.28.2",
|
|
28
29
|
"@types/jest": "27.0.2",
|
|
30
|
+
"@types/lodash": "4.14.176",
|
|
29
31
|
"@types/node": "16.11.1",
|
|
30
32
|
"@typescript-eslint/eslint-plugin": "5.1.0",
|
|
31
33
|
"@typescript-eslint/parser": "5.1.0",
|
|
@@ -38,5 +40,5 @@
|
|
|
38
40
|
"publishConfig": {
|
|
39
41
|
"access": "public"
|
|
40
42
|
},
|
|
41
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "27bda585ffc16d92c70c958227605f3b61171c64"
|
|
42
44
|
}
|