@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,428 @@
1
+ import type { Cache, ChangedAttributesHash, RelationshipDiff } from '../../../types/cache.ts';
2
+ import type { Change } from '../../../types/cache/change.ts';
3
+ import type { MergeOperation } from '../../../types/cache/operations.ts';
4
+ import type { CollectionRelationship, ResourceRelationship } from '../../../types/cache/relationship.ts';
5
+ import type { LocalRelationshipOperation } from '../../../types/graph.ts';
6
+ import type { StableDocumentIdentifier, StableRecordIdentifier } from '../../../types/identifier.ts';
7
+ import type { Value } from '../../../types/json/raw.ts';
8
+ import type { StructuredDataDocument, StructuredDocument } from '../../../types/request.ts';
9
+ import type { ResourceDocument, SingleResourceDataDocument } from '../../../types/spec/document.ts';
10
+ import type { ApiError } from '../../../types/spec/error.ts';
11
+ import type { StoreRequestContext } from '../cache-handler/handler.ts';
12
+ /**
13
+ * The CacheManager wraps a Cache enforcing that only
14
+ * the public API surface area is exposed.
15
+ *
16
+ * Hence, it is the value of `Store.cache`, wrapping
17
+ * the cache instance returned by `Store.createCache`.
18
+ *
19
+ * It handles translating between cache versions when
20
+ * necessary, for instance when a Store is configured
21
+ * to use both a v1 and a v2 cache depending on some
22
+ * heuristic.
23
+ *
24
+ * Starting with the v2 spec, the cache is designed such
25
+ * that it must be implemented as a singleton.
26
+ *
27
+ * @class CacheManager
28
+ * @public
29
+ */
30
+ export declare class CacheManager implements Cache {
31
+ #private;
32
+ version: "2";
33
+ constructor(cache: Cache);
34
+ /**
35
+ * Cache the response to a request
36
+ *
37
+ * Unlike `store.push` which has UPSERT
38
+ * semantics, `put` has `replace` semantics similar to
39
+ * the `http` method `PUT`
40
+ *
41
+ * the individually cacheable
42
+ * e resource data it may contain
43
+ * should upsert, but the document data surrounding it should
44
+ * fully replace any existing information
45
+ *
46
+ * Note that in order to support inserting arbitrary data
47
+ * to the cache that did not originate from a request `put`
48
+ * should expect to sometimes encounter a document with only
49
+ * a `content` member and therefor must not assume the existence
50
+ * of `request` and `response` on the document.
51
+ *
52
+ * @param {StructuredDocument} doc
53
+ * @return {ResourceDocument}
54
+ * @public
55
+ */
56
+ put<T>(doc: StructuredDocument<T> | {
57
+ content: T;
58
+ }): ResourceDocument;
59
+ /**
60
+ * Perform an operation on the cache to update the remote state.
61
+ *
62
+ * Note: currently the only valid operation is a MergeOperation
63
+ * which occurs when a collision of identifiers is detected.
64
+ *
65
+ * @public
66
+ * @param op the operation to perform
67
+ * @return {void}
68
+ */
69
+ patch(op: MergeOperation): void;
70
+ /**
71
+ * Update resource data with a local mutation. Currently supports operations
72
+ * on relationships only.
73
+ *
74
+ * @public
75
+ * @param mutation
76
+ */
77
+ mutate(mutation: LocalRelationshipOperation): void;
78
+ /**
79
+ * Peek resource data from the Cache.
80
+ *
81
+ * In development, if the return value
82
+ * is JSON the return value
83
+ * will be deep-cloned and deep-frozen
84
+ * to prevent mutation thereby enforcing cache
85
+ * Immutability.
86
+ *
87
+ * This form of peek is useful for implementations
88
+ * that want to feed raw-data from cache to the UI
89
+ * or which want to interact with a blob of data
90
+ * directly from the presentation cache.
91
+ *
92
+ * An implementation might want to do this because
93
+ * de-referencing records which read from their own
94
+ * blob is generally safer because the record does
95
+ * not require retaining connections to the Store
96
+ * and Cache to present data on a per-field basis.
97
+ *
98
+ * This generally takes the place of `getAttr` as
99
+ * an API and may even take the place of `getRelationship`
100
+ * depending on implementation specifics, though this
101
+ * latter usage is less recommended due to the advantages
102
+ * of the Graph handling necessary entanglements and
103
+ * notifications for relational data.
104
+ *
105
+ * @public
106
+ * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
107
+ * @return {ResourceDocument | ResourceBlob | null} the known resource data
108
+ */
109
+ peek(identifier: StableRecordIdentifier): unknown;
110
+ peek(identifier: StableDocumentIdentifier): ResourceDocument | null;
111
+ peekRemoteState(identifier: StableRecordIdentifier): unknown;
112
+ peekRemoteState(identifier: StableDocumentIdentifier): ResourceDocument | null;
113
+ /**
114
+ * Peek the Cache for the existing request data associated with
115
+ * a cacheable request
116
+ *
117
+ * @param {StableDocumentIdentifier}
118
+ * @return {StableDocumentIdentifier | null}
119
+ * @public
120
+ */
121
+ peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null;
122
+ /**
123
+ * Push resource data from a remote source into the cache for this identifier
124
+ *
125
+ * @public
126
+ * @param identifier
127
+ * @param data
128
+ * @param hasRecord
129
+ * @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
130
+ */
131
+ upsert(identifier: StableRecordIdentifier, data: unknown, hasRecord: boolean): void | string[];
132
+ /**
133
+ * Create a fork of the cache from the current state.
134
+ *
135
+ * Applications should typically not call this method themselves,
136
+ * preferring instead to fork at the Store level, which will
137
+ * utilize this method to fork the cache.
138
+ *
139
+ * @public
140
+ * @return {Promise<Cache>}
141
+ */
142
+ fork(): Promise<Cache>;
143
+ /**
144
+ * Merge a fork back into a parent Cache.
145
+ *
146
+ * Applications should typically not call this method themselves,
147
+ * preferring instead to merge at the Store level, which will
148
+ * utilize this method to merge the caches.
149
+ *
150
+ * @param {Cache} cache
151
+ * @public
152
+ * @return {Promise<void>}
153
+ */
154
+ merge(cache: Cache): Promise<void>;
155
+ /**
156
+ * Generate the list of changes applied to all
157
+ * record in the store.
158
+ *
159
+ * Each individual resource or document that has
160
+ * been mutated should be described as an individual
161
+ * `Change` entry in the returned array.
162
+ *
163
+ * A `Change` is described by an object containing up to
164
+ * three properties: (1) the `identifier` of the entity that
165
+ * changed; (2) the `op` code of that change being one of
166
+ * `upsert` or `remove`, and if the op is `upsert` a `patch`
167
+ * containing the data to merge into the cache for the given
168
+ * entity.
169
+ *
170
+ * This `patch` is opaque to the Store but should be understood
171
+ * by the Cache and may expect to be utilized by an Adapter
172
+ * when generating data during a `save` operation.
173
+ *
174
+ * It is generally recommended that the `patch` contain only
175
+ * the updated state, ignoring fields that are unchanged
176
+ *
177
+ * ```ts
178
+ * interface Change {
179
+ * identifier: StableRecordIdentifier | StableDocumentIdentifier;
180
+ * op: 'upsert' | 'remove';
181
+ * patch?: unknown;
182
+ * }
183
+ * ```
184
+ *
185
+ * @public
186
+ */
187
+ diff(): Promise<Change[]>;
188
+ /**
189
+ * Serialize the entire contents of the Cache into a Stream
190
+ * which may be fed back into a new instance of the same Cache
191
+ * via `cache.hydrate`.
192
+ *
193
+ * @return {Promise<ReadableStream>}
194
+ * @public
195
+ */
196
+ dump(): Promise<ReadableStream<unknown>>;
197
+ /**
198
+ * hydrate a Cache from a Stream with content previously serialized
199
+ * from another instance of the same Cache, resolving when hydration
200
+ * is complete.
201
+ *
202
+ * This method should expect to be called both in the context of restoring
203
+ * the Cache during application rehydration after SSR **AND** at unknown
204
+ * times during the lifetime of an already booted application when it is
205
+ * desired to bulk-load additional information into the cache. This latter
206
+ * behavior supports optimizing pre/fetching of data for route transitions
207
+ * via data-only SSR modes.
208
+ *
209
+ * @param {ReadableStream} stream
210
+ * @return {Promise<void>}
211
+ * @public
212
+ */
213
+ hydrate(stream: ReadableStream<unknown>): Promise<void>;
214
+ /**
215
+ * [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
216
+ *
217
+ * It returns properties from options that should be set on the record during the create
218
+ * process. This return value behavior is deprecated.
219
+ *
220
+ * @public
221
+ * @param identifier
222
+ * @param options
223
+ */
224
+ clientDidCreate(identifier: StableRecordIdentifier, options?: Record<string, unknown>): Record<string, unknown>;
225
+ /**
226
+ * [LIFECYCLE] Signals to the cache that a resource
227
+ * will be part of a save transaction.
228
+ *
229
+ * @public
230
+ * @param identifier
231
+ */
232
+ willCommit(identifier: StableRecordIdentifier, context: StoreRequestContext): void;
233
+ /**
234
+ * [LIFECYCLE] Signals to the cache that a resource
235
+ * was successfully updated as part of a save transaction.
236
+ *
237
+ * @public
238
+ * @param identifier
239
+ * @param data
240
+ */
241
+ didCommit(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument;
242
+ /**
243
+ * [LIFECYCLE] Signals to the cache that a resource
244
+ * was update via a save transaction failed.
245
+ *
246
+ * @public
247
+ * @param identifier
248
+ * @param errors
249
+ */
250
+ commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void;
251
+ /**
252
+ * [LIFECYCLE] Signals to the cache that all data for a resource
253
+ * should be cleared.
254
+ *
255
+ * @public
256
+ * @param identifier
257
+ */
258
+ unloadRecord(identifier: StableRecordIdentifier): void;
259
+ /**
260
+ * Retrieve the data for an attribute from the cache
261
+ *
262
+ * @public
263
+ * @param identifier
264
+ * @param propertyName
265
+ * @return {unknown}
266
+ */
267
+ getAttr(identifier: StableRecordIdentifier, propertyName: string): Value | undefined;
268
+ /**
269
+ * Retrieve the remote state for an attribute from the cache
270
+ *
271
+ * @public
272
+ * @param identifier
273
+ * @param propertyName
274
+ * @return {unknown}
275
+ */
276
+ getRemoteAttr(identifier: StableRecordIdentifier, propertyName: string): Value | undefined;
277
+ /**
278
+ * Mutate the data for an attribute in the cache
279
+ *
280
+ * @public
281
+ * @param identifier
282
+ * @param propertyName
283
+ * @param value
284
+ */
285
+ setAttr(identifier: StableRecordIdentifier, propertyName: string, value: Value): void;
286
+ /**
287
+ * Query the cache for the changed attributes of a resource.
288
+ *
289
+ * @public
290
+ * @param identifier
291
+ * @return
292
+ */
293
+ changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash;
294
+ /**
295
+ * Query the cache for whether any mutated attributes exist
296
+ *
297
+ * @public
298
+ * @param identifier
299
+ * @return {Boolean}
300
+ */
301
+ hasChangedAttrs(identifier: StableRecordIdentifier): boolean;
302
+ /**
303
+ * Tell the cache to discard any uncommitted mutations to attributes
304
+ *
305
+ * @public
306
+ * @param identifier
307
+ * @return the names of attributes that were restored
308
+ */
309
+ rollbackAttrs(identifier: StableRecordIdentifier): string[];
310
+ /**
311
+ * Query the cache for the changes to relationships of a resource.
312
+ *
313
+ * Returns a map of relationship names to RelationshipDiff objects.
314
+ *
315
+ * ```ts
316
+ * type RelationshipDiff =
317
+ | {
318
+ kind: 'collection';
319
+ remoteState: StableRecordIdentifier[];
320
+ additions: Set<StableRecordIdentifier>;
321
+ removals: Set<StableRecordIdentifier>;
322
+ localState: StableRecordIdentifier[];
323
+ reordered: boolean;
324
+ }
325
+ | {
326
+ kind: 'resource';
327
+ remoteState: StableRecordIdentifier | null;
328
+ localState: StableRecordIdentifier | null;
329
+ };
330
+ ```
331
+ *
332
+ * @public
333
+ * @param {StableRecordIdentifier} identifier
334
+ * @return {Map<string, RelationshipDiff>}
335
+ */
336
+ changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff>;
337
+ /**
338
+ * Query the cache for whether any mutated attributes exist
339
+ *
340
+ * @public
341
+ * @param {StableRecordIdentifier} identifier
342
+ * @return {Boolean}
343
+ */
344
+ hasChangedRelationships(identifier: StableRecordIdentifier): boolean;
345
+ /**
346
+ * Tell the cache to discard any uncommitted mutations to relationships.
347
+ *
348
+ * This will also discard the change on any appropriate inverses.
349
+ *
350
+ * This method is a candidate to become a mutation
351
+ *
352
+ * @public
353
+ * @param {StableRecordIdentifier} identifier
354
+ * @return {String[]} the names of relationships that were restored
355
+ */
356
+ rollbackRelationships(identifier: StableRecordIdentifier): string[];
357
+ /**
358
+ * Query the cache for the current state of a relationship property
359
+ *
360
+ * @public
361
+ * @param identifier
362
+ * @param propertyName
363
+ * @return resource relationship object
364
+ */
365
+ getRelationship(identifier: StableRecordIdentifier, propertyName: string): ResourceRelationship | CollectionRelationship;
366
+ /**
367
+ * Query the cache for the remote state of a relationship property
368
+ *
369
+ * @public
370
+ * @param identifier
371
+ * @param propertyName
372
+ * @return resource relationship object
373
+ */
374
+ getRemoteRelationship(identifier: StableRecordIdentifier, propertyName: string): ResourceRelationship | CollectionRelationship;
375
+ /**
376
+ * Update the cache state for the given resource to be marked as locally deleted,
377
+ * or remove such a mark.
378
+ *
379
+ * @public
380
+ * @param identifier
381
+ * @param isDeleted
382
+ */
383
+ setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void;
384
+ /**
385
+ * Query the cache for any validation errors applicable to the given resource.
386
+ *
387
+ * @public
388
+ * @param identifier
389
+ * @return
390
+ */
391
+ getErrors(identifier: StableRecordIdentifier): ApiError[];
392
+ /**
393
+ * Query the cache for whether a given resource has any available data
394
+ *
395
+ * @public
396
+ * @param identifier
397
+ * @return {Boolean}
398
+ */
399
+ isEmpty(identifier: StableRecordIdentifier): boolean;
400
+ /**
401
+ * Query the cache for whether a given resource was created locally and not
402
+ * yet persisted.
403
+ *
404
+ * @public
405
+ * @param identifier
406
+ * @return {Boolean}
407
+ */
408
+ isNew(identifier: StableRecordIdentifier): boolean;
409
+ /**
410
+ * Query the cache for whether a given resource is marked as deleted (but not
411
+ * necessarily persisted yet).
412
+ *
413
+ * @public
414
+ * @param identifier
415
+ * @return {Boolean}
416
+ */
417
+ isDeleted(identifier: StableRecordIdentifier): boolean;
418
+ /**
419
+ * Query the cache for whether a given resource has been deleted and that deletion
420
+ * has also been persisted.
421
+ *
422
+ * @public
423
+ * @param identifier
424
+ * @return {Boolean}
425
+ */
426
+ isDeletionCommitted(identifier: StableRecordIdentifier): boolean;
427
+ }
428
+ //# sourceMappingURL=cache-manager.d.ts.map
@@ -0,0 +1 @@
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;;;;OAOG;IACH,qBAAqB,CACnB,UAAU,EAAE,sBAAsB,EAClC,YAAY,EAAE,MAAM,GACnB,oBAAoB,GAAG,sBAAsB;IAOhD;;;;;;;OAOG;IACH,YAAY,CAAC,UAAU,EAAE,sBAAsB,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI;IAI1E;;;;;;OAMG;IACH,SAAS,CAAC,UAAU,EAAE,sBAAsB,GAAG,QAAQ,EAAE;IAIzD;;;;;;OAMG;IACH,OAAO,CAAC,UAAU,EAAE,sBAAsB,GAAG,OAAO;IAIpD;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,EAAE,sBAAsB,GAAG,OAAO;IAIlD;;;;;;;OAOG;IACH,SAAS,CAAC,UAAU,EAAE,sBAAsB,GAAG,OAAO;IAItD;;;;;;;OAOG;IACH,mBAAmB,CAAC,UAAU,EAAE,sBAAsB,GAAG,OAAO;CAGjE"}
@@ -0,0 +1,93 @@
1
+ import type { StableDocumentIdentifier, StableRecordIdentifier } from '../../../types/identifier.ts';
2
+ import type { Store } from '../store-service.ts';
3
+ export type UnsubscribeToken = object;
4
+ export type CacheOperation = 'added' | 'removed' | 'updated' | 'state';
5
+ export type DocumentCacheOperation = 'invalidated' | 'added' | 'removed' | 'updated' | 'state';
6
+ export type NotificationType = 'attributes' | 'relationships' | 'identity' | 'errors' | 'meta' | CacheOperation;
7
+ export interface NotificationCallback {
8
+ (identifier: StableRecordIdentifier, notificationType: 'attributes' | 'relationships', key?: string): void;
9
+ (identifier: StableRecordIdentifier, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;
10
+ (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
11
+ }
12
+ export interface ResourceOperationCallback {
13
+ (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
14
+ }
15
+ export interface DocumentOperationCallback {
16
+ (identifier: StableDocumentIdentifier, notificationType: DocumentCacheOperation): void;
17
+ }
18
+ /**
19
+ * The NotificationManager provides the ability to subscribe to
20
+ * changes to Cache state.
21
+ *
22
+ * This Feature is what allows WarpDrive to create subscriptions that
23
+ * work with any framework or change-notification system.
24
+ *
25
+ * @class NotificationManager
26
+ * @public
27
+ */
28
+ export default class NotificationManager {
29
+ store: Store;
30
+ isDestroyed: boolean;
31
+ _buffered: Map<StableDocumentIdentifier | StableRecordIdentifier, [string, string | undefined][]>;
32
+ _cache: Map<StableDocumentIdentifier | StableRecordIdentifier | 'resource' | 'document', Array<NotificationCallback | ResourceOperationCallback | DocumentOperationCallback>>;
33
+ _hasFlush: boolean;
34
+ _onFlushCB?: () => void;
35
+ constructor(store: Store);
36
+ /**
37
+ * Subscribe to changes for a given resource identifier, resource addition/removal, or document addition/removal.
38
+ *
39
+ * ```ts
40
+ * export type CacheOperation = 'added' | 'removed' | 'updated' | 'state';
41
+ *
42
+ * export interface NotificationCallback {
43
+ * (identifier: StableRecordIdentifier, notificationType: 'attributes' | 'relationships', key?: string): void;
44
+ * (identifier: StableRecordIdentifier, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;
45
+ * (identifier: StableRecordIdentifier, notificationType: NotificationType, key?: string): void;
46
+ * }
47
+ * export interface ResourceOperationCallback {
48
+ * // resource updates
49
+ * (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
50
+ * }
51
+ * export interface DocumentOperationCallback {
52
+ * // document updates
53
+ * (identifier: StableDocumentIdentifier, notificationType: CacheOperation): void;
54
+ * }
55
+ * ```
56
+ *
57
+ * @public
58
+ * @param {StableDocumentIdentifier | StableRecordIdentifier | 'resource' | 'document'} identifier
59
+ * @param {NotificationCallback | ResourceOperationCallback | DocumentOperationCallback} callback
60
+ * @return {UnsubscribeToken} an opaque token to be used with unsubscribe
61
+ */
62
+ subscribe(identifier: StableRecordIdentifier, callback: NotificationCallback): UnsubscribeToken;
63
+ subscribe(identifier: 'resource', callback: ResourceOperationCallback): UnsubscribeToken;
64
+ subscribe(identifier: 'document' | StableDocumentIdentifier, callback: DocumentOperationCallback): UnsubscribeToken;
65
+ /**
66
+ * remove a previous subscription
67
+ *
68
+ * @public
69
+ * @param {UnsubscribeToken} token
70
+ */
71
+ unsubscribe(token: UnsubscribeToken): void;
72
+ /**
73
+ * Custom Caches and Application Code should not call this method directly.
74
+ *
75
+ * @param identifier
76
+ * @param value
77
+ * @param key
78
+ * @return {Boolean} whether a notification was delivered to any subscribers
79
+ * @private
80
+ */
81
+ notify(identifier: StableRecordIdentifier, value: 'attributes' | 'relationships', key?: string): boolean;
82
+ notify(identifier: StableRecordIdentifier, value: 'errors' | 'meta' | 'identity' | 'state'): boolean;
83
+ notify(identifier: StableRecordIdentifier, value: CacheOperation): boolean;
84
+ notify(identifier: StableDocumentIdentifier, value: DocumentCacheOperation): boolean;
85
+ _onNextFlush(cb: () => void): void;
86
+ _scheduleNotify(): boolean;
87
+ _flush(): void;
88
+ _flushNotification(identifier: StableRecordIdentifier, value: 'attributes' | 'relationships', key?: string): boolean;
89
+ _flushNotification(identifier: StableRecordIdentifier, value: 'errors' | 'meta' | 'identity' | 'state'): boolean;
90
+ _flushNotification(identifier: StableRecordIdentifier | StableDocumentIdentifier, value: CacheOperation): boolean;
91
+ destroy(): void;
92
+ }
93
+ //# sourceMappingURL=notification-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification-manager.d.ts","sourceRoot":"","sources":["../../../../src/store/-private/managers/notification-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAIrG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AACvE,MAAM,MAAM,sBAAsB,GAAG,aAAa,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAQ/F,MAAM,MAAM,gBAAgB,GAA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AAoB,GAAG,gBAAgB;IAC/F,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,yBAAyB,GAAG,gBAAgB;IACxF,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,wBAAwB,EAAE,QAAQ,EAAE,yBAAyB,GAAG,gBAAgB;IA4BnH;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,gBAAgB;IAMnC;;;;;;;;OAQG;IACH,MAAM,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,YAAY,GAAG,eAAe,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO;IACxG,MAAM,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO;IACpG,MAAM,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO;IAC1E,MAAM,CAAC,UAAU,EAAE,wBAAwB,EAAE,KAAK,EAAE,sBAAsB,GAAG,OAAO;IAmEpF,YAAY,CAAC,EAAE,EAAE,MAAM,IAAI;IAI3B,eAAe,IAAI,OAAO;IAkB1B,MAAM;IAiBN,kBAAkB,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,YAAY,GAAG,eAAe,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO;IACpH,kBAAkB,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO;IAChH,kBAAkB,CAAC,UAAU,EAAE,sBAAsB,GAAG,wBAAwB,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO;IAyCjH,OAAO;CAIR"}
@@ -0,0 +1,98 @@
1
+ import type { LocalRelationshipOperation } from '../../../types/graph.ts';
2
+ import type { StableDocumentIdentifier, StableRecordIdentifier } from '../../../types/identifier.ts';
3
+ import type { ImmutableRequestInfo } from '../../../types/request.ts';
4
+ import type { CollectionResourceDocument } from '../../../types/spec/json-api-raw.ts';
5
+ import { Collection, IdentifierArray } from '../record-arrays/identifier-array.ts';
6
+ import type { Store } from '../store-service.ts';
7
+ import type { UnsubscribeToken } from './notification-manager.ts';
8
+ /**
9
+ * This is a clever optimization.
10
+ *
11
+ * clever optimizations rarely stand the test of time, so if you're
12
+ * ever curious or think something better is possible please benchmark
13
+ * and discuss. The benchmark for this at the time of writing is in
14
+ * `scripts/benchmark-push.js`
15
+ *
16
+ * This approach turns out to be 150x faster in Chrome and node than
17
+ * simply using push or concat. It's highly susceptible to the specifics
18
+ * of the batch size, and may require tuning.
19
+ *
20
+ * Clever optimizations should always come with a `why`. This optimization
21
+ * exists for two reasons.
22
+ *
23
+ * 1) array.push(...objects) and Array.prototype.push.apply(arr, objects)
24
+ * are susceptible to stack overflows. The size of objects at which this
25
+ * occurs varies by environment, browser, and current stack depth and memory
26
+ * pressure; however, it occurs in all browsers in fairly pristine conditions
27
+ * somewhere around 125k to 200k elements. Since WarpDrive regularly encounters
28
+ * arrays larger than this in size, we cannot use push.
29
+ *
30
+ * 2) `array.concat` or simply setting the array to a new reference is often an
31
+ * easier approach; however, native Proxy to an array cannot swap it's target array
32
+ * and attempts at juggling multiple array sources have proven to be victim to a number
33
+ * of browser implementation bugs. Should these bugs be addressed then we could
34
+ * simplify to using `concat`, however, do note this is currently 150x faster
35
+ * than concat, and due to the overloaded signature of concat will likely always
36
+ * be faster.
37
+ *
38
+ * Sincerely,
39
+ * - runspired (Chris Thoburn) 08/21/2022
40
+ *
41
+ * @function fastPush
42
+ * @internal
43
+ * @param target the array to push into
44
+ * @param source the items to push into target
45
+ */
46
+ export declare function fastPush<T>(target: T[], source: T[]): void;
47
+ type ChangeSet = Map<StableRecordIdentifier, 'add' | 'del'>;
48
+ /**
49
+ @class RecordArrayManager
50
+ @internal
51
+ */
52
+ export declare class RecordArrayManager {
53
+ store: Store;
54
+ isDestroying: boolean;
55
+ isDestroyed: boolean;
56
+ _set: Map<IdentifierArray, Set<StableRecordIdentifier>>;
57
+ _live: Map<string, IdentifierArray>;
58
+ _managed: Set<IdentifierArray>;
59
+ _pending: Map<IdentifierArray, ChangeSet>;
60
+ _identifiers: Map<StableRecordIdentifier, Set<Collection>>;
61
+ _staged: Map<string, ChangeSet>;
62
+ _subscription: UnsubscribeToken;
63
+ _documentSubscription: UnsubscribeToken;
64
+ _keyedArrays: Map<string, Collection>;
65
+ _visibilitySet: Map<StableRecordIdentifier, boolean>;
66
+ constructor(options: {
67
+ store: Store;
68
+ });
69
+ _syncArray(array: IdentifierArray | Collection): void;
70
+ mutate(mutation: LocalRelationshipOperation): void;
71
+ /**
72
+ Get the `RecordArray` for a modelName, which contains all loaded records of
73
+ given modelName.
74
+
75
+ @internal
76
+ @param {String} modelName
77
+ @return {RecordArray}
78
+ */
79
+ liveArrayFor(type: string): IdentifierArray;
80
+ getCollection(config: {
81
+ type?: string;
82
+ query?: ImmutableRequestInfo | Record<string, unknown>;
83
+ identifiers?: StableRecordIdentifier[];
84
+ doc?: CollectionResourceDocument;
85
+ identifier?: StableDocumentIdentifier | null;
86
+ }): Collection;
87
+ dirtyArray(array: IdentifierArray, delta: number, shouldSyncFromCache: boolean): void;
88
+ _getPendingFor(identifier: StableRecordIdentifier, includeManaged: boolean, isRemove?: boolean): Map<IdentifierArray, ChangeSet> | void;
89
+ populateManagedArray(array: Collection, identifiers: StableRecordIdentifier[], payload: CollectionResourceDocument | null): void;
90
+ identifierAdded(identifier: StableRecordIdentifier): void;
91
+ identifierRemoved(identifier: StableRecordIdentifier): void;
92
+ identifierChanged(identifier: StableRecordIdentifier): void;
93
+ clear(isClear?: boolean): void;
94
+ destroy(): void;
95
+ }
96
+ export declare function disassociateIdentifier(ArraysCache: Map<StableRecordIdentifier, Set<Collection>>, array: Collection, identifier: StableRecordIdentifier): void;
97
+ export {};
98
+ //# sourceMappingURL=record-array-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-array-manager.d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