houdini 1.0.0-next.4 → 1.0.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cmd-cjs/index.js +1307 -1102
- package/build/cmd-esm/index.js +1307 -1102
- 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 +2 -2
- 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/typescript/documentTypes.d.ts +2 -2
- package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -2
- package/build/codegen/generators/typescript/index.d.ts +2 -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 +4 -4
- package/build/codegen/transforms/fragmentVariables.d.ts +2 -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/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 +900 -757
- package/build/codegen-esm/index.js +900 -757
- package/build/lib/config.d.ts +10 -90
- 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/pipeline.d.ts +1 -1
- package/build/lib/plugin.d.ts +2 -0
- package/build/lib/types.d.ts +252 -4
- package/build/lib-cjs/index.js +351 -162
- package/build/lib-esm/index.js +349 -162
- package/build/runtime/cache/cache.d.ts +20 -3
- package/build/runtime/cache/staleManager.d.ts +30 -0
- package/build/runtime/cache/subscription.d.ts +2 -1
- package/build/runtime/client/plugins/subscription.d.ts +1 -2
- package/build/runtime/lib/config.d.ts +4 -0
- package/build/runtime/lib/index.d.ts +1 -0
- package/build/runtime/lib/key.d.ts +6 -0
- package/build/runtime/lib/types.d.ts +2 -2
- package/build/runtime/public/cache.d.ts +8 -1
- package/build/runtime/public/record.d.ts +11 -1
- package/build/runtime/public/tests/test.d.ts +9 -10
- package/build/runtime-cjs/cache/cache.d.ts +20 -3
- package/build/runtime-cjs/cache/cache.js +65 -6
- package/build/runtime-cjs/cache/gc.js +9 -0
- package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
- package/build/runtime-cjs/cache/staleManager.js +95 -0
- package/build/runtime-cjs/cache/subscription.d.ts +2 -1
- package/build/runtime-cjs/cache/subscription.js +6 -3
- package/build/runtime-cjs/client/documentStore.js +1 -0
- package/build/runtime-cjs/client/plugins/cache.js +5 -3
- package/build/runtime-cjs/client/plugins/fetch.js +1 -0
- package/build/runtime-cjs/client/plugins/query.js +1 -0
- package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -2
- package/build/runtime-cjs/client/plugins/subscription.js +2 -0
- package/build/runtime-cjs/lib/config.d.ts +4 -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/types.d.ts +2 -2
- package/build/runtime-cjs/public/cache.d.ts +8 -1
- package/build/runtime-cjs/public/cache.js +3 -0
- package/build/runtime-cjs/public/record.d.ts +11 -1
- package/build/runtime-cjs/public/record.js +8 -1
- package/build/runtime-cjs/public/tests/test.d.ts +9 -10
- package/build/runtime-esm/cache/cache.d.ts +20 -3
- package/build/runtime-esm/cache/cache.js +66 -7
- package/build/runtime-esm/cache/gc.js +9 -0
- package/build/runtime-esm/cache/staleManager.d.ts +30 -0
- package/build/runtime-esm/cache/staleManager.js +71 -0
- package/build/runtime-esm/cache/subscription.d.ts +2 -1
- package/build/runtime-esm/cache/subscription.js +6 -3
- package/build/runtime-esm/client/documentStore.js +1 -0
- package/build/runtime-esm/client/plugins/cache.js +5 -3
- package/build/runtime-esm/client/plugins/fetch.js +1 -0
- package/build/runtime-esm/client/plugins/query.js +1 -0
- package/build/runtime-esm/client/plugins/subscription.d.ts +1 -2
- package/build/runtime-esm/client/plugins/subscription.js +2 -0
- package/build/runtime-esm/lib/config.d.ts +4 -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/types.d.ts +2 -2
- package/build/runtime-esm/public/cache.d.ts +8 -1
- package/build/runtime-esm/public/cache.js +3 -0
- package/build/runtime-esm/public/record.d.ts +11 -1
- package/build/runtime-esm/public/record.js +8 -1
- package/build/runtime-esm/public/tests/test.d.ts +9 -10
- package/build/test/index.d.ts +3 -3
- package/build/test-cjs/index.js +983 -828
- package/build/test-esm/index.js +983 -828
- package/build/vite-cjs/index.js +1285 -1079
- package/build/vite-esm/index.js +1285 -1079
- package/package.json +3 -2
|
@@ -0,0 +1,95 @@
|
|
|
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 staleManager_exports = {};
|
|
20
|
+
__export(staleManager_exports, {
|
|
21
|
+
StaleManager: () => StaleManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(staleManager_exports);
|
|
24
|
+
var import_lib = require("../lib");
|
|
25
|
+
class StaleManager {
|
|
26
|
+
cache;
|
|
27
|
+
fieldsTime = /* @__PURE__ */ new Map();
|
|
28
|
+
constructor(cache) {
|
|
29
|
+
this.cache = cache;
|
|
30
|
+
}
|
|
31
|
+
#initMapId = (id) => {
|
|
32
|
+
if (!this.fieldsTime.get(id)) {
|
|
33
|
+
this.fieldsTime.set(id, /* @__PURE__ */ new Map());
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
getFieldTime(id, field) {
|
|
37
|
+
return this.fieldsTime.get(id)?.get(field);
|
|
38
|
+
}
|
|
39
|
+
setFieldTimeToNow(id, field) {
|
|
40
|
+
this.#initMapId(id);
|
|
41
|
+
this.fieldsTime.get(id)?.set(field, new Date().valueOf());
|
|
42
|
+
}
|
|
43
|
+
markFieldStale(id, field) {
|
|
44
|
+
this.#initMapId(id);
|
|
45
|
+
this.fieldsTime.get(id)?.set(field, null);
|
|
46
|
+
}
|
|
47
|
+
markAllStale() {
|
|
48
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
49
|
+
for (const [field] of fieldMap.entries()) {
|
|
50
|
+
this.markFieldStale(id, field);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
markRecordStale(id) {
|
|
55
|
+
const fieldsTimeOfType = this.fieldsTime.get(id);
|
|
56
|
+
if (fieldsTimeOfType) {
|
|
57
|
+
for (const [field] of fieldsTimeOfType.entries()) {
|
|
58
|
+
this.markFieldStale(id, field);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
markTypeStale(type) {
|
|
63
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
64
|
+
if (id.startsWith(`${type}:`)) {
|
|
65
|
+
for (const [field] of fieldMap.entries()) {
|
|
66
|
+
this.markFieldStale(id, field);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
markTypeFieldStale(type, field, when) {
|
|
72
|
+
const key = (0, import_lib.computeKey)({ field, args: when });
|
|
73
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
74
|
+
if (id.startsWith(`${type}:`)) {
|
|
75
|
+
for (const local_field of fieldMap.keys()) {
|
|
76
|
+
if (local_field === key) {
|
|
77
|
+
this.markFieldStale(id, field);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
delete(id, field) {
|
|
84
|
+
if (this.fieldsTime.has(id)) {
|
|
85
|
+
this.fieldsTime.get(id)?.delete(field);
|
|
86
|
+
if (this.fieldsTime.get(id)?.size === 0) {
|
|
87
|
+
this.fieldsTime.delete(id);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
StaleManager
|
|
95
|
+
});
|
|
@@ -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'];
|
|
@@ -51,7 +51,8 @@ class InMemorySubscriptions {
|
|
|
51
51
|
this.addFieldSubscription({
|
|
52
52
|
id: parent,
|
|
53
53
|
key,
|
|
54
|
-
selection: [spec, targetSelection2]
|
|
54
|
+
selection: [spec, targetSelection2],
|
|
55
|
+
type
|
|
55
56
|
});
|
|
56
57
|
if (list) {
|
|
57
58
|
this.registerList({
|
|
@@ -88,7 +89,8 @@ class InMemorySubscriptions {
|
|
|
88
89
|
addFieldSubscription({
|
|
89
90
|
id,
|
|
90
91
|
key,
|
|
91
|
-
selection
|
|
92
|
+
selection,
|
|
93
|
+
type
|
|
92
94
|
}) {
|
|
93
95
|
const spec = selection[0];
|
|
94
96
|
if (!this.subscribers[id]) {
|
|
@@ -160,7 +162,8 @@ class InMemorySubscriptions {
|
|
|
160
162
|
this.addFieldSubscription({
|
|
161
163
|
id: parent,
|
|
162
164
|
key,
|
|
163
|
-
selection: [spec, fieldSelection]
|
|
165
|
+
selection: [spec, fieldSelection],
|
|
166
|
+
type: linkedType
|
|
164
167
|
});
|
|
165
168
|
if (list) {
|
|
166
169
|
this.registerList({
|
|
@@ -52,7 +52,8 @@ const cachePolicyPlugin = ({
|
|
|
52
52
|
data: value.data,
|
|
53
53
|
errors: null,
|
|
54
54
|
source: import_types.DataSource.Cache,
|
|
55
|
-
partial: value.partial
|
|
55
|
+
partial: value.partial,
|
|
56
|
+
stale: value.stale
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
useCache = !!(value.data !== null && allowed);
|
|
@@ -63,10 +64,11 @@ const cachePolicyPlugin = ({
|
|
|
63
64
|
data: value.data,
|
|
64
65
|
errors: null,
|
|
65
66
|
source: import_types.DataSource.Cache,
|
|
66
|
-
partial: value.partial
|
|
67
|
+
partial: value.partial,
|
|
68
|
+
stale: value.stale
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
|
-
if (useCache && !value.partial) {
|
|
71
|
+
if (useCache && !value.partial && !value.stale) {
|
|
70
72
|
return;
|
|
71
73
|
}
|
|
72
74
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { GraphQLObject } from '../../lib/types';
|
|
2
1
|
import type { ClientPluginContext } from '../documentStore';
|
|
3
2
|
export declare function subscriptionPlugin(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
|
|
4
3
|
export type SubscriptionHandler = (ctx: ClientPluginContext) => {
|
|
@@ -7,7 +6,7 @@ export type SubscriptionHandler = (ctx: ClientPluginContext) => {
|
|
|
7
6
|
variables?: {};
|
|
8
7
|
}, handlers: {
|
|
9
8
|
next: (payload: {
|
|
10
|
-
data?:
|
|
9
|
+
data?: {} | null;
|
|
11
10
|
errors?: readonly {
|
|
12
11
|
message: string;
|
|
13
12
|
}[];
|
|
@@ -66,6 +66,7 @@ function subscriptionPlugin(factory) {
|
|
|
66
66
|
errors: [...errors ?? []],
|
|
67
67
|
fetching: false,
|
|
68
68
|
partial: true,
|
|
69
|
+
stale: false,
|
|
69
70
|
source: import_types.DataSource.Network,
|
|
70
71
|
variables: ctx.variables ?? null
|
|
71
72
|
});
|
|
@@ -74,6 +75,7 @@ function subscriptionPlugin(factory) {
|
|
|
74
75
|
clearSubscription?.();
|
|
75
76
|
resolve(ctx, {
|
|
76
77
|
partial: true,
|
|
78
|
+
stale: false,
|
|
77
79
|
source: import_types.DataSource.Network,
|
|
78
80
|
data: null,
|
|
79
81
|
errors: [data],
|
|
@@ -55,6 +55,10 @@ export type ConfigFile = {
|
|
|
55
55
|
* Specifies whether or not the cache should always use partial data. For more information: https://www.houdinigraphql.com/guides/caching-data#partial-data
|
|
56
56
|
*/
|
|
57
57
|
defaultPartial?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Specifies after how long a data goes stale in miliseconds. (default: `undefined`)
|
|
60
|
+
*/
|
|
61
|
+
defaultLifetime?: number;
|
|
58
62
|
/**
|
|
59
63
|
* Specifies whether mutations should append or prepend list. For more information: https://www.houdinigraphql.com/api/graphql (default: `append`)
|
|
60
64
|
*/
|
|
@@ -22,3 +22,4 @@ __reExport(lib_exports, require("./log"), module.exports);
|
|
|
22
22
|
__reExport(lib_exports, require("./scalars"), module.exports);
|
|
23
23
|
__reExport(lib_exports, require("./types"), module.exports);
|
|
24
24
|
__reExport(lib_exports, require("./store"), module.exports);
|
|
25
|
+
__reExport(lib_exports, require("./key"), module.exports);
|
|
@@ -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 key_exports = {};
|
|
20
|
+
__export(key_exports, {
|
|
21
|
+
computeKey: () => computeKey
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(key_exports);
|
|
24
|
+
const computeKey = ({ field, args }) => {
|
|
25
|
+
const keys = Object.keys(args ?? {});
|
|
26
|
+
keys.sort();
|
|
27
|
+
return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
|
|
28
|
+
};
|
|
29
|
+
const stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
|
|
30
|
+
if (Array.isArray(obj_from_json)) {
|
|
31
|
+
return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
|
|
32
|
+
}
|
|
33
|
+
if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
|
|
34
|
+
return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
|
|
35
|
+
}
|
|
36
|
+
return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
|
|
37
|
+
};
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
computeKey
|
|
41
|
+
});
|
|
@@ -80,7 +80,7 @@ export type BaseCompiledDocument = {
|
|
|
80
80
|
paginated: boolean;
|
|
81
81
|
direction: 'forward' | 'backward' | 'both';
|
|
82
82
|
};
|
|
83
|
-
|
|
83
|
+
plugin_data?: Record<string, any>;
|
|
84
84
|
};
|
|
85
85
|
export type HoudiniFetchContext = {
|
|
86
86
|
variables: () => {};
|
|
@@ -164,7 +164,6 @@ export type SubscriptionSpec = {
|
|
|
164
164
|
export type FetchQueryResult<_Data> = {
|
|
165
165
|
result: RequestPayload<_Data | null>;
|
|
166
166
|
source: DataSource | null;
|
|
167
|
-
partial: boolean;
|
|
168
167
|
};
|
|
169
168
|
export type QueryResult<_Data = GraphQLObject, _Input = Record<string, any>> = {
|
|
170
169
|
data: _Data | null;
|
|
@@ -173,6 +172,7 @@ export type QueryResult<_Data = GraphQLObject, _Input = Record<string, any>> = {
|
|
|
173
172
|
}[] | null;
|
|
174
173
|
fetching: boolean;
|
|
175
174
|
partial: boolean;
|
|
175
|
+
stale: boolean;
|
|
176
176
|
source: DataSource | null;
|
|
177
177
|
variables: _Input | null;
|
|
178
178
|
};
|
|
@@ -2,7 +2,7 @@ import type { Cache as _Cache } from '../cache/cache';
|
|
|
2
2
|
import { type QueryArtifact } from '../lib';
|
|
3
3
|
import { ListCollection } from './list';
|
|
4
4
|
import { Record } from './record';
|
|
5
|
-
import type { CacheTypeDef, IDFields, QueryInput, QueryList, QueryValue, TypeNames, ValidLists } from './types';
|
|
5
|
+
import type { ArgType, CacheTypeDef, IDFields, QueryInput, QueryList, QueryValue, TypeFieldNames, TypeNames, ValidLists } from './types';
|
|
6
6
|
export declare class Cache<Def extends CacheTypeDef> {
|
|
7
7
|
_internal_unstable: _Cache;
|
|
8
8
|
constructor(cache: _Cache);
|
|
@@ -29,4 +29,11 @@ export declare class Cache<Def extends CacheTypeDef> {
|
|
|
29
29
|
data: QueryValue<QueryList<Def>, _Query>;
|
|
30
30
|
variables?: QueryInput<QueryList<Def>, _Query>;
|
|
31
31
|
}): void;
|
|
32
|
+
/**
|
|
33
|
+
* Mark some elements of the cache stale.
|
|
34
|
+
*/
|
|
35
|
+
markStale<_Type extends TypeNames<Def>, _Field extends TypeFieldNames<Def, _Type>>(type?: _Type, options?: {
|
|
36
|
+
field?: _Field;
|
|
37
|
+
when?: ArgType<Def, _Type, _Field>;
|
|
38
|
+
}): void;
|
|
32
39
|
}
|
|
@@ -87,6 +87,9 @@ 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, options);
|
|
92
|
+
}
|
|
90
93
|
}
|
|
91
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
92
95
|
0 && (module.exports = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FragmentArtifact } from '../lib/types';
|
|
2
2
|
import type { Cache } from './cache';
|
|
3
|
-
import type { CacheTypeDef, FragmentList, FragmentValue, FragmentVariables, ValidTypes } from './types';
|
|
3
|
+
import type { ArgType, CacheTypeDef, FragmentList, FragmentValue, FragmentVariables, TypeFieldNames, ValidTypes } from './types';
|
|
4
4
|
export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<Def>> {
|
|
5
5
|
#private;
|
|
6
6
|
type: string;
|
|
@@ -26,6 +26,16 @@ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<De
|
|
|
26
26
|
fragment: _Fragment;
|
|
27
27
|
data: FragmentValue<FragmentList<Def, Type>, _Fragment>;
|
|
28
28
|
variables?: FragmentVariables<FragmentList<Def, Type>, _Fragment>;
|
|
29
|
+
forceStale?: boolean;
|
|
29
30
|
}): void;
|
|
30
31
|
delete(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Mark some elements of the record stale in the cache.
|
|
34
|
+
* @param field
|
|
35
|
+
* @param when
|
|
36
|
+
*/
|
|
37
|
+
markStale<Field extends TypeFieldNames<Def, Type>>({ field, when, }?: {
|
|
38
|
+
field?: Field;
|
|
39
|
+
when?: ArgType<Def, Type, Field>;
|
|
40
|
+
}): void;
|
|
31
41
|
}
|
|
@@ -70,12 +70,19 @@ class Record {
|
|
|
70
70
|
config: this.#cache.config,
|
|
71
71
|
artifact: args.fragment.artifact,
|
|
72
72
|
input: args.variables
|
|
73
|
-
}) ?? void 0
|
|
73
|
+
}) ?? void 0,
|
|
74
|
+
forceStale: args.forceStale
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
delete() {
|
|
77
78
|
this.#cache._internal_unstable.delete(this.#id);
|
|
78
79
|
}
|
|
80
|
+
markStale({
|
|
81
|
+
field,
|
|
82
|
+
when
|
|
83
|
+
} = {}) {
|
|
84
|
+
this.#cache._internal_unstable.markRecordStale(this.#id, { field, when });
|
|
85
|
+
}
|
|
79
86
|
}
|
|
80
87
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
88
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type SubscriptionSelection, type FragmentArtifact, type QueryArtifact } from '../../lib';
|
|
2
2
|
import { Cache } from '../cache';
|
|
3
3
|
import type { Record } from '../record';
|
|
4
|
-
type
|
|
4
|
+
export type CacheTypeDefTest = {
|
|
5
5
|
types: {
|
|
6
6
|
__ROOT__: {
|
|
7
7
|
idFields: {};
|
|
@@ -16,23 +16,23 @@ type CacheTypeDef = {
|
|
|
16
16
|
args: never;
|
|
17
17
|
};
|
|
18
18
|
viewer: {
|
|
19
|
-
type: Record<
|
|
19
|
+
type: Record<CacheTypeDefTest, 'User'> | null;
|
|
20
20
|
args: never;
|
|
21
21
|
};
|
|
22
22
|
pets: {
|
|
23
|
-
type: (Record<
|
|
23
|
+
type: (Record<CacheTypeDefTest, 'Cat'> | Record<CacheTypeDefTest, 'User'>)[];
|
|
24
24
|
args: never;
|
|
25
25
|
};
|
|
26
26
|
listOfLists: {
|
|
27
|
-
type: ((Record<
|
|
27
|
+
type: ((Record<CacheTypeDefTest, 'Cat'> | Record<CacheTypeDefTest, 'User'> | null | (null | Record<CacheTypeDefTest, 'User'>)[])[] | Record<CacheTypeDefTest, 'Cat'> | Record<CacheTypeDefTest, 'User'> | null)[];
|
|
28
28
|
args: never;
|
|
29
29
|
};
|
|
30
30
|
users: {
|
|
31
|
-
type: Record<
|
|
31
|
+
type: Record<CacheTypeDefTest, 'User'>[] | null;
|
|
32
32
|
args: never;
|
|
33
33
|
};
|
|
34
34
|
pet: {
|
|
35
|
-
type: Record<
|
|
35
|
+
type: Record<CacheTypeDefTest, 'Cat'> | Record<CacheTypeDefTest, 'User'>;
|
|
36
36
|
args: never;
|
|
37
37
|
};
|
|
38
38
|
};
|
|
@@ -60,7 +60,7 @@ type CacheTypeDef = {
|
|
|
60
60
|
args: never;
|
|
61
61
|
};
|
|
62
62
|
parent: {
|
|
63
|
-
type: Record<
|
|
63
|
+
type: Record<CacheTypeDefTest, 'User'>;
|
|
64
64
|
args: never;
|
|
65
65
|
};
|
|
66
66
|
id: {
|
|
@@ -84,7 +84,7 @@ type CacheTypeDef = {
|
|
|
84
84
|
args: never;
|
|
85
85
|
};
|
|
86
86
|
parent: {
|
|
87
|
-
type: Record<
|
|
87
|
+
type: Record<CacheTypeDefTest, 'User'> | null;
|
|
88
88
|
args: never;
|
|
89
89
|
};
|
|
90
90
|
id: {
|
|
@@ -147,11 +147,10 @@ type CacheTypeDef = {
|
|
|
147
147
|
};
|
|
148
148
|
};
|
|
149
149
|
};
|
|
150
|
-
export declare const testCache: () => Cache<
|
|
150
|
+
export declare const testCache: () => Cache<CacheTypeDefTest>;
|
|
151
151
|
export declare const testFragment: (selection: SubscriptionSelection) => {
|
|
152
152
|
artifact: FragmentArtifact;
|
|
153
153
|
};
|
|
154
154
|
export declare const testQuery: (selection: SubscriptionSelection) => {
|
|
155
155
|
artifact: QueryArtifact;
|
|
156
156
|
};
|
|
157
|
-
export {};
|
|
@@ -4,9 +4,10 @@ import { GarbageCollector } from './gc';
|
|
|
4
4
|
import type { ListCollection } from './lists';
|
|
5
5
|
import { ListManager } from './lists';
|
|
6
6
|
import { SchemaManager } from './schema';
|
|
7
|
+
import { StaleManager } from './staleManager';
|
|
7
8
|
import type { Layer, LayerID } from './storage';
|
|
8
9
|
import { InMemoryStorage } from './storage';
|
|
9
|
-
import { type FieldSelection
|
|
10
|
+
import { InMemorySubscriptions, type FieldSelection } from './subscription';
|
|
10
11
|
export declare class Cache {
|
|
11
12
|
_internal_unstable: CacheInternal;
|
|
12
13
|
constructor(config?: ConfigFile);
|
|
@@ -21,16 +22,27 @@ export declare class Cache {
|
|
|
21
22
|
applyUpdates?: string[];
|
|
22
23
|
notifySubscribers?: SubscriptionSpec[];
|
|
23
24
|
forceNotify?: boolean;
|
|
25
|
+
forceStale?: boolean;
|
|
24
26
|
}): SubscriptionSpec[];
|
|
25
27
|
read(...args: Parameters<CacheInternal['getSelection']>): {
|
|
26
28
|
data: GraphQLObject | null;
|
|
27
29
|
partial: boolean;
|
|
30
|
+
stale: boolean;
|
|
28
31
|
};
|
|
29
32
|
subscribe(spec: SubscriptionSpec, variables?: {}): void;
|
|
30
33
|
unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
|
|
31
34
|
list(name: string, parentID?: string, allLists?: boolean): ListCollection;
|
|
32
35
|
delete(id: string): void;
|
|
33
36
|
setConfig(config: ConfigFile): void;
|
|
37
|
+
markTypeStale(type?: string, options?: {
|
|
38
|
+
field?: string;
|
|
39
|
+
when?: {};
|
|
40
|
+
}): void;
|
|
41
|
+
markRecordStale(id: string, options: {
|
|
42
|
+
field?: string;
|
|
43
|
+
when?: {};
|
|
44
|
+
}): void;
|
|
45
|
+
getFieldTime(id: string, field: string): number | null | undefined;
|
|
34
46
|
}
|
|
35
47
|
declare class CacheInternal {
|
|
36
48
|
private _disabled;
|
|
@@ -40,17 +52,19 @@ declare class CacheInternal {
|
|
|
40
52
|
lists: ListManager;
|
|
41
53
|
cache: Cache;
|
|
42
54
|
lifetimes: GarbageCollector;
|
|
55
|
+
staleManager: StaleManager;
|
|
43
56
|
schema: SchemaManager;
|
|
44
|
-
constructor({ storage, subscriptions, lists, cache, lifetimes, schema, }: {
|
|
57
|
+
constructor({ storage, subscriptions, lists, cache, lifetimes, staleManager, schema, }: {
|
|
45
58
|
storage: InMemoryStorage;
|
|
46
59
|
subscriptions: InMemorySubscriptions;
|
|
47
60
|
lists: ListManager;
|
|
48
61
|
cache: Cache;
|
|
49
62
|
lifetimes: GarbageCollector;
|
|
63
|
+
staleManager: StaleManager;
|
|
50
64
|
schema: SchemaManager;
|
|
51
65
|
});
|
|
52
66
|
setConfig(config: ConfigFile): void;
|
|
53
|
-
writeSelection({ data, selection, variables, parent, applyUpdates, layer, toNotify, forceNotify, }: {
|
|
67
|
+
writeSelection({ data, selection, variables, parent, applyUpdates, layer, toNotify, forceNotify, forceStale, }: {
|
|
54
68
|
data: {
|
|
55
69
|
[key: string]: GraphQLValue;
|
|
56
70
|
};
|
|
@@ -64,6 +78,7 @@ declare class CacheInternal {
|
|
|
64
78
|
toNotify?: FieldSelection[];
|
|
65
79
|
applyUpdates?: string[];
|
|
66
80
|
forceNotify?: boolean;
|
|
81
|
+
forceStale?: boolean;
|
|
67
82
|
}): FieldSelection[];
|
|
68
83
|
getSelection({ selection, parent, variables, stepsFromConnection, }: {
|
|
69
84
|
selection: SubscriptionSelection;
|
|
@@ -73,6 +88,7 @@ declare class CacheInternal {
|
|
|
73
88
|
}): {
|
|
74
89
|
data: GraphQLObject | null;
|
|
75
90
|
partial: boolean;
|
|
91
|
+
stale: boolean;
|
|
76
92
|
hasData: boolean;
|
|
77
93
|
};
|
|
78
94
|
id(type: string, data: {} | null): string | null;
|
|
@@ -87,6 +103,7 @@ declare class CacheInternal {
|
|
|
87
103
|
}): {
|
|
88
104
|
data: LinkedList<GraphQLValue>;
|
|
89
105
|
partial: boolean;
|
|
106
|
+
stale: boolean;
|
|
90
107
|
hasData: boolean;
|
|
91
108
|
};
|
|
92
109
|
extractNestedListIDs({ value, abstract, recordID, key, linkedType, fields, variables, applyUpdates, specs, layer, forceNotify, }: {
|