@versionzero/schema 1.1.0 → 1.2.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/package.json
CHANGED
package/src/compiled-schema.js
CHANGED
|
@@ -1256,7 +1256,7 @@ export class CompiledSchema
|
|
|
1256
1256
|
*/
|
|
1257
1257
|
_process(input, target, options = {}) {
|
|
1258
1258
|
const location = options?.location ?? new SchemaLocation(this);
|
|
1259
|
-
const context = (options.context instanceof TraversalContext) ? options.context : new TraversalContext(location, {strict: options?.strict, deep: options?.deep, debug: options?.debug});
|
|
1259
|
+
const context = (options.context instanceof TraversalContext) ? options.context : new TraversalContext(location, {strict: options?.strict, deep: options?.deep, debug: options?.debug, stats: options?.stats});
|
|
1260
1260
|
|
|
1261
1261
|
const executors = [];
|
|
1262
1262
|
|
|
@@ -13,6 +13,7 @@ import { SchemaError } from '../errors.js';
|
|
|
13
13
|
* @property {boolean} [strict]
|
|
14
14
|
* @property {boolean} [deep]
|
|
15
15
|
* @property {boolean} [debug]
|
|
16
|
+
* @property {object} [stats]
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
/** @typedef {TraversalContextStandardOptions & {[key:string]:any}} TraversalContextOptions */
|
|
@@ -28,7 +29,7 @@ export class TraversalContext
|
|
|
28
29
|
this.root = (root instanceof CompiledSchema)? new SchemaLocation(root) : root;
|
|
29
30
|
this._final = false;
|
|
30
31
|
|
|
31
|
-
this._options = {...options, deep: options.deep ?? false, strict: options.strict ?? true, debug: options.debug ?? false}
|
|
32
|
+
this._options = {...options, deep: options.deep ?? false, strict: options.strict ?? true, debug: options.debug ?? false, stats: options.stats ?? {}}
|
|
32
33
|
|
|
33
34
|
this.traversals = 0;
|
|
34
35
|
this.counter = 0;
|
|
@@ -52,6 +53,10 @@ export class TraversalContext
|
|
|
52
53
|
return this._options.strict;
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
get stats() {
|
|
57
|
+
return this._options.stats;
|
|
58
|
+
}
|
|
59
|
+
|
|
55
60
|
update() {
|
|
56
61
|
this.counter++;
|
|
57
62
|
this.final = false;
|
|
@@ -192,6 +197,11 @@ export class TraversalContext
|
|
|
192
197
|
let done = false;
|
|
193
198
|
|
|
194
199
|
const updateDone = (counter) => {
|
|
200
|
+
this.traversals++;
|
|
201
|
+
|
|
202
|
+
this.stats.traversals = this.traversals;
|
|
203
|
+
this.stats.updates = this.counter;
|
|
204
|
+
|
|
195
205
|
if (this.isComplete) {
|
|
196
206
|
done = true;
|
|
197
207
|
}
|
|
@@ -222,7 +232,6 @@ export class TraversalContext
|
|
|
222
232
|
);
|
|
223
233
|
}
|
|
224
234
|
updateDone(counter);
|
|
225
|
-
this.traversals++;
|
|
226
235
|
}
|
|
227
236
|
return result;
|
|
228
237
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @property {boolean} [strict]
|
|
4
4
|
* @property {boolean} [deep]
|
|
5
5
|
* @property {boolean} [debug]
|
|
6
|
+
* @property {object} [stats]
|
|
6
7
|
*/
|
|
7
8
|
/** @typedef {TraversalContextStandardOptions & {[key:string]:any}} TraversalContextOptions */
|
|
8
9
|
export class TraversalContext {
|
|
@@ -17,6 +18,7 @@ export class TraversalContext {
|
|
|
17
18
|
deep: boolean;
|
|
18
19
|
strict: boolean;
|
|
19
20
|
debug: boolean;
|
|
21
|
+
stats: any;
|
|
20
22
|
};
|
|
21
23
|
traversals: number;
|
|
22
24
|
counter: number;
|
|
@@ -28,9 +30,11 @@ export class TraversalContext {
|
|
|
28
30
|
deep: boolean;
|
|
29
31
|
strict: boolean;
|
|
30
32
|
debug: boolean;
|
|
33
|
+
stats: any;
|
|
31
34
|
};
|
|
32
35
|
get deep(): boolean;
|
|
33
36
|
get strict(): boolean;
|
|
37
|
+
get stats(): any;
|
|
34
38
|
update(): void;
|
|
35
39
|
set final(finalize: boolean);
|
|
36
40
|
get final(): boolean;
|
|
@@ -58,6 +62,7 @@ export type TraversalContextStandardOptions = {
|
|
|
58
62
|
strict?: boolean | undefined;
|
|
59
63
|
deep?: boolean | undefined;
|
|
60
64
|
debug?: boolean | undefined;
|
|
65
|
+
stats?: object;
|
|
61
66
|
};
|
|
62
67
|
export type TraversalContextOptions = TraversalContextStandardOptions & {
|
|
63
68
|
[key: string]: any;
|