@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,1802 @@
1
+ import { isResourceSchema } from "./types/schema/fields.js";
2
+ import { B as withSignalStore, w as entangleSignal, E as consumeInternalSignal, d as SOURCE$1, f as fastPush, x as defineSignal, l as RelatedCollection, F as getOrCreateInternalSignal, D as notifyInternalSignal, z as Signals, h as setRecordIdentifier, r as recordIdentifierFor } from "./request-state-Bv5CY_H0.js";
3
+ import { EnableHydration, STRUCTURED } from "./types/request.js";
4
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
5
+ import { deprecate } from '@ember/debug';
6
+ import "./utils/string.js";
7
+ import { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, c as createMemo } from "./configure-Bz49BEZQ.js";
8
+ import { RecordStore, Type } from "./types/symbols.js";
9
+ import { getOrSetGlobal } from "./types/-private.js";
10
+ import { S as SOURCE, E as Editable, L as Legacy, I as Identifier, P as Parent, a as EmbeddedPath, D as Destroy, C as Checkout, b as EmbeddedType } from "./symbols-DyqeYQTe.js";
11
+ import "./index.js";
12
+ const ARRAY_GETTER_METHODS = new Set([Symbol.iterator, 'concat', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'reduce', 'reduceRight', 'slice', 'some', 'values']);
13
+ // const ARRAY_SETTER_METHODS = new Set<KeyType>(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
14
+ const SYNC_PROPS = new Set(['[]', 'length']);
15
+ function isArrayGetter(prop) {
16
+ return ARRAY_GETTER_METHODS.has(prop);
17
+ }
18
+ const ARRAY_SETTER_METHODS = new Set(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
19
+ function isArraySetter(prop) {
20
+ return ARRAY_SETTER_METHODS.has(prop);
21
+ }
22
+
23
+ // function isSelfProp<T extends object>(self: T, prop: KeyType): prop is keyof T {
24
+ // return prop in self;
25
+ // }
26
+
27
+ function convertToInt(prop) {
28
+ if (typeof prop === 'symbol') return null;
29
+ const num = Number(prop);
30
+ if (isNaN(num)) return null;
31
+ return num % 1 === 0 ? num : null;
32
+ }
33
+ function safeForEach(instance, arr, store, callback, target) {
34
+ if (target === undefined) {
35
+ target = null;
36
+ }
37
+ // clone to prevent mutation
38
+ arr = arr.slice();
39
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
40
+ if (!test) {
41
+ throw new Error('`forEach` expects a function as first argument.');
42
+ }
43
+ })(typeof callback === 'function') : {};
44
+
45
+ // because we retrieveLatest above we need not worry if array is mutated during iteration
46
+ // by unloadRecord/rollbackAttributes
47
+ // push/add/removeObject may still be problematic
48
+ // but this is a more traditionally expected forEach bug.
49
+ const length = arr.length; // we need to access length to ensure we are consumed
50
+
51
+ for (let index = 0; index < length; index++) {
52
+ callback.call(target, arr[index], index, instance);
53
+ }
54
+ return instance;
55
+ }
56
+ class ManagedArray {
57
+ [SOURCE];
58
+ constructor(store, schema, cache, field, data, identifier, path, owner, isSchemaArray, editable, legacy) {
59
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
60
+ const self = this;
61
+ this[SOURCE] = data?.slice();
62
+ const IS_EDITABLE = this[Editable] = editable ?? false;
63
+ this[Legacy] = legacy;
64
+
65
+ // FIXME probably can get rid of the manual ARRAY_SIGNAL storage
66
+ // FIXME probably the storage should be on the proxy/receiver not this class
67
+ const signals = withSignalStore(this);
68
+ const _SIGNAL = this[ARRAY_SIGNAL] = entangleSignal(signals, this, ARRAY_SIGNAL, undefined);
69
+ const boundFns = new Map();
70
+ this.identifier = identifier;
71
+ this.path = path;
72
+ this.owner = owner;
73
+ let transaction = false;
74
+ const mode = field.options?.key ?? '@identity';
75
+ const RefStorage = mode === '@identity' ? WeakMap :
76
+ // CAUTION CAUTION CAUTION
77
+ // this is a pile of lies
78
+ // the Map is Map<string, WeakRef<ReactiveResource>>
79
+ // but TS does not understand how to juggle modes like this
80
+ // internal to a method like ours without us duplicating the code
81
+ // into two separate methods.
82
+ Map;
83
+ const ManagedRecordRefs = isSchemaArray ? new RefStorage() : null;
84
+ const proxy = new Proxy(this[SOURCE], {
85
+ get(target, prop, receiver) {
86
+ if (prop === ARRAY_SIGNAL) {
87
+ return _SIGNAL;
88
+ }
89
+ if (prop === 'identifier') {
90
+ return self.identifier;
91
+ }
92
+ if (prop === 'owner') {
93
+ return self.owner;
94
+ }
95
+ const index = convertToInt(prop);
96
+ if (_SIGNAL.isStale && (index !== null || SYNC_PROPS.has(prop) || isArrayGetter(prop))) {
97
+ _SIGNAL.isStale = false;
98
+ const newData = cache.getAttr(identifier, path);
99
+ if (newData && newData !== self[SOURCE]) {
100
+ self[SOURCE].length = 0;
101
+ self[SOURCE].push(...newData);
102
+ }
103
+ }
104
+ if (index !== null) {
105
+ let val;
106
+ if (mode === '@hash') {
107
+ val = target[index];
108
+ const hashField = schema.resource({
109
+ type: field.type
110
+ }).identity;
111
+ const hashFn = schema.hashFn(hashField);
112
+ val = hashFn(val, null, null);
113
+ } else {
114
+ // if mode is not @identity or @index, then access the key path.
115
+ // we should assert that `mode` is a string
116
+ // it should read directly from the cache value for that field (e.g. no derivation, no transformation)
117
+ // and, we likely should lookup the associated field and throw an error IF
118
+ // the given field does not exist OR
119
+ // the field is anything other than a GenericField or LegacyAttributeField.
120
+ if (mode !== '@identity' && mode !== '@index') {
121
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
122
+ if (!test) {
123
+ throw new Error('mode must be a string');
124
+ }
125
+ })(typeof mode === 'string') : {};
126
+ const modeField = schema.resource({
127
+ type: field.type
128
+ }).fields.find(f => f.name === mode);
129
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
130
+ if (!test) {
131
+ throw new Error('field must exist in schema');
132
+ }
133
+ })(modeField) : {};
134
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
135
+ if (!test) {
136
+ throw new Error('field must be a GenericField or LegacyAttributeField');
137
+ }
138
+ })(modeField.kind === 'field' || modeField.kind === 'attribute') : {};
139
+ }
140
+ val = mode === '@identity' ? target[index] : mode === '@index' ? '@index' : target[index][mode];
141
+ }
142
+ if (isSchemaArray) {
143
+ if (!transaction) {
144
+ consumeInternalSignal(_SIGNAL);
145
+ }
146
+ if (val) {
147
+ const recordRef = ManagedRecordRefs.get(val);
148
+ let record = recordRef?.deref();
149
+ if (!record) {
150
+ const recordPath = path.slice();
151
+ // this is a dirty lie since path is string[] but really we
152
+ // should change the types for paths to `Array<string | number>`
153
+ // TODO we should allow the schema for the field to define a "key"
154
+ // for stability. Default should be `@identity` which means that
155
+ // same object reference from cache should result in same ReactiveResource
156
+ // embedded object.
157
+ recordPath.push(index);
158
+ const recordIdentifier = self.owner[Identifier] || self.owner[Parent];
159
+ record = new ReactiveResource(store, recordIdentifier, {
160
+ [Editable]: self.owner[Editable],
161
+ [Legacy]: self.owner[Legacy]
162
+ }, true, field.type, recordPath);
163
+ // if mode is not @identity or @index, then access the key path now
164
+ // to determine the key value.
165
+ // chris says we can implement this as a special kind `@hash` which
166
+ // would be a function that only has access to the cache value and not
167
+ // the record itself, so derivation is possible but intentionally limited
168
+ // and non-reactive?
169
+ ManagedRecordRefs.set(val, new WeakRef(record));
170
+ }
171
+ return record;
172
+ }
173
+ return val;
174
+ }
175
+ if (!transaction) {
176
+ consumeInternalSignal(_SIGNAL);
177
+ }
178
+ if (field.type) {
179
+ const transform = schema.transformation(field);
180
+ return transform.hydrate(val, field.options ?? null, self.owner);
181
+ }
182
+ return val;
183
+ }
184
+ if (isArrayGetter(prop)) {
185
+ let fn = boundFns.get(prop);
186
+ if (fn === undefined) {
187
+ if (prop === 'forEach') {
188
+ fn = function () {
189
+ consumeInternalSignal(_SIGNAL);
190
+ transaction = true;
191
+ const result = safeForEach(receiver, target, store, arguments[0], arguments[1]);
192
+ transaction = false;
193
+ return result;
194
+ };
195
+ } else {
196
+ fn = function () {
197
+ consumeInternalSignal(_SIGNAL);
198
+ // array functions must run through Reflect to work properly
199
+ // binding via other means will not work.
200
+ transaction = true;
201
+ const result = Reflect.apply(target[prop], receiver, arguments);
202
+ transaction = false;
203
+ return result;
204
+ };
205
+ }
206
+ boundFns.set(prop, fn);
207
+ }
208
+ return fn;
209
+ }
210
+ if (isArraySetter(prop)) {
211
+ let fn = boundFns.get(prop);
212
+ if (fn === undefined) {
213
+ fn = function () {
214
+ if (!IS_EDITABLE) {
215
+ throw new Error(`Mutating this array via ${String(prop)} is not allowed because the record is not editable`);
216
+ }
217
+ consumeInternalSignal(_SIGNAL);
218
+ transaction = true;
219
+ const result = Reflect.apply(target[prop], receiver, arguments);
220
+ transaction = false;
221
+ return result;
222
+ };
223
+ boundFns.set(prop, fn);
224
+ }
225
+ return fn;
226
+ }
227
+ return Reflect.get(target, prop, receiver);
228
+ },
229
+ set(target, prop, value, receiver) {
230
+ if (!IS_EDITABLE) {
231
+ let errorPath = identifier.type;
232
+ if (path) {
233
+ errorPath = path[path.length - 1];
234
+ }
235
+ throw new Error(`Cannot set ${String(prop)} on ${errorPath} because the record is not editable`);
236
+ }
237
+ if (prop === 'identifier') {
238
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
239
+ self.identifier = value;
240
+ return true;
241
+ }
242
+ if (prop === 'owner') {
243
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
244
+ self.owner = value;
245
+ return true;
246
+ }
247
+ const reflect = Reflect.set(target, prop, value, receiver);
248
+ if (reflect) {
249
+ if (!field.type) {
250
+ cache.setAttr(identifier, path, self[SOURCE]);
251
+ _SIGNAL.isStale = true;
252
+ return true;
253
+ }
254
+ let rawValue = self[SOURCE];
255
+ if (!isSchemaArray) {
256
+ const transform = schema.transformation(field);
257
+ if (!transform) {
258
+ throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
259
+ }
260
+ rawValue = self[SOURCE].map(item => transform.serialize(item, field.options ?? null, self.owner));
261
+ }
262
+ cache.setAttr(identifier, path, rawValue);
263
+ _SIGNAL.isStale = true;
264
+ }
265
+ return reflect;
266
+ },
267
+ has(target, prop) {
268
+ if (prop === 'identifier' || prop === 'owner' || prop === ARRAY_SIGNAL) {
269
+ return true;
270
+ }
271
+ return Reflect.has(target, prop);
272
+ }
273
+ });
274
+ return proxy;
275
+ }
276
+ }
277
+ const ObjectSymbols = new Set([OBJECT_SIGNAL, Parent, SOURCE, Editable, EmbeddedPath]);
278
+
279
+ // const ignoredGlobalFields = new Set<string>(['setInterval', 'nodeType', 'nodeName', 'length', 'document', STRUCTURED]);
280
+
281
+ class ManagedObject {
282
+ constructor(schema, cache, field, data, identifier, path, owner, editable, legacy) {
283
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
284
+ const self = this;
285
+ this[SOURCE] = {
286
+ ...data
287
+ };
288
+ const signals = withSignalStore(this);
289
+ const _SIGNAL = this[OBJECT_SIGNAL] = entangleSignal(signals, this, OBJECT_SIGNAL, undefined);
290
+ this[Editable] = editable;
291
+ this[Legacy] = legacy;
292
+ this[Parent] = identifier;
293
+ this[EmbeddedPath] = path;
294
+ const proxy = new Proxy(this[SOURCE], {
295
+ ownKeys() {
296
+ return Object.keys(self[SOURCE]);
297
+ },
298
+ has(target, prop) {
299
+ return prop in self[SOURCE];
300
+ },
301
+ getOwnPropertyDescriptor(target, prop) {
302
+ return {
303
+ writable: editable,
304
+ enumerable: true,
305
+ configurable: true
306
+ };
307
+ },
308
+ get(target, prop, receiver) {
309
+ if (ObjectSymbols.has(prop)) {
310
+ return self[prop];
311
+ }
312
+ if (prop === Symbol.toPrimitive) {
313
+ return () => null;
314
+ }
315
+ if (prop === Symbol.toStringTag) {
316
+ return `ManagedObject<${identifier.type}:${identifier.id} (${identifier.lid})>`;
317
+ }
318
+ if (prop === 'constructor') {
319
+ return Object;
320
+ }
321
+ if (prop === 'toString') {
322
+ return function () {
323
+ return `ManagedObject<${identifier.type}:${identifier.id} (${identifier.lid})>`;
324
+ };
325
+ }
326
+ if (prop === 'toHTML') {
327
+ return function () {
328
+ return '<span>ManagedObject</span>';
329
+ };
330
+ }
331
+ if (prop === 'toJSON') {
332
+ return function () {
333
+ return structuredClone(self[SOURCE]);
334
+ };
335
+ }
336
+ if (_SIGNAL.isStale) {
337
+ _SIGNAL.isStale = false;
338
+ let newData = cache.getAttr(identifier, path);
339
+ if (newData && newData !== self[SOURCE]) {
340
+ if (field.type) {
341
+ const transform = schema.transformation(field);
342
+ newData = transform.hydrate(newData, field.options ?? null, owner);
343
+ }
344
+ self[SOURCE] = {
345
+ ...newData
346
+ }; // Add type assertion for newData
347
+ }
348
+ }
349
+ if (prop in self[SOURCE]) {
350
+ consumeInternalSignal(_SIGNAL);
351
+ return self[SOURCE][prop];
352
+ }
353
+ return Reflect.get(target, prop, receiver);
354
+ },
355
+ set(target, prop, value, receiver) {
356
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
357
+ if (!test) {
358
+ throw new Error(`Cannot set read-only property '${String(prop)}' on ManagedObject`);
359
+ }
360
+ })(editable) : {};
361
+ const reflect = Reflect.set(target, prop, value, receiver);
362
+ if (!reflect) {
363
+ return false;
364
+ }
365
+ if (!field.type) {
366
+ cache.setAttr(identifier, path, self[SOURCE]);
367
+ } else {
368
+ const transform = schema.transformation(field);
369
+ const val = transform.serialize(self[SOURCE], field.options ?? null, owner);
370
+ cache.setAttr(identifier, path, val);
371
+ }
372
+ _SIGNAL.isStale = true;
373
+ return true;
374
+ }
375
+ });
376
+ return proxy;
377
+ }
378
+ }
379
+ class ManyArrayManager {
380
+ constructor(record, editable) {
381
+ this.record = record;
382
+ this.store = record[RecordStore];
383
+ this.identifier = record[Identifier];
384
+ this.editable = editable;
385
+ }
386
+ _syncArray(array) {
387
+ const method = this.editable ? 'getRelationship' : 'getRemoteRelationship';
388
+ const rawValue = this.store.cache[method](this.identifier, array.key);
389
+ if (rawValue.meta) {
390
+ array.meta = rawValue.meta;
391
+ }
392
+ if (rawValue.links) {
393
+ array.links = rawValue.links;
394
+ }
395
+ const currentState = array[SOURCE$1];
396
+
397
+ // unlike in the normal RecordArray case, we don't need to divorce the reference
398
+ // because we don't need to worry about associate/disassociate since the graph
399
+ // takes care of that for us
400
+ if (currentState !== rawValue.data) {
401
+ currentState.length = 0;
402
+ fastPush(currentState, rawValue.data);
403
+ }
404
+ }
405
+ reloadHasMany(key, options) {
406
+ const field = this.store.schema.fields(this.identifier).get(key);
407
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
408
+ if (!test) {
409
+ throw new Error(`Expected a hasMany field for ${key}`);
410
+ }
411
+ })(field?.kind === 'hasMany') : {};
412
+ const cacheOptions = options ? extractCacheOptions(options) : {
413
+ reload: true
414
+ };
415
+ cacheOptions.types = [field.type];
416
+ const rawValue = this.store.cache.getRelationship(this.identifier, key);
417
+ const req = {
418
+ url: getRelatedLink(rawValue),
419
+ op: 'findHasMany',
420
+ method: 'GET',
421
+ records: rawValue.data,
422
+ cacheOptions,
423
+ options: {
424
+ field,
425
+ identifier: this.identifier,
426
+ links: rawValue.links,
427
+ meta: rawValue.meta
428
+ },
429
+ [EnableHydration]: false
430
+ };
431
+ return this.store.request(req);
432
+ }
433
+ mutate(mutation) {
434
+ this.store.cache.mutate(mutation);
435
+ }
436
+ }
437
+ function getRelatedLink(resource) {
438
+ const related = resource.links?.related;
439
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
440
+ if (!test) {
441
+ throw new Error(`Expected a related link`);
442
+ }
443
+ })(related) : {};
444
+ return typeof related === 'object' ? related.href : related;
445
+ }
446
+ function extractCacheOptions(options) {
447
+ const cacheOptions = {};
448
+ if ('reload' in options) {
449
+ cacheOptions.reload = options.reload;
450
+ }
451
+ if ('backgroundReload' in options) {
452
+ cacheOptions.backgroundReload = options.backgroundReload;
453
+ }
454
+ return cacheOptions;
455
+ }
456
+ const ManagedArrayMap = getOrSetGlobal('ManagedArrayMap', new Map());
457
+ const ManagedObjectMap = getOrSetGlobal('ManagedObjectMap', new Map());
458
+ function computeLocal(record, field, prop) {
459
+ const signals = withSignalStore(record);
460
+ const signal = getOrCreateInternalSignal(signals, record, prop, field.options?.defaultValue ?? null);
461
+ consumeInternalSignal(signal);
462
+ return signal.value;
463
+ }
464
+ function peekManagedArray(record, field) {
465
+ const managedArrayMapForRecord = ManagedArrayMap.get(record);
466
+ if (managedArrayMapForRecord) {
467
+ return managedArrayMapForRecord.get(field.name);
468
+ }
469
+ }
470
+ function peekManagedObject(record, field) {
471
+ const managedObjectMapForRecord = ManagedObjectMap.get(record);
472
+ if (managedObjectMapForRecord) {
473
+ return managedObjectMapForRecord.get(field.name);
474
+ }
475
+ }
476
+ function computeField(schema, cache, record, identifier, field, prop, editable) {
477
+ const rawValue = editable ? cache.getAttr(identifier, prop) : cache.getRemoteAttr(identifier, prop);
478
+ if (!field.type) {
479
+ return rawValue;
480
+ }
481
+ const transform = schema.transformation(field);
482
+ return transform.hydrate(rawValue, field.options ?? null, record);
483
+ }
484
+ function computeArray(store, schema, cache, record, identifier, field, path, editable, legacy) {
485
+ const isSchemaArray = field.kind === 'schema-array';
486
+ // the thing we hand out needs to know its owner and path in a private manner
487
+ // its "address" is the parent identifier (identifier) + field name (field.name)
488
+ // in the nested object case field name here is the full dot path from root resource to this value
489
+ // its "key" is the field on the parent record
490
+ // its "owner" is the parent record
491
+
492
+ const managedArrayMapForRecord = ManagedArrayMap.get(record);
493
+ let managedArray;
494
+ if (managedArrayMapForRecord) {
495
+ managedArray = managedArrayMapForRecord.get(field.name);
496
+ }
497
+ if (managedArray) {
498
+ return managedArray;
499
+ } else {
500
+ const rawValue = editable ? cache.getAttr(identifier, path) : cache.getRemoteAttr(identifier, path);
501
+ if (!rawValue) {
502
+ return null;
503
+ }
504
+ managedArray = new ManagedArray(store, schema, cache, field, rawValue, identifier, path, record, isSchemaArray, editable, legacy);
505
+ if (!managedArrayMapForRecord) {
506
+ ManagedArrayMap.set(record, new Map([[field.name, managedArray]]));
507
+ } else {
508
+ managedArrayMapForRecord.set(field.name, managedArray);
509
+ }
510
+ }
511
+ return managedArray;
512
+ }
513
+ function computeObject(schema, cache, record, identifier, field, path, editable, legacy) {
514
+ const managedObjectMapForRecord = ManagedObjectMap.get(record);
515
+ let managedObject;
516
+ if (managedObjectMapForRecord) {
517
+ managedObject = managedObjectMapForRecord.get(field.name);
518
+ }
519
+ if (managedObject) {
520
+ return managedObject;
521
+ } else {
522
+ let rawValue = editable ? cache.getAttr(identifier, path) : cache.getRemoteAttr(identifier, path);
523
+ if (!rawValue) {
524
+ return null;
525
+ }
526
+ if (field.type) {
527
+ const transform = schema.transformation(field);
528
+ rawValue = transform.hydrate(rawValue, field.options ?? null, record);
529
+ }
530
+ managedObject = new ManagedObject(schema, cache, field, rawValue, identifier, path, record, editable, legacy);
531
+ if (!managedObjectMapForRecord) {
532
+ ManagedObjectMap.set(record, new Map([[field.name, managedObject]]));
533
+ } else {
534
+ managedObjectMapForRecord.set(field.name, managedObject);
535
+ }
536
+ }
537
+ return managedObject;
538
+ }
539
+ function computeSchemaObject(store, cache, record, identifier, field, path, legacy, editable) {
540
+ const schemaObjectMapForRecord = ManagedObjectMap.get(record);
541
+ let schemaObject;
542
+ if (schemaObjectMapForRecord) {
543
+ schemaObject = schemaObjectMapForRecord.get(field.name);
544
+ }
545
+ if (schemaObject) {
546
+ return schemaObject;
547
+ } else {
548
+ const rawValue = editable ? cache.getAttr(identifier, path) : cache.getRemoteAttr(identifier, path);
549
+ if (!rawValue) {
550
+ return null;
551
+ }
552
+ const embeddedPath = path.slice();
553
+ schemaObject = new ReactiveResource(store, identifier, {
554
+ [Editable]: editable,
555
+ [Legacy]: legacy
556
+ }, true, field.type, embeddedPath);
557
+ }
558
+ if (!schemaObjectMapForRecord) {
559
+ ManagedObjectMap.set(record, new Map([[field.name, schemaObject]]));
560
+ } else {
561
+ schemaObjectMapForRecord.set(field.name, schemaObject);
562
+ }
563
+ return schemaObject;
564
+ }
565
+ function computeAttribute(cache, identifier, prop, editable) {
566
+ return editable ? cache.getAttr(identifier, prop) : cache.getRemoteAttr(identifier, prop);
567
+ }
568
+ function computeDerivation(schema, record, identifier, field, prop) {
569
+ return schema.derivation(field)(record, field.options ?? null, prop);
570
+ }
571
+
572
+ // TODO probably this should just be a Document
573
+ // but its separate until we work out the lid situation
574
+ class ResourceRelationship {
575
+ constructor(store, cache, parent, identifier, field, name, editable) {
576
+ const rawValue = editable ? cache.getRelationship(identifier, name) : cache.getRemoteRelationship(identifier, name);
577
+
578
+ // TODO setup true lids for relationship documents
579
+ // @ts-expect-error we need to give relationship documents a lid
580
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
581
+ this.lid = rawValue.lid ?? rawValue.links?.self ?? `relationship:${identifier.lid}.${name}`;
582
+ this.data = rawValue.data ? store.peekRecord(rawValue.data) : null;
583
+ this.name = name;
584
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
585
+ this.links = Object.freeze(Object.assign({}, rawValue.links));
586
+ this.meta = Object.freeze(Object.assign({}, rawValue.meta));
587
+ } else {
588
+ this.links = rawValue.links ?? {};
589
+ this.meta = rawValue.meta ?? {};
590
+ }
591
+ this[RecordStore] = store;
592
+ this[Parent] = parent;
593
+ }
594
+ fetch(options) {
595
+ const url = options?.url ?? getHref(this.links.related) ?? getHref(this.links.self) ?? null;
596
+ if (!url) {
597
+ throw new Error(`Cannot ${options?.method ?? 'fetch'} ${this[Parent][Identifier].type}.${String(this.name)} because it has no related link`);
598
+ }
599
+ const request = Object.assign({
600
+ url,
601
+ method: 'GET'
602
+ }, options);
603
+ return this[RecordStore].request(request);
604
+ }
605
+ }
606
+ defineSignal(ResourceRelationship.prototype, 'data', null);
607
+ defineSignal(ResourceRelationship.prototype, 'links', null);
608
+ defineSignal(ResourceRelationship.prototype, 'meta', null);
609
+ function getHref(link) {
610
+ if (!link) {
611
+ return null;
612
+ }
613
+ if (typeof link === 'string') {
614
+ return link;
615
+ }
616
+ return link.href;
617
+ }
618
+ function computeResource(store, cache, parent, identifier, field, prop, editable) {
619
+ if (field.kind !== 'resource') {
620
+ throw new Error(`The schema for ${identifier.type}.${String(prop)} is not a resource relationship`);
621
+ }
622
+ return new ResourceRelationship(store, cache, parent, identifier, field, prop, editable);
623
+ }
624
+ function computeHasMany(store, schema, cache, record, identifier, field, path, editable, legacy) {
625
+ // the thing we hand out needs to know its owner and path in a private manner
626
+ // its "address" is the parent identifier (identifier) + field name (field.name)
627
+ // in the nested object case field name here is the full dot path from root resource to this value
628
+ // its "key" is the field on the parent record
629
+ // its "owner" is the parent record
630
+
631
+ const managedArrayMapForRecord = ManagedArrayMap.get(record);
632
+ let managedArray;
633
+ if (managedArrayMapForRecord) {
634
+ managedArray = managedArrayMapForRecord.get(field.name);
635
+ }
636
+ if (managedArray) {
637
+ return managedArray;
638
+ } else {
639
+ const rawValue = cache.getRelationship(identifier, field.name);
640
+ if (!rawValue) {
641
+ return null;
642
+ }
643
+ managedArray = new RelatedCollection({
644
+ store,
645
+ type: field.type,
646
+ identifier,
647
+ cache,
648
+ // we divorce the reference here because ManyArray mutates the target directly
649
+ // before sending the mutation op to the cache. We may be able to avoid this in the future
650
+ identifiers: rawValue.data?.slice(),
651
+ key: field.name,
652
+ meta: rawValue.meta || null,
653
+ links: rawValue.links || null,
654
+ isPolymorphic: field.options.polymorphic ?? false,
655
+ isAsync: field.options.async ?? false,
656
+ // TODO: Grab the proper value
657
+ _inverseIsAsync: false,
658
+ // @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
659
+ manager: new ManyArrayManager(record, editable),
660
+ isLoaded: true,
661
+ allowMutation: editable
662
+ });
663
+ if (!managedArrayMapForRecord) {
664
+ ManagedArrayMap.set(record, new Map([[field.name, managedArray]]));
665
+ } else {
666
+ managedArrayMapForRecord.set(field.name, managedArray);
667
+ }
668
+ }
669
+ return managedArray;
670
+ }
671
+ const IgnoredGlobalFields = new Set(['length', 'nodeType', 'then', 'setInterval', 'document', STRUCTURED]);
672
+ const symbolList = [Destroy, RecordStore, Identifier, Editable, Parent, Checkout, Legacy, EmbeddedPath, EmbeddedType];
673
+ const RecordSymbols = new Set(symbolList);
674
+ function isPathMatch(a, b) {
675
+ return a.length === b.length && a.every((v, i) => v === b[i]);
676
+ }
677
+ function isNonEnumerableProp(prop) {
678
+ return prop === 'constructor' || prop === 'prototype' || prop === '__proto__' || prop === 'toString' || prop === 'toJSON' || prop === 'toHTML' || typeof prop === 'symbol';
679
+ }
680
+ const Editables = new WeakMap();
681
+ /**
682
+ * A class that uses a the ResourceSchema for a ResourceType
683
+ * and a ResouceKey to transform data from the cache into a rich, reactive
684
+ * object.
685
+ *
686
+ * This class is not directly instantiable. To use it, you should
687
+ * configure the store's `instantiateRecord` and `teardownRecord` hooks
688
+ * with the matching hooks provided by this package.
689
+ *
690
+ * @hideconstructor
691
+ * @public
692
+ */
693
+ class ReactiveResource {
694
+ /** @internal */
695
+
696
+ /** @internal */
697
+
698
+ /** @internal */
699
+
700
+ /** @internal */
701
+
702
+ /** @internal */
703
+
704
+ /** @internal */
705
+
706
+ /** @internal */
707
+
708
+ /** @internal */
709
+
710
+ constructor(store, identifier, Mode, isEmbedded = false, embeddedType = null, embeddedPath = null) {
711
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
712
+ const self = this;
713
+ this[RecordStore] = store;
714
+ if (isEmbedded) {
715
+ this[Parent] = identifier;
716
+ } else {
717
+ this[Identifier] = identifier;
718
+ }
719
+ const IS_EDITABLE = this[Editable] = Mode[Editable] ?? false;
720
+ this[Legacy] = Mode[Legacy] ?? false;
721
+ const schema = store.schema;
722
+ const cache = store.cache;
723
+ const identityField = schema.resource(isEmbedded ? {
724
+ type: embeddedType
725
+ } : identifier).identity;
726
+ const BoundFns = new Map();
727
+ this[EmbeddedType] = embeddedType;
728
+ this[EmbeddedPath] = embeddedPath;
729
+ const fields = isEmbedded ? schema.fields({
730
+ type: embeddedType
731
+ }) : schema.fields(identifier);
732
+ const signals = withSignalStore(this);
733
+ const proxy = new Proxy(this, {
734
+ ownKeys() {
735
+ const identityKey = identityField?.name;
736
+ const keys = Array.from(fields.keys());
737
+ if (identityKey) {
738
+ keys.unshift(identityKey);
739
+ }
740
+ return keys;
741
+ },
742
+ has(target, prop) {
743
+ if (prop === Destroy || prop === Checkout) {
744
+ return true;
745
+ }
746
+ return fields.has(prop);
747
+ },
748
+ getOwnPropertyDescriptor(target, prop) {
749
+ const schemaForField = prop === identityField?.name ? identityField : fields.get(prop);
750
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
751
+ if (!test) {
752
+ throw new Error(`No field named ${String(prop)} on ${identifier.type}`);
753
+ }
754
+ })(schemaForField) : {};
755
+ if (isNonEnumerableProp(prop)) {
756
+ return {
757
+ writable: false,
758
+ enumerable: false,
759
+ configurable: true
760
+ };
761
+ }
762
+ switch (schemaForField.kind) {
763
+ case 'derived':
764
+ return {
765
+ writable: false,
766
+ enumerable: true,
767
+ configurable: true
768
+ };
769
+ case '@id':
770
+ return {
771
+ writable: identifier.id === null,
772
+ enumerable: true,
773
+ configurable: true
774
+ };
775
+ case '@local':
776
+ case 'field':
777
+ case 'attribute':
778
+ case 'resource':
779
+ case 'alias':
780
+ case 'belongsTo':
781
+ case 'hasMany':
782
+ case 'collection':
783
+ case 'schema-array':
784
+ case 'array':
785
+ case 'schema-object':
786
+ case 'object':
787
+ return {
788
+ writable: IS_EDITABLE,
789
+ enumerable: true,
790
+ configurable: true
791
+ };
792
+ default:
793
+ return {
794
+ writable: false,
795
+ enumerable: false,
796
+ configurable: false
797
+ };
798
+ }
799
+ },
800
+ get(target, prop, receiver) {
801
+ if (RecordSymbols.has(prop)) {
802
+ return target[prop];
803
+ }
804
+ if (prop === Signals) {
805
+ return signals;
806
+ }
807
+
808
+ // TODO make this a symbol
809
+ if (prop === '___notifications') {
810
+ return target.___notifications;
811
+ }
812
+
813
+ // ReactiveResource reserves use of keys that begin with these characters
814
+ // for its own usage.
815
+ // _, @, $, *
816
+
817
+ const maybeField = prop === identityField?.name ? identityField : fields.get(prop);
818
+ if (!maybeField) {
819
+ if (IgnoredGlobalFields.has(prop)) {
820
+ return undefined;
821
+ }
822
+
823
+ /////////////////////////////////////////////////////////////
824
+ //// Note these bound function behaviors are essentially ////
825
+ //// built-in but overrideable derivations. ////
826
+ //// ////
827
+ //// The bar for this has to be "basic expectations of ////
828
+ /// an object" – very, very high ////
829
+ /////////////////////////////////////////////////////////////
830
+
831
+ if (prop === Symbol.toStringTag || prop === 'toString') {
832
+ let fn = BoundFns.get('toString');
833
+ if (!fn) {
834
+ fn = function () {
835
+ entangleSignal(signals, receiver, '@identity', null);
836
+ return `Record<${identifier.type}:${identifier.id} (${identifier.lid})>`;
837
+ };
838
+ BoundFns.set(prop, fn);
839
+ }
840
+ return fn;
841
+ }
842
+ if (prop === 'toHTML') {
843
+ let fn = BoundFns.get('toHTML');
844
+ if (!fn) {
845
+ fn = function () {
846
+ entangleSignal(signals, receiver, '@identity', null);
847
+ return `<span>Record<${identifier.type}:${identifier.id} (${identifier.lid})></span>`;
848
+ };
849
+ BoundFns.set(prop, fn);
850
+ }
851
+ return fn;
852
+ }
853
+ if (prop === 'toJSON') {
854
+ let fn = BoundFns.get('toJSON');
855
+ if (!fn) {
856
+ fn = function () {
857
+ const json = {};
858
+ for (const key in receiver) {
859
+ json[key] = receiver[key];
860
+ }
861
+ return json;
862
+ };
863
+ BoundFns.set(prop, fn);
864
+ }
865
+ return fn;
866
+ }
867
+ if (prop === Symbol.toPrimitive) return () => null;
868
+ if (prop === Symbol.iterator) {
869
+ let fn = BoundFns.get(Symbol.iterator);
870
+ if (!fn) {
871
+ fn = function* () {
872
+ for (const key in receiver) {
873
+ yield [key, receiver[key]];
874
+ }
875
+ };
876
+ BoundFns.set(Symbol.iterator, fn);
877
+ }
878
+ return fn;
879
+ }
880
+ if (prop === 'constructor') {
881
+ return ReactiveResource;
882
+ }
883
+ // too many things check for random symbols
884
+ if (typeof prop === 'symbol') return undefined;
885
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
886
+ {
887
+ throw new Error(`No field named ${String(prop)} on ${isEmbedded ? embeddedType : identifier.type}`);
888
+ }
889
+ })() : {};
890
+ return undefined;
891
+ }
892
+ const field = maybeField.kind === 'alias' ? maybeField.options : maybeField;
893
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
894
+ if (!test) {
895
+ throw new Error(`Alias fields cannot alias '@id' '@local' '@hash' or 'derived' fields`);
896
+ }
897
+ })(maybeField.kind !== 'alias' || !['@id', '@local', '@hash', 'derived'].includes(maybeField.options.kind)) : {};
898
+ const propArray = isEmbedded ? embeddedPath.slice() : [];
899
+ // we use the field.name instead of prop here because we want to use the cache-path not
900
+ // the record path.
901
+ propArray.push(field.name);
902
+ // propArray.push(prop as string);
903
+
904
+ switch (field.kind) {
905
+ case '@id':
906
+ entangleSignal(signals, receiver, '@identity', null);
907
+ return identifier.id;
908
+ case '@hash':
909
+ // TODO pass actual cache value not {}
910
+ return schema.hashFn(field)({}, field.options ?? null, field.name ?? null);
911
+ case '@local':
912
+ {
913
+ return computeLocal(receiver, field, prop);
914
+ }
915
+ case 'field':
916
+ entangleSignal(signals, receiver, field.name, null);
917
+ return computeField(schema, cache, target, identifier, field, propArray, IS_EDITABLE);
918
+ case 'attribute':
919
+ entangleSignal(signals, receiver, field.name, null);
920
+ return computeAttribute(cache, identifier, prop, IS_EDITABLE);
921
+ case 'resource':
922
+ entangleSignal(signals, receiver, field.name, null);
923
+ return computeResource(store, cache, target, identifier, field, prop, IS_EDITABLE);
924
+ case 'derived':
925
+ return computeDerivation(schema, receiver, identifier, field, prop);
926
+ case 'schema-array':
927
+ case 'array':
928
+ entangleSignal(signals, receiver, field.name, null);
929
+ return computeArray(store, schema, cache, target, identifier, field, propArray, Mode[Editable], Mode[Legacy]);
930
+ case 'object':
931
+ entangleSignal(signals, receiver, field.name, null);
932
+ return computeObject(schema, cache, target, identifier, field, propArray, Mode[Editable], Mode[Legacy]);
933
+ case 'schema-object':
934
+ entangleSignal(signals, receiver, field.name, null);
935
+ // run transform, then use that value as the object to manage
936
+ return computeSchemaObject(store, cache, target, identifier, field, propArray, Mode[Legacy], Mode[Editable]);
937
+ case 'belongsTo':
938
+ if (field.options.linksMode) {
939
+ entangleSignal(signals, receiver, field.name, null);
940
+ const rawValue = IS_EDITABLE ? cache.getRelationship(identifier, field.name) : cache.getRemoteRelationship(identifier, field.name);
941
+
942
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
943
+ return rawValue.data ? store.peekRecord(rawValue.data) : null;
944
+ }
945
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
946
+ if (!test) {
947
+ throw new Error(`Can only use belongsTo fields when the resource is in legacy mode`);
948
+ }
949
+ })(Mode[Legacy]) : {};
950
+ entangleSignal(signals, receiver, field.name, null);
951
+ return schema._kind('@legacy', 'belongsTo').get(store, receiver, identifier, field);
952
+ case 'hasMany':
953
+ if (field.options.linksMode) {
954
+ entangleSignal(signals, receiver, field.name, null);
955
+ return computeHasMany(store, schema, cache, target, identifier, field, propArray, Mode[Editable], Mode[Legacy]);
956
+ }
957
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
958
+ if (!test) {
959
+ throw new Error(`Can only use hasMany fields when the resource is in legacy mode`);
960
+ }
961
+ })(Mode[Legacy]) : {};
962
+ entangleSignal(signals, receiver, field.name, null);
963
+ return schema._kind('@legacy', 'hasMany').get(store, receiver, identifier, field);
964
+ default:
965
+ throw new Error(`Field '${String(prop)}' on '${identifier.type}' has the unknown kind '${field.kind}'`);
966
+ }
967
+ },
968
+ set(target, prop, value, receiver) {
969
+ if (!IS_EDITABLE) {
970
+ const type = isEmbedded ? embeddedType : identifier.type;
971
+ throw new Error(`Cannot set ${String(prop)} on ${type} because the record is not editable`);
972
+ }
973
+ const maybeField = prop === identityField?.name ? identityField : fields.get(prop);
974
+ if (!maybeField) {
975
+ const type = isEmbedded ? embeddedType : identifier.type;
976
+ throw new Error(`There is no field named ${String(prop)} on ${type}`);
977
+ }
978
+ const field = maybeField.kind === 'alias' ? maybeField.options : maybeField;
979
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
980
+ if (!test) {
981
+ throw new Error(`Alias fields cannot alias '@id' '@local' '@hash' or 'derived' fields`);
982
+ }
983
+ })(maybeField.kind !== 'alias' || !['@id', '@local', '@hash', 'derived'].includes(maybeField.options.kind)) : {};
984
+ const propArray = isEmbedded ? embeddedPath.slice() : [];
985
+ // we use the field.name instead of prop here because we want to use the cache-path not
986
+ // the record path.
987
+ propArray.push(field.name);
988
+ // propArray.push(prop as string);
989
+
990
+ switch (field.kind) {
991
+ case '@id':
992
+ {
993
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
994
+ if (!test) {
995
+ throw new Error(`Expected to receive a string id`);
996
+ }
997
+ })(typeof value === 'string' && value.length) : {};
998
+ const normalizedId = String(value);
999
+ const didChange = normalizedId !== identifier.id;
1000
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1001
+ if (!test) {
1002
+ throw new Error(`Cannot set ${identifier.type} record's id to ${normalizedId}, because id is already ${identifier.id}`);
1003
+ }
1004
+ })(!didChange || identifier.id === null) : {};
1005
+ if (normalizedId !== null && didChange) {
1006
+ store._instanceCache.setRecordId(identifier, normalizedId);
1007
+ store.notifications.notify(identifier, 'identity');
1008
+ }
1009
+ return true;
1010
+ }
1011
+ case '@local':
1012
+ {
1013
+ const signal = getOrCreateInternalSignal(signals, receiver, prop, field.options?.defaultValue ?? null);
1014
+ if (signal.value !== value) {
1015
+ signal.value = value;
1016
+ notifyInternalSignal(signal);
1017
+ }
1018
+ return true;
1019
+ }
1020
+ case 'field':
1021
+ {
1022
+ if (!field.type) {
1023
+ cache.setAttr(identifier, propArray, value);
1024
+ return true;
1025
+ }
1026
+ const transform = schema.transformation(field);
1027
+ const rawValue = transform.serialize(value, field.options ?? null, target);
1028
+ cache.setAttr(identifier, propArray, rawValue);
1029
+ return true;
1030
+ }
1031
+ case 'attribute':
1032
+ {
1033
+ cache.setAttr(identifier, propArray, value);
1034
+ return true;
1035
+ }
1036
+ case 'array':
1037
+ {
1038
+ if (!field.type) {
1039
+ cache.setAttr(identifier, propArray, value?.slice());
1040
+ const peeked = peekManagedArray(self, field);
1041
+ if (peeked) {
1042
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1043
+ if (!test) {
1044
+ throw new Error(`Expected the peekManagedArray for ${field.kind} to return a ManagedArray`);
1045
+ }
1046
+ })(ARRAY_SIGNAL in peeked) : {};
1047
+ const arrSignal = peeked[ARRAY_SIGNAL];
1048
+ arrSignal.isStale = true;
1049
+ }
1050
+ if (!Array.isArray(value)) {
1051
+ ManagedArrayMap.delete(target);
1052
+ }
1053
+ return true;
1054
+ }
1055
+ const transform = schema.transformation(field);
1056
+ const rawValue = value.map(item => transform.serialize(item, field.options ?? null, target));
1057
+ cache.setAttr(identifier, propArray, rawValue);
1058
+ const peeked = peekManagedArray(self, field);
1059
+ if (peeked) {
1060
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1061
+ if (!test) {
1062
+ throw new Error(`Expected the peekManagedArray for ${field.kind} to return a ManagedArray`);
1063
+ }
1064
+ })(ARRAY_SIGNAL in peeked) : {};
1065
+ const arrSignal = peeked[ARRAY_SIGNAL];
1066
+ arrSignal.isStale = true;
1067
+ }
1068
+ return true;
1069
+ }
1070
+ case 'schema-array':
1071
+ {
1072
+ const arrayValue = value?.slice();
1073
+ if (!Array.isArray(arrayValue)) {
1074
+ ManagedArrayMap.delete(target);
1075
+ }
1076
+ cache.setAttr(identifier, propArray, arrayValue);
1077
+ const peeked = peekManagedArray(self, field);
1078
+ if (peeked) {
1079
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1080
+ if (!test) {
1081
+ throw new Error(`Expected the peekManagedArray for ${field.kind} to return a ManagedArray`);
1082
+ }
1083
+ })(ARRAY_SIGNAL in peeked) : {};
1084
+ const arrSignal = peeked[ARRAY_SIGNAL];
1085
+ arrSignal.isStale = true;
1086
+ }
1087
+ if (!Array.isArray(value)) {
1088
+ ManagedArrayMap.delete(target);
1089
+ }
1090
+ return true;
1091
+ }
1092
+ case 'object':
1093
+ {
1094
+ if (!field.type) {
1095
+ let newValue = value;
1096
+ if (value !== null) {
1097
+ newValue = {
1098
+ ...value
1099
+ };
1100
+ } else {
1101
+ ManagedObjectMap.delete(target);
1102
+ }
1103
+ cache.setAttr(identifier, propArray, newValue);
1104
+ const peeked = peekManagedObject(self, field);
1105
+ if (peeked) {
1106
+ const objSignal = peeked[OBJECT_SIGNAL];
1107
+ objSignal.isStale = true;
1108
+ }
1109
+ return true;
1110
+ }
1111
+ const transform = schema.transformation(field);
1112
+ const rawValue = transform.serialize({
1113
+ ...value
1114
+ }, field.options ?? null, target);
1115
+ cache.setAttr(identifier, propArray, rawValue);
1116
+ const peeked = peekManagedObject(self, field);
1117
+ if (peeked) {
1118
+ const objSignal = peeked[OBJECT_SIGNAL];
1119
+ objSignal.isStale = true;
1120
+ }
1121
+ return true;
1122
+ }
1123
+ case 'schema-object':
1124
+ {
1125
+ let newValue = value;
1126
+ if (value !== null) {
1127
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1128
+ if (!test) {
1129
+ throw new Error(`Expected value to be an object`);
1130
+ }
1131
+ })(typeof value === 'object') : {};
1132
+ newValue = {
1133
+ ...value
1134
+ };
1135
+ const schemaFields = schema.fields({
1136
+ type: field.type
1137
+ });
1138
+ for (const key of Object.keys(newValue)) {
1139
+ if (!schemaFields.has(key)) {
1140
+ throw new Error(`Field ${key} does not exist on schema object ${field.type}`);
1141
+ }
1142
+ }
1143
+ } else {
1144
+ ManagedObjectMap.delete(target);
1145
+ }
1146
+ cache.setAttr(identifier, propArray, newValue);
1147
+ // const peeked = peekManagedObject(self, field);
1148
+ // if (peeked) {
1149
+ // const objSignal = peeked[OBJECT_SIGNAL];
1150
+ // objSignal.isStale = true;
1151
+ // }
1152
+ return true;
1153
+ }
1154
+ case 'derived':
1155
+ {
1156
+ throw new Error(`Cannot set ${String(prop)} on ${identifier.type} because it is derived`);
1157
+ }
1158
+ case 'belongsTo':
1159
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1160
+ if (!test) {
1161
+ throw new Error(`Can only use belongsTo fields when the resource is in legacy mode`);
1162
+ }
1163
+ })(Mode[Legacy]) : {};
1164
+ schema._kind('@legacy', 'belongsTo').set(store, receiver, identifier, field, value);
1165
+ return true;
1166
+ case 'hasMany':
1167
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1168
+ if (!test) {
1169
+ throw new Error(`Can only use hasMany fields when the resource is in legacy mode`);
1170
+ }
1171
+ })(Mode[Legacy]) : {};
1172
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1173
+ if (!test) {
1174
+ throw new Error(`You must pass an array of records to set a hasMany relationship`);
1175
+ }
1176
+ })(Array.isArray(value)) : {};
1177
+ schema._kind('@legacy', 'hasMany').set(store, receiver, identifier, field, value);
1178
+ return true;
1179
+ default:
1180
+ throw new Error(`Unknown field kind ${field.kind}`);
1181
+ }
1182
+ }
1183
+ });
1184
+
1185
+ // what signal do we need for embedded record?
1186
+ this.___notifications = store.notifications.subscribe(identifier, (_, type, key) => {
1187
+ switch (type) {
1188
+ case 'identity':
1189
+ {
1190
+ if (isEmbedded || !identityField) return; // base paths never apply to embedded records
1191
+
1192
+ if (identityField.name && identityField.kind === '@id') {
1193
+ const signal = signals.get('@identity');
1194
+ if (signal) {
1195
+ notifyInternalSignal(signal);
1196
+ }
1197
+ }
1198
+ break;
1199
+ }
1200
+ case 'attributes':
1201
+ if (key) {
1202
+ if (Array.isArray(key)) {
1203
+ if (!isEmbedded) return; // deep paths will be handled by embedded records
1204
+ // TODO we should have the notification manager
1205
+ // ensure it is safe for each callback to mutate this array
1206
+ if (isPathMatch(embeddedPath, key)) {
1207
+ // handle the notification
1208
+ // TODO we should likely handle this notification here
1209
+ // also we should add a LOGGING flag
1210
+ // eslint-disable-next-line no-console
1211
+ console.warn(`Notification unhandled for ${key.join(',')} on ${identifier.type}`, self);
1212
+ return;
1213
+ }
1214
+
1215
+ // TODO we should add a LOGGING flag
1216
+ // console.log(`Deep notification skipped for ${key.join('.')} on ${identifier.type}`, self);
1217
+ // deep notify the key path
1218
+ } else {
1219
+ if (isEmbedded) return; // base paths never apply to embedded records
1220
+
1221
+ // TODO determine what LOGGING flag to wrap this in if any
1222
+ // console.log(`Notification for ${key} on ${identifier.type}`, self);
1223
+ const signal = signals.get(key);
1224
+ if (signal) {
1225
+ notifyInternalSignal(signal);
1226
+ }
1227
+ const field = fields.get(key);
1228
+ if (field?.kind === 'array' || field?.kind === 'schema-array') {
1229
+ const peeked = peekManagedArray(self, field);
1230
+ if (peeked) {
1231
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1232
+ if (!test) {
1233
+ throw new Error(`Expected the peekManagedArray for ${field.kind} to return a ManagedArray`);
1234
+ }
1235
+ })(ARRAY_SIGNAL in peeked) : {};
1236
+ const arrSignal = peeked[ARRAY_SIGNAL];
1237
+ notifyInternalSignal(arrSignal);
1238
+ }
1239
+ }
1240
+ if (field?.kind === 'object') {
1241
+ const peeked = peekManagedObject(self, field);
1242
+ if (peeked) {
1243
+ const objSignal = peeked[OBJECT_SIGNAL];
1244
+ notifyInternalSignal(objSignal);
1245
+ }
1246
+ }
1247
+ }
1248
+ }
1249
+ break;
1250
+ case 'relationships':
1251
+ if (key) {
1252
+ if (Array.isArray(key)) ;else {
1253
+ if (isEmbedded) return; // base paths never apply to embedded records
1254
+
1255
+ const field = fields.get(key);
1256
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1257
+ if (!test) {
1258
+ throw new Error(`Expected relationshp ${key} to be the name of a field`);
1259
+ }
1260
+ })(field) : {};
1261
+ if (field.kind === 'belongsTo') {
1262
+ // TODO determine what LOGGING flag to wrap this in if any
1263
+ // console.log(`Notification for ${key} on ${identifier.type}`, self);
1264
+ const signal = signals.get(key);
1265
+ if (signal) {
1266
+ notifyInternalSignal(signal);
1267
+ }
1268
+ // FIXME
1269
+ } else if (field.kind === 'resource') ;else if (field.kind === 'hasMany') {
1270
+ if (field.options.linksMode) {
1271
+ const peeked = peekManagedArray(self, field);
1272
+ if (peeked) {
1273
+ notifyInternalSignal(peeked[ARRAY_SIGNAL]);
1274
+ }
1275
+ return;
1276
+ }
1277
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1278
+ if (!test) {
1279
+ throw new Error(`Can only use hasMany fields when the resource is in legacy mode`);
1280
+ }
1281
+ })(Mode[Legacy]) : {};
1282
+ if (schema._kind('@legacy', 'hasMany').notify(store, proxy, identifier, field)) {
1283
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1284
+ if (!test) {
1285
+ throw new Error(`Expected options to exist on relationship meta`);
1286
+ }
1287
+ })(field.options) : {};
1288
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1289
+ if (!test) {
1290
+ throw new Error(`Expected async to exist on relationship meta options`);
1291
+ }
1292
+ })('async' in field.options) : {};
1293
+ if (field.options.async) {
1294
+ const signal = signals.get(key);
1295
+ if (signal) {
1296
+ notifyInternalSignal(signal);
1297
+ }
1298
+ }
1299
+ }
1300
+ } else if (field.kind === 'collection') ;
1301
+ }
1302
+ }
1303
+ break;
1304
+ }
1305
+ });
1306
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1307
+ Object.defineProperty(this, '__SHOW_ME_THE_DATA_(debug mode only)__', {
1308
+ enumerable: false,
1309
+ configurable: true,
1310
+ get() {
1311
+ const data = {};
1312
+ for (const key of fields.keys()) {
1313
+ data[key] = proxy[key];
1314
+ }
1315
+ return data;
1316
+ }
1317
+ });
1318
+ }
1319
+ return proxy;
1320
+ }
1321
+
1322
+ /** @internal */
1323
+ [Destroy]() {
1324
+ if (this[Legacy]) {
1325
+ // @ts-expect-error
1326
+ this.isDestroying = true;
1327
+ // @ts-expect-error
1328
+ this.isDestroyed = true;
1329
+ }
1330
+ this[RecordStore].notifications.unsubscribe(this.___notifications);
1331
+ }
1332
+
1333
+ /**
1334
+ * Create an editable copy of the record
1335
+ *
1336
+ * ReactiveResource instances are not editable by default. This method creates an editable copy of the record. To use,
1337
+ * import the `Checkout` symbol from `@warp-drive/schema-record` and call it on the record.
1338
+ *
1339
+ * ```ts
1340
+ * import { Checkout } from '@warp-drive/schema-record';
1341
+ *
1342
+ * const record = store.peekRecord('user', '1');
1343
+ * const editableRecord = await record[Checkout]();
1344
+ * ```
1345
+ *
1346
+ * @returns a promise that resolves to the editable record
1347
+ * @throws if the record is already editable or if the record is embedded
1348
+ *
1349
+ */
1350
+ [Checkout]() {
1351
+ // IF we are already the editable record, throw an error
1352
+ if (this[Editable]) {
1353
+ throw new Error(`Cannot checkout an already editable record`);
1354
+ }
1355
+ const editable = Editables.get(this);
1356
+ if (editable) {
1357
+ return Promise.resolve(editable);
1358
+ }
1359
+ const embeddedType = this[EmbeddedType];
1360
+ const embeddedPath = this[EmbeddedPath];
1361
+ const isEmbedded = embeddedType !== null && embeddedPath !== null;
1362
+ if (isEmbedded) {
1363
+ throw new Error(`Cannot checkout an embedded record (yet)`);
1364
+ }
1365
+ const editableRecord = new ReactiveResource(this[RecordStore], this[Identifier], {
1366
+ [Editable]: true,
1367
+ [Legacy]: this[Legacy]
1368
+ }, isEmbedded, embeddedType, embeddedPath);
1369
+ setRecordIdentifier(editableRecord, recordIdentifierFor(this));
1370
+ return Promise.resolve(editableRecord);
1371
+ }
1372
+ }
1373
+ function instantiateRecord(store, identifier, createArgs) {
1374
+ const schema = store.schema;
1375
+ const resourceSchema = schema.resource(identifier);
1376
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1377
+ if (!test) {
1378
+ throw new Error(`Expected a resource schema`);
1379
+ }
1380
+ })(isResourceSchema(resourceSchema)) : {};
1381
+ const isLegacy = resourceSchema?.legacy ?? false;
1382
+ const isEditable = isLegacy || store.cache.isNew(identifier);
1383
+ const record = new ReactiveResource(store, identifier, {
1384
+ [Editable]: isEditable,
1385
+ [Legacy]: isLegacy
1386
+ });
1387
+ if (createArgs) {
1388
+ Object.assign(record, createArgs);
1389
+ }
1390
+ return record;
1391
+ }
1392
+ function assertReactiveResource(record) {
1393
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1394
+ if (!test) {
1395
+ throw new Error('Expected a ReactiveResource');
1396
+ }
1397
+ })(record && typeof record === 'object' && Destroy in record) : {};
1398
+ }
1399
+ function teardownRecord(record) {
1400
+ assertReactiveResource(record);
1401
+ record[Destroy]();
1402
+ }
1403
+ const Support = getOrSetGlobal('Support', new WeakMap());
1404
+ const ConstructorField = {
1405
+ type: '@constructor',
1406
+ name: 'constructor',
1407
+ kind: 'derived'
1408
+ };
1409
+ const TypeField = {
1410
+ type: '@identity',
1411
+ name: '$type',
1412
+ kind: 'derived',
1413
+ options: {
1414
+ key: 'type'
1415
+ }
1416
+ };
1417
+ const DefaultIdentityField = {
1418
+ name: 'id',
1419
+ kind: '@id'
1420
+ };
1421
+ function _constructor(record) {
1422
+ let state = Support.get(record);
1423
+ if (!state) {
1424
+ state = {};
1425
+ Support.set(record, state);
1426
+ }
1427
+ return state._constructor = state._constructor || {
1428
+ name: `ReactiveResource<${recordIdentifierFor(record).type}>`,
1429
+ get modelName() {
1430
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1431
+ {
1432
+ throw new Error(`record.constructor.modelName is not available outside of legacy mode`);
1433
+ }
1434
+ })() : {};
1435
+ return undefined;
1436
+ }
1437
+ };
1438
+ }
1439
+ _constructor[Type] = '@constructor';
1440
+
1441
+ /**
1442
+ * Utility for constructing a ResourceSchema with the recommended
1443
+ * fields for the PolarisMode experience.
1444
+ *
1445
+ * Using this requires registering the PolarisMode derivations
1446
+ *
1447
+ * ```ts
1448
+ * import { registerDerivations } from '@warp-drive/schema-record';
1449
+ *
1450
+ * registerDerivations(schema);
1451
+ * ```
1452
+ *
1453
+ * @public
1454
+ * @param schema
1455
+ * @return {PolarisResourceSchema}
1456
+ */
1457
+ function withDefaults(schema) {
1458
+ schema.identity = schema.identity || DefaultIdentityField;
1459
+
1460
+ // because fields gets iterated in definition order,
1461
+ // we add TypeField to the beginning so that it will
1462
+ // appear right next to the identity field
1463
+ schema.fields.unshift(TypeField);
1464
+ schema.fields.push(ConstructorField);
1465
+ return schema;
1466
+ }
1467
+
1468
+ /**
1469
+ * A derivation that computes its value from the
1470
+ * record's identity.
1471
+ *
1472
+ * It can be used via a derived field definition like:
1473
+ *
1474
+ * ```ts
1475
+ * {
1476
+ * kind: 'derived',
1477
+ * name: 'id',
1478
+ * type: '@identity',
1479
+ * options: { key: 'id' }
1480
+ * }
1481
+ * ```
1482
+ *
1483
+ * Valid keys are `'id'`, `'lid'`, `'type'`, and `'^'`.
1484
+ *
1485
+ * `^` returns the entire identifier object.
1486
+ *
1487
+ * @public
1488
+ */
1489
+
1490
+ function fromIdentity(record, options, key) {
1491
+ const identifier = record[Identifier];
1492
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1493
+ if (!test) {
1494
+ throw new Error(`Cannot compute @identity for a record without an identifier`);
1495
+ }
1496
+ })(identifier) : {};
1497
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1498
+ if (!test) {
1499
+ throw new Error(`Expected to receive a key to compute @identity, but got ${String(options)}`);
1500
+ }
1501
+ })(options?.key && ['lid', 'id', 'type', '^'].includes(options.key)) : {};
1502
+ return options.key === '^' ? identifier : identifier[options.key];
1503
+ }
1504
+ fromIdentity[Type] = '@identity';
1505
+
1506
+ /**
1507
+ * Registers the default derivations for records that want
1508
+ * to use the PolarisMode defaults provided by
1509
+ *
1510
+ * ```ts
1511
+ * import { withDefaults } from '@warp-drive/schema-record';
1512
+ * ```
1513
+ *
1514
+ * @public
1515
+ * @param {SchemaService} schema
1516
+ */
1517
+ function registerDerivations(schema) {
1518
+ schema.registerDerivation(fromIdentity);
1519
+ schema.registerDerivation(_constructor);
1520
+ }
1521
+ /**
1522
+ * Wraps a derivation in a new function with Derivation signature but that looks
1523
+ * up the value in the cache before recomputing.
1524
+ *
1525
+ * @internal
1526
+ */
1527
+ function makeCachedDerivation(derivation) {
1528
+ const memoizedDerivation = (record, options, prop) => {
1529
+ const signals = withSignalStore(record);
1530
+ let signal = signals.get(prop);
1531
+ if (!signal) {
1532
+ signal = createMemo(record, prop, () => {
1533
+ return derivation(record, options, prop);
1534
+ }); // a total lie, for convenience of reusing the storage
1535
+ signals.set(prop, signal);
1536
+ }
1537
+ return signal();
1538
+ };
1539
+ memoizedDerivation[Type] = derivation[Type];
1540
+ return memoizedDerivation;
1541
+ }
1542
+ /**
1543
+ * A SchemaService designed to work with dynamically registered schemas.
1544
+ *
1545
+ * @class SchemaService
1546
+ * @public
1547
+ */
1548
+ class SchemaService {
1549
+ /** @internal */
1550
+
1551
+ /** @internal */
1552
+
1553
+ /** @internal */
1554
+
1555
+ /** @internal */
1556
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1557
+
1558
+ /** @internal */
1559
+
1560
+ /** @internal */
1561
+
1562
+ constructor() {
1563
+ this._schemas = new Map();
1564
+ this._transforms = new Map();
1565
+ this._hashFns = new Map();
1566
+ this._derivations = new Map();
1567
+ this._traits = new Set();
1568
+ this._modes = new Map();
1569
+ }
1570
+ resourceTypes() {
1571
+ return Array.from(this._schemas.keys());
1572
+ }
1573
+ hasTrait(type) {
1574
+ return this._traits.has(type);
1575
+ }
1576
+ resourceHasTrait(resource, trait) {
1577
+ return this._schemas.get(resource.type).traits.has(trait);
1578
+ }
1579
+ transformation(field) {
1580
+ const kind = 'kind' in field ? field.kind : '<unknown kind>';
1581
+ const name = 'name' in field ? field.name : '<unknown name>';
1582
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1583
+ if (!test) {
1584
+ throw new Error(`'${kind}' fields cannot be transformed. Only fields of kind 'field' 'object' or 'array' can specify a transformation. Attempted to find '${field.type ?? '<unknown type>'}' on field '${name}'.`);
1585
+ }
1586
+ })(!('kind' in field) || ['field', 'object', 'array'].includes(kind)) : {};
1587
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1588
+ if (!test) {
1589
+ throw new Error(`Expected the '${kind}' field '${name}' to specify a transformation via 'field.type', but none was present`);
1590
+ }
1591
+ })(field.type) : {};
1592
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1593
+ if (!test) {
1594
+ throw new Error(`No transformation registered with name '${field.type}' for '${kind}' field '${name}'`);
1595
+ }
1596
+ })(this._transforms.has(field.type)) : {};
1597
+ return this._transforms.get(field.type);
1598
+ }
1599
+ derivation(field) {
1600
+ const kind = 'kind' in field ? field.kind : '<unknown kind>';
1601
+ const name = 'name' in field ? field.name : '<unknown name>';
1602
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1603
+ if (!test) {
1604
+ throw new Error(`The '${kind}' field '${name}' is not derived and so cannot be used to lookup a derivation`);
1605
+ }
1606
+ })(!('kind' in field) || kind === 'derived') : {};
1607
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1608
+ if (!test) {
1609
+ throw new Error(`Expected the '${kind}' field '${name}' to specify a derivation via 'field.type', but no value was present`);
1610
+ }
1611
+ })(field.type) : {};
1612
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1613
+ if (!test) {
1614
+ throw new Error(`No '${field.type}' derivation registered for use by the '${kind}' field '${name}'`);
1615
+ }
1616
+ })(this._derivations.has(field.type)) : {};
1617
+ return this._derivations.get(field.type);
1618
+ }
1619
+ hashFn(field) {
1620
+ const kind = 'kind' in field ? field.kind : '<unknown kind>';
1621
+ const name = 'name' in field ? field.name : '<unknown name>';
1622
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1623
+ if (!test) {
1624
+ throw new Error(`The '${kind}' field '${name}' is not a HashField and so cannot be used to lookup a hash function`);
1625
+ }
1626
+ })(!('kind' in field) || kind === '@hash') : {};
1627
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1628
+ if (!test) {
1629
+ throw new Error(`Expected the '${kind}' field '${name}' to specify a hash function via 'field.type', but no value was present`);
1630
+ }
1631
+ })(field.type) : {};
1632
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1633
+ if (!test) {
1634
+ throw new Error(`No '${field.type}' hash function is registered for use by the '${kind}' field '${name}'`);
1635
+ }
1636
+ })(this._hashFns.has(field.type)) : {};
1637
+ return this._hashFns.get(field.type);
1638
+ }
1639
+ resource(resource) {
1640
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1641
+ if (!test) {
1642
+ throw new Error(`No resource registered with name '${resource.type}'`);
1643
+ }
1644
+ })(this._schemas.has(resource.type)) : {};
1645
+ return this._schemas.get(resource.type).original;
1646
+ }
1647
+ registerResources(schemas) {
1648
+ schemas.forEach(schema => {
1649
+ this.registerResource(schema);
1650
+ });
1651
+ }
1652
+ registerResource(schema) {
1653
+ const fields = new Map();
1654
+ const relationships = {};
1655
+ const attributes = {};
1656
+ schema.fields.forEach(field => {
1657
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1658
+ if (!test) {
1659
+ throw new Error(`${field.kind} is not valid inside a ResourceSchema's fields.`);
1660
+ }
1661
+ })(
1662
+ // @ts-expect-error we are checking for mistakes at runtime
1663
+ field.kind !== '@id' && field.kind !== '@hash') : {};
1664
+ fields.set(field.name, field);
1665
+ if (field.kind === 'attribute') {
1666
+ attributes[field.name] = field;
1667
+ } else if (field.kind === 'belongsTo' || field.kind === 'hasMany') {
1668
+ relationships[field.name] = field;
1669
+ }
1670
+ });
1671
+ const traits = new Set(isResourceSchema(schema) ? schema.traits : []);
1672
+ traits.forEach(trait => {
1673
+ this._traits.add(trait);
1674
+ });
1675
+ const internalSchema = {
1676
+ original: schema,
1677
+ fields,
1678
+ relationships,
1679
+ attributes,
1680
+ traits
1681
+ };
1682
+ this._schemas.set(schema.type, internalSchema);
1683
+ }
1684
+ registerTransformation(transformation) {
1685
+ this._transforms.set(transformation[Type], transformation);
1686
+ }
1687
+ registerDerivation(derivation) {
1688
+ this._derivations.set(derivation[Type], makeCachedDerivation(derivation));
1689
+ }
1690
+
1691
+ /**
1692
+ * This is an internal method used to register behaviors for legacy mode.
1693
+ * It is not intended for public use.
1694
+ *
1695
+ * We do think a generalized `kind` registration system would be useful,
1696
+ * but we have not yet designed it.
1697
+ *
1698
+ * See https://github.com/emberjs/data/issues/9534
1699
+ *
1700
+ * @internal
1701
+ */
1702
+ _registerMode(mode, kinds) {
1703
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1704
+ if (!test) {
1705
+ throw new Error(`Mode '${mode}' is already registered`);
1706
+ }
1707
+ })(!this._traits.has(mode)) : {};
1708
+ this._modes.set(mode, kinds);
1709
+ }
1710
+
1711
+ /**
1712
+ * This is an internal method used to enable legacy behaviors for legacy mode.
1713
+ * It is not intended for public use.
1714
+ *
1715
+ * We do think a generalized `kind` registration system would be useful,
1716
+ * but we have not yet designed it.
1717
+ *
1718
+ * See https://github.com/emberjs/data/issues/9534
1719
+ *
1720
+ * @internal
1721
+ */
1722
+ _kind(mode, kind) {
1723
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1724
+ if (!test) {
1725
+ throw new Error(`Mode '${mode}' is not registered`);
1726
+ }
1727
+ })(this._modes.has(mode)) : {};
1728
+ const kinds = this._modes.get(mode);
1729
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1730
+ if (!test) {
1731
+ throw new Error(`Kind '${kind}' is not registered for mode '${mode}'`);
1732
+ }
1733
+ })(kinds[kind]) : {};
1734
+ return kinds[kind];
1735
+ }
1736
+ registerHashFn(hashFn) {
1737
+ this._hashFns.set(hashFn[Type], hashFn);
1738
+ }
1739
+ fields({
1740
+ type
1741
+ }) {
1742
+ const schema = this._schemas.get(type);
1743
+ if (!schema) {
1744
+ throw new Error(`No schema defined for ${type}`);
1745
+ }
1746
+ return schema.fields;
1747
+ }
1748
+ hasResource(resource) {
1749
+ return this._schemas.has(resource.type);
1750
+ }
1751
+ }
1752
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
1753
+ SchemaService.prototype.attributesDefinitionFor = function ({
1754
+ type
1755
+ }) {
1756
+ deprecate(`Use \`schema.fields({ type })\` instead of \`schema.attributesDefinitionFor({ type })\``, false, {
1757
+ id: 'ember-data:schema-service-updates',
1758
+ until: '6.0',
1759
+ for: 'ember-data',
1760
+ since: {
1761
+ available: '4.13',
1762
+ enabled: '5.4'
1763
+ }
1764
+ });
1765
+ const schema = this._schemas.get(type);
1766
+ if (!schema) {
1767
+ throw new Error(`No schema defined for ${type}`);
1768
+ }
1769
+ return schema.attributes;
1770
+ };
1771
+ SchemaService.prototype.relationshipsDefinitionFor = function ({
1772
+ type
1773
+ }) {
1774
+ deprecate(`Use \`schema.fields({ type })\` instead of \`schema.relationshipsDefinitionFor({ type })\``, false, {
1775
+ id: 'ember-data:schema-service-updates',
1776
+ until: '6.0',
1777
+ for: 'ember-data',
1778
+ since: {
1779
+ available: '4.13',
1780
+ enabled: '5.4'
1781
+ }
1782
+ });
1783
+ const schema = this._schemas.get(type);
1784
+ if (!schema) {
1785
+ throw new Error(`No schema defined for ${type}`);
1786
+ }
1787
+ return schema.relationships;
1788
+ };
1789
+ SchemaService.prototype.doesTypeExist = function (type) {
1790
+ deprecate(`Use \`schema.hasResource({ type })\` instead of \`schema.doesTypeExist(type)\``, false, {
1791
+ id: 'ember-data:schema-service-updates',
1792
+ until: '6.0',
1793
+ for: 'ember-data',
1794
+ since: {
1795
+ available: '4.13',
1796
+ enabled: '5.4'
1797
+ }
1798
+ });
1799
+ return this._schemas.has(type);
1800
+ };
1801
+ }
1802
+ export { Checkout, SchemaService, fromIdentity, instantiateRecord, registerDerivations, teardownRecord, withDefaults };