@orion-js/schema 3.11.8 → 3.12.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 (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
@@ -1,2 +0,0 @@
1
- import fieldTypes from '../fieldTypes';
2
- export type FieldValidatorType = keyof typeof fieldTypes | 'custom' | 'plainObject';
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- export * from './schema';
2
- export * from './fieldValidators';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./schema"), exports);
18
- __exportStar(require("./fieldValidators"), exports);
@@ -1,118 +0,0 @@
1
- import { FieldType } from '../fieldType';
2
- export type Constructor<T> = new (...args: any[]) => T;
3
- export type Blackbox = {
4
- [name: string]: any;
5
- };
6
- export type FieldTypesList = 'string' | 'date' | 'integer' | 'number' | 'ID' | 'boolean' | 'email' | 'blackbox' | 'any';
7
- export type TypedModelOnSchema = Function;
8
- export type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date>;
9
- export type SchemaRecursiveNodeTypeExtras = {
10
- _isFieldType?: boolean;
11
- __clean?: CleanFunction;
12
- __validate?: ValidateFunction;
13
- __skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>;
14
- };
15
- export interface Schema {
16
- [key: string]: SchemaNode | Function;
17
- }
18
- export type SchemaRecursiveNodeType = Schema & SchemaRecursiveNodeTypeExtras;
19
- export type SchemaMetaFieldTypeSingle = FieldTypesList | ConstructorsTypesList | SchemaRecursiveNodeType | FieldType | TypedModelOnSchema;
20
- export type SchemaMetaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[];
21
- export type ValidateFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | void | Promise<object | string | void>;
22
- export type CleanFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => any | Promise<any>;
23
- export interface SchemaNode {
24
- /**
25
- * The type of the field. Used for type validations. Can also contain a subschema.
26
- */
27
- type: SchemaMetaFieldType;
28
- /**
29
- * Defaults to false
30
- */
31
- optional?: boolean;
32
- allowedValues?: Array<any>;
33
- defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>) | any;
34
- /**
35
- * Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
36
- */
37
- validate?: ValidateFunction;
38
- /**
39
- * Function that preprocesses a value before it is set.
40
- */
41
- clean?: CleanFunction;
42
- autoValue?: (value: any, info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>;
43
- /**
44
- * The minimum value if it's a number, the minimum length if it's a string or array.
45
- */
46
- min?: number;
47
- /**
48
- * The maximum value if it's a number, the maximum length if it's a string or array.
49
- */
50
- max?: number;
51
- /**
52
- * Internal use only.
53
- */
54
- isBlackboxChild?: boolean;
55
- /**
56
- * @deprecated
57
- */
58
- custom?: ValidateFunction;
59
- /**
60
- * Used in GraphQL. If true, the field will be omitted from the schema.
61
- */
62
- private?: boolean;
63
- /**
64
- * Used in GraphQL. When in GraphQL, this resolver will replace the static field.
65
- */
66
- graphQLResolver?: (...args: any) => any;
67
- /**
68
- * Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
69
- */
70
- key?: string;
71
- /**
72
- * The name that would be displayed in a front-end form
73
- */
74
- label?: string;
75
- /**
76
- * The description that would be displayed in a front-end form
77
- */
78
- description?: string;
79
- /**
80
- * The placeholder that would be displayed in a front-end form
81
- */
82
- placeholder?: string;
83
- /**
84
- * The field type that would be used in a front-end form
85
- */
86
- fieldType?: string;
87
- /**
88
- * The field options that will be passed as props to the front-end field
89
- */
90
- fieldOptions?: any;
91
- }
92
- export interface CurrentNodeInfoOptions {
93
- autoConvert?: boolean;
94
- filter?: boolean;
95
- trimStrings?: boolean;
96
- removeEmptyStrings?: boolean;
97
- forceDoc?: any;
98
- omitRequired?: boolean;
99
- }
100
- export interface CurrentNodeInfo {
101
- /**
102
- * The global schema, prefaced by {type: {...}} to be compatible with subschemas
103
- * Sometimes it's given without {type: {...}}. TODO: Normalize this.
104
- */
105
- schema?: SchemaNode | Schema;
106
- /**
107
- * The current node subschema
108
- */
109
- currentSchema?: Partial<SchemaNode>;
110
- value: any;
111
- doc?: any;
112
- currentDoc?: any;
113
- options?: CurrentNodeInfoOptions;
114
- args?: any[];
115
- type?: SchemaMetaFieldType;
116
- keys?: string[];
117
- addError?: (keys: string[], code: string | object) => void;
118
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/ban-types */
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- import { Schema } from './types/schema';
2
- export default function validate(schema: Schema | Function, doc: any, passedOptions?: {}, ...args: any[]): Promise<void>;
package/lib/validate.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const ValidationError_1 = __importDefault(require("./ValidationError"));
7
- const getValidationErrors_1 = __importDefault(require("./getValidationErrors"));
8
- async function validate(schema, doc, passedOptions = {}, ...args) {
9
- const validationErrors = await (0, getValidationErrors_1.default)(schema, doc, passedOptions, ...args);
10
- if (validationErrors) {
11
- throw new ValidationError_1.default(validationErrors);
12
- }
13
- }
14
- exports.default = validate;
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const validate_1 = __importDefault(require("./validate"));
7
- const schema = {
8
- firstName: {
9
- type: String
10
- },
11
- lastName: {
12
- type: String,
13
- optional: true
14
- }
15
- };
16
- const validObject = { firstName: 'Nicolás', lastName: 'López' };
17
- const invalidObject = { lastName: 'López' };
18
- test("doesn't throw any error when object is valid", async () => {
19
- await (0, validate_1.default)(schema, validObject);
20
- });
21
- test('throws validation error when object is invalid', async () => {
22
- expect.assertions(1);
23
- try {
24
- await (0, validate_1.default)(schema, invalidObject);
25
- }
26
- catch (error) {
27
- expect(error.code).toBe('validationError');
28
- }
29
- });
@@ -1,2 +0,0 @@
1
- import { Schema } from '..';
2
- export default function (schema: Schema, path: string): any;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
7
- const isNil_1 = __importDefault(require("lodash/isNil"));
8
- const dotGet = function dotGet(object, path) {
9
- if (path === '')
10
- return object;
11
- const pathParts = path.split('.');
12
- const first = pathParts.shift();
13
- const remainingPath = pathParts.join('.');
14
- const levelObject = object.type;
15
- if (first === '$' || /^[0-9]+$/.test(first)) {
16
- return dotGet({ type: levelObject[0] }, remainingPath);
17
- }
18
- else if ((0, isPlainObject_1.default)(levelObject[first])) {
19
- return dotGet(levelObject[first], remainingPath);
20
- }
21
- if (levelObject === 'blackbox') {
22
- return { type: 'blackbox', optional: true, isBlackboxChild: true };
23
- }
24
- return null;
25
- };
26
- function default_1(schema, path) {
27
- if ((0, isNil_1.default)(schema)) {
28
- throw new Error('You need to pass a schema');
29
- }
30
- return dotGet({ type: schema }, path);
31
- }
32
- exports.default = default_1;
@@ -1 +0,0 @@
1
- export {};
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const dotGetSchema_1 = __importDefault(require("./dotGetSchema"));
7
- const tag = {
8
- name: {
9
- type: String
10
- },
11
- other: {
12
- type: 'string'
13
- }
14
- };
15
- const car = {
16
- brand: {
17
- type: String
18
- },
19
- tags: {
20
- type: [tag]
21
- }
22
- };
23
- const schema = {
24
- name: {
25
- type: String
26
- },
27
- car: {
28
- type: car
29
- }
30
- };
31
- test('handle deep schemas', async () => {
32
- const value = (0, dotGetSchema_1.default)(schema, 'car.brand');
33
- expect(value).toBe(schema.car.type.brand);
34
- });
35
- test('throw error when no schema is passed', async () => {
36
- expect.assertions(1);
37
- try {
38
- (0, dotGetSchema_1.default)(null, 'car.brand');
39
- }
40
- catch (error) {
41
- expect(error.message).toBe('You need to pass a schema');
42
- }
43
- });
44
- test('handle invalid paths', async () => {
45
- const value = (0, dotGetSchema_1.default)(schema, 'car.brand.name');
46
- expect(value).toBeNull();
47
- });
48
- test('finds array first item when $ is passed', async () => {
49
- const value = (0, dotGetSchema_1.default)(schema, 'car.tags.$.name');
50
- expect(value).toBe(tag.name);
51
- });
52
- test('replaces numbers to $', async () => {
53
- expect((0, dotGetSchema_1.default)(schema, 'car.tags.0.name')).toBe(tag.name);
54
- expect((0, dotGetSchema_1.default)(schema, 'car.tags.1123.name')).toBe(tag.name);
55
- });
56
- test('returns information when is blackbox child', async () => {
57
- const schema = {
58
- services: {
59
- type: 'blackbox'
60
- }
61
- };
62
- expect((0, dotGetSchema_1.default)(schema, 'services')).toBe(schema.services);
63
- expect((0, dotGetSchema_1.default)(schema, 'services').isBlackboxChild).toBeUndefined();
64
- expect((0, dotGetSchema_1.default)(schema, 'services.phoneVerification').isBlackboxChild).toBe(true);
65
- });
@@ -1,2 +0,0 @@
1
- import { CurrentNodeInfoOptions, Schema } from '..';
2
- export default function (schema: Schema, key: string, value: any, passedOptions?: CurrentNodeInfoOptions, ...args: any[]): Promise<any>;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const dotGetSchema_1 = __importDefault(require("./dotGetSchema"));
7
- const getValidationErrors_1 = __importDefault(require("../getValidationErrors"));
8
- const Errors_1 = __importDefault(require("../Errors"));
9
- const defaultOptions = {
10
- filter: false
11
- };
12
- async function default_1(schema, key, value, passedOptions = {}, ...args) {
13
- const options = { ...defaultOptions, ...passedOptions };
14
- const keySchema = (0, dotGetSchema_1.default)(schema, key);
15
- if (!keySchema) {
16
- if (options.filter) {
17
- return Errors_1.default.NOT_IN_SCHEMA;
18
- }
19
- else {
20
- return null;
21
- }
22
- }
23
- if (keySchema.isBlackboxChild) {
24
- return null;
25
- }
26
- const result = await (0, getValidationErrors_1.default)({ validate: keySchema }, { validate: value }, options, ...args);
27
- if (!result)
28
- return null;
29
- return result.validate;
30
- }
31
- exports.default = default_1;
@@ -1 +0,0 @@
1
- export {};
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_1 = __importDefault(require("./index"));
7
- const Errors_1 = __importDefault(require("../Errors"));
8
- test('autoconvert value', async () => {
9
- const schema = {
10
- number: {
11
- type: Number
12
- }
13
- };
14
- const errors = await (0, index_1.default)(schema, 'number', '12');
15
- expect(errors).toEqual(Errors_1.default.NOT_A_NUMBER);
16
- });
17
- test('deep validate fields', async () => {
18
- const tag = {
19
- name: {
20
- type: 'string'
21
- }
22
- };
23
- const car = {
24
- brand: {
25
- type: 'string'
26
- },
27
- tags: {
28
- type: [tag]
29
- }
30
- };
31
- const schema = {
32
- name: {
33
- type: 'string'
34
- },
35
- car: {
36
- type: car
37
- }
38
- };
39
- expect(await (0, index_1.default)(schema, 'car.brand', 'Nissan')).toBeNull();
40
- expect(await (0, index_1.default)(schema, 'car.tags', 'Nice')).toBe(Errors_1.default.NOT_AN_ARRAY);
41
- expect(await (0, index_1.default)(schema, 'name', null)).toBe(Errors_1.default.REQUIRED);
42
- expect(await (0, index_1.default)(schema, 'car', null)).toBe(Errors_1.default.REQUIRED);
43
- expect(await (0, index_1.default)(schema, 'car.tags.$.name', 12)).toBe(Errors_1.default.NOT_A_STRING);
44
- expect(await (0, index_1.default)(schema, 'car.tags.100.name', 12)).toBe(Errors_1.default.NOT_A_STRING);
45
- });
46
- test('filters keys not in schema', async () => {
47
- const schema = {
48
- services: {
49
- type: 'blackbox'
50
- }
51
- };
52
- expect(await (0, index_1.default)(schema, 'person.name', 'Nicolás')).toBeNull();
53
- });
54
- test('dont filter keys not in schema if specified', async () => {
55
- const schema = {
56
- services: {
57
- type: 'blackbox'
58
- }
59
- };
60
- expect(await (0, index_1.default)(schema, 'person.name', 'Nicolás', { filter: true })).toBe(Errors_1.default.NOT_IN_SCHEMA);
61
- });
62
- test('should handle $ correctly', async () => {
63
- const Email = {
64
- address: {
65
- type: String
66
- },
67
- verified: {
68
- type: Boolean
69
- }
70
- };
71
- const user = {
72
- emails: {
73
- type: [Email]
74
- }
75
- };
76
- expect(await (0, index_1.default)(user, 'emails.$.verified', true)).toBeNull();
77
- });
78
- test('validate blackbox child', async () => {
79
- const schema = {
80
- _id: { type: 'ID' },
81
- services: { type: 'blackbox' }
82
- };
83
- expect(await (0, index_1.default)(schema, 'services.phoneVerification.tries', 1)).toBeNull();
84
- });