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