houdini 1.0.0-next.1 → 1.0.0-next.11

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 (256) hide show
  1. package/build/cmd/generate.d.ts +0 -1
  2. package/build/cmd-cjs/index.js +3487 -4695
  3. package/build/cmd-esm/index.js +3473 -4681
  4. package/build/codegen/generators/artifacts/fieldKey.d.ts +1 -1
  5. package/build/codegen/generators/artifacts/index.d.ts +2 -2
  6. package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
  7. package/build/codegen/generators/artifacts/inputs.d.ts +2 -2
  8. package/build/codegen/generators/artifacts/operations.d.ts +2 -2
  9. package/build/codegen/generators/artifacts/selection.d.ts +5 -5
  10. package/build/codegen/generators/artifacts/utils.d.ts +1 -2
  11. package/build/codegen/generators/definitions/enums.d.ts +1 -1
  12. package/build/codegen/generators/definitions/index.d.ts +1 -1
  13. package/build/codegen/generators/indexFile/index.d.ts +2 -2
  14. package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
  15. package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -0
  16. package/build/codegen/generators/runtime/index.d.ts +2 -2
  17. package/build/codegen/generators/runtime/injectPlugins.d.ts +7 -0
  18. package/build/codegen/generators/runtime/pluginIndex.d.ts +5 -0
  19. package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +1 -1
  20. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  21. package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
  22. package/build/codegen/generators/typescript/index.d.ts +2 -2
  23. package/build/codegen/generators/typescript/inlineType.d.ts +1 -1
  24. package/build/codegen/generators/typescript/typeReference.d.ts +5 -3
  25. package/build/codegen/generators/typescript/types.d.ts +1 -2
  26. package/build/codegen/index.d.ts +2 -2
  27. package/build/codegen/transforms/addID.d.ts +2 -2
  28. package/build/codegen/transforms/composeQueries.d.ts +5 -5
  29. package/build/codegen/transforms/fragmentVariables.d.ts +4 -3
  30. package/build/codegen/transforms/list.d.ts +2 -2
  31. package/build/codegen/transforms/paginate.d.ts +2 -2
  32. package/build/codegen/transforms/schema.d.ts +2 -2
  33. package/build/codegen/transforms/typename.d.ts +2 -2
  34. package/build/codegen/utils/commonjs.d.ts +2 -0
  35. package/build/codegen/utils/flattenSelections.d.ts +2 -2
  36. package/build/codegen/utils/moduleExport.d.ts +1 -1
  37. package/build/codegen/utils/objectIdentificationSelection.d.ts +1 -1
  38. package/build/codegen/validators/noIDAlias.d.ts +2 -2
  39. package/build/codegen/validators/plugins.d.ts +2 -2
  40. package/build/codegen/validators/typeCheck.d.ts +2 -2
  41. package/build/codegen/validators/uniqueNames.d.ts +2 -2
  42. package/build/codegen-cjs/index.js +3020 -4312
  43. package/build/codegen-esm/index.js +3058 -4350
  44. package/build/lib/config.d.ts +17 -91
  45. package/build/lib/deepMerge.d.ts +1 -0
  46. package/build/lib/fs.d.ts +1 -1
  47. package/build/lib/graphql.d.ts +5 -2
  48. package/build/lib/imports.d.ts +1 -1
  49. package/build/lib/index.d.ts +2 -0
  50. package/build/lib/path.d.ts +1 -1
  51. package/build/lib/pipeline.d.ts +1 -1
  52. package/build/lib/plugin.d.ts +2 -0
  53. package/build/lib/types.d.ts +254 -6
  54. package/build/lib/walk.d.ts +8 -5
  55. package/build/lib-cjs/index.js +885 -2394
  56. package/build/lib-esm/index.js +859 -2370
  57. package/build/runtime/cache/cache.d.ts +36 -17
  58. package/build/runtime/cache/gc.d.ts +1 -1
  59. package/build/runtime/cache/lists.d.ts +3 -2
  60. package/build/runtime/cache/schema.d.ts +2 -2
  61. package/build/runtime/cache/staleManager.d.ts +30 -0
  62. package/build/runtime/cache/storage.d.ts +5 -5
  63. package/build/runtime/cache/stuff.d.ts +1 -3
  64. package/build/runtime/cache/subscription.d.ts +20 -11
  65. package/build/runtime/client/documentStore.d.ts +88 -0
  66. package/build/runtime/client/index.d.ts +27 -0
  67. package/build/runtime/client/plugins/cache.d.ts +8 -0
  68. package/build/runtime/client/plugins/fetch.d.ts +37 -0
  69. package/build/runtime/client/plugins/fetchParams.d.ts +9 -0
  70. package/build/runtime/client/plugins/index.d.ts +7 -0
  71. package/build/runtime/client/plugins/injectedPlugins.d.ts +4 -0
  72. package/build/runtime/client/plugins/mutation.d.ts +1 -0
  73. package/build/runtime/client/plugins/query.d.ts +2 -0
  74. package/build/runtime/client/plugins/subscription.d.ts +17 -0
  75. package/build/runtime/client/plugins/throwOnError.d.ts +7 -0
  76. package/build/runtime/client/utils/documentPlugins.d.ts +3 -0
  77. package/build/runtime/client/utils/index.d.ts +1 -0
  78. package/build/runtime/generated.d.ts +1 -0
  79. package/build/runtime/imports/config.d.ts +3 -0
  80. package/build/runtime/index.d.ts +3 -2
  81. package/build/runtime/lib/config.d.ts +30 -25
  82. package/build/runtime/lib/flatten.d.ts +2 -0
  83. package/build/runtime/lib/index.d.ts +2 -2
  84. package/build/runtime/lib/key.d.ts +6 -0
  85. package/build/runtime/lib/scalars.d.ts +6 -5
  86. package/build/runtime/lib/selection.d.ts +1 -1
  87. package/build/runtime/lib/store.d.ts +19 -0
  88. package/build/runtime/lib/types.d.ts +27 -13
  89. package/build/runtime/public/cache.d.ts +27 -7
  90. package/build/runtime/public/list.d.ts +2 -2
  91. package/build/runtime/public/record.d.ts +27 -18
  92. package/build/runtime/public/tests/test.d.ts +53 -11
  93. package/build/runtime/public/types.d.ts +8 -0
  94. package/build/runtime-cjs/cache/cache.d.ts +36 -17
  95. package/build/runtime-cjs/cache/cache.js +102 -33
  96. package/build/runtime-cjs/cache/gc.d.ts +1 -1
  97. package/build/runtime-cjs/cache/gc.js +9 -0
  98. package/build/runtime-cjs/cache/lists.d.ts +3 -2
  99. package/build/runtime-cjs/cache/lists.js +11 -8
  100. package/build/runtime-cjs/cache/schema.d.ts +2 -2
  101. package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
  102. package/build/runtime-cjs/cache/staleManager.js +95 -0
  103. package/build/runtime-cjs/cache/storage.d.ts +5 -5
  104. package/build/runtime-cjs/cache/storage.js +2 -2
  105. package/build/runtime-cjs/cache/stuff.d.ts +1 -3
  106. package/build/runtime-cjs/cache/stuff.js +2 -19
  107. package/build/runtime-cjs/cache/subscription.d.ts +20 -11
  108. package/build/runtime-cjs/cache/subscription.js +102 -59
  109. package/build/runtime-cjs/client/documentStore.d.ts +88 -0
  110. package/build/runtime-cjs/client/documentStore.js +361 -0
  111. package/build/runtime-cjs/client/index.d.ts +27 -0
  112. package/build/runtime-cjs/client/index.js +113 -0
  113. package/build/runtime-cjs/client/plugins/cache.d.ts +8 -0
  114. package/build/runtime-cjs/client/plugins/cache.js +101 -0
  115. package/build/runtime-cjs/client/plugins/fetch.d.ts +37 -0
  116. package/build/runtime-cjs/{lib/networkUtils.js → client/plugins/fetch.js} +96 -3
  117. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +9 -0
  118. package/build/runtime-cjs/client/plugins/fetchParams.js +45 -0
  119. package/build/runtime-cjs/client/plugins/index.d.ts +7 -0
  120. package/build/runtime-cjs/client/plugins/index.js +24 -0
  121. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +4 -0
  122. package/build/runtime-cjs/{lib/errors.js → client/plugins/injectedPlugins.js} +7 -15
  123. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -0
  124. package/build/runtime-cjs/client/plugins/mutation.js +86 -0
  125. package/build/runtime-cjs/client/plugins/query.d.ts +2 -0
  126. package/build/runtime-cjs/client/plugins/query.js +83 -0
  127. package/build/runtime-cjs/client/plugins/subscription.d.ts +17 -0
  128. package/build/runtime-cjs/client/plugins/subscription.js +100 -0
  129. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +7 -0
  130. package/build/runtime-cjs/client/plugins/throwOnError.js +47 -0
  131. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -0
  132. package/build/runtime-cjs/client/utils/documentPlugins.js +56 -0
  133. package/build/runtime-cjs/client/utils/index.d.ts +1 -0
  134. package/build/runtime-cjs/client/utils/index.js +18 -0
  135. package/build/runtime-cjs/generated.d.ts +1 -0
  136. package/build/runtime-cjs/imports/config.d.ts +3 -0
  137. package/build/runtime-cjs/imports/config.js +26 -0
  138. package/build/runtime-cjs/index.d.ts +3 -2
  139. package/build/runtime-cjs/index.js +1 -0
  140. package/build/runtime-cjs/lib/config.d.ts +30 -25
  141. package/build/runtime-cjs/lib/config.js +5 -4
  142. package/build/runtime-cjs/lib/flatten.d.ts +2 -0
  143. package/build/runtime-cjs/lib/flatten.js +41 -0
  144. package/build/runtime-cjs/lib/index.d.ts +2 -2
  145. package/build/runtime-cjs/lib/index.js +2 -2
  146. package/build/runtime-cjs/lib/key.d.ts +6 -0
  147. package/build/runtime-cjs/lib/key.js +41 -0
  148. package/build/runtime-cjs/lib/scalars.d.ts +6 -5
  149. package/build/runtime-cjs/lib/scalars.js +20 -24
  150. package/build/runtime-cjs/lib/selection.d.ts +1 -1
  151. package/build/runtime-cjs/lib/store.d.ts +19 -0
  152. package/build/runtime-cjs/lib/store.js +81 -0
  153. package/build/runtime-cjs/lib/types.d.ts +27 -13
  154. package/build/runtime-cjs/public/cache.d.ts +27 -7
  155. package/build/runtime-cjs/public/cache.js +32 -32
  156. package/build/runtime-cjs/public/list.d.ts +2 -2
  157. package/build/runtime-cjs/public/list.js +6 -28
  158. package/build/runtime-cjs/public/record.d.ts +27 -18
  159. package/build/runtime-cjs/public/record.js +28 -188
  160. package/build/runtime-cjs/public/tests/test.d.ts +53 -11
  161. package/build/runtime-cjs/public/tests/test.js +27 -2
  162. package/build/runtime-cjs/public/types.d.ts +8 -0
  163. package/build/runtime-esm/cache/cache.d.ts +36 -17
  164. package/build/runtime-esm/cache/cache.js +104 -35
  165. package/build/runtime-esm/cache/gc.d.ts +1 -1
  166. package/build/runtime-esm/cache/gc.js +9 -0
  167. package/build/runtime-esm/cache/lists.d.ts +3 -2
  168. package/build/runtime-esm/cache/lists.js +11 -8
  169. package/build/runtime-esm/cache/schema.d.ts +2 -2
  170. package/build/runtime-esm/cache/staleManager.d.ts +30 -0
  171. package/build/runtime-esm/cache/staleManager.js +71 -0
  172. package/build/runtime-esm/cache/storage.d.ts +5 -5
  173. package/build/runtime-esm/cache/storage.js +2 -2
  174. package/build/runtime-esm/cache/stuff.d.ts +1 -3
  175. package/build/runtime-esm/cache/stuff.js +1 -17
  176. package/build/runtime-esm/cache/subscription.d.ts +20 -11
  177. package/build/runtime-esm/cache/subscription.js +103 -60
  178. package/build/runtime-esm/client/documentStore.d.ts +88 -0
  179. package/build/runtime-esm/client/documentStore.js +337 -0
  180. package/build/runtime-esm/client/index.d.ts +27 -0
  181. package/build/runtime-esm/client/index.js +83 -0
  182. package/build/runtime-esm/client/plugins/cache.d.ts +8 -0
  183. package/build/runtime-esm/client/plugins/cache.js +71 -0
  184. package/build/runtime-esm/client/plugins/fetch.d.ts +37 -0
  185. package/build/runtime-esm/client/plugins/fetch.js +152 -0
  186. package/build/runtime-esm/client/plugins/fetchParams.d.ts +9 -0
  187. package/build/runtime-esm/client/plugins/fetchParams.js +21 -0
  188. package/build/runtime-esm/client/plugins/index.d.ts +7 -0
  189. package/build/runtime-esm/client/plugins/index.js +7 -0
  190. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +4 -0
  191. package/build/runtime-esm/client/plugins/injectedPlugins.js +5 -0
  192. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -0
  193. package/build/runtime-esm/client/plugins/mutation.js +56 -0
  194. package/build/runtime-esm/client/plugins/query.d.ts +2 -0
  195. package/build/runtime-esm/client/plugins/query.js +53 -0
  196. package/build/runtime-esm/client/plugins/subscription.d.ts +17 -0
  197. package/build/runtime-esm/client/plugins/subscription.js +76 -0
  198. package/build/runtime-esm/client/plugins/throwOnError.d.ts +7 -0
  199. package/build/runtime-esm/client/plugins/throwOnError.js +23 -0
  200. package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -0
  201. package/build/runtime-esm/client/utils/documentPlugins.js +32 -0
  202. package/build/runtime-esm/client/utils/index.d.ts +1 -0
  203. package/build/runtime-esm/client/utils/index.js +1 -0
  204. package/build/runtime-esm/generated.d.ts +1 -0
  205. package/build/runtime-esm/imports/config.d.ts +3 -0
  206. package/build/runtime-esm/imports/config.js +4 -0
  207. package/build/runtime-esm/index.d.ts +3 -2
  208. package/build/runtime-esm/index.js +1 -0
  209. package/build/runtime-esm/lib/config.d.ts +30 -25
  210. package/build/runtime-esm/lib/config.js +5 -4
  211. package/build/runtime-esm/lib/flatten.d.ts +2 -0
  212. package/build/runtime-esm/lib/flatten.js +17 -0
  213. package/build/runtime-esm/lib/index.d.ts +2 -2
  214. package/build/runtime-esm/lib/index.js +2 -2
  215. package/build/runtime-esm/lib/key.d.ts +6 -0
  216. package/build/runtime-esm/lib/key.js +17 -0
  217. package/build/runtime-esm/lib/scalars.d.ts +6 -5
  218. package/build/runtime-esm/lib/scalars.js +20 -24
  219. package/build/runtime-esm/lib/selection.d.ts +1 -1
  220. package/build/runtime-esm/lib/store.d.ts +19 -0
  221. package/build/runtime-esm/lib/store.js +57 -0
  222. package/build/runtime-esm/lib/types.d.ts +27 -13
  223. package/build/runtime-esm/public/cache.d.ts +27 -7
  224. package/build/runtime-esm/public/cache.js +31 -30
  225. package/build/runtime-esm/public/list.d.ts +2 -2
  226. package/build/runtime-esm/public/list.js +6 -28
  227. package/build/runtime-esm/public/record.d.ts +27 -18
  228. package/build/runtime-esm/public/record.js +27 -184
  229. package/build/runtime-esm/public/tests/test.d.ts +53 -11
  230. package/build/runtime-esm/public/tests/test.js +26 -1
  231. package/build/runtime-esm/public/types.d.ts +8 -0
  232. package/build/test/index.d.ts +6 -5
  233. package/build/test-cjs/index.js +3051 -4304
  234. package/build/test-esm/index.js +3048 -4301
  235. package/build/vite/ast.d.ts +1 -1
  236. package/build/vite/houdini.d.ts +1 -1
  237. package/build/vite/imports.d.ts +3 -3
  238. package/build/vite/index.d.ts +1 -1
  239. package/build/vite/schema.d.ts +1 -1
  240. package/build/vite-cjs/index.js +3499 -4691
  241. package/build/vite-esm/index.js +3448 -4640
  242. package/package.json +6 -5
  243. package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
  244. package/build/runtime/lib/errors.d.ts +0 -3
  245. package/build/runtime/lib/network.d.ts +0 -79
  246. package/build/runtime/lib/networkUtils.d.ts +0 -8
  247. package/build/runtime-cjs/lib/errors.d.ts +0 -3
  248. package/build/runtime-cjs/lib/network.d.ts +0 -79
  249. package/build/runtime-cjs/lib/network.js +0 -200
  250. package/build/runtime-cjs/lib/networkUtils.d.ts +0 -8
  251. package/build/runtime-esm/lib/errors.d.ts +0 -3
  252. package/build/runtime-esm/lib/errors.js +0 -11
  253. package/build/runtime-esm/lib/network.d.ts +0 -79
  254. package/build/runtime-esm/lib/network.js +0 -170
  255. package/build/runtime-esm/lib/networkUtils.d.ts +0 -8
  256. package/build/runtime-esm/lib/networkUtils.js +0 -60
@@ -1,10 +1,13 @@
1
- import { ConfigFile } from '../lib/config';
2
- import { GraphQLObject, GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
1
+ import type { ConfigFile } from '../lib/config';
2
+ import type { GraphQLObject, GraphQLValue, NestedList, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
3
3
  import { GarbageCollector } from './gc';
4
- import { ListCollection, ListManager } from './lists';
4
+ import type { ListCollection } from './lists';
5
+ import { ListManager } from './lists';
5
6
  import { SchemaManager } from './schema';
6
- import { InMemoryStorage, Layer, LayerID } from './storage';
7
- import { InMemorySubscriptions } from './subscription';
7
+ import { StaleManager } from './staleManager';
8
+ import type { Layer, LayerID } from './storage';
9
+ import { InMemoryStorage } from './storage';
10
+ import { InMemorySubscriptions, type FieldSelection } from './subscription';
8
11
  export declare class Cache {
9
12
  _internal_unstable: CacheInternal;
10
13
  constructor(config?: ConfigFile);
@@ -16,19 +19,31 @@ export declare class Cache {
16
19
  variables?: {};
17
20
  parent?: string;
18
21
  layer?: LayerID | null;
19
- applyUpdates?: boolean;
22
+ applyUpdates?: string[];
20
23
  notifySubscribers?: SubscriptionSpec[];
21
24
  forceNotify?: boolean;
25
+ forceStale?: boolean;
22
26
  }): SubscriptionSpec[];
23
27
  read(...args: Parameters<CacheInternal['getSelection']>): {
24
28
  data: GraphQLObject | null;
25
29
  partial: boolean;
30
+ stale: boolean;
26
31
  };
27
32
  subscribe(spec: SubscriptionSpec, variables?: {}): void;
28
33
  unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
29
34
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
30
35
  delete(id: string): void;
31
36
  setConfig(config: ConfigFile): void;
37
+ markTypeStale(options?: {
38
+ type: string;
39
+ field?: string;
40
+ when?: {};
41
+ }): void;
42
+ markRecordStale(id: string, options: {
43
+ field?: string;
44
+ when?: {};
45
+ }): void;
46
+ getFieldTime(id: string, field: string): number | null | undefined;
32
47
  }
33
48
  declare class CacheInternal {
34
49
  private _disabled;
@@ -38,17 +53,19 @@ declare class CacheInternal {
38
53
  lists: ListManager;
39
54
  cache: Cache;
40
55
  lifetimes: GarbageCollector;
56
+ staleManager: StaleManager;
41
57
  schema: SchemaManager;
42
- constructor({ storage, subscriptions, lists, cache, lifetimes, schema, }: {
58
+ constructor({ storage, subscriptions, lists, cache, lifetimes, staleManager, schema, }: {
43
59
  storage: InMemoryStorage;
44
60
  subscriptions: InMemorySubscriptions;
45
61
  lists: ListManager;
46
62
  cache: Cache;
47
63
  lifetimes: GarbageCollector;
64
+ staleManager: StaleManager;
48
65
  schema: SchemaManager;
49
66
  });
50
67
  setConfig(config: ConfigFile): void;
51
- writeSelection({ data, selection, variables, parent, applyUpdates, layer, toNotify, forceNotify, }: {
68
+ writeSelection({ data, selection, variables, parent, applyUpdates, layer, toNotify, forceNotify, forceStale, }: {
52
69
  data: {
53
70
  [key: string]: GraphQLValue;
54
71
  };
@@ -59,10 +76,11 @@ declare class CacheInternal {
59
76
  parent?: string;
60
77
  root?: string;
61
78
  layer: Layer;
62
- toNotify?: SubscriptionSpec[];
63
- applyUpdates?: boolean;
79
+ toNotify?: FieldSelection[];
80
+ applyUpdates?: string[];
64
81
  forceNotify?: boolean;
65
- }): SubscriptionSpec[];
82
+ forceStale?: boolean;
83
+ }): FieldSelection[];
66
84
  getSelection({ selection, parent, variables, stepsFromConnection, }: {
67
85
  selection: SubscriptionSelection;
68
86
  parent?: string;
@@ -71,6 +89,7 @@ declare class CacheInternal {
71
89
  }): {
72
90
  data: GraphQLObject | null;
73
91
  partial: boolean;
92
+ stale: boolean;
74
93
  hasData: boolean;
75
94
  };
76
95
  id(type: string, data: {} | null): string | null;
@@ -80,11 +99,12 @@ declare class CacheInternal {
80
99
  hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, }: {
81
100
  fields: SubscriptionSelection;
82
101
  variables?: {};
83
- linkedList: LinkedList;
102
+ linkedList: NestedList;
84
103
  stepsFromConnection: number | null;
85
104
  }): {
86
- data: LinkedList<GraphQLValue>;
105
+ data: NestedList<GraphQLValue>;
87
106
  partial: boolean;
107
+ stale: boolean;
88
108
  hasData: boolean;
89
109
  };
90
110
  extractNestedListIDs({ value, abstract, recordID, key, linkedType, fields, variables, applyUpdates, specs, layer, forceNotify, }: {
@@ -94,17 +114,16 @@ declare class CacheInternal {
94
114
  linkedType: string;
95
115
  abstract: boolean;
96
116
  variables: {};
97
- specs: SubscriptionSpec[];
98
- applyUpdates: boolean;
117
+ specs: FieldSelection[];
118
+ applyUpdates?: string[];
99
119
  fields: SubscriptionSelection;
100
120
  layer: Layer;
101
121
  forceNotify?: boolean;
102
122
  }): {
103
- nestedIDs: LinkedList;
123
+ nestedIDs: NestedList;
104
124
  newIDs: (string | null)[];
105
125
  };
106
126
  collectGarbage(): void;
107
127
  }
108
128
  export declare const rootID = "_ROOT_";
109
- export type LinkedList<_Result = string> = (_Result | null | LinkedList<_Result>)[];
110
129
  export {};
@@ -1,11 +1,14 @@
1
- import { defaultConfigValues, computeID, keyFieldsForType } from "../lib/config";
1
+ import { computeKey } from "../lib";
2
+ import { computeID, defaultConfigValues, keyFieldsForType } from "../lib/config";
2
3
  import { deepEquals } from "../lib/deepEquals";
4
+ import { flatten } from "../lib/flatten";
3
5
  import { getFieldsForType } from "../lib/selection";
4
6
  import { GarbageCollector } from "./gc";
5
7
  import { ListManager } from "./lists";
6
8
  import { SchemaManager } from "./schema";
9
+ import { StaleManager } from "./staleManager";
7
10
  import { InMemoryStorage } from "./storage";
8
- import { evaluateKey, flattenList } from "./stuff";
11
+ import { evaluateKey } from "./stuff";
9
12
  import { InMemorySubscriptions } from "./subscription";
10
13
  class Cache {
11
14
  _internal_unstable;
@@ -16,6 +19,7 @@ class Cache {
16
19
  subscriptions: new InMemorySubscriptions(this),
17
20
  lists: new ListManager(this, rootID),
18
21
  lifetimes: new GarbageCollector(this),
22
+ staleManager: new StaleManager(this),
19
23
  schema: new SchemaManager(this)
20
24
  });
21
25
  if (config) {
@@ -28,7 +32,7 @@ class Cache {
28
32
  ...args
29
33
  }) {
30
34
  const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
31
- const subscribers = this._internal_unstable.writeSelection({ ...args, layer });
35
+ const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
32
36
  const notified = [];
33
37
  for (const spec of subscribers.concat(notifySubscribers)) {
34
38
  if (!notified.includes(spec.set)) {
@@ -45,13 +49,14 @@ class Cache {
45
49
  return subscribers;
46
50
  }
47
51
  read(...args) {
48
- const { data, partial, hasData } = this._internal_unstable.getSelection(...args);
52
+ const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
49
53
  if (!hasData) {
50
- return { data: null, partial: false };
54
+ return { data: null, partial: false, stale: false };
51
55
  }
52
56
  return {
53
57
  data,
54
- partial
58
+ partial,
59
+ stale
55
60
  };
56
61
  }
57
62
  subscribe(spec, variables = {}) {
@@ -87,6 +92,30 @@ class Cache {
87
92
  setConfig(config) {
88
93
  this._internal_unstable.setConfig(config);
89
94
  }
95
+ markTypeStale(options) {
96
+ if (!options) {
97
+ this._internal_unstable.staleManager.markAllStale();
98
+ } else if (!options.field) {
99
+ this._internal_unstable.staleManager.markTypeStale(options.type);
100
+ } else {
101
+ this._internal_unstable.staleManager.markTypeFieldStale(
102
+ options.type,
103
+ options.field,
104
+ options.when
105
+ );
106
+ }
107
+ }
108
+ markRecordStale(id, options) {
109
+ if (options.field) {
110
+ const key = computeKey({ field: options.field, args: options.when ?? {} });
111
+ this._internal_unstable.staleManager.markFieldStale(id, key);
112
+ } else {
113
+ this._internal_unstable.staleManager.markRecordStale(id);
114
+ }
115
+ }
116
+ getFieldTime(id, field) {
117
+ return this._internal_unstable.staleManager.getFieldTime(id, field);
118
+ }
90
119
  }
91
120
  class CacheInternal {
92
121
  _disabled = false;
@@ -102,6 +131,7 @@ class CacheInternal {
102
131
  lists;
103
132
  cache;
104
133
  lifetimes;
134
+ staleManager;
105
135
  schema;
106
136
  constructor({
107
137
  storage,
@@ -109,6 +139,7 @@ class CacheInternal {
109
139
  lists,
110
140
  cache,
111
141
  lifetimes,
142
+ staleManager,
112
143
  schema
113
144
  }) {
114
145
  this.storage = storage;
@@ -116,6 +147,7 @@ class CacheInternal {
116
147
  this.lists = lists;
117
148
  this.cache = cache;
118
149
  this.lifetimes = lifetimes;
150
+ this.staleManager = staleManager;
119
151
  this.schema = schema;
120
152
  this._disabled = typeof globalThis.window === "undefined";
121
153
  try {
@@ -133,10 +165,11 @@ class CacheInternal {
133
165
  selection,
134
166
  variables = {},
135
167
  parent = rootID,
136
- applyUpdates = false,
168
+ applyUpdates,
137
169
  layer,
138
170
  toNotify = [],
139
- forceNotify
171
+ forceNotify,
172
+ forceStale
140
173
  }) {
141
174
  if (this._disabled) {
142
175
  return [];
@@ -154,7 +187,7 @@ class CacheInternal {
154
187
  selection: fieldSelection,
155
188
  operations,
156
189
  abstract: isAbstract,
157
- update,
190
+ updates,
158
191
  nullable
159
192
  } = targetSelection[field];
160
193
  const key = evaluateKey(keyRaw, variables);
@@ -166,20 +199,36 @@ class CacheInternal {
166
199
  link: !!fieldSelection
167
200
  });
168
201
  const currentSubscribers = this.subscriptions.get(parent, key);
202
+ const specs = currentSubscribers.map((sub) => sub[0]);
169
203
  const { value: previousValue, displayLayers } = this.storage.get(parent, key);
170
204
  const displayLayer = layer.isDisplayLayer(displayLayers);
171
205
  if (displayLayer) {
172
206
  this.lifetimes.resetLifetime(parent, key);
207
+ if (forceStale) {
208
+ this.staleManager.markFieldStale(parent, key);
209
+ } else {
210
+ this.staleManager.setFieldTimeToNow(parent, key);
211
+ }
173
212
  }
174
213
  if (!fieldSelection) {
175
214
  let newValue = value;
176
- if (Array.isArray(value) && applyUpdates && update) {
177
- if (update === "append") {
178
- newValue = (previousValue || []).concat(value);
179
- } else if (update === "prepend") {
180
- newValue = value.concat(previousValue || []);
215
+ if (updates && applyUpdates && Array.isArray(value)) {
216
+ for (const update of applyUpdates) {
217
+ if (!updates.includes(update)) {
218
+ continue;
219
+ }
220
+ if (update === "append") {
221
+ newValue = (previousValue || []).concat(value);
222
+ } else if (update === "prepend") {
223
+ newValue = value.concat(previousValue || []);
224
+ }
181
225
  }
182
226
  }
227
+ if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
228
+ newValue = previousValue;
229
+ } else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
230
+ newValue = previousValue;
231
+ }
183
232
  const valueChanged = !deepEquals(newValue, previousValue);
184
233
  if (displayLayer && (valueChanged || forceNotify)) {
185
234
  toNotify.push(...currentSubscribers);
@@ -189,9 +238,9 @@ class CacheInternal {
189
238
  if (previousValue === null) {
190
239
  continue;
191
240
  }
192
- const previousLinks = flattenList([previousValue]);
241
+ const previousLinks = flatten([previousValue]);
193
242
  for (const link of previousLinks) {
194
- this.subscriptions.remove(link, fieldSelection, currentSubscribers, variables);
243
+ this.subscriptions.remove(link, fieldSelection, specs, variables);
195
244
  }
196
245
  layer.writeLink(parent, key, null);
197
246
  toNotify.push(...currentSubscribers);
@@ -215,16 +264,10 @@ class CacheInternal {
215
264
  layer.writeLink(parent, key, linkedID);
216
265
  if (linkedID && displayLayer && (linkChange || forceNotify)) {
217
266
  if (previousValue && typeof previousValue === "string") {
218
- this.subscriptions.remove(
219
- previousValue,
220
- fieldSelection,
221
- currentSubscribers,
222
- variables
223
- );
267
+ this.subscriptions.remove(previousValue, fieldSelection, specs, variables);
224
268
  }
225
269
  this.subscriptions.addMany({
226
270
  parent: linkedID,
227
- selection: fieldSelection,
228
271
  subscribers: currentSubscribers,
229
272
  variables,
230
273
  parentType: linkedType
@@ -245,7 +288,7 @@ class CacheInternal {
245
288
  }
246
289
  } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
247
290
  let oldIDs = [...previousValue || []];
248
- const emptyEdges = !update ? [] : oldIDs.map((id) => {
291
+ const emptyEdges = !updates ? [] : oldIDs.map((id) => {
249
292
  if (!id) {
250
293
  return "";
251
294
  }
@@ -273,7 +316,7 @@ class CacheInternal {
273
316
  layer,
274
317
  forceNotify
275
318
  });
276
- if (applyUpdates && update) {
319
+ if (applyUpdates && updates) {
277
320
  if (key === "edges") {
278
321
  const newNodeIDs = [];
279
322
  for (const id of newIDs) {
@@ -301,12 +344,17 @@ class CacheInternal {
301
344
  return true;
302
345
  });
303
346
  }
304
- if (update === "prepend") {
305
- linkedIDs = newIDs.concat(oldIDs);
306
- } else if (update === "append") {
307
- linkedIDs = oldIDs.concat(newIDs);
308
- } else if (update === "replace") {
309
- linkedIDs = newIDs;
347
+ for (const update of applyUpdates) {
348
+ if (update !== "replace" && !updates.includes(update)) {
349
+ continue;
350
+ }
351
+ if (update === "prepend") {
352
+ linkedIDs = newIDs.concat(oldIDs);
353
+ } else if (update === "append") {
354
+ linkedIDs = oldIDs.concat(newIDs);
355
+ } else if (update === "replace") {
356
+ linkedIDs = newIDs;
357
+ }
310
358
  }
311
359
  } else {
312
360
  linkedIDs = nestedIDs;
@@ -319,7 +367,7 @@ class CacheInternal {
319
367
  if (linkedIDs.includes(lostID) || !lostID) {
320
368
  continue;
321
369
  }
322
- this.subscriptions.remove(lostID, fieldSelection, currentSubscribers, variables);
370
+ this.subscriptions.remove(lostID, fieldSelection, specs, variables);
323
371
  }
324
372
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
325
373
  layer.writeLink(parent, key, linkedIDs);
@@ -330,7 +378,6 @@ class CacheInternal {
330
378
  }
331
379
  this.subscriptions.addMany({
332
380
  parent: id,
333
- selection: fieldSelection,
334
381
  subscribers: currentSubscribers,
335
382
  variables,
336
383
  parentType: linkedType
@@ -393,12 +440,13 @@ class CacheInternal {
393
440
  stepsFromConnection = null
394
441
  }) {
395
442
  if (parent === null) {
396
- return { data: null, partial: false, hasData: true };
443
+ return { data: null, partial: false, stale: false, hasData: true };
397
444
  }
398
445
  const target = {};
399
446
  let hasData = false;
400
447
  let partial = false;
401
448
  let cascadeNull = false;
449
+ let stale = false;
402
450
  const typename = this.storage.get(parent, "__typename").value;
403
451
  let targetSelection = getFieldsForType(selection, typename);
404
452
  for (const [
@@ -407,6 +455,10 @@ class CacheInternal {
407
455
  ] of Object.entries(targetSelection)) {
408
456
  const key = evaluateKey(keyRaw, variables);
409
457
  const { value } = this.storage.get(parent, key);
458
+ const dt_field = this.staleManager.getFieldTime(parent, key);
459
+ if (dt_field === null) {
460
+ stale = true;
461
+ }
410
462
  let nextStep = stepsFromConnection;
411
463
  if (nextStep !== null) {
412
464
  if (nextStep >= 2) {
@@ -446,6 +498,9 @@ class CacheInternal {
446
498
  if (listValue.partial) {
447
499
  partial = true;
448
500
  }
501
+ if (listValue.stale) {
502
+ stale = true;
503
+ }
449
504
  if (listValue.hasData || value.length === 0) {
450
505
  hasData = true;
451
506
  }
@@ -460,6 +515,9 @@ class CacheInternal {
460
515
  if (objectFields.partial) {
461
516
  partial = true;
462
517
  }
518
+ if (objectFields.stale) {
519
+ stale = true;
520
+ }
463
521
  if (objectFields.hasData) {
464
522
  hasData = true;
465
523
  }
@@ -471,6 +529,7 @@ class CacheInternal {
471
529
  return {
472
530
  data: cascadeNull ? null : target,
473
531
  partial: hasData && partial,
532
+ stale: hasData && stale,
474
533
  hasData
475
534
  };
476
535
  }
@@ -498,6 +557,7 @@ class CacheInternal {
498
557
  }) {
499
558
  const result = [];
500
559
  let partialData = false;
560
+ let stale = false;
501
561
  let hasValues = false;
502
562
  for (const entry of linkedList) {
503
563
  if (Array.isArray(entry)) {
@@ -517,7 +577,12 @@ class CacheInternal {
517
577
  result.push(entry);
518
578
  continue;
519
579
  }
520
- const { data, partial, hasData } = this.getSelection({
580
+ const {
581
+ data,
582
+ partial,
583
+ stale: local_stale,
584
+ hasData
585
+ } = this.getSelection({
521
586
  parent: entry,
522
587
  selection: fields,
523
588
  variables,
@@ -527,6 +592,9 @@ class CacheInternal {
527
592
  if (partial) {
528
593
  partialData = true;
529
594
  }
595
+ if (local_stale) {
596
+ stale = true;
597
+ }
530
598
  if (hasData) {
531
599
  hasValues = true;
532
600
  }
@@ -534,6 +602,7 @@ class CacheInternal {
534
602
  return {
535
603
  data: result,
536
604
  partial: partialData,
605
+ stale,
537
606
  hasData: hasValues
538
607
  };
539
608
  }
@@ -1,4 +1,4 @@
1
- import { Cache } from './cache';
1
+ import type { Cache } from './cache';
2
2
  export declare class GarbageCollector {
3
3
  cache: Cache;
4
4
  private lifetimes;
@@ -14,6 +14,8 @@ class GarbageCollector {
14
14
  this.lifetimes.get(id).set(field, 0);
15
15
  }
16
16
  tick() {
17
+ const dt_tick = Date.now().valueOf();
18
+ const config_max_time = this.cache._internal_unstable.config.defaultLifetime;
17
19
  for (const [id, fieldMap] of this.lifetimes.entries()) {
18
20
  for (const [field, lifetime] of fieldMap.entries()) {
19
21
  if (this.cache._internal_unstable.subscriptions.get(id, field).length > 0) {
@@ -27,6 +29,13 @@ class GarbageCollector {
27
29
  if ([...fieldMap.keys()].length === 0) {
28
30
  this.lifetimes.delete(id);
29
31
  }
32
+ this.cache._internal_unstable.staleManager.delete(id, field);
33
+ }
34
+ if (config_max_time && config_max_time > 0) {
35
+ const dt_valueOf = this.cache.getFieldTime(id, field);
36
+ if (dt_valueOf && dt_tick - dt_valueOf > config_max_time) {
37
+ this.cache._internal_unstable.staleManager.markFieldStale(id, field);
38
+ }
30
39
  }
31
40
  }
32
41
  }
@@ -1,5 +1,5 @@
1
- import { SubscriptionSelection, ListWhen, SubscriptionSpec } from '../lib/types';
2
- import { Cache } from './cache';
1
+ import type { SubscriptionSelection, ListWhen, SubscriptionSpec } from '../lib/types';
2
+ import type { Cache } from './cache';
3
3
  export declare class ListManager {
4
4
  rootID: string;
5
5
  cache: Cache;
@@ -55,6 +55,7 @@ export declare class List {
55
55
  export declare class ListCollection {
56
56
  lists: List[];
57
57
  constructor(lists: List[]);
58
+ get selection(): SubscriptionSelection;
58
59
  append(...args: Parameters<List['append']>): void;
59
60
  prepend(...args: Parameters<List['prepend']>): void;
60
61
  addToList(...args: Parameters<List['addToList']>): void;
@@ -1,5 +1,5 @@
1
+ import { flatten } from "../lib/flatten";
1
2
  import { rootID } from "./cache";
2
- import { flattenList } from "./stuff";
3
3
  class ListManager {
4
4
  rootID;
5
5
  cache;
@@ -151,7 +151,7 @@ class List {
151
151
  edges: {
152
152
  keyRaw: "edges",
153
153
  type: "ConnectionEdge",
154
- update: where === "first" ? "prepend" : "append",
154
+ updates: ["append", "prepend"],
155
155
  selection: {
156
156
  fields: {
157
157
  node: {
@@ -187,7 +187,7 @@ class List {
187
187
  newEntries: {
188
188
  keyRaw: this.key,
189
189
  type: listType,
190
- update: where === "first" ? "prepend" : "append",
190
+ updates: ["append", "prepend"],
191
191
  selection: {
192
192
  ...selection,
193
193
  fields: {
@@ -210,7 +210,7 @@ class List {
210
210
  data: insertData,
211
211
  variables,
212
212
  parent: this.recordID,
213
- applyUpdates: true
213
+ applyUpdates: [where === "first" ? "prepend" : "append"]
214
214
  });
215
215
  }
216
216
  removeID(id, variables = {}) {
@@ -233,7 +233,7 @@ class List {
233
233
  embeddedConnectionID,
234
234
  "edges"
235
235
  );
236
- for (const edge of flattenList(edges) || []) {
236
+ for (const edge of flatten(edges) || []) {
237
237
  if (!edge) {
238
238
  continue;
239
239
  }
@@ -257,11 +257,11 @@ class List {
257
257
  this.cache._internal_unstable.subscriptions.remove(
258
258
  targetID,
259
259
  this.connection ? this.selection.fields.edges.selection : this.selection,
260
- subscribers,
260
+ subscribers.map((sub) => sub[0]),
261
261
  variables
262
262
  );
263
263
  this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
264
- for (const spec of subscribers) {
264
+ for (const [spec] of subscribers) {
265
265
  spec.set(
266
266
  this.cache._internal_unstable.getSelection({
267
267
  parent: spec.parentID || this.manager.rootID,
@@ -311,7 +311,7 @@ class List {
311
311
  let entries = [];
312
312
  let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
313
313
  if (!this.connection) {
314
- entries = flattenList(value);
314
+ entries = flatten(value);
315
315
  } else {
316
316
  entries = this.cache._internal_unstable.storage.get(value, "edges").value;
317
317
  }
@@ -325,6 +325,9 @@ class ListCollection {
325
325
  constructor(lists) {
326
326
  this.lists = lists;
327
327
  }
328
+ get selection() {
329
+ return this.lists[0].selection;
330
+ }
328
331
  append(...args) {
329
332
  this.lists.forEach((list) => list.append(...args));
330
333
  }
@@ -1,5 +1,5 @@
1
- import { ConfigFile } from '../lib';
2
- import { Cache } from './cache';
1
+ import type { ConfigFile } from '../lib/config';
2
+ import type { Cache } from './cache';
3
3
  export type TypeInfo = {
4
4
  type: string;
5
5
  nullable: boolean;
@@ -0,0 +1,30 @@
1
+ import type { Cache } from './cache';
2
+ export declare class StaleManager {
3
+ #private;
4
+ cache: Cache;
5
+ private fieldsTime;
6
+ constructor(cache: Cache);
7
+ /**
8
+ * get the FieldTime info
9
+ * @param id User:1
10
+ * @param field firstName
11
+ */
12
+ getFieldTime(id: string, field: string): number | undefined | null;
13
+ /**
14
+ * set the date to a field
15
+ * @param id User:1
16
+ * @param field firstName
17
+ */
18
+ setFieldTimeToNow(id: string, field: string): void;
19
+ /**
20
+ * set null to a field (stale)
21
+ * @param id User:1
22
+ * @param field firstName
23
+ */
24
+ markFieldStale(id: string, field: string): void;
25
+ markAllStale(): void;
26
+ markRecordStale(id: string): void;
27
+ markTypeStale(type: string): void;
28
+ markTypeFieldStale(type: string, field: string, when?: {}): void;
29
+ delete(id: string, field: string): void;
30
+ }