houdini 1.0.0-next.2 → 1.0.0-next.21

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 (195) hide show
  1. package/README.md +4 -1
  2. package/build/cmd-cjs/index.js +5366 -2772
  3. package/build/cmd-esm/index.js +5340 -2746
  4. package/build/codegen/generators/artifacts/index.d.ts +2 -2
  5. package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
  6. package/build/codegen/generators/artifacts/selection.d.ts +5 -5
  7. package/build/codegen/generators/artifacts/utils.d.ts +0 -1
  8. package/build/codegen/generators/indexFile/index.d.ts +2 -2
  9. package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
  10. package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -2
  11. package/build/codegen/generators/runtime/index.d.ts +2 -2
  12. package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
  13. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  14. package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
  15. package/build/codegen/generators/typescript/index.d.ts +2 -2
  16. package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
  17. package/build/codegen/generators/typescript/types.d.ts +0 -1
  18. package/build/codegen/index.d.ts +2 -2
  19. package/build/codegen/transforms/addID.d.ts +2 -2
  20. package/build/codegen/transforms/composeQueries.d.ts +4 -4
  21. package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
  22. package/build/codegen/transforms/list.d.ts +2 -2
  23. package/build/codegen/transforms/paginate.d.ts +2 -2
  24. package/build/codegen/transforms/schema.d.ts +2 -2
  25. package/build/codegen/transforms/typename.d.ts +2 -2
  26. package/build/codegen/utils/flattenSelections.d.ts +1 -1
  27. package/build/codegen/validators/noIDAlias.d.ts +2 -2
  28. package/build/codegen/validators/plugins.d.ts +2 -2
  29. package/build/codegen/validators/typeCheck.d.ts +2 -2
  30. package/build/codegen/validators/uniqueNames.d.ts +2 -2
  31. package/build/codegen-cjs/index.js +4694 -2137
  32. package/build/codegen-esm/index.js +4682 -2125
  33. package/build/lib/config.d.ts +15 -96
  34. package/build/lib/deepMerge.d.ts +1 -0
  35. package/build/lib/graphql.d.ts +5 -2
  36. package/build/lib/index.d.ts +2 -0
  37. package/build/lib/path.d.ts +1 -1
  38. package/build/lib/pipeline.d.ts +1 -1
  39. package/build/lib/plugin.d.ts +2 -0
  40. package/build/lib/types.d.ts +257 -6
  41. package/build/lib/walk.d.ts +4 -1
  42. package/build/lib-cjs/index.js +4108 -928
  43. package/build/lib-esm/index.js +4078 -907
  44. package/build/runtime/cache/cache.d.ts +28 -11
  45. package/build/runtime/cache/lists.d.ts +1 -0
  46. package/build/runtime/cache/staleManager.d.ts +30 -0
  47. package/build/runtime/cache/storage.d.ts +23 -20
  48. package/build/runtime/cache/stuff.d.ts +0 -2
  49. package/build/runtime/cache/subscription.d.ts +2 -1
  50. package/build/runtime/client/documentStore.d.ts +20 -17
  51. package/build/runtime/client/index.d.ts +13 -11
  52. package/build/runtime/client/plugins/cache.d.ts +1 -1
  53. package/build/runtime/client/plugins/fetch.d.ts +1 -1
  54. package/build/runtime/client/plugins/fetchParams.d.ts +2 -2
  55. package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
  56. package/build/runtime/client/plugins/mutation.d.ts +1 -1
  57. package/build/runtime/client/plugins/query.d.ts +1 -1
  58. package/build/runtime/client/plugins/subscription.d.ts +2 -3
  59. package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
  60. package/build/runtime/client/utils/documentPlugins.d.ts +3 -3
  61. package/build/runtime/generated.d.ts +1 -0
  62. package/build/runtime/imports/pluginConfig.d.ts +3 -0
  63. package/build/runtime/index.d.ts +1 -1
  64. package/build/runtime/lib/config.d.ts +27 -24
  65. package/build/runtime/lib/flatten.d.ts +2 -0
  66. package/build/runtime/lib/index.d.ts +1 -0
  67. package/build/runtime/lib/key.d.ts +6 -0
  68. package/build/runtime/lib/scalars.d.ts +3 -3
  69. package/build/runtime/lib/types.d.ts +47 -47
  70. package/build/runtime/public/cache.d.ts +26 -6
  71. package/build/runtime/public/record.d.ts +26 -17
  72. package/build/runtime/public/tests/test.d.ts +52 -10
  73. package/build/runtime/public/types.d.ts +8 -0
  74. package/build/runtime-cjs/cache/cache.d.ts +28 -11
  75. package/build/runtime-cjs/cache/cache.js +97 -22
  76. package/build/runtime-cjs/cache/gc.js +9 -0
  77. package/build/runtime-cjs/cache/lists.d.ts +1 -0
  78. package/build/runtime-cjs/cache/lists.js +9 -6
  79. package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
  80. package/build/runtime-cjs/cache/staleManager.js +95 -0
  81. package/build/runtime-cjs/cache/storage.d.ts +23 -20
  82. package/build/runtime-cjs/cache/storage.js +11 -13
  83. package/build/runtime-cjs/cache/stuff.d.ts +0 -2
  84. package/build/runtime-cjs/cache/stuff.js +2 -19
  85. package/build/runtime-cjs/cache/subscription.d.ts +2 -1
  86. package/build/runtime-cjs/cache/subscription.js +11 -7
  87. package/build/runtime-cjs/client/documentStore.d.ts +20 -17
  88. package/build/runtime-cjs/client/documentStore.js +13 -9
  89. package/build/runtime-cjs/client/index.d.ts +13 -11
  90. package/build/runtime-cjs/client/index.js +48 -19
  91. package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
  92. package/build/runtime-cjs/client/plugins/cache.js +12 -10
  93. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
  94. package/build/runtime-cjs/client/plugins/fetch.js +10 -9
  95. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +2 -2
  96. package/build/runtime-cjs/client/plugins/fetchParams.js +9 -4
  97. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
  98. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
  99. package/build/runtime-cjs/client/plugins/mutation.js +3 -3
  100. package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
  101. package/build/runtime-cjs/client/plugins/query.js +5 -5
  102. package/build/runtime-cjs/client/plugins/subscription.d.ts +2 -3
  103. package/build/runtime-cjs/client/plugins/subscription.js +7 -5
  104. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
  105. package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
  106. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -3
  107. package/build/runtime-cjs/generated.d.ts +1 -0
  108. package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
  109. package/build/runtime-cjs/imports/pluginConfig.js +27 -0
  110. package/build/runtime-cjs/index.d.ts +1 -1
  111. package/build/runtime-cjs/lib/config.d.ts +27 -24
  112. package/build/runtime-cjs/lib/config.js +11 -1
  113. package/build/runtime-cjs/lib/flatten.d.ts +2 -0
  114. package/build/runtime-cjs/lib/flatten.js +41 -0
  115. package/build/runtime-cjs/lib/index.d.ts +1 -0
  116. package/build/runtime-cjs/lib/index.js +1 -0
  117. package/build/runtime-cjs/lib/key.d.ts +6 -0
  118. package/build/runtime-cjs/lib/key.js +41 -0
  119. package/build/runtime-cjs/lib/scalars.d.ts +3 -3
  120. package/build/runtime-cjs/lib/scalars.js +13 -2
  121. package/build/runtime-cjs/lib/types.d.ts +47 -47
  122. package/build/runtime-cjs/lib/types.js +26 -30
  123. package/build/runtime-cjs/public/cache.d.ts +26 -6
  124. package/build/runtime-cjs/public/cache.js +32 -32
  125. package/build/runtime-cjs/public/list.js +6 -28
  126. package/build/runtime-cjs/public/record.d.ts +26 -17
  127. package/build/runtime-cjs/public/record.js +27 -187
  128. package/build/runtime-cjs/public/tests/test.d.ts +52 -10
  129. package/build/runtime-cjs/public/tests/test.js +27 -2
  130. package/build/runtime-cjs/public/types.d.ts +8 -0
  131. package/build/runtime-esm/cache/cache.d.ts +28 -11
  132. package/build/runtime-esm/cache/cache.js +99 -24
  133. package/build/runtime-esm/cache/gc.js +9 -0
  134. package/build/runtime-esm/cache/lists.d.ts +1 -0
  135. package/build/runtime-esm/cache/lists.js +9 -6
  136. package/build/runtime-esm/cache/staleManager.d.ts +30 -0
  137. package/build/runtime-esm/cache/staleManager.js +71 -0
  138. package/build/runtime-esm/cache/storage.d.ts +23 -20
  139. package/build/runtime-esm/cache/storage.js +11 -13
  140. package/build/runtime-esm/cache/stuff.d.ts +0 -2
  141. package/build/runtime-esm/cache/stuff.js +1 -17
  142. package/build/runtime-esm/cache/subscription.d.ts +2 -1
  143. package/build/runtime-esm/cache/subscription.js +12 -8
  144. package/build/runtime-esm/client/documentStore.d.ts +20 -17
  145. package/build/runtime-esm/client/documentStore.js +14 -10
  146. package/build/runtime-esm/client/index.d.ts +13 -11
  147. package/build/runtime-esm/client/index.js +49 -21
  148. package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
  149. package/build/runtime-esm/client/plugins/cache.js +11 -9
  150. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
  151. package/build/runtime-esm/client/plugins/fetch.js +9 -8
  152. package/build/runtime-esm/client/plugins/fetchParams.d.ts +2 -2
  153. package/build/runtime-esm/client/plugins/fetchParams.js +8 -3
  154. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
  155. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
  156. package/build/runtime-esm/client/plugins/mutation.js +2 -2
  157. package/build/runtime-esm/client/plugins/query.d.ts +1 -1
  158. package/build/runtime-esm/client/plugins/query.js +4 -4
  159. package/build/runtime-esm/client/plugins/subscription.d.ts +2 -3
  160. package/build/runtime-esm/client/plugins/subscription.js +6 -4
  161. package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
  162. package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
  163. package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -3
  164. package/build/runtime-esm/generated.d.ts +1 -0
  165. package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
  166. package/build/runtime-esm/imports/pluginConfig.js +5 -0
  167. package/build/runtime-esm/index.d.ts +1 -1
  168. package/build/runtime-esm/lib/config.d.ts +27 -24
  169. package/build/runtime-esm/lib/config.js +11 -1
  170. package/build/runtime-esm/lib/flatten.d.ts +2 -0
  171. package/build/runtime-esm/lib/flatten.js +17 -0
  172. package/build/runtime-esm/lib/index.d.ts +1 -0
  173. package/build/runtime-esm/lib/index.js +1 -0
  174. package/build/runtime-esm/lib/key.d.ts +6 -0
  175. package/build/runtime-esm/lib/key.js +17 -0
  176. package/build/runtime-esm/lib/scalars.d.ts +3 -3
  177. package/build/runtime-esm/lib/scalars.js +13 -2
  178. package/build/runtime-esm/lib/types.d.ts +47 -47
  179. package/build/runtime-esm/lib/types.js +26 -30
  180. package/build/runtime-esm/public/cache.d.ts +26 -6
  181. package/build/runtime-esm/public/cache.js +31 -30
  182. package/build/runtime-esm/public/list.js +6 -28
  183. package/build/runtime-esm/public/record.d.ts +26 -17
  184. package/build/runtime-esm/public/record.js +26 -183
  185. package/build/runtime-esm/public/tests/test.d.ts +52 -10
  186. package/build/runtime-esm/public/tests/test.js +26 -1
  187. package/build/runtime-esm/public/types.d.ts +8 -0
  188. package/build/test/index.d.ts +3 -3
  189. package/build/test-cjs/index.js +5007 -2465
  190. package/build/test-esm/index.js +4995 -2453
  191. package/build/vite/houdini.d.ts +2 -0
  192. package/build/vite-cjs/index.js +5344 -2744
  193. package/build/vite-esm/index.js +5319 -2719
  194. package/package.json +6 -5
  195. package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
@@ -28,36 +28,32 @@ __export(types_exports, {
28
28
  RefetchUpdateMode: () => RefetchUpdateMode
29
29
  });
30
30
  module.exports = __toCommonJS(types_exports);
31
- var CachePolicy = /* @__PURE__ */ ((CachePolicy2) => {
32
- CachePolicy2["CacheOrNetwork"] = "CacheOrNetwork";
33
- CachePolicy2["CacheOnly"] = "CacheOnly";
34
- CachePolicy2["NetworkOnly"] = "NetworkOnly";
35
- CachePolicy2["CacheAndNetwork"] = "CacheAndNetwork";
36
- return CachePolicy2;
37
- })(CachePolicy || {});
38
- var ArtifactKind = /* @__PURE__ */ ((ArtifactKind2) => {
39
- ArtifactKind2["Query"] = "HoudiniQuery";
40
- ArtifactKind2["Subscription"] = "HoudiniSubscription";
41
- ArtifactKind2["Mutation"] = "HoudiniMutation";
42
- ArtifactKind2["Fragment"] = "HoudiniFragment";
43
- return ArtifactKind2;
44
- })(ArtifactKind || {});
45
- const CompiledFragmentKind = "HoudiniFragment" /* Fragment */;
46
- const CompiledMutationKind = "HoudiniMutation" /* Mutation */;
47
- const CompiledQueryKind = "HoudiniQuery" /* Query */;
48
- const CompiledSubscriptionKind = "HoudiniSubscription" /* Subscription */;
49
- var RefetchUpdateMode = /* @__PURE__ */ ((RefetchUpdateMode2) => {
50
- RefetchUpdateMode2["append"] = "append";
51
- RefetchUpdateMode2["prepend"] = "prepend";
52
- RefetchUpdateMode2["replace"] = "replace";
53
- return RefetchUpdateMode2;
54
- })(RefetchUpdateMode || {});
55
- var DataSource = /* @__PURE__ */ ((DataSource2) => {
56
- DataSource2["Cache"] = "cache";
57
- DataSource2["Network"] = "network";
58
- DataSource2["Ssr"] = "ssr";
59
- return DataSource2;
60
- })(DataSource || {});
31
+ const CachePolicy = {
32
+ CacheOrNetwork: "CacheOrNetwork",
33
+ CacheOnly: "CacheOnly",
34
+ NetworkOnly: "NetworkOnly",
35
+ CacheAndNetwork: "CacheAndNetwork"
36
+ };
37
+ const ArtifactKind = {
38
+ Query: "HoudiniQuery",
39
+ Subscription: "HoudiniSubscription",
40
+ Mutation: "HoudiniMutation",
41
+ Fragment: "HoudiniFragment"
42
+ };
43
+ const CompiledFragmentKind = ArtifactKind.Fragment;
44
+ const CompiledMutationKind = ArtifactKind.Mutation;
45
+ const CompiledQueryKind = ArtifactKind.Query;
46
+ const CompiledSubscriptionKind = ArtifactKind.Subscription;
47
+ const RefetchUpdateMode = {
48
+ append: "append",
49
+ prepend: "prepend",
50
+ replace: "replace"
51
+ };
52
+ const DataSource = {
53
+ Cache: "cache",
54
+ Network: "network",
55
+ Ssr: "ssr"
56
+ };
61
57
  // Annotate the CommonJS export names for ESM import in node:
62
58
  0 && (module.exports = {
63
59
  ArtifactKind,
@@ -1,19 +1,39 @@
1
1
  import type { Cache as _Cache } from '../cache/cache';
2
- import type { SchemaManager, TypeInfo } from '../cache/schema';
2
+ import { type QueryArtifact } from '../lib';
3
3
  import { ListCollection } from './list';
4
4
  import { Record } from './record';
5
- import type { CacheTypeDef, IDFields, 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);
9
9
  validateInstabilityWarning(): void;
10
- setFieldType(...args: Parameters<SchemaManager['setFieldType']>): void;
11
- get root(): Record<Def, '__ROOT__'>;
12
10
  get<T extends TypeNames<Def>>(type: T, data: IDFields<Def, T>): Record<Def, T>;
13
- get config(): import("..").ConfigFile;
11
+ get config(): import("../lib").ConfigFile;
14
12
  list<Name extends ValidLists<Def>>(name: Name, { parentID, allLists }?: {
15
13
  parentID?: string;
16
14
  allLists?: boolean;
17
15
  }): ListCollection<Def, Name>;
16
+ read<_Query extends {
17
+ artifact: QueryArtifact;
18
+ }>({ query, variables, }: {
19
+ query: _Query;
20
+ variables?: QueryInput<QueryList<Def>, _Query>;
21
+ }): {
22
+ data: QueryValue<QueryList<Def>, _Query> | null;
23
+ partial: boolean;
24
+ };
25
+ write<_Query extends {
26
+ artifact: QueryArtifact;
27
+ }>({ query, variables, data, }: {
28
+ query: _Query;
29
+ data: QueryValue<QueryList<Def>, _Query>;
30
+ variables?: QueryInput<QueryList<Def>, _Query>;
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;
18
39
  }
19
- export declare function _typeInfo<Def extends CacheTypeDef>(cache: Cache<Def>, type: string, field: string): TypeInfo;
@@ -18,11 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var cache_exports = {};
20
20
  __export(cache_exports, {
21
- Cache: () => Cache,
22
- _typeInfo: () => _typeInfo
21
+ Cache: () => Cache
23
22
  });
24
23
  module.exports = __toCommonJS(cache_exports);
25
- var import_cache = require("../cache/cache");
24
+ var import_lib = require("../lib");
26
25
  var import_list = require("./list");
27
26
  var import_record = require("./record");
28
27
  class Cache {
@@ -36,19 +35,6 @@ class Cache {
36
35
  Please acknowledge this by setting acceptImperativeInstability to true in your config file.`);
37
36
  }
38
37
  }
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
38
  get(type, data) {
53
39
  this.validateInstabilityWarning();
54
40
  let recordID = this._internal_unstable._internal_unstable.id(type, data);
@@ -66,6 +52,7 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
66
52
  return this._internal_unstable._internal_unstable.config;
67
53
  }
68
54
  list(name, { parentID, allLists } = {}) {
55
+ this.validateInstabilityWarning();
69
56
  return new import_list.ListCollection({
70
57
  cache: this,
71
58
  name,
@@ -73,25 +60,38 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
73
60
  allLists
74
61
  });
75
62
  }
76
- }
77
- function _typeInfo(cache, type, field) {
78
- if (field === "__typename") {
79
- return {
80
- type: "String",
81
- nullable: false,
82
- link: false
83
- };
63
+ read({
64
+ query,
65
+ variables
66
+ }) {
67
+ this.validateInstabilityWarning();
68
+ return this._internal_unstable.read({
69
+ selection: query.artifact.selection,
70
+ variables
71
+ });
72
+ }
73
+ write({
74
+ query,
75
+ variables,
76
+ data
77
+ }) {
78
+ this.validateInstabilityWarning();
79
+ this._internal_unstable.write({
80
+ selection: query.artifact.selection,
81
+ data,
82
+ variables: (0, import_lib.marshalInputs)({
83
+ config: this.config,
84
+ artifact: query.artifact,
85
+ input: variables
86
+ }) ?? {}
87
+ });
88
+ return;
84
89
  }
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
+ markStale(type, options) {
91
+ return this._internal_unstable.markTypeStale(type ? { ...options, type } : void 0);
90
92
  }
91
- return info;
92
93
  }
93
94
  // Annotate the CommonJS export names for ESM import in node:
94
95
  0 && (module.exports = {
95
- Cache,
96
- _typeInfo
96
+ Cache
97
97
  });
@@ -21,8 +21,6 @@ __export(list_exports, {
21
21
  ListCollection: () => ListCollection
22
22
  });
23
23
  module.exports = __toCommonJS(list_exports);
24
- var import_config = require("../lib/config");
25
- var import_cache = require("./cache");
26
24
  var import_record = require("./record");
27
25
  class ListCollection {
28
26
  #parentID;
@@ -83,7 +81,7 @@ class ListCollection {
83
81
  return new ListCollection({
84
82
  parentID: this.#parentID,
85
83
  allLists: this.#allLists,
86
- when: this.#when,
84
+ when: filter,
87
85
  cache: this.#cache,
88
86
  name: this.#name
89
87
  });
@@ -119,36 +117,16 @@ class ListCollection {
119
117
  }
120
118
  }
121
119
  #listOperationPayload(records) {
122
- const selection = {
123
- abstractFields: {
124
- fields: {},
125
- typeMap: {}
126
- }
127
- };
120
+ let selection = this.#collection.selection;
121
+ const connectionSelection = selection.fields?.["edges"]?.selection?.fields?.node.selection;
122
+ if (connectionSelection) {
123
+ selection = connectionSelection;
124
+ }
128
125
  const data = [];
129
126
  for (const record of records) {
130
127
  if (!(record instanceof import_record.Record)) {
131
128
  throw new Error("You must provide a Record to a list operation");
132
129
  }
133
- const keys = (0, import_config.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
130
  data.push({ __typename: record.type, ...record.idFields });
153
131
  }
154
132
  return {
@@ -1,5 +1,6 @@
1
+ import type { FragmentArtifact } from '../lib/types';
1
2
  import type { Cache } from './cache';
2
- import type { ArgType, CacheTypeDef, FieldType, TypeFieldNames, ValidTypes } from './types';
3
+ import type { ArgType, CacheTypeDef, FragmentList, FragmentValue, FragmentVariables, TypeFieldNames, ValidTypes } from './types';
3
4
  export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<Def>> {
4
5
  #private;
5
6
  type: string;
@@ -10,22 +11,30 @@ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<De
10
11
  idFields: {};
11
12
  id: string;
12
13
  });
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>;
14
+ read<_Fragment extends {
15
+ artifact: FragmentArtifact;
16
+ }>({ fragment, variables, }: {
17
+ fragment: _Fragment;
18
+ variables?: FragmentVariables<FragmentList<Def, Type>, _Fragment>;
19
+ }): {
20
+ data: FragmentValue<FragmentList<Def, Type>, _Fragment> | null;
21
+ partial: boolean;
22
+ };
23
+ write<_Fragment extends {
24
+ artifact: FragmentArtifact;
25
+ }, _Variable>(args: {
26
+ fragment: _Fragment;
27
+ data: FragmentValue<FragmentList<Def, Type>, _Fragment>;
28
+ variables?: FragmentVariables<FragmentList<Def, Type>, _Fragment>;
29
+ forceStale?: boolean;
17
30
  }): 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
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?: Field, { when, }?: {
38
+ when?: ArgType<Def, Type, Field>;
39
+ }): void;
23
40
  }
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[];
@@ -18,15 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var record_exports = {};
20
20
  __export(record_exports, {
21
- Record: () => Record,
22
- computeKey: () => computeKey,
23
- marshalNestedList: () => marshalNestedList,
24
- stringifyObjectWithNoQuotesOnKeys: () => stringifyObjectWithNoQuotesOnKeys
21
+ Record: () => Record
25
22
  });
26
23
  module.exports = __toCommonJS(record_exports);
27
24
  var import_cache = require("../cache/cache");
25
+ var import_lib = require("../lib");
28
26
  var import_config = require("../lib/config");
29
- var import_cache2 = require("./cache");
30
27
  class Record {
31
28
  #id;
32
29
  #cache;
@@ -50,200 +47,43 @@ class Record {
50
47
  }
51
48
  }
52
49
  }
53
- set({
54
- field,
55
- args,
56
- value
50
+ read({
51
+ fragment,
52
+ variables
57
53
  }) {
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_config.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({
54
+ return this.#cache._internal_unstable.read({
55
+ selection: fragment.artifact.selection,
104
56
  parent: this.#id,
105
- selection: {
106
- fields: {
107
- [field]: {
108
- keyRaw: key,
109
- ...typeInfo
110
- }
111
- }
112
- },
113
- data: {
114
- [field]: newValue
115
- }
57
+ variables: (0, import_lib.marshalInputs)({
58
+ config: this.#cache.config,
59
+ artifact: fragment.artifact,
60
+ input: variables
61
+ }) ?? void 0
116
62
  });
117
63
  }
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_config.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({
64
+ write(args) {
65
+ this.#cache._internal_unstable.write({
66
+ data: args.data,
67
+ selection: args.fragment.artifact.selection,
149
68
  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;
69
+ variables: (0, import_lib.marshalInputs)({
70
+ config: this.#cache.config,
71
+ artifact: args.fragment.artifact,
72
+ input: args.variables
73
+ }) ?? void 0,
74
+ forceStale: args.forceStale
171
75
  });
172
- return Array.isArray(data) ? finalResult : finalResult[0];
173
76
  }
174
77
  delete() {
175
78
  this.#cache._internal_unstable.delete(this.#id);
176
79
  }
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
- }
80
+ markStale(field, {
81
+ when
82
+ } = {}) {
83
+ this.#cache._internal_unstable.markRecordStale(this.#id, { field, when });
240
84
  }
241
- return newValue;
242
85
  }
243
86
  // Annotate the CommonJS export names for ESM import in node:
244
87
  0 && (module.exports = {
245
- Record,
246
- computeKey,
247
- marshalNestedList,
248
- stringifyObjectWithNoQuotesOnKeys
88
+ Record
249
89
  });