@based/schema 2.7.1 → 3.0.1

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 (62) hide show
  1. package/dist/display/index.d.ts +2 -0
  2. package/dist/display/index.js +26 -0
  3. package/dist/display/number.d.ts +3 -0
  4. package/dist/display/number.js +89 -0
  5. package/dist/display/string.d.ts +3 -0
  6. package/dist/display/string.js +23 -0
  7. package/dist/display/timestamp.d.ts +3 -0
  8. package/dist/display/timestamp.js +127 -0
  9. package/dist/error.d.ts +19 -0
  10. package/dist/error.js +24 -0
  11. package/dist/index.d.ts +5 -0
  12. package/dist/index.js +22 -0
  13. package/dist/languages.d.ts +187 -0
  14. package/dist/languages.js +190 -0
  15. package/dist/set/fields/array.d.ts +2 -0
  16. package/dist/set/fields/array.js +123 -0
  17. package/dist/set/fields/index.d.ts +3 -0
  18. package/dist/set/fields/index.js +74 -0
  19. package/dist/set/fields/number.d.ts +4 -0
  20. package/dist/set/fields/number.js +129 -0
  21. package/dist/set/fields/object.d.ts +3 -0
  22. package/dist/set/fields/object.js +33 -0
  23. package/dist/set/fields/references.d.ts +3 -0
  24. package/dist/set/fields/references.js +128 -0
  25. package/dist/set/fields/set.d.ts +2 -0
  26. package/dist/set/fields/set.js +63 -0
  27. package/dist/set/fields/string.d.ts +3 -0
  28. package/dist/set/fields/string.js +284 -0
  29. package/dist/set/index.d.ts +3 -0
  30. package/dist/set/index.js +183 -0
  31. package/dist/set/isValidId.d.ts +2 -0
  32. package/dist/set/isValidId.js +21 -0
  33. package/dist/set/types.d.ts +0 -0
  34. package/dist/set/types.js +1 -0
  35. package/dist/src/compat/index.d.ts +6 -2
  36. package/dist/src/compat/index.js +208 -2
  37. package/dist/src/compat/newToOld.js +6 -7
  38. package/dist/src/compat/oldSchemaType.d.ts +28 -4
  39. package/dist/src/set/fields/array.js +4 -4
  40. package/dist/src/types.d.ts +1 -1
  41. package/dist/src/validateSchema/fieldValidators.js +1 -1
  42. package/dist/test/array.js +4 -4
  43. package/dist/test/compat.js +50 -5
  44. package/dist/test/data/newSchemas.js +5 -9
  45. package/dist/test/rest.js +1 -1
  46. package/dist/test/validateSchema/fields.js +5 -5
  47. package/dist/test/walker.js +2 -2
  48. package/dist/types.d.ts +205 -0
  49. package/dist/types.js +27 -0
  50. package/dist/updateSchema.d.ts +2 -0
  51. package/dist/updateSchema.js +16 -0
  52. package/dist/validateSchema.d.ts +4 -0
  53. package/dist/validateSchema.js +41 -0
  54. package/dist/walker/args.d.ts +36 -0
  55. package/dist/walker/args.js +162 -0
  56. package/dist/walker/index.d.ts +6 -0
  57. package/dist/walker/index.js +49 -0
  58. package/dist/walker/parse.d.ts +3 -0
  59. package/dist/walker/parse.js +186 -0
  60. package/dist/walker/types.d.ts +45 -0
  61. package/dist/walker/types.js +10 -0
  62. package/package.json +1 -1
@@ -0,0 +1,205 @@
1
+ import type { Language } from './languages';
2
+ import type { PartialDeep } from 'type-fest';
3
+ import { ParseError } from './error';
4
+ import { ArgsClass, Path } from './walker';
5
+ import { StringFormat } from './display/string';
6
+ import { NumberFormat } from './display/number';
7
+ import { DateFormat } from './display/timestamp';
8
+ export type AllowedTypes = (string | {
9
+ type?: string;
10
+ $filter: any | any[];
11
+ })[];
12
+ export declare const basedSchemaFieldTypes: readonly ["array", "object", "record", "set", "string", "boolean", "number", "json", "integer", "timestamp", "reference", "references", "text", "enum", "cardinality"];
13
+ export type BasedSchemaFieldType = (typeof basedSchemaFieldTypes)[number];
14
+ export declare const isCollection: (type: string) => boolean;
15
+ export type BasedSchemaPattern = string;
16
+ export type BasedSchemaLanguage = Language;
17
+ export declare const languages: string[];
18
+ export type BasedSchemaTypePrefix = string;
19
+ export type BasedSchemaContentMediaType = 'text/html' | 'text/plain' | 'text/markdown' | 'image/png' | 'image/jpeg' | 'video/mp4' | 'image/*' | 'video/*' | 'audio/*' | '*/*' | `${string}/${string}`;
20
+ export type BasedSchemaFieldShared = {
21
+ hooks?: {
22
+ interval?: number;
23
+ hook: string;
24
+ } | {
25
+ interval?: number;
26
+ hook: string;
27
+ }[];
28
+ type?: BasedSchemaFieldType;
29
+ $id?: string;
30
+ $schema?: string;
31
+ isRequired?: boolean;
32
+ title?: string;
33
+ description?: string;
34
+ index?: number;
35
+ readOnly?: boolean;
36
+ writeOnly?: boolean;
37
+ $comment?: string;
38
+ examples?: any[];
39
+ default?: any;
40
+ customValidator?: (value: any, path: (number | string)[], target: BasedSetTarget) => Promise<boolean>;
41
+ $defs?: {
42
+ [key: string]: BasedSchemaField;
43
+ };
44
+ $delete?: boolean;
45
+ };
46
+ export type BasedSchemaStringShared = {
47
+ minLength?: number;
48
+ maxLength?: number;
49
+ contentMediaEncoding?: string;
50
+ contentMediaType?: BasedSchemaContentMediaType;
51
+ pattern?: BasedSchemaPattern;
52
+ format?: 'email' | 'URL' | 'MACAddress' | 'IP' | 'IPRange' | 'FQDN' | 'IBAN' | 'BIC' | 'alpha' | 'alphaLocales' | 'alphanumeric' | 'alphanumericLocales' | 'passportNumber' | 'port' | 'lowercase' | 'uppercase' | 'ascii' | 'semVer' | 'surrogatePair' | 'IMEI' | 'hexadecimal' | 'octal' | 'hexColor' | 'rgbColor' | 'HSL' | 'ISRC' | 'MD5' | 'JWT' | 'UUID' | 'luhnNumber' | 'creditCard' | 'identityCard' | 'EAN' | 'ISIN' | 'ISBN' | 'ISSN' | 'mobilePhone' | 'mobilePhoneLocales' | 'postalCode' | 'postalCodeLocales' | 'ethereumAddress' | 'currency' | 'btcAddress' | 'ISO6391' | 'ISO8601' | 'RFC3339' | 'ISO31661Alpha2' | 'ISO31661Alpha3' | 'ISO4217' | 'base32' | 'base58' | 'base64' | 'dataURI' | 'magnetURI' | 'mimeType' | 'latLong' | 'slug' | 'strongPassword' | 'taxID' | 'licensePlate' | 'VAT';
53
+ display?: StringFormat;
54
+ multiline?: boolean;
55
+ };
56
+ type NumberDefaults = {
57
+ multipleOf?: number;
58
+ minimum?: number;
59
+ maximum?: number;
60
+ exclusiveMaximum?: boolean;
61
+ exclusiveMinimum?: boolean;
62
+ };
63
+ export type BasedNumberDisplay = NumberFormat;
64
+ export type BasedTimestampDisplay = DateFormat;
65
+ export type BasedSchemaFieldString = {
66
+ type: 'string';
67
+ } & BasedSchemaFieldShared & BasedSchemaStringShared;
68
+ export type BasedSchemaFieldEnum = {
69
+ enum: any[];
70
+ type?: '';
71
+ } & BasedSchemaFieldShared;
72
+ export type BasedSchemaFieldCardinality = {
73
+ type: 'cardinality';
74
+ } & BasedSchemaFieldShared;
75
+ export type BasedSchemaFieldNumber = NumberDefaults & {
76
+ type: 'number';
77
+ display?: BasedNumberDisplay;
78
+ } & BasedSchemaFieldShared;
79
+ export type BasedSchemaFieldInteger = NumberDefaults & {
80
+ type: 'integer';
81
+ display?: BasedNumberDisplay;
82
+ } & BasedSchemaFieldShared;
83
+ export type BasedSchemaFieldTimeStamp = NumberDefaults & {
84
+ type: 'timestamp';
85
+ display?: BasedTimestampDisplay;
86
+ } & BasedSchemaFieldShared;
87
+ export type BasedSchemaFieldBoolean = {
88
+ type: 'boolean';
89
+ } & BasedSchemaFieldShared;
90
+ export type BasedSchemaFieldJSON = {
91
+ type: 'json';
92
+ } & BasedSchemaFieldShared;
93
+ export type BasedSchemaFieldPrimitive = BasedSchemaFieldString | BasedSchemaFieldNumber | BasedSchemaFieldInteger | BasedSchemaFieldTimeStamp | BasedSchemaFieldJSON | BasedSchemaFieldBoolean | BasedSchemaFieldEnum;
94
+ export type BasedSchemaFieldText = {
95
+ type: 'text';
96
+ required?: BasedSchemaLanguage[];
97
+ } & BasedSchemaFieldShared & BasedSchemaStringShared;
98
+ export type BasedSchemaFieldObject = {
99
+ type: 'object';
100
+ properties: {
101
+ [name: string]: BasedSchemaField;
102
+ };
103
+ required?: string[];
104
+ } & BasedSchemaFieldShared;
105
+ export type BasedSchemaFieldRecord = {
106
+ type: 'record';
107
+ values: BasedSchemaField;
108
+ } & BasedSchemaFieldShared;
109
+ export type BasedSchemaFieldArray = {
110
+ type: 'array';
111
+ values: BasedSchemaField;
112
+ } & BasedSchemaFieldShared;
113
+ export type BasedSchemaFieldSet = {
114
+ type: 'set';
115
+ items: BasedSchemaFieldPrimitive;
116
+ } & BasedSchemaFieldShared;
117
+ export type BasedSchemaFieldEnumerable = BasedSchemaFieldText | BasedSchemaFieldObject | BasedSchemaFieldRecord | BasedSchemaFieldArray | BasedSchemaFieldSet;
118
+ export type BasedSchemaFieldReference = {
119
+ type: 'reference';
120
+ bidirectional?: {
121
+ fromField: string;
122
+ };
123
+ allowedTypes?: AllowedTypes;
124
+ } & BasedSchemaFieldShared;
125
+ export type BasedSchemaFieldReferences = {
126
+ type: 'references';
127
+ bidirectional?: {
128
+ fromField: string;
129
+ };
130
+ allowedTypes?: AllowedTypes;
131
+ } & BasedSchemaFieldShared;
132
+ export type BasedSchemaFields = {
133
+ string: BasedSchemaFieldString;
134
+ number: BasedSchemaFieldNumber;
135
+ integer: BasedSchemaFieldInteger;
136
+ timestamp: BasedSchemaFieldTimeStamp;
137
+ json: BasedSchemaFieldJSON;
138
+ boolean: BasedSchemaFieldBoolean;
139
+ enum: BasedSchemaFieldEnum;
140
+ array: BasedSchemaFieldArray;
141
+ object: BasedSchemaFieldObject;
142
+ set: BasedSchemaFieldSet;
143
+ record: BasedSchemaFieldRecord;
144
+ reference: BasedSchemaFieldReference;
145
+ references: BasedSchemaFieldReferences;
146
+ text: BasedSchemaFieldText;
147
+ cardinality: BasedSchemaFieldCardinality;
148
+ };
149
+ export type BasedSchemaField = BasedSchemaFields[keyof BasedSchemaFields] | (BasedSchemaFieldShared & {
150
+ type?: '';
151
+ isRequired?: boolean;
152
+ $ref: string;
153
+ });
154
+ export type BasedSchemaType = {
155
+ fields: {
156
+ [name: string]: BasedSchemaField;
157
+ };
158
+ title?: string;
159
+ description?: string;
160
+ prefix?: BasedSchemaTypePrefix;
161
+ examples?: any[];
162
+ required?: string[];
163
+ $defs?: {
164
+ [key: string]: BasedSchemaField;
165
+ };
166
+ $delete?: boolean;
167
+ };
168
+ export type BasedSchema = {
169
+ language: BasedSchemaLanguage;
170
+ translations?: BasedSchemaLanguage[];
171
+ languageFallbacks?: Partial<Record<BasedSchemaLanguage, BasedSchemaLanguage[]>>;
172
+ root: BasedSchemaType;
173
+ $defs: {
174
+ [name: string]: BasedSchemaField;
175
+ };
176
+ types: {
177
+ [type: string]: BasedSchemaType;
178
+ };
179
+ prefixToTypeMapping: {
180
+ [prefix: string]: string;
181
+ };
182
+ };
183
+ export type BasedSchemaTypePartial = PartialDeep<BasedSchemaType>;
184
+ export type BasedSchemaFieldPartial = PartialDeep<BasedSchemaField>;
185
+ export type BasedSchemaPartial = PartialDeep<BasedSchema>;
186
+ export type BasedSetTarget = {
187
+ type: string;
188
+ $alias?: string;
189
+ $id?: string;
190
+ schema: BasedSchema;
191
+ $merge?: boolean;
192
+ $language?: BasedSchemaLanguage;
193
+ required: (number | string)[][];
194
+ collected: BasedSchemaCollectProps[];
195
+ errors: {
196
+ code: ParseError;
197
+ path: Path;
198
+ }[];
199
+ };
200
+ export type BasedSchemaCollectProps = ArgsClass<BasedSetTarget> & {
201
+ root: ArgsClass<BasedSetTarget> & {
202
+ typeSchema: BasedSchemaType;
203
+ };
204
+ };
205
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.languages = exports.isCollection = exports.basedSchemaFieldTypes = void 0;
4
+ const languages_1 = require("./languages");
5
+ exports.basedSchemaFieldTypes = [
6
+ 'array',
7
+ 'object',
8
+ 'record',
9
+ 'set',
10
+ 'string',
11
+ 'boolean',
12
+ 'number',
13
+ 'json',
14
+ 'integer',
15
+ 'timestamp',
16
+ 'reference',
17
+ 'references',
18
+ 'text',
19
+ 'enum',
20
+ 'cardinality',
21
+ ];
22
+ const isCollection = (type) => {
23
+ return type === 'array' || type === 'object' || type === 'record';
24
+ };
25
+ exports.isCollection = isCollection;
26
+ exports.languages = Object.keys(languages_1.languages);
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,2 @@
1
+ import { BasedSchema, BasedSchemaPartial } from './types';
2
+ export declare const updateSchema: (newSchema: BasedSchemaPartial, oldSchema?: BasedSchema) => Promise<BasedSchema>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateSchema = void 0;
4
+ const updateSchema = async (newSchema, oldSchema = {
5
+ $defs: {},
6
+ types: {},
7
+ language: 'en',
8
+ root: { fields: {} },
9
+ prefixToTypeMapping: {},
10
+ }) => {
11
+ // add sha
12
+ // put isRequired on the new schema in REQUIRED arrays
13
+ return oldSchema;
14
+ };
15
+ exports.updateSchema = updateSchema;
16
+ //# sourceMappingURL=updateSchema.js.map
@@ -0,0 +1,4 @@
1
+ import { BasedSchemaPartial, BasedSchemaFieldPartial, BasedSchemaTypePartial } from './types';
2
+ export declare const validateType: (fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
3
+ export declare const validateField: (fromSchema: BasedSchemaPartial, path: string[], field: BasedSchemaFieldPartial) => void;
4
+ export declare const validateSchema: (schema: BasedSchemaPartial) => BasedSchemaPartial;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateSchema = exports.validateField = exports.validateType = void 0;
4
+ // gaurd in the schema for refs in arrays
5
+ const validateType = (fromSchema, typeName, type) => {
6
+ if (type.prefix &&
7
+ (typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
8
+ throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
9
+ }
10
+ };
11
+ exports.validateType = validateType;
12
+ const validateField = (fromSchema, path, field) => {
13
+ //
14
+ };
15
+ exports.validateField = validateField;
16
+ const validateSchema = (schema) => {
17
+ // rewrite schema things like required / required: []
18
+ if (typeof schema !== 'object') {
19
+ throw new Error('Schema is not an object');
20
+ }
21
+ if (schema.language && typeof schema.language !== 'string') {
22
+ throw new Error('Language must be a string');
23
+ }
24
+ if (schema.translations && !Array.isArray(schema.translations)) {
25
+ throw new Error('Translations needs to be an array');
26
+ }
27
+ if (schema.$defs) {
28
+ // first defs ofc
29
+ }
30
+ if (schema.root) {
31
+ (0, exports.validateType)(schema, 'root', schema.root);
32
+ }
33
+ if (schema.types) {
34
+ for (const type in schema.types) {
35
+ (0, exports.validateType)(schema, type, schema.types[type]);
36
+ }
37
+ }
38
+ return schema;
39
+ };
40
+ exports.validateSchema = validateSchema;
41
+ //# sourceMappingURL=validateSchema.js.map
@@ -0,0 +1,36 @@
1
+ import { BasedSchema } from '../types';
2
+ import { BasedSchemaType, BasedSchemaFields } from '../types';
3
+ import { ArgsOpts, Path, Opts, Stopped, Collect } from './types';
4
+ import { ParseError } from '../error';
5
+ export declare class ArgsClass<T, K extends keyof BasedSchemaFields = keyof BasedSchemaFields> {
6
+ errors: any[];
7
+ id: number;
8
+ prev: ArgsClass<T, K>;
9
+ root: ArgsClass<T, K>;
10
+ _opts: Opts<T>;
11
+ _target: T;
12
+ _stopObject?: boolean;
13
+ _schema: BasedSchema;
14
+ parseTopLevel?: boolean;
15
+ _collectOverride: Collect<T>;
16
+ fieldSchema?: BasedSchemaFields[K];
17
+ typeSchema?: BasedSchemaType;
18
+ path: Path;
19
+ skipCollection: boolean;
20
+ value: any;
21
+ stopped: Stopped | void;
22
+ fromBackTrack: any[];
23
+ collectedCommands: any[];
24
+ constructor(opts: ArgsOpts<T, K>, prev?: ArgsClass<T, K>);
25
+ get schema(): BasedSchema;
26
+ get key(): number | string;
27
+ get target(): T;
28
+ stop(onllyStopFieldSchemaParser?: boolean): void;
29
+ create(opts?: ArgsOpts<T>): ArgsClass<T>;
30
+ parse(opts?: ArgsOpts<T>): Promise<ArgsClass<T> | void>;
31
+ getTopPaths(): Path[];
32
+ getBackTrackTarget(): ArgsClass<T>;
33
+ getCollectTarget(): void;
34
+ collect(value?: any): void;
35
+ error(code: ParseError): void;
36
+ }
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArgsClass = void 0;
4
+ const types_1 = require("./types");
5
+ const parse_1 = require("./parse");
6
+ const utils_1 = require("@saulx/utils");
7
+ let id = 0;
8
+ class ArgsClass {
9
+ constructor(opts, prev) {
10
+ this.id = ++id;
11
+ this.fromBackTrack = [];
12
+ this.collectedCommands = [];
13
+ if (opts.prev) {
14
+ prev = opts.prev;
15
+ }
16
+ if (opts.parseTopLevel) {
17
+ this.parseTopLevel = opts.parseTopLevel;
18
+ }
19
+ if (prev) {
20
+ this.prev = prev;
21
+ this.root = prev.root;
22
+ this.fieldSchema = prev.fieldSchema;
23
+ }
24
+ if (opts.path) {
25
+ this.path = opts.path;
26
+ }
27
+ else if (prev && opts.key !== undefined) {
28
+ this.path = [...prev.path, opts.key];
29
+ }
30
+ else if (opts && prev) {
31
+ this.path = prev.path;
32
+ }
33
+ else {
34
+ this.path = [];
35
+ }
36
+ this.value = opts.value;
37
+ if (opts.fieldSchema) {
38
+ // @ts-ignore K is too loose
39
+ this.fieldSchema = opts.fieldSchema;
40
+ }
41
+ if (opts.typeSchema) {
42
+ this.typeSchema = opts.typeSchema;
43
+ }
44
+ if (opts.target) {
45
+ this._target = opts.target;
46
+ }
47
+ if (opts.collect) {
48
+ this._collectOverride = opts.collect;
49
+ }
50
+ else if (prev?._collectOverride) {
51
+ this._collectOverride = prev._collectOverride;
52
+ }
53
+ if (opts.skipCollection) {
54
+ this.skipCollection = opts.skipCollection;
55
+ }
56
+ else if (prev?.skipCollection) {
57
+ this.skipCollection = true;
58
+ }
59
+ }
60
+ get schema() {
61
+ if (this._schema) {
62
+ return this.schema;
63
+ }
64
+ return this.root._schema;
65
+ }
66
+ get key() {
67
+ return this.path[this.path.length - 1] ?? '';
68
+ }
69
+ get target() {
70
+ if (this._target) {
71
+ return this._target;
72
+ }
73
+ let p = this.prev;
74
+ while (p) {
75
+ if (p._target) {
76
+ return p._target;
77
+ }
78
+ p = p.prev;
79
+ }
80
+ }
81
+ stop(onllyStopFieldSchemaParser) {
82
+ const target = this;
83
+ if (onllyStopFieldSchemaParser) {
84
+ target.stopped = types_1.Stopped.onlyStopFieldParser;
85
+ }
86
+ else {
87
+ target.stopped = types_1.Stopped.stopAll;
88
+ }
89
+ }
90
+ create(opts) {
91
+ const newArgs = new ArgsClass(opts, this);
92
+ if (this._collectOverride && !opts.collect) {
93
+ newArgs._collectOverride = this._collectOverride;
94
+ }
95
+ if (this.skipCollection && opts.skipCollection !== false) {
96
+ newArgs.skipCollection = this.skipCollection;
97
+ }
98
+ if (!('value' in opts)) {
99
+ newArgs.value = this.value;
100
+ }
101
+ return newArgs;
102
+ }
103
+ async parse(opts) {
104
+ if (!opts) {
105
+ return (0, parse_1.parse)(this);
106
+ }
107
+ else {
108
+ const newArgs = new ArgsClass(opts, this);
109
+ if (newArgs.value === undefined) {
110
+ newArgs.value = this.value;
111
+ }
112
+ return newArgs.parse();
113
+ }
114
+ }
115
+ getTopPaths() {
116
+ let argPath = [];
117
+ let p = this;
118
+ while (p) {
119
+ argPath.unshift({ path: p.path, id: p.id });
120
+ // @ts-ignore
121
+ p = p.prev;
122
+ }
123
+ return argPath;
124
+ }
125
+ getBackTrackTarget() {
126
+ let p = this;
127
+ while (p) {
128
+ if (p.prev) {
129
+ if ((0, utils_1.deepEqual)(p.prev.path, p.path)) {
130
+ p = p.prev;
131
+ }
132
+ else {
133
+ p = p.prev;
134
+ break;
135
+ }
136
+ }
137
+ else {
138
+ break;
139
+ }
140
+ }
141
+ return p;
142
+ }
143
+ getCollectTarget() { }
144
+ collect(value) {
145
+ if (this.skipCollection) {
146
+ return;
147
+ }
148
+ const collectArgs = value !== undefined ? new ArgsClass({ value }, this) : this;
149
+ let collectTarget = this.prev;
150
+ if (this._collectOverride) {
151
+ collectTarget.collectedCommands.push(this._collectOverride(collectArgs));
152
+ }
153
+ else {
154
+ collectTarget.collectedCommands.push(this.root._opts.collect(collectArgs));
155
+ }
156
+ }
157
+ error(code) {
158
+ this.root._opts.error(code, this);
159
+ }
160
+ }
161
+ exports.ArgsClass = ArgsClass;
162
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1,6 @@
1
+ import { BasedSchema } from '../types';
2
+ import { ArgsClass } from './args';
3
+ import { AsyncOperation, Opts } from './types';
4
+ export declare const walk: <T>(schema: BasedSchema, opts: Opts<T>, value: any, asyncOperationHandler?: AsyncOperation<T>) => Promise<T>;
5
+ export { ArgsClass };
6
+ export * from './types';
@@ -0,0 +1,49 @@
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
+ exports.ArgsClass = exports.walk = void 0;
18
+ const args_1 = require("./args");
19
+ Object.defineProperty(exports, "ArgsClass", { enumerable: true, get: function () { return args_1.ArgsClass; } });
20
+ const walk = async (schema, opts, value, asyncOperationHandler) => {
21
+ if (!('collect' in opts)) {
22
+ opts.collect = () => { };
23
+ }
24
+ if (!('error' in opts)) {
25
+ opts.error = () => { };
26
+ }
27
+ if (asyncOperationHandler) {
28
+ opts = {
29
+ ...opts,
30
+ asyncOperationHandler,
31
+ };
32
+ }
33
+ const argsOpts = await opts.init(value, schema, opts.error);
34
+ if (!argsOpts) {
35
+ return {};
36
+ }
37
+ if (!argsOpts.value) {
38
+ argsOpts.value = value;
39
+ }
40
+ const args = new args_1.ArgsClass(argsOpts);
41
+ args.root = args;
42
+ args._opts = opts;
43
+ args._schema = schema;
44
+ await args.parse();
45
+ return args.target;
46
+ };
47
+ exports.walk = walk;
48
+ __exportStar(require("./types"), exports);
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import { ArgsClass } from './args';
2
+ export type ParseResult<T> = ArgsClass<T> | void;
3
+ export declare function parse<T>(args: ArgsClass<T>): Promise<ArgsClass<T> | void>;