@dyrected/core 2.12.0 → 2.13.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.
@@ -1,1758 +1,33 @@
1
1
  import {
2
- __commonJS,
2
+ require_Jexl
3
+ } from "./chunk-27YRIGK5.js";
4
+ import {
3
5
  __toESM
4
6
  } from "./chunk-JSBRDJBE.js";
5
7
 
6
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/interopRequireDefault.js
7
- var require_interopRequireDefault = __commonJS({
8
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/interopRequireDefault.js"(exports, module) {
9
- "use strict";
10
- function _interopRequireDefault(e) {
11
- return e && e.__esModule ? e : {
12
- "default": e
13
- };
14
- }
15
- module.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports["default"] = module.exports;
16
- }
17
- });
18
-
19
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/typeof.js
20
- var require_typeof = __commonJS({
21
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/typeof.js"(exports, module) {
22
- "use strict";
23
- function _typeof(o) {
24
- "@babel/helpers - typeof";
25
- return module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
26
- return typeof o2;
27
- } : function(o2) {
28
- return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
29
- }, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof(o);
30
- }
31
- module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
32
- }
33
- });
34
-
35
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/toPrimitive.js
36
- var require_toPrimitive = __commonJS({
37
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/toPrimitive.js"(exports, module) {
38
- "use strict";
39
- var _typeof = require_typeof()["default"];
40
- function toPrimitive(t, r) {
41
- if ("object" != _typeof(t) || !t) return t;
42
- var e = t[Symbol.toPrimitive];
43
- if (void 0 !== e) {
44
- var i = e.call(t, r || "default");
45
- if ("object" != _typeof(i)) return i;
46
- throw new TypeError("@@toPrimitive must return a primitive value.");
47
- }
48
- return ("string" === r ? String : Number)(t);
49
- }
50
- module.exports = toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports;
51
- }
52
- });
53
-
54
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/toPropertyKey.js
55
- var require_toPropertyKey = __commonJS({
56
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/toPropertyKey.js"(exports, module) {
57
- "use strict";
58
- var _typeof = require_typeof()["default"];
59
- var toPrimitive = require_toPrimitive();
60
- function toPropertyKey(t) {
61
- var i = toPrimitive(t, "string");
62
- return "symbol" == _typeof(i) ? i : i + "";
63
- }
64
- module.exports = toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports;
65
- }
66
- });
67
-
68
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/defineProperty.js
69
- var require_defineProperty = __commonJS({
70
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/defineProperty.js"(exports, module) {
71
- "use strict";
72
- var toPropertyKey = require_toPropertyKey();
73
- function _defineProperty(e, r, t) {
74
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
75
- value: t,
76
- enumerable: true,
77
- configurable: true,
78
- writable: true
79
- }) : e[r] = t, e;
80
- }
81
- module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
82
- }
83
- });
84
-
85
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/classCallCheck.js
86
- var require_classCallCheck = __commonJS({
87
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/classCallCheck.js"(exports, module) {
88
- "use strict";
89
- function _classCallCheck(a, n) {
90
- if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
91
- }
92
- module.exports = _classCallCheck, module.exports.__esModule = true, module.exports["default"] = module.exports;
93
- }
94
- });
95
-
96
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/createClass.js
97
- var require_createClass = __commonJS({
98
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/createClass.js"(exports, module) {
99
- "use strict";
100
- var toPropertyKey = require_toPropertyKey();
101
- function _defineProperties(e, r) {
102
- for (var t = 0; t < r.length; t++) {
103
- var o = r[t];
104
- o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, toPropertyKey(o.key), o);
105
- }
106
- }
107
- function _createClass(e, r, t) {
108
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
109
- writable: false
110
- }), e;
111
- }
112
- module.exports = _createClass, module.exports.__esModule = true, module.exports["default"] = module.exports;
113
- }
114
- });
115
-
116
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/arrayLikeToArray.js
117
- var require_arrayLikeToArray = __commonJS({
118
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/arrayLikeToArray.js"(exports, module) {
119
- "use strict";
120
- function _arrayLikeToArray(r, a) {
121
- (null == a || a > r.length) && (a = r.length);
122
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
123
- return n;
124
- }
125
- module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
126
- }
127
- });
128
-
129
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/arrayWithoutHoles.js
130
- var require_arrayWithoutHoles = __commonJS({
131
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/arrayWithoutHoles.js"(exports, module) {
132
- "use strict";
133
- var arrayLikeToArray = require_arrayLikeToArray();
134
- function _arrayWithoutHoles(r) {
135
- if (Array.isArray(r)) return arrayLikeToArray(r);
136
- }
137
- module.exports = _arrayWithoutHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
138
- }
139
- });
140
-
141
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/iterableToArray.js
142
- var require_iterableToArray = __commonJS({
143
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/iterableToArray.js"(exports, module) {
144
- "use strict";
145
- function _iterableToArray(r) {
146
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
147
- }
148
- module.exports = _iterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
149
- }
150
- });
151
-
152
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js
153
- var require_unsupportedIterableToArray = __commonJS({
154
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js"(exports, module) {
155
- "use strict";
156
- var arrayLikeToArray = require_arrayLikeToArray();
157
- function _unsupportedIterableToArray(r, a) {
158
- if (r) {
159
- if ("string" == typeof r) return arrayLikeToArray(r, a);
160
- var t = {}.toString.call(r).slice(8, -1);
161
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? arrayLikeToArray(r, a) : void 0;
162
- }
163
- }
164
- module.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
165
- }
166
- });
167
-
168
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/nonIterableSpread.js
169
- var require_nonIterableSpread = __commonJS({
170
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/nonIterableSpread.js"(exports, module) {
171
- "use strict";
172
- function _nonIterableSpread() {
173
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
174
- }
175
- module.exports = _nonIterableSpread, module.exports.__esModule = true, module.exports["default"] = module.exports;
176
- }
177
- });
178
-
179
- // ../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/toConsumableArray.js
180
- var require_toConsumableArray = __commonJS({
181
- "../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/toConsumableArray.js"(exports, module) {
182
- "use strict";
183
- var arrayWithoutHoles = require_arrayWithoutHoles();
184
- var iterableToArray = require_iterableToArray();
185
- var unsupportedIterableToArray = require_unsupportedIterableToArray();
186
- var nonIterableSpread = require_nonIterableSpread();
187
- function _toConsumableArray(r) {
188
- return arrayWithoutHoles(r) || iterableToArray(r) || unsupportedIterableToArray(r) || nonIterableSpread();
189
- }
190
- module.exports = _toConsumableArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
191
- }
192
- });
193
-
194
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/evaluator/handlers.js
195
- var require_handlers = __commonJS({
196
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/evaluator/handlers.js"(exports) {
197
- "use strict";
198
- var _interopRequireDefault = require_interopRequireDefault();
199
- var _toConsumableArray2 = _interopRequireDefault(require_toConsumableArray());
200
- var poolNames = {
201
- functions: "Jexl Function",
202
- transforms: "Transform"
203
- };
204
- exports.ArrayLiteral = function(ast) {
205
- return this.evalArray(ast.value);
206
- };
207
- exports.BinaryExpression = function(ast) {
208
- var _this = this;
209
- var grammarOp = this._grammar.elements[ast.operator];
210
- if (grammarOp.evalOnDemand) {
211
- var wrap = function wrap2(subAst) {
212
- return {
213
- eval: function _eval() {
214
- return _this.eval(subAst);
215
- }
216
- };
217
- };
218
- return grammarOp.evalOnDemand(wrap(ast.left), wrap(ast.right));
219
- }
220
- return this.Promise.all([this.eval(ast.left), this.eval(ast.right)]).then(function(arr) {
221
- return grammarOp.eval(arr[0], arr[1]);
222
- });
223
- };
224
- exports.ConditionalExpression = function(ast) {
225
- var _this2 = this;
226
- return this.eval(ast.test).then(function(res) {
227
- if (res) {
228
- if (ast.consequent) {
229
- return _this2.eval(ast.consequent);
230
- }
231
- return res;
232
- }
233
- return _this2.eval(ast.alternate);
234
- });
235
- };
236
- exports.FilterExpression = function(ast) {
237
- var _this3 = this;
238
- return this.eval(ast.subject).then(function(subject) {
239
- if (ast.relative) {
240
- return _this3._filterRelative(subject, ast.expr);
241
- }
242
- return _this3._filterStatic(subject, ast.expr);
243
- });
244
- };
245
- exports.Identifier = function(ast) {
246
- if (!ast.from) {
247
- return ast.relative ? this._relContext[ast.value] : this._context[ast.value];
248
- }
249
- return this.eval(ast.from).then(function(context) {
250
- if (context === void 0 || context === null) {
251
- return void 0;
252
- }
253
- if (Array.isArray(context)) {
254
- context = context[0];
255
- }
256
- return context[ast.value];
257
- });
258
- };
259
- exports.Literal = function(ast) {
260
- return ast.value;
261
- };
262
- exports.ObjectLiteral = function(ast) {
263
- return this.evalMap(ast.value);
264
- };
265
- exports.FunctionCall = function(ast) {
266
- var poolName = poolNames[ast.pool];
267
- if (!poolName) {
268
- throw new Error("Corrupt AST: Pool '".concat(ast.pool, "' not found"));
269
- }
270
- var pool = this._grammar[ast.pool];
271
- var func = pool[ast.name];
272
- if (!func) {
273
- throw new Error("".concat(poolName, " ").concat(ast.name, " is not defined."));
274
- }
275
- return this.evalArray(ast.args || []).then(function(args) {
276
- return func.apply(void 0, (0, _toConsumableArray2.default)(args));
277
- });
278
- };
279
- exports.UnaryExpression = function(ast) {
280
- var _this4 = this;
281
- return this.eval(ast.right).then(function(right) {
282
- return _this4._grammar.elements[ast.operator].eval(right);
283
- });
284
- };
285
- }
286
- });
287
-
288
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/evaluator/Evaluator.js
289
- var require_Evaluator = __commonJS({
290
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/evaluator/Evaluator.js"(exports, module) {
291
- "use strict";
292
- var _interopRequireDefault = require_interopRequireDefault();
293
- var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
294
- var _createClass2 = _interopRequireDefault(require_createClass());
295
- var handlers = require_handlers();
296
- var Evaluator = /* @__PURE__ */ (function() {
297
- function Evaluator2(grammar, context, relativeContext) {
298
- var promise = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : Promise;
299
- (0, _classCallCheck2.default)(this, Evaluator2);
300
- this._grammar = grammar;
301
- this._context = context || {};
302
- this._relContext = relativeContext || this._context;
303
- this.Promise = promise;
304
- }
305
- (0, _createClass2.default)(Evaluator2, [{
306
- key: "eval",
307
- value: function _eval(ast) {
308
- var _this = this;
309
- return this.Promise.resolve().then(function() {
310
- return handlers[ast.type].call(_this, ast);
311
- });
312
- }
313
- /**
314
- * Simultaneously evaluates each expression within an array, and delivers the
315
- * response as an array with the resulting values at the same indexes as their
316
- * originating expressions.
317
- * @param {Array<string>} arr An array of expression strings to be evaluated
318
- * @returns {Promise<Array<{}>>} resolves with the result array
319
- */
320
- }, {
321
- key: "evalArray",
322
- value: function evalArray(arr) {
323
- var _this2 = this;
324
- return this.Promise.all(arr.map(function(elem) {
325
- return _this2.eval(elem);
326
- }));
327
- }
328
- /**
329
- * Simultaneously evaluates each expression within a map, and delivers the
330
- * response as a map with the same keys, but with the evaluated result for each
331
- * as their value.
332
- * @param {{}} map A map of expression names to expression trees to be
333
- * evaluated
334
- * @returns {Promise<{}>} resolves with the result map.
335
- */
336
- }, {
337
- key: "evalMap",
338
- value: function evalMap(map) {
339
- var _this3 = this;
340
- var keys = Object.keys(map);
341
- var result = {};
342
- var asts = keys.map(function(key) {
343
- return _this3.eval(map[key]);
344
- });
345
- return this.Promise.all(asts).then(function(vals) {
346
- vals.forEach(function(val, idx) {
347
- result[keys[idx]] = val;
348
- });
349
- return result;
350
- });
351
- }
352
- /**
353
- * Applies a filter expression with relative identifier elements to a subject.
354
- * The intent is for the subject to be an array of subjects that will be
355
- * individually used as the relative context against the provided expression
356
- * tree. Only the elements whose expressions result in a truthy value will be
357
- * included in the resulting array.
358
- *
359
- * If the subject is not an array of values, it will be converted to a single-
360
- * element array before running the filter.
361
- * @param {*} subject The value to be filtered usually an array. If this value is
362
- * not an array, it will be converted to an array with this value as the
363
- * only element.
364
- * @param {{}} expr The expression tree to run against each subject. If the
365
- * tree evaluates to a truthy result, then the value will be included in
366
- * the returned array otherwise, it will be eliminated.
367
- * @returns {Promise<Array>} resolves with an array of values that passed the
368
- * expression filter.
369
- * @private
370
- */
371
- }, {
372
- key: "_filterRelative",
373
- value: function _filterRelative(subject, expr) {
374
- var _this4 = this;
375
- var promises = [];
376
- if (!Array.isArray(subject)) {
377
- subject = subject === void 0 ? [] : [subject];
378
- }
379
- subject.forEach(function(elem) {
380
- var evalInst = new Evaluator2(_this4._grammar, _this4._context, elem, _this4.Promise);
381
- promises.push(evalInst.eval(expr));
382
- });
383
- return this.Promise.all(promises).then(function(values) {
384
- var results = [];
385
- values.forEach(function(value, idx) {
386
- if (value) {
387
- results.push(subject[idx]);
388
- }
389
- });
390
- return results;
391
- });
392
- }
393
- /**
394
- * Applies a static filter expression to a subject value. If the filter
395
- * expression evaluates to boolean true, the subject is returned if false,
396
- * undefined.
397
- *
398
- * For any other resulting value of the expression, this function will attempt
399
- * to respond with the property at that name or index of the subject.
400
- * @param {*} subject The value to be filtered. Usually an Array (for which
401
- * the expression would generally resolve to a numeric index) or an
402
- * Object (for which the expression would generally resolve to a string
403
- * indicating a property name)
404
- * @param {{}} expr The expression tree to run against the subject
405
- * @returns {Promise<*>} resolves with the value of the drill-down.
406
- * @private
407
- */
408
- }, {
409
- key: "_filterStatic",
410
- value: function _filterStatic(subject, expr) {
411
- return this.eval(expr).then(function(res) {
412
- if (typeof res === "boolean") {
413
- return res ? subject : void 0;
414
- }
415
- return subject[res];
416
- });
417
- }
418
- }]);
419
- return Evaluator2;
420
- })();
421
- module.exports = Evaluator;
422
- }
423
- });
424
-
425
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/Lexer.js
426
- var require_Lexer = __commonJS({
427
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/Lexer.js"(exports, module) {
428
- "use strict";
429
- var _interopRequireDefault = require_interopRequireDefault();
430
- var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
431
- var _createClass2 = _interopRequireDefault(require_createClass());
432
- var numericRegex = /^-?(?:(?:[0-9]*\.[0-9]+)|[0-9]+)$/;
433
- var identRegex = /^[a-zA-Zа-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$][a-zA-Zа-яА-Я0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$]*$/;
434
- var escEscRegex = /\\\\/;
435
- var whitespaceRegex = /^\s*$/;
436
- var preOpRegexElems = [
437
- // Strings
438
- "'(?:(?:\\\\')|[^'])*'",
439
- '"(?:(?:\\\\")|[^"])*"',
440
- // Whitespace
441
- "\\s+",
442
- // Booleans
443
- "\\btrue\\b",
444
- "\\bfalse\\b"
445
- ];
446
- var postOpRegexElems = [
447
- // Identifiers
448
- "[a-zA-Z\u0430-\u044F\u0410-\u042F_\xC0-\xD6\xD8-\xF6\xF8-\xFF\\$][a-zA-Z0-9\u0430-\u044F\u0410-\u042F_\xC0-\xD6\xD8-\xF6\xF8-\xFF\\$]*",
449
- // Numerics (without negative symbol)
450
- "(?:(?:[0-9]*\\.[0-9]+)|[0-9]+)"
451
- ];
452
- var minusNegatesAfter = ["binaryOp", "unaryOp", "openParen", "openBracket", "question", "colon"];
453
- var Lexer = /* @__PURE__ */ (function() {
454
- function Lexer2(grammar) {
455
- (0, _classCallCheck2.default)(this, Lexer2);
456
- this._grammar = grammar;
457
- }
458
- (0, _createClass2.default)(Lexer2, [{
459
- key: "getElements",
460
- value: function getElements(str) {
461
- var regex = this._getSplitRegex();
462
- return str.split(regex).filter(function(elem) {
463
- return elem;
464
- });
465
- }
466
- /**
467
- * Converts an array of expression elements into an array of tokens. Note that
468
- * the resulting array may not equal the element array in length, as any
469
- * elements that consist only of whitespace get appended to the previous
470
- * token's "raw" property. For the structure of a token object, please see
471
- * {@link Lexer#tokenize}.
472
- * @param {Array<string>} elements An array of Jexl expression elements to be
473
- * converted to tokens
474
- * @returns {Array<{type, value, raw}>} an array of token objects.
475
- */
476
- }, {
477
- key: "getTokens",
478
- value: function getTokens(elements) {
479
- var tokens = [];
480
- var negate = false;
481
- for (var i = 0; i < elements.length; i++) {
482
- if (this._isWhitespace(elements[i])) {
483
- if (tokens.length) {
484
- tokens[tokens.length - 1].raw += elements[i];
485
- }
486
- } else if (elements[i] === "-" && this._isNegative(tokens)) {
487
- negate = true;
488
- } else {
489
- if (negate) {
490
- elements[i] = "-" + elements[i];
491
- negate = false;
492
- }
493
- tokens.push(this._createToken(elements[i]));
494
- }
495
- }
496
- if (negate) {
497
- tokens.push(this._createToken("-"));
498
- }
499
- return tokens;
500
- }
501
- /**
502
- * Converts a Jexl string into an array of tokens. Each token is an object
503
- * in the following format:
504
- *
505
- * {
506
- * type: <string>,
507
- * [name]: <string>,
508
- * value: <boolean|number|string>,
509
- * raw: <string>
510
- * }
511
- *
512
- * Type is one of the following:
513
- *
514
- * literal, identifier, binaryOp, unaryOp
515
- *
516
- * OR, if the token is a control character its type is the name of the element
517
- * defined in the Grammar.
518
- *
519
- * Name appears only if the token is a control string found in
520
- * {@link grammar#elements}, and is set to the name of the element.
521
- *
522
- * Value is the value of the token in the correct type (boolean or numeric as
523
- * appropriate). Raw is the string representation of this value taken directly
524
- * from the expression string, including any trailing spaces.
525
- * @param {string} str The Jexl string to be tokenized
526
- * @returns {Array<{type, value, raw}>} an array of token objects.
527
- * @throws {Error} if the provided string contains an invalid token.
528
- */
529
- }, {
530
- key: "tokenize",
531
- value: function tokenize(str) {
532
- var elements = this.getElements(str);
533
- return this.getTokens(elements);
534
- }
535
- /**
536
- * Creates a new token object from an element of a Jexl string. See
537
- * {@link Lexer#tokenize} for a description of the token object.
538
- * @param {string} element The element from which a token should be made
539
- * @returns {{value: number|boolean|string, [name]: string, type: string,
540
- * raw: string}} a token object describing the provided element.
541
- * @throws {Error} if the provided string is not a valid expression element.
542
- * @private
543
- */
544
- }, {
545
- key: "_createToken",
546
- value: function _createToken(element) {
547
- var token = {
548
- type: "literal",
549
- value: element,
550
- raw: element
551
- };
552
- if (element[0] === '"' || element[0] === "'") {
553
- token.value = this._unquote(element);
554
- } else if (element.match(numericRegex)) {
555
- token.value = parseFloat(element);
556
- } else if (element === "true" || element === "false") {
557
- token.value = element === "true";
558
- } else if (this._grammar.elements[element]) {
559
- token.type = this._grammar.elements[element].type;
560
- } else if (element.match(identRegex)) {
561
- token.type = "identifier";
562
- } else {
563
- throw new Error("Invalid expression token: ".concat(element));
564
- }
565
- return token;
566
- }
567
- /**
568
- * Escapes a string so that it can be treated as a string literal within a
569
- * regular expression.
570
- * @param {string} str The string to be escaped
571
- * @returns {string} the RegExp-escaped string.
572
- * @see https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
573
- * @private
574
- */
575
- }, {
576
- key: "_escapeRegExp",
577
- value: function _escapeRegExp(str) {
578
- str = str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
579
- if (str.match(identRegex)) {
580
- str = "\\b" + str + "\\b";
581
- }
582
- return str;
583
- }
584
- /**
585
- * Gets a RegEx object appropriate for splitting a Jexl string into its core
586
- * elements.
587
- * @returns {RegExp} An element-splitting RegExp object
588
- * @private
589
- */
590
- }, {
591
- key: "_getSplitRegex",
592
- value: function _getSplitRegex() {
593
- var _this = this;
594
- if (!this._splitRegex) {
595
- var elemArray = Object.keys(this._grammar.elements).sort(function(a, b) {
596
- return b.length - a.length;
597
- }).map(function(elem) {
598
- return _this._escapeRegExp(elem);
599
- }, this);
600
- this._splitRegex = new RegExp("(" + [preOpRegexElems.join("|"), elemArray.join("|"), postOpRegexElems.join("|")].join("|") + ")");
601
- }
602
- return this._splitRegex;
603
- }
604
- /**
605
- * Determines whether the addition of a '-' token should be interpreted as a
606
- * negative symbol for an upcoming number, given an array of tokens already
607
- * processed.
608
- * @param {Array<Object>} tokens An array of tokens already processed
609
- * @returns {boolean} true if adding a '-' should be considered a negative
610
- * symbol; false otherwise
611
- * @private
612
- */
613
- }, {
614
- key: "_isNegative",
615
- value: function _isNegative(tokens) {
616
- if (!tokens.length) return true;
617
- return minusNegatesAfter.some(function(type) {
618
- return type === tokens[tokens.length - 1].type;
619
- });
620
- }
621
- /**
622
- * A utility function to determine if a string consists of only space
623
- * characters.
624
- * @param {string} str A string to be tested
625
- * @returns {boolean} true if the string is empty or consists of only spaces;
626
- * false otherwise.
627
- * @private
628
- */
629
- }, {
630
- key: "_isWhitespace",
631
- value: function _isWhitespace(str) {
632
- return !!str.match(whitespaceRegex);
633
- }
634
- /**
635
- * Removes the beginning and trailing quotes from a string, unescapes any
636
- * escaped quotes on its interior, and unescapes any escaped escape
637
- * characters. Note that this function is not defensive; it assumes that the
638
- * provided string is not empty, and that its first and last characters are
639
- * actually quotes.
640
- * @param {string} str A string whose first and last characters are quotes
641
- * @returns {string} a string with the surrounding quotes stripped and escapes
642
- * properly processed.
643
- * @private
644
- */
645
- }, {
646
- key: "_unquote",
647
- value: function _unquote(str) {
648
- var quote = str[0];
649
- var escQuoteRegex = new RegExp("\\\\" + quote, "g");
650
- return str.substr(1, str.length - 2).replace(escQuoteRegex, quote).replace(escEscRegex, "\\");
651
- }
652
- }]);
653
- return Lexer2;
654
- })();
655
- module.exports = Lexer;
656
- }
657
- });
658
-
659
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/parser/handlers.js
660
- var require_handlers2 = __commonJS({
661
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/parser/handlers.js"(exports) {
662
- "use strict";
663
- exports.argVal = function(ast) {
664
- if (ast) this._cursor.args.push(ast);
665
- };
666
- exports.arrayStart = function() {
667
- this._placeAtCursor({
668
- type: "ArrayLiteral",
669
- value: []
670
- });
671
- };
672
- exports.arrayVal = function(ast) {
673
- if (ast) {
674
- this._cursor.value.push(ast);
675
- }
676
- };
677
- exports.binaryOp = function(token) {
678
- var precedence = this._grammar.elements[token.value].precedence || 0;
679
- var parent = this._cursor._parent;
680
- while (parent && parent.operator && this._grammar.elements[parent.operator].precedence >= precedence) {
681
- this._cursor = parent;
682
- parent = parent._parent;
683
- }
684
- var node = {
685
- type: "BinaryExpression",
686
- operator: token.value,
687
- left: this._cursor
688
- };
689
- this._setParent(this._cursor, node);
690
- this._cursor = parent;
691
- this._placeAtCursor(node);
692
- };
693
- exports.dot = function() {
694
- this._nextIdentEncapsulate = this._cursor && this._cursor.type !== "UnaryExpression" && (this._cursor.type !== "BinaryExpression" || this._cursor.type === "BinaryExpression" && this._cursor.right);
695
- this._nextIdentRelative = !this._cursor || this._cursor && !this._nextIdentEncapsulate;
696
- if (this._nextIdentRelative) {
697
- this._relative = true;
698
- }
699
- };
700
- exports.filter = function(ast) {
701
- this._placeBeforeCursor({
702
- type: "FilterExpression",
703
- expr: ast,
704
- relative: this._subParser.isRelative(),
705
- subject: this._cursor
706
- });
707
- };
708
- exports.functionCall = function() {
709
- this._placeBeforeCursor({
710
- type: "FunctionCall",
711
- name: this._cursor.value,
712
- args: [],
713
- pool: "functions"
714
- });
715
- };
716
- exports.identifier = function(token) {
717
- var node = {
718
- type: "Identifier",
719
- value: token.value
720
- };
721
- if (this._nextIdentEncapsulate) {
722
- node.from = this._cursor;
723
- this._placeBeforeCursor(node);
724
- this._nextIdentEncapsulate = false;
725
- } else {
726
- if (this._nextIdentRelative) {
727
- node.relative = true;
728
- this._nextIdentRelative = false;
729
- }
730
- this._placeAtCursor(node);
731
- }
732
- };
733
- exports.literal = function(token) {
734
- this._placeAtCursor({
735
- type: "Literal",
736
- value: token.value
737
- });
738
- };
739
- exports.objKey = function(token) {
740
- this._curObjKey = token.value;
741
- };
742
- exports.objStart = function() {
743
- this._placeAtCursor({
744
- type: "ObjectLiteral",
745
- value: {}
746
- });
747
- };
748
- exports.objVal = function(ast) {
749
- this._cursor.value[this._curObjKey] = ast;
750
- };
751
- exports.subExpression = function(ast) {
752
- this._placeAtCursor(ast);
753
- };
754
- exports.ternaryEnd = function(ast) {
755
- this._cursor.alternate = ast;
756
- };
757
- exports.ternaryMid = function(ast) {
758
- this._cursor.consequent = ast;
759
- };
760
- exports.ternaryStart = function() {
761
- this._tree = {
762
- type: "ConditionalExpression",
763
- test: this._tree
764
- };
765
- this._cursor = this._tree;
766
- };
767
- exports.transform = function(token) {
768
- this._placeBeforeCursor({
769
- type: "FunctionCall",
770
- name: token.value,
771
- args: [this._cursor],
772
- pool: "transforms"
773
- });
774
- };
775
- exports.unaryOp = function(token) {
776
- this._placeAtCursor({
777
- type: "UnaryExpression",
778
- operator: token.value
779
- });
780
- };
781
- }
782
- });
783
-
784
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/parser/states.js
785
- var require_states = __commonJS({
786
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/parser/states.js"(exports) {
787
- "use strict";
788
- var h = require_handlers2();
789
- exports.states = {
790
- expectOperand: {
791
- tokenTypes: {
792
- literal: {
793
- toState: "expectBinOp"
794
- },
795
- identifier: {
796
- toState: "identifier"
797
- },
798
- unaryOp: {},
799
- openParen: {
800
- toState: "subExpression"
801
- },
802
- openCurl: {
803
- toState: "expectObjKey",
804
- handler: h.objStart
805
- },
806
- dot: {
807
- toState: "traverse"
808
- },
809
- openBracket: {
810
- toState: "arrayVal",
811
- handler: h.arrayStart
812
- }
813
- }
814
- },
815
- expectBinOp: {
816
- tokenTypes: {
817
- binaryOp: {
818
- toState: "expectOperand"
819
- },
820
- pipe: {
821
- toState: "expectTransform"
822
- },
823
- dot: {
824
- toState: "traverse"
825
- },
826
- question: {
827
- toState: "ternaryMid",
828
- handler: h.ternaryStart
829
- }
830
- },
831
- completable: true
832
- },
833
- expectTransform: {
834
- tokenTypes: {
835
- identifier: {
836
- toState: "postTransform",
837
- handler: h.transform
838
- }
839
- }
840
- },
841
- expectObjKey: {
842
- tokenTypes: {
843
- identifier: {
844
- toState: "expectKeyValSep",
845
- handler: h.objKey
846
- },
847
- closeCurl: {
848
- toState: "expectBinOp"
849
- }
850
- }
851
- },
852
- expectKeyValSep: {
853
- tokenTypes: {
854
- colon: {
855
- toState: "objVal"
856
- }
857
- }
858
- },
859
- postTransform: {
860
- tokenTypes: {
861
- openParen: {
862
- toState: "argVal"
863
- },
864
- binaryOp: {
865
- toState: "expectOperand"
866
- },
867
- dot: {
868
- toState: "traverse"
869
- },
870
- openBracket: {
871
- toState: "filter"
872
- },
873
- pipe: {
874
- toState: "expectTransform"
875
- }
876
- },
877
- completable: true
878
- },
879
- postArgs: {
880
- tokenTypes: {
881
- binaryOp: {
882
- toState: "expectOperand"
883
- },
884
- dot: {
885
- toState: "traverse"
886
- },
887
- openBracket: {
888
- toState: "filter"
889
- },
890
- pipe: {
891
- toState: "expectTransform"
892
- }
893
- },
894
- completable: true
895
- },
896
- identifier: {
897
- tokenTypes: {
898
- binaryOp: {
899
- toState: "expectOperand"
900
- },
901
- dot: {
902
- toState: "traverse"
903
- },
904
- openBracket: {
905
- toState: "filter"
906
- },
907
- openParen: {
908
- toState: "argVal",
909
- handler: h.functionCall
910
- },
911
- pipe: {
912
- toState: "expectTransform"
913
- },
914
- question: {
915
- toState: "ternaryMid",
916
- handler: h.ternaryStart
917
- }
918
- },
919
- completable: true
920
- },
921
- traverse: {
922
- tokenTypes: {
923
- identifier: {
924
- toState: "identifier"
925
- }
926
- }
927
- },
928
- filter: {
929
- subHandler: h.filter,
930
- endStates: {
931
- closeBracket: "identifier"
932
- }
933
- },
934
- subExpression: {
935
- subHandler: h.subExpression,
936
- endStates: {
937
- closeParen: "expectBinOp"
938
- }
939
- },
940
- argVal: {
941
- subHandler: h.argVal,
942
- endStates: {
943
- comma: "argVal",
944
- closeParen: "postArgs"
945
- }
946
- },
947
- objVal: {
948
- subHandler: h.objVal,
949
- endStates: {
950
- comma: "expectObjKey",
951
- closeCurl: "expectBinOp"
952
- }
953
- },
954
- arrayVal: {
955
- subHandler: h.arrayVal,
956
- endStates: {
957
- comma: "arrayVal",
958
- closeBracket: "expectBinOp"
959
- }
960
- },
961
- ternaryMid: {
962
- subHandler: h.ternaryMid,
963
- endStates: {
964
- colon: "ternaryEnd"
965
- }
966
- },
967
- ternaryEnd: {
968
- subHandler: h.ternaryEnd,
969
- completable: true
970
- }
971
- };
972
- }
973
- });
974
-
975
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/parser/Parser.js
976
- var require_Parser = __commonJS({
977
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/parser/Parser.js"(exports, module) {
978
- "use strict";
979
- var _interopRequireDefault = require_interopRequireDefault();
980
- var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
981
- var _createClass2 = _interopRequireDefault(require_createClass());
982
- var handlers = require_handlers2();
983
- var states = require_states().states;
984
- var Parser = /* @__PURE__ */ (function() {
985
- function Parser2(grammar, prefix, stopMap) {
986
- (0, _classCallCheck2.default)(this, Parser2);
987
- this._grammar = grammar;
988
- this._state = "expectOperand";
989
- this._tree = null;
990
- this._exprStr = prefix || "";
991
- this._relative = false;
992
- this._stopMap = stopMap || {};
993
- }
994
- (0, _createClass2.default)(Parser2, [{
995
- key: "addToken",
996
- value: function addToken(token) {
997
- if (this._state === "complete") {
998
- throw new Error("Cannot add a new token to a completed Parser");
999
- }
1000
- var state = states[this._state];
1001
- var startExpr = this._exprStr;
1002
- this._exprStr += token.raw;
1003
- if (state.subHandler) {
1004
- if (!this._subParser) {
1005
- this._startSubExpression(startExpr);
1006
- }
1007
- var stopState = this._subParser.addToken(token);
1008
- if (stopState) {
1009
- this._endSubExpression();
1010
- if (this._parentStop) return stopState;
1011
- this._state = stopState;
1012
- }
1013
- } else if (state.tokenTypes[token.type]) {
1014
- var typeOpts = state.tokenTypes[token.type];
1015
- var handleFunc = handlers[token.type];
1016
- if (typeOpts.handler) {
1017
- handleFunc = typeOpts.handler;
1018
- }
1019
- if (handleFunc) {
1020
- handleFunc.call(this, token);
1021
- }
1022
- if (typeOpts.toState) {
1023
- this._state = typeOpts.toState;
1024
- }
1025
- } else if (this._stopMap[token.type]) {
1026
- return this._stopMap[token.type];
1027
- } else {
1028
- throw new Error("Token ".concat(token.raw, " (").concat(token.type, ") unexpected in expression: ").concat(this._exprStr));
1029
- }
1030
- return false;
1031
- }
1032
- /**
1033
- * Processes an array of tokens iteratively through the {@link #addToken}
1034
- * function.
1035
- * @param {Array<{type: <string>}>} tokens An array of tokens, as provided by
1036
- * the {@link Lexer#tokenize} function.
1037
- */
1038
- }, {
1039
- key: "addTokens",
1040
- value: function addTokens(tokens) {
1041
- tokens.forEach(this.addToken, this);
1042
- }
1043
- /**
1044
- * Marks this Parser instance as completed and retrieves the full AST.
1045
- * @returns {{}|null} a full expression tree, ready for evaluation by the
1046
- * {@link Evaluator#eval} function, or null if no tokens were passed to
1047
- * the parser before complete was called
1048
- * @throws {Error} if the parser is not in a state where it's legal to end
1049
- * the expression, indicating that the expression is incomplete
1050
- */
1051
- }, {
1052
- key: "complete",
1053
- value: function complete() {
1054
- if (this._cursor && !states[this._state].completable) {
1055
- throw new Error("Unexpected end of expression: ".concat(this._exprStr));
1056
- }
1057
- if (this._subParser) {
1058
- this._endSubExpression();
1059
- }
1060
- this._state = "complete";
1061
- return this._cursor ? this._tree : null;
1062
- }
1063
- /**
1064
- * Indicates whether the expression tree contains a relative path identifier.
1065
- * @returns {boolean} true if a relative identifier exists false otherwise.
1066
- */
1067
- }, {
1068
- key: "isRelative",
1069
- value: function isRelative() {
1070
- return this._relative;
1071
- }
1072
- /**
1073
- * Ends a subexpression by completing the subParser and passing its result
1074
- * to the subHandler configured in the current state.
1075
- * @private
1076
- */
1077
- }, {
1078
- key: "_endSubExpression",
1079
- value: function _endSubExpression() {
1080
- states[this._state].subHandler.call(this, this._subParser.complete());
1081
- this._subParser = null;
1082
- }
1083
- /**
1084
- * Places a new tree node at the current position of the cursor (to the 'right'
1085
- * property) and then advances the cursor to the new node. This function also
1086
- * handles setting the parent of the new node.
1087
- * @param {{type: <string>}} node A node to be added to the AST
1088
- * @private
1089
- */
1090
- }, {
1091
- key: "_placeAtCursor",
1092
- value: function _placeAtCursor(node) {
1093
- if (!this._cursor) {
1094
- this._tree = node;
1095
- } else {
1096
- this._cursor.right = node;
1097
- this._setParent(node, this._cursor);
1098
- }
1099
- this._cursor = node;
1100
- }
1101
- /**
1102
- * Places a tree node before the current position of the cursor, replacing
1103
- * the node that the cursor currently points to. This should only be called in
1104
- * cases where the cursor is known to exist, and the provided node already
1105
- * contains a pointer to what's at the cursor currently.
1106
- * @param {{type: <string>}} node A node to be added to the AST
1107
- * @private
1108
- */
1109
- }, {
1110
- key: "_placeBeforeCursor",
1111
- value: function _placeBeforeCursor(node) {
1112
- this._cursor = this._cursor._parent;
1113
- this._placeAtCursor(node);
1114
- }
1115
- /**
1116
- * Sets the parent of a node by creating a non-enumerable _parent property
1117
- * that points to the supplied parent argument.
1118
- * @param {{type: <string>}} node A node of the AST on which to set a new
1119
- * parent
1120
- * @param {{type: <string>}} parent An existing node of the AST to serve as the
1121
- * parent of the new node
1122
- * @private
1123
- */
1124
- }, {
1125
- key: "_setParent",
1126
- value: function _setParent(node, parent) {
1127
- Object.defineProperty(node, "_parent", {
1128
- value: parent,
1129
- writable: true
1130
- });
1131
- }
1132
- /**
1133
- * Prepares the Parser to accept a subexpression by (re)instantiating the
1134
- * subParser.
1135
- * @param {string} [exprStr] The expression string to prefix to the new Parser
1136
- * @private
1137
- */
1138
- }, {
1139
- key: "_startSubExpression",
1140
- value: function _startSubExpression(exprStr) {
1141
- var endStates = states[this._state].endStates;
1142
- if (!endStates) {
1143
- this._parentStop = true;
1144
- endStates = this._stopMap;
1145
- }
1146
- this._subParser = new Parser2(this._grammar, exprStr, endStates);
1147
- }
1148
- }]);
1149
- return Parser2;
1150
- })();
1151
- module.exports = Parser;
1152
- }
1153
- });
1154
-
1155
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/PromiseSync.js
1156
- var require_PromiseSync = __commonJS({
1157
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/PromiseSync.js"(exports, module) {
1158
- "use strict";
1159
- var _interopRequireDefault = require_interopRequireDefault();
1160
- var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
1161
- var _createClass2 = _interopRequireDefault(require_createClass());
1162
- var PromiseSync = /* @__PURE__ */ (function() {
1163
- function PromiseSync2(fn) {
1164
- (0, _classCallCheck2.default)(this, PromiseSync2);
1165
- fn(this._resolve.bind(this), this._reject.bind(this));
1166
- }
1167
- (0, _createClass2.default)(PromiseSync2, [{
1168
- key: "catch",
1169
- value: function _catch(rejected) {
1170
- if (this.error) {
1171
- try {
1172
- this._resolve(rejected(this.error));
1173
- } catch (e) {
1174
- this._reject(e);
1175
- }
1176
- }
1177
- return this;
1178
- }
1179
- }, {
1180
- key: "then",
1181
- value: function then(resolved, rejected) {
1182
- if (!this.error) {
1183
- try {
1184
- this._resolve(resolved(this.value));
1185
- } catch (e) {
1186
- this._reject(e);
1187
- }
1188
- }
1189
- if (rejected) this.catch(rejected);
1190
- return this;
1191
- }
1192
- }, {
1193
- key: "_reject",
1194
- value: function _reject(error) {
1195
- this.value = void 0;
1196
- this.error = error;
1197
- }
1198
- }, {
1199
- key: "_resolve",
1200
- value: function _resolve(val) {
1201
- if (val instanceof PromiseSync2) {
1202
- if (val.error) {
1203
- this._reject(val.error);
1204
- } else {
1205
- this._resolve(val.value);
1206
- }
1207
- } else {
1208
- this.value = val;
1209
- this.error = void 0;
1210
- }
1211
- }
1212
- }]);
1213
- return PromiseSync2;
1214
- })();
1215
- PromiseSync.all = function(vals) {
1216
- return new PromiseSync(function(resolve) {
1217
- var resolved = vals.map(function(val) {
1218
- while (val instanceof PromiseSync) {
1219
- if (val.error) throw Error(val.error);
1220
- val = val.value;
1221
- }
1222
- return val;
1223
- });
1224
- resolve(resolved);
1225
- });
1226
- };
1227
- PromiseSync.resolve = function(val) {
1228
- return new PromiseSync(function(resolve) {
1229
- return resolve(val);
1230
- });
1231
- };
1232
- PromiseSync.reject = function(error) {
1233
- return new PromiseSync(function(resolve, reject) {
1234
- return reject(error);
1235
- });
1236
- };
1237
- module.exports = PromiseSync;
1238
- }
1239
- });
1240
-
1241
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/Expression.js
1242
- var require_Expression = __commonJS({
1243
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/Expression.js"(exports, module) {
1244
- "use strict";
1245
- var _interopRequireDefault = require_interopRequireDefault();
1246
- var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
1247
- var _createClass2 = _interopRequireDefault(require_createClass());
1248
- var Evaluator = require_Evaluator();
1249
- var Lexer = require_Lexer();
1250
- var Parser = require_Parser();
1251
- var PromiseSync = require_PromiseSync();
1252
- var Expression = /* @__PURE__ */ (function() {
1253
- function Expression2(grammar, exprStr) {
1254
- (0, _classCallCheck2.default)(this, Expression2);
1255
- this._grammar = grammar;
1256
- this._exprStr = exprStr;
1257
- this._ast = null;
1258
- }
1259
- (0, _createClass2.default)(Expression2, [{
1260
- key: "compile",
1261
- value: function compile() {
1262
- var lexer = new Lexer(this._grammar);
1263
- var parser = new Parser(this._grammar);
1264
- var tokens = lexer.tokenize(this._exprStr);
1265
- parser.addTokens(tokens);
1266
- this._ast = parser.complete();
1267
- return this;
1268
- }
1269
- /**
1270
- * Asynchronously evaluates the expression within an optional context.
1271
- * @param {Object} [context] A mapping of variables to values, which will be
1272
- * made accessible to the Jexl expression when evaluating it
1273
- * @returns {Promise<*>} resolves with the result of the evaluation.
1274
- */
1275
- }, {
1276
- key: "eval",
1277
- value: function _eval() {
1278
- var context = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1279
- return this._eval(context, Promise);
1280
- }
1281
- /**
1282
- * Synchronously evaluates the expression within an optional context.
1283
- * @param {Object} [context] A mapping of variables to values, which will be
1284
- * made accessible to the Jexl expression when evaluating it
1285
- * @returns {*} the result of the evaluation.
1286
- * @throws {*} on error
1287
- */
1288
- }, {
1289
- key: "evalSync",
1290
- value: function evalSync() {
1291
- var context = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1292
- var res = this._eval(context, PromiseSync);
1293
- if (res.error) throw res.error;
1294
- return res.value;
1295
- }
1296
- }, {
1297
- key: "_eval",
1298
- value: function _eval(context, promise) {
1299
- var _this = this;
1300
- return promise.resolve().then(function() {
1301
- var ast = _this._getAst();
1302
- var evaluator = new Evaluator(_this._grammar, context, void 0, promise);
1303
- return evaluator.eval(ast);
1304
- });
1305
- }
1306
- }, {
1307
- key: "_getAst",
1308
- value: function _getAst() {
1309
- if (!this._ast) this.compile();
1310
- return this._ast;
1311
- }
1312
- }]);
1313
- return Expression2;
1314
- })();
1315
- module.exports = Expression;
1316
- }
1317
- });
1318
-
1319
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/grammar.js
1320
- var require_grammar = __commonJS({
1321
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/grammar.js"(exports) {
1322
- "use strict";
1323
- exports.getGrammar = function() {
1324
- return {
1325
- /**
1326
- * A map of all expression elements to their properties. Note that changes
1327
- * here may require changes in the Lexer or Parser.
1328
- * @type {{}}
1329
- */
1330
- elements: {
1331
- ".": {
1332
- type: "dot"
1333
- },
1334
- "[": {
1335
- type: "openBracket"
1336
- },
1337
- "]": {
1338
- type: "closeBracket"
1339
- },
1340
- "|": {
1341
- type: "pipe"
1342
- },
1343
- "{": {
1344
- type: "openCurl"
1345
- },
1346
- "}": {
1347
- type: "closeCurl"
1348
- },
1349
- ":": {
1350
- type: "colon"
1351
- },
1352
- ",": {
1353
- type: "comma"
1354
- },
1355
- "(": {
1356
- type: "openParen"
1357
- },
1358
- ")": {
1359
- type: "closeParen"
1360
- },
1361
- "?": {
1362
- type: "question"
1363
- },
1364
- "+": {
1365
- type: "binaryOp",
1366
- precedence: 30,
1367
- eval: function _eval(left, right) {
1368
- return left + right;
1369
- }
1370
- },
1371
- "-": {
1372
- type: "binaryOp",
1373
- precedence: 30,
1374
- eval: function _eval(left, right) {
1375
- return left - right;
1376
- }
1377
- },
1378
- "*": {
1379
- type: "binaryOp",
1380
- precedence: 40,
1381
- eval: function _eval(left, right) {
1382
- return left * right;
1383
- }
1384
- },
1385
- "/": {
1386
- type: "binaryOp",
1387
- precedence: 40,
1388
- eval: function _eval(left, right) {
1389
- return left / right;
1390
- }
1391
- },
1392
- "//": {
1393
- type: "binaryOp",
1394
- precedence: 40,
1395
- eval: function _eval(left, right) {
1396
- return Math.floor(left / right);
1397
- }
1398
- },
1399
- "%": {
1400
- type: "binaryOp",
1401
- precedence: 50,
1402
- eval: function _eval(left, right) {
1403
- return left % right;
1404
- }
1405
- },
1406
- "^": {
1407
- type: "binaryOp",
1408
- precedence: 50,
1409
- eval: function _eval(left, right) {
1410
- return Math.pow(left, right);
1411
- }
1412
- },
1413
- "==": {
1414
- type: "binaryOp",
1415
- precedence: 20,
1416
- eval: function _eval(left, right) {
1417
- return left == right;
1418
- }
1419
- },
1420
- "!=": {
1421
- type: "binaryOp",
1422
- precedence: 20,
1423
- eval: function _eval(left, right) {
1424
- return left != right;
1425
- }
1426
- },
1427
- ">": {
1428
- type: "binaryOp",
1429
- precedence: 20,
1430
- eval: function _eval(left, right) {
1431
- return left > right;
1432
- }
1433
- },
1434
- ">=": {
1435
- type: "binaryOp",
1436
- precedence: 20,
1437
- eval: function _eval(left, right) {
1438
- return left >= right;
1439
- }
1440
- },
1441
- "<": {
1442
- type: "binaryOp",
1443
- precedence: 20,
1444
- eval: function _eval(left, right) {
1445
- return left < right;
1446
- }
1447
- },
1448
- "<=": {
1449
- type: "binaryOp",
1450
- precedence: 20,
1451
- eval: function _eval(left, right) {
1452
- return left <= right;
1453
- }
1454
- },
1455
- "&&": {
1456
- type: "binaryOp",
1457
- precedence: 10,
1458
- evalOnDemand: function evalOnDemand(left, right) {
1459
- return left.eval().then(function(leftVal) {
1460
- if (!leftVal) return leftVal;
1461
- return right.eval();
1462
- });
1463
- }
1464
- },
1465
- "||": {
1466
- type: "binaryOp",
1467
- precedence: 10,
1468
- evalOnDemand: function evalOnDemand(left, right) {
1469
- return left.eval().then(function(leftVal) {
1470
- if (leftVal) return leftVal;
1471
- return right.eval();
1472
- });
1473
- }
1474
- },
1475
- in: {
1476
- type: "binaryOp",
1477
- precedence: 20,
1478
- eval: function _eval(left, right) {
1479
- if (typeof right === "string") {
1480
- return right.indexOf(left) !== -1;
1481
- }
1482
- if (Array.isArray(right)) {
1483
- return right.some(function(elem) {
1484
- return elem === left;
1485
- });
1486
- }
1487
- return false;
1488
- }
1489
- },
1490
- "!": {
1491
- type: "unaryOp",
1492
- precedence: Infinity,
1493
- eval: function _eval(right) {
1494
- return !right;
1495
- }
1496
- }
1497
- },
1498
- /**
1499
- * A map of function names to javascript functions. A Jexl function
1500
- * takes zero ore more arguemnts:
1501
- *
1502
- * - {*} ...args: A variable number of arguments passed to this function.
1503
- * All of these are pre-evaluated to their actual values before calling
1504
- * the function.
1505
- *
1506
- * The Jexl function should return either the transformed value, or
1507
- * a Promises/A+ Promise object that resolves with the value and rejects
1508
- * or throws only when an unrecoverable error occurs. Functions should
1509
- * generally return undefined when they don't make sense to be used on the
1510
- * given value type, rather than throw/reject. An error is only
1511
- * appropriate when the function would normally return a value, but
1512
- * cannot due to some other failure.
1513
- */
1514
- functions: {},
1515
- /**
1516
- * A map of transform names to transform functions. A transform function
1517
- * takes one ore more arguemnts:
1518
- *
1519
- * - {*} val: A value to be transformed
1520
- * - {*} ...args: A variable number of arguments passed to this transform.
1521
- * All of these are pre-evaluated to their actual values before calling
1522
- * the function.
1523
- *
1524
- * The transform function should return either the transformed value, or
1525
- * a Promises/A+ Promise object that resolves with the value and rejects
1526
- * or throws only when an unrecoverable error occurs. Transforms should
1527
- * generally return undefined when they don't make sense to be used on the
1528
- * given value type, rather than throw/reject. An error is only
1529
- * appropriate when the transform would normally return a value, but
1530
- * cannot due to some other failure.
1531
- */
1532
- transforms: {}
1533
- };
8
+ // src/types/ai-errors.ts
9
+ var DyrectedAIError = class _DyrectedAIError extends Error {
10
+ code;
11
+ status;
12
+ details;
13
+ constructor(code, message, status = 500, details) {
14
+ super(message);
15
+ this.name = "DyrectedAIError";
16
+ this.code = code;
17
+ this.status = status;
18
+ this.details = details;
19
+ Object.setPrototypeOf(this, _DyrectedAIError.prototype);
20
+ }
21
+ toJSON() {
22
+ return {
23
+ error: true,
24
+ code: this.code,
25
+ message: this.message,
26
+ status: this.status,
27
+ details: this.details
1534
28
  };
1535
29
  }
1536
- });
1537
-
1538
- // ../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/Jexl.js
1539
- var require_Jexl = __commonJS({
1540
- "../../node_modules/.pnpm/jexl@2.3.0/node_modules/jexl/dist/Jexl.js"(exports, module) {
1541
- "use strict";
1542
- var _interopRequireDefault = require_interopRequireDefault();
1543
- var _defineProperty2 = _interopRequireDefault(require_defineProperty());
1544
- var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
1545
- var _createClass2 = _interopRequireDefault(require_createClass());
1546
- var Expression = require_Expression();
1547
- var _require = require_grammar();
1548
- var getGrammar = _require.getGrammar;
1549
- var Jexl = /* @__PURE__ */ (function() {
1550
- function Jexl2() {
1551
- (0, _classCallCheck2.default)(this, Jexl2);
1552
- this.expr = this.expr.bind(this);
1553
- this._grammar = getGrammar();
1554
- }
1555
- (0, _createClass2.default)(Jexl2, [{
1556
- key: "addBinaryOp",
1557
- value: function addBinaryOp(operator, precedence, fn, manualEval) {
1558
- this._addGrammarElement(operator, (0, _defineProperty2.default)({
1559
- type: "binaryOp",
1560
- precedence
1561
- }, manualEval ? "evalOnDemand" : "eval", fn));
1562
- }
1563
- /**
1564
- * Adds or replaces an expression function in this Jexl instance.
1565
- * @param {string} name The name of the expression function, as it will be
1566
- * used within Jexl expressions
1567
- * @param {function} fn The javascript function to be executed when this
1568
- * expression function is invoked. It will be provided with each argument
1569
- * supplied in the expression, in the same order.
1570
- */
1571
- }, {
1572
- key: "addFunction",
1573
- value: function addFunction(name, fn) {
1574
- this._grammar.functions[name] = fn;
1575
- }
1576
- /**
1577
- * Syntactic sugar for calling {@link #addFunction} repeatedly. This function
1578
- * accepts a map of one or more expression function names to their javascript
1579
- * function counterpart.
1580
- * @param {{}} map A map of expression function names to javascript functions
1581
- */
1582
- }, {
1583
- key: "addFunctions",
1584
- value: function addFunctions(map) {
1585
- for (var key in map) {
1586
- this._grammar.functions[key] = map[key];
1587
- }
1588
- }
1589
- /**
1590
- * Adds a unary operator to Jexl. Unary operators are currently only supported
1591
- * on the left side of the value on which it will operate.
1592
- * @param {string} operator The operator string to be added
1593
- * @param {function} fn A function to run to calculate the result. The function
1594
- * will be called with one argument: the literal value to the right of the
1595
- * operator. It should return either the resulting value, or a Promise
1596
- * that resolves with the resulting value.
1597
- */
1598
- }, {
1599
- key: "addUnaryOp",
1600
- value: function addUnaryOp(operator, fn) {
1601
- this._addGrammarElement(operator, {
1602
- type: "unaryOp",
1603
- weight: Infinity,
1604
- eval: fn
1605
- });
1606
- }
1607
- /**
1608
- * Adds or replaces a transform function in this Jexl instance.
1609
- * @param {string} name The name of the transform function, as it will be used
1610
- * within Jexl expressions
1611
- * @param {function} fn The function to be executed when this transform is
1612
- * invoked. It will be provided with at least one argument:
1613
- * - {*} value: The value to be transformed
1614
- * - {...*} args: The arguments for this transform
1615
- */
1616
- }, {
1617
- key: "addTransform",
1618
- value: function addTransform(name, fn) {
1619
- this._grammar.transforms[name] = fn;
1620
- }
1621
- /**
1622
- * Syntactic sugar for calling {@link #addTransform} repeatedly. This function
1623
- * accepts a map of one or more transform names to their transform function.
1624
- * @param {{}} map A map of transform names to transform functions
1625
- */
1626
- }, {
1627
- key: "addTransforms",
1628
- value: function addTransforms(map) {
1629
- for (var key in map) {
1630
- this._grammar.transforms[key] = map[key];
1631
- }
1632
- }
1633
- /**
1634
- * Creates an Expression object from the given Jexl expression string, and
1635
- * immediately compiles it. The returned Expression object can then be
1636
- * evaluated multiple times with new contexts, without generating any
1637
- * additional string processing overhead.
1638
- * @param {string} expression The Jexl expression to be compiled
1639
- * @returns {Expression} The compiled Expression object
1640
- */
1641
- }, {
1642
- key: "compile",
1643
- value: function compile(expression) {
1644
- var exprObj = this.createExpression(expression);
1645
- return exprObj.compile();
1646
- }
1647
- /**
1648
- * Constructs an Expression object from a Jexl expression string.
1649
- * @param {string} expression The Jexl expression to be wrapped in an
1650
- * Expression object
1651
- * @returns {Expression} The Expression object representing the given string
1652
- */
1653
- }, {
1654
- key: "createExpression",
1655
- value: function createExpression(expression) {
1656
- return new Expression(this._grammar, expression);
1657
- }
1658
- /**
1659
- * Retrieves a previously set expression function.
1660
- * @param {string} name The name of the expression function
1661
- * @returns {function} The expression function
1662
- */
1663
- }, {
1664
- key: "getFunction",
1665
- value: function getFunction(name) {
1666
- return this._grammar.functions[name];
1667
- }
1668
- /**
1669
- * Retrieves a previously set transform function.
1670
- * @param {string} name The name of the transform function
1671
- * @returns {function} The transform function
1672
- */
1673
- }, {
1674
- key: "getTransform",
1675
- value: function getTransform(name) {
1676
- return this._grammar.transforms[name];
1677
- }
1678
- /**
1679
- * Asynchronously evaluates a Jexl string within an optional context.
1680
- * @param {string} expression The Jexl expression to be evaluated
1681
- * @param {Object} [context] A mapping of variables to values, which will be
1682
- * made accessible to the Jexl expression when evaluating it
1683
- * @returns {Promise<*>} resolves with the result of the evaluation.
1684
- */
1685
- }, {
1686
- key: "eval",
1687
- value: function _eval(expression) {
1688
- var context = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1689
- var exprObj = this.createExpression(expression);
1690
- return exprObj.eval(context);
1691
- }
1692
- /**
1693
- * Synchronously evaluates a Jexl string within an optional context.
1694
- * @param {string} expression The Jexl expression to be evaluated
1695
- * @param {Object} [context] A mapping of variables to values, which will be
1696
- * made accessible to the Jexl expression when evaluating it
1697
- * @returns {*} the result of the evaluation.
1698
- * @throws {*} on error
1699
- */
1700
- }, {
1701
- key: "evalSync",
1702
- value: function evalSync(expression) {
1703
- var context = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1704
- var exprObj = this.createExpression(expression);
1705
- return exprObj.evalSync(context);
1706
- }
1707
- /**
1708
- * A JavaScript template literal to allow expressions to be defined by the
1709
- * syntax: expr`40 + 2`
1710
- * @param {Array<string>} strs
1711
- * @param {...any} args
1712
- */
1713
- }, {
1714
- key: "expr",
1715
- value: function expr(strs) {
1716
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1717
- args[_key - 1] = arguments[_key];
1718
- }
1719
- var exprStr = strs.reduce(function(acc, str, idx) {
1720
- var arg = idx < args.length ? args[idx] : "";
1721
- acc += str + arg;
1722
- return acc;
1723
- }, "");
1724
- return this.createExpression(exprStr);
1725
- }
1726
- /**
1727
- * Removes a binary or unary operator from the Jexl grammar.
1728
- * @param {string} operator The operator string to be removed
1729
- */
1730
- }, {
1731
- key: "removeOp",
1732
- value: function removeOp(operator) {
1733
- if (this._grammar.elements[operator] && (this._grammar.elements[operator].type === "binaryOp" || this._grammar.elements[operator].type === "unaryOp")) {
1734
- delete this._grammar.elements[operator];
1735
- }
1736
- }
1737
- /**
1738
- * Adds an element to the grammar map used by this Jexl instance.
1739
- * @param {string} str The key string to be added
1740
- * @param {{type: <string>}} obj A map of configuration options for this
1741
- * grammar element
1742
- * @private
1743
- */
1744
- }, {
1745
- key: "_addGrammarElement",
1746
- value: function _addGrammarElement(str, obj) {
1747
- this._grammar.elements[str] = obj;
1748
- }
1749
- }]);
1750
- return Jexl2;
1751
- })();
1752
- module.exports = new Jexl();
1753
- module.exports.Jexl = Jexl;
1754
- }
1755
- });
30
+ };
1756
31
 
1757
32
  // src/workflows.ts
1758
33
  var WORKFLOW_HISTORY_COLLECTION = "__workflow_history";
@@ -2150,18 +425,31 @@ async function transitionWorkflow(args) {
2150
425
  await hook({ ...hookContext, doc: updated, event: events[0] });
2151
426
  } catch (error) {
2152
427
  try {
2153
- const { getConfigLogger, getObservabilityRuntime } = await import("./observability-HQF4EUSV.js");
2154
- getObservabilityRuntime(config)?.recordWorkflowHookFailure({
428
+ const obs = config?.__observability;
429
+ obs?.recordWorkflowHookFailure?.({
2155
430
  collection: collection.slug,
2156
431
  transition: transition.name
2157
432
  });
2158
- getConfigLogger(config, "workflow").error({
2159
- err: error,
2160
- msg: "afterTransition hook failed",
2161
- collection: collection.slug,
2162
- transition: transition.name,
2163
- documentId: id
2164
- });
433
+ const logger = config?.logger;
434
+ if (logger && typeof logger.child === "function") {
435
+ logger.child({ component: "workflow" }).error({
436
+ err: error,
437
+ msg: "afterTransition hook failed",
438
+ collection: collection.slug,
439
+ transition: transition.name,
440
+ documentId: id
441
+ });
442
+ } else if (logger && typeof logger.error === "function") {
443
+ logger.error({
444
+ err: error,
445
+ msg: "afterTransition hook failed",
446
+ collection: collection.slug,
447
+ transition: transition.name,
448
+ documentId: id
449
+ });
450
+ } else {
451
+ console.error("afterTransition hook failed:", error);
452
+ }
2165
453
  } catch {
2166
454
  console.error("afterTransition hook failed:", error);
2167
455
  }
@@ -4204,6 +2492,182 @@ function generateOpenApi(config) {
4204
2492
  }
4205
2493
  }
4206
2494
  };
2495
+ spec.paths["/api/ai/chat"] = {
2496
+ post: {
2497
+ tags: ["AI"],
2498
+ summary: "Send prompt and stream AI assistant response",
2499
+ requestBody: {
2500
+ required: true,
2501
+ content: {
2502
+ "application/json": {
2503
+ schema: {
2504
+ type: "object",
2505
+ properties: {
2506
+ content: { type: "string", description: "User prompt message" },
2507
+ prompt: { type: "string", description: "Alias for content" },
2508
+ threadId: { type: "string", description: "Existing conversation thread ID" },
2509
+ messages: { type: "array", items: { type: "object" }, description: "Conversation history" }
2510
+ },
2511
+ required: []
2512
+ }
2513
+ }
2514
+ }
2515
+ },
2516
+ responses: {
2517
+ 200: {
2518
+ description: "Server-Sent Events (SSE) AI message stream",
2519
+ content: { "text/event-stream": { schema: { type: "string" } } }
2520
+ }
2521
+ }
2522
+ }
2523
+ };
2524
+ spec.paths["/api/ai/threads"] = {
2525
+ get: {
2526
+ tags: ["AI"],
2527
+ summary: "List conversation threads",
2528
+ parameters: [
2529
+ { name: "limit", in: "query", schema: { type: "integer", default: 20 } }
2530
+ ],
2531
+ responses: { 200: { description: "Array of conversation threads" } }
2532
+ },
2533
+ post: {
2534
+ tags: ["AI"],
2535
+ summary: "Create a new conversation thread",
2536
+ requestBody: {
2537
+ content: {
2538
+ "application/json": {
2539
+ schema: {
2540
+ type: "object",
2541
+ properties: { title: { type: "string" } }
2542
+ }
2543
+ }
2544
+ }
2545
+ },
2546
+ responses: { 201: { description: "Created conversation thread" } }
2547
+ },
2548
+ delete: {
2549
+ tags: ["AI"],
2550
+ summary: "Clear all conversation threads",
2551
+ responses: { 200: { description: "Count of deleted threads" } }
2552
+ }
2553
+ };
2554
+ spec.paths["/api/ai/threads/{threadId}"] = {
2555
+ get: {
2556
+ tags: ["AI"],
2557
+ summary: "Get conversation thread and historical messages",
2558
+ parameters: [
2559
+ { name: "threadId", in: "path", required: true, schema: { type: "string" } }
2560
+ ],
2561
+ responses: { 200: { description: "Thread details and messages" } }
2562
+ },
2563
+ delete: {
2564
+ tags: ["AI"],
2565
+ summary: "Delete a specific conversation thread",
2566
+ parameters: [
2567
+ { name: "threadId", in: "path", required: true, schema: { type: "string" } }
2568
+ ],
2569
+ responses: { 200: { description: "Deletion success status" } }
2570
+ }
2571
+ };
2572
+ spec.paths["/api/ai/threads/{threadId}/messages"] = {
2573
+ post: {
2574
+ tags: ["AI"],
2575
+ summary: "Post a message to an existing thread and stream reply",
2576
+ parameters: [
2577
+ { name: "threadId", in: "path", required: true, schema: { type: "string" } }
2578
+ ],
2579
+ requestBody: {
2580
+ required: true,
2581
+ content: {
2582
+ "application/json": {
2583
+ schema: {
2584
+ type: "object",
2585
+ properties: { content: { type: "string" } },
2586
+ required: ["content"]
2587
+ }
2588
+ }
2589
+ }
2590
+ },
2591
+ responses: {
2592
+ 200: {
2593
+ description: "Server-Sent Events (SSE) AI message stream",
2594
+ content: { "text/event-stream": { schema: { type: "string" } } }
2595
+ }
2596
+ }
2597
+ }
2598
+ };
2599
+ spec.paths["/api/ai/actions/{actionId}"] = {
2600
+ get: {
2601
+ tags: ["AI"],
2602
+ summary: "Get an AI mutation action proposal",
2603
+ parameters: [
2604
+ { name: "actionId", in: "path", required: true, schema: { type: "string" } }
2605
+ ],
2606
+ responses: { 200: { description: "AI Action details and diff payload" } }
2607
+ }
2608
+ };
2609
+ spec.paths["/api/ai/actions/{actionId}/execute"] = {
2610
+ post: {
2611
+ tags: ["AI"],
2612
+ summary: "Approve and execute an AI mutation proposal",
2613
+ parameters: [
2614
+ { name: "actionId", in: "path", required: true, schema: { type: "string" } }
2615
+ ],
2616
+ responses: { 200: { description: "Execution result" } }
2617
+ }
2618
+ };
2619
+ spec.paths["/api/ai/actions/{actionId}/reject"] = {
2620
+ post: {
2621
+ tags: ["AI"],
2622
+ summary: "Reject an AI mutation proposal",
2623
+ parameters: [
2624
+ { name: "actionId", in: "path", required: true, schema: { type: "string" } }
2625
+ ],
2626
+ responses: { 200: { description: "Rejection result" } }
2627
+ }
2628
+ };
2629
+ spec.paths["/api/ai/rag/reindex"] = {
2630
+ post: {
2631
+ tags: ["AI"],
2632
+ summary: "Trigger vector reindexing for semantic search",
2633
+ requestBody: {
2634
+ content: {
2635
+ "application/json": {
2636
+ schema: {
2637
+ type: "object",
2638
+ properties: {
2639
+ collection: { type: "string" },
2640
+ force: { type: "boolean" }
2641
+ }
2642
+ }
2643
+ }
2644
+ }
2645
+ },
2646
+ responses: { 200: { description: "Reindexing results and chunk counts" } }
2647
+ }
2648
+ };
2649
+ spec.paths["/api/ai/rag/search"] = {
2650
+ post: {
2651
+ tags: ["AI"],
2652
+ summary: "Perform semantic vector search against indexed content",
2653
+ requestBody: {
2654
+ required: true,
2655
+ content: {
2656
+ "application/json": {
2657
+ schema: {
2658
+ type: "object",
2659
+ properties: {
2660
+ query: { type: "string" },
2661
+ limit: { type: "integer", default: 5 }
2662
+ },
2663
+ required: ["query"]
2664
+ }
2665
+ }
2666
+ }
2667
+ },
2668
+ responses: { 200: { description: "Semantic search results" } }
2669
+ }
2670
+ };
4207
2671
  for (const collection of config.collections) {
4208
2672
  spec.components.schemas[collection.slug] = collectionToSchema(collection);
4209
2673
  }
@@ -5289,7 +3753,46 @@ function isDetailItemVisible(item, doc, user) {
5289
3753
  return true;
5290
3754
  }
5291
3755
 
3756
+ // src/utils/tenant.ts
3757
+ import { HTTPException } from "hono/http-exception";
3758
+ function getAllowedSitesForUser(user, payload) {
3759
+ const raw = user?.allowedSites ?? user?.siteIds ?? user?.siteAccess ?? (user?.siteId ? [user.siteId] : void 0) ?? payload?.allowedSites ?? payload?.siteIds ?? payload?.siteAccess ?? (payload?.siteId ? [payload.siteId] : void 0);
3760
+ if (Array.isArray(raw)) {
3761
+ return raw.filter((s) => typeof s === "string" && s.trim().length > 0);
3762
+ }
3763
+ return void 0;
3764
+ }
3765
+ function isSiteAuthorized(user, payload, requestedSiteId) {
3766
+ const allowedSites = getAllowedSitesForUser(user, payload);
3767
+ if (!allowedSites || allowedSites.length === 0) {
3768
+ return true;
3769
+ }
3770
+ if (!requestedSiteId) {
3771
+ return false;
3772
+ }
3773
+ return allowedSites.includes(requestedSiteId);
3774
+ }
3775
+ function resolveAuthorizedSiteId(c) {
3776
+ const user = typeof c.get === "function" ? c.get("user") : void 0;
3777
+ const tokenPayload = typeof c.get === "function" ? c.get("authTokenPayload") : void 0;
3778
+ const requestedSiteId = (typeof c.req?.header === "function" ? c.req.header("X-Site-Id") : void 0) || (typeof c.get === "function" ? c.get("siteId") : void 0);
3779
+ const allowedSites = getAllowedSitesForUser(user, tokenPayload);
3780
+ if (Array.isArray(allowedSites) && allowedSites.length > 0) {
3781
+ if (!requestedSiteId) {
3782
+ return allowedSites[0];
3783
+ }
3784
+ if (!allowedSites.includes(requestedSiteId)) {
3785
+ throw new HTTPException(403, {
3786
+ message: `Forbidden: User is not authorized to access site "${requestedSiteId}".`
3787
+ });
3788
+ }
3789
+ return requestedSiteId;
3790
+ }
3791
+ return requestedSiteId || "default";
3792
+ }
3793
+
5292
3794
  export {
3795
+ DyrectedAIError,
5293
3796
  signCollectionToken,
5294
3797
  verifyCollectionToken,
5295
3798
  issueAuthSessionToken,
@@ -5319,7 +3822,6 @@ export {
5319
3822
  resolveAdminAuthCollection,
5320
3823
  getPublicAdminAuthConfig,
5321
3824
  mergeDynamicConfig,
5322
- require_Jexl,
5323
3825
  slugify,
5324
3826
  lower,
5325
3827
  upper,
@@ -5401,5 +3903,8 @@ export {
5401
3903
  displayCustomComponent,
5402
3904
  evaluateDetailComputed,
5403
3905
  generateDefaultDetailSchema,
5404
- isDetailItemVisible
3906
+ isDetailItemVisible,
3907
+ getAllowedSitesForUser,
3908
+ isSiteAuthorized,
3909
+ resolveAuthorizedSiteId
5405
3910
  };