@dcupl/common 2.0.0-beta.10 → 2.0.0-beta.12

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.
@@ -18,6 +18,7 @@ export * from './query-builder.js';
18
18
  export * from './query.helper.js';
19
19
  export * from './queryData.js';
20
20
  export * from './resource-id.js';
21
+ export * from './scheduling.js';
21
22
  export * from './script.controller.js';
22
23
  export * from './template-parser.js';
23
24
  export * from './types/index.js';
package/dist/esm/index.js CHANGED
@@ -41,7 +41,7 @@ const b = {
41
41
  return performance.getEntriesByType(n);
42
42
  }
43
43
  };
44
- class Re {
44
+ class Te {
45
45
  data;
46
46
  enabled = !1;
47
47
  constructor() {
@@ -408,7 +408,7 @@ let X = class _ {
408
408
  return { addedNodes: s, removedNodes: i, addedEdges: c, removedEdges: u, kindChanges: f };
409
409
  }
410
410
  };
411
- class Te {
411
+ class Re {
412
412
  graph;
413
413
  nodeIndex;
414
414
  constructor() {
@@ -940,7 +940,7 @@ class Ge {
940
940
  };
941
941
  }
942
942
  }
943
- const ze = (n, e = "") => `${n}#${e}`, _e = (n) => `${n.gt}_${n.gte}_${n.lt}_${n.lte}_${n.eq}_${n.ne}`, Be = (n) => `${n.gt}_${n.gte}_${n.lt}_${n.lte}_${n.eq}_${n.ne}`, je = (n, e) => {
943
+ const ze = (n, e = "") => `${n}#${e}`, _e = (n) => `${n.gt}_${n.gte}_${n.lt}_${n.lte}_${n.eq}_${n.ne}`, Pe = (n) => `${n.gt}_${n.gte}_${n.lt}_${n.lte}_${n.eq}_${n.ne}`, Be = (n, e) => {
944
944
  const t = typeof e == "function" ? e : (r) => r[e];
945
945
  return [
946
946
  ...n.reduce((r, s) => {
@@ -948,7 +948,7 @@ const ze = (n, e = "") => `${n}#${e}`, _e = (n) => `${n.gt}_${n.gte}_${n.lt}_${n
948
948
  return r.has(i) || r.set(i, s), r;
949
949
  }, /* @__PURE__ */ new Map()).values()
950
950
  ];
951
- }, Pe = (n, e) => n.reduce(function(t, r) {
951
+ }, je = (n, e) => n.reduce(function(t, r) {
952
952
  const s = typeof e == "function" ? e(r) : r[e];
953
953
  return Object.prototype.hasOwnProperty.call(t, s) || (t[s] = []), t[s].push(r), t;
954
954
  }, {});
@@ -1011,9 +1011,9 @@ class Ue {
1011
1011
  };
1012
1012
  }
1013
1013
  }
1014
- const B = (n, e) => e ? typeof structuredClone < "u" ? structuredClone(n) : v(n) : n, R = (n, e, t, r, s, i) => {
1014
+ const P = (n, e) => e ? typeof structuredClone < "u" ? structuredClone(n) : v(n) : n, T = (n, e, t, r, s, i) => {
1015
1015
  try {
1016
- const o = !!e.dcuplInitOptions.performance?.clone?.enabled && !!t.cloneResult, a = B(i, o);
1016
+ const o = !!e.dcuplInitOptions.performance?.clone?.enabled && !!t.cloneResult, a = P(i, o);
1017
1017
  if (t.scope === "list" && (t.listKey = n.cdRef?.key || n.key, t.modelKey = n.model?.key || n.modelKey), t.type === "list_created" && t.args[0].listKey.startsWith("__global_list__") || t.listKey?.startsWith("__global_list__"))
1018
1018
  return a;
1019
1019
  const c = b.now(), u = c - r, f = Math.round(u * 1e3) / 1e3;
@@ -1037,7 +1037,7 @@ const B = (n, e) => e ? typeof structuredClone < "u" ? structuredClone(n) : v(n)
1037
1037
  }, Ve = (n) => (t, r, s) => {
1038
1038
  const i = s.value;
1039
1039
  return s.value = function(...o) {
1040
- const a = b.now(), c = this.cdRef, u = B(n, !0);
1040
+ const a = b.now(), c = this.cdRef, u = P(n, !0);
1041
1041
  u.key || (c.increaseCounter(), u.key = c.getCounter());
1042
1042
  const f = ee();
1043
1043
  c.analyticsController.mark({
@@ -1047,7 +1047,7 @@ const B = (n, e) => e ? typeof structuredClone < "u" ? structuredClone(n) : v(n)
1047
1047
  const l = this.model?.key;
1048
1048
  !u.originCdRefKey && c.key && (u.originCdRefKey = c.key), l && (u.modelKey = l);
1049
1049
  const d = i.apply(this, o);
1050
- return u.method = r, u.args = o, d && typeof d == "object" && "then" in d ? d.then((h) => R(this, c, u, a, f, h)) : R(this, c, u, a, f, d);
1050
+ return u.method = r, u.args = o, d && typeof d == "object" && "then" in d ? d.then((h) => T(this, c, u, a, f, h)) : T(this, c, u, a, f, d);
1051
1051
  }, s;
1052
1052
  };
1053
1053
  function Je(n, e, t, r) {
@@ -1474,7 +1474,7 @@ function x(n, e) {
1474
1474
  else i !== void 0 && s.push(i);
1475
1475
  return s;
1476
1476
  }
1477
- function Q(n) {
1477
+ function M(n) {
1478
1478
  let e = 0;
1479
1479
  for (let t of n) {
1480
1480
  const r = t.toString().split(".")[1];
@@ -1482,7 +1482,7 @@ function Q(n) {
1482
1482
  }
1483
1483
  return Math.pow(10, e);
1484
1484
  }
1485
- function T(n, e, t) {
1485
+ function R(n, e, t) {
1486
1486
  return (n * t + e * t) / t;
1487
1487
  }
1488
1488
  function de(n, e, t) {
@@ -1570,11 +1570,11 @@ const C = (n, e, t, r) => {
1570
1570
  for (const u of c)
1571
1571
  if (Array.isArray(u))
1572
1572
  for (const f of u)
1573
- typeof f == "number" && (t = T(t, f, Q([t, f])), r++);
1574
- else typeof u == "number" && (t = T(t, u, Q([t, u])), r++);
1573
+ typeof f == "number" && (t = R(t, f, M([t, f])), r++);
1574
+ else typeof u == "number" && (t = R(t, u, M([t, u])), r++);
1575
1575
  }
1576
1576
  return r === 0 ? void 0 : {
1577
- average: de(t, r, Q([t, r])),
1577
+ average: de(t, r, M([t, r])),
1578
1578
  count: r,
1579
1579
  sum: t
1580
1580
  };
@@ -1598,7 +1598,7 @@ class A extends Error {
1598
1598
  super(r), this.query = t, this.name = "DcuplQueryError";
1599
1599
  }
1600
1600
  }
1601
- class j {
1601
+ class B {
1602
1602
  _defaultQueryOptions = {
1603
1603
  modelKey: "",
1604
1604
  groupKey: "root",
@@ -2279,7 +2279,7 @@ class j {
2279
2279
  return e(this.currentQuery.queries);
2280
2280
  }
2281
2281
  }
2282
- const N = new j();
2282
+ const N = new B();
2283
2283
  function Xe(n, e, t, r, s, i, o) {
2284
2284
  const a = N.removeQuery({ groupKey: s }, v(r)), c = o.queryData(n, a, !1, i), u = e ? [...e.keys()] : [], f = new Set(u), l = i.get(s) ?? /* @__PURE__ */ new Map();
2285
2285
  if (!t.excludeUnresolved)
@@ -2371,6 +2371,15 @@ class xe {
2371
2371
  reset(e) {
2372
2372
  e ? (this.indexMap.delete(e), this.dataMap.delete(e), this.indexMetadata.delete(e)) : (this.indexMap.clear(), this.dataMap.clear(), this.indexMetadata.clear());
2373
2373
  }
2374
+ /**
2375
+ * Removes every index the predicate selects. Used to drop indices that
2376
+ * were built from now-stale data; the next read lazily rebuilds them via
2377
+ * {@link getOrCreateIndex}.
2378
+ */
2379
+ resetIndicesWhere(e) {
2380
+ for (const t of Array.from(this.indexMap.keys()))
2381
+ e(t) && this.reset(t);
2382
+ }
2374
2383
  fillDataMap(e, t) {
2375
2384
  let r = this.dataMap.get(e);
2376
2385
  r || (r = /* @__PURE__ */ new Map(), this.dataMap.set(e, r));
@@ -2610,7 +2619,7 @@ class xe {
2610
2619
  }
2611
2620
  }
2612
2621
  const w = "__";
2613
- function P(n, e, t = { key: "root" }, r = "root", s = new xe(), i) {
2622
+ function j(n, e, t = { key: "root" }, r = "root", s = new xe(), i) {
2614
2623
  const o = i || n;
2615
2624
  for (const a of e.columns)
2616
2625
  a.attribute && (y.parse(a.attribute), s.getOrCreateIndex(a.attribute, o));
@@ -2657,7 +2666,7 @@ function Ae(n, e, t, r, s = "", i) {
2657
2666
  }
2658
2667
  if (o.rows = o.rows || [], o.rows.push(f), t.rows.length > 1) {
2659
2668
  const d = { ...t, rows: t.rows.slice(1) };
2660
- P(
2669
+ j(
2661
2670
  l,
2662
2671
  d,
2663
2672
  f,
@@ -2702,7 +2711,7 @@ function L(n, e, t, r, s = "", i) {
2702
2711
  }
2703
2712
  if (o.columns = o.columns || [], o.columns.push(f), t.columns.length > 1) {
2704
2713
  const d = { ...t, columns: t.columns.slice(1) };
2705
- P(
2714
+ j(
2706
2715
  l,
2707
2716
  d,
2708
2717
  f,
@@ -2715,7 +2724,7 @@ function L(n, e, t, r, s = "", i) {
2715
2724
  }
2716
2725
  return o;
2717
2726
  }
2718
- const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/, Se = /^-?\d+$/, De = /^-?\d+\.\d+$/, Ie = /^\d{1,2}([/.-])\d{1,2}\1\d{2,4}$/, Ke = (n) => n === "true" || n === "false" ? "boolean" : Se.test(n) ? "int" : De.test(n) ? "float" : be.test(n) && !Number.isNaN(Date.parse(n)) ? "date" : "string", Qe = (n) => Ie.test(n), Me = (n) => n == null || n === "", ke = (n) => {
2727
+ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/, Se = /^-?\d+$/, De = /^-?\d+\.\d+$/, Ie = /^\d{1,2}([/.-])\d{1,2}\1\d{2,4}$/, Ke = (n) => n === "true" || n === "false" ? "boolean" : Se.test(n) ? "int" : De.test(n) ? "float" : be.test(n) && !Number.isNaN(Date.parse(n)) ? "date" : "string", Me = (n) => Ie.test(n), Qe = (n) => n == null || n === "", ke = (n) => {
2719
2728
  const e = [...n];
2720
2729
  return e.length <= 1 ? { type: e[0] ?? "any", conflict: !1 } : e.every((t) => t === "int" || t === "float") ? { type: "float", conflict: !1 } : { type: "any", conflict: !0 };
2721
2730
  }, Ne = (n, e = {}) => {
@@ -2725,12 +2734,12 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2725
2734
  if (l)
2726
2735
  for (const [d, h] of Object.entries(l)) {
2727
2736
  let g = i.get(d);
2728
- if (g || (g = { observed: /* @__PURE__ */ new Set(), empty: 0, scanned: 0 }, i.set(d, g), o.push(d)), g.scanned++, Me(h)) {
2737
+ if (g || (g = { observed: /* @__PURE__ */ new Set(), empty: 0, scanned: 0 }, i.set(d, g), o.push(d)), g.scanned++, Qe(h)) {
2729
2738
  g.empty++;
2730
2739
  continue;
2731
2740
  }
2732
2741
  let m;
2733
- typeof h == "string" && s ? (m = Ke(h), m === "string" && !g.hint && Qe(h) && (g.hint = "column looks date-like (non-ISO) — review manually")) : m = $e(h), g.observed.add(m);
2742
+ typeof h == "string" && s ? (m = Ke(h), m === "string" && !g.hint && Me(h) && (g.hint = "column looks date-like (non-ISO) — review manually")) : m = $e(h), g.observed.add(m);
2734
2743
  }
2735
2744
  }
2736
2745
  const c = [], u = [];
@@ -2873,7 +2882,7 @@ class it {
2873
2882
  globalItemService;
2874
2883
  modelParser;
2875
2884
  registeredCustomOperator = /* @__PURE__ */ new Map();
2876
- queryBuilder = new j();
2885
+ queryBuilder = new B();
2877
2886
  registerCustomOperator(e, t) {
2878
2887
  this.registeredCustomOperator.set(e, t);
2879
2888
  }
@@ -3071,8 +3080,10 @@ class it {
3071
3080
  return o;
3072
3081
  }
3073
3082
  queryData(e, t, r, s) {
3083
+ if (t.queries.length === 0)
3084
+ return e;
3074
3085
  const i = new Map(e);
3075
- return t.queries.length === 0 ? e : (t.groupKey || (t.groupKey = "root"), t.groupType || (t.groupType = "and"), t.queries || (t.queries = []), this.validateQuery(t), this.evaluateQueryGroup(t, t, i, r, s));
3086
+ return t.groupKey || (t.groupKey = "root"), t.groupType || (t.groupType = "and"), t.queries || (t.queries = []), this.validateQuery(t), this.evaluateQueryGroup(t, t, i, r, s);
3076
3087
  }
3077
3088
  // public getRelevantQueryData(data: any, options: DcuplGlobalQueryOptions<any>, model: DcuplModel<ListItem>) {
3078
3089
  // // detect if any of the query attributes are a deep query.
@@ -3109,7 +3120,7 @@ class it {
3109
3120
  // }
3110
3121
  }
3111
3122
  const Oe = "k:", qe = "h:";
3112
- function M(n, e = 0) {
3123
+ function Q(n, e = 0) {
3113
3124
  if (n.key)
3114
3125
  return `${Oe}${n.key}`;
3115
3126
  const t = K({
@@ -3124,13 +3135,22 @@ function ot(n) {
3124
3135
  const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set();
3125
3136
  return n.map((r) => {
3126
3137
  const s = `${r.key ?? ""}|${r.type}|${r.rawUrl ?? r.url}|${r.model ?? ""}`;
3127
- let i = e.get(s) ?? 0, o = M(r, i);
3138
+ let i = e.get(s) ?? 0, o = Q(r, i);
3128
3139
  for (; t.has(o); )
3129
- i += 1, o = r.key ? `${M(r)}#${i}` : M(r, i);
3140
+ i += 1, o = r.key ? `${Q(r)}#${i}` : Q(r, i);
3130
3141
  return e.set(s, i + 1), t.add(o), o;
3131
3142
  });
3132
3143
  }
3133
- class at {
3144
+ function at() {
3145
+ const n = globalThis;
3146
+ return typeof n.scheduler?.yield == "function" ? n.scheduler.yield() : typeof n.setImmediate == "function" ? new Promise((e) => n.setImmediate(() => e())) : typeof n.MessageChannel == "function" ? new Promise((e) => {
3147
+ const t = new n.MessageChannel();
3148
+ t.port1.onmessage = () => {
3149
+ t.port1.close(), e();
3150
+ }, t.port2.postMessage(null);
3151
+ }) : new Promise((e) => setTimeout(e, 0));
3152
+ }
3153
+ class ct {
3134
3154
  scripts = /* @__PURE__ */ new Map();
3135
3155
  scriptFunctions = /* @__PURE__ */ new Map();
3136
3156
  constructor() {
@@ -3173,10 +3193,10 @@ class at {
3173
3193
  return this.getScriptAsFn(e, i)(t, ...o);
3174
3194
  }
3175
3195
  }
3176
- const ct = (n, e) => n ? (e || (e = {}), n.replace(/\$\{(.*?)\}/g, (t, r) => I(e, r.trim(), ""))) : "", ut = (n) => {
3196
+ const ut = (n, e) => n ? (e || (e = {}), n.replace(/\$\{(.*?)\}/g, (t, r) => I(e, r.trim(), ""))) : "", ft = (n) => {
3177
3197
  const e = /* @__PURE__ */ new Set();
3178
3198
  return n.replace(/\$\{(.*?)\}/g, (r, s) => (e.add(s.trim()), "")), { variables: Array.from(e).map((r) => ({ name: r })) };
3179
- }, ft = [
3199
+ }, lt = [
3180
3200
  "any",
3181
3201
  "Array<date>",
3182
3202
  "Array<float>",
@@ -3188,7 +3208,7 @@ const ct = (n, e) => n ? (e || (e = {}), n.replace(/\$\{(.*?)\}/g, (t, r) => I(e
3188
3208
  "int",
3189
3209
  "json",
3190
3210
  "string"
3191
- ], lt = ["int", "float", "Array<int>", "Array<float>"], dt = ["date", "Array<date>"], ht = [
3211
+ ], dt = ["int", "float", "Array<int>", "Array<float>"], ht = ["date", "Array<date>"], pt = [
3192
3212
  "eq",
3193
3213
  "find",
3194
3214
  "gt",
@@ -3201,36 +3221,36 @@ const ct = (n, e) => n ? (e || (e = {}), n.replace(/\$\{(.*?)\}/g, (t, r) => I(e
3201
3221
  ];
3202
3222
  export {
3203
3223
  Oe as AUTHORED_RESOURCE_ID_PREFIX,
3204
- Re as AnalyticsController,
3205
- Te as AttributeDependencyGraph,
3224
+ Te as AnalyticsController,
3225
+ Re as AttributeDependencyGraph,
3206
3226
  Ge as CacheController,
3207
3227
  Ue as ChangeDetector,
3208
3228
  qe as DERIVED_RESOURCE_ID_PREFIX,
3209
- dt as DatePropertyTypes,
3210
- j as DcuplQueryBuilder,
3211
- ht as DcuplQueryOperatorsAsArray,
3229
+ ht as DatePropertyTypes,
3230
+ B as DcuplQueryBuilder,
3231
+ pt as DcuplQueryOperatorsAsArray,
3212
3232
  le as DeepQueryService,
3213
3233
  X as DependencyGraph,
3214
3234
  xe as IndicesController,
3215
3235
  p as Logger,
3216
- lt as NumberPropertyTypes,
3217
- ft as PropertyTypesAsArray,
3236
+ dt as NumberPropertyTypes,
3237
+ lt as PropertyTypesAsArray,
3218
3238
  it as QueryManager,
3219
- at as ScriptController,
3220
- B as clone,
3239
+ ct as ScriptController,
3240
+ P as clone,
3221
3241
  Ke as coerceStringType,
3222
3242
  re as compareVersions,
3223
3243
  Je as computeSuggestions,
3224
3244
  y as deepQueryService,
3225
3245
  te as escapeRegExp,
3226
- ct as evaluateTemplate,
3246
+ ut as evaluateTemplate,
3227
3247
  tt as generateBooleanQuery,
3228
3248
  ee as generateKey,
3229
3249
  rt as generateNumberAndDateQuery,
3230
3250
  st as generateReferenceQuery,
3231
3251
  et as generateTextQuery,
3232
3252
  C as getAggregation,
3233
- Be as getDateConstraintUid,
3253
+ Pe as getDateConstraintUid,
3234
3254
  $e as getDcuplPropertyTypeForNativeType,
3235
3255
  x as getDeepPathValues,
3236
3256
  me as getDistinct,
@@ -3238,7 +3258,7 @@ export {
3238
3258
  ze as getFilterEntryId,
3239
3259
  _e as getNumberConstraintUid,
3240
3260
  Ye as getPropertiesForData,
3241
- Pe as groupBy,
3261
+ je as groupBy,
3242
3262
  He as hasMinimumVersion,
3243
3263
  Ne as inferModel,
3244
3264
  se as isDateInstance,
@@ -3248,16 +3268,17 @@ export {
3248
3268
  nt as isValidQueryStatement,
3249
3269
  F as isValidVersion,
3250
3270
  Y as logger,
3251
- Qe as looksDateLike,
3271
+ Me as looksDateLike,
3252
3272
  Ze as parseDate,
3253
- ut as parseTemplate,
3273
+ ft as parseTemplate,
3254
3274
  b as perf,
3255
- P as pivot,
3275
+ j as pivot,
3256
3276
  Le as removeTrailingSlash,
3257
- M as resolveResourceId,
3277
+ Q as resolveResourceId,
3258
3278
  ot as resolveResourceIds,
3259
3279
  Ve as trigger,
3260
3280
  We as unescapeRegExp,
3261
- je as uniqBy
3281
+ Be as uniqBy,
3282
+ at as yieldToEventLoop
3262
3283
  };
3263
3284
  //# sourceMappingURL=index.js.map