@kalada/core 0.0.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 +10 -0
- package/THIRD_PARTY_NOTICES.md +42 -0
- package/dist/index.cjs +20 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/kuery-v1/callback-promise.cjs +79 -0
- package/dist/kuery-v1/callback-promise.cjs.map +1 -0
- package/dist/kuery-v1/callback-promise.d.cts +4 -0
- package/dist/kuery-v1/callback-promise.d.ts +4 -0
- package/dist/kuery-v1/callback-promise.js +77 -0
- package/dist/kuery-v1/callback-promise.js.map +1 -0
- package/dist/kuery-v1/canonicalize.cjs +181 -0
- package/dist/kuery-v1/canonicalize.cjs.map +1 -0
- package/dist/kuery-v1/canonicalize.d.cts +7 -0
- package/dist/kuery-v1/canonicalize.d.ts +7 -0
- package/dist/kuery-v1/canonicalize.js +178 -0
- package/dist/kuery-v1/canonicalize.js.map +1 -0
- package/dist/kuery-v1/compile.cjs +53 -0
- package/dist/kuery-v1/compile.cjs.map +1 -0
- package/dist/kuery-v1/compile.d.cts +10 -0
- package/dist/kuery-v1/compile.d.ts +10 -0
- package/dist/kuery-v1/compile.js +51 -0
- package/dist/kuery-v1/compile.js.map +1 -0
- package/dist/kuery-v1/dependencies.cjs +32 -0
- package/dist/kuery-v1/dependencies.cjs.map +1 -0
- package/dist/kuery-v1/dependencies.d.cts +7 -0
- package/dist/kuery-v1/dependencies.d.ts +7 -0
- package/dist/kuery-v1/dependencies.js +29 -0
- package/dist/kuery-v1/dependencies.js.map +1 -0
- package/dist/kuery-v1/evaluate.cjs +174 -0
- package/dist/kuery-v1/evaluate.cjs.map +1 -0
- package/dist/kuery-v1/evaluate.d.cts +6 -0
- package/dist/kuery-v1/evaluate.d.ts +6 -0
- package/dist/kuery-v1/evaluate.js +172 -0
- package/dist/kuery-v1/evaluate.js.map +1 -0
- package/dist/kuery-v1/index.cjs +54 -0
- package/dist/kuery-v1/index.cjs.map +1 -0
- package/dist/kuery-v1/index.d.cts +8 -0
- package/dist/kuery-v1/index.d.ts +8 -0
- package/dist/kuery-v1/index.js +9 -0
- package/dist/kuery-v1/index.js.map +1 -0
- package/dist/kuery-v1/inspect.cjs +167 -0
- package/dist/kuery-v1/inspect.cjs.map +1 -0
- package/dist/kuery-v1/inspect.d.cts +17 -0
- package/dist/kuery-v1/inspect.d.ts +17 -0
- package/dist/kuery-v1/inspect.js +160 -0
- package/dist/kuery-v1/inspect.js.map +1 -0
- package/dist/kuery-v1/json-schema.cjs +108 -0
- package/dist/kuery-v1/json-schema.cjs.map +1 -0
- package/dist/kuery-v1/json-schema.d.cts +10 -0
- package/dist/kuery-v1/json-schema.d.ts +10 -0
- package/dist/kuery-v1/json-schema.js +105 -0
- package/dist/kuery-v1/json-schema.js.map +1 -0
- package/dist/kuery-v1/limits.cjs +35 -0
- package/dist/kuery-v1/limits.cjs.map +1 -0
- package/dist/kuery-v1/limits.d.cts +6 -0
- package/dist/kuery-v1/limits.d.ts +6 -0
- package/dist/kuery-v1/limits.js +32 -0
- package/dist/kuery-v1/limits.js.map +1 -0
- package/dist/kuery-v1/profile.cjs +224 -0
- package/dist/kuery-v1/profile.cjs.map +1 -0
- package/dist/kuery-v1/profile.d.cts +48 -0
- package/dist/kuery-v1/profile.d.ts +48 -0
- package/dist/kuery-v1/profile.js +219 -0
- package/dist/kuery-v1/profile.js.map +1 -0
- package/dist/kuery-v1/result.cjs +44 -0
- package/dist/kuery-v1/result.cjs.map +1 -0
- package/dist/kuery-v1/result.d.cts +12 -0
- package/dist/kuery-v1/result.d.ts +12 -0
- package/dist/kuery-v1/result.js +39 -0
- package/dist/kuery-v1/result.js.map +1 -0
- package/dist/kuery-v1/standard-profile.cjs +173 -0
- package/dist/kuery-v1/standard-profile.cjs.map +1 -0
- package/dist/kuery-v1/standard-profile.d.cts +7 -0
- package/dist/kuery-v1/standard-profile.d.ts +7 -0
- package/dist/kuery-v1/standard-profile.js +171 -0
- package/dist/kuery-v1/standard-profile.js.map +1 -0
- package/dist/kuery-v1/types.cjs +4 -0
- package/dist/kuery-v1/types.cjs.map +1 -0
- package/dist/kuery-v1/types.d.cts +65 -0
- package/dist/kuery-v1/types.d.ts +65 -0
- package/dist/kuery-v1/types.js +3 -0
- package/dist/kuery-v1/types.js.map +1 -0
- package/dist/program-v1.cjs +72 -0
- package/dist/program-v1.cjs.map +1 -0
- package/dist/program-v1.d.cts +17 -0
- package/dist/program-v1.d.ts +17 -0
- package/dist/program-v1.js +68 -0
- package/dist/program-v1.js.map +1 -0
- package/package.json +51 -0
- package/provenance/kuery-2.1.0.json +93 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const MAX_EXPRESSION_OPERATOR_ARGS = 32;
|
|
4
|
+
const OPERATOR_NAME = /^[a-z][a-z0-9-]*(?:[.:/][a-z][a-z0-9-]*)*$/;
|
|
5
|
+
const NAMESPACED_OPERATOR_NAME = /^[a-z][a-z0-9-]*[.:/][a-z][a-z0-9-]*(?:[.:/][a-z][a-z0-9-]*)*$/;
|
|
6
|
+
const PROFILE_NAME = /^[A-Za-z][A-Za-z0-9._:/@-]{0,127}$/;
|
|
7
|
+
const EXPRESSION_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
8
|
+
"any",
|
|
9
|
+
"null",
|
|
10
|
+
"boolean",
|
|
11
|
+
"number",
|
|
12
|
+
"string",
|
|
13
|
+
"array",
|
|
14
|
+
"object"
|
|
15
|
+
]);
|
|
16
|
+
const PROFILE_STATE = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
const OPERATOR_STRATEGIES = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
const INVALID_INPUT_TYPES = /* @__PURE__ */ Symbol("invalid input types");
|
|
19
|
+
class ExpressionProfile {
|
|
20
|
+
name;
|
|
21
|
+
constructor(name, operators) {
|
|
22
|
+
validateProfileName(name);
|
|
23
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
24
|
+
addDefinitions(operators, snapshot);
|
|
25
|
+
this.name = name;
|
|
26
|
+
PROFILE_STATE.set(this, snapshot);
|
|
27
|
+
Object.freeze(this);
|
|
28
|
+
}
|
|
29
|
+
/** Derive a new immutable profile while preserving this profile's evaluation semantics. */
|
|
30
|
+
extend(name, operators) {
|
|
31
|
+
validateProfileName(name);
|
|
32
|
+
const snapshot = new Map(profileOperators(this));
|
|
33
|
+
for (const definition of operators) {
|
|
34
|
+
const captured = captureDefinition(definition);
|
|
35
|
+
validateCustomDefinition(captured);
|
|
36
|
+
if (snapshot.has(captured.name))
|
|
37
|
+
throw new TypeError(`Duplicate expression operator: ${captured.name}`);
|
|
38
|
+
snapshot.set(captured.name, freezeDefinition(captured));
|
|
39
|
+
}
|
|
40
|
+
return createProfileSnapshot(name, snapshot);
|
|
41
|
+
}
|
|
42
|
+
get(name) {
|
|
43
|
+
validateLookupName(name);
|
|
44
|
+
return profileOperators(this).get(name);
|
|
45
|
+
}
|
|
46
|
+
has(name) {
|
|
47
|
+
validateLookupName(name);
|
|
48
|
+
return profileOperators(this).has(name);
|
|
49
|
+
}
|
|
50
|
+
get definitions() {
|
|
51
|
+
return Object.freeze([...profileOperators(this).values()]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function profileOperators(profile) {
|
|
55
|
+
const operators = PROFILE_STATE.get(profile);
|
|
56
|
+
if (!operators) throw new TypeError("Invalid expression profile receiver.");
|
|
57
|
+
return operators;
|
|
58
|
+
}
|
|
59
|
+
function addDefinitions(operators, snapshot) {
|
|
60
|
+
for (const definition of operators) {
|
|
61
|
+
const captured = captureDefinition(definition);
|
|
62
|
+
validateDefinition(captured);
|
|
63
|
+
if (snapshot.has(captured.name))
|
|
64
|
+
throw new TypeError(`Duplicate expression operator: ${captured.name}`);
|
|
65
|
+
snapshot.set(captured.name, freezeDefinition(captured));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function createProfileSnapshot(name, operators) {
|
|
69
|
+
validateProfileName(name);
|
|
70
|
+
const profile = Object.create(ExpressionProfile.prototype);
|
|
71
|
+
const snapshot = new Map(operators);
|
|
72
|
+
Object.defineProperty(profile, "name", { value: name, enumerable: true });
|
|
73
|
+
PROFILE_STATE.set(profile, snapshot);
|
|
74
|
+
Object.freeze(profile);
|
|
75
|
+
return profile;
|
|
76
|
+
}
|
|
77
|
+
class ExpressionProfileBuilder {
|
|
78
|
+
definitions = /* @__PURE__ */ new Map();
|
|
79
|
+
name;
|
|
80
|
+
constructor(name) {
|
|
81
|
+
validateProfileName(name);
|
|
82
|
+
this.name = name;
|
|
83
|
+
}
|
|
84
|
+
add(definition) {
|
|
85
|
+
const captured = captureDefinition(definition);
|
|
86
|
+
validateCustomDefinition(captured);
|
|
87
|
+
if (this.definitions.has(captured.name))
|
|
88
|
+
throw new TypeError(`Duplicate expression operator: ${captured.name}`);
|
|
89
|
+
this.definitions.set(captured.name, captured);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
build() {
|
|
93
|
+
const operators = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const [name, definition] of this.definitions)
|
|
95
|
+
operators.set(name, freezeDefinition(definition));
|
|
96
|
+
return createProfileSnapshot(this.name, operators);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function validateDefinition(definition) {
|
|
100
|
+
if (typeof definition.name !== "string" || !OPERATOR_NAME.test(definition.name) || typeof definition.execute !== "function") {
|
|
101
|
+
throw new TypeError("Expression operator name or implementation is invalid.");
|
|
102
|
+
}
|
|
103
|
+
const inputTypes = validatedInputTypes(definition.inputTypes);
|
|
104
|
+
validateResultType(definition.resultType);
|
|
105
|
+
const arity = definition.arity;
|
|
106
|
+
const minArgs = definition.minArgs;
|
|
107
|
+
const maxArgs = definition.maxArgs;
|
|
108
|
+
const hasExact = arity !== void 0;
|
|
109
|
+
if (hasExact === (minArgs !== void 0 || maxArgs !== void 0)) {
|
|
110
|
+
throw new TypeError("Expression operators require exact arity or min/max arity.");
|
|
111
|
+
}
|
|
112
|
+
if (hasExact) validateCount(arity);
|
|
113
|
+
if (minArgs !== void 0) validateCount(minArgs);
|
|
114
|
+
if (maxArgs !== void 0) validateCount(maxArgs);
|
|
115
|
+
if ((minArgs ?? 0) > (maxArgs ?? Number.MAX_SAFE_INTEGER)) {
|
|
116
|
+
throw new TypeError("Expression operator minimum arity exceeds maximum arity.");
|
|
117
|
+
}
|
|
118
|
+
if (inputTypes && hasExact && inputTypes.length !== arity) {
|
|
119
|
+
throw new TypeError("Expression operator input metadata must match exact arity.");
|
|
120
|
+
}
|
|
121
|
+
if (inputTypes && !hasExact && inputTypes.length !== 1) {
|
|
122
|
+
throw new TypeError("Variadic expression operators accept one repeated input type.");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function validateCustomDefinition(definition) {
|
|
126
|
+
validateDefinition(definition);
|
|
127
|
+
if (typeof definition.name !== "string" || !NAMESPACED_OPERATOR_NAME.test(definition.name)) {
|
|
128
|
+
throw new TypeError("Custom expression operators require a namespaced name.");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function validateProfileName(name) {
|
|
132
|
+
if (typeof name !== "string" || !PROFILE_NAME.test(name))
|
|
133
|
+
throw new TypeError("Expression profile name is invalid.");
|
|
134
|
+
}
|
|
135
|
+
function validateLookupName(name) {
|
|
136
|
+
if (typeof name !== "string")
|
|
137
|
+
throw new TypeError("Expression operator name must be a primitive string.");
|
|
138
|
+
}
|
|
139
|
+
function validatedInputTypes(input) {
|
|
140
|
+
if (input !== void 0 && !validInputTypes(input)) {
|
|
141
|
+
throw new TypeError("Expression operator input metadata is invalid.");
|
|
142
|
+
}
|
|
143
|
+
return input;
|
|
144
|
+
}
|
|
145
|
+
function validateResultType(input) {
|
|
146
|
+
if (input !== void 0 && !isExpressionValueType(input)) {
|
|
147
|
+
throw new TypeError("Expression operator result metadata is invalid.");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function validInputTypes(input) {
|
|
151
|
+
if (!Array.isArray(input)) return false;
|
|
152
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
153
|
+
if (!Object.hasOwn(input, index) || !isExpressionValueType(input[index])) return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
function isExpressionValueType(value) {
|
|
158
|
+
return typeof value === "string" && EXPRESSION_VALUE_TYPES.has(value);
|
|
159
|
+
}
|
|
160
|
+
function validateCount(value) {
|
|
161
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > MAX_EXPRESSION_OPERATOR_ARGS) {
|
|
162
|
+
throw new TypeError("Expression operator arity is invalid.");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function freezeDefinition(definition) {
|
|
166
|
+
const operator = Object.freeze({
|
|
167
|
+
name: definition.name,
|
|
168
|
+
arity: definition.arity,
|
|
169
|
+
minArgs: definition.minArgs,
|
|
170
|
+
maxArgs: definition.maxArgs,
|
|
171
|
+
inputTypes: definition.inputTypes,
|
|
172
|
+
resultType: definition.resultType,
|
|
173
|
+
execute: definition.execute
|
|
174
|
+
});
|
|
175
|
+
if (definition.strategy) OPERATOR_STRATEGIES.set(operator, definition.strategy);
|
|
176
|
+
return operator;
|
|
177
|
+
}
|
|
178
|
+
function createStandardProfile(name, operators) {
|
|
179
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
180
|
+
for (const definition of operators) {
|
|
181
|
+
const captured = captureDefinition(definition, true);
|
|
182
|
+
validateDefinition(captured);
|
|
183
|
+
if (snapshot.has(captured.name))
|
|
184
|
+
throw new TypeError(`Duplicate expression operator: ${captured.name}`);
|
|
185
|
+
snapshot.set(captured.name, freezeDefinition(captured));
|
|
186
|
+
}
|
|
187
|
+
return createProfileSnapshot(name, snapshot);
|
|
188
|
+
}
|
|
189
|
+
function getEvaluationStrategy(operator) {
|
|
190
|
+
return OPERATOR_STRATEGIES.get(operator);
|
|
191
|
+
}
|
|
192
|
+
const internalProfile = Object.freeze({ createStandardProfile, getEvaluationStrategy });
|
|
193
|
+
function captureDefinition(definition, includeStrategy = false) {
|
|
194
|
+
const inputTypes = definition.inputTypes;
|
|
195
|
+
return Object.freeze({
|
|
196
|
+
name: definition.name,
|
|
197
|
+
arity: definition.arity,
|
|
198
|
+
minArgs: definition.minArgs,
|
|
199
|
+
maxArgs: definition.maxArgs,
|
|
200
|
+
inputTypes: captureInputTypes(inputTypes),
|
|
201
|
+
resultType: definition.resultType,
|
|
202
|
+
execute: definition.execute,
|
|
203
|
+
strategy: includeStrategy ? definition.strategy : void 0
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function captureInputTypes(input) {
|
|
207
|
+
if (input === void 0 || !Array.isArray(input)) return input;
|
|
208
|
+
try {
|
|
209
|
+
const length = input.length;
|
|
210
|
+
if (length > MAX_EXPRESSION_OPERATOR_ARGS) return INVALID_INPUT_TYPES;
|
|
211
|
+
const output = [];
|
|
212
|
+
for (let index = 0; index < length; index += 1) output.push(input[index]);
|
|
213
|
+
return Object.freeze(output);
|
|
214
|
+
} catch {
|
|
215
|
+
return INVALID_INPUT_TYPES;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
exports.ExpressionProfile = ExpressionProfile;
|
|
220
|
+
exports.ExpressionProfileBuilder = ExpressionProfileBuilder;
|
|
221
|
+
exports.MAX_EXPRESSION_OPERATOR_ARGS = MAX_EXPRESSION_OPERATOR_ARGS;
|
|
222
|
+
exports.internalProfile = internalProfile;
|
|
223
|
+
//# sourceMappingURL=profile.cjs.map
|
|
224
|
+
//# sourceMappingURL=profile.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/kuery-v1/profile.ts"],"names":[],"mappings":";;AAUO,MAAM,4BAAA,GAA+B;AAgB5C,MAAM,aAAA,GAAgB,4CAAA;AACtB,MAAM,wBAAA,GAA2B,gEAAA;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,OAAO,mBAAA;AAClD,IAAA,MAAM,SAAoB,EAAC;AAC3B,IAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,MAAA,EAAQ,KAAA,IAAS,GAAG,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,KAAK,CAAC,CAAA;AACxE,IAAA,OAAO,MAAA,CAAO,OAAO,MAAM,CAAA;AAAA,EAC7B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,mBAAA;AAAA,EACT;AACF","file":"profile.cjs","sourcesContent":["import type { JsonValue } from \"./types.js\";\n\nexport type ExpressionValueType =\n | \"any\"\n | \"null\"\n | \"boolean\"\n | \"number\"\n | \"string\"\n | \"array\"\n | \"object\";\nexport const MAX_EXPRESSION_OPERATOR_ARGS = 32;\nexport type ExpressionOperatorFn = (args: readonly JsonValue[]) => JsonValue;\ntype ExpressionEvaluationStrategy = \"and\" | \"or\" | \"coalesce\" | \"exists\" | \"if\";\n\nexport interface ExpressionOperatorDefinition {\n readonly name: string;\n readonly arity?: number;\n readonly minArgs?: number;\n readonly maxArgs?: number;\n readonly inputTypes?: readonly ExpressionValueType[];\n readonly resultType?: ExpressionValueType;\n readonly execute: ExpressionOperatorFn;\n}\n\nexport interface ExpressionOperator extends ExpressionOperatorDefinition {}\n\nconst OPERATOR_NAME = /^[a-z][a-z0-9-]*(?:[.:/][a-z][a-z0-9-]*)*$/;\nconst NAMESPACED_OPERATOR_NAME = /^[a-z][a-z0-9-]*[.:/][a-z][a-z0-9-]*(?:[.:/][a-z][a-z0-9-]*)*$/;\nconst PROFILE_NAME = /^[A-Za-z][A-Za-z0-9._:/@-]{0,127}$/;\nconst EXPRESSION_VALUE_TYPES = new Set<ExpressionValueType>([\n \"any\",\n \"null\",\n \"boolean\",\n \"number\",\n \"string\",\n \"array\",\n \"object\",\n]);\nconst PROFILE_STATE = new WeakMap<ExpressionProfile, ReadonlyMap<string, ExpressionOperator>>();\nconst OPERATOR_STRATEGIES = new WeakMap<ExpressionOperator, ExpressionEvaluationStrategy>();\nconst INVALID_INPUT_TYPES = Symbol(\"invalid input types\");\n\ninterface DefinitionSnapshot {\n readonly name: unknown;\n readonly arity: unknown;\n readonly minArgs: unknown;\n readonly maxArgs: unknown;\n readonly inputTypes: unknown;\n readonly resultType: unknown;\n readonly execute: unknown;\n readonly strategy: unknown;\n}\n\ntype ValidDefinitionSnapshot = DefinitionSnapshot & {\n readonly name: string;\n readonly arity: number | undefined;\n readonly minArgs: number | undefined;\n readonly maxArgs: number | undefined;\n readonly inputTypes: readonly ExpressionValueType[] | undefined;\n readonly resultType: ExpressionValueType | undefined;\n readonly execute: ExpressionOperatorFn;\n readonly strategy: ExpressionEvaluationStrategy | undefined;\n};\n/**\n * Structurally immutable snapshot of operator metadata and callback identities.\n * Callbacks are trusted host code; their closed-over or function-object state remains producer-owned.\n */\nexport class ExpressionProfile {\n readonly name: string;\n\n constructor(name: string, operators: Iterable<ExpressionOperatorDefinition>) {\n validateProfileName(name);\n const snapshot = new Map<string, ExpressionOperator>();\n addDefinitions(operators, snapshot);\n this.name = name;\n PROFILE_STATE.set(this, snapshot);\n Object.freeze(this);\n }\n\n /** Derive a new immutable profile while preserving this profile's evaluation semantics. */\n extend(name: string, operators: Iterable<ExpressionOperatorDefinition>): ExpressionProfile {\n validateProfileName(name);\n const snapshot = new Map(profileOperators(this));\n for (const definition of operators) {\n const captured = captureDefinition(definition);\n validateCustomDefinition(captured);\n if (snapshot.has(captured.name))\n throw new TypeError(`Duplicate expression operator: ${captured.name}`);\n snapshot.set(captured.name, freezeDefinition(captured));\n }\n return createProfileSnapshot(name, snapshot);\n }\n\n get(name: string): ExpressionOperator | undefined {\n validateLookupName(name);\n return profileOperators(this).get(name);\n }\n\n has(name: string): boolean {\n validateLookupName(name);\n return profileOperators(this).has(name);\n }\n\n get definitions(): readonly ExpressionOperator[] {\n return Object.freeze([...profileOperators(this).values()]);\n }\n}\n\nfunction profileOperators(profile: ExpressionProfile): ReadonlyMap<string, ExpressionOperator> {\n const operators = PROFILE_STATE.get(profile);\n if (!operators) throw new TypeError(\"Invalid expression profile receiver.\");\n return operators;\n}\n\nfunction addDefinitions(\n operators: Iterable<ExpressionOperatorDefinition>,\n snapshot: Map<string, ExpressionOperator>,\n): void {\n for (const definition of operators) {\n const captured = captureDefinition(definition);\n validateDefinition(captured);\n if (snapshot.has(captured.name))\n throw new TypeError(`Duplicate expression operator: ${captured.name}`);\n snapshot.set(captured.name, freezeDefinition(captured));\n }\n}\n\nfunction createProfileSnapshot(\n name: string,\n operators: ReadonlyMap<string, ExpressionOperator>,\n): ExpressionProfile {\n validateProfileName(name);\n const profile = Object.create(ExpressionProfile.prototype) as ExpressionProfile;\n const snapshot = new Map(operators);\n Object.defineProperty(profile, \"name\", { value: name, enumerable: true });\n PROFILE_STATE.set(profile, snapshot);\n Object.freeze(profile);\n return profile;\n}\n\n/** Mutable construction helper whose build result is an independent structural snapshot. */\nexport class ExpressionProfileBuilder {\n private readonly definitions = new Map<string, ValidDefinitionSnapshot>();\n private readonly name: string;\n\n constructor(name: string) {\n validateProfileName(name);\n this.name = name;\n }\n\n add(definition: ExpressionOperatorDefinition): this {\n const captured = captureDefinition(definition);\n validateCustomDefinition(captured);\n if (this.definitions.has(captured.name))\n throw new TypeError(`Duplicate expression operator: ${captured.name}`);\n this.definitions.set(captured.name, captured);\n return this;\n }\n\n build(): ExpressionProfile {\n const operators = new Map<string, ExpressionOperator>();\n for (const [name, definition] of this.definitions)\n operators.set(name, freezeDefinition(definition));\n return createProfileSnapshot(this.name, operators);\n }\n}\n\nfunction validateDefinition(\n definition: DefinitionSnapshot,\n): asserts definition is ValidDefinitionSnapshot {\n if (\n typeof definition.name !== \"string\" ||\n !OPERATOR_NAME.test(definition.name) ||\n typeof definition.execute !== \"function\"\n ) {\n throw new TypeError(\"Expression operator name or implementation is invalid.\");\n }\n const inputTypes = validatedInputTypes(definition.inputTypes);\n validateResultType(definition.resultType);\n const arity = definition.arity;\n const minArgs = definition.minArgs;\n const maxArgs = definition.maxArgs;\n const hasExact = arity !== undefined;\n if (hasExact === (minArgs !== undefined || maxArgs !== undefined)) {\n throw new TypeError(\"Expression operators require exact arity or min/max arity.\");\n }\n if (hasExact) validateCount(arity);\n if (minArgs !== undefined) validateCount(minArgs);\n if (maxArgs !== undefined) validateCount(maxArgs);\n if ((minArgs ?? 0) > (maxArgs ?? Number.MAX_SAFE_INTEGER)) {\n throw new TypeError(\"Expression operator minimum arity exceeds maximum arity.\");\n }\n if (inputTypes && hasExact && inputTypes.length !== arity) {\n throw new TypeError(\"Expression operator input metadata must match exact arity.\");\n }\n if (inputTypes && !hasExact && inputTypes.length !== 1) {\n throw new TypeError(\"Variadic expression operators accept one repeated input type.\");\n }\n}\n\nfunction validateCustomDefinition(\n definition: DefinitionSnapshot,\n): asserts definition is ValidDefinitionSnapshot {\n validateDefinition(definition);\n if (typeof definition.name !== \"string\" || !NAMESPACED_OPERATOR_NAME.test(definition.name)) {\n throw new TypeError(\"Custom expression operators require a namespaced name.\");\n }\n}\n\nfunction validateProfileName(name: string): void {\n if (typeof name !== \"string\" || !PROFILE_NAME.test(name))\n throw new TypeError(\"Expression profile name is invalid.\");\n}\n\nfunction validateLookupName(name: string): void {\n if (typeof name !== \"string\")\n throw new TypeError(\"Expression operator name must be a primitive string.\");\n}\n\nfunction validatedInputTypes(input: unknown): readonly ExpressionValueType[] | undefined {\n if (input !== undefined && !validInputTypes(input)) {\n throw new TypeError(\"Expression operator input metadata is invalid.\");\n }\n return input;\n}\n\nfunction validateResultType(input: unknown): asserts input is ExpressionValueType | undefined {\n if (input !== undefined && !isExpressionValueType(input)) {\n throw new TypeError(\"Expression operator result metadata is invalid.\");\n }\n}\n\nfunction validInputTypes(input: unknown): input is readonly ExpressionValueType[] {\n if (!Array.isArray(input)) return false;\n for (let index = 0; index < input.length; index += 1) {\n if (!Object.hasOwn(input, index) || !isExpressionValueType(input[index])) return false;\n }\n return true;\n}\n\nfunction isExpressionValueType(value: unknown): value is ExpressionValueType {\n return typeof value === \"string\" && EXPRESSION_VALUE_TYPES.has(value as ExpressionValueType);\n}\n\nfunction validateCount(value: unknown): asserts value is number {\n if (\n !Number.isSafeInteger(value) ||\n (value as number) < 0 ||\n (value as number) > MAX_EXPRESSION_OPERATOR_ARGS\n ) {\n throw new TypeError(\"Expression operator arity is invalid.\");\n }\n}\n\nfunction freezeDefinition(definition: ValidDefinitionSnapshot): ExpressionOperator {\n const operator = Object.freeze({\n name: definition.name,\n arity: definition.arity,\n minArgs: definition.minArgs,\n maxArgs: definition.maxArgs,\n inputTypes: definition.inputTypes,\n resultType: definition.resultType,\n execute: definition.execute,\n });\n if (definition.strategy) OPERATOR_STRATEGIES.set(operator, definition.strategy);\n return operator;\n}\n\nfunction createStandardProfile(\n name: string,\n operators: Iterable<\n ExpressionOperatorDefinition & { readonly strategy?: ExpressionEvaluationStrategy }\n >,\n): ExpressionProfile {\n const snapshot = new Map<string, ExpressionOperator>();\n for (const definition of operators) {\n const captured = captureDefinition(definition, true);\n validateDefinition(captured);\n if (snapshot.has(captured.name))\n throw new TypeError(`Duplicate expression operator: ${captured.name}`);\n snapshot.set(captured.name, freezeDefinition(captured));\n }\n return createProfileSnapshot(name, snapshot);\n}\n\nfunction getEvaluationStrategy(\n operator: ExpressionOperator,\n): ExpressionEvaluationStrategy | undefined {\n return OPERATOR_STRATEGIES.get(operator);\n}\n\nexport const internalProfile = Object.freeze({ createStandardProfile, getEvaluationStrategy });\n\nfunction captureDefinition(\n definition: ExpressionOperatorDefinition,\n includeStrategy = false,\n): DefinitionSnapshot {\n const inputTypes = definition.inputTypes;\n return Object.freeze({\n name: definition.name,\n arity: definition.arity,\n minArgs: definition.minArgs,\n maxArgs: definition.maxArgs,\n inputTypes: captureInputTypes(inputTypes),\n resultType: definition.resultType,\n execute: definition.execute,\n strategy: includeStrategy\n ? (\n definition as ExpressionOperatorDefinition & {\n readonly strategy?: ExpressionEvaluationStrategy;\n }\n ).strategy\n : undefined,\n });\n}\n\nfunction captureInputTypes(input: unknown): unknown {\n if (input === undefined || !Array.isArray(input)) return input;\n try {\n const length = input.length;\n if (length > MAX_EXPRESSION_OPERATOR_ARGS) return INVALID_INPUT_TYPES;\n const output: unknown[] = [];\n for (let index = 0; index < length; index += 1) output.push(input[index]);\n return Object.freeze(output);\n } catch {\n return INVALID_INPUT_TYPES;\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { JsonValue } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
type ExpressionValueType = "any" | "null" | "boolean" | "number" | "string" | "array" | "object";
|
|
4
|
+
declare const MAX_EXPRESSION_OPERATOR_ARGS = 32;
|
|
5
|
+
type ExpressionOperatorFn = (args: readonly JsonValue[]) => JsonValue;
|
|
6
|
+
type ExpressionEvaluationStrategy = "and" | "or" | "coalesce" | "exists" | "if";
|
|
7
|
+
interface ExpressionOperatorDefinition {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly arity?: number;
|
|
10
|
+
readonly minArgs?: number;
|
|
11
|
+
readonly maxArgs?: number;
|
|
12
|
+
readonly inputTypes?: readonly ExpressionValueType[];
|
|
13
|
+
readonly resultType?: ExpressionValueType;
|
|
14
|
+
readonly execute: ExpressionOperatorFn;
|
|
15
|
+
}
|
|
16
|
+
interface ExpressionOperator extends ExpressionOperatorDefinition {
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Structurally immutable snapshot of operator metadata and callback identities.
|
|
20
|
+
* Callbacks are trusted host code; their closed-over or function-object state remains producer-owned.
|
|
21
|
+
*/
|
|
22
|
+
declare class ExpressionProfile {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
constructor(name: string, operators: Iterable<ExpressionOperatorDefinition>);
|
|
25
|
+
/** Derive a new immutable profile while preserving this profile's evaluation semantics. */
|
|
26
|
+
extend(name: string, operators: Iterable<ExpressionOperatorDefinition>): ExpressionProfile;
|
|
27
|
+
get(name: string): ExpressionOperator | undefined;
|
|
28
|
+
has(name: string): boolean;
|
|
29
|
+
get definitions(): readonly ExpressionOperator[];
|
|
30
|
+
}
|
|
31
|
+
/** Mutable construction helper whose build result is an independent structural snapshot. */
|
|
32
|
+
declare class ExpressionProfileBuilder {
|
|
33
|
+
private readonly definitions;
|
|
34
|
+
private readonly name;
|
|
35
|
+
constructor(name: string);
|
|
36
|
+
add(definition: ExpressionOperatorDefinition): this;
|
|
37
|
+
build(): ExpressionProfile;
|
|
38
|
+
}
|
|
39
|
+
declare function createStandardProfile(name: string, operators: Iterable<ExpressionOperatorDefinition & {
|
|
40
|
+
readonly strategy?: ExpressionEvaluationStrategy;
|
|
41
|
+
}>): ExpressionProfile;
|
|
42
|
+
declare function getEvaluationStrategy(operator: ExpressionOperator): ExpressionEvaluationStrategy | undefined;
|
|
43
|
+
declare const internalProfile: Readonly<{
|
|
44
|
+
createStandardProfile: typeof createStandardProfile;
|
|
45
|
+
getEvaluationStrategy: typeof getEvaluationStrategy;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
export { type ExpressionOperator, type ExpressionOperatorDefinition, type ExpressionOperatorFn, ExpressionProfile, ExpressionProfileBuilder, type ExpressionValueType, MAX_EXPRESSION_OPERATOR_ARGS, internalProfile };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { JsonValue } from './types.js';
|
|
2
|
+
|
|
3
|
+
type ExpressionValueType = "any" | "null" | "boolean" | "number" | "string" | "array" | "object";
|
|
4
|
+
declare const MAX_EXPRESSION_OPERATOR_ARGS = 32;
|
|
5
|
+
type ExpressionOperatorFn = (args: readonly JsonValue[]) => JsonValue;
|
|
6
|
+
type ExpressionEvaluationStrategy = "and" | "or" | "coalesce" | "exists" | "if";
|
|
7
|
+
interface ExpressionOperatorDefinition {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly arity?: number;
|
|
10
|
+
readonly minArgs?: number;
|
|
11
|
+
readonly maxArgs?: number;
|
|
12
|
+
readonly inputTypes?: readonly ExpressionValueType[];
|
|
13
|
+
readonly resultType?: ExpressionValueType;
|
|
14
|
+
readonly execute: ExpressionOperatorFn;
|
|
15
|
+
}
|
|
16
|
+
interface ExpressionOperator extends ExpressionOperatorDefinition {
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Structurally immutable snapshot of operator metadata and callback identities.
|
|
20
|
+
* Callbacks are trusted host code; their closed-over or function-object state remains producer-owned.
|
|
21
|
+
*/
|
|
22
|
+
declare class ExpressionProfile {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
constructor(name: string, operators: Iterable<ExpressionOperatorDefinition>);
|
|
25
|
+
/** Derive a new immutable profile while preserving this profile's evaluation semantics. */
|
|
26
|
+
extend(name: string, operators: Iterable<ExpressionOperatorDefinition>): ExpressionProfile;
|
|
27
|
+
get(name: string): ExpressionOperator | undefined;
|
|
28
|
+
has(name: string): boolean;
|
|
29
|
+
get definitions(): readonly ExpressionOperator[];
|
|
30
|
+
}
|
|
31
|
+
/** Mutable construction helper whose build result is an independent structural snapshot. */
|
|
32
|
+
declare class ExpressionProfileBuilder {
|
|
33
|
+
private readonly definitions;
|
|
34
|
+
private readonly name;
|
|
35
|
+
constructor(name: string);
|
|
36
|
+
add(definition: ExpressionOperatorDefinition): this;
|
|
37
|
+
build(): ExpressionProfile;
|
|
38
|
+
}
|
|
39
|
+
declare function createStandardProfile(name: string, operators: Iterable<ExpressionOperatorDefinition & {
|
|
40
|
+
readonly strategy?: ExpressionEvaluationStrategy;
|
|
41
|
+
}>): ExpressionProfile;
|
|
42
|
+
declare function getEvaluationStrategy(operator: ExpressionOperator): ExpressionEvaluationStrategy | undefined;
|
|
43
|
+
declare const internalProfile: Readonly<{
|
|
44
|
+
createStandardProfile: typeof createStandardProfile;
|
|
45
|
+
getEvaluationStrategy: typeof getEvaluationStrategy;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
export { type ExpressionOperator, type ExpressionOperatorDefinition, type ExpressionOperatorFn, ExpressionProfile, ExpressionProfileBuilder, type ExpressionValueType, MAX_EXPRESSION_OPERATOR_ARGS, internalProfile };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
const MAX_EXPRESSION_OPERATOR_ARGS = 32;
|
|
2
|
+
const OPERATOR_NAME = /^[a-z][a-z0-9-]*(?:[.:/][a-z][a-z0-9-]*)*$/;
|
|
3
|
+
const NAMESPACED_OPERATOR_NAME = /^[a-z][a-z0-9-]*[.:/][a-z][a-z0-9-]*(?:[.:/][a-z][a-z0-9-]*)*$/;
|
|
4
|
+
const PROFILE_NAME = /^[A-Za-z][A-Za-z0-9._:/@-]{0,127}$/;
|
|
5
|
+
const EXPRESSION_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
6
|
+
"any",
|
|
7
|
+
"null",
|
|
8
|
+
"boolean",
|
|
9
|
+
"number",
|
|
10
|
+
"string",
|
|
11
|
+
"array",
|
|
12
|
+
"object"
|
|
13
|
+
]);
|
|
14
|
+
const PROFILE_STATE = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
const OPERATOR_STRATEGIES = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
const INVALID_INPUT_TYPES = /* @__PURE__ */ Symbol("invalid input types");
|
|
17
|
+
class ExpressionProfile {
|
|
18
|
+
name;
|
|
19
|
+
constructor(name, operators) {
|
|
20
|
+
validateProfileName(name);
|
|
21
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
22
|
+
addDefinitions(operators, snapshot);
|
|
23
|
+
this.name = name;
|
|
24
|
+
PROFILE_STATE.set(this, snapshot);
|
|
25
|
+
Object.freeze(this);
|
|
26
|
+
}
|
|
27
|
+
/** Derive a new immutable profile while preserving this profile's evaluation semantics. */
|
|
28
|
+
extend(name, operators) {
|
|
29
|
+
validateProfileName(name);
|
|
30
|
+
const snapshot = new Map(profileOperators(this));
|
|
31
|
+
for (const definition of operators) {
|
|
32
|
+
const captured = captureDefinition(definition);
|
|
33
|
+
validateCustomDefinition(captured);
|
|
34
|
+
if (snapshot.has(captured.name))
|
|
35
|
+
throw new TypeError(`Duplicate expression operator: ${captured.name}`);
|
|
36
|
+
snapshot.set(captured.name, freezeDefinition(captured));
|
|
37
|
+
}
|
|
38
|
+
return createProfileSnapshot(name, snapshot);
|
|
39
|
+
}
|
|
40
|
+
get(name) {
|
|
41
|
+
validateLookupName(name);
|
|
42
|
+
return profileOperators(this).get(name);
|
|
43
|
+
}
|
|
44
|
+
has(name) {
|
|
45
|
+
validateLookupName(name);
|
|
46
|
+
return profileOperators(this).has(name);
|
|
47
|
+
}
|
|
48
|
+
get definitions() {
|
|
49
|
+
return Object.freeze([...profileOperators(this).values()]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function profileOperators(profile) {
|
|
53
|
+
const operators = PROFILE_STATE.get(profile);
|
|
54
|
+
if (!operators) throw new TypeError("Invalid expression profile receiver.");
|
|
55
|
+
return operators;
|
|
56
|
+
}
|
|
57
|
+
function addDefinitions(operators, snapshot) {
|
|
58
|
+
for (const definition of operators) {
|
|
59
|
+
const captured = captureDefinition(definition);
|
|
60
|
+
validateDefinition(captured);
|
|
61
|
+
if (snapshot.has(captured.name))
|
|
62
|
+
throw new TypeError(`Duplicate expression operator: ${captured.name}`);
|
|
63
|
+
snapshot.set(captured.name, freezeDefinition(captured));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function createProfileSnapshot(name, operators) {
|
|
67
|
+
validateProfileName(name);
|
|
68
|
+
const profile = Object.create(ExpressionProfile.prototype);
|
|
69
|
+
const snapshot = new Map(operators);
|
|
70
|
+
Object.defineProperty(profile, "name", { value: name, enumerable: true });
|
|
71
|
+
PROFILE_STATE.set(profile, snapshot);
|
|
72
|
+
Object.freeze(profile);
|
|
73
|
+
return profile;
|
|
74
|
+
}
|
|
75
|
+
class ExpressionProfileBuilder {
|
|
76
|
+
definitions = /* @__PURE__ */ new Map();
|
|
77
|
+
name;
|
|
78
|
+
constructor(name) {
|
|
79
|
+
validateProfileName(name);
|
|
80
|
+
this.name = name;
|
|
81
|
+
}
|
|
82
|
+
add(definition) {
|
|
83
|
+
const captured = captureDefinition(definition);
|
|
84
|
+
validateCustomDefinition(captured);
|
|
85
|
+
if (this.definitions.has(captured.name))
|
|
86
|
+
throw new TypeError(`Duplicate expression operator: ${captured.name}`);
|
|
87
|
+
this.definitions.set(captured.name, captured);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
build() {
|
|
91
|
+
const operators = /* @__PURE__ */ new Map();
|
|
92
|
+
for (const [name, definition] of this.definitions)
|
|
93
|
+
operators.set(name, freezeDefinition(definition));
|
|
94
|
+
return createProfileSnapshot(this.name, operators);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function validateDefinition(definition) {
|
|
98
|
+
if (typeof definition.name !== "string" || !OPERATOR_NAME.test(definition.name) || typeof definition.execute !== "function") {
|
|
99
|
+
throw new TypeError("Expression operator name or implementation is invalid.");
|
|
100
|
+
}
|
|
101
|
+
const inputTypes = validatedInputTypes(definition.inputTypes);
|
|
102
|
+
validateResultType(definition.resultType);
|
|
103
|
+
const arity = definition.arity;
|
|
104
|
+
const minArgs = definition.minArgs;
|
|
105
|
+
const maxArgs = definition.maxArgs;
|
|
106
|
+
const hasExact = arity !== void 0;
|
|
107
|
+
if (hasExact === (minArgs !== void 0 || maxArgs !== void 0)) {
|
|
108
|
+
throw new TypeError("Expression operators require exact arity or min/max arity.");
|
|
109
|
+
}
|
|
110
|
+
if (hasExact) validateCount(arity);
|
|
111
|
+
if (minArgs !== void 0) validateCount(minArgs);
|
|
112
|
+
if (maxArgs !== void 0) validateCount(maxArgs);
|
|
113
|
+
if ((minArgs ?? 0) > (maxArgs ?? Number.MAX_SAFE_INTEGER)) {
|
|
114
|
+
throw new TypeError("Expression operator minimum arity exceeds maximum arity.");
|
|
115
|
+
}
|
|
116
|
+
if (inputTypes && hasExact && inputTypes.length !== arity) {
|
|
117
|
+
throw new TypeError("Expression operator input metadata must match exact arity.");
|
|
118
|
+
}
|
|
119
|
+
if (inputTypes && !hasExact && inputTypes.length !== 1) {
|
|
120
|
+
throw new TypeError("Variadic expression operators accept one repeated input type.");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function validateCustomDefinition(definition) {
|
|
124
|
+
validateDefinition(definition);
|
|
125
|
+
if (typeof definition.name !== "string" || !NAMESPACED_OPERATOR_NAME.test(definition.name)) {
|
|
126
|
+
throw new TypeError("Custom expression operators require a namespaced name.");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function validateProfileName(name) {
|
|
130
|
+
if (typeof name !== "string" || !PROFILE_NAME.test(name))
|
|
131
|
+
throw new TypeError("Expression profile name is invalid.");
|
|
132
|
+
}
|
|
133
|
+
function validateLookupName(name) {
|
|
134
|
+
if (typeof name !== "string")
|
|
135
|
+
throw new TypeError("Expression operator name must be a primitive string.");
|
|
136
|
+
}
|
|
137
|
+
function validatedInputTypes(input) {
|
|
138
|
+
if (input !== void 0 && !validInputTypes(input)) {
|
|
139
|
+
throw new TypeError("Expression operator input metadata is invalid.");
|
|
140
|
+
}
|
|
141
|
+
return input;
|
|
142
|
+
}
|
|
143
|
+
function validateResultType(input) {
|
|
144
|
+
if (input !== void 0 && !isExpressionValueType(input)) {
|
|
145
|
+
throw new TypeError("Expression operator result metadata is invalid.");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function validInputTypes(input) {
|
|
149
|
+
if (!Array.isArray(input)) return false;
|
|
150
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
151
|
+
if (!Object.hasOwn(input, index) || !isExpressionValueType(input[index])) return false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
function isExpressionValueType(value) {
|
|
156
|
+
return typeof value === "string" && EXPRESSION_VALUE_TYPES.has(value);
|
|
157
|
+
}
|
|
158
|
+
function validateCount(value) {
|
|
159
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > MAX_EXPRESSION_OPERATOR_ARGS) {
|
|
160
|
+
throw new TypeError("Expression operator arity is invalid.");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function freezeDefinition(definition) {
|
|
164
|
+
const operator = Object.freeze({
|
|
165
|
+
name: definition.name,
|
|
166
|
+
arity: definition.arity,
|
|
167
|
+
minArgs: definition.minArgs,
|
|
168
|
+
maxArgs: definition.maxArgs,
|
|
169
|
+
inputTypes: definition.inputTypes,
|
|
170
|
+
resultType: definition.resultType,
|
|
171
|
+
execute: definition.execute
|
|
172
|
+
});
|
|
173
|
+
if (definition.strategy) OPERATOR_STRATEGIES.set(operator, definition.strategy);
|
|
174
|
+
return operator;
|
|
175
|
+
}
|
|
176
|
+
function createStandardProfile(name, operators) {
|
|
177
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
178
|
+
for (const definition of operators) {
|
|
179
|
+
const captured = captureDefinition(definition, true);
|
|
180
|
+
validateDefinition(captured);
|
|
181
|
+
if (snapshot.has(captured.name))
|
|
182
|
+
throw new TypeError(`Duplicate expression operator: ${captured.name}`);
|
|
183
|
+
snapshot.set(captured.name, freezeDefinition(captured));
|
|
184
|
+
}
|
|
185
|
+
return createProfileSnapshot(name, snapshot);
|
|
186
|
+
}
|
|
187
|
+
function getEvaluationStrategy(operator) {
|
|
188
|
+
return OPERATOR_STRATEGIES.get(operator);
|
|
189
|
+
}
|
|
190
|
+
const internalProfile = Object.freeze({ createStandardProfile, getEvaluationStrategy });
|
|
191
|
+
function captureDefinition(definition, includeStrategy = false) {
|
|
192
|
+
const inputTypes = definition.inputTypes;
|
|
193
|
+
return Object.freeze({
|
|
194
|
+
name: definition.name,
|
|
195
|
+
arity: definition.arity,
|
|
196
|
+
minArgs: definition.minArgs,
|
|
197
|
+
maxArgs: definition.maxArgs,
|
|
198
|
+
inputTypes: captureInputTypes(inputTypes),
|
|
199
|
+
resultType: definition.resultType,
|
|
200
|
+
execute: definition.execute,
|
|
201
|
+
strategy: includeStrategy ? definition.strategy : void 0
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function captureInputTypes(input) {
|
|
205
|
+
if (input === void 0 || !Array.isArray(input)) return input;
|
|
206
|
+
try {
|
|
207
|
+
const length = input.length;
|
|
208
|
+
if (length > MAX_EXPRESSION_OPERATOR_ARGS) return INVALID_INPUT_TYPES;
|
|
209
|
+
const output = [];
|
|
210
|
+
for (let index = 0; index < length; index += 1) output.push(input[index]);
|
|
211
|
+
return Object.freeze(output);
|
|
212
|
+
} catch {
|
|
213
|
+
return INVALID_INPUT_TYPES;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { ExpressionProfile, ExpressionProfileBuilder, MAX_EXPRESSION_OPERATOR_ARGS, internalProfile };
|
|
218
|
+
//# sourceMappingURL=profile.js.map
|
|
219
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/kuery-v1/profile.ts"],"names":[],"mappings":"AAUO,MAAM,4BAAA,GAA+B;AAgB5C,MAAM,aAAA,GAAgB,4CAAA;AACtB,MAAM,wBAAA,GAA2B,gEAAA;AACjC,MAAM,YAAA,GAAe,oCAAA;AACrB,MAAM,sBAAA,uBAA6B,GAAA,CAAyB;AAAA,EAC1D,KAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAAC,CAAA;AACD,MAAM,aAAA,uBAAoB,OAAA,EAAoE;AAC9F,MAAM,mBAAA,uBAA0B,OAAA,EAA0D;AAC1F,MAAM,mBAAA,0BAA6B,qBAAqB,CAAA;AA2BjD,MAAM,iBAAA,CAAkB;AAAA,EACpB,IAAA;AAAA,EAET,WAAA,CAAY,MAAc,SAAA,EAAmD;AAC3E,IAAA,mBAAA,CAAoB,IAAI,CAAA;AACxB,IAAA,MAAM,QAAA,uBAAe,GAAA,EAAgC;AACrD,IAAA,cAAA,CAAe,WAAW,QAAQ,CAAA;AAClC,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,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E;AACpB,EAAA,MAAM,aAAa,UAAA,CAAW,UAAA;AAC9B,EAAA,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,MAAM,UAAA,CAAW,IAAA;AAAA,IACjB,OAAO,UAAA,CAAW,KAAA;AAAA,IAClB,SAAS,UAAA,CAAW,OAAA;AAAA,IACpB,SAAS,UAAA,CAAW,OAAA;AAAA,IACpB,UAAA,EAAY,kBAAkB,UAAU,CAAA;AAAA,IACxC,YAAY,UAAA,CAAW,UAAA;AAAA,IACvB,SAAS,UAAA,CAAW,OAAA;AAAA,IACpB,QAAA,EAAU,eAAA,GAEJ,UAAA,CAGA,QAAA,GACF;AAAA,GACL,CAAA;AACH;AAEA,SAAS,kBAAkB,KAAA,EAAyB;AAClD,EAAA,IAAI,UAAU,MAAA,IAAa,CAAC,MAAM,OAAA,CAAQ,KAAK,GAAG,OAAO,KAAA;AACzD,EAAA,IAAI;AACF,IAAA,MAAM,SAAS,KAAA,CAAM,MAAA;AACrB,IAAA,IAAI,MAAA,GAAS,8BAA8B,OAAO,mBAAA;AAClD,IAAA,MAAM,SAAoB,EAAC;AAC3B,IAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,MAAA,EAAQ,KAAA,IAAS,GAAG,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,KAAK,CAAC,CAAA;AACxE,IAAA,OAAO,MAAA,CAAO,OAAO,MAAM,CAAA;AAAA,EAC7B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,mBAAA;AAAA,EACT;AACF","file":"profile.js","sourcesContent":["import type { JsonValue } from \"./types.js\";\n\nexport type ExpressionValueType =\n | \"any\"\n | \"null\"\n | \"boolean\"\n | \"number\"\n | \"string\"\n | \"array\"\n | \"object\";\nexport const MAX_EXPRESSION_OPERATOR_ARGS = 32;\nexport type ExpressionOperatorFn = (args: readonly JsonValue[]) => JsonValue;\ntype ExpressionEvaluationStrategy = \"and\" | \"or\" | \"coalesce\" | \"exists\" | \"if\";\n\nexport interface ExpressionOperatorDefinition {\n readonly name: string;\n readonly arity?: number;\n readonly minArgs?: number;\n readonly maxArgs?: number;\n readonly inputTypes?: readonly ExpressionValueType[];\n readonly resultType?: ExpressionValueType;\n readonly execute: ExpressionOperatorFn;\n}\n\nexport interface ExpressionOperator extends ExpressionOperatorDefinition {}\n\nconst OPERATOR_NAME = /^[a-z][a-z0-9-]*(?:[.:/][a-z][a-z0-9-]*)*$/;\nconst NAMESPACED_OPERATOR_NAME = /^[a-z][a-z0-9-]*[.:/][a-z][a-z0-9-]*(?:[.:/][a-z][a-z0-9-]*)*$/;\nconst PROFILE_NAME = /^[A-Za-z][A-Za-z0-9._:/@-]{0,127}$/;\nconst EXPRESSION_VALUE_TYPES = new Set<ExpressionValueType>([\n \"any\",\n \"null\",\n \"boolean\",\n \"number\",\n \"string\",\n \"array\",\n \"object\",\n]);\nconst PROFILE_STATE = new WeakMap<ExpressionProfile, ReadonlyMap<string, ExpressionOperator>>();\nconst OPERATOR_STRATEGIES = new WeakMap<ExpressionOperator, ExpressionEvaluationStrategy>();\nconst INVALID_INPUT_TYPES = Symbol(\"invalid input types\");\n\ninterface DefinitionSnapshot {\n readonly name: unknown;\n readonly arity: unknown;\n readonly minArgs: unknown;\n readonly maxArgs: unknown;\n readonly inputTypes: unknown;\n readonly resultType: unknown;\n readonly execute: unknown;\n readonly strategy: unknown;\n}\n\ntype ValidDefinitionSnapshot = DefinitionSnapshot & {\n readonly name: string;\n readonly arity: number | undefined;\n readonly minArgs: number | undefined;\n readonly maxArgs: number | undefined;\n readonly inputTypes: readonly ExpressionValueType[] | undefined;\n readonly resultType: ExpressionValueType | undefined;\n readonly execute: ExpressionOperatorFn;\n readonly strategy: ExpressionEvaluationStrategy | undefined;\n};\n/**\n * Structurally immutable snapshot of operator metadata and callback identities.\n * Callbacks are trusted host code; their closed-over or function-object state remains producer-owned.\n */\nexport class ExpressionProfile {\n readonly name: string;\n\n constructor(name: string, operators: Iterable<ExpressionOperatorDefinition>) {\n validateProfileName(name);\n const snapshot = new Map<string, ExpressionOperator>();\n addDefinitions(operators, snapshot);\n this.name = name;\n PROFILE_STATE.set(this, snapshot);\n Object.freeze(this);\n }\n\n /** Derive a new immutable profile while preserving this profile's evaluation semantics. */\n extend(name: string, operators: Iterable<ExpressionOperatorDefinition>): ExpressionProfile {\n validateProfileName(name);\n const snapshot = new Map(profileOperators(this));\n for (const definition of operators) {\n const captured = captureDefinition(definition);\n validateCustomDefinition(captured);\n if (snapshot.has(captured.name))\n throw new TypeError(`Duplicate expression operator: ${captured.name}`);\n snapshot.set(captured.name, freezeDefinition(captured));\n }\n return createProfileSnapshot(name, snapshot);\n }\n\n get(name: string): ExpressionOperator | undefined {\n validateLookupName(name);\n return profileOperators(this).get(name);\n }\n\n has(name: string): boolean {\n validateLookupName(name);\n return profileOperators(this).has(name);\n }\n\n get definitions(): readonly ExpressionOperator[] {\n return Object.freeze([...profileOperators(this).values()]);\n }\n}\n\nfunction profileOperators(profile: ExpressionProfile): ReadonlyMap<string, ExpressionOperator> {\n const operators = PROFILE_STATE.get(profile);\n if (!operators) throw new TypeError(\"Invalid expression profile receiver.\");\n return operators;\n}\n\nfunction addDefinitions(\n operators: Iterable<ExpressionOperatorDefinition>,\n snapshot: Map<string, ExpressionOperator>,\n): void {\n for (const definition of operators) {\n const captured = captureDefinition(definition);\n validateDefinition(captured);\n if (snapshot.has(captured.name))\n throw new TypeError(`Duplicate expression operator: ${captured.name}`);\n snapshot.set(captured.name, freezeDefinition(captured));\n }\n}\n\nfunction createProfileSnapshot(\n name: string,\n operators: ReadonlyMap<string, ExpressionOperator>,\n): ExpressionProfile {\n validateProfileName(name);\n const profile = Object.create(ExpressionProfile.prototype) as ExpressionProfile;\n const snapshot = new Map(operators);\n Object.defineProperty(profile, \"name\", { value: name, enumerable: true });\n PROFILE_STATE.set(profile, snapshot);\n Object.freeze(profile);\n return profile;\n}\n\n/** Mutable construction helper whose build result is an independent structural snapshot. */\nexport class ExpressionProfileBuilder {\n private readonly definitions = new Map<string, ValidDefinitionSnapshot>();\n private readonly name: string;\n\n constructor(name: string) {\n validateProfileName(name);\n this.name = name;\n }\n\n add(definition: ExpressionOperatorDefinition): this {\n const captured = captureDefinition(definition);\n validateCustomDefinition(captured);\n if (this.definitions.has(captured.name))\n throw new TypeError(`Duplicate expression operator: ${captured.name}`);\n this.definitions.set(captured.name, captured);\n return this;\n }\n\n build(): ExpressionProfile {\n const operators = new Map<string, ExpressionOperator>();\n for (const [name, definition] of this.definitions)\n operators.set(name, freezeDefinition(definition));\n return createProfileSnapshot(this.name, operators);\n }\n}\n\nfunction validateDefinition(\n definition: DefinitionSnapshot,\n): asserts definition is ValidDefinitionSnapshot {\n if (\n typeof definition.name !== \"string\" ||\n !OPERATOR_NAME.test(definition.name) ||\n typeof definition.execute !== \"function\"\n ) {\n throw new TypeError(\"Expression operator name or implementation is invalid.\");\n }\n const inputTypes = validatedInputTypes(definition.inputTypes);\n validateResultType(definition.resultType);\n const arity = definition.arity;\n const minArgs = definition.minArgs;\n const maxArgs = definition.maxArgs;\n const hasExact = arity !== undefined;\n if (hasExact === (minArgs !== undefined || maxArgs !== undefined)) {\n throw new TypeError(\"Expression operators require exact arity or min/max arity.\");\n }\n if (hasExact) validateCount(arity);\n if (minArgs !== undefined) validateCount(minArgs);\n if (maxArgs !== undefined) validateCount(maxArgs);\n if ((minArgs ?? 0) > (maxArgs ?? Number.MAX_SAFE_INTEGER)) {\n throw new TypeError(\"Expression operator minimum arity exceeds maximum arity.\");\n }\n if (inputTypes && hasExact && inputTypes.length !== arity) {\n throw new TypeError(\"Expression operator input metadata must match exact arity.\");\n }\n if (inputTypes && !hasExact && inputTypes.length !== 1) {\n throw new TypeError(\"Variadic expression operators accept one repeated input type.\");\n }\n}\n\nfunction validateCustomDefinition(\n definition: DefinitionSnapshot,\n): asserts definition is ValidDefinitionSnapshot {\n validateDefinition(definition);\n if (typeof definition.name !== \"string\" || !NAMESPACED_OPERATOR_NAME.test(definition.name)) {\n throw new TypeError(\"Custom expression operators require a namespaced name.\");\n }\n}\n\nfunction validateProfileName(name: string): void {\n if (typeof name !== \"string\" || !PROFILE_NAME.test(name))\n throw new TypeError(\"Expression profile name is invalid.\");\n}\n\nfunction validateLookupName(name: string): void {\n if (typeof name !== \"string\")\n throw new TypeError(\"Expression operator name must be a primitive string.\");\n}\n\nfunction validatedInputTypes(input: unknown): readonly ExpressionValueType[] | undefined {\n if (input !== undefined && !validInputTypes(input)) {\n throw new TypeError(\"Expression operator input metadata is invalid.\");\n }\n return input;\n}\n\nfunction validateResultType(input: unknown): asserts input is ExpressionValueType | undefined {\n if (input !== undefined && !isExpressionValueType(input)) {\n throw new TypeError(\"Expression operator result metadata is invalid.\");\n }\n}\n\nfunction validInputTypes(input: unknown): input is readonly ExpressionValueType[] {\n if (!Array.isArray(input)) return false;\n for (let index = 0; index < input.length; index += 1) {\n if (!Object.hasOwn(input, index) || !isExpressionValueType(input[index])) return false;\n }\n return true;\n}\n\nfunction isExpressionValueType(value: unknown): value is ExpressionValueType {\n return typeof value === \"string\" && EXPRESSION_VALUE_TYPES.has(value as ExpressionValueType);\n}\n\nfunction validateCount(value: unknown): asserts value is number {\n if (\n !Number.isSafeInteger(value) ||\n (value as number) < 0 ||\n (value as number) > MAX_EXPRESSION_OPERATOR_ARGS\n ) {\n throw new TypeError(\"Expression operator arity is invalid.\");\n }\n}\n\nfunction freezeDefinition(definition: ValidDefinitionSnapshot): ExpressionOperator {\n const operator = Object.freeze({\n name: definition.name,\n arity: definition.arity,\n minArgs: definition.minArgs,\n maxArgs: definition.maxArgs,\n inputTypes: definition.inputTypes,\n resultType: definition.resultType,\n execute: definition.execute,\n });\n if (definition.strategy) OPERATOR_STRATEGIES.set(operator, definition.strategy);\n return operator;\n}\n\nfunction createStandardProfile(\n name: string,\n operators: Iterable<\n ExpressionOperatorDefinition & { readonly strategy?: ExpressionEvaluationStrategy }\n >,\n): ExpressionProfile {\n const snapshot = new Map<string, ExpressionOperator>();\n for (const definition of operators) {\n const captured = captureDefinition(definition, true);\n validateDefinition(captured);\n if (snapshot.has(captured.name))\n throw new TypeError(`Duplicate expression operator: ${captured.name}`);\n snapshot.set(captured.name, freezeDefinition(captured));\n }\n return createProfileSnapshot(name, snapshot);\n}\n\nfunction getEvaluationStrategy(\n operator: ExpressionOperator,\n): ExpressionEvaluationStrategy | undefined {\n return OPERATOR_STRATEGIES.get(operator);\n}\n\nexport const internalProfile = Object.freeze({ createStandardProfile, getEvaluationStrategy });\n\nfunction captureDefinition(\n definition: ExpressionOperatorDefinition,\n includeStrategy = false,\n): DefinitionSnapshot {\n const inputTypes = definition.inputTypes;\n return Object.freeze({\n name: definition.name,\n arity: definition.arity,\n minArgs: definition.minArgs,\n maxArgs: definition.maxArgs,\n inputTypes: captureInputTypes(inputTypes),\n resultType: definition.resultType,\n execute: definition.execute,\n strategy: includeStrategy\n ? (\n definition as ExpressionOperatorDefinition & {\n readonly strategy?: ExpressionEvaluationStrategy;\n }\n ).strategy\n : undefined,\n });\n}\n\nfunction captureInputTypes(input: unknown): unknown {\n if (input === undefined || !Array.isArray(input)) return input;\n try {\n const length = input.length;\n if (length > MAX_EXPRESSION_OPERATOR_ARGS) return INVALID_INPUT_TYPES;\n const output: unknown[] = [];\n for (let index = 0; index < length; index += 1) output.push(input[index]);\n return Object.freeze(output);\n } catch {\n return INVALID_INPUT_TYPES;\n }\n}\n"]}
|