houdini 0.18.3 → 0.19.1

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.
Files changed (78) hide show
  1. package/build/cmd-cjs/index.js +961 -534
  2. package/build/cmd-esm/index.js +961 -534
  3. package/build/codegen/generators/artifacts/utils.d.ts +2 -1
  4. package/build/codegen/generators/runtime/index.d.ts +2 -2
  5. package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +1 -1
  6. package/build/codegen/generators/typescript/imperativeCache.d.ts +2 -0
  7. package/build/codegen/generators/typescript/typeReference.d.ts +1 -1
  8. package/build/codegen-cjs/index.js +861 -483
  9. package/build/codegen-esm/index.js +861 -483
  10. package/build/lib/config.d.ts +27 -10
  11. package/build/lib-cjs/index.js +172 -64
  12. package/build/lib-esm/index.js +171 -64
  13. package/build/runtime/cache/cache.d.ts +5 -2
  14. package/build/runtime/cache/schema.d.ts +21 -0
  15. package/build/runtime/generated.d.ts +4 -0
  16. package/build/runtime/index.d.ts +6 -3
  17. package/build/runtime/lib/config.d.ts +7 -3
  18. package/build/runtime/lib/network.d.ts +2 -2
  19. package/build/runtime/lib/types.d.ts +2 -2
  20. package/build/runtime/public/cache.d.ts +19 -0
  21. package/build/runtime/public/index.d.ts +1 -0
  22. package/build/runtime/public/list.d.ts +18 -0
  23. package/build/runtime/public/record.d.ts +31 -0
  24. package/build/runtime/public/tests/test.d.ts +114 -0
  25. package/build/runtime/public/types.d.ts +36 -0
  26. package/build/runtime-cjs/cache/cache.d.ts +5 -2
  27. package/build/runtime-cjs/cache/cache.js +16 -5
  28. package/build/runtime-cjs/cache/schema.d.ts +21 -0
  29. package/build/runtime-cjs/cache/schema.js +66 -0
  30. package/build/runtime-cjs/generated.d.ts +4 -0
  31. package/build/runtime-cjs/generated.js +16 -0
  32. package/build/runtime-cjs/index.d.ts +6 -3
  33. package/build/runtime-cjs/index.js +4 -0
  34. package/build/runtime-cjs/lib/config.d.ts +7 -3
  35. package/build/runtime-cjs/lib/network.d.ts +2 -2
  36. package/build/runtime-cjs/lib/network.js +2 -2
  37. package/build/runtime-cjs/lib/types.d.ts +2 -2
  38. package/build/runtime-cjs/public/cache.d.ts +19 -0
  39. package/build/runtime-cjs/public/cache.js +97 -0
  40. package/build/runtime-cjs/public/index.d.ts +1 -0
  41. package/build/runtime-cjs/public/index.js +28 -0
  42. package/build/runtime-cjs/public/list.d.ts +18 -0
  43. package/build/runtime-cjs/public/list.js +163 -0
  44. package/build/runtime-cjs/public/record.d.ts +31 -0
  45. package/build/runtime-cjs/public/record.js +249 -0
  46. package/build/runtime-cjs/public/tests/test.d.ts +114 -0
  47. package/build/runtime-cjs/public/tests/test.js +31 -0
  48. package/build/runtime-cjs/public/types.d.ts +36 -0
  49. package/build/runtime-cjs/public/types.js +16 -0
  50. package/build/runtime-esm/cache/cache.d.ts +5 -2
  51. package/build/runtime-esm/cache/cache.js +16 -5
  52. package/build/runtime-esm/cache/schema.d.ts +21 -0
  53. package/build/runtime-esm/cache/schema.js +42 -0
  54. package/build/runtime-esm/generated.d.ts +4 -0
  55. package/build/runtime-esm/generated.js +0 -0
  56. package/build/runtime-esm/index.d.ts +6 -3
  57. package/build/runtime-esm/index.js +5 -2
  58. package/build/runtime-esm/lib/config.d.ts +7 -3
  59. package/build/runtime-esm/lib/network.d.ts +2 -2
  60. package/build/runtime-esm/lib/network.js +2 -2
  61. package/build/runtime-esm/lib/types.d.ts +2 -2
  62. package/build/runtime-esm/public/cache.d.ts +19 -0
  63. package/build/runtime-esm/public/cache.js +72 -0
  64. package/build/runtime-esm/public/index.d.ts +1 -0
  65. package/build/runtime-esm/public/index.js +4 -0
  66. package/build/runtime-esm/public/list.d.ts +18 -0
  67. package/build/runtime-esm/public/list.js +139 -0
  68. package/build/runtime-esm/public/record.d.ts +31 -0
  69. package/build/runtime-esm/public/record.js +222 -0
  70. package/build/runtime-esm/public/tests/test.d.ts +114 -0
  71. package/build/runtime-esm/public/tests/test.js +7 -0
  72. package/build/runtime-esm/public/types.d.ts +36 -0
  73. package/build/runtime-esm/public/types.js +0 -0
  74. package/build/test-cjs/index.js +857 -466
  75. package/build/test-esm/index.js +857 -466
  76. package/build/vite-cjs/index.js +939 -527
  77. package/build/vite-esm/index.js +939 -527
  78. package/package.json +2 -2
@@ -0,0 +1,163 @@
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 list_exports = {};
20
+ __export(list_exports, {
21
+ ListCollection: () => ListCollection
22
+ });
23
+ module.exports = __toCommonJS(list_exports);
24
+ var import_lib = require("../lib");
25
+ var import_cache = require("./cache");
26
+ var import_record = require("./record");
27
+ class ListCollection {
28
+ #parentID;
29
+ #allLists;
30
+ #when;
31
+ #cache;
32
+ #name;
33
+ constructor({
34
+ parentID,
35
+ allLists,
36
+ when,
37
+ cache,
38
+ name
39
+ }) {
40
+ this.#parentID = parentID;
41
+ this.#allLists = allLists;
42
+ this.#when = when;
43
+ this.#cache = cache;
44
+ this.#name = name;
45
+ }
46
+ append(...records) {
47
+ if (!this.#collection) {
48
+ return;
49
+ }
50
+ const { selection, data } = this.#listOperationPayload(records);
51
+ for (const entry of data) {
52
+ if (entry) {
53
+ this.#collection.append(selection, entry);
54
+ }
55
+ }
56
+ }
57
+ prepend(...records) {
58
+ if (!this.#collection) {
59
+ return;
60
+ }
61
+ const { selection, data } = this.#listOperationPayload(records);
62
+ for (const entry of data) {
63
+ if (entry) {
64
+ this.#collection.prepend(selection, entry);
65
+ }
66
+ }
67
+ }
68
+ toggle(where, ...records) {
69
+ if (!this.#collection) {
70
+ return;
71
+ }
72
+ const { selection, data } = this.#listOperationPayload(records);
73
+ for (const entry of data) {
74
+ if (entry) {
75
+ this.#collection.toggleElement(selection, entry, {}, where);
76
+ }
77
+ }
78
+ }
79
+ when(filter) {
80
+ if (!this.#collection) {
81
+ return this;
82
+ }
83
+ return new ListCollection({
84
+ parentID: this.#parentID,
85
+ allLists: this.#allLists,
86
+ when: this.#when,
87
+ cache: this.#cache,
88
+ name: this.#name
89
+ });
90
+ }
91
+ remove(...records) {
92
+ if (!this.#collection) {
93
+ return;
94
+ }
95
+ for (const record of records) {
96
+ if (record) {
97
+ this.#collection.remove(record.idFields);
98
+ }
99
+ }
100
+ }
101
+ *[Symbol.iterator]() {
102
+ for (const entry of this.#collection ?? []) {
103
+ yield entry;
104
+ }
105
+ }
106
+ get #collection() {
107
+ try {
108
+ const list = this.#cache._internal_unstable.list(
109
+ this.#name,
110
+ this.#parentID,
111
+ this.#allLists
112
+ );
113
+ if (this.#when) {
114
+ return list.when(this.#when);
115
+ }
116
+ return list;
117
+ } catch {
118
+ return null;
119
+ }
120
+ }
121
+ #listOperationPayload(records) {
122
+ const selection = {
123
+ abstractFields: {
124
+ fields: {},
125
+ typeMap: {}
126
+ }
127
+ };
128
+ const data = [];
129
+ for (const record of records) {
130
+ if (!(record instanceof import_record.Record)) {
131
+ throw new Error("You must provide a Record to a list operation");
132
+ }
133
+ const keys = (0, import_lib.keyFieldsForType)(this.#cache.config, record.type);
134
+ selection.abstractFields.fields[record.type] = keys.reduce(
135
+ (acc, key) => {
136
+ const keyInfo = (0, import_cache._typeInfo)(this.#cache, record.type, key);
137
+ return {
138
+ ...acc,
139
+ [key]: {
140
+ type: keyInfo.type,
141
+ keyRaw: key
142
+ }
143
+ };
144
+ },
145
+ {
146
+ __typename: {
147
+ type: "String",
148
+ keyRaw: "__typename"
149
+ }
150
+ }
151
+ );
152
+ data.push({ __typename: record.type, ...record.idFields });
153
+ }
154
+ return {
155
+ selection,
156
+ data
157
+ };
158
+ }
159
+ }
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ ListCollection
163
+ });
@@ -0,0 +1,31 @@
1
+ import { Cache } from './cache';
2
+ import type { ArgType, CacheTypeDef, FieldType, TypeFieldNames, ValidTypes } from './types';
3
+ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<Def>> {
4
+ #private;
5
+ type: string;
6
+ idFields: {};
7
+ constructor({ cache, type, id, idFields, }: {
8
+ cache: Cache<Def>;
9
+ type: string;
10
+ idFields: {};
11
+ id: string;
12
+ });
13
+ set<Field extends TypeFieldNames<Def, Type>>({ field, args, value, }: {
14
+ field: Field;
15
+ args?: ArgType<Def, Type, Field>;
16
+ value: FieldType<Def, Type, Field>;
17
+ }): void;
18
+ get<Field extends TypeFieldNames<Def, Type>>({ field, args, }: {
19
+ field: Field;
20
+ args?: ArgType<Def, Type, Field>;
21
+ }): FieldType<Def, Type, Field>;
22
+ delete(): void;
23
+ }
24
+ export declare function computeKey({ field, args }: {
25
+ field: string;
26
+ args?: {
27
+ [key: string]: any;
28
+ };
29
+ }): string;
30
+ export declare const stringifyObjectWithNoQuotesOnKeys: (obj_from_json: {}) => string;
31
+ export declare function marshalNestedList(list: any[]): any[];
@@ -0,0 +1,249 @@
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 record_exports = {};
20
+ __export(record_exports, {
21
+ Record: () => Record,
22
+ computeKey: () => computeKey,
23
+ marshalNestedList: () => marshalNestedList,
24
+ stringifyObjectWithNoQuotesOnKeys: () => stringifyObjectWithNoQuotesOnKeys
25
+ });
26
+ module.exports = __toCommonJS(record_exports);
27
+ var import_cache = require("../cache/cache");
28
+ var import_lib = require("../lib");
29
+ var import_cache2 = require("./cache");
30
+ class Record {
31
+ #id;
32
+ #cache;
33
+ type;
34
+ idFields;
35
+ constructor({
36
+ cache,
37
+ type,
38
+ id,
39
+ idFields
40
+ }) {
41
+ this.#cache = cache;
42
+ this.#id = id;
43
+ this.type = type;
44
+ this.idFields = idFields;
45
+ if (id !== import_cache.rootID) {
46
+ for (const key of (0, import_lib.keyFieldsForType)(this.#cache.config, type)) {
47
+ if (!(key in idFields)) {
48
+ throw new Error("Missing key in idFields: " + key);
49
+ }
50
+ }
51
+ }
52
+ }
53
+ set({
54
+ field,
55
+ args,
56
+ value
57
+ }) {
58
+ this.#cache.validateInstabilityWarning();
59
+ const key = computeKey({ field, args });
60
+ const typeInfo = (0, import_cache2._typeInfo)(this.#cache, this.type, field);
61
+ let newValue;
62
+ if (typeInfo.link) {
63
+ const keys = (0, import_lib.keyFieldsForType)(this.#cache.config, typeInfo.type);
64
+ typeInfo.selection = {
65
+ fields: keys.reduce(
66
+ (acc, key2) => {
67
+ const keyInfo = (0, import_cache2._typeInfo)(this.#cache, typeInfo.type, key2);
68
+ return {
69
+ ...acc,
70
+ [key2]: {
71
+ type: keyInfo.type,
72
+ keyRaw: key2
73
+ }
74
+ };
75
+ },
76
+ {
77
+ __typename: {
78
+ type: "String",
79
+ keyRaw: "__typename"
80
+ }
81
+ }
82
+ )
83
+ };
84
+ }
85
+ if (!typeInfo.link) {
86
+ const fnMarshal = this.#cache.config.scalars?.[typeInfo.type]?.marshal;
87
+ if (fnMarshal) {
88
+ newValue = fnMarshal(value);
89
+ } else {
90
+ newValue = value;
91
+ }
92
+ } else if (value instanceof Record) {
93
+ newValue = {
94
+ ...value.idFields,
95
+ __typename: value.type
96
+ };
97
+ } else if (Array.isArray(value)) {
98
+ newValue = marshalNestedList(value);
99
+ } else if (value !== null) {
100
+ throw new Error("Value must be a RecordProxy if the field is a link to another record");
101
+ }
102
+ this.#cache._internal_unstable._internal_unstable.lifetimes.resetLifetime(this.#id, key);
103
+ this.#cache._internal_unstable.write({
104
+ parent: this.#id,
105
+ selection: {
106
+ fields: {
107
+ [field]: {
108
+ keyRaw: key,
109
+ ...typeInfo
110
+ }
111
+ }
112
+ },
113
+ data: {
114
+ [field]: newValue
115
+ }
116
+ });
117
+ }
118
+ get({
119
+ field,
120
+ args
121
+ }) {
122
+ this.#cache.validateInstabilityWarning();
123
+ const key = computeKey({ field, args });
124
+ const typeInfo = (0, import_cache2._typeInfo)(this.#cache, this.type, field);
125
+ if (typeInfo.link) {
126
+ const keys = (0, import_lib.keyFieldsForType)(this.#cache.config, typeInfo.type);
127
+ typeInfo.selection = {
128
+ fields: keys.reduce(
129
+ (acc, key2) => {
130
+ const keyInfo = (0, import_cache2._typeInfo)(this.#cache, typeInfo.type, key2);
131
+ return {
132
+ ...acc,
133
+ [key2]: {
134
+ type: keyInfo.type,
135
+ keyRaw: key2
136
+ }
137
+ };
138
+ },
139
+ {
140
+ __typename: {
141
+ type: "String",
142
+ keyRaw: "__typename"
143
+ }
144
+ }
145
+ )
146
+ };
147
+ }
148
+ const result = this.#cache._internal_unstable.read({
149
+ parent: this.#id,
150
+ selection: {
151
+ fields: {
152
+ [field]: {
153
+ keyRaw: key,
154
+ ...typeInfo
155
+ }
156
+ }
157
+ }
158
+ });
159
+ if (!typeInfo.link) {
160
+ return result.data?.[field] ?? (typeInfo.nullable ? null : void 0);
161
+ }
162
+ const data = result.data?.[field] || {};
163
+ let finalResult = unmarshalNestedList(
164
+ this.#cache,
165
+ !Array.isArray(data) ? [data] : data
166
+ ).map((val) => {
167
+ if (typeInfo.nullable && (val === null || Object.keys(val).length === 0)) {
168
+ return null;
169
+ }
170
+ return val;
171
+ });
172
+ return Array.isArray(data) ? finalResult : finalResult[0];
173
+ }
174
+ delete() {
175
+ this.#cache._internal_unstable.delete(this.#id);
176
+ }
177
+ }
178
+ function computeKey({ field, args }) {
179
+ const keys = Object.keys(args ?? {});
180
+ keys.sort();
181
+ return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
182
+ }
183
+ const stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
184
+ if (Array.isArray(obj_from_json)) {
185
+ return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
186
+ }
187
+ if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
188
+ return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
189
+ }
190
+ return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
191
+ };
192
+ function marshalNestedList(list) {
193
+ const newValue = [];
194
+ for (const inner of list) {
195
+ if (Array.isArray(inner)) {
196
+ newValue.push(marshalNestedList(inner));
197
+ } else if (inner instanceof Record) {
198
+ newValue.push({ ...inner.idFields, __typename: inner.type });
199
+ } else {
200
+ newValue.push(inner);
201
+ }
202
+ }
203
+ return newValue;
204
+ }
205
+ function unmarshalNestedList(cache, list) {
206
+ const newValue = [];
207
+ for (const inner of list) {
208
+ if (Array.isArray(inner)) {
209
+ newValue.push(unmarshalNestedList(cache, inner));
210
+ } else if (inner === null) {
211
+ newValue.push(null);
212
+ } else if (inner.__typename) {
213
+ const type = inner.__typename;
214
+ let recordID = cache._internal_unstable._internal_unstable.id(type, inner);
215
+ if (!recordID) {
216
+ throw new Error("todo");
217
+ }
218
+ const typename = cache._internal_unstable.read({
219
+ selection: {
220
+ fields: {
221
+ __typename: {
222
+ keyRaw: "__typename",
223
+ type: "String"
224
+ }
225
+ }
226
+ },
227
+ parent: recordID
228
+ }).data?.__typename;
229
+ newValue.push(
230
+ new Record({
231
+ cache,
232
+ type: type || typename,
233
+ idFields: inner,
234
+ id: recordID
235
+ })
236
+ );
237
+ } else {
238
+ newValue.push(inner);
239
+ }
240
+ }
241
+ return newValue;
242
+ }
243
+ // Annotate the CommonJS export names for ESM import in node:
244
+ 0 && (module.exports = {
245
+ Record,
246
+ computeKey,
247
+ marshalNestedList,
248
+ stringifyObjectWithNoQuotesOnKeys
249
+ });
@@ -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,31 @@
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 test_exports = {};
20
+ __export(test_exports, {
21
+ testCache: () => testCache
22
+ });
23
+ module.exports = __toCommonJS(test_exports);
24
+ var import_test = require("../../../test");
25
+ var import_cache = require("../../cache/cache");
26
+ var import_cache2 = require("../cache");
27
+ const testCache = () => new import_cache2.Cache(new import_cache.Cache((0, import_test.testConfigFile)()));
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ testCache
31
+ });
@@ -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']>;
@@ -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 types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -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
- constructor({ storage, subscriptions, lists, cache, lifetimes, }: {
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, root, parent, applyUpdates, layer, toNotify, forceNotify, }: {
51
+ writeSelection({ data, selection, variables, parent, applyUpdates, layer, toNotify, forceNotify, }: {
49
52
  data: {
50
53
  [key: string]: GraphQLValue;
51
54
  };