@based/schema 0.0.16 → 1.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 (112) hide show
  1. package/dist/{set/error.d.ts → error.d.ts} +4 -2
  2. package/dist/{set/error.js → error.js} +2 -0
  3. package/dist/error.js.map +1 -0
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/set/fields/array.d.ts +2 -0
  8. package/dist/set/fields/array.js +96 -0
  9. package/dist/set/fields/array.js.map +1 -0
  10. package/dist/set/fields/index.d.ts +3 -0
  11. package/dist/set/fields/index.js +72 -0
  12. package/dist/set/fields/index.js.map +1 -0
  13. package/dist/set/fields/number.d.ts +4 -0
  14. package/dist/set/fields/number.js +121 -0
  15. package/dist/set/fields/number.js.map +1 -0
  16. package/dist/set/fields/object.d.ts +3 -0
  17. package/dist/set/fields/object.js +33 -0
  18. package/dist/set/fields/object.js.map +1 -0
  19. package/dist/set/fields/references.d.ts +3 -0
  20. package/dist/set/fields/references.js +106 -0
  21. package/dist/set/fields/references.js.map +1 -0
  22. package/dist/set/fields/set.d.ts +2 -0
  23. package/dist/set/fields/set.js +63 -0
  24. package/dist/set/fields/set.js.map +1 -0
  25. package/dist/set/fields/string.d.ts +3 -0
  26. package/dist/set/fields/string.js +190 -0
  27. package/dist/set/fields/string.js.map +1 -0
  28. package/dist/set/index.d.ts +2 -5
  29. package/dist/set/index.js +98 -126
  30. package/dist/set/index.js.map +1 -1
  31. package/dist/set/isValidId.d.ts +2 -0
  32. package/dist/set/isValidId.js +21 -0
  33. package/dist/set/isValidId.js.map +1 -0
  34. package/dist/set/types.d.ts +0 -5
  35. package/dist/set/types.js +0 -2
  36. package/dist/types.d.ts +7 -1
  37. package/dist/types.js.map +1 -1
  38. package/dist/walker/args.d.ts +31 -0
  39. package/dist/walker/args.js +120 -0
  40. package/dist/walker/args.js.map +1 -0
  41. package/dist/walker/index.d.ts +6 -0
  42. package/dist/walker/index.js +40 -0
  43. package/dist/walker/index.js.map +1 -0
  44. package/dist/walker/parse.d.ts +2 -0
  45. package/dist/walker/parse.js +157 -0
  46. package/dist/walker/parse.js.map +1 -0
  47. package/dist/walker/types.d.ts +44 -0
  48. package/dist/walker/types.js +9 -0
  49. package/dist/walker/types.js.map +1 -0
  50. package/package.json +2 -2
  51. package/src/{set/error.ts → error.ts} +3 -1
  52. package/src/index.ts +2 -2
  53. package/src/set/fields/array.ts +111 -0
  54. package/src/set/fields/index.ts +69 -0
  55. package/src/set/fields/number.ts +134 -0
  56. package/src/set/fields/object.ts +30 -0
  57. package/src/set/fields/references.ts +114 -0
  58. package/src/set/fields/set.ts +63 -0
  59. package/src/set/fields/string.ts +199 -0
  60. package/src/set/index.ts +103 -188
  61. package/src/set/isValidId.ts +23 -0
  62. package/src/set/types.ts +0 -20
  63. package/src/types.ts +4 -2
  64. package/src/walker/args.ts +159 -0
  65. package/src/walker/index.ts +35 -0
  66. package/src/walker/parse.ts +193 -0
  67. package/src/walker/types.ts +75 -0
  68. package/test/number.ts +289 -543
  69. package/test/reference.ts +150 -198
  70. package/test/rest.ts +227 -0
  71. package/test/string.ts +139 -183
  72. package/test/utils/index.ts +23 -0
  73. package/test/walker.ts +558 -3
  74. package/dist/set/collections.d.ts +0 -5
  75. package/dist/set/collections.js +0 -229
  76. package/dist/set/collections.js.map +0 -1
  77. package/dist/set/error.js.map +0 -1
  78. package/dist/set/number.d.ts +0 -4
  79. package/dist/set/number.js +0 -124
  80. package/dist/set/number.js.map +0 -1
  81. package/dist/set/parseDefaultAndValue.d.ts +0 -3
  82. package/dist/set/parseDefaultAndValue.js +0 -35
  83. package/dist/set/parseDefaultAndValue.js.map +0 -1
  84. package/dist/set/parsers.d.ts +0 -3
  85. package/dist/set/parsers.js +0 -42
  86. package/dist/set/parsers.js.map +0 -1
  87. package/dist/set/references.d.ts +0 -3
  88. package/dist/set/references.js +0 -84
  89. package/dist/set/references.js.map +0 -1
  90. package/dist/set/rest.d.ts +0 -5
  91. package/dist/set/rest.js +0 -76
  92. package/dist/set/rest.js.map +0 -1
  93. package/dist/set/string.d.ts +0 -3
  94. package/dist/set/string.js +0 -173
  95. package/dist/set/string.js.map +0 -1
  96. package/dist/set2/index.d.ts +0 -0
  97. package/dist/set2/index.js +0 -71
  98. package/dist/set2/index.js.map +0 -1
  99. package/dist/walker.d.ts +0 -51
  100. package/dist/walker.js +0 -120
  101. package/dist/walker.js.map +0 -1
  102. package/src/set/collections.ts +0 -338
  103. package/src/set/number.ts +0 -167
  104. package/src/set/parseDefaultAndValue.ts +0 -54
  105. package/src/set/parsers.ts +0 -20
  106. package/src/set/references.ts +0 -113
  107. package/src/set/rest.ts +0 -135
  108. package/src/set/string.ts +0 -254
  109. package/src/set2/index.ts +0 -71
  110. package/src/walker.ts +0 -201
  111. package/test/setWalker.ts +0 -494
  112. package/test/text.ts +0 -171
package/src/set/rest.ts DELETED
@@ -1,135 +0,0 @@
1
- import { Parser } from './types'
2
- import { deepEqual } from '@saulx/utils'
3
- import { hashObjectIgnoreKeyOrder, hash } from '@saulx/hash'
4
- import { error, ParseError } from './error'
5
- import { parseValueAndDefault } from './parseDefaultAndValue'
6
-
7
- export const cardinality: Parser<'cardinality'> = async (
8
- path,
9
- value,
10
- fieldSchema,
11
- typeSchema,
12
- target,
13
- handlers,
14
- noCollect
15
- ) => {
16
- if (value && typeof value === 'object') {
17
- if (value.$default !== undefined) {
18
- error(handlers, ParseError.defaultNotSupported, path)
19
- }
20
- if (value.$value !== undefined) {
21
- value = hashObjectIgnoreKeyOrder(value.$value).toString(16)
22
- } else {
23
- value = hashObjectIgnoreKeyOrder(value).toString(16)
24
- }
25
- } else {
26
- value = hash(value).toString(16)
27
- }
28
- if (!noCollect) {
29
- handlers.collect({ path, value, typeSchema, fieldSchema, target })
30
- }
31
- }
32
-
33
- export const boolean: Parser<'boolean'> = async (
34
- path,
35
- value,
36
- fieldSchema,
37
- typeSchema,
38
- target,
39
- handlers,
40
- noCollect
41
- ) => {
42
- if (
43
- await parseValueAndDefault(
44
- path,
45
- value,
46
- fieldSchema,
47
- typeSchema,
48
- target,
49
- handlers,
50
- noCollect
51
- )
52
- ) {
53
- return
54
- }
55
-
56
- if (typeof value !== 'boolean') {
57
- error(handlers, ParseError.incorrectFormat, path)
58
- }
59
-
60
- if (!noCollect) {
61
- handlers.collect({ path, value, typeSchema, fieldSchema, target })
62
- }
63
- }
64
-
65
- export const enumParser: Parser<'enum'> = async (
66
- path,
67
- value,
68
- fieldSchema,
69
- typeSchema,
70
- target,
71
- handlers,
72
- noCollect
73
- ) => {
74
- const enumValues = fieldSchema.enum
75
- if (
76
- !(await parseValueAndDefault(
77
- path,
78
- value,
79
- fieldSchema,
80
- typeSchema,
81
- target,
82
- handlers,
83
- noCollect
84
- ))
85
- ) {
86
- for (let i = 0; i < enumValues.length; i++) {
87
- if (deepEqual(enumValues[i], value)) {
88
- if (!noCollect) {
89
- handlers.collect({ path, value: i, typeSchema, fieldSchema, target })
90
- }
91
- return
92
- }
93
- }
94
- error(handlers, ParseError.incorrectFormat, path)
95
- }
96
- }
97
-
98
- export const json: Parser<'json'> = async (
99
- path,
100
- value,
101
- fieldSchema,
102
- typeSchema,
103
- target,
104
- handlers,
105
- noCollect
106
- ) => {
107
- if (
108
- await parseValueAndDefault(
109
- path,
110
- value,
111
- fieldSchema,
112
- typeSchema,
113
- target,
114
- handlers,
115
- noCollect
116
- )
117
- ) {
118
- return
119
- }
120
-
121
- try {
122
- const parsedValue = JSON.stringify(value)
123
- if (!noCollect) {
124
- handlers.collect({
125
- path,
126
- value: parsedValue,
127
- typeSchema,
128
- fieldSchema,
129
- target,
130
- })
131
- }
132
- } catch (err) {
133
- error(handlers, ParseError.incorrectFormat, path)
134
- }
135
- }
package/src/set/string.ts DELETED
@@ -1,254 +0,0 @@
1
- import { Parser } from './types'
2
- import { error, ParseError } from './error'
3
- import {
4
- BasedSchemaFieldString,
5
- BasedSchemaFieldText,
6
- BasedSchemaLanguage,
7
- BasedSetHandlers,
8
- } from '../types'
9
- import validators from 'validator'
10
- import { parseValueAndDefault } from './parseDefaultAndValue'
11
-
12
- const formatPatterns: Record<
13
- BasedSchemaFieldString['format'],
14
- (str: string) => boolean
15
- > = {
16
- email: validators.isEmail,
17
- URL: validators.isURL,
18
- MACAddress: validators.isMACAddress,
19
- IP: validators.isIP,
20
- IPRange: validators.isIPRange,
21
- FQDN: validators.isFQDN,
22
- IBAN: validators.isIBAN,
23
- BIC: validators.isBIC,
24
- alpha: validators.isAlpha,
25
- alphaLocales: validators.isAlphaLocales,
26
- alphanumeric: validators.isAlphanumeric,
27
- alphanumericLocales: validators.isAlphanumericLocales,
28
- passportNumber: validators.isPassportNumber,
29
- port: validators.isPort,
30
- lowercase: validators.isLowercase,
31
- uppercase: validators.isUppercase,
32
- ascii: validators.isAscii,
33
- semVer: validators.isSemVer,
34
- surrogatePair: validators.isSurrogatePair,
35
- IMEI: validators.isIMEI,
36
- hexadecimal: validators.isHexadecimal,
37
- octal: validators.isOctal,
38
- hexColor: validators.isHexColor,
39
- rgbColor: validators.isRgbColor,
40
- HSL: validators.isHSL,
41
- ISRC: validators.isISRC,
42
- MD5: validators.isMD5,
43
- JWT: validators.isJWT,
44
- UUID: validators.isUUID,
45
- luhnNumber: validators.isLuhnNumber,
46
- creditCard: validators.isCreditCard,
47
- identityCard: validators.isIdentityCard,
48
- EAN: validators.isEAN,
49
- ISIN: validators.isISIN,
50
- ISBN: validators.isISBN,
51
- ISSN: validators.isISSN,
52
- mobilePhone: validators.isMobilePhone,
53
- mobilePhoneLocales: validators.isMobilePhoneLocales,
54
- postalCode: validators.isPostalCode,
55
- postalCodeLocales: validators.isPostalCodeLocales,
56
- ethereumAddress: validators.isEthereumAddress,
57
- currency: validators.isCurrency,
58
- btcAddress: validators.isBtcAddress,
59
- ISO6391: validators.isISO6391,
60
- ISO8601: validators.isISO8601,
61
- RFC3339: validators.isRFC3339,
62
- ISO31661Alpha2: validators.isISO31661Alpha2,
63
- ISO31661Alpha3: validators.isISO31661Alpha3,
64
- ISO4217: validators.isISO4217,
65
- base32: validators.isBase32,
66
- base58: validators.isBase58,
67
- base64: validators.isBase64,
68
- dataURI: validators.isDataURI,
69
- magnetURI: validators.isMagnetURI,
70
- mimeType: validators.isMimeType,
71
- latLong: validators.isLatLong,
72
- slug: validators.isSlug,
73
- strongPassword: validators.isStrongPassword,
74
- taxID: validators.isTaxID,
75
- licensePlate: validators.isLicensePlate,
76
- VAT: validators.isVAT,
77
- }
78
-
79
- const validate = (
80
- handlers: BasedSetHandlers,
81
- path: (string | number)[],
82
- value: string,
83
- fieldSchema: BasedSchemaFieldText | BasedSchemaFieldString
84
- ) => {
85
- if (typeof value !== 'string') {
86
- error(handlers, ParseError.incorrectFormat, path)
87
- }
88
- if (fieldSchema.minLength && value.length < fieldSchema.minLength) {
89
- error(handlers, ParseError.subceedsMinimum, path)
90
- }
91
- if (fieldSchema.maxLength && value.length > fieldSchema.maxLength) {
92
- error(handlers, ParseError.exceedsMaximum, path)
93
- }
94
- if (fieldSchema.pattern) {
95
- const re = new RegExp(fieldSchema.pattern)
96
- if (!re.test(value)) {
97
- error(handlers, ParseError.incorrectFormat, path)
98
- }
99
- }
100
- if (fieldSchema.format && !formatPatterns[fieldSchema.format](value)) {
101
- error(handlers, ParseError.incorrectFormat, path)
102
- }
103
- // return true / false and add collectError
104
- }
105
-
106
- export const string: Parser<'string'> = async (
107
- path,
108
- value,
109
- fieldSchema,
110
- typeSchema,
111
- target,
112
- handlers,
113
- noCollect
114
- ) => {
115
- if (
116
- await parseValueAndDefault(
117
- path,
118
- value,
119
- fieldSchema,
120
- typeSchema,
121
- target,
122
- handlers,
123
- noCollect
124
- )
125
- ) {
126
- return
127
- }
128
- validate(handlers, path, value, fieldSchema)
129
- if (!noCollect) {
130
- handlers.collect({ path, value, typeSchema, fieldSchema, target })
131
- }
132
- }
133
-
134
- export const text: Parser<'text'> = async (
135
- path,
136
- value,
137
- fieldSchema,
138
- typeSchema,
139
- target,
140
- handlers,
141
- noCollect
142
- ) => {
143
- const valueType = typeof value
144
- if (target.$language && valueType === 'string') {
145
- validate(handlers, path, value, fieldSchema)
146
- if (!noCollect) {
147
- handlers.collect({
148
- path,
149
- value: { [target.$language]: value },
150
- typeSchema,
151
- fieldSchema,
152
- target,
153
- })
154
- }
155
- return
156
- }
157
-
158
- if (valueType !== 'object') {
159
- error(handlers, ParseError.incorrectFormat, path)
160
- }
161
-
162
- if (
163
- target.$language &&
164
- (await parseValueAndDefault(
165
- path,
166
- value,
167
- fieldSchema,
168
- typeSchema,
169
- target,
170
- handlers,
171
- true
172
- ))
173
- ) {
174
- if (!noCollect) {
175
- handlers.collect({
176
- path,
177
- value: {
178
- [target.$language]: value,
179
- },
180
- typeSchema,
181
- fieldSchema,
182
- target,
183
- })
184
- }
185
- return
186
- } else if (
187
- await parseValueAndDefault(
188
- path,
189
- value,
190
- fieldSchema,
191
- typeSchema,
192
- target,
193
- handlers,
194
- true
195
- )
196
- ) {
197
- if (!noCollect) {
198
- handlers.collect({
199
- path,
200
- value,
201
- typeSchema,
202
- fieldSchema,
203
- target,
204
- })
205
- }
206
- return
207
- }
208
-
209
- for (const key in value) {
210
- if (!target.schema.languages.includes(<BasedSchemaLanguage>key)) {
211
- error(handlers, ParseError.languageNotSupported, path)
212
- }
213
-
214
- if (typeof value[key] === 'object') {
215
- if (
216
- await parseValueAndDefault(
217
- path,
218
- value[key],
219
- fieldSchema,
220
- typeSchema,
221
- target,
222
- handlers,
223
- true
224
- )
225
- ) {
226
- continue
227
- }
228
- }
229
-
230
- if (
231
- !(await parseValueAndDefault(
232
- path,
233
- { [key]: value[key] },
234
- fieldSchema,
235
- typeSchema,
236
- target,
237
- handlers,
238
- true
239
- ))
240
- ) {
241
- validate(handlers, path, value[key], fieldSchema)
242
- }
243
- }
244
-
245
- if (!noCollect) {
246
- handlers.collect({
247
- path,
248
- value,
249
- typeSchema,
250
- fieldSchema,
251
- target,
252
- })
253
- }
254
- }
package/src/set2/index.ts DELETED
@@ -1,71 +0,0 @@
1
- // import { ParseError } from '../set/error'
2
- // import { BasedSchema, BasedSetTarget } from '../types'
3
- // import { walk } from '../walker'
4
-
5
- // export const setWalker2 = (schema: BasedSchema, value: any) => {
6
- // return walk<BasedSetTarget>(
7
- // {
8
- // schema,
9
- // parsers: {
10
- // keys: {},
11
- // fields: {
12
- // object: async (args) => {
13
- // if (typeof value !== 'object') {
14
- // args.error(args, ParseError.incorrectFormat)
15
- // return
16
- // }
17
- // const isArray = Array.isArray(value)
18
- // if (isArray) {
19
- // args.error(args, ParseError.incorrectFormat)
20
- // return
21
- // }
22
- // const q: Promise<any>[] = []
23
- // for (const key in value) {
24
- // q.push(args.parse(args, key, value[key]))
25
- // }
26
- // await Promise.all(q)
27
- // },
28
- // boolean: async (args) => {
29
- // if (typeof value !== 'boolean') {
30
- // args.error(args, ParseError.incorrectFormat)
31
- // return
32
- // }
33
- // args.collect(args)
34
- // },
35
- // },
36
- // any: async (args) => {
37
- // args.error(args, ParseError.fieldDoesNotExist)
38
- // },
39
- // },
40
- // init: async (value, args) => {
41
- // let type: string
42
- // if (value.$id) {
43
- // type = schema.prefixToTypeMapping[value.$id.slice(0, 2)]
44
- // if (!type) {
45
- // args.error(args, ParseError.incorrectFieldType)
46
- // return
47
- // }
48
- // }
49
- // if (value.type) {
50
- // if (type && value.type !== type) {
51
- // args.error(args, ParseError.incorrectNodeType)
52
- // return
53
- // }
54
- // type = value.type
55
- // }
56
- // const schemaType = schema.types[type]
57
- // if (!schemaType) {
58
- // args.error(args, ParseError.incorrectNodeType)
59
- // return
60
- // }
61
- // const target: BasedSetTarget = {
62
- // type,
63
- // schema,
64
- // required: [],
65
- // }
66
- // return { ...args, target }
67
- // },
68
- // },
69
- // value
70
- // )
71
- // }
package/src/walker.ts DELETED
@@ -1,201 +0,0 @@
1
- import { ParseError } from './set/error'
2
- import { BasedSchema, BasedSetHandlers, BasedSetTarget } from './types'
3
- import { BasedSchemaType, BasedSchemaFields } from './types'
4
-
5
- type Path = (string | number)[]
6
-
7
- type ErrorHandler<T> = (args: Args<T>, code: ParseError) => void
8
-
9
- type Parse<T> = (
10
- args: Args<T>,
11
- key?: string | number,
12
- value?: any
13
- ) => Promise<Args<T> | void> // If true will not continue
14
-
15
- type BackTrack<T> = (
16
- args: Args<T>,
17
- fromBackTrack: any[],
18
- collectedCommands: any[]
19
- ) => any
20
-
21
- export type Args<
22
- T,
23
- K extends keyof BasedSchemaFields = keyof BasedSchemaFields
24
- > = {
25
- schema: BasedSchema
26
- parentValue?: any
27
- skipCollection?: boolean
28
- fieldSchema?: BasedSchemaFields[K]
29
- typeSchema?: BasedSchemaType
30
- path: Path
31
- key?: number | string
32
- value: any
33
- target: T
34
- fromBackTrack: any[]
35
- parse: Parse<T>
36
- collect: (args: Args<T>) => any
37
- backtrack: BackTrack<T>
38
- requiresAsyncValidation: (validationType: any) => Promise<any>
39
- error: ErrorHandler<T>
40
- }
41
-
42
- export type FieldParser<K extends keyof BasedSchemaFields, T = any> = (
43
- args: Args<T, K>
44
- ) => Promise<Args<T> | void>
45
-
46
- export type KeyParser<T = any> = (
47
- args: Args<T, keyof BasedSchemaFields>
48
- ) => Promise<Args<T> | void>
49
-
50
- export type Opts<T> = {
51
- schema: BasedSchema
52
- init: (args: Args<T>) => Promise<Args<T>>
53
- parsers: {
54
- fields: Partial<{
55
- [Key in keyof BasedSchemaFields]: FieldParser<Key, T>
56
- }>
57
- keys: { [key: string]: KeyParser<T> } // $list -> true
58
- any: KeyParser<T> // y.x
59
- }
60
- collect?: (args: Args<T>) => any
61
- backtrack?: BackTrack<T>
62
- requiresAsyncValidation?: (validationType: any) => Promise<boolean>
63
- errorsCollector?: ErrorHandler<T>
64
- }
65
-
66
- export const walk = async <T>(
67
- opts: Opts<T>,
68
- value: any
69
- ): Promise<{
70
- target: T
71
- errors: { code: ParseError; message: string }[]
72
- }> => {
73
- const errors: { code: ParseError; message: string }[] = []
74
-
75
- if (!('collect' in opts)) {
76
- opts.collect = () => {}
77
- }
78
-
79
- if (!('backtrack' in opts)) {
80
- opts.backtrack = (args, btC, c) => btC
81
- }
82
-
83
- if (!('requiresAsyncValidation' in opts)) {
84
- opts.requiresAsyncValidation = async () => true
85
- }
86
-
87
- const errorsCollector: ErrorHandler<T> = (args, code) => {
88
- const err = {
89
- code,
90
- message: `Error in ${args.path.join('.')}`,
91
- }
92
- if (opts.errorsCollector) {
93
- opts.errorsCollector(args, code)
94
- }
95
- errors.push(err)
96
- }
97
-
98
- const parse: Parse<T> = async (prevArgs, key, value) => {
99
- const collectedCommands: any[] = []
100
- const fromBackTrack: any[] = []
101
- const args: Args<T> = {
102
- schema: opts.schema,
103
- path: key ? [...prevArgs.path, key] : prevArgs.path,
104
- key: key ?? prevArgs.path[prevArgs.path.length - 1],
105
- parentValue: value ? prevArgs.value : undefined,
106
- value: value ?? prevArgs.value,
107
- target: prevArgs.target,
108
- parse: prevArgs.parse,
109
- collect: (args) => {
110
- collectedCommands.push(opts.collect(args))
111
- },
112
- fromBackTrack,
113
- backtrack: opts.backtrack,
114
- error: errorsCollector,
115
- requiresAsyncValidation: prevArgs.requiresAsyncValidation,
116
- }
117
- if (typeof args.value === 'object' && args.value !== null) {
118
- const q: Promise<Args<T> | void>[] = []
119
-
120
- if (args.typeSchema && !args.fieldSchema) {
121
- // top level
122
- }
123
-
124
- if (args.fieldSchema) {
125
- //
126
- }
127
-
128
- // first do key parsers
129
-
130
- if (Array.isArray(args.value)) {
131
- for (let i = 0; i < args.value.length; i++) {
132
- const parser = opts.parsers.keys[i] || opts.parsers.any
133
- const j = i
134
- q.push(
135
- (async () => {
136
- const newArgs = await parser({
137
- ...args,
138
- value: args.value[j],
139
- path: [...args.path, j],
140
- key: j,
141
- })
142
- if (newArgs) {
143
- return parse(newArgs)
144
- }
145
- })()
146
- )
147
- }
148
- } else {
149
- for (const key in args.value) {
150
- const parser = opts.parsers.keys[key] || opts.parsers.any
151
- q.push(
152
- (async () => {
153
- const newArgs = await parser({
154
- ...args,
155
- value: args.value[key],
156
- path: [...args.path, key],
157
- key,
158
- })
159
- if (newArgs) {
160
- return parse(newArgs)
161
- }
162
- })()
163
- )
164
- }
165
- }
166
-
167
- await Promise.all(q)
168
-
169
- if (fromBackTrack.length || collectedCommands.length) {
170
- const x = args.backtrack(args, fromBackTrack, collectedCommands)
171
- if (x) {
172
- prevArgs.fromBackTrack?.push(x)
173
- }
174
- }
175
- }
176
- }
177
- const args: Args<T> = await opts.init(<Args<T>>{
178
- schema: opts.schema,
179
- path: [],
180
- value,
181
- parse,
182
- collect: opts.collect,
183
- backtrack: opts.backtrack,
184
- error: errorsCollector,
185
- requiresAsyncValidation: opts.requiresAsyncValidation,
186
- })
187
-
188
- if (!args) {
189
- return {
190
- // TODO: temp
191
- // @ts-ignore // for now
192
- target: {},
193
- errors,
194
- }
195
- }
196
- await parse(args)
197
- return {
198
- target: args.target,
199
- errors,
200
- }
201
- }