houdini 1.0.0-next.1 → 1.0.0-next.11
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/generate.d.ts +0 -1
- package/build/cmd-cjs/index.js +3487 -4695
- package/build/cmd-esm/index.js +3473 -4681
- package/build/codegen/generators/artifacts/fieldKey.d.ts +1 -1
- package/build/codegen/generators/artifacts/index.d.ts +2 -2
- package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
- package/build/codegen/generators/artifacts/inputs.d.ts +2 -2
- package/build/codegen/generators/artifacts/operations.d.ts +2 -2
- package/build/codegen/generators/artifacts/selection.d.ts +5 -5
- package/build/codegen/generators/artifacts/utils.d.ts +1 -2
- package/build/codegen/generators/definitions/enums.d.ts +1 -1
- package/build/codegen/generators/definitions/index.d.ts +1 -1
- package/build/codegen/generators/indexFile/index.d.ts +2 -2
- package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
- package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -0
- package/build/codegen/generators/runtime/index.d.ts +2 -2
- package/build/codegen/generators/runtime/injectPlugins.d.ts +7 -0
- package/build/codegen/generators/runtime/pluginIndex.d.ts +5 -0
- package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +1 -1
- package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
- package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
- package/build/codegen/generators/typescript/index.d.ts +2 -2
- package/build/codegen/generators/typescript/inlineType.d.ts +1 -1
- package/build/codegen/generators/typescript/typeReference.d.ts +5 -3
- package/build/codegen/generators/typescript/types.d.ts +1 -2
- package/build/codegen/index.d.ts +2 -2
- package/build/codegen/transforms/addID.d.ts +2 -2
- package/build/codegen/transforms/composeQueries.d.ts +5 -5
- package/build/codegen/transforms/fragmentVariables.d.ts +4 -3
- package/build/codegen/transforms/list.d.ts +2 -2
- package/build/codegen/transforms/paginate.d.ts +2 -2
- package/build/codegen/transforms/schema.d.ts +2 -2
- package/build/codegen/transforms/typename.d.ts +2 -2
- package/build/codegen/utils/commonjs.d.ts +2 -0
- package/build/codegen/utils/flattenSelections.d.ts +2 -2
- package/build/codegen/utils/moduleExport.d.ts +1 -1
- package/build/codegen/utils/objectIdentificationSelection.d.ts +1 -1
- package/build/codegen/validators/noIDAlias.d.ts +2 -2
- package/build/codegen/validators/plugins.d.ts +2 -2
- package/build/codegen/validators/typeCheck.d.ts +2 -2
- package/build/codegen/validators/uniqueNames.d.ts +2 -2
- package/build/codegen-cjs/index.js +3020 -4312
- package/build/codegen-esm/index.js +3058 -4350
- package/build/lib/config.d.ts +17 -91
- package/build/lib/deepMerge.d.ts +1 -0
- package/build/lib/fs.d.ts +1 -1
- package/build/lib/graphql.d.ts +5 -2
- package/build/lib/imports.d.ts +1 -1
- package/build/lib/index.d.ts +2 -0
- package/build/lib/path.d.ts +1 -1
- package/build/lib/pipeline.d.ts +1 -1
- package/build/lib/plugin.d.ts +2 -0
- package/build/lib/types.d.ts +254 -6
- package/build/lib/walk.d.ts +8 -5
- package/build/lib-cjs/index.js +885 -2394
- package/build/lib-esm/index.js +859 -2370
- package/build/runtime/cache/cache.d.ts +36 -17
- package/build/runtime/cache/gc.d.ts +1 -1
- package/build/runtime/cache/lists.d.ts +3 -2
- package/build/runtime/cache/schema.d.ts +2 -2
- package/build/runtime/cache/staleManager.d.ts +30 -0
- package/build/runtime/cache/storage.d.ts +5 -5
- package/build/runtime/cache/stuff.d.ts +1 -3
- package/build/runtime/cache/subscription.d.ts +20 -11
- package/build/runtime/client/documentStore.d.ts +88 -0
- package/build/runtime/client/index.d.ts +27 -0
- package/build/runtime/client/plugins/cache.d.ts +8 -0
- package/build/runtime/client/plugins/fetch.d.ts +37 -0
- package/build/runtime/client/plugins/fetchParams.d.ts +9 -0
- package/build/runtime/client/plugins/index.d.ts +7 -0
- package/build/runtime/client/plugins/injectedPlugins.d.ts +4 -0
- package/build/runtime/client/plugins/mutation.d.ts +1 -0
- package/build/runtime/client/plugins/query.d.ts +2 -0
- package/build/runtime/client/plugins/subscription.d.ts +17 -0
- package/build/runtime/client/plugins/throwOnError.d.ts +7 -0
- package/build/runtime/client/utils/documentPlugins.d.ts +3 -0
- package/build/runtime/client/utils/index.d.ts +1 -0
- package/build/runtime/generated.d.ts +1 -0
- package/build/runtime/imports/config.d.ts +3 -0
- package/build/runtime/index.d.ts +3 -2
- package/build/runtime/lib/config.d.ts +30 -25
- package/build/runtime/lib/flatten.d.ts +2 -0
- package/build/runtime/lib/index.d.ts +2 -2
- package/build/runtime/lib/key.d.ts +6 -0
- package/build/runtime/lib/scalars.d.ts +6 -5
- package/build/runtime/lib/selection.d.ts +1 -1
- package/build/runtime/lib/store.d.ts +19 -0
- package/build/runtime/lib/types.d.ts +27 -13
- package/build/runtime/public/cache.d.ts +27 -7
- package/build/runtime/public/list.d.ts +2 -2
- package/build/runtime/public/record.d.ts +27 -18
- package/build/runtime/public/tests/test.d.ts +53 -11
- package/build/runtime/public/types.d.ts +8 -0
- package/build/runtime-cjs/cache/cache.d.ts +36 -17
- package/build/runtime-cjs/cache/cache.js +102 -33
- package/build/runtime-cjs/cache/gc.d.ts +1 -1
- package/build/runtime-cjs/cache/gc.js +9 -0
- package/build/runtime-cjs/cache/lists.d.ts +3 -2
- package/build/runtime-cjs/cache/lists.js +11 -8
- package/build/runtime-cjs/cache/schema.d.ts +2 -2
- package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
- package/build/runtime-cjs/cache/staleManager.js +95 -0
- package/build/runtime-cjs/cache/storage.d.ts +5 -5
- package/build/runtime-cjs/cache/storage.js +2 -2
- package/build/runtime-cjs/cache/stuff.d.ts +1 -3
- package/build/runtime-cjs/cache/stuff.js +2 -19
- package/build/runtime-cjs/cache/subscription.d.ts +20 -11
- package/build/runtime-cjs/cache/subscription.js +102 -59
- package/build/runtime-cjs/client/documentStore.d.ts +88 -0
- package/build/runtime-cjs/client/documentStore.js +361 -0
- package/build/runtime-cjs/client/index.d.ts +27 -0
- package/build/runtime-cjs/client/index.js +113 -0
- package/build/runtime-cjs/client/plugins/cache.d.ts +8 -0
- package/build/runtime-cjs/client/plugins/cache.js +101 -0
- package/build/runtime-cjs/client/plugins/fetch.d.ts +37 -0
- package/build/runtime-cjs/{lib/networkUtils.js → client/plugins/fetch.js} +96 -3
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +9 -0
- package/build/runtime-cjs/client/plugins/fetchParams.js +45 -0
- package/build/runtime-cjs/client/plugins/index.d.ts +7 -0
- package/build/runtime-cjs/client/plugins/index.js +24 -0
- package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +4 -0
- package/build/runtime-cjs/{lib/errors.js → client/plugins/injectedPlugins.js} +7 -15
- package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -0
- package/build/runtime-cjs/client/plugins/mutation.js +86 -0
- package/build/runtime-cjs/client/plugins/query.d.ts +2 -0
- package/build/runtime-cjs/client/plugins/query.js +83 -0
- package/build/runtime-cjs/client/plugins/subscription.d.ts +17 -0
- package/build/runtime-cjs/client/plugins/subscription.js +100 -0
- package/build/runtime-cjs/client/plugins/throwOnError.d.ts +7 -0
- package/build/runtime-cjs/client/plugins/throwOnError.js +47 -0
- package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -0
- package/build/runtime-cjs/client/utils/documentPlugins.js +56 -0
- package/build/runtime-cjs/client/utils/index.d.ts +1 -0
- package/build/runtime-cjs/client/utils/index.js +18 -0
- package/build/runtime-cjs/generated.d.ts +1 -0
- package/build/runtime-cjs/imports/config.d.ts +3 -0
- package/build/runtime-cjs/imports/config.js +26 -0
- package/build/runtime-cjs/index.d.ts +3 -2
- package/build/runtime-cjs/index.js +1 -0
- package/build/runtime-cjs/lib/config.d.ts +30 -25
- package/build/runtime-cjs/lib/config.js +5 -4
- package/build/runtime-cjs/lib/flatten.d.ts +2 -0
- package/build/runtime-cjs/lib/flatten.js +41 -0
- package/build/runtime-cjs/lib/index.d.ts +2 -2
- package/build/runtime-cjs/lib/index.js +2 -2
- package/build/runtime-cjs/lib/key.d.ts +6 -0
- package/build/runtime-cjs/lib/key.js +41 -0
- package/build/runtime-cjs/lib/scalars.d.ts +6 -5
- package/build/runtime-cjs/lib/scalars.js +20 -24
- package/build/runtime-cjs/lib/selection.d.ts +1 -1
- package/build/runtime-cjs/lib/store.d.ts +19 -0
- package/build/runtime-cjs/lib/store.js +81 -0
- package/build/runtime-cjs/lib/types.d.ts +27 -13
- package/build/runtime-cjs/public/cache.d.ts +27 -7
- package/build/runtime-cjs/public/cache.js +32 -32
- package/build/runtime-cjs/public/list.d.ts +2 -2
- package/build/runtime-cjs/public/list.js +6 -28
- package/build/runtime-cjs/public/record.d.ts +27 -18
- package/build/runtime-cjs/public/record.js +28 -188
- package/build/runtime-cjs/public/tests/test.d.ts +53 -11
- package/build/runtime-cjs/public/tests/test.js +27 -2
- package/build/runtime-cjs/public/types.d.ts +8 -0
- package/build/runtime-esm/cache/cache.d.ts +36 -17
- package/build/runtime-esm/cache/cache.js +104 -35
- package/build/runtime-esm/cache/gc.d.ts +1 -1
- package/build/runtime-esm/cache/gc.js +9 -0
- package/build/runtime-esm/cache/lists.d.ts +3 -2
- package/build/runtime-esm/cache/lists.js +11 -8
- package/build/runtime-esm/cache/schema.d.ts +2 -2
- package/build/runtime-esm/cache/staleManager.d.ts +30 -0
- package/build/runtime-esm/cache/staleManager.js +71 -0
- package/build/runtime-esm/cache/storage.d.ts +5 -5
- package/build/runtime-esm/cache/storage.js +2 -2
- package/build/runtime-esm/cache/stuff.d.ts +1 -3
- package/build/runtime-esm/cache/stuff.js +1 -17
- package/build/runtime-esm/cache/subscription.d.ts +20 -11
- package/build/runtime-esm/cache/subscription.js +103 -60
- package/build/runtime-esm/client/documentStore.d.ts +88 -0
- package/build/runtime-esm/client/documentStore.js +337 -0
- package/build/runtime-esm/client/index.d.ts +27 -0
- package/build/runtime-esm/client/index.js +83 -0
- package/build/runtime-esm/client/plugins/cache.d.ts +8 -0
- package/build/runtime-esm/client/plugins/cache.js +71 -0
- package/build/runtime-esm/client/plugins/fetch.d.ts +37 -0
- package/build/runtime-esm/client/plugins/fetch.js +152 -0
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +9 -0
- package/build/runtime-esm/client/plugins/fetchParams.js +21 -0
- package/build/runtime-esm/client/plugins/index.d.ts +7 -0
- package/build/runtime-esm/client/plugins/index.js +7 -0
- package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +4 -0
- package/build/runtime-esm/client/plugins/injectedPlugins.js +5 -0
- package/build/runtime-esm/client/plugins/mutation.d.ts +1 -0
- package/build/runtime-esm/client/plugins/mutation.js +56 -0
- package/build/runtime-esm/client/plugins/query.d.ts +2 -0
- package/build/runtime-esm/client/plugins/query.js +53 -0
- package/build/runtime-esm/client/plugins/subscription.d.ts +17 -0
- package/build/runtime-esm/client/plugins/subscription.js +76 -0
- package/build/runtime-esm/client/plugins/throwOnError.d.ts +7 -0
- package/build/runtime-esm/client/plugins/throwOnError.js +23 -0
- package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -0
- package/build/runtime-esm/client/utils/documentPlugins.js +32 -0
- package/build/runtime-esm/client/utils/index.d.ts +1 -0
- package/build/runtime-esm/client/utils/index.js +1 -0
- package/build/runtime-esm/generated.d.ts +1 -0
- package/build/runtime-esm/imports/config.d.ts +3 -0
- package/build/runtime-esm/imports/config.js +4 -0
- package/build/runtime-esm/index.d.ts +3 -2
- package/build/runtime-esm/index.js +1 -0
- package/build/runtime-esm/lib/config.d.ts +30 -25
- package/build/runtime-esm/lib/config.js +5 -4
- package/build/runtime-esm/lib/flatten.d.ts +2 -0
- package/build/runtime-esm/lib/flatten.js +17 -0
- package/build/runtime-esm/lib/index.d.ts +2 -2
- package/build/runtime-esm/lib/index.js +2 -2
- package/build/runtime-esm/lib/key.d.ts +6 -0
- package/build/runtime-esm/lib/key.js +17 -0
- package/build/runtime-esm/lib/scalars.d.ts +6 -5
- package/build/runtime-esm/lib/scalars.js +20 -24
- package/build/runtime-esm/lib/selection.d.ts +1 -1
- package/build/runtime-esm/lib/store.d.ts +19 -0
- package/build/runtime-esm/lib/store.js +57 -0
- package/build/runtime-esm/lib/types.d.ts +27 -13
- package/build/runtime-esm/public/cache.d.ts +27 -7
- package/build/runtime-esm/public/cache.js +31 -30
- package/build/runtime-esm/public/list.d.ts +2 -2
- package/build/runtime-esm/public/list.js +6 -28
- package/build/runtime-esm/public/record.d.ts +27 -18
- package/build/runtime-esm/public/record.js +27 -184
- package/build/runtime-esm/public/tests/test.d.ts +53 -11
- package/build/runtime-esm/public/tests/test.js +26 -1
- package/build/runtime-esm/public/types.d.ts +8 -0
- package/build/test/index.d.ts +6 -5
- package/build/test-cjs/index.js +3051 -4304
- package/build/test-esm/index.js +3048 -4301
- package/build/vite/ast.d.ts +1 -1
- package/build/vite/houdini.d.ts +1 -1
- package/build/vite/imports.d.ts +3 -3
- package/build/vite/index.d.ts +1 -1
- package/build/vite/schema.d.ts +1 -1
- package/build/vite-cjs/index.js +3499 -4691
- package/build/vite-esm/index.js +3448 -4640
- package/package.json +6 -5
- package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
- package/build/runtime/lib/errors.d.ts +0 -3
- package/build/runtime/lib/network.d.ts +0 -79
- package/build/runtime/lib/networkUtils.d.ts +0 -8
- package/build/runtime-cjs/lib/errors.d.ts +0 -3
- package/build/runtime-cjs/lib/network.d.ts +0 -79
- package/build/runtime-cjs/lib/network.js +0 -200
- package/build/runtime-cjs/lib/networkUtils.d.ts +0 -8
- package/build/runtime-esm/lib/errors.d.ts +0 -3
- package/build/runtime-esm/lib/errors.js +0 -11
- package/build/runtime-esm/lib/network.d.ts +0 -79
- package/build/runtime-esm/lib/network.js +0 -170
- package/build/runtime-esm/lib/networkUtils.d.ts +0 -8
- package/build/runtime-esm/lib/networkUtils.js +0 -60
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { computeKey } from "../lib";
|
|
2
|
+
class StaleManager {
|
|
3
|
+
cache;
|
|
4
|
+
fieldsTime = /* @__PURE__ */ new Map();
|
|
5
|
+
constructor(cache) {
|
|
6
|
+
this.cache = cache;
|
|
7
|
+
}
|
|
8
|
+
#initMapId = (id) => {
|
|
9
|
+
if (!this.fieldsTime.get(id)) {
|
|
10
|
+
this.fieldsTime.set(id, /* @__PURE__ */ new Map());
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
getFieldTime(id, field) {
|
|
14
|
+
return this.fieldsTime.get(id)?.get(field);
|
|
15
|
+
}
|
|
16
|
+
setFieldTimeToNow(id, field) {
|
|
17
|
+
this.#initMapId(id);
|
|
18
|
+
this.fieldsTime.get(id)?.set(field, new Date().valueOf());
|
|
19
|
+
}
|
|
20
|
+
markFieldStale(id, field) {
|
|
21
|
+
this.#initMapId(id);
|
|
22
|
+
this.fieldsTime.get(id)?.set(field, null);
|
|
23
|
+
}
|
|
24
|
+
markAllStale() {
|
|
25
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
26
|
+
for (const [field] of fieldMap.entries()) {
|
|
27
|
+
this.markFieldStale(id, field);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
markRecordStale(id) {
|
|
32
|
+
const fieldsTimeOfType = this.fieldsTime.get(id);
|
|
33
|
+
if (fieldsTimeOfType) {
|
|
34
|
+
for (const [field] of fieldsTimeOfType.entries()) {
|
|
35
|
+
this.markFieldStale(id, field);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
markTypeStale(type) {
|
|
40
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
41
|
+
if (id.startsWith(`${type}:`)) {
|
|
42
|
+
for (const [field] of fieldMap.entries()) {
|
|
43
|
+
this.markFieldStale(id, field);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
markTypeFieldStale(type, field, when) {
|
|
49
|
+
const key = computeKey({ field, args: when });
|
|
50
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
51
|
+
if (id.startsWith(`${type}:`)) {
|
|
52
|
+
for (const local_field of fieldMap.keys()) {
|
|
53
|
+
if (local_field === key) {
|
|
54
|
+
this.markFieldStale(id, field);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
delete(id, field) {
|
|
61
|
+
if (this.fieldsTime.has(id)) {
|
|
62
|
+
this.fieldsTime.get(id)?.delete(field);
|
|
63
|
+
if (this.fieldsTime.get(id)?.size === 0) {
|
|
64
|
+
this.fieldsTime.delete(id);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
StaleManager
|
|
71
|
+
};
|
|
@@ -21,7 +21,7 @@ export declare class InMemoryStorage {
|
|
|
21
21
|
kind: 'link' | 'scalar' | 'unknown';
|
|
22
22
|
displayLayers: number[];
|
|
23
23
|
};
|
|
24
|
-
writeLink(id: string, field: string, value: string |
|
|
24
|
+
writeLink(id: string, field: string, value: string | NestedList): number;
|
|
25
25
|
writeField(id: string, field: string, value: GraphQLValue): number;
|
|
26
26
|
resolveLayer(id: number): void;
|
|
27
27
|
get topLayer(): Layer;
|
|
@@ -37,7 +37,7 @@ export declare class Layer {
|
|
|
37
37
|
get(id: string, field: string): [GraphQLField, 'link' | 'scalar'];
|
|
38
38
|
getOperations(id: string, field: string): Operation[] | undefined;
|
|
39
39
|
writeField(id: string, field: string, value: GraphQLField): LayerID;
|
|
40
|
-
writeLink(id: string, field: string, value: null | string |
|
|
40
|
+
writeLink(id: string, field: string, value: null | string | NestedList): LayerID;
|
|
41
41
|
isDisplayLayer(displayLayers: number[]): boolean;
|
|
42
42
|
clear(): void;
|
|
43
43
|
replaceID({ from, to }: {
|
|
@@ -52,14 +52,14 @@ export declare class Layer {
|
|
|
52
52
|
writeLayer(layer: Layer): void;
|
|
53
53
|
private addFieldOperation;
|
|
54
54
|
}
|
|
55
|
-
type GraphQLField = GraphQLValue |
|
|
55
|
+
type GraphQLField = GraphQLValue | NestedList;
|
|
56
56
|
type EntityMap<_Value> = {
|
|
57
57
|
[id: string]: {
|
|
58
58
|
[field: string]: _Value;
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
61
|
type EntityFieldMap = EntityMap<GraphQLField>;
|
|
62
|
-
type LinkMap = EntityMap<string | null |
|
|
62
|
+
type LinkMap = EntityMap<string | null | NestedList>;
|
|
63
63
|
type OperationMap = {
|
|
64
64
|
[id: string]: {
|
|
65
65
|
deleted?: boolean;
|
|
@@ -69,7 +69,7 @@ type OperationMap = {
|
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
|
-
type
|
|
72
|
+
type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
|
|
73
73
|
type InsertOperation = {
|
|
74
74
|
kind: OperationKind.insert;
|
|
75
75
|
location: OperationLocation;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flatten } from "../lib/flatten";
|
|
2
2
|
class InMemoryStorage {
|
|
3
3
|
data;
|
|
4
4
|
idCount = 0;
|
|
@@ -198,7 +198,7 @@ class Layer {
|
|
|
198
198
|
}
|
|
199
199
|
writeLink(id, field, value) {
|
|
200
200
|
const valueList = Array.isArray(value) ? value : [value];
|
|
201
|
-
for (const value2 of
|
|
201
|
+
for (const value2 of flatten(valueList)) {
|
|
202
202
|
if (!value2) {
|
|
203
203
|
continue;
|
|
204
204
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { GraphQLValue } from '../lib/types';
|
|
2
|
-
import { LinkedList } from './cache';
|
|
3
|
-
export declare function flattenList<T>(source: LinkedList<T>): T[];
|
|
1
|
+
import type { GraphQLValue } from '../lib/types';
|
|
4
2
|
export declare function evaluateKey(key: string, variables?: {
|
|
5
3
|
[key: string]: GraphQLValue;
|
|
6
4
|
}): string;
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
function flattenList(source) {
|
|
2
|
-
const flat = [];
|
|
3
|
-
const unvisited = [source || []];
|
|
4
|
-
while (unvisited.length > 0) {
|
|
5
|
-
const target = unvisited.shift();
|
|
6
|
-
for (const id of target) {
|
|
7
|
-
if (Array.isArray(id)) {
|
|
8
|
-
unvisited.push(id);
|
|
9
|
-
continue;
|
|
10
|
-
}
|
|
11
|
-
flat.push(id);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return flat;
|
|
15
|
-
}
|
|
16
1
|
function evaluateKey(key, variables = {}) {
|
|
17
2
|
let evaluated = "";
|
|
18
3
|
let varName = "";
|
|
@@ -40,6 +25,5 @@ function evaluateKey(key, variables = {}) {
|
|
|
40
25
|
}
|
|
41
26
|
const varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
|
|
42
27
|
export {
|
|
43
|
-
evaluateKey
|
|
44
|
-
flattenList
|
|
28
|
+
evaluateKey
|
|
45
29
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
|
|
2
|
+
import type { Cache } from './cache';
|
|
3
|
+
export type FieldSelection = [
|
|
4
|
+
SubscriptionSpec,
|
|
5
|
+
Required<SubscriptionSelection>['fields'] | undefined
|
|
6
|
+
];
|
|
4
7
|
export declare class InMemorySubscriptions {
|
|
5
8
|
private cache;
|
|
6
9
|
constructor(cache: Cache);
|
|
@@ -16,22 +19,28 @@ export declare class InMemorySubscriptions {
|
|
|
16
19
|
[key: string]: GraphQLValue;
|
|
17
20
|
};
|
|
18
21
|
}): void;
|
|
19
|
-
addFieldSubscription({ id, key,
|
|
22
|
+
addFieldSubscription({ id, key, selection, type, }: {
|
|
20
23
|
id: string;
|
|
21
24
|
key: string;
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
selection: FieldSelection;
|
|
26
|
+
type: string;
|
|
27
|
+
}): void;
|
|
28
|
+
registerList({ list, id, key, parentType, selection, filters, variables, }: {
|
|
29
|
+
list: Required<Required<SubscriptionSelection>['fields'][string]>['list'];
|
|
30
|
+
selection: SubscriptionSelection;
|
|
31
|
+
id: string;
|
|
24
32
|
parentType: string;
|
|
25
|
-
|
|
33
|
+
key: string;
|
|
34
|
+
filters: Required<SubscriptionSelection>['fields'][string]['filters'];
|
|
35
|
+
variables: Record<string, any>;
|
|
26
36
|
}): void;
|
|
27
|
-
addMany({ parent,
|
|
37
|
+
addMany({ parent, variables, subscribers, parentType, }: {
|
|
28
38
|
parent: string;
|
|
29
|
-
selection: SubscriptionSelection;
|
|
30
39
|
variables: {};
|
|
31
|
-
subscribers:
|
|
40
|
+
subscribers: FieldSelection[];
|
|
32
41
|
parentType: string;
|
|
33
42
|
}): void;
|
|
34
|
-
get(id: string, field: string):
|
|
43
|
+
get(id: string, field: string): FieldSelection[];
|
|
35
44
|
remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
|
|
36
45
|
private removeSubscribers;
|
|
37
46
|
removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { flatten } from "../lib/flatten";
|
|
1
2
|
import { getFieldsForType } from "../lib/selection";
|
|
2
|
-
import { evaluateKey
|
|
3
|
+
import { evaluateKey } from "./stuff";
|
|
3
4
|
class InMemorySubscriptions {
|
|
4
5
|
cache;
|
|
5
6
|
constructor(cache) {
|
|
@@ -18,22 +19,36 @@ class InMemorySubscriptions {
|
|
|
18
19
|
const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
19
20
|
let targetSelection = getFieldsForType(selection, __typename);
|
|
20
21
|
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
21
|
-
const { keyRaw, selection: innerSelection, type } = fieldSelection;
|
|
22
|
+
const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
|
|
22
23
|
const key = evaluateKey(keyRaw, variables);
|
|
24
|
+
let targetSelection2;
|
|
25
|
+
if (innerSelection) {
|
|
26
|
+
const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
27
|
+
targetSelection2 = getFieldsForType(innerSelection, __typename2);
|
|
28
|
+
}
|
|
23
29
|
this.addFieldSubscription({
|
|
24
30
|
id: parent,
|
|
25
31
|
key,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
parentType: parentType || spec.rootType,
|
|
29
|
-
variables
|
|
32
|
+
selection: [spec, targetSelection2],
|
|
33
|
+
type
|
|
30
34
|
});
|
|
35
|
+
if (list) {
|
|
36
|
+
this.registerList({
|
|
37
|
+
list,
|
|
38
|
+
filters,
|
|
39
|
+
id: parent,
|
|
40
|
+
key,
|
|
41
|
+
variables,
|
|
42
|
+
selection: innerSelection,
|
|
43
|
+
parentType: parentType || spec.rootType
|
|
44
|
+
});
|
|
45
|
+
}
|
|
31
46
|
if (innerSelection) {
|
|
32
47
|
const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
|
|
33
48
|
parent,
|
|
34
49
|
key
|
|
35
50
|
);
|
|
36
|
-
let children = !Array.isArray(linkedRecord) ? [linkedRecord] :
|
|
51
|
+
let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
|
|
37
52
|
for (const child of children) {
|
|
38
53
|
if (!child) {
|
|
39
54
|
continue;
|
|
@@ -52,11 +67,10 @@ class InMemorySubscriptions {
|
|
|
52
67
|
addFieldSubscription({
|
|
53
68
|
id,
|
|
54
69
|
key,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
parentType,
|
|
58
|
-
variables
|
|
70
|
+
selection,
|
|
71
|
+
type
|
|
59
72
|
}) {
|
|
73
|
+
const spec = selection[0];
|
|
60
74
|
if (!this.subscribers[id]) {
|
|
61
75
|
this.subscribers[id] = {};
|
|
62
76
|
}
|
|
@@ -67,8 +81,8 @@ class InMemorySubscriptions {
|
|
|
67
81
|
this.keyVersions[key] = /* @__PURE__ */ new Set();
|
|
68
82
|
}
|
|
69
83
|
this.keyVersions[key].add(key);
|
|
70
|
-
if (!this.subscribers[id][key].map(({ set }) => set).includes(spec.set)) {
|
|
71
|
-
this.subscribers[id][key].push(spec);
|
|
84
|
+
if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
|
|
85
|
+
this.subscribers[id][key].push([spec, selection[1]]);
|
|
72
86
|
}
|
|
73
87
|
if (!this.referenceCounts[id]) {
|
|
74
88
|
this.referenceCounts[id] = {};
|
|
@@ -79,61 +93,88 @@ class InMemorySubscriptions {
|
|
|
79
93
|
const counts = this.referenceCounts[id][key];
|
|
80
94
|
counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
|
|
81
95
|
this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
|
|
82
|
-
const { selection
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
const { selection: innerSelection } = selection[1]?.[key] ?? {};
|
|
97
|
+
}
|
|
98
|
+
registerList({
|
|
99
|
+
list,
|
|
100
|
+
id,
|
|
101
|
+
key,
|
|
102
|
+
parentType,
|
|
103
|
+
selection,
|
|
104
|
+
filters,
|
|
105
|
+
variables
|
|
106
|
+
}) {
|
|
107
|
+
this.cache._internal_unstable.lists.add({
|
|
108
|
+
name: list.name,
|
|
109
|
+
connection: list.connection,
|
|
110
|
+
recordID: id,
|
|
111
|
+
recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
|
|
112
|
+
listType: list.type,
|
|
113
|
+
key,
|
|
114
|
+
selection,
|
|
115
|
+
filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
|
|
116
|
+
return {
|
|
117
|
+
...acc,
|
|
118
|
+
[key2]: kind !== "Variable" ? value : variables[value]
|
|
119
|
+
};
|
|
120
|
+
}, {})
|
|
121
|
+
});
|
|
100
122
|
}
|
|
101
123
|
addMany({
|
|
102
124
|
parent,
|
|
103
|
-
selection,
|
|
104
125
|
variables,
|
|
105
126
|
subscribers,
|
|
106
127
|
parentType
|
|
107
128
|
}) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
129
|
+
for (const [spec, targetSelection] of subscribers) {
|
|
130
|
+
for (const selection of Object.values(targetSelection ?? {})) {
|
|
131
|
+
const {
|
|
132
|
+
type: linkedType,
|
|
133
|
+
keyRaw,
|
|
134
|
+
selection: innerSelection,
|
|
135
|
+
list,
|
|
136
|
+
filters
|
|
137
|
+
} = selection;
|
|
138
|
+
const key = evaluateKey(keyRaw, variables);
|
|
139
|
+
const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType) : void 0;
|
|
113
140
|
this.addFieldSubscription({
|
|
114
141
|
id: parent,
|
|
115
142
|
key,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
parentType,
|
|
119
|
-
variables
|
|
143
|
+
selection: [spec, fieldSelection],
|
|
144
|
+
type: linkedType
|
|
120
145
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
this.addMany({
|
|
130
|
-
parent: linkedRecord,
|
|
131
|
-
selection: innerSelection,
|
|
146
|
+
if (list) {
|
|
147
|
+
this.registerList({
|
|
148
|
+
list,
|
|
149
|
+
filters,
|
|
150
|
+
id: parent,
|
|
151
|
+
key,
|
|
132
152
|
variables,
|
|
133
|
-
|
|
134
|
-
parentType:
|
|
153
|
+
selection: innerSelection,
|
|
154
|
+
parentType: parentType || spec.rootType
|
|
135
155
|
});
|
|
136
156
|
}
|
|
157
|
+
const childSelection = selection.selection;
|
|
158
|
+
if (childSelection) {
|
|
159
|
+
const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
|
|
160
|
+
const children = !Array.isArray(link) ? [link] : flatten(link);
|
|
161
|
+
for (const linkedRecord of children) {
|
|
162
|
+
if (!linkedRecord) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const __typename = this.cache._internal_unstable.storage.get(
|
|
166
|
+
linkedRecord,
|
|
167
|
+
"__typename"
|
|
168
|
+
).value;
|
|
169
|
+
let targetSelection2 = getFieldsForType(childSelection, __typename);
|
|
170
|
+
this.addMany({
|
|
171
|
+
parent: linkedRecord,
|
|
172
|
+
variables,
|
|
173
|
+
subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
|
|
174
|
+
parentType: linkedType
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
137
178
|
}
|
|
138
179
|
}
|
|
139
180
|
}
|
|
@@ -143,14 +184,16 @@ class InMemorySubscriptions {
|
|
|
143
184
|
remove(id, selection, targets, variables, visited = []) {
|
|
144
185
|
visited.push(id);
|
|
145
186
|
const linkedIDs = [];
|
|
146
|
-
|
|
187
|
+
const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
|
|
188
|
+
let targetSelection = getFieldsForType(selection, __typename);
|
|
189
|
+
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
147
190
|
const key = evaluateKey(fieldSelection.keyRaw, variables);
|
|
148
191
|
this.removeSubscribers(id, key, targets);
|
|
149
|
-
if (!fieldSelection.selection
|
|
192
|
+
if (!fieldSelection.selection) {
|
|
150
193
|
continue;
|
|
151
194
|
}
|
|
152
195
|
const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
|
|
153
|
-
const links = !Array.isArray(previousValue) ? [previousValue] :
|
|
196
|
+
const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
|
|
154
197
|
for (const link of links) {
|
|
155
198
|
if (link !== null) {
|
|
156
199
|
linkedIDs.push([link, fieldSelection.selection || {}]);
|
|
@@ -177,20 +220,20 @@ class InMemorySubscriptions {
|
|
|
177
220
|
}
|
|
178
221
|
if (this.subscribers[id]) {
|
|
179
222
|
this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
|
|
180
|
-
({ set }) => !targets.includes(set)
|
|
223
|
+
([{ set }]) => !targets.includes(set)
|
|
181
224
|
);
|
|
182
225
|
}
|
|
183
226
|
}
|
|
184
227
|
removeAllSubscribers(id, targets, visited = []) {
|
|
185
228
|
visited.push(id);
|
|
186
229
|
for (const field of Object.keys(this.subscribers[id] || [])) {
|
|
187
|
-
const subscribers = targets || this.subscribers[id][field];
|
|
230
|
+
const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
|
|
188
231
|
this.removeSubscribers(id, field, subscribers);
|
|
189
232
|
const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
|
|
190
233
|
if (kind === "scalar") {
|
|
191
234
|
continue;
|
|
192
235
|
}
|
|
193
|
-
const nextTargets = Array.isArray(value) ?
|
|
236
|
+
const nextTargets = Array.isArray(value) ? flatten(value) : [value];
|
|
194
237
|
for (const id2 of nextTargets) {
|
|
195
238
|
if (visited.includes(id2)) {
|
|
196
239
|
continue;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { HoudiniClient } from '.';
|
|
2
|
+
import type { Layer } from '../cache/storage';
|
|
3
|
+
import type { ConfigFile } from '../lib/config';
|
|
4
|
+
import { Writable } from '../lib/store';
|
|
5
|
+
import type { CachePolicy, DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec } from '../lib/types';
|
|
6
|
+
export declare class DocumentStore<_Data extends GraphQLObject, _Input extends Record<string, any>> extends Writable<QueryResult<_Data, _Input>> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
|
|
9
|
+
artifact: DocumentArtifact;
|
|
10
|
+
plugins?: ClientHooks[];
|
|
11
|
+
pipeline?: ClientHooks[];
|
|
12
|
+
client: HoudiniClient | null;
|
|
13
|
+
cache?: boolean;
|
|
14
|
+
initialValue?: _Data | null;
|
|
15
|
+
fetching?: boolean;
|
|
16
|
+
});
|
|
17
|
+
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, }?: {
|
|
18
|
+
fetch?: Fetch;
|
|
19
|
+
variables?: Record<string, any> | null;
|
|
20
|
+
metadata?: App.Metadata | null;
|
|
21
|
+
session?: App.Session | null;
|
|
22
|
+
policy?: CachePolicy;
|
|
23
|
+
stuff?: Partial<App.Stuff>;
|
|
24
|
+
cacheParams?: ClientPluginContext['cacheParams'];
|
|
25
|
+
setup?: boolean;
|
|
26
|
+
}): Promise<QueryResult<_Data, _Input>>;
|
|
27
|
+
}
|
|
28
|
+
declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
|
|
29
|
+
export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
|
|
30
|
+
export type ClientHooks = {
|
|
31
|
+
start?: ClientPluginEnterPhase;
|
|
32
|
+
beforeNetwork?: ClientPluginEnterPhase;
|
|
33
|
+
network?: ClientPluginEnterPhase;
|
|
34
|
+
afterNetwork?: ClientPluginExitPhase;
|
|
35
|
+
end?: ClientPluginExitPhase;
|
|
36
|
+
cleanup?(ctx: ClientPluginContext): void | Promise<void>;
|
|
37
|
+
catch?(ctx: ClientPluginContext, args: ClientPluginErrorHandlers): void | Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
export type Fetch = typeof globalThis.fetch;
|
|
40
|
+
export type ClientPluginContext = {
|
|
41
|
+
config: ConfigFile;
|
|
42
|
+
text: string;
|
|
43
|
+
hash: string;
|
|
44
|
+
artifact: DocumentArtifact;
|
|
45
|
+
policy?: CachePolicy;
|
|
46
|
+
fetch?: Fetch;
|
|
47
|
+
variables?: Record<string, any>;
|
|
48
|
+
metadata?: App.Metadata | null;
|
|
49
|
+
session?: App.Session | null;
|
|
50
|
+
fetchParams?: RequestInit;
|
|
51
|
+
cacheParams?: {
|
|
52
|
+
layer?: Layer;
|
|
53
|
+
notifySubscribers?: SubscriptionSpec[];
|
|
54
|
+
forceNotify?: boolean;
|
|
55
|
+
disableWrite?: boolean;
|
|
56
|
+
disableRead?: boolean;
|
|
57
|
+
applyUpdates?: string[];
|
|
58
|
+
};
|
|
59
|
+
stuff: App.Stuff;
|
|
60
|
+
};
|
|
61
|
+
type ClientPluginPhase<Handlers> = (ctx: ClientPluginContext, handlers: Handlers) => void | Promise<void>;
|
|
62
|
+
export type ClientPluginEnterPhase = ClientPluginPhase<ClientPluginEnterHandlers>;
|
|
63
|
+
export type ClientPluginExitPhase = ClientPluginPhase<ClientPluginExitHandlers>;
|
|
64
|
+
export type ClientPluginEnterHandlers = {
|
|
65
|
+
initialValue: QueryResult;
|
|
66
|
+
/** A reference to the houdini client to access any configuration values */
|
|
67
|
+
client: HoudiniClient;
|
|
68
|
+
/** Move onto the next step using the provided context. */
|
|
69
|
+
next(ctx: ClientPluginContext): void;
|
|
70
|
+
/** Terminate the current chain */
|
|
71
|
+
resolve(ctx: ClientPluginContext, data: QueryResult): void;
|
|
72
|
+
/** Update the stores state without resolving the promise */
|
|
73
|
+
updateState(updater: (old: QueryResult) => QueryResult): void;
|
|
74
|
+
/** Return true if the variables have changed */
|
|
75
|
+
variablesChanged: (ctx: ClientPluginContext) => boolean;
|
|
76
|
+
/** Returns the marshaled variables for the operation */
|
|
77
|
+
marshalVariables: typeof marshalVariables;
|
|
78
|
+
};
|
|
79
|
+
/** Exit handlers are the same as enter handles but don't need to resolve with a specific value */
|
|
80
|
+
export type ClientPluginExitHandlers = Omit<ClientPluginEnterHandlers, 'resolve'> & {
|
|
81
|
+
resolve: (ctx: ClientPluginContext, data?: QueryResult) => void;
|
|
82
|
+
value: QueryResult;
|
|
83
|
+
};
|
|
84
|
+
/** Exit handlers are the same as enter handles but don't need to resolve with a specific value */
|
|
85
|
+
export type ClientPluginErrorHandlers = ClientPluginEnterHandlers & {
|
|
86
|
+
error: unknown;
|
|
87
|
+
};
|
|
88
|
+
export {};
|