houdini 0.18.2 → 0.19.0
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 +1126 -706
- package/build/cmd-esm/index.js +1126 -706
- package/build/codegen/generators/artifacts/utils.d.ts +2 -1
- package/build/codegen/generators/runtime/index.d.ts +2 -2
- package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +1 -1
- package/build/codegen/generators/typescript/imperativeCache.d.ts +2 -0
- package/build/codegen/generators/typescript/typeReference.d.ts +1 -1
- package/build/codegen/utils/objectIdentificationSelection.d.ts +3 -0
- package/build/codegen-cjs/index.js +1026 -655
- package/build/codegen-esm/index.js +1026 -655
- package/build/lib/config.d.ts +27 -10
- package/build/lib-cjs/index.js +172 -64
- package/build/lib-esm/index.js +171 -64
- package/build/runtime/cache/cache.d.ts +5 -2
- package/build/runtime/cache/schema.d.ts +21 -0
- package/build/runtime/generated.d.ts +4 -0
- package/build/runtime/index.d.ts +6 -3
- package/build/runtime/lib/config.d.ts +8 -4
- package/build/runtime/lib/network.d.ts +2 -2
- package/build/runtime/lib/types.d.ts +2 -2
- package/build/runtime/public/cache.d.ts +19 -0
- package/build/runtime/public/index.d.ts +1 -0
- package/build/runtime/public/list.d.ts +18 -0
- package/build/runtime/public/record.d.ts +31 -0
- package/build/runtime/public/tests/test.d.ts +114 -0
- package/build/runtime/public/types.d.ts +36 -0
- package/build/runtime-cjs/cache/cache.d.ts +5 -2
- package/build/runtime-cjs/cache/cache.js +16 -5
- package/build/runtime-cjs/cache/schema.d.ts +21 -0
- package/build/runtime-cjs/cache/schema.js +66 -0
- package/build/runtime-cjs/generated.d.ts +4 -0
- package/build/runtime-cjs/generated.js +16 -0
- package/build/runtime-cjs/index.d.ts +6 -3
- package/build/runtime-cjs/index.js +4 -0
- package/build/runtime-cjs/lib/config.d.ts +8 -4
- package/build/runtime-cjs/lib/network.d.ts +2 -2
- package/build/runtime-cjs/lib/network.js +2 -2
- package/build/runtime-cjs/lib/types.d.ts +2 -2
- package/build/runtime-cjs/public/cache.d.ts +19 -0
- package/build/runtime-cjs/public/cache.js +97 -0
- package/build/runtime-cjs/public/index.d.ts +1 -0
- package/build/runtime-cjs/public/index.js +28 -0
- package/build/runtime-cjs/public/list.d.ts +18 -0
- package/build/runtime-cjs/public/list.js +163 -0
- package/build/runtime-cjs/public/record.d.ts +31 -0
- package/build/runtime-cjs/public/record.js +249 -0
- package/build/runtime-cjs/public/tests/test.d.ts +114 -0
- package/build/runtime-cjs/public/tests/test.js +31 -0
- package/build/runtime-cjs/public/types.d.ts +36 -0
- package/build/runtime-cjs/public/types.js +16 -0
- package/build/runtime-esm/cache/cache.d.ts +5 -2
- package/build/runtime-esm/cache/cache.js +16 -5
- package/build/runtime-esm/cache/schema.d.ts +21 -0
- package/build/runtime-esm/cache/schema.js +42 -0
- package/build/runtime-esm/generated.d.ts +4 -0
- package/build/runtime-esm/generated.js +0 -0
- package/build/runtime-esm/index.d.ts +6 -3
- package/build/runtime-esm/index.js +5 -2
- package/build/runtime-esm/lib/config.d.ts +8 -4
- package/build/runtime-esm/lib/network.d.ts +2 -2
- package/build/runtime-esm/lib/network.js +2 -2
- package/build/runtime-esm/lib/types.d.ts +2 -2
- package/build/runtime-esm/public/cache.d.ts +19 -0
- package/build/runtime-esm/public/cache.js +72 -0
- package/build/runtime-esm/public/index.d.ts +1 -0
- package/build/runtime-esm/public/index.js +4 -0
- package/build/runtime-esm/public/list.d.ts +18 -0
- package/build/runtime-esm/public/list.js +139 -0
- package/build/runtime-esm/public/record.d.ts +31 -0
- package/build/runtime-esm/public/record.js +222 -0
- package/build/runtime-esm/public/tests/test.d.ts +114 -0
- package/build/runtime-esm/public/tests/test.js +7 -0
- package/build/runtime-esm/public/types.d.ts +36 -0
- package/build/runtime-esm/public/types.js +0 -0
- package/build/test-cjs/index.js +1032 -638
- package/build/test-esm/index.js +1032 -638
- package/build/vite-cjs/index.js +1104 -699
- package/build/vite-esm/index.js +1104 -699
- package/package.json +2 -2
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Cache } from '../cache';
|
|
2
|
+
import { Record } from '../record';
|
|
3
|
+
type CacheTypeDef = {
|
|
4
|
+
types: {
|
|
5
|
+
__ROOT__: {
|
|
6
|
+
idFields: {};
|
|
7
|
+
fields: {
|
|
8
|
+
test: {
|
|
9
|
+
type: number | null;
|
|
10
|
+
args: never;
|
|
11
|
+
};
|
|
12
|
+
testDate: {
|
|
13
|
+
type: Date;
|
|
14
|
+
args: never;
|
|
15
|
+
};
|
|
16
|
+
viewer: {
|
|
17
|
+
type: Record<CacheTypeDef, 'User'> | null;
|
|
18
|
+
args: never;
|
|
19
|
+
};
|
|
20
|
+
pets: {
|
|
21
|
+
type: (Record<CacheTypeDef, 'Cat'> | Record<CacheTypeDef, 'User'>)[];
|
|
22
|
+
args: never;
|
|
23
|
+
};
|
|
24
|
+
listOfLists: {
|
|
25
|
+
type: ((Record<CacheTypeDef, 'Cat'> | Record<CacheTypeDef, 'User'> | null | (null | Record<CacheTypeDef, 'User'>)[])[] | Record<CacheTypeDef, 'Cat'> | Record<CacheTypeDef, 'User'> | null)[];
|
|
26
|
+
args: never;
|
|
27
|
+
};
|
|
28
|
+
users: {
|
|
29
|
+
type: Record<CacheTypeDef, 'User'>[] | null;
|
|
30
|
+
args: never;
|
|
31
|
+
};
|
|
32
|
+
pet: {
|
|
33
|
+
type: Record<CacheTypeDef, 'Cat'> | Record<CacheTypeDef, 'User'>;
|
|
34
|
+
args: never;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
User: {
|
|
39
|
+
idFields: {
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
fields: {
|
|
43
|
+
firstName: {
|
|
44
|
+
type: string;
|
|
45
|
+
args: never;
|
|
46
|
+
};
|
|
47
|
+
parent: {
|
|
48
|
+
type: Record<CacheTypeDef, 'User'>;
|
|
49
|
+
args: never;
|
|
50
|
+
};
|
|
51
|
+
id: {
|
|
52
|
+
type: string;
|
|
53
|
+
args: never;
|
|
54
|
+
};
|
|
55
|
+
__typename: {
|
|
56
|
+
type: string;
|
|
57
|
+
args: never;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
Cat: {
|
|
62
|
+
idFields: {
|
|
63
|
+
id: string;
|
|
64
|
+
};
|
|
65
|
+
fields: {
|
|
66
|
+
name: {
|
|
67
|
+
type: string | null;
|
|
68
|
+
args: never;
|
|
69
|
+
};
|
|
70
|
+
parent: {
|
|
71
|
+
type: Record<CacheTypeDef, 'User'> | null;
|
|
72
|
+
args: never;
|
|
73
|
+
};
|
|
74
|
+
id: {
|
|
75
|
+
type: string;
|
|
76
|
+
args: never;
|
|
77
|
+
};
|
|
78
|
+
__typename: {
|
|
79
|
+
type: string;
|
|
80
|
+
args: never;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
Ghost: {
|
|
85
|
+
idFields: {
|
|
86
|
+
id: string;
|
|
87
|
+
};
|
|
88
|
+
fields: {
|
|
89
|
+
name: {
|
|
90
|
+
type: string | null;
|
|
91
|
+
args: never;
|
|
92
|
+
};
|
|
93
|
+
__typename: {
|
|
94
|
+
type: string;
|
|
95
|
+
args: never;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
lists: {
|
|
101
|
+
All_Pets: {
|
|
102
|
+
types: 'User' | 'Cat';
|
|
103
|
+
filters: never;
|
|
104
|
+
};
|
|
105
|
+
All_Users: {
|
|
106
|
+
types: 'User';
|
|
107
|
+
filters: {
|
|
108
|
+
foo?: string;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
export declare const testCache: () => Cache<CacheTypeDef>;
|
|
114
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Record } from './record';
|
|
2
|
+
export type CacheTypeDef = {
|
|
3
|
+
types: {
|
|
4
|
+
[typeName: string]: {
|
|
5
|
+
idFields: {
|
|
6
|
+
[fieldName: string]: any;
|
|
7
|
+
};
|
|
8
|
+
fields: {
|
|
9
|
+
[fieldName: string]: {
|
|
10
|
+
args: any;
|
|
11
|
+
type: any;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
lists: {
|
|
17
|
+
[listName: string]: {
|
|
18
|
+
types: any;
|
|
19
|
+
filters: any;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export type ValidTypes<Def extends CacheTypeDef> = keyof Def['types'];
|
|
24
|
+
export type TypeFields<Def extends CacheTypeDef, Type extends keyof Def['types']> = Def['types'][Type]['fields'];
|
|
25
|
+
export type TypeFieldNames<Def extends CacheTypeDef, Type extends keyof Def['types']> = Extract<keyof TypeFields<Def, Type>, string>;
|
|
26
|
+
export type TypeNames<Def extends CacheTypeDef> = Extract<Exclude<ValidTypes<Def>, '__ROOT__'>, string>;
|
|
27
|
+
export type IDFields<Def extends CacheTypeDef, Type extends keyof Def['types']> = Def['types'][Type]['idFields'];
|
|
28
|
+
export type ProxyUnion<Def extends CacheTypeDef, U> = U extends null ? null : U extends TypeNames<Def> ? Record<Def, U> : never;
|
|
29
|
+
export type FieldType<Def extends CacheTypeDef, Type extends keyof Def['types'], Field extends keyof TypeFields<Def, Type>> = TypeFields<Def, Type>[Field]['type'];
|
|
30
|
+
export type ArgType<Def extends CacheTypeDef, Type extends keyof Def['types'], Field extends keyof TypeFields<Def, Type>> = TypeFields<Def, Type>[Field]['args'];
|
|
31
|
+
export type ValidLists<Def extends CacheTypeDef> = Extract<keyof Def['lists'], string>;
|
|
32
|
+
export type ListFilters<Def extends CacheTypeDef, ListName extends ValidLists<Def>> = Def['lists'][ListName]['filters'] extends any ? {
|
|
33
|
+
must?: Def['lists'][ListName]['filters'];
|
|
34
|
+
must_not?: Def['lists'][ListName]['filters'];
|
|
35
|
+
} : never;
|
|
36
|
+
export type ListType<Def extends CacheTypeDef, Name extends ValidLists<Def>> = ProxyUnion<Def, Def['lists'][Name]['types']>;
|
|
@@ -2,6 +2,7 @@ import { ConfigFile } from '../lib/config';
|
|
|
2
2
|
import { GraphQLObject, GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
|
|
3
3
|
import { GarbageCollector } from './gc';
|
|
4
4
|
import { ListCollection, ListManager } from './lists';
|
|
5
|
+
import { SchemaManager } from './schema';
|
|
5
6
|
import { InMemoryStorage, Layer, LayerID } from './storage';
|
|
6
7
|
import { InMemorySubscriptions } from './subscription';
|
|
7
8
|
export declare class Cache {
|
|
@@ -37,15 +38,17 @@ declare class CacheInternal {
|
|
|
37
38
|
lists: ListManager;
|
|
38
39
|
cache: Cache;
|
|
39
40
|
lifetimes: GarbageCollector;
|
|
40
|
-
|
|
41
|
+
schema: SchemaManager;
|
|
42
|
+
constructor({ storage, subscriptions, lists, cache, lifetimes, schema, }: {
|
|
41
43
|
storage: InMemoryStorage;
|
|
42
44
|
subscriptions: InMemorySubscriptions;
|
|
43
45
|
lists: ListManager;
|
|
44
46
|
cache: Cache;
|
|
45
47
|
lifetimes: GarbageCollector;
|
|
48
|
+
schema: SchemaManager;
|
|
46
49
|
});
|
|
47
50
|
setConfig(config: ConfigFile): void;
|
|
48
|
-
writeSelection({ data, selection, variables,
|
|
51
|
+
writeSelection({ data, selection, variables, parent, applyUpdates, layer, toNotify, forceNotify, }: {
|
|
49
52
|
data: {
|
|
50
53
|
[key: string]: GraphQLValue;
|
|
51
54
|
};
|
|
@@ -27,6 +27,7 @@ var import_deepEquals = require("../lib/deepEquals");
|
|
|
27
27
|
var import_selection = require("../lib/selection");
|
|
28
28
|
var import_gc = require("./gc");
|
|
29
29
|
var import_lists = require("./lists");
|
|
30
|
+
var import_schema = require("./schema");
|
|
30
31
|
var import_storage = require("./storage");
|
|
31
32
|
var import_stuff = require("./stuff");
|
|
32
33
|
var import_subscription = require("./subscription");
|
|
@@ -38,7 +39,8 @@ class Cache {
|
|
|
38
39
|
storage: new import_storage.InMemoryStorage(),
|
|
39
40
|
subscriptions: new import_subscription.InMemorySubscriptions(this),
|
|
40
41
|
lists: new import_lists.ListManager(this, rootID),
|
|
41
|
-
lifetimes: new import_gc.GarbageCollector(this)
|
|
42
|
+
lifetimes: new import_gc.GarbageCollector(this),
|
|
43
|
+
schema: new import_schema.SchemaManager(this)
|
|
42
44
|
});
|
|
43
45
|
if (config) {
|
|
44
46
|
this.setConfig((0, import_config.defaultConfigValues)(config));
|
|
@@ -124,18 +126,21 @@ class CacheInternal {
|
|
|
124
126
|
lists;
|
|
125
127
|
cache;
|
|
126
128
|
lifetimes;
|
|
129
|
+
schema;
|
|
127
130
|
constructor({
|
|
128
131
|
storage,
|
|
129
132
|
subscriptions,
|
|
130
133
|
lists,
|
|
131
134
|
cache,
|
|
132
|
-
lifetimes
|
|
135
|
+
lifetimes,
|
|
136
|
+
schema
|
|
133
137
|
}) {
|
|
134
138
|
this.storage = storage;
|
|
135
139
|
this.subscriptions = subscriptions;
|
|
136
140
|
this.lists = lists;
|
|
137
141
|
this.cache = cache;
|
|
138
142
|
this.lifetimes = lifetimes;
|
|
143
|
+
this.schema = schema;
|
|
139
144
|
this._disabled = typeof globalThis.window === "undefined";
|
|
140
145
|
try {
|
|
141
146
|
if (process.env.HOUDINI_TEST === "true") {
|
|
@@ -151,7 +156,6 @@ class CacheInternal {
|
|
|
151
156
|
data,
|
|
152
157
|
selection,
|
|
153
158
|
variables = {},
|
|
154
|
-
root = rootID,
|
|
155
159
|
parent = rootID,
|
|
156
160
|
applyUpdates = false,
|
|
157
161
|
layer,
|
|
@@ -174,9 +178,17 @@ class CacheInternal {
|
|
|
174
178
|
selection: fieldSelection,
|
|
175
179
|
operations,
|
|
176
180
|
abstract: isAbstract,
|
|
177
|
-
update
|
|
181
|
+
update,
|
|
182
|
+
nullable
|
|
178
183
|
} = targetSelection[field];
|
|
179
184
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
185
|
+
this.schema.setFieldType({
|
|
186
|
+
parent,
|
|
187
|
+
key: keyRaw,
|
|
188
|
+
type: linkedType,
|
|
189
|
+
nullable,
|
|
190
|
+
link: !!fieldSelection
|
|
191
|
+
});
|
|
180
192
|
const currentSubscribers = this.subscriptions.get(parent, key);
|
|
181
193
|
const { value: previousValue, displayLayers } = this.storage.get(parent, key);
|
|
182
194
|
const displayLayer = layer.isDisplayLayer(displayLayers);
|
|
@@ -245,7 +257,6 @@ class CacheInternal {
|
|
|
245
257
|
}
|
|
246
258
|
if (linkedID) {
|
|
247
259
|
this.writeSelection({
|
|
248
|
-
root,
|
|
249
260
|
selection: fieldSelection,
|
|
250
261
|
parent: linkedID,
|
|
251
262
|
data: value,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ConfigFile } from '../lib';
|
|
2
|
+
import { Cache } from './cache';
|
|
3
|
+
export type TypeInfo = {
|
|
4
|
+
type: string;
|
|
5
|
+
nullable: boolean;
|
|
6
|
+
link: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare class SchemaManager {
|
|
9
|
+
cache: Cache;
|
|
10
|
+
fieldTypes: Record<string, Record<string, TypeInfo>>;
|
|
11
|
+
constructor(cache: Cache);
|
|
12
|
+
setFieldType({ parent, key, type, nullable, link, }: {
|
|
13
|
+
parent: string;
|
|
14
|
+
key: string;
|
|
15
|
+
type: string;
|
|
16
|
+
nullable?: boolean;
|
|
17
|
+
link?: boolean;
|
|
18
|
+
}): void;
|
|
19
|
+
fieldType(type: string, field: string): TypeInfo;
|
|
20
|
+
get config(): ConfigFile;
|
|
21
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 schema_exports = {};
|
|
20
|
+
__export(schema_exports, {
|
|
21
|
+
SchemaManager: () => SchemaManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(schema_exports);
|
|
24
|
+
var import_cache = require("./cache");
|
|
25
|
+
class SchemaManager {
|
|
26
|
+
cache;
|
|
27
|
+
fieldTypes = {};
|
|
28
|
+
constructor(cache) {
|
|
29
|
+
this.cache = cache;
|
|
30
|
+
}
|
|
31
|
+
setFieldType({
|
|
32
|
+
parent,
|
|
33
|
+
key,
|
|
34
|
+
type,
|
|
35
|
+
nullable = false,
|
|
36
|
+
link
|
|
37
|
+
}) {
|
|
38
|
+
let parensIndex = key.indexOf("(");
|
|
39
|
+
if (parensIndex !== -1) {
|
|
40
|
+
key = key.substring(0, parensIndex);
|
|
41
|
+
}
|
|
42
|
+
if (parent === import_cache.rootID) {
|
|
43
|
+
parent = "Query";
|
|
44
|
+
} else if (parent.includes(":")) {
|
|
45
|
+
parent = parent.substring(0, parent.indexOf(":"));
|
|
46
|
+
}
|
|
47
|
+
if (!this.fieldTypes[parent]) {
|
|
48
|
+
this.fieldTypes[parent] = {};
|
|
49
|
+
}
|
|
50
|
+
this.fieldTypes[parent][key] = {
|
|
51
|
+
type,
|
|
52
|
+
nullable,
|
|
53
|
+
link: !!link
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
fieldType(type, field) {
|
|
57
|
+
return this.fieldTypes[type]?.[field] || null;
|
|
58
|
+
}
|
|
59
|
+
get config() {
|
|
60
|
+
return this.cache._internal_unstable.config;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
SchemaManager
|
|
66
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var generated_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(generated_exports);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Cache as InternalCache } from './cache/cache';
|
|
2
|
+
import type { CacheTypeDef } from './generated';
|
|
3
|
+
import { Cache } from './public';
|
|
2
4
|
export * from './lib';
|
|
3
|
-
export declare function graphql(str: TemplateStringsArray): any;
|
|
4
|
-
export declare
|
|
5
|
+
export declare function graphql(str: string | TemplateStringsArray): any;
|
|
6
|
+
export declare const cache: Cache<CacheTypeDef>;
|
|
7
|
+
export declare function getCache(): InternalCache;
|
|
@@ -25,11 +25,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
26
|
var runtime_exports = {};
|
|
27
27
|
__export(runtime_exports, {
|
|
28
|
+
cache: () => cache,
|
|
28
29
|
getCache: () => getCache,
|
|
29
30
|
graphql: () => graphql
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(runtime_exports);
|
|
32
33
|
var import_cache = __toESM(require("./cache"), 1);
|
|
34
|
+
var import_public = require("./public");
|
|
33
35
|
__reExport(runtime_exports, require("./lib"), module.exports);
|
|
34
36
|
function graphql(str) {
|
|
35
37
|
if (globalThis?.process?.env?.HOUDINI_PLUGIN) {
|
|
@@ -40,11 +42,13 @@ function graphql(str) {
|
|
|
40
42
|
Please make sure you have the appropriate plugin/preprocessor enabled. For more information, visit this link: https://houdinigraphql.com/guides/setting-up-your-project
|
|
41
43
|
`);
|
|
42
44
|
}
|
|
45
|
+
const cache = new import_public.Cache(import_cache.default);
|
|
43
46
|
function getCache() {
|
|
44
47
|
return import_cache.default;
|
|
45
48
|
}
|
|
46
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47
50
|
0 && (module.exports = {
|
|
51
|
+
cache,
|
|
48
52
|
getCache,
|
|
49
53
|
graphql
|
|
50
54
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { GraphQLSchema } from 'graphql';
|
|
3
2
|
import { CachePolicy } from './types';
|
|
4
3
|
export declare function getMockConfig(): ConfigFile | null;
|
|
@@ -35,7 +34,7 @@ export type ConfigFile = {
|
|
|
35
34
|
/**
|
|
36
35
|
* A url to use to pull the schema. For more information: https://www.houdinigraphql.com/api/cli#generate
|
|
37
36
|
*/
|
|
38
|
-
apiUrl?: string;
|
|
37
|
+
apiUrl?: string | ((env: Record<string, string | undefined>) => string);
|
|
39
38
|
/**
|
|
40
39
|
* An object describing custom scalars for your project. For more information: https://www.houdinigraphql.com/api/config#custom-scalars
|
|
41
40
|
*/
|
|
@@ -104,7 +103,7 @@ export type ConfigFile = {
|
|
|
104
103
|
* directly. If the value is a function, the current environment will be passed to your function so you can perform any
|
|
105
104
|
* logic you need
|
|
106
105
|
*/
|
|
107
|
-
schemaPollHeaders?: Record<string, string | ((env:
|
|
106
|
+
schemaPollHeaders?: Record<string, string | ((env: Record<string, string | undefined>) => string)> | ((env: Record<string, string | undefined>) => Record<string, string>);
|
|
108
107
|
/**
|
|
109
108
|
* An object describing the plugins enabled for the project
|
|
110
109
|
*/
|
|
@@ -114,6 +113,11 @@ export type ConfigFile = {
|
|
|
114
113
|
* @default process.cwd()
|
|
115
114
|
*/
|
|
116
115
|
projectDir?: string;
|
|
116
|
+
/**
|
|
117
|
+
* For now, the cache's imperative API is considered unstable. In order to suppress the warning,
|
|
118
|
+
* you must enable this flag.
|
|
119
|
+
*/
|
|
120
|
+
acceptImperativeInstability?: boolean;
|
|
117
121
|
};
|
|
118
122
|
type ScalarMap = {
|
|
119
123
|
[typeName: string]: ScalarSpec;
|
|
@@ -121,7 +125,7 @@ type ScalarMap = {
|
|
|
121
125
|
export type TypeConfig = {
|
|
122
126
|
[typeName: string]: {
|
|
123
127
|
keys?: string[];
|
|
124
|
-
resolve
|
|
128
|
+
resolve?: {
|
|
125
129
|
queryField: string;
|
|
126
130
|
arguments?: (data: any) => {
|
|
127
131
|
[key: string]: any;
|
|
@@ -4,7 +4,7 @@ import { CachePolicy, GraphQLObject, MutationArtifact, QueryArtifact, FetchQuery
|
|
|
4
4
|
export declare class HoudiniClient {
|
|
5
5
|
private fetchFn;
|
|
6
6
|
socket: SubscriptionHandler | null | undefined;
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(requestHandler: RequestHandler<any>, subscriptionHandler?: SubscriptionHandler | null);
|
|
8
8
|
handleMultipart(params: FetchParams, args: Parameters<FetchContext['fetch']>): Parameters<FetchContext['fetch']> | undefined;
|
|
9
9
|
sendRequest<_Data>(ctx: FetchContext, params: FetchParams): Promise<RequestPayloadMagic<_Data>>;
|
|
10
10
|
}
|
|
@@ -53,7 +53,7 @@ export type FetchContext = {
|
|
|
53
53
|
export type RequestHandlerArgs = FetchContext & FetchParams & {
|
|
54
54
|
session?: App.Session;
|
|
55
55
|
};
|
|
56
|
-
export type RequestHandler<_Data> = (args: RequestHandlerArgs) => Promise<RequestPayload<_Data>>;
|
|
56
|
+
export type RequestHandler<_Data = any> = (args: RequestHandlerArgs) => Promise<RequestPayload<_Data>>;
|
|
57
57
|
export declare function executeQuery<_Data extends GraphQLObject, _Input extends {}>({ client, artifact, variables, session, setFetching, cached, fetch, metadata, }: {
|
|
58
58
|
client: HoudiniClient;
|
|
59
59
|
artifact: QueryArtifact | MutationArtifact;
|
|
@@ -37,8 +37,8 @@ var import_types = require("./types");
|
|
|
37
37
|
class HoudiniClient {
|
|
38
38
|
fetchFn;
|
|
39
39
|
socket;
|
|
40
|
-
constructor(
|
|
41
|
-
this.fetchFn =
|
|
40
|
+
constructor(requestHandler, subscriptionHandler) {
|
|
41
|
+
this.fetchFn = requestHandler;
|
|
42
42
|
this.socket = subscriptionHandler;
|
|
43
43
|
}
|
|
44
44
|
handleMultipart(params, args) {
|
|
@@ -161,10 +161,10 @@ export type QueryResult<_Data, _Input, _Extra = {}> = {
|
|
|
161
161
|
variables: _Input;
|
|
162
162
|
} & _Extra;
|
|
163
163
|
export type RequestPayload<_Data = any> = {
|
|
164
|
-
data: _Data;
|
|
164
|
+
data: _Data | null;
|
|
165
165
|
errors: {
|
|
166
166
|
message: string;
|
|
167
|
-
}[];
|
|
167
|
+
}[] | null;
|
|
168
168
|
};
|
|
169
169
|
export type RequestPayloadMagic<_Data = any> = {
|
|
170
170
|
ssr: boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Cache as _Cache } from '../cache/cache';
|
|
2
|
+
import { SchemaManager, TypeInfo } from '../cache/schema';
|
|
3
|
+
import { ListCollection } from './list';
|
|
4
|
+
import { Record } from './record';
|
|
5
|
+
import type { CacheTypeDef, IDFields, TypeNames, ValidLists } from './types';
|
|
6
|
+
export declare class Cache<Def extends CacheTypeDef> {
|
|
7
|
+
_internal_unstable: _Cache;
|
|
8
|
+
constructor(cache: _Cache);
|
|
9
|
+
validateInstabilityWarning(): void;
|
|
10
|
+
setFieldType(...args: Parameters<SchemaManager['setFieldType']>): void;
|
|
11
|
+
get root(): Record<Def, '__ROOT__'>;
|
|
12
|
+
get<T extends TypeNames<Def>>(type: T, data: IDFields<Def, T>): Record<Def, T>;
|
|
13
|
+
get config(): import("..").ConfigFile;
|
|
14
|
+
list<Name extends ValidLists<Def>>(name: Name, { parentID, allLists }?: {
|
|
15
|
+
parentID?: string;
|
|
16
|
+
allLists?: boolean;
|
|
17
|
+
}): ListCollection<Def, Name>;
|
|
18
|
+
}
|
|
19
|
+
export declare function _typeInfo<Def extends CacheTypeDef>(cache: Cache<Def>, type: string, field: string): TypeInfo;
|
|
@@ -0,0 +1,97 @@
|
|
|
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 cache_exports = {};
|
|
20
|
+
__export(cache_exports, {
|
|
21
|
+
Cache: () => Cache,
|
|
22
|
+
_typeInfo: () => _typeInfo
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cache_exports);
|
|
25
|
+
var import_cache = require("../cache/cache");
|
|
26
|
+
var import_list = require("./list");
|
|
27
|
+
var import_record = require("./record");
|
|
28
|
+
class Cache {
|
|
29
|
+
_internal_unstable;
|
|
30
|
+
constructor(cache) {
|
|
31
|
+
this._internal_unstable = cache;
|
|
32
|
+
}
|
|
33
|
+
validateInstabilityWarning() {
|
|
34
|
+
if (!this.config.acceptImperativeInstability) {
|
|
35
|
+
console.warn(`\u26A0\uFE0F The imperative cache API is considered unstable and will change in any minor version release
|
|
36
|
+
Please acknowledge this by setting acceptImperativeInstability to true in your config file.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
setFieldType(...args) {
|
|
40
|
+
this.validateInstabilityWarning();
|
|
41
|
+
this._internal_unstable._internal_unstable.schema.setFieldType(...args);
|
|
42
|
+
}
|
|
43
|
+
get root() {
|
|
44
|
+
this.validateInstabilityWarning();
|
|
45
|
+
return new import_record.Record({
|
|
46
|
+
cache: this,
|
|
47
|
+
type: "Query",
|
|
48
|
+
id: import_cache.rootID,
|
|
49
|
+
idFields: {}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
get(type, data) {
|
|
53
|
+
this.validateInstabilityWarning();
|
|
54
|
+
let recordID = this._internal_unstable._internal_unstable.id(type, data);
|
|
55
|
+
if (!recordID) {
|
|
56
|
+
throw new Error("todo");
|
|
57
|
+
}
|
|
58
|
+
return new import_record.Record({
|
|
59
|
+
cache: this,
|
|
60
|
+
type,
|
|
61
|
+
id: recordID,
|
|
62
|
+
idFields: data
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
get config() {
|
|
66
|
+
return this._internal_unstable._internal_unstable.config;
|
|
67
|
+
}
|
|
68
|
+
list(name, { parentID, allLists } = {}) {
|
|
69
|
+
return new import_list.ListCollection({
|
|
70
|
+
cache: this,
|
|
71
|
+
name,
|
|
72
|
+
parentID,
|
|
73
|
+
allLists
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function _typeInfo(cache, type, field) {
|
|
78
|
+
if (field === "__typename") {
|
|
79
|
+
return {
|
|
80
|
+
type: "String",
|
|
81
|
+
nullable: false,
|
|
82
|
+
link: false
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const info = cache._internal_unstable._internal_unstable.schema.fieldType(type, field);
|
|
86
|
+
if (!info) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Unknown field: ${field} for type ${type}. Please provide type information using setFieldType().`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return info;
|
|
92
|
+
}
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
Cache,
|
|
96
|
+
_typeInfo
|
|
97
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Cache } from './cache';
|
|
@@ -0,0 +1,28 @@
|
|
|
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 public_exports = {};
|
|
20
|
+
__export(public_exports, {
|
|
21
|
+
Cache: () => import_cache.Cache
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(public_exports);
|
|
24
|
+
var import_cache = require("./cache");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
Cache
|
|
28
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Cache } from './cache';
|
|
2
|
+
import { CacheTypeDef, ListType, ValidLists, ListFilters } from './types';
|
|
3
|
+
export declare class ListCollection<Def extends CacheTypeDef, ListName extends ValidLists<Def>> {
|
|
4
|
+
#private;
|
|
5
|
+
constructor({ parentID, allLists, when, cache, name, }: {
|
|
6
|
+
name: ValidLists<Def>;
|
|
7
|
+
parentID?: string;
|
|
8
|
+
allLists?: boolean;
|
|
9
|
+
when?: ListFilters<Def, ListName>;
|
|
10
|
+
cache: Cache<Def>;
|
|
11
|
+
});
|
|
12
|
+
append(...records: ListType<Def, ListName>[]): void;
|
|
13
|
+
prepend(...records: ListType<Def, ListName>[]): void;
|
|
14
|
+
toggle(where: 'first' | 'last', ...records: ListType<Def, ListName>[]): void;
|
|
15
|
+
when(filter: ListFilters<Def, ListName>): ListCollection<Def, ListName>;
|
|
16
|
+
remove(...records: ListType<Def, ListName>[]): void;
|
|
17
|
+
[Symbol.iterator](): Generator<string, void, unknown>;
|
|
18
|
+
}
|