@warp-drive/legacy 5.8.0-alpha.30 → 5.8.0-alpha.34

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 (477) hide show
  1. package/declarations/adapter/error.d.ts +5 -5
  2. package/declarations/adapter/json-api.d.ts +2 -2
  3. package/declarations/compat/builders/find-all.d.ts +6 -6
  4. package/declarations/compat/builders/find-record.d.ts +8 -8
  5. package/declarations/compat/builders/query.d.ts +12 -12
  6. package/declarations/compat.d.ts +3 -3
  7. package/declarations/model/-private/references/belongs-to.d.ts +4 -4
  8. package/declarations/model/-private/references/has-many.d.ts +2 -2
  9. package/declarations/model/migration-support.d.ts +34 -18
  10. package/declarations/model.d.ts +2 -2
  11. package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -1
  12. package/declarations/serializer/json-api.d.ts +3 -3
  13. package/declarations/serializer/json.d.ts +1 -1
  14. package/declarations/serializer.d.ts +1 -1
  15. package/dist/adapter/error.js +7 -7
  16. package/dist/compat/builders.js +26 -26
  17. package/dist/compat/utils.js +0 -1
  18. package/dist/compat.js +3 -3
  19. package/dist/{errors-B9CDPh3R.js → errors-CIGPcDvd.js} +12 -12
  20. package/dist/{hooks-CQXyievu.js → hooks-QqRnX108.js} +1 -1
  21. package/dist/index.js +4 -4
  22. package/dist/{json-BHxlccxF.js → json-BNrV8EYG.js} +4 -4
  23. package/dist/model/-private.js +1 -1
  24. package/dist/model/migration-support.js +41 -24
  25. package/dist/{model-for-B0TSd9HU.js → model-for-CqXsIKws.js} +1 -1
  26. package/dist/model-fragments.js +2 -2
  27. package/dist/model.js +3 -3
  28. package/dist/{schema-provider-BnVr_CnJ.js → schema-provider-g5MfTj8n.js} +11 -11
  29. package/dist/serializer/json-api.js +7 -7
  30. package/dist/serializer/json.js +1 -1
  31. package/dist/serializer/rest.js +10 -10
  32. package/dist/serializer.js +1 -1
  33. package/dist/unpkg/dev/-private-B1pSSN52.js +1210 -0
  34. package/dist/unpkg/dev/adapter/-private.js +1 -0
  35. package/dist/unpkg/dev/adapter/error.js +336 -0
  36. package/dist/unpkg/dev/adapter/json-api.js +132 -0
  37. package/dist/unpkg/dev/adapter/rest.js +1257 -0
  38. package/dist/unpkg/dev/adapter.js +1253 -0
  39. package/dist/unpkg/dev/compat/-private.js +1 -0
  40. package/dist/unpkg/dev/compat/builders.js +273 -0
  41. package/dist/unpkg/dev/compat/extensions.js +243 -0
  42. package/dist/unpkg/dev/compat/utils.js +224 -0
  43. package/dist/unpkg/dev/compat.js +1020 -0
  44. package/dist/unpkg/dev/declarations/adapter/-private/build-url-mixin.d.ts +33 -0
  45. package/dist/unpkg/dev/declarations/adapter/-private/fastboot-interface.d.ts +8 -0
  46. package/dist/unpkg/dev/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -0
  47. package/dist/unpkg/dev/declarations/adapter/-private/utils/determine-body-promise.d.ts +4 -0
  48. package/dist/unpkg/dev/declarations/adapter/-private/utils/fetch.d.ts +8 -0
  49. package/dist/unpkg/dev/declarations/adapter/-private/utils/parse-response-headers.d.ts +1 -0
  50. package/dist/unpkg/dev/declarations/adapter/-private/utils/serialize-into-hash.d.ts +6 -0
  51. package/dist/unpkg/dev/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -0
  52. package/dist/unpkg/dev/declarations/adapter/-private.d.ts +5 -0
  53. package/dist/unpkg/dev/declarations/adapter/error.d.ts +215 -0
  54. package/dist/unpkg/dev/declarations/adapter/json-api.d.ts +231 -0
  55. package/dist/unpkg/dev/declarations/adapter/rest.d.ts +815 -0
  56. package/dist/unpkg/dev/declarations/adapter.d.ts +770 -0
  57. package/dist/unpkg/dev/declarations/compat/-private.d.ts +13 -0
  58. package/dist/unpkg/dev/declarations/compat/builders/find-all.d.ts +35 -0
  59. package/dist/unpkg/dev/declarations/compat/builders/find-record.d.ts +56 -0
  60. package/dist/unpkg/dev/declarations/compat/builders/query.d.ts +66 -0
  61. package/dist/unpkg/dev/declarations/compat/builders/save-record.d.ts +34 -0
  62. package/dist/unpkg/dev/declarations/compat/builders/utils.d.ts +3 -0
  63. package/dist/unpkg/dev/declarations/compat/builders.d.ts +14 -0
  64. package/dist/unpkg/dev/declarations/compat/extensions.d.ts +59 -0
  65. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/fetch-manager.d.ts +55 -0
  66. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -0
  67. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +11 -0
  68. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +5 -0
  69. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +2 -0
  70. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +524 -0
  71. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +213 -0
  72. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/serializer-response.d.ts +6 -0
  73. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +110 -0
  74. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/snapshot.d.ts +255 -0
  75. package/dist/unpkg/dev/declarations/compat/utils.d.ts +137 -0
  76. package/dist/unpkg/dev/declarations/compat.d.ts +157 -0
  77. package/dist/unpkg/dev/declarations/index.d.ts +70 -0
  78. package/dist/unpkg/dev/declarations/model/-private/attr.d.ts +170 -0
  79. package/dist/unpkg/dev/declarations/model/-private/belongs-to.d.ts +174 -0
  80. package/dist/unpkg/dev/declarations/model/-private/debug/assert-polymorphic-type.d.ts +5 -0
  81. package/dist/unpkg/dev/declarations/model/-private/errors.d.ts +289 -0
  82. package/dist/unpkg/dev/declarations/model/-private/has-many.d.ts +162 -0
  83. package/dist/unpkg/dev/declarations/model/-private/hooks.d.ts +10 -0
  84. package/dist/unpkg/dev/declarations/model/-private/legacy-relationships-support.d.ts +47 -0
  85. package/dist/unpkg/dev/declarations/model/-private/model-for-mixin.d.ts +3 -0
  86. package/dist/unpkg/dev/declarations/model/-private/model-methods.d.ts +39 -0
  87. package/dist/unpkg/dev/declarations/model/-private/model.d.ts +1269 -0
  88. package/dist/unpkg/dev/declarations/model/-private/notify-changes.d.ts +4 -0
  89. package/dist/unpkg/dev/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  90. package/dist/unpkg/dev/declarations/model/-private/promise-many-array.d.ts +124 -0
  91. package/dist/unpkg/dev/declarations/model/-private/record-state.d.ts +58 -0
  92. package/dist/unpkg/dev/declarations/model/-private/references/belongs-to.d.ts +498 -0
  93. package/dist/unpkg/dev/declarations/model/-private/references/has-many.d.ts +500 -0
  94. package/dist/unpkg/dev/declarations/model/-private/schema-provider.d.ts +56 -0
  95. package/dist/unpkg/dev/declarations/model/-private/type-utils.d.ts +57 -0
  96. package/dist/unpkg/dev/declarations/model/-private/util.d.ts +5 -0
  97. package/dist/unpkg/dev/declarations/model/-private.d.ts +8 -0
  98. package/dist/unpkg/dev/declarations/model/migration-support.d.ts +280 -0
  99. package/dist/unpkg/dev/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  100. package/dist/unpkg/dev/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  101. package/dist/unpkg/dev/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  102. package/dist/unpkg/dev/declarations/model-fragments/index.d.ts +5 -0
  103. package/dist/unpkg/dev/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  104. package/dist/unpkg/dev/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  105. package/dist/unpkg/dev/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  106. package/dist/unpkg/dev/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  107. package/dist/unpkg/dev/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  108. package/dist/unpkg/dev/declarations/model-fragments.d.ts +9 -0
  109. package/dist/unpkg/dev/declarations/model.d.ts +49 -0
  110. package/dist/unpkg/dev/declarations/serializer/-private/embedded-records-mixin.d.ts +91 -0
  111. package/dist/unpkg/dev/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  112. package/dist/unpkg/dev/declarations/serializer/-private/transforms/date.d.ts +28 -0
  113. package/dist/unpkg/dev/declarations/serializer/-private/transforms/number.d.ts +29 -0
  114. package/dist/unpkg/dev/declarations/serializer/-private/transforms/string.d.ts +29 -0
  115. package/dist/unpkg/dev/declarations/serializer/-private/transforms/transform.d.ts +118 -0
  116. package/dist/unpkg/dev/declarations/serializer/-private/utils.d.ts +3 -0
  117. package/dist/unpkg/dev/declarations/serializer/json-api.d.ts +123 -0
  118. package/dist/unpkg/dev/declarations/serializer/json.d.ts +75 -0
  119. package/dist/unpkg/dev/declarations/serializer/rest.d.ts +51 -0
  120. package/dist/unpkg/dev/declarations/serializer/transform.d.ts +5 -0
  121. package/dist/unpkg/dev/declarations/serializer.d.ts +254 -0
  122. package/dist/unpkg/dev/declarations/store/-private.d.ts +223 -0
  123. package/dist/unpkg/dev/declarations/store.d.ts +3 -0
  124. package/dist/unpkg/dev/errors-CIGPcDvd.js +2595 -0
  125. package/dist/unpkg/dev/hooks-QqRnX108.js +74 -0
  126. package/dist/unpkg/dev/index.js +195 -0
  127. package/dist/unpkg/dev/json-BNrV8EYG.js +1272 -0
  128. package/dist/unpkg/dev/model/-private.js +1 -0
  129. package/dist/unpkg/dev/model/migration-support.js +579 -0
  130. package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
  131. package/dist/unpkg/dev/model-fragments.js +76 -0
  132. package/dist/unpkg/dev/model.js +667 -0
  133. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  134. package/dist/unpkg/dev/schema-provider-g5MfTj8n.js +2338 -0
  135. package/dist/unpkg/dev/serialize-into-hash-BnYvPex3.js +261 -0
  136. package/dist/unpkg/dev/serializer/json-api.js +527 -0
  137. package/dist/unpkg/dev/serializer/json.js +6 -0
  138. package/dist/unpkg/dev/serializer/rest.js +1243 -0
  139. package/dist/unpkg/dev/serializer/transform.js +278 -0
  140. package/dist/unpkg/dev/serializer.js +248 -0
  141. package/dist/unpkg/dev/store.js +636 -0
  142. package/dist/unpkg/dev/util-Dul6TZts.js +35 -0
  143. package/dist/unpkg/dev/utils-Cqw9eRj5.js +23 -0
  144. package/dist/unpkg/dev-deprecated/-private-B1pSSN52.js +1210 -0
  145. package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
  146. package/dist/unpkg/dev-deprecated/adapter/error.js +336 -0
  147. package/dist/unpkg/dev-deprecated/adapter/json-api.js +132 -0
  148. package/dist/unpkg/dev-deprecated/adapter/rest.js +1257 -0
  149. package/dist/unpkg/dev-deprecated/adapter.js +1253 -0
  150. package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
  151. package/dist/unpkg/dev-deprecated/compat/builders.js +273 -0
  152. package/dist/unpkg/dev-deprecated/compat/extensions.js +243 -0
  153. package/dist/unpkg/dev-deprecated/compat/utils.js +224 -0
  154. package/dist/unpkg/dev-deprecated/compat.js +1020 -0
  155. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/build-url-mixin.d.ts +33 -0
  156. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/fastboot-interface.d.ts +8 -0
  157. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -0
  158. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/determine-body-promise.d.ts +4 -0
  159. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/fetch.d.ts +8 -0
  160. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/parse-response-headers.d.ts +1 -0
  161. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/serialize-into-hash.d.ts +6 -0
  162. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -0
  163. package/dist/unpkg/dev-deprecated/declarations/adapter/-private.d.ts +5 -0
  164. package/dist/unpkg/dev-deprecated/declarations/adapter/error.d.ts +215 -0
  165. package/dist/unpkg/dev-deprecated/declarations/adapter/json-api.d.ts +231 -0
  166. package/dist/unpkg/dev-deprecated/declarations/adapter/rest.d.ts +815 -0
  167. package/dist/unpkg/dev-deprecated/declarations/adapter.d.ts +770 -0
  168. package/dist/unpkg/dev-deprecated/declarations/compat/-private.d.ts +13 -0
  169. package/dist/unpkg/dev-deprecated/declarations/compat/builders/find-all.d.ts +35 -0
  170. package/dist/unpkg/dev-deprecated/declarations/compat/builders/find-record.d.ts +56 -0
  171. package/dist/unpkg/dev-deprecated/declarations/compat/builders/query.d.ts +66 -0
  172. package/dist/unpkg/dev-deprecated/declarations/compat/builders/save-record.d.ts +34 -0
  173. package/dist/unpkg/dev-deprecated/declarations/compat/builders/utils.d.ts +3 -0
  174. package/dist/unpkg/dev-deprecated/declarations/compat/builders.d.ts +14 -0
  175. package/dist/unpkg/dev-deprecated/declarations/compat/extensions.d.ts +59 -0
  176. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/fetch-manager.d.ts +55 -0
  177. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -0
  178. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +11 -0
  179. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +5 -0
  180. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +2 -0
  181. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +524 -0
  182. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +213 -0
  183. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/serializer-response.d.ts +6 -0
  184. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +110 -0
  185. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/snapshot.d.ts +255 -0
  186. package/dist/unpkg/dev-deprecated/declarations/compat/utils.d.ts +137 -0
  187. package/dist/unpkg/dev-deprecated/declarations/compat.d.ts +157 -0
  188. package/dist/unpkg/dev-deprecated/declarations/index.d.ts +70 -0
  189. package/dist/unpkg/dev-deprecated/declarations/model/-private/attr.d.ts +170 -0
  190. package/dist/unpkg/dev-deprecated/declarations/model/-private/belongs-to.d.ts +174 -0
  191. package/dist/unpkg/dev-deprecated/declarations/model/-private/debug/assert-polymorphic-type.d.ts +5 -0
  192. package/dist/unpkg/dev-deprecated/declarations/model/-private/errors.d.ts +289 -0
  193. package/dist/unpkg/dev-deprecated/declarations/model/-private/has-many.d.ts +162 -0
  194. package/dist/unpkg/dev-deprecated/declarations/model/-private/hooks.d.ts +10 -0
  195. package/dist/unpkg/dev-deprecated/declarations/model/-private/legacy-relationships-support.d.ts +47 -0
  196. package/dist/unpkg/dev-deprecated/declarations/model/-private/model-for-mixin.d.ts +3 -0
  197. package/dist/unpkg/dev-deprecated/declarations/model/-private/model-methods.d.ts +39 -0
  198. package/dist/unpkg/dev-deprecated/declarations/model/-private/model.d.ts +1269 -0
  199. package/dist/unpkg/dev-deprecated/declarations/model/-private/notify-changes.d.ts +4 -0
  200. package/dist/unpkg/dev-deprecated/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  201. package/dist/unpkg/dev-deprecated/declarations/model/-private/promise-many-array.d.ts +124 -0
  202. package/dist/unpkg/dev-deprecated/declarations/model/-private/record-state.d.ts +58 -0
  203. package/dist/unpkg/dev-deprecated/declarations/model/-private/references/belongs-to.d.ts +498 -0
  204. package/dist/unpkg/dev-deprecated/declarations/model/-private/references/has-many.d.ts +500 -0
  205. package/dist/unpkg/dev-deprecated/declarations/model/-private/schema-provider.d.ts +56 -0
  206. package/dist/unpkg/dev-deprecated/declarations/model/-private/type-utils.d.ts +57 -0
  207. package/dist/unpkg/dev-deprecated/declarations/model/-private/util.d.ts +5 -0
  208. package/dist/unpkg/dev-deprecated/declarations/model/-private.d.ts +8 -0
  209. package/dist/unpkg/dev-deprecated/declarations/model/migration-support.d.ts +280 -0
  210. package/dist/unpkg/dev-deprecated/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  211. package/dist/unpkg/dev-deprecated/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  212. package/dist/unpkg/dev-deprecated/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  213. package/dist/unpkg/dev-deprecated/declarations/model-fragments/index.d.ts +5 -0
  214. package/dist/unpkg/dev-deprecated/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  215. package/dist/unpkg/dev-deprecated/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  216. package/dist/unpkg/dev-deprecated/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  217. package/dist/unpkg/dev-deprecated/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  218. package/dist/unpkg/dev-deprecated/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  219. package/dist/unpkg/dev-deprecated/declarations/model-fragments.d.ts +9 -0
  220. package/dist/unpkg/dev-deprecated/declarations/model.d.ts +49 -0
  221. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/embedded-records-mixin.d.ts +91 -0
  222. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  223. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/date.d.ts +28 -0
  224. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/number.d.ts +29 -0
  225. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/string.d.ts +29 -0
  226. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/transform.d.ts +118 -0
  227. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/utils.d.ts +3 -0
  228. package/dist/unpkg/dev-deprecated/declarations/serializer/json-api.d.ts +123 -0
  229. package/dist/unpkg/dev-deprecated/declarations/serializer/json.d.ts +75 -0
  230. package/dist/unpkg/dev-deprecated/declarations/serializer/rest.d.ts +51 -0
  231. package/dist/unpkg/dev-deprecated/declarations/serializer/transform.d.ts +5 -0
  232. package/dist/unpkg/dev-deprecated/declarations/serializer.d.ts +254 -0
  233. package/dist/unpkg/dev-deprecated/declarations/store/-private.d.ts +223 -0
  234. package/dist/unpkg/dev-deprecated/declarations/store.d.ts +3 -0
  235. package/dist/unpkg/dev-deprecated/errors-CIGPcDvd.js +2595 -0
  236. package/dist/unpkg/dev-deprecated/hooks-QqRnX108.js +74 -0
  237. package/dist/unpkg/dev-deprecated/index.js +195 -0
  238. package/dist/unpkg/dev-deprecated/json-BNrV8EYG.js +1272 -0
  239. package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
  240. package/dist/unpkg/dev-deprecated/model/migration-support.js +579 -0
  241. package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
  242. package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
  243. package/dist/unpkg/dev-deprecated/model.js +667 -0
  244. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  245. package/dist/unpkg/dev-deprecated/schema-provider-g5MfTj8n.js +2338 -0
  246. package/dist/unpkg/dev-deprecated/serialize-into-hash-BnYvPex3.js +261 -0
  247. package/dist/unpkg/dev-deprecated/serializer/json-api.js +527 -0
  248. package/dist/unpkg/dev-deprecated/serializer/json.js +6 -0
  249. package/dist/unpkg/dev-deprecated/serializer/rest.js +1243 -0
  250. package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
  251. package/dist/unpkg/dev-deprecated/serializer.js +248 -0
  252. package/dist/unpkg/dev-deprecated/store.js +636 -0
  253. package/dist/unpkg/dev-deprecated/util-Dul6TZts.js +35 -0
  254. package/dist/unpkg/dev-deprecated/utils-Cqw9eRj5.js +23 -0
  255. package/dist/unpkg/prod/-private-B1pSSN52.js +1210 -0
  256. package/dist/unpkg/prod/adapter/-private.js +1 -0
  257. package/dist/unpkg/prod/adapter/error.js +336 -0
  258. package/dist/unpkg/prod/adapter/json-api.js +132 -0
  259. package/dist/unpkg/prod/adapter/rest.js +1257 -0
  260. package/dist/unpkg/prod/adapter.js +1253 -0
  261. package/dist/unpkg/prod/compat/-private.js +1 -0
  262. package/dist/unpkg/prod/compat/builders.js +273 -0
  263. package/dist/unpkg/prod/compat/extensions.js +243 -0
  264. package/dist/unpkg/prod/compat/utils.js +224 -0
  265. package/dist/unpkg/prod/compat.js +1020 -0
  266. package/dist/unpkg/prod/declarations/adapter/-private/build-url-mixin.d.ts +33 -0
  267. package/dist/unpkg/prod/declarations/adapter/-private/fastboot-interface.d.ts +8 -0
  268. package/dist/unpkg/prod/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -0
  269. package/dist/unpkg/prod/declarations/adapter/-private/utils/determine-body-promise.d.ts +4 -0
  270. package/dist/unpkg/prod/declarations/adapter/-private/utils/fetch.d.ts +8 -0
  271. package/dist/unpkg/prod/declarations/adapter/-private/utils/parse-response-headers.d.ts +1 -0
  272. package/dist/unpkg/prod/declarations/adapter/-private/utils/serialize-into-hash.d.ts +6 -0
  273. package/dist/unpkg/prod/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -0
  274. package/dist/unpkg/prod/declarations/adapter/-private.d.ts +5 -0
  275. package/dist/unpkg/prod/declarations/adapter/error.d.ts +215 -0
  276. package/dist/unpkg/prod/declarations/adapter/json-api.d.ts +231 -0
  277. package/dist/unpkg/prod/declarations/adapter/rest.d.ts +815 -0
  278. package/dist/unpkg/prod/declarations/adapter.d.ts +770 -0
  279. package/dist/unpkg/prod/declarations/compat/-private.d.ts +13 -0
  280. package/dist/unpkg/prod/declarations/compat/builders/find-all.d.ts +35 -0
  281. package/dist/unpkg/prod/declarations/compat/builders/find-record.d.ts +56 -0
  282. package/dist/unpkg/prod/declarations/compat/builders/query.d.ts +66 -0
  283. package/dist/unpkg/prod/declarations/compat/builders/save-record.d.ts +34 -0
  284. package/dist/unpkg/prod/declarations/compat/builders/utils.d.ts +3 -0
  285. package/dist/unpkg/prod/declarations/compat/builders.d.ts +14 -0
  286. package/dist/unpkg/prod/declarations/compat/extensions.d.ts +59 -0
  287. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/fetch-manager.d.ts +55 -0
  288. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -0
  289. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +11 -0
  290. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +5 -0
  291. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +2 -0
  292. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +524 -0
  293. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +213 -0
  294. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/serializer-response.d.ts +6 -0
  295. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +110 -0
  296. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/snapshot.d.ts +255 -0
  297. package/dist/unpkg/prod/declarations/compat/utils.d.ts +137 -0
  298. package/dist/unpkg/prod/declarations/compat.d.ts +157 -0
  299. package/dist/unpkg/prod/declarations/index.d.ts +70 -0
  300. package/dist/unpkg/prod/declarations/model/-private/attr.d.ts +170 -0
  301. package/dist/unpkg/prod/declarations/model/-private/belongs-to.d.ts +174 -0
  302. package/dist/unpkg/prod/declarations/model/-private/debug/assert-polymorphic-type.d.ts +5 -0
  303. package/dist/unpkg/prod/declarations/model/-private/errors.d.ts +289 -0
  304. package/dist/unpkg/prod/declarations/model/-private/has-many.d.ts +162 -0
  305. package/dist/unpkg/prod/declarations/model/-private/hooks.d.ts +10 -0
  306. package/dist/unpkg/prod/declarations/model/-private/legacy-relationships-support.d.ts +47 -0
  307. package/dist/unpkg/prod/declarations/model/-private/model-for-mixin.d.ts +3 -0
  308. package/dist/unpkg/prod/declarations/model/-private/model-methods.d.ts +39 -0
  309. package/dist/unpkg/prod/declarations/model/-private/model.d.ts +1269 -0
  310. package/dist/unpkg/prod/declarations/model/-private/notify-changes.d.ts +4 -0
  311. package/dist/unpkg/prod/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  312. package/dist/unpkg/prod/declarations/model/-private/promise-many-array.d.ts +124 -0
  313. package/dist/unpkg/prod/declarations/model/-private/record-state.d.ts +58 -0
  314. package/dist/unpkg/prod/declarations/model/-private/references/belongs-to.d.ts +498 -0
  315. package/dist/unpkg/prod/declarations/model/-private/references/has-many.d.ts +500 -0
  316. package/dist/unpkg/prod/declarations/model/-private/schema-provider.d.ts +56 -0
  317. package/dist/unpkg/prod/declarations/model/-private/type-utils.d.ts +57 -0
  318. package/dist/unpkg/prod/declarations/model/-private/util.d.ts +5 -0
  319. package/dist/unpkg/prod/declarations/model/-private.d.ts +8 -0
  320. package/dist/unpkg/prod/declarations/model/migration-support.d.ts +280 -0
  321. package/dist/unpkg/prod/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  322. package/dist/unpkg/prod/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  323. package/dist/unpkg/prod/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  324. package/dist/unpkg/prod/declarations/model-fragments/index.d.ts +5 -0
  325. package/dist/unpkg/prod/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  326. package/dist/unpkg/prod/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  327. package/dist/unpkg/prod/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  328. package/dist/unpkg/prod/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  329. package/dist/unpkg/prod/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  330. package/dist/unpkg/prod/declarations/model-fragments.d.ts +9 -0
  331. package/dist/unpkg/prod/declarations/model.d.ts +49 -0
  332. package/dist/unpkg/prod/declarations/serializer/-private/embedded-records-mixin.d.ts +91 -0
  333. package/dist/unpkg/prod/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  334. package/dist/unpkg/prod/declarations/serializer/-private/transforms/date.d.ts +28 -0
  335. package/dist/unpkg/prod/declarations/serializer/-private/transforms/number.d.ts +29 -0
  336. package/dist/unpkg/prod/declarations/serializer/-private/transforms/string.d.ts +29 -0
  337. package/dist/unpkg/prod/declarations/serializer/-private/transforms/transform.d.ts +118 -0
  338. package/dist/unpkg/prod/declarations/serializer/-private/utils.d.ts +3 -0
  339. package/dist/unpkg/prod/declarations/serializer/json-api.d.ts +123 -0
  340. package/dist/unpkg/prod/declarations/serializer/json.d.ts +75 -0
  341. package/dist/unpkg/prod/declarations/serializer/rest.d.ts +51 -0
  342. package/dist/unpkg/prod/declarations/serializer/transform.d.ts +5 -0
  343. package/dist/unpkg/prod/declarations/serializer.d.ts +254 -0
  344. package/dist/unpkg/prod/declarations/store/-private.d.ts +223 -0
  345. package/dist/unpkg/prod/declarations/store.d.ts +3 -0
  346. package/dist/unpkg/prod/errors-CIGPcDvd.js +2595 -0
  347. package/dist/unpkg/prod/hooks-QqRnX108.js +74 -0
  348. package/dist/unpkg/prod/index.js +195 -0
  349. package/dist/unpkg/prod/json-BNrV8EYG.js +1272 -0
  350. package/dist/unpkg/prod/model/-private.js +1 -0
  351. package/dist/unpkg/prod/model/migration-support.js +579 -0
  352. package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
  353. package/dist/unpkg/prod/model-fragments.js +76 -0
  354. package/dist/unpkg/prod/model.js +667 -0
  355. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  356. package/dist/unpkg/prod/schema-provider-g5MfTj8n.js +2338 -0
  357. package/dist/unpkg/prod/serialize-into-hash-BnYvPex3.js +261 -0
  358. package/dist/unpkg/prod/serializer/json-api.js +527 -0
  359. package/dist/unpkg/prod/serializer/json.js +6 -0
  360. package/dist/unpkg/prod/serializer/rest.js +1243 -0
  361. package/dist/unpkg/prod/serializer/transform.js +278 -0
  362. package/dist/unpkg/prod/serializer.js +248 -0
  363. package/dist/unpkg/prod/store.js +636 -0
  364. package/dist/unpkg/prod/util-Dul6TZts.js +35 -0
  365. package/dist/unpkg/prod/utils-Cqw9eRj5.js +23 -0
  366. package/dist/unpkg/prod-deprecated/-private-B1pSSN52.js +1210 -0
  367. package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
  368. package/dist/unpkg/prod-deprecated/adapter/error.js +336 -0
  369. package/dist/unpkg/prod-deprecated/adapter/json-api.js +132 -0
  370. package/dist/unpkg/prod-deprecated/adapter/rest.js +1257 -0
  371. package/dist/unpkg/prod-deprecated/adapter.js +1253 -0
  372. package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
  373. package/dist/unpkg/prod-deprecated/compat/builders.js +273 -0
  374. package/dist/unpkg/prod-deprecated/compat/extensions.js +243 -0
  375. package/dist/unpkg/prod-deprecated/compat/utils.js +224 -0
  376. package/dist/unpkg/prod-deprecated/compat.js +1020 -0
  377. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/build-url-mixin.d.ts +33 -0
  378. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/fastboot-interface.d.ts +8 -0
  379. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -0
  380. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/determine-body-promise.d.ts +4 -0
  381. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/fetch.d.ts +8 -0
  382. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/parse-response-headers.d.ts +1 -0
  383. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/serialize-into-hash.d.ts +6 -0
  384. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -0
  385. package/dist/unpkg/prod-deprecated/declarations/adapter/-private.d.ts +5 -0
  386. package/dist/unpkg/prod-deprecated/declarations/adapter/error.d.ts +215 -0
  387. package/dist/unpkg/prod-deprecated/declarations/adapter/json-api.d.ts +231 -0
  388. package/dist/unpkg/prod-deprecated/declarations/adapter/rest.d.ts +815 -0
  389. package/dist/unpkg/prod-deprecated/declarations/adapter.d.ts +770 -0
  390. package/dist/unpkg/prod-deprecated/declarations/compat/-private.d.ts +13 -0
  391. package/dist/unpkg/prod-deprecated/declarations/compat/builders/find-all.d.ts +35 -0
  392. package/dist/unpkg/prod-deprecated/declarations/compat/builders/find-record.d.ts +56 -0
  393. package/dist/unpkg/prod-deprecated/declarations/compat/builders/query.d.ts +66 -0
  394. package/dist/unpkg/prod-deprecated/declarations/compat/builders/save-record.d.ts +34 -0
  395. package/dist/unpkg/prod-deprecated/declarations/compat/builders/utils.d.ts +3 -0
  396. package/dist/unpkg/prod-deprecated/declarations/compat/builders.d.ts +14 -0
  397. package/dist/unpkg/prod-deprecated/declarations/compat/extensions.d.ts +59 -0
  398. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/fetch-manager.d.ts +55 -0
  399. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -0
  400. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +11 -0
  401. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +5 -0
  402. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +2 -0
  403. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +524 -0
  404. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +213 -0
  405. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/serializer-response.d.ts +6 -0
  406. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +110 -0
  407. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/snapshot.d.ts +255 -0
  408. package/dist/unpkg/prod-deprecated/declarations/compat/utils.d.ts +137 -0
  409. package/dist/unpkg/prod-deprecated/declarations/compat.d.ts +157 -0
  410. package/dist/unpkg/prod-deprecated/declarations/index.d.ts +70 -0
  411. package/dist/unpkg/prod-deprecated/declarations/model/-private/attr.d.ts +170 -0
  412. package/dist/unpkg/prod-deprecated/declarations/model/-private/belongs-to.d.ts +174 -0
  413. package/dist/unpkg/prod-deprecated/declarations/model/-private/debug/assert-polymorphic-type.d.ts +5 -0
  414. package/dist/unpkg/prod-deprecated/declarations/model/-private/errors.d.ts +289 -0
  415. package/dist/unpkg/prod-deprecated/declarations/model/-private/has-many.d.ts +162 -0
  416. package/dist/unpkg/prod-deprecated/declarations/model/-private/hooks.d.ts +10 -0
  417. package/dist/unpkg/prod-deprecated/declarations/model/-private/legacy-relationships-support.d.ts +47 -0
  418. package/dist/unpkg/prod-deprecated/declarations/model/-private/model-for-mixin.d.ts +3 -0
  419. package/dist/unpkg/prod-deprecated/declarations/model/-private/model-methods.d.ts +39 -0
  420. package/dist/unpkg/prod-deprecated/declarations/model/-private/model.d.ts +1269 -0
  421. package/dist/unpkg/prod-deprecated/declarations/model/-private/notify-changes.d.ts +4 -0
  422. package/dist/unpkg/prod-deprecated/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  423. package/dist/unpkg/prod-deprecated/declarations/model/-private/promise-many-array.d.ts +124 -0
  424. package/dist/unpkg/prod-deprecated/declarations/model/-private/record-state.d.ts +58 -0
  425. package/dist/unpkg/prod-deprecated/declarations/model/-private/references/belongs-to.d.ts +498 -0
  426. package/dist/unpkg/prod-deprecated/declarations/model/-private/references/has-many.d.ts +500 -0
  427. package/dist/unpkg/prod-deprecated/declarations/model/-private/schema-provider.d.ts +56 -0
  428. package/dist/unpkg/prod-deprecated/declarations/model/-private/type-utils.d.ts +57 -0
  429. package/dist/unpkg/prod-deprecated/declarations/model/-private/util.d.ts +5 -0
  430. package/dist/unpkg/prod-deprecated/declarations/model/-private.d.ts +8 -0
  431. package/dist/unpkg/prod-deprecated/declarations/model/migration-support.d.ts +280 -0
  432. package/dist/unpkg/prod-deprecated/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  433. package/dist/unpkg/prod-deprecated/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  434. package/dist/unpkg/prod-deprecated/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  435. package/dist/unpkg/prod-deprecated/declarations/model-fragments/index.d.ts +5 -0
  436. package/dist/unpkg/prod-deprecated/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  437. package/dist/unpkg/prod-deprecated/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  438. package/dist/unpkg/prod-deprecated/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  439. package/dist/unpkg/prod-deprecated/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  440. package/dist/unpkg/prod-deprecated/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  441. package/dist/unpkg/prod-deprecated/declarations/model-fragments.d.ts +9 -0
  442. package/dist/unpkg/prod-deprecated/declarations/model.d.ts +49 -0
  443. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/embedded-records-mixin.d.ts +91 -0
  444. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  445. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/date.d.ts +28 -0
  446. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/number.d.ts +29 -0
  447. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/string.d.ts +29 -0
  448. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/transform.d.ts +118 -0
  449. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/utils.d.ts +3 -0
  450. package/dist/unpkg/prod-deprecated/declarations/serializer/json-api.d.ts +123 -0
  451. package/dist/unpkg/prod-deprecated/declarations/serializer/json.d.ts +75 -0
  452. package/dist/unpkg/prod-deprecated/declarations/serializer/rest.d.ts +51 -0
  453. package/dist/unpkg/prod-deprecated/declarations/serializer/transform.d.ts +5 -0
  454. package/dist/unpkg/prod-deprecated/declarations/serializer.d.ts +254 -0
  455. package/dist/unpkg/prod-deprecated/declarations/store/-private.d.ts +223 -0
  456. package/dist/unpkg/prod-deprecated/declarations/store.d.ts +3 -0
  457. package/dist/unpkg/prod-deprecated/errors-CIGPcDvd.js +2595 -0
  458. package/dist/unpkg/prod-deprecated/hooks-QqRnX108.js +74 -0
  459. package/dist/unpkg/prod-deprecated/index.js +195 -0
  460. package/dist/unpkg/prod-deprecated/json-BNrV8EYG.js +1272 -0
  461. package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
  462. package/dist/unpkg/prod-deprecated/model/migration-support.js +579 -0
  463. package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
  464. package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
  465. package/dist/unpkg/prod-deprecated/model.js +667 -0
  466. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  467. package/dist/unpkg/prod-deprecated/schema-provider-g5MfTj8n.js +2338 -0
  468. package/dist/unpkg/prod-deprecated/serialize-into-hash-BnYvPex3.js +261 -0
  469. package/dist/unpkg/prod-deprecated/serializer/json-api.js +527 -0
  470. package/dist/unpkg/prod-deprecated/serializer/json.js +6 -0
  471. package/dist/unpkg/prod-deprecated/serializer/rest.js +1243 -0
  472. package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
  473. package/dist/unpkg/prod-deprecated/serializer.js +248 -0
  474. package/dist/unpkg/prod-deprecated/store.js +636 -0
  475. package/dist/unpkg/prod-deprecated/util-Dul6TZts.js +35 -0
  476. package/dist/unpkg/prod-deprecated/utils-Cqw9eRj5.js +23 -0
  477. package/package.json +30 -6
@@ -0,0 +1,2338 @@
1
+ import { getOwner } from '@ember/application';
2
+ import { deprecate } from '@ember/debug';
3
+ import EmberObject from '@ember/object';
4
+ import { recordIdentifierFor, storeFor } from '@warp-drive/core';
5
+ import { assertPrivateStore, notifyInternalSignal, peekInternalSignal, withSignalStore, recordIdentifierFor as recordIdentifierFor$1, gate, memoized, defineSignal, coerceId, entangleSignal, defineGate } from '@warp-drive/core/store/-private';
6
+ import { RecordStore } from '@warp-drive/core/types/symbols';
7
+ import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-CIGPcDvd.js";
8
+ import { u as upgradeStore, F as FetchManager } from "./-private-B1pSSN52.js";
9
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
10
+ import { cacheFor } from '@ember/object/internals';
11
+ import { Context } from '@warp-drive/core/reactive/-private';
12
+ import { d as decorateMethodV2 } from "./runtime-BPCpkOf1-BKOwiRJp.js";
13
+ import { n as normalizeModelName } from "./util-Dul6TZts.js";
14
+ function rollbackAttributes() {
15
+ const {
16
+ currentState
17
+ } = this;
18
+ const {
19
+ isNew
20
+ } = currentState;
21
+ const store = this[RecordStore];
22
+ assertPrivateStore(store);
23
+ store._join(() => {
24
+ store.cache.rollbackAttrs(recordIdentifierFor(this));
25
+ this.errors.clear();
26
+ currentState.cleanErrorRequests();
27
+ if (isNew) {
28
+ this.unloadRecord();
29
+ }
30
+ });
31
+ }
32
+ function unloadRecord() {
33
+ if (this.currentState.isNew && (this.isDestroyed || this.isDestroying)) {
34
+ return;
35
+ }
36
+ this[RecordStore].unloadRecord(this);
37
+ }
38
+ function belongsTo(prop) {
39
+ return lookupLegacySupport(this).referenceFor('belongsTo', prop);
40
+ }
41
+ function hasMany(prop) {
42
+ return lookupLegacySupport(this).referenceFor('hasMany', prop);
43
+ }
44
+ function reload(options = {}) {
45
+ if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) {
46
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
47
+ {
48
+ throw new Error(`You cannot use reload() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`);
49
+ }
50
+ })() : {};
51
+ } else {
52
+ deprecate(`record.reload is deprecated, please use store.request to initiate a request instead.`, false, {
53
+ id: 'warp-drive:deprecate-legacy-request-methods',
54
+ until: '6.0',
55
+ for: '@warp-drive/core',
56
+ url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
57
+ since: {
58
+ enabled: '5.7',
59
+ available: '5.7'
60
+ }
61
+ });
62
+ return _reload.call(this, options);
63
+ }
64
+ }
65
+ function _reload(options = {}) {
66
+ options.isReloading = true;
67
+ options.reload = true;
68
+ const identifier = recordIdentifierFor(this);
69
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
70
+ if (!test) {
71
+ throw new Error(`You cannot reload a record without an ID`);
72
+ }
73
+ })(identifier.id) : {};
74
+ this.isReloading = true;
75
+ const promise = this[RecordStore].request({
76
+ op: 'findRecord',
77
+ data: {
78
+ options,
79
+ record: identifier
80
+ },
81
+ cacheOptions: {
82
+ [Symbol.for('wd:skip-cache')]: true
83
+ }
84
+ }).then(() => this).finally(() => {
85
+ this.isReloading = false;
86
+ });
87
+ return promise;
88
+ }
89
+ function changedAttributes() {
90
+ return this[RecordStore].cache.changedAttrs(recordIdentifierFor(this));
91
+ }
92
+ function serialize(options) {
93
+ upgradeStore(this[RecordStore]);
94
+ return this[RecordStore].serializeRecord(this, options);
95
+ }
96
+ function deleteRecord() {
97
+ // ensure we've populated currentState prior to deleting a new record
98
+ if (this.currentState) {
99
+ this[RecordStore].deleteRecord(this);
100
+ }
101
+ }
102
+ function save(options) {
103
+ if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) {
104
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
105
+ {
106
+ throw new Error(`You cannot use save() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`);
107
+ }
108
+ })() : {};
109
+ } else {
110
+ deprecate(`record.save is deprecated, please use store.request to initiate a request instead.`, false, {
111
+ id: 'warp-drive:deprecate-legacy-request-methods',
112
+ until: '6.0',
113
+ for: '@warp-drive/core',
114
+ url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
115
+ since: {
116
+ enabled: '5.7',
117
+ available: '5.7'
118
+ }
119
+ });
120
+ return _save.call(this, options);
121
+ }
122
+ }
123
+ function _save(options) {
124
+ let promise;
125
+ if (this.currentState.isNew && this.currentState.isDeleted) {
126
+ promise = Promise.resolve(this);
127
+ } else {
128
+ this.errors.clear();
129
+ promise = this[RecordStore].saveRecord(this, options);
130
+ }
131
+ return promise;
132
+ }
133
+ function destroyRecord(options) {
134
+ if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) {
135
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
136
+ {
137
+ throw new Error(`You cannot use destroyRecord() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`);
138
+ }
139
+ })() : {};
140
+ } else {
141
+ deprecate(`record.destroyRecord is deprecated, please use store.request to initiate a request instead.`, false, {
142
+ id: 'warp-drive:deprecate-legacy-request-methods',
143
+ until: '6.0',
144
+ for: '@warp-drive/core',
145
+ url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
146
+ since: {
147
+ enabled: '5.7',
148
+ available: '5.7'
149
+ }
150
+ });
151
+ return _destroyRecord.call(this, options);
152
+ }
153
+ }
154
+ function _destroyRecord(options) {
155
+ const {
156
+ isNew
157
+ } = this.currentState;
158
+ this.deleteRecord();
159
+ if (isNew) {
160
+ return Promise.resolve(this);
161
+ }
162
+ return this.save(options).then(_ => {
163
+ this.unloadRecord();
164
+ return this;
165
+ });
166
+ }
167
+ function createSnapshot() {
168
+ const store = this[RecordStore];
169
+ if (!store._fetchManager) {
170
+ store._fetchManager = new FetchManager(store);
171
+ }
172
+
173
+ // @ts-expect-error Typescript isn't able to curry narrowed args that are divorced from each other.
174
+ return store._fetchManager.createSnapshot(recordIdentifierFor(this));
175
+ }
176
+ function notifyChanges(identifier, value, key, record, store) {
177
+ switch (value) {
178
+ case 'added':
179
+ case 'attributes':
180
+ if (key) {
181
+ notifyAttribute(store, identifier, key, record);
182
+ } else {
183
+ record.eachAttribute(name => {
184
+ notifyAttribute(store, identifier, name, record);
185
+ });
186
+ }
187
+ break;
188
+ case 'relationships':
189
+ if (key) {
190
+ const meta = record.constructor.relationshipsByName.get(key);
191
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
192
+ if (!test) {
193
+ throw new Error(`Expected to find a relationship for ${key} on ${identifier.type}`);
194
+ }
195
+ })(meta) : {};
196
+ notifyRelationship(identifier, key, record, meta);
197
+ } else {
198
+ record.eachRelationship((name, meta) => {
199
+ notifyRelationship(identifier, name, record, meta);
200
+ });
201
+ }
202
+ break;
203
+ case 'identity':
204
+ notifyInternalSignal(peekInternalSignal(withSignalStore(record), 'id'));
205
+ break;
206
+ }
207
+ }
208
+ function notifyRelationship(identifier, key, record, meta) {
209
+ if (meta.kind === 'belongsTo') {
210
+ record.notifyPropertyChange(key);
211
+ } else if (meta.kind === 'hasMany') {
212
+ const support = LEGACY_SUPPORT.get(identifier);
213
+ const manyArray = support && support._manyArrayCache[key];
214
+ const hasPromise = support && support._relationshipPromisesCache[key];
215
+ if (manyArray && hasPromise) {
216
+ // do nothing, we will notify the ManyArray directly
217
+ // once the fetch has completed.
218
+ return;
219
+ }
220
+ if (manyArray) {
221
+ notifyInternalSignal(manyArray[Context].signal);
222
+
223
+ //We need to notifyPropertyChange in the adding case because we need to make sure
224
+ //we fetch the newly added record in case it is unloaded
225
+ //TODO(Igor): Consider whether we could do this only if the record state is unloaded
226
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
227
+ if (!test) {
228
+ throw new Error(`Expected options to exist on relationship meta`);
229
+ }
230
+ })(meta.options) : {};
231
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
232
+ if (!test) {
233
+ throw new Error(`Expected async to exist on relationship meta options`);
234
+ }
235
+ })('async' in meta.options) : {};
236
+ if (meta.options.async) {
237
+ record.notifyPropertyChange(key);
238
+ }
239
+ }
240
+ }
241
+ }
242
+ function notifyAttribute(store, identifier, key, record) {
243
+ const currentValue = cacheFor(record, key);
244
+ const cache = store.cache;
245
+ if (currentValue !== cache.getAttr(identifier, key)) {
246
+ record.notifyPropertyChange(key);
247
+ }
248
+ }
249
+ const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
250
+ const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
251
+ const PRIMARY_ATTRIBUTE_KEY = 'base';
252
+ function isInvalidError(error) {
253
+ return !!error && error instanceof Error && 'isAdapterError' in error && error.isAdapterError === true && 'code' in error && error.code === 'InvalidError';
254
+ }
255
+
256
+ /**
257
+ Historically WarpDrive managed a state machine
258
+ for each record, the localState for which
259
+ was reflected onto Model.
260
+
261
+ This implements the flags and stateName for backwards compat
262
+ with the state tree that used to be possible (listed below).
263
+
264
+ stateName and dirtyType are candidates for deprecation.
265
+
266
+ root
267
+ empty
268
+ deleted // hidden from stateName
269
+ preloaded // hidden from stateName
270
+
271
+ loading
272
+ empty // hidden from stateName
273
+ preloaded // hidden from stateName
274
+
275
+ loaded
276
+ saved
277
+ updated
278
+ uncommitted
279
+ invalid
280
+ inFlight
281
+ created
282
+ uncommitted
283
+ invalid
284
+ inFlight
285
+
286
+ deleted
287
+ saved
288
+ new // hidden from stateName
289
+ uncommitted
290
+ invalid
291
+ inFlight
292
+
293
+ @hideconstructor
294
+ @private
295
+ */
296
+ class RecordState {
297
+ /** @internal */
298
+
299
+ /** @internal */
300
+
301
+ /** @internal */
302
+
303
+ /** @internal */
304
+
305
+ /** @internal */
306
+
307
+ /** @internal */
308
+
309
+ /** @internal */
310
+
311
+ /** @internal */
312
+
313
+ /** @internal */
314
+
315
+ /** @internal */
316
+
317
+ /** @internal */
318
+
319
+ constructor(record) {
320
+ const store = storeFor(record, false);
321
+ const identity = recordIdentifierFor$1(record);
322
+ this.identifier = identity;
323
+ this.record = record;
324
+ this.cache = store.cache;
325
+ this.pendingCount = 0;
326
+ this.fulfilledCount = 0;
327
+ this.rejectedCount = 0;
328
+ this._errorRequests = [];
329
+ this._lastError = null;
330
+ const requests = store.getRequestStateService();
331
+ const notifications = store.notifications;
332
+ const handleRequest = req => {
333
+ if (req.type === 'mutation') {
334
+ switch (req.state) {
335
+ case 'pending':
336
+ this.isSaving = true;
337
+ break;
338
+ case 'rejected':
339
+ this.isSaving = false;
340
+ this._lastError = req;
341
+ if (!(req.response && isInvalidError(req.response.data))) {
342
+ this._errorRequests.push(req);
343
+ }
344
+ notifyErrorsStateChanged(this);
345
+ break;
346
+ case 'fulfilled':
347
+ this._errorRequests = [];
348
+ this._lastError = null;
349
+ this.isSaving = false;
350
+ this.notify('isDirty');
351
+ notifyErrorsStateChanged(this);
352
+ break;
353
+ }
354
+ } else {
355
+ switch (req.state) {
356
+ case 'pending':
357
+ this.pendingCount++;
358
+ this.notify('isLoading');
359
+ break;
360
+ case 'rejected':
361
+ this.pendingCount--;
362
+ this._lastError = req;
363
+ if (!(req.response && isInvalidError(req.response.data))) {
364
+ this._errorRequests.push(req);
365
+ }
366
+ this.notify('isLoading');
367
+ notifyErrorsStateChanged(this);
368
+ break;
369
+ case 'fulfilled':
370
+ this.pendingCount--;
371
+ this.fulfilledCount++;
372
+ this.notify('isLoading');
373
+ this.notify('isDirty');
374
+ notifyErrorsStateChanged(this);
375
+ this._errorRequests = [];
376
+ this._lastError = null;
377
+ break;
378
+ }
379
+ }
380
+ };
381
+ requests.subscribeForRecord(identity, handleRequest);
382
+
383
+ // we instantiate lazily
384
+ // so we grab anything we don't have yet
385
+ const lastRequest = requests.getLastRequestForRecord(identity);
386
+ if (lastRequest) {
387
+ handleRequest(lastRequest);
388
+ }
389
+ this.handler = notifications.subscribe(identity, (identifier, type, key) => {
390
+ switch (type) {
391
+ case 'state':
392
+ this.notify('isSaved');
393
+ this.notify('isNew');
394
+ this.notify('isDeleted');
395
+ this.notify('isDirty');
396
+ break;
397
+ case 'attributes':
398
+ this.notify('isEmpty');
399
+ this.notify('isDirty');
400
+ break;
401
+ case 'errors':
402
+ this.updateInvalidErrors(this.record.errors);
403
+ this.notify('isValid');
404
+ break;
405
+ }
406
+ });
407
+ }
408
+
409
+ /** @internal */
410
+ destroy() {
411
+ storeFor(this.record, false).notifications.unsubscribe(this.handler);
412
+ }
413
+
414
+ /** @internal */
415
+ notify(key) {
416
+ const signals = withSignalStore(this);
417
+ const signal = peekInternalSignal(signals, key);
418
+ if (signal) {
419
+ notifyInternalSignal(signal);
420
+ }
421
+ }
422
+
423
+ /** @internal */
424
+ updateInvalidErrors(errors) {
425
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
426
+ if (!test) {
427
+ throw new Error(`Expected the Cache instance for ${this.identifier.lid} to implement getErrors(identifier)`);
428
+ }
429
+ })(typeof this.cache.getErrors === 'function') : {};
430
+ const jsonApiErrors = this.cache.getErrors(this.identifier);
431
+ errors.clear();
432
+ for (let i = 0; i < jsonApiErrors.length; i++) {
433
+ const error = jsonApiErrors[i];
434
+ if (error.source && error.source.pointer) {
435
+ const keyMatch = error.source.pointer.match(SOURCE_POINTER_REGEXP);
436
+ let key;
437
+ if (keyMatch) {
438
+ key = keyMatch[2];
439
+ } else if (error.source.pointer.search(SOURCE_POINTER_PRIMARY_REGEXP) !== -1) {
440
+ key = PRIMARY_ATTRIBUTE_KEY;
441
+ }
442
+ if (key) {
443
+ const errMsg = error.detail || error.title;
444
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
445
+ if (!test) {
446
+ throw new Error(`Expected field error to have a detail or title to use as the message`);
447
+ }
448
+ })(errMsg) : {};
449
+ errors.add(key, errMsg);
450
+ }
451
+ }
452
+ }
453
+ }
454
+
455
+ /** @internal */
456
+ cleanErrorRequests() {
457
+ this.notify('isValid');
458
+ this.notify('isError');
459
+ this.notify('adapterError');
460
+ this._errorRequests = [];
461
+ this._lastError = null;
462
+ }
463
+ get isLoading() {
464
+ return !this.isLoaded && this.pendingCount > 0 && this.fulfilledCount === 0;
465
+ }
466
+ static {
467
+ decorateMethodV2(this.prototype, "isLoading", [gate]);
468
+ }
469
+ get isLoaded() {
470
+ if (this.isNew) {
471
+ return true;
472
+ }
473
+ return this.fulfilledCount > 0 || !this.isEmpty;
474
+ }
475
+ static {
476
+ decorateMethodV2(this.prototype, "isLoaded", [gate]);
477
+ }
478
+ get isSaved() {
479
+ const rd = this.cache;
480
+ if (this.isDeleted) {
481
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
482
+ if (!test) {
483
+ throw new Error(`Expected Cache to implement isDeletionCommitted()`);
484
+ }
485
+ })(typeof rd.isDeletionCommitted === 'function') : {};
486
+ return rd.isDeletionCommitted(this.identifier);
487
+ }
488
+ if (this.isNew || this.isEmpty || !this.isValid || this.isDirty || this.isLoading) {
489
+ return false;
490
+ }
491
+ return true;
492
+ }
493
+ static {
494
+ decorateMethodV2(this.prototype, "isSaved", [gate]);
495
+ }
496
+ get isEmpty() {
497
+ const rd = this.cache;
498
+ // TODO this is not actually an RFC'd concept. Determine the
499
+ // correct heuristic to replace this with.
500
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
501
+ if (!test) {
502
+ throw new Error(`Expected Cache to implement isEmpty()`);
503
+ }
504
+ })(typeof rd.isEmpty === 'function') : {};
505
+ return !this.isNew && rd.isEmpty(this.identifier);
506
+ }
507
+ static {
508
+ decorateMethodV2(this.prototype, "isEmpty", [gate]);
509
+ }
510
+ get isNew() {
511
+ const rd = this.cache;
512
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
513
+ if (!test) {
514
+ throw new Error(`Expected Cache to implement isNew()`);
515
+ }
516
+ })(typeof rd.isNew === 'function') : {};
517
+ return rd.isNew(this.identifier);
518
+ }
519
+ static {
520
+ decorateMethodV2(this.prototype, "isNew", [gate]);
521
+ }
522
+ get isDeleted() {
523
+ const rd = this.cache;
524
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
525
+ if (!test) {
526
+ throw new Error(`Expected Cache to implement isDeleted()`);
527
+ }
528
+ })(typeof rd.isDeleted === 'function') : {};
529
+ return rd.isDeleted(this.identifier);
530
+ }
531
+ static {
532
+ decorateMethodV2(this.prototype, "isDeleted", [gate]);
533
+ }
534
+ get isValid() {
535
+ return this.record.errors.length === 0;
536
+ }
537
+ static {
538
+ decorateMethodV2(this.prototype, "isValid", [gate]);
539
+ }
540
+ get isDirty() {
541
+ const rd = this.cache;
542
+ if (this.isEmpty || rd.isDeletionCommitted(this.identifier) || this.isDeleted && this.isNew) {
543
+ return false;
544
+ }
545
+ return this.isDeleted || this.isNew || rd.hasChangedAttrs(this.identifier);
546
+ }
547
+ static {
548
+ decorateMethodV2(this.prototype, "isDirty", [gate]);
549
+ }
550
+ get isError() {
551
+ const errorReq = this._errorRequests[this._errorRequests.length - 1];
552
+ if (!errorReq) {
553
+ return false;
554
+ } else {
555
+ return true;
556
+ }
557
+ }
558
+ static {
559
+ decorateMethodV2(this.prototype, "isError", [gate]);
560
+ }
561
+ get adapterError() {
562
+ const request = this._lastError;
563
+ if (!request) {
564
+ return null;
565
+ }
566
+ return request.state === 'rejected' && request.response.data;
567
+ }
568
+ static {
569
+ decorateMethodV2(this.prototype, "adapterError", [gate]);
570
+ }
571
+ get isPreloaded() {
572
+ return !this.isEmpty && this.isLoading;
573
+ }
574
+ static {
575
+ decorateMethodV2(this.prototype, "isPreloaded", [memoized]);
576
+ }
577
+ get stateName() {
578
+ // we might be empty while loading so check this first
579
+ if (this.isLoading) {
580
+ return 'root.loading';
581
+
582
+ // got nothing yet or were unloaded
583
+ } else if (this.isEmpty) {
584
+ return 'root.empty';
585
+
586
+ // deleted substates
587
+ } else if (this.isDeleted) {
588
+ if (this.isSaving) {
589
+ return 'root.deleted.inFlight';
590
+ } else if (this.isSaved) {
591
+ // TODO ensure isSaved isn't true from previous requests
592
+ return 'root.deleted.saved';
593
+ } else if (!this.isValid) {
594
+ return 'root.deleted.invalid';
595
+ } else {
596
+ return 'root.deleted.uncommitted';
597
+ }
598
+
599
+ // loaded.created substates
600
+ } else if (this.isNew) {
601
+ if (this.isSaving) {
602
+ return 'root.loaded.created.inFlight';
603
+ } else if (!this.isValid) {
604
+ return 'root.loaded.created.invalid';
605
+ }
606
+ return 'root.loaded.created.uncommitted';
607
+
608
+ // loaded.updated substates
609
+ } else if (this.isSaving) {
610
+ return 'root.loaded.updated.inFlight';
611
+ } else if (!this.isValid) {
612
+ return 'root.loaded.updated.invalid';
613
+ } else if (this.isDirty) {
614
+ return 'root.loaded.updated.uncommitted';
615
+
616
+ // if nothing remains, we are loaded saved!
617
+ } else {
618
+ return 'root.loaded.saved';
619
+ }
620
+ }
621
+ static {
622
+ decorateMethodV2(this.prototype, "stateName", [memoized]);
623
+ }
624
+ get dirtyType() {
625
+ // we might be empty while loading so check this first
626
+ if (this.isLoading || this.isEmpty) {
627
+ return '';
628
+
629
+ // deleted substates
630
+ } else if (this.isDirty && this.isDeleted) {
631
+ return 'deleted';
632
+
633
+ // loaded.created substates
634
+ } else if (this.isNew) {
635
+ return 'created';
636
+
637
+ // loaded.updated substates
638
+ } else if (this.isSaving || !this.isValid || this.isDirty) {
639
+ return 'updated';
640
+
641
+ // if nothing remains, we are loaded saved!
642
+ } else {
643
+ return '';
644
+ }
645
+ }
646
+ static {
647
+ decorateMethodV2(this.prototype, "dirtyType", [memoized]);
648
+ }
649
+ }
650
+ defineSignal(RecordState.prototype, 'isSaving', false);
651
+ function notifyErrorsStateChanged(state) {
652
+ state.notify('isValid');
653
+ state.notify('isError');
654
+ state.notify('adapterError');
655
+ }
656
+
657
+ /*
658
+ * This decorator allows us to lazily compute
659
+ * an expensive getter on first-access and thereafter
660
+ * never recompute it.
661
+ */
662
+ function computeOnce(target, propertyName, desc) {
663
+ const cache = new WeakMap();
664
+ // eslint-disable-next-line @typescript-eslint/unbound-method
665
+ const getter = desc.get;
666
+ desc.get = function () {
667
+ let meta = cache.get(this);
668
+ if (!meta) {
669
+ meta = {
670
+ hasComputed: false,
671
+ value: undefined
672
+ };
673
+ cache.set(this, meta);
674
+ }
675
+ if (!meta.hasComputed) {
676
+ meta.value = getter.call(this);
677
+ meta.hasComputed = true;
678
+ }
679
+ return meta.value;
680
+ };
681
+ return desc;
682
+ }
683
+ /**
684
+ * Base class from which Models can be defined.
685
+ *
686
+ * ::: code-group
687
+ *
688
+ * ```js [app/models/user.js]
689
+ * import { Model, attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
690
+ *
691
+ * export default class User extends Model {
692
+ * @attr name;
693
+ * @attr('number') age;
694
+ * @hasMany('post', { async: true, inverse: null }) posts;
695
+ * @belongsTo('group', { async: false, inverse: 'users' }) group;
696
+ * }
697
+ * ```
698
+ *
699
+ * ```ts [app/models/user.ts]
700
+ * import { Model, attr, belongsTo, hasMany, type AsyncHasMany } from '@warp-drive/legacy/model';
701
+ * import type { NumberTransform } from '@ember-data/serializer/transform';
702
+ * import type Group from './group';
703
+ * import type Post from './post';
704
+ *
705
+ * export default class User extends Model {
706
+ * @attr declare name: string;
707
+ *
708
+ * @attr<NumberTransform>('number')
709
+ * declare age: number;
710
+ *
711
+ * @hasMany('post', { async: true, inverse: null })
712
+ * declare posts: AsyncHasMany<Post>;
713
+ *
714
+ * @belongsTo('group', { async: false, inverse: 'users' })
715
+ * declare group: Group | null;
716
+ * }
717
+ * ```
718
+ *
719
+ * :::
720
+ *
721
+ * Models both define the schema for a resource type and provide
722
+ * the class to use as the reactive object for data of resource
723
+ * of that type.
724
+ *
725
+ * @public
726
+ * @noInheritDoc
727
+ * @hideconstructor
728
+ * @legacy
729
+ */
730
+ class Model extends EmberObject {
731
+ /** @internal */
732
+ init(options) {
733
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
734
+ if (!options?._secretInit && !options?._createProps) {
735
+ throw new Error('You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.');
736
+ }
737
+ }
738
+ const createProps = options._createProps;
739
+ const _secretInit = options._secretInit;
740
+ options._createProps = null;
741
+ options._secretInit = null;
742
+ const store = this.store = _secretInit.store;
743
+ super.init(options);
744
+ this[RecordStore] = store;
745
+ const identity = _secretInit.identifier;
746
+ _secretInit.cb(this, identity, _secretInit.store);
747
+ this.___recordState = macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? new RecordState(this) : null;
748
+ this.setProperties(createProps);
749
+ const notifications = store.notifications;
750
+ this.___private_notifications = notifications.subscribe(identity, (identifier, type, field) => {
751
+ notifyChanges(identifier, type, field, this, store);
752
+ });
753
+ }
754
+
755
+ /** @private */
756
+ // @ts-expect-error destroy should not return a value, but ember's types force it to
757
+ destroy() {
758
+ const identifier = recordIdentifierFor(this);
759
+ this.___recordState?.destroy();
760
+ const store = storeFor(this, false);
761
+ store.notifications.unsubscribe(this.___private_notifications);
762
+ const support = LEGACY_SUPPORT.get(identifier);
763
+ if (support) {
764
+ support.destroy();
765
+ LEGACY_SUPPORT.delete(identifier);
766
+ }
767
+ super.destroy();
768
+ }
769
+
770
+ /**
771
+ If this property is `true` the record is in the `empty`
772
+ state. Empty is the first state all records enter after they have
773
+ been created. Most records created by the store will quickly
774
+ transition to the `loading` state if data needs to be fetched from
775
+ the server or the `created` state if the record is created on the
776
+ client. A record can also enter the empty state if the adapter is
777
+ unable to locate the record.
778
+ @property isEmpty
779
+ @public
780
+ @readonly
781
+ */
782
+ get isEmpty() {
783
+ return this.currentState.isEmpty;
784
+ }
785
+
786
+ /**
787
+ If this property is `true` the record is in the `loading` state. A
788
+ record enters this state when the store asks the adapter for its
789
+ data. It remains in this state until the adapter provides the
790
+ requested data.
791
+ @property isLoading
792
+ @public
793
+ @readonly
794
+ */
795
+ static {
796
+ decorateMethodV2(this.prototype, "isEmpty", [memoized]);
797
+ }
798
+ get isLoading() {
799
+ return this.currentState.isLoading;
800
+ }
801
+
802
+ /**
803
+ If this property is `true` the record is in the `loaded` state. A
804
+ record enters this state when its data is populated. Most of a
805
+ record's lifecycle is spent inside substates of the `loaded`
806
+ state.
807
+ Example
808
+ ```javascript
809
+ let record = store.createRecord('model');
810
+ record.isLoaded; // true
811
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
812
+ model.isLoaded;
813
+ ```
814
+ @property isLoaded
815
+ @public
816
+ @readonly
817
+ */
818
+ static {
819
+ decorateMethodV2(this.prototype, "isLoading", [memoized]);
820
+ }
821
+ get isLoaded() {
822
+ return this.currentState.isLoaded;
823
+ }
824
+
825
+ /**
826
+ If this property is `true` the record is in the `dirty` state. The
827
+ record has local changes that have not yet been saved by the
828
+ adapter. This includes records that have been created (but not yet
829
+ saved) or deleted.
830
+ Example
831
+ ```javascript
832
+ let record = store.createRecord('model');
833
+ record.hasDirtyAttributes; // true
834
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
835
+ model.hasDirtyAttributes; // false
836
+ model.foo = 'some value';
837
+ model.hasDirtyAttributes; // true
838
+ ```
839
+ @since 1.13.0
840
+ @property hasDirtyAttributes
841
+ @public
842
+ @readonly
843
+ */
844
+ static {
845
+ decorateMethodV2(this.prototype, "isLoaded", [memoized]);
846
+ }
847
+ get hasDirtyAttributes() {
848
+ return this.currentState.isDirty;
849
+ }
850
+
851
+ /**
852
+ If this property is `true` the record is in the `saving` state. A
853
+ record enters the saving state when `save` is called, but the
854
+ adapter has not yet acknowledged that the changes have been
855
+ persisted to the backend.
856
+ Example
857
+ ```javascript
858
+ let record = store.createRecord('model');
859
+ record.isSaving; // false
860
+ let promise = record.save();
861
+ record.isSaving; // true
862
+ promise.then(function() {
863
+ record.isSaving; // false
864
+ });
865
+ ```
866
+ @property isSaving
867
+ @public
868
+ @readonly
869
+ */
870
+ static {
871
+ decorateMethodV2(this.prototype, "hasDirtyAttributes", [memoized]);
872
+ }
873
+ get isSaving() {
874
+ return this.currentState.isSaving;
875
+ }
876
+
877
+ /**
878
+ If this property is `true` the record is in the `deleted` state
879
+ and has been marked for deletion. When `isDeleted` is true and
880
+ `hasDirtyAttributes` is true, the record is deleted locally but the deletion
881
+ was not yet persisted. When `isSaving` is true, the change is
882
+ in-flight. When both `hasDirtyAttributes` and `isSaving` are false, the
883
+ change has persisted.
884
+ Example
885
+ ```javascript
886
+ let record = store.createRecord('model');
887
+ record.isDeleted; // false
888
+ record.deleteRecord();
889
+ // Locally deleted
890
+ record.isDeleted; // true
891
+ record.hasDirtyAttributes; // true
892
+ record.isSaving; // false
893
+ // Persisting the deletion
894
+ let promise = record.save();
895
+ record.isDeleted; // true
896
+ record.isSaving; // true
897
+ // Deletion Persisted
898
+ promise.then(function() {
899
+ record.isDeleted; // true
900
+ record.isSaving; // false
901
+ record.hasDirtyAttributes; // false
902
+ });
903
+ ```
904
+ @property isDeleted
905
+ @public
906
+ @readonly
907
+ */
908
+ static {
909
+ decorateMethodV2(this.prototype, "isSaving", [memoized]);
910
+ }
911
+ get isDeleted() {
912
+ return this.currentState.isDeleted;
913
+ }
914
+
915
+ /**
916
+ If this property is `true` the record is in the `new` state. A
917
+ record will be in the `new` state when it has been created on the
918
+ client and the adapter has not yet report that it was successfully
919
+ saved.
920
+ Example
921
+ ```javascript
922
+ let record = store.createRecord('model');
923
+ record.isNew; // true
924
+ record.save().then(function(model) {
925
+ model.isNew; // false
926
+ });
927
+ ```
928
+ @property isNew
929
+ @public
930
+ @readonly
931
+ */
932
+ static {
933
+ decorateMethodV2(this.prototype, "isDeleted", [memoized]);
934
+ }
935
+ get isNew() {
936
+ return this.currentState.isNew;
937
+ }
938
+
939
+ /**
940
+ If this property is `true` the record is in the `valid` state.
941
+ A record will be in the `valid` state when the adapter did not report any
942
+ server-side validation failures.
943
+ @property isValid
944
+ @public
945
+ @readonly
946
+ */
947
+ static {
948
+ decorateMethodV2(this.prototype, "isNew", [memoized]);
949
+ }
950
+ get isValid() {
951
+ return this.currentState.isValid;
952
+ }
953
+
954
+ /**
955
+ If the record is in the dirty state this property will report what
956
+ kind of change has caused it to move into the dirty
957
+ state. Possible values are:
958
+ - `created` The record has been created by the client and not yet saved to the adapter.
959
+ - `updated` The record has been updated by the client and not yet saved to the adapter.
960
+ - `deleted` The record has been deleted by the client and not yet saved to the adapter.
961
+ Example
962
+ ```javascript
963
+ let record = store.createRecord('model');
964
+ record.dirtyType; // 'created'
965
+ ```
966
+ @property dirtyType
967
+ @public
968
+ @readonly
969
+ */
970
+ static {
971
+ decorateMethodV2(this.prototype, "isValid", [memoized]);
972
+ }
973
+ get dirtyType() {
974
+ return this.currentState.dirtyType;
975
+ }
976
+
977
+ /**
978
+ If `true` the adapter reported that it was unable to save local
979
+ changes to the backend for any reason other than a server-side
980
+ validation error.
981
+ Example
982
+ ```javascript
983
+ record.isError; // false
984
+ record.set('foo', 'valid value');
985
+ record.save().then(null, function() {
986
+ record.isError; // true
987
+ });
988
+ ```
989
+ @property isError
990
+ @public
991
+ @readonly
992
+ */
993
+ static {
994
+ decorateMethodV2(this.prototype, "dirtyType", [memoized]);
995
+ }
996
+ get isError() {
997
+ return this.currentState.isError;
998
+ }
999
+ static {
1000
+ decorateMethodV2(this.prototype, "isError", [memoized]);
1001
+ }
1002
+ set isError(v) {
1003
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1004
+ throw new Error(`isError is not directly settable`);
1005
+ }
1006
+ }
1007
+
1008
+ /**
1009
+ If `true` the store is attempting to reload the record from the adapter.
1010
+ Example
1011
+ ```javascript
1012
+ record.isReloading; // false
1013
+ record.reload();
1014
+ record.isReloading; // true
1015
+ ```
1016
+ @property isReloading
1017
+ @public
1018
+ @readonly
1019
+ */
1020
+
1021
+ /**
1022
+ All ember models have an id property. This is an identifier
1023
+ managed by an external source. These are always coerced to be
1024
+ strings before being used internally. Note when declaring the
1025
+ attributes for a model it is an error to declare an id
1026
+ attribute.
1027
+ ```javascript
1028
+ let record = store.createRecord('model');
1029
+ record.id; // null
1030
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
1031
+ model.id; // '1'
1032
+ ```
1033
+ @property id
1034
+ @public
1035
+ */
1036
+ get id() {
1037
+ // this guard exists, because some dev-only deprecation code
1038
+ // (addListener via validatePropertyInjections) invokes toString before the
1039
+ // object is real.
1040
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1041
+ try {
1042
+ return recordIdentifierFor(this).id;
1043
+ } catch {
1044
+ return null;
1045
+ }
1046
+ }
1047
+ return recordIdentifierFor(this).id;
1048
+ }
1049
+ static {
1050
+ decorateMethodV2(this.prototype, "id", [gate]);
1051
+ }
1052
+ set id(id) {
1053
+ const normalizedId = coerceId(id);
1054
+ const identifier = recordIdentifierFor(this);
1055
+ const didChange = normalizedId !== identifier.id;
1056
+ assertPrivateStore(this.store);
1057
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1058
+ if (!test) {
1059
+ throw new Error(`Cannot set ${identifier.type} record's id to ${id}, because id is already ${identifier.id}`);
1060
+ }
1061
+ })(!didChange || identifier.id === null) : {};
1062
+ if (normalizedId !== null && didChange) {
1063
+ this.store._instanceCache.setRecordId(identifier, normalizedId);
1064
+ this.store.notifications.notify(identifier, 'identity', null);
1065
+ }
1066
+ }
1067
+ toString() {
1068
+ return `<model::${this.constructor.modelName}:${this.id}>`;
1069
+ }
1070
+
1071
+ /**
1072
+ @property currentState
1073
+ @private
1074
+ */
1075
+ // TODO we can probably make this a computeOnce
1076
+ // we likely do not need to notify the currentState root anymore
1077
+ get currentState() {
1078
+ // descriptors are called with the wrong `this` context during mergeMixins
1079
+ // when using legacy/classic ember classes. Basically: lazy in prod and eager in dev.
1080
+ // so we do this to try to steer folks to the nicer "dont user currentState"
1081
+ // error.
1082
+ if (macroCondition(!getGlobalConfig().WarpDrive.env.DEBUG)) {
1083
+ if (!this.___recordState) {
1084
+ this.___recordState = new RecordState(this);
1085
+ }
1086
+ }
1087
+ return this.___recordState;
1088
+ }
1089
+ static {
1090
+ decorateMethodV2(this.prototype, "currentState", [gate]);
1091
+ }
1092
+ set currentState(_v) {
1093
+ throw new Error('cannot set currentState');
1094
+ }
1095
+
1096
+ /**
1097
+ The store service instance which created this record instance
1098
+ @property store
1099
+ @public
1100
+ */
1101
+
1102
+ /**
1103
+ When the record is in the `invalid` state this object will contain
1104
+ any errors returned by the adapter. When present the errors hash
1105
+ contains keys corresponding to the invalid property names
1106
+ and values which are arrays of Javascript objects with two keys:
1107
+ - `message` A string containing the error message from the backend
1108
+ - `attribute` The name of the property associated with this error message
1109
+ ```javascript
1110
+ record.errors.length; // 0
1111
+ record.set('foo', 'invalid value');
1112
+ record.save().catch(function() {
1113
+ record.errors.foo;
1114
+ // [{message: 'foo should be a number.', attribute: 'foo'}]
1115
+ });
1116
+ ```
1117
+ The `errors` property is useful for displaying error messages to
1118
+ the user.
1119
+ ```handlebars
1120
+ <label>Username: <Input @value={{@model.username}} /> </label>
1121
+ {{#each @model.errors.username as |error|}}
1122
+ <div class="error">
1123
+ {{error.message}}
1124
+ </div>
1125
+ {{/each}}
1126
+ <label>Email: <Input @value={{@model.email}} /> </label>
1127
+ {{#each @model.errors.email as |error|}}
1128
+ <div class="error">
1129
+ {{error.message}}
1130
+ </div>
1131
+ {{/each}}
1132
+ ```
1133
+ You can also access the special `messages` property on the error
1134
+ object to get an array of all the error strings.
1135
+ ```handlebars
1136
+ {{#each @model.errors.messages as |message|}}
1137
+ <div class="error">
1138
+ {{message}}
1139
+ </div>
1140
+ {{/each}}
1141
+ ```
1142
+ @property errors
1143
+ @public
1144
+ */
1145
+ get errors() {
1146
+ const errors = Errors.create({
1147
+ __record: this
1148
+ });
1149
+ this.currentState.updateInvalidErrors(errors);
1150
+ return errors;
1151
+ }
1152
+
1153
+ /**
1154
+ This property holds the `AdapterError` object with which
1155
+ last adapter operation was rejected.
1156
+ @property adapterError
1157
+ @public
1158
+ */
1159
+ static {
1160
+ decorateMethodV2(this.prototype, "errors", [computeOnce]);
1161
+ }
1162
+ get adapterError() {
1163
+ return this.currentState.adapterError;
1164
+ }
1165
+ static {
1166
+ decorateMethodV2(this.prototype, "adapterError", [memoized]);
1167
+ }
1168
+ set adapterError(v) {
1169
+ throw new Error(`adapterError is not directly settable`);
1170
+ }
1171
+
1172
+ /*
1173
+ We hook the default implementation to ensure
1174
+ our tagged properties are properly notified
1175
+ as well. We still super for everything because
1176
+ sync observers require a direct call occuring
1177
+ to trigger their flush. We wouldn't need to
1178
+ super in 4.0+ where sync observers are removed.
1179
+ */
1180
+ // @ts-expect-error no return is necessary, but Ember's types are forcing it
1181
+ notifyPropertyChange(prop) {
1182
+ const signals = withSignalStore(this);
1183
+ entangleSignal(signals, this, prop, undefined);
1184
+ super.notifyPropertyChange(prop);
1185
+ }
1186
+
1187
+ /** @internal */
1188
+ attr() {
1189
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1190
+ {
1191
+ throw new Error('The `attr` method is not available on Model, a Snapshot was probably expected. Are you passing a Model instead of a Snapshot to your serializer?');
1192
+ }
1193
+ })() : {};
1194
+ }
1195
+
1196
+ /**
1197
+ Given a callback, iterates over each of the relationships in the model,
1198
+ invoking the callback with the name of each relationship and its relationship
1199
+ descriptor.
1200
+ The callback method you provide should have the following signature (all
1201
+ parameters are optional):
1202
+ ```javascript
1203
+ function(name, descriptor);
1204
+ ```
1205
+ - `name` the name of the current property in the iteration
1206
+ - `descriptor` the meta object that describes this relationship
1207
+ The relationship descriptor argument is an object with the following properties.
1208
+ - **name** <span class="type">String</span> the name of this relationship on the Model
1209
+ - **kind** <span class="type">String</span> "hasMany" or "belongsTo"
1210
+ - **options** <span class="type">Object</span> the original options hash passed when the relationship was declared
1211
+ - **parentType** <span class="type">Model</span> the type of the Model that owns this relationship
1212
+ - **type** <span class="type">String</span> the type name of the related Model
1213
+ Note that in addition to a callback, you can also pass an optional target
1214
+ object that will be set as `this` on the context.
1215
+ Example
1216
+ ```js [app/serializers/application.js]
1217
+ import JSONSerializer from '@ember-data/serializer/json';
1218
+ export default class ApplicationSerializer extends JSONSerializer {
1219
+ serialize(record, options) {
1220
+ let json = {};
1221
+ record.eachRelationship(function(name, descriptor) {
1222
+ if (descriptor.kind === 'hasMany') {
1223
+ let serializedHasManyName = name.toUpperCase() + '_IDS';
1224
+ json[serializedHasManyName] = record.get(name).map(r => r.id);
1225
+ }
1226
+ });
1227
+ return json;
1228
+ }
1229
+ }
1230
+ ```
1231
+ @public
1232
+ @param callback the callback to invoke
1233
+ @param binding the value to which the callback's `this` should be bound
1234
+ */
1235
+ eachRelationship(callback, binding) {
1236
+ this.constructor.eachRelationship(callback, binding);
1237
+ }
1238
+ relationshipFor(name) {
1239
+ return this.constructor.relationshipsByName.get(name);
1240
+ }
1241
+ inverseFor(name) {
1242
+ return this.constructor.inverseFor(name, storeFor(this, false));
1243
+ }
1244
+ eachAttribute(callback, binding) {
1245
+ this.constructor.eachAttribute(callback, binding);
1246
+ }
1247
+
1248
+ /**
1249
+ * @internal
1250
+ */
1251
+ static isModel = true;
1252
+
1253
+ /**
1254
+ Represents the model's class name as a string. This can be used to look up the model's class name through
1255
+ `Store`'s modelFor method.
1256
+ `modelName` is generated for you by WarpDrive. It will be a lowercased, dasherized string.
1257
+ For example:
1258
+ ```javascript
1259
+ store.modelFor('post').modelName; // 'post'
1260
+ store.modelFor('blog-post').modelName; // 'blog-post'
1261
+ ```
1262
+ The most common place you'll want to access `modelName` is in your serializer's `payloadKeyFromModelName` method. For example, to change payload
1263
+ keys to underscore (instead of dasherized), you might use the following code:
1264
+ ```javascript
1265
+ import RESTSerializer from '@ember-data/serializer/rest';
1266
+ import { underscore } from '<app-name>/utils/string-utils';
1267
+ export default const PostSerializer = RESTSerializer.extend({
1268
+ payloadKeyFromModelName(modelName) {
1269
+ return underscore(modelName);
1270
+ }
1271
+ });
1272
+ ```
1273
+ @property modelName
1274
+ @public
1275
+ @readonly
1276
+ */
1277
+ static modelName = null;
1278
+
1279
+ /*
1280
+ These class methods below provide relationship
1281
+ introspection abilities about relationships.
1282
+ A note about the computed properties contained here:
1283
+ **These properties are effectively sealed once called for the first time.**
1284
+ To avoid repeatedly doing expensive iteration over a model's fields, these
1285
+ values are computed once and then cached for the remainder of the runtime of
1286
+ your application.
1287
+ If your application needs to modify a class after its initial definition
1288
+ (for example, using `reopen()` to add additional attributes), make sure you
1289
+ do it before using your model with the store, which uses these properties
1290
+ extensively.
1291
+ */
1292
+
1293
+ /**
1294
+ For a given relationship name, returns the model type of the relationship.
1295
+ For example, if you define a model like this:
1296
+ ```js [app/models/post.js]
1297
+ import { Model, hasMany } from '@warp-drive/legacy/model';
1298
+ export default class PostModel extends Model {
1299
+ @hasMany('comment') comments;
1300
+ }
1301
+ ```
1302
+ Calling `store.modelFor('post').typeForRelationship('comments', store)` will return `Comment`.
1303
+ @public
1304
+ @param name the name of the relationship
1305
+ @param store an instance of Store
1306
+ @return the type of the relationship, or undefined
1307
+ */
1308
+ static typeForRelationship(name, store) {
1309
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1310
+ if (!test) {
1311
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1312
+ }
1313
+ })(this.modelName) : {};
1314
+ const relationship = this.relationshipsByName.get(name);
1315
+ return relationship && store.modelFor(relationship.type);
1316
+ }
1317
+ static get inverseMap() {
1318
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1319
+ if (!test) {
1320
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1321
+ }
1322
+ })(this.modelName) : {};
1323
+ return Object.create(null);
1324
+ }
1325
+
1326
+ /**
1327
+ Find the relationship which is the inverse of the one asked for.
1328
+ For example, if you define models like this:
1329
+ ```js [app/models/post.js]
1330
+ import { Model, hasMany } from '@warp-drive/legacy/model';
1331
+ export default class PostModel extends Model {
1332
+ @hasMany('message') comments;
1333
+ }
1334
+ ```
1335
+ ```js [app/models/message.js]
1336
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1337
+ export default class MessageModel extends Model {
1338
+ @belongsTo('post') owner;
1339
+ }
1340
+ ```
1341
+ ``` js
1342
+ store.modelFor('post').inverseFor('comments', store) // { type: 'message', name: 'owner', kind: 'belongsTo' }
1343
+ store.modelFor('message').inverseFor('owner', store) // { type: 'post', name: 'comments', kind: 'hasMany' }
1344
+ ```
1345
+ @public
1346
+ @param name the name of the relationship
1347
+ @param store
1348
+ @return the inverse relationship, or null
1349
+ */
1350
+ static {
1351
+ decorateMethodV2(this, "inverseMap", [computeOnce]);
1352
+ }
1353
+ static inverseFor(name, store) {
1354
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1355
+ if (!test) {
1356
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1357
+ }
1358
+ })(this.modelName) : {};
1359
+ const inverseMap = this.inverseMap;
1360
+ if (inverseMap[name]) {
1361
+ return inverseMap[name];
1362
+ } else {
1363
+ const inverse = this._findInverseFor(name, store);
1364
+ inverseMap[name] = inverse;
1365
+ return inverse;
1366
+ }
1367
+ }
1368
+
1369
+ //Calculate the inverse, ignoring the cache
1370
+ static _findInverseFor(name, store) {
1371
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1372
+ if (!test) {
1373
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1374
+ }
1375
+ })(this.modelName) : {};
1376
+ const relationship = this.relationshipsByName.get(name);
1377
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1378
+ if (!test) {
1379
+ throw new Error(`No relationship named '${name}' on '${this.modelName}' exists.`);
1380
+ }
1381
+ })(relationship) : {};
1382
+ if (!relationship) {
1383
+ return null;
1384
+ }
1385
+ const {
1386
+ options
1387
+ } = relationship;
1388
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1389
+ if (!test) {
1390
+ throw new Error(`Expected the relationship ${name} on ${this.modelName} to define an inverse.`);
1391
+ }
1392
+ })(options.inverse === null || typeof options.inverse === 'string' && options.inverse.length > 0) : {};
1393
+ if (options.inverse === null) {
1394
+ return null;
1395
+ }
1396
+ const schemaExists = store.schema.hasResource(relationship);
1397
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1398
+ if (!test) {
1399
+ throw new Error(`No associated schema found for '${relationship.type}' while calculating the inverse of ${name} on ${this.modelName}`);
1400
+ }
1401
+ })(schemaExists) : {};
1402
+ if (!schemaExists) {
1403
+ return null;
1404
+ }
1405
+ const inverseField = store.schema.fields(relationship).get(options.inverse);
1406
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1407
+ if (!test) {
1408
+ throw new Error(`No inverse relationship found for '${name}' on '${this.modelName}'`);
1409
+ }
1410
+ })(inverseField && (inverseField.kind === 'belongsTo' || inverseField.kind === 'hasMany')) : {};
1411
+ return inverseField || null;
1412
+ }
1413
+
1414
+ /**
1415
+ The model's relationships as a map, keyed on the type of the
1416
+ relationship. The value of each entry is an array containing a descriptor
1417
+ for each relationship with that type, describing the name of the relationship
1418
+ as well as the type.
1419
+ For example, given the following model definition:
1420
+ ```js [app/models/blog.js]
1421
+ import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';
1422
+ export default class BlogModel extends Model {
1423
+ @hasMany('user') users;
1424
+ @belongsTo('user') owner;
1425
+ @hasMany('post') posts;
1426
+ }
1427
+ ```
1428
+ This computed property would return a map describing these
1429
+ relationships, like this:
1430
+ ```javascript
1431
+ import Blog from 'app/models/blog';
1432
+ import User from 'app/models/user';
1433
+ import Post from 'app/models/post';
1434
+ let relationships = Blog.relationships;
1435
+ relationships.user;
1436
+ //=> [ { name: 'users', kind: 'hasMany' },
1437
+ // { name: 'owner', kind: 'belongsTo' } ]
1438
+ relationships.post;
1439
+ //=> [ { name: 'posts', kind: 'hasMany' } ]
1440
+ ```
1441
+ @property relationships
1442
+ @public
1443
+ @readonly
1444
+ */
1445
+
1446
+ static get relationships() {
1447
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1448
+ if (!test) {
1449
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1450
+ }
1451
+ })(this.modelName) : {};
1452
+ const map = new Map();
1453
+ const relationshipsByName = this.relationshipsByName;
1454
+
1455
+ // Loop through each computed property on the class
1456
+ relationshipsByName.forEach(desc => {
1457
+ const {
1458
+ type
1459
+ } = desc;
1460
+ if (!map.has(type)) {
1461
+ map.set(type, []);
1462
+ }
1463
+ map.get(type).push(desc);
1464
+ });
1465
+ return map;
1466
+ }
1467
+
1468
+ /**
1469
+ A hash containing lists of the model's relationships, grouped
1470
+ by the relationship kind. For example, given a model with this
1471
+ definition:
1472
+ ```js [app/models/blog.js]
1473
+ import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';
1474
+ export default class BlogModel extends Model {
1475
+ @hasMany('user') users;
1476
+ @belongsTo('user') owner;
1477
+ @hasMany('post') posts;
1478
+ }
1479
+ ```
1480
+ This property would contain the following:
1481
+ ```javascript
1482
+ import Blog from 'app/models/blog';
1483
+ let relationshipNames = Blog.relationshipNames;
1484
+ relationshipNames.hasMany;
1485
+ //=> ['users', 'posts']
1486
+ relationshipNames.belongsTo;
1487
+ //=> ['owner']
1488
+ ```
1489
+ @property relationshipNames
1490
+ @public
1491
+ @readonly
1492
+ */
1493
+ static {
1494
+ decorateMethodV2(this, "relationships", [computeOnce]);
1495
+ }
1496
+ static get relationshipNames() {
1497
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1498
+ if (!test) {
1499
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1500
+ }
1501
+ })(this.modelName) : {};
1502
+ const names = {
1503
+ hasMany: [],
1504
+ belongsTo: []
1505
+ };
1506
+ this.eachComputedProperty((name, meta) => {
1507
+ if (isRelationshipSchema(meta)) {
1508
+ names[meta.kind].push(name);
1509
+ }
1510
+ });
1511
+ return names;
1512
+ }
1513
+
1514
+ /**
1515
+ An array of types directly related to a model. Each type will be
1516
+ included once, regardless of the number of relationships it has with
1517
+ the model.
1518
+ For example, given a model with this definition:
1519
+ ```js [app/models/blog.js]
1520
+ import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';
1521
+ export default class BlogModel extends Model {
1522
+ @hasMany('user') users;
1523
+ @belongsTo('user') owner;
1524
+ @hasMany('post') posts;
1525
+ }
1526
+ ```
1527
+ This property would contain the following:
1528
+ ```javascript
1529
+ import Blog from 'app/models/blog';
1530
+ let relatedTypes = Blog.relatedTypes');
1531
+ //=> ['user', 'post']
1532
+ ```
1533
+ @property relatedTypes
1534
+ @public
1535
+ @readonly
1536
+ */
1537
+ static {
1538
+ decorateMethodV2(this, "relationshipNames", [computeOnce]);
1539
+ }
1540
+ static get relatedTypes() {
1541
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1542
+ if (!test) {
1543
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1544
+ }
1545
+ })(this.modelName) : {};
1546
+ const types = [];
1547
+ const rels = this.relationshipsObject;
1548
+ const relationships = Object.keys(rels);
1549
+
1550
+ // create an array of the unique types involved
1551
+ // in relationships
1552
+ for (let i = 0; i < relationships.length; i++) {
1553
+ const name = relationships[i];
1554
+ const meta = rels[name];
1555
+ const modelName = meta.type;
1556
+ if (!types.includes(modelName)) {
1557
+ types.push(modelName);
1558
+ }
1559
+ }
1560
+ return types;
1561
+ }
1562
+
1563
+ /**
1564
+ A map whose keys are the relationships of a model and whose values are
1565
+ relationship descriptors.
1566
+ For example, given a model with this
1567
+ definition:
1568
+ ```js [app/models/blog.js]
1569
+ import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';
1570
+ export default class BlogModel extends Model {
1571
+ @hasMany('user') users;
1572
+ @belongsTo('user') owner;
1573
+ @hasMany('post') posts;
1574
+ }
1575
+ ```
1576
+ This property would contain the following:
1577
+ ```javascript
1578
+ import Blog from 'app/models/blog';
1579
+ let relationshipsByName = Blog.relationshipsByName;
1580
+ relationshipsByName.users;
1581
+ //=> { name: 'users', kind: 'hasMany', type: 'user', options: Object }
1582
+ relationshipsByName.owner;
1583
+ //=> { name: 'owner', kind: 'belongsTo', type: 'user', options: Object }
1584
+ ```
1585
+ @property relationshipsByName
1586
+ @public
1587
+ @readonly
1588
+ */
1589
+ static {
1590
+ decorateMethodV2(this, "relatedTypes", [computeOnce]);
1591
+ }
1592
+ static get relationshipsByName() {
1593
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1594
+ if (!test) {
1595
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1596
+ }
1597
+ })(this.modelName) : {};
1598
+ const map = new Map();
1599
+ const rels = this.relationshipsObject;
1600
+ const relationships = Object.keys(rels);
1601
+ for (let i = 0; i < relationships.length; i++) {
1602
+ const name = relationships[i];
1603
+ const value = rels[name];
1604
+ map.set(value.name, value);
1605
+ }
1606
+ return map;
1607
+ }
1608
+ static {
1609
+ decorateMethodV2(this, "relationshipsByName", [computeOnce]);
1610
+ }
1611
+ static get relationshipsObject() {
1612
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1613
+ if (!test) {
1614
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1615
+ }
1616
+ })(this.modelName) : {};
1617
+ const relationships = Object.create(null);
1618
+ const modelName = this.modelName;
1619
+ this.eachComputedProperty((name, meta) => {
1620
+ if (!isRelationshipSchema(meta)) {
1621
+ return;
1622
+ }
1623
+ // TODO deprecate key being here
1624
+ meta.key = name;
1625
+ meta.name = name;
1626
+ relationships[name] = meta;
1627
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1628
+ if (!test) {
1629
+ throw new Error(`Expected options in meta`);
1630
+ }
1631
+ })(meta.options && typeof meta.options === 'object') : {};
1632
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1633
+ if (!test) {
1634
+ throw new Error(`You should not specify both options.as and options.inverse as null on ${modelName}.${meta.name}, as if there is no inverse field there is no abstract type to conform to. You may have intended for this relationship to be polymorphic, or you may have mistakenly set inverse to null.`);
1635
+ }
1636
+ })(!(meta.options.inverse === null && meta.options.as?.length)) : {};
1637
+ });
1638
+ return relationships;
1639
+ }
1640
+
1641
+ /**
1642
+ A map whose keys are the fields of the model and whose values are strings
1643
+ describing the kind of the field. A model's fields are the union of all of its
1644
+ attributes and relationships.
1645
+ For example:
1646
+ ```js [app/models/blog.js]
1647
+ import { Model, attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
1648
+ export default class BlogModel extends Model {
1649
+ @hasMany('user') users;
1650
+ @belongsTo('user') owner;
1651
+ @hasMany('post') posts;
1652
+ @attr('string') title;
1653
+ }
1654
+ ```
1655
+ ```js
1656
+ import Blog from 'app/models/blog'
1657
+ let fields = Blog.fields;
1658
+ fields.forEach(function(kind, field) {
1659
+ // do thing
1660
+ });
1661
+ // prints:
1662
+ // users, hasMany
1663
+ // owner, belongsTo
1664
+ // posts, hasMany
1665
+ // title, attribute
1666
+ ```
1667
+ @property fields
1668
+ @public
1669
+ @readonly
1670
+ */
1671
+ static {
1672
+ decorateMethodV2(this, "relationshipsObject", [computeOnce]);
1673
+ }
1674
+ static get fields() {
1675
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1676
+ if (!test) {
1677
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1678
+ }
1679
+ })(this.modelName) : {};
1680
+ const map = new Map();
1681
+ this.eachComputedProperty((name, meta) => {
1682
+ if (isRelationshipSchema(meta)) {
1683
+ map.set(name, meta.kind);
1684
+ } else if (isAttributeSchema(meta)) {
1685
+ map.set(name, 'attribute');
1686
+ }
1687
+ });
1688
+ return map;
1689
+ }
1690
+
1691
+ /**
1692
+ Given a callback, iterates over each of the relationships in the model,
1693
+ invoking the callback with the name of each relationship and its relationship
1694
+ descriptor.
1695
+ @public
1696
+ @param {Function} callback the callback to invoke
1697
+ @param {any} binding the value to which the callback's `this` should be bound
1698
+ */
1699
+ static {
1700
+ decorateMethodV2(this, "fields", [computeOnce]);
1701
+ }
1702
+ static eachRelationship(callback, binding) {
1703
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1704
+ if (!test) {
1705
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1706
+ }
1707
+ })(this.modelName) : {};
1708
+ this.relationshipsByName.forEach((relationship, name) => {
1709
+ callback.call(binding, name, relationship);
1710
+ });
1711
+ }
1712
+
1713
+ /**
1714
+ Given a callback, iterates over each of the types related to a model,
1715
+ invoking the callback with the related type's class. Each type will be
1716
+ returned just once, regardless of how many different relationships it has
1717
+ with a model.
1718
+ @public
1719
+ @param {Function} callback the callback to invoke
1720
+ @param {any} binding the value to which the callback's `this` should be bound
1721
+ */
1722
+ static eachRelatedType(callback, binding) {
1723
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1724
+ if (!test) {
1725
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1726
+ }
1727
+ })(this.modelName) : {};
1728
+ const relationshipTypes = this.relatedTypes;
1729
+ for (let i = 0; i < relationshipTypes.length; i++) {
1730
+ const type = relationshipTypes[i];
1731
+ callback.call(binding, type);
1732
+ }
1733
+ }
1734
+
1735
+ /**
1736
+ *
1737
+ * @private
1738
+ * @deprecated
1739
+ */
1740
+ static determineRelationshipType(knownSide, store) {
1741
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1742
+ if (!test) {
1743
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1744
+ }
1745
+ })(this.modelName) : {};
1746
+ const knownKey = knownSide.name;
1747
+ const knownKind = knownSide.kind;
1748
+ const inverse = this.inverseFor(knownKey, store);
1749
+ // let key;
1750
+
1751
+ if (!inverse) {
1752
+ return knownKind === 'belongsTo' ? 'oneToNone' : 'manyToNone';
1753
+ }
1754
+
1755
+ // key = inverse.name;
1756
+ const otherKind = inverse.kind;
1757
+ if (otherKind === 'belongsTo') {
1758
+ return knownKind === 'belongsTo' ? 'oneToOne' : 'manyToOne';
1759
+ } else {
1760
+ return knownKind === 'belongsTo' ? 'oneToMany' : 'manyToMany';
1761
+ }
1762
+ }
1763
+
1764
+ /**
1765
+ A map whose keys are the attributes of the model (properties
1766
+ described by attr) and whose values are the meta object for the
1767
+ property.
1768
+ Example
1769
+ ```js [app/models/person.js]
1770
+ import { Model, attr } from '@warp-drive/legacy/model';
1771
+ export default class PersonModel extends Model {
1772
+ @attr('string') firstName;
1773
+ @attr('string') lastName;
1774
+ @attr('date') birthday;
1775
+ }
1776
+ ```
1777
+ ```javascript
1778
+ import Person from 'app/models/person'
1779
+ let attributes = Person.attributes
1780
+ attributes.forEach(function(meta, name) {
1781
+ // do thing
1782
+ });
1783
+ // prints:
1784
+ // firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
1785
+ // lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
1786
+ // birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
1787
+ ```
1788
+ @property attributes
1789
+ @public
1790
+ @readonly
1791
+ */
1792
+ static get attributes() {
1793
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1794
+ if (!test) {
1795
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1796
+ }
1797
+ })(this.modelName) : {};
1798
+ const map = new Map();
1799
+ this.eachComputedProperty((name, meta) => {
1800
+ if (isAttributeSchema(meta)) {
1801
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1802
+ if (!test) {
1803
+ throw new Error("You may not set 'id' as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " + this.toString());
1804
+ }
1805
+ })(name !== 'id') : {};
1806
+
1807
+ // TODO deprecate key being here
1808
+ meta.key = name;
1809
+ meta.name = name;
1810
+ map.set(name, meta);
1811
+ }
1812
+ });
1813
+ return map;
1814
+ }
1815
+
1816
+ /**
1817
+ A map whose keys are the attributes of the model (properties
1818
+ described by attr) and whose values are type of transformation
1819
+ applied to each attribute. This map does not include any
1820
+ attributes that do not have an transformation type.
1821
+ Example
1822
+ ```js [app/models/person.js]
1823
+ import { Model, attr } from '@warp-drive/legacy/model';
1824
+ export default class PersonModel extends Model {
1825
+ @attr firstName;
1826
+ @attr('string') lastName;
1827
+ @attr('date') birthday;
1828
+ }
1829
+ ```
1830
+ ```javascript
1831
+ import Person from 'app/models/person';
1832
+ let transformedAttributes = Person.transformedAttributes
1833
+ transformedAttributes.forEach(function(field, type) {
1834
+ // do thing
1835
+ });
1836
+ // prints:
1837
+ // lastName string
1838
+ // birthday date
1839
+ ```
1840
+ @property transformedAttributes
1841
+ @public
1842
+ @readonly
1843
+ */
1844
+ static {
1845
+ decorateMethodV2(this, "attributes", [computeOnce]);
1846
+ }
1847
+ static get transformedAttributes() {
1848
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1849
+ if (!test) {
1850
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1851
+ }
1852
+ })(this.modelName) : {};
1853
+ const map = new Map();
1854
+ this.eachAttribute((name, meta) => {
1855
+ if (meta.type) {
1856
+ map.set(name, meta.type);
1857
+ }
1858
+ });
1859
+ return map;
1860
+ }
1861
+
1862
+ /**
1863
+ Iterates through the attributes of the model, calling the passed function on each
1864
+ attribute.
1865
+ The callback method you provide should have the following signature (all
1866
+ parameters are optional):
1867
+ ```javascript
1868
+ function(name, meta);
1869
+ ```
1870
+ - `name` the name of the current property in the iteration
1871
+ - `meta` the meta object for the attribute property in the iteration
1872
+ Note that in addition to a callback, you can also pass an optional target
1873
+ object that will be set as `this` on the context.
1874
+ Example
1875
+ ```javascript
1876
+ import { Model, attr } from '@warp-drive/legacy/model';
1877
+ class PersonModel extends Model {
1878
+ @attr('string') firstName;
1879
+ @attr('string') lastName;
1880
+ @attr('date') birthday;
1881
+ }
1882
+ PersonModel.eachAttribute(function(name, meta) {
1883
+ // do thing
1884
+ });
1885
+ // prints:
1886
+ // firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
1887
+ // lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
1888
+ // birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
1889
+ ```
1890
+ @public
1891
+ @param {Function} callback The callback to execute
1892
+ @param {Object} [binding] the value to which the callback's `this` should be bound
1893
+ */
1894
+ static {
1895
+ decorateMethodV2(this, "transformedAttributes", [computeOnce]);
1896
+ }
1897
+ static eachAttribute(callback, binding) {
1898
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1899
+ if (!test) {
1900
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1901
+ }
1902
+ })(this.modelName) : {};
1903
+ this.attributes.forEach((meta, name) => {
1904
+ callback.call(binding, name, meta);
1905
+ });
1906
+ }
1907
+
1908
+ /**
1909
+ Iterates through the transformedAttributes of the model, calling
1910
+ the passed function on each attribute. Note the callback will not be
1911
+ called for any attributes that do not have an transformation type.
1912
+ The callback method you provide should have the following signature (all
1913
+ parameters are optional):
1914
+ ```javascript
1915
+ function(name, type);
1916
+ ```
1917
+ - `name` the name of the current property in the iteration
1918
+ - `type` a string containing the name of the type of transformed
1919
+ applied to the attribute
1920
+ Note that in addition to a callback, you can also pass an optional target
1921
+ object that will be set as `this` on the context.
1922
+ Example
1923
+ ```javascript
1924
+ import { Model, attr } from '@warp-drive/legacy/model';
1925
+ let Person = Model.extend({
1926
+ firstName: attr(),
1927
+ lastName: attr('string'),
1928
+ birthday: attr('date')
1929
+ });
1930
+ Person.eachTransformedAttribute(function(name, type) {
1931
+ // do thing
1932
+ });
1933
+ // prints:
1934
+ // lastName string
1935
+ // birthday date
1936
+ ```
1937
+ @public
1938
+ @param {Function} callback The callback to execute
1939
+ @param {Object} [binding] the value to which the callback's `this` should be bound
1940
+ */
1941
+ static eachTransformedAttribute(callback, binding) {
1942
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1943
+ if (!test) {
1944
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1945
+ }
1946
+ })(this.modelName) : {};
1947
+ this.transformedAttributes.forEach((type, name) => {
1948
+ callback.call(binding, name, type);
1949
+ });
1950
+ }
1951
+
1952
+ /**
1953
+ Returns the name of the model class.
1954
+ @public
1955
+ */
1956
+ static toString() {
1957
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1958
+ if (!test) {
1959
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1960
+ }
1961
+ })(this.modelName) : {};
1962
+ return `model:${this.modelName}`;
1963
+ }
1964
+ }
1965
+
1966
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
1967
+ Model.prototype.save = save;
1968
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
1969
+ Model.prototype.destroyRecord = destroyRecord;
1970
+ Model.prototype.unloadRecord = unloadRecord;
1971
+ Model.prototype.hasMany = hasMany;
1972
+ Model.prototype.belongsTo = belongsTo;
1973
+ Model.prototype.serialize = serialize;
1974
+ Model.prototype._createSnapshot = createSnapshot;
1975
+ Model.prototype.deleteRecord = deleteRecord;
1976
+ Model.prototype.changedAttributes = changedAttributes;
1977
+ Model.prototype.rollbackAttributes = rollbackAttributes;
1978
+ Model.prototype.reload = reload;
1979
+ defineGate(Model.prototype, 'isReloading', {
1980
+ get() {
1981
+ deprecate(`record.isReloading is deprecated, please use store.request and either <Request> or getRequuestState to keep track of the request state instead.`, false, {
1982
+ id: 'warp-drive:deprecate-legacy-request-methods',
1983
+ until: '6.0',
1984
+ for: '@warp-drive/core',
1985
+ url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
1986
+ since: {
1987
+ enabled: '5.7',
1988
+ available: '5.7'
1989
+ }
1990
+ });
1991
+ return this._isReloading ?? false;
1992
+ },
1993
+ set(v) {
1994
+ this._isReloading = v;
1995
+ },
1996
+ configurable: true,
1997
+ // @ts-expect-error specially handled prop
1998
+ isLocal: true
1999
+ });
2000
+ function restoreDeprecatedModelRequestBehaviors(ModelKlass) {
2001
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
2002
+ ModelKlass.prototype.save = _save;
2003
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
2004
+ ModelKlass.prototype.destroyRecord = _destroyRecord;
2005
+ ModelKlass.prototype.reload = _reload;
2006
+ defineGate(Model.prototype, 'isReloading', {
2007
+ get() {
2008
+ return this._isReloading ?? false;
2009
+ },
2010
+ set(v) {
2011
+ this._isReloading = v;
2012
+ },
2013
+ // @ts-expect-error specially handled prop
2014
+ isLocal: true
2015
+ });
2016
+ }
2017
+
2018
+ // this is required to prevent `init` from passing
2019
+ // the values initialized during create to `setUnknownProperty`
2020
+ Model.prototype._createProps = null;
2021
+ Model.prototype._secretInit = null;
2022
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
2023
+ const lookupDescriptor = function lookupDescriptor(obj, keyName) {
2024
+ let current = obj;
2025
+ do {
2026
+ const descriptor = Object.getOwnPropertyDescriptor(current, keyName);
2027
+ if (descriptor !== undefined) {
2028
+ return descriptor;
2029
+ }
2030
+ current = Object.getPrototypeOf(current);
2031
+ } while (current !== null);
2032
+ return null;
2033
+ };
2034
+
2035
+ // eslint-disable-next-line @typescript-eslint/unbound-method
2036
+ const init = Model.prototype.init;
2037
+ Model.prototype.init = function (createArgs) {
2038
+ init.call(this, createArgs);
2039
+ const ourDescriptor = lookupDescriptor(Model.prototype, 'currentState');
2040
+ const theirDescriptor = lookupDescriptor(this, 'currentState');
2041
+ if (!ourDescriptor || !theirDescriptor) {
2042
+ throw new Error(`Unable to determine if 'currentState' is a reserved property name on instances of classes extending Model. Please ensure that 'currentState' is not defined as a property on ${this.constructor.toString()}`);
2043
+ }
2044
+ const realState = this.___recordState;
2045
+ if (ourDescriptor.get !== theirDescriptor.get || realState !== this.currentState) {
2046
+ throw new Error(`'currentState' is a reserved property name on instances of classes extending Model. Please choose a different property name for ${this.constructor.toString()}`);
2047
+ }
2048
+ const ID_DESCRIPTOR = lookupDescriptor(Model.prototype, 'id');
2049
+ const idDesc = lookupDescriptor(this, 'id');
2050
+ if (!ID_DESCRIPTOR || !idDesc) {
2051
+ throw new Error(`Unable to determine if 'id' is a reserved property name on instances of classes extending Model. Please ensure that 'id' is not defined as a property on ${this.constructor.toString()}`);
2052
+ }
2053
+ if (idDesc.get !== ID_DESCRIPTOR.get) {
2054
+ throw new Error(`You may not set 'id' as an attribute on your model. Please remove any lines that look like: \`id: attr('<type>')\` from ${this.constructor.toString()}`);
2055
+ }
2056
+ };
2057
+ delete Model.reopen;
2058
+ delete Model.reopenClass;
2059
+ }
2060
+ function isRelationshipSchema(meta) {
2061
+ const hasKind = typeof meta === 'object' && meta !== null && 'kind' in meta && 'options' in meta;
2062
+ return hasKind && (meta.kind === 'hasMany' || meta.kind === 'belongsTo');
2063
+ }
2064
+ function isAttributeSchema(meta) {
2065
+ return typeof meta === 'object' && meta !== null && 'kind' in meta && meta.kind === 'attribute';
2066
+ }
2067
+
2068
+ /*
2069
+ In case someone defined a relationship to a mixin, for example:
2070
+ ```ts
2071
+ class CommentModel extends Model {
2072
+ @belongsTo('commentable', { polymorphic: true }) owner;
2073
+ }
2074
+
2075
+ let Commentable = Mixin.create({
2076
+ @hasMany('comment') comments;
2077
+ });
2078
+ ```
2079
+ we want to look up a Commentable class which has all the necessary
2080
+ relationship meta data. Thus, we look up the mixin and create a mock
2081
+ Model, so we can access the relationship CPs of the mixin (`comments`)
2082
+ in this case
2083
+ */
2084
+ function modelForMixin(store, normalizedModelName) {
2085
+ const owner = getOwner(store);
2086
+ const MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);
2087
+ const mixin = MaybeMixin && MaybeMixin.class;
2088
+ if (mixin) {
2089
+ const ModelForMixin = Model.extend(mixin);
2090
+ ModelForMixin.__isMixin = true;
2091
+ ModelForMixin.__mixin = mixin;
2092
+ //Cache the class as a model
2093
+ owner.register(`model:${normalizedModelName}`, ModelForMixin);
2094
+ }
2095
+ return owner.factoryFor(`model:${normalizedModelName}`);
2096
+ }
2097
+ class ModelSchemaProvider {
2098
+ /** @internal */
2099
+
2100
+ /** @internal */
2101
+
2102
+ /** @internal */
2103
+
2104
+ constructor(store) {
2105
+ this.store = store;
2106
+ this._schemas = new Map();
2107
+ this._typeMisses = new Set();
2108
+ }
2109
+ resourceTypes() {
2110
+ return Array.from(this._schemas.keys());
2111
+ }
2112
+ hasTrait(type) {
2113
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2114
+ {
2115
+ throw new Error(`hasTrait is not available with @warp-drive/legacy/model's SchemaService`);
2116
+ }
2117
+ })() : {};
2118
+ return false;
2119
+ }
2120
+ resourceHasTrait(resource, trait) {
2121
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2122
+ {
2123
+ throw new Error(`resourceHasTrait is not available with @warp-drive/legacy/model's SchemaService`);
2124
+ }
2125
+ })() : {};
2126
+ return false;
2127
+ }
2128
+ transformation(field) {
2129
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2130
+ {
2131
+ throw new Error(`transformation is not available with @warp-drive/legacy/model's SchemaService`);
2132
+ }
2133
+ })() : {};
2134
+ }
2135
+ derivation(field) {
2136
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2137
+ {
2138
+ throw new Error(`derivation is not available with @warp-drive/legacy/model's SchemaService`);
2139
+ }
2140
+ })() : {};
2141
+ }
2142
+ hashFn(field) {
2143
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2144
+ {
2145
+ throw new Error(`hashFn is not available with @warp-drive/legacy/model's SchemaService`);
2146
+ }
2147
+ })() : {};
2148
+ }
2149
+ resource(resource) {
2150
+ const type = normalizeModelName(resource.type);
2151
+ if (!this._schemas.has(type)) {
2152
+ this._loadModelSchema(type);
2153
+ }
2154
+ return this._schemas.get(type).schema;
2155
+ }
2156
+ registerResources(schemas) {
2157
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2158
+ {
2159
+ throw new Error(`registerResources is not available with @warp-drive/legacy/model's SchemaService`);
2160
+ }
2161
+ })() : {};
2162
+ }
2163
+ registerResource(schema) {
2164
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2165
+ {
2166
+ throw new Error(`registerResource is not available with @warp-drive/legacy/model's SchemaService`);
2167
+ }
2168
+ })() : {};
2169
+ }
2170
+ registerTransformation(transform) {
2171
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2172
+ {
2173
+ throw new Error(`registerTransformation is not available with @warp-drive/legacy/model's SchemaService`);
2174
+ }
2175
+ })() : {};
2176
+ }
2177
+ registerDerivation(derivation) {
2178
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2179
+ {
2180
+ throw new Error(`registerDerivation is not available with @warp-drive/legacy/model's SchemaService`);
2181
+ }
2182
+ })() : {};
2183
+ }
2184
+ registerHashFn(hashFn) {
2185
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2186
+ {
2187
+ throw new Error(`registerHashFn is not available with @warp-drive/legacy/model's SchemaService`);
2188
+ }
2189
+ })() : {};
2190
+ }
2191
+ /** @internal */
2192
+ _loadModelSchema(type) {
2193
+ const modelClass = this.store.modelFor(type);
2194
+ const attributeMap = modelClass.attributes;
2195
+ const attributes = Object.create(null);
2196
+ attributeMap.forEach((meta, name) => attributes[name] = meta);
2197
+ const relationships = modelClass.relationshipsObject || null;
2198
+ const fields = new Map();
2199
+ for (const attr of Object.values(attributes)) {
2200
+ fields.set(attr.name, attr);
2201
+ }
2202
+ for (const rel of Object.values(relationships)) {
2203
+ fields.set(rel.name, rel);
2204
+ }
2205
+ const schema = {
2206
+ legacy: true,
2207
+ identity: {
2208
+ name: 'id',
2209
+ kind: '@id'
2210
+ },
2211
+ type,
2212
+ fields: Array.from(fields.values())
2213
+ };
2214
+ const internalSchema = {
2215
+ schema,
2216
+ attributes,
2217
+ relationships,
2218
+ fields
2219
+ };
2220
+ this._schemas.set(type, internalSchema);
2221
+ return internalSchema;
2222
+ }
2223
+ fields(resource) {
2224
+ const type = normalizeModelName(resource.type);
2225
+ if (!this._schemas.has(type)) {
2226
+ this._loadModelSchema(type);
2227
+ }
2228
+ return this._schemas.get(type).fields;
2229
+ }
2230
+ hasResource(resource) {
2231
+ const type = normalizeModelName(resource.type);
2232
+ if (this._schemas.has(type)) {
2233
+ return true;
2234
+ }
2235
+ if (this._typeMisses.has(type)) {
2236
+ return false;
2237
+ }
2238
+ const factory = getModelFactory(this.store, type);
2239
+ const exists = factory !== null;
2240
+ if (!exists) {
2241
+ this._typeMisses.add(type);
2242
+ return false;
2243
+ }
2244
+ return true;
2245
+ }
2246
+ }
2247
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
2248
+ ModelSchemaProvider.prototype.doesTypeExist = function (type) {
2249
+ deprecate(`Use \`schema.hasResource({ type })\` instead of \`schema.doesTypeExist(type)\``, false, {
2250
+ id: 'ember-data:schema-service-updates',
2251
+ until: '6.0',
2252
+ for: 'ember-data',
2253
+ since: {
2254
+ available: '4.13',
2255
+ enabled: '5.4'
2256
+ }
2257
+ });
2258
+ return this.hasResource({
2259
+ type
2260
+ });
2261
+ };
2262
+ ModelSchemaProvider.prototype.attributesDefinitionFor = function (resource) {
2263
+ deprecate(`Use \`schema.fields({ type })\` instead of \`schema.attributesDefinitionFor({ type })\``, false, {
2264
+ id: 'ember-data:schema-service-updates',
2265
+ until: '6.0',
2266
+ for: 'ember-data',
2267
+ since: {
2268
+ available: '4.13',
2269
+ enabled: '5.4'
2270
+ }
2271
+ });
2272
+ const type = normalizeModelName(resource.type);
2273
+
2274
+ // @ts-expect-error intentional use of internal API
2275
+ if (!this._schemas.has(type)) {
2276
+ // @ts-expect-error intentional use of internal API
2277
+ this._loadModelSchema(type);
2278
+ }
2279
+
2280
+ // @ts-expect-error intentional use of internal API
2281
+ return this._schemas.get(type).attributes;
2282
+ };
2283
+ ModelSchemaProvider.prototype.relationshipsDefinitionFor = function (resource) {
2284
+ deprecate(`Use \`schema.fields({ type })\` instead of \`schema.relationshipsDefinitionFor({ type })\``, false, {
2285
+ id: 'ember-data:schema-service-updates',
2286
+ until: '6.0',
2287
+ for: 'ember-data',
2288
+ since: {
2289
+ available: '4.13',
2290
+ enabled: '5.4'
2291
+ }
2292
+ });
2293
+ const type = normalizeModelName(resource.type);
2294
+
2295
+ // @ts-expect-error intentional use of internal API
2296
+ if (!this._schemas.has(type)) {
2297
+ // @ts-expect-error intentional use of internal API
2298
+ this._loadModelSchema(type);
2299
+ }
2300
+
2301
+ // @ts-expect-error intentional use of internal API
2302
+ return this._schemas.get(type).relationships;
2303
+ };
2304
+ }
2305
+ function buildSchema(store) {
2306
+ return new ModelSchemaProvider(store);
2307
+ }
2308
+ function getModelFactory(store, type) {
2309
+ if (!store._modelFactoryCache) {
2310
+ store._modelFactoryCache = Object.create(null);
2311
+ }
2312
+ const cache = store._modelFactoryCache;
2313
+ let factory = cache[type];
2314
+ if (!factory) {
2315
+ const owner = getOwner(store);
2316
+ factory = owner.factoryFor(`model:${type}`);
2317
+ if (!factory) {
2318
+ //Support looking up mixins as base types for polymorphic relationships
2319
+ factory = modelForMixin(store, type);
2320
+ }
2321
+ if (!factory) {
2322
+ // we don't cache misses in case someone wants to register a missing model
2323
+ return null;
2324
+ }
2325
+ const klass = factory.class;
2326
+ if (klass.isModel) {
2327
+ const hasOwnModelNameSet = klass.modelName && Object.prototype.hasOwnProperty.call(klass, 'modelName');
2328
+ if (!hasOwnModelNameSet) {
2329
+ Object.defineProperty(klass, 'modelName', {
2330
+ value: type
2331
+ });
2332
+ }
2333
+ }
2334
+ cache[type] = factory;
2335
+ }
2336
+ return factory;
2337
+ }
2338
+ export { Model as M, RecordState as R, _save as _, save as a, buildSchema as b, _reload as c, reload as d, _destroyRecord as e, destroyRecord as f, getModelFactory as g, hasMany as h, deleteRecord as i, changedAttributes as j, belongsTo as k, createSnapshot as l, restoreDeprecatedModelRequestBehaviors as m, rollbackAttributes as r, serialize as s, unloadRecord as u };