@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.
Files changed (36) hide show
  1. package/lib/clean/cleanType.d.ts +2 -2
  2. package/lib/clean/cleanType.js +2 -2
  3. package/lib/clean/getObjectNode.d.ts +2 -2
  4. package/lib/clean/index.test.js +9 -8
  5. package/lib/clean/recursiveClean.d.ts +2 -2
  6. package/lib/cleanKey.test.js +0 -1
  7. package/lib/fieldType.d.ts +8 -8
  8. package/lib/fieldTypes/ID.d.ts +1 -1
  9. package/lib/fieldTypes/array.d.ts +1 -2
  10. package/lib/fieldTypes/blackbox.d.ts +1 -1
  11. package/lib/fieldTypes/boolean.d.ts +1 -1
  12. package/lib/fieldTypes/date.d.ts +1 -1
  13. package/lib/fieldTypes/email.d.ts +1 -1
  14. package/lib/fieldTypes/index.d.ts +10 -10
  15. package/lib/fieldTypes/integer.d.ts +1 -1
  16. package/lib/fieldTypes/number.d.ts +1 -1
  17. package/lib/fieldTypes/plainObject.d.ts +1 -1
  18. package/lib/fieldTypes/string.d.ts +1 -1
  19. package/lib/getValidationErrors/doValidation.d.ts +2 -2
  20. package/lib/getValidationErrors/doValidation.js +4 -3
  21. package/lib/getValidationErrors/getError/getFieldType.d.ts +2 -2
  22. package/lib/getValidationErrors/getError/index.d.ts +2 -2
  23. package/lib/getValidationErrors/getError/index.js +3 -2
  24. package/lib/getValidationErrors/index.d.ts +2 -2
  25. package/lib/isValid.d.ts +2 -2
  26. package/lib/types/schema.d.ts +42 -42
  27. package/lib/types/schema.js +1 -6
  28. package/lib/types/types.test.d.ts +1 -0
  29. package/lib/types/types.test.js +17 -0
  30. package/lib/validate.d.ts +2 -2
  31. package/lib/validateKey/dotGetSchema.d.ts +2 -1
  32. package/lib/validateKey/dotGetSchema.js +1 -1
  33. package/lib/validateKey/dotGetSchema.test.js +3 -0
  34. package/lib/validateKey/index.d.ts +2 -1
  35. package/lib/validateKey/index.test.js +3 -4
  36. package/package.json +6 -4
@@ -1,3 +1,3 @@
1
- import { CurrentNodeInfo, SchemaMetaFieldType, SchemaNode, SchemaNodeType } from '../types/schema';
1
+ import { CurrentNodeInfo, SchemaMetaFieldType, SchemaNode } from '../types/schema';
2
2
  import { FieldValidatorType } from '../types/fieldValidators';
3
- export default function cleanType<T extends SchemaNodeType>(type: SchemaMetaFieldType<T> | FieldValidatorType, fieldSchema: Partial<SchemaNode<T>>, value: T, info: CurrentNodeInfo<any>, ...args: any[]): Promise<T>;
3
+ export default function cleanType(type: SchemaMetaFieldType | FieldValidatorType, fieldSchema: Partial<SchemaNode>, value: any, info: CurrentNodeInfo, ...args: any[]): Promise<any>;
@@ -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 = (await rootFieldClean(value, info, ...args));
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 = (await rootFieldClean(value, info, ...args));
45
+ value = await rootFieldClean(value, info, ...args);
46
46
  }
47
47
  return value;
48
48
  }
@@ -1,2 +1,2 @@
1
- import { SchemaNode, SchemaNodeType } from '../types/schema';
2
- export default function getObjectNode<T extends SchemaNodeType>(schema: Partial<SchemaNode<T>>, value: T | T[]): SchemaNode<object> | void;
1
+ import { SchemaNode } from '../types/schema';
2
+ export default function getObjectNode(schema: Partial<SchemaNode>, value: any): SchemaNode | void;
@@ -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: (0, schema_1.asSchemaNode)({
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: (0, schema_1.asSchemaNode)({
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: (0, schema_1.asSchemaNode)({
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, SchemaNodeType } from '../types/schema';
2
- declare const clean: <T extends SchemaNodeType>(info: CurrentNodeInfo<T, any>) => Promise<T>;
1
+ import { CurrentNodeInfo } from '../types/schema';
2
+ declare const clean: (info: CurrentNodeInfo) => Promise<any>;
3
3
  export default clean;
@@ -104,7 +104,6 @@ test('should inject doc on cleanKey', async () => {
104
104
  data: {
105
105
  type: String,
106
106
  clean(value, { doc }) {
107
- console.log(value, doc);
108
107
  expect(doc).toEqual(item);
109
108
  return value;
110
109
  }
@@ -1,13 +1,13 @@
1
- import { CleanFunction, SchemaNodeType, ValidateFunction } from './types/schema';
2
- export interface FieldTypeOpts<T extends SchemaNodeType> {
1
+ import { CleanFunction, ValidateFunction } from './types/schema';
2
+ export interface FieldTypeOpts {
3
3
  name: string;
4
- validate?: ValidateFunction<T>;
5
- clean?: CleanFunction<T>;
4
+ validate?: ValidateFunction;
5
+ clean?: CleanFunction;
6
6
  }
7
- export interface FieldType<T extends SchemaNodeType> {
7
+ export interface FieldType {
8
8
  name: string;
9
- validate: ValidateFunction<T>;
10
- clean: CleanFunction<T>;
9
+ validate: ValidateFunction;
10
+ clean: CleanFunction;
11
11
  _isFieldType: boolean;
12
12
  }
13
- export default function fieldType<T extends SchemaNodeType>(opts: FieldTypeOpts<T>): FieldType<T>;
13
+ export default function fieldType(opts: FieldTypeOpts): FieldType;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../fieldType").FieldType<string>;
1
+ declare const _default: import("../fieldType").FieldType;
2
2
  export default _default;
@@ -1,3 +1,2 @@
1
- import { SchemaNodeType } from '../types/schema';
2
- declare const _default: import("../fieldType").FieldType<SchemaNodeType>;
1
+ declare const _default: import("../fieldType").FieldType;
3
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../fieldType").FieldType<import("..").SchemaNodeType>;
1
+ declare const _default: import("../fieldType").FieldType;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../fieldType").FieldType<import("..").SchemaNodeType>;
1
+ declare const _default: import("../fieldType").FieldType;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../fieldType").FieldType<import("..").SchemaNodeType>;
1
+ declare const _default: import("../fieldType").FieldType;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../fieldType").FieldType<string>;
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<import("..").SchemaNodeType>;
3
- plainObject: import("../fieldType").FieldType<object>;
4
- string: import("../fieldType").FieldType<string>;
5
- date: import("../fieldType").FieldType<import("..").SchemaNodeType>;
6
- integer: import("../fieldType").FieldType<number>;
7
- number: import("../fieldType").FieldType<number>;
8
- ID: import("../fieldType").FieldType<string>;
9
- boolean: import("../fieldType").FieldType<import("..").SchemaNodeType>;
10
- email: import("../fieldType").FieldType<string>;
11
- blackbox: import("../fieldType").FieldType<import("..").SchemaNodeType>;
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<number>;
1
+ declare const _default: import("../fieldType").FieldType;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../fieldType").FieldType<number>;
1
+ declare const _default: import("../fieldType").FieldType;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../fieldType").FieldType<object>;
1
+ declare const _default: import("../fieldType").FieldType;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../fieldType").FieldType<string>;
1
+ declare const _default: import("../fieldType").FieldType;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- import { CurrentNodeInfo, SchemaNodeType } from '../types/schema';
2
- export default function doValidation<T extends SchemaNodeType>(params: CurrentNodeInfo<T>): Promise<void>;
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
- if (typeof currentSchema.type?.__skipChildValidation === 'function') {
28
- if (await currentSchema.type?.__skipChildValidation(value, info)) {
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, SchemaNodeType } from '../../types/schema';
1
+ import { SchemaMetaFieldType } from '../../types/schema';
2
2
  import { FieldValidatorType } from '../../types/fieldValidators';
3
3
  import { FieldType } from '../../fieldType';
4
- export default function getFieldType<T extends SchemaNodeType>(type: SchemaMetaFieldType<T> | FieldValidatorType | any): FieldType<T>;
4
+ export default function getFieldType(type: SchemaMetaFieldType | FieldValidatorType | any): FieldType;
@@ -1,2 +1,2 @@
1
- import { CurrentNodeInfo, SchemaNodeType } from '../../types/schema';
2
- export default function getValidationErrors<T extends SchemaNodeType>(params: CurrentNodeInfo<T>): Promise<object | string | void>;
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
- if (currentSchema.type.__validate) {
36
- const typeError = await currentSchema.type.__validate(value, info, ...args);
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, SchemaNodeType } from '../types/schema';
2
- export default function getValidationErrors<T extends SchemaNodeType>(schema: Schema, doc: T, passedOptions?: {}, ...args: any[]): Promise<any>;
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, SchemaNodeType } from './types/schema';
2
- export default function isValid<T extends SchemaNodeType>(schema: Schema, doc: T, passedOptions?: {}, ...args: any[]): Promise<boolean>;
1
+ import { Schema } from './types/schema';
2
+ export default function isValid(schema: Schema, doc: any, passedOptions?: {}, ...args: any[]): Promise<boolean>;
@@ -1,47 +1,40 @@
1
+ import { FieldType } from '../fieldType';
1
2
  export declare type Constructor<T> = new (...args: any[]) => T;
2
- export declare type SpecialSchemaString = 'ID' | 'email' | 'string';
3
- export declare type SpecialSchemaNumber = 'integer' | 'number';
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<any>;
7
- __validate?: ValidateFunction<any>;
6
+ __clean?: CleanFunction;
7
+ __validate?: ValidateFunction;
8
+ __skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>;
8
9
  };
9
- export declare type SchemaRecursiveType = {
10
- [key: string]: SchemaNode<SchemaNodeType> | Function;
11
- };
12
- export declare type SchemaRecursiveNodeType = SchemaRecursiveType & SchemaRecursiveNodeTypeExtras;
13
- export declare type SchemaNodeType = string | Date | number | boolean | object | SchemaNodeArrayType;
14
- export declare type SchemaNodeArrayType = Array<string> | Array<Date> | Array<number> | Array<boolean> | Array<object>;
15
- /**
16
- * Converts the SchemaNodeType to its abstraction.
17
- * E.g. if the Node has type string, it will return the String constructor.
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<T>;
22
+ type: SchemaMetaFieldType;
30
23
  /**
31
24
  * Defaults to false
32
25
  */
33
26
  optional?: boolean;
34
- allowedValues?: Array<T>;
35
- defaultValue?: T | ((info: CurrentNodeInfo<T>, ...args: any[]) => T | Promise<T>);
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<T>;
32
+ validate?: ValidateFunction;
40
33
  /**
41
34
  * Function that preprocesses a value before it is set.
42
35
  */
43
- clean?: CleanFunction<T>;
44
- autoValue?: (value: T, info: CurrentNodeInfo<T>, ...args: any[]) => T | Promise<T>;
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
- * Deprecated
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
- custom?: ValidateFunction<T>;
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<T extends SchemaNodeType, S extends SchemaNodeType = any> {
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<T> | Schema;
80
+ schema?: SchemaNode | Schema;
81
81
  /**
82
82
  * The current node subschema
83
83
  */
84
- currentSchema?: Partial<SchemaNode<S>>;
85
- value: T;
86
- doc?: T;
87
- currentDoc?: T;
84
+ currentSchema?: Partial<SchemaNode>;
85
+ value: any;
86
+ doc?: any;
87
+ currentDoc?: any;
88
88
  options?: CurrentNodeInfoOptions;
89
89
  args?: any[];
90
- type?: SchemaMetaFieldType<T>;
90
+ type?: SchemaMetaFieldType;
91
91
  keys?: string[];
92
92
  addError?: (keys: string[], code: string | object) => void;
93
93
  }
@@ -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, SchemaNodeType } from './types/schema';
2
- export default function validate<T extends SchemaNodeType>(schema: Schema, doc: T, passedOptions?: {}, ...args: any[]): Promise<void>;
1
+ import { Schema } from './types/schema';
2
+ export default function validate(schema: Schema, doc: any, passedOptions?: {}, ...args: any[]): Promise<void>;
@@ -1 +1,2 @@
1
- export default function (schema: any, path: any): any;
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
- let first = pathParts.shift();
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)) {
@@ -7,6 +7,9 @@ const dotGetSchema_1 = __importDefault(require("./dotGetSchema"));
7
7
  const tag = {
8
8
  name: {
9
9
  type: String
10
+ },
11
+ other: {
12
+ type: 'string'
10
13
  }
11
14
  };
12
15
  const car = {
@@ -1 +1,2 @@
1
- export default function (schema: any, key: any, value: any, passedOptions?: {}, ...args: any[]): Promise<any>;
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: String
20
+ type: 'string'
21
21
  }
22
22
  };
23
23
  const car = {
24
24
  brand: {
25
- type: String
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: String
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-alpha.11",
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
- "build": "tsc",
14
- "watch": "tsc -w",
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": "7f7fb73a75f6f233c7a868ae0dda870fb70fe7c3"
43
+ "gitHead": "27bda585ffc16d92c70c958227605f3b61171c64"
42
44
  }