@dcupl/common 2.0.0-beta.23 → 2.0.0-beta.24

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.
@@ -21,5 +21,6 @@ export * from './redact-url.js';
21
21
  export * from './resource-id.js';
22
22
  export * from './scheduling.js';
23
23
  export * from './script.controller.js';
24
+ export * from './script-compiler.js';
24
25
  export * from './template-parser.js';
25
26
  export * from './types/index.js';
package/dist/esm/index.js CHANGED
@@ -41,7 +41,7 @@ const b = {
41
41
  return performance.getEntriesByType(i);
42
42
  }
43
43
  };
44
- class qe {
44
+ class Fe {
45
45
  data;
46
46
  enabled = !1;
47
47
  constructor() {
@@ -408,7 +408,7 @@ let X = class z {
408
408
  return { addedNodes: s, removedNodes: n, addedEdges: c, removedEdges: u, kindChanges: f };
409
409
  }
410
410
  };
411
- class Fe {
411
+ class Pe {
412
412
  graph;
413
413
  nodeIndex;
414
414
  constructor() {
@@ -800,7 +800,7 @@ class g {
800
800
  }
801
801
  }
802
802
  const Y = new g();
803
- class Pe {
803
+ class _e {
804
804
  constructor(e) {
805
805
  this.enabled = e, this.cache = /* @__PURE__ */ new Map(), this.cacheDependencies = /* @__PURE__ */ new Map();
806
806
  }
@@ -943,7 +943,7 @@ class Pe {
943
943
  const j = (i, e = "") => {
944
944
  if (!(typeof i != "string" || !i.startsWith("/") || !i.endsWith("/")))
945
945
  return { pattern: i.slice(1, -1), flags: e };
946
- }, _e = (i, e = "") => `${i}#${e}`, ze = (i) => `${i.gt}_${i.gte}_${i.lt}_${i.lte}_${i.eq}_${i.ne}`, je = (i) => `${i.gt}_${i.gte}_${i.lt}_${i.lte}_${i.eq}_${i.ne}`, Be = (i, e) => {
946
+ }, ze = (i, e = "") => `${i}#${e}`, je = (i) => `${i.gt}_${i.gte}_${i.lt}_${i.lte}_${i.eq}_${i.ne}`, Be = (i) => `${i.gt}_${i.gte}_${i.lt}_${i.lte}_${i.eq}_${i.ne}`, Le = (i, e) => {
947
947
  const t = typeof e == "function" ? e : (r) => r[e];
948
948
  return [
949
949
  ...i.reduce((r, s) => {
@@ -951,7 +951,7 @@ const j = (i, e = "") => {
951
951
  return r.has(n) || r.set(n, s), r;
952
952
  }, /* @__PURE__ */ new Map()).values()
953
953
  ];
954
- }, Le = (i, e) => i.reduce(function(t, r) {
954
+ }, Ue = (i, e) => i.reduce(function(t, r) {
955
955
  const s = typeof e == "function" ? e(r) : r[e];
956
956
  return Object.prototype.hasOwnProperty.call(t, s) || (t[s] = []), t[s].push(r), t;
957
957
  }, {});
@@ -961,7 +961,7 @@ function ee(i = 10) {
961
961
  for (let r = 0; r < i; r++) e += t.charAt(Math.floor(Math.random() * t.length));
962
962
  return e;
963
963
  }
964
- const Ue = (i) => i.replace(/\/+$/, ""), te = (i) => typeof i != "string" ? "" : i.replace(/[[\]{}()*+?.,\\^$|#]/g, "\\$&"), We = (i) => typeof i != "string" ? "" : i.replace(/\\([[\]{}()*+?.,\\^$|#])/g, "$1"), Ve = (i, e) => {
964
+ const We = (i) => i.replace(/\/+$/, ""), te = (i) => typeof i != "string" ? "" : i.replace(/[[\]{}()*+?.,\\^$|#]/g, "\\$&"), Ve = (i) => typeof i != "string" ? "" : i.replace(/\\([[\]{}()*+?.,\\^$|#])/g, "$1"), He = (i, e) => {
965
965
  try {
966
966
  return re(i, e) >= 0;
967
967
  } catch {
@@ -978,7 +978,7 @@ const Ue = (i) => i.replace(/\/+$/, ""), te = (i) => typeof i != "string" ? "" :
978
978
  }
979
979
  return 0;
980
980
  }, T = (i) => /^\d+(\.\d+){0,2}$/.test(i);
981
- class He {
981
+ class Je {
982
982
  key;
983
983
  parentCd;
984
984
  dcuplInitOptions;
@@ -1037,7 +1037,7 @@ const B = (i, e) => e ? typeof structuredClone < "u" ? structuredClone(i) : v(i)
1037
1037
  } catch {
1038
1038
  return n;
1039
1039
  }
1040
- }, Je = (i) => (t, r, s) => {
1040
+ }, Ze = (i) => (t, r, s) => {
1041
1041
  const n = s.value;
1042
1042
  return s.value = function(...o) {
1043
1043
  const a = b.now(), c = this.cdRef, u = B(i, !0);
@@ -1053,7 +1053,7 @@ const B = (i, e) => e ? typeof structuredClone < "u" ? structuredClone(i) : v(i)
1053
1053
  return u.method = r, u.args = o, l && typeof l == "object" && "then" in l ? l.then((h) => q(this, c, u, a, f, h)) : q(this, c, u, a, f, l);
1054
1054
  }, s;
1055
1055
  };
1056
- function Ze(i, e, t, r) {
1056
+ function Xe(i, e, t, r) {
1057
1057
  t.max || (t.max = 20);
1058
1058
  const s = [], n = t.transform ? r.transformValue(t.value, t.transform) : t.value;
1059
1059
  for (const [o, a] of e.entries()) {
@@ -1180,7 +1180,7 @@ function ce(i) {
1180
1180
  );
1181
1181
  return ne(e) ? e.getFullYear() !== i.year || e.getMonth() !== i.month - 1 || e.getDate() !== i.day ? /* @__PURE__ */ new Date(NaN) : e : /* @__PURE__ */ new Date(NaN);
1182
1182
  }
1183
- function Xe(i, e, t) {
1183
+ function Ye(i, e, t) {
1184
1184
  if (i = i.trim(), e === "t") {
1185
1185
  const a = Number(i);
1186
1186
  return isNaN(a) ? /* @__PURE__ */ new Date(NaN) : new Date(a * 1e3);
@@ -2375,7 +2375,7 @@ class L {
2375
2375
  }
2376
2376
  }
2377
2377
  const N = new L();
2378
- function Ye(i, e, t, r, s, n, o) {
2378
+ function et(i, e, t, r, s, n, o) {
2379
2379
  const a = t.excludeGroup ?? s, c = N.removeQuery({ groupKey: a }, v(r)), u = o.queryData(i, c, !1, n), f = e ? [...e.keys()] : [], d = new Set(f), l = n.get(s) ?? /* @__PURE__ */ new Map();
2380
2380
  if (!t.excludeUnresolved)
2381
2381
  for (const p of l.keys())
@@ -2856,7 +2856,7 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2856
2856
  });
2857
2857
  }
2858
2858
  return { properties: c, diagnostics: u };
2859
- }, et = (i, e = !1) => Ee(i, typeof e == "boolean" ? { deep: e } : e).properties, Ne = (i) => Number(i) === i && i % 1 === 0, Ce = (i) => Number(i) === i && i % 1 !== 0, $e = (i) => {
2859
+ }, tt = (i, e = !1) => Ee(i, typeof e == "boolean" ? { deep: e } : e).properties, Ne = (i) => Number(i) === i && i % 1 === 0, Ce = (i) => Number(i) === i && i % 1 !== 0, $e = (i) => {
2860
2860
  switch (typeof i) {
2861
2861
  case "string":
2862
2862
  return "string";
@@ -2869,7 +2869,7 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2869
2869
  default:
2870
2870
  return "any";
2871
2871
  }
2872
- }, tt = (i, e) => {
2872
+ }, rt = (i, e) => {
2873
2873
  const t = te(i.text || ""), r = e?.attributeKey || i.filterKey;
2874
2874
  let s;
2875
2875
  const n = e?.comparisonType || "containsIgnoreCase";
@@ -2933,7 +2933,7 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2933
2933
  }
2934
2934
  ]
2935
2935
  }), s;
2936
- }, rt = (i, e) => {
2936
+ }, st = (i, e) => {
2937
2937
  const t = e?.attributeKey || i.filterKey;
2938
2938
  return {
2939
2939
  groupKey: i.filterKey,
@@ -2946,7 +2946,7 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2946
2946
  }
2947
2947
  ]
2948
2948
  };
2949
- }, st = (i, e) => {
2949
+ }, nt = (i, e) => {
2950
2950
  const t = e?.attributeKey || i.filterKey, r = {
2951
2951
  groupKey: i.filterKey,
2952
2952
  queries: []
@@ -2961,7 +2961,7 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2961
2961
  operator: "eq",
2962
2962
  options: { invert: !0 }
2963
2963
  })), typeof i.gt < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: i.gt, operator: "gt" })), typeof i.lt < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: i.lt, operator: "lt" })), typeof i.gte < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: i.gte, operator: "gte" })), typeof i.lte < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: i.lte, operator: "lte" })), r;
2964
- }, nt = (i, e) => {
2964
+ }, it = (i, e) => {
2965
2965
  const t = e?.attributeKey || i.filterKey, r = {
2966
2966
  groupKey: i.filterKey,
2967
2967
  queries: []
@@ -2974,8 +2974,8 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2974
2974
  operator: "eq"
2975
2975
  });
2976
2976
  }), r;
2977
- }, it = (i) => !(typeof i.modelKey != "string" || !Array.isArray(i.queries));
2978
- class ot {
2977
+ }, ot = (i) => !(typeof i.modelKey != "string" || !Array.isArray(i.queries));
2978
+ class at {
2979
2979
  constructor(e, t, r) {
2980
2980
  this.scriptController = e, this.globalItemService = t, this.modelParser = r;
2981
2981
  }
@@ -3365,7 +3365,7 @@ const Oe = /* @__PURE__ */ new Set([
3365
3365
  "manager-key",
3366
3366
  "sdk-key"
3367
3367
  ]);
3368
- function at(i) {
3368
+ function ct(i) {
3369
3369
  const e = i.indexOf("?");
3370
3370
  if (e < 0) return i;
3371
3371
  const t = i.slice(e + 1).split("&").map((r) => {
@@ -3388,7 +3388,7 @@ function M(i, e = 0) {
3388
3388
  });
3389
3389
  return `${Re}${t}`;
3390
3390
  }
3391
- function ct(i) {
3391
+ function ut(i) {
3392
3392
  const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set();
3393
3393
  return i.map((r) => {
3394
3394
  const s = `${r.key ?? ""}|${r.type}|${r.rawUrl ?? r.url}|${r.model ?? ""}`;
@@ -3398,7 +3398,7 @@ function ct(i) {
3398
3398
  return e.set(s, n + 1), t.add(o), o;
3399
3399
  });
3400
3400
  }
3401
- function ut() {
3401
+ function ft() {
3402
3402
  const i = globalThis;
3403
3403
  return typeof i.scheduler?.yield == "function" ? i.scheduler.yield() : typeof i.setImmediate == "function" ? new Promise((e) => i.setImmediate(() => e())) : typeof i.MessageChannel == "function" ? new Promise((e) => {
3404
3404
  const t = new i.MessageChannel();
@@ -3407,9 +3407,14 @@ function ut() {
3407
3407
  }, t.port2.postMessage(null);
3408
3408
  }) : new Promise((e) => setTimeout(e, 0));
3409
3409
  }
3410
- class ft {
3410
+ const Te = (i, e) => new Function(...e, i);
3411
+ class dt {
3411
3412
  scripts = /* @__PURE__ */ new Map();
3412
3413
  scriptFunctions = /* @__PURE__ */ new Map();
3414
+ /** How script text becomes a function; hosts running untrusted code swap in a sandboxed compiler. */
3415
+ compiler = Te;
3416
+ /** `false` refuses to run any script; set from `DcuplInitOptions.scripting.enabled`. */
3417
+ enabled = !0;
3413
3418
  constructor() {
3414
3419
  }
3415
3420
  keys() {
@@ -3433,7 +3438,7 @@ class ft {
3433
3438
  const r = this.getScript(e);
3434
3439
  if (!r)
3435
3440
  throw new Error(`Script ${e} not found`);
3436
- const s = this.getWrapperScript(r), n = new Function("script_type", ...t, s);
3441
+ const s = this.getWrapperScript(r), n = this.compiler(s, ["script_type", ...t]);
3437
3442
  return this.scriptFunctions.set(e, n), n;
3438
3443
  }
3439
3444
  getWrapperScript(e) {
@@ -3443,6 +3448,8 @@ class ft {
3443
3448
  `;
3444
3449
  }
3445
3450
  executeScript(e, t, r) {
3451
+ if (!this.enabled)
3452
+ throw new Error("Scripting is disabled for this dcupl instance");
3446
3453
  if (!this.getScript(e))
3447
3454
  throw new Error(`Script ${e} not found`);
3448
3455
  r.context || (r.context = r.options || {});
@@ -3450,10 +3457,10 @@ class ft {
3450
3457
  return this.getScriptAsFn(e, n)(t, ...o);
3451
3458
  }
3452
3459
  }
3453
- const dt = (i, e) => i ? (e || (e = {}), i.replace(/\$\{(.*?)\}/g, (t, r) => I(e, r.trim(), ""))) : "", lt = (i) => {
3460
+ const lt = (i, e) => i ? (e || (e = {}), i.replace(/\$\{(.*?)\}/g, (t, r) => I(e, r.trim(), ""))) : "", ht = (i) => {
3454
3461
  const e = /* @__PURE__ */ new Set();
3455
3462
  return i.replace(/\$\{(.*?)\}/g, (r, s) => (e.add(s.trim()), "")), { variables: Array.from(e).map((r) => ({ name: r })) };
3456
- }, ht = [
3463
+ }, pt = [
3457
3464
  "any",
3458
3465
  "Array<date>",
3459
3466
  "Array<float>",
@@ -3465,7 +3472,7 @@ const dt = (i, e) => i ? (e || (e = {}), i.replace(/\$\{(.*?)\}/g, (t, r) => I(e
3465
3472
  "int",
3466
3473
  "json",
3467
3474
  "string"
3468
- ], pt = ["int", "float", "Array<int>", "Array<float>"], gt = ["date", "Array<date>"], yt = [
3475
+ ], gt = ["int", "float", "Array<int>", "Array<float>"], yt = ["date", "Array<date>"], mt = [
3469
3476
  "eq",
3470
3477
  "in",
3471
3478
  "find",
@@ -3479,66 +3486,67 @@ const dt = (i, e) => i ? (e || (e = {}), i.replace(/\$\{(.*?)\}/g, (t, r) => I(e
3479
3486
  ];
3480
3487
  export {
3481
3488
  Ge as AUTHORED_RESOURCE_ID_PREFIX,
3482
- qe as AnalyticsController,
3483
- Fe as AttributeDependencyGraph,
3484
- Pe as CacheController,
3485
- He as ChangeDetector,
3489
+ Fe as AnalyticsController,
3490
+ Pe as AttributeDependencyGraph,
3491
+ _e as CacheController,
3492
+ Je as ChangeDetector,
3486
3493
  Re as DERIVED_RESOURCE_ID_PREFIX,
3487
- gt as DatePropertyTypes,
3494
+ yt as DatePropertyTypes,
3488
3495
  L as DcuplQueryBuilder,
3489
- yt as DcuplQueryOperatorsAsArray,
3496
+ mt as DcuplQueryOperatorsAsArray,
3490
3497
  de as DeepQueryService,
3491
3498
  X as DependencyGraph,
3492
3499
  xe as IndicesController,
3493
3500
  g as Logger,
3494
- pt as NumberPropertyTypes,
3495
- ht as PropertyTypesAsArray,
3496
- ot as QueryManager,
3497
- ft as ScriptController,
3501
+ gt as NumberPropertyTypes,
3502
+ pt as PropertyTypesAsArray,
3503
+ at as QueryManager,
3504
+ dt as ScriptController,
3498
3505
  B as clone,
3499
3506
  Ke as coerceStringType,
3500
3507
  re as compareVersions,
3501
- Ze as computeSuggestions,
3508
+ Xe as computeSuggestions,
3502
3509
  m as deepQueryService,
3510
+ Te as defaultScriptCompiler,
3503
3511
  te as escapeRegExp,
3504
- dt as evaluateTemplate,
3505
- rt as generateBooleanQuery,
3512
+ lt as evaluateTemplate,
3513
+ st as generateBooleanQuery,
3506
3514
  ee as generateKey,
3507
- st as generateNumberAndDateQuery,
3508
- nt as generateReferenceQuery,
3509
- tt as generateTextQuery,
3515
+ nt as generateNumberAndDateQuery,
3516
+ it as generateReferenceQuery,
3517
+ rt as generateTextQuery,
3510
3518
  C as getAggregation,
3511
- je as getDateConstraintUid,
3519
+ Be as getDateConstraintUid,
3512
3520
  $e as getDcuplPropertyTypeForNativeType,
3513
3521
  w as getDeepPathValues,
3514
3522
  me as getDistinct,
3515
- Ye as getFacets,
3516
- _e as getFilterEntryId,
3517
- ze as getNumberConstraintUid,
3518
- et as getPropertiesForData,
3519
- Le as groupBy,
3520
- Ve as hasMinimumVersion,
3523
+ et as getFacets,
3524
+ ze as getFilterEntryId,
3525
+ je as getNumberConstraintUid,
3526
+ tt as getPropertiesForData,
3527
+ Ue as groupBy,
3528
+ He as hasMinimumVersion,
3521
3529
  Ee as inferModel,
3522
3530
  se as isDateInstance,
3523
3531
  Ce as isFloat,
3524
3532
  Ne as isInt,
3525
3533
  ne as isValidDate,
3526
- it as isValidQueryStatement,
3534
+ ot as isValidQueryStatement,
3527
3535
  T as isValidVersion,
3528
3536
  Y as logger,
3529
3537
  ke as looksDateLike,
3530
- Xe as parseDate,
3538
+ Ye as parseDate,
3531
3539
  j as parseRegexLiteral,
3532
- lt as parseTemplate,
3540
+ ht as parseTemplate,
3533
3541
  b as perf,
3534
3542
  U as pivot,
3535
- at as redactUrl,
3536
- Ue as removeTrailingSlash,
3543
+ ct as redactUrl,
3544
+ We as removeTrailingSlash,
3537
3545
  M as resolveResourceId,
3538
- ct as resolveResourceIds,
3539
- Je as trigger,
3540
- We as unescapeRegExp,
3541
- Be as uniqBy,
3542
- ut as yieldToEventLoop
3546
+ ut as resolveResourceIds,
3547
+ Ze as trigger,
3548
+ Ve as unescapeRegExp,
3549
+ Le as uniqBy,
3550
+ ft as yieldToEventLoop
3543
3551
  };
3544
3552
  //# sourceMappingURL=index.js.map