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.
Files changed (43) hide show
  1. package/README.md +3 -1
  2. package/TESTING.md +246 -47
  3. package/bin/tape6-server.js +19 -19
  4. package/index.d.ts +67 -0
  5. package/llms-full.txt +102 -0
  6. package/llms.txt +66 -0
  7. package/package.json +13 -4
  8. package/skills/write-tests/SKILL.md +63 -16
  9. package/src/State.js +26 -21
  10. package/src/Tester.js +59 -27
  11. package/src/deep6/env.d.ts +174 -0
  12. package/src/deep6/env.js +4 -4
  13. package/src/deep6/index.d.ts +86 -0
  14. package/src/deep6/index.js +10 -7
  15. package/src/deep6/traverse/assemble.d.ts +59 -0
  16. package/src/deep6/traverse/assemble.js +4 -3
  17. package/src/deep6/traverse/clone.d.ts +57 -0
  18. package/src/deep6/traverse/clone.js +4 -2
  19. package/src/deep6/traverse/deref.d.ts +59 -0
  20. package/src/deep6/traverse/deref.js +3 -2
  21. package/src/deep6/traverse/preprocess.d.ts +65 -0
  22. package/src/deep6/traverse/preprocess.js +2 -1
  23. package/src/deep6/traverse/walk.d.ts +219 -0
  24. package/src/deep6/traverse/walk.js +9 -4
  25. package/src/deep6/unifiers/matchCondition.d.ts +45 -0
  26. package/src/deep6/unifiers/matchCondition.js +1 -0
  27. package/src/deep6/unifiers/matchInstanceOf.d.ts +37 -0
  28. package/src/deep6/unifiers/matchInstanceOf.js +1 -0
  29. package/src/deep6/unifiers/matchString.d.ts +56 -0
  30. package/src/deep6/unifiers/matchString.js +1 -0
  31. package/src/deep6/unifiers/matchTypeOf.d.ts +37 -0
  32. package/src/deep6/unifiers/matchTypeOf.js +1 -0
  33. package/src/deep6/unifiers/ref.d.ts +52 -0
  34. package/src/deep6/unifiers/ref.js +1 -0
  35. package/src/deep6/unify.d.ts +95 -0
  36. package/src/deep6/unify.js +130 -66
  37. package/src/deep6/utils/replaceVars.d.ts +25 -0
  38. package/src/deep6/utils/replaceVars.js +23 -19
  39. package/src/response.d.ts +43 -0
  40. package/src/response.js +57 -0
  41. package/src/server.d.ts +81 -0
  42. package/src/server.js +69 -0
  43. package/src/test.js +26 -53
@@ -34,7 +34,10 @@ const processCircular = (value, context) => context.stackOut.push(new Circular(v
34
34
 
35
35
  const processMap = (postProcess, postProcessSeen) => (object, context) => {
36
36
  const stack = context.stack;
37
- postProcess && stack.push(new Command(postProcessSeen ? (context.seen ? postProcessSeen : postProcess) : postProcess, object));
37
+ if (postProcess) {
38
+ const processor = context.seen && postProcessSeen ? postProcessSeen : postProcess;
39
+ stack.push(new Command(processor, object));
40
+ }
38
41
  for (const value of object.values()) {
39
42
  stack.push(value);
40
43
  }
@@ -170,8 +173,9 @@ class Command {
170
173
 
171
174
  const processCommand = (val, context) => val.f(context);
172
175
 
173
- const defaultRegistry = [Command, processCommand, Array, processObject(), Date, nop, RegExp, nop, Map, processMap(), Set, nop, Promise, nop],
174
- defaultFilters = [];
176
+ const defaultRegistry = [Command, processCommand, Array, processObject(), Date, nop, RegExp, nop, Map, processMap(), Set, nop, Promise, nop];
177
+ typeof URL == 'function' && defaultRegistry.push(URL, nop);
178
+ const defaultFilters = [];
175
179
 
176
180
  // add more types
177
181
 
@@ -257,6 +261,7 @@ export {
257
261
  getObjectData,
258
262
  buildNewObject,
259
263
  processVariable,
260
- processCommand
264
+ processCommand,
265
+ walk
261
266
  };
262
267
  export default walk;
@@ -0,0 +1,45 @@
1
+ // Type definitions for deep6 matchCondition unifier
2
+ // Generated from src/unifiers/matchCondition.js
3
+
4
+ import type {Unifier, Env} from '../env.js';
5
+
6
+ /**
7
+ * Predicate-based matching unifier
8
+ *
9
+ * Delegates matching to a user-supplied function that receives
10
+ * the full unification context (value, stacks, environment).
11
+ */
12
+ export declare class MatchCondition extends Unifier {
13
+ /** Predicate function */
14
+ f: (val: unknown, ls: unknown[], rs: unknown[], env: Env) => boolean;
15
+
16
+ /**
17
+ * @param f - Predicate that returns true if the value matches
18
+ */
19
+ constructor(f: (val: unknown, ls: unknown[], rs: unknown[], env: Env) => boolean);
20
+
21
+ /**
22
+ * Delegates to the predicate function
23
+ * @param val - Value to test
24
+ * @param ls - Left argument stack
25
+ * @param rs - Right argument stack
26
+ * @param env - Unification environment
27
+ * @returns Result of the predicate
28
+ */
29
+ unify(val: unknown, ls: unknown[], rs: unknown[], env: Env): boolean;
30
+ }
31
+
32
+ /**
33
+ * Creates a predicate matcher
34
+ *
35
+ * @param f - Predicate function `(val, ls, rs, env) => boolean`
36
+ * @returns A new MatchCondition instance
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const isPositive = matchCondition(val => typeof val === 'number' && val > 0);
41
+ * match({n: 5}, {n: isPositive}); // true
42
+ * ```
43
+ */
44
+ export declare const matchCondition: (f: (val: unknown, ls: unknown[], rs: unknown[], env: Env) => boolean) => MatchCondition;
45
+ export default matchCondition;
@@ -13,4 +13,5 @@ class MatchCondition extends Unifier {
13
13
 
14
14
  const matchCondition = f => new MatchCondition(f);
15
15
 
16
+ export {matchCondition};
16
17
  export default matchCondition;
@@ -0,0 +1,37 @@
1
+ // Type definitions for deep6 matchInstanceOf unifier
2
+ // Generated from src/unifiers/matchInstanceOf.js
3
+
4
+ import type {Unifier} from '../env.js';
5
+
6
+ /**
7
+ * Instanceof-based matching unifier
8
+ *
9
+ * Matches values by their prototype chain. Rejects falsy values and unbound Variables.
10
+ */
11
+ export declare class MatchInstanceOf extends Unifier {
12
+ /** Array of constructors to match against */
13
+ types: (new (...args: any[]) => unknown)[];
14
+
15
+ /**
16
+ * @param types - Constructor or array of constructors
17
+ */
18
+ constructor(types: (new (...args: any[]) => unknown) | (new (...args: any[]) => unknown)[]);
19
+
20
+ /**
21
+ * Tests if the value is an instance of one of the configured constructors
22
+ * @param val - Value to check
23
+ * @param ls - Left argument stack (unused)
24
+ * @param rs - Right argument stack (unused)
25
+ * @returns True if val is an instance of any configured type
26
+ */
27
+ unify(val: unknown, ls: unknown[], rs: unknown[]): boolean;
28
+ }
29
+
30
+ /**
31
+ * Creates an instanceof matcher
32
+ *
33
+ * @param types - Constructor(s) to match against
34
+ * @returns A new MatchInstanceOf instance
35
+ */
36
+ export declare const matchInstanceOf: (types: (new (...args: any[]) => unknown) | (new (...args: any[]) => unknown)[]) => MatchInstanceOf;
37
+ export default matchInstanceOf;
@@ -13,4 +13,5 @@ class MatchInstanceOf extends Unifier {
13
13
 
14
14
  const matchInstanceOf = types => new MatchInstanceOf(types);
15
15
 
16
+ export {matchInstanceOf};
16
17
  export default matchInstanceOf;
@@ -0,0 +1,56 @@
1
+ // Type definitions for deep6 matchString unifier
2
+ // Generated from src/unifiers/matchString.js
3
+
4
+ import type {Unifier} from '../env.js';
5
+
6
+ /**
7
+ * RegExp-based string matching unifier
8
+ *
9
+ * Matches values against a regular expression. Optionally captures
10
+ * the match array and match properties (index, input) for variable binding.
11
+ */
12
+ export declare class MatchString extends Unifier {
13
+ /** Regular expression to match against */
14
+ regexp: RegExp;
15
+ /** Pattern to unify with the match result array (optional) */
16
+ matches?: unknown;
17
+ /** Pattern to unify with match properties {index, input} (optional) */
18
+ props?: unknown;
19
+
20
+ /**
21
+ * @param regexp - Regular expression to match
22
+ * @param matches - Pattern to unify with match array (optional)
23
+ * @param props - Pattern to unify with {index, input} (optional)
24
+ */
25
+ constructor(regexp: RegExp, matches?: unknown, props?: unknown);
26
+
27
+ /**
28
+ * Tests a value against the regex and pushes capture bindings
29
+ * @param val - Value to match (coerced to string)
30
+ * @param ls - Left argument stack
31
+ * @param rs - Right argument stack
32
+ * @returns Truthy if the regex matches
33
+ */
34
+ unify(val: unknown, ls: unknown[], rs: unknown[]): boolean;
35
+ }
36
+
37
+ /**
38
+ * Creates a regex string matcher
39
+ *
40
+ * @param regexp - Regular expression to match against
41
+ * @param matches - Pattern to unify with the full match array (optional)
42
+ * @param props - Pattern to unify with {index, input} (optional)
43
+ * @returns A new MatchString instance
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * // Simple matching
48
+ * matchString(/^hello/i);
49
+ *
50
+ * // With captures bound to a variable array
51
+ * const names = [any, variable('first'), variable('last')];
52
+ * matchString(/^(\w+)\s+(\w+)$/, names);
53
+ * ```
54
+ */
55
+ export declare const matchString: (regexp: RegExp, matches?: unknown, props?: unknown) => MatchString;
56
+ export default matchString;
@@ -30,4 +30,5 @@ class MatchString extends Unifier {
30
30
 
31
31
  const matchString = (regexp, matches, props) => new MatchString(regexp, matches, props);
32
32
 
33
+ export {matchString};
33
34
  export default matchString;
@@ -0,0 +1,37 @@
1
+ // Type definitions for deep6 matchTypeOf unifier
2
+ // Generated from src/unifiers/matchTypeOf.js
3
+
4
+ import type {Unifier} from '../env.js';
5
+
6
+ /**
7
+ * Type-based matching unifier
8
+ *
9
+ * Matches values by their `typeof` result. Rejects unbound Variables.
10
+ */
11
+ export declare class MatchTypeOf extends Unifier {
12
+ /** Array of type names to match against */
13
+ types: string[];
14
+
15
+ /**
16
+ * @param types - Type name or array of type names
17
+ */
18
+ constructor(types: string | string[]);
19
+
20
+ /**
21
+ * Tests if the value's typeof matches one of the configured types
22
+ * @param val - Value to check
23
+ * @param ls - Left argument stack (unused)
24
+ * @param rs - Right argument stack (unused)
25
+ * @returns True if typeof val matches
26
+ */
27
+ unify(val: unknown, ls: unknown[], rs: unknown[]): boolean;
28
+ }
29
+
30
+ /**
31
+ * Creates a typeof matcher
32
+ *
33
+ * @param types - Type name(s) to match against (e.g. 'string', ['number', 'bigint'])
34
+ * @returns A new MatchTypeOf instance
35
+ */
36
+ export declare const matchTypeOf: (types: string | string[]) => MatchTypeOf;
37
+ export default matchTypeOf;
@@ -13,4 +13,5 @@ class MatchTypeOf extends Unifier {
13
13
 
14
14
  const matchTypeOf = types => new MatchTypeOf(types);
15
15
 
16
+ export {matchTypeOf};
16
17
  export default matchTypeOf;
@@ -0,0 +1,52 @@
1
+ // Type definitions for deep6 ref unifier
2
+ // Generated from src/unifiers/ref.js
3
+
4
+ import type {Variable, Env} from '../env.js';
5
+
6
+ /**
7
+ * Reference unifier for cross-pattern variable binding
8
+ *
9
+ * Binds both a variable and a value to the same input during unification.
10
+ * Pushes `(this.value, val)` and `(this.variable, val)` onto the stacks.
11
+ */
12
+ export declare class Ref extends Variable {
13
+ /** The variable being referenced */
14
+ variable: Variable;
15
+ /** The value pattern to unify against */
16
+ value: unknown;
17
+
18
+ /**
19
+ * @param variable - Variable name (string) or Variable instance
20
+ * @param value - Value pattern to bind alongside the variable
21
+ */
22
+ constructor(variable: string | Variable, value: unknown);
23
+
24
+ /**
25
+ * Pushes value and variable bindings onto the stacks
26
+ * @param val - Input value
27
+ * @param ls - Left argument stack
28
+ * @param rs - Right argument stack
29
+ * @param env - Unification environment
30
+ * @returns Always true
31
+ */
32
+ unify(val: unknown, ls: unknown[], rs: unknown[], env: Env): boolean;
33
+ }
34
+
35
+ /**
36
+ * Creates a reference unifier
37
+ *
38
+ * @param variable - Variable name or Variable instance
39
+ * @param value - Value pattern to bind alongside the variable
40
+ * @returns A new Ref instance
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const r = ref('x', variable('y'));
45
+ * // During unification, both 'x' and 'y' get bound to the matched value
46
+ * ```
47
+ */
48
+ export declare const ref: ((variable: string | Variable, value: unknown) => Ref) & {
49
+ Ref: typeof Ref;
50
+ };
51
+
52
+ export default ref;
@@ -18,4 +18,5 @@ class Ref extends Variable {
18
18
  const ref = (variable, value) => new Ref(variable, value);
19
19
  ref.Ref = Ref;
20
20
 
21
+ export {ref};
21
22
  export default ref;
@@ -0,0 +1,95 @@
1
+ // Type definitions for deep6 unification
2
+ // Generated from src/unify.js
3
+
4
+ import {Env, Unifier, Variable} from './env.js';
5
+
6
+ /**
7
+ * Options for unification
8
+ */
9
+ export interface UnifyOptions {
10
+ /** Handle circular references (default: false) */
11
+ circular?: boolean;
12
+ /** Include symbol properties (default: false) */
13
+ symbols?: boolean;
14
+ /** Use loose equality for primitives (default: false) */
15
+ loose?: boolean;
16
+ /** Ignore function properties (default: false) */
17
+ ignoreFunctions?: boolean;
18
+ /** Distinguish +0 from -0 (default: false) */
19
+ signedZero?: boolean;
20
+ /** Allow extra keys on target objects (default: false) */
21
+ openObjects?: boolean;
22
+ /** Allow extra elements in target arrays (default: false) */
23
+ openArrays?: boolean;
24
+ /** Allow extra entries in target Maps (default: false) */
25
+ openMaps?: boolean;
26
+ /** Allow extra entries in target Sets (default: false) */
27
+ openSets?: boolean;
28
+ }
29
+
30
+ /**
31
+ * Core unification algorithm
32
+ *
33
+ * Attempts to unify two values, optionally binding variables.
34
+ * Returns an Env with bindings on success, or null on failure.
35
+ *
36
+ * @param l - Left value
37
+ * @param r - Right value
38
+ * @param env - Existing environment, options object, or null
39
+ * @param options - Unification options (when env is provided separately)
40
+ * @returns Environment with bindings, or null on failure
41
+ */
42
+ export declare const unify: (l: unknown, r: unknown, env?: Env | UnifyOptions | null, options?: UnifyOptions) => Env | null;
43
+
44
+ /**
45
+ * Flat array of type-specific unifier pairs: [Constructor, handler, Constructor, handler, ...]
46
+ *
47
+ * Use `registry.push(Type, handler)` to register a custom type handler.
48
+ * Handler signature: `(l, r, ls, rs, env) => boolean`
49
+ */
50
+ export declare const registry: unknown[];
51
+
52
+ /**
53
+ * Flat array of filter pairs: [predicate, handler, predicate, handler, ...]
54
+ *
55
+ * Use `filters.push(predicate, handler)` to register a custom filter.
56
+ */
57
+ export declare const filters: unknown[];
58
+
59
+ /**
60
+ * Wraps a value for open matching (target may have extra properties)
61
+ * @param o - Value to wrap
62
+ * @returns Open-wrapped value
63
+ */
64
+ export declare const open: <T>(o: T) => T;
65
+
66
+ /**
67
+ * Wraps a value for soft matching (bidirectional open, updates both sides)
68
+ * @param o - Value to wrap
69
+ * @returns Soft-wrapped value
70
+ */
71
+ export declare const soft: <T>(o: T) => T;
72
+
73
+ /**
74
+ * Checks if a value is open-wrapped
75
+ * @param o - Value to check
76
+ */
77
+ export declare const isOpen: (o: unknown) => boolean;
78
+
79
+ /**
80
+ * Checks if a value is soft-wrapped
81
+ * @param o - Value to check
82
+ */
83
+ export declare const isSoft: (o: unknown) => boolean;
84
+
85
+ /**
86
+ * Checks if a value is wrapped (open or soft)
87
+ * @param o - Value to check
88
+ */
89
+ export declare const isWrapped: (o: unknown) => boolean;
90
+
91
+ // Re-exports from env.js (value exports, usable as constructors)
92
+ export {Env, Unifier, Variable} from './env.js';
93
+ export {_, any, isUnifier, isVariable, variable} from './env.js';
94
+
95
+ export default unify;