@datacapy/schema 0.1.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 (184) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +113 -0
  3. package/dist/builder/builder-array.d.ts +11 -0
  4. package/dist/builder/builder-array.js +35 -0
  5. package/dist/builder/builder-array.js.map +1 -0
  6. package/dist/builder/builder-base.d.ts +25 -0
  7. package/dist/builder/builder-base.js +140 -0
  8. package/dist/builder/builder-base.js.map +1 -0
  9. package/dist/builder/builder-boolean.d.ts +5 -0
  10. package/dist/builder/builder-boolean.js +12 -0
  11. package/dist/builder/builder-boolean.js.map +1 -0
  12. package/dist/builder/builder-date.d.ts +5 -0
  13. package/dist/builder/builder-date.js +12 -0
  14. package/dist/builder/builder-date.js.map +1 -0
  15. package/dist/builder/builder-mixed.d.ts +7 -0
  16. package/dist/builder/builder-mixed.js +16 -0
  17. package/dist/builder/builder-mixed.js.map +1 -0
  18. package/dist/builder/builder-number.d.ts +5 -0
  19. package/dist/builder/builder-number.js +12 -0
  20. package/dist/builder/builder-number.js.map +1 -0
  21. package/dist/builder/builder-object.d.ts +17 -0
  22. package/dist/builder/builder-object.js +47 -0
  23. package/dist/builder/builder-object.js.map +1 -0
  24. package/dist/builder/builder-or.d.ts +9 -0
  25. package/dist/builder/builder-or.js +23 -0
  26. package/dist/builder/builder-or.js.map +1 -0
  27. package/dist/builder/builder-schema.d.ts +18 -0
  28. package/dist/builder/builder-schema.js +68 -0
  29. package/dist/builder/builder-schema.js.map +1 -0
  30. package/dist/builder/builder-string.d.ts +17 -0
  31. package/dist/builder/builder-string.js +106 -0
  32. package/dist/builder/builder-string.js.map +1 -0
  33. package/dist/builder/index.d.ts +14 -0
  34. package/dist/builder/index.js +28 -0
  35. package/dist/builder/index.js.map +1 -0
  36. package/dist/builder/schema-builder.d.ts +25 -0
  37. package/dist/builder/schema-builder.js +46 -0
  38. package/dist/builder/schema-builder.js.map +1 -0
  39. package/dist/config.d.ts +17 -0
  40. package/dist/config.js +3 -0
  41. package/dist/config.js.map +1 -0
  42. package/dist/encryption/encryption-service.d.ts +4 -0
  43. package/dist/encryption/encryption-service.js +3 -0
  44. package/dist/encryption/encryption-service.js.map +1 -0
  45. package/dist/encryption/index.d.ts +1 -0
  46. package/dist/encryption/index.js +18 -0
  47. package/dist/encryption/index.js.map +1 -0
  48. package/dist/filter/filter-abstract.d.ts +9 -0
  49. package/dist/filter/filter-abstract.js +11 -0
  50. package/dist/filter/filter-abstract.js.map +1 -0
  51. package/dist/filter/filter-callback.d.ts +6 -0
  52. package/dist/filter/filter-callback.js +18 -0
  53. package/dist/filter/filter-callback.js.map +1 -0
  54. package/dist/filter/filter-condition.d.ts +8 -0
  55. package/dist/filter/filter-condition.js +15 -0
  56. package/dist/filter/filter-condition.js.map +1 -0
  57. package/dist/filter/filter-default-value.d.ts +10 -0
  58. package/dist/filter/filter-default-value.js +29 -0
  59. package/dist/filter/filter-default-value.js.map +1 -0
  60. package/dist/filter/filter-lowercase.d.ts +6 -0
  61. package/dist/filter/filter-lowercase.js +17 -0
  62. package/dist/filter/filter-lowercase.js.map +1 -0
  63. package/dist/filter/filter-postcode.d.ts +7 -0
  64. package/dist/filter/filter-postcode.js +30 -0
  65. package/dist/filter/filter-postcode.js.map +1 -0
  66. package/dist/filter/filter-prepend-http.d.ts +6 -0
  67. package/dist/filter/filter-prepend-http.js +17 -0
  68. package/dist/filter/filter-prepend-http.js.map +1 -0
  69. package/dist/filter/filter-strip-html.d.ts +13 -0
  70. package/dist/filter/filter-strip-html.js +96 -0
  71. package/dist/filter/filter-strip-html.js.map +1 -0
  72. package/dist/filter/filter-trim.d.ts +6 -0
  73. package/dist/filter/filter-trim.js +17 -0
  74. package/dist/filter/filter-trim.js.map +1 -0
  75. package/dist/filter/filter-uppercase.d.ts +6 -0
  76. package/dist/filter/filter-uppercase.js +17 -0
  77. package/dist/filter/filter-uppercase.js.map +1 -0
  78. package/dist/filter/filter.d.ts +7 -0
  79. package/dist/filter/filter.js +59 -0
  80. package/dist/filter/filter.js.map +1 -0
  81. package/dist/filter/index.d.ts +9 -0
  82. package/dist/filter/index.js +26 -0
  83. package/dist/filter/index.js.map +1 -0
  84. package/dist/index.d.ts +18 -0
  85. package/dist/index.js +39 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/inquisitor.d.ts +9 -0
  88. package/dist/inquisitor.js +44 -0
  89. package/dist/inquisitor.js.map +1 -0
  90. package/dist/iterator.d.ts +70 -0
  91. package/dist/iterator.js +339 -0
  92. package/dist/iterator.js.map +1 -0
  93. package/dist/manager.d.ts +30 -0
  94. package/dist/manager.js +55 -0
  95. package/dist/manager.js.map +1 -0
  96. package/dist/processors/field-filter.d.ts +32 -0
  97. package/dist/processors/field-filter.js +114 -0
  98. package/dist/processors/field-filter.js.map +1 -0
  99. package/dist/processors/field-private-filter.d.ts +9 -0
  100. package/dist/processors/field-private-filter.js +84 -0
  101. package/dist/processors/field-private-filter.js.map +1 -0
  102. package/dist/processors/field-type-caster.d.ts +12 -0
  103. package/dist/processors/field-type-caster.js +89 -0
  104. package/dist/processors/field-type-caster.js.map +1 -0
  105. package/dist/processors/field-validator.d.ts +36 -0
  106. package/dist/processors/field-validator.js +171 -0
  107. package/dist/processors/field-validator.js.map +1 -0
  108. package/dist/processors/index.d.ts +5 -0
  109. package/dist/processors/index.js +22 -0
  110. package/dist/processors/index.js.map +1 -0
  111. package/dist/processors/transient-processor.d.ts +23 -0
  112. package/dist/processors/transient-processor.js +124 -0
  113. package/dist/processors/transient-processor.js.map +1 -0
  114. package/dist/schema.d.ts +104 -0
  115. package/dist/schema.js +400 -0
  116. package/dist/schema.js.map +1 -0
  117. package/dist/spec.d.ts +69 -0
  118. package/dist/spec.js +3 -0
  119. package/dist/spec.js.map +1 -0
  120. package/dist/type/PropsOf.d.ts +5 -0
  121. package/dist/type/PropsOf.js +3 -0
  122. package/dist/type/PropsOf.js.map +1 -0
  123. package/dist/type/index.d.ts +1 -0
  124. package/dist/type/index.js +18 -0
  125. package/dist/type/index.js.map +1 -0
  126. package/dist/types.d.ts +13 -0
  127. package/dist/types.js +21 -0
  128. package/dist/types.js.map +1 -0
  129. package/dist/utilities/collection.d.ts +10 -0
  130. package/dist/utilities/collection.js +41 -0
  131. package/dist/utilities/collection.js.map +1 -0
  132. package/dist/utilities/index.d.ts +4 -0
  133. package/dist/utilities/index.js +21 -0
  134. package/dist/utilities/index.js.map +1 -0
  135. package/dist/utilities/object-path-accessor.d.ts +16 -0
  136. package/dist/utilities/object-path-accessor.js +132 -0
  137. package/dist/utilities/object-path-accessor.js.map +1 -0
  138. package/dist/utilities/type-caster.d.ts +10 -0
  139. package/dist/utilities/type-caster.js +126 -0
  140. package/dist/utilities/type-caster.js.map +1 -0
  141. package/dist/utilities/utility.d.ts +8 -0
  142. package/dist/utilities/utility.js +53 -0
  143. package/dist/utilities/utility.js.map +1 -0
  144. package/dist/validator/index.d.ts +12 -0
  145. package/dist/validator/index.js +29 -0
  146. package/dist/validator/index.js.map +1 -0
  147. package/dist/validator/validator-callback.d.ts +6 -0
  148. package/dist/validator/validator-callback.js +15 -0
  149. package/dist/validator/validator-callback.js.map +1 -0
  150. package/dist/validator/validator-email.d.ts +5 -0
  151. package/dist/validator/validator-email.js +20 -0
  152. package/dist/validator/validator-email.js.map +1 -0
  153. package/dist/validator/validator-equality.d.ts +5 -0
  154. package/dist/validator/validator-equality.js +19 -0
  155. package/dist/validator/validator-equality.js.map +1 -0
  156. package/dist/validator/validator-in-array.d.ts +5 -0
  157. package/dist/validator/validator-in-array.js +17 -0
  158. package/dist/validator/validator-in-array.js.map +1 -0
  159. package/dist/validator/validator-interface.d.ts +5 -0
  160. package/dist/validator/validator-interface.js +3 -0
  161. package/dist/validator/validator-interface.js.map +1 -0
  162. package/dist/validator/validator-is-empty.d.ts +5 -0
  163. package/dist/validator/validator-is-empty.js +37 -0
  164. package/dist/validator/validator-is-empty.js.map +1 -0
  165. package/dist/validator/validator-not-empty.d.ts +5 -0
  166. package/dist/validator/validator-not-empty.js +21 -0
  167. package/dist/validator/validator-not-empty.js.map +1 -0
  168. package/dist/validator/validator-not-null.d.ts +5 -0
  169. package/dist/validator/validator-not-null.js +19 -0
  170. package/dist/validator/validator-not-null.js.map +1 -0
  171. package/dist/validator/validator-regex.d.ts +5 -0
  172. package/dist/validator/validator-regex.js +20 -0
  173. package/dist/validator/validator-regex.js.map +1 -0
  174. package/dist/validator/validator-required.d.ts +5 -0
  175. package/dist/validator/validator-required.js +18 -0
  176. package/dist/validator/validator-required.js.map +1 -0
  177. package/dist/validator/validator-value-length.d.ts +5 -0
  178. package/dist/validator/validator-value-length.js +39 -0
  179. package/dist/validator/validator-value-length.js.map +1 -0
  180. package/dist/validator/validator.d.ts +7 -0
  181. package/dist/validator/validator.js +72 -0
  182. package/dist/validator/validator.js.map +1 -0
  183. package/package.json +51 -0
  184. package/tsconfig.json +26 -0
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2016, Kevin Foster
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # @datacapy/schema
2
+
3
+ Data schemas for JavaScript and TypeScript. Define the shape of your data once,
4
+ then use the schema to type-cast, filter, validate, hide private fields and
5
+ encrypt sensitive fields.
6
+
7
+ - **Fluent builder** (`sb`) for defining schemas, with an equivalent
8
+ plain-object spec underneath
9
+ - **Validation**: required, length, regex, email, allowed values, custom sync or
10
+ async rules, per-rule messages
11
+ - **Type-casting**: `'33'` becomes `33`, `'true'` becomes `true`, and values
12
+ that cannot be cast become validation errors
13
+ - **Filtering**: defaults, trimming, case, HTML stripping, conditional and
14
+ custom filters
15
+ - **Private fields**: strip or mask fields per read or write mode
16
+ - **Field encryption**: mark fields for at-rest encryption using your own
17
+ encryption service
18
+ - **Composition**: nested objects, arrays, named schema references, `$or`
19
+ alternatives, dynamic keys, class constructors
20
+ - **Query validation**: cast and validate the values in a MongoDB-style query
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install @datacapy/schema
26
+ ```
27
+
28
+ ## Quick start
29
+
30
+ ```ts
31
+ import { Schema, sb } from '@datacapy/schema'
32
+
33
+ const personSchema = new Schema(
34
+ sb
35
+ .schema('person')
36
+ .strict()
37
+ .shape({
38
+ _id: sb.string(),
39
+ name: sb.string().label('Name').required().trim().length(2, 50),
40
+ email: sb.string().email().lowercase(),
41
+ age: sb.number(),
42
+ tel: sb
43
+ .string()
44
+ .regex(/^[+0-9]+$/, { message: 'Tel must contain digits only' })
45
+ .regex(/^\+/, {
46
+ message: 'Tel must start with a country code (e.g. +44)',
47
+ }),
48
+ createdAt: sb.date().default('now'),
49
+ address: sb.object({
50
+ city: sb.string().required(),
51
+ postcode: sb.string().uppercase(),
52
+ }),
53
+ })
54
+ .build()
55
+ )
56
+
57
+ const paul = {
58
+ name: ' Paul ',
59
+ email: 'Paul@Example.COM',
60
+ age: '33',
61
+ tel: '0123456789',
62
+ address: { city: 'Liverpool', postcode: 'l1 8jq' },
63
+ }
64
+
65
+ const { isValid, errors } = await personSchema.validate(paul)
66
+
67
+ isValid // false
68
+ errors // { tel: ['Tel must start with a country code (e.g. +44)'] }
69
+ ```
70
+
71
+ `validate()` also **modifies the object in place**: it casts, applies filters
72
+ and fills defaults, whether or not the data is valid. After the call above
73
+ `paul` is:
74
+
75
+ ```ts
76
+ {
77
+ name: 'Paul',
78
+ email: 'paul@example.com',
79
+ age: 33,
80
+ tel: '0123456789',
81
+ address: { city: 'Liverpool', postcode: 'L1 8JQ' },
82
+ _id: 'ecrDWdCQCiXSrf6', // generated: a String field named _id defaults to @datacapy/id
83
+ createdAt: 2026-09-21T17:32:34.279Z,
84
+ }
85
+ ```
86
+
87
+ Validate a clone if you need to keep the input untouched.
88
+
89
+ ## Guides
90
+
91
+ | Guide | Covers |
92
+ | ---------------------------------- | -------------------------------------------------------------------------------------------- |
93
+ | [Builder](docs/builder.md) | Every builder and method, `.build()`, the equivalent plain spec, `$` option reference |
94
+ | [Validation](docs/validation.md) | Rules, error messages, result shape, strict mode, casting, partial-path and query validation |
95
+ | [Filtering](docs/filtering.md) | Defaults, string filters, conditional and custom filters, private fields |
96
+ | [Encryption](docs/encryption.md) | Marking fields, the encryption service interface, encrypting and decrypting |
97
+ | [Composition](docs/composition.md) | Schema references, arrays, `$or`, dynamic keys, constructors, relations |
98
+
99
+ ## Plain-object specs
100
+
101
+ The builder produces a plain object, and `new Schema()` accepts one directly.
102
+ Both are supported and interchangeable; the guides use the builder. See
103
+ [Builder](docs/builder.md#the-plain-spec-form) for the mapping.
104
+
105
+ ## Related packages
106
+
107
+ - [`@datacapy/id`](../id/README.md) generates the default `_id` values.
108
+ - [`@datacapy/om`](../om/README.md) uses `@datacapy/schema` for repository
109
+ validation, private-field filtering and field encryption.
110
+
111
+ ## Licence
112
+
113
+ [BSD 3-Clause](LICENSE)
@@ -0,0 +1,11 @@
1
+ import { BuilderBase } from './builder-base';
2
+ import SchemaSpec from '../spec';
3
+ export declare class BuilderArray<T = any> extends BuilderBase<T[]> {
4
+ constructor(itemSpec?: SchemaSpec | BuilderBase<any>);
5
+ protected getType(): ArrayConstructor;
6
+ of(itemSpec: SchemaSpec | BuilderBase<any>): this;
7
+ ofSchema(schemaName: string): this;
8
+ construct(constructorName: string | Function): this;
9
+ constructCollection(constructorName: string | Function): this;
10
+ }
11
+ export default BuilderArray;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuilderArray = void 0;
4
+ const builder_base_1 = require("./builder-base");
5
+ class BuilderArray extends builder_base_1.BuilderBase {
6
+ constructor(itemSpec) {
7
+ super();
8
+ if (itemSpec !== undefined) {
9
+ this.of(itemSpec);
10
+ }
11
+ }
12
+ getType() {
13
+ return Array;
14
+ }
15
+ of(itemSpec) {
16
+ const spec = itemSpec instanceof builder_base_1.BuilderBase ? itemSpec.build() : itemSpec;
17
+ this.spec.$spec = spec;
18
+ return this;
19
+ }
20
+ ofSchema(schemaName) {
21
+ this.spec.$spec = { $schema: schemaName };
22
+ return this;
23
+ }
24
+ construct(constructorName) {
25
+ this.spec.$construct = constructorName;
26
+ return this;
27
+ }
28
+ constructCollection(constructorName) {
29
+ this.spec.$constructCollection = constructorName;
30
+ return this;
31
+ }
32
+ }
33
+ exports.BuilderArray = BuilderArray;
34
+ exports.default = BuilderArray;
35
+ //# sourceMappingURL=builder-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-array.js","sourceRoot":"","sources":["../../src/builder/builder-array.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAO5C,MAAa,YAAsB,SAAQ,0BAAgB;IACzD,YAAY,QAAwC;QAClD,KAAK,EAAE,CAAA;QACP,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;IAES,OAAO;QACf,OAAO,KAAK,CAAA;IACd,CAAC;IAMD,EAAE,CAAC,QAAuC;QACxC,MAAM,IAAI,GAAG,QAAQ,YAAY,0BAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAA;QAC1E,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;IAMD,QAAQ,CAAC,UAAkB;QACzB,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,CAAA;QACzC,OAAO,IAAI,CAAA;IACb,CAAC;IAKD,SAAS,CAAC,eAAkC;QAC1C,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,eAAe,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAKD,mBAAmB,CAAC,eAAkC;QACpD,IAAI,CAAC,IAAI,CAAC,oBAAoB,GAAG,eAAe,CAAA;QAChD,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA9CD,oCA8CC;AAED,kBAAe,YAAY,CAAA"}
@@ -0,0 +1,25 @@
1
+ import SchemaSpec, { SchemaSpecValidateOptions, CustomValidatorFn } from '../spec';
2
+ import { FilterConditionSpec } from '../filter/filter-condition';
3
+ export declare abstract class BuilderBase<T = any> {
4
+ protected spec: SchemaSpec;
5
+ protected abstract getType(): any;
6
+ required(options?: SchemaSpecValidateOptions): this;
7
+ notNull(options?: SchemaSpecValidateOptions): this;
8
+ notEmpty(options?: SchemaSpecValidateOptions): this;
9
+ isEmpty(options?: SchemaSpecValidateOptions): this;
10
+ validate(validator: CustomValidatorFn, options?: SchemaSpecValidateOptions): this;
11
+ default(value: any): this;
12
+ private(mode?: boolean | string): this;
13
+ privateValue(mode?: boolean | string): this;
14
+ encrypt(mode?: boolean): this;
15
+ filter(fn: (value: any) => boolean | string): this;
16
+ filterIf(filterName: string, condition: FilterConditionSpec, filterConfig?: any): this;
17
+ label(label: string): this;
18
+ nullable(): this;
19
+ noCast(value?: boolean): this;
20
+ relation(value?: boolean): this;
21
+ private static buildValue;
22
+ build(): SchemaSpec;
23
+ protected getSpec(): SchemaSpec;
24
+ }
25
+ export default BuilderBase;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuilderBase = void 0;
4
+ class BuilderBase {
5
+ constructor() {
6
+ this.spec = {};
7
+ }
8
+ required(options) {
9
+ if (!this.spec.$validate)
10
+ this.spec.$validate = {};
11
+ this.spec.$validate.required = options || true;
12
+ return this;
13
+ }
14
+ notNull(options) {
15
+ if (!this.spec.$validate)
16
+ this.spec.$validate = {};
17
+ this.spec.$validate.notNull = options || true;
18
+ return this;
19
+ }
20
+ notEmpty(options) {
21
+ if (!this.spec.$validate)
22
+ this.spec.$validate = {};
23
+ this.spec.$validate.notEmpty = options || true;
24
+ return this;
25
+ }
26
+ isEmpty(options) {
27
+ if (!this.spec.$validate)
28
+ this.spec.$validate = {};
29
+ this.spec.$validate.isEmpty = options || true;
30
+ return this;
31
+ }
32
+ validate(validator, options) {
33
+ if (!this.spec.$validate)
34
+ this.spec.$validate = {};
35
+ const customConfig = { validator, ...options };
36
+ if (this.spec.$validate.callback) {
37
+ if (Array.isArray(this.spec.$validate.callback)) {
38
+ this.spec.$validate.callback.push(customConfig);
39
+ }
40
+ else {
41
+ this.spec.$validate.callback = [
42
+ this.spec.$validate.callback,
43
+ customConfig,
44
+ ];
45
+ }
46
+ }
47
+ else {
48
+ this.spec.$validate.callback = customConfig;
49
+ }
50
+ return this;
51
+ }
52
+ default(value) {
53
+ if (!this.spec.$filter)
54
+ this.spec.$filter = {};
55
+ this.spec.$filter.defaultValue = value;
56
+ return this;
57
+ }
58
+ private(mode) {
59
+ if (!this.spec.$filter)
60
+ this.spec.$filter = {};
61
+ this.spec.$filter.private = mode === undefined ? true : mode;
62
+ return this;
63
+ }
64
+ privateValue(mode) {
65
+ if (!this.spec.$filter)
66
+ this.spec.$filter = {};
67
+ this.spec.$filter.privateValue = mode === undefined ? true : mode;
68
+ return this;
69
+ }
70
+ encrypt(mode) {
71
+ if (!this.spec.$filter)
72
+ this.spec.$filter = {};
73
+ this.spec.$filter.encrypt = mode === undefined ? true : mode;
74
+ return this;
75
+ }
76
+ filter(fn) {
77
+ if (!this.spec.$filter)
78
+ this.spec.$filter = {};
79
+ this.spec.$filter.callback = fn;
80
+ return this;
81
+ }
82
+ filterIf(filterName, condition, filterConfig) {
83
+ if (!this.spec.$filter)
84
+ this.spec.$filter = {};
85
+ this.spec.$filter[filterName] = {
86
+ $if: condition,
87
+ ...(filterConfig !== undefined ? { $then: filterConfig } : {}),
88
+ };
89
+ return this;
90
+ }
91
+ label(label) {
92
+ this.spec.$label = label;
93
+ return this;
94
+ }
95
+ nullable() {
96
+ this.spec.$nullable = true;
97
+ return this;
98
+ }
99
+ noCast(value = true) {
100
+ this.spec.$noCast = value;
101
+ return this;
102
+ }
103
+ relation(value = true) {
104
+ this.spec.$relation = value;
105
+ return this;
106
+ }
107
+ static buildValue(value) {
108
+ if (value instanceof BuilderBase) {
109
+ return value.build();
110
+ }
111
+ if (Array.isArray(value)) {
112
+ return value.map((item) => BuilderBase.buildValue(item));
113
+ }
114
+ if (value && typeof value === 'object' && value.constructor === Object) {
115
+ const result = {};
116
+ for (const key in value) {
117
+ result[key] = BuilderBase.buildValue(value[key]);
118
+ }
119
+ return result;
120
+ }
121
+ return value;
122
+ }
123
+ build() {
124
+ const type = this.getType();
125
+ const builtSpec = {};
126
+ for (const key in this.spec) {
127
+ builtSpec[key] = BuilderBase.buildValue(this.spec[key]);
128
+ }
129
+ return {
130
+ ...builtSpec,
131
+ ...(type !== undefined && { $type: type }),
132
+ };
133
+ }
134
+ getSpec() {
135
+ return this.spec;
136
+ }
137
+ }
138
+ exports.BuilderBase = BuilderBase;
139
+ exports.default = BuilderBase;
140
+ //# sourceMappingURL=builder-base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-base.js","sourceRoot":"","sources":["../../src/builder/builder-base.ts"],"names":[],"mappings":";;;AAYA,MAAsB,WAAW;IAAjC;QACY,SAAI,GAAe,EAAE,CAAA;IA0OjC,CAAC;IA9NC,QAAQ,CAAC,OAAmC;QAC1C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;QAClD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,OAAO,IAAI,IAAI,CAAA;QAC9C,OAAO,IAAI,CAAA;IACb,CAAC;IAKD,OAAO,CAAC,OAAmC;QACzC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;QAClD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,OAAO,IAAI,IAAI,CAAA;QAC7C,OAAO,IAAI,CAAA;IACb,CAAC;IAKD,QAAQ,CAAC,OAAmC;QAC1C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;QAClD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,OAAO,IAAI,IAAI,CAAA;QAC9C,OAAO,IAAI,CAAA;IACb,CAAC;IAKD,OAAO,CAAC,OAAmC;QACzC,IAA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CAAC,GAAG,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;YAClD,CAAC;YACD,OAAO,MAAM,CAAA;QACf,CAAC;QAGD,OAAO,KAAK,CAAA;IACd,CAAC;IAKD,KAAK;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAC3B,MAAM,SAAS,GAAe,EAAE,CAAA;QAGhC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QACzD,CAAC;QAED,OAAO;YACL,GAAG,SAAS;YACZ,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SAC3C,CAAA;IACH,CAAC;IAKS,OAAO;QACf,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;CACF;AA3OD,kCA2OC;AAED,kBAAe,WAAW,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { BuilderBase } from './builder-base';
2
+ export declare class BuilderBoolean extends BuilderBase<boolean> {
3
+ protected getType(): BooleanConstructor;
4
+ }
5
+ export default BuilderBoolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuilderBoolean = void 0;
4
+ const builder_base_1 = require("./builder-base");
5
+ class BuilderBoolean extends builder_base_1.BuilderBase {
6
+ getType() {
7
+ return Boolean;
8
+ }
9
+ }
10
+ exports.BuilderBoolean = BuilderBoolean;
11
+ exports.default = BuilderBoolean;
12
+ //# sourceMappingURL=builder-boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-boolean.js","sourceRoot":"","sources":["../../src/builder/builder-boolean.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAK5C,MAAa,cAAe,SAAQ,0BAAoB;IAC5C,OAAO;QACf,OAAO,OAAO,CAAA;IAChB,CAAC;CAIF;AAPD,wCAOC;AAED,kBAAe,cAAc,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { BuilderBase } from './builder-base';
2
+ export declare class BuilderDate extends BuilderBase<Date> {
3
+ protected getType(): DateConstructor;
4
+ }
5
+ export default BuilderDate;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuilderDate = void 0;
4
+ const builder_base_1 = require("./builder-base");
5
+ class BuilderDate extends builder_base_1.BuilderBase {
6
+ getType() {
7
+ return Date;
8
+ }
9
+ }
10
+ exports.BuilderDate = BuilderDate;
11
+ exports.default = BuilderDate;
12
+ //# sourceMappingURL=builder-date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-date.js","sourceRoot":"","sources":["../../src/builder/builder-date.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAK5C,MAAa,WAAY,SAAQ,0BAAiB;IACtC,OAAO;QACf,OAAO,IAAI,CAAA;IACb,CAAC;CAKF;AARD,kCAQC;AAED,kBAAe,WAAW,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { BuilderBase } from './builder-base';
2
+ export declare class BuilderMixed extends BuilderBase<any> {
3
+ protected getType(): {
4
+ new (): {};
5
+ };
6
+ }
7
+ export default BuilderMixed;
@@ -0,0 +1,16 @@
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
+ exports.BuilderMixed = void 0;
7
+ const builder_base_1 = require("./builder-base");
8
+ const types_1 = __importDefault(require("../types"));
9
+ class BuilderMixed extends builder_base_1.BuilderBase {
10
+ getType() {
11
+ return types_1.default.Mixed;
12
+ }
13
+ }
14
+ exports.BuilderMixed = BuilderMixed;
15
+ exports.default = BuilderMixed;
16
+ //# sourceMappingURL=builder-mixed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-mixed.js","sourceRoot":"","sources":["../../src/builder/builder-mixed.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA4C;AAC5C,qDAAkC;AAMlC,MAAa,YAAa,SAAQ,0BAAgB;IACtC,OAAO;QACf,OAAO,eAAW,CAAC,KAAK,CAAA;IAC1B,CAAC;CACF;AAJD,oCAIC;AAED,kBAAe,YAAY,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { BuilderBase } from './builder-base';
2
+ export declare class BuilderNumber extends BuilderBase<number> {
3
+ protected getType(): NumberConstructor;
4
+ }
5
+ export default BuilderNumber;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuilderNumber = void 0;
4
+ const builder_base_1 = require("./builder-base");
5
+ class BuilderNumber extends builder_base_1.BuilderBase {
6
+ getType() {
7
+ return Number;
8
+ }
9
+ }
10
+ exports.BuilderNumber = BuilderNumber;
11
+ exports.default = BuilderNumber;
12
+ //# sourceMappingURL=builder-number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-number.js","sourceRoot":"","sources":["../../src/builder/builder-number.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAM5C,MAAa,aAAc,SAAQ,0BAAmB;IAC1C,OAAO;QACf,OAAO,MAAM,CAAA;IACf,CAAC;CAMF;AATD,sCASC;AAED,kBAAe,aAAa,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { BuilderBase } from './builder-base';
2
+ import SchemaSpec from '../spec';
3
+ export declare class BuilderObject<T extends object = any> extends BuilderBase<T> {
4
+ constructor(shape?: {
5
+ [K in keyof T]?: SchemaSpec | BuilderBase<any>;
6
+ });
7
+ protected getType(): ObjectConstructor;
8
+ shape(fields: {
9
+ [K in keyof T]?: SchemaSpec | BuilderBase<any>;
10
+ }): this;
11
+ matchAll(fieldSpec: SchemaSpec | BuilderBase<any>): this;
12
+ schema(schemaName: string): this;
13
+ strict(value?: boolean): this;
14
+ construct(constructorName: string | Function): this;
15
+ constructCollection(constructorName: string | Function): this;
16
+ }
17
+ export default BuilderObject;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuilderObject = void 0;
4
+ const builder_base_1 = require("./builder-base");
5
+ class BuilderObject extends builder_base_1.BuilderBase {
6
+ constructor(shape) {
7
+ super();
8
+ if (shape) {
9
+ this.shape(shape);
10
+ }
11
+ }
12
+ getType() {
13
+ return Object;
14
+ }
15
+ shape(fields) {
16
+ Object.entries(fields).forEach(([key, value]) => {
17
+ if (value !== undefined) {
18
+ this.spec[key] = value instanceof builder_base_1.BuilderBase ? value.build() : value;
19
+ }
20
+ });
21
+ return this;
22
+ }
23
+ matchAll(fieldSpec) {
24
+ const spec = fieldSpec instanceof builder_base_1.BuilderBase ? fieldSpec.build() : fieldSpec;
25
+ this.spec['*'] = spec;
26
+ return this;
27
+ }
28
+ schema(schemaName) {
29
+ this.spec.$schema = schemaName;
30
+ return this;
31
+ }
32
+ strict(value = true) {
33
+ this.spec.$strict = value;
34
+ return this;
35
+ }
36
+ construct(constructorName) {
37
+ this.spec.$construct = constructorName;
38
+ return this;
39
+ }
40
+ constructCollection(constructorName) {
41
+ this.spec.$constructCollection = constructorName;
42
+ return this;
43
+ }
44
+ }
45
+ exports.BuilderObject = BuilderObject;
46
+ exports.default = BuilderObject;
47
+ //# sourceMappingURL=builder-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-object.js","sourceRoot":"","sources":["../../src/builder/builder-object.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAO5C,MAAa,aAAsC,SAAQ,0BAAc;IACvE,YAAY,KAEX;QACC,KAAK,EAAE,CAAA;QACP,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;IAES,OAAO;QACf,OAAO,MAAM,CAAA;IACf,CAAC;IAMD,KAAK,CAAC,MAEL;QACC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC9C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,YAAY,0BAAW,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;YACvE,CAAC;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAMD,QAAQ,CAAC,SAAwC;QAC/C,MAAM,IAAI,GACR,SAAS,YAAY,0BAAW,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;QAClE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAMD,MAAM,CAAC,UAAkB;QACvB,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;IAMD,MAAM,CAAC,QAAiB,IAAI;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IAKD,SAAS,CAAC,eAAkC;QAC1C,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,eAAe,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAKD,mBAAmB,CAAC,eAAkC;QACpD,IAAI,CAAC,IAAI,CAAC,oBAAoB,GAAG,eAAe,CAAA;QAChD,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAzED,sCAyEC;AAED,kBAAe,aAAa,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { BuilderBase } from './builder-base';
2
+ import SchemaSpec from '../spec';
3
+ export declare class BuilderOr extends BuilderBase<any> {
4
+ private orSpecs;
5
+ constructor(specs: Array<SchemaSpec | BuilderBase<any>>);
6
+ protected getType(): any;
7
+ build(): SchemaSpec;
8
+ }
9
+ export default BuilderOr;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuilderOr = void 0;
4
+ const builder_base_1 = require("./builder-base");
5
+ class BuilderOr extends builder_base_1.BuilderBase {
6
+ constructor(specs) {
7
+ super();
8
+ this.orSpecs = [];
9
+ this.orSpecs = specs;
10
+ }
11
+ getType() {
12
+ return undefined;
13
+ }
14
+ build() {
15
+ return {
16
+ ...this.spec,
17
+ $or: this.orSpecs.map((spec) => spec instanceof builder_base_1.BuilderBase ? spec.build() : spec),
18
+ };
19
+ }
20
+ }
21
+ exports.BuilderOr = BuilderOr;
22
+ exports.default = BuilderOr;
23
+ //# sourceMappingURL=builder-or.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-or.js","sourceRoot":"","sources":["../../src/builder/builder-or.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAO5C,MAAa,SAAU,SAAQ,0BAAgB;IAG7C,YAAY,KAA2C;QACrD,KAAK,EAAE,CAAA;QAHD,YAAO,GAAyC,EAAE,CAAA;QAIxD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;IACtB,CAAC;IAES,OAAO;QAEf,OAAO,SAAS,CAAA;IAClB,CAAC;IAKD,KAAK;QACH,OAAO;YACL,GAAG,IAAI,CAAC,IAAI;YACZ,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC7B,IAAI,YAAY,0BAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAClD;SACF,CAAA;IACH,CAAC;CACF;AAxBD,8BAwBC;AAED,kBAAe,SAAS,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { BuilderBase } from './builder-base';
2
+ import SchemaSpec from '../spec';
3
+ export declare class BuilderSchema {
4
+ private spec;
5
+ constructor(name?: string);
6
+ name(name: string): this;
7
+ construct(constructorName: string | Function): this;
8
+ constructCollection(constructorName: string | Function): this;
9
+ strict(value?: boolean): this;
10
+ shape(fields: {
11
+ [key: string]: SchemaSpec | BuilderBase<any>;
12
+ }): this;
13
+ matchAll(fieldSpec: SchemaSpec | BuilderBase<any>): this;
14
+ extend(baseSpec: SchemaSpec): this;
15
+ private static buildValue;
16
+ build(): SchemaSpec;
17
+ }
18
+ export default BuilderSchema;