@khanacademy/wonder-blocks-data 0.0.0-PR2089-20231019161345

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 (102) hide show
  1. package/CHANGELOG.md +473 -0
  2. package/dist/components/data.d.ts +52 -0
  3. package/dist/components/gql-router.d.ts +24 -0
  4. package/dist/components/intercept-context.d.ts +10 -0
  5. package/dist/components/intercept-requests.d.ts +42 -0
  6. package/dist/components/track-data.d.ts +11 -0
  7. package/dist/es/index.js +853 -0
  8. package/dist/hooks/use-cached-effect.d.ts +70 -0
  9. package/dist/hooks/use-gql-router-context.d.ts +5 -0
  10. package/dist/hooks/use-gql.d.ts +16 -0
  11. package/dist/hooks/use-hydratable-effect.d.ts +102 -0
  12. package/dist/hooks/use-request-interception.d.ts +14 -0
  13. package/dist/hooks/use-server-effect.d.ts +39 -0
  14. package/dist/hooks/use-shared-cache.d.ts +32 -0
  15. package/dist/index.d.ts +24 -0
  16. package/dist/index.js +904 -0
  17. package/dist/util/data-error.d.ts +45 -0
  18. package/dist/util/get-gql-data-from-response.d.ts +4 -0
  19. package/dist/util/get-gql-request-id.d.ts +5 -0
  20. package/dist/util/gql-error.d.ts +28 -0
  21. package/dist/util/gql-router-context.d.ts +4 -0
  22. package/dist/util/gql-types.d.ts +34 -0
  23. package/dist/util/graphql-document-node-parser.d.ts +18 -0
  24. package/dist/util/graphql-types.d.ts +19 -0
  25. package/dist/util/hydration-cache-api.d.ts +17 -0
  26. package/dist/util/merge-gql-context.d.ts +8 -0
  27. package/dist/util/purge-caches.d.ts +8 -0
  28. package/dist/util/request-api.d.ts +28 -0
  29. package/dist/util/request-fulfillment.d.ts +37 -0
  30. package/dist/util/request-tracking.d.ts +62 -0
  31. package/dist/util/result-from-cache-response.d.ts +5 -0
  32. package/dist/util/scoped-in-memory-cache.d.ts +38 -0
  33. package/dist/util/serializable-in-memory-cache.d.ts +16 -0
  34. package/dist/util/ssr-cache.d.ts +51 -0
  35. package/dist/util/status.d.ts +11 -0
  36. package/dist/util/to-gql-operation.d.ts +32 -0
  37. package/dist/util/types.d.ts +113 -0
  38. package/package.json +29 -0
  39. package/src/components/__tests__/data.test.tsx +832 -0
  40. package/src/components/__tests__/gql-router.test.tsx +63 -0
  41. package/src/components/__tests__/intercept-requests.test.tsx +57 -0
  42. package/src/components/__tests__/track-data.test.tsx +56 -0
  43. package/src/components/data.ts +73 -0
  44. package/src/components/gql-router.tsx +63 -0
  45. package/src/components/intercept-context.ts +19 -0
  46. package/src/components/intercept-requests.tsx +67 -0
  47. package/src/components/track-data.tsx +28 -0
  48. package/src/hooks/__tests__/__snapshots__/use-shared-cache.test.ts.snap +17 -0
  49. package/src/hooks/__tests__/use-cached-effect.test.tsx +789 -0
  50. package/src/hooks/__tests__/use-gql-router-context.test.tsx +132 -0
  51. package/src/hooks/__tests__/use-gql.test.tsx +204 -0
  52. package/src/hooks/__tests__/use-hydratable-effect.test.ts +708 -0
  53. package/src/hooks/__tests__/use-request-interception.test.tsx +254 -0
  54. package/src/hooks/__tests__/use-server-effect.test.ts +293 -0
  55. package/src/hooks/__tests__/use-shared-cache.test.ts +263 -0
  56. package/src/hooks/use-cached-effect.ts +297 -0
  57. package/src/hooks/use-gql-router-context.ts +49 -0
  58. package/src/hooks/use-gql.ts +58 -0
  59. package/src/hooks/use-hydratable-effect.ts +201 -0
  60. package/src/hooks/use-request-interception.ts +53 -0
  61. package/src/hooks/use-server-effect.ts +75 -0
  62. package/src/hooks/use-shared-cache.ts +107 -0
  63. package/src/index.ts +46 -0
  64. package/src/util/__tests__/__snapshots__/scoped-in-memory-cache.test.ts.snap +19 -0
  65. package/src/util/__tests__/__snapshots__/serializable-in-memory-cache.test.ts.snap +19 -0
  66. package/src/util/__tests__/get-gql-data-from-response.test.ts +186 -0
  67. package/src/util/__tests__/get-gql-request-id.test.ts +132 -0
  68. package/src/util/__tests__/graphql-document-node-parser.test.ts +535 -0
  69. package/src/util/__tests__/hydration-cache-api.test.ts +34 -0
  70. package/src/util/__tests__/merge-gql-context.test.ts +73 -0
  71. package/src/util/__tests__/purge-caches.test.ts +28 -0
  72. package/src/util/__tests__/request-api.test.ts +176 -0
  73. package/src/util/__tests__/request-fulfillment.test.ts +146 -0
  74. package/src/util/__tests__/request-tracking.test.tsx +321 -0
  75. package/src/util/__tests__/result-from-cache-response.test.ts +79 -0
  76. package/src/util/__tests__/scoped-in-memory-cache.test.ts +316 -0
  77. package/src/util/__tests__/serializable-in-memory-cache.test.ts +397 -0
  78. package/src/util/__tests__/ssr-cache.test.ts +636 -0
  79. package/src/util/__tests__/to-gql-operation.test.ts +41 -0
  80. package/src/util/data-error.ts +63 -0
  81. package/src/util/get-gql-data-from-response.ts +65 -0
  82. package/src/util/get-gql-request-id.ts +106 -0
  83. package/src/util/gql-error.ts +43 -0
  84. package/src/util/gql-router-context.ts +9 -0
  85. package/src/util/gql-types.ts +64 -0
  86. package/src/util/graphql-document-node-parser.ts +132 -0
  87. package/src/util/graphql-types.ts +28 -0
  88. package/src/util/hydration-cache-api.ts +30 -0
  89. package/src/util/merge-gql-context.ts +35 -0
  90. package/src/util/purge-caches.ts +14 -0
  91. package/src/util/request-api.ts +65 -0
  92. package/src/util/request-fulfillment.ts +121 -0
  93. package/src/util/request-tracking.ts +211 -0
  94. package/src/util/result-from-cache-response.ts +30 -0
  95. package/src/util/scoped-in-memory-cache.ts +121 -0
  96. package/src/util/serializable-in-memory-cache.ts +44 -0
  97. package/src/util/ssr-cache.ts +193 -0
  98. package/src/util/status.ts +35 -0
  99. package/src/util/to-gql-operation.ts +43 -0
  100. package/src/util/types.ts +145 -0
  101. package/tsconfig-build.json +11 -0
  102. package/tsconfig-build.tsbuildinfo +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,473 @@
1
+ # @khanacademy/wonder-blocks-data
2
+
3
+ ## 0.0.0-PR2089-20231019161345
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [ab3f7875]
8
+ - @khanacademy/wonder-blocks-core@0.0.0-PR2089-20231019161345
9
+
10
+ ## 13.0.4
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [4b97b9a2]
15
+ - @khanacademy/wonder-blocks-core@6.2.0
16
+
17
+ ## 13.0.3
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [2871f0a9]
22
+ - @khanacademy/wonder-blocks-core@6.1.1
23
+
24
+ ## 13.0.2
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [efb59c29]
29
+ - Updated dependencies [8bc40ed2]
30
+ - @khanacademy/wonder-blocks-core@6.1.0
31
+
32
+ ## 13.0.1
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [f19da46e]
37
+ - @khanacademy/wonder-blocks-core@6.0.2
38
+
39
+ ## 13.0.0
40
+
41
+ ### Major Changes
42
+
43
+ - 65c02cff: Return new no-data state from useCachedEffect when it is not loading and there is no data to return
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies [1920feb8]
48
+ - @khanacademy/wonder-blocks-core@6.0.1
49
+
50
+ ## 12.0.0
51
+
52
+ ### Major Changes
53
+
54
+ - 674a1e5c: POJOs have been replace with TS enums
55
+
56
+ ### Patch Changes
57
+
58
+ - 674a1e5c: We're no longer building flow types
59
+ - Updated dependencies [674a1e5c]
60
+ - Updated dependencies [674a1e5c]
61
+ - @khanacademy/wonder-blocks-core@6.0.0
62
+
63
+ ## 11.0.16
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [1344436f]
68
+ - @khanacademy/wonder-blocks-core@5.4.0
69
+
70
+ ## 11.0.15
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies [9f3752d4]
75
+ - @khanacademy/wonder-blocks-core@5.3.1
76
+
77
+ ## 11.0.14
78
+
79
+ ### Patch Changes
80
+
81
+ - Updated dependencies [c37b99aa]
82
+ - Updated dependencies [c4cef3e6]
83
+ - @khanacademy/wonder-blocks-core@5.3.0
84
+
85
+ ## 11.0.13
86
+
87
+ ### Patch Changes
88
+
89
+ - Updated dependencies [d4c412b5]
90
+ - @khanacademy/wonder-blocks-core@5.2.3
91
+
92
+ ## 11.0.12
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies [64a188e3]
97
+ - @khanacademy/wonder-blocks-core@5.2.2
98
+
99
+ ## 11.0.11
100
+
101
+ ### Patch Changes
102
+
103
+ - 5a1ea891: Make sure that React contexts are named
104
+ - Updated dependencies [5a1ea891]
105
+ - Updated dependencies [df9a10aa]
106
+ - @khanacademy/wonder-blocks-core@5.2.1
107
+
108
+ ## 11.0.10
109
+
110
+ ### Patch Changes
111
+
112
+ - Updated dependencies [fa70c895]
113
+ - Updated dependencies [19ab0408]
114
+ - Updated dependencies [fa70c895]
115
+ - @khanacademy/wonder-blocks-core@5.2.0
116
+
117
+ ## 11.0.9
118
+
119
+ ### Patch Changes
120
+
121
+ - a6164ed0: Don't use React.FC<> for functional components
122
+ - Updated dependencies [3c400719]
123
+ - Updated dependencies [a6164ed0]
124
+ - @khanacademy/wonder-blocks-core@5.1.0
125
+
126
+ ## 11.0.8
127
+
128
+ ## 11.0.7
129
+
130
+ ## 11.0.6
131
+
132
+ ### Patch Changes
133
+
134
+ - c20f48f3: Don't transpile classes when building bundles
135
+ - Updated dependencies [c20f48f3]
136
+ - @khanacademy/wonder-blocks-core@5.0.4
137
+
138
+ ## 11.0.5
139
+
140
+ ### Patch Changes
141
+
142
+ - 43155769: Fix DocumentNode type definition
143
+
144
+ ## 11.0.4
145
+
146
+ ### Patch Changes
147
+
148
+ - bedcbcf8: Update <Data>'s 'children' prop to allow a ReactNode to be returned
149
+
150
+ ## 11.0.3
151
+
152
+ ### Patch Changes
153
+
154
+ - Updated dependencies [b281e2eb]
155
+ - @khanacademy/wonder-blocks-core@5.0.3
156
+
157
+ ## 11.0.2
158
+
159
+ ### Patch Changes
160
+
161
+ - Updated dependencies [21ce20c7]
162
+ - @khanacademy/wonder-blocks-core@5.0.2
163
+
164
+ ## 11.0.1
165
+
166
+ ### Patch Changes
167
+
168
+ - ccb6fe00: Miscellaneous TS type fixes
169
+ - d4c2b18c: Fix a variety of issues with Flow types generated by flowgen
170
+ - Updated dependencies [ccb6fe00]
171
+ - Updated dependencies [d4c2b18c]
172
+ - @khanacademy/wonder-blocks-core@5.0.1
173
+
174
+ ## 11.0.0
175
+
176
+ ### Major Changes
177
+
178
+ - 1ca4d7e3: Fix minor issue with generate Flow types (this is a major bump b/c I forgot to do one after doing the TS conversion)
179
+
180
+ ### Patch Changes
181
+
182
+ - Updated dependencies [1ca4d7e3]
183
+ - @khanacademy/wonder-blocks-core@5.0.0
184
+
185
+ ## 10.1.3
186
+
187
+ ### Patch Changes
188
+
189
+ - b5ba5568: Ensure that flow lib defs use React.ElementConfig<> isntead of JSX.LibraryManagedAttributes<>
190
+ - Updated dependencies [b5ba5568]
191
+ - @khanacademy/wonder-blocks-core@4.9.1
192
+
193
+ ## 10.1.2
194
+
195
+ ### Patch Changes
196
+
197
+ - Updated dependencies [779b031d]
198
+ - @khanacademy/wonder-blocks-core@4.9.0
199
+
200
+ ## 10.1.1
201
+
202
+ ### Patch Changes
203
+
204
+ - d816af08: Update build and test configs use TypeScript
205
+ - 3891f544: Update babel config to include plugins that Storybook needed
206
+ - 3813715d: Update wonder-stuff dependencies (non-functional changes)
207
+ - 0d28bb1c: Configured TypeScript
208
+ - 3d05f764: Fix HOCs and other type errors
209
+ - c2ec4902: Update eslint configuration, fix lint
210
+ - 2983c05b: Include 'types' field in package.json
211
+ - 77ff6a66: Generate Flow types from TypeScript types
212
+ - ec8d4b7f: Fix miscellaneous TypeScript errors
213
+ - Updated dependencies [d816af08]
214
+ - Updated dependencies [3891f544]
215
+ - Updated dependencies [0d28bb1c]
216
+ - Updated dependencies [873f4a14]
217
+ - Updated dependencies [3d05f764]
218
+ - Updated dependencies [c2ec4902]
219
+ - Updated dependencies [2983c05b]
220
+ - Updated dependencies [77ff6a66]
221
+ - Updated dependencies [ec8d4b7f]
222
+ - @khanacademy/wonder-blocks-core@4.8.0
223
+
224
+ ## 10.1.0
225
+
226
+ ### Minor Changes
227
+
228
+ - 91cb727c: Convert enums to POJOs
229
+
230
+ ### Patch Changes
231
+
232
+ - 91cb727c: Update wonder-stuff dependencies
233
+ - 91cb727c: Remove file extensions from imports
234
+ - Updated dependencies [91cb727c]
235
+ - Updated dependencies [91cb727c]
236
+ - @khanacademy/wonder-blocks-core@4.7.0
237
+
238
+ ## 10.0.5
239
+
240
+ ### Patch Changes
241
+
242
+ - 1a5624d4: Update wonder-stuff dependencies to use newly published packages after migrating wonder-stuff to TypeScript
243
+
244
+ ## 10.0.4
245
+
246
+ ### Patch Changes
247
+
248
+ - Updated dependencies [496119f2]
249
+ - @khanacademy/wonder-blocks-core@4.6.2
250
+
251
+ ## 10.0.3
252
+
253
+ ### Patch Changes
254
+
255
+ - @khanacademy/wonder-blocks-core@4.6.1
256
+
257
+ ## 10.0.2
258
+
259
+ ### Patch Changes
260
+
261
+ - Updated dependencies [b561425a]
262
+ - Updated dependencies [a566e232]
263
+ - Updated dependencies [d2b21a6e]
264
+ - @khanacademy/wonder-blocks-core@4.6.0
265
+
266
+ ## 10.0.1
267
+
268
+ ### Patch Changes
269
+
270
+ - Updated dependencies [175a2dd2]
271
+ - @khanacademy/wonder-blocks-core@4.5.0
272
+
273
+ ## 10.0.0
274
+
275
+ ### Major Changes
276
+
277
+ - 5a3ec7f9: Make sure request ID generation handles objects like Date and Error instances better
278
+
279
+ ## 9.1.2
280
+
281
+ ### Patch Changes
282
+
283
+ - Updated dependencies [6ee20af9]
284
+ - @khanacademy/wonder-blocks-core@4.4.0
285
+
286
+ ## 9.1.1
287
+
288
+ ### Patch Changes
289
+
290
+ - eb59ce34: Update to latest Wonder Stuff Core
291
+
292
+ ## 9.1.0
293
+
294
+ ### Minor Changes
295
+
296
+ - 944c3071: Make sure objects and arrays in variables are sorted and readable in generated request identifiers
297
+
298
+ ## 9.0.0
299
+
300
+ ### Major Changes
301
+
302
+ - 778f8e43: `SharedCache` export added for interacting with the shared in-memory cache. `purgeSharedCache` method has been removed.
303
+ - 778f8e43: Rename `ScopedCache` type to `RawScopedCache`
304
+
305
+ ## 8.0.5
306
+
307
+ ### Patch Changes
308
+
309
+ - 08238b89: Export the `getGqlDataFromResponse` method so we can use it in custom `gqlFetch` scenarios for a consistent experience
310
+
311
+ ## 8.0.4
312
+
313
+ ### Patch Changes
314
+
315
+ - dc2e00f4: Do not fetch if FetchPolicy is CacheBeforeNetwork and there is already a cached value, even if the requestId changes
316
+
317
+ ## 8.0.3
318
+
319
+ ### Patch Changes
320
+
321
+ - 5f4a4297: Make dependency on `flow-enums-runtime` explicit
322
+ - 2b96fd59: Change flow-enums-runtime to be peer dependencies
323
+ - Updated dependencies [5f4a4297]
324
+ - Updated dependencies [2b96fd59]
325
+ - @khanacademy/wonder-blocks-core@4.3.2
326
+
327
+ ## 8.0.2
328
+
329
+ ### Patch Changes
330
+
331
+ - 580141ed: Always initialize SSR-only cache
332
+
333
+ ## 8.0.1
334
+
335
+ ### Patch Changes
336
+
337
+ - e5fa4d9e: Make sure ssr-only cache is initialized when purging caches in test environment
338
+
339
+ ## 8.0.0
340
+
341
+ ### Major Changes
342
+
343
+ - 0720470e: Renamed `initializeCache` to `initializeHydrationCache`, deleted `removeFromCache`, renamed `removeAllFromCache` to `purgeHydrationCache`
344
+ - cf9ed87f: Add `fetchPolicy` to `useCachedEffect` options, add `refetch` to `useCachedEffect` return value (return value is now a tuple of [result, refetch]), add abort API to request fulfillment (not truly aborting though)
345
+ - b882b082: Stop exporting `RequestFulfillment`, update `useCachedEffect` to consider scope with sharing inflight requests
346
+ - 0720470e: Rename `fulfillAllDataRequests` to `fetchTrackedRequests`, rename `hasUnfulfilledRequests` to `hasTrackedRequestsToBeFetched`
347
+ - 0720470e: Renamed `clearSharedCache` to `purgeSharedCache`
348
+
349
+ ### Minor Changes
350
+
351
+ - 0720470e: Add `purgeCaches` export for purging all caches with one call
352
+ - 75c10036: Add `abortInflightRequests` to exports
353
+ - a85f2f3a: Provide `getGqlRequestId` function
354
+
355
+ ### Patch Changes
356
+
357
+ - 1385f468: Removed unnecessary `new` on tracking context creation
358
+
359
+ ## 7.0.1
360
+
361
+ ### Patch Changes
362
+
363
+ - @khanacademy/wonder-blocks-core@4.3.1
364
+
365
+ ## 7.0.0
366
+
367
+ ### Major Changes
368
+
369
+ - 34407c4a: `useServerEffect` now has a `skip` option, preventing the request from getting tracked for server-side fulfillment
370
+
371
+ ## 6.0.1
372
+
373
+ ### Patch Changes
374
+
375
+ - 5ad01891: [FIX] Make sure hydratable effect properly renders when requestId changes
376
+
377
+ ## 6.0.0
378
+
379
+ ### Major Changes
380
+
381
+ - 1f34c4e8: `Result<TData>` is now the main return type, `useGql` supports context modification, and context overrides that are set explicitly to null now mean those values are deleted when merging
382
+ - 885fe62b: [NEW] `useCachedEffect` hook for performing asynchronous work client-side and caching the result. Updated `useHydratableEffect` to use `useCachedEffect`. `useServerEffect` handler is now interceptable with Wonder Blocks Data `InterceptData` component.
383
+ - 5c852025: [NEW] Added the `useHydratableEffect` hook and updated the `Data` component to use it. Breaking change: `Data` props have been renamed and retyped to fit `useHydratableResult` API.
384
+ - c91f3959: New `DataError` type and changes to the `GqlError` type. Also changes what errors are thrown in various code
385
+ - 753220a4: Exported in-flight request tracking mechanism and reworked Data component so that client-side requests don't get morphed to and from a cache-style value
386
+
387
+ ### Minor Changes
388
+
389
+ - 5d614ed4: Changed `Result<TData>` error status so that error field is an error object, not a string
390
+
391
+ ### Patch Changes
392
+
393
+ - Updated dependencies [246a921d]
394
+ - @khanacademy/wonder-blocks-core@4.3.0
395
+
396
+ ## 5.0.1
397
+
398
+ ### Patch Changes
399
+
400
+ - c9922b34: Export resultFromCachedResponse
401
+
402
+ ## 5.0.0
403
+
404
+ ### Major Changes
405
+
406
+ - 5b5f85ac: Replace `InterceptData` with `InterceptRequests` and introduce new `useRequestInterception` hook
407
+
408
+ ## 4.0.0
409
+
410
+ ### Major Changes
411
+
412
+ - febc7309: Rename types and update signatures
413
+ - `ValidData` is now `ValidCacheData`
414
+ - `Cache` type is now `ResponseCache` (old `ResponseCache` can be created with `$ReadOnly<ResponseCache>`)
415
+ - `CacheEntry` type is now `CachedResponse`
416
+ - Signatures that were typed as `$ReadOnly<Cache>` previously are now typed as `ResponseCache` which is more appropriate to how they work
417
+ - bffc345e: Simplified, more versatile API
418
+
419
+ - NEW: `useServerEffect` hook - a way to perform asynchronous tasks on the server and have the value available for hydration
420
+ - UPDATED: `Data` component - New API that does away with the `IRequestHandler` interface. Includes new props to control behavior on hydration and when new requests occur.
421
+ - UPDATED: `InterceptData` component - New API to reflect changes in `Data` component.
422
+
423
+ - REMOVED: `IRequestHandler` API. All associated call signatures have been updated to reflect this.
424
+ - REMOVED: `useData` hook - The `Data` component should be used
425
+
426
+ ### Minor Changes
427
+
428
+ - 7c9dd09b: - New `useSharedData` hook
429
+ - New `ScopedInMemoryCache` export
430
+
431
+ ## 3.2.0
432
+
433
+ ### Minor Changes
434
+
435
+ - 6973afa2: useGql method now merges defaultContext and partial context by ignoring values explicitly set to undefined in the partial context. This ensures that that existing default context values are not overridden unless explicitly given a value other than undefined.
436
+
437
+ ## 3.1.3
438
+
439
+ ### Patch Changes
440
+
441
+ - 9931ae6b: Simplify GQL types
442
+
443
+ ## 3.1.2
444
+
445
+ ### Patch Changes
446
+
447
+ - @khanacademy/wonder-blocks-core@4.2.1
448
+
449
+ ## 3.1.1
450
+
451
+ ### Patch Changes
452
+
453
+ - 4ff59815: Add GraphQL fetch mock support to wonder-blocks-testing
454
+
455
+ ## 3.1.0
456
+
457
+ ### Minor Changes
458
+
459
+ - b68cedfe: Add GqlRouter component
460
+ - c7233a97: Implement useGql hook
461
+
462
+ ## 3.0.1
463
+
464
+ ### Patch Changes
465
+
466
+ - d281dac8: Ensure server-side request fulfillments can be intercepted
467
+
468
+ ## 3.0.0
469
+
470
+ ### Major Changes
471
+
472
+ - b252d9c8: Remove client-side caching
473
+ - b252d9c8: Introduce useData hook
@@ -0,0 +1,52 @@
1
+ import * as React from "react";
2
+ import { WhenClientSide } from "../hooks/use-hydratable-effect";
3
+ import type { Result, ValidCacheData } from "../util/types";
4
+ type Props<
5
+ /**
6
+ * The type of data resolved by the handler's fulfillRequest method.
7
+ */
8
+ TData extends ValidCacheData> = {
9
+ /**
10
+ * A unique identifier for the request.
11
+ *
12
+ * This should not be shared by other uses of this component.
13
+ */
14
+ requestId: string;
15
+ /**
16
+ * This defines how the request is fulfilled.
17
+ *
18
+ * If this is changed without changing the ID, there are cases where the
19
+ * old handler result may be given. This is not a supported mode of
20
+ * operation.
21
+ */
22
+ handler: () => Promise<TData>;
23
+ /**
24
+ * How the hook should behave when rendering client-side for the first time.
25
+ *
26
+ * This controls how the hook hydrates and executes when client-side.
27
+ *
28
+ * Default is `OnClientRender.ExecuteWhenNoSuccessResult`.
29
+ */
30
+ clientBehavior?: typeof WhenClientSide[keyof typeof WhenClientSide];
31
+ /**
32
+ * When true, the children will be rendered with the existing result
33
+ * until the pending load is completed. Otherwise, the children will be
34
+ * given a loading state until the request is fulfilled.
35
+ *
36
+ * Defaults to false.
37
+ */
38
+ retainResultOnChange?: boolean;
39
+ /**
40
+ * A function that will render the content of this component using the
41
+ * loading state and data or error that gets retrieved from cache or loaded
42
+ * via the request if no cached value is available.
43
+ */
44
+ children: (result: Result<TData>) => React.ReactElement | null;
45
+ };
46
+ /**
47
+ * This component is the main component of Wonder Blocks Data. With this, data
48
+ * requirements can be placed in a React application in a manner that will
49
+ * support server-side rendering and efficient caching.
50
+ */
51
+ declare const Data: <TData extends ValidCacheData>({ requestId, handler, children, retainResultOnChange, clientBehavior, }: Props<TData>) => React.ReactElement | null;
52
+ export default Data;
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ import type { GqlContext, GqlFetchFn } from "../util/gql-types";
3
+ type Props<TContext extends GqlContext> = {
4
+ /**
5
+ * The default context to be used by operations when no context is provided.
6
+ */
7
+ defaultContext: TContext;
8
+ /**
9
+ * The function to use when fetching requests.
10
+ */
11
+ fetch: GqlFetchFn<any, any, TContext>;
12
+ /**
13
+ * The children to be rendered inside the router.
14
+ */
15
+ children: React.ReactNode;
16
+ };
17
+ /**
18
+ * Configure GraphQL routing for GraphQL hooks and components.
19
+ *
20
+ * These can be nested. Components and hooks relying on the GraphQL routing
21
+ * will use the configuration from their closest ancestral GqlRouter.
22
+ */
23
+ export declare const GqlRouter: <TContext extends GqlContext>({ defaultContext: thisDefaultContext, fetch: thisFetch, children, }: Props<TContext>) => React.ReactElement;
24
+ export {};
@@ -0,0 +1,10 @@
1
+ import * as React from "react";
2
+ import type { ValidCacheData } from "../util/types";
3
+ type InterceptContextData = ReadonlyArray<(requestId: string) => Promise<ValidCacheData | null | undefined> | null | undefined>;
4
+ /**
5
+ * InterceptContext defines a map from request ID to interception methods.
6
+ *
7
+ * INTERNAL USE ONLY
8
+ */
9
+ declare const InterceptContext: React.Context<InterceptContextData>;
10
+ export default InterceptContext;
@@ -0,0 +1,42 @@
1
+ import * as React from "react";
2
+ import type { ValidCacheData } from "../util/types";
3
+ type Props<TData extends ValidCacheData> = {
4
+ /**
5
+ * Called to intercept and possibly handle the request.
6
+ * If this returns null, the request will be handled by ancestor
7
+ * any ancestor interceptors, and ultimately, the original request
8
+ * handler, otherwise, this interceptor is handling the request.
9
+ *
10
+ * Interceptors are called in ancestor precedence, with the closest
11
+ * interceptor ancestor being called first, and the furthest ancestor
12
+ * being called last.
13
+ *
14
+ * Beware: Interceptors do not care about what data they are intercepting,
15
+ * so make sure to only intercept requests that you recognize from the
16
+ * identifier.
17
+ */
18
+ interceptor: (requestId: string) => Promise<TData> | null | undefined;
19
+ /**
20
+ * The children to render within this component. Any requests by `Data`
21
+ * components that use same ID as this component will be intercepted.
22
+ * If `InterceptRequests` is used within `children`, that interception will
23
+ * be given a chance to intercept first.
24
+ */
25
+ children: React.ReactNode;
26
+ };
27
+ /**
28
+ * This component provides a mechanism to intercept data requests.
29
+ * This is for use in testing.
30
+ *
31
+ * This component is not recommended for use in production code as it
32
+ * can prevent predictable functioning of the Wonder Blocks Data framework.
33
+ * One possible side-effect is that inflight requests from the interceptor could
34
+ * be picked up by `Data` component requests from outside the children of this
35
+ * component.
36
+ *
37
+ * Interceptions within the same component tree are chained such that the
38
+ * interceptor closest to the intercepted request is called first, and the
39
+ * furthest interceptor is called last.
40
+ */
41
+ declare const InterceptRequests: <TData extends ValidCacheData>({ interceptor, children, }: Props<TData>) => React.ReactElement;
42
+ export default InterceptRequests;
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ type TrackDataProps = {
3
+ children: React.ReactNode;
4
+ };
5
+ /**
6
+ * Component to enable data request tracking when server-side rendering.
7
+ */
8
+ export default class TrackData extends React.Component<TrackDataProps> {
9
+ render(): React.ReactNode;
10
+ }
11
+ export {};