houdini 1.1.1 → 1.1.2
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/build/cmd-cjs/index.js +92 -44
- package/build/cmd-esm/index.js +92 -44
- package/build/codegen-cjs/index.js +90 -42
- package/build/codegen-esm/index.js +90 -42
- package/build/lib-cjs/index.js +41 -21
- package/build/lib-esm/index.js +41 -21
- package/build/runtime/cache/lists.d.ts +21 -4
- package/build/runtime-cjs/cache/cache.js +16 -13
- package/build/runtime-cjs/cache/lists.d.ts +21 -4
- package/build/runtime-cjs/cache/lists.js +25 -8
- package/build/runtime-cjs/public/list.js +13 -3
- package/build/runtime-esm/cache/cache.js +16 -13
- package/build/runtime-esm/cache/lists.d.ts +21 -4
- package/build/runtime-esm/cache/lists.js +25 -8
- package/build/runtime-esm/public/list.js +13 -3
- package/build/test-cjs/index.js +122 -42
- package/build/test-esm/index.js +122 -42
- package/build/vite-cjs/index.js +90 -42
- package/build/vite-esm/index.js +90 -42
- package/package.json +1 -1
package/build/lib-esm/index.js
CHANGED
|
@@ -63773,13 +63773,23 @@ var List = class {
|
|
|
63773
63773
|
when(when) {
|
|
63774
63774
|
return this.manager.lists.get(this.name).get(this.recordID).when(when);
|
|
63775
63775
|
}
|
|
63776
|
-
append(
|
|
63777
|
-
|
|
63776
|
+
append({
|
|
63777
|
+
selection,
|
|
63778
|
+
data,
|
|
63779
|
+
variables = {},
|
|
63780
|
+
layer
|
|
63781
|
+
}) {
|
|
63782
|
+
return this.addToList(selection, data, variables, "last", layer);
|
|
63778
63783
|
}
|
|
63779
|
-
prepend(
|
|
63780
|
-
|
|
63784
|
+
prepend({
|
|
63785
|
+
selection,
|
|
63786
|
+
data,
|
|
63787
|
+
variables = {},
|
|
63788
|
+
layer
|
|
63789
|
+
}) {
|
|
63790
|
+
return this.addToList(selection, data, variables, "first", layer);
|
|
63781
63791
|
}
|
|
63782
|
-
addToList(selection, data, variables = {}, where) {
|
|
63792
|
+
addToList(selection, data, variables = {}, where, layer) {
|
|
63783
63793
|
const listType = this.listType(data);
|
|
63784
63794
|
const dataID = this.cache._internal_unstable.id(listType, data);
|
|
63785
63795
|
if (!this.validateWhen() || !dataID) {
|
|
@@ -63857,7 +63867,8 @@ var List = class {
|
|
|
63857
63867
|
data: insertData,
|
|
63858
63868
|
variables,
|
|
63859
63869
|
parent: this.recordID,
|
|
63860
|
-
applyUpdates: [where === "first" ? "prepend" : "append"]
|
|
63870
|
+
applyUpdates: [where === "first" ? "prepend" : "append"],
|
|
63871
|
+
layer: layer?.id
|
|
63861
63872
|
});
|
|
63862
63873
|
}
|
|
63863
63874
|
removeID(id, variables = {}) {
|
|
@@ -63950,9 +63961,15 @@ var List = class {
|
|
|
63950
63961
|
}
|
|
63951
63962
|
return ok;
|
|
63952
63963
|
}
|
|
63953
|
-
toggleElement(
|
|
63964
|
+
toggleElement({
|
|
63965
|
+
selection,
|
|
63966
|
+
data,
|
|
63967
|
+
variables = {},
|
|
63968
|
+
layer,
|
|
63969
|
+
where
|
|
63970
|
+
}) {
|
|
63954
63971
|
if (!this.remove(data, variables)) {
|
|
63955
|
-
this.addToList(selection, data, variables, where);
|
|
63972
|
+
this.addToList(selection, data, variables, where, layer);
|
|
63956
63973
|
}
|
|
63957
63974
|
}
|
|
63958
63975
|
*[Symbol.iterator]() {
|
|
@@ -64960,6 +64977,9 @@ var CacheInternal = class {
|
|
|
64960
64977
|
nullable,
|
|
64961
64978
|
link: !!fieldSelection
|
|
64962
64979
|
});
|
|
64980
|
+
if (value && typeof value === "object" && "__typename" in value && value["__typename"]) {
|
|
64981
|
+
linkedType = value["__typename"];
|
|
64982
|
+
}
|
|
64963
64983
|
const currentSubscribers = this.subscriptions.get(parent, key);
|
|
64964
64984
|
const specs = currentSubscribers.map((sub) => sub[0]);
|
|
64965
64985
|
const { value: previousValue, displayLayers } = this.storage.get(parent, key);
|
|
@@ -65013,7 +65033,6 @@ var CacheInternal = class {
|
|
|
65013
65033
|
"Encountered interface type without __typename in the payload"
|
|
65014
65034
|
);
|
|
65015
65035
|
}
|
|
65016
|
-
linkedType = value.__typename;
|
|
65017
65036
|
}
|
|
65018
65037
|
const embedded = this.idFields(linkedType)?.filter(
|
|
65019
65038
|
(field2) => typeof value[field2] === "undefined"
|
|
@@ -65169,7 +65188,8 @@ var CacheInternal = class {
|
|
|
65169
65188
|
fieldSelection,
|
|
65170
65189
|
target,
|
|
65171
65190
|
variables,
|
|
65172
|
-
operation.position || "last"
|
|
65191
|
+
operation.position || "last",
|
|
65192
|
+
layer
|
|
65173
65193
|
);
|
|
65174
65194
|
} else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
|
|
65175
65195
|
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
|
|
@@ -65183,12 +65203,13 @@ var CacheInternal = class {
|
|
|
65183
65203
|
}
|
|
65184
65204
|
this.cache.delete(targetID);
|
|
65185
65205
|
} else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
|
|
65186
|
-
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
|
|
65187
|
-
fieldSelection,
|
|
65188
|
-
target,
|
|
65206
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
|
|
65207
|
+
selection: fieldSelection,
|
|
65208
|
+
data: target,
|
|
65189
65209
|
variables,
|
|
65190
|
-
operation.position || "last"
|
|
65191
|
-
|
|
65210
|
+
where: operation.position || "last",
|
|
65211
|
+
layer
|
|
65212
|
+
});
|
|
65192
65213
|
}
|
|
65193
65214
|
}
|
|
65194
65215
|
}
|
|
@@ -65217,7 +65238,7 @@ var CacheInternal = class {
|
|
|
65217
65238
|
])
|
|
65218
65239
|
);
|
|
65219
65240
|
}
|
|
65220
|
-
let hasData =
|
|
65241
|
+
let hasData = !!selection.fragments;
|
|
65221
65242
|
let partial = false;
|
|
65222
65243
|
let cascadeNull = false;
|
|
65223
65244
|
let stale = false;
|
|
@@ -65432,13 +65453,12 @@ var CacheInternal = class {
|
|
|
65432
65453
|
const embedded = this.idFields(linkedType)?.filter(
|
|
65433
65454
|
(field) => typeof entry[field] === "undefined"
|
|
65434
65455
|
).length > 0;
|
|
65435
|
-
const typename = entryObj.__typename;
|
|
65436
65456
|
let innerType = linkedType;
|
|
65437
|
-
|
|
65438
|
-
|
|
65439
|
-
throw new Error("Encountered interface type without __typename in the payload");
|
|
65440
|
-
}
|
|
65457
|
+
const typename = entryObj.__typename;
|
|
65458
|
+
if (typename) {
|
|
65441
65459
|
innerType = typename;
|
|
65460
|
+
} else if (abstract) {
|
|
65461
|
+
throw new Error("Encountered interface type without __typename in the payload");
|
|
65442
65462
|
}
|
|
65443
65463
|
if (!embedded) {
|
|
65444
65464
|
const id = this.id(innerType, entry);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SubscriptionSelection, ListWhen, SubscriptionSpec } from '../lib/types';
|
|
2
2
|
import type { Cache } from './cache';
|
|
3
|
+
import type { Layer } from './storage';
|
|
3
4
|
export declare class ListManager {
|
|
4
5
|
rootID: string;
|
|
5
6
|
cache: Cache;
|
|
@@ -40,16 +41,32 @@ export declare class List {
|
|
|
40
41
|
manager: ListManager;
|
|
41
42
|
});
|
|
42
43
|
when(when?: ListWhen): ListCollection;
|
|
43
|
-
append(selection
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
append({ selection, data, variables, layer, }: {
|
|
45
|
+
selection: SubscriptionSelection;
|
|
46
|
+
data: {};
|
|
47
|
+
variables?: {};
|
|
48
|
+
layer?: Layer;
|
|
49
|
+
}): void;
|
|
50
|
+
prepend({ selection, data, variables, layer, }: {
|
|
51
|
+
selection: SubscriptionSelection;
|
|
52
|
+
data: {};
|
|
53
|
+
variables?: {};
|
|
54
|
+
layer?: Layer;
|
|
55
|
+
}): void;
|
|
56
|
+
addToList(selection: SubscriptionSelection, data: {}, variables: {} | undefined, where: 'first' | 'last', layer?: Layer): void;
|
|
46
57
|
removeID(id: string, variables?: {}): true | undefined;
|
|
47
58
|
remove(data: {}, variables?: {}): true | undefined;
|
|
48
59
|
listType(data: {
|
|
49
60
|
__typename?: string;
|
|
50
61
|
}): string;
|
|
51
62
|
validateWhen(when?: ListWhen): boolean;
|
|
52
|
-
toggleElement(selection
|
|
63
|
+
toggleElement({ selection, data, variables, layer, where, }: {
|
|
64
|
+
selection: SubscriptionSelection;
|
|
65
|
+
data: {};
|
|
66
|
+
variables?: {};
|
|
67
|
+
layer?: Layer;
|
|
68
|
+
where: 'first' | 'last';
|
|
69
|
+
}): void;
|
|
53
70
|
[Symbol.iterator](): Generator<string, void, unknown>;
|
|
54
71
|
}
|
|
55
72
|
export declare class ListCollection {
|
|
@@ -227,6 +227,9 @@ class CacheInternal {
|
|
|
227
227
|
nullable,
|
|
228
228
|
link: !!fieldSelection
|
|
229
229
|
});
|
|
230
|
+
if (value && typeof value === "object" && "__typename" in value && value["__typename"]) {
|
|
231
|
+
linkedType = value["__typename"];
|
|
232
|
+
}
|
|
230
233
|
const currentSubscribers = this.subscriptions.get(parent, key);
|
|
231
234
|
const specs = currentSubscribers.map((sub) => sub[0]);
|
|
232
235
|
const { value: previousValue, displayLayers } = this.storage.get(parent, key);
|
|
@@ -280,7 +283,6 @@ class CacheInternal {
|
|
|
280
283
|
"Encountered interface type without __typename in the payload"
|
|
281
284
|
);
|
|
282
285
|
}
|
|
283
|
-
linkedType = value.__typename;
|
|
284
286
|
}
|
|
285
287
|
const embedded = this.idFields(linkedType)?.filter(
|
|
286
288
|
(field2) => typeof value[field2] === "undefined"
|
|
@@ -436,7 +438,8 @@ class CacheInternal {
|
|
|
436
438
|
fieldSelection,
|
|
437
439
|
target,
|
|
438
440
|
variables,
|
|
439
|
-
operation.position || "last"
|
|
441
|
+
operation.position || "last",
|
|
442
|
+
layer
|
|
440
443
|
);
|
|
441
444
|
} else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
|
|
442
445
|
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
|
|
@@ -450,12 +453,13 @@ class CacheInternal {
|
|
|
450
453
|
}
|
|
451
454
|
this.cache.delete(targetID);
|
|
452
455
|
} else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
|
|
453
|
-
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
|
|
454
|
-
fieldSelection,
|
|
455
|
-
target,
|
|
456
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
|
|
457
|
+
selection: fieldSelection,
|
|
458
|
+
data: target,
|
|
456
459
|
variables,
|
|
457
|
-
operation.position || "last"
|
|
458
|
-
|
|
460
|
+
where: operation.position || "last",
|
|
461
|
+
layer
|
|
462
|
+
});
|
|
459
463
|
}
|
|
460
464
|
}
|
|
461
465
|
}
|
|
@@ -484,7 +488,7 @@ class CacheInternal {
|
|
|
484
488
|
])
|
|
485
489
|
);
|
|
486
490
|
}
|
|
487
|
-
let hasData =
|
|
491
|
+
let hasData = !!selection.fragments;
|
|
488
492
|
let partial = false;
|
|
489
493
|
let cascadeNull = false;
|
|
490
494
|
let stale = false;
|
|
@@ -699,13 +703,12 @@ class CacheInternal {
|
|
|
699
703
|
const embedded = this.idFields(linkedType)?.filter(
|
|
700
704
|
(field) => typeof entry[field] === "undefined"
|
|
701
705
|
).length > 0;
|
|
702
|
-
const typename = entryObj.__typename;
|
|
703
706
|
let innerType = linkedType;
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
throw new Error("Encountered interface type without __typename in the payload");
|
|
707
|
-
}
|
|
707
|
+
const typename = entryObj.__typename;
|
|
708
|
+
if (typename) {
|
|
708
709
|
innerType = typename;
|
|
710
|
+
} else if (abstract) {
|
|
711
|
+
throw new Error("Encountered interface type without __typename in the payload");
|
|
709
712
|
}
|
|
710
713
|
if (!embedded) {
|
|
711
714
|
const id = this.id(innerType, entry);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SubscriptionSelection, ListWhen, SubscriptionSpec } from '../lib/types';
|
|
2
2
|
import type { Cache } from './cache';
|
|
3
|
+
import type { Layer } from './storage';
|
|
3
4
|
export declare class ListManager {
|
|
4
5
|
rootID: string;
|
|
5
6
|
cache: Cache;
|
|
@@ -40,16 +41,32 @@ export declare class List {
|
|
|
40
41
|
manager: ListManager;
|
|
41
42
|
});
|
|
42
43
|
when(when?: ListWhen): ListCollection;
|
|
43
|
-
append(selection
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
append({ selection, data, variables, layer, }: {
|
|
45
|
+
selection: SubscriptionSelection;
|
|
46
|
+
data: {};
|
|
47
|
+
variables?: {};
|
|
48
|
+
layer?: Layer;
|
|
49
|
+
}): void;
|
|
50
|
+
prepend({ selection, data, variables, layer, }: {
|
|
51
|
+
selection: SubscriptionSelection;
|
|
52
|
+
data: {};
|
|
53
|
+
variables?: {};
|
|
54
|
+
layer?: Layer;
|
|
55
|
+
}): void;
|
|
56
|
+
addToList(selection: SubscriptionSelection, data: {}, variables: {} | undefined, where: 'first' | 'last', layer?: Layer): void;
|
|
46
57
|
removeID(id: string, variables?: {}): true | undefined;
|
|
47
58
|
remove(data: {}, variables?: {}): true | undefined;
|
|
48
59
|
listType(data: {
|
|
49
60
|
__typename?: string;
|
|
50
61
|
}): string;
|
|
51
62
|
validateWhen(when?: ListWhen): boolean;
|
|
52
|
-
toggleElement(selection
|
|
63
|
+
toggleElement({ selection, data, variables, layer, where, }: {
|
|
64
|
+
selection: SubscriptionSelection;
|
|
65
|
+
data: {};
|
|
66
|
+
variables?: {};
|
|
67
|
+
layer?: Layer;
|
|
68
|
+
where: 'first' | 'last';
|
|
69
|
+
}): void;
|
|
53
70
|
[Symbol.iterator](): Generator<string, void, unknown>;
|
|
54
71
|
}
|
|
55
72
|
export declare class ListCollection {
|
|
@@ -151,13 +151,23 @@ class List {
|
|
|
151
151
|
when(when) {
|
|
152
152
|
return this.manager.lists.get(this.name).get(this.recordID).when(when);
|
|
153
153
|
}
|
|
154
|
-
append(
|
|
155
|
-
|
|
154
|
+
append({
|
|
155
|
+
selection,
|
|
156
|
+
data,
|
|
157
|
+
variables = {},
|
|
158
|
+
layer
|
|
159
|
+
}) {
|
|
160
|
+
return this.addToList(selection, data, variables, "last", layer);
|
|
156
161
|
}
|
|
157
|
-
prepend(
|
|
158
|
-
|
|
162
|
+
prepend({
|
|
163
|
+
selection,
|
|
164
|
+
data,
|
|
165
|
+
variables = {},
|
|
166
|
+
layer
|
|
167
|
+
}) {
|
|
168
|
+
return this.addToList(selection, data, variables, "first", layer);
|
|
159
169
|
}
|
|
160
|
-
addToList(selection, data, variables = {}, where) {
|
|
170
|
+
addToList(selection, data, variables = {}, where, layer) {
|
|
161
171
|
const listType = this.listType(data);
|
|
162
172
|
const dataID = this.cache._internal_unstable.id(listType, data);
|
|
163
173
|
if (!this.validateWhen() || !dataID) {
|
|
@@ -235,7 +245,8 @@ class List {
|
|
|
235
245
|
data: insertData,
|
|
236
246
|
variables,
|
|
237
247
|
parent: this.recordID,
|
|
238
|
-
applyUpdates: [where === "first" ? "prepend" : "append"]
|
|
248
|
+
applyUpdates: [where === "first" ? "prepend" : "append"],
|
|
249
|
+
layer: layer?.id
|
|
239
250
|
});
|
|
240
251
|
}
|
|
241
252
|
removeID(id, variables = {}) {
|
|
@@ -328,9 +339,15 @@ class List {
|
|
|
328
339
|
}
|
|
329
340
|
return ok;
|
|
330
341
|
}
|
|
331
|
-
toggleElement(
|
|
342
|
+
toggleElement({
|
|
343
|
+
selection,
|
|
344
|
+
data,
|
|
345
|
+
variables = {},
|
|
346
|
+
layer,
|
|
347
|
+
where
|
|
348
|
+
}) {
|
|
332
349
|
if (!this.remove(data, variables)) {
|
|
333
|
-
this.addToList(selection, data, variables, where);
|
|
350
|
+
this.addToList(selection, data, variables, where, layer);
|
|
334
351
|
}
|
|
335
352
|
}
|
|
336
353
|
*[Symbol.iterator]() {
|
|
@@ -48,7 +48,10 @@ class ListCollection {
|
|
|
48
48
|
const { selection, data } = this.#listOperationPayload(records);
|
|
49
49
|
for (const entry of data) {
|
|
50
50
|
if (entry) {
|
|
51
|
-
this.#collection.append(
|
|
51
|
+
this.#collection.append({
|
|
52
|
+
selection,
|
|
53
|
+
data: entry
|
|
54
|
+
});
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -59,7 +62,10 @@ class ListCollection {
|
|
|
59
62
|
const { selection, data } = this.#listOperationPayload(records);
|
|
60
63
|
for (const entry of data) {
|
|
61
64
|
if (entry) {
|
|
62
|
-
this.#collection.prepend(
|
|
65
|
+
this.#collection.prepend({
|
|
66
|
+
selection,
|
|
67
|
+
data: entry
|
|
68
|
+
});
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -70,7 +76,11 @@ class ListCollection {
|
|
|
70
76
|
const { selection, data } = this.#listOperationPayload(records);
|
|
71
77
|
for (const entry of data) {
|
|
72
78
|
if (entry) {
|
|
73
|
-
this.#collection.toggleElement(
|
|
79
|
+
this.#collection.toggleElement({
|
|
80
|
+
selection,
|
|
81
|
+
data: entry,
|
|
82
|
+
where
|
|
83
|
+
});
|
|
74
84
|
}
|
|
75
85
|
}
|
|
76
86
|
}
|
|
@@ -202,6 +202,9 @@ class CacheInternal {
|
|
|
202
202
|
nullable,
|
|
203
203
|
link: !!fieldSelection
|
|
204
204
|
});
|
|
205
|
+
if (value && typeof value === "object" && "__typename" in value && value["__typename"]) {
|
|
206
|
+
linkedType = value["__typename"];
|
|
207
|
+
}
|
|
205
208
|
const currentSubscribers = this.subscriptions.get(parent, key);
|
|
206
209
|
const specs = currentSubscribers.map((sub) => sub[0]);
|
|
207
210
|
const { value: previousValue, displayLayers } = this.storage.get(parent, key);
|
|
@@ -255,7 +258,6 @@ class CacheInternal {
|
|
|
255
258
|
"Encountered interface type without __typename in the payload"
|
|
256
259
|
);
|
|
257
260
|
}
|
|
258
|
-
linkedType = value.__typename;
|
|
259
261
|
}
|
|
260
262
|
const embedded = this.idFields(linkedType)?.filter(
|
|
261
263
|
(field2) => typeof value[field2] === "undefined"
|
|
@@ -411,7 +413,8 @@ class CacheInternal {
|
|
|
411
413
|
fieldSelection,
|
|
412
414
|
target,
|
|
413
415
|
variables,
|
|
414
|
-
operation.position || "last"
|
|
416
|
+
operation.position || "last",
|
|
417
|
+
layer
|
|
415
418
|
);
|
|
416
419
|
} else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
|
|
417
420
|
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
|
|
@@ -425,12 +428,13 @@ class CacheInternal {
|
|
|
425
428
|
}
|
|
426
429
|
this.cache.delete(targetID);
|
|
427
430
|
} else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
|
|
428
|
-
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
|
|
429
|
-
fieldSelection,
|
|
430
|
-
target,
|
|
431
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
|
|
432
|
+
selection: fieldSelection,
|
|
433
|
+
data: target,
|
|
431
434
|
variables,
|
|
432
|
-
operation.position || "last"
|
|
433
|
-
|
|
435
|
+
where: operation.position || "last",
|
|
436
|
+
layer
|
|
437
|
+
});
|
|
434
438
|
}
|
|
435
439
|
}
|
|
436
440
|
}
|
|
@@ -459,7 +463,7 @@ class CacheInternal {
|
|
|
459
463
|
])
|
|
460
464
|
);
|
|
461
465
|
}
|
|
462
|
-
let hasData =
|
|
466
|
+
let hasData = !!selection.fragments;
|
|
463
467
|
let partial = false;
|
|
464
468
|
let cascadeNull = false;
|
|
465
469
|
let stale = false;
|
|
@@ -674,13 +678,12 @@ class CacheInternal {
|
|
|
674
678
|
const embedded = this.idFields(linkedType)?.filter(
|
|
675
679
|
(field) => typeof entry[field] === "undefined"
|
|
676
680
|
).length > 0;
|
|
677
|
-
const typename = entryObj.__typename;
|
|
678
681
|
let innerType = linkedType;
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
throw new Error("Encountered interface type without __typename in the payload");
|
|
682
|
-
}
|
|
682
|
+
const typename = entryObj.__typename;
|
|
683
|
+
if (typename) {
|
|
683
684
|
innerType = typename;
|
|
685
|
+
} else if (abstract) {
|
|
686
|
+
throw new Error("Encountered interface type without __typename in the payload");
|
|
684
687
|
}
|
|
685
688
|
if (!embedded) {
|
|
686
689
|
const id = this.id(innerType, entry);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SubscriptionSelection, ListWhen, SubscriptionSpec } from '../lib/types';
|
|
2
2
|
import type { Cache } from './cache';
|
|
3
|
+
import type { Layer } from './storage';
|
|
3
4
|
export declare class ListManager {
|
|
4
5
|
rootID: string;
|
|
5
6
|
cache: Cache;
|
|
@@ -40,16 +41,32 @@ export declare class List {
|
|
|
40
41
|
manager: ListManager;
|
|
41
42
|
});
|
|
42
43
|
when(when?: ListWhen): ListCollection;
|
|
43
|
-
append(selection
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
append({ selection, data, variables, layer, }: {
|
|
45
|
+
selection: SubscriptionSelection;
|
|
46
|
+
data: {};
|
|
47
|
+
variables?: {};
|
|
48
|
+
layer?: Layer;
|
|
49
|
+
}): void;
|
|
50
|
+
prepend({ selection, data, variables, layer, }: {
|
|
51
|
+
selection: SubscriptionSelection;
|
|
52
|
+
data: {};
|
|
53
|
+
variables?: {};
|
|
54
|
+
layer?: Layer;
|
|
55
|
+
}): void;
|
|
56
|
+
addToList(selection: SubscriptionSelection, data: {}, variables: {} | undefined, where: 'first' | 'last', layer?: Layer): void;
|
|
46
57
|
removeID(id: string, variables?: {}): true | undefined;
|
|
47
58
|
remove(data: {}, variables?: {}): true | undefined;
|
|
48
59
|
listType(data: {
|
|
49
60
|
__typename?: string;
|
|
50
61
|
}): string;
|
|
51
62
|
validateWhen(when?: ListWhen): boolean;
|
|
52
|
-
toggleElement(selection
|
|
63
|
+
toggleElement({ selection, data, variables, layer, where, }: {
|
|
64
|
+
selection: SubscriptionSelection;
|
|
65
|
+
data: {};
|
|
66
|
+
variables?: {};
|
|
67
|
+
layer?: Layer;
|
|
68
|
+
where: 'first' | 'last';
|
|
69
|
+
}): void;
|
|
53
70
|
[Symbol.iterator](): Generator<string, void, unknown>;
|
|
54
71
|
}
|
|
55
72
|
export declare class ListCollection {
|
|
@@ -126,13 +126,23 @@ class List {
|
|
|
126
126
|
when(when) {
|
|
127
127
|
return this.manager.lists.get(this.name).get(this.recordID).when(when);
|
|
128
128
|
}
|
|
129
|
-
append(
|
|
130
|
-
|
|
129
|
+
append({
|
|
130
|
+
selection,
|
|
131
|
+
data,
|
|
132
|
+
variables = {},
|
|
133
|
+
layer
|
|
134
|
+
}) {
|
|
135
|
+
return this.addToList(selection, data, variables, "last", layer);
|
|
131
136
|
}
|
|
132
|
-
prepend(
|
|
133
|
-
|
|
137
|
+
prepend({
|
|
138
|
+
selection,
|
|
139
|
+
data,
|
|
140
|
+
variables = {},
|
|
141
|
+
layer
|
|
142
|
+
}) {
|
|
143
|
+
return this.addToList(selection, data, variables, "first", layer);
|
|
134
144
|
}
|
|
135
|
-
addToList(selection, data, variables = {}, where) {
|
|
145
|
+
addToList(selection, data, variables = {}, where, layer) {
|
|
136
146
|
const listType = this.listType(data);
|
|
137
147
|
const dataID = this.cache._internal_unstable.id(listType, data);
|
|
138
148
|
if (!this.validateWhen() || !dataID) {
|
|
@@ -210,7 +220,8 @@ class List {
|
|
|
210
220
|
data: insertData,
|
|
211
221
|
variables,
|
|
212
222
|
parent: this.recordID,
|
|
213
|
-
applyUpdates: [where === "first" ? "prepend" : "append"]
|
|
223
|
+
applyUpdates: [where === "first" ? "prepend" : "append"],
|
|
224
|
+
layer: layer?.id
|
|
214
225
|
});
|
|
215
226
|
}
|
|
216
227
|
removeID(id, variables = {}) {
|
|
@@ -303,9 +314,15 @@ class List {
|
|
|
303
314
|
}
|
|
304
315
|
return ok;
|
|
305
316
|
}
|
|
306
|
-
toggleElement(
|
|
317
|
+
toggleElement({
|
|
318
|
+
selection,
|
|
319
|
+
data,
|
|
320
|
+
variables = {},
|
|
321
|
+
layer,
|
|
322
|
+
where
|
|
323
|
+
}) {
|
|
307
324
|
if (!this.remove(data, variables)) {
|
|
308
|
-
this.addToList(selection, data, variables, where);
|
|
325
|
+
this.addToList(selection, data, variables, where, layer);
|
|
309
326
|
}
|
|
310
327
|
}
|
|
311
328
|
*[Symbol.iterator]() {
|
|
@@ -25,7 +25,10 @@ class ListCollection {
|
|
|
25
25
|
const { selection, data } = this.#listOperationPayload(records);
|
|
26
26
|
for (const entry of data) {
|
|
27
27
|
if (entry) {
|
|
28
|
-
this.#collection.append(
|
|
28
|
+
this.#collection.append({
|
|
29
|
+
selection,
|
|
30
|
+
data: entry
|
|
31
|
+
});
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -36,7 +39,10 @@ class ListCollection {
|
|
|
36
39
|
const { selection, data } = this.#listOperationPayload(records);
|
|
37
40
|
for (const entry of data) {
|
|
38
41
|
if (entry) {
|
|
39
|
-
this.#collection.prepend(
|
|
42
|
+
this.#collection.prepend({
|
|
43
|
+
selection,
|
|
44
|
+
data: entry
|
|
45
|
+
});
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -47,7 +53,11 @@ class ListCollection {
|
|
|
47
53
|
const { selection, data } = this.#listOperationPayload(records);
|
|
48
54
|
for (const entry of data) {
|
|
49
55
|
if (entry) {
|
|
50
|
-
this.#collection.toggleElement(
|
|
56
|
+
this.#collection.toggleElement({
|
|
57
|
+
selection,
|
|
58
|
+
data: entry,
|
|
59
|
+
where
|
|
60
|
+
});
|
|
51
61
|
}
|
|
52
62
|
}
|
|
53
63
|
}
|