tape-six 1.7.13 → 1.8.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 +3 -1
- package/TESTING.md +246 -47
- package/bin/tape6-server.js +19 -19
- package/index.d.ts +67 -0
- package/llms-full.txt +102 -0
- package/llms.txt +66 -0
- package/package.json +13 -4
- package/skills/write-tests/SKILL.md +63 -16
- package/src/State.js +26 -21
- package/src/Tester.js +59 -27
- package/src/deep6/env.d.ts +174 -0
- package/src/deep6/env.js +4 -4
- package/src/deep6/index.d.ts +86 -0
- package/src/deep6/index.js +10 -7
- package/src/deep6/traverse/assemble.d.ts +59 -0
- package/src/deep6/traverse/assemble.js +4 -3
- package/src/deep6/traverse/clone.d.ts +57 -0
- package/src/deep6/traverse/clone.js +4 -2
- package/src/deep6/traverse/deref.d.ts +59 -0
- package/src/deep6/traverse/deref.js +3 -2
- package/src/deep6/traverse/preprocess.d.ts +65 -0
- package/src/deep6/traverse/preprocess.js +2 -1
- package/src/deep6/traverse/walk.d.ts +219 -0
- package/src/deep6/traverse/walk.js +9 -4
- package/src/deep6/unifiers/matchCondition.d.ts +45 -0
- package/src/deep6/unifiers/matchCondition.js +1 -0
- package/src/deep6/unifiers/matchInstanceOf.d.ts +37 -0
- package/src/deep6/unifiers/matchInstanceOf.js +1 -0
- package/src/deep6/unifiers/matchString.d.ts +56 -0
- package/src/deep6/unifiers/matchString.js +1 -0
- package/src/deep6/unifiers/matchTypeOf.d.ts +37 -0
- package/src/deep6/unifiers/matchTypeOf.js +1 -0
- package/src/deep6/unifiers/ref.d.ts +52 -0
- package/src/deep6/unifiers/ref.js +1 -0
- package/src/deep6/unify.d.ts +95 -0
- package/src/deep6/unify.js +130 -66
- package/src/deep6/utils/replaceVars.d.ts +25 -0
- package/src/deep6/utils/replaceVars.js +23 -19
- package/src/response.d.ts +43 -0
- package/src/response.js +57 -0
- package/src/server.d.ts +81 -0
- package/src/server.js +69 -0
- package/src/test.js +26 -53
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Type definitions for deep6
|
|
2
|
+
// Generated from src/index.js
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for deep equality comparison
|
|
6
|
+
*/
|
|
7
|
+
export interface EqualOptions {
|
|
8
|
+
/** Handle circular references (default: true) */
|
|
9
|
+
circular?: boolean;
|
|
10
|
+
/** Include symbol properties (default: false) */
|
|
11
|
+
symbols?: boolean;
|
|
12
|
+
/** Use loose equality for primitives (default: false) */
|
|
13
|
+
loose?: boolean;
|
|
14
|
+
/** Ignore function properties (default: false) */
|
|
15
|
+
ignoreFunctions?: boolean;
|
|
16
|
+
/** Distinguish +0 from -0 (default: false) */
|
|
17
|
+
signedZero?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Options for pattern matching
|
|
22
|
+
*/
|
|
23
|
+
export interface MatchOptions {
|
|
24
|
+
/** Allow extra keys on target objects (default: true) */
|
|
25
|
+
openObjects?: boolean;
|
|
26
|
+
/** Allow extra entries in target Maps (default: true) */
|
|
27
|
+
openMaps?: boolean;
|
|
28
|
+
/** Allow extra entries in target Sets (default: true) */
|
|
29
|
+
openSets?: boolean;
|
|
30
|
+
/** Allow extra elements in target arrays (default: false) */
|
|
31
|
+
openArrays?: boolean;
|
|
32
|
+
/** Handle circular references (default: true) */
|
|
33
|
+
circular?: boolean;
|
|
34
|
+
/** Include symbol properties (default: false) */
|
|
35
|
+
symbols?: boolean;
|
|
36
|
+
/** Use loose equality for primitives (default: false) */
|
|
37
|
+
loose?: boolean;
|
|
38
|
+
/** Ignore function properties (default: false) */
|
|
39
|
+
ignoreFunctions?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Options for deep cloning via the main API
|
|
44
|
+
*/
|
|
45
|
+
export interface CloneOptions {
|
|
46
|
+
/** Handle circular references (default: true) */
|
|
47
|
+
circular?: boolean;
|
|
48
|
+
/** Clone symbol properties (default: false) */
|
|
49
|
+
symbols?: boolean;
|
|
50
|
+
/** Clone non-enumerable properties (default: false) */
|
|
51
|
+
allProps?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Deep equality check using unification
|
|
56
|
+
* @param a - First value
|
|
57
|
+
* @param b - Second value
|
|
58
|
+
* @param options - Comparison options
|
|
59
|
+
* @returns True if values are deeply equal
|
|
60
|
+
*/
|
|
61
|
+
export declare const equal: (a: unknown, b: unknown, options?: EqualOptions) => boolean;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Deep clone of a value
|
|
65
|
+
* @param a - Value to clone
|
|
66
|
+
* @param options - Cloning options
|
|
67
|
+
* @returns Deep copy of the value
|
|
68
|
+
*/
|
|
69
|
+
export declare const clone: <T>(a: T, options?: CloneOptions) => T;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Pattern matching with wildcards
|
|
73
|
+
* @param object - Value to test
|
|
74
|
+
* @param pattern - Pattern to match against
|
|
75
|
+
* @param options - Matching options
|
|
76
|
+
* @returns True if object matches the pattern
|
|
77
|
+
*/
|
|
78
|
+
export declare const match: (object: unknown, pattern: unknown, options?: MatchOptions) => boolean;
|
|
79
|
+
|
|
80
|
+
/** Alias for `match` */
|
|
81
|
+
export declare const isShape: typeof match;
|
|
82
|
+
|
|
83
|
+
export {any, _} from './env.js';
|
|
84
|
+
|
|
85
|
+
/** Default export — deep equality function */
|
|
86
|
+
export default equal;
|
package/src/deep6/index.js
CHANGED
|
@@ -7,13 +7,16 @@ const defaultOptions = {circular: true};
|
|
|
7
7
|
const equal = (a, b, options = defaultOptions) => !!unify(a, b, null, options);
|
|
8
8
|
|
|
9
9
|
const defaultMatchOptions = {openObjects: true, openMaps: true, openSets: true, circular: true};
|
|
10
|
-
const match = (object, pattern, options = defaultMatchOptions) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const match = (object, pattern, options = defaultMatchOptions) => {
|
|
11
|
+
const processedPattern = preprocess(pattern, options),
|
|
12
|
+
unifyOptions = {
|
|
13
|
+
circular: options.circular,
|
|
14
|
+
symbols: options.symbols,
|
|
15
|
+
loose: options.loose,
|
|
16
|
+
ignoreFunctions: options.ignoreFunctions
|
|
17
|
+
};
|
|
18
|
+
return !!unify(object, processedPattern, null, unifyOptions);
|
|
19
|
+
};
|
|
17
20
|
|
|
18
21
|
const clone = (a, options = defaultOptions) => originalClone(a, null, options);
|
|
19
22
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Type definitions for deep6 assemble
|
|
2
|
+
// Generated from src/traverse/assemble.js
|
|
3
|
+
|
|
4
|
+
import type {Env} from '../env.js';
|
|
5
|
+
import type {WalkContext} from './walk.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for assembly
|
|
9
|
+
*/
|
|
10
|
+
export interface AssembleOptions {
|
|
11
|
+
/** Handle circular references (default: false) */
|
|
12
|
+
circular?: boolean;
|
|
13
|
+
/** Include symbol properties (default: false) */
|
|
14
|
+
symbols?: boolean;
|
|
15
|
+
/** Include non-enumerable properties (default: false) */
|
|
16
|
+
allProps?: boolean;
|
|
17
|
+
/** Custom context object */
|
|
18
|
+
context?: Record<string, unknown>;
|
|
19
|
+
/** Custom object processor */
|
|
20
|
+
processObject?: (object: unknown, context: WalkContext) => void;
|
|
21
|
+
/** Custom non-object value processor */
|
|
22
|
+
processOther?: (value: unknown, context: WalkContext) => void;
|
|
23
|
+
/** Custom circular reference processor */
|
|
24
|
+
processCircular?: (value: unknown, context: WalkContext) => void;
|
|
25
|
+
/** Custom type handler registry (flat array of [Constructor, handler] pairs) */
|
|
26
|
+
registry?: unknown[];
|
|
27
|
+
/** Custom filter functions */
|
|
28
|
+
filters?: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Flat array of type-specific assembler pairs: [Constructor, handler, ...]
|
|
33
|
+
*
|
|
34
|
+
* Use `registry.push(Type, handler)` to register a custom assembler.
|
|
35
|
+
*/
|
|
36
|
+
export declare const registry: unknown[];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Filter functions for custom assembly processing
|
|
40
|
+
*/
|
|
41
|
+
export declare const filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Replaces variables with their bound values from an environment
|
|
45
|
+
*
|
|
46
|
+
* Creates a new structure only when values differ from the source.
|
|
47
|
+
* Unbound variables are kept as-is.
|
|
48
|
+
*
|
|
49
|
+
* @param source - Value containing variables to resolve
|
|
50
|
+
* @param env - Env with bindings, or options object
|
|
51
|
+
* @param options - Assembly options (when env is provided separately)
|
|
52
|
+
* @returns New value with variables replaced, or original if unchanged
|
|
53
|
+
*/
|
|
54
|
+
export declare const assemble: ((source: unknown, env?: Env | AssembleOptions | null, options?: AssembleOptions) => unknown) & {
|
|
55
|
+
registry: unknown[];
|
|
56
|
+
filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default assemble;
|
|
@@ -52,7 +52,7 @@ function postProcessSeen(context) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
function postProcessMap(context) {
|
|
56
56
|
const stackOut = context.stackOut,
|
|
57
57
|
s = this.s;
|
|
58
58
|
let j = stackOut.length - 1;
|
|
@@ -65,7 +65,7 @@ const postProcessMap = context => {
|
|
|
65
65
|
} else {
|
|
66
66
|
replaceObject(j, s, stackOut);
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|
|
69
69
|
|
|
70
70
|
function postProcessMapSeen(context) {
|
|
71
71
|
const stackOut = context.stackOut,
|
|
@@ -108,6 +108,7 @@ const registry = [
|
|
|
108
108
|
|
|
109
109
|
const addType = (Type, process) => registry.push(Type, process || processOther);
|
|
110
110
|
|
|
111
|
+
typeof URL == 'function' && addType(URL);
|
|
111
112
|
typeof Int8Array == 'function' && addType(Int8Array);
|
|
112
113
|
typeof Uint8Array == 'function' && addType(Uint8Array);
|
|
113
114
|
typeof Uint8ClampedArray == 'function' && addType(Uint8ClampedArray);
|
|
@@ -154,5 +155,5 @@ const assemble = (source, env, options) => {
|
|
|
154
155
|
assemble.registry = registry;
|
|
155
156
|
assemble.filters = filters;
|
|
156
157
|
|
|
157
|
-
export {registry, filters};
|
|
158
|
+
export {registry, filters, assemble};
|
|
158
159
|
export default assemble;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Type definitions for deep6 clone
|
|
2
|
+
// Generated from src/traverse/clone.js
|
|
3
|
+
|
|
4
|
+
import type {Env} from '../env.js';
|
|
5
|
+
import type {WalkContext} from './walk.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for deep cloning
|
|
9
|
+
*/
|
|
10
|
+
export interface CloneOptions {
|
|
11
|
+
/** Handle circular references (default: true in main API) */
|
|
12
|
+
circular?: boolean;
|
|
13
|
+
/** Clone symbol properties (default: false) */
|
|
14
|
+
symbols?: boolean;
|
|
15
|
+
/** Clone non-enumerable properties (default: false) */
|
|
16
|
+
allProps?: boolean;
|
|
17
|
+
/** Custom context object */
|
|
18
|
+
context?: Record<string, unknown>;
|
|
19
|
+
/** Custom object processor */
|
|
20
|
+
processObject?: (object: unknown, context: WalkContext) => void;
|
|
21
|
+
/** Custom non-object value processor */
|
|
22
|
+
processOther?: (value: unknown, context: WalkContext) => void;
|
|
23
|
+
/** Custom circular reference processor */
|
|
24
|
+
processCircular?: (value: unknown, context: WalkContext) => void;
|
|
25
|
+
/** Custom type handler registry (flat array of [Constructor, handler] pairs) */
|
|
26
|
+
registry?: unknown[];
|
|
27
|
+
/** Custom filter functions — return true to indicate value was handled */
|
|
28
|
+
filters?: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Flat array of type-specific cloner pairs: [Constructor, handler, Constructor, handler, ...]
|
|
33
|
+
*
|
|
34
|
+
* Use `registry.push(Type, handler)` to register a custom type cloner.
|
|
35
|
+
* Handler signature: `(val, context) => void` (push result to context.stackOut)
|
|
36
|
+
*/
|
|
37
|
+
export declare const registry: unknown[];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Filter functions for custom clone processing — return true to indicate value was handled
|
|
41
|
+
*/
|
|
42
|
+
export declare const filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Deep clones a value with circular reference handling
|
|
46
|
+
*
|
|
47
|
+
* @param source - Value to clone
|
|
48
|
+
* @param env - Optional Env for variable resolution, or options object
|
|
49
|
+
* @param options - Cloning options (when env is provided separately)
|
|
50
|
+
* @returns Deep copy of the value
|
|
51
|
+
*/
|
|
52
|
+
export declare const clone: (<T>(source: T, env?: Env | CloneOptions | null, options?: CloneOptions) => T) & {
|
|
53
|
+
registry: unknown[];
|
|
54
|
+
filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default clone;
|
|
@@ -45,7 +45,7 @@ const registry = [
|
|
|
45
45
|
Date,
|
|
46
46
|
(val, context) => context.stackOut.push(new Date(val.getTime())),
|
|
47
47
|
RegExp,
|
|
48
|
-
(val, context) => context.stackOut.push(new RegExp(val.source,
|
|
48
|
+
(val, context) => context.stackOut.push(new RegExp(val.source, val.flags)),
|
|
49
49
|
Map,
|
|
50
50
|
processMap(postProcessMap, postProcessMapSeen),
|
|
51
51
|
Promise,
|
|
@@ -53,6 +53,8 @@ const registry = [
|
|
|
53
53
|
],
|
|
54
54
|
filters = [];
|
|
55
55
|
|
|
56
|
+
typeof URL == 'function' && registry.push(URL, (val, context) => context.stackOut.push(new URL(val.href)));
|
|
57
|
+
|
|
56
58
|
// add more types
|
|
57
59
|
|
|
58
60
|
const addType = (Type, process) => registry.push(Type, process || ((val, context) => context.stackOut.push(new Type(val))));
|
|
@@ -105,5 +107,5 @@ const clone = (source, env, options) => {
|
|
|
105
107
|
clone.registry = registry;
|
|
106
108
|
clone.filters = filters;
|
|
107
109
|
|
|
108
|
-
export {registry, filters};
|
|
110
|
+
export {registry, filters, clone};
|
|
109
111
|
export default clone;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Type definitions for deep6 deref
|
|
2
|
+
// Generated from src/traverse/deref.js
|
|
3
|
+
|
|
4
|
+
import type {Env} from '../env.js';
|
|
5
|
+
import type {WalkContext} from './walk.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for dereferencing
|
|
9
|
+
*/
|
|
10
|
+
export interface DerefOptions {
|
|
11
|
+
/** Handle circular references (default: false) */
|
|
12
|
+
circular?: boolean;
|
|
13
|
+
/** Include symbol properties (default: false) */
|
|
14
|
+
symbols?: boolean;
|
|
15
|
+
/** Include non-enumerable properties (default: false) */
|
|
16
|
+
allProps?: boolean;
|
|
17
|
+
/** Custom context object */
|
|
18
|
+
context?: Record<string, unknown>;
|
|
19
|
+
/** Custom object processor */
|
|
20
|
+
processObject?: (object: unknown, context: WalkContext) => void;
|
|
21
|
+
/** Custom non-object value processor */
|
|
22
|
+
processOther?: (value: unknown, context: WalkContext) => void;
|
|
23
|
+
/** Custom circular reference processor */
|
|
24
|
+
processCircular?: (value: unknown, context: WalkContext) => void;
|
|
25
|
+
/** Custom type handler registry (flat array of [Constructor, handler] pairs) */
|
|
26
|
+
registry?: unknown[];
|
|
27
|
+
/** Custom filter functions */
|
|
28
|
+
filters?: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Flat array of type-specific deref pairs: [Constructor, handler, ...]
|
|
33
|
+
*
|
|
34
|
+
* Use `registry.push(Type, handler)` to register a custom handler.
|
|
35
|
+
*/
|
|
36
|
+
export declare const registry: unknown[];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Filter functions for custom deref processing
|
|
40
|
+
*/
|
|
41
|
+
export declare const filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Replaces variables with bound values in-place
|
|
45
|
+
*
|
|
46
|
+
* Unlike assemble(), modifies the existing structure directly
|
|
47
|
+
* rather than creating a new one.
|
|
48
|
+
*
|
|
49
|
+
* @param source - Value to dereference (modified in-place)
|
|
50
|
+
* @param env - Env with bindings, or options object
|
|
51
|
+
* @param options - Deref options (when env is provided separately)
|
|
52
|
+
* @returns The same source value with variables replaced
|
|
53
|
+
*/
|
|
54
|
+
export declare const deref: ((source: unknown, env?: Env | DerefOptions | null, options?: DerefOptions) => unknown) & {
|
|
55
|
+
registry: unknown[];
|
|
56
|
+
filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default deref;
|
|
@@ -22,7 +22,7 @@ function postProcessMap(context) {
|
|
|
22
22
|
const stackOut = context.stackOut,
|
|
23
23
|
s = this.s;
|
|
24
24
|
let j = stackOut.length - 1;
|
|
25
|
-
for (const key of s) {
|
|
25
|
+
for (const key of s.keys()) {
|
|
26
26
|
s.set(key, stackOut[j--]);
|
|
27
27
|
}
|
|
28
28
|
replaceObject(j, s, stackOut);
|
|
@@ -54,6 +54,7 @@ const registry = [
|
|
|
54
54
|
|
|
55
55
|
const addType = (Type, process) => registry.push(Type, process || processOther);
|
|
56
56
|
|
|
57
|
+
typeof URL == 'function' && addType(URL);
|
|
57
58
|
typeof Int8Array == 'function' && addType(Int8Array);
|
|
58
59
|
typeof Uint8Array == 'function' && addType(Uint8Array);
|
|
59
60
|
typeof Uint8ClampedArray == 'function' && addType(Uint8ClampedArray);
|
|
@@ -100,5 +101,5 @@ const deref = (source, env, options) => {
|
|
|
100
101
|
deref.registry = registry;
|
|
101
102
|
deref.filters = filters;
|
|
102
103
|
|
|
103
|
-
export {registry, filters};
|
|
104
|
+
export {registry, filters, deref};
|
|
104
105
|
export default deref;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Type definitions for deep6 preprocess
|
|
2
|
+
// Generated from src/traverse/preprocess.js
|
|
3
|
+
|
|
4
|
+
import type {WalkContext} from './walk.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for pattern preprocessing
|
|
8
|
+
*/
|
|
9
|
+
export interface PreprocessOptions {
|
|
10
|
+
/** Wrap plain objects with open() (default: false) */
|
|
11
|
+
openObjects?: boolean;
|
|
12
|
+
/** Wrap arrays with open() (default: false) */
|
|
13
|
+
openArrays?: boolean;
|
|
14
|
+
/** Wrap Maps with open() (default: false) */
|
|
15
|
+
openMaps?: boolean;
|
|
16
|
+
/** Wrap Sets with open() (default: false) */
|
|
17
|
+
openSets?: boolean;
|
|
18
|
+
/** Handle circular references */
|
|
19
|
+
circular?: boolean;
|
|
20
|
+
/** Include symbol properties */
|
|
21
|
+
symbols?: boolean;
|
|
22
|
+
/** Include non-enumerable properties */
|
|
23
|
+
allProps?: boolean;
|
|
24
|
+
/** Custom context object */
|
|
25
|
+
context?: Record<string, unknown>;
|
|
26
|
+
/** Custom object processor */
|
|
27
|
+
processObject?: (object: unknown, context: WalkContext) => void;
|
|
28
|
+
/** Custom non-object value processor */
|
|
29
|
+
processOther?: (value: unknown, context: WalkContext) => void;
|
|
30
|
+
/** Custom circular reference processor */
|
|
31
|
+
processCircular?: (value: unknown, context: WalkContext) => void;
|
|
32
|
+
/** Custom type handler registry (flat array of [Constructor, handler] pairs) */
|
|
33
|
+
registry?: unknown[];
|
|
34
|
+
/** Custom filter functions */
|
|
35
|
+
filters?: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Flat array of type-specific preprocessor pairs: [Constructor, handler, ...]
|
|
40
|
+
*
|
|
41
|
+
* Use `registry.push(Type, handler)` to register a custom preprocessor.
|
|
42
|
+
*/
|
|
43
|
+
export declare const registry: unknown[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Filter functions for custom preprocessing
|
|
47
|
+
*/
|
|
48
|
+
export declare const filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Preprocesses a pattern for unification
|
|
52
|
+
*
|
|
53
|
+
* Wraps objects, arrays, Maps, and Sets with open/soft markers
|
|
54
|
+
* based on options. Used internally by match().
|
|
55
|
+
*
|
|
56
|
+
* @param source - Pattern to preprocess
|
|
57
|
+
* @param options - Preprocessing options
|
|
58
|
+
* @returns Preprocessed pattern ready for unification
|
|
59
|
+
*/
|
|
60
|
+
export declare const preprocess: ((source: unknown, options?: PreprocessOptions) => unknown) & {
|
|
61
|
+
registry: unknown[];
|
|
62
|
+
filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default preprocess;
|
|
@@ -63,6 +63,7 @@ const registry = [
|
|
|
63
63
|
|
|
64
64
|
const addType = (Type, process) => registry.push(Type, process || processOther);
|
|
65
65
|
|
|
66
|
+
typeof URL == 'function' && addType(URL);
|
|
66
67
|
typeof Int8Array == 'function' && addType(Int8Array);
|
|
67
68
|
typeof Uint8Array == 'function' && addType(Uint8Array);
|
|
68
69
|
typeof Uint8ClampedArray == 'function' && addType(Uint8ClampedArray);
|
|
@@ -108,5 +109,5 @@ const preprocess = (source, options) => {
|
|
|
108
109
|
preprocess.registry = registry;
|
|
109
110
|
preprocess.filters = filters;
|
|
110
111
|
|
|
111
|
-
export {registry, filters};
|
|
112
|
+
export {registry, filters, preprocess};
|
|
112
113
|
export default preprocess;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Type definitions for deep6 walk
|
|
2
|
+
// Generated from src/traverse/walk.js
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Context object available during walk traversal
|
|
6
|
+
*/
|
|
7
|
+
export interface WalkContext {
|
|
8
|
+
/** Stack of values to process */
|
|
9
|
+
stack: unknown[];
|
|
10
|
+
/** Output stack for processed values */
|
|
11
|
+
stackOut: unknown[];
|
|
12
|
+
/** Map tracking circular references (present when circular: true) */
|
|
13
|
+
seen: Map<unknown, {value?: unknown; actions?: Array<[unknown, unknown]>}> | null;
|
|
14
|
+
/** Include symbol properties */
|
|
15
|
+
symbols?: boolean;
|
|
16
|
+
/** Include non-enumerable properties */
|
|
17
|
+
allProps?: boolean;
|
|
18
|
+
/** Optional environment for variable handling */
|
|
19
|
+
env?: unknown;
|
|
20
|
+
/** Wrapper for Maps (set by preprocess) */
|
|
21
|
+
wrapMap?: (map: Map<unknown, unknown>) => unknown;
|
|
22
|
+
/** Wrapper for Arrays (set by preprocess) */
|
|
23
|
+
wrapArray?: (array: unknown[]) => unknown;
|
|
24
|
+
/** Wrapper for Objects (set by preprocess) */
|
|
25
|
+
wrapObject?: (object: unknown) => unknown;
|
|
26
|
+
/** Wrapper for Sets (set by preprocess) */
|
|
27
|
+
wrapSet?: (set: Set<unknown>) => unknown;
|
|
28
|
+
/** Additional context properties */
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Options for walk traversal
|
|
34
|
+
*/
|
|
35
|
+
export interface WalkOptions {
|
|
36
|
+
/** Custom object processor */
|
|
37
|
+
processObject?: (object: unknown, context: WalkContext) => void;
|
|
38
|
+
/** Custom non-object value processor */
|
|
39
|
+
processOther?: (value: unknown, context: WalkContext) => void;
|
|
40
|
+
/** Custom circular reference processor */
|
|
41
|
+
processCircular?: (value: unknown, context: WalkContext) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Flat array of type handler pairs: [Constructor, handler, Constructor, handler, ...]
|
|
44
|
+
*
|
|
45
|
+
* Each pair maps a constructor to a processing function.
|
|
46
|
+
*/
|
|
47
|
+
registry?: unknown[];
|
|
48
|
+
/** Array of filter functions — return true to indicate value was handled */
|
|
49
|
+
filters?: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
50
|
+
/** Enable circular reference detection */
|
|
51
|
+
circular?: boolean;
|
|
52
|
+
/** Include symbol properties */
|
|
53
|
+
symbols?: boolean;
|
|
54
|
+
/** Include non-enumerable properties */
|
|
55
|
+
allProps?: boolean;
|
|
56
|
+
/** Custom context object (properties are merged into WalkContext) */
|
|
57
|
+
context?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Marker for values that were already seen (circular references)
|
|
62
|
+
*/
|
|
63
|
+
export declare class Circular {
|
|
64
|
+
/** The already-seen value */
|
|
65
|
+
value: unknown;
|
|
66
|
+
constructor(value: unknown);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Deferred processing command pushed onto the walk stack
|
|
71
|
+
*/
|
|
72
|
+
export declare class Command {
|
|
73
|
+
/** Function to execute during post-processing */
|
|
74
|
+
f: (context: WalkContext) => void;
|
|
75
|
+
/** Source object being processed */
|
|
76
|
+
s: unknown;
|
|
77
|
+
constructor(f: (context: WalkContext) => void, s: unknown);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Non-recursive stack-based object tree walker
|
|
82
|
+
*
|
|
83
|
+
* Traverses values using an explicit stack with support for
|
|
84
|
+
* circular references, type registries, and filters.
|
|
85
|
+
*
|
|
86
|
+
* @param o - Value to traverse
|
|
87
|
+
* @param options - Walk options and processors
|
|
88
|
+
*/
|
|
89
|
+
export declare const walk: ((o: unknown, options?: WalkOptions) => void) & {
|
|
90
|
+
Command: typeof Command;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Default type handler registry (flat array of [Constructor, handler] pairs)
|
|
95
|
+
*/
|
|
96
|
+
export declare const registry: unknown[];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Default filter functions
|
|
100
|
+
*/
|
|
101
|
+
export declare const filters: Array<(val: unknown, context: WalkContext) => boolean>;
|
|
102
|
+
|
|
103
|
+
// Utility processors
|
|
104
|
+
|
|
105
|
+
/** Pushes value to stackOut unchanged */
|
|
106
|
+
export declare const processOther: (value: unknown, context: WalkContext) => void;
|
|
107
|
+
|
|
108
|
+
/** Pushes a Circular marker to stackOut */
|
|
109
|
+
export declare const processCircular: (value: unknown, context: WalkContext) => void;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Creates a Map processor with optional post-processing
|
|
113
|
+
* @param postProcess - Post-processor for normal flow
|
|
114
|
+
* @param postProcessSeen - Post-processor when circular refs are tracked
|
|
115
|
+
* @returns Map processing function
|
|
116
|
+
*/
|
|
117
|
+
export declare const processMap: (
|
|
118
|
+
postProcess?: (context: WalkContext) => void,
|
|
119
|
+
postProcessSeen?: (context: WalkContext) => void
|
|
120
|
+
) => (object: Map<unknown, unknown>, context: WalkContext) => void;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Post-processes a Map with circular reference resolution
|
|
124
|
+
* @param source - Original Map
|
|
125
|
+
* @param context - Walk context
|
|
126
|
+
*/
|
|
127
|
+
export declare const postMapCircular: (source: Map<unknown, unknown>, context: WalkContext) => void;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Builds a new Map from processed values on stackOut
|
|
131
|
+
* @param keys - Keys for the new Map
|
|
132
|
+
* @param stackOut - Output stack with values
|
|
133
|
+
* @param wrap - Optional wrapper function
|
|
134
|
+
*/
|
|
135
|
+
export declare const buildNewMap: (keys: Iterable<unknown>, stackOut: unknown[], wrap?: (map: Map<unknown, unknown>) => unknown) => void;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Replaces stackOut entries from upTo to end with a single object
|
|
139
|
+
* @param upTo - Index offset from end
|
|
140
|
+
* @param object - Object to push
|
|
141
|
+
* @param stackOut - Output stack
|
|
142
|
+
*/
|
|
143
|
+
export declare const replaceObject: (upTo: number, object: unknown, stackOut: unknown[]) => void;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Creates an Object processor with optional post-processing
|
|
147
|
+
* @param postProcess - Post-processor for normal flow
|
|
148
|
+
* @param postProcessSeen - Post-processor when circular refs are tracked
|
|
149
|
+
* @returns Object processing function
|
|
150
|
+
*/
|
|
151
|
+
export declare const processObject: (
|
|
152
|
+
postProcess?: (context: WalkContext) => void,
|
|
153
|
+
postProcessSeen?: (context: WalkContext) => void
|
|
154
|
+
) => (object: unknown, context: WalkContext) => void;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Post-processes an Object with circular reference resolution
|
|
158
|
+
* @param source - Original object
|
|
159
|
+
* @param descriptors - Property descriptors
|
|
160
|
+
* @param keys - Property keys
|
|
161
|
+
* @param context - Walk context
|
|
162
|
+
*/
|
|
163
|
+
export declare const postObjectCircular: (
|
|
164
|
+
source: unknown,
|
|
165
|
+
descriptors: Record<string | symbol, PropertyDescriptor>,
|
|
166
|
+
keys: Array<string | symbol>,
|
|
167
|
+
context: WalkContext
|
|
168
|
+
) => void;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Extracts property descriptors and keys from an object
|
|
172
|
+
* @param object - Object to analyze
|
|
173
|
+
* @param context - Walk context (uses symbols and allProps flags)
|
|
174
|
+
* @returns Descriptors and keys
|
|
175
|
+
*/
|
|
176
|
+
export declare const getObjectData: (
|
|
177
|
+
object: unknown,
|
|
178
|
+
context: WalkContext
|
|
179
|
+
) => {descriptors: Record<string | symbol, PropertyDescriptor>; keys: Array<string | symbol>};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Builds a new object from processed values on stackOut
|
|
183
|
+
* @param source - Original object (used for prototype and array detection)
|
|
184
|
+
* @param descriptors - Property descriptors
|
|
185
|
+
* @param keys - Property keys
|
|
186
|
+
* @param stackOut - Output stack with values
|
|
187
|
+
* @param wrap - Optional wrapper function
|
|
188
|
+
*/
|
|
189
|
+
export declare const buildNewObject: (
|
|
190
|
+
source: unknown,
|
|
191
|
+
descriptors: Record<string | symbol, PropertyDescriptor>,
|
|
192
|
+
keys: Array<string | symbol>,
|
|
193
|
+
stackOut: unknown[],
|
|
194
|
+
wrap?: (object: unknown) => unknown
|
|
195
|
+
) => void;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Resolves a Variable to its bound value and pushes to the stack
|
|
199
|
+
* @param val - Variable instance
|
|
200
|
+
* @param context - Walk context (uses context.env)
|
|
201
|
+
*/
|
|
202
|
+
export declare const processVariable: (val: unknown, context: WalkContext) => void;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Executes a Command's function
|
|
206
|
+
* @param val - Command instance
|
|
207
|
+
* @param context - Walk context
|
|
208
|
+
*/
|
|
209
|
+
export declare const processCommand: (val: unknown, context: WalkContext) => void;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Resolves circular reference actions for a seen object
|
|
213
|
+
* @param seen - Map of seen objects
|
|
214
|
+
* @param source - Source object
|
|
215
|
+
* @param value - Resolved value
|
|
216
|
+
*/
|
|
217
|
+
export declare const setObject: (seen: Map<unknown, {value?: unknown; actions?: Array<[unknown, unknown]>}>, source: unknown, value: unknown) => void;
|
|
218
|
+
|
|
219
|
+
export default walk;
|