houdini 1.0.0-next.7 → 1.0.0-next.9
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 +93 -66
- package/build/cmd-esm/index.js +66 -39
- package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
- package/build/codegen/generators/typescript/types.d.ts +0 -1
- package/build/codegen-cjs/index.js +67 -39
- package/build/codegen-esm/index.js +54 -26
- package/build/lib/config.d.ts +2 -1
- package/build/lib/path.d.ts +1 -1
- package/build/lib-cjs/index.js +40 -37
- package/build/lib-esm/index.js +14 -11
- 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 +4 -3
- package/build/runtime/client/index.d.ts +6 -5
- 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 +1 -1
- 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 +1 -1
- package/build/runtime/client/plugins/throwOnError.d.ts +1 -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 +2 -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 +4 -3
- package/build/runtime-cjs/client/documentStore.js +4 -4
- package/build/runtime-cjs/client/index.d.ts +6 -5
- package/build/runtime-cjs/client/index.js +45 -19
- package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/cache.js +3 -3
- package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetch.js +7 -7
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetchParams.js +3 -3
- 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 +3 -3
- package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/subscription.js +3 -3
- 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 +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 +2 -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 +4 -3
- package/build/runtime-esm/client/documentStore.js +5 -5
- package/build/runtime-esm/client/index.d.ts +6 -5
- package/build/runtime-esm/client/index.js +46 -21
- package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
- package/build/runtime-esm/client/plugins/cache.js +2 -2
- package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetch.js +6 -6
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetchParams.js +2 -2
- 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 +2 -2
- package/build/runtime-esm/client/plugins/subscription.d.ts +1 -1
- package/build/runtime-esm/client/plugins/subscription.js +2 -2
- 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 +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 +2 -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 +67 -39
- package/build/test-esm/index.js +54 -26
- package/build/vite-cjs/index.js +90 -58
- package/build/vite-esm/index.js +64 -32
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DocumentArtifact } from '../../lib/types';
|
|
2
2
|
import type { ClientPlugin, ClientPluginContext } from '../documentStore';
|
|
3
3
|
export type FetchParamFn = (ctx: FetchParamsInput) => Required<ClientPluginContext>['fetchParams'];
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const fetchParams: (fn?: FetchParamFn) => ClientPlugin;
|
|
5
5
|
export type FetchParamsInput = Pick<ClientPluginContext, 'config' | 'policy' | 'variables' | 'metadata' | 'session' | 'stuff'> & {
|
|
6
6
|
text: string;
|
|
7
7
|
hash: string;
|
|
@@ -18,10 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var fetchParams_exports = {};
|
|
20
20
|
__export(fetchParams_exports, {
|
|
21
|
-
|
|
21
|
+
fetchParams: () => fetchParams
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(fetchParams_exports);
|
|
24
|
-
const
|
|
24
|
+
const fetchParams = (fn = () => ({})) => () => ({
|
|
25
25
|
beforeNetwork(ctx, { next, marshalVariables }) {
|
|
26
26
|
next({
|
|
27
27
|
...ctx,
|
|
@@ -41,5 +41,5 @@ const fetchParamsPlugin = (fn = () => ({})) => () => ({
|
|
|
41
41
|
});
|
|
42
42
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
43
|
0 && (module.exports = {
|
|
44
|
-
|
|
44
|
+
fetchParams
|
|
45
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const mutation: import("..").ClientPlugin;
|
|
@@ -24,14 +24,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var mutation_exports = {};
|
|
26
26
|
__export(mutation_exports, {
|
|
27
|
-
|
|
27
|
+
mutation: () => mutation
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(mutation_exports);
|
|
30
30
|
var import_cache = __toESM(require("../../cache"), 1);
|
|
31
31
|
var import_scalars = require("../../lib/scalars");
|
|
32
32
|
var import_types = require("../../lib/types");
|
|
33
33
|
var import_utils = require("../utils");
|
|
34
|
-
const
|
|
34
|
+
const mutation = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Mutation, () => {
|
|
35
35
|
return {
|
|
36
36
|
async start(ctx, { next, marshalVariables }) {
|
|
37
37
|
const layer = import_cache.default._internal_unstable.storage.createLayer(true);
|
|
@@ -82,5 +82,5 @@ const mutationPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKin
|
|
|
82
82
|
});
|
|
83
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
84
84
|
0 && (module.exports = {
|
|
85
|
-
|
|
85
|
+
mutation
|
|
86
86
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ClientPlugin } from '../documentStore';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const query: ClientPlugin;
|
|
@@ -24,13 +24,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var query_exports = {};
|
|
26
26
|
__export(query_exports, {
|
|
27
|
-
|
|
27
|
+
query: () => query
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(query_exports);
|
|
30
30
|
var import_cache = __toESM(require("../../cache"), 1);
|
|
31
31
|
var import_types = require("../../lib/types");
|
|
32
32
|
var import_utils = require("../utils");
|
|
33
|
-
const
|
|
33
|
+
const query = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Query, function() {
|
|
34
34
|
let subscriptionSpec = null;
|
|
35
35
|
let lastVariables = null;
|
|
36
36
|
let artifactName = "";
|
|
@@ -79,5 +79,5 @@ const queryPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Q
|
|
|
79
79
|
});
|
|
80
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
81
|
0 && (module.exports = {
|
|
82
|
-
|
|
82
|
+
query
|
|
83
83
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClientPluginContext } from '../documentStore';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function subscription(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
|
|
3
3
|
export type SubscriptionHandler = (ctx: ClientPluginContext) => {
|
|
4
4
|
subscribe: (payload: {
|
|
5
5
|
query: string;
|
|
@@ -18,13 +18,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var subscription_exports = {};
|
|
20
20
|
__export(subscription_exports, {
|
|
21
|
-
|
|
21
|
+
subscription: () => subscription
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(subscription_exports);
|
|
24
24
|
var import_deepEquals = require("../../lib/deepEquals");
|
|
25
25
|
var import_types = require("../../lib/types");
|
|
26
26
|
var import_utils = require("../utils");
|
|
27
|
-
function
|
|
27
|
+
function subscription(factory) {
|
|
28
28
|
return (0, import_utils.documentPlugin)(import_types.ArtifactKind.Subscription, () => {
|
|
29
29
|
let clearSubscription = null;
|
|
30
30
|
let socketClient = null;
|
|
@@ -96,5 +96,5 @@ function subscriptionPlugin(factory) {
|
|
|
96
96
|
}
|
|
97
97
|
// Annotate the CommonJS export names for ESM import in node:
|
|
98
98
|
0 && (module.exports = {
|
|
99
|
-
|
|
99
|
+
subscription
|
|
100
100
|
});
|
|
@@ -4,4 +4,4 @@ export type ThrowOnErrorParams = {
|
|
|
4
4
|
operations: ('all' | 'query' | 'mutation' | 'subscription')[];
|
|
5
5
|
error?: (errors: NonNullable<QueryResult<any, any>['errors']>) => unknown;
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const throwOnError: ({ operations, error }: ThrowOnErrorParams) => ClientPlugin;
|
|
@@ -18,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var throwOnError_exports = {};
|
|
20
20
|
__export(throwOnError_exports, {
|
|
21
|
-
|
|
21
|
+
throwOnError: () => throwOnError
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(throwOnError_exports);
|
|
24
24
|
var import_lib = require("../../lib");
|
|
25
|
-
const
|
|
25
|
+
const throwOnError = ({ operations, error }) => () => {
|
|
26
26
|
const all = operations.includes("all");
|
|
27
27
|
const throwOnKind = (kind) => all || {
|
|
28
28
|
[import_lib.ArtifactKind.Query]: operations.includes("query"),
|
|
@@ -43,5 +43,5 @@ const throwOnErrorPlugin = ({ operations, error }) => () => {
|
|
|
43
43
|
const defaultErrorFn = async (errors) => new Error(errors.map((error) => error.message).join(". ") + ".");
|
|
44
44
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
45
|
0 && (module.exports = {
|
|
46
|
-
|
|
46
|
+
throwOnError
|
|
47
47
|
});
|
|
@@ -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,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,8 +7,8 @@ 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?:
|
|
10
|
+
plugins?: ClientHooks[];
|
|
11
|
+
pipeline?: ClientHooks[];
|
|
12
12
|
client: HoudiniClient | null;
|
|
13
13
|
cache?: boolean;
|
|
14
14
|
initialValue?: _Data | null;
|
|
@@ -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;
|
|
@@ -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"]
|
|
@@ -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 =
|
|
52
|
-
|
|
51
|
+
this.#plugins = pipeline ?? [
|
|
52
|
+
cachePolicy({
|
|
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,15 +1,15 @@
|
|
|
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
15
|
export type ObserveParams<_Data extends GraphQLObject, _Artifact extends DocumentArtifact = DocumentArtifact> = {
|
|
@@ -24,3 +24,4 @@ export declare class HoudiniClient {
|
|
|
24
24
|
constructor({ url, fetchParams, plugins, pipeline, throwOnError }: ConstructorArgs);
|
|
25
25
|
observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
|
|
26
26
|
}
|
|
27
|
+
export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
|