@osdk/client 2.2.0-beta.8 → 2.2.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.
- package/CHANGELOG.md +18 -0
- package/build/browser/createMinimalClient.js +2 -2
- package/build/browser/createMinimalClient.js.map +1 -1
- package/build/browser/object/SimpleOsdkProperties.js +2 -0
- package/build/browser/object/SimpleOsdkProperties.js.map +1 -0
- package/build/browser/object/convertWireToOsdkObjects/BaseHolder.js +2 -0
- package/build/browser/object/convertWireToOsdkObjects/BaseHolder.js.map +1 -0
- package/build/browser/object/convertWireToOsdkObjects/InterfaceHolder.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/ObjectHolder.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js +10 -3
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/getDollarAs.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/getDollarLink.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects.js +4 -2
- package/build/browser/object/convertWireToOsdkObjects.js.map +1 -1
- package/build/browser/object/fetchPage.js +13 -1
- package/build/browser/object/fetchPage.js.map +1 -1
- package/build/browser/object/fetchPage.test.js +56 -2
- package/build/browser/object/fetchPage.test.js.map +1 -1
- package/build/browser/object/object.test.js.map +1 -1
- package/build/browser/objectSet/InterfaceObjectSet.test.js +18 -2
- package/build/browser/objectSet/InterfaceObjectSet.test.js.map +1 -1
- package/build/browser/objectSet/ObjectSet.test.js +92 -102
- package/build/browser/objectSet/ObjectSet.test.js.map +1 -1
- package/build/browser/objectSet/ObjectSetListenerWebsocket.js +18 -14
- package/build/browser/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
- package/build/browser/objectSet/createObjectSet.js.map +1 -1
- package/build/browser/observable/ListPayload.js.map +1 -1
- package/build/browser/observable/ObjectPayload.js.map +1 -1
- package/build/browser/observable/ObservableClient.js.map +1 -1
- package/build/browser/observable/internal/ActionApplication.js +29 -29
- package/build/browser/observable/internal/ActionApplication.js.map +1 -1
- package/build/browser/observable/internal/CacheKey.js +1 -1
- package/build/browser/observable/internal/CacheKey.js.map +1 -1
- package/build/browser/observable/internal/CacheKeys.js +2 -2
- package/build/browser/observable/internal/CacheKeys.js.map +1 -1
- package/build/browser/observable/internal/{ChangedObjects.js → Changes.js} +20 -9
- package/build/browser/observable/internal/Changes.js.map +1 -0
- package/build/browser/observable/internal/Layer.js +3 -0
- package/build/browser/observable/internal/Layer.js.map +1 -1
- package/build/browser/observable/internal/ListQuery.js +411 -170
- package/build/browser/observable/internal/ListQuery.js.map +1 -1
- package/build/browser/observable/internal/ObjectQuery.js +32 -16
- package/build/browser/observable/internal/ObjectQuery.js.map +1 -1
- package/build/browser/observable/internal/ObservableClientImpl.js +4 -12
- package/build/browser/observable/internal/ObservableClientImpl.js.map +1 -1
- package/build/browser/observable/internal/OptimisticJob.js.map +1 -1
- package/build/browser/observable/internal/OrderByCanonicalizer.js +73 -0
- package/build/browser/observable/internal/OrderByCanonicalizer.js.map +1 -0
- package/build/browser/observable/internal/OrderByCanonicalizer.test.js +78 -0
- package/build/browser/observable/internal/OrderByCanonicalizer.test.js.map +1 -0
- package/build/browser/observable/internal/Query.js +64 -31
- package/build/browser/observable/internal/Query.js.map +1 -1
- package/build/browser/observable/internal/RefCounts.js +7 -2
- package/build/browser/observable/internal/RefCounts.js.map +1 -1
- package/build/browser/observable/internal/SimpleWhereClause.js +2 -0
- package/build/browser/observable/internal/SimpleWhereClause.js.map +1 -0
- package/build/browser/observable/internal/Store.js +84 -267
- package/build/browser/observable/internal/Store.js.map +1 -1
- package/build/browser/observable/internal/Store.test.js +264 -247
- package/build/browser/observable/internal/Store.test.js.map +1 -1
- package/build/browser/observable/internal/WhereClauseCanonicalizer.js +11 -3
- package/build/browser/observable/internal/WhereClauseCanonicalizer.js.map +1 -1
- package/build/browser/observable/internal/objectMatchesWhereClause.js.map +1 -1
- package/build/browser/observable/internal/objectMatchesWhereClause.test.js.map +1 -1
- package/build/browser/observable/internal/testUtils.js +82 -18
- package/build/browser/observable/internal/testUtils.js.map +1 -1
- package/build/browser/public/unstable-do-not-use.js.map +1 -1
- package/build/browser/util/UserAgent.js +1 -1
- package/build/cjs/{chunk-JPENHIJB.cjs → chunk-EY52J5Z4.cjs} +25 -15
- package/build/cjs/chunk-EY52J5Z4.cjs.map +1 -0
- package/build/cjs/{chunk-IU47QMYO.cjs → chunk-MCQVHD2F.cjs} +32 -28
- package/build/cjs/chunk-MCQVHD2F.cjs.map +1 -0
- package/build/cjs/chunk-T4NIFYZS.cjs +14 -0
- package/build/cjs/chunk-T4NIFYZS.cjs.map +1 -0
- package/build/cjs/index.cjs +69 -72
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/public/internal.cjs +6 -6
- package/build/cjs/public/unstable-do-not-use.cjs +683 -539
- package/build/cjs/public/unstable-do-not-use.cjs.map +1 -1
- package/build/cjs/public/unstable-do-not-use.d.cts +27 -26
- package/build/esm/createMinimalClient.js +2 -2
- package/build/esm/createMinimalClient.js.map +1 -1
- package/build/esm/object/SimpleOsdkProperties.js +2 -0
- package/build/esm/object/SimpleOsdkProperties.js.map +1 -0
- package/build/esm/object/convertWireToOsdkObjects/BaseHolder.js +2 -0
- package/build/esm/object/convertWireToOsdkObjects/BaseHolder.js.map +1 -0
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/ObjectHolder.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js +10 -3
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/getDollarAs.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/getDollarLink.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects.js +4 -2
- package/build/esm/object/convertWireToOsdkObjects.js.map +1 -1
- package/build/esm/object/fetchPage.js +13 -1
- package/build/esm/object/fetchPage.js.map +1 -1
- package/build/esm/object/fetchPage.test.js +56 -2
- package/build/esm/object/fetchPage.test.js.map +1 -1
- package/build/esm/object/object.test.js.map +1 -1
- package/build/esm/objectSet/InterfaceObjectSet.test.js +18 -2
- package/build/esm/objectSet/InterfaceObjectSet.test.js.map +1 -1
- package/build/esm/objectSet/ObjectSet.test.js +92 -102
- package/build/esm/objectSet/ObjectSet.test.js.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.js +18 -14
- package/build/esm/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
- package/build/esm/objectSet/createObjectSet.js.map +1 -1
- package/build/esm/observable/ListPayload.js.map +1 -1
- package/build/esm/observable/ObjectPayload.js.map +1 -1
- package/build/esm/observable/ObservableClient.js.map +1 -1
- package/build/esm/observable/internal/ActionApplication.js +29 -29
- package/build/esm/observable/internal/ActionApplication.js.map +1 -1
- package/build/esm/observable/internal/CacheKey.js +1 -1
- package/build/esm/observable/internal/CacheKey.js.map +1 -1
- package/build/esm/observable/internal/CacheKeys.js +2 -2
- package/build/esm/observable/internal/CacheKeys.js.map +1 -1
- package/build/esm/observable/internal/{ChangedObjects.js → Changes.js} +20 -9
- package/build/esm/observable/internal/Changes.js.map +1 -0
- package/build/esm/observable/internal/Layer.js +3 -0
- package/build/esm/observable/internal/Layer.js.map +1 -1
- package/build/esm/observable/internal/ListQuery.js +411 -170
- package/build/esm/observable/internal/ListQuery.js.map +1 -1
- package/build/esm/observable/internal/ObjectQuery.js +32 -16
- package/build/esm/observable/internal/ObjectQuery.js.map +1 -1
- package/build/esm/observable/internal/ObservableClientImpl.js +4 -12
- package/build/esm/observable/internal/ObservableClientImpl.js.map +1 -1
- package/build/esm/observable/internal/OptimisticJob.js.map +1 -1
- package/build/esm/observable/internal/OrderByCanonicalizer.js +73 -0
- package/build/esm/observable/internal/OrderByCanonicalizer.js.map +1 -0
- package/build/esm/observable/internal/OrderByCanonicalizer.test.js +78 -0
- package/build/esm/observable/internal/OrderByCanonicalizer.test.js.map +1 -0
- package/build/esm/observable/internal/Query.js +64 -31
- package/build/esm/observable/internal/Query.js.map +1 -1
- package/build/esm/observable/internal/RefCounts.js +7 -2
- package/build/esm/observable/internal/RefCounts.js.map +1 -1
- package/build/esm/observable/internal/SimpleWhereClause.js +2 -0
- package/build/esm/observable/internal/SimpleWhereClause.js.map +1 -0
- package/build/esm/observable/internal/Store.js +84 -267
- package/build/esm/observable/internal/Store.js.map +1 -1
- package/build/esm/observable/internal/Store.test.js +264 -247
- package/build/esm/observable/internal/Store.test.js.map +1 -1
- package/build/esm/observable/internal/WhereClauseCanonicalizer.js +11 -3
- package/build/esm/observable/internal/WhereClauseCanonicalizer.js.map +1 -1
- package/build/esm/observable/internal/objectMatchesWhereClause.js.map +1 -1
- package/build/esm/observable/internal/objectMatchesWhereClause.test.js.map +1 -1
- package/build/esm/observable/internal/testUtils.js +82 -18
- package/build/esm/observable/internal/testUtils.js.map +1 -1
- package/build/esm/public/unstable-do-not-use.js.map +1 -1
- package/build/esm/util/UserAgent.js +1 -1
- package/build/types/object/SimpleOsdkProperties.d.ts +1 -0
- package/build/types/object/SimpleOsdkProperties.d.ts.map +1 -0
- package/build/types/object/convertWireToOsdkObjects/BaseHolder.d.ts +1 -0
- package/build/types/object/convertWireToOsdkObjects/BaseHolder.d.ts.map +1 -0
- package/build/types/object/convertWireToOsdkObjects.d.ts +8 -1
- package/build/types/object/convertWireToOsdkObjects.d.ts.map +1 -1
- package/build/types/observable/ListPayload.d.ts +5 -9
- package/build/types/observable/ListPayload.d.ts.map +1 -1
- package/build/types/observable/ObjectPayload.d.ts +4 -7
- package/build/types/observable/ObjectPayload.d.ts.map +1 -1
- package/build/types/observable/ObservableClient.d.ts +27 -11
- package/build/types/observable/ObservableClient.d.ts.map +1 -1
- package/build/types/observable/internal/ActionApplication.d.ts.map +1 -1
- package/build/types/observable/internal/CacheKeys.d.ts +1 -1
- package/build/types/observable/internal/CacheKeys.d.ts.map +1 -1
- package/build/types/observable/internal/Changes.d.ts +15 -0
- package/build/types/observable/internal/Changes.d.ts.map +1 -0
- package/build/types/observable/internal/Layer.d.ts +1 -0
- package/build/types/observable/internal/Layer.d.ts.map +1 -1
- package/build/types/observable/internal/ListQuery.d.ts +59 -14
- package/build/types/observable/internal/ListQuery.d.ts.map +1 -1
- package/build/types/observable/internal/ObjectQuery.d.ts +5 -6
- package/build/types/observable/internal/ObjectQuery.d.ts.map +1 -1
- package/build/types/observable/internal/OptimisticJob.d.ts +1 -1
- package/build/types/observable/internal/OptimisticJob.d.ts.map +1 -1
- package/build/types/observable/internal/OrderByCanonicalizer.d.ts +12 -0
- package/build/types/observable/internal/OrderByCanonicalizer.d.ts.map +1 -0
- package/build/types/observable/internal/OrderByCanonicalizer.test.d.ts +1 -0
- package/build/types/observable/internal/OrderByCanonicalizer.test.d.ts.map +1 -0
- package/build/types/observable/internal/Query.d.ts +39 -4
- package/build/types/observable/internal/Query.d.ts.map +1 -1
- package/build/types/observable/internal/RefCounts.d.ts.map +1 -1
- package/build/types/observable/internal/SimpleWhereClause.d.ts +2 -0
- package/build/types/observable/internal/SimpleWhereClause.d.ts.map +1 -0
- package/build/types/observable/internal/Store.d.ts +19 -43
- package/build/types/observable/internal/Store.d.ts.map +1 -1
- package/build/types/observable/internal/WhereClauseCanonicalizer.d.ts +2 -1
- package/build/types/observable/internal/WhereClauseCanonicalizer.d.ts.map +1 -1
- package/build/types/observable/internal/objectMatchesWhereClause.d.ts +4 -2
- package/build/types/observable/internal/objectMatchesWhereClause.d.ts.map +1 -1
- package/build/types/observable/internal/testUtils.d.ts +39 -9
- package/build/types/observable/internal/testUtils.d.ts.map +1 -1
- package/build/types/public/unstable-do-not-use.d.ts +1 -4
- package/build/types/public/unstable-do-not-use.d.ts.map +1 -1
- package/package.json +12 -10
- package/build/browser/observable/internal/ChangedObjects.js.map +0 -1
- package/build/cjs/chunk-IU47QMYO.cjs.map +0 -1
- package/build/cjs/chunk-JPENHIJB.cjs.map +0 -1
- package/build/esm/observable/internal/ChangedObjects.js.map +0 -1
- package/build/types/observable/internal/ChangedObjects.d.ts +0 -11
- package/build/types/observable/internal/ChangedObjects.d.ts.map +0 -1
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkT4NIFYZS_cjs = require('../chunk-T4NIFYZS.cjs');
|
|
4
|
+
var chunkEY52J5Z4_cjs = require('../chunk-EY52J5Z4.cjs');
|
|
4
5
|
require('../chunk-Q7SFCCGT.cjs');
|
|
5
6
|
var rxjs = require('rxjs');
|
|
6
7
|
var invariant2 = require('tiny-invariant');
|
|
7
8
|
var mnemonist = require('mnemonist');
|
|
8
9
|
var trie = require('@wry/trie');
|
|
9
10
|
var deepEqual = require('fast-deep-equal');
|
|
11
|
+
var groupBy = require('object.groupby');
|
|
10
12
|
|
|
11
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
14
|
|
|
13
15
|
var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
|
|
14
16
|
var deepEqual__default = /*#__PURE__*/_interopDefault(deepEqual);
|
|
17
|
+
var groupBy__default = /*#__PURE__*/_interopDefault(groupBy);
|
|
15
18
|
|
|
16
19
|
// src/observable/internal/ObservableClientImpl.ts
|
|
17
20
|
var ObservableClientImpl = class {
|
|
18
21
|
#store;
|
|
19
22
|
constructor(store) {
|
|
20
23
|
this.#store = store;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
observeList(options, subFn) {
|
|
26
|
-
return this.#store.observeList(options, subFn);
|
|
27
|
-
}
|
|
28
|
-
applyAction(action, args, opts) {
|
|
29
|
-
return this.#store.applyAction(action, args, opts);
|
|
30
|
-
}
|
|
31
|
-
canonicalizeWhereClause(where) {
|
|
32
|
-
return this.#store.whereCanonicalizer.canonicalize(where);
|
|
24
|
+
this.observeObject = store.observeObject.bind(store);
|
|
25
|
+
this.observeList = store.observeList.bind(store);
|
|
26
|
+
this.applyAction = store.applyAction.bind(store);
|
|
27
|
+
this.canonicalizeWhereClause = store.canonicalizeWhereClause.bind(store);
|
|
33
28
|
}
|
|
34
29
|
};
|
|
35
30
|
|
|
@@ -100,28 +95,39 @@ function DEBUG_ONLY__cacheKeyToString(x) {
|
|
|
100
95
|
}
|
|
101
96
|
function DEBUG_ONLY__cacheKeysToString(x) {
|
|
102
97
|
if (process.env.NODE_ENV !== "production") {
|
|
103
|
-
return
|
|
98
|
+
return "\n - " + x.map(DEBUG_ONLY__cacheKeyToString).join("\n - ");
|
|
104
99
|
} else {
|
|
105
100
|
throw new Error("not implemented");
|
|
106
101
|
}
|
|
107
102
|
}
|
|
108
103
|
|
|
109
|
-
// src/observable/internal/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
// src/observable/internal/Changes.ts
|
|
105
|
+
var Changes = class {
|
|
106
|
+
modifiedObjects = new mnemonist.MultiMap();
|
|
107
|
+
addedObjects = new mnemonist.MultiMap();
|
|
108
|
+
added = /* @__PURE__ */ new Set();
|
|
109
|
+
modified = /* @__PURE__ */ new Set();
|
|
110
|
+
registerObject = (cacheKey, data, isNew) => {
|
|
111
|
+
this[isNew ? "addedObjects" : "modifiedObjects"].set(data.$apiName, data);
|
|
112
|
+
this[isNew ? "added" : "modified"].add(cacheKey);
|
|
116
113
|
};
|
|
114
|
+
registerList = (key) => {
|
|
115
|
+
this.modified.add(key);
|
|
116
|
+
};
|
|
117
|
+
isEmpty() {
|
|
118
|
+
return this.modifiedObjects.size === 0 && this.addedObjects.size === 0 && this.added.size === 0 && this.modified.size === 0;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
function createChangedObjects() {
|
|
122
|
+
return new Changes();
|
|
117
123
|
}
|
|
118
124
|
function DEBUG_ONLY__changesToString(changes) {
|
|
119
125
|
if (process.env.NODE_ENV !== "production") {
|
|
120
126
|
return JSON.stringify({
|
|
121
127
|
modifiedObjects: multimapHelper(changes.modifiedObjects),
|
|
122
128
|
addedObjects: multimapHelper(changes.addedObjects),
|
|
123
|
-
|
|
124
|
-
|
|
129
|
+
added: listHelper(changes.added),
|
|
130
|
+
modified: listHelper(changes.modified)
|
|
125
131
|
}, null, 2);
|
|
126
132
|
} else {
|
|
127
133
|
throw new Error("not implemented");
|
|
@@ -183,7 +189,7 @@ var OptimisticJob = class {
|
|
|
183
189
|
return this;
|
|
184
190
|
},
|
|
185
191
|
createObject(type, pk, properties) {
|
|
186
|
-
const create = store.client[
|
|
192
|
+
const create = store.client[chunkEY52J5Z4_cjs.additionalContext].objectFactory2(store.client[chunkEY52J5Z4_cjs.additionalContext], [{
|
|
187
193
|
$primaryKey: pk,
|
|
188
194
|
$apiName: type.apiName,
|
|
189
195
|
$objectType: type.apiName,
|
|
@@ -224,22 +230,27 @@ var ActionApplication = class {
|
|
|
224
230
|
applyAction = (action, args, {
|
|
225
231
|
optimisticUpdate
|
|
226
232
|
} = {}) => {
|
|
233
|
+
const logger = process.env.NODE_ENV !== "production" ? this.store.logger?.child({
|
|
234
|
+
methodName: "applyAction"
|
|
235
|
+
}) : this.store.logger;
|
|
227
236
|
const removeOptimisticResult = runOptimisticJob(this.store, optimisticUpdate);
|
|
228
237
|
return (async () => {
|
|
229
238
|
try {
|
|
230
239
|
const actionResults = await this.store.client(action).applyAction(args, {
|
|
231
240
|
$returnEdits: true
|
|
232
241
|
});
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
242
|
+
if (process.env.NODE_ENV !== "production") {
|
|
243
|
+
if (ACTION_DELAY > 0) {
|
|
244
|
+
logger?.debug("action done, pausing");
|
|
245
|
+
await delay(ACTION_DELAY);
|
|
246
|
+
logger?.debug("action done, pausing done");
|
|
247
|
+
}
|
|
237
248
|
}
|
|
238
249
|
await this.#invalidateActionEditResponse(actionResults);
|
|
239
250
|
return actionResults;
|
|
240
251
|
} finally {
|
|
241
252
|
if (process.env.NODE_ENV !== "production") {
|
|
242
|
-
|
|
253
|
+
logger?.debug("optimistic action complete; remove the results");
|
|
243
254
|
}
|
|
244
255
|
await removeOptimisticResult();
|
|
245
256
|
}
|
|
@@ -258,8 +269,20 @@ var ActionApplication = class {
|
|
|
258
269
|
typesToInvalidate.add(obj.objectType);
|
|
259
270
|
}
|
|
260
271
|
await Promise.all(promisesToWait);
|
|
261
|
-
|
|
262
|
-
|
|
272
|
+
const changes2 = createChangedObjects();
|
|
273
|
+
for (const changeType of ["addedObjects", "modifiedObjects"]) {
|
|
274
|
+
for (const {
|
|
275
|
+
objectType,
|
|
276
|
+
primaryKey
|
|
277
|
+
} of value[changeType] ?? []) {
|
|
278
|
+
const cacheKey = this.store.getCacheKey("object", objectType, primaryKey);
|
|
279
|
+
const obj = this.store.getValue(cacheKey);
|
|
280
|
+
if (obj && obj.value) {
|
|
281
|
+
changes2[changeType].set(objectType, obj.value);
|
|
282
|
+
(changeType === "addedObjects" ? changes2.added : changes2.modified).add(cacheKey);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
263
286
|
} else {
|
|
264
287
|
for (const apiName of value.editedObjectTypes) {
|
|
265
288
|
typesToInvalidate.add(apiName.toString());
|
|
@@ -268,21 +291,6 @@ var ActionApplication = class {
|
|
|
268
291
|
}
|
|
269
292
|
return value;
|
|
270
293
|
};
|
|
271
|
-
#changesFromActionEditResponse = (value) => {
|
|
272
|
-
const changes = createChangedObjects();
|
|
273
|
-
for (const changeType of ["addedObjects", "modifiedObjects"]) {
|
|
274
|
-
for (const {
|
|
275
|
-
objectType,
|
|
276
|
-
primaryKey
|
|
277
|
-
} of value[changeType] ?? []) {
|
|
278
|
-
const obj = this.store.getObject(objectType, primaryKey);
|
|
279
|
-
if (obj) {
|
|
280
|
-
changes[changeType].set(objectType, obj);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return changes;
|
|
285
|
-
};
|
|
286
294
|
};
|
|
287
295
|
var CacheKeys = class {
|
|
288
296
|
#cacheKeys = new trie.Trie(false, (keys) => {
|
|
@@ -301,9 +309,9 @@ var CacheKeys = class {
|
|
|
301
309
|
if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) ;
|
|
302
310
|
return this.#cacheKeys.lookupArray(["object", apiName, pk]);
|
|
303
311
|
});
|
|
304
|
-
this.#registerCacheKeyFactory("list", (apiName, where, orderBy) => {
|
|
312
|
+
this.#registerCacheKeyFactory("list", (type, apiName, where, orderBy) => {
|
|
305
313
|
if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) ;
|
|
306
|
-
return this.#cacheKeys.lookupArray(["list", apiName, whereCanonicalizer.canonicalize(where), orderByCanonicalizer.canonicalize(orderBy)]);
|
|
314
|
+
return this.#cacheKeys.lookupArray(["list", type, apiName, whereCanonicalizer.canonicalize(where), orderByCanonicalizer.canonicalize(orderBy)]);
|
|
307
315
|
});
|
|
308
316
|
}
|
|
309
317
|
#registerCacheKeyFactory(type, factory) {
|
|
@@ -456,6 +464,9 @@ var Layer = class _Layer {
|
|
|
456
464
|
entries() {
|
|
457
465
|
return this.#cache.entries();
|
|
458
466
|
}
|
|
467
|
+
keys() {
|
|
468
|
+
return this.#cache.keys();
|
|
469
|
+
}
|
|
459
470
|
get(cacheKey) {
|
|
460
471
|
return this.#cache.get(cacheKey) ?? this.#parent?.get(cacheKey);
|
|
461
472
|
}
|
|
@@ -569,7 +580,7 @@ var Query = class {
|
|
|
569
580
|
this.cacheKey = cacheKey;
|
|
570
581
|
this.store = store;
|
|
571
582
|
this.#subject = observable;
|
|
572
|
-
this.logger = logger ?? (process.env.NODE_ENV === "production" ? store.client[
|
|
583
|
+
this.logger = logger ?? (process.env.NODE_ENV === "production" ? store.client[chunkEY52J5Z4_cjs.additionalContext].logger : store.client[chunkEY52J5Z4_cjs.additionalContext].logger?.child({}, {
|
|
573
584
|
msgPrefix: process.env.NODE_ENV !== "production" ? `Query<${cacheKey.type}, ${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>` : "Query"
|
|
574
585
|
}));
|
|
575
586
|
}
|
|
@@ -578,61 +589,66 @@ var Query = class {
|
|
|
578
589
|
this.#subscription = this.#connectable.connect();
|
|
579
590
|
return this.#connectable.subscribe(observer);
|
|
580
591
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
592
|
+
/**
|
|
593
|
+
* Causes the query to revalidate. This will cause the query to fetch
|
|
594
|
+
* the latest data from the server and update the store if it is deemed
|
|
595
|
+
* "stale" or if `force` is true.
|
|
596
|
+
*
|
|
597
|
+
* @param force
|
|
598
|
+
* @returns
|
|
599
|
+
*/
|
|
600
|
+
async revalidate(force) {
|
|
601
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
602
|
+
methodName: "revalidate"
|
|
603
|
+
}) : this.logger;
|
|
587
604
|
if (force) {
|
|
588
605
|
this.abortController?.abort();
|
|
589
606
|
}
|
|
590
607
|
if (this.pendingFetch) {
|
|
591
|
-
|
|
608
|
+
if (process.env.NODE_ENV !== "production") {
|
|
609
|
+
logger?.info("Fetch is already pending, using it");
|
|
610
|
+
}
|
|
611
|
+
await this.pendingFetch;
|
|
612
|
+
return;
|
|
592
613
|
}
|
|
593
614
|
if ((this.options.dedupeInterval ?? 0) > 0 && this.lastFetchStarted != null && Date.now() - this.lastFetchStarted < (this.options.dedupeInterval ?? 0)) {
|
|
594
615
|
if (process.env.NODE_ENV !== "production") {
|
|
595
|
-
|
|
596
|
-
methodName: "revalidate"
|
|
597
|
-
}, "DEDUPE");
|
|
616
|
+
logger?.debug("Within dupeInterval, aborting revalidate");
|
|
598
617
|
}
|
|
599
618
|
return Promise.resolve();
|
|
600
619
|
}
|
|
620
|
+
if (process.env.NODE_ENV !== "production") {
|
|
621
|
+
logger?.debug("Starting actual revalidate");
|
|
622
|
+
}
|
|
601
623
|
this.store.batch({}, (batch) => {
|
|
602
624
|
this.setStatus("loading", batch);
|
|
603
625
|
});
|
|
604
626
|
this._preFetch();
|
|
605
627
|
this.lastFetchStarted = Date.now();
|
|
606
628
|
if (process.env.NODE_ENV !== "production") {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
this.pendingFetch = this._fetch().catch((e) => {
|
|
612
|
-
this.logger?.error({
|
|
613
|
-
methodName: "revalidate"
|
|
614
|
-
}, "_fetch() FAILED", e);
|
|
615
|
-
throw e;
|
|
616
|
-
}).finally(() => {
|
|
617
|
-
this.logger?.info({
|
|
618
|
-
methodName: "revalidate"
|
|
619
|
-
}, "finally _fetch()");
|
|
629
|
+
logger?.debug("calling _fetchAndStore()");
|
|
630
|
+
}
|
|
631
|
+
this.pendingFetch = this._fetchAndStore().finally(() => {
|
|
632
|
+
logger?.info("finally _fetchAndStore()");
|
|
620
633
|
this.pendingFetch = undefined;
|
|
621
634
|
});
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
methodName: "revalidate"
|
|
625
|
-
}, "Returning");
|
|
626
|
-
}
|
|
627
|
-
return this.pendingFetch;
|
|
635
|
+
await this.pendingFetch;
|
|
636
|
+
return;
|
|
628
637
|
}
|
|
629
638
|
_preFetch() {
|
|
630
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Sets the status of the query in the store (but does not store that in `changes`).
|
|
642
|
+
*
|
|
643
|
+
* @param status
|
|
644
|
+
* @param batch
|
|
645
|
+
* @returns
|
|
646
|
+
*/
|
|
631
647
|
setStatus(status, batch) {
|
|
632
648
|
if (process.env.NODE_ENV !== "production") {
|
|
633
|
-
this.logger?.
|
|
649
|
+
this.logger?.child({
|
|
634
650
|
methodName: "setStatus"
|
|
635
|
-
}
|
|
651
|
+
}).debug(status);
|
|
636
652
|
}
|
|
637
653
|
const existing = batch.read(this.cacheKey);
|
|
638
654
|
if (existing?.status === status) return;
|
|
@@ -645,31 +661,209 @@ var Query = class {
|
|
|
645
661
|
this.#subscription?.unsubscribe();
|
|
646
662
|
this._dispose();
|
|
647
663
|
}
|
|
664
|
+
/**
|
|
665
|
+
* Per query type dispose functionality
|
|
666
|
+
*/
|
|
648
667
|
_dispose() {
|
|
649
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* The purpose of this method is to provide a way for others to write
|
|
671
|
+
* directly into the store for this query.
|
|
672
|
+
*
|
|
673
|
+
* @param data
|
|
674
|
+
* @param status
|
|
675
|
+
* @param batch
|
|
676
|
+
*/
|
|
677
|
+
/**
|
|
678
|
+
* @param changes
|
|
679
|
+
* @param optimisticId
|
|
680
|
+
* @returns If revalidation is needed, a promise that resolves after the
|
|
681
|
+
* revalidation is complete. Otherwise, undefined.
|
|
682
|
+
*/
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
// src/observable/internal/ObjectQuery.ts
|
|
686
|
+
var ObjectQuery = class extends Query {
|
|
687
|
+
#apiName;
|
|
688
|
+
#pk;
|
|
689
|
+
constructor(store, subject, type, pk, cacheKey, opts) {
|
|
690
|
+
super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkEY52J5Z4_cjs.additionalContext].logger?.child({}, {
|
|
691
|
+
msgPrefix: `ObjectQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
|
|
692
|
+
}) : undefined);
|
|
693
|
+
this.#apiName = type;
|
|
694
|
+
this.#pk = pk;
|
|
695
|
+
}
|
|
696
|
+
_createConnectable(subject) {
|
|
697
|
+
return rxjs.connectable(subject.pipe(rxjs.map((x) => {
|
|
698
|
+
return {
|
|
699
|
+
status: x.status,
|
|
700
|
+
object: x.value,
|
|
701
|
+
lastUpdated: x.lastUpdated,
|
|
702
|
+
isOptimistic: x.isOptimistic
|
|
703
|
+
};
|
|
704
|
+
})), {
|
|
705
|
+
connector: () => new rxjs.BehaviorSubject({
|
|
706
|
+
status: "init",
|
|
707
|
+
object: undefined,
|
|
708
|
+
lastUpdated: 0,
|
|
709
|
+
isOptimistic: false
|
|
710
|
+
})
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
async _fetchAndStore() {
|
|
714
|
+
if (process.env.NODE_ENV !== "production") {
|
|
715
|
+
this.logger?.child({
|
|
716
|
+
methodName: "_fetchAndStore"
|
|
717
|
+
}).info("calling fetchOne");
|
|
718
|
+
}
|
|
719
|
+
const objectSet = this.store.client({
|
|
720
|
+
type: "object",
|
|
721
|
+
apiName: this.#apiName
|
|
722
|
+
});
|
|
723
|
+
const obj = await objectSet.fetchOne(this.#pk);
|
|
724
|
+
this.store.batch({}, (batch) => {
|
|
725
|
+
this.writeToStore(obj, "loaded", batch);
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
writeToStore(data, status, batch) {
|
|
729
|
+
const entry = batch.read(this.cacheKey);
|
|
730
|
+
if (entry && deepEqual__default.default(data, entry.value)) {
|
|
731
|
+
if (process.env.NODE_ENV !== "production") {
|
|
732
|
+
this.logger?.child({
|
|
733
|
+
methodName: "writeToStore"
|
|
734
|
+
}).debug(`Object was deep equal, just setting status`);
|
|
735
|
+
}
|
|
736
|
+
return batch.write(this.cacheKey, entry.value, status);
|
|
737
|
+
}
|
|
738
|
+
if (process.env.NODE_ENV !== "production") {
|
|
739
|
+
this.logger?.child({
|
|
740
|
+
methodName: "writeToStore"
|
|
741
|
+
}).debug(JSON.stringify({
|
|
742
|
+
status
|
|
743
|
+
}), data);
|
|
744
|
+
}
|
|
745
|
+
const ret = batch.write(this.cacheKey, data, status);
|
|
746
|
+
batch.changes.registerObject(
|
|
747
|
+
this.cacheKey,
|
|
748
|
+
data,
|
|
749
|
+
/* isNew */
|
|
750
|
+
!entry
|
|
751
|
+
);
|
|
752
|
+
return ret;
|
|
753
|
+
}
|
|
650
754
|
};
|
|
755
|
+
function storeOsdkInstances(store, values, batch) {
|
|
756
|
+
return values.map((v) => {
|
|
757
|
+
return store.getObjectQuery(v.$apiName, v.$primaryKey).writeToStore(v, "loaded", batch).cacheKey;
|
|
758
|
+
});
|
|
759
|
+
}
|
|
651
760
|
|
|
652
761
|
// src/observable/internal/ListQuery.ts
|
|
653
|
-
var
|
|
762
|
+
var API_NAME_IDX = 1;
|
|
763
|
+
var BaseListQuery = class extends Query {
|
|
764
|
+
//
|
|
765
|
+
// Per list type implementations
|
|
766
|
+
//
|
|
767
|
+
//
|
|
768
|
+
// Shared Implementations
|
|
769
|
+
//
|
|
770
|
+
/**
|
|
771
|
+
* Only intended to be "protected" and used by subclasses but exposed for
|
|
772
|
+
* testing.
|
|
773
|
+
*
|
|
774
|
+
* @param objectCacheKeys
|
|
775
|
+
* @param append
|
|
776
|
+
* @param status
|
|
777
|
+
* @param batch
|
|
778
|
+
* @returns
|
|
779
|
+
*/
|
|
780
|
+
_updateList(objectCacheKeys, append, status, batch) {
|
|
781
|
+
if (process.env.NODE_ENV !== "production") {
|
|
782
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
783
|
+
methodName: "updateList"
|
|
784
|
+
}) : this.logger;
|
|
785
|
+
logger?.debug(`{status: ${status}}`, JSON.stringify(objectCacheKeys, null, 2));
|
|
786
|
+
}
|
|
787
|
+
objectCacheKeys = this.#retainReleaseAppend(batch, append, objectCacheKeys);
|
|
788
|
+
objectCacheKeys = this._sortCacheKeys(objectCacheKeys, batch);
|
|
789
|
+
objectCacheKeys = removeDuplicates(objectCacheKeys, batch);
|
|
790
|
+
return this.writeToStore({
|
|
791
|
+
data: objectCacheKeys
|
|
792
|
+
}, status, batch);
|
|
793
|
+
}
|
|
794
|
+
writeToStore(data, status, batch) {
|
|
795
|
+
const entry = batch.read(this.cacheKey);
|
|
796
|
+
if (entry && deepEqual__default.default(data, entry.value)) {
|
|
797
|
+
if (process.env.NODE_ENV !== "production") {
|
|
798
|
+
this.logger?.child({
|
|
799
|
+
methodName: "writeToStore"
|
|
800
|
+
}).debug(`Object was deep equal, just setting status`);
|
|
801
|
+
}
|
|
802
|
+
return batch.write(this.cacheKey, entry.value, status);
|
|
803
|
+
}
|
|
804
|
+
if (process.env.NODE_ENV !== "production") {
|
|
805
|
+
this.logger?.child({
|
|
806
|
+
methodName: "writeToStore"
|
|
807
|
+
}).debug(`{status: ${status}},`, DEBUG_ONLY__cacheKeysToString(data.data));
|
|
808
|
+
}
|
|
809
|
+
const ret = batch.write(this.cacheKey, data, status);
|
|
810
|
+
batch.changes.registerList(this.cacheKey);
|
|
811
|
+
return ret;
|
|
812
|
+
}
|
|
813
|
+
#retainReleaseAppend(batch, append, objectCacheKeys) {
|
|
814
|
+
const existingList = batch.read(this.cacheKey);
|
|
815
|
+
if (!batch.optimisticWrite) {
|
|
816
|
+
if (!append) {
|
|
817
|
+
for (const objectCacheKey of existingList?.value?.data ?? []) {
|
|
818
|
+
this.store.release(objectCacheKey);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
for (const objectCacheKey of objectCacheKeys) {
|
|
822
|
+
this.store.retain(objectCacheKey);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (append) {
|
|
826
|
+
objectCacheKeys = [...existingList?.value?.data ?? [], ...objectCacheKeys];
|
|
827
|
+
}
|
|
828
|
+
return objectCacheKeys;
|
|
829
|
+
}
|
|
830
|
+
_dispose() {
|
|
831
|
+
console.log("DISPOSE LIST QUERY");
|
|
832
|
+
this.store.batch({}, (batch) => {
|
|
833
|
+
const entry = batch.read(this.cacheKey);
|
|
834
|
+
if (entry) {
|
|
835
|
+
for (const objectCacheKey of entry.value?.data ?? []) {
|
|
836
|
+
this.store.release(objectCacheKey);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
var ListQuery = class extends BaseListQuery {
|
|
654
843
|
// pageSize?: number; // this is the internal page size. we need to track this properly
|
|
655
|
-
#client;
|
|
656
844
|
#type;
|
|
845
|
+
#apiName;
|
|
657
846
|
#whereClause;
|
|
658
847
|
// this represents the minimum number of results we need to load if we revalidate
|
|
659
848
|
#minNumResults = 0;
|
|
660
849
|
#nextPageToken;
|
|
661
850
|
#pendingPageFetch;
|
|
662
|
-
#toRelease = /* @__PURE__ */ new Set();
|
|
663
851
|
#orderBy;
|
|
664
|
-
|
|
665
|
-
|
|
852
|
+
#objectSet;
|
|
853
|
+
#sortFns;
|
|
854
|
+
constructor(store, subject, apiType, apiName, whereClause, orderBy, cacheKey, opts) {
|
|
855
|
+
super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkEY52J5Z4_cjs.additionalContext].logger?.child({}, {
|
|
666
856
|
msgPrefix: `ListQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
|
|
667
857
|
}) : undefined);
|
|
668
|
-
this.#
|
|
669
|
-
this.#
|
|
858
|
+
this.#type = apiType;
|
|
859
|
+
this.#apiName = apiName;
|
|
670
860
|
this.#whereClause = whereClause;
|
|
671
861
|
this.#orderBy = orderBy;
|
|
672
|
-
|
|
862
|
+
this.#objectSet = store.client({
|
|
863
|
+
type: this.#type,
|
|
864
|
+
apiName: this.#apiName
|
|
865
|
+
}).where(this.#whereClause);
|
|
866
|
+
this.#sortFns = createOrderBySortFns(this.#orderBy);
|
|
673
867
|
}
|
|
674
868
|
get canonicalWhere() {
|
|
675
869
|
return this.#whereClause;
|
|
@@ -696,13 +890,14 @@ var ListQuery = class extends Query {
|
|
|
696
890
|
_preFetch() {
|
|
697
891
|
this.#nextPageToken = undefined;
|
|
698
892
|
}
|
|
699
|
-
async
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
893
|
+
async _fetchAndStore() {
|
|
894
|
+
if (process.env.NODE_ENV !== "production") {
|
|
895
|
+
this.logger?.child({
|
|
896
|
+
methodName: "_fetchAndStore"
|
|
897
|
+
}).info("fetching pages");
|
|
898
|
+
}
|
|
704
899
|
while (true) {
|
|
705
|
-
const entry = await this.#fetchPageAndUpdate(objectSet, "loading", this.abortController?.signal);
|
|
900
|
+
const entry = await this.#fetchPageAndUpdate(this.#objectSet, "loading", this.abortController?.signal);
|
|
706
901
|
if (!entry) {
|
|
707
902
|
return;
|
|
708
903
|
}
|
|
@@ -734,40 +929,75 @@ var ListQuery = class extends Query {
|
|
|
734
929
|
this.store.batch({}, (batch) => {
|
|
735
930
|
this.setStatus("loading", batch);
|
|
736
931
|
});
|
|
737
|
-
|
|
738
|
-
type: "object",
|
|
739
|
-
apiName: this.#type
|
|
740
|
-
}).where(this.#whereClause);
|
|
741
|
-
this.pendingFetch = this.#fetchPageAndUpdate(objectSet, "loaded", this.abortController?.signal).finally(() => {
|
|
932
|
+
this.pendingFetch = this.#fetchPageAndUpdate(this.#objectSet, "loaded", this.abortController?.signal).finally(() => {
|
|
742
933
|
this.#pendingPageFetch = undefined;
|
|
743
934
|
});
|
|
744
935
|
return this.pendingFetch;
|
|
745
936
|
};
|
|
746
937
|
async #fetchPageAndUpdate(objectSet, status, signal) {
|
|
747
938
|
const append = this.#nextPageToken != null;
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
939
|
+
try {
|
|
940
|
+
let {
|
|
941
|
+
data,
|
|
942
|
+
nextPageToken
|
|
943
|
+
} = await objectSet.fetchPage({
|
|
944
|
+
$nextPageToken: this.#nextPageToken,
|
|
945
|
+
$pageSize: this.options.pageSize,
|
|
946
|
+
// For now this keeps the shared test code from falling apart
|
|
947
|
+
// but shouldn't be needed ideally
|
|
948
|
+
...Object.keys(this.#orderBy).length > 0 ? {
|
|
949
|
+
$orderBy: this.#orderBy
|
|
950
|
+
} : {}
|
|
951
|
+
});
|
|
952
|
+
if (signal?.aborted) {
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
this.#nextPageToken = nextPageToken;
|
|
956
|
+
if (this.#type === "interface") {
|
|
957
|
+
data = await reloadDataAsFullObjects(this.store.client, data);
|
|
958
|
+
}
|
|
959
|
+
const {
|
|
960
|
+
retVal
|
|
961
|
+
} = this.store.batch({}, (batch) => {
|
|
962
|
+
return this._updateList(storeOsdkInstances(this.store, data, batch), append, nextPageToken ? status : "loaded", batch);
|
|
963
|
+
});
|
|
964
|
+
return retVal;
|
|
965
|
+
} catch (e) {
|
|
966
|
+
this.logger?.error("error", e);
|
|
967
|
+
this.store.getSubject(this.cacheKey).error(e);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Will revalidate the list if its query is affected by invalidating the
|
|
972
|
+
* apiName of the object type passed in.
|
|
973
|
+
*
|
|
974
|
+
* @param apiName to invalidate
|
|
975
|
+
* @returns
|
|
976
|
+
*/
|
|
977
|
+
revalidateObjectType = async (apiName) => {
|
|
978
|
+
if (this.#type === "object") {
|
|
979
|
+
if (this.#apiName === apiName) {
|
|
980
|
+
await this.revalidate(
|
|
981
|
+
/* force */
|
|
982
|
+
true
|
|
983
|
+
);
|
|
984
|
+
return;
|
|
985
|
+
} else {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
const objectMetadata = await this.store.client.fetchMetadata({
|
|
990
|
+
type: "object",
|
|
991
|
+
apiName
|
|
759
992
|
});
|
|
760
|
-
if (
|
|
993
|
+
if (this.#apiName in objectMetadata.interfaceMap) {
|
|
994
|
+
await this.revalidate(
|
|
995
|
+
/* force */
|
|
996
|
+
true
|
|
997
|
+
);
|
|
761
998
|
return;
|
|
762
999
|
}
|
|
763
|
-
|
|
764
|
-
const {
|
|
765
|
-
retVal
|
|
766
|
-
} = this.store.batch({}, (batch) => {
|
|
767
|
-
return this.updateList(this.store.updateObjects(data, batch), append, nextPageToken ? status : "loaded", batch);
|
|
768
|
-
});
|
|
769
|
-
return retVal;
|
|
770
|
-
}
|
|
1000
|
+
};
|
|
771
1001
|
/**
|
|
772
1002
|
* Note: This method is not async because I want it to return right after it
|
|
773
1003
|
* finishes the synchronous updates. The promise that is returned
|
|
@@ -779,50 +1009,25 @@ var ListQuery = class extends Query {
|
|
|
779
1009
|
*/
|
|
780
1010
|
maybeUpdateAndRevalidate = (changes, optimisticId) => {
|
|
781
1011
|
if (process.env.NODE_ENV !== "production") {
|
|
782
|
-
this.logger?.
|
|
783
|
-
methodName: "
|
|
784
|
-
}
|
|
1012
|
+
this.logger?.child({
|
|
1013
|
+
methodName: "maybeUpdateAndRevalidate"
|
|
1014
|
+
}).debug(DEBUG_ONLY__changesToString(changes));
|
|
785
1015
|
}
|
|
786
|
-
if (changes.
|
|
1016
|
+
if (changes.modified.has(this.cacheKey)) return;
|
|
1017
|
+
changes.modified.add(this.cacheKey);
|
|
787
1018
|
try {
|
|
788
|
-
const relevantObjects =
|
|
789
|
-
added: {
|
|
790
|
-
all: changes.addedObjects.get(this.cacheKey.otherKeys[0]) ?? [],
|
|
791
|
-
strictMatches: /* @__PURE__ */ new Set(),
|
|
792
|
-
sortaMatches: /* @__PURE__ */ new Set()
|
|
793
|
-
},
|
|
794
|
-
modified: {
|
|
795
|
-
all: changes.modifiedObjects.get(this.cacheKey.otherKeys[0]) ?? [],
|
|
796
|
-
strictMatches: /* @__PURE__ */ new Set(),
|
|
797
|
-
sortaMatches: /* @__PURE__ */ new Set()
|
|
798
|
-
}
|
|
799
|
-
};
|
|
1019
|
+
const relevantObjects = this._extractRelevantObjects(changes);
|
|
800
1020
|
if (relevantObjects.added.all.length === 0 && relevantObjects.modified.all.length === 0) {
|
|
801
1021
|
return;
|
|
802
1022
|
}
|
|
803
|
-
for (const group of Object.values(relevantObjects)) {
|
|
804
|
-
for (const obj of group.all ?? []) {
|
|
805
|
-
const strictMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, true);
|
|
806
|
-
if (strictMatch) {
|
|
807
|
-
group.strictMatches.add(obj);
|
|
808
|
-
} else {
|
|
809
|
-
const sortaMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, false);
|
|
810
|
-
if (sortaMatch) {
|
|
811
|
-
group.sortaMatches.add(obj);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
1023
|
const status = optimisticId || relevantObjects.added.sortaMatches.size > 0 || relevantObjects.modified.sortaMatches.size > 0 ? "loading" : "loaded";
|
|
817
|
-
changes.modifiedLists.add(this.cacheKey);
|
|
818
1024
|
const newList = [];
|
|
819
1025
|
let needsRevalidation = false;
|
|
820
1026
|
this.store.batch({
|
|
821
1027
|
optimisticId,
|
|
822
1028
|
changes
|
|
823
1029
|
}, (batch) => {
|
|
824
|
-
const
|
|
825
|
-
const existingList = new Set(curValue?.value?.data);
|
|
1030
|
+
const existingList = new Set(batch.read(this.cacheKey)?.value?.data);
|
|
826
1031
|
const toAdd = new Set(
|
|
827
1032
|
// easy case. objects are new to the cache and they match this filter
|
|
828
1033
|
relevantObjects.added.strictMatches
|
|
@@ -830,15 +1035,15 @@ var ListQuery = class extends Query {
|
|
|
830
1035
|
const toRemove = /* @__PURE__ */ new Set();
|
|
831
1036
|
for (const obj of relevantObjects.modified.all) {
|
|
832
1037
|
if (relevantObjects.modified.strictMatches.has(obj)) {
|
|
833
|
-
const
|
|
834
|
-
if (!existingList.has(
|
|
1038
|
+
const objectCacheKey = this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey);
|
|
1039
|
+
if (!existingList.has(objectCacheKey)) {
|
|
835
1040
|
toAdd.add(obj);
|
|
836
1041
|
}
|
|
837
1042
|
continue;
|
|
838
1043
|
} else if (batch.optimisticWrite) {
|
|
839
1044
|
continue;
|
|
840
1045
|
} else {
|
|
841
|
-
const existingObjectCacheKey = this.store.getCacheKey("object", obj.$
|
|
1046
|
+
const existingObjectCacheKey = this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey);
|
|
842
1047
|
toRemove.add(existingObjectCacheKey);
|
|
843
1048
|
if (relevantObjects.modified.sortaMatches.has(obj)) {
|
|
844
1049
|
needsRevalidation = true;
|
|
@@ -850,9 +1055,9 @@ var ListQuery = class extends Query {
|
|
|
850
1055
|
newList.push(key);
|
|
851
1056
|
}
|
|
852
1057
|
for (const obj of toAdd) {
|
|
853
|
-
newList.push(this.store.getCacheKey("object", obj.$
|
|
1058
|
+
newList.push(this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey));
|
|
854
1059
|
}
|
|
855
|
-
this.
|
|
1060
|
+
this._updateList(
|
|
856
1061
|
newList,
|
|
857
1062
|
/* append */
|
|
858
1063
|
false,
|
|
@@ -861,69 +1066,73 @@ var ListQuery = class extends Query {
|
|
|
861
1066
|
);
|
|
862
1067
|
});
|
|
863
1068
|
if (needsRevalidation) {
|
|
864
|
-
|
|
865
|
-
return this.revalidate(true).then(() => void 0);
|
|
1069
|
+
return this.revalidate(true);
|
|
866
1070
|
}
|
|
867
1071
|
return void 0;
|
|
868
1072
|
} finally {
|
|
869
1073
|
if (process.env.NODE_ENV !== "production") {
|
|
870
|
-
this.logger?.
|
|
871
|
-
methodName: "
|
|
872
|
-
}
|
|
1074
|
+
this.logger?.child({
|
|
1075
|
+
methodName: "maybeUpdateAndRevalidate"
|
|
1076
|
+
}).debug("in finally");
|
|
873
1077
|
}
|
|
874
1078
|
}
|
|
875
1079
|
};
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
1080
|
+
_extractRelevantObjects(changes) {
|
|
1081
|
+
const relevantObjects = this.#type === "object" ? this.#extractRelevantObjectsForTypeObject(changes) : this.#extractRelevantObjectsForTypeInterface(changes);
|
|
1082
|
+
for (const group of Object.values(relevantObjects)) {
|
|
1083
|
+
for (const obj of group.all ?? []) {
|
|
1084
|
+
const strictMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, true);
|
|
1085
|
+
if (strictMatch) {
|
|
1086
|
+
group.strictMatches.add(obj);
|
|
1087
|
+
} else {
|
|
1088
|
+
const sortaMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, false);
|
|
1089
|
+
if (sortaMatch) {
|
|
1090
|
+
group.sortaMatches.add(obj);
|
|
1091
|
+
}
|
|
888
1092
|
}
|
|
889
1093
|
}
|
|
890
|
-
for (const objectCacheKey of objectCacheKeys) {
|
|
891
|
-
this.#toRelease.add(objectCacheKey);
|
|
892
|
-
this.store.retain(objectCacheKey);
|
|
893
|
-
}
|
|
894
1094
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1095
|
+
return relevantObjects;
|
|
1096
|
+
}
|
|
1097
|
+
#extractRelevantObjectsForTypeInterface(changes) {
|
|
1098
|
+
const added = Array.from(changes.addedObjects).filter(([, object]) => {
|
|
1099
|
+
return this.#apiName in object[chunkT4NIFYZS_cjs.ObjectDefRef].interfaceMap;
|
|
1100
|
+
}).map(([, object]) => object.$as(this.#apiName));
|
|
1101
|
+
const modified = Array.from(changes.modifiedObjects).filter(([, object]) => {
|
|
1102
|
+
return this.#apiName in object[chunkT4NIFYZS_cjs.ObjectDefRef].interfaceMap;
|
|
1103
|
+
}).map(([, object]) => object.$as(this.#apiName));
|
|
1104
|
+
return {
|
|
1105
|
+
added: {
|
|
1106
|
+
all: added,
|
|
1107
|
+
strictMatches: /* @__PURE__ */ new Set(),
|
|
1108
|
+
sortaMatches: /* @__PURE__ */ new Set()
|
|
1109
|
+
},
|
|
1110
|
+
modified: {
|
|
1111
|
+
all: modified,
|
|
1112
|
+
strictMatches: /* @__PURE__ */ new Set(),
|
|
1113
|
+
sortaMatches: /* @__PURE__ */ new Set()
|
|
906
1114
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
#extractRelevantObjectsForTypeObject(changes) {
|
|
1118
|
+
return {
|
|
1119
|
+
added: {
|
|
1120
|
+
all: changes.addedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
|
|
1121
|
+
strictMatches: /* @__PURE__ */ new Set(),
|
|
1122
|
+
sortaMatches: /* @__PURE__ */ new Set()
|
|
1123
|
+
},
|
|
1124
|
+
modified: {
|
|
1125
|
+
all: changes.modifiedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
|
|
1126
|
+
strictMatches: /* @__PURE__ */ new Set(),
|
|
1127
|
+
sortaMatches: /* @__PURE__ */ new Set()
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
_sortCacheKeys(objectCacheKeys, batch) {
|
|
1132
|
+
if (Object.keys(this.#orderBy).length > 0) {
|
|
924
1133
|
objectCacheKeys = objectCacheKeys.sort((a, b) => {
|
|
925
|
-
for (const sortFn of sortFns) {
|
|
926
|
-
const ret = sortFn(batch.read(a)?.value, batch.read(b)?.value);
|
|
1134
|
+
for (const sortFn of this.#sortFns) {
|
|
1135
|
+
const ret = sortFn(batch.read(a)?.value?.$as(this.#apiName), batch.read(b)?.value?.$as(this.#apiName));
|
|
927
1136
|
if (ret !== 0) {
|
|
928
1137
|
return ret;
|
|
929
1138
|
}
|
|
@@ -931,108 +1140,206 @@ var ListQuery = class extends Query {
|
|
|
931
1140
|
return 0;
|
|
932
1141
|
});
|
|
933
1142
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
1143
|
+
return objectCacheKeys;
|
|
1144
|
+
}
|
|
1145
|
+
registerStreamUpdates(sub) {
|
|
1146
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
1147
|
+
methodName: "registerStreamUpdates"
|
|
1148
|
+
}) : this.logger;
|
|
1149
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1150
|
+
logger?.child({
|
|
1151
|
+
methodName: "observeList"
|
|
1152
|
+
}).info("Subscribing from websocket");
|
|
1153
|
+
}
|
|
1154
|
+
const websocketSubscription = this.#objectSet.subscribe({
|
|
1155
|
+
onChange: this.#onOswChange.bind(this),
|
|
1156
|
+
onError: this.#onOswError.bind(this),
|
|
1157
|
+
onOutOfDate: this.#onOswOutOfDate.bind(this),
|
|
1158
|
+
onSuccessfulSubscription: this.#onOswSuccessfulSubscription.bind(this)
|
|
1159
|
+
});
|
|
1160
|
+
sub.add(() => {
|
|
1161
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1162
|
+
logger?.child({
|
|
1163
|
+
methodName: "observeList"
|
|
1164
|
+
}).info("Unsubscribing from websocket");
|
|
939
1165
|
}
|
|
940
|
-
|
|
941
|
-
return true;
|
|
1166
|
+
websocketSubscription.unsubscribe();
|
|
942
1167
|
});
|
|
943
|
-
return this.writeToStore({
|
|
944
|
-
data: objectCacheKeys
|
|
945
|
-
}, status, batch);
|
|
946
1168
|
}
|
|
947
|
-
|
|
1169
|
+
#onOswSuccessfulSubscription() {
|
|
948
1170
|
if (process.env.NODE_ENV !== "production") {
|
|
949
|
-
this.logger?.
|
|
950
|
-
methodName: "
|
|
951
|
-
}
|
|
1171
|
+
this.logger?.child({
|
|
1172
|
+
methodName: "onSuccessfulSubscription"
|
|
1173
|
+
}).debug("");
|
|
952
1174
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
1175
|
+
}
|
|
1176
|
+
#onOswOutOfDate() {
|
|
1177
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1178
|
+
this.logger?.child({
|
|
1179
|
+
methodName: "onOutOfDate"
|
|
1180
|
+
}).info("");
|
|
956
1181
|
}
|
|
957
|
-
const ret = batch.write(this.cacheKey, data, status);
|
|
958
|
-
batch.changes.modifiedLists.add(this.cacheKey);
|
|
959
|
-
return ret;
|
|
960
1182
|
}
|
|
961
|
-
|
|
962
|
-
|
|
1183
|
+
#onOswError(errors) {
|
|
1184
|
+
if (this.logger) {
|
|
1185
|
+
this.logger?.child({
|
|
1186
|
+
methodName: "onError"
|
|
1187
|
+
}).error("subscription errors", errors);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
#onOswChange({
|
|
1191
|
+
object: objOrIface,
|
|
1192
|
+
state
|
|
1193
|
+
}) {
|
|
1194
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
1195
|
+
methodName: "registerStreamUpdates"
|
|
1196
|
+
}) : this.logger;
|
|
1197
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1198
|
+
logger?.child({
|
|
1199
|
+
methodName: "onChange"
|
|
1200
|
+
}).debug(`Got an update of type: ${state}`, objOrIface);
|
|
1201
|
+
}
|
|
1202
|
+
if (state === "ADDED_OR_UPDATED") {
|
|
1203
|
+
const object = objOrIface.$apiName !== objOrIface.$objectType ? objOrIface.$as(objOrIface.$objectType) : objOrIface;
|
|
1204
|
+
this.store.batch({}, (batch) => {
|
|
1205
|
+
storeOsdkInstances(this.store, [object], batch);
|
|
1206
|
+
});
|
|
1207
|
+
} else if (state === "REMOVED") {
|
|
1208
|
+
this.#onOswRemoved(objOrIface, logger);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
#onOswRemoved(objOrIface, logger) {
|
|
963
1212
|
this.store.batch({}, (batch) => {
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1213
|
+
const existing = batch.read(this.cacheKey);
|
|
1214
|
+
!existing ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "the truth value for our list should exist as we already subscribed") : invariant2__default.default(false) : undefined;
|
|
1215
|
+
if (existing.status === "loaded") {
|
|
1216
|
+
const objectCacheKey = this.store.getCacheKey("object", objOrIface.$objectType, objOrIface.$primaryKey);
|
|
1217
|
+
const newObjects = existing.value?.data.filter((o) => o !== objectCacheKey);
|
|
1218
|
+
if (newObjects?.length !== existing.value?.data.length) {
|
|
1219
|
+
batch.changes.registerList(this.cacheKey);
|
|
1220
|
+
batch.write(this.cacheKey, {
|
|
1221
|
+
data: newObjects ?? []
|
|
1222
|
+
}, "loaded");
|
|
968
1223
|
}
|
|
1224
|
+
return;
|
|
969
1225
|
}
|
|
1226
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1227
|
+
logger?.info("Removing an object from an object list that is in the middle of being loaded.", existing);
|
|
1228
|
+
}
|
|
1229
|
+
this.revalidate(
|
|
1230
|
+
/* force */
|
|
1231
|
+
true
|
|
1232
|
+
).catch((e) => {
|
|
1233
|
+
if (logger) {
|
|
1234
|
+
logger?.error("Uncaught error while revalidating list", e);
|
|
1235
|
+
} else {
|
|
1236
|
+
console.error("Uncaught error while revalidating list", e);
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
970
1239
|
});
|
|
971
1240
|
}
|
|
972
1241
|
};
|
|
973
|
-
function
|
|
974
|
-
|
|
1242
|
+
function removeDuplicates(objectCacheKeys, batch) {
|
|
1243
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1244
|
+
objectCacheKeys = objectCacheKeys.filter((key) => {
|
|
1245
|
+
batch.read(key);
|
|
1246
|
+
if (visited.has(key)) {
|
|
1247
|
+
return false;
|
|
1248
|
+
}
|
|
1249
|
+
visited.add(key);
|
|
1250
|
+
return true;
|
|
1251
|
+
});
|
|
1252
|
+
return objectCacheKeys;
|
|
975
1253
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1254
|
+
function createOrderBySortFns(orderBy) {
|
|
1255
|
+
return Object.entries(orderBy).map(([key, order]) => {
|
|
1256
|
+
return (a, b) => {
|
|
1257
|
+
const aValue = a?.[key];
|
|
1258
|
+
const bValue = b?.[key];
|
|
1259
|
+
if (aValue == null && bValue == null) {
|
|
1260
|
+
return 0;
|
|
1261
|
+
}
|
|
1262
|
+
if (aValue == null) {
|
|
1263
|
+
return 1;
|
|
1264
|
+
}
|
|
1265
|
+
if (bValue == null) {
|
|
1266
|
+
return -1;
|
|
1267
|
+
}
|
|
1268
|
+
const m = order === "asc" ? -1 : 1;
|
|
1269
|
+
return aValue < bValue ? m : aValue > bValue ? -m : 0;
|
|
1270
|
+
};
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
async function reloadDataAsFullObjects(client, data) {
|
|
1274
|
+
const groups = groupBy__default.default(data, (x) => x.$objectType);
|
|
1275
|
+
const objectTypeToPrimaryKeyToObject = Object.fromEntries(await Promise.all(Object.entries(groups).map(async ([apiName, objects]) => {
|
|
1276
|
+
const objectDef = objects[0][chunkT4NIFYZS_cjs.UnderlyingOsdkObject][chunkT4NIFYZS_cjs.ObjectDefRef];
|
|
1277
|
+
const where = {
|
|
1278
|
+
[objectDef.primaryKeyApiName]: {
|
|
1279
|
+
$in: objects.map((x) => x.$primaryKey)
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
const result = await client(objectDef).where(where).fetchPage();
|
|
1283
|
+
return [apiName, Object.fromEntries(result.data.map((x) => [x.$primaryKey, x]))];
|
|
1284
|
+
})));
|
|
1285
|
+
data = data.map((obj) => objectTypeToPrimaryKeyToObject[obj.$objectType][obj.$primaryKey]);
|
|
1286
|
+
return data;
|
|
1287
|
+
}
|
|
1288
|
+
function isListCacheKey(cacheKey) {
|
|
1289
|
+
return cacheKey.type === "list";
|
|
1290
|
+
}
|
|
1291
|
+
var defaultMakeData = () => /* @__PURE__ */ Object.create(null);
|
|
1292
|
+
var WeakRefTrie = class {
|
|
1293
|
+
#finalizer = new FinalizationRegistry((orderBy) => {
|
|
1294
|
+
this.#trie.removeArray(Object.entries(orderBy).flat());
|
|
1295
|
+
});
|
|
1296
|
+
#trie;
|
|
1297
|
+
constructor(makeData = defaultMakeData) {
|
|
1298
|
+
this.#trie = new trie.Trie(false, (array) => {
|
|
1299
|
+
const data = makeData(array);
|
|
1300
|
+
this.#finalizer.register(data, array);
|
|
1301
|
+
return new WeakRef(data);
|
|
1001
1302
|
});
|
|
1002
1303
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1304
|
+
lookupArray(array) {
|
|
1305
|
+
const maybe = this.#trie.lookupArray(array);
|
|
1306
|
+
let ret = maybe.deref();
|
|
1307
|
+
if (maybe && !ret) {
|
|
1308
|
+
this.#trie.removeArray(array);
|
|
1309
|
+
ret = this.#trie.lookupArray(array).deref();
|
|
1008
1310
|
}
|
|
1009
|
-
|
|
1010
|
-
type: "object",
|
|
1011
|
-
apiName: this.#apiName
|
|
1012
|
-
});
|
|
1013
|
-
const obj = await objectSet.fetchOne(this.#pk);
|
|
1014
|
-
this.store.batch({}, (batch) => {
|
|
1015
|
-
this.writeToStore(obj, "loaded", batch);
|
|
1016
|
-
});
|
|
1311
|
+
return ret;
|
|
1017
1312
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
}
|
|
1024
|
-
const entry = batch.read(this.cacheKey);
|
|
1025
|
-
if (entry && deepEqual__default.default(data, entry.value)) {
|
|
1026
|
-
return batch.write(this.cacheKey, entry.value, status);
|
|
1027
|
-
}
|
|
1028
|
-
const ret = batch.write(this.cacheKey, data, status);
|
|
1029
|
-
if (entry) {
|
|
1030
|
-
batch.changes.modifiedObjects.set(data.$apiName, data);
|
|
1031
|
-
} else {
|
|
1032
|
-
batch.changes.addedObjects.set(data.$apiName, data);
|
|
1313
|
+
peekArray(array) {
|
|
1314
|
+
const maybe = this.#trie.peekArray(array);
|
|
1315
|
+
const ret = maybe?.deref();
|
|
1316
|
+
if (maybe && !ret) {
|
|
1317
|
+
this.#trie.removeArray(array);
|
|
1033
1318
|
}
|
|
1034
1319
|
return ret;
|
|
1035
1320
|
}
|
|
1321
|
+
removeArray(array) {
|
|
1322
|
+
return this.#trie.removeArray(array)?.deref();
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
var OrderByCanonicalizer = class {
|
|
1326
|
+
#trie = new WeakRefTrie((array) => {
|
|
1327
|
+
const pairs = array.reduce(function(result, _, index, array2) {
|
|
1328
|
+
if (index % 2 === 0 && array2[index] != null) {
|
|
1329
|
+
result.push(array2.slice(index, index + 2));
|
|
1330
|
+
}
|
|
1331
|
+
return result;
|
|
1332
|
+
}, []);
|
|
1333
|
+
let data = Object.fromEntries(pairs);
|
|
1334
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1335
|
+
data = Object.freeze(data);
|
|
1336
|
+
}
|
|
1337
|
+
return data;
|
|
1338
|
+
});
|
|
1339
|
+
canonicalize = (orderBy) => {
|
|
1340
|
+
const strings = Object.entries(orderBy).flat();
|
|
1341
|
+
return this.#trie.lookupArray(strings);
|
|
1342
|
+
};
|
|
1036
1343
|
};
|
|
1037
1344
|
|
|
1038
1345
|
// src/observable/internal/RefCounts.ts
|
|
@@ -1059,8 +1366,8 @@ var RefCounts = class {
|
|
|
1059
1366
|
}
|
|
1060
1367
|
}
|
|
1061
1368
|
release(key) {
|
|
1062
|
-
const count = this.refCounts.get(key)
|
|
1063
|
-
if (count === 1) {
|
|
1369
|
+
const count = this.refCounts.get(key);
|
|
1370
|
+
if (count === undefined) ; else if (count === 1) {
|
|
1064
1371
|
this.refCounts.delete(key);
|
|
1065
1372
|
this.gcMap.set(key, Date.now() + this.keepAlive);
|
|
1066
1373
|
} else {
|
|
@@ -1081,6 +1388,14 @@ var RefCounts = class {
|
|
|
1081
1388
|
}
|
|
1082
1389
|
};
|
|
1083
1390
|
var WhereClauseCanonicalizer = class {
|
|
1391
|
+
/**
|
|
1392
|
+
* This is a shortcut cache for any WhereClause's that we have
|
|
1393
|
+
* seen and already canonicalized. The theory behind this
|
|
1394
|
+
* is that well behaving React applications will either `useMemo`
|
|
1395
|
+
* their where clause, or store it in state or pass it through as
|
|
1396
|
+
* props such that we are likely to get the same WhereClause
|
|
1397
|
+
* object multiple times and we can skip unnecessary work.
|
|
1398
|
+
*/
|
|
1084
1399
|
#cache = /* @__PURE__ */ new WeakMap();
|
|
1085
1400
|
/**
|
|
1086
1401
|
* This is a trie that stores the sorted collapsed keys of a where clause to
|
|
@@ -1098,14 +1413,14 @@ var WhereClauseCanonicalizer = class {
|
|
|
1098
1413
|
return this.#cache.get(where);
|
|
1099
1414
|
}
|
|
1100
1415
|
const keysSet = /* @__PURE__ */ new Set();
|
|
1101
|
-
const
|
|
1416
|
+
const calculatedCanon = this.#toCanon(where, keysSet);
|
|
1102
1417
|
const cacheKey = this.#trie.lookupArray(Array.from(keysSet).sort());
|
|
1103
1418
|
const lookupEntry = this.#existingOptions.get(cacheKey) ?? {
|
|
1104
1419
|
options: []
|
|
1105
1420
|
};
|
|
1106
1421
|
this.#existingOptions.set(cacheKey, lookupEntry);
|
|
1107
|
-
const canon = lookupEntry.options.find((ref) => deepEqual__default.default(ref.deref(),
|
|
1108
|
-
if (canon ===
|
|
1422
|
+
const canon = lookupEntry.options.find((ref) => deepEqual__default.default(ref.deref(), calculatedCanon))?.deref() ?? calculatedCanon;
|
|
1423
|
+
if (canon === calculatedCanon) {
|
|
1109
1424
|
lookupEntry.options.push(new WeakRef(canon));
|
|
1110
1425
|
}
|
|
1111
1426
|
this.#cache.set(where, canon);
|
|
@@ -1146,32 +1461,24 @@ function createInitEntry(cacheKey) {
|
|
|
1146
1461
|
lastUpdated: 0
|
|
1147
1462
|
};
|
|
1148
1463
|
}
|
|
1149
|
-
var OrderByCanonicalizer = class {
|
|
1150
|
-
// crappy version
|
|
1151
|
-
#map = /* @__PURE__ */ new Map();
|
|
1152
|
-
canonicalize = (orderBy) => {
|
|
1153
|
-
if (this.#map.has(JSON.stringify(orderBy))) {
|
|
1154
|
-
return this.#map.get(JSON.stringify(orderBy));
|
|
1155
|
-
} else {
|
|
1156
|
-
this.#map.set(JSON.stringify(orderBy), orderBy);
|
|
1157
|
-
return orderBy;
|
|
1158
|
-
}
|
|
1159
|
-
};
|
|
1160
|
-
};
|
|
1161
1464
|
var Store = class {
|
|
1162
1465
|
whereCanonicalizer = new WhereClauseCanonicalizer();
|
|
1163
1466
|
orderByCanonicalizer = new OrderByCanonicalizer();
|
|
1164
1467
|
#truthLayer = new Layer(undefined, undefined);
|
|
1165
1468
|
#topLayer;
|
|
1166
1469
|
/** @internal */
|
|
1167
|
-
|
|
1470
|
+
// we can use a regular Map here because the refCounting will
|
|
1471
|
+
// handle cleanup.
|
|
1472
|
+
#queries = /* @__PURE__ */ new Map();
|
|
1168
1473
|
#cacheKeyToSubject = /* @__PURE__ */ new WeakMap();
|
|
1169
1474
|
#cacheKeys;
|
|
1170
1475
|
#refCounts = new RefCounts(6e4, (k) => this.#cleanupCacheKey(k));
|
|
1476
|
+
// we are currently only using this for debug logging and should just remove it in the future if that
|
|
1477
|
+
// continues to be true
|
|
1171
1478
|
#finalizationRegistry;
|
|
1172
1479
|
constructor(client) {
|
|
1173
1480
|
this.client = client;
|
|
1174
|
-
this.logger = client[
|
|
1481
|
+
this.logger = client[chunkEY52J5Z4_cjs.additionalContext].logger?.child({}, {
|
|
1175
1482
|
msgPrefix: "Store"
|
|
1176
1483
|
});
|
|
1177
1484
|
this.#topLayer = this.#truthLayer;
|
|
@@ -1253,14 +1560,18 @@ var Store = class {
|
|
|
1253
1560
|
}
|
|
1254
1561
|
return subject;
|
|
1255
1562
|
};
|
|
1563
|
+
canonicalizeWhereClause(where) {
|
|
1564
|
+
return this.whereCanonicalizer.canonicalize(where);
|
|
1565
|
+
}
|
|
1256
1566
|
observeObject(apiName, pk, options, subFn) {
|
|
1257
1567
|
if (typeof apiName !== "string") {
|
|
1258
1568
|
apiName = apiName.apiName;
|
|
1259
1569
|
}
|
|
1260
1570
|
const query = this.getObjectQuery(apiName, pk);
|
|
1261
|
-
this
|
|
1571
|
+
this.retain(query.cacheKey);
|
|
1262
1572
|
if (options.mode !== "offline") {
|
|
1263
1573
|
query.revalidate(options.mode === "force").catch((e) => {
|
|
1574
|
+
subFn.error(e);
|
|
1264
1575
|
if (this.logger) {
|
|
1265
1576
|
this.logger.error("Unhandled error in observeObject", e);
|
|
1266
1577
|
} else {
|
|
@@ -1268,145 +1579,54 @@ var Store = class {
|
|
|
1268
1579
|
}
|
|
1269
1580
|
});
|
|
1270
1581
|
}
|
|
1271
|
-
const sub = query.subscribe(
|
|
1272
|
-
next: subFn
|
|
1273
|
-
});
|
|
1582
|
+
const sub = query.subscribe(subFn);
|
|
1274
1583
|
return {
|
|
1275
1584
|
unsubscribe: () => {
|
|
1276
1585
|
sub.unsubscribe();
|
|
1277
|
-
this
|
|
1586
|
+
this.release(query.cacheKey);
|
|
1278
1587
|
}
|
|
1279
1588
|
};
|
|
1280
1589
|
}
|
|
1281
1590
|
observeList(options, subFn) {
|
|
1282
|
-
const query = this.getListQuery(options.
|
|
1283
|
-
this
|
|
1591
|
+
const query = this.getListQuery(options.type, options.where ?? {}, options.orderBy ?? {}, options);
|
|
1592
|
+
this.retain(query.cacheKey);
|
|
1284
1593
|
if (options.mode !== "offline") {
|
|
1285
|
-
|
|
1594
|
+
query.revalidate(options.mode === "force").catch((x) => {
|
|
1595
|
+
subFn.error(x);
|
|
1596
|
+
});
|
|
1286
1597
|
}
|
|
1287
|
-
const sub = query.subscribe(
|
|
1288
|
-
next: subFn
|
|
1289
|
-
});
|
|
1598
|
+
const sub = query.subscribe(subFn);
|
|
1290
1599
|
if (options.streamUpdates) {
|
|
1291
|
-
|
|
1292
|
-
type: "object",
|
|
1293
|
-
apiName: typeof options.objectType === "string" ? options.objectType : options.objectType.apiName
|
|
1294
|
-
};
|
|
1295
|
-
let objectSet = this.client(miniDef);
|
|
1296
|
-
if (options.where) {
|
|
1297
|
-
objectSet = objectSet.where(options.where ?? {});
|
|
1298
|
-
}
|
|
1299
|
-
const store = this;
|
|
1300
|
-
const websocketSubscription = objectSet.subscribe({
|
|
1301
|
-
onChange({
|
|
1302
|
-
object,
|
|
1303
|
-
state
|
|
1304
|
-
}) {
|
|
1305
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1306
|
-
store.logger?.debug({
|
|
1307
|
-
methodName: "onError"
|
|
1308
|
-
}, "updates", state, object);
|
|
1309
|
-
}
|
|
1310
|
-
const cacheKey = store.getCacheKey("object", object.$objectType, object.$primaryKey);
|
|
1311
|
-
const type = store.#peekQuery(cacheKey) == null ? "addedObjects" : "modifiedObjects";
|
|
1312
|
-
const changes = createChangedObjects();
|
|
1313
|
-
changes[type].set(object.$objectType, object);
|
|
1314
|
-
if (state === "ADDED_OR_UPDATED") {
|
|
1315
|
-
store.updateObject(object.$objectType, object);
|
|
1316
|
-
store.maybeRevalidateLists(changes).catch((err) => {
|
|
1317
|
-
console.error("Unhandled error in maybeRevalidateLists", err);
|
|
1318
|
-
});
|
|
1319
|
-
} else if (state === "REMOVED") {
|
|
1320
|
-
const changes2 = createChangedObjects();
|
|
1321
|
-
store.batch({
|
|
1322
|
-
changes: changes2
|
|
1323
|
-
}, (batch) => {
|
|
1324
|
-
const existing = batch.read(query.cacheKey);
|
|
1325
|
-
const cacheKeyToRemove = store.getCacheKey("object", object.$objectType, object.$primaryKey);
|
|
1326
|
-
if (existing?.status === "loaded") {
|
|
1327
|
-
const newObjects = existing.value?.data.filter((o) => o !== cacheKeyToRemove);
|
|
1328
|
-
if (newObjects?.length !== existing.value?.data.length) {
|
|
1329
|
-
batch.changes.modifiedLists.add(query.cacheKey);
|
|
1330
|
-
batch.write(query.cacheKey, {
|
|
1331
|
-
data: newObjects ?? []
|
|
1332
|
-
}, "loaded");
|
|
1333
|
-
}
|
|
1334
|
-
} else {
|
|
1335
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1336
|
-
store.logger?.info("Removing an object from an object list that is in the middle of being loaded.", existing);
|
|
1337
|
-
}
|
|
1338
|
-
query.revalidate(
|
|
1339
|
-
/* force */
|
|
1340
|
-
true
|
|
1341
|
-
).catch((e) => {
|
|
1342
|
-
if (store.logger) {
|
|
1343
|
-
store.logger?.error("Uncaught error while revalidating list", e);
|
|
1344
|
-
} else {
|
|
1345
|
-
console.error("Uncaught error while revalidating list", e);
|
|
1346
|
-
}
|
|
1347
|
-
});
|
|
1348
|
-
}
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
},
|
|
1352
|
-
onError(errors) {
|
|
1353
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1354
|
-
store.logger?.info({
|
|
1355
|
-
methodName: "onError"
|
|
1356
|
-
}, "subscription errors", errors);
|
|
1357
|
-
}
|
|
1358
|
-
},
|
|
1359
|
-
onOutOfDate() {
|
|
1360
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1361
|
-
store.logger?.info({
|
|
1362
|
-
methodName: "onOutOfDate"
|
|
1363
|
-
});
|
|
1364
|
-
}
|
|
1365
|
-
},
|
|
1366
|
-
onSuccessfulSubscription() {
|
|
1367
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1368
|
-
store.logger?.info({
|
|
1369
|
-
methodName: "onSuccessfulSubscription"
|
|
1370
|
-
});
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
});
|
|
1374
|
-
sub.add(() => {
|
|
1375
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1376
|
-
store.logger?.info({
|
|
1377
|
-
methodName: "observeList"
|
|
1378
|
-
}, "Unsubscribing from websocket");
|
|
1379
|
-
}
|
|
1380
|
-
websocketSubscription.unsubscribe();
|
|
1381
|
-
});
|
|
1600
|
+
query.registerStreamUpdates(sub);
|
|
1382
1601
|
}
|
|
1383
1602
|
return {
|
|
1384
1603
|
unsubscribe: () => {
|
|
1385
1604
|
sub.unsubscribe();
|
|
1386
|
-
this
|
|
1605
|
+
this.release(query.cacheKey);
|
|
1387
1606
|
}
|
|
1388
1607
|
};
|
|
1389
1608
|
}
|
|
1390
|
-
|
|
1609
|
+
peekQuery(cacheKey) {
|
|
1391
1610
|
return this.#queries.get(cacheKey);
|
|
1392
1611
|
}
|
|
1393
1612
|
#getQuery(cacheKey, createQuery) {
|
|
1394
|
-
let query = this
|
|
1613
|
+
let query = this.peekQuery(cacheKey);
|
|
1395
1614
|
if (!query) {
|
|
1396
1615
|
query = createQuery();
|
|
1397
1616
|
this.#queries.set(cacheKey, query);
|
|
1398
1617
|
}
|
|
1399
1618
|
return query;
|
|
1400
1619
|
}
|
|
1401
|
-
getListQuery(
|
|
1402
|
-
|
|
1403
|
-
apiName
|
|
1404
|
-
|
|
1620
|
+
getListQuery(def, where, orderBy, opts) {
|
|
1621
|
+
const {
|
|
1622
|
+
apiName,
|
|
1623
|
+
type
|
|
1624
|
+
} = def;
|
|
1405
1625
|
const canonWhere = this.whereCanonicalizer.canonicalize(where);
|
|
1406
1626
|
const canonOrderBy = this.orderByCanonicalizer.canonicalize(orderBy);
|
|
1407
|
-
const listCacheKey = this.getCacheKey("list", apiName, canonWhere, canonOrderBy);
|
|
1627
|
+
const listCacheKey = this.getCacheKey("list", type, apiName, canonWhere, canonOrderBy);
|
|
1408
1628
|
return this.#getQuery(listCacheKey, () => {
|
|
1409
|
-
return new ListQuery(this, this.getSubject(listCacheKey), apiName, canonWhere, canonOrderBy, listCacheKey, opts);
|
|
1629
|
+
return new ListQuery(this, this.getSubject(listCacheKey), type, apiName, canonWhere, canonOrderBy, listCacheKey, opts);
|
|
1410
1630
|
});
|
|
1411
1631
|
}
|
|
1412
1632
|
getObjectQuery(apiName, pk) {
|
|
@@ -1418,13 +1638,8 @@ var Store = class {
|
|
|
1418
1638
|
dedupeInterval: 0
|
|
1419
1639
|
}));
|
|
1420
1640
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
apiName = apiName.apiName;
|
|
1424
|
-
}
|
|
1425
|
-
const objectCacheKey = this.getCacheKey("object", apiName, pk);
|
|
1426
|
-
const objEntry = this.#topLayer.get(objectCacheKey);
|
|
1427
|
-
return objEntry?.value;
|
|
1641
|
+
getValue(cacheKey) {
|
|
1642
|
+
return this.#topLayer.get(cacheKey);
|
|
1428
1643
|
}
|
|
1429
1644
|
batch = ({
|
|
1430
1645
|
optimisticId,
|
|
@@ -1462,63 +1677,59 @@ var Store = class {
|
|
|
1462
1677
|
}
|
|
1463
1678
|
};
|
|
1464
1679
|
const retVal = batchFn(batchContext);
|
|
1465
|
-
|
|
1680
|
+
this.maybeRevalidateQueries(changes, optimisticId).catch((e) => {
|
|
1681
|
+
if (this.logger) {
|
|
1682
|
+
this.logger.error("Unhandled error in batch", e);
|
|
1683
|
+
} else {
|
|
1684
|
+
console.error("Unhandled error in batch", e);
|
|
1685
|
+
throw e;
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1466
1688
|
return {
|
|
1467
1689
|
batchResult: batchContext,
|
|
1468
|
-
retVal
|
|
1690
|
+
retVal,
|
|
1691
|
+
changes: batchContext.changes
|
|
1469
1692
|
};
|
|
1470
1693
|
};
|
|
1471
1694
|
invalidateObject(apiName, pk) {
|
|
1472
1695
|
if (typeof apiName !== "string") {
|
|
1473
1696
|
apiName = apiName.apiName;
|
|
1474
1697
|
}
|
|
1475
|
-
|
|
1476
|
-
|
|
1698
|
+
return this.getObjectQuery(apiName, pk).revalidate(
|
|
1699
|
+
/* force */
|
|
1700
|
+
true
|
|
1701
|
+
);
|
|
1477
1702
|
}
|
|
1478
|
-
async
|
|
1703
|
+
async maybeRevalidateQueries(changes, optimisticId) {
|
|
1704
|
+
if (changes.isEmpty()) {
|
|
1705
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1706
|
+
this.logger?.child({
|
|
1707
|
+
methodName: "maybeRevalidateQueries"
|
|
1708
|
+
}).debug("No changes, aborting");
|
|
1709
|
+
}
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1479
1712
|
if (process.env.NODE_ENV !== "production") {
|
|
1480
|
-
this.logger?.
|
|
1481
|
-
methodName: "
|
|
1482
|
-
}
|
|
1713
|
+
this.logger?.child({
|
|
1714
|
+
methodName: "maybeRevalidateQueries"
|
|
1715
|
+
}).debug(DEBUG_ONLY__changesToString(changes), {
|
|
1716
|
+
optimisticId
|
|
1717
|
+
});
|
|
1483
1718
|
}
|
|
1484
1719
|
try {
|
|
1485
1720
|
const promises = [];
|
|
1486
|
-
for (const
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
if (promise) promises.push(promise);
|
|
1490
|
-
}
|
|
1721
|
+
for (const cacheKey of this.#queries.keys()) {
|
|
1722
|
+
const promise = this.peekQuery(cacheKey)?.maybeUpdateAndRevalidate?.(changes, optimisticId);
|
|
1723
|
+
if (promise) promises.push(promise);
|
|
1491
1724
|
}
|
|
1492
1725
|
await Promise.all(promises);
|
|
1493
1726
|
} finally {
|
|
1494
1727
|
if (process.env.NODE_ENV !== "production") {
|
|
1495
|
-
this.logger?.
|
|
1496
|
-
methodName: "
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
maybeUpdateLists(changes, optimisticId) {
|
|
1502
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1503
|
-
this.logger?.trace({
|
|
1504
|
-
methodName: "maybeUpdateLists"
|
|
1505
|
-
}, DEBUG_ONLY__changesToString(changes), {
|
|
1506
|
-
optimisticId
|
|
1507
|
-
});
|
|
1508
|
-
}
|
|
1509
|
-
if (changes.addedObjects.size === 0 && changes.modifiedObjects.size === 0) {
|
|
1510
|
-
return Promise.resolve([]);
|
|
1511
|
-
}
|
|
1512
|
-
const promises = [];
|
|
1513
|
-
for (const cacheKey of this.#queries.keys()) {
|
|
1514
|
-
if (isListCacheKey(cacheKey)) {
|
|
1515
|
-
if (!changes.modifiedLists.has(cacheKey)) {
|
|
1516
|
-
const promise = this.#peekQuery(cacheKey)?.maybeUpdateAndRevalidate(changes, optimisticId);
|
|
1517
|
-
if (promise) promises.push(promise);
|
|
1518
|
-
}
|
|
1728
|
+
this.logger?.child({
|
|
1729
|
+
methodName: "maybeRevalidateQueries"
|
|
1730
|
+
}).debug("in finally", DEBUG_ONLY__changesToString(changes));
|
|
1519
1731
|
}
|
|
1520
1732
|
}
|
|
1521
|
-
return Promise.all(promises);
|
|
1522
1733
|
}
|
|
1523
1734
|
/**
|
|
1524
1735
|
* @param apiName
|
|
@@ -1530,90 +1741,23 @@ var Store = class {
|
|
|
1530
1741
|
apiName = apiName.apiName;
|
|
1531
1742
|
}
|
|
1532
1743
|
if (process.env.NODE_ENV !== "production") {
|
|
1533
|
-
this.logger?.
|
|
1744
|
+
this.logger?.child({
|
|
1534
1745
|
methodName: "invalidateObjectType"
|
|
1535
|
-
}
|
|
1746
|
+
}).info(changes ? DEBUG_ONLY__changesToString(changes) : undefined);
|
|
1536
1747
|
}
|
|
1537
1748
|
const promises = [];
|
|
1538
|
-
for (const
|
|
1539
|
-
if (isListCacheKey(cacheKey
|
|
1540
|
-
if (!changes || !changes.
|
|
1541
|
-
const promise = this
|
|
1749
|
+
for (const cacheKey of this.#truthLayer.keys()) {
|
|
1750
|
+
if (isListCacheKey(cacheKey)) {
|
|
1751
|
+
if (!changes || !changes.modified.has(cacheKey)) {
|
|
1752
|
+
const promise = this.peekQuery(cacheKey)?.revalidate(true);
|
|
1542
1753
|
if (promise) {
|
|
1543
1754
|
promises.push(promise);
|
|
1544
|
-
changes?.
|
|
1755
|
+
changes?.modified.add(cacheKey);
|
|
1545
1756
|
}
|
|
1546
1757
|
}
|
|
1547
1758
|
}
|
|
1548
1759
|
}
|
|
1549
|
-
return Promise.all(promises);
|
|
1550
|
-
}
|
|
1551
|
-
invalidateList({
|
|
1552
|
-
objectType,
|
|
1553
|
-
where,
|
|
1554
|
-
orderBy
|
|
1555
|
-
}) {
|
|
1556
|
-
if (typeof objectType !== "string") {
|
|
1557
|
-
objectType = objectType.apiName;
|
|
1558
|
-
}
|
|
1559
|
-
where = this.whereCanonicalizer.canonicalize(where ?? {});
|
|
1560
|
-
orderBy = this.orderByCanonicalizer.canonicalize(orderBy ?? {});
|
|
1561
|
-
const cacheKey = this.getCacheKey("list", objectType, where, orderBy);
|
|
1562
|
-
void this.#peekQuery(cacheKey)?.revalidate(true);
|
|
1563
|
-
}
|
|
1564
|
-
updateObject(apiName, value, {
|
|
1565
|
-
optimisticId
|
|
1566
|
-
} = {}) {
|
|
1567
|
-
if (typeof apiName !== "string") {
|
|
1568
|
-
apiName = apiName.apiName;
|
|
1569
|
-
}
|
|
1570
|
-
const query = this.getObjectQuery(apiName, value.$primaryKey);
|
|
1571
|
-
return this.batch({
|
|
1572
|
-
optimisticId
|
|
1573
|
-
}, (batch) => {
|
|
1574
|
-
return query.writeToStore(value, "loaded", batch);
|
|
1575
|
-
}).retVal.value;
|
|
1576
|
-
}
|
|
1577
|
-
updateObjects(values, batch) {
|
|
1578
|
-
return values.map((v) => {
|
|
1579
|
-
return this.getObjectQuery(v.$apiName, v.$primaryKey).writeToStore(v, "loaded", batch).cacheKey;
|
|
1580
|
-
});
|
|
1581
|
-
}
|
|
1582
|
-
/**
|
|
1583
|
-
* Updates the internal state of a list and will create a new internal query if needed.
|
|
1584
|
-
*
|
|
1585
|
-
* Helper method only for tests right now. May be removed later.
|
|
1586
|
-
*
|
|
1587
|
-
* @param apiName
|
|
1588
|
-
* @param where
|
|
1589
|
-
* @param orderBy
|
|
1590
|
-
* @param objects
|
|
1591
|
-
* @param param4
|
|
1592
|
-
* @param opts
|
|
1593
|
-
*/
|
|
1594
|
-
updateList({
|
|
1595
|
-
objectType: apiName,
|
|
1596
|
-
where,
|
|
1597
|
-
orderBy
|
|
1598
|
-
}, objects, {
|
|
1599
|
-
optimisticId
|
|
1600
|
-
} = {}, opts = {
|
|
1601
|
-
dedupeInterval: 0
|
|
1602
|
-
}) {
|
|
1603
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1604
|
-
this.logger?.info({
|
|
1605
|
-
methodName: "updateList"
|
|
1606
|
-
}, "", {
|
|
1607
|
-
optimisticId
|
|
1608
|
-
});
|
|
1609
|
-
}
|
|
1610
|
-
const query = this.getListQuery(apiName, where ?? {}, orderBy ?? {}, opts);
|
|
1611
|
-
this.batch({
|
|
1612
|
-
optimisticId
|
|
1613
|
-
}, (batch) => {
|
|
1614
|
-
const objectCacheKeys = this.updateObjects(objects, batch);
|
|
1615
|
-
query.updateList(objectCacheKeys, false, "loaded", batch);
|
|
1616
|
-
});
|
|
1760
|
+
return Promise.all(promises).then(() => undefined);
|
|
1617
1761
|
}
|
|
1618
1762
|
retain(cacheKey) {
|
|
1619
1763
|
this.#refCounts.retain(cacheKey);
|
|
@@ -1630,7 +1774,7 @@ function createObservableClient(client) {
|
|
|
1630
1774
|
|
|
1631
1775
|
Object.defineProperty(exports, "augment", {
|
|
1632
1776
|
enumerable: true,
|
|
1633
|
-
get: function () { return
|
|
1777
|
+
get: function () { return chunkEY52J5Z4_cjs.augment; }
|
|
1634
1778
|
});
|
|
1635
1779
|
exports.createObservableClient = createObservableClient;
|
|
1636
1780
|
//# sourceMappingURL=unstable-do-not-use.cjs.map
|