houdini 1.0.0-next.2 → 1.0.0-next.21
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/README.md +4 -1
- package/build/cmd-cjs/index.js +5366 -2772
- package/build/cmd-esm/index.js +5340 -2746
- 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/selection.d.ts +5 -5
- package/build/codegen/generators/artifacts/utils.d.ts +0 -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 -2
- package/build/codegen/generators/runtime/index.d.ts +2 -2
- package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
- 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/typeReference.d.ts +4 -2
- package/build/codegen/generators/typescript/types.d.ts +0 -1
- package/build/codegen/index.d.ts +2 -2
- package/build/codegen/transforms/addID.d.ts +2 -2
- package/build/codegen/transforms/composeQueries.d.ts +4 -4
- package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
- 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/flattenSelections.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 +4694 -2137
- package/build/codegen-esm/index.js +4682 -2125
- package/build/lib/config.d.ts +15 -96
- package/build/lib/deepMerge.d.ts +1 -0
- package/build/lib/graphql.d.ts +5 -2
- 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 +257 -6
- package/build/lib/walk.d.ts +4 -1
- package/build/lib-cjs/index.js +4108 -928
- package/build/lib-esm/index.js +4078 -907
- package/build/runtime/cache/cache.d.ts +28 -11
- package/build/runtime/cache/lists.d.ts +1 -0
- package/build/runtime/cache/staleManager.d.ts +30 -0
- package/build/runtime/cache/storage.d.ts +23 -20
- package/build/runtime/cache/stuff.d.ts +0 -2
- package/build/runtime/cache/subscription.d.ts +2 -1
- package/build/runtime/client/documentStore.d.ts +20 -17
- package/build/runtime/client/index.d.ts +13 -11
- package/build/runtime/client/plugins/cache.d.ts +1 -1
- package/build/runtime/client/plugins/fetch.d.ts +1 -1
- package/build/runtime/client/plugins/fetchParams.d.ts +2 -2
- package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime/client/plugins/mutation.d.ts +1 -1
- package/build/runtime/client/plugins/query.d.ts +1 -1
- package/build/runtime/client/plugins/subscription.d.ts +2 -3
- package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime/client/utils/documentPlugins.d.ts +3 -3
- package/build/runtime/generated.d.ts +1 -0
- package/build/runtime/imports/pluginConfig.d.ts +3 -0
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/lib/config.d.ts +27 -24
- package/build/runtime/lib/flatten.d.ts +2 -0
- package/build/runtime/lib/index.d.ts +1 -0
- package/build/runtime/lib/key.d.ts +6 -0
- package/build/runtime/lib/scalars.d.ts +3 -3
- package/build/runtime/lib/types.d.ts +47 -47
- package/build/runtime/public/cache.d.ts +26 -6
- package/build/runtime/public/record.d.ts +26 -17
- package/build/runtime/public/tests/test.d.ts +52 -10
- package/build/runtime/public/types.d.ts +8 -0
- package/build/runtime-cjs/cache/cache.d.ts +28 -11
- package/build/runtime-cjs/cache/cache.js +97 -22
- package/build/runtime-cjs/cache/gc.js +9 -0
- package/build/runtime-cjs/cache/lists.d.ts +1 -0
- package/build/runtime-cjs/cache/lists.js +9 -6
- 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 +23 -20
- package/build/runtime-cjs/cache/storage.js +11 -13
- package/build/runtime-cjs/cache/stuff.d.ts +0 -2
- package/build/runtime-cjs/cache/stuff.js +2 -19
- package/build/runtime-cjs/cache/subscription.d.ts +2 -1
- package/build/runtime-cjs/cache/subscription.js +11 -7
- package/build/runtime-cjs/client/documentStore.d.ts +20 -17
- package/build/runtime-cjs/client/documentStore.js +13 -9
- package/build/runtime-cjs/client/index.d.ts +13 -11
- package/build/runtime-cjs/client/index.js +48 -19
- package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/cache.js +12 -10
- package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetch.js +10 -9
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +2 -2
- package/build/runtime-cjs/client/plugins/fetchParams.js +9 -4
- package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/mutation.js +3 -3
- package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/query.js +5 -5
- package/build/runtime-cjs/client/plugins/subscription.d.ts +2 -3
- package/build/runtime-cjs/client/plugins/subscription.js +7 -5
- package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
- package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -3
- package/build/runtime-cjs/generated.d.ts +1 -0
- package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-cjs/imports/pluginConfig.js +27 -0
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/lib/config.d.ts +27 -24
- package/build/runtime-cjs/lib/config.js +11 -1
- 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 +1 -0
- package/build/runtime-cjs/lib/index.js +1 -0
- 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 +3 -3
- package/build/runtime-cjs/lib/scalars.js +13 -2
- package/build/runtime-cjs/lib/types.d.ts +47 -47
- package/build/runtime-cjs/lib/types.js +26 -30
- package/build/runtime-cjs/public/cache.d.ts +26 -6
- package/build/runtime-cjs/public/cache.js +32 -32
- package/build/runtime-cjs/public/list.js +6 -28
- package/build/runtime-cjs/public/record.d.ts +26 -17
- package/build/runtime-cjs/public/record.js +27 -187
- package/build/runtime-cjs/public/tests/test.d.ts +52 -10
- 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 +28 -11
- package/build/runtime-esm/cache/cache.js +99 -24
- package/build/runtime-esm/cache/gc.js +9 -0
- package/build/runtime-esm/cache/lists.d.ts +1 -0
- package/build/runtime-esm/cache/lists.js +9 -6
- 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 +23 -20
- package/build/runtime-esm/cache/storage.js +11 -13
- package/build/runtime-esm/cache/stuff.d.ts +0 -2
- package/build/runtime-esm/cache/stuff.js +1 -17
- package/build/runtime-esm/cache/subscription.d.ts +2 -1
- package/build/runtime-esm/cache/subscription.js +12 -8
- package/build/runtime-esm/client/documentStore.d.ts +20 -17
- package/build/runtime-esm/client/documentStore.js +14 -10
- package/build/runtime-esm/client/index.d.ts +13 -11
- package/build/runtime-esm/client/index.js +49 -21
- package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
- package/build/runtime-esm/client/plugins/cache.js +11 -9
- package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetch.js +9 -8
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +2 -2
- package/build/runtime-esm/client/plugins/fetchParams.js +8 -3
- package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
- package/build/runtime-esm/client/plugins/mutation.js +2 -2
- package/build/runtime-esm/client/plugins/query.d.ts +1 -1
- package/build/runtime-esm/client/plugins/query.js +4 -4
- package/build/runtime-esm/client/plugins/subscription.d.ts +2 -3
- package/build/runtime-esm/client/plugins/subscription.js +6 -4
- package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
- package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -3
- package/build/runtime-esm/generated.d.ts +1 -0
- package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-esm/imports/pluginConfig.js +5 -0
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/lib/config.d.ts +27 -24
- package/build/runtime-esm/lib/config.js +11 -1
- 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 +1 -0
- package/build/runtime-esm/lib/index.js +1 -0
- 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 +3 -3
- package/build/runtime-esm/lib/scalars.js +13 -2
- package/build/runtime-esm/lib/types.d.ts +47 -47
- package/build/runtime-esm/lib/types.js +26 -30
- package/build/runtime-esm/public/cache.d.ts +26 -6
- package/build/runtime-esm/public/cache.js +31 -30
- package/build/runtime-esm/public/list.js +6 -28
- package/build/runtime-esm/public/record.d.ts +26 -17
- package/build/runtime-esm/public/record.js +26 -183
- package/build/runtime-esm/public/tests/test.d.ts +52 -10
- 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 +3 -3
- package/build/test-cjs/index.js +5007 -2465
- package/build/test-esm/index.js +4995 -2453
- package/build/vite/houdini.d.ts +2 -0
- package/build/vite-cjs/index.js +5344 -2744
- package/build/vite-esm/index.js +5319 -2719
- package/package.json +6 -5
- package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { flatten } from "../lib/flatten";
|
|
1
2
|
import { rootID } from "./cache";
|
|
2
|
-
import { flattenList } from "./stuff";
|
|
3
3
|
class ListManager {
|
|
4
4
|
rootID;
|
|
5
5
|
cache;
|
|
@@ -151,7 +151,7 @@ class List {
|
|
|
151
151
|
edges: {
|
|
152
152
|
keyRaw: "edges",
|
|
153
153
|
type: "ConnectionEdge",
|
|
154
|
-
|
|
154
|
+
updates: ["append", "prepend"],
|
|
155
155
|
selection: {
|
|
156
156
|
fields: {
|
|
157
157
|
node: {
|
|
@@ -187,7 +187,7 @@ class List {
|
|
|
187
187
|
newEntries: {
|
|
188
188
|
keyRaw: this.key,
|
|
189
189
|
type: listType,
|
|
190
|
-
|
|
190
|
+
updates: ["append", "prepend"],
|
|
191
191
|
selection: {
|
|
192
192
|
...selection,
|
|
193
193
|
fields: {
|
|
@@ -210,7 +210,7 @@ class List {
|
|
|
210
210
|
data: insertData,
|
|
211
211
|
variables,
|
|
212
212
|
parent: this.recordID,
|
|
213
|
-
applyUpdates:
|
|
213
|
+
applyUpdates: [where === "first" ? "prepend" : "append"]
|
|
214
214
|
});
|
|
215
215
|
}
|
|
216
216
|
removeID(id, variables = {}) {
|
|
@@ -233,7 +233,7 @@ class List {
|
|
|
233
233
|
embeddedConnectionID,
|
|
234
234
|
"edges"
|
|
235
235
|
);
|
|
236
|
-
for (const edge of
|
|
236
|
+
for (const edge of flatten(edges) || []) {
|
|
237
237
|
if (!edge) {
|
|
238
238
|
continue;
|
|
239
239
|
}
|
|
@@ -311,7 +311,7 @@ class List {
|
|
|
311
311
|
let entries = [];
|
|
312
312
|
let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
|
|
313
313
|
if (!this.connection) {
|
|
314
|
-
entries =
|
|
314
|
+
entries = flatten(value);
|
|
315
315
|
} else {
|
|
316
316
|
entries = this.cache._internal_unstable.storage.get(value, "edges").value;
|
|
317
317
|
}
|
|
@@ -325,6 +325,9 @@ class ListCollection {
|
|
|
325
325
|
constructor(lists) {
|
|
326
326
|
this.lists = lists;
|
|
327
327
|
}
|
|
328
|
+
get selection() {
|
|
329
|
+
return this.lists[0].selection;
|
|
330
|
+
}
|
|
328
331
|
append(...args) {
|
|
329
332
|
this.lists.forEach((list) => list.append(...args));
|
|
330
333
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Cache } from './cache';
|
|
2
|
+
export declare class StaleManager {
|
|
3
|
+
#private;
|
|
4
|
+
cache: Cache;
|
|
5
|
+
private fieldsTime;
|
|
6
|
+
constructor(cache: Cache);
|
|
7
|
+
/**
|
|
8
|
+
* get the FieldTime info
|
|
9
|
+
* @param id User:1
|
|
10
|
+
* @param field firstName
|
|
11
|
+
*/
|
|
12
|
+
getFieldTime(id: string, field: string): number | undefined | null;
|
|
13
|
+
/**
|
|
14
|
+
* set the date to a field
|
|
15
|
+
* @param id User:1
|
|
16
|
+
* @param field firstName
|
|
17
|
+
*/
|
|
18
|
+
setFieldTimeToNow(id: string, field: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* set null to a field (stale)
|
|
21
|
+
* @param id User:1
|
|
22
|
+
* @param field firstName
|
|
23
|
+
*/
|
|
24
|
+
markFieldStale(id: string, field: string): void;
|
|
25
|
+
markAllStale(): void;
|
|
26
|
+
markRecordStale(id: string): void;
|
|
27
|
+
markTypeStale(type: string): void;
|
|
28
|
+
markTypeFieldStale(type: string, field: string, when?: {}): void;
|
|
29
|
+
delete(id: string, field: string): void;
|
|
30
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -7,7 +7,7 @@ export declare class InMemoryStorage {
|
|
|
7
7
|
get layerCount(): number;
|
|
8
8
|
get nextRank(): number;
|
|
9
9
|
createLayer(optimistic?: boolean): Layer;
|
|
10
|
-
insert(id: string, field: string, location:
|
|
10
|
+
insert(id: string, field: string, location: OperationLocations, target: string): void;
|
|
11
11
|
remove(id: string, field: string, target: string): void;
|
|
12
12
|
delete(id: string): void;
|
|
13
13
|
deleteField(id: string, field: string): void;
|
|
@@ -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 }: {
|
|
@@ -47,19 +47,19 @@ export declare class Layer {
|
|
|
47
47
|
removeUndefinedFields(): void;
|
|
48
48
|
delete(id: string): void;
|
|
49
49
|
deleteField(id: string, field: string): void;
|
|
50
|
-
insert(id: string, field: string, where:
|
|
50
|
+
insert(id: string, field: string, where: OperationLocations, target: string): void;
|
|
51
51
|
remove(id: string, field: string, target: string): void;
|
|
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,30 +69,33 @@ type OperationMap = {
|
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
|
-
type
|
|
72
|
+
type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
|
|
73
73
|
type InsertOperation = {
|
|
74
|
-
kind:
|
|
75
|
-
location:
|
|
74
|
+
kind: 'insert';
|
|
75
|
+
location: OperationLocations;
|
|
76
76
|
id: string;
|
|
77
77
|
};
|
|
78
78
|
type RemoveOperation = {
|
|
79
|
-
kind:
|
|
79
|
+
kind: 'remove';
|
|
80
80
|
id: string;
|
|
81
81
|
};
|
|
82
82
|
type DeleteOperation = {
|
|
83
|
-
kind:
|
|
83
|
+
kind: 'delete';
|
|
84
84
|
target: string;
|
|
85
85
|
};
|
|
86
86
|
type ListOperation = InsertOperation | RemoveOperation;
|
|
87
87
|
type Operation = ListOperation | DeleteOperation;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
type ValuesOf<Target> = Target[keyof Target];
|
|
89
|
+
export declare const OperationLocation: {
|
|
90
|
+
readonly start: "start";
|
|
91
|
+
readonly end: "end";
|
|
92
|
+
};
|
|
93
|
+
export type OperationLocations = ValuesOf<typeof OperationLocation>;
|
|
94
|
+
export declare const OperationKind: {
|
|
95
|
+
readonly delete: "delete";
|
|
96
|
+
readonly insert: "insert";
|
|
97
|
+
readonly remove: "remove";
|
|
98
|
+
};
|
|
99
|
+
export type OperationKinds = ValuesOf<typeof OperationKind>;
|
|
97
100
|
export type LayerID = number;
|
|
98
101
|
export {};
|
|
@@ -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
|
}
|
|
@@ -350,17 +350,15 @@ function isInsertOperation(value) {
|
|
|
350
350
|
function isRemoveOperation(value) {
|
|
351
351
|
return !!value && value.kind === OperationKind.remove;
|
|
352
352
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return OperationKind2;
|
|
363
|
-
})(OperationKind || {});
|
|
353
|
+
const OperationLocation = {
|
|
354
|
+
start: "start",
|
|
355
|
+
end: "end"
|
|
356
|
+
};
|
|
357
|
+
const OperationKind = {
|
|
358
|
+
delete: "delete",
|
|
359
|
+
insert: "insert",
|
|
360
|
+
remove: "remove"
|
|
361
|
+
};
|
|
364
362
|
export {
|
|
365
363
|
InMemoryStorage,
|
|
366
364
|
Layer,
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { GraphQLValue } from '../lib/types';
|
|
2
|
-
import type { LinkedList } from './cache';
|
|
3
|
-
export declare function flattenList<T>(source: LinkedList<T>): T[];
|
|
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
|
};
|
|
@@ -19,10 +19,11 @@ export declare class InMemorySubscriptions {
|
|
|
19
19
|
[key: string]: GraphQLValue;
|
|
20
20
|
};
|
|
21
21
|
}): void;
|
|
22
|
-
addFieldSubscription({ id, key, selection, }: {
|
|
22
|
+
addFieldSubscription({ id, key, selection, type, }: {
|
|
23
23
|
id: string;
|
|
24
24
|
key: string;
|
|
25
25
|
selection: FieldSelection;
|
|
26
|
+
type: string;
|
|
26
27
|
}): void;
|
|
27
28
|
registerList({ list, id, key, parentType, selection, filters, variables, }: {
|
|
28
29
|
list: Required<Required<SubscriptionSelection>['fields'][string]>['list'];
|
|
@@ -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) {
|
|
@@ -28,7 +29,8 @@ class InMemorySubscriptions {
|
|
|
28
29
|
this.addFieldSubscription({
|
|
29
30
|
id: parent,
|
|
30
31
|
key,
|
|
31
|
-
selection: [spec, targetSelection2]
|
|
32
|
+
selection: [spec, targetSelection2],
|
|
33
|
+
type
|
|
32
34
|
});
|
|
33
35
|
if (list) {
|
|
34
36
|
this.registerList({
|
|
@@ -46,7 +48,7 @@ class InMemorySubscriptions {
|
|
|
46
48
|
parent,
|
|
47
49
|
key
|
|
48
50
|
);
|
|
49
|
-
let children = !Array.isArray(linkedRecord) ? [linkedRecord] :
|
|
51
|
+
let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
|
|
50
52
|
for (const child of children) {
|
|
51
53
|
if (!child) {
|
|
52
54
|
continue;
|
|
@@ -65,7 +67,8 @@ class InMemorySubscriptions {
|
|
|
65
67
|
addFieldSubscription({
|
|
66
68
|
id,
|
|
67
69
|
key,
|
|
68
|
-
selection
|
|
70
|
+
selection,
|
|
71
|
+
type
|
|
69
72
|
}) {
|
|
70
73
|
const spec = selection[0];
|
|
71
74
|
if (!this.subscribers[id]) {
|
|
@@ -137,7 +140,8 @@ class InMemorySubscriptions {
|
|
|
137
140
|
this.addFieldSubscription({
|
|
138
141
|
id: parent,
|
|
139
142
|
key,
|
|
140
|
-
selection: [spec, fieldSelection]
|
|
143
|
+
selection: [spec, fieldSelection],
|
|
144
|
+
type: linkedType
|
|
141
145
|
});
|
|
142
146
|
if (list) {
|
|
143
147
|
this.registerList({
|
|
@@ -153,7 +157,7 @@ class InMemorySubscriptions {
|
|
|
153
157
|
const childSelection = selection.selection;
|
|
154
158
|
if (childSelection) {
|
|
155
159
|
const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
|
|
156
|
-
const children = !Array.isArray(link) ? [link] :
|
|
160
|
+
const children = !Array.isArray(link) ? [link] : flatten(link);
|
|
157
161
|
for (const linkedRecord of children) {
|
|
158
162
|
if (!linkedRecord) {
|
|
159
163
|
continue;
|
|
@@ -189,7 +193,7 @@ class InMemorySubscriptions {
|
|
|
189
193
|
continue;
|
|
190
194
|
}
|
|
191
195
|
const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
|
|
192
|
-
const links = !Array.isArray(previousValue) ? [previousValue] :
|
|
196
|
+
const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
|
|
193
197
|
for (const link of links) {
|
|
194
198
|
if (link !== null) {
|
|
195
199
|
linkedIDs.push([link, fieldSelection.selection || {}]);
|
|
@@ -229,7 +233,7 @@ class InMemorySubscriptions {
|
|
|
229
233
|
if (kind === "scalar") {
|
|
230
234
|
continue;
|
|
231
235
|
}
|
|
232
|
-
const nextTargets = Array.isArray(value) ?
|
|
236
|
+
const nextTargets = Array.isArray(value) ? flatten(value) : [value];
|
|
233
237
|
for (const id2 of nextTargets) {
|
|
234
238
|
if (visited.includes(id2)) {
|
|
235
239
|
continue;
|
|
@@ -2,31 +2,23 @@ import type { HoudiniClient } from '.';
|
|
|
2
2
|
import type { Layer } from '../cache/storage';
|
|
3
3
|
import type { ConfigFile } from '../lib/config';
|
|
4
4
|
import { Writable } from '../lib/store';
|
|
5
|
-
import type {
|
|
5
|
+
import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies } from '../lib/types';
|
|
6
6
|
export declare class DocumentStore<_Data extends GraphQLObject, _Input extends Record<string, any>> extends Writable<QueryResult<_Data, _Input>> {
|
|
7
7
|
#private;
|
|
8
8
|
constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
|
|
9
9
|
artifact: DocumentArtifact;
|
|
10
|
-
plugins?:
|
|
11
|
-
pipeline?:
|
|
12
|
-
client: HoudiniClient;
|
|
10
|
+
plugins?: ClientHooks[];
|
|
11
|
+
pipeline?: ClientHooks[];
|
|
12
|
+
client: HoudiniClient | null;
|
|
13
13
|
cache?: boolean;
|
|
14
14
|
initialValue?: _Data | null;
|
|
15
15
|
fetching?: boolean;
|
|
16
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>>;
|
|
17
|
+
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
|
|
27
18
|
}
|
|
28
19
|
declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
|
|
29
|
-
export type ClientPlugin = () =>
|
|
20
|
+
export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
|
|
21
|
+
export type ClientHooks = {
|
|
30
22
|
start?: ClientPluginEnterPhase;
|
|
31
23
|
beforeNetwork?: ClientPluginEnterPhase;
|
|
32
24
|
network?: ClientPluginEnterPhase;
|
|
@@ -41,7 +33,7 @@ export type ClientPluginContext = {
|
|
|
41
33
|
text: string;
|
|
42
34
|
hash: string;
|
|
43
35
|
artifact: DocumentArtifact;
|
|
44
|
-
policy?:
|
|
36
|
+
policy?: CachePolicies;
|
|
45
37
|
fetch?: Fetch;
|
|
46
38
|
variables?: Record<string, any>;
|
|
47
39
|
metadata?: App.Metadata | null;
|
|
@@ -53,7 +45,7 @@ export type ClientPluginContext = {
|
|
|
53
45
|
forceNotify?: boolean;
|
|
54
46
|
disableWrite?: boolean;
|
|
55
47
|
disableRead?: boolean;
|
|
56
|
-
applyUpdates?:
|
|
48
|
+
applyUpdates?: string[];
|
|
57
49
|
};
|
|
58
50
|
stuff: App.Stuff;
|
|
59
51
|
};
|
|
@@ -84,4 +76,15 @@ export type ClientPluginExitHandlers = Omit<ClientPluginEnterHandlers, 'resolve'
|
|
|
84
76
|
export type ClientPluginErrorHandlers = ClientPluginEnterHandlers & {
|
|
85
77
|
error: unknown;
|
|
86
78
|
};
|
|
79
|
+
export type SendParams = {
|
|
80
|
+
fetch?: Fetch;
|
|
81
|
+
variables?: Record<string, any> | null;
|
|
82
|
+
metadata?: App.Metadata | null;
|
|
83
|
+
session?: App.Session | null;
|
|
84
|
+
policy?: CachePolicies;
|
|
85
|
+
stuff?: Partial<App.Stuff>;
|
|
86
|
+
cacheParams?: ClientPluginContext['cacheParams'];
|
|
87
|
+
setup?: boolean;
|
|
88
|
+
silenceEcho?: boolean;
|
|
89
|
+
};
|
|
87
90
|
export {};
|
|
@@ -3,7 +3,7 @@ import { deepEquals } from "../lib/deepEquals";
|
|
|
3
3
|
import { marshalInputs, unmarshalSelection } from "../lib/scalars";
|
|
4
4
|
import { Writable } from "../lib/store";
|
|
5
5
|
import { ArtifactKind } from "../lib/types";
|
|
6
|
-
import {
|
|
6
|
+
import { cachePolicy } from "./plugins";
|
|
7
7
|
const steps = {
|
|
8
8
|
forward: ["start", "beforeNetwork", "network"],
|
|
9
9
|
backwards: ["end", "afterNetwork"]
|
|
@@ -24,16 +24,15 @@ class DocumentStore extends Writable {
|
|
|
24
24
|
initialValue,
|
|
25
25
|
fetching
|
|
26
26
|
}) {
|
|
27
|
-
|
|
28
|
-
fetching = artifact.kind === ArtifactKind.Query;
|
|
29
|
-
}
|
|
27
|
+
fetching ??= artifact.kind === ArtifactKind.Query;
|
|
30
28
|
const initialState = {
|
|
31
29
|
data: initialValue ?? null,
|
|
32
30
|
errors: null,
|
|
33
31
|
partial: false,
|
|
32
|
+
stale: false,
|
|
34
33
|
source: null,
|
|
35
34
|
fetching,
|
|
36
|
-
variables:
|
|
35
|
+
variables: {}
|
|
37
36
|
};
|
|
38
37
|
super(initialState, () => {
|
|
39
38
|
return () => {
|
|
@@ -47,13 +46,13 @@ class DocumentStore extends Writable {
|
|
|
47
46
|
this.#client = client;
|
|
48
47
|
this.#lastVariables = null;
|
|
49
48
|
this.#configFile = getCurrentConfig();
|
|
50
|
-
this.#plugins =
|
|
51
|
-
|
|
49
|
+
this.#plugins = pipeline ?? [
|
|
50
|
+
cachePolicy({
|
|
52
51
|
enabled: cache,
|
|
53
52
|
setFetching: (fetching2) => this.update((state) => ({ ...state, fetching: fetching2 }))
|
|
54
|
-
}),
|
|
53
|
+
})(),
|
|
55
54
|
...plugins ?? []
|
|
56
|
-
]
|
|
55
|
+
];
|
|
57
56
|
}
|
|
58
57
|
async send({
|
|
59
58
|
metadata,
|
|
@@ -63,7 +62,8 @@ class DocumentStore extends Writable {
|
|
|
63
62
|
policy,
|
|
64
63
|
stuff,
|
|
65
64
|
cacheParams,
|
|
66
|
-
setup = false
|
|
65
|
+
setup = false,
|
|
66
|
+
silenceEcho = false
|
|
67
67
|
} = {}) {
|
|
68
68
|
let context = new ClientPluginContextWrapper({
|
|
69
69
|
config: this.#configFile,
|
|
@@ -94,6 +94,7 @@ class DocumentStore extends Writable {
|
|
|
94
94
|
setup,
|
|
95
95
|
currentStep: 0,
|
|
96
96
|
index: 0,
|
|
97
|
+
silenceEcho,
|
|
97
98
|
promise: {
|
|
98
99
|
resolved: false,
|
|
99
100
|
resolve,
|
|
@@ -231,6 +232,9 @@ class DocumentStore extends Writable {
|
|
|
231
232
|
}
|
|
232
233
|
this.#lastContext = ctx.context.draft();
|
|
233
234
|
this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
|
|
235
|
+
if (ctx.silenceEcho && finalValue.data === this.state.data) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
234
238
|
this.set(finalValue);
|
|
235
239
|
}
|
|
236
240
|
}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
/// <reference path="../../../../../houdini.d.ts" />
|
|
2
|
-
import type { DocumentArtifact, GraphQLObject } from '../lib/types';
|
|
3
|
-
import type { ClientPlugin } from './documentStore';
|
|
2
|
+
import type { DocumentArtifact, GraphQLObject, NestedList } from '../lib/types';
|
|
3
|
+
import type { ClientPlugin, ClientHooks } from './documentStore';
|
|
4
4
|
import { DocumentStore } from './documentStore';
|
|
5
5
|
import { type FetchParamFn, type ThrowOnErrorParams } from './plugins';
|
|
6
6
|
export { DocumentStore, type ClientPlugin } from './documentStore';
|
|
7
|
-
export {
|
|
7
|
+
export { fetch, mutation, query, subscription } from './plugins';
|
|
8
8
|
type ConstructorArgs = {
|
|
9
9
|
url: string;
|
|
10
10
|
fetchParams?: FetchParamFn;
|
|
11
|
-
plugins?: ClientPlugin
|
|
12
|
-
pipeline?: ClientPlugin
|
|
11
|
+
plugins?: NestedList<ClientPlugin>;
|
|
12
|
+
pipeline?: NestedList<ClientPlugin>;
|
|
13
13
|
throwOnError?: ThrowOnErrorParams;
|
|
14
14
|
};
|
|
15
|
+
export type ObserveParams<_Data extends GraphQLObject, _Artifact extends DocumentArtifact = DocumentArtifact> = {
|
|
16
|
+
artifact: _Artifact;
|
|
17
|
+
cache?: boolean;
|
|
18
|
+
initialValue?: _Data | null;
|
|
19
|
+
fetching?: boolean;
|
|
20
|
+
};
|
|
15
21
|
export declare class HoudiniClient {
|
|
16
22
|
#private;
|
|
17
23
|
url: string;
|
|
18
24
|
constructor({ url, fetchParams, plugins, pipeline, throwOnError }: ConstructorArgs);
|
|
19
|
-
observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }:
|
|
20
|
-
artifact: DocumentArtifact;
|
|
21
|
-
cache?: boolean;
|
|
22
|
-
initialValue?: _Data | null;
|
|
23
|
-
fetching?: boolean;
|
|
24
|
-
}): DocumentStore<_Data, _Input>;
|
|
25
|
+
observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
|
|
25
26
|
}
|
|
27
|
+
export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
|