@warp-drive/core 5.6.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +70 -0
  4. package/addon-main.cjs +5 -0
  5. package/cjs-dist/addon-shim.cjs +1 -0
  6. package/cjs-dist/cjs-set-config.cjs +1 -0
  7. package/declarations/build-config/babel-macros.d.ts +2 -0
  8. package/declarations/build-config/babel-macros.d.ts.map +1 -0
  9. package/declarations/build-config/canary-features.d.ts +2 -0
  10. package/declarations/build-config/canary-features.d.ts.map +1 -0
  11. package/declarations/build-config/debugging.d.ts +2 -0
  12. package/declarations/build-config/debugging.d.ts.map +1 -0
  13. package/declarations/build-config/deprecations.d.ts +2 -0
  14. package/declarations/build-config/deprecations.d.ts.map +1 -0
  15. package/declarations/build-config/env.d.ts +2 -0
  16. package/declarations/build-config/env.d.ts.map +1 -0
  17. package/declarations/build-config/macros.d.ts +2 -0
  18. package/declarations/build-config/macros.d.ts.map +1 -0
  19. package/declarations/build-config.d.ts +2 -0
  20. package/declarations/build-config.d.ts.map +1 -0
  21. package/declarations/configure.d.ts +8 -0
  22. package/declarations/configure.d.ts.map +1 -0
  23. package/declarations/graph/-private/-diff.d.ts +33 -0
  24. package/declarations/graph/-private/-diff.d.ts.map +1 -0
  25. package/declarations/graph/-private/-edge-definition.d.ts +149 -0
  26. package/declarations/graph/-private/-edge-definition.d.ts.map +1 -0
  27. package/declarations/graph/-private/-state.d.ts +10 -0
  28. package/declarations/graph/-private/-state.d.ts.map +1 -0
  29. package/declarations/graph/-private/-utils.d.ts +26 -0
  30. package/declarations/graph/-private/-utils.d.ts.map +1 -0
  31. package/declarations/graph/-private/coerce-id.d.ts +5 -0
  32. package/declarations/graph/-private/coerce-id.d.ts.map +1 -0
  33. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +7 -0
  34. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  35. package/declarations/graph/-private/edges/collection.d.ts +40 -0
  36. package/declarations/graph/-private/edges/collection.d.ts.map +1 -0
  37. package/declarations/graph/-private/edges/implicit.d.ts +14 -0
  38. package/declarations/graph/-private/edges/implicit.d.ts.map +1 -0
  39. package/declarations/graph/-private/edges/resource.d.ts +25 -0
  40. package/declarations/graph/-private/edges/resource.d.ts.map +1 -0
  41. package/declarations/graph/-private/graph.d.ts +55 -0
  42. package/declarations/graph/-private/graph.d.ts.map +1 -0
  43. package/declarations/graph/-private/normalize-link.d.ts +3 -0
  44. package/declarations/graph/-private/normalize-link.d.ts.map +1 -0
  45. package/declarations/graph/-private/operations/add-to-related-records.d.ts +5 -0
  46. package/declarations/graph/-private/operations/add-to-related-records.d.ts.map +1 -0
  47. package/declarations/graph/-private/operations/merge-identifier.d.ts +4 -0
  48. package/declarations/graph/-private/operations/merge-identifier.d.ts.map +1 -0
  49. package/declarations/graph/-private/operations/remove-from-related-records.d.ts +5 -0
  50. package/declarations/graph/-private/operations/remove-from-related-records.d.ts.map +1 -0
  51. package/declarations/graph/-private/operations/replace-related-record.d.ts +4 -0
  52. package/declarations/graph/-private/operations/replace-related-record.d.ts.map +1 -0
  53. package/declarations/graph/-private/operations/replace-related-records.d.ts +8 -0
  54. package/declarations/graph/-private/operations/replace-related-records.d.ts.map +1 -0
  55. package/declarations/graph/-private/operations/update-relationship.d.ts +11 -0
  56. package/declarations/graph/-private/operations/update-relationship.d.ts.map +1 -0
  57. package/declarations/graph/-private.d.ts +14 -0
  58. package/declarations/graph/-private.d.ts.map +1 -0
  59. package/declarations/index.d.ts +15 -0
  60. package/declarations/index.d.ts.map +1 -0
  61. package/declarations/reactive/-private/document.d.ts +147 -0
  62. package/declarations/reactive/-private/document.d.ts.map +1 -0
  63. package/declarations/reactive/-private/fields/compute.d.ts +40 -0
  64. package/declarations/reactive/-private/fields/compute.d.ts.map +1 -0
  65. package/declarations/reactive/-private/fields/managed-array.d.ts +23 -0
  66. package/declarations/reactive/-private/fields/managed-array.d.ts.map +1 -0
  67. package/declarations/reactive/-private/fields/managed-object.d.ts +21 -0
  68. package/declarations/reactive/-private/fields/managed-object.d.ts.map +1 -0
  69. package/declarations/reactive/-private/fields/many-array-manager.d.ts +20 -0
  70. package/declarations/reactive/-private/fields/many-array-manager.d.ts.map +1 -0
  71. package/declarations/reactive/-private/hooks.d.ts +6 -0
  72. package/declarations/reactive/-private/hooks.d.ts.map +1 -0
  73. package/declarations/reactive/-private/record.d.ts +61 -0
  74. package/declarations/reactive/-private/record.d.ts.map +1 -0
  75. package/declarations/reactive/-private/schema.d.ts +180 -0
  76. package/declarations/reactive/-private/schema.d.ts.map +1 -0
  77. package/declarations/reactive/-private/symbols.d.ts +11 -0
  78. package/declarations/reactive/-private/symbols.d.ts.map +1 -0
  79. package/declarations/reactive/-private.d.ts +2 -0
  80. package/declarations/reactive/-private.d.ts.map +1 -0
  81. package/declarations/reactive.d.ts +5 -0
  82. package/declarations/reactive.d.ts.map +1 -0
  83. package/declarations/request/-private/context.d.ts +42 -0
  84. package/declarations/request/-private/context.d.ts.map +1 -0
  85. package/declarations/request/-private/debug.d.ts +5 -0
  86. package/declarations/request/-private/debug.d.ts.map +1 -0
  87. package/declarations/request/-private/fetch.d.ts +40 -0
  88. package/declarations/request/-private/fetch.d.ts.map +1 -0
  89. package/declarations/request/-private/future.d.ts +8 -0
  90. package/declarations/request/-private/future.d.ts.map +1 -0
  91. package/declarations/request/-private/manager.d.ts +160 -0
  92. package/declarations/request/-private/manager.d.ts.map +1 -0
  93. package/declarations/request/-private/promise-cache.d.ts +20 -0
  94. package/declarations/request/-private/promise-cache.d.ts.map +1 -0
  95. package/declarations/request/-private/types.d.ts +236 -0
  96. package/declarations/request/-private/types.d.ts.map +1 -0
  97. package/declarations/request/-private/utils.d.ts +16 -0
  98. package/declarations/request/-private/utils.d.ts.map +1 -0
  99. package/declarations/request.d.ts +6 -0
  100. package/declarations/request.d.ts.map +1 -0
  101. package/declarations/store/-private/cache-handler/handler.d.ts +57 -0
  102. package/declarations/store/-private/cache-handler/handler.d.ts.map +1 -0
  103. package/declarations/store/-private/cache-handler/types.d.ts +99 -0
  104. package/declarations/store/-private/cache-handler/types.d.ts.map +1 -0
  105. package/declarations/store/-private/cache-handler/utils.d.ts +32 -0
  106. package/declarations/store/-private/cache-handler/utils.d.ts.map +1 -0
  107. package/declarations/store/-private/caches/cache-utils.d.ts +9 -0
  108. package/declarations/store/-private/caches/cache-utils.d.ts.map +1 -0
  109. package/declarations/store/-private/caches/identifier-cache.d.ts +316 -0
  110. package/declarations/store/-private/caches/identifier-cache.d.ts.map +1 -0
  111. package/declarations/store/-private/caches/instance-cache.d.ts +65 -0
  112. package/declarations/store/-private/caches/instance-cache.d.ts.map +1 -0
  113. package/declarations/store/-private/caches/resource-utils.d.ts +10 -0
  114. package/declarations/store/-private/caches/resource-utils.d.ts.map +1 -0
  115. package/declarations/store/-private/debug/utils.d.ts +7 -0
  116. package/declarations/store/-private/debug/utils.d.ts.map +1 -0
  117. package/declarations/store/-private/default-cache-policy.d.ts +383 -0
  118. package/declarations/store/-private/default-cache-policy.d.ts.map +1 -0
  119. package/declarations/store/-private/legacy-model-support/record-reference.d.ts +164 -0
  120. package/declarations/store/-private/legacy-model-support/record-reference.d.ts.map +1 -0
  121. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +17 -0
  122. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts.map +1 -0
  123. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +26 -0
  124. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts.map +1 -0
  125. package/declarations/store/-private/managers/cache-manager.d.ts +428 -0
  126. package/declarations/store/-private/managers/cache-manager.d.ts.map +1 -0
  127. package/declarations/store/-private/managers/notification-manager.d.ts +93 -0
  128. package/declarations/store/-private/managers/notification-manager.d.ts.map +1 -0
  129. package/declarations/store/-private/managers/record-array-manager.d.ts +98 -0
  130. package/declarations/store/-private/managers/record-array-manager.d.ts.map +1 -0
  131. package/declarations/store/-private/network/request-cache.d.ts +104 -0
  132. package/declarations/store/-private/network/request-cache.d.ts.map +1 -0
  133. package/declarations/store/-private/new-core-tmp/promise-state.d.ts +255 -0
  134. package/declarations/store/-private/new-core-tmp/promise-state.d.ts.map +1 -0
  135. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +93 -0
  136. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts.map +1 -0
  137. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +170 -0
  138. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts.map +1 -0
  139. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +30 -0
  140. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts.map +1 -0
  141. package/declarations/store/-private/new-core-tmp/request-state.d.ts +255 -0
  142. package/declarations/store/-private/new-core-tmp/request-state.d.ts.map +1 -0
  143. package/declarations/store/-private/record-arrays/identifier-array.d.ts +141 -0
  144. package/declarations/store/-private/record-arrays/identifier-array.d.ts.map +1 -0
  145. package/declarations/store/-private/record-arrays/many-array.d.ts +199 -0
  146. package/declarations/store/-private/record-arrays/many-array.d.ts.map +1 -0
  147. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +116 -0
  148. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts.map +1 -0
  149. package/declarations/store/-private/store-service.d.ts +1597 -0
  150. package/declarations/store/-private/store-service.d.ts.map +1 -0
  151. package/declarations/store/-private/store-service.type-test.d.ts +2 -0
  152. package/declarations/store/-private/store-service.type-test.d.ts.map +1 -0
  153. package/declarations/store/-private/utils/coerce-id.d.ts +5 -0
  154. package/declarations/store/-private/utils/coerce-id.d.ts.map +1 -0
  155. package/declarations/store/-private/utils/construct-resource.d.ts +7 -0
  156. package/declarations/store/-private/utils/construct-resource.d.ts.map +1 -0
  157. package/declarations/store/-private/utils/is-non-empty-string.d.ts +2 -0
  158. package/declarations/store/-private/utils/is-non-empty-string.d.ts.map +1 -0
  159. package/declarations/store/-private/utils/normalize-model-name.d.ts +2 -0
  160. package/declarations/store/-private/utils/normalize-model-name.d.ts.map +1 -0
  161. package/declarations/store/-private/utils/uuid-polyfill.d.ts +2 -0
  162. package/declarations/store/-private/utils/uuid-polyfill.d.ts.map +1 -0
  163. package/declarations/store/-private.d.ts +27 -0
  164. package/declarations/store/-private.d.ts.map +1 -0
  165. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +100 -0
  166. package/declarations/store/-types/q/cache-capabilities-manager.d.ts.map +1 -0
  167. package/declarations/store/-types/q/ds-model.d.ts +22 -0
  168. package/declarations/store/-types/q/ds-model.d.ts.map +1 -0
  169. package/declarations/store/-types/q/identifier.d.ts +21 -0
  170. package/declarations/store/-types/q/identifier.d.ts.map +1 -0
  171. package/declarations/store/-types/q/promise-proxies.d.ts +2 -0
  172. package/declarations/store/-types/q/promise-proxies.d.ts.map +1 -0
  173. package/declarations/store/-types/q/record-data-json-api.d.ts +31 -0
  174. package/declarations/store/-types/q/record-data-json-api.d.ts.map +1 -0
  175. package/declarations/store/-types/q/record-instance.d.ts +24 -0
  176. package/declarations/store/-types/q/record-instance.d.ts.map +1 -0
  177. package/declarations/store/-types/q/schema-service.d.ts +331 -0
  178. package/declarations/store/-types/q/schema-service.d.ts.map +1 -0
  179. package/declarations/store/-types/q/store.d.ts +35 -0
  180. package/declarations/store/-types/q/store.d.ts.map +1 -0
  181. package/declarations/store.d.ts +2 -0
  182. package/declarations/store.d.ts.map +1 -0
  183. package/declarations/types/-private.d.ts +14 -0
  184. package/declarations/types/-private.d.ts.map +1 -0
  185. package/declarations/types/cache/aliases.d.ts +2 -0
  186. package/declarations/types/cache/aliases.d.ts.map +1 -0
  187. package/declarations/types/cache/change.d.ts +7 -0
  188. package/declarations/types/cache/change.d.ts.map +1 -0
  189. package/declarations/types/cache/mutations.d.ts +39 -0
  190. package/declarations/types/cache/mutations.d.ts.map +1 -0
  191. package/declarations/types/cache/operations.d.ts +72 -0
  192. package/declarations/types/cache/operations.d.ts.map +1 -0
  193. package/declarations/types/cache/relationship.d.ts +14 -0
  194. package/declarations/types/cache/relationship.d.ts.map +1 -0
  195. package/declarations/types/cache.d.ts +492 -0
  196. package/declarations/types/cache.d.ts.map +1 -0
  197. package/declarations/types/graph.d.ts +48 -0
  198. package/declarations/types/graph.d.ts.map +1 -0
  199. package/declarations/types/identifier.d.ts +111 -0
  200. package/declarations/types/identifier.d.ts.map +1 -0
  201. package/declarations/types/json/raw.d.ts +7 -0
  202. package/declarations/types/json/raw.d.ts.map +1 -0
  203. package/declarations/types/params.d.ts +10 -0
  204. package/declarations/types/params.d.ts.map +1 -0
  205. package/declarations/types/record.d.ts +96 -0
  206. package/declarations/types/record.d.ts.map +1 -0
  207. package/declarations/types/record.type-test.d.ts +2 -0
  208. package/declarations/types/record.type-test.d.ts.map +1 -0
  209. package/declarations/types/request.d.ts +308 -0
  210. package/declarations/types/request.d.ts.map +1 -0
  211. package/declarations/types/request.type-test.d.ts +2 -0
  212. package/declarations/types/request.type-test.d.ts.map +1 -0
  213. package/declarations/types/runtime.d.ts +15 -0
  214. package/declarations/types/runtime.d.ts.map +1 -0
  215. package/declarations/types/schema/concepts.d.ts +17 -0
  216. package/declarations/types/schema/concepts.d.ts.map +1 -0
  217. package/declarations/types/schema/fields.d.ts +1674 -0
  218. package/declarations/types/schema/fields.d.ts.map +1 -0
  219. package/declarations/types/schema/fields.type-test.d.ts +2 -0
  220. package/declarations/types/schema/fields.type-test.d.ts.map +1 -0
  221. package/declarations/types/spec/document.d.ts +31 -0
  222. package/declarations/types/spec/document.d.ts.map +1 -0
  223. package/declarations/types/spec/error.d.ts +19 -0
  224. package/declarations/types/spec/error.d.ts.map +1 -0
  225. package/declarations/types/spec/json-api-raw.d.ts +142 -0
  226. package/declarations/types/spec/json-api-raw.d.ts.map +1 -0
  227. package/declarations/types/symbols.d.ts +79 -0
  228. package/declarations/types/symbols.d.ts.map +1 -0
  229. package/declarations/types/utils.d.ts +5 -0
  230. package/declarations/types/utils.d.ts.map +1 -0
  231. package/declarations/types.d.ts +12 -0
  232. package/declarations/types.d.ts.map +1 -0
  233. package/declarations/utils/string.d.ts +45 -0
  234. package/declarations/utils/string.d.ts.map +1 -0
  235. package/dist/build-config/babel-macros.js +1 -0
  236. package/dist/build-config/babel-macros.js.map +1 -0
  237. package/dist/build-config/canary-features.js +1 -0
  238. package/dist/build-config/canary-features.js.map +1 -0
  239. package/dist/build-config/debugging.js +1 -0
  240. package/dist/build-config/debugging.js.map +1 -0
  241. package/dist/build-config/deprecations.js +1 -0
  242. package/dist/build-config/deprecations.js.map +1 -0
  243. package/dist/build-config/env.js +1 -0
  244. package/dist/build-config/env.js.map +1 -0
  245. package/dist/build-config/macros.js +1 -0
  246. package/dist/build-config/macros.js.map +1 -0
  247. package/dist/build-config.js +1 -0
  248. package/dist/build-config.js.map +1 -0
  249. package/dist/configure-Bz49BEZQ.js +145 -0
  250. package/dist/configure-Bz49BEZQ.js.map +1 -0
  251. package/dist/configure.js +1 -0
  252. package/dist/configure.js.map +1 -0
  253. package/dist/context-DE5sFezZ.js +636 -0
  254. package/dist/context-DE5sFezZ.js.map +1 -0
  255. package/dist/graph/-private.js +3364 -0
  256. package/dist/graph/-private.js.map +1 -0
  257. package/dist/handler-DYUefHNU.js +339 -0
  258. package/dist/handler-DYUefHNU.js.map +1 -0
  259. package/dist/index.js +382 -0
  260. package/dist/index.js.map +1 -0
  261. package/dist/reactive/-private.js +1 -0
  262. package/dist/reactive/-private.js.map +1 -0
  263. package/dist/reactive.js +1802 -0
  264. package/dist/reactive.js.map +1 -0
  265. package/dist/request-state-Bv5CY_H0.js +7358 -0
  266. package/dist/request-state-Bv5CY_H0.js.map +1 -0
  267. package/dist/request.js +1 -0
  268. package/dist/request.js.map +1 -0
  269. package/dist/store/-private.js +3 -0
  270. package/dist/store/-private.js.map +1 -0
  271. package/dist/store.js +545 -0
  272. package/dist/store.js.map +1 -0
  273. package/dist/symbols-DyqeYQTe.js +44 -0
  274. package/dist/symbols-DyqeYQTe.js.map +1 -0
  275. package/dist/types/-private.js +79 -0
  276. package/dist/types/-private.js.map +1 -0
  277. package/dist/types/cache/aliases.js +0 -0
  278. package/dist/types/cache/aliases.js.map +1 -0
  279. package/dist/types/cache/change.js +0 -0
  280. package/dist/types/cache/change.js.map +1 -0
  281. package/dist/types/cache/mutations.js +0 -0
  282. package/dist/types/cache/mutations.js.map +1 -0
  283. package/dist/types/cache/operations.js +0 -0
  284. package/dist/types/cache/operations.js.map +1 -0
  285. package/dist/types/cache/relationship.js +0 -0
  286. package/dist/types/cache/relationship.js.map +1 -0
  287. package/dist/types/cache.js +0 -0
  288. package/dist/types/cache.js.map +1 -0
  289. package/dist/types/graph.js +0 -0
  290. package/dist/types/graph.js.map +1 -0
  291. package/dist/types/identifier.js +89 -0
  292. package/dist/types/identifier.js.map +1 -0
  293. package/dist/types/json/raw.js +0 -0
  294. package/dist/types/json/raw.js.map +1 -0
  295. package/dist/types/params.js +0 -0
  296. package/dist/types/params.js.map +1 -0
  297. package/dist/types/record.js +64 -0
  298. package/dist/types/record.js.map +1 -0
  299. package/dist/types/request.js +33 -0
  300. package/dist/types/request.js.map +1 -0
  301. package/dist/types/runtime.js +34 -0
  302. package/dist/types/runtime.js.map +1 -0
  303. package/dist/types/schema/concepts.js +0 -0
  304. package/dist/types/schema/concepts.js.map +1 -0
  305. package/dist/types/schema/fields.js +470 -0
  306. package/dist/types/schema/fields.js.map +1 -0
  307. package/dist/types/schema/fields.type-test.js +0 -0
  308. package/dist/types/schema/fields.type-test.js.map +1 -0
  309. package/dist/types/spec/document.js +0 -0
  310. package/dist/types/spec/document.js.map +1 -0
  311. package/dist/types/spec/error.js +0 -0
  312. package/dist/types/spec/error.js.map +1 -0
  313. package/dist/types/spec/json-api-raw.js +0 -0
  314. package/dist/types/spec/json-api-raw.js.map +1 -0
  315. package/dist/types/symbols.js +84 -0
  316. package/dist/types/symbols.js.map +1 -0
  317. package/dist/types/utils.js +0 -0
  318. package/dist/types/utils.js.map +1 -0
  319. package/dist/types.js +0 -0
  320. package/dist/types.js.map +1 -0
  321. package/dist/utils/string.js +92 -0
  322. package/dist/utils/string.js.map +1 -0
  323. package/logos/NCC-1701-a-blue.svg +4 -0
  324. package/logos/NCC-1701-a-gold.svg +4 -0
  325. package/logos/NCC-1701-a-gold_100.svg +1 -0
  326. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  327. package/logos/NCC-1701-a.svg +4 -0
  328. package/logos/README.md +4 -0
  329. package/logos/docs-badge.svg +2 -0
  330. package/logos/ember-data-logo-dark.svg +12 -0
  331. package/logos/ember-data-logo-light.svg +12 -0
  332. package/logos/github-header.svg +444 -0
  333. package/logos/social1.png +0 -0
  334. package/logos/social2.png +0 -0
  335. package/logos/warp-drive-logo-dark.svg +4 -0
  336. package/logos/warp-drive-logo-gold.svg +4 -0
  337. package/package.json +70 -0
@@ -0,0 +1,236 @@
1
+ import type { StableDocumentIdentifier } from '../../types/identifier';
2
+ import type { IS_FUTURE, RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from '../../types/request';
3
+ export interface GodContext {
4
+ controller: AbortController;
5
+ response: ResponseInfo | null;
6
+ stream: ReadableStream | Promise<ReadableStream | null> | null;
7
+ hasRequestedStream: boolean;
8
+ id: number;
9
+ identifier: StableDocumentIdentifier | null;
10
+ }
11
+ export type Deferred<T> = {
12
+ resolve(v: T): void;
13
+ reject(v: unknown): void;
14
+ promise: Promise<T>;
15
+ };
16
+ export type ManagedRequestPriority = {
17
+ blocking: boolean;
18
+ };
19
+ export type DeferredStream = {
20
+ resolve(v: ReadableStream | null): void;
21
+ reject(v: unknown): void;
22
+ promise: Promise<ReadableStream | null> & {
23
+ sizeHint?: number;
24
+ };
25
+ };
26
+ /**
27
+ * A Future is a {@link Promise} which resolves to a {@link StructuredDataDocument | StructuredDocument}
28
+ * while providing the ability to {@link Future.abort | abort} the underlying request, and
29
+ * {@link Future.getStream | access the response stream} before the outer promise resolves;
30
+ *
31
+ * @public
32
+ */
33
+ export interface Future<T> extends Promise<StructuredDataDocument<T>> {
34
+ [IS_FUTURE]: true;
35
+ /**
36
+ * Cancel this request by firing the {@link AbortController}'s signal.
37
+ *
38
+ * @privateRemarks
39
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/abort)
40
+ *
41
+ * @param reason optional reason for aborting the request
42
+ * @public
43
+ */
44
+ abort(reason?: string): void;
45
+ /**
46
+ * Get the response stream, if any, once made available.
47
+ *
48
+ * @public
49
+ * @return {Promise<ReadableStream | null>}
50
+ */
51
+ getStream(): Promise<ReadableStream | null>;
52
+ /**
53
+ * Run a callback when this request completes. Use sparingly,
54
+ * mostly useful for instrumentation and infrastructure.
55
+ *
56
+ * @param cb the callback to run
57
+ * @public
58
+ * @return {void}
59
+ */
60
+ onFinalize(cb: () => void): void;
61
+ /**
62
+ * The identifier of the associated request, if any, as
63
+ * assigned by the CacheHandler.
64
+ *
65
+ * @property lid
66
+ * @type {StableDocumentIdentifier | null}
67
+ * @public
68
+ */
69
+ lid: StableDocumentIdentifier | null;
70
+ /**
71
+ * The id of the associated request, if any, as assigned
72
+ * by the RequestManager
73
+ *
74
+ * @property id
75
+ * @type {Number}
76
+ * @public
77
+ */
78
+ id: number;
79
+ }
80
+ export type DeferredFuture<T> = {
81
+ resolve(v: StructuredDataDocument<T>): void;
82
+ reject(v: unknown): void;
83
+ promise: Future<T>;
84
+ };
85
+ export type NextFn<P = unknown> = (req: RequestInfo) => Future<P>;
86
+ /**
87
+ * Requests are fulfilled by handlers. A handler receives the request context
88
+ as well as a `next` function with which to pass along a request to the next
89
+ handler if it so chooses.
90
+
91
+ A handler may be any object with a `request` method. This allows both stateful and non-stateful
92
+ handlers to be utilized.
93
+
94
+ If a handler calls `next`, it receives a `Future` which resolves to a `StructuredDocument`
95
+ that it can then compose how it sees fit with its own response.
96
+
97
+ ```ts
98
+ type NextFn<P> = (req: RequestInfo) => Future<P>;
99
+
100
+ interface Handler {
101
+ async request<T>(context: RequestContext, next: NextFn<P>): T;
102
+ }
103
+ ```
104
+
105
+ `RequestContext` contains a readonly version of the RequestInfo as well as a few methods for building up the `StructuredDocument` and `Future` that will be part of the response.
106
+
107
+ ```ts
108
+ interface RequestContext<T> {
109
+ readonly request: RequestInfo;
110
+
111
+ setStream(stream: ReadableStream | Promise<ReadableStream>): void;
112
+ setResponse(response: Response | ResponseInfo): void;
113
+ }
114
+ ```
115
+
116
+ A basic `fetch` handler with support for streaming content updates while
117
+ the download is still underway might look like the following, where we use
118
+ [`response.clone()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/clone) to `tee` the `ReadableStream` into two streams.
119
+
120
+ A more efficient handler might read from the response stream, building up the
121
+ response content before passing along the chunk downstream.
122
+
123
+ ```ts
124
+ const FetchHandler = {
125
+ async request(context) {
126
+ const response = await fetch(context.request);
127
+ context.setResponse(reponse);
128
+ context.setStream(response.clone().body);
129
+
130
+ return response.json();
131
+ }
132
+ }
133
+ ```
134
+
135
+ ### Stream Currying
136
+
137
+ `RequestManager.request` and `next` differ from `fetch` in one **crucial detail** in that the outer Promise resolves only once the response stream has been processed.
138
+
139
+ For context, it helps to understand a few of the use-cases that RequestManager
140
+ is intended to allow.
141
+
142
+ - to manage and return streaming content (such as video files)
143
+ - to fulfill a request from multiple sources or by splitting one request into multiple requests
144
+ - for instance one API call for a user and another for the user's friends
145
+ - or e.g. fulfilling part of the request from one source (one API, in-memory, localStorage, IndexedDB etc.) and the rest from another source (a different API, a WebWorker, etc.)
146
+ - to coalesce multiple requests
147
+ - to decorate a request with additional info
148
+ - e.g. an Auth handler that ensures the correct tokens or headers or cookies are attached.
149
+
150
+ ----
151
+
152
+ `await fetch(<req>)` resolves at the moment headers are received. This allows for the body of the request to be processed as a stream by application
153
+ code *while chunks are still being received by the browser*.
154
+
155
+ When an app chooses to `await response.json()` what occurs is the browser reads the stream to completion and then returns the result. Additionally, this stream may only be read **once**.
156
+
157
+ The `RequestManager` preserves this ability to subscribe to and utilize the stream by either the application or the handler – thereby delivering the full power and flexibility of native APIs – without restricting developers in ways that lead to complicated workarounds.
158
+
159
+ Each handler may call `setStream` only once, but may do so *at any time* until the promise that the handler returns has resolved. The associated promise returned by calling `future.getStream` will resolve with the stream set by `setStream` if that method is called, or `null` if that method
160
+ has not been called by the time that the handler's request method has resolved.
161
+
162
+ Handlers that do not create a stream of their own, but which call `next`, should defensively pipe the stream forward. While this is not required (see automatic currying below) it is better to do so in most cases as otherwise the stream may not become available to downstream handlers or the application until the upstream handler has fully read it.
163
+
164
+ ```ts
165
+ context.setStream(future.getStream());
166
+ ```
167
+
168
+ Handlers that either call `next` multiple times or otherwise have reason to create multiple fetch requests should either choose to return no stream, meaningfully combine the streams, or select a single prioritized stream.
169
+
170
+ Of course, any handler may choose to read and handle the stream, and return either no stream or a different stream in the process.
171
+
172
+ ### Automatic Currying of Stream and Response
173
+
174
+ In order to simplify the common case for handlers which decorate a request, if `next` is called only a single time and `setResponse` was never called by the handler, the response set by the next handler in the chain will be applied to that handler's outcome. For instance, this makes the following pattern possible `return (await next(<req>)).content;`.
175
+
176
+ Similarly, if `next` is called only a single time and neither `setStream` nor `getStream` was called, we automatically curry the stream from the future returned by `next` onto the future returned by the handler.
177
+
178
+ Finally, if the return value of a handler is a `Future`, we curry `content` and `errors` as well, thus enabling the simplest form `return next(<req>)`.
179
+
180
+ In the case of the `Future` being returned, `Stream` proxying is automatic and immediate and does not wait for the `Future` to resolve.
181
+
182
+ ### Handler Order
183
+
184
+ Request handlers are registered by configuring the manager via `use`
185
+
186
+ ```ts
187
+ const manager = new RequestManager()
188
+ .use([Handler1, Handler2]);
189
+ ```
190
+
191
+ Handlers will be invoked in the order they are registered ("fifo", first-in first-out), and may only be registered up until the first request is made. It is recommended but not required to register all handlers at one time in order to ensure explicitly visible handler ordering.
192
+
193
+
194
+ @class (Interface) Handler
195
+ @public
196
+ */
197
+ export interface Handler {
198
+ /**
199
+ * Method to implement to handle requests. Receives the request
200
+ * context and a nextFn to call to pass-along the request to
201
+ * other handlers.
202
+ *
203
+ * @public
204
+ * @param context
205
+ * @param next
206
+ */
207
+ request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T>;
208
+ }
209
+ /**
210
+ * The CacheHandler is identical to other handlers ecxept that it
211
+ * is allowed to return a value synchronously. This is useful for
212
+ * features like reducing microtask queueing when de-duping.
213
+ *
214
+ * A RequestManager may only have one CacheHandler, registered via
215
+ * `manager.useCache(CacheHandler)`.
216
+ *
217
+ * @class (Interface) CacheHandler
218
+ * @public
219
+ */
220
+ export interface CacheHandler {
221
+ /**
222
+ * Method to implement to handle requests. Receives the request
223
+ * context and a nextFn to call to pass-along the request to
224
+ * other handlers.
225
+ *
226
+ * @public
227
+ * @param context
228
+ * @param next
229
+ */
230
+ request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T> | T;
231
+ }
232
+ export interface RequestResponse<T> {
233
+ result: T;
234
+ }
235
+ export type GenericCreateArgs = Record<string | symbol, unknown>;
236
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/request/-private/types.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,16 @@
1
+ import type { RequestInfo, StructuredDataDocument } from '../../types/request';
2
+ import { ContextOwner } from './context';
3
+ import type { DeferredFuture, Future, GodContext, Handler } from './types';
4
+ export declare const IS_CACHE_HANDLER: "___(unique) Symbol(IS_CACHE_HANDLER)";
5
+ export declare function curryFuture<T>(owner: ContextOwner, inbound: Future<T>, outbound: DeferredFuture<T>): Future<T>;
6
+ export interface HttpErrorProps extends DOMException {
7
+ code: number;
8
+ name: string;
9
+ status: number;
10
+ statusText: string;
11
+ isRequestError: boolean;
12
+ }
13
+ export declare function enhanceReason(reason?: string): DOMException;
14
+ export declare function handleOutcome<T>(owner: ContextOwner, inbound: Promise<T | StructuredDataDocument<T>>, outbound: DeferredFuture<T>): Future<T>;
15
+ export declare function executeNextHandler<T>(wares: Readonly<Handler[]>, request: RequestInfo, i: number, god: GodContext): Future<T>;
16
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/request/-private/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EACX,sBAAsB,EAGvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAW,YAAY,EAAE,MAAM,WAAW,CAAC;AAIlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE3E,eAAO,MAAM,gBAAgB,wCAAiE,CAAC;AAC/F,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAuC9G;AA4BD,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAE3D;AAED,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC,EAC/C,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAC1B,MAAM,CAAC,CAAC,CAAC,CA6CX;AAMD,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,EAC1B,OAAO,EAAE,WAAW,EACpB,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,UAAU,GACd,MAAM,CAAC,CAAC,CAAC,CAmDX"}
@@ -0,0 +1,6 @@
1
+ export { createDeferred } from './request/-private/future.ts';
2
+ export type { Future, Handler, CacheHandler, NextFn, Deferred, ManagedRequestPriority, } from './request/-private/types.ts';
3
+ export { setPromiseResult, getPromiseResult } from './request/-private/promise-cache.ts';
4
+ export type { Awaitable } from './request/-private/promise-cache.ts';
5
+ export type { Context } from './request/-private/context.ts';
6
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,YAAY,EACV,MAAM,EACN,OAAO,EACP,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACzF,YAAY,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACrE,YAAY,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,57 @@
1
+ import type { CacheHandler as CacheHandlerType } from '../../../request.ts';
2
+ import type { ImmutableRequestInfo, RequestContext } from '../../../types/request.ts';
3
+ import type { ResourceIdentifierObject } from '../../../types/spec/json-api-raw.ts';
4
+ import type { RequestSignature } from '../../../types/symbols.ts';
5
+ import type { Store } from '../store-service.ts';
6
+ export type LooseStoreRequestInfo<RT = unknown, T = unknown> = Omit<ImmutableRequestInfo<RT, T>, 'records' | 'headers' | typeof RequestSignature> & {
7
+ records?: ResourceIdentifierObject[];
8
+ headers?: Headers;
9
+ };
10
+ export type StoreRequestInput<RT = unknown, T = unknown> = ImmutableRequestInfo<RT, T> | LooseStoreRequestInfo<RT, T>;
11
+ export interface StoreRequestContext extends RequestContext {
12
+ request: ImmutableRequestInfo & {
13
+ store: Store;
14
+ };
15
+ }
16
+ /**
17
+ * A CacheHandler that adds support for using an WarpDrive Cache with a RequestManager.
18
+ *
19
+ * This handler will only run when a request has supplied a `store` instance. Requests
20
+ * issued by the store via `store.request()` will automatically have the `store` instance
21
+ * attached to the request.
22
+ *
23
+ * ```ts
24
+ * requestManager.request({
25
+ * store: store,
26
+ * url: '/api/posts',
27
+ * method: 'GET'
28
+ * });
29
+ * ```
30
+ *
31
+ * When this handler elects to handle a request, it will return the raw `StructuredDocument`
32
+ * unless the request has `[EnableHydration]` set to `true`. In this case, the handler will
33
+ * return a `Document` instance that will automatically update the UI when the cache is updated
34
+ * in the future and will hydrate any identifiers in the StructuredDocument into Record instances.
35
+ *
36
+ * When issuing a request via the store, [EnableHydration] is automatically set to `true`. This
37
+ * means that if desired you can issue requests that utilize the cache without needing to also
38
+ * utilize Record instances if desired.
39
+ *
40
+ * Said differently, you could elect to issue all requests via a RequestManager, without ever using
41
+ * the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not
42
+ * necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature
43
+ * approach of WarpDrive allows for this flexibility.
44
+ *
45
+ * ```ts
46
+ * import { EnableHydration } from '@warp-drive/core/types/request';
47
+ *
48
+ * requestManager.request({
49
+ * store: store,
50
+ * url: '/api/posts',
51
+ * method: 'GET',
52
+ * [EnableHydration]: true
53
+ * });
54
+ *
55
+ */
56
+ export declare const CacheHandler: CacheHandlerType;
57
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/store/-private/cache-handler/handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAA0C,MAAM,qBAAqB,CAAC;AAEpH,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EAGf,MAAM,2BAA2B,CAAC;AAInC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAUjD,MAAM,MAAM,qBAAqB,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,IAAI,CACjE,oBAAoB,CAAC,EAAE,EAAE,CAAC,CAAC,EAC3B,SAAS,GAAG,SAAS,GAAG,OAAO,gBAAgB,CAChD,GAAG;IACF,OAAO,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,oBAAoB,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAEtH,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,OAAO,EAAE,oBAAoB,GAAG;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,YAAY,EAAE,gBA0E1B,CAAC"}
@@ -0,0 +1,99 @@
1
+ import type { StableDocumentIdentifier } from '../../../types/identifier.ts';
2
+ import type { ImmutableRequestInfo, ResponseInfo } from '../../../types/request.ts';
3
+ import type { Store } from '../store-service';
4
+ /**
5
+ * A service which an application may provide to the store via
6
+ * the store's `lifetimes` property to configure the behavior
7
+ * of the CacheHandler.
8
+ *
9
+ * The default behavior for request lifetimes is to never expire
10
+ * unless manually refreshed via `cacheOptions.reload` or `cacheOptions.backgroundReload`.
11
+ *
12
+ * Implementing this service allows you to programatically define
13
+ * when a request should be considered expired.
14
+ *
15
+ * @class (Interface) CachePolicy
16
+ * @public
17
+ */
18
+ export interface CachePolicy {
19
+ /**
20
+ * Invoked to determine if the request may be fulfilled from cache
21
+ * if possible.
22
+ *
23
+ * Note, this is only invoked if the request has a cache-key.
24
+ *
25
+ * If no cache entry is found or the entry is hard expired,
26
+ * the request will be fulfilled from the configured request handlers
27
+ * and the cache will be updated before returning the response.
28
+ *
29
+ * @public
30
+ * @param {StableDocumentIdentifier} identifier
31
+ * @param {Store} store
32
+ * @return {Boolean} true if the request is considered hard expired
33
+ */
34
+ isHardExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
35
+ /**
36
+ * Invoked if `isHardExpired` is false to determine if the request
37
+ * should be update behind the scenes if cache data is already available.
38
+ *
39
+ * Note, this is only invoked if the request has a cache-key.
40
+ *
41
+ * If true, the request will be fulfilled from cache while a backgrounded
42
+ * request is made to update the cache via the configured request handlers.
43
+ *
44
+ * @public
45
+ * @param {StableDocumentIdentifier} identifier
46
+ * @param {Store} store
47
+ * @return {Boolean} true if the request is considered soft expired
48
+ */
49
+ isSoftExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
50
+ /**
51
+ * Invoked when a request will be sent to the configured request handlers.
52
+ * This is invoked for both foreground and background requests.
53
+ *
54
+ * Note, this is invoked regardless of whether the request has a cache-key.
55
+ *
56
+ * @public
57
+ * @param {ImmutableRequestInfo} request
58
+ * @param {StableDocumentIdentifier | null} identifier
59
+ * @param {Store} store
60
+ * @return {void}
61
+ */
62
+ willRequest?(request: ImmutableRequestInfo, identifier: StableDocumentIdentifier | null, store: Store): void;
63
+ /**
64
+ * Invoked when a request has been fulfilled from the configured request handlers.
65
+ * This is invoked for both foreground and background requests once the cache has
66
+ * been updated.
67
+ *
68
+ * Note, this is invoked regardless of whether the request has a cache-key.
69
+ *
70
+ * It is best practice to notify the store of any requests marked as invalidated
71
+ * so that request subscriptions can reload when needed.
72
+ *
73
+ * ```ts
74
+ * store.notifications.notify(identifier, 'invalidated');
75
+ * ```
76
+ *
77
+ * This allows anything subscribed to the request to be notified of the change
78
+ *
79
+ * e.g.
80
+ *
81
+ * ```ts
82
+ * store.notifications.subscribe(identifier, (_, type) => {
83
+ * if (type === 'invalidated') {
84
+ * // do update
85
+ * }
86
+ * });
87
+ * ```
88
+ *
89
+ *
90
+ * @public
91
+ * @param {ImmutableRequestInfo} request
92
+ * @param {ImmutableResponse} response
93
+ * @param {StableDocumentIdentifier | null} identifier
94
+ * @param {Store} store
95
+ * @return {void}
96
+ */
97
+ didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: StableDocumentIdentifier | null, store: Store): void;
98
+ }
99
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/store/-private/cache-handler/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,UAAU,EAAE,wBAAwB,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IAC3E;;;;;;;;;;;;;OAaG;IACH,aAAa,CAAC,UAAU,EAAE,wBAAwB,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IAE3E;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,CAAC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,wBAAwB,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,UAAU,CAAC,CACT,OAAO,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,QAAQ,GAAG,YAAY,GAAG,IAAI,EACxC,UAAU,EAAE,wBAAwB,GAAG,IAAI,EAC3C,KAAK,EAAE,KAAK,GACX,IAAI,CAAC;CACT"}
@@ -0,0 +1,32 @@
1
+ import type { StableDocumentIdentifier } from '../../../types/identifier.ts';
2
+ import type { ImmutableCreateRequestOptions, ImmutableDeleteRequestOptions, ImmutableRequestInfo, ImmutableUpdateRequestOptions, StructuredDataDocument } from '../../../types/request.ts';
3
+ import type { ResourceDataDocument, ResourceErrorDocument } from '../../../types/spec/document.ts';
4
+ import type { ApiError } from '../../../types/spec/error.ts';
5
+ import type { Store } from '../store-service.ts';
6
+ export declare const MUTATION_OPS: Set<string>;
7
+ export declare function calcShouldFetch(store: Store, request: ImmutableRequestInfo, hasCachedValue: boolean, identifier: StableDocumentIdentifier | null): boolean;
8
+ export declare function calcShouldBackgroundFetch(store: Store, request: ImmutableRequestInfo, willFetch: boolean, identifier: StableDocumentIdentifier | null): boolean;
9
+ export declare function isMutation(request: Partial<ImmutableRequestInfo>): request is ImmutableUpdateRequestOptions | ImmutableCreateRequestOptions | ImmutableDeleteRequestOptions;
10
+ export declare function isCacheAffecting<T>(document: StructuredDataDocument<T>): boolean;
11
+ export declare function isAggregateError(error: Error & {
12
+ errors?: ApiError[];
13
+ }): error is AggregateError & {
14
+ errors: ApiError[];
15
+ };
16
+ export type RobustError = Error & {
17
+ error: string | object;
18
+ errors?: ApiError[];
19
+ content?: unknown;
20
+ };
21
+ export declare function cloneError(error: RobustError): RobustError;
22
+ export declare function isErrorDocument(document: ResourceDataDocument | ResourceErrorDocument): document is ResourceErrorDocument;
23
+ export declare function getPriority(identifier: StableDocumentIdentifier | null, deduped: Map<StableDocumentIdentifier, {
24
+ priority: {
25
+ blocking: boolean;
26
+ };
27
+ }>, priority: {
28
+ blocking: boolean;
29
+ }): {
30
+ blocking: boolean;
31
+ };
32
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/store/-private/cache-handler/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EACV,6BAA6B,EAC7B,6BAA6B,EAC7B,oBAAoB,EACpB,6BAA6B,EAC7B,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,eAAO,MAAM,YAAY,aAA4D,CAAC;AAEtF,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,oBAAoB,EAC7B,cAAc,EAAE,OAAO,EACvB,UAAU,EAAE,wBAAwB,GAAG,IAAI,GAC1C,OAAO,CAQT;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,oBAAoB,EAC7B,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,wBAAwB,GAAG,IAAI,GAC1C,OAAO,CAOT;AAED,wBAAgB,UAAU,CACxB,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,GACrC,OAAO,IAAI,6BAA6B,GAAG,6BAA6B,GAAG,6BAA6B,CAE1G;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,OAAO,CAahF;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,GAAG;IAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAA;CAAE,GACrC,KAAK,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;CAAE,CAElD;AAED,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG;IAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAGrG,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,eAa5C;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,oBAAoB,GAAG,qBAAqB,GACrD,QAAQ,IAAI,qBAAqB,CAEnC;AAED,wBAAgB,WAAW,CACzB,UAAU,EAAE,wBAAwB,GAAG,IAAI,EAC3C,OAAO,EAAE,GAAG,CAAC,wBAAwB,EAAE;IAAE,QAAQ,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAC,EAC3E,QAAQ,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE;cADgC,OAAO;EAUvE"}
@@ -0,0 +1,9 @@
1
+ import type { Cache } from '../../../types/cache.ts';
2
+ import type { StableRecordIdentifier } from '../../../types/identifier.ts';
3
+ import type { OpaqueRecordInstance } from '../../-types/q/record-instance';
4
+ export declare const CacheForIdentifierCache: Map<unknown, Cache>;
5
+ export declare function setCacheFor(identifier: StableRecordIdentifier | OpaqueRecordInstance, cache: Cache): void;
6
+ export declare function removeRecordDataFor(identifier: StableRecordIdentifier | OpaqueRecordInstance): void;
7
+ export declare function peekCache(instance: StableRecordIdentifier): Cache | null;
8
+ export declare function peekCache(instance: OpaqueRecordInstance): Cache;
9
+ //# sourceMappingURL=cache-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-utils.d.ts","sourceRoot":"","sources":["../../../../src/store/-private/caches/cache-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAO3E,eAAO,MAAM,uBAAuB,qBAGnC,CAAC;AAEF,wBAAgB,WAAW,CAAC,UAAU,EAAE,sBAAsB,GAAG,oBAAoB,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAMzG;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,sBAAsB,GAAG,oBAAoB,GAAG,IAAI,CAEnG;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,sBAAsB,GAAG,KAAK,GAAG,IAAI,CAAC;AAC1E,wBAAgB,SAAS,CAAC,QAAQ,EAAE,oBAAoB,GAAG,KAAK,CAAC"}