houdini 1.0.0-next.1 → 1.0.0-next.3

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 (224) hide show
  1. package/build/cmd/generate.d.ts +0 -1
  2. package/build/cmd-cjs/index.js +1400 -2836
  3. package/build/cmd-esm/index.js +1400 -2836
  4. package/build/codegen/generators/artifacts/fieldKey.d.ts +1 -1
  5. package/build/codegen/generators/artifacts/index.d.ts +1 -1
  6. package/build/codegen/generators/artifacts/indexFile.d.ts +1 -1
  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 +1 -1
  10. package/build/codegen/generators/artifacts/utils.d.ts +1 -1
  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 +1 -1
  14. package/build/codegen/generators/persistedQueries/index.d.ts +1 -1
  15. package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -0
  16. package/build/codegen/generators/runtime/index.d.ts +1 -1
  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/{imperativeCache.d.ts → imperativeTypeDef.d.ts} +1 -1
  22. package/build/codegen/generators/typescript/index.d.ts +1 -1
  23. package/build/codegen/generators/typescript/inlineType.d.ts +1 -1
  24. package/build/codegen/generators/typescript/typeReference.d.ts +1 -1
  25. package/build/codegen/generators/typescript/types.d.ts +1 -1
  26. package/build/codegen/index.d.ts +1 -1
  27. package/build/codegen/transforms/addID.d.ts +1 -1
  28. package/build/codegen/transforms/composeQueries.d.ts +2 -2
  29. package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
  30. package/build/codegen/transforms/list.d.ts +1 -1
  31. package/build/codegen/transforms/paginate.d.ts +1 -1
  32. package/build/codegen/transforms/schema.d.ts +1 -1
  33. package/build/codegen/transforms/typename.d.ts +1 -1
  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 +1 -1
  39. package/build/codegen/validators/typeCheck.d.ts +1 -1
  40. package/build/codegen-cjs/index.js +1320 -2779
  41. package/build/codegen-esm/index.js +1320 -2779
  42. package/build/lib/config.d.ts +9 -4
  43. package/build/lib/fs.d.ts +1 -1
  44. package/build/lib/graphql.d.ts +1 -1
  45. package/build/lib/imports.d.ts +1 -1
  46. package/build/lib/types.d.ts +3 -3
  47. package/build/lib/walk.d.ts +8 -5
  48. package/build/lib-cjs/index.js +155 -1856
  49. package/build/lib-esm/index.js +155 -1856
  50. package/build/runtime/cache/cache.d.ts +10 -8
  51. package/build/runtime/cache/gc.d.ts +1 -1
  52. package/build/runtime/cache/lists.d.ts +3 -2
  53. package/build/runtime/cache/schema.d.ts +2 -2
  54. package/build/runtime/cache/stuff.d.ts +2 -2
  55. package/build/runtime/cache/subscription.d.ts +19 -11
  56. package/build/runtime/client/documentStore.d.ts +87 -0
  57. package/build/runtime/client/index.d.ts +25 -0
  58. package/build/runtime/client/plugins/cache.d.ts +8 -0
  59. package/build/runtime/client/plugins/fetch.d.ts +37 -0
  60. package/build/runtime/client/plugins/fetchParams.d.ts +9 -0
  61. package/build/runtime/client/plugins/index.d.ts +7 -0
  62. package/build/runtime/client/plugins/injectedPlugins.d.ts +3 -0
  63. package/build/runtime/client/plugins/mutation.d.ts +1 -0
  64. package/build/runtime/client/plugins/query.d.ts +2 -0
  65. package/build/runtime/client/plugins/subscription.d.ts +18 -0
  66. package/build/runtime/client/plugins/throwOnError.d.ts +7 -0
  67. package/build/runtime/client/utils/documentPlugins.d.ts +3 -0
  68. package/build/runtime/client/utils/index.d.ts +1 -0
  69. package/build/runtime/generated.d.ts +1 -0
  70. package/build/runtime/imports/config.d.ts +3 -0
  71. package/build/runtime/index.d.ts +3 -2
  72. package/build/runtime/lib/config.d.ts +26 -25
  73. package/build/runtime/lib/index.d.ts +1 -2
  74. package/build/runtime/lib/scalars.d.ts +6 -5
  75. package/build/runtime/lib/selection.d.ts +1 -1
  76. package/build/runtime/lib/store.d.ts +19 -0
  77. package/build/runtime/lib/types.d.ts +22 -9
  78. package/build/runtime/public/cache.d.ts +20 -7
  79. package/build/runtime/public/list.d.ts +2 -2
  80. package/build/runtime/public/record.d.ts +18 -18
  81. package/build/runtime/public/tests/test.d.ts +44 -1
  82. package/build/runtime/public/types.d.ts +8 -0
  83. package/build/runtime-cjs/cache/cache.d.ts +10 -8
  84. package/build/runtime-cjs/cache/cache.js +5 -11
  85. package/build/runtime-cjs/cache/gc.d.ts +1 -1
  86. package/build/runtime-cjs/cache/lists.d.ts +3 -2
  87. package/build/runtime-cjs/cache/lists.js +5 -2
  88. package/build/runtime-cjs/cache/schema.d.ts +2 -2
  89. package/build/runtime-cjs/cache/stuff.d.ts +2 -2
  90. package/build/runtime-cjs/cache/subscription.d.ts +19 -11
  91. package/build/runtime-cjs/cache/subscription.js +95 -56
  92. package/build/runtime-cjs/client/documentStore.d.ts +87 -0
  93. package/build/runtime-cjs/client/documentStore.js +360 -0
  94. package/build/runtime-cjs/client/index.d.ts +25 -0
  95. package/build/runtime-cjs/client/index.js +87 -0
  96. package/build/runtime-cjs/client/plugins/cache.d.ts +8 -0
  97. package/build/runtime-cjs/client/plugins/cache.js +99 -0
  98. package/build/runtime-cjs/client/plugins/fetch.d.ts +37 -0
  99. package/build/runtime-cjs/{lib/networkUtils.js → client/plugins/fetch.js} +95 -3
  100. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +9 -0
  101. package/build/runtime-cjs/client/plugins/fetchParams.js +40 -0
  102. package/build/runtime-cjs/client/plugins/index.d.ts +7 -0
  103. package/build/runtime-cjs/client/plugins/index.js +24 -0
  104. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +3 -0
  105. package/build/runtime-cjs/{lib/errors.js → client/plugins/injectedPlugins.js} +7 -15
  106. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -0
  107. package/build/runtime-cjs/client/plugins/mutation.js +86 -0
  108. package/build/runtime-cjs/client/plugins/query.d.ts +2 -0
  109. package/build/runtime-cjs/client/plugins/query.js +83 -0
  110. package/build/runtime-cjs/client/plugins/subscription.d.ts +18 -0
  111. package/build/runtime-cjs/client/plugins/subscription.js +98 -0
  112. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +7 -0
  113. package/build/runtime-cjs/client/plugins/throwOnError.js +47 -0
  114. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -0
  115. package/build/runtime-cjs/client/utils/documentPlugins.js +56 -0
  116. package/build/runtime-cjs/client/utils/index.d.ts +1 -0
  117. package/build/runtime-cjs/client/utils/index.js +18 -0
  118. package/build/runtime-cjs/generated.d.ts +1 -0
  119. package/build/runtime-cjs/imports/config.d.ts +3 -0
  120. package/build/runtime-cjs/imports/config.js +26 -0
  121. package/build/runtime-cjs/index.d.ts +3 -2
  122. package/build/runtime-cjs/index.js +1 -0
  123. package/build/runtime-cjs/lib/config.d.ts +26 -25
  124. package/build/runtime-cjs/lib/config.js +5 -4
  125. package/build/runtime-cjs/lib/index.d.ts +1 -2
  126. package/build/runtime-cjs/lib/index.js +1 -2
  127. package/build/runtime-cjs/lib/scalars.d.ts +6 -5
  128. package/build/runtime-cjs/lib/scalars.js +20 -24
  129. package/build/runtime-cjs/lib/selection.d.ts +1 -1
  130. package/build/runtime-cjs/lib/store.d.ts +19 -0
  131. package/build/runtime-cjs/lib/store.js +81 -0
  132. package/build/runtime-cjs/lib/types.d.ts +22 -9
  133. package/build/runtime-cjs/public/cache.d.ts +20 -7
  134. package/build/runtime-cjs/public/cache.js +29 -32
  135. package/build/runtime-cjs/public/list.d.ts +2 -2
  136. package/build/runtime-cjs/public/list.js +6 -28
  137. package/build/runtime-cjs/public/record.d.ts +18 -18
  138. package/build/runtime-cjs/public/record.js +23 -189
  139. package/build/runtime-cjs/public/tests/test.d.ts +44 -1
  140. package/build/runtime-cjs/public/tests/test.js +27 -2
  141. package/build/runtime-cjs/public/types.d.ts +8 -0
  142. package/build/runtime-esm/cache/cache.d.ts +10 -8
  143. package/build/runtime-esm/cache/cache.js +5 -11
  144. package/build/runtime-esm/cache/gc.d.ts +1 -1
  145. package/build/runtime-esm/cache/lists.d.ts +3 -2
  146. package/build/runtime-esm/cache/lists.js +5 -2
  147. package/build/runtime-esm/cache/schema.d.ts +2 -2
  148. package/build/runtime-esm/cache/stuff.d.ts +2 -2
  149. package/build/runtime-esm/cache/subscription.d.ts +19 -11
  150. package/build/runtime-esm/cache/subscription.js +95 -56
  151. package/build/runtime-esm/client/documentStore.d.ts +87 -0
  152. package/build/runtime-esm/client/documentStore.js +336 -0
  153. package/build/runtime-esm/client/index.d.ts +25 -0
  154. package/build/runtime-esm/client/index.js +58 -0
  155. package/build/runtime-esm/client/plugins/cache.d.ts +8 -0
  156. package/build/runtime-esm/client/plugins/cache.js +69 -0
  157. package/build/runtime-esm/client/plugins/fetch.d.ts +37 -0
  158. package/build/runtime-esm/client/plugins/fetch.js +151 -0
  159. package/build/runtime-esm/client/plugins/fetchParams.d.ts +9 -0
  160. package/build/runtime-esm/client/plugins/fetchParams.js +16 -0
  161. package/build/runtime-esm/client/plugins/index.d.ts +7 -0
  162. package/build/runtime-esm/client/plugins/index.js +7 -0
  163. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +3 -0
  164. package/build/runtime-esm/client/plugins/injectedPlugins.js +5 -0
  165. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -0
  166. package/build/runtime-esm/client/plugins/mutation.js +56 -0
  167. package/build/runtime-esm/client/plugins/query.d.ts +2 -0
  168. package/build/runtime-esm/client/plugins/query.js +53 -0
  169. package/build/runtime-esm/client/plugins/subscription.d.ts +18 -0
  170. package/build/runtime-esm/client/plugins/subscription.js +74 -0
  171. package/build/runtime-esm/client/plugins/throwOnError.d.ts +7 -0
  172. package/build/runtime-esm/client/plugins/throwOnError.js +23 -0
  173. package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -0
  174. package/build/runtime-esm/client/utils/documentPlugins.js +32 -0
  175. package/build/runtime-esm/client/utils/index.d.ts +1 -0
  176. package/build/runtime-esm/client/utils/index.js +1 -0
  177. package/build/runtime-esm/generated.d.ts +1 -0
  178. package/build/runtime-esm/imports/config.d.ts +3 -0
  179. package/build/runtime-esm/imports/config.js +4 -0
  180. package/build/runtime-esm/index.d.ts +3 -2
  181. package/build/runtime-esm/index.js +1 -0
  182. package/build/runtime-esm/lib/config.d.ts +26 -25
  183. package/build/runtime-esm/lib/config.js +5 -4
  184. package/build/runtime-esm/lib/index.d.ts +1 -2
  185. package/build/runtime-esm/lib/index.js +1 -2
  186. package/build/runtime-esm/lib/scalars.d.ts +6 -5
  187. package/build/runtime-esm/lib/scalars.js +20 -24
  188. package/build/runtime-esm/lib/selection.d.ts +1 -1
  189. package/build/runtime-esm/lib/store.d.ts +19 -0
  190. package/build/runtime-esm/lib/store.js +57 -0
  191. package/build/runtime-esm/lib/types.d.ts +22 -9
  192. package/build/runtime-esm/public/cache.d.ts +20 -7
  193. package/build/runtime-esm/public/cache.js +28 -30
  194. package/build/runtime-esm/public/list.d.ts +2 -2
  195. package/build/runtime-esm/public/list.js +6 -28
  196. package/build/runtime-esm/public/record.d.ts +18 -18
  197. package/build/runtime-esm/public/record.js +22 -185
  198. package/build/runtime-esm/public/tests/test.d.ts +44 -1
  199. package/build/runtime-esm/public/tests/test.js +26 -1
  200. package/build/runtime-esm/public/types.d.ts +8 -0
  201. package/build/test/index.d.ts +4 -3
  202. package/build/test-cjs/index.js +1334 -2766
  203. package/build/test-esm/index.js +1334 -2766
  204. package/build/vite/ast.d.ts +1 -1
  205. package/build/vite/houdini.d.ts +1 -1
  206. package/build/vite/imports.d.ts +3 -3
  207. package/build/vite/index.d.ts +1 -1
  208. package/build/vite/schema.d.ts +1 -1
  209. package/build/vite-cjs/index.js +1395 -2821
  210. package/build/vite-esm/index.js +1395 -2821
  211. package/package.json +1 -1
  212. package/build/runtime/lib/errors.d.ts +0 -3
  213. package/build/runtime/lib/network.d.ts +0 -79
  214. package/build/runtime/lib/networkUtils.d.ts +0 -8
  215. package/build/runtime-cjs/lib/errors.d.ts +0 -3
  216. package/build/runtime-cjs/lib/network.d.ts +0 -79
  217. package/build/runtime-cjs/lib/network.js +0 -200
  218. package/build/runtime-cjs/lib/networkUtils.d.ts +0 -8
  219. package/build/runtime-esm/lib/errors.d.ts +0 -3
  220. package/build/runtime-esm/lib/errors.js +0 -11
  221. package/build/runtime-esm/lib/network.d.ts +0 -79
  222. package/build/runtime-esm/lib/network.js +0 -170
  223. package/build/runtime-esm/lib/networkUtils.d.ts +0 -8
  224. package/build/runtime-esm/lib/networkUtils.js +0 -60
@@ -1,5 +1,6 @@
1
- import { Cache } from './cache';
2
- import type { ArgType, CacheTypeDef, FieldType, TypeFieldNames, ValidTypes } from './types';
1
+ import type { FragmentArtifact } from '../lib/types';
2
+ import type { Cache } from './cache';
3
+ import type { CacheTypeDef, FragmentList, FragmentValue, FragmentVariables, ValidTypes } from './types';
3
4
  export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<Def>> {
4
5
  #private;
5
6
  type: string;
@@ -10,22 +11,21 @@ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<De
10
11
  idFields: {};
11
12
  id: string;
12
13
  });
13
- set<Field extends TypeFieldNames<Def, Type>>({ field, args, value, }: {
14
- field: Field;
15
- args?: ArgType<Def, Type, Field>;
16
- value: FieldType<Def, Type, Field>;
14
+ read<_Fragment extends {
15
+ artifact: FragmentArtifact;
16
+ }>({ fragment, variables, }: {
17
+ fragment: _Fragment;
18
+ variables?: FragmentVariables<FragmentList<Def, Type>, _Fragment>;
19
+ }): {
20
+ data: FragmentValue<FragmentList<Def, Type>, _Fragment> | null;
21
+ partial: boolean;
22
+ };
23
+ write<_Fragment extends {
24
+ artifact: FragmentArtifact;
25
+ }, _Variable>(args: {
26
+ fragment: _Fragment;
27
+ data: FragmentValue<FragmentList<Def, Type>, _Fragment>;
28
+ variables?: FragmentVariables<FragmentList<Def, Type>, _Fragment>;
17
29
  }): void;
18
- get<Field extends TypeFieldNames<Def, Type>>({ field, args, }: {
19
- field: Field;
20
- args?: ArgType<Def, Type, Field>;
21
- }): FieldType<Def, Type, Field>;
22
30
  delete(): void;
23
31
  }
24
- export declare function computeKey({ field, args }: {
25
- field: string;
26
- args?: {
27
- [key: string]: any;
28
- };
29
- }): string;
30
- export declare const stringifyObjectWithNoQuotesOnKeys: (obj_from_json: {}) => string;
31
- export declare function marshalNestedList(list: any[]): any[];
@@ -1,9 +1,11 @@
1
+ import { type SubscriptionSelection, type FragmentArtifact, type QueryArtifact } from '../../lib';
1
2
  import { Cache } from '../cache';
2
- import { Record } from '../record';
3
+ import type { Record } from '../record';
3
4
  type CacheTypeDef = {
4
5
  types: {
5
6
  __ROOT__: {
6
7
  idFields: {};
8
+ fragments: [];
7
9
  fields: {
8
10
  test: {
9
11
  type: number | null;
@@ -39,6 +41,19 @@ type CacheTypeDef = {
39
41
  idFields: {
40
42
  id: string;
41
43
  };
44
+ fragments: [
45
+ [
46
+ {
47
+ artifact: FragmentArtifact;
48
+ },
49
+ {
50
+ firstName: string;
51
+ },
52
+ {
53
+ pattern: string;
54
+ }
55
+ ]
56
+ ];
42
57
  fields: {
43
58
  firstName: {
44
59
  type: string;
@@ -62,6 +77,7 @@ type CacheTypeDef = {
62
77
  idFields: {
63
78
  id: string;
64
79
  };
80
+ fragments: [];
65
81
  fields: {
66
82
  name: {
67
83
  type: string | null;
@@ -85,6 +101,7 @@ type CacheTypeDef = {
85
101
  idFields: {
86
102
  id: string;
87
103
  };
104
+ fragments: [];
88
105
  fields: {
89
106
  name: {
90
107
  type: string | null;
@@ -97,6 +114,26 @@ type CacheTypeDef = {
97
114
  };
98
115
  };
99
116
  };
117
+ queries: [
118
+ [
119
+ {
120
+ artifact: QueryArtifact;
121
+ },
122
+ {
123
+ viewer: {
124
+ id: string;
125
+ firstName: string;
126
+ __typename: string;
127
+ parent: {
128
+ id: string;
129
+ firstName: string;
130
+ __typename: string;
131
+ };
132
+ };
133
+ },
134
+ any
135
+ ]
136
+ ];
100
137
  lists: {
101
138
  All_Pets: {
102
139
  types: 'User' | 'Cat';
@@ -111,4 +148,10 @@ type CacheTypeDef = {
111
148
  };
112
149
  };
113
150
  export declare const testCache: () => Cache<CacheTypeDef>;
151
+ export declare const testFragment: (selection: SubscriptionSelection) => {
152
+ artifact: FragmentArtifact;
153
+ };
154
+ export declare const testQuery: (selection: SubscriptionSelection) => {
155
+ artifact: QueryArtifact;
156
+ };
114
157
  export {};
@@ -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,10 +1,12 @@
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, 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 type { Layer, LayerID } from './storage';
8
+ import { InMemoryStorage } from './storage';
9
+ import { type FieldSelection, InMemorySubscriptions } from './subscription';
8
10
  export declare class Cache {
9
11
  _internal_unstable: CacheInternal;
10
12
  constructor(config?: ConfigFile);
@@ -59,10 +61,10 @@ declare class CacheInternal {
59
61
  parent?: string;
60
62
  root?: string;
61
63
  layer: Layer;
62
- toNotify?: SubscriptionSpec[];
64
+ toNotify?: FieldSelection[];
63
65
  applyUpdates?: boolean;
64
66
  forceNotify?: boolean;
65
- }): SubscriptionSpec[];
67
+ }): FieldSelection[];
66
68
  getSelection({ selection, parent, variables, stepsFromConnection, }: {
67
69
  selection: SubscriptionSelection;
68
70
  parent?: string;
@@ -94,7 +96,7 @@ declare class CacheInternal {
94
96
  linkedType: string;
95
97
  abstract: boolean;
96
98
  variables: {};
97
- specs: SubscriptionSpec[];
99
+ specs: FieldSelection[];
98
100
  applyUpdates: boolean;
99
101
  fields: SubscriptionSelection;
100
102
  layer: Layer;
@@ -52,7 +52,7 @@ class Cache {
52
52
  ...args
53
53
  }) {
54
54
  const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
55
- const subscribers = this._internal_unstable.writeSelection({ ...args, layer });
55
+ const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
56
56
  const notified = [];
57
57
  for (const spec of subscribers.concat(notifySubscribers)) {
58
58
  if (!notified.includes(spec.set)) {
@@ -190,6 +190,7 @@ class CacheInternal {
190
190
  link: !!fieldSelection
191
191
  });
192
192
  const currentSubscribers = this.subscriptions.get(parent, key);
193
+ const specs = currentSubscribers.map((sub) => sub[0]);
193
194
  const { value: previousValue, displayLayers } = this.storage.get(parent, key);
194
195
  const displayLayer = layer.isDisplayLayer(displayLayers);
195
196
  if (displayLayer) {
@@ -215,7 +216,7 @@ class CacheInternal {
215
216
  }
216
217
  const previousLinks = (0, import_stuff.flattenList)([previousValue]);
217
218
  for (const link of previousLinks) {
218
- this.subscriptions.remove(link, fieldSelection, currentSubscribers, variables);
219
+ this.subscriptions.remove(link, fieldSelection, specs, variables);
219
220
  }
220
221
  layer.writeLink(parent, key, null);
221
222
  toNotify.push(...currentSubscribers);
@@ -239,16 +240,10 @@ class CacheInternal {
239
240
  layer.writeLink(parent, key, linkedID);
240
241
  if (linkedID && displayLayer && (linkChange || forceNotify)) {
241
242
  if (previousValue && typeof previousValue === "string") {
242
- this.subscriptions.remove(
243
- previousValue,
244
- fieldSelection,
245
- currentSubscribers,
246
- variables
247
- );
243
+ this.subscriptions.remove(previousValue, fieldSelection, specs, variables);
248
244
  }
249
245
  this.subscriptions.addMany({
250
246
  parent: linkedID,
251
- selection: fieldSelection,
252
247
  subscribers: currentSubscribers,
253
248
  variables,
254
249
  parentType: linkedType
@@ -343,7 +338,7 @@ class CacheInternal {
343
338
  if (linkedIDs.includes(lostID) || !lostID) {
344
339
  continue;
345
340
  }
346
- this.subscriptions.remove(lostID, fieldSelection, currentSubscribers, variables);
341
+ this.subscriptions.remove(lostID, fieldSelection, specs, variables);
347
342
  }
348
343
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
349
344
  layer.writeLink(parent, key, linkedIDs);
@@ -354,7 +349,6 @@ class CacheInternal {
354
349
  }
355
350
  this.subscriptions.addMany({
356
351
  parent: id,
357
- selection: fieldSelection,
358
352
  subscribers: currentSubscribers,
359
353
  variables,
360
354
  parentType: linkedType
@@ -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;
@@ -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;
@@ -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,
@@ -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;
@@ -1,5 +1,5 @@
1
- import { GraphQLValue } from '../lib/types';
2
- import { LinkedList } from './cache';
1
+ import type { GraphQLValue } from '../lib/types';
2
+ import type { LinkedList } from './cache';
3
3
  export declare function flattenList<T>(source: LinkedList<T>): T[];
4
4
  export declare function evaluateKey(key: string, variables?: {
5
5
  [key: string]: GraphQLValue;
@@ -1,6 +1,9 @@
1
- import type { SubscriptionSpec, SubscriptionSelection, GraphQLObject } from '../lib/types';
2
- import type { GraphQLValue } from '../lib/types';
3
- import { Cache } from './cache';
1
+ import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
2
+ import type { Cache } from './cache';
3
+ export type FieldSelection = [
4
+ SubscriptionSpec,
5
+ Required<SubscriptionSelection>['fields'] | undefined
6
+ ];
4
7
  export declare class InMemorySubscriptions {
5
8
  private cache;
6
9
  constructor(cache: Cache);
@@ -16,22 +19,27 @@ export declare class InMemorySubscriptions {
16
19
  [key: string]: GraphQLValue;
17
20
  };
18
21
  }): void;
19
- addFieldSubscription({ id, key, field, spec, parentType, variables, }: {
22
+ addFieldSubscription({ id, key, selection, }: {
20
23
  id: string;
21
24
  key: string;
22
- field: Required<SubscriptionSelection>['fields'][string];
23
- spec: SubscriptionSpec;
25
+ selection: FieldSelection;
26
+ }): void;
27
+ registerList({ list, id, key, parentType, selection, filters, variables, }: {
28
+ list: Required<Required<SubscriptionSelection>['fields'][string]>['list'];
29
+ selection: SubscriptionSelection;
30
+ id: string;
24
31
  parentType: string;
25
- variables: GraphQLObject;
32
+ key: string;
33
+ filters: Required<SubscriptionSelection>['fields'][string]['filters'];
34
+ variables: Record<string, any>;
26
35
  }): void;
27
- addMany({ parent, selection, variables, subscribers, parentType, }: {
36
+ addMany({ parent, variables, subscribers, parentType, }: {
28
37
  parent: string;
29
- selection: SubscriptionSelection;
30
38
  variables: {};
31
- subscribers: SubscriptionSpec[];
39
+ subscribers: FieldSelection[];
32
40
  parentType: string;
33
41
  }): void;
34
- get(id: string, field: string): SubscriptionSpec[];
42
+ get(id: string, field: string): FieldSelection[];
35
43
  remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
36
44
  private removeSubscribers;
37
45
  removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
@@ -41,16 +41,29 @@ class InMemorySubscriptions {
41
41
  const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
42
42
  let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
43
43
  for (const fieldSelection of Object.values(targetSelection || {})) {
44
- const { keyRaw, selection: innerSelection, type } = fieldSelection;
44
+ const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
45
45
  const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
46
+ let targetSelection2;
47
+ if (innerSelection) {
48
+ const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
49
+ targetSelection2 = (0, import_selection.getFieldsForType)(innerSelection, __typename2);
50
+ }
46
51
  this.addFieldSubscription({
47
52
  id: parent,
48
53
  key,
49
- field: fieldSelection,
50
- spec,
51
- parentType: parentType || spec.rootType,
52
- variables
54
+ selection: [spec, targetSelection2]
53
55
  });
56
+ if (list) {
57
+ this.registerList({
58
+ list,
59
+ filters,
60
+ id: parent,
61
+ key,
62
+ variables,
63
+ selection: innerSelection,
64
+ parentType: parentType || spec.rootType
65
+ });
66
+ }
54
67
  if (innerSelection) {
55
68
  const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
56
69
  parent,
@@ -75,11 +88,9 @@ class InMemorySubscriptions {
75
88
  addFieldSubscription({
76
89
  id,
77
90
  key,
78
- field,
79
- spec,
80
- parentType,
81
- variables
91
+ selection
82
92
  }) {
93
+ const spec = selection[0];
83
94
  if (!this.subscribers[id]) {
84
95
  this.subscribers[id] = {};
85
96
  }
@@ -90,8 +101,8 @@ class InMemorySubscriptions {
90
101
  this.keyVersions[key] = /* @__PURE__ */ new Set();
91
102
  }
92
103
  this.keyVersions[key].add(key);
93
- if (!this.subscribers[id][key].map(({ set }) => set).includes(spec.set)) {
94
- this.subscribers[id][key].push(spec);
104
+ if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
105
+ this.subscribers[id][key].push([spec, selection[1]]);
95
106
  }
96
107
  if (!this.referenceCounts[id]) {
97
108
  this.referenceCounts[id] = {};
@@ -102,61 +113,87 @@ class InMemorySubscriptions {
102
113
  const counts = this.referenceCounts[id][key];
103
114
  counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
104
115
  this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
105
- const { selection, list, filters } = field;
106
- if (selection && list) {
107
- this.cache._internal_unstable.lists.add({
108
- name: list.name,
109
- connection: list.connection,
110
- recordID: id,
111
- recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
112
- listType: list.type,
113
- key,
114
- selection,
115
- filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
116
- return {
117
- ...acc,
118
- [key2]: kind !== "Variable" ? value : variables[value]
119
- };
120
- }, {})
121
- });
122
- }
116
+ const { selection: innerSelection } = selection[1]?.[key] ?? {};
117
+ }
118
+ registerList({
119
+ list,
120
+ id,
121
+ key,
122
+ parentType,
123
+ selection,
124
+ filters,
125
+ variables
126
+ }) {
127
+ this.cache._internal_unstable.lists.add({
128
+ name: list.name,
129
+ connection: list.connection,
130
+ recordID: id,
131
+ recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
132
+ listType: list.type,
133
+ key,
134
+ selection,
135
+ filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
136
+ return {
137
+ ...acc,
138
+ [key2]: kind !== "Variable" ? value : variables[value]
139
+ };
140
+ }, {})
141
+ });
123
142
  }
124
143
  addMany({
125
144
  parent,
126
- selection,
127
145
  variables,
128
146
  subscribers,
129
147
  parentType
130
148
  }) {
131
- let targetSelection = (0, import_selection.getFieldsForType)(selection, parentType);
132
- for (const fieldSelection of Object.values(targetSelection)) {
133
- const { type: linkedType, keyRaw, selection: innerSelection } = fieldSelection;
134
- const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
135
- for (const spec of subscribers) {
149
+ for (const [spec, targetSelection] of subscribers) {
150
+ for (const selection of Object.values(targetSelection ?? {})) {
151
+ const {
152
+ type: linkedType,
153
+ keyRaw,
154
+ selection: innerSelection,
155
+ list,
156
+ filters
157
+ } = selection;
158
+ const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
159
+ const fieldSelection = innerSelection ? (0, import_selection.getFieldsForType)(innerSelection, parentType) : void 0;
136
160
  this.addFieldSubscription({
137
161
  id: parent,
138
162
  key,
139
- field: fieldSelection,
140
- spec,
141
- parentType,
142
- variables
163
+ selection: [spec, fieldSelection]
143
164
  });
144
- }
145
- if (innerSelection) {
146
- const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
147
- const children = !Array.isArray(link) ? [link] : (0, import_stuff.flattenList)(link);
148
- for (const linkedRecord of children) {
149
- if (!linkedRecord) {
150
- continue;
151
- }
152
- this.addMany({
153
- parent: linkedRecord,
154
- selection: innerSelection,
165
+ if (list) {
166
+ this.registerList({
167
+ list,
168
+ filters,
169
+ id: parent,
170
+ key,
155
171
  variables,
156
- subscribers,
157
- parentType: linkedType
172
+ selection: innerSelection,
173
+ parentType: parentType || spec.rootType
158
174
  });
159
175
  }
176
+ const childSelection = selection.selection;
177
+ if (childSelection) {
178
+ const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
179
+ const children = !Array.isArray(link) ? [link] : (0, import_stuff.flattenList)(link);
180
+ for (const linkedRecord of children) {
181
+ if (!linkedRecord) {
182
+ continue;
183
+ }
184
+ const __typename = this.cache._internal_unstable.storage.get(
185
+ linkedRecord,
186
+ "__typename"
187
+ ).value;
188
+ let targetSelection2 = (0, import_selection.getFieldsForType)(childSelection, __typename);
189
+ this.addMany({
190
+ parent: linkedRecord,
191
+ variables,
192
+ subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
193
+ parentType: linkedType
194
+ });
195
+ }
196
+ }
160
197
  }
161
198
  }
162
199
  }
@@ -166,10 +203,12 @@ class InMemorySubscriptions {
166
203
  remove(id, selection, targets, variables, visited = []) {
167
204
  visited.push(id);
168
205
  const linkedIDs = [];
169
- for (const fieldSelection of Object.values(selection.fields || {})) {
206
+ const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
207
+ let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
208
+ for (const fieldSelection of Object.values(targetSelection || {})) {
170
209
  const key = (0, import_stuff.evaluateKey)(fieldSelection.keyRaw, variables);
171
210
  this.removeSubscribers(id, key, targets);
172
- if (!fieldSelection.selection?.fields) {
211
+ if (!fieldSelection.selection) {
173
212
  continue;
174
213
  }
175
214
  const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
@@ -200,14 +239,14 @@ class InMemorySubscriptions {
200
239
  }
201
240
  if (this.subscribers[id]) {
202
241
  this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
203
- ({ set }) => !targets.includes(set)
242
+ ([{ set }]) => !targets.includes(set)
204
243
  );
205
244
  }
206
245
  }
207
246
  removeAllSubscribers(id, targets, visited = []) {
208
247
  visited.push(id);
209
248
  for (const field of Object.keys(this.subscribers[id] || [])) {
210
- const subscribers = targets || this.subscribers[id][field];
249
+ const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
211
250
  this.removeSubscribers(id, field, subscribers);
212
251
  const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
213
252
  if (kind === "scalar") {