@osdk/client 2.6.0-beta.7 → 2.6.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/build/browser/index.js.map +1 -1
  3. package/build/browser/internal/conversions/modernToLegacyWhereClause.js +13 -15
  4. package/build/browser/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
  5. package/build/browser/internal/conversions/modernToLegacyWhereClause.test.js +62 -0
  6. package/build/browser/internal/conversions/modernToLegacyWhereClause.test.js.map +1 -1
  7. package/build/browser/object/mediaUpload.js +1 -1
  8. package/build/browser/object/mediaUpload.js.map +1 -1
  9. package/build/browser/observable/ObservableClient.js.map +1 -1
  10. package/build/browser/observable/internal/Changes.js.map +1 -1
  11. package/build/browser/observable/internal/IntersectCanonicalizer.js +35 -0
  12. package/build/browser/observable/internal/IntersectCanonicalizer.js.map +1 -0
  13. package/build/browser/observable/internal/KnownCacheKey.js.map +1 -1
  14. package/build/browser/observable/internal/ObservableClientImpl.js +3 -0
  15. package/build/browser/observable/internal/ObservableClientImpl.js.map +1 -1
  16. package/build/browser/observable/internal/PivotCanonicalizer.js +33 -0
  17. package/build/browser/observable/internal/PivotCanonicalizer.js.map +1 -0
  18. package/build/browser/observable/internal/Store.js +14 -2
  19. package/build/browser/observable/internal/Store.js.map +1 -1
  20. package/build/browser/observable/internal/WhereClauseCanonicalizer.js.map +1 -1
  21. package/build/browser/observable/internal/aggregation/AggregationCacheKey.js +22 -0
  22. package/build/browser/observable/internal/aggregation/AggregationCacheKey.js.map +1 -0
  23. package/build/browser/observable/internal/aggregation/AggregationQuery.js +77 -0
  24. package/build/browser/observable/internal/aggregation/AggregationQuery.js.map +1 -0
  25. package/build/browser/observable/internal/aggregation/AggregationsHelper.js +54 -0
  26. package/build/browser/observable/internal/aggregation/AggregationsHelper.js.map +1 -0
  27. package/build/browser/observable/internal/aggregation/ObjectAggregationQuery.js +33 -0
  28. package/build/browser/observable/internal/aggregation/ObjectAggregationQuery.js.map +1 -0
  29. package/build/browser/observable/internal/links/LinksHelper.js +0 -3
  30. package/build/browser/observable/internal/links/LinksHelper.js.map +1 -1
  31. package/build/browser/observable/internal/list/ListCacheKey.js +2 -0
  32. package/build/browser/observable/internal/list/ListCacheKey.js.map +1 -1
  33. package/build/browser/observable/internal/list/ListQuery.js +12 -2
  34. package/build/browser/observable/internal/list/ListQuery.js.map +1 -1
  35. package/build/browser/observable/internal/list/ListQueryOptions.js.map +1 -1
  36. package/build/browser/observable/internal/list/ListsHelper.js +9 -3
  37. package/build/browser/observable/internal/list/ListsHelper.js.map +1 -1
  38. package/build/browser/observable/internal/list/ObjectListQuery.js +48 -9
  39. package/build/browser/observable/internal/list/ObjectListQuery.js.map +1 -1
  40. package/build/browser/observable/internal/testUtils/invalidateList.js +6 -1
  41. package/build/browser/observable/internal/testUtils/invalidateList.js.map +1 -1
  42. package/build/browser/observable/internal/testUtils.js.map +1 -1
  43. package/build/browser/public/internal-node.js +18 -0
  44. package/build/browser/public/internal-node.js.map +1 -0
  45. package/build/browser/public/unstable-do-not-use.js.map +1 -1
  46. package/build/browser/util/UserAgent.js +2 -2
  47. package/build/browser/util/toDataValue.js +3 -2
  48. package/build/browser/util/toDataValue.js.map +1 -1
  49. package/build/browser/util/toDataValue.test.js +1 -1
  50. package/build/browser/util/toDataValue.test.js.map +1 -1
  51. package/build/cjs/chunk-6SCDLAU2.cjs +57 -0
  52. package/build/cjs/chunk-6SCDLAU2.cjs.map +1 -0
  53. package/build/cjs/{chunk-3LMKH6RS.cjs → chunk-DZE6IAUU.cjs} +145 -47
  54. package/build/cjs/chunk-DZE6IAUU.cjs.map +1 -0
  55. package/build/cjs/{chunk-4ZOXOCQX.cjs → chunk-S4JPAF56.cjs} +225 -67
  56. package/build/cjs/chunk-S4JPAF56.cjs.map +1 -0
  57. package/build/cjs/{delay-QK4T7RVX.cjs → delay-KIUUJ5NJ.cjs} +4 -3
  58. package/build/cjs/delay-KIUUJ5NJ.cjs.map +1 -0
  59. package/build/cjs/index.cjs +17 -9
  60. package/build/cjs/index.cjs.map +1 -1
  61. package/build/cjs/index.d.cts +1 -1
  62. package/build/cjs/public/internal-node.cjs +193767 -0
  63. package/build/cjs/public/internal-node.cjs.map +1 -0
  64. package/build/cjs/public/internal-node.d.cts +29 -0
  65. package/build/cjs/public/internal.cjs +16 -9
  66. package/build/cjs/public/internal.cjs.map +1 -1
  67. package/build/cjs/public/unstable-do-not-use.cjs +1050 -706
  68. package/build/cjs/public/unstable-do-not-use.cjs.map +1 -1
  69. package/build/cjs/public/unstable-do-not-use.d.cts +36 -2
  70. package/build/esm/index.js.map +1 -1
  71. package/build/esm/internal/conversions/modernToLegacyWhereClause.js +13 -15
  72. package/build/esm/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
  73. package/build/esm/internal/conversions/modernToLegacyWhereClause.test.js +62 -0
  74. package/build/esm/internal/conversions/modernToLegacyWhereClause.test.js.map +1 -1
  75. package/build/esm/object/mediaUpload.js +1 -1
  76. package/build/esm/object/mediaUpload.js.map +1 -1
  77. package/build/esm/observable/ObservableClient.js.map +1 -1
  78. package/build/esm/observable/internal/Changes.js.map +1 -1
  79. package/build/esm/observable/internal/IntersectCanonicalizer.js +35 -0
  80. package/build/esm/observable/internal/IntersectCanonicalizer.js.map +1 -0
  81. package/build/esm/observable/internal/KnownCacheKey.js.map +1 -1
  82. package/build/esm/observable/internal/ObservableClientImpl.js +3 -0
  83. package/build/esm/observable/internal/ObservableClientImpl.js.map +1 -1
  84. package/build/esm/observable/internal/PivotCanonicalizer.js +33 -0
  85. package/build/esm/observable/internal/PivotCanonicalizer.js.map +1 -0
  86. package/build/esm/observable/internal/Store.js +14 -2
  87. package/build/esm/observable/internal/Store.js.map +1 -1
  88. package/build/esm/observable/internal/WhereClauseCanonicalizer.js.map +1 -1
  89. package/build/esm/observable/internal/aggregation/AggregationCacheKey.js +22 -0
  90. package/build/esm/observable/internal/aggregation/AggregationCacheKey.js.map +1 -0
  91. package/build/esm/observable/internal/aggregation/AggregationQuery.js +77 -0
  92. package/build/esm/observable/internal/aggregation/AggregationQuery.js.map +1 -0
  93. package/build/esm/observable/internal/aggregation/AggregationsHelper.js +54 -0
  94. package/build/esm/observable/internal/aggregation/AggregationsHelper.js.map +1 -0
  95. package/build/esm/observable/internal/aggregation/ObjectAggregationQuery.js +33 -0
  96. package/build/esm/observable/internal/aggregation/ObjectAggregationQuery.js.map +1 -0
  97. package/build/esm/observable/internal/links/LinksHelper.js +0 -3
  98. package/build/esm/observable/internal/links/LinksHelper.js.map +1 -1
  99. package/build/esm/observable/internal/list/ListCacheKey.js +2 -0
  100. package/build/esm/observable/internal/list/ListCacheKey.js.map +1 -1
  101. package/build/esm/observable/internal/list/ListQuery.js +12 -2
  102. package/build/esm/observable/internal/list/ListQuery.js.map +1 -1
  103. package/build/esm/observable/internal/list/ListQueryOptions.js.map +1 -1
  104. package/build/esm/observable/internal/list/ListsHelper.js +9 -3
  105. package/build/esm/observable/internal/list/ListsHelper.js.map +1 -1
  106. package/build/esm/observable/internal/list/ObjectListQuery.js +48 -9
  107. package/build/esm/observable/internal/list/ObjectListQuery.js.map +1 -1
  108. package/build/esm/observable/internal/testUtils/invalidateList.js +6 -1
  109. package/build/esm/observable/internal/testUtils/invalidateList.js.map +1 -1
  110. package/build/esm/observable/internal/testUtils.js.map +1 -1
  111. package/build/esm/public/internal-node.js +18 -0
  112. package/build/esm/public/internal-node.js.map +1 -0
  113. package/build/esm/public/unstable-do-not-use.js.map +1 -1
  114. package/build/esm/util/UserAgent.js +2 -2
  115. package/build/esm/util/toDataValue.js +3 -2
  116. package/build/esm/util/toDataValue.js.map +1 -1
  117. package/build/esm/util/toDataValue.test.js +1 -1
  118. package/build/esm/util/toDataValue.test.js.map +1 -1
  119. package/build/types/index.d.ts +1 -1
  120. package/build/types/index.d.ts.map +1 -1
  121. package/build/types/observable/ObservableClient.d.ts +46 -1
  122. package/build/types/observable/ObservableClient.d.ts.map +1 -1
  123. package/build/types/observable/internal/Changes.d.ts +4 -3
  124. package/build/types/observable/internal/Changes.d.ts.map +1 -1
  125. package/build/types/observable/internal/IntersectCanonicalizer.d.ts +18 -0
  126. package/build/types/observable/internal/IntersectCanonicalizer.d.ts.map +1 -0
  127. package/build/types/observable/internal/KnownCacheKey.d.ts +2 -1
  128. package/build/types/observable/internal/KnownCacheKey.d.ts.map +1 -1
  129. package/build/types/observable/internal/PivotCanonicalizer.d.ts +10 -0
  130. package/build/types/observable/internal/PivotCanonicalizer.d.ts.map +1 -0
  131. package/build/types/observable/internal/Store.d.ts +6 -0
  132. package/build/types/observable/internal/Store.d.ts.map +1 -1
  133. package/build/types/observable/internal/WhereClauseCanonicalizer.d.ts.map +1 -1
  134. package/build/types/observable/internal/aggregation/AggregationCacheKey.d.ts +12 -0
  135. package/build/types/observable/internal/aggregation/AggregationCacheKey.d.ts.map +1 -0
  136. package/build/types/observable/internal/aggregation/AggregationQuery.d.ts +49 -0
  137. package/build/types/observable/internal/aggregation/AggregationQuery.d.ts.map +1 -0
  138. package/build/types/observable/internal/aggregation/AggregationsHelper.d.ts +37 -0
  139. package/build/types/observable/internal/aggregation/AggregationsHelper.d.ts.map +1 -0
  140. package/build/types/observable/internal/aggregation/ObjectAggregationQuery.d.ts +5 -0
  141. package/build/types/observable/internal/aggregation/ObjectAggregationQuery.d.ts.map +1 -0
  142. package/build/types/observable/internal/links/LinksHelper.d.ts +0 -4
  143. package/build/types/observable/internal/links/LinksHelper.d.ts.map +1 -1
  144. package/build/types/observable/internal/list/ListCacheKey.d.ts +4 -1
  145. package/build/types/observable/internal/list/ListCacheKey.d.ts.map +1 -1
  146. package/build/types/observable/internal/list/ListQuery.d.ts +4 -1
  147. package/build/types/observable/internal/list/ListQuery.d.ts.map +1 -1
  148. package/build/types/observable/internal/list/ListQueryOptions.d.ts +9 -1
  149. package/build/types/observable/internal/list/ListQueryOptions.d.ts.map +1 -1
  150. package/build/types/observable/internal/list/ListsHelper.d.ts +5 -1
  151. package/build/types/observable/internal/list/ListsHelper.d.ts.map +1 -1
  152. package/build/types/observable/internal/list/ObjectListQuery.d.ts.map +1 -1
  153. package/build/types/observable/internal/testUtils.d.ts +1 -1
  154. package/build/types/observable/internal/testUtils.d.ts.map +1 -1
  155. package/build/types/public/internal-node.d.ts +2 -0
  156. package/build/types/public/internal-node.d.ts.map +1 -0
  157. package/build/types/public/unstable-do-not-use.d.ts +1 -1
  158. package/build/types/public/unstable-do-not-use.d.ts.map +1 -1
  159. package/internal-node.d.ts +17 -0
  160. package/package.json +21 -11
  161. package/build/cjs/chunk-3LMKH6RS.cjs.map +0 -1
  162. package/build/cjs/chunk-4ZOXOCQX.cjs.map +0 -1
  163. package/build/cjs/chunk-Q7SFCCGT.cjs +0 -11
  164. package/build/cjs/chunk-Q7SFCCGT.cjs.map +0 -1
  165. package/build/cjs/delay-QK4T7RVX.cjs.map +0 -1
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunk4ZOXOCQX_cjs = require('../chunk-4ZOXOCQX.cjs');
4
- var chunk3LMKH6RS_cjs = require('../chunk-3LMKH6RS.cjs');
5
- require('../chunk-Q7SFCCGT.cjs');
3
+ var chunkS4JPAF56_cjs = require('../chunk-S4JPAF56.cjs');
4
+ var chunkDZE6IAUU_cjs = require('../chunk-DZE6IAUU.cjs');
5
+ var chunk6SCDLAU2_cjs = require('../chunk-6SCDLAU2.cjs');
6
6
  var trie = require('@wry/trie');
7
7
  var deepEqual = require('fast-deep-equal');
8
8
  var invariant4 = require('tiny-invariant');
@@ -18,6 +18,17 @@ var deepEqual__default = /*#__PURE__*/_interopDefault(deepEqual);
18
18
  var invariant4__default = /*#__PURE__*/_interopDefault(invariant4);
19
19
  var groupBy__default = /*#__PURE__*/_interopDefault(groupBy);
20
20
 
21
+ // src/public/unstable-do-not-use.ts
22
+ chunk6SCDLAU2_cjs.init_cjs_shims();
23
+
24
+ // src/observable/computeObjectSetCacheKey.ts
25
+ chunk6SCDLAU2_cjs.init_cjs_shims();
26
+
27
+ // src/observable/internal/OrderByCanonicalizer.ts
28
+ chunk6SCDLAU2_cjs.init_cjs_shims();
29
+
30
+ // src/observable/internal/WeakRefTrie.ts
31
+ chunk6SCDLAU2_cjs.init_cjs_shims();
21
32
  var defaultMakeData = () => /* @__PURE__ */ Object.create(null);
22
33
  var WeakRefTrie = class {
23
34
  #finalizer = new FinalizationRegistry((orderBy) => {
@@ -70,6 +81,9 @@ var OrderByCanonicalizer = class {
70
81
  return this.#trie.lookupArray(strings);
71
82
  };
72
83
  };
84
+
85
+ // src/observable/internal/WhereClauseCanonicalizer.ts
86
+ chunk6SCDLAU2_cjs.init_cjs_shims();
73
87
  var WhereClauseCanonicalizer = class {
74
88
  /**
75
89
  * This is a shortcut cache for any WhereClause's that we have
@@ -139,7 +153,7 @@ var WhereClauseCanonicalizer = class {
139
153
  var whereCanonicalizer = new WhereClauseCanonicalizer();
140
154
  var orderByCanonicalizer = new OrderByCanonicalizer();
141
155
  function computeObjectSetCacheKey(objectSet, options) {
142
- const keyParts = ["objectSet", chunk3LMKH6RS_cjs.getWireObjectSet(objectSet)];
156
+ const keyParts = ["objectSet", chunkDZE6IAUU_cjs.getWireObjectSet(objectSet)];
143
157
  if (!options) {
144
158
  return JSON.stringify(keyParts);
145
159
  }
@@ -151,13 +165,13 @@ function computeObjectSetCacheKey(objectSet, options) {
151
165
  keyParts.push("props", propKeys);
152
166
  }
153
167
  if (options.union && options.union.length > 0) {
154
- keyParts.push("union", options.union.map((os) => chunk3LMKH6RS_cjs.getWireObjectSet(os)));
168
+ keyParts.push("union", options.union.map((os) => chunkDZE6IAUU_cjs.getWireObjectSet(os)));
155
169
  }
156
170
  if (options.intersect && options.intersect.length > 0) {
157
- keyParts.push("intersect", options.intersect.map((os) => chunk3LMKH6RS_cjs.getWireObjectSet(os)));
171
+ keyParts.push("intersect", options.intersect.map((os) => chunkDZE6IAUU_cjs.getWireObjectSet(os)));
158
172
  }
159
173
  if (options.subtract && options.subtract.length > 0) {
160
- keyParts.push("subtract", options.subtract.map((os) => chunk3LMKH6RS_cjs.getWireObjectSet(os)));
174
+ keyParts.push("subtract", options.subtract.map((os) => chunkDZE6IAUU_cjs.getWireObjectSet(os)));
161
175
  }
162
176
  if (options.pivotTo) {
163
177
  keyParts.push("pivotTo", options.pivotTo);
@@ -171,7 +185,14 @@ function computeObjectSetCacheKey(objectSet, options) {
171
185
  return JSON.stringify(keyParts);
172
186
  }
173
187
 
188
+ // src/observable/ObservableClient.ts
189
+ chunk6SCDLAU2_cjs.init_cjs_shims();
190
+
191
+ // src/observable/internal/ObservableClientImpl.ts
192
+ chunk6SCDLAU2_cjs.init_cjs_shims();
193
+
174
194
  // src/observable/internal/UnsubscribableWrapper.ts
195
+ chunk6SCDLAU2_cjs.init_cjs_shims();
175
196
  var UnsubscribableWrapper = class {
176
197
  #subscription;
177
198
  constructor(subscription) {
@@ -207,6 +228,9 @@ var ObservableClientImpl = class {
207
228
  subFn
208
229
  );
209
230
  };
231
+ observeAggregation = (options, subFn) => {
232
+ return this.__experimentalStore.aggregations.observe(options, subFn);
233
+ };
210
234
  observeLinks = (objects, linkName, options, subFn) => {
211
235
  const objectsArray = Array.isArray(objects) ? objects : [objects];
212
236
  const parentSub = new rxjs.Subscription();
@@ -252,11 +276,22 @@ var ObservableClientImpl = class {
252
276
  }
253
277
  };
254
278
 
279
+ // src/observable/internal/Store.ts
280
+ chunk6SCDLAU2_cjs.init_cjs_shims();
281
+
255
282
  // src/observable/DebugFlags.ts
283
+ chunk6SCDLAU2_cjs.init_cjs_shims();
256
284
  process.env.NODE_ENV !== "production" && false;
257
285
  var DEBUG_CACHE_KEYS = process.env.NODE_ENV !== "production" && false;
258
286
 
287
+ // src/observable/internal/actions/ActionApplication.ts
288
+ chunk6SCDLAU2_cjs.init_cjs_shims();
289
+
290
+ // src/observable/internal/actions/OptimisticJob.ts
291
+ chunk6SCDLAU2_cjs.init_cjs_shims();
292
+
259
293
  // src/observable/internal/OptimisticId.ts
294
+ chunk6SCDLAU2_cjs.init_cjs_shims();
260
295
  function createOptimisticId() {
261
296
  if (process.env.NODE_ENV !== "production") {
262
297
  if (createOptimisticId.counter === void 0) {
@@ -316,7 +351,7 @@ var OptimisticJob = class {
316
351
  return this;
317
352
  },
318
353
  createObject(type, pk, properties) {
319
- const create = store.client[chunk3LMKH6RS_cjs.additionalContext].objectFactory2(store.client[chunk3LMKH6RS_cjs.additionalContext], [{
354
+ const create = store.client[chunkDZE6IAUU_cjs.additionalContext].objectFactory2(store.client[chunkDZE6IAUU_cjs.additionalContext], [{
320
355
  $primaryKey: pk,
321
356
  $apiName: type.apiName,
322
357
  $objectType: type.apiName,
@@ -383,7 +418,7 @@ var ActionApplication = class {
383
418
  if (process.env.NODE_ENV !== "production") {
384
419
  if (ACTION_DELAY > 0) {
385
420
  logger?.debug("action done, pausing", actionResults);
386
- const delay = (await import('../delay-QK4T7RVX.cjs')).default;
421
+ const delay = (await import('../delay-KIUUJ5NJ.cjs')).default;
387
422
  await delay(ACTION_DELAY);
388
423
  logger?.debug("action done, pausing done");
389
424
  }
@@ -441,735 +476,950 @@ var ActionApplication = class {
441
476
  };
442
477
  };
443
478
 
444
- // src/observable/internal/CacheKey.ts
445
- function DEBUG_ONLY__cacheKeyToString(x) {
446
- if (process.env.NODE_ENV !== "production") {
447
- return `${x.type}CacheKey<${x.otherKeys.map((xx) => JSON.stringify(xx)).join(", ")}>`.replaceAll('"', "'");
448
- } else {
449
- throw new Error("not implemented");
450
- }
451
- }
452
- function DEBUG_ONLY__cacheKeysToString(x) {
453
- if (process.env.NODE_ENV !== "production") {
454
- return "\n - " + x.map(DEBUG_ONLY__cacheKeyToString).join("\n - ");
455
- } else {
456
- throw new Error("not implemented");
457
- }
458
- }
479
+ // src/observable/internal/aggregation/AggregationCacheKey.ts
480
+ chunk6SCDLAU2_cjs.init_cjs_shims();
481
+ var API_NAME_IDX = 1;
482
+ var WHERE_IDX = 2;
483
+ var RDP_IDX = 3;
484
+ var AGGREGATE_IDX = 4;
459
485
 
460
- // src/observable/internal/RefCounts.ts
461
- var RefCounts = class {
462
- refCounts = /* @__PURE__ */ new Map();
463
- // keeps our objects around for some extended duration after they are no longer
464
- // needed which is good for quick clicks across tabs.
465
- gcMap = /* @__PURE__ */ new Map();
466
- constructor(keepAlive, cleanup) {
467
- this.keepAlive = keepAlive;
468
- this.cleanup = cleanup;
469
- }
470
- register(key) {
471
- if (!this.refCounts.has(key)) {
472
- this.gcMap.set(key, Date.now() + this.keepAlive);
473
- }
474
- return key;
475
- }
476
- retain(key) {
477
- const count = this.refCounts.get(key) ?? 0;
478
- this.refCounts.set(key, count + 1);
479
- if (this.gcMap.has(key)) {
480
- this.gcMap.delete(key);
481
- }
486
+ // src/observable/internal/aggregation/AggregationsHelper.ts
487
+ chunk6SCDLAU2_cjs.init_cjs_shims();
488
+
489
+ // src/observable/internal/AbstractHelper.ts
490
+ chunk6SCDLAU2_cjs.init_cjs_shims();
491
+
492
+ // src/observable/internal/QuerySubscription.ts
493
+ chunk6SCDLAU2_cjs.init_cjs_shims();
494
+ var subscriptionIdCounter = 0;
495
+ var QuerySubscription = class extends UnsubscribableWrapper {
496
+ /** @internal */
497
+ /** @internal */
498
+ /** @internal */
499
+ constructor(query, subscription) {
500
+ super(subscription);
501
+ this.query = query;
502
+ this.subscription = subscription;
503
+ this.subscriptionId = `sub_${++subscriptionIdCounter}`;
504
+ Object.defineProperties(this, {
505
+ query: {
506
+ enumerable: false
507
+ },
508
+ subscription: {
509
+ enumerable: false
510
+ },
511
+ subscriptionId: {
512
+ enumerable: false
513
+ }
514
+ });
482
515
  }
483
- release(key) {
484
- const count = this.refCounts.get(key);
485
- if (count === void 0) ; else if (count === 1) {
486
- this.refCounts.delete(key);
487
- this.gcMap.set(key, Date.now() + this.keepAlive);
488
- } else {
489
- this.refCounts.set(key, count - 1);
490
- }
516
+ };
517
+
518
+ // src/observable/internal/AbstractHelper.ts
519
+ var AbstractHelper = class {
520
+ constructor(store, cacheKeys) {
521
+ this.store = store;
522
+ this.cacheKeys = cacheKeys;
491
523
  }
492
- has(key) {
493
- return this.refCounts.has(key);
524
+ observe(options, subFn) {
525
+ const query = this.getQuery(options);
526
+ return this._subscribe(query, options, subFn);
494
527
  }
495
- gc() {
496
- const now = Date.now();
497
- for (const [key, deathTime] of this.gcMap) {
498
- if (deathTime < now) {
499
- this.gcMap.delete(key);
500
- this.cleanup(key);
501
- }
528
+ _subscribe(query, options, subFn) {
529
+ this.store.cacheKeys.retain(query.cacheKey);
530
+ if (options.mode !== "offline") {
531
+ query.revalidate(options.mode === "force").catch((e) => {
532
+ subFn.error(e);
533
+ if (this.store.logger) {
534
+ this.store.logger.error("Unhandled error in observeObject", e);
535
+ } else {
536
+ throw e;
537
+ }
538
+ });
502
539
  }
540
+ const sub = query.subscribe(subFn);
541
+ const querySub = new QuerySubscription(query, sub);
542
+ query.registerSubscriptionDedupeInterval(querySub.subscriptionId, options.dedupeInterval);
543
+ sub.add(() => {
544
+ query.unregisterSubscriptionDedupeInterval(querySub.subscriptionId);
545
+ this.store.cacheKeys.release(query.cacheKey);
546
+ });
547
+ return querySub;
503
548
  }
504
549
  };
505
550
 
506
- // src/observable/internal/CacheKeys.ts
507
- var CacheKeys = class {
508
- #cacheKeys = new trie.Trie(false, (keys) => {
509
- const cacheKey = {
510
- type: keys[0],
511
- otherKeys: keys.slice(1)
512
- };
513
- this.#onCreate?.(cacheKey);
514
- return cacheKey;
515
- });
516
- #refCounts = new RefCounts(6e4, (k) => this.#cleanupCacheKey(k));
517
- // we are currently only using this for debug logging and should just remove it in the future if that
518
- // continues to be true
519
- #finalizationRegistry;
520
- #onCreate;
521
- #onDestroy;
522
- constructor({
523
- onCreate,
524
- onDestroy
525
- }) {
526
- this.#onCreate = onCreate;
527
- this.#onDestroy = onDestroy;
528
- setInterval(() => {
529
- this.#refCounts.gc();
530
- }, 1e3);
531
- this.#finalizationRegistry = new FinalizationRegistry((cleanupCallback) => {
532
- try {
533
- cleanupCallback();
534
- } catch (e) {
535
- console.error("Caught an error while running a finalization callback", e);
551
+ // src/observable/internal/aggregation/ObjectAggregationQuery.ts
552
+ chunk6SCDLAU2_cjs.init_cjs_shims();
553
+
554
+ // src/observable/internal/aggregation/AggregationQuery.ts
555
+ chunk6SCDLAU2_cjs.init_cjs_shims();
556
+
557
+ // src/observable/internal/Query.ts
558
+ chunk6SCDLAU2_cjs.init_cjs_shims();
559
+ var Query = class {
560
+ retainCount = 0;
561
+ #connectable;
562
+ #subscription;
563
+ #subject;
564
+ #subscriptionDedupeIntervals = /* @__PURE__ */ new Map();
565
+ /** @internal */
566
+ constructor(store, observable, opts, cacheKey, logger) {
567
+ this.options = opts;
568
+ this.cacheKey = cacheKey;
569
+ this.store = store;
570
+ this.cacheKeys = store.cacheKeys;
571
+ this.#subject = observable;
572
+ this.logger = logger ?? (process.env.NODE_ENV === "production" ? store.client[chunkDZE6IAUU_cjs.additionalContext].logger : store.client[chunkDZE6IAUU_cjs.additionalContext].logger?.child({}, {
573
+ msgPrefix: process.env.NODE_ENV !== "production" ? `Query<${cacheKey.type}, ${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>` : "Query"
574
+ }));
575
+ }
576
+ subscribe(observer) {
577
+ this.#connectable ??= this._createConnectable(this.#subject);
578
+ this.#subscription = this.#connectable.connect();
579
+ const sub = this.#connectable.subscribe({
580
+ next: (value) => {
581
+ if (observer.next) {
582
+ observer.next(value);
583
+ }
584
+ },
585
+ error: (err) => {
586
+ if (observer.error) {
587
+ observer.error(err);
588
+ }
589
+ },
590
+ complete: () => {
591
+ if (observer.complete) {
592
+ observer.complete();
593
+ }
536
594
  }
537
595
  });
596
+ return sub;
538
597
  }
539
- get(type, ...args) {
540
- const normalizedArgs = [...args];
541
- while (normalizedArgs.length > 0 && normalizedArgs[normalizedArgs.length - 1] === void 0) {
542
- normalizedArgs.pop();
598
+ /**
599
+ * Register a subscription's dedupeInterval value
600
+ */
601
+ registerSubscriptionDedupeInterval(subscriptionId, dedupeInterval) {
602
+ if (dedupeInterval != null && dedupeInterval > 0) {
603
+ this.#subscriptionDedupeIntervals.set(subscriptionId, dedupeInterval);
543
604
  }
544
- const cacheKeyArgs = [type, ...normalizedArgs];
545
- if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) ;
546
- const cacheKey = this.#cacheKeys.lookupArray(cacheKeyArgs);
547
- this.#refCounts.register(cacheKey);
548
- return cacheKey;
549
- }
550
- retain(cacheKey) {
551
- this.#refCounts.retain(cacheKey);
552
605
  }
553
- release(cacheKey) {
554
- this.#refCounts.release(cacheKey);
606
+ /**
607
+ * Unregister a subscription's dedupeInterval value
608
+ */
609
+ unregisterSubscriptionDedupeInterval(subscriptionId) {
610
+ this.#subscriptionDedupeIntervals.delete(subscriptionId);
555
611
  }
556
- #remove(cacheKey) {
557
- this.#cacheKeys.remove(cacheKey.type, ...cacheKey.otherKeys);
612
+ /**
613
+ * Get the minimum dedupeInterval from all active subscriptions
614
+ */
615
+ getMinimumDedupeInterval() {
616
+ if (this.#subscriptionDedupeIntervals.size === 0) {
617
+ return this.options.dedupeInterval ?? 0;
618
+ }
619
+ return Math.min(...this.#subscriptionDedupeIntervals.values());
558
620
  }
559
621
  /**
560
- * Called after a key is no longer retained and the timeout has elapsed
561
- * @param key
622
+ * Causes the query to revalidate. This will cause the query to fetch
623
+ * the latest data from the server and update the store if it is deemed
624
+ * "stale" or if `force` is true.
625
+ *
626
+ * @param force
627
+ * @returns
562
628
  */
563
- #cleanupCacheKey = (key) => {
564
- this.#onDestroy?.(key);
565
- this.#remove(key);
566
- };
567
- };
568
- var Changes = class {
569
- modifiedObjects = new mnemonist.MultiMap();
570
- addedObjects = new mnemonist.MultiMap();
571
- added = /* @__PURE__ */ new Set();
572
- modified = /* @__PURE__ */ new Set();
573
- deleted = /* @__PURE__ */ new Set();
574
- registerObject = (cacheKey, data, isNew) => {
575
- this[isNew ? "addedObjects" : "modifiedObjects"].set(data.$apiName, data);
576
- this[isNew ? "added" : "modified"].add(cacheKey);
577
- };
578
- deleteObject = (cacheKey) => {
579
- this.deleted.add(cacheKey);
580
- };
581
- registerList = (key) => {
582
- this.modified.add(key);
583
- };
584
- registerLink = (cacheKey) => {
585
- this.modified.add(cacheKey);
586
- };
587
- deleteLink = (cacheKey) => {
588
- this.deleted.add(cacheKey);
589
- };
590
- registerObjectSet = (key) => {
591
- this.modified.add(key);
592
- };
593
- isEmpty() {
594
- return this.modifiedObjects.size === 0 && this.addedObjects.size === 0 && this.added.size === 0 && this.modified.size === 0 && this.deleted.size === 0;
595
- }
596
- };
597
- function createChangedObjects() {
598
- return new Changes();
599
- }
600
- function DEBUG_ONLY__changesToString(changes) {
601
- if (process.env.NODE_ENV !== "production") {
602
- return JSON.stringify({
603
- modifiedObjects: multimapHelper(changes.modifiedObjects),
604
- addedObjects: multimapHelper(changes.addedObjects),
605
- added: listHelper(changes.added),
606
- modified: listHelper(changes.modified)
607
- }, null, 2);
608
- } else {
609
- throw new Error("not implemented");
610
- }
611
- }
612
- function listHelper(set) {
613
- return Array.from(set).map(DEBUG_ONLY__cacheKeyToString);
614
- }
615
- function multimapHelper(multimap) {
616
- return Object.fromEntries(Array.from(multimap.associations()).map(([type, objects]) => {
617
- return [type, objects.map((o) => o.$primaryKey)];
618
- }));
619
- }
620
-
621
- // src/observable/internal/createInitEntry.ts
622
- function createInitEntry(cacheKey) {
623
- return {
624
- cacheKey,
625
- status: "init",
626
- value: void 0,
627
- lastUpdated: 0
628
- };
629
- }
630
-
631
- // src/observable/internal/WeakMapWithEntries.ts
632
- var WeakMapWithEntries = class {
633
- #map = /* @__PURE__ */ new WeakMap();
634
- #list = [];
635
- #toClean = [];
636
- #needsCleaning = false;
637
- #registry = new FinalizationRegistry(() => {
638
- this.#toClean.push(new WeakRef({}));
639
- this.#needsCleaning = true;
640
- });
641
- constructor() {
642
- const weakThis = new WeakRef(this);
643
- const intervalId = setInterval(() => {
644
- const self = weakThis.deref();
645
- if (self) {
646
- if (this.#needsCleaning) {
647
- this.#clean();
648
- }
649
- } else {
650
- clearInterval(intervalId);
629
+ async revalidate(force) {
630
+ const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
631
+ methodName: "revalidate"
632
+ }) : this.logger;
633
+ if (force) {
634
+ this.abortController?.abort();
635
+ }
636
+ if (this.pendingFetch) {
637
+ if (process.env.NODE_ENV !== "production") {
638
+ logger?.debug("Fetch is already pending, using it");
651
639
  }
652
- }, 1e3);
653
- }
654
- #clean() {
655
- this.#list = this.#list.filter((ref) => ref.deref() !== void 0);
656
- }
657
- // functions for WeakMap
658
- delete(key) {
659
- const ret = this.#map.delete(key);
660
- this.#toClean.push(new WeakRef(key));
661
- this.#needsCleaning = true;
662
- return ret;
663
- }
664
- get(key) {
665
- return this.#map.get(key);
640
+ await this.pendingFetch;
641
+ return;
642
+ }
643
+ const minDedupeInterval = this.getMinimumDedupeInterval();
644
+ if (minDedupeInterval > 0 && this.lastFetchStarted != null && Date.now() - this.lastFetchStarted < minDedupeInterval) {
645
+ if (process.env.NODE_ENV !== "production") {
646
+ logger?.debug("Within dupeInterval, aborting revalidate");
647
+ }
648
+ return Promise.resolve();
649
+ }
650
+ if (process.env.NODE_ENV !== "production") {
651
+ logger?.debug("Starting actual revalidate");
652
+ }
653
+ this.store.batch({}, (batch) => {
654
+ this.setStatus("loading", batch);
655
+ });
656
+ this._preFetch();
657
+ this.lastFetchStarted = Date.now();
658
+ if (process.env.NODE_ENV !== "production") {
659
+ logger?.debug("calling _fetchAndStore()");
660
+ }
661
+ this.pendingFetch = this._fetchAndStore().finally(() => {
662
+ logger?.debug("promise's finally for _fetchAndStore()");
663
+ this.pendingFetch = void 0;
664
+ });
665
+ await this.pendingFetch;
666
+ return;
666
667
  }
667
- has(key) {
668
- return this.#map.has(key);
668
+ _preFetch() {
669
669
  }
670
670
  /**
671
- * Adds a new element with a specified key and value.
672
- * @param key Must be an object or symbol.
671
+ * Sets the status of the query in the store (but does not store that in `changes`).
672
+ *
673
+ * @param status
674
+ * @param batch
675
+ * @returns
673
676
  */
674
- set(key, value) {
675
- if (!this.#map.has(key)) {
676
- this.#list.push(new WeakRef(key));
677
+ setStatus(status, batch) {
678
+ if (process.env.NODE_ENV !== "production") {
679
+ this.logger?.child({
680
+ methodName: "setStatus"
681
+ }).debug(`Attempting to set status to '${status}'`);
677
682
  }
678
- this.#map.set(key, value);
679
- return this;
683
+ const existing = batch.read(this.cacheKey);
684
+ if (existing?.status === status) {
685
+ if (process.env.NODE_ENV !== "production") {
686
+ this.logger?.child({
687
+ methodName: "setStatus"
688
+ }).debug(`Status is already set to '${status}'; aborting`);
689
+ }
690
+ return;
691
+ }
692
+ if (process.env.NODE_ENV !== "production") {
693
+ this.logger?.child({
694
+ methodName: "setStatus"
695
+ }).debug(`Writing status '${status}' to cache`);
696
+ }
697
+ batch.write(this.cacheKey, existing?.value, status);
680
698
  }
681
- [Symbol.toStringTag] = "WeakMap";
682
- // functions for iterables
683
- /** Returns an iterable of entries in the map. */
684
- [Symbol.iterator]() {
685
- return this.entries();
699
+ dispose() {
700
+ if (this.abortController) {
701
+ this.abortController.abort();
702
+ }
703
+ this.#subscription?.unsubscribe();
704
+ this._dispose();
686
705
  }
687
706
  /**
688
- * Returns an iterable of key, value pairs for every entry in the map.
707
+ * Per query type dispose functionality
689
708
  */
690
- entries() {
691
- const self = this;
692
- function* iter() {
693
- for (const ref of self.#list) {
694
- const key = ref.deref();
695
- if (key !== void 0) {
696
- yield [key, self.#map.get(key)];
697
- }
698
- }
699
- }
700
- return iter();
709
+ _dispose() {
701
710
  }
702
711
  /**
703
- * Returns an iterable of keys in the map
712
+ * The purpose of this method is to provide a way for others to write
713
+ * directly into the store for this query.
714
+ *
715
+ * @param data
716
+ * @param status
717
+ * @param batch
704
718
  */
705
- keys() {
706
- const self = this;
707
- function* iter() {
708
- for (const ref of self.#list) {
709
- const key = ref.deref();
710
- if (key !== void 0) {
711
- yield key;
712
- }
713
- }
714
- }
715
- return iter();
716
- }
717
719
  /**
718
- * Returns an iterable of values in the map
720
+ * @param changes
721
+ * @param optimisticId
722
+ * @returns If revalidation is needed, a promise that resolves after the
723
+ * revalidation is complete. Otherwise, undefined.
719
724
  */
720
- values() {
721
- const self = this;
722
- function* iter() {
723
- for (const ref of self.#list) {
724
- const key = ref.deref();
725
- if (key !== void 0) {
726
- const value = self.#map.get(key);
727
- if (value !== void 0) {
728
- yield value;
729
- }
730
- }
731
- }
732
- }
733
- return iter();
734
- }
735
725
  };
736
726
 
737
- // src/observable/internal/Layer.ts
738
- var Layer = class _Layer {
739
- #parent;
740
- #cache = new WeakMapWithEntries();
741
- #layerId;
742
- constructor(parent, layerId) {
743
- this.#parent = parent;
744
- this.#layerId = layerId;
745
- }
746
- get parentLayer() {
747
- return this.#parent;
748
- }
749
- get layerId() {
750
- return this.#layerId;
727
+ // src/observable/internal/aggregation/AggregationQuery.ts
728
+ var AggregationQuery = class extends Query {
729
+ constructor(store, subject, cacheKey, opts) {
730
+ super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkDZE6IAUU_cjs.additionalContext].logger?.child({}, {
731
+ msgPrefix: `AggregationQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
732
+ }) : void 0);
733
+ this.apiName = cacheKey.otherKeys[API_NAME_IDX];
734
+ this.canonicalWhere = cacheKey.otherKeys[WHERE_IDX];
735
+ this.rdpConfig = cacheKey.otherKeys[RDP_IDX];
736
+ this.canonicalAggregate = cacheKey.otherKeys[AGGREGATE_IDX];
751
737
  }
752
- addLayer(layerId) {
753
- return new _Layer(this, layerId);
738
+ _createConnectable(subject) {
739
+ return rxjs.connectable(subject.pipe(rxjs.map((x) => {
740
+ return {
741
+ status: x.status,
742
+ result: x.value,
743
+ lastUpdated: x.lastUpdated,
744
+ error: x.status === "error" ? new Error("Aggregation failed") : void 0
745
+ };
746
+ })), {
747
+ connector: () => new rxjs.BehaviorSubject({
748
+ status: "init",
749
+ result: void 0,
750
+ lastUpdated: 0
751
+ })
752
+ });
754
753
  }
755
- removeLayer(layerId) {
756
- if (layerId == null || this.#parent == null) {
757
- return this;
758
- }
759
- if (this.#layerId !== layerId) {
760
- this.#parent = this.#parent.removeLayer(layerId);
761
- return this;
754
+ async _fetchAndStore() {
755
+ if (process.env.NODE_ENV !== "production") {
756
+ this.logger?.child({
757
+ methodName: "_fetchAndStore"
758
+ }).debug("calling _fetchAndStore");
759
+ }
760
+ try {
761
+ const result = await this._fetchAggregation();
762
+ this.store.batch({}, (batch) => {
763
+ this.writeToStore(result, "loaded", batch);
764
+ });
765
+ } catch (err) {
766
+ this.store.batch({}, (batch) => {
767
+ this.writeToStore(void 0, "error", batch);
768
+ });
762
769
  }
763
- return this.#parent.removeLayer(layerId);
764
770
  }
765
- entries() {
766
- return this.#cache.entries();
771
+ writeToStore(data, status, batch) {
772
+ batch.write(this.cacheKey, data, status);
773
+ batch.changes.modified.add(this.cacheKey);
774
+ return batch.read(this.cacheKey);
767
775
  }
768
- keys() {
769
- return this.#cache.keys();
776
+ invalidateObjectType = (objectType, changes) => {
777
+ if (this.apiName === objectType) {
778
+ changes?.modified.add(this.cacheKey);
779
+ return this.revalidate(true);
780
+ }
781
+ return Promise.resolve();
782
+ };
783
+ };
784
+
785
+ // src/observable/internal/aggregation/ObjectAggregationQuery.ts
786
+ var ObjectAggregationQuery = class extends AggregationQuery {
787
+ async _fetchAggregation() {
788
+ const type = this.cacheKey.otherKeys[API_NAME_IDX];
789
+ let objectSet = this.store.client({
790
+ type: "object",
791
+ apiName: type
792
+ });
793
+ if (this.rdpConfig) {
794
+ objectSet = objectSet.withProperties(this.rdpConfig);
795
+ }
796
+ objectSet = objectSet.where(this.canonicalWhere);
797
+ return await objectSet.aggregate(this.canonicalAggregate);
770
798
  }
771
- get(cacheKey) {
772
- return this.#cache.get(cacheKey) ?? this.#parent?.get(cacheKey);
799
+ };
800
+
801
+ // src/observable/internal/aggregation/AggregationsHelper.ts
802
+ var AggregationsHelper = class extends AbstractHelper {
803
+ constructor(store, cacheKeys, whereCanonicalizer2, rdpCanonicalizer) {
804
+ super(store, cacheKeys);
805
+ this.whereCanonicalizer = whereCanonicalizer2;
806
+ this.rdpCanonicalizer = rdpCanonicalizer;
773
807
  }
774
- set(cacheKey, value) {
775
- this.#cache.set(cacheKey, value);
808
+ observe(options, subFn) {
809
+ return super.observe(options, subFn);
776
810
  }
777
- };
778
- var Subjects = class {
779
- #layers;
780
- // we can use a regular Map here because the refCounting will
781
- // handle cleanup.
782
- #cacheKeyToSubject = /* @__PURE__ */ new WeakMap();
783
- constructor({
784
- logger,
785
- layers
786
- }) {
787
- this.logger = logger;
788
- this.#layers = layers;
811
+ getQuery(options) {
812
+ const {
813
+ type,
814
+ where,
815
+ withProperties,
816
+ aggregate
817
+ } = options;
818
+ const {
819
+ apiName
820
+ } = type;
821
+ const typeKind = "type" in type ? type.type : "interface";
822
+ const canonWhere = this.whereCanonicalizer.canonicalize(where ?? {});
823
+ const canonRdp = withProperties ? this.rdpCanonicalizer.canonicalize(withProperties) : void 0;
824
+ const canonAggregate = this.canonicalizeAggregate(aggregate);
825
+ const aggregationCacheKey = this.cacheKeys.get("aggregation", typeKind, apiName, canonWhere, canonRdp, canonAggregate);
826
+ return this.store.queries.get(aggregationCacheKey, () => {
827
+ if (typeKind !== "object") {
828
+ throw new Error("Only ObjectTypeDefinition is currently supported for aggregations");
829
+ }
830
+ return new ObjectAggregationQuery(this.store, this.store.subjects.get(aggregationCacheKey), aggregationCacheKey, options);
831
+ });
832
+ }
833
+ canonicalizeAggregate(aggregate) {
834
+ return JSON.parse(JSON.stringify(aggregate));
789
835
  }
790
- peek = (cacheKey) => {
791
- return this.#cacheKeyToSubject.get(cacheKey);
792
- };
793
- get = (cacheKey) => {
794
- let subject = this.#cacheKeyToSubject.get(cacheKey);
795
- if (!subject) {
796
- const initialValue = this.#layers.top.get(cacheKey) ?? createInitEntry(cacheKey);
797
- subject = new rxjs.BehaviorSubject({
798
- ...initialValue,
799
- isOptimistic: initialValue.value !== this.#layers.truth.get(cacheKey)?.value
800
- });
801
- this.#cacheKeyToSubject.set(cacheKey, subject);
802
- }
803
- return subject;
804
- };
805
- delete = (cacheKey) => {
806
- const subject = this.peek(cacheKey);
807
- if (subject) {
808
- subject.complete();
809
- this.#cacheKeyToSubject.delete(cacheKey);
810
- }
811
- };
812
836
  };
813
837
 
814
- // src/observable/internal/tombstone.ts
815
- var tombstone = void 0;
838
+ // src/observable/internal/CacheKey.ts
839
+ chunk6SCDLAU2_cjs.init_cjs_shims();
840
+ function DEBUG_ONLY__cacheKeyToString(x) {
841
+ if (process.env.NODE_ENV !== "production") {
842
+ return `${x.type}CacheKey<${x.otherKeys.map((xx) => JSON.stringify(xx)).join(", ")}>`.replaceAll('"', "'");
843
+ } else {
844
+ throw new Error("not implemented");
845
+ }
846
+ }
847
+ function DEBUG_ONLY__cacheKeysToString(x) {
848
+ if (process.env.NODE_ENV !== "production") {
849
+ return "\n - " + x.map(DEBUG_ONLY__cacheKeyToString).join("\n - ");
850
+ } else {
851
+ throw new Error("not implemented");
852
+ }
853
+ }
816
854
 
817
- // src/observable/internal/Layers.ts
818
- var Layers = class {
819
- #truthLayer = new Layer(void 0, void 0);
820
- #topLayer;
821
- #onRevalidate;
822
- constructor({
823
- logger,
824
- onRevalidate
825
- }) {
826
- this.logger = logger;
827
- this.#topLayer = this.#truthLayer;
828
- this.subjects = new Subjects({
829
- logger,
830
- layers: this
831
- });
832
- this.#onRevalidate = onRevalidate;
855
+ // src/observable/internal/CacheKeys.ts
856
+ chunk6SCDLAU2_cjs.init_cjs_shims();
857
+
858
+ // src/observable/internal/RefCounts.ts
859
+ chunk6SCDLAU2_cjs.init_cjs_shims();
860
+ var RefCounts = class {
861
+ refCounts = /* @__PURE__ */ new Map();
862
+ // keeps our objects around for some extended duration after they are no longer
863
+ // needed which is good for quick clicks across tabs.
864
+ gcMap = /* @__PURE__ */ new Map();
865
+ constructor(keepAlive, cleanup) {
866
+ this.keepAlive = keepAlive;
867
+ this.cleanup = cleanup;
833
868
  }
834
- get top() {
835
- return this.#topLayer;
869
+ register(key) {
870
+ if (!this.refCounts.has(key)) {
871
+ this.gcMap.set(key, Date.now() + this.keepAlive);
872
+ }
873
+ return key;
836
874
  }
837
- get truth() {
838
- return this.#truthLayer;
875
+ retain(key) {
876
+ const count = this.refCounts.get(key) ?? 0;
877
+ this.refCounts.set(key, count + 1);
878
+ if (this.gcMap.has(key)) {
879
+ this.gcMap.delete(key);
880
+ }
839
881
  }
840
- remove(layerId) {
841
- !(layerId != null) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, "undefined is the reserved layerId for the truth layer") : invariant4__default.default(false) : void 0;
842
- let currentLayer = this.#topLayer;
843
- const cacheKeys = /* @__PURE__ */ new Map();
844
- while (currentLayer != null && currentLayer.parentLayer != null) {
845
- if (currentLayer.layerId === layerId) {
846
- for (const [k, v] of currentLayer.entries()) {
847
- if (cacheKeys.has(k)) continue;
848
- cacheKeys.set(k, v);
849
- }
850
- }
851
- currentLayer = currentLayer.parentLayer;
882
+ release(key) {
883
+ const count = this.refCounts.get(key);
884
+ if (count === void 0) ; else if (count === 1) {
885
+ this.refCounts.delete(key);
886
+ this.gcMap.set(key, Date.now() + this.keepAlive);
887
+ } else {
888
+ this.refCounts.set(key, count - 1);
852
889
  }
853
- this.#topLayer = this.#topLayer.removeLayer(layerId);
854
- for (const [k, oldEntry] of cacheKeys) {
855
- const currentEntry = this.#topLayer.get(k);
856
- if (oldEntry !== currentEntry) {
857
- const newEntry = currentEntry ?? createInitEntry(k);
858
- this.subjects.peek(k)?.next({
859
- ...newEntry,
860
- isOptimistic: currentEntry?.value !== this.#truthLayer.get(k)?.value
861
- });
890
+ }
891
+ has(key) {
892
+ return this.refCounts.has(key);
893
+ }
894
+ gc() {
895
+ const now = Date.now();
896
+ for (const [key, deathTime] of this.gcMap) {
897
+ if (deathTime < now) {
898
+ this.gcMap.delete(key);
899
+ this.cleanup(key);
862
900
  }
863
901
  }
864
902
  }
865
- batch({
866
- optimisticId,
867
- changes
868
- }, batchFn) {
869
- !(optimisticId === void 0 || !!optimisticId) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, "optimistic must be undefined or not falsy") : invariant4__default.default(false) : void 0;
870
- const batchContext = this.#createBatchContext({
871
- optimisticId,
872
- changes
873
- });
874
- const retVal = batchFn(batchContext);
875
- this.#onRevalidate(changes, optimisticId).catch((e) => {
876
- if (this.logger) {
877
- this.logger.error("Unhandled error in batch", e);
878
- } else {
879
- console.error("Unhandled error in batch", e);
880
- throw e;
881
- }
882
- });
883
- return {
884
- batchResult: batchContext,
885
- retVal,
886
- changes: batchContext.changes
903
+ };
904
+
905
+ // src/observable/internal/CacheKeys.ts
906
+ var CacheKeys = class {
907
+ #cacheKeys = new trie.Trie(false, (keys) => {
908
+ const cacheKey = {
909
+ type: keys[0],
910
+ otherKeys: keys.slice(1)
887
911
  };
888
- }
889
- #createBatchContext({
890
- optimisticId,
891
- changes
912
+ this.#onCreate?.(cacheKey);
913
+ return cacheKey;
914
+ });
915
+ #refCounts = new RefCounts(6e4, (k) => this.#cleanupCacheKey(k));
916
+ // we are currently only using this for debug logging and should just remove it in the future if that
917
+ // continues to be true
918
+ #finalizationRegistry;
919
+ #onCreate;
920
+ #onDestroy;
921
+ constructor({
922
+ onCreate,
923
+ onDestroy
892
924
  }) {
893
- let needsLayer = optimisticId !== void 0;
894
- const batchContext = {
895
- changes,
896
- createLayerIfNeeded: () => {
897
- if (needsLayer) {
898
- this.#topLayer = this.#topLayer.addLayer(optimisticId);
899
- needsLayer = false;
900
- }
901
- },
902
- optimisticWrite: !!optimisticId,
903
- write: (cacheKey, value, status) => {
904
- const oldTopValue = this.#topLayer.get(cacheKey);
905
- if (optimisticId) batchContext.createLayerIfNeeded();
906
- const writeLayer = optimisticId ? this.#topLayer : this.#truthLayer;
907
- const newValue = {
908
- cacheKey,
909
- value,
910
- lastUpdated: Date.now(),
911
- status
912
- };
913
- writeLayer.set(cacheKey, newValue);
914
- const newTopValue = this.#topLayer.get(cacheKey);
915
- if (oldTopValue !== newTopValue) {
916
- this.subjects.get(cacheKey)?.next({
917
- ...newValue,
918
- isOptimistic: newTopValue?.value !== this.#truthLayer.get(cacheKey)?.value
919
- });
920
- }
921
- return newValue;
922
- },
923
- delete: (cacheKey, status) => {
924
- return batchContext.write(cacheKey, tombstone, status);
925
- },
926
- read: (cacheKey) => {
927
- return optimisticId ? this.#topLayer.get(cacheKey) : this.#truthLayer.get(cacheKey);
925
+ this.#onCreate = onCreate;
926
+ this.#onDestroy = onDestroy;
927
+ setInterval(() => {
928
+ this.#refCounts.gc();
929
+ }, 1e3);
930
+ this.#finalizationRegistry = new FinalizationRegistry((cleanupCallback) => {
931
+ try {
932
+ cleanupCallback();
933
+ } catch (e) {
934
+ console.error("Caught an error while running a finalization callback", e);
928
935
  }
929
- };
930
- return batchContext;
936
+ });
931
937
  }
938
+ get(type, ...args) {
939
+ const normalizedArgs = [...args];
940
+ while (normalizedArgs.length > 0 && normalizedArgs[normalizedArgs.length - 1] === void 0) {
941
+ normalizedArgs.pop();
942
+ }
943
+ const cacheKeyArgs = [type, ...normalizedArgs];
944
+ if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) ;
945
+ const cacheKey = this.#cacheKeys.lookupArray(cacheKeyArgs);
946
+ this.#refCounts.register(cacheKey);
947
+ return cacheKey;
948
+ }
949
+ retain(cacheKey) {
950
+ this.#refCounts.retain(cacheKey);
951
+ }
952
+ release(cacheKey) {
953
+ this.#refCounts.release(cacheKey);
954
+ }
955
+ #remove(cacheKey) {
956
+ this.#cacheKeys.remove(cacheKey.type, ...cacheKey.otherKeys);
957
+ }
958
+ /**
959
+ * Called after a key is no longer retained and the timeout has elapsed
960
+ * @param key
961
+ */
962
+ #cleanupCacheKey = (key) => {
963
+ this.#onDestroy?.(key);
964
+ this.#remove(key);
965
+ };
932
966
  };
933
967
 
934
- // src/observable/internal/QuerySubscription.ts
935
- var subscriptionIdCounter = 0;
936
- var QuerySubscription = class extends UnsubscribableWrapper {
937
- /** @internal */
938
- /** @internal */
939
- /** @internal */
940
- constructor(query, subscription) {
941
- super(subscription);
942
- this.query = query;
943
- this.subscription = subscription;
944
- this.subscriptionId = `sub_${++subscriptionIdCounter}`;
945
- Object.defineProperties(this, {
946
- query: {
947
- enumerable: false
948
- },
949
- subscription: {
950
- enumerable: false
951
- },
952
- subscriptionId: {
953
- enumerable: false
954
- }
955
- });
968
+ // src/observable/internal/Changes.ts
969
+ chunk6SCDLAU2_cjs.init_cjs_shims();
970
+ var Changes = class {
971
+ modifiedObjects = new mnemonist.MultiMap();
972
+ addedObjects = new mnemonist.MultiMap();
973
+ added = /* @__PURE__ */ new Set();
974
+ modified = /* @__PURE__ */ new Set();
975
+ deleted = /* @__PURE__ */ new Set();
976
+ registerObject = (cacheKey, data, isNew) => {
977
+ this[isNew ? "addedObjects" : "modifiedObjects"].set(data.$apiName, data);
978
+ this[isNew ? "added" : "modified"].add(cacheKey);
979
+ };
980
+ deleteObject = (cacheKey) => {
981
+ this.deleted.add(cacheKey);
982
+ };
983
+ registerList = (key) => {
984
+ this.modified.add(key);
985
+ };
986
+ registerLink = (cacheKey) => {
987
+ this.modified.add(cacheKey);
988
+ };
989
+ deleteLink = (cacheKey) => {
990
+ this.deleted.add(cacheKey);
991
+ };
992
+ registerObjectSet = (key) => {
993
+ this.modified.add(key);
994
+ };
995
+ isEmpty() {
996
+ return this.modifiedObjects.size === 0 && this.addedObjects.size === 0 && this.added.size === 0 && this.modified.size === 0 && this.deleted.size === 0;
956
997
  }
957
998
  };
999
+ function createChangedObjects() {
1000
+ return new Changes();
1001
+ }
1002
+ function DEBUG_ONLY__changesToString(changes) {
1003
+ if (process.env.NODE_ENV !== "production") {
1004
+ return JSON.stringify({
1005
+ modifiedObjects: multimapHelper(changes.modifiedObjects),
1006
+ addedObjects: multimapHelper(changes.addedObjects),
1007
+ added: listHelper(changes.added),
1008
+ modified: listHelper(changes.modified)
1009
+ }, null, 2);
1010
+ } else {
1011
+ throw new Error("not implemented");
1012
+ }
1013
+ }
1014
+ function listHelper(set) {
1015
+ return Array.from(set).map(DEBUG_ONLY__cacheKeyToString);
1016
+ }
1017
+ function multimapHelper(multimap) {
1018
+ return Object.fromEntries(Array.from(multimap.associations()).map(([type, objects]) => {
1019
+ return [type, objects.map((o) => o.$primaryKey)];
1020
+ }));
1021
+ }
958
1022
 
959
- // src/observable/internal/AbstractHelper.ts
960
- var AbstractHelper = class {
961
- constructor(store, cacheKeys) {
962
- this.store = store;
963
- this.cacheKeys = cacheKeys;
1023
+ // src/observable/internal/IntersectCanonicalizer.ts
1024
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1025
+
1026
+ // src/observable/internal/Canonicalizer.ts
1027
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1028
+ var CachingCanonicalizer = class {
1029
+ /**
1030
+ * Cache for input object identity.
1031
+ */
1032
+ inputCache = /* @__PURE__ */ new WeakMap();
1033
+ /**
1034
+ * Look up or create a canonical form for the given input.
1035
+ * This method handles the structural deduplication logic.
1036
+ *
1037
+ * @param input The input to canonicalize
1038
+ * @returns The canonical form
1039
+ */
1040
+ canonicalize(input) {
1041
+ if (!input) {
1042
+ return void 0;
1043
+ }
1044
+ if (this.inputCache.has(input)) {
1045
+ return this.inputCache.get(input);
1046
+ }
1047
+ const canonical = this.lookupOrCreate(input);
1048
+ this.inputCache.set(input, canonical);
1049
+ return canonical;
964
1050
  }
965
- observe(options, subFn) {
966
- const query = this.getQuery(options);
967
- return this._subscribe(query, options, subFn);
1051
+ };
1052
+
1053
+ // src/observable/internal/IntersectCanonicalizer.ts
1054
+ var IntersectCanonicalizer = class extends CachingCanonicalizer {
1055
+ structuralCache = /* @__PURE__ */ new Map();
1056
+ constructor(whereCanonicalizer2) {
1057
+ super();
1058
+ this.whereCanonicalizer = whereCanonicalizer2;
968
1059
  }
969
- _subscribe(query, options, subFn) {
970
- this.store.cacheKeys.retain(query.cacheKey);
971
- if (options.mode !== "offline") {
972
- query.revalidate(options.mode === "force").catch((e) => {
973
- subFn.error(e);
974
- if (this.store.logger) {
975
- this.store.logger.error("Unhandled error in observeObject", e);
976
- } else {
977
- throw e;
978
- }
979
- });
1060
+ lookupOrCreate(intersectWith) {
1061
+ const canonicalClauses = intersectWith.map((item) => this.whereCanonicalizer.canonicalize(item.where ?? {}));
1062
+ const structuralKey = canonicalClauses.map((clause) => JSON.stringify(clause)).join("||");
1063
+ let canonical = this.structuralCache.get(structuralKey);
1064
+ if (!canonical) {
1065
+ canonical = canonicalClauses;
1066
+ this.structuralCache.set(structuralKey, canonical);
980
1067
  }
981
- const sub = query.subscribe(subFn);
982
- const querySub = new QuerySubscription(query, sub);
983
- query.registerSubscriptionDedupeInterval(querySub.subscriptionId, options.dedupeInterval);
984
- sub.add(() => {
985
- query.unregisterSubscriptionDedupeInterval(querySub.subscriptionId);
986
- this.store.cacheKeys.release(query.cacheKey);
987
- });
988
- return querySub;
1068
+ return canonical;
989
1069
  }
990
1070
  };
991
1071
 
992
- // src/observable/internal/isObjectInstance.ts
993
- function isObjectInstance(item) {
994
- return item != null && typeof item === "object" && "$primaryKey" in item;
1072
+ // src/observable/internal/Layers.ts
1073
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1074
+
1075
+ // src/observable/internal/createInitEntry.ts
1076
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1077
+ function createInitEntry(cacheKey) {
1078
+ return {
1079
+ cacheKey,
1080
+ status: "init",
1081
+ value: void 0,
1082
+ lastUpdated: 0
1083
+ };
995
1084
  }
996
1085
 
997
- // src/observable/internal/list/ListCacheKey.ts
998
- var API_NAME_IDX = 1;
999
- var WHERE_IDX = 2;
1000
- var ORDER_BY_IDX = 3;
1001
- var RDP_IDX = 4;
1086
+ // src/observable/internal/Layer.ts
1087
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1002
1088
 
1003
- // src/observable/internal/Query.ts
1004
- var Query = class {
1005
- retainCount = 0;
1006
- #connectable;
1007
- #subscription;
1008
- #subject;
1009
- #subscriptionDedupeIntervals = /* @__PURE__ */ new Map();
1010
- /** @internal */
1011
- constructor(store, observable, opts, cacheKey, logger) {
1012
- this.options = opts;
1013
- this.cacheKey = cacheKey;
1014
- this.store = store;
1015
- this.cacheKeys = store.cacheKeys;
1016
- this.#subject = observable;
1017
- this.logger = logger ?? (process.env.NODE_ENV === "production" ? store.client[chunk3LMKH6RS_cjs.additionalContext].logger : store.client[chunk3LMKH6RS_cjs.additionalContext].logger?.child({}, {
1018
- msgPrefix: process.env.NODE_ENV !== "production" ? `Query<${cacheKey.type}, ${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>` : "Query"
1019
- }));
1020
- }
1021
- subscribe(observer) {
1022
- this.#connectable ??= this._createConnectable(this.#subject);
1023
- this.#subscription = this.#connectable.connect();
1024
- const sub = this.#connectable.subscribe({
1025
- next: (value) => {
1026
- if (observer.next) {
1027
- observer.next(value);
1028
- }
1029
- },
1030
- error: (err) => {
1031
- if (observer.error) {
1032
- observer.error(err);
1033
- }
1034
- },
1035
- complete: () => {
1036
- if (observer.complete) {
1037
- observer.complete();
1089
+ // src/observable/internal/WeakMapWithEntries.ts
1090
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1091
+ var WeakMapWithEntries = class {
1092
+ #map = /* @__PURE__ */ new WeakMap();
1093
+ #list = [];
1094
+ #toClean = [];
1095
+ #needsCleaning = false;
1096
+ #registry = new FinalizationRegistry(() => {
1097
+ this.#toClean.push(new WeakRef({}));
1098
+ this.#needsCleaning = true;
1099
+ });
1100
+ constructor() {
1101
+ const weakThis = new WeakRef(this);
1102
+ const intervalId = setInterval(() => {
1103
+ const self = weakThis.deref();
1104
+ if (self) {
1105
+ if (this.#needsCleaning) {
1106
+ this.#clean();
1038
1107
  }
1108
+ } else {
1109
+ clearInterval(intervalId);
1039
1110
  }
1040
- });
1041
- return sub;
1111
+ }, 1e3);
1112
+ }
1113
+ #clean() {
1114
+ this.#list = this.#list.filter((ref) => ref.deref() !== void 0);
1115
+ }
1116
+ // functions for WeakMap
1117
+ delete(key) {
1118
+ const ret = this.#map.delete(key);
1119
+ this.#toClean.push(new WeakRef(key));
1120
+ this.#needsCleaning = true;
1121
+ return ret;
1122
+ }
1123
+ get(key) {
1124
+ return this.#map.get(key);
1125
+ }
1126
+ has(key) {
1127
+ return this.#map.has(key);
1042
1128
  }
1043
1129
  /**
1044
- * Register a subscription's dedupeInterval value
1130
+ * Adds a new element with a specified key and value.
1131
+ * @param key Must be an object or symbol.
1045
1132
  */
1046
- registerSubscriptionDedupeInterval(subscriptionId, dedupeInterval) {
1047
- if (dedupeInterval != null && dedupeInterval > 0) {
1048
- this.#subscriptionDedupeIntervals.set(subscriptionId, dedupeInterval);
1133
+ set(key, value) {
1134
+ if (!this.#map.has(key)) {
1135
+ this.#list.push(new WeakRef(key));
1049
1136
  }
1137
+ this.#map.set(key, value);
1138
+ return this;
1139
+ }
1140
+ [Symbol.toStringTag] = "WeakMap";
1141
+ // functions for iterables
1142
+ /** Returns an iterable of entries in the map. */
1143
+ [Symbol.iterator]() {
1144
+ return this.entries();
1050
1145
  }
1051
1146
  /**
1052
- * Unregister a subscription's dedupeInterval value
1147
+ * Returns an iterable of key, value pairs for every entry in the map.
1053
1148
  */
1054
- unregisterSubscriptionDedupeInterval(subscriptionId) {
1055
- this.#subscriptionDedupeIntervals.delete(subscriptionId);
1149
+ entries() {
1150
+ const self = this;
1151
+ function* iter() {
1152
+ for (const ref of self.#list) {
1153
+ const key = ref.deref();
1154
+ if (key !== void 0) {
1155
+ yield [key, self.#map.get(key)];
1156
+ }
1157
+ }
1158
+ }
1159
+ return iter();
1056
1160
  }
1057
1161
  /**
1058
- * Get the minimum dedupeInterval from all active subscriptions
1162
+ * Returns an iterable of keys in the map
1059
1163
  */
1060
- getMinimumDedupeInterval() {
1061
- if (this.#subscriptionDedupeIntervals.size === 0) {
1062
- return this.options.dedupeInterval ?? 0;
1164
+ keys() {
1165
+ const self = this;
1166
+ function* iter() {
1167
+ for (const ref of self.#list) {
1168
+ const key = ref.deref();
1169
+ if (key !== void 0) {
1170
+ yield key;
1171
+ }
1172
+ }
1063
1173
  }
1064
- return Math.min(...this.#subscriptionDedupeIntervals.values());
1174
+ return iter();
1065
1175
  }
1066
1176
  /**
1067
- * Causes the query to revalidate. This will cause the query to fetch
1068
- * the latest data from the server and update the store if it is deemed
1069
- * "stale" or if `force` is true.
1070
- *
1071
- * @param force
1072
- * @returns
1177
+ * Returns an iterable of values in the map
1073
1178
  */
1074
- async revalidate(force) {
1075
- const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
1076
- methodName: "revalidate"
1077
- }) : this.logger;
1078
- if (force) {
1079
- this.abortController?.abort();
1080
- }
1081
- if (this.pendingFetch) {
1082
- if (process.env.NODE_ENV !== "production") {
1083
- logger?.debug("Fetch is already pending, using it");
1179
+ values() {
1180
+ const self = this;
1181
+ function* iter() {
1182
+ for (const ref of self.#list) {
1183
+ const key = ref.deref();
1184
+ if (key !== void 0) {
1185
+ const value = self.#map.get(key);
1186
+ if (value !== void 0) {
1187
+ yield value;
1188
+ }
1189
+ }
1084
1190
  }
1085
- await this.pendingFetch;
1086
- return;
1087
1191
  }
1088
- const minDedupeInterval = this.getMinimumDedupeInterval();
1089
- if (minDedupeInterval > 0 && this.lastFetchStarted != null && Date.now() - this.lastFetchStarted < minDedupeInterval) {
1090
- if (process.env.NODE_ENV !== "production") {
1091
- logger?.debug("Within dupeInterval, aborting revalidate");
1092
- }
1093
- return Promise.resolve();
1192
+ return iter();
1193
+ }
1194
+ };
1195
+
1196
+ // src/observable/internal/Layer.ts
1197
+ var Layer = class _Layer {
1198
+ #parent;
1199
+ #cache = new WeakMapWithEntries();
1200
+ #layerId;
1201
+ constructor(parent, layerId) {
1202
+ this.#parent = parent;
1203
+ this.#layerId = layerId;
1204
+ }
1205
+ get parentLayer() {
1206
+ return this.#parent;
1207
+ }
1208
+ get layerId() {
1209
+ return this.#layerId;
1210
+ }
1211
+ addLayer(layerId) {
1212
+ return new _Layer(this, layerId);
1213
+ }
1214
+ removeLayer(layerId) {
1215
+ if (layerId == null || this.#parent == null) {
1216
+ return this;
1094
1217
  }
1095
- if (process.env.NODE_ENV !== "production") {
1096
- logger?.debug("Starting actual revalidate");
1218
+ if (this.#layerId !== layerId) {
1219
+ this.#parent = this.#parent.removeLayer(layerId);
1220
+ return this;
1097
1221
  }
1098
- this.store.batch({}, (batch) => {
1099
- this.setStatus("loading", batch);
1100
- });
1101
- this._preFetch();
1102
- this.lastFetchStarted = Date.now();
1103
- if (process.env.NODE_ENV !== "production") {
1104
- logger?.debug("calling _fetchAndStore()");
1222
+ return this.#parent.removeLayer(layerId);
1223
+ }
1224
+ entries() {
1225
+ return this.#cache.entries();
1226
+ }
1227
+ keys() {
1228
+ return this.#cache.keys();
1229
+ }
1230
+ get(cacheKey) {
1231
+ return this.#cache.get(cacheKey) ?? this.#parent?.get(cacheKey);
1232
+ }
1233
+ set(cacheKey, value) {
1234
+ this.#cache.set(cacheKey, value);
1235
+ }
1236
+ };
1237
+
1238
+ // src/observable/internal/Subjects.ts
1239
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1240
+ var Subjects = class {
1241
+ #layers;
1242
+ // we can use a regular Map here because the refCounting will
1243
+ // handle cleanup.
1244
+ #cacheKeyToSubject = /* @__PURE__ */ new WeakMap();
1245
+ constructor({
1246
+ logger,
1247
+ layers
1248
+ }) {
1249
+ this.logger = logger;
1250
+ this.#layers = layers;
1251
+ }
1252
+ peek = (cacheKey) => {
1253
+ return this.#cacheKeyToSubject.get(cacheKey);
1254
+ };
1255
+ get = (cacheKey) => {
1256
+ let subject = this.#cacheKeyToSubject.get(cacheKey);
1257
+ if (!subject) {
1258
+ const initialValue = this.#layers.top.get(cacheKey) ?? createInitEntry(cacheKey);
1259
+ subject = new rxjs.BehaviorSubject({
1260
+ ...initialValue,
1261
+ isOptimistic: initialValue.value !== this.#layers.truth.get(cacheKey)?.value
1262
+ });
1263
+ this.#cacheKeyToSubject.set(cacheKey, subject);
1264
+ }
1265
+ return subject;
1266
+ };
1267
+ delete = (cacheKey) => {
1268
+ const subject = this.peek(cacheKey);
1269
+ if (subject) {
1270
+ subject.complete();
1271
+ this.#cacheKeyToSubject.delete(cacheKey);
1105
1272
  }
1106
- this.pendingFetch = this._fetchAndStore().finally(() => {
1107
- logger?.debug("promise's finally for _fetchAndStore()");
1108
- this.pendingFetch = void 0;
1273
+ };
1274
+ };
1275
+
1276
+ // src/observable/internal/tombstone.ts
1277
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1278
+ var tombstone = void 0;
1279
+
1280
+ // src/observable/internal/Layers.ts
1281
+ var Layers = class {
1282
+ #truthLayer = new Layer(void 0, void 0);
1283
+ #topLayer;
1284
+ #onRevalidate;
1285
+ constructor({
1286
+ logger,
1287
+ onRevalidate
1288
+ }) {
1289
+ this.logger = logger;
1290
+ this.#topLayer = this.#truthLayer;
1291
+ this.subjects = new Subjects({
1292
+ logger,
1293
+ layers: this
1109
1294
  });
1110
- await this.pendingFetch;
1111
- return;
1295
+ this.#onRevalidate = onRevalidate;
1112
1296
  }
1113
- _preFetch() {
1297
+ get top() {
1298
+ return this.#topLayer;
1114
1299
  }
1115
- /**
1116
- * Sets the status of the query in the store (but does not store that in `changes`).
1117
- *
1118
- * @param status
1119
- * @param batch
1120
- * @returns
1121
- */
1122
- setStatus(status, batch) {
1123
- if (process.env.NODE_ENV !== "production") {
1124
- this.logger?.child({
1125
- methodName: "setStatus"
1126
- }).debug(`Attempting to set status to '${status}'`);
1127
- }
1128
- const existing = batch.read(this.cacheKey);
1129
- if (existing?.status === status) {
1130
- if (process.env.NODE_ENV !== "production") {
1131
- this.logger?.child({
1132
- methodName: "setStatus"
1133
- }).debug(`Status is already set to '${status}'; aborting`);
1300
+ get truth() {
1301
+ return this.#truthLayer;
1302
+ }
1303
+ remove(layerId) {
1304
+ !(layerId != null) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, "undefined is the reserved layerId for the truth layer") : invariant4__default.default(false) : void 0;
1305
+ let currentLayer = this.#topLayer;
1306
+ const cacheKeys = /* @__PURE__ */ new Map();
1307
+ while (currentLayer != null && currentLayer.parentLayer != null) {
1308
+ if (currentLayer.layerId === layerId) {
1309
+ for (const [k, v] of currentLayer.entries()) {
1310
+ if (cacheKeys.has(k)) continue;
1311
+ cacheKeys.set(k, v);
1312
+ }
1134
1313
  }
1135
- return;
1314
+ currentLayer = currentLayer.parentLayer;
1136
1315
  }
1137
- if (process.env.NODE_ENV !== "production") {
1138
- this.logger?.child({
1139
- methodName: "setStatus"
1140
- }).debug(`Writing status '${status}' to cache`);
1316
+ this.#topLayer = this.#topLayer.removeLayer(layerId);
1317
+ for (const [k, oldEntry] of cacheKeys) {
1318
+ const currentEntry = this.#topLayer.get(k);
1319
+ if (oldEntry !== currentEntry) {
1320
+ const newEntry = currentEntry ?? createInitEntry(k);
1321
+ this.subjects.peek(k)?.next({
1322
+ ...newEntry,
1323
+ isOptimistic: currentEntry?.value !== this.#truthLayer.get(k)?.value
1324
+ });
1325
+ }
1141
1326
  }
1142
- batch.write(this.cacheKey, existing?.value, status);
1143
1327
  }
1144
- dispose() {
1145
- if (this.abortController) {
1146
- this.abortController.abort();
1147
- }
1148
- this.#subscription?.unsubscribe();
1149
- this._dispose();
1328
+ batch({
1329
+ optimisticId,
1330
+ changes
1331
+ }, batchFn) {
1332
+ !(optimisticId === void 0 || !!optimisticId) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, "optimistic must be undefined or not falsy") : invariant4__default.default(false) : void 0;
1333
+ const batchContext = this.#createBatchContext({
1334
+ optimisticId,
1335
+ changes
1336
+ });
1337
+ const retVal = batchFn(batchContext);
1338
+ this.#onRevalidate(changes, optimisticId).catch((e) => {
1339
+ if (this.logger) {
1340
+ this.logger.error("Unhandled error in batch", e);
1341
+ } else {
1342
+ console.error("Unhandled error in batch", e);
1343
+ throw e;
1344
+ }
1345
+ });
1346
+ return {
1347
+ batchResult: batchContext,
1348
+ retVal,
1349
+ changes: batchContext.changes
1350
+ };
1150
1351
  }
1151
- /**
1152
- * Per query type dispose functionality
1153
- */
1154
- _dispose() {
1352
+ #createBatchContext({
1353
+ optimisticId,
1354
+ changes
1355
+ }) {
1356
+ let needsLayer = optimisticId !== void 0;
1357
+ const batchContext = {
1358
+ changes,
1359
+ createLayerIfNeeded: () => {
1360
+ if (needsLayer) {
1361
+ this.#topLayer = this.#topLayer.addLayer(optimisticId);
1362
+ needsLayer = false;
1363
+ }
1364
+ },
1365
+ optimisticWrite: !!optimisticId,
1366
+ write: (cacheKey, value, status) => {
1367
+ const oldTopValue = this.#topLayer.get(cacheKey);
1368
+ if (optimisticId) batchContext.createLayerIfNeeded();
1369
+ const writeLayer = optimisticId ? this.#topLayer : this.#truthLayer;
1370
+ const newValue = {
1371
+ cacheKey,
1372
+ value,
1373
+ lastUpdated: Date.now(),
1374
+ status
1375
+ };
1376
+ writeLayer.set(cacheKey, newValue);
1377
+ const newTopValue = this.#topLayer.get(cacheKey);
1378
+ if (oldTopValue !== newTopValue) {
1379
+ this.subjects.get(cacheKey)?.next({
1380
+ ...newValue,
1381
+ isOptimistic: newTopValue?.value !== this.#truthLayer.get(cacheKey)?.value
1382
+ });
1383
+ }
1384
+ return newValue;
1385
+ },
1386
+ delete: (cacheKey, status) => {
1387
+ return batchContext.write(cacheKey, tombstone, status);
1388
+ },
1389
+ read: (cacheKey) => {
1390
+ return optimisticId ? this.#topLayer.get(cacheKey) : this.#truthLayer.get(cacheKey);
1391
+ }
1392
+ };
1393
+ return batchContext;
1155
1394
  }
1156
- /**
1157
- * The purpose of this method is to provide a way for others to write
1158
- * directly into the store for this query.
1159
- *
1160
- * @param data
1161
- * @param status
1162
- * @param batch
1163
- */
1164
- /**
1165
- * @param changes
1166
- * @param optimisticId
1167
- * @returns If revalidation is needed, a promise that resolves after the
1168
- * revalidation is complete. Otherwise, undefined.
1169
- */
1170
1395
  };
1171
1396
 
1397
+ // src/observable/internal/links/LinksHelper.ts
1398
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1399
+
1400
+ // src/observable/internal/links/SpecificLinkQuery.ts
1401
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1402
+
1403
+ // src/observable/internal/base-list/BaseListQuery.ts
1404
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1405
+
1406
+ // src/observable/internal/isObjectInstance.ts
1407
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1408
+ function isObjectInstance(item) {
1409
+ return item != null && typeof item === "object" && "$primaryKey" in item;
1410
+ }
1411
+
1412
+ // src/observable/internal/list/ListCacheKey.ts
1413
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1414
+ var API_NAME_IDX2 = 1;
1415
+ var WHERE_IDX2 = 2;
1416
+ var ORDER_BY_IDX = 3;
1417
+ var RDP_IDX2 = 4;
1418
+ var INTERSECT_IDX = 5;
1419
+ var PIVOT_IDX = 6;
1420
+
1172
1421
  // src/observable/internal/sorting/SortingStrategy.ts
1422
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1173
1423
  var NoOpSortingStrategy = class {
1174
1424
  sortCacheKeys(objectCacheKeys, _batch) {
1175
1425
  return objectCacheKeys;
@@ -1215,6 +1465,9 @@ function createOrderBySortFns(orderBy) {
1215
1465
  };
1216
1466
  });
1217
1467
  }
1468
+
1469
+ // src/observable/internal/base-list/createCollectionConnectable.ts
1470
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1218
1471
  function createCollectionConnectable(subject, subjects, createPayload) {
1219
1472
  return rxjs.connectable(subject.pipe(rxjs.switchMap((listEntry) => {
1220
1473
  const resolvedData = listEntry?.value?.data == null || listEntry.value.data.length === 0 ? rxjs.of([]) : rxjs.combineLatest(listEntry.value.data.map((cacheKey) => subjects.get(cacheKey).pipe(rxjs.map((objectEntry) => objectEntry?.value), rxjs.distinctUntilChanged())));
@@ -1236,6 +1489,7 @@ function createCollectionConnectable(subject, subjects, createPayload) {
1236
1489
  }
1237
1490
 
1238
1491
  // src/observable/internal/base-list/removeDuplicates.ts
1492
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1239
1493
  function removeDuplicates(objectCacheKeys, batch) {
1240
1494
  const visited = /* @__PURE__ */ new Set();
1241
1495
  return objectCacheKeys.filter((key) => {
@@ -1259,7 +1513,7 @@ var BaseListQuery = class extends Query {
1259
1513
  * Get RDP configuration from the cache key
1260
1514
  */
1261
1515
  get rdpConfig() {
1262
- return this.cacheKey.otherKeys[RDP_IDX];
1516
+ return this.cacheKey.otherKeys[RDP_IDX2];
1263
1517
  }
1264
1518
  // Collection-specific behavior is implemented by subclasses
1265
1519
  /**
@@ -1722,7 +1976,7 @@ var SpecificLinkQuery = class extends BaseListQuery {
1722
1976
  batch.changes.modified.add(this.cacheKey);
1723
1977
  }
1724
1978
  constructor(store, subject, cacheKey, opts) {
1725
- super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunk3LMKH6RS_cjs.additionalContext].logger?.child({}, {
1979
+ super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkDZE6IAUU_cjs.additionalContext].logger?.child({}, {
1726
1980
  msgPrefix: `SpecificLinkQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
1727
1981
  }) : void 0);
1728
1982
  [this.#sourceApiName, this.#sourcePk, this.#linkName, this.#whereClause, this.#orderBy] = cacheKey.otherKeys;
@@ -1739,7 +1993,7 @@ var SpecificLinkQuery = class extends BaseListQuery {
1739
1993
  type: "object",
1740
1994
  apiName: this.#sourceApiName
1741
1995
  };
1742
- const sourceMetadata = await client[chunk3LMKH6RS_cjs.additionalContext].ontologyProvider.getObjectDefinition(this.#sourceApiName);
1996
+ const sourceMetadata = await client[chunkDZE6IAUU_cjs.additionalContext].ontologyProvider.getObjectDefinition(this.#sourceApiName);
1743
1997
  const sourceQuery = client(sourceObjectDef).where({
1744
1998
  [sourceMetadata.primaryKeyApiName]: this.#sourcePk
1745
1999
  });
@@ -1803,7 +2057,7 @@ var SpecificLinkQuery = class extends BaseListQuery {
1803
2057
  return this.revalidate(true);
1804
2058
  } else {
1805
2059
  return (async () => {
1806
- const sourceMetadata = await this.store.client[chunk3LMKH6RS_cjs.additionalContext].ontologyProvider.getObjectDefinition(this.#sourceApiName);
2060
+ const sourceMetadata = await this.store.client[chunkDZE6IAUU_cjs.additionalContext].ontologyProvider.getObjectDefinition(this.#sourceApiName);
1807
2061
  const linkDef = sourceMetadata.links?.[this.#linkName];
1808
2062
  if (!linkDef || linkDef.targetType !== objectType) return;
1809
2063
  const promise = this.revalidate(true);
@@ -1821,9 +2075,6 @@ var LinksHelper = class extends AbstractHelper {
1821
2075
  this.whereCanonicalizer = whereCanonicalizer2;
1822
2076
  this.orderByCanonicalizer = orderByCanonicalizer2;
1823
2077
  }
1824
- observe(options, subFn) {
1825
- return super.observe(options, subFn);
1826
- }
1827
2078
  getQuery(options) {
1828
2079
  const {
1829
2080
  apiName
@@ -1836,6 +2087,21 @@ var LinksHelper = class extends AbstractHelper {
1836
2087
  });
1837
2088
  }
1838
2089
  };
2090
+
2091
+ // src/observable/internal/list/ListsHelper.ts
2092
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2093
+
2094
+ // src/observable/internal/list/InterfaceListQuery.ts
2095
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2096
+
2097
+ // src/observable/internal/list/ListQuery.ts
2098
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2099
+
2100
+ // src/observable/internal/objectMatchesWhereClause.ts
2101
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2102
+
2103
+ // src/observable/internal/evaluateFilter.ts
2104
+ chunk6SCDLAU2_cjs.init_cjs_shims();
1839
2105
  function evaluateFilter(f, realValue, expected, strict) {
1840
2106
  switch (f) {
1841
2107
  case "$eq":
@@ -1933,6 +2199,8 @@ var ListQuery = class extends BaseListQuery {
1933
2199
  #whereClause;
1934
2200
  // Using base class minResultsToLoad instead of a private property
1935
2201
  #orderBy;
2202
+ #intersectWith;
2203
+ #pivotInfo;
1936
2204
  #objectSet;
1937
2205
  /**
1938
2206
  * Register changes to the cache specific to ListQuery
@@ -1941,12 +2209,14 @@ var ListQuery = class extends BaseListQuery {
1941
2209
  batch.changes.registerList(this.cacheKey);
1942
2210
  }
1943
2211
  constructor(store, subject, apiName, cacheKey, opts) {
1944
- super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunk3LMKH6RS_cjs.additionalContext].logger?.child({}, {
2212
+ super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkDZE6IAUU_cjs.additionalContext].logger?.child({}, {
1945
2213
  msgPrefix: `ListQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
1946
2214
  }) : void 0);
1947
2215
  this.apiName = apiName;
1948
- this.#whereClause = cacheKey.otherKeys[WHERE_IDX];
2216
+ this.#whereClause = cacheKey.otherKeys[WHERE_IDX2];
1949
2217
  this.#orderBy = cacheKey.otherKeys[ORDER_BY_IDX];
2218
+ this.#intersectWith = cacheKey.otherKeys[INTERSECT_IDX];
2219
+ this.#pivotInfo = cacheKey.otherKeys[PIVOT_IDX];
1950
2220
  this.#objectSet = this.createObjectSet(store);
1951
2221
  this.sortingStrategy = new OrderBySortingStrategy(this.apiName, this.#orderBy);
1952
2222
  this.minResultsToLoad = 0;
@@ -1954,6 +2224,12 @@ var ListQuery = class extends BaseListQuery {
1954
2224
  get canonicalWhere() {
1955
2225
  return this.#whereClause;
1956
2226
  }
2227
+ get canonicalIntersectWith() {
2228
+ return this.#intersectWith;
2229
+ }
2230
+ get canonicalPivotInfo() {
2231
+ return this.#pivotInfo;
2232
+ }
1957
2233
  /**
1958
2234
  * Create the ObjectSet for this query.
1959
2235
  */
@@ -2179,7 +2455,7 @@ var ListQuery = class extends BaseListQuery {
2179
2455
  // src/observable/internal/list/InterfaceListQuery.ts
2180
2456
  var InterfaceListQuery = class extends ListQuery {
2181
2457
  createObjectSet(store) {
2182
- const rdpConfig = this.cacheKey.otherKeys[RDP_IDX];
2458
+ const rdpConfig = this.cacheKey.otherKeys[RDP_IDX2];
2183
2459
  const type = "interface";
2184
2460
  const objectTypeDef = {
2185
2461
  type,
@@ -2207,7 +2483,7 @@ var InterfaceListQuery = class extends ListQuery {
2207
2483
  }
2208
2484
  extractRelevantObjects(changes) {
2209
2485
  const matchesApiName = ([, object]) => {
2210
- return this.apiName in object[chunk4ZOXOCQX_cjs.ObjectDefRef].interfaceMap;
2486
+ return this.apiName in object[chunkS4JPAF56_cjs.ObjectDefRef].interfaceMap;
2211
2487
  };
2212
2488
  const added = Array.from(changes.addedObjects).filter(matchesApiName).map(([, object]) => object.$as(this.apiName));
2213
2489
  const modified = Array.from(changes.modifiedObjects).filter(matchesApiName).map(([, object]) => object.$as(this.apiName));
@@ -2228,7 +2504,7 @@ var InterfaceListQuery = class extends ListQuery {
2228
2504
  async function reloadDataAsFullObjects(client, data) {
2229
2505
  const groups = groupBy__default.default(data, (x) => x.$objectType);
2230
2506
  const objectTypeToPrimaryKeyToObject = Object.fromEntries(await Promise.all(Object.entries(groups).map(async ([apiName, objects]) => {
2231
- const objectDef = objects[0][chunk4ZOXOCQX_cjs.UnderlyingOsdkObject][chunk4ZOXOCQX_cjs.ObjectDefRef];
2507
+ const objectDef = objects[0][chunkS4JPAF56_cjs.UnderlyingOsdkObject][chunkS4JPAF56_cjs.ObjectDefRef];
2232
2508
  const where = {
2233
2509
  [objectDef.primaryKeyApiName]: {
2234
2510
  $in: objects.map((x) => x.$primaryKey)
@@ -2245,19 +2521,59 @@ async function reloadDataAsFullObjects(client, data) {
2245
2521
  }
2246
2522
 
2247
2523
  // src/observable/internal/list/ObjectListQuery.ts
2524
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2248
2525
  var ObjectListQuery = class extends ListQuery {
2249
2526
  createObjectSet(store) {
2250
- const rdpConfig = this.cacheKey.otherKeys[RDP_IDX];
2251
- if (rdpConfig != null) {
2252
- return store.client({
2527
+ const rdpConfig = this.cacheKey.otherKeys[RDP_IDX2];
2528
+ const intersectWith = this.cacheKey.otherKeys[INTERSECT_IDX];
2529
+ const pivotInfo = this.cacheKey.otherKeys[PIVOT_IDX];
2530
+ if (pivotInfo != null) {
2531
+ const sourceSet = store.client({
2253
2532
  type: "object",
2254
- apiName: this.apiName
2255
- }).withProperties(rdpConfig).where(this.canonicalWhere);
2533
+ apiName: pivotInfo.sourceType
2534
+ });
2535
+ let objectSet2 = sourceSet.pivotTo(pivotInfo.linkName);
2536
+ if (rdpConfig != null) {
2537
+ objectSet2 = objectSet2.withProperties(rdpConfig);
2538
+ }
2539
+ objectSet2 = objectSet2.where(this.canonicalWhere);
2540
+ if (intersectWith != null && intersectWith.length > 0) {
2541
+ const intersectSets = intersectWith.map((whereClause) => {
2542
+ let intersectSet = store.client({
2543
+ type: "object",
2544
+ apiName: pivotInfo.targetType
2545
+ });
2546
+ if (rdpConfig != null) {
2547
+ intersectSet = intersectSet.withProperties(rdpConfig);
2548
+ }
2549
+ return intersectSet.where(whereClause);
2550
+ });
2551
+ objectSet2 = objectSet2.intersect(...intersectSets);
2552
+ }
2553
+ return objectSet2;
2256
2554
  }
2257
- return store.client({
2555
+ let objectSet = store.client({
2258
2556
  type: "object",
2259
2557
  apiName: this.apiName
2260
- }).where(this.canonicalWhere);
2558
+ });
2559
+ if (rdpConfig != null) {
2560
+ objectSet = objectSet.withProperties(rdpConfig);
2561
+ }
2562
+ objectSet = objectSet.where(this.canonicalWhere);
2563
+ if (intersectWith != null && intersectWith.length > 0) {
2564
+ const intersectSets = intersectWith.map((whereClause) => {
2565
+ let intersectSet = store.client({
2566
+ type: "object",
2567
+ apiName: this.apiName
2568
+ });
2569
+ if (rdpConfig != null) {
2570
+ intersectSet = intersectSet.withProperties(rdpConfig);
2571
+ }
2572
+ return intersectSet.where(whereClause);
2573
+ });
2574
+ objectSet = objectSet.intersect(...intersectSets);
2575
+ }
2576
+ return objectSet;
2261
2577
  }
2262
2578
  async revalidateObjectType(apiName) {
2263
2579
  if (this.apiName === apiName) {
@@ -2273,12 +2589,12 @@ var ObjectListQuery = class extends ListQuery {
2273
2589
  extractRelevantObjects(changes) {
2274
2590
  return {
2275
2591
  added: {
2276
- all: changes.addedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
2592
+ all: changes.addedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX2]) ?? [],
2277
2593
  strictMatches: /* @__PURE__ */ new Set(),
2278
2594
  sortaMatches: /* @__PURE__ */ new Set()
2279
2595
  },
2280
2596
  modified: {
2281
- all: changes.modifiedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
2597
+ all: changes.modifiedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX2]) ?? [],
2282
2598
  strictMatches: /* @__PURE__ */ new Set(),
2283
2599
  sortaMatches: /* @__PURE__ */ new Set()
2284
2600
  }
@@ -2288,11 +2604,13 @@ var ObjectListQuery = class extends ListQuery {
2288
2604
 
2289
2605
  // src/observable/internal/list/ListsHelper.ts
2290
2606
  var ListsHelper = class extends AbstractHelper {
2291
- constructor(store, cacheKeys, whereCanonicalizer2, orderByCanonicalizer2, rdpCanonicalizer) {
2607
+ constructor(store, cacheKeys, whereCanonicalizer2, orderByCanonicalizer2, rdpCanonicalizer, intersectCanonicalizer, pivotCanonicalizer) {
2292
2608
  super(store, cacheKeys);
2293
2609
  this.whereCanonicalizer = whereCanonicalizer2;
2294
2610
  this.orderByCanonicalizer = orderByCanonicalizer2;
2295
2611
  this.rdpCanonicalizer = rdpCanonicalizer;
2612
+ this.intersectCanonicalizer = intersectCanonicalizer;
2613
+ this.pivotCanonicalizer = pivotCanonicalizer;
2296
2614
  }
2297
2615
  observe(options, subFn) {
2298
2616
  const ret = super.observe(options, subFn);
@@ -2306,7 +2624,9 @@ var ListsHelper = class extends AbstractHelper {
2306
2624
  type: typeDefinition,
2307
2625
  where,
2308
2626
  orderBy,
2309
- withProperties
2627
+ withProperties,
2628
+ intersectWith,
2629
+ pivotTo
2310
2630
  } = options;
2311
2631
  const {
2312
2632
  apiName,
@@ -2315,7 +2635,9 @@ var ListsHelper = class extends AbstractHelper {
2315
2635
  const canonWhere = this.whereCanonicalizer.canonicalize(where ?? {});
2316
2636
  const canonOrderBy = this.orderByCanonicalizer.canonicalize(orderBy ?? {});
2317
2637
  const canonRdp = withProperties ? this.rdpCanonicalizer.canonicalize(withProperties) : void 0;
2318
- const listCacheKey = this.cacheKeys.get("list", type, apiName, canonWhere, canonOrderBy, canonRdp);
2638
+ const canonIntersect = intersectWith && intersectWith.length > 0 ? this.intersectCanonicalizer.canonicalize(intersectWith) : void 0;
2639
+ const canonPivot = pivotTo ? this.pivotCanonicalizer.canonicalize(apiName, pivotTo) : void 0;
2640
+ const listCacheKey = this.cacheKeys.get("list", type, apiName, canonWhere, canonOrderBy, canonRdp, canonIntersect, canonPivot);
2319
2641
  return this.store.queries.get(listCacheKey, () => {
2320
2642
  const QueryClass = type === "object" ? ObjectListQuery : InterfaceListQuery;
2321
2643
  return new QueryClass(this.store, this.store.subjects.get(listCacheKey), apiName, listCacheKey, options);
@@ -2324,10 +2646,15 @@ var ListsHelper = class extends AbstractHelper {
2324
2646
  };
2325
2647
 
2326
2648
  // src/observable/internal/object/ObjectCacheKey.ts
2327
- var API_NAME_IDX2 = 0;
2649
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2650
+ var API_NAME_IDX3 = 0;
2328
2651
  var RDP_CONFIG_IDX = 2;
2329
2652
 
2653
+ // src/observable/internal/object/ObjectCacheKeyRegistry.ts
2654
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2655
+
2330
2656
  // src/observable/internal/utils/rdpFieldOperations.ts
2657
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2331
2658
  function extractRdpFieldNames(rdpConfig) {
2332
2659
  if (!rdpConfig) {
2333
2660
  return /* @__PURE__ */ new Set();
@@ -2494,7 +2821,17 @@ var ObjectCacheKeyRegistry = class {
2494
2821
  }
2495
2822
  };
2496
2823
 
2824
+ // src/observable/internal/object/ObjectsHelper.ts
2825
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2826
+
2827
+ // src/observable/internal/object/ObjectQuery.ts
2828
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2829
+
2830
+ // src/observable/internal/BulkObjectLoader.ts
2831
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2832
+
2497
2833
  // ../../node_modules/.pnpm/p-defer@4.0.1/node_modules/p-defer/index.js
2834
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2498
2835
  function pDefer() {
2499
2836
  const deferred = {};
2500
2837
  deferred.promise = new Promise((resolve, reject) => {
@@ -2520,7 +2857,7 @@ var BulkObjectLoader = class {
2520
2857
  #maxEntries;
2521
2858
  constructor(client, maxWait = 25, maxEntries = 100) {
2522
2859
  this.#client = client;
2523
- this.#logger = client[chunk3LMKH6RS_cjs.additionalContext].logger;
2860
+ this.#logger = client[chunkDZE6IAUU_cjs.additionalContext].logger;
2524
2861
  this.#maxWait = maxWait;
2525
2862
  this.#maxEntries = maxEntries;
2526
2863
  }
@@ -2588,7 +2925,7 @@ var ObjectQuery = class extends Query {
2588
2925
  #apiName;
2589
2926
  #pk;
2590
2927
  constructor(store, subject, type, pk, cacheKey, opts) {
2591
- super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunk3LMKH6RS_cjs.additionalContext].logger?.child({}, {
2928
+ super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkDZE6IAUU_cjs.additionalContext].logger?.child({}, {
2592
2929
  msgPrefix: `ObjectQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
2593
2930
  }) : void 0);
2594
2931
  this.#apiName = type;
@@ -2725,14 +3062,18 @@ var ObjectsHelper = class extends AbstractHelper {
2725
3062
  }
2726
3063
  };
2727
3064
 
3065
+ // src/observable/internal/objectset/ObjectSetHelper.ts
3066
+ chunk6SCDLAU2_cjs.init_cjs_shims();
3067
+
2728
3068
  // src/observable/internal/objectset/ObjectSetQuery.ts
3069
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2729
3070
  var ObjectSetQuery = class extends BaseListQuery {
2730
3071
  #baseObjectSetWire;
2731
3072
  #operations;
2732
3073
  #composedObjectSet;
2733
3074
  #objectTypes;
2734
3075
  constructor(store, subject, baseObjectSetWire, operations, cacheKey, opts) {
2735
- super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunk3LMKH6RS_cjs.additionalContext].logger?.child({}, {
3076
+ super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkDZE6IAUU_cjs.additionalContext].logger?.child({}, {
2736
3077
  msgPrefix: `ObjectSetQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
2737
3078
  }) : void 0);
2738
3079
  this.#baseObjectSetWire = baseObjectSetWire;
@@ -2775,7 +3116,7 @@ var ObjectSetQuery = class extends BaseListQuery {
2775
3116
  }
2776
3117
  if (opts.union) {
2777
3118
  for (const os of opts.union) {
2778
- const wire = chunk3LMKH6RS_cjs.getWireObjectSet(os);
3119
+ const wire = chunkDZE6IAUU_cjs.getWireObjectSet(os);
2779
3120
  if (wire.type) {
2780
3121
  types.add(wire.type);
2781
3122
  }
@@ -2783,7 +3124,7 @@ var ObjectSetQuery = class extends BaseListQuery {
2783
3124
  }
2784
3125
  if (opts.intersect) {
2785
3126
  for (const os of opts.intersect) {
2786
- const wire = chunk3LMKH6RS_cjs.getWireObjectSet(os);
3127
+ const wire = chunkDZE6IAUU_cjs.getWireObjectSet(os);
2787
3128
  if (wire.type) {
2788
3129
  types.add(wire.type);
2789
3130
  }
@@ -2791,7 +3132,7 @@ var ObjectSetQuery = class extends BaseListQuery {
2791
3132
  }
2792
3133
  if (opts.subtract) {
2793
3134
  for (const os of opts.subtract) {
2794
- const wire = chunk3LMKH6RS_cjs.getWireObjectSet(os);
3135
+ const wire = chunkDZE6IAUU_cjs.getWireObjectSet(os);
2795
3136
  if (wire.type) {
2796
3137
  types.add(wire.type);
2797
3138
  }
@@ -2872,7 +3213,7 @@ var ObjectSetHelper = class extends AbstractHelper {
2872
3213
  const {
2873
3214
  baseObjectSet
2874
3215
  } = options;
2875
- const baseObjectSetWire = JSON.stringify(chunk3LMKH6RS_cjs.getWireObjectSet(baseObjectSet));
3216
+ const baseObjectSetWire = JSON.stringify(chunkDZE6IAUU_cjs.getWireObjectSet(baseObjectSet));
2876
3217
  const operations = this.buildCanonicalizedOperations(options);
2877
3218
  const objectSetCacheKey = this.cacheKeys.get("objectSet", baseObjectSetWire, operations);
2878
3219
  return this.store.queries.get(objectSetCacheKey, () => {
@@ -2888,13 +3229,13 @@ var ObjectSetHelper = class extends AbstractHelper {
2888
3229
  operations.withProperties = Object.keys(options.withProperties).sort();
2889
3230
  }
2890
3231
  if (options.union && options.union.length > 0) {
2891
- operations.union = options.union.map((os) => JSON.stringify(chunk3LMKH6RS_cjs.getWireObjectSet(os)));
3232
+ operations.union = options.union.map((os) => JSON.stringify(chunkDZE6IAUU_cjs.getWireObjectSet(os)));
2892
3233
  }
2893
3234
  if (options.intersect && options.intersect.length > 0) {
2894
- operations.intersect = options.intersect.map((os) => JSON.stringify(chunk3LMKH6RS_cjs.getWireObjectSet(os)));
3235
+ operations.intersect = options.intersect.map((os) => JSON.stringify(chunkDZE6IAUU_cjs.getWireObjectSet(os)));
2895
3236
  }
2896
3237
  if (options.subtract && options.subtract.length > 0) {
2897
- operations.subtract = options.subtract.map((os) => JSON.stringify(chunk3LMKH6RS_cjs.getWireObjectSet(os)));
3238
+ operations.subtract = options.subtract.map((os) => JSON.stringify(chunkDZE6IAUU_cjs.getWireObjectSet(os)));
2898
3239
  }
2899
3240
  if (options.pivotTo) {
2900
3241
  operations.pivotTo = options.pivotTo;
@@ -2909,7 +3250,27 @@ var ObjectSetHelper = class extends AbstractHelper {
2909
3250
  }
2910
3251
  };
2911
3252
 
3253
+ // src/observable/internal/PivotCanonicalizer.ts
3254
+ chunk6SCDLAU2_cjs.init_cjs_shims();
3255
+ var PivotCanonicalizer = class {
3256
+ #cache = /* @__PURE__ */ new Map();
3257
+ canonicalize(sourceType, linkName) {
3258
+ const key = `${sourceType}::${linkName}`;
3259
+ let canonical = this.#cache.get(key);
3260
+ if (!canonical) {
3261
+ canonical = {
3262
+ sourceType,
3263
+ linkName,
3264
+ targetType: "<targetType>"
3265
+ };
3266
+ this.#cache.set(key, canonical);
3267
+ }
3268
+ return canonical;
3269
+ }
3270
+ };
3271
+
2912
3272
  // src/observable/internal/Queries.ts
3273
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2913
3274
  var Queries = class {
2914
3275
  // we can use a regular Map here because the refCounting will
2915
3276
  // handle cleanup.
@@ -2934,33 +3295,8 @@ var Queries = class {
2934
3295
  }
2935
3296
  };
2936
3297
 
2937
- // src/observable/internal/Canonicalizer.ts
2938
- var CachingCanonicalizer = class {
2939
- /**
2940
- * Cache for input object identity.
2941
- */
2942
- inputCache = /* @__PURE__ */ new WeakMap();
2943
- /**
2944
- * Look up or create a canonical form for the given input.
2945
- * This method handles the structural deduplication logic.
2946
- *
2947
- * @param input The input to canonicalize
2948
- * @returns The canonical form
2949
- */
2950
- canonicalize(input) {
2951
- if (!input) {
2952
- return void 0;
2953
- }
2954
- if (this.inputCache.has(input)) {
2955
- return this.inputCache.get(input);
2956
- }
2957
- const canonical = this.lookupOrCreate(input);
2958
- this.inputCache.set(input, canonical);
2959
- return canonical;
2960
- }
2961
- };
2962
-
2963
3298
  // src/observable/internal/RdpCanonicalizer.ts
3299
+ chunk6SCDLAU2_cjs.init_cjs_shims();
2964
3300
  var RdpCanonicalizer = class extends CachingCanonicalizer {
2965
3301
  structuralCache = /* @__PURE__ */ new Map();
2966
3302
  lookupOrCreate(rdp) {
@@ -2971,7 +3307,7 @@ var RdpCanonicalizer = class extends CachingCanonicalizer {
2971
3307
  apiName: "__rdp_canonicalizer_holder__"
2972
3308
  };
2973
3309
  for (const [key, rdpFunction] of Object.entries(rdp)) {
2974
- const builder = chunk3LMKH6RS_cjs.createWithPropertiesObjectSet(
3310
+ const builder = chunkDZE6IAUU_cjs.createWithPropertiesObjectSet(
2975
3311
  objectTypeHolder,
2976
3312
  {
2977
3313
  type: "methodInput"
@@ -3010,6 +3346,8 @@ var Store = class {
3010
3346
  whereCanonicalizer = new WhereClauseCanonicalizer();
3011
3347
  orderByCanonicalizer = new OrderByCanonicalizer();
3012
3348
  rdpCanonicalizer = new RdpCanonicalizer();
3349
+ intersectCanonicalizer = new IntersectCanonicalizer(this.whereCanonicalizer);
3350
+ pivotCanonicalizer = new PivotCanonicalizer();
3013
3351
  /** @internal */
3014
3352
  queries = new Queries();
3015
3353
  objectCacheKeyRegistry = new ObjectCacheKeyRegistry();
@@ -3020,14 +3358,15 @@ var Store = class {
3020
3358
  subjects = this.layers.subjects;
3021
3359
  // these are hopefully temporary
3022
3360
  constructor(client) {
3023
- this.logger = client[chunk3LMKH6RS_cjs.additionalContext].logger?.child({}, {
3361
+ this.logger = client[chunkDZE6IAUU_cjs.additionalContext].logger?.child({}, {
3024
3362
  msgPrefix: "Store"
3025
3363
  });
3026
3364
  this.client = client;
3027
3365
  this.cacheKeys = new CacheKeys({
3028
3366
  onDestroy: this.#cleanupCacheKey
3029
3367
  });
3030
- this.lists = new ListsHelper(this, this.cacheKeys, this.whereCanonicalizer, this.orderByCanonicalizer, this.rdpCanonicalizer);
3368
+ this.aggregations = new AggregationsHelper(this, this.cacheKeys, this.whereCanonicalizer, this.rdpCanonicalizer);
3369
+ this.lists = new ListsHelper(this, this.cacheKeys, this.whereCanonicalizer, this.orderByCanonicalizer, this.rdpCanonicalizer, this.intersectCanonicalizer, this.pivotCanonicalizer);
3031
3370
  this.objects = new ObjectsHelper(this, this.cacheKeys);
3032
3371
  this.links = new LinksHelper(this, this.cacheKeys, this.whereCanonicalizer, this.orderByCanonicalizer);
3033
3372
  this.objectSets = new ObjectSetHelper(this, this.cacheKeys, this.whereCanonicalizer, this.orderByCanonicalizer);
@@ -3182,13 +3521,15 @@ var Store = class {
3182
3521
  * Extracts RDP configuration from a cache key if present.
3183
3522
  *
3184
3523
  * @param cacheKey - The cache key to check
3185
- * @returns The RDP configuration, or undefined if not present
3524
+ * @returns The RDP configuration, null, or undefined
3186
3525
  */
3187
3526
  #getQueryRdpConfig(cacheKey) {
3188
3527
  if ("otherKeys" in cacheKey && Array.isArray(cacheKey.otherKeys)) {
3189
3528
  if (cacheKey.type === "object") {
3190
3529
  return cacheKey.otherKeys[RDP_CONFIG_IDX];
3191
3530
  } else if (cacheKey.type === "list") {
3531
+ return cacheKey.otherKeys[RDP_IDX2];
3532
+ } else if (cacheKey.type === "aggregation") {
3192
3533
  return cacheKey.otherKeys[RDP_IDX];
3193
3534
  }
3194
3535
  }
@@ -3203,8 +3544,10 @@ var Store = class {
3203
3544
  #getQueryObjectType(cacheKey) {
3204
3545
  if ("otherKeys" in cacheKey && Array.isArray(cacheKey.otherKeys)) {
3205
3546
  if (cacheKey.type === "object") {
3206
- return cacheKey.otherKeys[API_NAME_IDX2];
3547
+ return cacheKey.otherKeys[API_NAME_IDX3];
3207
3548
  } else if (cacheKey.type === "list") {
3549
+ return cacheKey.otherKeys[API_NAME_IDX2];
3550
+ } else if (cacheKey.type === "aggregation") {
3208
3551
  return cacheKey.otherKeys[API_NAME_IDX];
3209
3552
  }
3210
3553
  }
@@ -3281,10 +3624,10 @@ var Store = class {
3281
3624
 
3282
3625
  // src/observable/ObservableClient.ts
3283
3626
  function createObservableClient(client) {
3284
- const tweakedClient = chunk4ZOXOCQX_cjs.createClientFromContext({
3285
- ...client[chunk3LMKH6RS_cjs.additionalContext],
3286
- fetch: shared_net_fetch.createFetchHeaderMutator(client[chunk3LMKH6RS_cjs.additionalContext].fetch, (headers) => {
3287
- headers.set("Fetch-User-Agent", [headers.get("Fetch-User-Agent"), chunk4ZOXOCQX_cjs.OBSERVABLE_USER_AGENT].filter((x) => x && x?.length > 0).join(" "));
3627
+ const tweakedClient = chunkS4JPAF56_cjs.createClientFromContext({
3628
+ ...client[chunkDZE6IAUU_cjs.additionalContext],
3629
+ fetch: shared_net_fetch.createFetchHeaderMutator(client[chunkDZE6IAUU_cjs.additionalContext].fetch, (headers) => {
3630
+ headers.set("Fetch-User-Agent", [headers.get("Fetch-User-Agent"), chunkS4JPAF56_cjs.OBSERVABLE_USER_AGENT].filter((x) => x && x?.length > 0).join(" "));
3288
3631
  return headers;
3289
3632
  })
3290
3633
  });
@@ -3292,6 +3635,7 @@ function createObservableClient(client) {
3292
3635
  }
3293
3636
 
3294
3637
  // src/public-utils/osdkConfig.ts
3638
+ chunk6SCDLAU2_cjs.init_cjs_shims();
3295
3639
  function getMetaTagContent(name) {
3296
3640
  const element = document.querySelector(`meta[name="${name}"]`);
3297
3641
  const val = element ? element.getAttribute("content") : null;
@@ -3327,11 +3671,11 @@ function getOsdkConfig(ontologyRid) {
3327
3671
 
3328
3672
  Object.defineProperty(exports, "createClientWithTransaction", {
3329
3673
  enumerable: true,
3330
- get: function () { return chunk4ZOXOCQX_cjs.createClientWithTransaction; }
3674
+ get: function () { return chunkS4JPAF56_cjs.createClientWithTransaction; }
3331
3675
  });
3332
3676
  Object.defineProperty(exports, "augment", {
3333
3677
  enumerable: true,
3334
- get: function () { return chunk3LMKH6RS_cjs.augment; }
3678
+ get: function () { return chunkDZE6IAUU_cjs.augment; }
3335
3679
  });
3336
3680
  exports.computeObjectSetCacheKey = computeObjectSetCacheKey;
3337
3681
  exports.createObservableClient = createObservableClient;