@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.
Files changed (94) hide show
  1. package/README.md +10 -0
  2. package/THIRD_PARTY_NOTICES.md +42 -0
  3. package/dist/index.cjs +20 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +2 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +3 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/kuery-v1/callback-promise.cjs +79 -0
  10. package/dist/kuery-v1/callback-promise.cjs.map +1 -0
  11. package/dist/kuery-v1/callback-promise.d.cts +4 -0
  12. package/dist/kuery-v1/callback-promise.d.ts +4 -0
  13. package/dist/kuery-v1/callback-promise.js +77 -0
  14. package/dist/kuery-v1/callback-promise.js.map +1 -0
  15. package/dist/kuery-v1/canonicalize.cjs +181 -0
  16. package/dist/kuery-v1/canonicalize.cjs.map +1 -0
  17. package/dist/kuery-v1/canonicalize.d.cts +7 -0
  18. package/dist/kuery-v1/canonicalize.d.ts +7 -0
  19. package/dist/kuery-v1/canonicalize.js +178 -0
  20. package/dist/kuery-v1/canonicalize.js.map +1 -0
  21. package/dist/kuery-v1/compile.cjs +53 -0
  22. package/dist/kuery-v1/compile.cjs.map +1 -0
  23. package/dist/kuery-v1/compile.d.cts +10 -0
  24. package/dist/kuery-v1/compile.d.ts +10 -0
  25. package/dist/kuery-v1/compile.js +51 -0
  26. package/dist/kuery-v1/compile.js.map +1 -0
  27. package/dist/kuery-v1/dependencies.cjs +32 -0
  28. package/dist/kuery-v1/dependencies.cjs.map +1 -0
  29. package/dist/kuery-v1/dependencies.d.cts +7 -0
  30. package/dist/kuery-v1/dependencies.d.ts +7 -0
  31. package/dist/kuery-v1/dependencies.js +29 -0
  32. package/dist/kuery-v1/dependencies.js.map +1 -0
  33. package/dist/kuery-v1/evaluate.cjs +174 -0
  34. package/dist/kuery-v1/evaluate.cjs.map +1 -0
  35. package/dist/kuery-v1/evaluate.d.cts +6 -0
  36. package/dist/kuery-v1/evaluate.d.ts +6 -0
  37. package/dist/kuery-v1/evaluate.js +172 -0
  38. package/dist/kuery-v1/evaluate.js.map +1 -0
  39. package/dist/kuery-v1/index.cjs +54 -0
  40. package/dist/kuery-v1/index.cjs.map +1 -0
  41. package/dist/kuery-v1/index.d.cts +8 -0
  42. package/dist/kuery-v1/index.d.ts +8 -0
  43. package/dist/kuery-v1/index.js +9 -0
  44. package/dist/kuery-v1/index.js.map +1 -0
  45. package/dist/kuery-v1/inspect.cjs +167 -0
  46. package/dist/kuery-v1/inspect.cjs.map +1 -0
  47. package/dist/kuery-v1/inspect.d.cts +17 -0
  48. package/dist/kuery-v1/inspect.d.ts +17 -0
  49. package/dist/kuery-v1/inspect.js +160 -0
  50. package/dist/kuery-v1/inspect.js.map +1 -0
  51. package/dist/kuery-v1/json-schema.cjs +108 -0
  52. package/dist/kuery-v1/json-schema.cjs.map +1 -0
  53. package/dist/kuery-v1/json-schema.d.cts +10 -0
  54. package/dist/kuery-v1/json-schema.d.ts +10 -0
  55. package/dist/kuery-v1/json-schema.js +105 -0
  56. package/dist/kuery-v1/json-schema.js.map +1 -0
  57. package/dist/kuery-v1/limits.cjs +35 -0
  58. package/dist/kuery-v1/limits.cjs.map +1 -0
  59. package/dist/kuery-v1/limits.d.cts +6 -0
  60. package/dist/kuery-v1/limits.d.ts +6 -0
  61. package/dist/kuery-v1/limits.js +32 -0
  62. package/dist/kuery-v1/limits.js.map +1 -0
  63. package/dist/kuery-v1/profile.cjs +224 -0
  64. package/dist/kuery-v1/profile.cjs.map +1 -0
  65. package/dist/kuery-v1/profile.d.cts +48 -0
  66. package/dist/kuery-v1/profile.d.ts +48 -0
  67. package/dist/kuery-v1/profile.js +219 -0
  68. package/dist/kuery-v1/profile.js.map +1 -0
  69. package/dist/kuery-v1/result.cjs +44 -0
  70. package/dist/kuery-v1/result.cjs.map +1 -0
  71. package/dist/kuery-v1/result.d.cts +12 -0
  72. package/dist/kuery-v1/result.d.ts +12 -0
  73. package/dist/kuery-v1/result.js +39 -0
  74. package/dist/kuery-v1/result.js.map +1 -0
  75. package/dist/kuery-v1/standard-profile.cjs +173 -0
  76. package/dist/kuery-v1/standard-profile.cjs.map +1 -0
  77. package/dist/kuery-v1/standard-profile.d.cts +7 -0
  78. package/dist/kuery-v1/standard-profile.d.ts +7 -0
  79. package/dist/kuery-v1/standard-profile.js +171 -0
  80. package/dist/kuery-v1/standard-profile.js.map +1 -0
  81. package/dist/kuery-v1/types.cjs +4 -0
  82. package/dist/kuery-v1/types.cjs.map +1 -0
  83. package/dist/kuery-v1/types.d.cts +65 -0
  84. package/dist/kuery-v1/types.d.ts +65 -0
  85. package/dist/kuery-v1/types.js +3 -0
  86. package/dist/kuery-v1/types.js.map +1 -0
  87. package/dist/program-v1.cjs +72 -0
  88. package/dist/program-v1.cjs.map +1 -0
  89. package/dist/program-v1.d.cts +17 -0
  90. package/dist/program-v1.d.ts +17 -0
  91. package/dist/program-v1.js +68 -0
  92. package/dist/program-v1.js.map +1 -0
  93. package/package.json +51 -0
  94. package/provenance/kuery-2.1.0.json +93 -0
@@ -0,0 +1,160 @@
1
+ import { ExpressionFailure } from './result.js';
2
+
3
+ const UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
4
+ function dataProperties(input, path, allowed, maxProperties, maxKeyLength) {
5
+ if (!isPlainObject(input)) throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
6
+ try {
7
+ return readDataProperties(input, path, allowed, maxProperties, maxKeyLength);
8
+ } catch (error) {
9
+ if (error instanceof ExpressionFailure) throw error;
10
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
11
+ }
12
+ }
13
+ function readDataProperties(input, path, allowed, maxProperties, maxKeyLength) {
14
+ const keys = Reflect.ownKeys(input);
15
+ if (maxProperties !== void 0 && keys.length > maxProperties) {
16
+ throw new ExpressionFailure("EXPRESSION_LIMIT_EXCEEDED", path);
17
+ }
18
+ const output = {};
19
+ for (const key of keys) {
20
+ if (typeof key !== "string") {
21
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", [...path, String(key)]);
22
+ }
23
+ const descriptor = Object.getOwnPropertyDescriptor(input, key);
24
+ if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
25
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", [...path, key]);
26
+ }
27
+ if (maxKeyLength !== void 0 && exceedsStringLimit(key, maxKeyLength)) {
28
+ throw new ExpressionFailure("EXPRESSION_LIMIT_EXCEEDED", [...path, key]);
29
+ }
30
+ if (UNSAFE_KEYS.has(key) || allowed && !allowed.has(key)) {
31
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", [...path, key]);
32
+ }
33
+ Object.defineProperty(output, key, {
34
+ value: descriptor.value,
35
+ enumerable: true,
36
+ writable: true
37
+ });
38
+ }
39
+ return output;
40
+ }
41
+ function isPlainObject(input) {
42
+ if (typeof input !== "object" || input === null || Array.isArray(input)) return false;
43
+ try {
44
+ const prototype = Object.getPrototypeOf(input);
45
+ return prototype === Object.prototype || prototype === null;
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+ function cloneJson(input, path, depth, state) {
51
+ countValue(input, path, depth, state);
52
+ if (input === null || typeof input === "boolean") return input;
53
+ if (typeof input === "number") return input;
54
+ if (typeof input === "string") return cloneString(input, path, state.maxStringLength);
55
+ if (Array.isArray(input)) return cloneArray(input, path, depth, state);
56
+ return cloneObject(input, path, depth, state);
57
+ }
58
+ function countValue(input, path, depth, state) {
59
+ state.nodes += 1;
60
+ if (depth > state.maxDepth || state.nodes > state.maxNodes) {
61
+ throw new ExpressionFailure("EXPRESSION_LIMIT_EXCEEDED", path);
62
+ }
63
+ if (typeof input === "number" && !Number.isFinite(input)) {
64
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
65
+ }
66
+ if (input === null || ["boolean", "number", "string"].includes(typeof input)) return;
67
+ if (typeof input !== "object") throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
68
+ }
69
+ function cloneString(input, path, maxLength) {
70
+ if (exceedsStringLimit(input, maxLength))
71
+ throw new ExpressionFailure("EXPRESSION_LIMIT_EXCEEDED", path);
72
+ return input;
73
+ }
74
+ function exceedsStringLimit(input, maxLength) {
75
+ let length = 0;
76
+ for (const _codePoint of input) {
77
+ length += 1;
78
+ if (length > maxLength) return true;
79
+ }
80
+ return false;
81
+ }
82
+ function cloneArray(input, path, depth, state) {
83
+ enter(input, path, state);
84
+ try {
85
+ const length = arrayLength(input, path);
86
+ if (length > state.maxNodes - state.nodes) {
87
+ throw new ExpressionFailure("EXPRESSION_LIMIT_EXCEEDED", path);
88
+ }
89
+ const keys = Reflect.ownKeys(input);
90
+ if (keys.some(
91
+ (key) => typeof key === "symbol" || key !== "length" && !isArrayIndex(key, length)
92
+ )) {
93
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
94
+ }
95
+ const values = [];
96
+ for (let index = 0; index < length; index += 1) {
97
+ const descriptor = Object.getOwnPropertyDescriptor(input, String(index));
98
+ if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
99
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", [...path, index]);
100
+ }
101
+ values.push(cloneJson(descriptor.value, [...path, index], depth + 1, state));
102
+ }
103
+ return Object.freeze(values);
104
+ } catch (error) {
105
+ if (error instanceof ExpressionFailure) throw error;
106
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
107
+ } finally {
108
+ state.active.delete(input);
109
+ }
110
+ }
111
+ function cloneObject(input, path, depth, state) {
112
+ enter(input, path, state);
113
+ try {
114
+ const properties = dataProperties(
115
+ input,
116
+ path,
117
+ void 0,
118
+ state.maxNodes - state.nodes,
119
+ state.maxStringLength
120
+ );
121
+ const output = {};
122
+ for (const key of Object.keys(properties).sort()) {
123
+ Object.defineProperty(output, key, {
124
+ value: cloneJson(properties[key], [...path, key], depth + 1, state),
125
+ enumerable: true
126
+ });
127
+ }
128
+ return Object.freeze(output);
129
+ } finally {
130
+ state.active.delete(input);
131
+ }
132
+ }
133
+ function arrayLength(input, path) {
134
+ try {
135
+ const descriptor = Object.getOwnPropertyDescriptor(input, "length");
136
+ if (!descriptor || !("value" in descriptor) || !Number.isSafeInteger(descriptor.value) || descriptor.value < 0 || descriptor.value > 4294967295) {
137
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
138
+ }
139
+ return descriptor.value;
140
+ } catch (error) {
141
+ if (error instanceof ExpressionFailure) throw error;
142
+ throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
143
+ }
144
+ }
145
+ function enter(input, path, state) {
146
+ if (state.active.has(input)) throw new ExpressionFailure("EXPRESSION_INVALID_INPUT", path);
147
+ state.active.add(input);
148
+ }
149
+ function isArrayIndex(key, length) {
150
+ if (!/^(0|[1-9]\d*)$/.test(key)) return false;
151
+ const index = Number(key);
152
+ return Number.isSafeInteger(index) && index < length;
153
+ }
154
+ function stableJson(value) {
155
+ return JSON.stringify(value);
156
+ }
157
+
158
+ export { UNSAFE_KEYS, arrayLength, cloneJson, dataProperties, exceedsStringLimit, stableJson };
159
+ //# sourceMappingURL=inspect.js.map
160
+ //# sourceMappingURL=inspect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kuery-v1/inspect.ts"],"names":[],"mappings":";;AAGO,MAAM,8BAAc,IAAI,GAAA,CAAI,CAAC,WAAA,EAAa,aAAA,EAAe,WAAW,CAAC;AAUrE,SAAS,cAAA,CACd,KAAA,EACA,IAAA,EACA,OAAA,EACA,eACA,YAAA,EACmC;AACnC,EAAA,IAAI,CAAC,cAAc,KAAK,CAAA,QAAS,IAAI,iBAAA,CAAkB,4BAA4B,IAAI,CAAA;AACvF,EAAA,IAAI;AACF,IAAA,OAAO,kBAAA,CAAmB,KAAA,EAAO,IAAA,EAAM,OAAA,EAAS,eAAe,YAAY,CAAA;AAAA,EAC7E,SAAS,KAAA,EAAO;AACd,IA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E,CAAC,UAAA,IACD,EAAE,OAAA,IAAW,UAAA,CAAA,IACb,CAAC,MAAA,CAAO,aAAA,CAAc,UAAA,CAAW,KAAK,KACtC,UAAA,CAAW,KAAA,GAAQ,CAAA,IACnB,UAAA,CAAW,QAAQ,UAAA,EACnB;AACA,MAAA,MAAM,IAAI,iBAAA,CAAkB,0BAAA,EAA4B,IAAI,CAAA;AAAA,IAC9D;AACA,IAAA,OAAO,UAAA,CAAW,KAAA;AAAA,EACpB,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,KAAA,YAAiB,mBAAmB,MAAM,KAAA;AAC9C,IAAA,MAAM,IAAI,iBAAA,CAAkB,0BAAA,EAA4B,IAAI,CAAA;AAAA,EAC9D;AACF;AAEA,SAAS,KAAA,CAAM,KAAA,EAAe,IAAA,EAAsB,KAAA,EAA8B;AAChF,EAAA,IAAI,KAAA,CAAM,OAAO,GAAA,CAAI,KAAK,GAAG,MAAM,IAAI,iBAAA,CAAkB,0BAAA,EAA4B,IAAI,CAAA;AACzF,EAAA,KAAA,CAAM,MAAA,CAAO,IAAI,KAAK,CAAA;AACxB;AAEA,SAAS,YAAA,CAAa,KAAa,MAAA,EAAyB;AAC1D,EAAA,IAAI,CAAC,gBAAA,CAAiB,IAAA,CAAK,GAAG,GAAG,OAAO,KAAA;AACxC,EAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,EAAA,OAAO,MAAA,CAAO,aAAA,CAAc,KAAK,CAAA,IAAK,KAAA,GAAQ,MAAA;AAChD;AAEO,SAAS,WAAW,KAAA,EAA0B;AACnD,EAAA,OAAO,IAAA,CAAK,UAAU,KAAK,CAAA;AAC7B","file":"inspect.js","sourcesContent":["import { ExpressionFailure } from \"./result.js\";\nimport type { ExpressionPath, JsonObject, JsonValue } from \"./types.js\";\n\nexport const UNSAFE_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nexport interface ValidationState {\n readonly maxDepth: number;\n readonly maxNodes: number;\n readonly maxStringLength: number;\n nodes: number;\n readonly active: WeakSet<object>;\n}\n\nexport function dataProperties(\n input: unknown,\n path: ExpressionPath,\n allowed?: ReadonlySet<string>,\n maxProperties?: number,\n maxKeyLength?: number,\n): Readonly<Record<string, unknown>> {\n if (!isPlainObject(input)) throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n try {\n return readDataProperties(input, path, allowed, maxProperties, maxKeyLength);\n } catch (error) {\n if (error instanceof ExpressionFailure) throw error;\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n }\n}\n\nfunction readDataProperties(\n input: object,\n path: ExpressionPath,\n allowed?: ReadonlySet<string>,\n maxProperties?: number,\n maxKeyLength?: number,\n): Readonly<Record<string, unknown>> {\n const keys = Reflect.ownKeys(input);\n if (maxProperties !== undefined && keys.length > maxProperties) {\n throw new ExpressionFailure(\"EXPRESSION_LIMIT_EXCEEDED\", path);\n }\n const output: Record<string, unknown> = {};\n for (const key of keys) {\n if (typeof key !== \"string\") {\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", [...path, String(key)]);\n }\n const descriptor = Object.getOwnPropertyDescriptor(input, key);\n if (!descriptor || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", [...path, key]);\n }\n if (maxKeyLength !== undefined && exceedsStringLimit(key, maxKeyLength)) {\n throw new ExpressionFailure(\"EXPRESSION_LIMIT_EXCEEDED\", [...path, key]);\n }\n if (UNSAFE_KEYS.has(key) || (allowed && !allowed.has(key))) {\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", [...path, key]);\n }\n Object.defineProperty(output, key, {\n value: descriptor.value,\n enumerable: true,\n writable: true,\n });\n }\n return output;\n}\n\nfunction isPlainObject(input: unknown): input is object {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) return false;\n try {\n const prototype = Object.getPrototypeOf(input);\n return prototype === Object.prototype || prototype === null;\n } catch {\n return false;\n }\n}\n\nexport function cloneJson(\n input: unknown,\n path: ExpressionPath,\n depth: number,\n state: ValidationState,\n): JsonValue {\n countValue(input, path, depth, state);\n if (input === null || typeof input === \"boolean\") return input;\n if (typeof input === \"number\") return input;\n if (typeof input === \"string\") return cloneString(input, path, state.maxStringLength);\n if (Array.isArray(input)) return cloneArray(input, path, depth, state);\n return cloneObject(input as object, path, depth, state);\n}\n\nfunction countValue(\n input: unknown,\n path: ExpressionPath,\n depth: number,\n state: ValidationState,\n): void {\n state.nodes += 1;\n if (depth > state.maxDepth || state.nodes > state.maxNodes) {\n throw new ExpressionFailure(\"EXPRESSION_LIMIT_EXCEEDED\", path);\n }\n if (typeof input === \"number\" && !Number.isFinite(input)) {\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n }\n if (input === null || [\"boolean\", \"number\", \"string\"].includes(typeof input)) return;\n if (typeof input !== \"object\") throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n}\n\nfunction cloneString(input: string, path: ExpressionPath, maxLength: number): string {\n if (exceedsStringLimit(input, maxLength))\n throw new ExpressionFailure(\"EXPRESSION_LIMIT_EXCEEDED\", path);\n return input;\n}\n\nexport function exceedsStringLimit(input: string, maxLength: number): boolean {\n let length = 0;\n for (const _codePoint of input) {\n length += 1;\n if (length > maxLength) return true;\n }\n return false;\n}\n\nfunction cloneArray(\n input: unknown[],\n path: ExpressionPath,\n depth: number,\n state: ValidationState,\n): JsonValue {\n enter(input, path, state);\n try {\n const length = arrayLength(input, path);\n if (length > state.maxNodes - state.nodes) {\n throw new ExpressionFailure(\"EXPRESSION_LIMIT_EXCEEDED\", path);\n }\n const keys = Reflect.ownKeys(input);\n if (\n keys.some(\n (key) => typeof key === \"symbol\" || (key !== \"length\" && !isArrayIndex(key, length)),\n )\n ) {\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n }\n const values: JsonValue[] = [];\n for (let index = 0; index < length; index += 1) {\n const descriptor = Object.getOwnPropertyDescriptor(input, String(index));\n if (!descriptor || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", [...path, index]);\n }\n values.push(cloneJson(descriptor.value, [...path, index], depth + 1, state));\n }\n return Object.freeze(values);\n } catch (error) {\n if (error instanceof ExpressionFailure) throw error;\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n } finally {\n state.active.delete(input);\n }\n}\n\nfunction cloneObject(\n input: object,\n path: ExpressionPath,\n depth: number,\n state: ValidationState,\n): JsonObject {\n enter(input, path, state);\n try {\n const properties = dataProperties(\n input,\n path,\n undefined,\n state.maxNodes - state.nodes,\n state.maxStringLength,\n );\n const output: Record<string, JsonValue> = {};\n for (const key of Object.keys(properties).sort()) {\n Object.defineProperty(output, key, {\n value: cloneJson(properties[key], [...path, key], depth + 1, state),\n enumerable: true,\n });\n }\n return Object.freeze(output);\n } finally {\n state.active.delete(input);\n }\n}\n\nexport function arrayLength(input: unknown[], path: ExpressionPath): number {\n try {\n const descriptor = Object.getOwnPropertyDescriptor(input, \"length\");\n if (\n !descriptor ||\n !(\"value\" in descriptor) ||\n !Number.isSafeInteger(descriptor.value) ||\n descriptor.value < 0 ||\n descriptor.value > 0xffff_ffff\n ) {\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n }\n return descriptor.value as number;\n } catch (error) {\n if (error instanceof ExpressionFailure) throw error;\n throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n }\n}\n\nfunction enter(input: object, path: ExpressionPath, state: ValidationState): void {\n if (state.active.has(input)) throw new ExpressionFailure(\"EXPRESSION_INVALID_INPUT\", path);\n state.active.add(input);\n}\n\nfunction isArrayIndex(key: string, length: number): boolean {\n if (!/^(0|[1-9]\\d*)$/.test(key)) return false;\n const index = Number(key);\n return Number.isSafeInteger(index) && index < length;\n}\n\nexport function stableJson(value: JsonValue): string {\n return JSON.stringify(value);\n}\n"]}
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ var limits_js = require('./limits.js');
4
+ var profile_js = require('./profile.js');
5
+ var standardProfile_js = require('./standard-profile.js');
6
+
7
+ const jsonValueSchema = deepFreeze({
8
+ anyOf: [
9
+ { type: "null" },
10
+ { type: "boolean" },
11
+ { type: "number", minimum: -17976931348623157e292, maximum: 17976931348623157e292 },
12
+ { type: "string", maxLength: limits_js.DEFAULT_EXPRESSION_LIMITS.maxStringLength },
13
+ {
14
+ type: "array",
15
+ maxItems: limits_js.DEFAULT_EXPRESSION_LIMITS.maxNodes,
16
+ items: { $ref: "#/$defs/jsonValue" }
17
+ },
18
+ {
19
+ type: "object",
20
+ maxProperties: limits_js.DEFAULT_EXPRESSION_LIMITS.maxNodes,
21
+ propertyNames: {
22
+ allOf: [
23
+ { maxLength: limits_js.DEFAULT_EXPRESSION_LIMITS.maxStringLength },
24
+ { not: { enum: ["__proto__", "constructor", "prototype"] } }
25
+ ]
26
+ },
27
+ additionalProperties: { $ref: "#/$defs/jsonValue" }
28
+ }
29
+ ]
30
+ });
31
+ function generateExpressionJsonSchema(profile) {
32
+ if (!(profile instanceof profile_js.ExpressionProfile))
33
+ throw new TypeError("An expression profile is required.");
34
+ const operatorSchemas = profile.definitions.map(operatorSchema);
35
+ return deepFreeze({
36
+ $schema: "https://json-schema.org/draft/2020-12/schema",
37
+ $id: `https://kuery.dev/schema/expression/${encodeURIComponent(profile.name)}`,
38
+ $comment: "This schema enforces recursive shape and profile constraints only; aggregate maxNodes and maxDepth limits are runtime-authoritative during canonicalization and compilation.",
39
+ $ref: "#/$defs/expression",
40
+ $defs: {
41
+ jsonValue: jsonValueSchema,
42
+ expression: {
43
+ oneOf: [
44
+ literalSchema(),
45
+ referenceSchema(),
46
+ ...operatorSchemas.length ? operatorSchemas : [neverSchema()]
47
+ ]
48
+ }
49
+ }
50
+ });
51
+ }
52
+ function neverSchema() {
53
+ return false;
54
+ }
55
+ function getStandardExpressionJsonSchema() {
56
+ return generateExpressionJsonSchema(standardProfile_js.standardV1);
57
+ }
58
+ function literalSchema() {
59
+ return {
60
+ type: "object",
61
+ properties: { kind: { const: "literal" }, value: { $ref: "#/$defs/jsonValue" } },
62
+ required: ["kind", "value"],
63
+ additionalProperties: false
64
+ };
65
+ }
66
+ function referenceSchema() {
67
+ return {
68
+ type: "object",
69
+ properties: {
70
+ kind: { const: "ref" },
71
+ ref: {
72
+ type: "string",
73
+ minLength: 1,
74
+ maxLength: limits_js.DEFAULT_EXPRESSION_LIMITS.maxReferenceLength
75
+ }
76
+ },
77
+ required: ["kind", "ref"],
78
+ additionalProperties: false
79
+ };
80
+ }
81
+ function operatorSchema(operator) {
82
+ const args = {
83
+ type: "array",
84
+ items: { $ref: "#/$defs/expression" },
85
+ minItems: operator.arity ?? operator.minArgs ?? 0,
86
+ maxItems: operator.arity ?? operator.maxArgs ?? profile_js.MAX_EXPRESSION_OPERATOR_ARGS
87
+ };
88
+ return {
89
+ type: "object",
90
+ properties: {
91
+ kind: { const: "op" },
92
+ op: { const: operator.name },
93
+ args
94
+ },
95
+ required: ["kind", "op", "args"],
96
+ additionalProperties: false
97
+ };
98
+ }
99
+ function deepFreeze(value) {
100
+ if (typeof value !== "object" || value === null) return value;
101
+ for (const child of Object.values(value)) deepFreeze(child);
102
+ return Object.isFrozen(value) ? value : Object.freeze(value);
103
+ }
104
+
105
+ exports.generateExpressionJsonSchema = generateExpressionJsonSchema;
106
+ exports.getStandardExpressionJsonSchema = getStandardExpressionJsonSchema;
107
+ //# sourceMappingURL=json-schema.cjs.map
108
+ //# sourceMappingURL=json-schema.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kuery-v1/json-schema.ts"],"names":["DEFAULT_EXPRESSION_LIMITS","ExpressionProfile","standardV1","MAX_EXPRESSION_OPERATOR_ARGS"],"mappings":";;;;;;AAUA,MAAM,kBAAkB,UAAA,CAAW;AAAA,EACjC,KAAA,EAAO;AAAA,IACL,EAAE,MAAM,MAAA,EAAO;AAAA,IACf,EAAE,MAAM,SAAA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S,OAAA,IAAWG;AAAA,GAClD;AACA,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,QAAA;AAAA,IACN,UAAA,EAAY;AAAA,MACV,IAAA,EAAM,EAAE,KAAA,EAAO,IAAA,EAAK;AAAA,MACpB,EAAA,EAAI,EAAE,KAAA,EAAO,QAAA,CAAS,IAAA,EAAK;AAAA,MAC3B;AAAA,KACF;AAAA,IACA,QAAA,EAAU,CAAC,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,IAC/B,oBAAA,EAAsB;AAAA,GACxB;AACF;AAEA,SAAS,WAAc,KAAA,EAAa;AAClC,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,KAAA,MAAW,SAAS,MAAA,CAAO,MAAA,CAAO,KAAK,CAAA,aAAc,KAAK,CAAA;AAC1D,EAAA,OAAO,OAAO,QAAA,CAAS,KAAK,IAAI,KAAA,GAAQ,MAAA,CAAO,OAAO,KAAK,CAAA;AAC7D","file":"json-schema.cjs","sourcesContent":["import { DEFAULT_EXPRESSION_LIMITS } from \"./limits.js\";\nimport {\n type ExpressionOperator,\n ExpressionProfile,\n MAX_EXPRESSION_OPERATOR_ARGS,\n} from \"./profile.js\";\nimport { standardV1 } from \"./standard-profile.js\";\n\nexport type ExpressionJsonSchema = Readonly<Record<string, unknown>>;\n\nconst jsonValueSchema = deepFreeze({\n anyOf: [\n { type: \"null\" },\n { type: \"boolean\" },\n { type: \"number\", minimum: -1.7976931348623157e308, maximum: 1.7976931348623157e308 },\n { type: \"string\", maxLength: DEFAULT_EXPRESSION_LIMITS.maxStringLength },\n {\n type: \"array\",\n maxItems: DEFAULT_EXPRESSION_LIMITS.maxNodes,\n items: { $ref: \"#/$defs/jsonValue\" },\n },\n {\n type: \"object\",\n maxProperties: DEFAULT_EXPRESSION_LIMITS.maxNodes,\n propertyNames: {\n allOf: [\n { maxLength: DEFAULT_EXPRESSION_LIMITS.maxStringLength },\n { not: { enum: [\"__proto__\", \"constructor\", \"prototype\"] } },\n ],\n },\n additionalProperties: { $ref: \"#/$defs/jsonValue\" },\n },\n ],\n});\n\n/** Generate a strict JSON Schema from one profile's public operator metadata. */\nexport function generateExpressionJsonSchema(profile: ExpressionProfile): ExpressionJsonSchema {\n if (!(profile instanceof ExpressionProfile))\n throw new TypeError(\"An expression profile is required.\");\n const operatorSchemas = profile.definitions.map(operatorSchema);\n return deepFreeze({\n $schema: \"https://json-schema.org/draft/2020-12/schema\",\n $id: `https://kuery.dev/schema/expression/${encodeURIComponent(profile.name)}`,\n $comment:\n \"This schema enforces recursive shape and profile constraints only; aggregate maxNodes and maxDepth limits are runtime-authoritative during canonicalization and compilation.\",\n $ref: \"#/$defs/expression\",\n $defs: {\n jsonValue: jsonValueSchema,\n expression: {\n oneOf: [\n literalSchema(),\n referenceSchema(),\n ...(operatorSchemas.length ? operatorSchemas : [neverSchema()]),\n ],\n },\n },\n });\n}\n\nfunction neverSchema(): false {\n return false;\n}\n\n/** Strict schema for the built-in standard-v1 profile and default string references. */\nexport function getStandardExpressionJsonSchema(): ExpressionJsonSchema {\n return generateExpressionJsonSchema(standardV1);\n}\n\nfunction literalSchema(): Record<string, unknown> {\n return {\n type: \"object\",\n properties: { kind: { const: \"literal\" }, value: { $ref: \"#/$defs/jsonValue\" } },\n required: [\"kind\", \"value\"],\n additionalProperties: false,\n };\n}\n\nfunction referenceSchema(): Record<string, unknown> {\n return {\n type: \"object\",\n properties: {\n kind: { const: \"ref\" },\n ref: {\n type: \"string\",\n minLength: 1,\n maxLength: DEFAULT_EXPRESSION_LIMITS.maxReferenceLength,\n },\n },\n required: [\"kind\", \"ref\"],\n additionalProperties: false,\n };\n}\n\nfunction operatorSchema(operator: ExpressionOperator): Record<string, unknown> {\n const args: Record<string, unknown> = {\n type: \"array\",\n items: { $ref: \"#/$defs/expression\" },\n minItems: operator.arity ?? operator.minArgs ?? 0,\n maxItems: operator.arity ?? operator.maxArgs ?? MAX_EXPRESSION_OPERATOR_ARGS,\n };\n return {\n type: \"object\",\n properties: {\n kind: { const: \"op\" },\n op: { const: operator.name },\n args,\n },\n required: [\"kind\", \"op\", \"args\"],\n additionalProperties: false,\n };\n}\n\nfunction deepFreeze<T>(value: T): T {\n if (typeof value !== \"object\" || value === null) return value;\n for (const child of Object.values(value)) deepFreeze(child);\n return Object.isFrozen(value) ? value : Object.freeze(value);\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { ExpressionProfile } from './profile.cjs';
2
+ import './types.cjs';
3
+
4
+ type ExpressionJsonSchema = Readonly<Record<string, unknown>>;
5
+ /** Generate a strict JSON Schema from one profile's public operator metadata. */
6
+ declare function generateExpressionJsonSchema(profile: ExpressionProfile): ExpressionJsonSchema;
7
+ /** Strict schema for the built-in standard-v1 profile and default string references. */
8
+ declare function getStandardExpressionJsonSchema(): ExpressionJsonSchema;
9
+
10
+ export { type ExpressionJsonSchema, generateExpressionJsonSchema, getStandardExpressionJsonSchema };
@@ -0,0 +1,10 @@
1
+ import { ExpressionProfile } from './profile.js';
2
+ import './types.js';
3
+
4
+ type ExpressionJsonSchema = Readonly<Record<string, unknown>>;
5
+ /** Generate a strict JSON Schema from one profile's public operator metadata. */
6
+ declare function generateExpressionJsonSchema(profile: ExpressionProfile): ExpressionJsonSchema;
7
+ /** Strict schema for the built-in standard-v1 profile and default string references. */
8
+ declare function getStandardExpressionJsonSchema(): ExpressionJsonSchema;
9
+
10
+ export { type ExpressionJsonSchema, generateExpressionJsonSchema, getStandardExpressionJsonSchema };
@@ -0,0 +1,105 @@
1
+ import { DEFAULT_EXPRESSION_LIMITS } from './limits.js';
2
+ import { ExpressionProfile, MAX_EXPRESSION_OPERATOR_ARGS } from './profile.js';
3
+ import { standardV1 } from './standard-profile.js';
4
+
5
+ const jsonValueSchema = deepFreeze({
6
+ anyOf: [
7
+ { type: "null" },
8
+ { type: "boolean" },
9
+ { type: "number", minimum: -17976931348623157e292, maximum: 17976931348623157e292 },
10
+ { type: "string", maxLength: DEFAULT_EXPRESSION_LIMITS.maxStringLength },
11
+ {
12
+ type: "array",
13
+ maxItems: DEFAULT_EXPRESSION_LIMITS.maxNodes,
14
+ items: { $ref: "#/$defs/jsonValue" }
15
+ },
16
+ {
17
+ type: "object",
18
+ maxProperties: DEFAULT_EXPRESSION_LIMITS.maxNodes,
19
+ propertyNames: {
20
+ allOf: [
21
+ { maxLength: DEFAULT_EXPRESSION_LIMITS.maxStringLength },
22
+ { not: { enum: ["__proto__", "constructor", "prototype"] } }
23
+ ]
24
+ },
25
+ additionalProperties: { $ref: "#/$defs/jsonValue" }
26
+ }
27
+ ]
28
+ });
29
+ function generateExpressionJsonSchema(profile) {
30
+ if (!(profile instanceof ExpressionProfile))
31
+ throw new TypeError("An expression profile is required.");
32
+ const operatorSchemas = profile.definitions.map(operatorSchema);
33
+ return deepFreeze({
34
+ $schema: "https://json-schema.org/draft/2020-12/schema",
35
+ $id: `https://kuery.dev/schema/expression/${encodeURIComponent(profile.name)}`,
36
+ $comment: "This schema enforces recursive shape and profile constraints only; aggregate maxNodes and maxDepth limits are runtime-authoritative during canonicalization and compilation.",
37
+ $ref: "#/$defs/expression",
38
+ $defs: {
39
+ jsonValue: jsonValueSchema,
40
+ expression: {
41
+ oneOf: [
42
+ literalSchema(),
43
+ referenceSchema(),
44
+ ...operatorSchemas.length ? operatorSchemas : [neverSchema()]
45
+ ]
46
+ }
47
+ }
48
+ });
49
+ }
50
+ function neverSchema() {
51
+ return false;
52
+ }
53
+ function getStandardExpressionJsonSchema() {
54
+ return generateExpressionJsonSchema(standardV1);
55
+ }
56
+ function literalSchema() {
57
+ return {
58
+ type: "object",
59
+ properties: { kind: { const: "literal" }, value: { $ref: "#/$defs/jsonValue" } },
60
+ required: ["kind", "value"],
61
+ additionalProperties: false
62
+ };
63
+ }
64
+ function referenceSchema() {
65
+ return {
66
+ type: "object",
67
+ properties: {
68
+ kind: { const: "ref" },
69
+ ref: {
70
+ type: "string",
71
+ minLength: 1,
72
+ maxLength: DEFAULT_EXPRESSION_LIMITS.maxReferenceLength
73
+ }
74
+ },
75
+ required: ["kind", "ref"],
76
+ additionalProperties: false
77
+ };
78
+ }
79
+ function operatorSchema(operator) {
80
+ const args = {
81
+ type: "array",
82
+ items: { $ref: "#/$defs/expression" },
83
+ minItems: operator.arity ?? operator.minArgs ?? 0,
84
+ maxItems: operator.arity ?? operator.maxArgs ?? MAX_EXPRESSION_OPERATOR_ARGS
85
+ };
86
+ return {
87
+ type: "object",
88
+ properties: {
89
+ kind: { const: "op" },
90
+ op: { const: operator.name },
91
+ args
92
+ },
93
+ required: ["kind", "op", "args"],
94
+ additionalProperties: false
95
+ };
96
+ }
97
+ function deepFreeze(value) {
98
+ if (typeof value !== "object" || value === null) return value;
99
+ for (const child of Object.values(value)) deepFreeze(child);
100
+ return Object.isFrozen(value) ? value : Object.freeze(value);
101
+ }
102
+
103
+ export { generateExpressionJsonSchema, getStandardExpressionJsonSchema };
104
+ //# sourceMappingURL=json-schema.js.map
105
+ //# sourceMappingURL=json-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kuery-v1/json-schema.ts"],"names":[],"mappings":";;;;AAUA,MAAM,kBAAkB,UAAA,CAAW;AAAA,EACjC,KAAA,EAAO;AAAA,IACL,EAAE,MAAM,MAAA,EAAO;AAAA,IACf,EAAE,MAAM,SAAA,EAAU;AAAA,IAClB,EAAE,IAAA,EAAM,QAAA,EAAU,OAAA,EAAS,sBAAA,EAAyB,SAAS,qBAAA,EAAuB;AAAA,IACpF,EAAE,IAAA,EAAM,QAAA,EAAU,SAAA,EAAW,0BAA0B,eAAA,EAAgB;AAAA,IACvE;AAAA,MACE,IAAA,EAAM,OAAA;AAAA,MACN,UAAU,yBAAA,CAA0B,QAAA;AAAA,MACpC,KAAA,EAAO,EAAE,IAAA,EAAM,mBAAA;AAAoB,KACrC;AAAA,IACA;AAAA,MACE,IAAA,EAAM,QAAA;AAAA,MACN,eAAe,yBAAA,CAA0B,QAAA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AAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,KAAA,MAAW,SAAS,MAAA,CAAO,MAAA,CAAO,KAAK,CAAA,aAAc,KAAK,CAAA;AAC1D,EAAA,OAAO,OAAO,QAAA,CAAS,KAAK,IAAI,KAAA,GAAQ,MAAA,CAAO,OAAO,KAAK,CAAA;AAC7D","file":"json-schema.js","sourcesContent":["import { DEFAULT_EXPRESSION_LIMITS } from \"./limits.js\";\nimport {\n type ExpressionOperator,\n ExpressionProfile,\n MAX_EXPRESSION_OPERATOR_ARGS,\n} from \"./profile.js\";\nimport { standardV1 } from \"./standard-profile.js\";\n\nexport type ExpressionJsonSchema = Readonly<Record<string, unknown>>;\n\nconst jsonValueSchema = deepFreeze({\n anyOf: [\n { type: \"null\" },\n { type: \"boolean\" },\n { type: \"number\", minimum: -1.7976931348623157e308, maximum: 1.7976931348623157e308 },\n { type: \"string\", maxLength: DEFAULT_EXPRESSION_LIMITS.maxStringLength },\n {\n type: \"array\",\n maxItems: DEFAULT_EXPRESSION_LIMITS.maxNodes,\n items: { $ref: \"#/$defs/jsonValue\" },\n },\n {\n type: \"object\",\n maxProperties: DEFAULT_EXPRESSION_LIMITS.maxNodes,\n propertyNames: {\n allOf: [\n { maxLength: DEFAULT_EXPRESSION_LIMITS.maxStringLength },\n { not: { enum: [\"__proto__\", \"constructor\", \"prototype\"] } },\n ],\n },\n additionalProperties: { $ref: \"#/$defs/jsonValue\" },\n },\n ],\n});\n\n/** Generate a strict JSON Schema from one profile's public operator metadata. */\nexport function generateExpressionJsonSchema(profile: ExpressionProfile): ExpressionJsonSchema {\n if (!(profile instanceof ExpressionProfile))\n throw new TypeError(\"An expression profile is required.\");\n const operatorSchemas = profile.definitions.map(operatorSchema);\n return deepFreeze({\n $schema: \"https://json-schema.org/draft/2020-12/schema\",\n $id: `https://kuery.dev/schema/expression/${encodeURIComponent(profile.name)}`,\n $comment:\n \"This schema enforces recursive shape and profile constraints only; aggregate maxNodes and maxDepth limits are runtime-authoritative during canonicalization and compilation.\",\n $ref: \"#/$defs/expression\",\n $defs: {\n jsonValue: jsonValueSchema,\n expression: {\n oneOf: [\n literalSchema(),\n referenceSchema(),\n ...(operatorSchemas.length ? operatorSchemas : [neverSchema()]),\n ],\n },\n },\n });\n}\n\nfunction neverSchema(): false {\n return false;\n}\n\n/** Strict schema for the built-in standard-v1 profile and default string references. */\nexport function getStandardExpressionJsonSchema(): ExpressionJsonSchema {\n return generateExpressionJsonSchema(standardV1);\n}\n\nfunction literalSchema(): Record<string, unknown> {\n return {\n type: \"object\",\n properties: { kind: { const: \"literal\" }, value: { $ref: \"#/$defs/jsonValue\" } },\n required: [\"kind\", \"value\"],\n additionalProperties: false,\n };\n}\n\nfunction referenceSchema(): Record<string, unknown> {\n return {\n type: \"object\",\n properties: {\n kind: { const: \"ref\" },\n ref: {\n type: \"string\",\n minLength: 1,\n maxLength: DEFAULT_EXPRESSION_LIMITS.maxReferenceLength,\n },\n },\n required: [\"kind\", \"ref\"],\n additionalProperties: false,\n };\n}\n\nfunction operatorSchema(operator: ExpressionOperator): Record<string, unknown> {\n const args: Record<string, unknown> = {\n type: \"array\",\n items: { $ref: \"#/$defs/expression\" },\n minItems: operator.arity ?? operator.minArgs ?? 0,\n maxItems: operator.arity ?? operator.maxArgs ?? MAX_EXPRESSION_OPERATOR_ARGS,\n };\n return {\n type: \"object\",\n properties: {\n kind: { const: \"op\" },\n op: { const: operator.name },\n args,\n },\n required: [\"kind\", \"op\", \"args\"],\n additionalProperties: false,\n };\n}\n\nfunction deepFreeze<T>(value: T): T {\n if (typeof value !== \"object\" || value === null) return value;\n for (const child of Object.values(value)) deepFreeze(child);\n return Object.isFrozen(value) ? value : Object.freeze(value);\n}\n"]}
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var profile_js = require('./profile.js');
4
+
5
+ const DEFAULT_EXPRESSION_LIMITS = Object.freeze({
6
+ maxDepth: 64,
7
+ maxNodes: 1e4,
8
+ maxArgs: profile_js.MAX_EXPRESSION_OPERATOR_ARGS,
9
+ maxStringLength: 1e4,
10
+ maxReferenceLength: 1e3,
11
+ maxEvaluationSteps: 1e4
12
+ });
13
+ const MAX_EXPRESSION_LIMITS = Object.freeze({
14
+ maxDepth: 256,
15
+ maxNodes: 1e5,
16
+ maxArgs: profile_js.MAX_EXPRESSION_OPERATOR_ARGS,
17
+ maxStringLength: 1e6,
18
+ maxReferenceLength: 1e5,
19
+ maxEvaluationSteps: 1e5
20
+ });
21
+ function resolveLimits(input) {
22
+ const limits = { ...DEFAULT_EXPRESSION_LIMITS, ...input };
23
+ for (const key of Object.keys(limits)) {
24
+ const value = limits[key];
25
+ if (!Number.isSafeInteger(value) || value < 1 || value > MAX_EXPRESSION_LIMITS[key]) {
26
+ throw new TypeError("Expression limits must be positive safe integers.");
27
+ }
28
+ }
29
+ return Object.freeze(limits);
30
+ }
31
+
32
+ exports.DEFAULT_EXPRESSION_LIMITS = DEFAULT_EXPRESSION_LIMITS;
33
+ exports.resolveLimits = resolveLimits;
34
+ //# sourceMappingURL=limits.cjs.map
35
+ //# sourceMappingURL=limits.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kuery-v1/limits.ts"],"names":["MAX_EXPRESSION_OPERATOR_ARGS"],"mappings":";;;;AAGO,MAAM,yBAAA,GAA8C,OAAO,MAAA,CAAO;AAAA,EACvE,QAAA,EAAU,EAAA;AAAA,EACV,QAAA,EAAU,GAAA;AAAA,EACV,OAAA,EAASA,uCAAA;AAAA,EACT,eAAA,EAAiB,GAAA;AAAA,EACjB,kBAAA,EAAoB,GAAA;AAAA,EACpB,kBAAA,EAAoB;AACtB,CAAC;AAED,MAAM,qBAAA,GAA0C,OAAO,MAAA,CAAO;AAAA,EAC5D,QAAA,EAAU,GAAA;AAAA,EACV,QAAA,EAAU,GAAA;AAAA,EACV,OAAA,EAASA,uCAAA;AAAA,EACT,eAAA,EAAiB,GAAA;AAAA,EACjB,kBAAA,EAAoB,GAAA;AAAA,EACpB,kBAAA,EAAoB;AACtB,CAAC,CAAA;AAEM,SAAS,cAAc,KAAA,EAAqD;AACjF,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,yBAAA,EAA2B,GAAG,KAAA,EAAM;AACxD,EAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,EAAiC;AACnE,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,CAAC,MAAA,CAAO,aAAA,CAAc,KAAK,CAAA,IAAK,QAAQ,CAAA,IAAK,KAAA,GAAQ,qBAAA,CAAsB,GAAG,CAAA,EAAG;AACnF,MAAA,MAAM,IAAI,UAAU,mDAAmD,CAAA;AAAA,IACzE;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,OAAO,MAAM,CAAA;AAC7B","file":"limits.cjs","sourcesContent":["import { MAX_EXPRESSION_OPERATOR_ARGS } from \"./profile.js\";\nimport type { ExpressionLimits } from \"./types.js\";\n\nexport const DEFAULT_EXPRESSION_LIMITS: ExpressionLimits = Object.freeze({\n maxDepth: 64,\n maxNodes: 10_000,\n maxArgs: MAX_EXPRESSION_OPERATOR_ARGS,\n maxStringLength: 10_000,\n maxReferenceLength: 1_000,\n maxEvaluationSteps: 10_000,\n});\n\nconst MAX_EXPRESSION_LIMITS: ExpressionLimits = Object.freeze({\n maxDepth: 256,\n maxNodes: 100_000,\n maxArgs: MAX_EXPRESSION_OPERATOR_ARGS,\n maxStringLength: 1_000_000,\n maxReferenceLength: 100_000,\n maxEvaluationSteps: 100_000,\n});\n\nexport function resolveLimits(input?: Partial<ExpressionLimits>): ExpressionLimits {\n const limits = { ...DEFAULT_EXPRESSION_LIMITS, ...input };\n for (const key of Object.keys(limits) as (keyof ExpressionLimits)[]) {\n const value = limits[key];\n if (!Number.isSafeInteger(value) || value < 1 || value > MAX_EXPRESSION_LIMITS[key]) {\n throw new TypeError(\"Expression limits must be positive safe integers.\");\n }\n }\n return Object.freeze(limits);\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { ExpressionLimits } from './types.cjs';
2
+
3
+ declare const DEFAULT_EXPRESSION_LIMITS: ExpressionLimits;
4
+ declare function resolveLimits(input?: Partial<ExpressionLimits>): ExpressionLimits;
5
+
6
+ export { DEFAULT_EXPRESSION_LIMITS, resolveLimits };
@@ -0,0 +1,6 @@
1
+ import { ExpressionLimits } from './types.js';
2
+
3
+ declare const DEFAULT_EXPRESSION_LIMITS: ExpressionLimits;
4
+ declare function resolveLimits(input?: Partial<ExpressionLimits>): ExpressionLimits;
5
+
6
+ export { DEFAULT_EXPRESSION_LIMITS, resolveLimits };
@@ -0,0 +1,32 @@
1
+ import { MAX_EXPRESSION_OPERATOR_ARGS } from './profile.js';
2
+
3
+ const DEFAULT_EXPRESSION_LIMITS = Object.freeze({
4
+ maxDepth: 64,
5
+ maxNodes: 1e4,
6
+ maxArgs: MAX_EXPRESSION_OPERATOR_ARGS,
7
+ maxStringLength: 1e4,
8
+ maxReferenceLength: 1e3,
9
+ maxEvaluationSteps: 1e4
10
+ });
11
+ const MAX_EXPRESSION_LIMITS = Object.freeze({
12
+ maxDepth: 256,
13
+ maxNodes: 1e5,
14
+ maxArgs: MAX_EXPRESSION_OPERATOR_ARGS,
15
+ maxStringLength: 1e6,
16
+ maxReferenceLength: 1e5,
17
+ maxEvaluationSteps: 1e5
18
+ });
19
+ function resolveLimits(input) {
20
+ const limits = { ...DEFAULT_EXPRESSION_LIMITS, ...input };
21
+ for (const key of Object.keys(limits)) {
22
+ const value = limits[key];
23
+ if (!Number.isSafeInteger(value) || value < 1 || value > MAX_EXPRESSION_LIMITS[key]) {
24
+ throw new TypeError("Expression limits must be positive safe integers.");
25
+ }
26
+ }
27
+ return Object.freeze(limits);
28
+ }
29
+
30
+ export { DEFAULT_EXPRESSION_LIMITS, resolveLimits };
31
+ //# sourceMappingURL=limits.js.map
32
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kuery-v1/limits.ts"],"names":[],"mappings":";;AAGO,MAAM,yBAAA,GAA8C,OAAO,MAAA,CAAO;AAAA,EACvE,QAAA,EAAU,EAAA;AAAA,EACV,QAAA,EAAU,GAAA;AAAA,EACV,OAAA,EAAS,4BAAA;AAAA,EACT,eAAA,EAAiB,GAAA;AAAA,EACjB,kBAAA,EAAoB,GAAA;AAAA,EACpB,kBAAA,EAAoB;AACtB,CAAC;AAED,MAAM,qBAAA,GAA0C,OAAO,MAAA,CAAO;AAAA,EAC5D,QAAA,EAAU,GAAA;AAAA,EACV,QAAA,EAAU,GAAA;AAAA,EACV,OAAA,EAAS,4BAAA;AAAA,EACT,eAAA,EAAiB,GAAA;AAAA,EACjB,kBAAA,EAAoB,GAAA;AAAA,EACpB,kBAAA,EAAoB;AACtB,CAAC,CAAA;AAEM,SAAS,cAAc,KAAA,EAAqD;AACjF,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,yBAAA,EAA2B,GAAG,KAAA,EAAM;AACxD,EAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,EAAiC;AACnE,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,CAAC,MAAA,CAAO,aAAA,CAAc,KAAK,CAAA,IAAK,QAAQ,CAAA,IAAK,KAAA,GAAQ,qBAAA,CAAsB,GAAG,CAAA,EAAG;AACnF,MAAA,MAAM,IAAI,UAAU,mDAAmD,CAAA;AAAA,IACzE;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,OAAO,MAAM,CAAA;AAC7B","file":"limits.js","sourcesContent":["import { MAX_EXPRESSION_OPERATOR_ARGS } from \"./profile.js\";\nimport type { ExpressionLimits } from \"./types.js\";\n\nexport const DEFAULT_EXPRESSION_LIMITS: ExpressionLimits = Object.freeze({\n maxDepth: 64,\n maxNodes: 10_000,\n maxArgs: MAX_EXPRESSION_OPERATOR_ARGS,\n maxStringLength: 10_000,\n maxReferenceLength: 1_000,\n maxEvaluationSteps: 10_000,\n});\n\nconst MAX_EXPRESSION_LIMITS: ExpressionLimits = Object.freeze({\n maxDepth: 256,\n maxNodes: 100_000,\n maxArgs: MAX_EXPRESSION_OPERATOR_ARGS,\n maxStringLength: 1_000_000,\n maxReferenceLength: 100_000,\n maxEvaluationSteps: 100_000,\n});\n\nexport function resolveLimits(input?: Partial<ExpressionLimits>): ExpressionLimits {\n const limits = { ...DEFAULT_EXPRESSION_LIMITS, ...input };\n for (const key of Object.keys(limits) as (keyof ExpressionLimits)[]) {\n const value = limits[key];\n if (!Number.isSafeInteger(value) || value < 1 || value > MAX_EXPRESSION_LIMITS[key]) {\n throw new TypeError(\"Expression limits must be positive safe integers.\");\n }\n }\n return Object.freeze(limits);\n}\n"]}