houdini 1.2.5 → 1.2.6
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 +613 -562
- package/build/cmd-esm/index.js +613 -562
- package/build/codegen/generators/artifacts/selection.d.ts +1 -3
- package/build/codegen-cjs/index.js +600 -549
- package/build/codegen-esm/index.js +600 -549
- package/build/lib-cjs/index.js +41 -10
- package/build/lib-esm/index.js +41 -10
- package/build/runtime/cache/cache.d.ts +2 -0
- package/build/runtime/cache/gc.d.ts +1 -0
- package/build/runtime/cache/lists.d.ts +1 -0
- package/build/runtime/cache/staleManager.d.ts +1 -0
- package/build/runtime/cache/storage.d.ts +1 -0
- package/build/runtime/cache/subscription.d.ts +2 -1
- package/build/runtime/public/cache.d.ts +4 -0
- package/build/runtime-cjs/cache/cache.d.ts +2 -0
- package/build/runtime-cjs/cache/cache.js +16 -10
- package/build/runtime-cjs/cache/gc.d.ts +1 -0
- package/build/runtime-cjs/cache/gc.js +3 -0
- package/build/runtime-cjs/cache/lists.d.ts +1 -0
- package/build/runtime-cjs/cache/lists.js +4 -0
- package/build/runtime-cjs/cache/staleManager.d.ts +1 -0
- package/build/runtime-cjs/cache/staleManager.js +3 -0
- package/build/runtime-cjs/cache/storage.d.ts +1 -0
- package/build/runtime-cjs/cache/storage.js +3 -0
- package/build/runtime-cjs/cache/subscription.d.ts +2 -1
- package/build/runtime-cjs/cache/subscription.js +13 -0
- package/build/runtime-cjs/public/cache.d.ts +4 -0
- package/build/runtime-cjs/public/cache.js +3 -0
- package/build/runtime-esm/cache/cache.d.ts +2 -0
- package/build/runtime-esm/cache/cache.js +16 -10
- package/build/runtime-esm/cache/gc.d.ts +1 -0
- package/build/runtime-esm/cache/gc.js +3 -0
- package/build/runtime-esm/cache/lists.d.ts +1 -0
- package/build/runtime-esm/cache/lists.js +4 -0
- package/build/runtime-esm/cache/staleManager.d.ts +1 -0
- package/build/runtime-esm/cache/staleManager.js +3 -0
- package/build/runtime-esm/cache/storage.d.ts +1 -0
- package/build/runtime-esm/cache/storage.js +3 -0
- package/build/runtime-esm/cache/subscription.d.ts +2 -1
- package/build/runtime-esm/cache/subscription.js +13 -0
- package/build/runtime-esm/public/cache.d.ts +4 -0
- package/build/runtime-esm/public/cache.js +3 -0
- package/build/test-cjs/index.js +603 -552
- package/build/test-esm/index.js +603 -552
- package/build/vite-cjs/index.js +618 -567
- package/build/vite-esm/index.js +618 -567
- package/package.json +1 -1
package/build/lib-cjs/index.js
CHANGED
|
@@ -63711,6 +63711,9 @@ var GarbageCollector = class {
|
|
|
63711
63711
|
constructor(cache) {
|
|
63712
63712
|
this.cache = cache;
|
|
63713
63713
|
}
|
|
63714
|
+
reset() {
|
|
63715
|
+
this.lifetimes.clear();
|
|
63716
|
+
}
|
|
63714
63717
|
resetLifetime(id, field) {
|
|
63715
63718
|
if (!this.lifetimes.get(id)) {
|
|
63716
63719
|
this.lifetimes.set(id, /* @__PURE__ */ new Map());
|
|
@@ -63830,6 +63833,10 @@ var ListManager = class {
|
|
|
63830
63833
|
}
|
|
63831
63834
|
this.listsByField.get(parentID).delete(field);
|
|
63832
63835
|
}
|
|
63836
|
+
reset() {
|
|
63837
|
+
this.lists.clear();
|
|
63838
|
+
this.listsByField.clear();
|
|
63839
|
+
}
|
|
63833
63840
|
};
|
|
63834
63841
|
var List = class {
|
|
63835
63842
|
recordID;
|
|
@@ -64212,6 +64219,9 @@ var StaleManager = class {
|
|
|
64212
64219
|
}
|
|
64213
64220
|
}
|
|
64214
64221
|
}
|
|
64222
|
+
reset() {
|
|
64223
|
+
this.fieldsTime.clear();
|
|
64224
|
+
}
|
|
64215
64225
|
};
|
|
64216
64226
|
|
|
64217
64227
|
// src/runtime/cache/storage.ts
|
|
@@ -64392,6 +64402,9 @@ var InMemoryStorage = class {
|
|
|
64392
64402
|
layer.fields = fields;
|
|
64393
64403
|
layer.links = links;
|
|
64394
64404
|
}
|
|
64405
|
+
reset() {
|
|
64406
|
+
this.data = [];
|
|
64407
|
+
}
|
|
64395
64408
|
};
|
|
64396
64409
|
var Layer = class {
|
|
64397
64410
|
id;
|
|
@@ -64837,6 +64850,18 @@ var InMemorySubscriptions = class {
|
|
|
64837
64850
|
this.remove(linkedRecordID, linkFields, targets, visited);
|
|
64838
64851
|
}
|
|
64839
64852
|
}
|
|
64853
|
+
reset() {
|
|
64854
|
+
const subscribers = Object.entries(this.subscribers).filter(
|
|
64855
|
+
([id]) => !id.startsWith(rootID)
|
|
64856
|
+
);
|
|
64857
|
+
for (const [id, _fields] of subscribers) {
|
|
64858
|
+
delete this.subscribers[id];
|
|
64859
|
+
}
|
|
64860
|
+
const subscriptionSpecs = subscribers.flatMap(
|
|
64861
|
+
([_id, fields]) => Object.values(fields).flatMap((field) => field.map(([spec]) => spec))
|
|
64862
|
+
);
|
|
64863
|
+
return subscriptionSpecs;
|
|
64864
|
+
}
|
|
64840
64865
|
removeSubscribers(id, fieldName, specs) {
|
|
64841
64866
|
let targets = [];
|
|
64842
64867
|
for (const spec of specs) {
|
|
@@ -65026,6 +65051,14 @@ var Cache = class {
|
|
|
65026
65051
|
}
|
|
65027
65052
|
this.#notifySubscribers(toNotify);
|
|
65028
65053
|
}
|
|
65054
|
+
reset() {
|
|
65055
|
+
const subSpecs = this._internal_unstable.subscriptions.reset();
|
|
65056
|
+
this._internal_unstable.staleManager.reset();
|
|
65057
|
+
this._internal_unstable.lifetimes.reset();
|
|
65058
|
+
this._internal_unstable.lists.reset();
|
|
65059
|
+
this._internal_unstable.storage.reset();
|
|
65060
|
+
this.#notifySubscribers(subSpecs);
|
|
65061
|
+
}
|
|
65029
65062
|
#notifySubscribers(subs) {
|
|
65030
65063
|
if (subs.length === 0) {
|
|
65031
65064
|
return;
|
|
@@ -65175,12 +65208,9 @@ var CacheInternal = class {
|
|
|
65175
65208
|
);
|
|
65176
65209
|
}
|
|
65177
65210
|
}
|
|
65178
|
-
const embedded = this.idFields(linkedType)?.filter(
|
|
65179
|
-
(field2) => typeof value[field2] === "undefined"
|
|
65180
|
-
).length > 0;
|
|
65181
65211
|
let linkedID = null;
|
|
65182
65212
|
if (value !== null) {
|
|
65183
|
-
linkedID = !
|
|
65213
|
+
linkedID = !this.isEmbedded(linkedType, value) ? this.id(linkedType, value) : `${parent}.${key}`;
|
|
65184
65214
|
}
|
|
65185
65215
|
let linkChange = linkedID !== previousValue;
|
|
65186
65216
|
layer.writeLink(parent, key, linkedID);
|
|
@@ -65208,7 +65238,7 @@ var CacheInternal = class {
|
|
|
65208
65238
|
forceNotify
|
|
65209
65239
|
});
|
|
65210
65240
|
}
|
|
65211
|
-
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
65241
|
+
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
|
|
65212
65242
|
let oldIDs = [...previousValue || []];
|
|
65213
65243
|
const emptyEdges = !updates ? [] : oldIDs.map((id) => {
|
|
65214
65244
|
if (!id) {
|
|
@@ -65281,7 +65311,7 @@ var CacheInternal = class {
|
|
|
65281
65311
|
} else {
|
|
65282
65312
|
linkedIDs = nestedIDs;
|
|
65283
65313
|
}
|
|
65284
|
-
const contentChanged = !deepEquals(linkedIDs, oldIDs);
|
|
65314
|
+
const contentChanged = !deepEquals(linkedIDs, oldIDs) || previousValue === null;
|
|
65285
65315
|
if (contentChanged || forceNotify) {
|
|
65286
65316
|
toNotify.push(...currentSubscribers);
|
|
65287
65317
|
}
|
|
@@ -65552,6 +65582,10 @@ var CacheInternal = class {
|
|
|
65552
65582
|
computeID(type, data) {
|
|
65553
65583
|
return computeID(this.config, type, data);
|
|
65554
65584
|
}
|
|
65585
|
+
isEmbedded(linkedType, value) {
|
|
65586
|
+
const idFields = this.idFields(linkedType);
|
|
65587
|
+
return idFields.length === 0 || idFields.filter((field) => typeof value[field] === "undefined").length > 0;
|
|
65588
|
+
}
|
|
65555
65589
|
hydrateNestedList({
|
|
65556
65590
|
fields,
|
|
65557
65591
|
variables,
|
|
@@ -65659,9 +65693,6 @@ var CacheInternal = class {
|
|
|
65659
65693
|
}
|
|
65660
65694
|
const entryObj = entry;
|
|
65661
65695
|
let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
|
|
65662
|
-
const embedded = this.idFields(linkedType)?.filter(
|
|
65663
|
-
(field) => typeof entry[field] === "undefined"
|
|
65664
|
-
).length > 0;
|
|
65665
65696
|
let innerType = linkedType;
|
|
65666
65697
|
const typename = entryObj.__typename;
|
|
65667
65698
|
if (typename) {
|
|
@@ -65669,7 +65700,7 @@ var CacheInternal = class {
|
|
|
65669
65700
|
} else if (abstract) {
|
|
65670
65701
|
throw new Error("Encountered interface type without __typename in the payload");
|
|
65671
65702
|
}
|
|
65672
|
-
if (!
|
|
65703
|
+
if (!this.isEmbedded(linkedType, entry)) {
|
|
65673
65704
|
const id = this.id(innerType, entry);
|
|
65674
65705
|
if (id) {
|
|
65675
65706
|
linkedID = id;
|
package/build/lib-esm/index.js
CHANGED
|
@@ -63651,6 +63651,9 @@ var GarbageCollector = class {
|
|
|
63651
63651
|
constructor(cache) {
|
|
63652
63652
|
this.cache = cache;
|
|
63653
63653
|
}
|
|
63654
|
+
reset() {
|
|
63655
|
+
this.lifetimes.clear();
|
|
63656
|
+
}
|
|
63654
63657
|
resetLifetime(id, field) {
|
|
63655
63658
|
if (!this.lifetimes.get(id)) {
|
|
63656
63659
|
this.lifetimes.set(id, /* @__PURE__ */ new Map());
|
|
@@ -63770,6 +63773,10 @@ var ListManager = class {
|
|
|
63770
63773
|
}
|
|
63771
63774
|
this.listsByField.get(parentID).delete(field);
|
|
63772
63775
|
}
|
|
63776
|
+
reset() {
|
|
63777
|
+
this.lists.clear();
|
|
63778
|
+
this.listsByField.clear();
|
|
63779
|
+
}
|
|
63773
63780
|
};
|
|
63774
63781
|
var List = class {
|
|
63775
63782
|
recordID;
|
|
@@ -64152,6 +64159,9 @@ var StaleManager = class {
|
|
|
64152
64159
|
}
|
|
64153
64160
|
}
|
|
64154
64161
|
}
|
|
64162
|
+
reset() {
|
|
64163
|
+
this.fieldsTime.clear();
|
|
64164
|
+
}
|
|
64155
64165
|
};
|
|
64156
64166
|
|
|
64157
64167
|
// src/runtime/cache/storage.ts
|
|
@@ -64332,6 +64342,9 @@ var InMemoryStorage = class {
|
|
|
64332
64342
|
layer.fields = fields;
|
|
64333
64343
|
layer.links = links;
|
|
64334
64344
|
}
|
|
64345
|
+
reset() {
|
|
64346
|
+
this.data = [];
|
|
64347
|
+
}
|
|
64335
64348
|
};
|
|
64336
64349
|
var Layer = class {
|
|
64337
64350
|
id;
|
|
@@ -64777,6 +64790,18 @@ var InMemorySubscriptions = class {
|
|
|
64777
64790
|
this.remove(linkedRecordID, linkFields, targets, visited);
|
|
64778
64791
|
}
|
|
64779
64792
|
}
|
|
64793
|
+
reset() {
|
|
64794
|
+
const subscribers = Object.entries(this.subscribers).filter(
|
|
64795
|
+
([id]) => !id.startsWith(rootID)
|
|
64796
|
+
);
|
|
64797
|
+
for (const [id, _fields] of subscribers) {
|
|
64798
|
+
delete this.subscribers[id];
|
|
64799
|
+
}
|
|
64800
|
+
const subscriptionSpecs = subscribers.flatMap(
|
|
64801
|
+
([_id, fields]) => Object.values(fields).flatMap((field) => field.map(([spec]) => spec))
|
|
64802
|
+
);
|
|
64803
|
+
return subscriptionSpecs;
|
|
64804
|
+
}
|
|
64780
64805
|
removeSubscribers(id, fieldName, specs) {
|
|
64781
64806
|
let targets = [];
|
|
64782
64807
|
for (const spec of specs) {
|
|
@@ -64966,6 +64991,14 @@ var Cache = class {
|
|
|
64966
64991
|
}
|
|
64967
64992
|
this.#notifySubscribers(toNotify);
|
|
64968
64993
|
}
|
|
64994
|
+
reset() {
|
|
64995
|
+
const subSpecs = this._internal_unstable.subscriptions.reset();
|
|
64996
|
+
this._internal_unstable.staleManager.reset();
|
|
64997
|
+
this._internal_unstable.lifetimes.reset();
|
|
64998
|
+
this._internal_unstable.lists.reset();
|
|
64999
|
+
this._internal_unstable.storage.reset();
|
|
65000
|
+
this.#notifySubscribers(subSpecs);
|
|
65001
|
+
}
|
|
64969
65002
|
#notifySubscribers(subs) {
|
|
64970
65003
|
if (subs.length === 0) {
|
|
64971
65004
|
return;
|
|
@@ -65115,12 +65148,9 @@ var CacheInternal = class {
|
|
|
65115
65148
|
);
|
|
65116
65149
|
}
|
|
65117
65150
|
}
|
|
65118
|
-
const embedded = this.idFields(linkedType)?.filter(
|
|
65119
|
-
(field2) => typeof value[field2] === "undefined"
|
|
65120
|
-
).length > 0;
|
|
65121
65151
|
let linkedID = null;
|
|
65122
65152
|
if (value !== null) {
|
|
65123
|
-
linkedID = !
|
|
65153
|
+
linkedID = !this.isEmbedded(linkedType, value) ? this.id(linkedType, value) : `${parent}.${key}`;
|
|
65124
65154
|
}
|
|
65125
65155
|
let linkChange = linkedID !== previousValue;
|
|
65126
65156
|
layer.writeLink(parent, key, linkedID);
|
|
@@ -65148,7 +65178,7 @@ var CacheInternal = class {
|
|
|
65148
65178
|
forceNotify
|
|
65149
65179
|
});
|
|
65150
65180
|
}
|
|
65151
|
-
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
65181
|
+
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
|
|
65152
65182
|
let oldIDs = [...previousValue || []];
|
|
65153
65183
|
const emptyEdges = !updates ? [] : oldIDs.map((id) => {
|
|
65154
65184
|
if (!id) {
|
|
@@ -65221,7 +65251,7 @@ var CacheInternal = class {
|
|
|
65221
65251
|
} else {
|
|
65222
65252
|
linkedIDs = nestedIDs;
|
|
65223
65253
|
}
|
|
65224
|
-
const contentChanged = !deepEquals(linkedIDs, oldIDs);
|
|
65254
|
+
const contentChanged = !deepEquals(linkedIDs, oldIDs) || previousValue === null;
|
|
65225
65255
|
if (contentChanged || forceNotify) {
|
|
65226
65256
|
toNotify.push(...currentSubscribers);
|
|
65227
65257
|
}
|
|
@@ -65492,6 +65522,10 @@ var CacheInternal = class {
|
|
|
65492
65522
|
computeID(type, data) {
|
|
65493
65523
|
return computeID(this.config, type, data);
|
|
65494
65524
|
}
|
|
65525
|
+
isEmbedded(linkedType, value) {
|
|
65526
|
+
const idFields = this.idFields(linkedType);
|
|
65527
|
+
return idFields.length === 0 || idFields.filter((field) => typeof value[field] === "undefined").length > 0;
|
|
65528
|
+
}
|
|
65495
65529
|
hydrateNestedList({
|
|
65496
65530
|
fields,
|
|
65497
65531
|
variables,
|
|
@@ -65599,9 +65633,6 @@ var CacheInternal = class {
|
|
|
65599
65633
|
}
|
|
65600
65634
|
const entryObj = entry;
|
|
65601
65635
|
let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
|
|
65602
|
-
const embedded = this.idFields(linkedType)?.filter(
|
|
65603
|
-
(field) => typeof entry[field] === "undefined"
|
|
65604
|
-
).length > 0;
|
|
65605
65636
|
let innerType = linkedType;
|
|
65606
65637
|
const typename = entryObj.__typename;
|
|
65607
65638
|
if (typename) {
|
|
@@ -65609,7 +65640,7 @@ var CacheInternal = class {
|
|
|
65609
65640
|
} else if (abstract) {
|
|
65610
65641
|
throw new Error("Encountered interface type without __typename in the payload");
|
|
65611
65642
|
}
|
|
65612
|
-
if (!
|
|
65643
|
+
if (!this.isEmbedded(linkedType, entry)) {
|
|
65613
65644
|
const id = this.id(innerType, entry);
|
|
65614
65645
|
if (id) {
|
|
65615
65646
|
linkedID = id;
|
|
@@ -50,6 +50,7 @@ export declare class Cache {
|
|
|
50
50
|
serialize(): string;
|
|
51
51
|
hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
|
|
52
52
|
clearLayer(layerID: Layer['id']): void;
|
|
53
|
+
reset(): void;
|
|
53
54
|
}
|
|
54
55
|
declare class CacheInternal {
|
|
55
56
|
private _disabled;
|
|
@@ -106,6 +107,7 @@ declare class CacheInternal {
|
|
|
106
107
|
id(type: string, id: string): string | null;
|
|
107
108
|
idFields(type: string): string[];
|
|
108
109
|
computeID(type: string, data: any): string;
|
|
110
|
+
isEmbedded(linkedType: string, value: GraphQLObject): boolean;
|
|
109
111
|
hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, loading, }: {
|
|
110
112
|
fields: SubscriptionSelection;
|
|
111
113
|
variables?: {} | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
|
|
2
|
-
import type
|
|
2
|
+
import { type Cache } from './cache';
|
|
3
3
|
export type FieldSelection = [
|
|
4
4
|
SubscriptionSpec,
|
|
5
5
|
Required<SubscriptionSelection>['fields'] | undefined
|
|
@@ -43,6 +43,7 @@ export declare class InMemorySubscriptions {
|
|
|
43
43
|
}): void;
|
|
44
44
|
get(id: string, field: string): FieldSelection[];
|
|
45
45
|
remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
|
|
46
|
+
reset(): SubscriptionSpec[];
|
|
46
47
|
private removeSubscribers;
|
|
47
48
|
removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
|
|
48
49
|
}
|
|
@@ -50,6 +50,7 @@ export declare class Cache {
|
|
|
50
50
|
serialize(): string;
|
|
51
51
|
hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
|
|
52
52
|
clearLayer(layerID: Layer['id']): void;
|
|
53
|
+
reset(): void;
|
|
53
54
|
}
|
|
54
55
|
declare class CacheInternal {
|
|
55
56
|
private _disabled;
|
|
@@ -106,6 +107,7 @@ declare class CacheInternal {
|
|
|
106
107
|
id(type: string, id: string): string | null;
|
|
107
108
|
idFields(type: string): string[];
|
|
108
109
|
computeID(type: string, data: any): string;
|
|
110
|
+
isEmbedded(linkedType: string, value: GraphQLObject): boolean;
|
|
109
111
|
hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, loading, }: {
|
|
110
112
|
fields: SubscriptionSelection;
|
|
111
113
|
variables?: {} | null;
|
|
@@ -183,6 +183,14 @@ class Cache {
|
|
|
183
183
|
}
|
|
184
184
|
this.#notifySubscribers(toNotify);
|
|
185
185
|
}
|
|
186
|
+
reset() {
|
|
187
|
+
const subSpecs = this._internal_unstable.subscriptions.reset();
|
|
188
|
+
this._internal_unstable.staleManager.reset();
|
|
189
|
+
this._internal_unstable.lifetimes.reset();
|
|
190
|
+
this._internal_unstable.lists.reset();
|
|
191
|
+
this._internal_unstable.storage.reset();
|
|
192
|
+
this.#notifySubscribers(subSpecs);
|
|
193
|
+
}
|
|
186
194
|
#notifySubscribers(subs) {
|
|
187
195
|
if (subs.length === 0) {
|
|
188
196
|
return;
|
|
@@ -332,12 +340,9 @@ class CacheInternal {
|
|
|
332
340
|
);
|
|
333
341
|
}
|
|
334
342
|
}
|
|
335
|
-
const embedded = this.idFields(linkedType)?.filter(
|
|
336
|
-
(field2) => typeof value[field2] === "undefined"
|
|
337
|
-
).length > 0;
|
|
338
343
|
let linkedID = null;
|
|
339
344
|
if (value !== null) {
|
|
340
|
-
linkedID = !
|
|
345
|
+
linkedID = !this.isEmbedded(linkedType, value) ? this.id(linkedType, value) : `${parent}.${key}`;
|
|
341
346
|
}
|
|
342
347
|
let linkChange = linkedID !== previousValue;
|
|
343
348
|
layer.writeLink(parent, key, linkedID);
|
|
@@ -365,7 +370,7 @@ class CacheInternal {
|
|
|
365
370
|
forceNotify
|
|
366
371
|
});
|
|
367
372
|
}
|
|
368
|
-
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
373
|
+
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
|
|
369
374
|
let oldIDs = [...previousValue || []];
|
|
370
375
|
const emptyEdges = !updates ? [] : oldIDs.map((id) => {
|
|
371
376
|
if (!id) {
|
|
@@ -438,7 +443,7 @@ class CacheInternal {
|
|
|
438
443
|
} else {
|
|
439
444
|
linkedIDs = nestedIDs;
|
|
440
445
|
}
|
|
441
|
-
const contentChanged = !(0, import_deepEquals.deepEquals)(linkedIDs, oldIDs);
|
|
446
|
+
const contentChanged = !(0, import_deepEquals.deepEquals)(linkedIDs, oldIDs) || previousValue === null;
|
|
442
447
|
if (contentChanged || forceNotify) {
|
|
443
448
|
toNotify.push(...currentSubscribers);
|
|
444
449
|
}
|
|
@@ -709,6 +714,10 @@ class CacheInternal {
|
|
|
709
714
|
computeID(type, data) {
|
|
710
715
|
return (0, import_config.computeID)(this.config, type, data);
|
|
711
716
|
}
|
|
717
|
+
isEmbedded(linkedType, value) {
|
|
718
|
+
const idFields = this.idFields(linkedType);
|
|
719
|
+
return idFields.length === 0 || idFields.filter((field) => typeof value[field] === "undefined").length > 0;
|
|
720
|
+
}
|
|
712
721
|
hydrateNestedList({
|
|
713
722
|
fields,
|
|
714
723
|
variables,
|
|
@@ -816,9 +825,6 @@ class CacheInternal {
|
|
|
816
825
|
}
|
|
817
826
|
const entryObj = entry;
|
|
818
827
|
let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
|
|
819
|
-
const embedded = this.idFields(linkedType)?.filter(
|
|
820
|
-
(field) => typeof entry[field] === "undefined"
|
|
821
|
-
).length > 0;
|
|
822
828
|
let innerType = linkedType;
|
|
823
829
|
const typename = entryObj.__typename;
|
|
824
830
|
if (typename) {
|
|
@@ -826,7 +832,7 @@ class CacheInternal {
|
|
|
826
832
|
} else if (abstract) {
|
|
827
833
|
throw new Error("Encountered interface type without __typename in the payload");
|
|
828
834
|
}
|
|
829
|
-
if (!
|
|
835
|
+
if (!this.isEmbedded(linkedType, entry)) {
|
|
830
836
|
const id = this.id(innerType, entry);
|
|
831
837
|
if (id) {
|
|
832
838
|
linkedID = id;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
|
|
2
|
-
import type
|
|
2
|
+
import { type Cache } from './cache';
|
|
3
3
|
export type FieldSelection = [
|
|
4
4
|
SubscriptionSpec,
|
|
5
5
|
Required<SubscriptionSelection>['fields'] | undefined
|
|
@@ -43,6 +43,7 @@ export declare class InMemorySubscriptions {
|
|
|
43
43
|
}): void;
|
|
44
44
|
get(id: string, field: string): FieldSelection[];
|
|
45
45
|
remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
|
|
46
|
+
reset(): SubscriptionSpec[];
|
|
46
47
|
private removeSubscribers;
|
|
47
48
|
removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
|
|
48
49
|
}
|
|
@@ -23,6 +23,7 @@ __export(subscription_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(subscription_exports);
|
|
24
24
|
var import_flatten = require("../lib/flatten");
|
|
25
25
|
var import_selection = require("../lib/selection");
|
|
26
|
+
var import_cache = require("./cache");
|
|
26
27
|
var import_stuff = require("./stuff");
|
|
27
28
|
class InMemorySubscriptions {
|
|
28
29
|
cache;
|
|
@@ -239,6 +240,18 @@ class InMemorySubscriptions {
|
|
|
239
240
|
this.remove(linkedRecordID, linkFields, targets, visited);
|
|
240
241
|
}
|
|
241
242
|
}
|
|
243
|
+
reset() {
|
|
244
|
+
const subscribers = Object.entries(this.subscribers).filter(
|
|
245
|
+
([id]) => !id.startsWith(import_cache.rootID)
|
|
246
|
+
);
|
|
247
|
+
for (const [id, _fields] of subscribers) {
|
|
248
|
+
delete this.subscribers[id];
|
|
249
|
+
}
|
|
250
|
+
const subscriptionSpecs = subscribers.flatMap(
|
|
251
|
+
([_id, fields]) => Object.values(fields).flatMap((field) => field.map(([spec]) => spec))
|
|
252
|
+
);
|
|
253
|
+
return subscriptionSpecs;
|
|
254
|
+
}
|
|
242
255
|
removeSubscribers(id, fieldName, specs) {
|
|
243
256
|
let targets = [];
|
|
244
257
|
for (const spec of specs) {
|
|
@@ -90,6 +90,9 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
|
|
|
90
90
|
markStale(type, options) {
|
|
91
91
|
return this._internal_unstable.markTypeStale(type ? { ...options, type } : void 0);
|
|
92
92
|
}
|
|
93
|
+
reset() {
|
|
94
|
+
return this._internal_unstable.reset();
|
|
95
|
+
}
|
|
93
96
|
}
|
|
94
97
|
// Annotate the CommonJS export names for ESM import in node:
|
|
95
98
|
0 && (module.exports = {
|
|
@@ -50,6 +50,7 @@ export declare class Cache {
|
|
|
50
50
|
serialize(): string;
|
|
51
51
|
hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
|
|
52
52
|
clearLayer(layerID: Layer['id']): void;
|
|
53
|
+
reset(): void;
|
|
53
54
|
}
|
|
54
55
|
declare class CacheInternal {
|
|
55
56
|
private _disabled;
|
|
@@ -106,6 +107,7 @@ declare class CacheInternal {
|
|
|
106
107
|
id(type: string, id: string): string | null;
|
|
107
108
|
idFields(type: string): string[];
|
|
108
109
|
computeID(type: string, data: any): string;
|
|
110
|
+
isEmbedded(linkedType: string, value: GraphQLObject): boolean;
|
|
109
111
|
hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, loading, }: {
|
|
110
112
|
fields: SubscriptionSelection;
|
|
111
113
|
variables?: {} | null;
|
|
@@ -158,6 +158,14 @@ class Cache {
|
|
|
158
158
|
}
|
|
159
159
|
this.#notifySubscribers(toNotify);
|
|
160
160
|
}
|
|
161
|
+
reset() {
|
|
162
|
+
const subSpecs = this._internal_unstable.subscriptions.reset();
|
|
163
|
+
this._internal_unstable.staleManager.reset();
|
|
164
|
+
this._internal_unstable.lifetimes.reset();
|
|
165
|
+
this._internal_unstable.lists.reset();
|
|
166
|
+
this._internal_unstable.storage.reset();
|
|
167
|
+
this.#notifySubscribers(subSpecs);
|
|
168
|
+
}
|
|
161
169
|
#notifySubscribers(subs) {
|
|
162
170
|
if (subs.length === 0) {
|
|
163
171
|
return;
|
|
@@ -307,12 +315,9 @@ class CacheInternal {
|
|
|
307
315
|
);
|
|
308
316
|
}
|
|
309
317
|
}
|
|
310
|
-
const embedded = this.idFields(linkedType)?.filter(
|
|
311
|
-
(field2) => typeof value[field2] === "undefined"
|
|
312
|
-
).length > 0;
|
|
313
318
|
let linkedID = null;
|
|
314
319
|
if (value !== null) {
|
|
315
|
-
linkedID = !
|
|
320
|
+
linkedID = !this.isEmbedded(linkedType, value) ? this.id(linkedType, value) : `${parent}.${key}`;
|
|
316
321
|
}
|
|
317
322
|
let linkChange = linkedID !== previousValue;
|
|
318
323
|
layer.writeLink(parent, key, linkedID);
|
|
@@ -340,7 +345,7 @@ class CacheInternal {
|
|
|
340
345
|
forceNotify
|
|
341
346
|
});
|
|
342
347
|
}
|
|
343
|
-
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
348
|
+
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
|
|
344
349
|
let oldIDs = [...previousValue || []];
|
|
345
350
|
const emptyEdges = !updates ? [] : oldIDs.map((id) => {
|
|
346
351
|
if (!id) {
|
|
@@ -413,7 +418,7 @@ class CacheInternal {
|
|
|
413
418
|
} else {
|
|
414
419
|
linkedIDs = nestedIDs;
|
|
415
420
|
}
|
|
416
|
-
const contentChanged = !deepEquals(linkedIDs, oldIDs);
|
|
421
|
+
const contentChanged = !deepEquals(linkedIDs, oldIDs) || previousValue === null;
|
|
417
422
|
if (contentChanged || forceNotify) {
|
|
418
423
|
toNotify.push(...currentSubscribers);
|
|
419
424
|
}
|
|
@@ -684,6 +689,10 @@ class CacheInternal {
|
|
|
684
689
|
computeID(type, data) {
|
|
685
690
|
return computeID(this.config, type, data);
|
|
686
691
|
}
|
|
692
|
+
isEmbedded(linkedType, value) {
|
|
693
|
+
const idFields = this.idFields(linkedType);
|
|
694
|
+
return idFields.length === 0 || idFields.filter((field) => typeof value[field] === "undefined").length > 0;
|
|
695
|
+
}
|
|
687
696
|
hydrateNestedList({
|
|
688
697
|
fields,
|
|
689
698
|
variables,
|
|
@@ -791,9 +800,6 @@ class CacheInternal {
|
|
|
791
800
|
}
|
|
792
801
|
const entryObj = entry;
|
|
793
802
|
let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
|
|
794
|
-
const embedded = this.idFields(linkedType)?.filter(
|
|
795
|
-
(field) => typeof entry[field] === "undefined"
|
|
796
|
-
).length > 0;
|
|
797
803
|
let innerType = linkedType;
|
|
798
804
|
const typename = entryObj.__typename;
|
|
799
805
|
if (typename) {
|
|
@@ -801,7 +807,7 @@ class CacheInternal {
|
|
|
801
807
|
} else if (abstract) {
|
|
802
808
|
throw new Error("Encountered interface type without __typename in the payload");
|
|
803
809
|
}
|
|
804
|
-
if (!
|
|
810
|
+
if (!this.isEmbedded(linkedType, entry)) {
|
|
805
811
|
const id = this.id(innerType, entry);
|
|
806
812
|
if (id) {
|
|
807
813
|
linkedID = id;
|