stringent 0.0.2 → 0.0.4
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 +61 -73
- package/dist/context.d.ts +20 -2
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +1 -0
- package/dist/context.js.map +1 -0
- package/dist/createParser.d.ts +109 -26
- package/dist/createParser.d.ts.map +1 -0
- package/dist/createParser.js +80 -19
- package/dist/createParser.js.map +1 -0
- package/dist/errors.d.ts +121 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +186 -0
- package/dist/errors.js.map +1 -0
- package/dist/grammar/index.d.ts +19 -14
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +4 -3
- package/dist/grammar/index.js.map +1 -0
- package/dist/index.d.ts +19 -11
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -0
- package/dist/parse/index.d.ts +101 -27
- package/dist/parse/index.d.ts.map +1 -0
- package/dist/parse/index.js +1 -0
- package/dist/parse/index.js.map +1 -0
- package/dist/performance.bench.d.ts +10 -0
- package/dist/performance.bench.d.ts.map +1 -0
- package/dist/performance.bench.js +379 -0
- package/dist/performance.bench.js.map +1 -0
- package/dist/primitive/index.d.ts +27 -35
- package/dist/primitive/index.d.ts.map +1 -0
- package/dist/primitive/index.js +22 -17
- package/dist/primitive/index.js.map +1 -0
- package/dist/runtime/eval.d.ts +157 -0
- package/dist/runtime/eval.d.ts.map +1 -0
- package/dist/runtime/eval.js +206 -0
- package/dist/runtime/eval.js.map +1 -0
- package/dist/runtime/infer.d.ts +2 -1
- package/dist/runtime/infer.d.ts.map +1 -0
- package/dist/runtime/infer.js +3 -2
- package/dist/runtime/infer.js.map +1 -0
- package/dist/runtime/parser.d.ts +92 -11
- package/dist/runtime/parser.d.ts.map +1 -0
- package/dist/runtime/parser.js +522 -47
- package/dist/runtime/parser.js.map +1 -0
- package/dist/schema/index.d.ts +230 -27
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +54 -28
- package/dist/schema/index.js.map +1 -0
- package/dist/static/infer.d.ts +4 -3
- package/dist/static/infer.d.ts.map +1 -0
- package/dist/static/infer.js +1 -0
- package/dist/static/infer.js.map +1 -0
- package/package.json +35 -4
- package/dist/combinators/index.d.ts +0 -57
- package/dist/combinators/index.js +0 -104
- package/dist/static/parser.d.ts +0 -7
- package/dist/static/parser.js +0 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.bench.js","sourceRoot":"","sources":["../src/performance.bench.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEhF,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,2BAA2B;AAC3B,MAAM,GAAG,GAAG,UAAU,CAAC;IACrB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAC7E,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,QAAQ;CACrB,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,UAAU,CAAC;IACrB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAC7E,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,QAAQ;CACrB,CA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pD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -10,61 +10,49 @@
|
|
|
10
10
|
* DO NOT remove the $ generic parameter - it ensures schema type information
|
|
11
11
|
* flows through the parser chain. See CLAUDE.md for details.
|
|
12
12
|
*/
|
|
13
|
-
import { Token } from
|
|
14
|
-
import type { Context } from
|
|
15
|
-
import type { ToNumber } from
|
|
16
|
-
export type { Context } from
|
|
13
|
+
import { Token } from '@sinclair/parsebox';
|
|
14
|
+
import type { Context } from '../context.js';
|
|
15
|
+
import type { ToNumber } from 'hotscript/dist/internals/numbers/impl/utils.js';
|
|
16
|
+
export type { Context } from '../context.js';
|
|
17
17
|
/** Parse result: empty = no match, [value, rest] = matched */
|
|
18
18
|
export type ParseResult<T, R extends string = string> = [] | [T, R];
|
|
19
19
|
export interface ASTNode<TType extends string = string, TOutputSchema = unknown> {
|
|
20
20
|
node: TType;
|
|
21
21
|
outputSchema: TOutputSchema;
|
|
22
22
|
}
|
|
23
|
-
export interface IdentNode<TName extends string = string, TOutputSchema =
|
|
23
|
+
export interface IdentNode<TName extends string = string, TOutputSchema = 'unknown'> extends ASTNode<'identifier', TOutputSchema> {
|
|
24
24
|
name: TName;
|
|
25
25
|
}
|
|
26
|
-
export type NumberNode<TValue extends string = string> = ASTNode<
|
|
26
|
+
export type NumberNode<TValue extends string = string> = ASTNode<'literal', 'number'> & {
|
|
27
27
|
raw: TValue;
|
|
28
28
|
value: ToNumber<TValue>;
|
|
29
29
|
};
|
|
30
|
-
export type StringNode<TValue extends string = string> = ASTNode<
|
|
30
|
+
export type StringNode<TValue extends string = string> = ASTNode<'literal', 'string'> & {
|
|
31
31
|
raw: TValue;
|
|
32
32
|
value: TValue;
|
|
33
33
|
};
|
|
34
|
-
export type NullNode = ASTNode<
|
|
35
|
-
raw:
|
|
34
|
+
export type NullNode = ASTNode<'literal', 'null'> & {
|
|
35
|
+
raw: 'null';
|
|
36
36
|
value: null;
|
|
37
37
|
};
|
|
38
|
-
export type UndefinedNode = ASTNode<
|
|
39
|
-
raw:
|
|
38
|
+
export type UndefinedNode = ASTNode<'literal', 'undefined'> & {
|
|
39
|
+
raw: 'undefined';
|
|
40
40
|
value: undefined;
|
|
41
41
|
};
|
|
42
|
-
export type BooleanNode<TValue extends string = string> = ASTNode<
|
|
42
|
+
export type BooleanNode<TValue extends string = string> = ASTNode<'literal', 'boolean'> & {
|
|
43
43
|
raw: TValue;
|
|
44
|
-
value: TValue extends
|
|
44
|
+
value: TValue extends 'true' ? true : false;
|
|
45
45
|
};
|
|
46
46
|
export type LiteralNode = NumberNode | StringNode | NullNode | UndefinedNode | BooleanNode;
|
|
47
|
-
export type ConstNode<TValue extends string = string> = ASTNode<
|
|
47
|
+
export type ConstNode<TValue extends string = string> = ASTNode<'const', TValue>;
|
|
48
48
|
/** Computed parse result for Number */
|
|
49
|
-
export type ParseNumber<TInput extends string> = Token.TNumber<TInput> extends [
|
|
50
|
-
infer V extends string,
|
|
51
|
-
infer R extends string
|
|
52
|
-
] ? [NumberNode<V>, R] : [];
|
|
49
|
+
export type ParseNumber<TInput extends string> = Token.TNumber<TInput> extends [infer V extends string, infer R extends string] ? [NumberNode<V>, R] : [];
|
|
53
50
|
/** Computed parse result for String */
|
|
54
|
-
export type ParseString<TQuotes extends string[], TInput extends string> = Token.TString<TQuotes, TInput> extends [
|
|
55
|
-
infer V extends string,
|
|
56
|
-
infer R extends string
|
|
57
|
-
] ? [StringNode<V>, R] : [];
|
|
51
|
+
export type ParseString<TQuotes extends string[], TInput extends string> = Token.TString<TQuotes, TInput> extends [infer V extends string, infer R extends string] ? [StringNode<V>, R] : [];
|
|
58
52
|
/** Computed parse result for Ident - looks up value type from schema */
|
|
59
|
-
export type ParseIdent<TInput extends string, $ extends Context> = Token.TIdent<TInput> extends [
|
|
60
|
-
infer V extends string,
|
|
61
|
-
infer R extends string
|
|
62
|
-
] ? V extends keyof $["data"] ? [IdentNode<V, $["data"][V]>, R] : [IdentNode<V>, R] : [];
|
|
53
|
+
export type ParseIdent<TInput extends string, $ extends Context> = Token.TIdent<TInput> extends [infer V extends string, infer R extends string] ? V extends keyof $['data'] ? [IdentNode<V, $['data'][V]>, R] : [IdentNode<V>, R] : [];
|
|
63
54
|
/** Computed parse result for Const */
|
|
64
|
-
export type ParseConst<TValue extends string, TInput extends string> = Token.TConst<TValue, TInput> extends [
|
|
65
|
-
infer _V extends string,
|
|
66
|
-
infer R extends string
|
|
67
|
-
] ? [ConstNode<TValue>, R] : [];
|
|
55
|
+
export type ParseConst<TValue extends string, TInput extends string> = Token.TConst<TValue, TInput> extends [infer _V extends string, infer R extends string] ? [ConstNode<TValue>, R] : [];
|
|
68
56
|
/**
|
|
69
57
|
* Base parser interface. All parsers implement this.
|
|
70
58
|
* Context is generic to preserve type information.
|
|
@@ -96,9 +84,13 @@ declare class _Const<TValue extends string> {
|
|
|
96
84
|
constructor(value: TValue);
|
|
97
85
|
parse<TInput extends string, $ extends Context>(input: TInput, _$: $): ParseConst<TValue, TInput>;
|
|
98
86
|
}
|
|
99
|
-
|
|
100
|
-
export declare const
|
|
101
|
-
|
|
102
|
-
export declare const
|
|
87
|
+
/** @internal */
|
|
88
|
+
export declare const createNumber: () => _Number;
|
|
89
|
+
/** @internal */
|
|
90
|
+
export declare const createString: <TQuotes extends string[]>(quotes: [...TQuotes]) => _String<TQuotes>;
|
|
91
|
+
/** @internal */
|
|
92
|
+
export declare const createIdent: () => _Ident;
|
|
93
|
+
/** @internal */
|
|
94
|
+
export declare const createConst: <TValue extends string>(value: TValue) => _Const<TValue>;
|
|
103
95
|
export type { _Number, _String, _Ident, _Const };
|
|
104
|
-
|
|
96
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitive/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO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,EAAE,MAAM,CAAC;CAahC;AAED,kEAAkE;AAClE,cAAM,MAAM;IACV,QAAQ,CAAC,WAAW,EAAG,OAAO,CAAU;IAExC,KAAK,CAAC,MAAM,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;CAW5F;AAED,sEAAsE;AACtE,cAAM,MAAM,CAAC,MAAM,SAAS,MAAM;IAChC,QAAQ,CAAC,WAAW,EAAG,OAAO,CAAU;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBAEX,KAAK,EAAE,MAAM;IAIzB,KAAK,CAAC,MAAM,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,EAC5C,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,CAAC,GACJ,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC;CAQ9B;AAMD,gBAAgB;AAChB,eAAO,MAAM,YAAY,QAAO,OAAwB,CAAC;AAEzD,gBAAgB;AAChB,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,MAAM,EAAE,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,KAAG,OAAO,CAAC,OAAO,CACxE,CAAC;AAEtB,gBAAgB;AAChB,eAAO,MAAM,WAAW,QAAO,MAAsB,CAAC;AAEtD,gBAAgB;AAChB,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,MAAM,EAAE,OAAO,MAAM,KAAG,MAAM,CAAC,MAAM,CAC7D,CAAC;AAGpB,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/primitive/index.js
CHANGED
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
* DO NOT remove the $ generic parameter - it ensures schema type information
|
|
11
11
|
* flows through the parser chain. See CLAUDE.md for details.
|
|
12
12
|
*/
|
|
13
|
-
import { Token } from
|
|
13
|
+
import { Token } from '@sinclair/parsebox';
|
|
14
14
|
// =============================================================================
|
|
15
15
|
// Primitive Implementations
|
|
16
16
|
// =============================================================================
|
|
17
17
|
/** Number primitive - parses numeric literals using Token.Number */
|
|
18
18
|
class _Number {
|
|
19
|
-
__primitive =
|
|
19
|
+
__primitive = 'number';
|
|
20
20
|
parse(input, _$) {
|
|
21
21
|
// Runtime type is [] | [string, string], but TypeScript computes exact type
|
|
22
22
|
const result = Token.Number(input);
|
|
@@ -24,10 +24,10 @@ class _Number {
|
|
|
24
24
|
return [];
|
|
25
25
|
return [
|
|
26
26
|
{
|
|
27
|
-
node:
|
|
27
|
+
node: 'literal',
|
|
28
28
|
raw: result[0],
|
|
29
29
|
value: +result[0],
|
|
30
|
-
outputSchema:
|
|
30
|
+
outputSchema: 'number',
|
|
31
31
|
},
|
|
32
32
|
result[1],
|
|
33
33
|
];
|
|
@@ -35,7 +35,7 @@ class _Number {
|
|
|
35
35
|
}
|
|
36
36
|
/** String primitive - parses quoted string literals using Token.String */
|
|
37
37
|
class _String {
|
|
38
|
-
__primitive =
|
|
38
|
+
__primitive = 'string';
|
|
39
39
|
quotes;
|
|
40
40
|
constructor(quotes) {
|
|
41
41
|
this.quotes = quotes;
|
|
@@ -46,10 +46,10 @@ class _String {
|
|
|
46
46
|
return [];
|
|
47
47
|
return [
|
|
48
48
|
{
|
|
49
|
-
node:
|
|
49
|
+
node: 'literal',
|
|
50
50
|
raw: result[0],
|
|
51
51
|
value: result[0],
|
|
52
|
-
outputSchema:
|
|
52
|
+
outputSchema: 'string',
|
|
53
53
|
},
|
|
54
54
|
result[1],
|
|
55
55
|
];
|
|
@@ -57,23 +57,23 @@ class _String {
|
|
|
57
57
|
}
|
|
58
58
|
/** Identifier primitive - parses identifiers using Token.Ident */
|
|
59
59
|
class _Ident {
|
|
60
|
-
__primitive =
|
|
60
|
+
__primitive = 'ident';
|
|
61
61
|
parse(input, $) {
|
|
62
62
|
const result = Token.Ident(input);
|
|
63
63
|
if (result.length !== 2)
|
|
64
64
|
return [];
|
|
65
65
|
const name = result[0];
|
|
66
66
|
const data = $.data;
|
|
67
|
-
const valueType = name in data ? data[name] :
|
|
67
|
+
const valueType = name in data ? data[name] : 'unknown';
|
|
68
68
|
return [
|
|
69
|
-
{ node:
|
|
69
|
+
{ node: 'identifier', name, outputSchema: valueType },
|
|
70
70
|
result[1],
|
|
71
71
|
];
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
/** Const primitive - parses exact string matches using Token.Const */
|
|
75
75
|
class _Const {
|
|
76
|
-
__primitive =
|
|
76
|
+
__primitive = 'const';
|
|
77
77
|
value;
|
|
78
78
|
constructor(value) {
|
|
79
79
|
this.value = value;
|
|
@@ -83,15 +83,20 @@ class _Const {
|
|
|
83
83
|
if (result.length !== 2)
|
|
84
84
|
return [];
|
|
85
85
|
return [
|
|
86
|
-
{ node:
|
|
86
|
+
{ node: 'const', outputSchema: JSON.stringify(this.value) },
|
|
87
87
|
result[1],
|
|
88
88
|
];
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
// =============================================================================
|
|
92
|
-
//
|
|
92
|
+
// Internal Factories (used by runtime parser)
|
|
93
93
|
// =============================================================================
|
|
94
|
-
|
|
95
|
-
export const
|
|
96
|
-
|
|
97
|
-
export const
|
|
94
|
+
/** @internal */
|
|
95
|
+
export const createNumber = () => new _Number();
|
|
96
|
+
/** @internal */
|
|
97
|
+
export const createString = (quotes) => new _String(quotes);
|
|
98
|
+
/** @internal */
|
|
99
|
+
export const createIdent = () => new _Ident();
|
|
100
|
+
/** @internal */
|
|
101
|
+
export const createConst = (value) => new _Const(value);
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/primitive/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AA6G3C,gFAAgF;AAChF,4BAA4B;AAC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AAM,WAAW,GAAG,GAAW,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC;AAEtD,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAwB,KAAa,EAAkB,EAAE,CAClF,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Expression Evaluation
|
|
3
|
+
*
|
|
4
|
+
* Evaluates parsed AST nodes to produce runtime values.
|
|
5
|
+
* Uses the eval functions defined in NodeSchema to compute results.
|
|
6
|
+
*
|
|
7
|
+
* The evaluator:
|
|
8
|
+
* 1. Recursively evaluates child nodes first
|
|
9
|
+
* 2. Passes evaluated values to the node's eval function
|
|
10
|
+
* 3. Returns the computed result
|
|
11
|
+
* 4. Validates values against arktype constraints at runtime
|
|
12
|
+
*/
|
|
13
|
+
import type { NodeSchema, SchemaToType } from '../schema/index.js';
|
|
14
|
+
/**
|
|
15
|
+
* Extract the outputSchema from an AST node type.
|
|
16
|
+
* Returns the literal schema string if present, otherwise 'unknown'.
|
|
17
|
+
*/
|
|
18
|
+
type ExtractOutputSchema<T> = T extends {
|
|
19
|
+
outputSchema: infer S extends string;
|
|
20
|
+
} ? S : 'unknown';
|
|
21
|
+
/**
|
|
22
|
+
* A type that represents any AST node with an outputSchema field.
|
|
23
|
+
* This is used as a constraint for the evaluate() function.
|
|
24
|
+
*/
|
|
25
|
+
export type ASTNodeWithSchema<TSchema extends string = string> = {
|
|
26
|
+
readonly node: string;
|
|
27
|
+
readonly outputSchema: TSchema;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Recursively extract all identifier nodes from an AST.
|
|
31
|
+
* Returns a union of { name: string, outputSchema: string } tuples.
|
|
32
|
+
*
|
|
33
|
+
* This is used to determine what variables are used in an expression
|
|
34
|
+
* and what types they expect.
|
|
35
|
+
*/
|
|
36
|
+
type ExtractIdentifiers<T> = T extends {
|
|
37
|
+
node: 'identifier';
|
|
38
|
+
name: infer N;
|
|
39
|
+
outputSchema: infer S;
|
|
40
|
+
} ? {
|
|
41
|
+
name: N;
|
|
42
|
+
outputSchema: S;
|
|
43
|
+
} : T extends object ? {
|
|
44
|
+
[K in keyof T]: ExtractIdentifiers<T[K]>;
|
|
45
|
+
}[keyof T] : never;
|
|
46
|
+
/**
|
|
47
|
+
* Convert a union of identifier tuples to a data object type.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* type Ids = { name: 'x'; outputSchema: 'number' } | { name: 'y'; outputSchema: 'string' };
|
|
51
|
+
* type Data = IdentifiersToData<Ids>;
|
|
52
|
+
* // { x: number; y: string }
|
|
53
|
+
*/
|
|
54
|
+
type IdentifiersToData<T> = T extends {
|
|
55
|
+
name: infer N extends string;
|
|
56
|
+
outputSchema: infer S;
|
|
57
|
+
} ? {
|
|
58
|
+
[K in N]: SchemaToType<S>;
|
|
59
|
+
} : never;
|
|
60
|
+
/**
|
|
61
|
+
* Merge a union of single-key objects into a single object type.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* type Union = { x: number } | { y: string };
|
|
65
|
+
* type Merged = UnionToIntersection<Union>;
|
|
66
|
+
* // { x: number } & { y: string }
|
|
67
|
+
*/
|
|
68
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
69
|
+
/**
|
|
70
|
+
* Extract required data types from an AST based on its identifier nodes.
|
|
71
|
+
* Returns Record<string, never> if no identifiers are found (empty object is allowed).
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* type AST = { node: 'add'; left: { node: 'identifier'; name: 'x'; outputSchema: 'number' }; ... };
|
|
75
|
+
* type Data = ExtractRequiredData<AST>;
|
|
76
|
+
* // { x: number }
|
|
77
|
+
*/
|
|
78
|
+
export type ExtractRequiredData<T> = ExtractIdentifiers<T> extends never ? Record<string, never> : UnionToIntersection<IdentifiersToData<ExtractIdentifiers<T>>>;
|
|
79
|
+
/**
|
|
80
|
+
* Evaluation context that includes both the parse context and node schemas.
|
|
81
|
+
* When AST type is provided, the data is type-checked against the AST's variables.
|
|
82
|
+
*/
|
|
83
|
+
export interface EvalContext<TData = Record<string, unknown>> {
|
|
84
|
+
/** The data context (variable name → value mapping) */
|
|
85
|
+
data: TData;
|
|
86
|
+
/** The node schemas (for looking up eval functions) */
|
|
87
|
+
nodes: readonly NodeSchema[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Evaluate an AST node to produce a runtime value.
|
|
91
|
+
*
|
|
92
|
+
* The return type is inferred from the AST node's `outputSchema` field:
|
|
93
|
+
* - `outputSchema: "number"` → returns `number`
|
|
94
|
+
* - `outputSchema: "string"` → returns `string`
|
|
95
|
+
* - `outputSchema: "boolean"` → returns `boolean`
|
|
96
|
+
* - `outputSchema: "null"` → returns `null`
|
|
97
|
+
* - `outputSchema: "undefined"` → returns `undefined`
|
|
98
|
+
* - Other/unknown → returns `unknown`
|
|
99
|
+
*
|
|
100
|
+
* @param ast - The parsed AST node to evaluate
|
|
101
|
+
* @param ctx - The evaluation context containing variable values and node schemas
|
|
102
|
+
* @returns The evaluated value with the type derived from the AST's outputSchema
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { createParser, defineNode, lhs, rhs, constVal } from "stringent";
|
|
107
|
+
* import { evaluate } from "stringent/runtime/eval";
|
|
108
|
+
*
|
|
109
|
+
* const add = defineNode({
|
|
110
|
+
* name: "add",
|
|
111
|
+
* pattern: [lhs("number").as("left"), constVal("+"), rhs("number").as("right")],
|
|
112
|
+
* precedence: 1,
|
|
113
|
+
* resultType: "number",
|
|
114
|
+
* eval: ({ left, right }) => left + right,
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* const parser = createParser([add] as const);
|
|
118
|
+
* const result = parser.parse("1+2", {});
|
|
119
|
+
*
|
|
120
|
+
* if (result.length === 2) {
|
|
121
|
+
* const value = evaluate(result[0], { data: {}, nodes: [add] });
|
|
122
|
+
* // value has type: number (not unknown!)
|
|
123
|
+
* // value === 3
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function evaluate<T, TData extends ExtractRequiredData<T>>(ast: T, ctx: EvalContext<TData>): SchemaToType<ExtractOutputSchema<T>>;
|
|
128
|
+
/**
|
|
129
|
+
* Create a bound evaluator function for a specific set of node schemas.
|
|
130
|
+
*
|
|
131
|
+
* This is a convenience function that pre-binds the node schemas,
|
|
132
|
+
* so you only need to pass the AST and variable values when evaluating.
|
|
133
|
+
*
|
|
134
|
+
* The returned evaluator function preserves type inference:
|
|
135
|
+
* - The return type is derived from the AST's `outputSchema` field
|
|
136
|
+
* - `outputSchema: "number"` → returns `number`
|
|
137
|
+
* - `outputSchema: "string"` → returns `string`
|
|
138
|
+
* - etc.
|
|
139
|
+
*
|
|
140
|
+
* @param nodes - The node schemas with eval functions
|
|
141
|
+
* @returns An evaluator function with type inference
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const evaluator = createEvaluator([add, mul]);
|
|
146
|
+
*
|
|
147
|
+
* const result = parser.parse("1+2*3", {});
|
|
148
|
+
* if (result.length === 2) {
|
|
149
|
+
* const value = evaluator(result[0], {});
|
|
150
|
+
* // value has type: number (inferred from AST's outputSchema)
|
|
151
|
+
* // value === 7
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function createEvaluator(nodes: readonly NodeSchema[]): <T, TData extends ExtractRequiredData<T>>(ast: T, data: TData) => SchemaToType<ExtractOutputSchema<T>>;
|
|
156
|
+
export {};
|
|
157
|
+
//# sourceMappingURL=eval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../src/runtime/eval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,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,KAAK,CAAC;AAEV;;;;;;;;GAQG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAC/B,kBAAkB,CAAC,CAAC,CAAC,SAAS,KAAK,GAC/B,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACrB,mBAAmB,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC1D,uDAAuD;IACvD,IAAI,EAAE,KAAK,CAAC;IACZ,uDAAuD;IACvD,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;CAC9B;AA0DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,SAAS,mBAAmB,CAAC,CAAC,CAAC,EAC9D,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC,GACtB,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAgGtC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,IAChC,CAAC,EAAE,KAAK,SAAS,mBAAmB,CAAC,CAAC,CAAC,EAC/D,KAAK,CAAC,EACN,MAAM,KAAK,KACV,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAGxC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Expression Evaluation
|
|
3
|
+
*
|
|
4
|
+
* Evaluates parsed AST nodes to produce runtime values.
|
|
5
|
+
* Uses the eval functions defined in NodeSchema to compute results.
|
|
6
|
+
*
|
|
7
|
+
* The evaluator:
|
|
8
|
+
* 1. Recursively evaluates child nodes first
|
|
9
|
+
* 2. Passes evaluated values to the node's eval function
|
|
10
|
+
* 3. Returns the computed result
|
|
11
|
+
* 4. Validates values against arktype constraints at runtime
|
|
12
|
+
*/
|
|
13
|
+
import { type } from 'arktype';
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Runtime ArkType Validation
|
|
16
|
+
// =============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Cache for arktype validators to avoid re-creating them for each evaluation.
|
|
19
|
+
* Maps schema strings to their compiled validators.
|
|
20
|
+
*/
|
|
21
|
+
const validatorCache = new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Get or create an arktype validator for a given schema string.
|
|
24
|
+
* Uses a cache to avoid re-creating validators for frequently used schemas.
|
|
25
|
+
*
|
|
26
|
+
* @param schema - The arktype schema string (e.g., 'number >= 0', 'string.email')
|
|
27
|
+
* @returns The compiled arktype validator
|
|
28
|
+
*/
|
|
29
|
+
function getValidator(schema) {
|
|
30
|
+
let validator = validatorCache.get(schema);
|
|
31
|
+
if (!validator) {
|
|
32
|
+
// Create and cache the validator
|
|
33
|
+
// Note: Invalid schemas will cause arktype to throw at compile time
|
|
34
|
+
// At runtime, we trust the schema was validated at parse time
|
|
35
|
+
validator = type(schema);
|
|
36
|
+
validatorCache.set(schema, validator);
|
|
37
|
+
}
|
|
38
|
+
return validator;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate a value against an arktype schema at runtime.
|
|
42
|
+
* Throws an error if the value doesn't match the schema constraints.
|
|
43
|
+
*
|
|
44
|
+
* @param value - The value to validate
|
|
45
|
+
* @param schema - The arktype schema string (e.g., 'number >= 0', 'string.email')
|
|
46
|
+
* @param variableName - The name of the variable (for error messages)
|
|
47
|
+
* @throws Error if the value doesn't match the schema constraints
|
|
48
|
+
*/
|
|
49
|
+
function validateValue(value, schema, variableName) {
|
|
50
|
+
// Skip validation for generic schemas that don't have runtime constraints
|
|
51
|
+
// These basic types are handled by TypeScript's compile-time checking
|
|
52
|
+
if (schema === 'unknown' || schema === 'never') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const validator = getValidator(schema);
|
|
56
|
+
const result = validator(value);
|
|
57
|
+
// arktype returns the value if valid, or an ArkErrors object if invalid
|
|
58
|
+
if (result instanceof type.errors) {
|
|
59
|
+
throw new Error(`Variable '${variableName}' failed validation for schema '${schema}': ${result.summary}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Evaluate an AST node to produce a runtime value.
|
|
64
|
+
*
|
|
65
|
+
* The return type is inferred from the AST node's `outputSchema` field:
|
|
66
|
+
* - `outputSchema: "number"` → returns `number`
|
|
67
|
+
* - `outputSchema: "string"` → returns `string`
|
|
68
|
+
* - `outputSchema: "boolean"` → returns `boolean`
|
|
69
|
+
* - `outputSchema: "null"` → returns `null`
|
|
70
|
+
* - `outputSchema: "undefined"` → returns `undefined`
|
|
71
|
+
* - Other/unknown → returns `unknown`
|
|
72
|
+
*
|
|
73
|
+
* @param ast - The parsed AST node to evaluate
|
|
74
|
+
* @param ctx - The evaluation context containing variable values and node schemas
|
|
75
|
+
* @returns The evaluated value with the type derived from the AST's outputSchema
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { createParser, defineNode, lhs, rhs, constVal } from "stringent";
|
|
80
|
+
* import { evaluate } from "stringent/runtime/eval";
|
|
81
|
+
*
|
|
82
|
+
* const add = defineNode({
|
|
83
|
+
* name: "add",
|
|
84
|
+
* pattern: [lhs("number").as("left"), constVal("+"), rhs("number").as("right")],
|
|
85
|
+
* precedence: 1,
|
|
86
|
+
* resultType: "number",
|
|
87
|
+
* eval: ({ left, right }) => left + right,
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* const parser = createParser([add] as const);
|
|
91
|
+
* const result = parser.parse("1+2", {});
|
|
92
|
+
*
|
|
93
|
+
* if (result.length === 2) {
|
|
94
|
+
* const value = evaluate(result[0], { data: {}, nodes: [add] });
|
|
95
|
+
* // value has type: number (not unknown!)
|
|
96
|
+
* // value === 3
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export function evaluate(ast, ctx) {
|
|
101
|
+
if (typeof ast !== 'object' || ast === null) {
|
|
102
|
+
throw new Error(`Invalid AST node: expected object, got ${typeof ast}`);
|
|
103
|
+
}
|
|
104
|
+
const node = ast;
|
|
105
|
+
// Check for the 'node' property that indicates the node type
|
|
106
|
+
if (!('node' in node) || typeof node.node !== 'string') {
|
|
107
|
+
throw new Error(`Invalid AST node: missing 'node' property`);
|
|
108
|
+
}
|
|
109
|
+
const nodeType = node.node;
|
|
110
|
+
// Handle literal nodes (number, string, boolean, null, undefined)
|
|
111
|
+
if (nodeType === 'literal') {
|
|
112
|
+
if ('value' in node) {
|
|
113
|
+
return node.value;
|
|
114
|
+
}
|
|
115
|
+
throw new Error(`Literal node missing 'value' property`);
|
|
116
|
+
}
|
|
117
|
+
// Internal eval context for recursive calls (typed at runtime level)
|
|
118
|
+
const internalCtx = ctx;
|
|
119
|
+
// Handle identifier nodes - look up value in context and validate against schema
|
|
120
|
+
if (nodeType === 'identifier') {
|
|
121
|
+
if (!('name' in node) || typeof node.name !== 'string') {
|
|
122
|
+
throw new Error(`Identifier node missing 'name' property`);
|
|
123
|
+
}
|
|
124
|
+
const name = node.name;
|
|
125
|
+
if (!(name in internalCtx.data)) {
|
|
126
|
+
throw new Error(`Undefined variable: ${name}`);
|
|
127
|
+
}
|
|
128
|
+
const value = internalCtx.data[name];
|
|
129
|
+
// Validate value against arktype schema at runtime
|
|
130
|
+
if ('outputSchema' in node && typeof node.outputSchema === 'string') {
|
|
131
|
+
validateValue(value, node.outputSchema, name);
|
|
132
|
+
}
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
// Handle const nodes (operators, keywords) - these shouldn't be evaluated directly
|
|
136
|
+
if (nodeType === 'const') {
|
|
137
|
+
throw new Error(`Cannot evaluate const node directly`);
|
|
138
|
+
}
|
|
139
|
+
// Handle parentheses - just evaluate the inner expression
|
|
140
|
+
if (nodeType === 'parentheses') {
|
|
141
|
+
if (!('inner' in node)) {
|
|
142
|
+
throw new Error(`Parentheses node missing 'inner' property`);
|
|
143
|
+
}
|
|
144
|
+
// Use type assertion for recursive call (data constraint already validated at entry)
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
146
|
+
return evaluate(node.inner, internalCtx);
|
|
147
|
+
}
|
|
148
|
+
// Look up the node schema for this node type
|
|
149
|
+
const nodeSchema = internalCtx.nodes.find((n) => n.name === nodeType);
|
|
150
|
+
if (!nodeSchema) {
|
|
151
|
+
throw new Error(`Unknown node type: ${nodeType}. Make sure to pass all node schemas to evaluate().`);
|
|
152
|
+
}
|
|
153
|
+
if (!nodeSchema.eval) {
|
|
154
|
+
throw new Error(`Node type '${nodeType}' has no eval function defined`);
|
|
155
|
+
}
|
|
156
|
+
// Extract and evaluate all named bindings from the node
|
|
157
|
+
const evaluatedBindings = {};
|
|
158
|
+
// Get the pattern to determine which fields are named bindings
|
|
159
|
+
for (const element of nodeSchema.pattern) {
|
|
160
|
+
// Check if this is a named schema (has __named and name)
|
|
161
|
+
if ('__named' in element && element.__named === true && 'name' in element) {
|
|
162
|
+
const bindingName = element.name;
|
|
163
|
+
if (bindingName in node) {
|
|
164
|
+
// Recursively evaluate the child node
|
|
165
|
+
// Use type assertion for recursive call (data constraint already validated at entry)
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
167
|
+
evaluatedBindings[bindingName] = evaluate(node[bindingName], internalCtx);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Call the eval function with evaluated bindings
|
|
172
|
+
return nodeSchema.eval(evaluatedBindings, internalCtx.data);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create a bound evaluator function for a specific set of node schemas.
|
|
176
|
+
*
|
|
177
|
+
* This is a convenience function that pre-binds the node schemas,
|
|
178
|
+
* so you only need to pass the AST and variable values when evaluating.
|
|
179
|
+
*
|
|
180
|
+
* The returned evaluator function preserves type inference:
|
|
181
|
+
* - The return type is derived from the AST's `outputSchema` field
|
|
182
|
+
* - `outputSchema: "number"` → returns `number`
|
|
183
|
+
* - `outputSchema: "string"` → returns `string`
|
|
184
|
+
* - etc.
|
|
185
|
+
*
|
|
186
|
+
* @param nodes - The node schemas with eval functions
|
|
187
|
+
* @returns An evaluator function with type inference
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* const evaluator = createEvaluator([add, mul]);
|
|
192
|
+
*
|
|
193
|
+
* const result = parser.parse("1+2*3", {});
|
|
194
|
+
* if (result.length === 2) {
|
|
195
|
+
* const value = evaluator(result[0], {});
|
|
196
|
+
* // value has type: number (inferred from AST's outputSchema)
|
|
197
|
+
* // value === 7
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export function createEvaluator(nodes) {
|
|
202
|
+
return function evaluator(ast, data) {
|
|
203
|
+
return evaluate(ast, { data, nodes });
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=eval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval.js","sourceRoot":"","sources":["../../src/runtime/eval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAQ,MAAM,SAAS,CAAC;AA6FrC,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,EAAgB,CAAC;AAE/C;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,iCAAiC;QACjC,oEAAoE;QACpE,8DAA8D;QAC9D,SAAS,GAAG,IAAI,CAAC,MAA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,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/runtime/infer.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* With the new architecture, nodes carry their outputSchema directly,
|
|
7
7
|
* so inference is simpler - just extract the outputSchema field.
|
|
8
8
|
*/
|
|
9
|
-
import type { Context } from
|
|
9
|
+
import type { Context } from '../context.js';
|
|
10
10
|
export type InferredType = string;
|
|
11
11
|
/**
|
|
12
12
|
* Runtime inference - extracts outputSchema from parsed AST nodes.
|
|
@@ -24,3 +24,4 @@ export type InferredType = string;
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export declare function infer(ast: unknown, _context: Context): InferredType;
|
|
27
|
+
//# sourceMappingURL=infer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer.d.ts","sourceRoot":"","sources":["../../src/runtime/infer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,YAAY,CAanE"}
|