houdini 1.0.0-next.6 → 1.0.0-next.8
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 +398 -399
- package/build/cmd-esm/index.js +372 -373
- package/build/codegen-cjs/index.js +372 -372
- package/build/codegen-esm/index.js +360 -360
- package/build/lib/config.d.ts +2 -1
- package/build/lib/path.d.ts +1 -1
- package/build/lib-cjs/index.js +393 -390
- package/build/lib-esm/index.js +368 -365
- package/build/runtime/cache/cache.d.ts +6 -6
- package/build/runtime/cache/storage.d.ts +5 -5
- package/build/runtime/cache/stuff.d.ts +0 -2
- package/build/runtime/client/documentStore.d.ts +5 -4
- package/build/runtime/client/index.d.ts +12 -10
- package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime/lib/flatten.d.ts +2 -0
- package/build/runtime/lib/types.d.ts +1 -0
- package/build/runtime/public/record.d.ts +1 -2
- package/build/runtime-cjs/cache/cache.d.ts +6 -6
- package/build/runtime-cjs/cache/cache.js +6 -5
- package/build/runtime-cjs/cache/lists.js +3 -3
- 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 +0 -2
- package/build/runtime-cjs/cache/stuff.js +2 -19
- package/build/runtime-cjs/cache/subscription.js +5 -4
- package/build/runtime-cjs/client/documentStore.d.ts +5 -4
- package/build/runtime-cjs/client/documentStore.js +3 -3
- package/build/runtime-cjs/client/index.d.ts +12 -10
- package/build/runtime-cjs/client/index.js +37 -11
- package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime-cjs/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime-cjs/lib/flatten.d.ts +2 -0
- package/build/runtime-cjs/lib/flatten.js +41 -0
- package/build/runtime-cjs/lib/types.d.ts +1 -0
- package/build/runtime-cjs/public/cache.js +2 -2
- package/build/runtime-cjs/public/record.d.ts +1 -2
- package/build/runtime-cjs/public/record.js +1 -2
- package/build/runtime-esm/cache/cache.d.ts +6 -6
- package/build/runtime-esm/cache/cache.js +7 -6
- package/build/runtime-esm/cache/lists.js +3 -3
- 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 +0 -2
- package/build/runtime-esm/cache/stuff.js +1 -17
- package/build/runtime-esm/cache/subscription.js +6 -5
- package/build/runtime-esm/client/documentStore.d.ts +5 -4
- package/build/runtime-esm/client/documentStore.js +3 -3
- package/build/runtime-esm/client/index.d.ts +12 -10
- package/build/runtime-esm/client/index.js +36 -11
- package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime-esm/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime-esm/lib/flatten.d.ts +2 -0
- package/build/runtime-esm/lib/flatten.js +17 -0
- package/build/runtime-esm/lib/types.d.ts +1 -0
- package/build/runtime-esm/public/cache.js +2 -2
- package/build/runtime-esm/public/record.d.ts +1 -2
- package/build/runtime-esm/public/record.js +1 -2
- package/build/test-cjs/index.js +372 -372
- package/build/test-esm/index.js +360 -360
- package/build/vite-cjs/index.js +395 -391
- package/build/vite-esm/index.js +370 -366
- package/package.json +4 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var flatten_exports = {};
|
|
20
|
+
__export(flatten_exports, {
|
|
21
|
+
flatten: () => flatten
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(flatten_exports);
|
|
24
|
+
function flatten(source) {
|
|
25
|
+
if (!source) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
return source.reduce((acc, element) => {
|
|
29
|
+
if (!element) {
|
|
30
|
+
return acc;
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(element)) {
|
|
33
|
+
return acc.concat(flatten(element));
|
|
34
|
+
}
|
|
35
|
+
return acc.concat(element);
|
|
36
|
+
}, []);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
flatten
|
|
41
|
+
});
|
|
@@ -87,8 +87,8 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
|
|
|
87
87
|
});
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
|
-
markStale(type, options
|
|
91
|
-
return this._internal_unstable.markTypeStale(type,
|
|
90
|
+
markStale(type, options) {
|
|
91
|
+
return this._internal_unstable.markTypeStale(type ? { ...options, type } : void 0);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -34,8 +34,7 @@ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<De
|
|
|
34
34
|
* @param field
|
|
35
35
|
* @param when
|
|
36
36
|
*/
|
|
37
|
-
markStale<Field extends TypeFieldNames<Def, Type>>(
|
|
38
|
-
field?: Field;
|
|
37
|
+
markStale<Field extends TypeFieldNames<Def, Type>>(field?: Field, { when, }?: {
|
|
39
38
|
when?: ArgType<Def, Type, Field>;
|
|
40
39
|
}): void;
|
|
41
40
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConfigFile } from '../lib/config';
|
|
2
|
-
import type { GraphQLObject, GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
|
|
2
|
+
import type { GraphQLObject, GraphQLValue, NestedList, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
|
|
3
3
|
import { GarbageCollector } from './gc';
|
|
4
4
|
import type { ListCollection } from './lists';
|
|
5
5
|
import { ListManager } from './lists';
|
|
@@ -34,7 +34,8 @@ export declare class Cache {
|
|
|
34
34
|
list(name: string, parentID?: string, allLists?: boolean): ListCollection;
|
|
35
35
|
delete(id: string): void;
|
|
36
36
|
setConfig(config: ConfigFile): void;
|
|
37
|
-
markTypeStale(
|
|
37
|
+
markTypeStale(options?: {
|
|
38
|
+
type: string;
|
|
38
39
|
field?: string;
|
|
39
40
|
when?: {};
|
|
40
41
|
}): void;
|
|
@@ -98,10 +99,10 @@ declare class CacheInternal {
|
|
|
98
99
|
hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, }: {
|
|
99
100
|
fields: SubscriptionSelection;
|
|
100
101
|
variables?: {};
|
|
101
|
-
linkedList:
|
|
102
|
+
linkedList: NestedList;
|
|
102
103
|
stepsFromConnection: number | null;
|
|
103
104
|
}): {
|
|
104
|
-
data:
|
|
105
|
+
data: NestedList<GraphQLValue>;
|
|
105
106
|
partial: boolean;
|
|
106
107
|
stale: boolean;
|
|
107
108
|
hasData: boolean;
|
|
@@ -119,11 +120,10 @@ declare class CacheInternal {
|
|
|
119
120
|
layer: Layer;
|
|
120
121
|
forceNotify?: boolean;
|
|
121
122
|
}): {
|
|
122
|
-
nestedIDs:
|
|
123
|
+
nestedIDs: NestedList;
|
|
123
124
|
newIDs: (string | null)[];
|
|
124
125
|
};
|
|
125
126
|
collectGarbage(): void;
|
|
126
127
|
}
|
|
127
128
|
export declare const rootID = "_ROOT_";
|
|
128
|
-
export type LinkedList<_Result = string> = (_Result | null | LinkedList<_Result>)[];
|
|
129
129
|
export {};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { computeKey } from "../lib";
|
|
2
2
|
import { computeID, defaultConfigValues, keyFieldsForType } from "../lib/config";
|
|
3
3
|
import { deepEquals } from "../lib/deepEquals";
|
|
4
|
+
import { flatten } from "../lib/flatten";
|
|
4
5
|
import { getFieldsForType } from "../lib/selection";
|
|
5
6
|
import { GarbageCollector } from "./gc";
|
|
6
7
|
import { ListManager } from "./lists";
|
|
7
8
|
import { SchemaManager } from "./schema";
|
|
8
9
|
import { StaleManager } from "./staleManager";
|
|
9
10
|
import { InMemoryStorage } from "./storage";
|
|
10
|
-
import { evaluateKey
|
|
11
|
+
import { evaluateKey } from "./stuff";
|
|
11
12
|
import { InMemorySubscriptions } from "./subscription";
|
|
12
13
|
class Cache {
|
|
13
14
|
_internal_unstable;
|
|
@@ -91,14 +92,14 @@ class Cache {
|
|
|
91
92
|
setConfig(config) {
|
|
92
93
|
this._internal_unstable.setConfig(config);
|
|
93
94
|
}
|
|
94
|
-
markTypeStale(
|
|
95
|
-
if (!
|
|
95
|
+
markTypeStale(options) {
|
|
96
|
+
if (!options) {
|
|
96
97
|
this._internal_unstable.staleManager.markAllStale();
|
|
97
98
|
} else if (!options.field) {
|
|
98
|
-
this._internal_unstable.staleManager.markTypeStale(type);
|
|
99
|
+
this._internal_unstable.staleManager.markTypeStale(options.type);
|
|
99
100
|
} else {
|
|
100
101
|
this._internal_unstable.staleManager.markTypeFieldStale(
|
|
101
|
-
type,
|
|
102
|
+
options.type,
|
|
102
103
|
options.field,
|
|
103
104
|
options.when
|
|
104
105
|
);
|
|
@@ -237,7 +238,7 @@ class CacheInternal {
|
|
|
237
238
|
if (previousValue === null) {
|
|
238
239
|
continue;
|
|
239
240
|
}
|
|
240
|
-
const previousLinks =
|
|
241
|
+
const previousLinks = flatten([previousValue]);
|
|
241
242
|
for (const link of previousLinks) {
|
|
242
243
|
this.subscriptions.remove(link, fieldSelection, specs, variables);
|
|
243
244
|
}
|
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -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
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
|
};
|
|
@@ -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) {
|
|
@@ -47,7 +48,7 @@ class InMemorySubscriptions {
|
|
|
47
48
|
parent,
|
|
48
49
|
key
|
|
49
50
|
);
|
|
50
|
-
let children = !Array.isArray(linkedRecord) ? [linkedRecord] :
|
|
51
|
+
let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
|
|
51
52
|
for (const child of children) {
|
|
52
53
|
if (!child) {
|
|
53
54
|
continue;
|
|
@@ -156,7 +157,7 @@ class InMemorySubscriptions {
|
|
|
156
157
|
const childSelection = selection.selection;
|
|
157
158
|
if (childSelection) {
|
|
158
159
|
const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
|
|
159
|
-
const children = !Array.isArray(link) ? [link] :
|
|
160
|
+
const children = !Array.isArray(link) ? [link] : flatten(link);
|
|
160
161
|
for (const linkedRecord of children) {
|
|
161
162
|
if (!linkedRecord) {
|
|
162
163
|
continue;
|
|
@@ -192,7 +193,7 @@ class InMemorySubscriptions {
|
|
|
192
193
|
continue;
|
|
193
194
|
}
|
|
194
195
|
const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
|
|
195
|
-
const links = !Array.isArray(previousValue) ? [previousValue] :
|
|
196
|
+
const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
|
|
196
197
|
for (const link of links) {
|
|
197
198
|
if (link !== null) {
|
|
198
199
|
linkedIDs.push([link, fieldSelection.selection || {}]);
|
|
@@ -232,7 +233,7 @@ class InMemorySubscriptions {
|
|
|
232
233
|
if (kind === "scalar") {
|
|
233
234
|
continue;
|
|
234
235
|
}
|
|
235
|
-
const nextTargets = Array.isArray(value) ?
|
|
236
|
+
const nextTargets = Array.isArray(value) ? flatten(value) : [value];
|
|
236
237
|
for (const id2 of nextTargets) {
|
|
237
238
|
if (visited.includes(id2)) {
|
|
238
239
|
continue;
|
|
@@ -7,9 +7,9 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
|
|
|
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;
|
|
@@ -26,7 +26,8 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
|
|
|
26
26
|
}): Promise<QueryResult<_Data, _Input>>;
|
|
27
27
|
}
|
|
28
28
|
declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
|
|
29
|
-
export type ClientPlugin = () =>
|
|
29
|
+
export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
|
|
30
|
+
export type ClientHooks = {
|
|
30
31
|
start?: ClientPluginEnterPhase;
|
|
31
32
|
beforeNetwork?: ClientPluginEnterPhase;
|
|
32
33
|
network?: ClientPluginEnterPhase;
|
|
@@ -48,13 +48,13 @@ class DocumentStore extends Writable {
|
|
|
48
48
|
this.#client = client;
|
|
49
49
|
this.#lastVariables = null;
|
|
50
50
|
this.#configFile = getCurrentConfig();
|
|
51
|
-
this.#plugins =
|
|
51
|
+
this.#plugins = pipeline ?? [
|
|
52
52
|
cachePolicyPlugin({
|
|
53
53
|
enabled: cache,
|
|
54
54
|
setFetching: (fetching2) => this.update((state) => ({ ...state, fetching: fetching2 }))
|
|
55
|
-
}),
|
|
55
|
+
})(),
|
|
56
56
|
...plugins ?? []
|
|
57
|
-
]
|
|
57
|
+
];
|
|
58
58
|
}
|
|
59
59
|
async send({
|
|
60
60
|
metadata,
|
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
|
@@ -8,18 +8,20 @@ export { fetchPlugin, mutationPlugin, queryPlugin, subscriptionPlugin } from './
|
|
|
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[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { flatten } from "../lib/flatten";
|
|
1
2
|
import { DocumentStore } from "./documentStore";
|
|
2
3
|
import {
|
|
3
4
|
fetchParamsPlugin,
|
|
@@ -18,16 +19,18 @@ class HoudiniClient {
|
|
|
18
19
|
"A client cannot be given a pipeline and a list of plugins at the same time."
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
|
-
this.#plugins =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
this.#plugins = flatten(
|
|
23
|
+
[].concat(
|
|
24
|
+
throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
|
|
25
|
+
fetchParamsPlugin(fetchParams),
|
|
26
|
+
pipeline ?? [
|
|
27
|
+
queryPlugin,
|
|
28
|
+
mutationPlugin
|
|
29
|
+
].concat(
|
|
30
|
+
plugins ?? [],
|
|
31
|
+
pluginsFromPlugins,
|
|
32
|
+
fetchPlugin()
|
|
33
|
+
)
|
|
31
34
|
)
|
|
32
35
|
);
|
|
33
36
|
this.url = url;
|
|
@@ -41,16 +44,38 @@ class HoudiniClient {
|
|
|
41
44
|
return new DocumentStore({
|
|
42
45
|
client: this,
|
|
43
46
|
artifact,
|
|
44
|
-
plugins: this.#plugins,
|
|
47
|
+
plugins: createPluginHooks(this.#plugins),
|
|
45
48
|
cache,
|
|
46
49
|
initialValue,
|
|
47
50
|
fetching
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
53
|
}
|
|
54
|
+
function createPluginHooks(plugins) {
|
|
55
|
+
return plugins.reduce((hooks, plugin) => {
|
|
56
|
+
const result = plugin();
|
|
57
|
+
if (!result) {
|
|
58
|
+
return hooks;
|
|
59
|
+
}
|
|
60
|
+
if (!Array.isArray(result)) {
|
|
61
|
+
return hooks.concat(result);
|
|
62
|
+
}
|
|
63
|
+
for (const value of result) {
|
|
64
|
+
if (!value) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (typeof value === "function") {
|
|
68
|
+
return hooks.concat(createPluginHooks([value]));
|
|
69
|
+
}
|
|
70
|
+
hooks.push(value);
|
|
71
|
+
}
|
|
72
|
+
return hooks;
|
|
73
|
+
}, []);
|
|
74
|
+
}
|
|
51
75
|
export {
|
|
52
76
|
DocumentStore2 as DocumentStore,
|
|
53
77
|
HoudiniClient,
|
|
78
|
+
createPluginHooks,
|
|
54
79
|
fetchPlugin2 as fetchPlugin,
|
|
55
80
|
mutationPlugin2 as mutationPlugin,
|
|
56
81
|
queryPlugin2 as queryPlugin,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ArtifactKind } from '../../lib/types';
|
|
2
|
-
import type { ClientPlugin } from '../documentStore';
|
|
3
|
-
export declare const documentPlugin: (kind: ArtifactKind, source:
|
|
2
|
+
import type { ClientPlugin, ClientHooks } from '../documentStore';
|
|
3
|
+
export declare const documentPlugin: (kind: ArtifactKind, source: () => ClientHooks) => ClientPlugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function flatten(source) {
|
|
2
|
+
if (!source) {
|
|
3
|
+
return [];
|
|
4
|
+
}
|
|
5
|
+
return source.reduce((acc, element) => {
|
|
6
|
+
if (!element) {
|
|
7
|
+
return acc;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(element)) {
|
|
10
|
+
return acc.concat(flatten(element));
|
|
11
|
+
}
|
|
12
|
+
return acc.concat(element);
|
|
13
|
+
}, []);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
flatten
|
|
17
|
+
};
|
|
@@ -64,8 +64,8 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
|
|
|
64
64
|
});
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
markStale(type, options
|
|
68
|
-
return this._internal_unstable.markTypeStale(type,
|
|
67
|
+
markStale(type, options) {
|
|
68
|
+
return this._internal_unstable.markTypeStale(type ? { ...options, type } : void 0);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
export {
|
|
@@ -34,8 +34,7 @@ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<De
|
|
|
34
34
|
* @param field
|
|
35
35
|
* @param when
|
|
36
36
|
*/
|
|
37
|
-
markStale<Field extends TypeFieldNames<Def, Type>>(
|
|
38
|
-
field?: Field;
|
|
37
|
+
markStale<Field extends TypeFieldNames<Def, Type>>(field?: Field, { when, }?: {
|
|
39
38
|
when?: ArgType<Def, Type, Field>;
|
|
40
39
|
}): void;
|
|
41
40
|
}
|