@based/schema 3.2.0 → 4.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.
- package/dist/index.d.ts +3 -5
- package/dist/index.js +2 -21
- package/dist/parse/assert.d.ts +7 -0
- package/dist/parse/assert.js +33 -0
- package/dist/parse/errors.d.ts +19 -0
- package/dist/parse/errors.js +19 -0
- package/dist/parse/index.d.ts +20 -0
- package/dist/parse/index.js +132 -0
- package/dist/parse/props.d.ts +7 -0
- package/dist/parse/props.js +290 -0
- package/dist/parse/utils.d.ts +3 -0
- package/dist/parse/utils.js +29 -0
- package/dist/parsePayload/index.d.ts +3 -0
- package/dist/parsePayload/index.js +2 -0
- package/dist/parseSchema/assert.d.ts +6 -0
- package/dist/parseSchema/assert.js +27 -0
- package/dist/parseSchema/errors.d.ts +19 -0
- package/dist/parseSchema/errors.js +19 -0
- package/dist/parseSchema/index.d.ts +20 -0
- package/dist/parseSchema/index.js +132 -0
- package/dist/parseSchema/props.d.ts +7 -0
- package/dist/parseSchema/props.js +256 -0
- package/dist/parseSchema/utils.d.ts +3 -0
- package/dist/parseSchema/utils.js +29 -0
- package/dist/src/compat/index.js +2 -2
- package/dist/src/set/fields/references.js +3 -30
- package/dist/src/types.d.ts +5 -13
- package/dist/src/types.js +14 -0
- package/dist/src/validateSchema/fieldValidators.js +4 -4
- package/dist/test/compat.js +1 -1
- package/dist/test/data/newSchemas.js +19 -21
- package/dist/test/reference.js +4 -2
- package/dist/test/walker.js +2 -2
- package/dist/types.d.ts +129 -194
- package/dist/types.js +3 -25
- package/package.json +14 -25
- package/README.md +0 -2
- package/dist/display/index.d.ts +0 -2
- package/dist/display/index.js +0 -26
- package/dist/display/number.d.ts +0 -3
- package/dist/display/number.js +0 -89
- package/dist/display/string.d.ts +0 -3
- package/dist/display/string.js +0 -23
- package/dist/display/timestamp.d.ts +0 -3
- package/dist/display/timestamp.js +0 -127
- package/dist/error.d.ts +0 -19
- package/dist/error.js +0 -24
- package/dist/languages.d.ts +0 -187
- package/dist/languages.js +0 -190
- package/dist/set/fields/array.d.ts +0 -2
- package/dist/set/fields/array.js +0 -123
- package/dist/set/fields/index.d.ts +0 -3
- package/dist/set/fields/index.js +0 -74
- package/dist/set/fields/number.d.ts +0 -4
- package/dist/set/fields/number.js +0 -129
- package/dist/set/fields/object.d.ts +0 -3
- package/dist/set/fields/object.js +0 -33
- package/dist/set/fields/references.d.ts +0 -3
- package/dist/set/fields/references.js +0 -128
- package/dist/set/fields/set.d.ts +0 -2
- package/dist/set/fields/set.js +0 -63
- package/dist/set/fields/string.d.ts +0 -3
- package/dist/set/fields/string.js +0 -284
- package/dist/set/index.d.ts +0 -3
- package/dist/set/index.js +0 -183
- package/dist/set/isValidId.d.ts +0 -2
- package/dist/set/isValidId.js +0 -21
- package/dist/set/types.d.ts +0 -0
- package/dist/set/types.js +0 -1
- package/dist/src/compat/newToOld.d.ts +0 -3
- package/dist/src/compat/newToOld.js +0 -218
- package/dist/src/compat/oldToNew.d.ts +0 -3
- package/dist/src/compat/oldToNew.js +0 -210
- package/dist/src/generateQuery.d.ts +0 -12
- package/dist/src/generateQuery.js +0 -75
- package/dist/test/query.d.ts +0 -1
- package/dist/test/query.js +0 -93
- package/dist/updateSchema.d.ts +0 -2
- package/dist/updateSchema.js +0 -16
- package/dist/validateSchema.d.ts +0 -4
- package/dist/validateSchema.js +0 -41
- package/dist/walker/args.d.ts +0 -36
- package/dist/walker/args.js +0 -162
- package/dist/walker/index.d.ts +0 -6
- package/dist/walker/index.js +0 -49
- package/dist/walker/parse.d.ts +0 -3
- package/dist/walker/parse.js +0 -186
- package/dist/walker/types.d.ts +0 -45
- package/dist/walker/types.js +0 -10
package/dist/walker/args.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/walker/args.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
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
|
package/dist/walker/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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';
|
package/dist/walker/index.js
DELETED
|
@@ -1,49 +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
|
-
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
|
package/dist/walker/parse.d.ts
DELETED
package/dist/walker/parse.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parse = void 0;
|
|
4
|
-
const args_1 = require("./args");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
// TODO needs cleaning
|
|
7
|
-
function createOrUseArgs(from, newArgs) {
|
|
8
|
-
if (!newArgs) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (newArgs instanceof args_1.ArgsClass) {
|
|
12
|
-
return newArgs;
|
|
13
|
-
}
|
|
14
|
-
const x = from.create(newArgs);
|
|
15
|
-
// x.collectedCommands = from.collectedCommands
|
|
16
|
-
// x.fromBackTrack = from.fromBackTrack
|
|
17
|
-
return x;
|
|
18
|
-
}
|
|
19
|
-
async function parseKey(from, key, parser) {
|
|
20
|
-
const keyArgs = new args_1.ArgsClass({
|
|
21
|
-
key,
|
|
22
|
-
value: from.value[key],
|
|
23
|
-
fieldSchema: from.fieldSchema,
|
|
24
|
-
}, from);
|
|
25
|
-
// if same
|
|
26
|
-
const newArgs = createOrUseArgs(keyArgs, await parser(keyArgs));
|
|
27
|
-
if (newArgs) {
|
|
28
|
-
return newArgs.parse();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function createFieldArgs(from, key, fieldSchema) {
|
|
32
|
-
return new args_1.ArgsClass({
|
|
33
|
-
key,
|
|
34
|
-
value: from.value[key],
|
|
35
|
-
// @ts-ignore needs key
|
|
36
|
-
fieldSchema,
|
|
37
|
-
}, from);
|
|
38
|
-
}
|
|
39
|
-
function getFieldParser(args) {
|
|
40
|
-
const fieldParser = 'enum' in args.fieldSchema
|
|
41
|
-
? args.root._opts.parsers.fields.enum
|
|
42
|
-
: args.root._opts.parsers.fields[args.fieldSchema.type];
|
|
43
|
-
return fieldParser;
|
|
44
|
-
}
|
|
45
|
-
async function parse(args) {
|
|
46
|
-
const opts = args.root._opts;
|
|
47
|
-
if (args.parseTopLevel) {
|
|
48
|
-
const parser = opts.parsers.any;
|
|
49
|
-
if (parser) {
|
|
50
|
-
const nArgs = await parser(args);
|
|
51
|
-
if (nArgs) {
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
return parse(createOrUseArgs(args, nArgs));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (typeof args.value === 'object' && args.value !== null) {
|
|
58
|
-
const keyQ = [];
|
|
59
|
-
const keysHandled = new Set();
|
|
60
|
-
let allKeysHandled = false;
|
|
61
|
-
for (const key in opts.parsers.keys) {
|
|
62
|
-
if (key in args.value) {
|
|
63
|
-
keysHandled.add(key);
|
|
64
|
-
keyQ.push(parseKey(args, key, opts.parsers.keys[key]));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
await Promise.all(keyQ);
|
|
68
|
-
if (typeof args.value !== 'object' || args.value === null) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// schema
|
|
72
|
-
if (args.stopped === undefined) {
|
|
73
|
-
const fieldQ = [];
|
|
74
|
-
if (args.typeSchema && !args.fieldSchema) {
|
|
75
|
-
for (const key in args.typeSchema.fields) {
|
|
76
|
-
const fieldSchema = args.typeSchema.fields[key];
|
|
77
|
-
if (key in args.value) {
|
|
78
|
-
keysHandled.add(key);
|
|
79
|
-
fieldQ.push(createFieldArgs(args, key, fieldSchema).parse());
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else if (args.fieldSchema && !args.stopped) {
|
|
84
|
-
if (args.fieldSchema.type === 'object') {
|
|
85
|
-
// @ts-ignore should detect from line above
|
|
86
|
-
const objFieldSchema = args.fieldSchema;
|
|
87
|
-
for (const key in objFieldSchema.properties) {
|
|
88
|
-
const fieldSchema = objFieldSchema.properties[key];
|
|
89
|
-
if (key in args.value) {
|
|
90
|
-
keysHandled.add(key);
|
|
91
|
-
fieldQ.push(createFieldArgs(args, key, fieldSchema).parse());
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else if (args.fieldSchema.type === 'record') {
|
|
96
|
-
// @ts-ignore should detect from line above
|
|
97
|
-
const objFieldSchema = args.fieldSchema;
|
|
98
|
-
for (const key in args.value) {
|
|
99
|
-
const fieldSchema = objFieldSchema.values;
|
|
100
|
-
keysHandled.add(key);
|
|
101
|
-
fieldQ.push(createFieldArgs(args, key, fieldSchema).parse());
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else if (args.fieldSchema) {
|
|
105
|
-
const fieldParser = getFieldParser(args);
|
|
106
|
-
if (fieldParser) {
|
|
107
|
-
const newArgs = createOrUseArgs(args, await fieldParser(args));
|
|
108
|
-
if (newArgs) {
|
|
109
|
-
return newArgs.parse();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
await Promise.all(fieldQ);
|
|
115
|
-
if (args.fieldSchema &&
|
|
116
|
-
fieldQ.length > 0 &&
|
|
117
|
-
(args.fieldSchema.type === 'object' ||
|
|
118
|
-
args.fieldSchema.type === 'record')) {
|
|
119
|
-
const fieldParser = getFieldParser(args);
|
|
120
|
-
if (fieldParser) {
|
|
121
|
-
fieldParser(args);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (typeof args.value !== 'object' || args.value === null) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
// any
|
|
129
|
-
if (args.stopped !== types_1.Stopped.stopAll) {
|
|
130
|
-
const parser = opts.parsers.any || opts.parsers.catch;
|
|
131
|
-
if (parser) {
|
|
132
|
-
const q = [];
|
|
133
|
-
if (Array.isArray(args.value)) {
|
|
134
|
-
for (let i = 0; i < args.value.length; i++) {
|
|
135
|
-
if ((!opts.parsers.any && keysHandled.has(i)) || allKeysHandled) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
q.push(parseKey(args, i, parser));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
for (const key in args.value) {
|
|
143
|
-
if ((!opts.parsers.any && keysHandled.has(key)) || allKeysHandled) {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
q.push(parseKey(args, key, parser));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
await Promise.all(q);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (opts.backtrack &&
|
|
153
|
-
!args.skipCollection &&
|
|
154
|
-
(args.fromBackTrack.length || args.collectedCommands.length)) {
|
|
155
|
-
const backtracked = opts.backtrack(args, args.fromBackTrack ?? [], args.collectedCommands ?? []);
|
|
156
|
-
if (backtracked) {
|
|
157
|
-
const target = args.getBackTrackTarget();
|
|
158
|
-
if (!target.fromBackTrack) {
|
|
159
|
-
target.fromBackTrack = [];
|
|
160
|
-
}
|
|
161
|
-
target.fromBackTrack.push(backtracked);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
// more
|
|
167
|
-
if (args.fieldSchema) {
|
|
168
|
-
const fieldParser = getFieldParser(args);
|
|
169
|
-
if (fieldParser) {
|
|
170
|
-
const newArgs = createOrUseArgs(args, await fieldParser(args));
|
|
171
|
-
if (newArgs) {
|
|
172
|
-
return newArgs.parse();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
console.warn('fieldSchema type not implemented yet!', args.fieldSchema);
|
|
177
|
-
const anyParser = opts.parsers.any || opts.parsers.catch;
|
|
178
|
-
anyParser(args);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
exports.parse = parse;
|
|
186
|
-
//# sourceMappingURL=parse.js.map
|
package/dist/walker/types.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ParseError } from '../error';
|
|
2
|
-
import { BasedSchemaType, BasedSchemaFields, BasedSchemaField, BasedSchema } from '../types';
|
|
3
|
-
import { ArgsClass } from './args';
|
|
4
|
-
export type Path = (string | number)[];
|
|
5
|
-
export type ErrorHandler<T> = (code: ParseError, args: ArgsClass<T> | ArgsOpts<T>) => void;
|
|
6
|
-
export type Collect<T> = (args: ArgsClass<T>) => any;
|
|
7
|
-
export type FieldParser<K extends keyof BasedSchemaFields, T = any> = (args: ArgsClass<T, K>) => Promise<ArgsClass<T> | ArgsOpts<T> | void>;
|
|
8
|
-
export type KeyParser<T = any> = (args: ArgsClass<T, keyof BasedSchemaFields>) => Promise<ArgsOpts<T> | ArgsClass<T> | void>;
|
|
9
|
-
export type FieldParsers<T = any> = {
|
|
10
|
-
[Key in keyof BasedSchemaFields]: FieldParser<Key, T>;
|
|
11
|
-
};
|
|
12
|
-
export type AsyncOperation<T> = (args: ArgsClass<T>, type?: string) => Promise<any>;
|
|
13
|
-
export type Opts<T> = {
|
|
14
|
-
init: (value: any, schema: BasedSchema, error: ErrorHandler<T>) => Promise<ArgsOpts<T>>;
|
|
15
|
-
parsers: {
|
|
16
|
-
fields: Partial<{
|
|
17
|
-
[Key in keyof BasedSchemaFields]: FieldParser<Key, T>;
|
|
18
|
-
}>;
|
|
19
|
-
keys: {
|
|
20
|
-
[key: string]: KeyParser<T>;
|
|
21
|
-
};
|
|
22
|
-
any?: KeyParser<T>;
|
|
23
|
-
catch?: KeyParser<T>;
|
|
24
|
-
};
|
|
25
|
-
collect?: (args: ArgsClass<T>) => any;
|
|
26
|
-
error?: ErrorHandler<T>;
|
|
27
|
-
backtrack?: (args: ArgsClass<T>, fromBackTrack: any[], collectedCommands: any[]) => any;
|
|
28
|
-
asyncOperationHandler?: AsyncOperation<T>;
|
|
29
|
-
};
|
|
30
|
-
export declare enum Stopped {
|
|
31
|
-
onlyStopFieldParser = 0,
|
|
32
|
-
stopAll = 1
|
|
33
|
-
}
|
|
34
|
-
export type ArgsOpts<T, K extends keyof BasedSchemaFields = keyof BasedSchemaFields> = {
|
|
35
|
-
parseTopLevel?: boolean;
|
|
36
|
-
target?: T;
|
|
37
|
-
key?: string | number;
|
|
38
|
-
path?: Path;
|
|
39
|
-
value?: any;
|
|
40
|
-
prev?: ArgsClass<T, K>;
|
|
41
|
-
fieldSchema?: BasedSchemaField;
|
|
42
|
-
typeSchema?: BasedSchemaType;
|
|
43
|
-
skipCollection?: boolean;
|
|
44
|
-
collect?: (args: ArgsClass<T, K>, value?: any) => any;
|
|
45
|
-
};
|
package/dist/walker/types.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Stopped = void 0;
|
|
4
|
-
var Stopped;
|
|
5
|
-
(function (Stopped) {
|
|
6
|
-
Stopped[Stopped["onlyStopFieldParser"] = 0] = "onlyStopFieldParser";
|
|
7
|
-
Stopped[Stopped["stopAll"] = 1] = "stopAll";
|
|
8
|
-
})(Stopped || (exports.Stopped = Stopped = {}));
|
|
9
|
-
// Add asyncOperations // requiresAsyncValidation -> asyncOperation: () => {}
|
|
10
|
-
//# sourceMappingURL=types.js.map
|