@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
|
@@ -15,34 +15,134 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import deepEqual from "fast-deep-equal";
|
|
18
|
-
import
|
|
18
|
+
import groupBy from "object.groupby";
|
|
19
|
+
import { auditTime, combineLatest, connectable, map, of, ReplaySubject, switchMap } from "rxjs";
|
|
19
20
|
import invariant from "tiny-invariant";
|
|
20
21
|
import { additionalContext } from "../../Client.js";
|
|
22
|
+
import { ObjectDefRef, UnderlyingOsdkObject } from "../../object/convertWireToOsdkObjects/InternalSymbols.js";
|
|
21
23
|
import { DEBUG_ONLY__cacheKeysToString } from "./CacheKey.js";
|
|
22
|
-
import { DEBUG_ONLY__changesToString } from "./
|
|
23
|
-
import { objectSortaMatchesWhereClause } from "./objectMatchesWhereClause.js";
|
|
24
|
+
import { DEBUG_ONLY__changesToString } from "./Changes.js";
|
|
25
|
+
import { objectSortaMatchesWhereClause as objectMatchesWhereClause } from "./objectMatchesWhereClause.js";
|
|
26
|
+
import { storeOsdkInstances } from "./ObjectQuery.js";
|
|
24
27
|
import { Query } from "./Query.js";
|
|
25
|
-
export
|
|
28
|
+
export const API_NAME_IDX = 1;
|
|
29
|
+
export const TYPE_IDX = 0;
|
|
30
|
+
export const WHERE_IDX = 2;
|
|
31
|
+
export const ORDER_BY_IDX = 3;
|
|
32
|
+
class BaseListQuery extends Query {
|
|
33
|
+
//
|
|
34
|
+
// Per list type implementations
|
|
35
|
+
//
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
// Shared Implementations
|
|
39
|
+
//
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Only intended to be "protected" and used by subclasses but exposed for
|
|
43
|
+
* testing.
|
|
44
|
+
*
|
|
45
|
+
* @param objectCacheKeys
|
|
46
|
+
* @param append
|
|
47
|
+
* @param status
|
|
48
|
+
* @param batch
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
_updateList(objectCacheKeys, append, status, batch) {
|
|
52
|
+
if (process.env.NODE_ENV !== "production") {
|
|
53
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
54
|
+
methodName: "updateList"
|
|
55
|
+
}) : this.logger;
|
|
56
|
+
logger?.debug(`{status: ${status}}`, JSON.stringify(objectCacheKeys, null, 2));
|
|
57
|
+
}
|
|
58
|
+
objectCacheKeys = this.#retainReleaseAppend(batch, append, objectCacheKeys);
|
|
59
|
+
objectCacheKeys = this._sortCacheKeys(objectCacheKeys, batch);
|
|
60
|
+
objectCacheKeys = removeDuplicates(objectCacheKeys, batch);
|
|
61
|
+
return this.writeToStore({
|
|
62
|
+
data: objectCacheKeys
|
|
63
|
+
}, status, batch);
|
|
64
|
+
}
|
|
65
|
+
writeToStore(data, status, batch) {
|
|
66
|
+
const entry = batch.read(this.cacheKey);
|
|
67
|
+
if (entry && deepEqual(data, entry.value)) {
|
|
68
|
+
if (process.env.NODE_ENV !== "production") {
|
|
69
|
+
this.logger?.child({
|
|
70
|
+
methodName: "writeToStore"
|
|
71
|
+
}).debug(`Object was deep equal, just setting status`);
|
|
72
|
+
}
|
|
73
|
+
return batch.write(this.cacheKey, entry.value, status);
|
|
74
|
+
}
|
|
75
|
+
if (process.env.NODE_ENV !== "production") {
|
|
76
|
+
this.logger?.child({
|
|
77
|
+
methodName: "writeToStore"
|
|
78
|
+
}).debug(`{status: ${status}},`, DEBUG_ONLY__cacheKeysToString(data.data));
|
|
79
|
+
}
|
|
80
|
+
const ret = batch.write(this.cacheKey, data, status);
|
|
81
|
+
batch.changes.registerList(this.cacheKey);
|
|
82
|
+
return ret;
|
|
83
|
+
}
|
|
84
|
+
#retainReleaseAppend(batch, append, objectCacheKeys) {
|
|
85
|
+
const existingList = batch.read(this.cacheKey);
|
|
86
|
+
|
|
87
|
+
// whether its append or update we need to retain all the new objects
|
|
88
|
+
if (!batch.optimisticWrite) {
|
|
89
|
+
if (!append) {
|
|
90
|
+
// we need to release all the old objects
|
|
91
|
+
// N.B. the store keeps the cache keys around for a bit so we don't
|
|
92
|
+
// need to worry about them being GC'd before we re-retain them
|
|
93
|
+
for (const objectCacheKey of existingList?.value?.data ?? []) {
|
|
94
|
+
this.store.release(objectCacheKey);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const objectCacheKey of objectCacheKeys) {
|
|
98
|
+
this.store.retain(objectCacheKey);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (append) {
|
|
102
|
+
objectCacheKeys = [...(existingList?.value?.data ?? []), ...objectCacheKeys];
|
|
103
|
+
}
|
|
104
|
+
return objectCacheKeys;
|
|
105
|
+
}
|
|
106
|
+
_dispose() {
|
|
107
|
+
// eslint-disable-next-line no-console
|
|
108
|
+
console.log("DISPOSE LIST QUERY");
|
|
109
|
+
this.store.batch({}, batch => {
|
|
110
|
+
const entry = batch.read(this.cacheKey);
|
|
111
|
+
if (entry) {
|
|
112
|
+
for (const objectCacheKey of entry.value?.data ?? []) {
|
|
113
|
+
this.store.release(objectCacheKey);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export class ListQuery extends BaseListQuery {
|
|
26
120
|
// pageSize?: number; // this is the internal page size. we need to track this properly
|
|
27
|
-
|
|
121
|
+
|
|
28
122
|
#type;
|
|
123
|
+
#apiName;
|
|
29
124
|
#whereClause;
|
|
30
125
|
|
|
31
126
|
// this represents the minimum number of results we need to load if we revalidate
|
|
32
127
|
#minNumResults = 0;
|
|
33
128
|
#nextPageToken;
|
|
34
129
|
#pendingPageFetch;
|
|
35
|
-
#toRelease = new Set();
|
|
36
130
|
#orderBy;
|
|
37
|
-
|
|
131
|
+
#objectSet;
|
|
132
|
+
#sortFns;
|
|
133
|
+
constructor(store, subject, apiType, apiName, whereClause, orderBy, cacheKey, opts) {
|
|
38
134
|
super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[additionalContext].logger?.child({}, {
|
|
39
135
|
msgPrefix: `ListQuery<${cacheKey.otherKeys.map(x => JSON.stringify(x)).join(", ")}>`
|
|
40
136
|
}) : undefined);
|
|
41
|
-
this.#
|
|
42
|
-
this.#
|
|
137
|
+
this.#type = apiType;
|
|
138
|
+
this.#apiName = apiName;
|
|
43
139
|
this.#whereClause = whereClause;
|
|
44
140
|
this.#orderBy = orderBy;
|
|
45
|
-
|
|
141
|
+
this.#objectSet = store.client({
|
|
142
|
+
type: this.#type,
|
|
143
|
+
apiName: this.#apiName
|
|
144
|
+
}).where(this.#whereClause);
|
|
145
|
+
this.#sortFns = createOrderBySortFns(this.#orderBy);
|
|
46
146
|
}
|
|
47
147
|
get canonicalWhere() {
|
|
48
148
|
return this.#whereClause;
|
|
@@ -67,13 +167,14 @@ export class ListQuery extends Query {
|
|
|
67
167
|
_preFetch() {
|
|
68
168
|
this.#nextPageToken = undefined;
|
|
69
169
|
}
|
|
70
|
-
async
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
170
|
+
async _fetchAndStore() {
|
|
171
|
+
if (process.env.NODE_ENV !== "production") {
|
|
172
|
+
this.logger?.child({
|
|
173
|
+
methodName: "_fetchAndStore"
|
|
174
|
+
}).info("fetching pages");
|
|
175
|
+
}
|
|
75
176
|
while (true) {
|
|
76
|
-
const entry = await this.#fetchPageAndUpdate(objectSet, "loading", this.abortController?.signal);
|
|
177
|
+
const entry = await this.#fetchPageAndUpdate(this.#objectSet, "loading", this.abortController?.signal);
|
|
77
178
|
if (!entry) {
|
|
78
179
|
// we were aborted
|
|
79
180
|
return;
|
|
@@ -106,41 +207,78 @@ export class ListQuery extends Query {
|
|
|
106
207
|
this.store.batch({}, batch => {
|
|
107
208
|
this.setStatus("loading", batch);
|
|
108
209
|
});
|
|
109
|
-
|
|
110
|
-
type: "object",
|
|
111
|
-
apiName: this.#type
|
|
112
|
-
}).where(this.#whereClause);
|
|
113
|
-
this.pendingFetch = this.#fetchPageAndUpdate(objectSet, "loaded", this.abortController?.signal).finally(() => {
|
|
210
|
+
this.pendingFetch = this.#fetchPageAndUpdate(this.#objectSet, "loaded", this.abortController?.signal).finally(() => {
|
|
114
211
|
this.#pendingPageFetch = undefined;
|
|
115
212
|
});
|
|
116
213
|
return this.pendingFetch;
|
|
117
214
|
};
|
|
118
215
|
async #fetchPageAndUpdate(objectSet, status, signal) {
|
|
119
216
|
const append = this.#nextPageToken != null;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
217
|
+
try {
|
|
218
|
+
let {
|
|
219
|
+
data,
|
|
220
|
+
nextPageToken
|
|
221
|
+
} = await objectSet.fetchPage({
|
|
222
|
+
$nextPageToken: this.#nextPageToken,
|
|
223
|
+
$pageSize: this.options.pageSize,
|
|
224
|
+
// For now this keeps the shared test code from falling apart
|
|
225
|
+
// but shouldn't be needed ideally
|
|
226
|
+
...(Object.keys(this.#orderBy).length > 0 ? {
|
|
227
|
+
$orderBy: this.#orderBy
|
|
228
|
+
} : {})
|
|
229
|
+
});
|
|
230
|
+
if (signal?.aborted) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
this.#nextPageToken = nextPageToken;
|
|
234
|
+
|
|
235
|
+
// Our caching really expects to have the full objects in the list
|
|
236
|
+
// so we need to fetch them all here
|
|
237
|
+
if (this.#type === "interface") {
|
|
238
|
+
data = await reloadDataAsFullObjects(this.store.client, data);
|
|
239
|
+
}
|
|
240
|
+
const {
|
|
241
|
+
retVal
|
|
242
|
+
} = this.store.batch({}, batch => {
|
|
243
|
+
return this._updateList(storeOsdkInstances(this.store, data, batch), append, nextPageToken ? status : "loaded", batch);
|
|
244
|
+
});
|
|
245
|
+
return retVal;
|
|
246
|
+
} catch (e) {
|
|
247
|
+
this.logger?.error("error", e);
|
|
248
|
+
this.store.getSubject(this.cacheKey).error(e);
|
|
249
|
+
|
|
250
|
+
// rethrowing would result in many unhandled promise rejections
|
|
251
|
+
// which i don't think we want
|
|
252
|
+
// throw e;
|
|
134
253
|
}
|
|
135
|
-
this.#nextPageToken = nextPageToken;
|
|
136
|
-
const {
|
|
137
|
-
retVal
|
|
138
|
-
} = this.store.batch({}, batch => {
|
|
139
|
-
return this.updateList(this.store.updateObjects(data, batch), append, nextPageToken ? status : "loaded", batch);
|
|
140
|
-
});
|
|
141
|
-
return retVal;
|
|
142
254
|
}
|
|
143
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Will revalidate the list if its query is affected by invalidating the
|
|
258
|
+
* apiName of the object type passed in.
|
|
259
|
+
*
|
|
260
|
+
* @param apiName to invalidate
|
|
261
|
+
* @returns
|
|
262
|
+
*/
|
|
263
|
+
revalidateObjectType = async apiName => {
|
|
264
|
+
if (this.#type === "object") {
|
|
265
|
+
if (this.#apiName === apiName) {
|
|
266
|
+
await this.revalidate(/* force */true);
|
|
267
|
+
return;
|
|
268
|
+
} else {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
//
|
|
273
|
+
const objectMetadata = await this.store.client.fetchMetadata({
|
|
274
|
+
type: "object",
|
|
275
|
+
apiName
|
|
276
|
+
});
|
|
277
|
+
if (this.#apiName in objectMetadata.interfaceMap) {
|
|
278
|
+
await this.revalidate(/* force */true);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
144
282
|
/**
|
|
145
283
|
* Note: This method is not async because I want it to return right after it
|
|
146
284
|
* finishes the synchronous updates. The promise that is returned
|
|
@@ -153,45 +291,19 @@ export class ListQuery extends Query {
|
|
|
153
291
|
|
|
154
292
|
maybeUpdateAndRevalidate = (changes, optimisticId) => {
|
|
155
293
|
if (process.env.NODE_ENV !== "production") {
|
|
156
|
-
this.logger?.
|
|
157
|
-
methodName: "
|
|
158
|
-
}
|
|
294
|
+
this.logger?.child({
|
|
295
|
+
methodName: "maybeUpdateAndRevalidate"
|
|
296
|
+
}).debug(DEBUG_ONLY__changesToString(changes));
|
|
159
297
|
}
|
|
160
|
-
if (changes.
|
|
298
|
+
if (changes.modified.has(this.cacheKey)) return;
|
|
299
|
+
// mark ourselves as updated so we don't infinite recurse.
|
|
300
|
+
changes.modified.add(this.cacheKey);
|
|
161
301
|
try {
|
|
162
|
-
const relevantObjects =
|
|
163
|
-
added: {
|
|
164
|
-
all: changes.addedObjects.get(this.cacheKey.otherKeys[0]) ?? [],
|
|
165
|
-
strictMatches: new Set(),
|
|
166
|
-
sortaMatches: new Set()
|
|
167
|
-
},
|
|
168
|
-
modified: {
|
|
169
|
-
all: changes.modifiedObjects.get(this.cacheKey.otherKeys[0]) ?? [],
|
|
170
|
-
strictMatches: new Set(),
|
|
171
|
-
sortaMatches: new Set()
|
|
172
|
-
}
|
|
173
|
-
};
|
|
302
|
+
const relevantObjects = this._extractRelevantObjects(changes);
|
|
174
303
|
if (relevantObjects.added.all.length === 0 && relevantObjects.modified.all.length === 0) {
|
|
175
304
|
return;
|
|
176
305
|
}
|
|
177
306
|
|
|
178
|
-
// categorize
|
|
179
|
-
for (const group of Object.values(relevantObjects)) {
|
|
180
|
-
for (const obj of group.all ?? []) {
|
|
181
|
-
// if its a strict match we can just insert it into place
|
|
182
|
-
const strictMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, true);
|
|
183
|
-
if (strictMatch) {
|
|
184
|
-
group.strictMatches.add(obj);
|
|
185
|
-
} else {
|
|
186
|
-
// sorta match means it used a filter we cannot use on the frontend
|
|
187
|
-
const sortaMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, false);
|
|
188
|
-
if (sortaMatch) {
|
|
189
|
-
group.sortaMatches.add(obj);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
307
|
// If we got purely strict matches we can just update the list and move
|
|
196
308
|
// on with our lives. But if we got sorta matches, then we need to revalidate
|
|
197
309
|
// the list so we preemptively set it to loading to avoid thrashing the store.
|
|
@@ -200,16 +312,13 @@ export class ListQuery extends Query {
|
|
|
200
312
|
// while we only push updates for the strict matches, we still need to
|
|
201
313
|
// trigger the list updating if some of our objects changed
|
|
202
314
|
|
|
203
|
-
// mark ourselves as updated so we don't infinite recurse.
|
|
204
|
-
changes.modifiedLists.add(this.cacheKey);
|
|
205
315
|
const newList = [];
|
|
206
316
|
let needsRevalidation = false;
|
|
207
317
|
this.store.batch({
|
|
208
318
|
optimisticId,
|
|
209
319
|
changes
|
|
210
320
|
}, batch => {
|
|
211
|
-
const
|
|
212
|
-
const existingList = new Set(curValue?.value?.data);
|
|
321
|
+
const existingList = new Set(batch.read(this.cacheKey)?.value?.data);
|
|
213
322
|
const toAdd = new Set(
|
|
214
323
|
// easy case. objects are new to the cache and they match this filter
|
|
215
324
|
relevantObjects.added.strictMatches);
|
|
@@ -218,10 +327,8 @@ export class ListQuery extends Query {
|
|
|
218
327
|
// deal with the modified objects
|
|
219
328
|
for (const obj of relevantObjects.modified.all) {
|
|
220
329
|
if (relevantObjects.modified.strictMatches.has(obj)) {
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
// full match and already there, do nothing
|
|
224
|
-
if (!existingList.has(existingObjectCacheKey)) {
|
|
330
|
+
const objectCacheKey = this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey);
|
|
331
|
+
if (!existingList.has(objectCacheKey)) {
|
|
225
332
|
// object is new to the list
|
|
226
333
|
toAdd.add(obj);
|
|
227
334
|
}
|
|
@@ -233,7 +340,7 @@ export class ListQuery extends Query {
|
|
|
233
340
|
continue;
|
|
234
341
|
} else {
|
|
235
342
|
// object is no longer a strict match
|
|
236
|
-
const existingObjectCacheKey = this.store.getCacheKey("object", obj.$
|
|
343
|
+
const existingObjectCacheKey = this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey);
|
|
237
344
|
toRemove.add(existingObjectCacheKey);
|
|
238
345
|
if (relevantObjects.modified.sortaMatches.has(obj)) {
|
|
239
346
|
// since it might still be in the list we need to revalidate
|
|
@@ -246,79 +353,83 @@ export class ListQuery extends Query {
|
|
|
246
353
|
newList.push(key);
|
|
247
354
|
}
|
|
248
355
|
for (const obj of toAdd) {
|
|
249
|
-
newList.push(this.store.getCacheKey("object", obj.$
|
|
356
|
+
newList.push(this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey));
|
|
250
357
|
}
|
|
251
|
-
this.
|
|
358
|
+
this._updateList(newList, /* append */false, status, batch);
|
|
252
359
|
});
|
|
253
360
|
if (needsRevalidation) {
|
|
254
|
-
|
|
255
|
-
return this.revalidate(true).then(() => void 0); // strip return value
|
|
361
|
+
return this.revalidate(true);
|
|
256
362
|
}
|
|
257
363
|
return undefined;
|
|
258
364
|
} finally {
|
|
259
365
|
if (process.env.NODE_ENV !== "production") {
|
|
260
|
-
this.logger?.
|
|
261
|
-
methodName: "
|
|
262
|
-
}
|
|
366
|
+
this.logger?.child({
|
|
367
|
+
methodName: "maybeUpdateAndRevalidate"
|
|
368
|
+
}).debug("in finally");
|
|
263
369
|
}
|
|
264
370
|
}
|
|
265
371
|
};
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
methodName: "updateList"
|
|
270
|
-
}, `{status: ${status}}`, JSON.stringify(objectCacheKeys, null, 2));
|
|
271
|
-
}
|
|
272
|
-
const existingList = batch.read(this.cacheKey);
|
|
372
|
+
_extractRelevantObjects(changes) {
|
|
373
|
+
// TODO refactor this ternary into subclasses
|
|
374
|
+
const relevantObjects = this.#type === "object" ? this.#extractRelevantObjectsForTypeObject(changes) : this.#extractRelevantObjectsForTypeInterface(changes);
|
|
273
375
|
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
// we
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
376
|
+
// categorize
|
|
377
|
+
for (const group of Object.values(relevantObjects)) {
|
|
378
|
+
for (const obj of group.all ?? []) {
|
|
379
|
+
// if its a strict match we can just insert it into place
|
|
380
|
+
const strictMatch = objectMatchesWhereClause(obj, this.#whereClause, true);
|
|
381
|
+
if (strictMatch) {
|
|
382
|
+
group.strictMatches.add(obj);
|
|
383
|
+
} else {
|
|
384
|
+
// sorta match means it used a filter we cannot use on the frontend
|
|
385
|
+
const sortaMatch = objectMatchesWhereClause(obj, this.#whereClause, false);
|
|
386
|
+
if (sortaMatch) {
|
|
387
|
+
group.sortaMatches.add(obj);
|
|
388
|
+
}
|
|
283
389
|
}
|
|
284
390
|
}
|
|
285
|
-
for (const objectCacheKey of objectCacheKeys) {
|
|
286
|
-
this.#toRelease.add(objectCacheKey);
|
|
287
|
-
this.store.retain(objectCacheKey);
|
|
288
|
-
}
|
|
289
391
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
392
|
+
return relevantObjects;
|
|
393
|
+
}
|
|
394
|
+
#extractRelevantObjectsForTypeInterface(changes) {
|
|
395
|
+
const added = Array.from(changes.addedObjects).filter(([, object]) => {
|
|
396
|
+
return this.#apiName in object[ObjectDefRef].interfaceMap;
|
|
397
|
+
}).map(([, object]) => object.$as(this.#apiName));
|
|
398
|
+
const modified = Array.from(changes.modifiedObjects).filter(([, object]) => {
|
|
399
|
+
return this.#apiName in object[ObjectDefRef].interfaceMap;
|
|
400
|
+
}).map(([, object]) => object.$as(this.#apiName));
|
|
401
|
+
return {
|
|
402
|
+
added: {
|
|
403
|
+
all: added,
|
|
404
|
+
strictMatches: new Set(),
|
|
405
|
+
sortaMatches: new Set()
|
|
406
|
+
},
|
|
407
|
+
modified: {
|
|
408
|
+
all: modified,
|
|
409
|
+
strictMatches: new Set(),
|
|
410
|
+
sortaMatches: new Set()
|
|
301
411
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
#extractRelevantObjectsForTypeObject(changes) {
|
|
415
|
+
return {
|
|
416
|
+
added: {
|
|
417
|
+
all: changes.addedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
|
|
418
|
+
strictMatches: new Set(),
|
|
419
|
+
sortaMatches: new Set()
|
|
420
|
+
},
|
|
421
|
+
modified: {
|
|
422
|
+
all: changes.modifiedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
|
|
423
|
+
strictMatches: new Set(),
|
|
424
|
+
sortaMatches: new Set()
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
_sortCacheKeys(objectCacheKeys, batch) {
|
|
429
|
+
if (Object.keys(this.#orderBy).length > 0) {
|
|
319
430
|
objectCacheKeys = objectCacheKeys.sort((a, b) => {
|
|
320
|
-
for (const sortFn of sortFns) {
|
|
321
|
-
const ret = sortFn(batch.read(a)?.value, batch.read(b)?.value);
|
|
431
|
+
for (const sortFn of this.#sortFns) {
|
|
432
|
+
const ret = sortFn(batch.read(a)?.value?.$as(this.#apiName), batch.read(b)?.value?.$as(this.#apiName));
|
|
322
433
|
if (ret !== 0) {
|
|
323
434
|
return ret;
|
|
324
435
|
}
|
|
@@ -326,47 +437,177 @@ export class ListQuery extends Query {
|
|
|
326
437
|
return 0;
|
|
327
438
|
});
|
|
328
439
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
440
|
+
return objectCacheKeys;
|
|
441
|
+
}
|
|
442
|
+
registerStreamUpdates(sub) {
|
|
443
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
444
|
+
methodName: "registerStreamUpdates"
|
|
445
|
+
}) : this.logger;
|
|
446
|
+
if (process.env.NODE_ENV !== "production") {
|
|
447
|
+
logger?.child({
|
|
448
|
+
methodName: "observeList"
|
|
449
|
+
}).info("Subscribing from websocket");
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// FIXME: We should only do this once. If we already have one we should probably
|
|
453
|
+
// just reuse it.
|
|
454
|
+
|
|
455
|
+
const websocketSubscription = this.#objectSet.subscribe({
|
|
456
|
+
onChange: this.#onOswChange.bind(this),
|
|
457
|
+
onError: this.#onOswError.bind(this),
|
|
458
|
+
onOutOfDate: this.#onOswOutOfDate.bind(this),
|
|
459
|
+
onSuccessfulSubscription: this.#onOswSuccessfulSubscription.bind(this)
|
|
460
|
+
});
|
|
461
|
+
sub.add(() => {
|
|
462
|
+
if (process.env.NODE_ENV !== "production") {
|
|
463
|
+
logger?.child({
|
|
464
|
+
methodName: "observeList"
|
|
465
|
+
}).info("Unsubscribing from websocket");
|
|
334
466
|
}
|
|
335
|
-
|
|
336
|
-
return true;
|
|
467
|
+
websocketSubscription.unsubscribe();
|
|
337
468
|
});
|
|
338
|
-
return this.writeToStore({
|
|
339
|
-
data: objectCacheKeys
|
|
340
|
-
}, status, batch);
|
|
341
469
|
}
|
|
342
|
-
|
|
470
|
+
#onOswSuccessfulSubscription() {
|
|
343
471
|
if (process.env.NODE_ENV !== "production") {
|
|
344
|
-
this.logger?.
|
|
345
|
-
methodName: "
|
|
346
|
-
}
|
|
472
|
+
this.logger?.child({
|
|
473
|
+
methodName: "onSuccessfulSubscription"
|
|
474
|
+
}).debug("");
|
|
347
475
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
476
|
+
}
|
|
477
|
+
#onOswOutOfDate() {
|
|
478
|
+
if (process.env.NODE_ENV !== "production") {
|
|
479
|
+
this.logger?.child({
|
|
480
|
+
methodName: "onOutOfDate"
|
|
481
|
+
}).info("");
|
|
351
482
|
}
|
|
352
|
-
const ret = batch.write(this.cacheKey, data, status);
|
|
353
|
-
batch.changes.modifiedLists.add(this.cacheKey);
|
|
354
|
-
return ret;
|
|
355
483
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
484
|
+
#onOswError(errors) {
|
|
485
|
+
if (this.logger) {
|
|
486
|
+
this.logger?.child({
|
|
487
|
+
methodName: "onError"
|
|
488
|
+
}).error("subscription errors", errors);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
#onOswChange({
|
|
492
|
+
object: objOrIface,
|
|
493
|
+
state
|
|
494
|
+
}) {
|
|
495
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
496
|
+
methodName: "registerStreamUpdates"
|
|
497
|
+
}) : this.logger;
|
|
498
|
+
if (process.env.NODE_ENV !== "production") {
|
|
499
|
+
logger?.child({
|
|
500
|
+
methodName: "onChange"
|
|
501
|
+
}).debug(`Got an update of type: ${state}`, objOrIface);
|
|
502
|
+
}
|
|
503
|
+
if (state === "ADDED_OR_UPDATED") {
|
|
504
|
+
const object = objOrIface.$apiName !== objOrIface.$objectType ? objOrIface.$as(objOrIface.$objectType) : objOrIface;
|
|
505
|
+
this.store.batch({}, batch => {
|
|
506
|
+
storeOsdkInstances(this.store, [object], batch);
|
|
507
|
+
});
|
|
508
|
+
} else if (state === "REMOVED") {
|
|
509
|
+
this.#onOswRemoved(objOrIface, logger);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
#onOswRemoved(objOrIface, logger) {
|
|
359
513
|
this.store.batch({}, batch => {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
514
|
+
// Read the truth layer (since not optimistic)
|
|
515
|
+
const existing = batch.read(this.cacheKey);
|
|
516
|
+
!existing ? process.env.NODE_ENV !== "production" ? invariant(false, "the truth value for our list should exist as we already subscribed") : invariant(false) : void 0;
|
|
517
|
+
if (existing.status === "loaded") {
|
|
518
|
+
const objectCacheKey = this.store.getCacheKey("object", objOrIface.$objectType, objOrIface.$primaryKey);
|
|
519
|
+
// remove the object from the list
|
|
520
|
+
const newObjects = existing.value?.data.filter(o => o !== objectCacheKey);
|
|
521
|
+
|
|
522
|
+
// If the filter didn't change anything, then the list was already
|
|
523
|
+
// updated (or didn't exist, which is nonsensical)
|
|
524
|
+
if (newObjects?.length !== existing.value?.data.length) {
|
|
525
|
+
batch.changes.registerList(this.cacheKey);
|
|
526
|
+
batch.write(this.cacheKey, {
|
|
527
|
+
data: newObjects ?? []
|
|
528
|
+
}, "loaded");
|
|
529
|
+
// Should there be an else for this case? Do we need to invalidate
|
|
530
|
+
// the paging tokens we may have? FIXME
|
|
364
531
|
}
|
|
532
|
+
return;
|
|
365
533
|
}
|
|
534
|
+
// There may be a tiny race here where OSW tells us the object has
|
|
535
|
+
// been removed but an outstanding invalidation of this query is
|
|
536
|
+
// about to return. In this case, its possible that we remove this item
|
|
537
|
+
// from the list and then the returned list load re-adds it.
|
|
538
|
+
// To avoid this, we will just force reload the query to be sure
|
|
539
|
+
// we don't leave things in a bad state.
|
|
540
|
+
if (process.env.NODE_ENV !== "production") {
|
|
541
|
+
logger?.info("Removing an object from an object list that is in the middle of being loaded.", existing);
|
|
542
|
+
}
|
|
543
|
+
this.revalidate(/* force */true).catch(e => {
|
|
544
|
+
if (logger) {
|
|
545
|
+
logger?.error("Uncaught error while revalidating list", e);
|
|
546
|
+
} else {
|
|
547
|
+
// Make sure we write to the console if there is no logger!
|
|
548
|
+
// eslint-disable-next-line no-console
|
|
549
|
+
console.error("Uncaught error while revalidating list", e);
|
|
550
|
+
}
|
|
551
|
+
});
|
|
366
552
|
});
|
|
367
553
|
}
|
|
368
554
|
}
|
|
369
|
-
|
|
370
|
-
|
|
555
|
+
function removeDuplicates(objectCacheKeys, batch) {
|
|
556
|
+
const visited = new Set();
|
|
557
|
+
objectCacheKeys = objectCacheKeys.filter(key => {
|
|
558
|
+
batch.read(key);
|
|
559
|
+
if (visited.has(key)) {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
visited.add(key);
|
|
563
|
+
return true;
|
|
564
|
+
});
|
|
565
|
+
return objectCacheKeys;
|
|
371
566
|
}
|
|
567
|
+
function createOrderBySortFns(orderBy) {
|
|
568
|
+
return Object.entries(orderBy).map(([key, order]) => {
|
|
569
|
+
return (a, b) => {
|
|
570
|
+
const aValue = a?.[key];
|
|
571
|
+
const bValue = b?.[key];
|
|
572
|
+
if (aValue == null && bValue == null) {
|
|
573
|
+
return 0;
|
|
574
|
+
}
|
|
575
|
+
if (aValue == null) {
|
|
576
|
+
return 1;
|
|
577
|
+
}
|
|
578
|
+
if (bValue == null) {
|
|
579
|
+
return -1;
|
|
580
|
+
}
|
|
581
|
+
const m = order === "asc" ? -1 : 1;
|
|
582
|
+
return aValue < bValue ? m : aValue > bValue ? -m : 0;
|
|
583
|
+
};
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Hopefully this can go away when we can just request the full object properties on first load
|
|
588
|
+
async function reloadDataAsFullObjects(client, data) {
|
|
589
|
+
const groups = groupBy(data, x => x.$objectType);
|
|
590
|
+
const objectTypeToPrimaryKeyToObject = Object.fromEntries(await Promise.all(Object.entries(groups).map(async ([apiName, objects]) => {
|
|
591
|
+
// to keep InternalSimpleOsdkInstance simple, we make both the `ObjectDefRef` and
|
|
592
|
+
// the `InterfaceDefRef` optional but we know that the right one is on there
|
|
593
|
+
// thus we can `!`
|
|
594
|
+
const objectDef = objects[0][UnderlyingOsdkObject][ObjectDefRef];
|
|
595
|
+
const where = {
|
|
596
|
+
[objectDef.primaryKeyApiName]: {
|
|
597
|
+
$in: objects.map(x => x.$primaryKey)
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
const result = await client(objectDef).where(where).fetchPage();
|
|
601
|
+
return [apiName, Object.fromEntries(result.data.map(x => [x.$primaryKey, x]))];
|
|
602
|
+
})));
|
|
603
|
+
data = data.map(obj => objectTypeToPrimaryKeyToObject[obj.$objectType][obj.$primaryKey]);
|
|
604
|
+
return data;
|
|
605
|
+
}
|
|
606
|
+
export function isListCacheKey(cacheKey) {
|
|
607
|
+
return cacheKey.type === "list";
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Copied from @osdk/api
|
|
612
|
+
*/
|
|
372
613
|
//# sourceMappingURL=ListQuery.js.map
|