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 {};
@@ -22,12 +22,15 @@ __export(cache_exports, {
22
22
  rootID: () => rootID
23
23
  });
24
24
  module.exports = __toCommonJS(cache_exports);
25
+ var import_lib = require("../lib");
25
26
  var import_config = require("../lib/config");
26
27
  var import_deepEquals = require("../lib/deepEquals");
28
+ var import_flatten = require("../lib/flatten");
27
29
  var import_selection = require("../lib/selection");
28
30
  var import_gc = require("./gc");
29
31
  var import_lists = require("./lists");
30
32
  var import_schema = require("./schema");
33
+ var import_staleManager = require("./staleManager");
31
34
  var import_storage = require("./storage");
32
35
  var import_stuff = require("./stuff");
33
36
  var import_subscription = require("./subscription");
@@ -40,6 +43,7 @@ class Cache {
40
43
  subscriptions: new import_subscription.InMemorySubscriptions(this),
41
44
  lists: new import_lists.ListManager(this, rootID),
42
45
  lifetimes: new import_gc.GarbageCollector(this),
46
+ staleManager: new import_staleManager.StaleManager(this),
43
47
  schema: new import_schema.SchemaManager(this)
44
48
  });
45
49
  if (config) {
@@ -52,7 +56,7 @@ class Cache {
52
56
  ...args
53
57
  }) {
54
58
  const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
55
- const subscribers = this._internal_unstable.writeSelection({ ...args, layer });
59
+ const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
56
60
  const notified = [];
57
61
  for (const spec of subscribers.concat(notifySubscribers)) {
58
62
  if (!notified.includes(spec.set)) {
@@ -69,13 +73,14 @@ class Cache {
69
73
  return subscribers;
70
74
  }
71
75
  read(...args) {
72
- const { data, partial, hasData } = this._internal_unstable.getSelection(...args);
76
+ const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
73
77
  if (!hasData) {
74
- return { data: null, partial: false };
78
+ return { data: null, partial: false, stale: false };
75
79
  }
76
80
  return {
77
81
  data,
78
- partial
82
+ partial,
83
+ stale
79
84
  };
80
85
  }
81
86
  subscribe(spec, variables = {}) {
@@ -111,6 +116,30 @@ class Cache {
111
116
  setConfig(config) {
112
117
  this._internal_unstable.setConfig(config);
113
118
  }
119
+ markTypeStale(options) {
120
+ if (!options) {
121
+ this._internal_unstable.staleManager.markAllStale();
122
+ } else if (!options.field) {
123
+ this._internal_unstable.staleManager.markTypeStale(options.type);
124
+ } else {
125
+ this._internal_unstable.staleManager.markTypeFieldStale(
126
+ options.type,
127
+ options.field,
128
+ options.when
129
+ );
130
+ }
131
+ }
132
+ markRecordStale(id, options) {
133
+ if (options.field) {
134
+ const key = (0, import_lib.computeKey)({ field: options.field, args: options.when ?? {} });
135
+ this._internal_unstable.staleManager.markFieldStale(id, key);
136
+ } else {
137
+ this._internal_unstable.staleManager.markRecordStale(id);
138
+ }
139
+ }
140
+ getFieldTime(id, field) {
141
+ return this._internal_unstable.staleManager.getFieldTime(id, field);
142
+ }
114
143
  }
115
144
  class CacheInternal {
116
145
  _disabled = false;
@@ -126,6 +155,7 @@ class CacheInternal {
126
155
  lists;
127
156
  cache;
128
157
  lifetimes;
158
+ staleManager;
129
159
  schema;
130
160
  constructor({
131
161
  storage,
@@ -133,6 +163,7 @@ class CacheInternal {
133
163
  lists,
134
164
  cache,
135
165
  lifetimes,
166
+ staleManager,
136
167
  schema
137
168
  }) {
138
169
  this.storage = storage;
@@ -140,6 +171,7 @@ class CacheInternal {
140
171
  this.lists = lists;
141
172
  this.cache = cache;
142
173
  this.lifetimes = lifetimes;
174
+ this.staleManager = staleManager;
143
175
  this.schema = schema;
144
176
  this._disabled = typeof globalThis.window === "undefined";
145
177
  try {
@@ -157,10 +189,11 @@ class CacheInternal {
157
189
  selection,
158
190
  variables = {},
159
191
  parent = rootID,
160
- applyUpdates = false,
192
+ applyUpdates,
161
193
  layer,
162
194
  toNotify = [],
163
- forceNotify
195
+ forceNotify,
196
+ forceStale
164
197
  }) {
165
198
  if (this._disabled) {
166
199
  return [];
@@ -178,7 +211,7 @@ class CacheInternal {
178
211
  selection: fieldSelection,
179
212
  operations,
180
213
  abstract: isAbstract,
181
- update,
214
+ updates,
182
215
  nullable
183
216
  } = targetSelection[field];
184
217
  const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
@@ -190,20 +223,36 @@ class CacheInternal {
190
223
  link: !!fieldSelection
191
224
  });
192
225
  const currentSubscribers = this.subscriptions.get(parent, key);
226
+ const specs = currentSubscribers.map((sub) => sub[0]);
193
227
  const { value: previousValue, displayLayers } = this.storage.get(parent, key);
194
228
  const displayLayer = layer.isDisplayLayer(displayLayers);
195
229
  if (displayLayer) {
196
230
  this.lifetimes.resetLifetime(parent, key);
231
+ if (forceStale) {
232
+ this.staleManager.markFieldStale(parent, key);
233
+ } else {
234
+ this.staleManager.setFieldTimeToNow(parent, key);
235
+ }
197
236
  }
198
237
  if (!fieldSelection) {
199
238
  let newValue = value;
200
- if (Array.isArray(value) && applyUpdates && update) {
201
- if (update === "append") {
202
- newValue = (previousValue || []).concat(value);
203
- } else if (update === "prepend") {
204
- newValue = value.concat(previousValue || []);
239
+ if (updates && applyUpdates && Array.isArray(value)) {
240
+ for (const update of applyUpdates) {
241
+ if (!updates.includes(update)) {
242
+ continue;
243
+ }
244
+ if (update === "append") {
245
+ newValue = (previousValue || []).concat(value);
246
+ } else if (update === "prepend") {
247
+ newValue = value.concat(previousValue || []);
248
+ }
205
249
  }
206
250
  }
251
+ if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
252
+ newValue = previousValue;
253
+ } else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
254
+ newValue = previousValue;
255
+ }
207
256
  const valueChanged = !(0, import_deepEquals.deepEquals)(newValue, previousValue);
208
257
  if (displayLayer && (valueChanged || forceNotify)) {
209
258
  toNotify.push(...currentSubscribers);
@@ -213,9 +262,9 @@ class CacheInternal {
213
262
  if (previousValue === null) {
214
263
  continue;
215
264
  }
216
- const previousLinks = (0, import_stuff.flattenList)([previousValue]);
265
+ const previousLinks = (0, import_flatten.flatten)([previousValue]);
217
266
  for (const link of previousLinks) {
218
- this.subscriptions.remove(link, fieldSelection, currentSubscribers, variables);
267
+ this.subscriptions.remove(link, fieldSelection, specs, variables);
219
268
  }
220
269
  layer.writeLink(parent, key, null);
221
270
  toNotify.push(...currentSubscribers);
@@ -239,16 +288,10 @@ class CacheInternal {
239
288
  layer.writeLink(parent, key, linkedID);
240
289
  if (linkedID && displayLayer && (linkChange || forceNotify)) {
241
290
  if (previousValue && typeof previousValue === "string") {
242
- this.subscriptions.remove(
243
- previousValue,
244
- fieldSelection,
245
- currentSubscribers,
246
- variables
247
- );
291
+ this.subscriptions.remove(previousValue, fieldSelection, specs, variables);
248
292
  }
249
293
  this.subscriptions.addMany({
250
294
  parent: linkedID,
251
- selection: fieldSelection,
252
295
  subscribers: currentSubscribers,
253
296
  variables,
254
297
  parentType: linkedType
@@ -269,7 +312,7 @@ class CacheInternal {
269
312
  }
270
313
  } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
271
314
  let oldIDs = [...previousValue || []];
272
- const emptyEdges = !update ? [] : oldIDs.map((id) => {
315
+ const emptyEdges = !updates ? [] : oldIDs.map((id) => {
273
316
  if (!id) {
274
317
  return "";
275
318
  }
@@ -297,7 +340,7 @@ class CacheInternal {
297
340
  layer,
298
341
  forceNotify
299
342
  });
300
- if (applyUpdates && update) {
343
+ if (applyUpdates && updates) {
301
344
  if (key === "edges") {
302
345
  const newNodeIDs = [];
303
346
  for (const id of newIDs) {
@@ -325,12 +368,17 @@ class CacheInternal {
325
368
  return true;
326
369
  });
327
370
  }
328
- if (update === "prepend") {
329
- linkedIDs = newIDs.concat(oldIDs);
330
- } else if (update === "append") {
331
- linkedIDs = oldIDs.concat(newIDs);
332
- } else if (update === "replace") {
333
- linkedIDs = newIDs;
371
+ for (const update of applyUpdates) {
372
+ if (update !== "replace" && !updates.includes(update)) {
373
+ continue;
374
+ }
375
+ if (update === "prepend") {
376
+ linkedIDs = newIDs.concat(oldIDs);
377
+ } else if (update === "append") {
378
+ linkedIDs = oldIDs.concat(newIDs);
379
+ } else if (update === "replace") {
380
+ linkedIDs = newIDs;
381
+ }
334
382
  }
335
383
  } else {
336
384
  linkedIDs = nestedIDs;
@@ -343,7 +391,7 @@ class CacheInternal {
343
391
  if (linkedIDs.includes(lostID) || !lostID) {
344
392
  continue;
345
393
  }
346
- this.subscriptions.remove(lostID, fieldSelection, currentSubscribers, variables);
394
+ this.subscriptions.remove(lostID, fieldSelection, specs, variables);
347
395
  }
348
396
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
349
397
  layer.writeLink(parent, key, linkedIDs);
@@ -354,7 +402,6 @@ class CacheInternal {
354
402
  }
355
403
  this.subscriptions.addMany({
356
404
  parent: id,
357
- selection: fieldSelection,
358
405
  subscribers: currentSubscribers,
359
406
  variables,
360
407
  parentType: linkedType
@@ -417,12 +464,13 @@ class CacheInternal {
417
464
  stepsFromConnection = null
418
465
  }) {
419
466
  if (parent === null) {
420
- return { data: null, partial: false, hasData: true };
467
+ return { data: null, partial: false, stale: false, hasData: true };
421
468
  }
422
469
  const target = {};
423
470
  let hasData = false;
424
471
  let partial = false;
425
472
  let cascadeNull = false;
473
+ let stale = false;
426
474
  const typename = this.storage.get(parent, "__typename").value;
427
475
  let targetSelection = (0, import_selection.getFieldsForType)(selection, typename);
428
476
  for (const [
@@ -431,6 +479,10 @@ class CacheInternal {
431
479
  ] of Object.entries(targetSelection)) {
432
480
  const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
433
481
  const { value } = this.storage.get(parent, key);
482
+ const dt_field = this.staleManager.getFieldTime(parent, key);
483
+ if (dt_field === null) {
484
+ stale = true;
485
+ }
434
486
  let nextStep = stepsFromConnection;
435
487
  if (nextStep !== null) {
436
488
  if (nextStep >= 2) {
@@ -470,6 +522,9 @@ class CacheInternal {
470
522
  if (listValue.partial) {
471
523
  partial = true;
472
524
  }
525
+ if (listValue.stale) {
526
+ stale = true;
527
+ }
473
528
  if (listValue.hasData || value.length === 0) {
474
529
  hasData = true;
475
530
  }
@@ -484,6 +539,9 @@ class CacheInternal {
484
539
  if (objectFields.partial) {
485
540
  partial = true;
486
541
  }
542
+ if (objectFields.stale) {
543
+ stale = true;
544
+ }
487
545
  if (objectFields.hasData) {
488
546
  hasData = true;
489
547
  }
@@ -495,6 +553,7 @@ class CacheInternal {
495
553
  return {
496
554
  data: cascadeNull ? null : target,
497
555
  partial: hasData && partial,
556
+ stale: hasData && stale,
498
557
  hasData
499
558
  };
500
559
  }
@@ -522,6 +581,7 @@ class CacheInternal {
522
581
  }) {
523
582
  const result = [];
524
583
  let partialData = false;
584
+ let stale = false;
525
585
  let hasValues = false;
526
586
  for (const entry of linkedList) {
527
587
  if (Array.isArray(entry)) {
@@ -541,7 +601,12 @@ class CacheInternal {
541
601
  result.push(entry);
542
602
  continue;
543
603
  }
544
- const { data, partial, hasData } = this.getSelection({
604
+ const {
605
+ data,
606
+ partial,
607
+ stale: local_stale,
608
+ hasData
609
+ } = this.getSelection({
545
610
  parent: entry,
546
611
  selection: fields,
547
612
  variables,
@@ -551,6 +616,9 @@ class CacheInternal {
551
616
  if (partial) {
552
617
  partialData = true;
553
618
  }
619
+ if (local_stale) {
620
+ stale = true;
621
+ }
554
622
  if (hasData) {
555
623
  hasValues = true;
556
624
  }
@@ -558,6 +626,7 @@ class CacheInternal {
558
626
  return {
559
627
  data: result,
560
628
  partial: partialData,
629
+ stale,
561
630
  hasData: hasValues
562
631
  };
563
632
  }
@@ -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;
@@ -37,6 +37,8 @@ class GarbageCollector {
37
37
  this.lifetimes.get(id).set(field, 0);
38
38
  }
39
39
  tick() {
40
+ const dt_tick = Date.now().valueOf();
41
+ const config_max_time = this.cache._internal_unstable.config.defaultLifetime;
40
42
  for (const [id, fieldMap] of this.lifetimes.entries()) {
41
43
  for (const [field, lifetime] of fieldMap.entries()) {
42
44
  if (this.cache._internal_unstable.subscriptions.get(id, field).length > 0) {
@@ -50,6 +52,13 @@ class GarbageCollector {
50
52
  if ([...fieldMap.keys()].length === 0) {
51
53
  this.lifetimes.delete(id);
52
54
  }
55
+ this.cache._internal_unstable.staleManager.delete(id, field);
56
+ }
57
+ if (config_max_time && config_max_time > 0) {
58
+ const dt_valueOf = this.cache.getFieldTime(id, field);
59
+ if (dt_valueOf && dt_tick - dt_valueOf > config_max_time) {
60
+ this.cache._internal_unstable.staleManager.markFieldStale(id, field);
61
+ }
53
62
  }
54
63
  }
55
64
  }
@@ -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;
@@ -23,8 +23,8 @@ __export(lists_exports, {
23
23
  ListManager: () => ListManager
24
24
  });
25
25
  module.exports = __toCommonJS(lists_exports);
26
+ var import_flatten = require("../lib/flatten");
26
27
  var import_cache = require("./cache");
27
- var import_stuff = require("./stuff");
28
28
  class ListManager {
29
29
  rootID;
30
30
  cache;
@@ -176,7 +176,7 @@ class List {
176
176
  edges: {
177
177
  keyRaw: "edges",
178
178
  type: "ConnectionEdge",
179
- update: where === "first" ? "prepend" : "append",
179
+ updates: ["append", "prepend"],
180
180
  selection: {
181
181
  fields: {
182
182
  node: {
@@ -212,7 +212,7 @@ class List {
212
212
  newEntries: {
213
213
  keyRaw: this.key,
214
214
  type: listType,
215
- update: where === "first" ? "prepend" : "append",
215
+ updates: ["append", "prepend"],
216
216
  selection: {
217
217
  ...selection,
218
218
  fields: {
@@ -235,7 +235,7 @@ class List {
235
235
  data: insertData,
236
236
  variables,
237
237
  parent: this.recordID,
238
- applyUpdates: true
238
+ applyUpdates: [where === "first" ? "prepend" : "append"]
239
239
  });
240
240
  }
241
241
  removeID(id, variables = {}) {
@@ -258,7 +258,7 @@ class List {
258
258
  embeddedConnectionID,
259
259
  "edges"
260
260
  );
261
- for (const edge of (0, import_stuff.flattenList)(edges) || []) {
261
+ for (const edge of (0, import_flatten.flatten)(edges) || []) {
262
262
  if (!edge) {
263
263
  continue;
264
264
  }
@@ -282,11 +282,11 @@ class List {
282
282
  this.cache._internal_unstable.subscriptions.remove(
283
283
  targetID,
284
284
  this.connection ? this.selection.fields.edges.selection : this.selection,
285
- subscribers,
285
+ subscribers.map((sub) => sub[0]),
286
286
  variables
287
287
  );
288
288
  this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
289
- for (const spec of subscribers) {
289
+ for (const [spec] of subscribers) {
290
290
  spec.set(
291
291
  this.cache._internal_unstable.getSelection({
292
292
  parent: spec.parentID || this.manager.rootID,
@@ -336,7 +336,7 @@ class List {
336
336
  let entries = [];
337
337
  let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
338
338
  if (!this.connection) {
339
- entries = (0, import_stuff.flattenList)(value);
339
+ entries = (0, import_flatten.flatten)(value);
340
340
  } else {
341
341
  entries = this.cache._internal_unstable.storage.get(value, "edges").value;
342
342
  }
@@ -350,6 +350,9 @@ class ListCollection {
350
350
  constructor(lists) {
351
351
  this.lists = lists;
352
352
  }
353
+ get selection() {
354
+ return this.lists[0].selection;
355
+ }
353
356
  append(...args) {
354
357
  this.lists.forEach((list) => list.append(...args));
355
358
  }
@@ -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
+ }