houdini 1.0.0-next.2 → 1.0.0-next.20

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 +46 -46
  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 +12 -8
  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 +10 -8
  93. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
  94. package/build/runtime-cjs/client/plugins/fetch.js +9 -8
  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 +4 -4
  102. package/build/runtime-cjs/client/plugins/subscription.d.ts +2 -3
  103. package/build/runtime-cjs/client/plugins/subscription.js +5 -3
  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 +46 -46
  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 +13 -9
  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 +9 -7
  150. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
  151. package/build/runtime-esm/client/plugins/fetch.js +8 -7
  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 +3 -3
  159. package/build/runtime-esm/client/plugins/subscription.d.ts +2 -3
  160. package/build/runtime-esm/client/plugins/subscription.js +4 -2
  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 +46 -46
  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
@@ -11,6 +11,7 @@ export type CacheTypeDef = {
11
11
  type: any;
12
12
  };
13
13
  };
14
+ fragments: [any, any, any][];
14
15
  };
15
16
  };
16
17
  lists: {
@@ -19,11 +20,14 @@ export type CacheTypeDef = {
19
20
  filters: any;
20
21
  };
21
22
  };
23
+ queries: [any, any, any][];
22
24
  };
23
25
  export type ValidTypes<Def extends CacheTypeDef> = keyof Def['types'];
24
26
  export type TypeFields<Def extends CacheTypeDef, Type extends keyof Def['types']> = Def['types'][Type]['fields'];
25
27
  export type TypeFieldNames<Def extends CacheTypeDef, Type extends keyof Def['types']> = Extract<keyof TypeFields<Def, Type>, string>;
26
28
  export type TypeNames<Def extends CacheTypeDef> = Extract<Exclude<ValidTypes<Def>, '__ROOT__'>, string>;
29
+ export type FragmentList<Def extends CacheTypeDef, Type extends ValidTypes<Def>> = Def['types'][Type]['fragments'];
30
+ export type QueryList<Def extends CacheTypeDef> = Def['queries'];
27
31
  export type IDFields<Def extends CacheTypeDef, Type extends keyof Def['types']> = Def['types'][Type]['idFields'];
28
32
  export type ProxyUnion<Def extends CacheTypeDef, U> = U extends null ? null : U extends TypeNames<Def> ? Record<Def, U> : never;
29
33
  export type FieldType<Def extends CacheTypeDef, Type extends keyof Def['types'], Field extends keyof TypeFields<Def, Type>> = TypeFields<Def, Type>[Field]['type'];
@@ -34,3 +38,7 @@ export type ListFilters<Def extends CacheTypeDef, ListName extends ValidLists<De
34
38
  must_not?: Def['lists'][ListName]['filters'];
35
39
  } : never;
36
40
  export type ListType<Def extends CacheTypeDef, Name extends ValidLists<Def>> = ProxyUnion<Def, Def['lists'][Name]['types']>;
41
+ export type FragmentVariables<_List, _Target> = _List extends [infer Head, ...infer Rest] ? Head extends [infer _Key, infer _Value, infer _Input] ? _Key extends _Target ? _Input : FragmentValue<Rest, _Target> : 'Encountered unknown fragment. Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).' : 'Encountered unknown fragment. Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).';
42
+ export type FragmentValue<List, _Target> = List extends [infer Head, ...infer Rest] ? Head extends [infer _Key, infer _Value, infer _Input] ? _Key extends _Target ? _Value : FragmentValue<Rest, _Target> : 'Encountered unknown fragment. Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).' : 'Encountered unknown fragment. Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).';
43
+ export type QueryValue<List, _Target> = List extends [infer Head, ...infer Rest] ? Head extends [infer _Key, infer _Value, infer _Input] ? _Key extends _Target ? _Value : QueryValue<Rest, _Target> : 'Encountered unknown query.Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).' : 'Encountered unknown query.Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).';
44
+ export type QueryInput<List, _Target> = List extends [infer Head, ...infer Rest] ? Head extends [infer _Key, infer _Value, infer _Input] ? _Key extends _Target ? _Input : QueryValue<Rest, _Target> : 'Encountered unknown query.Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).' : 'Encountered unknown query.Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).';
@@ -1,12 +1,13 @@
1
1
  import type { ConfigFile } from '../lib/config';
2
- import type { GraphQLObject, GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
2
+ import type { GraphQLObject, GraphQLValue, NestedList, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
3
3
  import { GarbageCollector } from './gc';
4
4
  import type { ListCollection } from './lists';
5
5
  import { ListManager } from './lists';
6
6
  import { SchemaManager } from './schema';
7
+ import { StaleManager } from './staleManager';
7
8
  import type { Layer, LayerID } from './storage';
8
9
  import { InMemoryStorage } from './storage';
9
- import { type FieldSelection, InMemorySubscriptions } from './subscription';
10
+ import { InMemorySubscriptions, type FieldSelection } from './subscription';
10
11
  export declare class Cache {
11
12
  _internal_unstable: CacheInternal;
12
13
  constructor(config?: ConfigFile);
@@ -18,19 +19,31 @@ export declare class Cache {
18
19
  variables?: {};
19
20
  parent?: string;
20
21
  layer?: LayerID | null;
21
- applyUpdates?: boolean;
22
+ applyUpdates?: string[];
22
23
  notifySubscribers?: SubscriptionSpec[];
23
24
  forceNotify?: boolean;
25
+ forceStale?: boolean;
24
26
  }): SubscriptionSpec[];
25
27
  read(...args: Parameters<CacheInternal['getSelection']>): {
26
28
  data: GraphQLObject | null;
27
29
  partial: boolean;
30
+ stale: boolean;
28
31
  };
29
32
  subscribe(spec: SubscriptionSpec, variables?: {}): void;
30
33
  unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
31
34
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
32
35
  delete(id: string): void;
33
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;
34
47
  }
35
48
  declare class CacheInternal {
36
49
  private _disabled;
@@ -40,17 +53,19 @@ declare class CacheInternal {
40
53
  lists: ListManager;
41
54
  cache: Cache;
42
55
  lifetimes: GarbageCollector;
56
+ staleManager: StaleManager;
43
57
  schema: SchemaManager;
44
- constructor({ storage, subscriptions, lists, cache, lifetimes, schema, }: {
58
+ constructor({ storage, subscriptions, lists, cache, lifetimes, staleManager, schema, }: {
45
59
  storage: InMemoryStorage;
46
60
  subscriptions: InMemorySubscriptions;
47
61
  lists: ListManager;
48
62
  cache: Cache;
49
63
  lifetimes: GarbageCollector;
64
+ staleManager: StaleManager;
50
65
  schema: SchemaManager;
51
66
  });
52
67
  setConfig(config: ConfigFile): void;
53
- writeSelection({ data, selection, variables, parent, applyUpdates, layer, toNotify, forceNotify, }: {
68
+ writeSelection({ data, selection, variables, parent, applyUpdates, layer, toNotify, forceNotify, forceStale, }: {
54
69
  data: {
55
70
  [key: string]: GraphQLValue;
56
71
  };
@@ -62,8 +77,9 @@ declare class CacheInternal {
62
77
  root?: string;
63
78
  layer: Layer;
64
79
  toNotify?: FieldSelection[];
65
- applyUpdates?: boolean;
80
+ applyUpdates?: string[];
66
81
  forceNotify?: boolean;
82
+ forceStale?: boolean;
67
83
  }): FieldSelection[];
68
84
  getSelection({ selection, parent, variables, stepsFromConnection, }: {
69
85
  selection: SubscriptionSelection;
@@ -73,6 +89,7 @@ declare class CacheInternal {
73
89
  }): {
74
90
  data: GraphQLObject | null;
75
91
  partial: boolean;
92
+ stale: boolean;
76
93
  hasData: boolean;
77
94
  };
78
95
  id(type: string, data: {} | null): string | null;
@@ -82,11 +99,12 @@ declare class CacheInternal {
82
99
  hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, }: {
83
100
  fields: SubscriptionSelection;
84
101
  variables?: {};
85
- linkedList: LinkedList;
102
+ linkedList: NestedList;
86
103
  stepsFromConnection: number | null;
87
104
  }): {
88
- data: LinkedList<GraphQLValue>;
105
+ data: NestedList<GraphQLValue>;
89
106
  partial: boolean;
107
+ stale: boolean;
90
108
  hasData: boolean;
91
109
  };
92
110
  extractNestedListIDs({ value, abstract, recordID, key, linkedType, fields, variables, applyUpdates, specs, layer, forceNotify, }: {
@@ -97,16 +115,15 @@ declare class CacheInternal {
97
115
  abstract: boolean;
98
116
  variables: {};
99
117
  specs: FieldSelection[];
100
- applyUpdates: boolean;
118
+ applyUpdates?: string[];
101
119
  fields: SubscriptionSelection;
102
120
  layer: Layer;
103
121
  forceNotify?: boolean;
104
122
  }): {
105
- nestedIDs: LinkedList;
123
+ nestedIDs: NestedList;
106
124
  newIDs: (string | null)[];
107
125
  };
108
126
  collectGarbage(): void;
109
127
  }
110
128
  export declare const rootID = "_ROOT_";
111
- export type LinkedList<_Result = string> = (_Result | null | LinkedList<_Result>)[];
112
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) {
@@ -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);
@@ -171,16 +204,31 @@ class CacheInternal {
171
204
  const displayLayer = layer.isDisplayLayer(displayLayers);
172
205
  if (displayLayer) {
173
206
  this.lifetimes.resetLifetime(parent, key);
207
+ if (forceStale) {
208
+ this.staleManager.markFieldStale(parent, key);
209
+ } else {
210
+ this.staleManager.setFieldTimeToNow(parent, key);
211
+ }
174
212
  }
175
213
  if (!fieldSelection) {
176
214
  let newValue = value;
177
- if (Array.isArray(value) && applyUpdates && update) {
178
- if (update === "append") {
179
- newValue = (previousValue || []).concat(value);
180
- } else if (update === "prepend") {
181
- 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
+ }
182
225
  }
183
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
+ }
184
232
  const valueChanged = !deepEquals(newValue, previousValue);
185
233
  if (displayLayer && (valueChanged || forceNotify)) {
186
234
  toNotify.push(...currentSubscribers);
@@ -190,7 +238,7 @@ class CacheInternal {
190
238
  if (previousValue === null) {
191
239
  continue;
192
240
  }
193
- const previousLinks = flattenList([previousValue]);
241
+ const previousLinks = flatten([previousValue]);
194
242
  for (const link of previousLinks) {
195
243
  this.subscriptions.remove(link, fieldSelection, specs, variables);
196
244
  }
@@ -240,7 +288,7 @@ class CacheInternal {
240
288
  }
241
289
  } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
242
290
  let oldIDs = [...previousValue || []];
243
- const emptyEdges = !update ? [] : oldIDs.map((id) => {
291
+ const emptyEdges = !updates ? [] : oldIDs.map((id) => {
244
292
  if (!id) {
245
293
  return "";
246
294
  }
@@ -268,7 +316,7 @@ class CacheInternal {
268
316
  layer,
269
317
  forceNotify
270
318
  });
271
- if (applyUpdates && update) {
319
+ if (applyUpdates && updates) {
272
320
  if (key === "edges") {
273
321
  const newNodeIDs = [];
274
322
  for (const id of newIDs) {
@@ -296,12 +344,17 @@ class CacheInternal {
296
344
  return true;
297
345
  });
298
346
  }
299
- if (update === "prepend") {
300
- linkedIDs = newIDs.concat(oldIDs);
301
- } else if (update === "append") {
302
- linkedIDs = oldIDs.concat(newIDs);
303
- } else if (update === "replace") {
304
- 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
+ }
305
358
  }
306
359
  } else {
307
360
  linkedIDs = nestedIDs;
@@ -387,12 +440,13 @@ class CacheInternal {
387
440
  stepsFromConnection = null
388
441
  }) {
389
442
  if (parent === null) {
390
- return { data: null, partial: false, hasData: true };
443
+ return { data: null, partial: false, stale: false, hasData: true };
391
444
  }
392
445
  const target = {};
393
446
  let hasData = false;
394
447
  let partial = false;
395
448
  let cascadeNull = false;
449
+ let stale = false;
396
450
  const typename = this.storage.get(parent, "__typename").value;
397
451
  let targetSelection = getFieldsForType(selection, typename);
398
452
  for (const [
@@ -401,6 +455,10 @@ class CacheInternal {
401
455
  ] of Object.entries(targetSelection)) {
402
456
  const key = evaluateKey(keyRaw, variables);
403
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
+ }
404
462
  let nextStep = stepsFromConnection;
405
463
  if (nextStep !== null) {
406
464
  if (nextStep >= 2) {
@@ -440,6 +498,9 @@ class CacheInternal {
440
498
  if (listValue.partial) {
441
499
  partial = true;
442
500
  }
501
+ if (listValue.stale) {
502
+ stale = true;
503
+ }
443
504
  if (listValue.hasData || value.length === 0) {
444
505
  hasData = true;
445
506
  }
@@ -454,6 +515,9 @@ class CacheInternal {
454
515
  if (objectFields.partial) {
455
516
  partial = true;
456
517
  }
518
+ if (objectFields.stale) {
519
+ stale = true;
520
+ }
457
521
  if (objectFields.hasData) {
458
522
  hasData = true;
459
523
  }
@@ -465,6 +529,7 @@ class CacheInternal {
465
529
  return {
466
530
  data: cascadeNull ? null : target,
467
531
  partial: hasData && partial,
532
+ stale: hasData && stale,
468
533
  hasData
469
534
  };
470
535
  }
@@ -492,6 +557,7 @@ class CacheInternal {
492
557
  }) {
493
558
  const result = [];
494
559
  let partialData = false;
560
+ let stale = false;
495
561
  let hasValues = false;
496
562
  for (const entry of linkedList) {
497
563
  if (Array.isArray(entry)) {
@@ -511,7 +577,12 @@ class CacheInternal {
511
577
  result.push(entry);
512
578
  continue;
513
579
  }
514
- const { data, partial, hasData } = this.getSelection({
580
+ const {
581
+ data,
582
+ partial,
583
+ stale: local_stale,
584
+ hasData
585
+ } = this.getSelection({
515
586
  parent: entry,
516
587
  selection: fields,
517
588
  variables,
@@ -521,6 +592,9 @@ class CacheInternal {
521
592
  if (partial) {
522
593
  partialData = true;
523
594
  }
595
+ if (local_stale) {
596
+ stale = true;
597
+ }
524
598
  if (hasData) {
525
599
  hasValues = true;
526
600
  }
@@ -528,6 +602,7 @@ class CacheInternal {
528
602
  return {
529
603
  data: result,
530
604
  partial: partialData,
605
+ stale,
531
606
  hasData: hasValues
532
607
  };
533
608
  }
@@ -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
  }
@@ -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
  }
@@ -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
  }
@@ -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
+ }
@@ -0,0 +1,71 @@
1
+ import { computeKey } from "../lib";
2
+ class StaleManager {
3
+ cache;
4
+ fieldsTime = /* @__PURE__ */ new Map();
5
+ constructor(cache) {
6
+ this.cache = cache;
7
+ }
8
+ #initMapId = (id) => {
9
+ if (!this.fieldsTime.get(id)) {
10
+ this.fieldsTime.set(id, /* @__PURE__ */ new Map());
11
+ }
12
+ };
13
+ getFieldTime(id, field) {
14
+ return this.fieldsTime.get(id)?.get(field);
15
+ }
16
+ setFieldTimeToNow(id, field) {
17
+ this.#initMapId(id);
18
+ this.fieldsTime.get(id)?.set(field, new Date().valueOf());
19
+ }
20
+ markFieldStale(id, field) {
21
+ this.#initMapId(id);
22
+ this.fieldsTime.get(id)?.set(field, null);
23
+ }
24
+ markAllStale() {
25
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
26
+ for (const [field] of fieldMap.entries()) {
27
+ this.markFieldStale(id, field);
28
+ }
29
+ }
30
+ }
31
+ markRecordStale(id) {
32
+ const fieldsTimeOfType = this.fieldsTime.get(id);
33
+ if (fieldsTimeOfType) {
34
+ for (const [field] of fieldsTimeOfType.entries()) {
35
+ this.markFieldStale(id, field);
36
+ }
37
+ }
38
+ }
39
+ markTypeStale(type) {
40
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
41
+ if (id.startsWith(`${type}:`)) {
42
+ for (const [field] of fieldMap.entries()) {
43
+ this.markFieldStale(id, field);
44
+ }
45
+ }
46
+ }
47
+ }
48
+ markTypeFieldStale(type, field, when) {
49
+ const key = computeKey({ field, args: when });
50
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
51
+ if (id.startsWith(`${type}:`)) {
52
+ for (const local_field of fieldMap.keys()) {
53
+ if (local_field === key) {
54
+ this.markFieldStale(id, field);
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ delete(id, field) {
61
+ if (this.fieldsTime.has(id)) {
62
+ this.fieldsTime.get(id)?.delete(field);
63
+ if (this.fieldsTime.get(id)?.size === 0) {
64
+ this.fieldsTime.delete(id);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ export {
70
+ StaleManager
71
+ };