@warp-drive/legacy 5.9.0-beta.0 → 5.9.0-beta.2

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 (468) hide show
  1. package/README.md +6 -0
  2. package/dist/-private-DQ6Iap2t.js +193 -0
  3. package/dist/-private-DQ6Iap2t.js.map +1 -0
  4. package/dist/-private-DccRZQsm.js +904 -0
  5. package/dist/-private-DccRZQsm.js.map +1 -0
  6. package/dist/adapter/-private.d.ts +33 -0
  7. package/dist/adapter/-private.d.ts.map +1 -0
  8. package/dist/adapter/-private.js +3 -1
  9. package/dist/adapter/error.d.ts +2 -0
  10. package/dist/adapter/error.js +425 -311
  11. package/dist/adapter/error.js.map +1 -0
  12. package/{declarations → dist}/adapter/json-api.d.ts +31 -19
  13. package/dist/adapter/json-api.d.ts.map +1 -0
  14. package/dist/adapter/json-api.js +265 -131
  15. package/dist/adapter/json-api.js.map +1 -0
  16. package/dist/adapter/rest.d.ts +2 -0
  17. package/dist/adapter/rest.js +937 -1100
  18. package/dist/adapter/rest.js.map +1 -0
  19. package/dist/adapter-CARrK3-8.d.ts +784 -0
  20. package/dist/adapter-CARrK3-8.d.ts.map +1 -0
  21. package/dist/adapter-eYo2pIuM.js +1130 -0
  22. package/dist/adapter-eYo2pIuM.js.map +1 -0
  23. package/dist/adapter.d.ts +2 -0
  24. package/dist/adapter.js +1 -1251
  25. package/dist/compat/-private.d.ts +2 -0
  26. package/dist/compat/-private.js +3 -1
  27. package/dist/compat/builders.d.ts +169 -0
  28. package/dist/compat/builders.d.ts.map +1 -0
  29. package/dist/compat/builders.js +205 -246
  30. package/dist/compat/builders.js.map +1 -0
  31. package/dist/compat/extensions.d.ts +2 -0
  32. package/dist/compat/extensions.js +271 -233
  33. package/dist/compat/extensions.js.map +1 -0
  34. package/dist/compat/utils.d.ts +151 -0
  35. package/dist/compat/utils.d.ts.map +1 -0
  36. package/dist/compat/utils.js +189 -194
  37. package/dist/compat/utils.js.map +1 -0
  38. package/dist/compat-BbNNmTM-.d.ts +1386 -0
  39. package/dist/compat-BbNNmTM-.d.ts.map +1 -0
  40. package/dist/compat-DcHVxuuZ.js +734 -0
  41. package/dist/compat-DcHVxuuZ.js.map +1 -0
  42. package/dist/compat.d.ts +2 -0
  43. package/dist/compat.js +1 -1019
  44. package/dist/error-CzkyXr1Q.d.ts +435 -0
  45. package/dist/error-CzkyXr1Q.d.ts.map +1 -0
  46. package/dist/errors-BEEsrHbl.js +2134 -0
  47. package/dist/errors-BEEsrHbl.js.map +1 -0
  48. package/dist/extensions-DumNm4dA.d.ts +102 -0
  49. package/dist/extensions-DumNm4dA.d.ts.map +1 -0
  50. package/dist/index.d.ts +243 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +271 -188
  53. package/dist/index.js.map +1 -0
  54. package/dist/json-BXNPTlcH.js +1106 -0
  55. package/dist/json-BXNPTlcH.js.map +1 -0
  56. package/dist/model/-private.d.ts +3 -0
  57. package/dist/model/-private.js +3 -1
  58. package/dist/model/migration-support.d.ts +335 -0
  59. package/dist/model/migration-support.d.ts.map +1 -0
  60. package/dist/model/migration-support.js +506 -564
  61. package/dist/model/migration-support.js.map +1 -0
  62. package/dist/model-62hn5_PD.d.ts +3107 -0
  63. package/dist/model-62hn5_PD.d.ts.map +1 -0
  64. package/dist/model-DcXZdNMu.js +683 -0
  65. package/dist/model-DcXZdNMu.js.map +1 -0
  66. package/dist/model-fragments-DSqu0ptR.js +334 -0
  67. package/dist/model-fragments-DSqu0ptR.js.map +1 -0
  68. package/dist/model-fragments.d.ts +294 -0
  69. package/dist/model-fragments.d.ts.map +1 -0
  70. package/dist/model-fragments.js +2 -75
  71. package/dist/model.d.ts +404 -0
  72. package/dist/model.d.ts.map +1 -0
  73. package/dist/model.js +3 -666
  74. package/{declarations/adapter/rest.d.ts → dist/rest-0NhtexIq.d.ts} +187 -103
  75. package/dist/rest-0NhtexIq.d.ts.map +1 -0
  76. package/dist/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  77. package/dist/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  78. package/dist/schema-provider-H4zNXtry.js +1929 -0
  79. package/dist/schema-provider-H4zNXtry.js.map +1 -0
  80. package/{declarations → dist}/serializer/json-api.d.ts +4 -1
  81. package/dist/serializer/json-api.d.ts.map +1 -0
  82. package/dist/serializer/json-api.js +527 -514
  83. package/dist/serializer/json-api.js.map +1 -0
  84. package/{declarations → dist}/serializer/json.d.ts +3 -0
  85. package/dist/serializer/json.d.ts.map +1 -0
  86. package/dist/serializer/json.js +3 -6
  87. package/{declarations/serializer/-private/embedded-records-mixin.d.ts → dist/serializer/rest.d.ts} +56 -1
  88. package/dist/serializer/rest.d.ts.map +1 -0
  89. package/dist/serializer/rest.js +958 -1200
  90. package/dist/serializer/rest.js.map +1 -0
  91. package/dist/serializer/transform.d.ts +313 -0
  92. package/dist/serializer/transform.d.ts.map +1 -0
  93. package/dist/serializer/transform.js +283 -260
  94. package/dist/serializer/transform.js.map +1 -0
  95. package/dist/serializer.d.ts +151 -0
  96. package/dist/serializer.d.ts.map +1 -0
  97. package/dist/serializer.js +205 -208
  98. package/dist/serializer.js.map +1 -0
  99. package/dist/store-C4qYzXei.js +473 -0
  100. package/dist/store-C4qYzXei.js.map +1 -0
  101. package/dist/store.d.ts +13 -0
  102. package/dist/store.d.ts.map +1 -0
  103. package/dist/store.js +1 -635
  104. package/dist/unpkg/dev/-private-CrEyBE-B.js +189 -0
  105. package/dist/unpkg/dev/-private-CrEyBE-B.js.map +1 -0
  106. package/dist/unpkg/dev/-private-vOhxVExH.js +896 -0
  107. package/dist/unpkg/dev/-private-vOhxVExH.js.map +1 -0
  108. package/dist/unpkg/dev/adapter/-private.js +3 -1
  109. package/dist/unpkg/dev/adapter/error.js +424 -310
  110. package/dist/unpkg/dev/adapter/error.js.map +1 -0
  111. package/dist/unpkg/dev/adapter/json-api.js +239 -245
  112. package/dist/unpkg/dev/adapter/json-api.js.map +1 -0
  113. package/dist/unpkg/dev/adapter/rest.js +935 -1098
  114. package/dist/unpkg/dev/adapter/rest.js.map +1 -0
  115. package/dist/unpkg/dev/adapter-oLwyr47q.js +1129 -0
  116. package/dist/unpkg/dev/adapter-oLwyr47q.js.map +1 -0
  117. package/dist/unpkg/dev/adapter.js +1 -1250
  118. package/dist/unpkg/dev/compat/-private.js +3 -1
  119. package/dist/unpkg/dev/compat/builders.js +204 -248
  120. package/dist/unpkg/dev/compat/builders.js.map +1 -0
  121. package/dist/unpkg/dev/compat/extensions.js +270 -232
  122. package/dist/unpkg/dev/compat/extensions.js.map +1 -0
  123. package/dist/unpkg/dev/compat/utils.js +188 -193
  124. package/dist/unpkg/dev/compat/utils.js.map +1 -0
  125. package/dist/unpkg/dev/compat-D48B8sXv.js +825 -0
  126. package/dist/unpkg/dev/compat-D48B8sXv.js.map +1 -0
  127. package/dist/unpkg/dev/compat.js +1 -1145
  128. package/dist/unpkg/dev/errors-8GnRWcxo.js +2127 -0
  129. package/dist/unpkg/dev/errors-8GnRWcxo.js.map +1 -0
  130. package/dist/unpkg/dev/index.js +270 -190
  131. package/dist/unpkg/dev/index.js.map +1 -0
  132. package/dist/unpkg/dev/json-DDJji3V3.js +1104 -0
  133. package/dist/unpkg/dev/json-DDJji3V3.js.map +1 -0
  134. package/dist/unpkg/dev/model/-private.js +3 -1
  135. package/dist/unpkg/dev/model/migration-support.js +483 -537
  136. package/dist/unpkg/dev/model/migration-support.js.map +1 -0
  137. package/dist/unpkg/dev/model-LK7ethC5.js +655 -0
  138. package/dist/unpkg/dev/model-LK7ethC5.js.map +1 -0
  139. package/dist/unpkg/dev/model-fragments-DSqu0ptR.js +334 -0
  140. package/dist/unpkg/dev/model-fragments-DSqu0ptR.js.map +1 -0
  141. package/dist/unpkg/dev/model-fragments.js +2 -75
  142. package/dist/unpkg/dev/model.js +3 -677
  143. package/dist/unpkg/dev/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  144. package/dist/unpkg/dev/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  145. package/dist/unpkg/dev/schema-provider-CRzoMoTO.js +1834 -0
  146. package/dist/unpkg/dev/schema-provider-CRzoMoTO.js.map +1 -0
  147. package/dist/unpkg/dev/serializer/json-api.js +514 -629
  148. package/dist/unpkg/dev/serializer/json-api.js.map +1 -0
  149. package/dist/unpkg/dev/serializer/json.js +3 -4
  150. package/dist/unpkg/dev/serializer/rest.js +954 -1197
  151. package/dist/unpkg/dev/serializer/rest.js.map +1 -0
  152. package/dist/unpkg/dev/serializer/transform.js +283 -260
  153. package/dist/unpkg/dev/serializer/transform.js.map +1 -0
  154. package/dist/unpkg/dev/serializer.js +205 -208
  155. package/dist/unpkg/dev/serializer.js.map +1 -0
  156. package/dist/unpkg/dev/store-D_V8-HQl.js +472 -0
  157. package/dist/unpkg/dev/store-D_V8-HQl.js.map +1 -0
  158. package/dist/unpkg/dev/store.js +1 -635
  159. package/dist/unpkg/dev/util-dSKEgQDp.js +12 -0
  160. package/dist/unpkg/dev/util-dSKEgQDp.js.map +1 -0
  161. package/dist/unpkg/dev/utils-DYC9utVJ.js +11 -0
  162. package/dist/unpkg/dev/utils-DYC9utVJ.js.map +1 -0
  163. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js +189 -0
  164. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js.map +1 -0
  165. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js +896 -0
  166. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js.map +1 -0
  167. package/dist/unpkg/dev-deprecated/adapter/-private.js +3 -1
  168. package/dist/unpkg/dev-deprecated/adapter/error.js +424 -310
  169. package/dist/unpkg/dev-deprecated/adapter/error.js.map +1 -0
  170. package/dist/unpkg/dev-deprecated/adapter/json-api.js +239 -245
  171. package/dist/unpkg/dev-deprecated/adapter/json-api.js.map +1 -0
  172. package/dist/unpkg/dev-deprecated/adapter/rest.js +935 -1098
  173. package/dist/unpkg/dev-deprecated/adapter/rest.js.map +1 -0
  174. package/dist/unpkg/dev-deprecated/adapter-oLwyr47q.js +1129 -0
  175. package/dist/unpkg/dev-deprecated/adapter-oLwyr47q.js.map +1 -0
  176. package/dist/unpkg/dev-deprecated/adapter.js +1 -1250
  177. package/dist/unpkg/dev-deprecated/compat/-private.js +3 -1
  178. package/dist/unpkg/dev-deprecated/compat/builders.js +204 -248
  179. package/dist/unpkg/dev-deprecated/compat/builders.js.map +1 -0
  180. package/dist/unpkg/dev-deprecated/compat/extensions.js +270 -232
  181. package/dist/unpkg/dev-deprecated/compat/extensions.js.map +1 -0
  182. package/dist/unpkg/dev-deprecated/compat/utils.js +188 -193
  183. package/dist/unpkg/dev-deprecated/compat/utils.js.map +1 -0
  184. package/dist/unpkg/dev-deprecated/compat-DGSurLh7.js +825 -0
  185. package/dist/unpkg/dev-deprecated/compat-DGSurLh7.js.map +1 -0
  186. package/dist/unpkg/dev-deprecated/compat.js +1 -1145
  187. package/dist/unpkg/dev-deprecated/errors-0ydn94s0.js +2128 -0
  188. package/dist/unpkg/dev-deprecated/errors-0ydn94s0.js.map +1 -0
  189. package/dist/unpkg/dev-deprecated/index.js +270 -189
  190. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  191. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js +1104 -0
  192. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js.map +1 -0
  193. package/dist/unpkg/dev-deprecated/model/-private.js +3 -1
  194. package/dist/unpkg/dev-deprecated/model/migration-support.js +494 -554
  195. package/dist/unpkg/dev-deprecated/model/migration-support.js.map +1 -0
  196. package/dist/unpkg/dev-deprecated/model-C1ts6Mod.js +660 -0
  197. package/dist/unpkg/dev-deprecated/model-C1ts6Mod.js.map +1 -0
  198. package/dist/unpkg/dev-deprecated/model-fragments-DSqu0ptR.js +334 -0
  199. package/dist/unpkg/dev-deprecated/model-fragments-DSqu0ptR.js.map +1 -0
  200. package/dist/unpkg/dev-deprecated/model-fragments.js +2 -75
  201. package/dist/unpkg/dev-deprecated/model.js +3 -681
  202. package/dist/unpkg/dev-deprecated/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  203. package/dist/unpkg/dev-deprecated/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  204. package/dist/unpkg/dev-deprecated/schema-provider-D2ESMsA8.js +1835 -0
  205. package/dist/unpkg/dev-deprecated/schema-provider-D2ESMsA8.js.map +1 -0
  206. package/dist/unpkg/dev-deprecated/serializer/json-api.js +514 -629
  207. package/dist/unpkg/dev-deprecated/serializer/json-api.js.map +1 -0
  208. package/dist/unpkg/dev-deprecated/serializer/json.js +3 -4
  209. package/dist/unpkg/dev-deprecated/serializer/rest.js +954 -1197
  210. package/dist/unpkg/dev-deprecated/serializer/rest.js.map +1 -0
  211. package/dist/unpkg/dev-deprecated/serializer/transform.js +283 -260
  212. package/dist/unpkg/dev-deprecated/serializer/transform.js.map +1 -0
  213. package/dist/unpkg/dev-deprecated/serializer.js +205 -208
  214. package/dist/unpkg/dev-deprecated/serializer.js.map +1 -0
  215. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js +472 -0
  216. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js.map +1 -0
  217. package/dist/unpkg/dev-deprecated/store.js +1 -635
  218. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js +18 -0
  219. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js.map +1 -0
  220. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js +17 -0
  221. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js.map +1 -0
  222. package/dist/unpkg/prod/-private-B4bxoTuK.js +160 -0
  223. package/dist/unpkg/prod/-private-B4bxoTuK.js.map +1 -0
  224. package/dist/unpkg/prod/-private-SfXkkHKd.js +745 -0
  225. package/dist/unpkg/prod/-private-SfXkkHKd.js.map +1 -0
  226. package/dist/unpkg/prod/adapter/-private.js +3 -1
  227. package/dist/unpkg/prod/adapter/error.js +421 -305
  228. package/dist/unpkg/prod/adapter/error.js.map +1 -0
  229. package/dist/unpkg/prod/adapter/json-api.js +236 -240
  230. package/dist/unpkg/prod/adapter/json-api.js.map +1 -0
  231. package/dist/unpkg/prod/adapter/rest.js +911 -1061
  232. package/dist/unpkg/prod/adapter/rest.js.map +1 -0
  233. package/dist/unpkg/prod/adapter-DQ9UA7FC.js +1111 -0
  234. package/dist/unpkg/prod/adapter-DQ9UA7FC.js.map +1 -0
  235. package/dist/unpkg/prod/adapter.js +1 -1217
  236. package/dist/unpkg/prod/compat/-private.js +3 -1
  237. package/dist/unpkg/prod/compat/builders.js +165 -183
  238. package/dist/unpkg/prod/compat/builders.js.map +1 -0
  239. package/dist/unpkg/prod/compat/extensions.js +258 -222
  240. package/dist/unpkg/prod/compat/extensions.js.map +1 -0
  241. package/dist/unpkg/prod/compat/utils.js +185 -188
  242. package/dist/unpkg/prod/compat/utils.js.map +1 -0
  243. package/dist/unpkg/prod/compat-DxiVkCUb.js +547 -0
  244. package/dist/unpkg/prod/compat-DxiVkCUb.js.map +1 -0
  245. package/dist/unpkg/prod/compat.js +1 -725
  246. package/dist/unpkg/prod/errors-CVXWrUjP.js +1977 -0
  247. package/dist/unpkg/prod/errors-CVXWrUjP.js.map +1 -0
  248. package/dist/unpkg/prod/index.js +249 -146
  249. package/dist/unpkg/prod/index.js.map +1 -0
  250. package/dist/unpkg/prod/json-BD1kRTfB.js +1080 -0
  251. package/dist/unpkg/prod/json-BD1kRTfB.js.map +1 -0
  252. package/dist/unpkg/prod/model/-private.js +3 -1
  253. package/dist/unpkg/prod/model/migration-support.js +479 -530
  254. package/dist/unpkg/prod/model/migration-support.js.map +1 -0
  255. package/dist/unpkg/prod/model-D3WMsNNE.js +603 -0
  256. package/dist/unpkg/prod/model-D3WMsNNE.js.map +1 -0
  257. package/dist/unpkg/prod/model-fragments-DSqu0ptR.js +334 -0
  258. package/dist/unpkg/prod/model-fragments-DSqu0ptR.js.map +1 -0
  259. package/dist/unpkg/prod/model-fragments.js +2 -75
  260. package/dist/unpkg/prod/model.js +3 -592
  261. package/dist/unpkg/prod/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  262. package/dist/unpkg/prod/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  263. package/dist/unpkg/prod/schema-provider-_pimTZ3P.js +1622 -0
  264. package/dist/unpkg/prod/schema-provider-_pimTZ3P.js.map +1 -0
  265. package/dist/unpkg/prod/serializer/json-api.js +497 -587
  266. package/dist/unpkg/prod/serializer/json-api.js.map +1 -0
  267. package/dist/unpkg/prod/serializer/json.js +3 -4
  268. package/dist/unpkg/prod/serializer/rest.js +938 -1167
  269. package/dist/unpkg/prod/serializer/rest.js.map +1 -0
  270. package/dist/unpkg/prod/serializer/transform.js +283 -260
  271. package/dist/unpkg/prod/serializer/transform.js.map +1 -0
  272. package/dist/unpkg/prod/serializer.js +205 -208
  273. package/dist/unpkg/prod/serializer.js.map +1 -0
  274. package/dist/unpkg/prod/store-RGGc1ilN.js +392 -0
  275. package/dist/unpkg/prod/store-RGGc1ilN.js.map +1 -0
  276. package/dist/unpkg/prod/store.js +1 -503
  277. package/dist/unpkg/prod/util-dSKEgQDp.js +12 -0
  278. package/dist/unpkg/prod/util-dSKEgQDp.js.map +1 -0
  279. package/dist/unpkg/prod/utils-DYC9utVJ.js +11 -0
  280. package/dist/unpkg/prod/utils-DYC9utVJ.js.map +1 -0
  281. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js +160 -0
  282. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js.map +1 -0
  283. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js +745 -0
  284. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js.map +1 -0
  285. package/dist/unpkg/prod-deprecated/adapter/-private.js +3 -1
  286. package/dist/unpkg/prod-deprecated/adapter/error.js +421 -305
  287. package/dist/unpkg/prod-deprecated/adapter/error.js.map +1 -0
  288. package/dist/unpkg/prod-deprecated/adapter/json-api.js +236 -240
  289. package/dist/unpkg/prod-deprecated/adapter/json-api.js.map +1 -0
  290. package/dist/unpkg/prod-deprecated/adapter/rest.js +911 -1061
  291. package/dist/unpkg/prod-deprecated/adapter/rest.js.map +1 -0
  292. package/{declarations/adapter.d.ts → dist/unpkg/prod-deprecated/adapter-DQ9UA7FC.js} +451 -110
  293. package/dist/unpkg/prod-deprecated/adapter-DQ9UA7FC.js.map +1 -0
  294. package/dist/unpkg/prod-deprecated/adapter.js +1 -1217
  295. package/dist/unpkg/prod-deprecated/compat/-private.js +3 -1
  296. package/dist/unpkg/prod-deprecated/compat/builders.js +165 -183
  297. package/dist/unpkg/prod-deprecated/compat/builders.js.map +1 -0
  298. package/dist/unpkg/prod-deprecated/compat/extensions.js +258 -222
  299. package/dist/unpkg/prod-deprecated/compat/extensions.js.map +1 -0
  300. package/dist/unpkg/prod-deprecated/compat/utils.js +185 -188
  301. package/dist/unpkg/prod-deprecated/compat/utils.js.map +1 -0
  302. package/dist/unpkg/prod-deprecated/compat-DxiVkCUb.js +547 -0
  303. package/dist/unpkg/prod-deprecated/compat-DxiVkCUb.js.map +1 -0
  304. package/dist/unpkg/prod-deprecated/compat.js +1 -725
  305. package/dist/unpkg/prod-deprecated/errors-9LXqpfRd.js +1978 -0
  306. package/dist/unpkg/prod-deprecated/errors-9LXqpfRd.js.map +1 -0
  307. package/dist/unpkg/prod-deprecated/index.js +249 -145
  308. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  309. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js +1080 -0
  310. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js.map +1 -0
  311. package/dist/unpkg/prod-deprecated/model/-private.js +3 -1
  312. package/dist/unpkg/prod-deprecated/model/migration-support.js +490 -547
  313. package/dist/unpkg/prod-deprecated/model/migration-support.js.map +1 -0
  314. package/dist/unpkg/prod-deprecated/model-aiVrr1fz.js +604 -0
  315. package/dist/unpkg/prod-deprecated/model-aiVrr1fz.js.map +1 -0
  316. package/dist/unpkg/prod-deprecated/model-fragments-DSqu0ptR.js +334 -0
  317. package/dist/unpkg/prod-deprecated/model-fragments-DSqu0ptR.js.map +1 -0
  318. package/dist/unpkg/prod-deprecated/model-fragments.js +2 -75
  319. package/dist/unpkg/prod-deprecated/model.js +3 -595
  320. package/dist/unpkg/prod-deprecated/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  321. package/dist/unpkg/prod-deprecated/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  322. package/dist/unpkg/prod-deprecated/schema-provider-DyfSd9Cv.js +1635 -0
  323. package/dist/unpkg/prod-deprecated/schema-provider-DyfSd9Cv.js.map +1 -0
  324. package/dist/unpkg/prod-deprecated/serializer/json-api.js +497 -587
  325. package/dist/unpkg/prod-deprecated/serializer/json-api.js.map +1 -0
  326. package/dist/unpkg/prod-deprecated/serializer/json.js +3 -4
  327. package/dist/unpkg/prod-deprecated/serializer/rest.js +938 -1167
  328. package/dist/unpkg/prod-deprecated/serializer/rest.js.map +1 -0
  329. package/dist/unpkg/prod-deprecated/serializer/transform.js +283 -260
  330. package/dist/unpkg/prod-deprecated/serializer/transform.js.map +1 -0
  331. package/dist/unpkg/prod-deprecated/serializer.js +205 -208
  332. package/dist/unpkg/prod-deprecated/serializer.js.map +1 -0
  333. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js +392 -0
  334. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js.map +1 -0
  335. package/dist/unpkg/prod-deprecated/store.js +1 -503
  336. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js +14 -0
  337. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js.map +1 -0
  338. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js +13 -0
  339. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js.map +1 -0
  340. package/dist/util-Bnx8nm-D.js +29 -0
  341. package/dist/util-Bnx8nm-D.js.map +1 -0
  342. package/dist/utils-ZAytYep8.js +28 -0
  343. package/dist/utils-ZAytYep8.js.map +1 -0
  344. package/package.json +21 -25
  345. package/declarations/adapter/-private/build-url-mixin.d.ts +0 -33
  346. package/declarations/adapter/-private/fastboot-interface.d.ts +0 -8
  347. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +0 -1
  348. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +0 -4
  349. package/declarations/adapter/-private/utils/fetch.d.ts +0 -8
  350. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
  351. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +0 -6
  352. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -5
  353. package/declarations/adapter/-private.d.ts +0 -5
  354. package/declarations/adapter/error.d.ts +0 -215
  355. package/declarations/compat/-private.d.ts +0 -13
  356. package/declarations/compat/builders/find-all.d.ts +0 -35
  357. package/declarations/compat/builders/find-record.d.ts +0 -56
  358. package/declarations/compat/builders/query.d.ts +0 -66
  359. package/declarations/compat/builders/save-record.d.ts +0 -34
  360. package/declarations/compat/builders/utils.d.ts +0 -3
  361. package/declarations/compat/builders.d.ts +0 -14
  362. package/declarations/compat/extensions.d.ts +0 -59
  363. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +0 -55
  364. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +0 -2
  365. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +0 -11
  366. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +0 -5
  367. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +0 -2
  368. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +0 -524
  369. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +0 -213
  370. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +0 -6
  371. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +0 -110
  372. package/declarations/compat/legacy-network-handler/snapshot.d.ts +0 -255
  373. package/declarations/compat/utils.d.ts +0 -137
  374. package/declarations/compat.d.ts +0 -157
  375. package/declarations/index.d.ts +0 -102
  376. package/declarations/model/-private/attr.d.ts +0 -170
  377. package/declarations/model/-private/belongs-to.d.ts +0 -174
  378. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +0 -5
  379. package/declarations/model/-private/errors.d.ts +0 -289
  380. package/declarations/model/-private/has-many.d.ts +0 -162
  381. package/declarations/model/-private/hooks.d.ts +0 -10
  382. package/declarations/model/-private/legacy-relationships-support.d.ts +0 -47
  383. package/declarations/model/-private/model-for-mixin.d.ts +0 -3
  384. package/declarations/model/-private/model-methods.d.ts +0 -39
  385. package/declarations/model/-private/model.d.ts +0 -1228
  386. package/declarations/model/-private/notify-changes.d.ts +0 -4
  387. package/declarations/model/-private/promise-belongs-to.d.ts +0 -40
  388. package/declarations/model/-private/promise-many-array.d.ts +0 -106
  389. package/declarations/model/-private/record-state.d.ts +0 -58
  390. package/declarations/model/-private/references/belongs-to.d.ts +0 -488
  391. package/declarations/model/-private/references/has-many.d.ts +0 -498
  392. package/declarations/model/-private/schema-provider.d.ts +0 -56
  393. package/declarations/model/-private/type-utils.d.ts +0 -57
  394. package/declarations/model/-private/util.d.ts +0 -5
  395. package/declarations/model/-private.d.ts +0 -8
  396. package/declarations/model/migration-support.d.ts +0 -280
  397. package/declarations/model-fragments/extensions/fragment-array.d.ts +0 -16
  398. package/declarations/model-fragments/extensions/fragment.d.ts +0 -15
  399. package/declarations/model-fragments/hooks/model-for.d.ts +0 -20
  400. package/declarations/model-fragments/index.d.ts +0 -5
  401. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +0 -9
  402. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +0 -15
  403. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +0 -20
  404. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +0 -19
  405. package/declarations/model-fragments/utilities/with-legacy.d.ts +0 -3
  406. package/declarations/model-fragments.d.ts +0 -9
  407. package/declarations/model.d.ts +0 -49
  408. package/declarations/serializer/-private/transforms/boolean.d.ts +0 -47
  409. package/declarations/serializer/-private/transforms/date.d.ts +0 -28
  410. package/declarations/serializer/-private/transforms/number.d.ts +0 -29
  411. package/declarations/serializer/-private/transforms/string.d.ts +0 -29
  412. package/declarations/serializer/-private/transforms/transform.d.ts +0 -118
  413. package/declarations/serializer/-private/utils.d.ts +0 -3
  414. package/declarations/serializer/rest.d.ts +0 -51
  415. package/declarations/serializer/transform.d.ts +0 -5
  416. package/declarations/serializer.d.ts +0 -254
  417. package/declarations/store/-private.d.ts +0 -223
  418. package/declarations/store.d.ts +0 -3
  419. package/dist/-private-BG3bMiKp.js +0 -1211
  420. package/dist/errors-Cz5KrzBk.js +0 -2566
  421. package/dist/hooks-D6diaM34.js +0 -74
  422. package/dist/json-ChdEfB0X.js +0 -1259
  423. package/dist/model-for-CqXsIKws.js +0 -221
  424. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  425. package/dist/schema-provider-DJCV_6AF.js +0 -2295
  426. package/dist/serialize-into-hash-DPZYoF-i.js +0 -261
  427. package/dist/unpkg/dev/-private-DtjBbEgy.js +0 -1206
  428. package/dist/unpkg/dev/errors-DmGGJr3T.js +0 -2562
  429. package/dist/unpkg/dev/hooks-CkYiE6Ud.js +0 -73
  430. package/dist/unpkg/dev/json-Cu1LNgmQ.js +0 -1256
  431. package/dist/unpkg/dev/model-for-CqXsIKws.js +0 -221
  432. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  433. package/dist/unpkg/dev/schema-provider-DDVYxmUV.js +0 -2186
  434. package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +0 -259
  435. package/dist/unpkg/dev/util-DvanW33H.js +0 -20
  436. package/dist/unpkg/dev/utils-BhvS1iTS.js +0 -8
  437. package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +0 -1206
  438. package/dist/unpkg/dev-deprecated/errors-Spt6ubMd.js +0 -2565
  439. package/dist/unpkg/dev-deprecated/hooks-DOXegvhL.js +0 -73
  440. package/dist/unpkg/dev-deprecated/json-Cu1LNgmQ.js +0 -1256
  441. package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +0 -221
  442. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  443. package/dist/unpkg/dev-deprecated/schema-provider-BP6_8N-V.js +0 -2211
  444. package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +0 -259
  445. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +0 -24
  446. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +0 -12
  447. package/dist/unpkg/prod/-private-BdyZaGEh.js +0 -971
  448. package/dist/unpkg/prod/errors-BGVFCBmi.js +0 -2314
  449. package/dist/unpkg/prod/hooks-BztVA_x0.js +0 -41
  450. package/dist/unpkg/prod/json-BWrZ5546.js +0 -1243
  451. package/dist/unpkg/prod/model-for-CqXsIKws.js +0 -221
  452. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  453. package/dist/unpkg/prod/schema-provider-DJtD_8jZ.js +0 -1861
  454. package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +0 -215
  455. package/dist/unpkg/prod/util-DvanW33H.js +0 -20
  456. package/dist/unpkg/prod/utils-BhvS1iTS.js +0 -8
  457. package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +0 -971
  458. package/dist/unpkg/prod-deprecated/errors-CdDaK81x.js +0 -2317
  459. package/dist/unpkg/prod-deprecated/hooks-yId87yyG.js +0 -41
  460. package/dist/unpkg/prod-deprecated/json-BWrZ5546.js +0 -1243
  461. package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +0 -221
  462. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  463. package/dist/unpkg/prod-deprecated/schema-provider-CjX55uSY.js +0 -1904
  464. package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +0 -215
  465. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +0 -23
  466. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +0 -11
  467. package/dist/util-Dul6TZts.js +0 -35
  468. package/dist/utils-Cqw9eRj5.js +0 -23
@@ -0,0 +1,1835 @@
1
+ import { n as FetchManager, t as upgradeStore } from "./-private-vOhxVExH.js";
2
+ import { n as normalizeModelName } from "./util-9mgEBJ3W.js";
3
+ import { n as LEGACY_SUPPORT, r as lookupLegacySupport, t as Errors } from "./errors-0ydn94s0.js";
4
+ import { n as decorateMethodV2 } from "./runtime--fcdnjmJ-DMTJ0Kb3.js";
5
+ import { recordIdentifierFor, storeFor } from "@warp-drive/core";
6
+ import { getOwner } from "@ember/application";
7
+ import { assertPrivateStore, coerceId, recordIdentifierFor as recordIdentifierFor$1 } from "@warp-drive/core/store/-private";
8
+ import { Context } from "@warp-drive/core/reactive/-private";
9
+ import { defineGate, defineSignal, entangleSignal, gate, memoized, notifyInternalSignal, peekInternalSignal, withSignalStore } from "@warp-drive/core/signals/-leaked";
10
+ import EmberObject from "@ember/object";
11
+ import { RecordStore } from "@warp-drive/core/types/symbols";
12
+ import { cacheFor } from "@ember/object/internals";
13
+
14
+ //#region src/model/-private/model-methods.ts
15
+ function rollbackAttributes() {
16
+ const { currentState } = this;
17
+ const { isNew } = currentState;
18
+ const store = this[RecordStore];
19
+ assertPrivateStore(store);
20
+ store._join(() => {
21
+ store.cache.rollbackAttrs(recordIdentifierFor(this));
22
+ this.errors.clear();
23
+ currentState.cleanErrorRequests();
24
+ if (isNew) this.unloadRecord();
25
+ });
26
+ }
27
+ function unloadRecord() {
28
+ if (this.currentState.isNew && (this.isDestroyed || this.isDestroying)) return;
29
+ this[RecordStore].unloadRecord(this);
30
+ }
31
+ function belongsTo(prop) {
32
+ return lookupLegacySupport(this).referenceFor("belongsTo", prop);
33
+ }
34
+ function hasMany(prop) {
35
+ return lookupLegacySupport(this).referenceFor("hasMany", prop);
36
+ }
37
+ function reload(options = {}) {
38
+ console.warn(`record.reload is deprecated, please use store.request to initiate a request instead.`);
39
+ return _reload.call(this, options);
40
+ }
41
+ function _reload(options = {}) {
42
+ options.isReloading = true;
43
+ options.reload = true;
44
+ const identifier = recordIdentifierFor(this);
45
+ ((test) => {
46
+ if (!test) throw new Error(`You cannot reload a record without an ID`);
47
+ })(identifier.id);
48
+ this.isReloading = true;
49
+ return this[RecordStore].request({
50
+ op: "findRecord",
51
+ data: {
52
+ options,
53
+ record: identifier
54
+ },
55
+ cacheOptions: { [Symbol.for("wd:skip-cache")]: true }
56
+ }).then(() => this).finally(() => {
57
+ this.isReloading = false;
58
+ });
59
+ }
60
+ function changedAttributes() {
61
+ return this[RecordStore].cache.changedAttrs(recordIdentifierFor(this));
62
+ }
63
+ function serialize(options) {
64
+ /* @__PURE__ */ upgradeStore(this[RecordStore]);
65
+ return this[RecordStore].serializeRecord(this, options);
66
+ }
67
+ function deleteRecord() {
68
+ if (this.currentState) this[RecordStore].deleteRecord(this);
69
+ }
70
+ function save(options) {
71
+ console.warn(`record.save is deprecated, please use store.request to initiate a request instead.`);
72
+ return _save.call(this, options);
73
+ }
74
+ function _save(options) {
75
+ let promise;
76
+ if (this.currentState.isNew && this.currentState.isDeleted) promise = Promise.resolve(this);
77
+ else {
78
+ this.errors.clear();
79
+ promise = this[RecordStore].saveRecord(this, options);
80
+ }
81
+ return promise;
82
+ }
83
+ function destroyRecord(options) {
84
+ console.warn(`record.destroyRecord is deprecated, please use store.request to initiate a request instead.`);
85
+ return _destroyRecord.call(this, options);
86
+ }
87
+ function _destroyRecord(options) {
88
+ const { isNew } = this.currentState;
89
+ this.deleteRecord();
90
+ if (isNew) return Promise.resolve(this);
91
+ return this.save(options).then((_) => {
92
+ this.unloadRecord();
93
+ return this;
94
+ });
95
+ }
96
+ function createSnapshot() {
97
+ const store = this[RecordStore];
98
+ /* @__PURE__ */ upgradeStore(store);
99
+ if (!store._fetchManager) store._fetchManager = new FetchManager(store);
100
+ return store._fetchManager.createSnapshot(recordIdentifierFor(this));
101
+ }
102
+
103
+ //#endregion
104
+ //#region src/model/-private/notify-changes.ts
105
+ function notifyChanges(identifier, value, key, record, store) {
106
+ switch (value) {
107
+ case "added":
108
+ case "attributes":
109
+ if (key) notifyAttribute(store, identifier, key, record);
110
+ else record.eachAttribute((name) => {
111
+ notifyAttribute(store, identifier, name, record);
112
+ });
113
+ break;
114
+ case "relationships":
115
+ if (key) {
116
+ const meta = record.constructor.relationshipsByName.get(key);
117
+ ((test) => {
118
+ if (!test) throw new Error(`Expected to find a relationship for ${key} on ${identifier.type}`);
119
+ })(meta);
120
+ notifyRelationship(identifier, key, record, meta);
121
+ } else record.eachRelationship((name, meta) => {
122
+ notifyRelationship(identifier, name, record, meta);
123
+ });
124
+ break;
125
+ case "identity": notifyInternalSignal(peekInternalSignal(withSignalStore(record), "id"));
126
+ }
127
+ }
128
+ function notifyRelationship(identifier, key, record, meta) {
129
+ if (meta.kind === "belongsTo") record.notifyPropertyChange(key);
130
+ else if (meta.kind === "hasMany") {
131
+ const support = LEGACY_SUPPORT.get(identifier);
132
+ const manyArray = support && support._manyArrayCache[key];
133
+ const hasPromise = support && support._relationshipPromisesCache[key];
134
+ if (manyArray && hasPromise) return;
135
+ if (manyArray) {
136
+ notifyInternalSignal(manyArray[Context].signal);
137
+ ((test) => {
138
+ if (!test) throw new Error(`Expected options to exist on relationship meta`);
139
+ })(meta.options);
140
+ ((test) => {
141
+ if (!test) throw new Error(`Expected async to exist on relationship meta options`);
142
+ })("async" in meta.options);
143
+ if (meta.options.async) record.notifyPropertyChange(key);
144
+ }
145
+ }
146
+ }
147
+ function notifyAttribute(store, identifier, key, record) {
148
+ if (cacheFor(record, key) !== store.cache.getAttr(identifier, key)) record.notifyPropertyChange(key);
149
+ }
150
+
151
+ //#endregion
152
+ //#region src/model/-private/record-state.ts
153
+ const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
154
+ const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
155
+ const PRIMARY_ATTRIBUTE_KEY = "base";
156
+ function isInvalidError(error) {
157
+ return !!error && error instanceof Error && "isAdapterError" in error && error.isAdapterError === true && "code" in error && error.code === "InvalidError";
158
+ }
159
+ /**
160
+ Historically WarpDrive managed a state machine
161
+ for each record, the localState for which
162
+ was reflected onto Model.
163
+
164
+ This implements the flags and stateName for backwards compat
165
+ with the state tree that used to be possible (listed below).
166
+
167
+ stateName and dirtyType are candidates for deprecation.
168
+
169
+ root
170
+ empty
171
+ deleted // hidden from stateName
172
+ preloaded // hidden from stateName
173
+
174
+ loading
175
+ empty // hidden from stateName
176
+ preloaded // hidden from stateName
177
+
178
+ loaded
179
+ saved
180
+ updated
181
+ uncommitted
182
+ invalid
183
+ inFlight
184
+ created
185
+ uncommitted
186
+ invalid
187
+ inFlight
188
+
189
+ deleted
190
+ saved
191
+ new // hidden from stateName
192
+ uncommitted
193
+ invalid
194
+ inFlight
195
+
196
+ @hideconstructor
197
+ @private
198
+ */
199
+ var RecordState = class {
200
+ /** @internal */
201
+ /** @internal */
202
+ /** @internal */
203
+ /** @internal */
204
+ /** @internal */
205
+ /** @internal */
206
+ /** @internal */
207
+ /** @internal */
208
+ /** @internal */
209
+ /** @internal */
210
+ /** @internal */
211
+ constructor(record) {
212
+ const store = storeFor(record, false);
213
+ const identity = recordIdentifierFor$1(record);
214
+ this.identifier = identity;
215
+ this.record = record;
216
+ this.cache = store.cache;
217
+ this.pendingCount = 0;
218
+ this.fulfilledCount = 0;
219
+ this.rejectedCount = 0;
220
+ this._errorRequests = [];
221
+ this._lastError = null;
222
+ const requests = store.getRequestStateService();
223
+ const notifications = store.notifications;
224
+ const handleRequest = (req) => {
225
+ if (req.type === "mutation") switch (req.state) {
226
+ case "pending":
227
+ this.isSaving = true;
228
+ break;
229
+ case "rejected":
230
+ this.isSaving = false;
231
+ this._lastError = req;
232
+ if (!(req.response && isInvalidError(req.response.data))) this._errorRequests.push(req);
233
+ notifyErrorsStateChanged(this);
234
+ break;
235
+ case "fulfilled":
236
+ this._errorRequests = [];
237
+ this._lastError = null;
238
+ this.isSaving = false;
239
+ this.notify("isDirty");
240
+ notifyErrorsStateChanged(this);
241
+ }
242
+ else switch (req.state) {
243
+ case "pending":
244
+ this.pendingCount++;
245
+ this.notify("isLoading");
246
+ break;
247
+ case "rejected":
248
+ this.pendingCount--;
249
+ this._lastError = req;
250
+ if (!(req.response && isInvalidError(req.response.data))) this._errorRequests.push(req);
251
+ this.notify("isLoading");
252
+ notifyErrorsStateChanged(this);
253
+ break;
254
+ case "fulfilled":
255
+ this.pendingCount--;
256
+ this.fulfilledCount++;
257
+ this.notify("isLoading");
258
+ this.notify("isDirty");
259
+ notifyErrorsStateChanged(this);
260
+ this._errorRequests = [];
261
+ this._lastError = null;
262
+ }
263
+ };
264
+ requests.subscribeForRecord(identity, handleRequest);
265
+ const lastRequest = requests.getLastRequestForRecord(identity);
266
+ if (lastRequest) handleRequest(lastRequest);
267
+ this.handler = notifications.subscribe(identity, (identifier, type, key) => {
268
+ switch (type) {
269
+ case "state":
270
+ this.notify("isSaved");
271
+ this.notify("isNew");
272
+ this.notify("isDeleted");
273
+ this.notify("isDirty");
274
+ break;
275
+ case "attributes":
276
+ this.notify("isEmpty");
277
+ this.notify("isDirty");
278
+ break;
279
+ case "errors":
280
+ this.updateInvalidErrors(this.record.errors);
281
+ this.notify("isValid");
282
+ }
283
+ });
284
+ }
285
+ /** @internal */
286
+ destroy() {
287
+ storeFor(this.record, false).notifications.unsubscribe(this.handler);
288
+ }
289
+ /** @internal */
290
+ notify(key) {
291
+ const signals = withSignalStore(this);
292
+ const signal = peekInternalSignal(signals, key);
293
+ if (signal) notifyInternalSignal(signal);
294
+ }
295
+ /** @internal */
296
+ updateInvalidErrors(errors) {
297
+ ((test) => {
298
+ if (!test) throw new Error(`Expected the Cache instance for ${this.identifier.lid} to implement getErrors(identifier)`);
299
+ })(typeof this.cache.getErrors === "function");
300
+ const jsonApiErrors = this.cache.getErrors(this.identifier);
301
+ errors.clear();
302
+ for (let i = 0; i < jsonApiErrors.length; i++) {
303
+ const error = jsonApiErrors[i];
304
+ if (error.source && error.source.pointer) {
305
+ const keyMatch = error.source.pointer.match(SOURCE_POINTER_REGEXP);
306
+ let key;
307
+ if (keyMatch) key = keyMatch[2];
308
+ else if (error.source.pointer.search(SOURCE_POINTER_PRIMARY_REGEXP) !== -1) key = PRIMARY_ATTRIBUTE_KEY;
309
+ if (key) {
310
+ const errMsg = error.detail || error.title;
311
+ ((test) => {
312
+ if (!test) throw new Error(`Expected field error to have a detail or title to use as the message`);
313
+ })(errMsg);
314
+ errors.add(key, errMsg);
315
+ }
316
+ }
317
+ }
318
+ }
319
+ /** @internal */
320
+ cleanErrorRequests() {
321
+ this.notify("isValid");
322
+ this.notify("isError");
323
+ this.notify("adapterError");
324
+ this._errorRequests = [];
325
+ this._lastError = null;
326
+ }
327
+ get isLoading() {
328
+ return !this.isLoaded && this.pendingCount > 0 && this.fulfilledCount === 0;
329
+ }
330
+ static {
331
+ decorateMethodV2(this.prototype, "isLoading", [gate]);
332
+ }
333
+ get isLoaded() {
334
+ if (this.isNew) return true;
335
+ return this.fulfilledCount > 0 || !this.isEmpty;
336
+ }
337
+ static {
338
+ decorateMethodV2(this.prototype, "isLoaded", [gate]);
339
+ }
340
+ get isSaved() {
341
+ const rd = this.cache;
342
+ if (this.isDeleted) {
343
+ ((test) => {
344
+ if (!test) throw new Error(`Expected Cache to implement isDeletionCommitted()`);
345
+ })(typeof rd.isDeletionCommitted === "function");
346
+ return rd.isDeletionCommitted(this.identifier);
347
+ }
348
+ if (this.isNew || this.isEmpty || !this.isValid || this.isDirty || this.isLoading) return false;
349
+ return true;
350
+ }
351
+ static {
352
+ decorateMethodV2(this.prototype, "isSaved", [gate]);
353
+ }
354
+ get isEmpty() {
355
+ const rd = this.cache;
356
+ ((test) => {
357
+ if (!test) throw new Error(`Expected Cache to implement isEmpty()`);
358
+ })(typeof rd.isEmpty === "function");
359
+ return !this.isNew && rd.isEmpty(this.identifier);
360
+ }
361
+ static {
362
+ decorateMethodV2(this.prototype, "isEmpty", [gate]);
363
+ }
364
+ get isNew() {
365
+ const rd = this.cache;
366
+ ((test) => {
367
+ if (!test) throw new Error(`Expected Cache to implement isNew()`);
368
+ })(typeof rd.isNew === "function");
369
+ return rd.isNew(this.identifier);
370
+ }
371
+ static {
372
+ decorateMethodV2(this.prototype, "isNew", [gate]);
373
+ }
374
+ get isDeleted() {
375
+ const rd = this.cache;
376
+ ((test) => {
377
+ if (!test) throw new Error(`Expected Cache to implement isDeleted()`);
378
+ })(typeof rd.isDeleted === "function");
379
+ return rd.isDeleted(this.identifier);
380
+ }
381
+ static {
382
+ decorateMethodV2(this.prototype, "isDeleted", [gate]);
383
+ }
384
+ get isValid() {
385
+ return this.record.errors.length === 0;
386
+ }
387
+ static {
388
+ decorateMethodV2(this.prototype, "isValid", [gate]);
389
+ }
390
+ get isDirty() {
391
+ const rd = this.cache;
392
+ if (this.isEmpty || rd.isDeletionCommitted(this.identifier) || this.isDeleted && this.isNew) return false;
393
+ return this.isDeleted || this.isNew || rd.hasChangedAttrs(this.identifier);
394
+ }
395
+ static {
396
+ decorateMethodV2(this.prototype, "isDirty", [gate]);
397
+ }
398
+ get isError() {
399
+ if (!this._errorRequests[this._errorRequests.length - 1]) return false;
400
+ else return true;
401
+ }
402
+ static {
403
+ decorateMethodV2(this.prototype, "isError", [gate]);
404
+ }
405
+ get adapterError() {
406
+ const request = this._lastError;
407
+ if (!request) return null;
408
+ return request.state === "rejected" && request.response.data;
409
+ }
410
+ static {
411
+ decorateMethodV2(this.prototype, "adapterError", [gate]);
412
+ }
413
+ get isPreloaded() {
414
+ return !this.isEmpty && this.isLoading;
415
+ }
416
+ static {
417
+ decorateMethodV2(this.prototype, "isPreloaded", [memoized]);
418
+ }
419
+ get stateName() {
420
+ if (this.isLoading) return "root.loading";
421
+ else if (this.isEmpty) return "root.empty";
422
+ else if (this.isDeleted) {
423
+ if (this.isSaving) return "root.deleted.inFlight";
424
+ else if (this.isSaved) return "root.deleted.saved";
425
+ else if (!this.isValid) return "root.deleted.invalid";
426
+ else return "root.deleted.uncommitted";
427
+ } else if (this.isNew) {
428
+ if (this.isSaving) return "root.loaded.created.inFlight";
429
+ else if (!this.isValid) return "root.loaded.created.invalid";
430
+ return "root.loaded.created.uncommitted";
431
+ } else if (this.isSaving) return "root.loaded.updated.inFlight";
432
+ else if (!this.isValid) return "root.loaded.updated.invalid";
433
+ else if (this.isDirty) return "root.loaded.updated.uncommitted";
434
+ else return "root.loaded.saved";
435
+ }
436
+ static {
437
+ decorateMethodV2(this.prototype, "stateName", [memoized]);
438
+ }
439
+ get dirtyType() {
440
+ if (this.isLoading || this.isEmpty) return "";
441
+ else if (this.isDirty && this.isDeleted) return "deleted";
442
+ else if (this.isNew) return "created";
443
+ else if (this.isSaving || !this.isValid || this.isDirty) return "updated";
444
+ else return "";
445
+ }
446
+ static {
447
+ decorateMethodV2(this.prototype, "dirtyType", [memoized]);
448
+ }
449
+ };
450
+ defineSignal(RecordState.prototype, "isSaving", false);
451
+ function notifyErrorsStateChanged(state) {
452
+ state.notify("isValid");
453
+ state.notify("isError");
454
+ state.notify("adapterError");
455
+ }
456
+
457
+ //#endregion
458
+ //#region src/model/-private/model.ts
459
+ function computeOnce(target, propertyName, desc) {
460
+ const cache = /* @__PURE__ */ new WeakMap();
461
+ const getter = desc.get;
462
+ desc.get = function() {
463
+ let meta = cache.get(this);
464
+ if (!meta) {
465
+ meta = {
466
+ hasComputed: false,
467
+ value: void 0
468
+ };
469
+ cache.set(this, meta);
470
+ }
471
+ if (!meta.hasComputed) {
472
+ meta.value = getter.call(this);
473
+ meta.hasComputed = true;
474
+ }
475
+ return meta.value;
476
+ };
477
+ return desc;
478
+ }
479
+ /**
480
+ * Base class from which Models can be defined.
481
+ *
482
+ * ::: code-group
483
+ *
484
+ * ```js [app/models/user.js]
485
+ * import { Model, attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
486
+ *
487
+ * export default class User extends Model {
488
+ * @attr name;
489
+ * @attr('number') age;
490
+ * @hasMany('post', { async: true, inverse: null }) posts;
491
+ * @belongsTo('group', { async: false, inverse: 'users' }) group;
492
+ * }
493
+ * ```
494
+ *
495
+ * ```ts [app/models/user.ts]
496
+ * import { Model, attr, belongsTo, hasMany, type AsyncHasMany } from '@warp-drive/legacy/model';
497
+ * import type { NumberTransform } from '@ember-data/serializer/transform';
498
+ * import type Group from './group';
499
+ * import type Post from './post';
500
+ *
501
+ * export default class User extends Model {
502
+ * @attr declare name: string;
503
+ *
504
+ * @attr<NumberTransform>('number')
505
+ * declare age: number;
506
+ *
507
+ * @hasMany('post', { async: true, inverse: null })
508
+ * declare posts: AsyncHasMany<Post>;
509
+ *
510
+ * @belongsTo('group', { async: false, inverse: 'users' })
511
+ * declare group: Group | null;
512
+ * }
513
+ * ```
514
+ *
515
+ * :::
516
+ *
517
+ * Models both define the schema for a resource type and provide
518
+ * the class to use as the reactive object for data of resource
519
+ * of that type.
520
+ *
521
+ * @public
522
+ * @noInheritDoc
523
+ * @hideconstructor
524
+ * @legacy
525
+ */
526
+ var Model = class extends EmberObject {
527
+ /** @internal */
528
+ init(options) {
529
+ if (!options?._secretInit && !options?._createProps) throw new Error("You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.");
530
+ const createProps = options._createProps;
531
+ const _secretInit = options._secretInit;
532
+ options._createProps = null;
533
+ options._secretInit = null;
534
+ const store = this.store = _secretInit.store;
535
+ super.init(options);
536
+ this[RecordStore] = store;
537
+ const identity = _secretInit.identifier;
538
+ _secretInit.cb(this, identity, _secretInit.store);
539
+ this.___recordState = new RecordState(this);
540
+ this.setProperties(createProps);
541
+ const notifications = store.notifications;
542
+ this.___private_notifications = notifications.subscribe(identity, (identifier, type, field) => {
543
+ notifyChanges(identifier, type, field, this, store);
544
+ });
545
+ }
546
+ /** @private */
547
+ destroy() {
548
+ const identifier = recordIdentifierFor(this);
549
+ this.___recordState?.destroy();
550
+ storeFor(this, false).notifications.unsubscribe(this.___private_notifications);
551
+ const support = LEGACY_SUPPORT.get(identifier);
552
+ if (support) {
553
+ support.destroy();
554
+ LEGACY_SUPPORT.delete(identifier);
555
+ }
556
+ super.destroy();
557
+ }
558
+ /**
559
+ If this property is `true` the record is in the `empty`
560
+ state. Empty is the first state all records enter after they have
561
+ been created. Most records created by the store will quickly
562
+ transition to the `loading` state if data needs to be fetched from
563
+ the server or the `created` state if the record is created on the
564
+ client. A record can also enter the empty state if the adapter is
565
+ unable to locate the record.
566
+ @public
567
+ */
568
+ get isEmpty() {
569
+ return this.currentState.isEmpty;
570
+ }
571
+ /**
572
+ If this property is `true` the record is in the `loading` state. A
573
+ record enters this state when the store asks the adapter for its
574
+ data. It remains in this state until the adapter provides the
575
+ requested data.
576
+ @public
577
+ */
578
+ static {
579
+ decorateMethodV2(this.prototype, "isEmpty", [memoized]);
580
+ }
581
+ get isLoading() {
582
+ return this.currentState.isLoading;
583
+ }
584
+ /**
585
+ If this property is `true` the record is in the `loaded` state. A
586
+ record enters this state when its data is populated. Most of a
587
+ record's lifecycle is spent inside substates of the `loaded`
588
+ state.
589
+ Example
590
+ ```javascript
591
+ let record = store.createRecord('model');
592
+ record.isLoaded; // true
593
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
594
+ model.isLoaded;
595
+ ```
596
+ @public
597
+ */
598
+ static {
599
+ decorateMethodV2(this.prototype, "isLoading", [memoized]);
600
+ }
601
+ get isLoaded() {
602
+ return this.currentState.isLoaded;
603
+ }
604
+ /**
605
+ If this property is `true` the record is in the `dirty` state. The
606
+ record has local changes that have not yet been saved by the
607
+ adapter. This includes records that have been created (but not yet
608
+ saved) or deleted.
609
+ Example
610
+ ```javascript
611
+ let record = store.createRecord('model');
612
+ record.hasDirtyAttributes; // true
613
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
614
+ model.hasDirtyAttributes; // false
615
+ model.foo = 'some value';
616
+ model.hasDirtyAttributes; // true
617
+ ```
618
+ @since 1.13.0
619
+ @public
620
+ */
621
+ static {
622
+ decorateMethodV2(this.prototype, "isLoaded", [memoized]);
623
+ }
624
+ get hasDirtyAttributes() {
625
+ return this.currentState.isDirty;
626
+ }
627
+ /**
628
+ If this property is `true` the record is in the `saving` state. A
629
+ record enters the saving state when `save` is called, but the
630
+ adapter has not yet acknowledged that the changes have been
631
+ persisted to the backend.
632
+ Example
633
+ ```javascript
634
+ let record = store.createRecord('model');
635
+ record.isSaving; // false
636
+ let promise = record.save();
637
+ record.isSaving; // true
638
+ promise.then(function() {
639
+ record.isSaving; // false
640
+ });
641
+ ```
642
+ @public
643
+ */
644
+ static {
645
+ decorateMethodV2(this.prototype, "hasDirtyAttributes", [memoized]);
646
+ }
647
+ get isSaving() {
648
+ return this.currentState.isSaving;
649
+ }
650
+ /**
651
+ If this property is `true` the record is in the `deleted` state
652
+ and has been marked for deletion. When `isDeleted` is true and
653
+ `hasDirtyAttributes` is true, the record is deleted locally but the deletion
654
+ was not yet persisted. When `isSaving` is true, the change is
655
+ in-flight. When both `hasDirtyAttributes` and `isSaving` are false, the
656
+ change has persisted.
657
+ Example
658
+ ```javascript
659
+ let record = store.createRecord('model');
660
+ record.isDeleted; // false
661
+ record.deleteRecord();
662
+ // Locally deleted
663
+ record.isDeleted; // true
664
+ record.hasDirtyAttributes; // true
665
+ record.isSaving; // false
666
+ // Persisting the deletion
667
+ let promise = record.save();
668
+ record.isDeleted; // true
669
+ record.isSaving; // true
670
+ // Deletion Persisted
671
+ promise.then(function() {
672
+ record.isDeleted; // true
673
+ record.isSaving; // false
674
+ record.hasDirtyAttributes; // false
675
+ });
676
+ ```
677
+ @public
678
+ */
679
+ static {
680
+ decorateMethodV2(this.prototype, "isSaving", [memoized]);
681
+ }
682
+ get isDeleted() {
683
+ return this.currentState.isDeleted;
684
+ }
685
+ /**
686
+ If this property is `true` the record is in the `new` state. A
687
+ record will be in the `new` state when it has been created on the
688
+ client and the adapter has not yet report that it was successfully
689
+ saved.
690
+ Example
691
+ ```javascript
692
+ let record = store.createRecord('model');
693
+ record.isNew; // true
694
+ record.save().then(function(model) {
695
+ model.isNew; // false
696
+ });
697
+ ```
698
+ @public
699
+ */
700
+ static {
701
+ decorateMethodV2(this.prototype, "isDeleted", [memoized]);
702
+ }
703
+ get isNew() {
704
+ return this.currentState.isNew;
705
+ }
706
+ /**
707
+ If this property is `true` the record is in the `valid` state.
708
+ A record will be in the `valid` state when the adapter did not report any
709
+ server-side validation failures.
710
+ @public
711
+ */
712
+ static {
713
+ decorateMethodV2(this.prototype, "isNew", [memoized]);
714
+ }
715
+ get isValid() {
716
+ return this.currentState.isValid;
717
+ }
718
+ /**
719
+ If the record is in the dirty state this property will report what
720
+ kind of change has caused it to move into the dirty
721
+ state. Possible values are:
722
+ - `created` The record has been created by the client and not yet saved to the adapter.
723
+ - `updated` The record has been updated by the client and not yet saved to the adapter.
724
+ - `deleted` The record has been deleted by the client and not yet saved to the adapter.
725
+ Example
726
+ ```javascript
727
+ let record = store.createRecord('model');
728
+ record.dirtyType; // 'created'
729
+ ```
730
+ @public
731
+ */
732
+ static {
733
+ decorateMethodV2(this.prototype, "isValid", [memoized]);
734
+ }
735
+ get dirtyType() {
736
+ return this.currentState.dirtyType;
737
+ }
738
+ /**
739
+ If `true` the adapter reported that it was unable to save local
740
+ changes to the backend for any reason other than a server-side
741
+ validation error.
742
+ Example
743
+ ```javascript
744
+ record.isError; // false
745
+ record.set('foo', 'valid value');
746
+ record.save().then(null, function() {
747
+ record.isError; // true
748
+ });
749
+ ```
750
+ @public
751
+ */
752
+ static {
753
+ decorateMethodV2(this.prototype, "dirtyType", [memoized]);
754
+ }
755
+ get isError() {
756
+ return this.currentState.isError;
757
+ }
758
+ /**
759
+ * `isError` is read-only and cannot be set directly.
760
+ */
761
+ static {
762
+ decorateMethodV2(this.prototype, "isError", [memoized]);
763
+ }
764
+ set isError(v) {
765
+ throw new Error(`isError is not directly settable`);
766
+ }
767
+ /**
768
+ If `true` the store is attempting to reload the record from the adapter.
769
+ Example
770
+ ```javascript
771
+ record.isReloading; // false
772
+ record.reload();
773
+ record.isReloading; // true
774
+ ```
775
+ @public
776
+ */
777
+ /**
778
+ All ember models have an id property. This is an identifier
779
+ managed by an external source. These are always coerced to be
780
+ strings before being used internally. Note when declaring the
781
+ attributes for a model it is an error to declare an id
782
+ attribute.
783
+ ```javascript
784
+ let record = store.createRecord('model');
785
+ record.id; // null
786
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
787
+ model.id; // '1'
788
+ ```
789
+ @public
790
+ */
791
+ get id() {
792
+ try {
793
+ return recordIdentifierFor(this).id;
794
+ } catch {
795
+ return null;
796
+ }
797
+ }
798
+ /**
799
+ * Assigns the resource's primary key. Typically only used internally
800
+ * when a client-created record is assigned an id upon being saved.
801
+ */
802
+ static {
803
+ decorateMethodV2(this.prototype, "id", [gate]);
804
+ }
805
+ set id(id) {
806
+ const normalizedId = coerceId(id);
807
+ const identifier = recordIdentifierFor(this);
808
+ const didChange = normalizedId !== identifier.id;
809
+ assertPrivateStore(this.store);
810
+ ((test) => {
811
+ if (!test) throw new Error(`Cannot set ${identifier.type} record's id to ${id}, because id is already ${identifier.id}`);
812
+ })(!didChange || identifier.id === null);
813
+ if (normalizedId !== null && didChange) {
814
+ this.store._instanceCache.setRecordId(identifier, normalizedId);
815
+ this.store.notifications.notify(identifier, "identity", null);
816
+ }
817
+ }
818
+ toString() {
819
+ return `<model::${this.constructor.modelName}:${this.id}>`;
820
+ }
821
+ /**
822
+ @private
823
+ */
824
+ get currentState() {
825
+ return this.___recordState;
826
+ }
827
+ /**
828
+ * `currentState` is read-only and cannot be set directly.
829
+ */
830
+ static {
831
+ decorateMethodV2(this.prototype, "currentState", [gate]);
832
+ }
833
+ set currentState(_v) {
834
+ throw new Error("cannot set currentState");
835
+ }
836
+ /**
837
+ The store service instance which created this record instance
838
+ @public
839
+ */
840
+ /**
841
+ When the record is in the `invalid` state this object will contain
842
+ any errors returned by the adapter. When present the errors hash
843
+ contains keys corresponding to the invalid property names
844
+ and values which are arrays of Javascript objects with two keys:
845
+ - `message` A string containing the error message from the backend
846
+ - `attribute` The name of the property associated with this error message
847
+ ```javascript
848
+ record.errors.length; // 0
849
+ record.set('foo', 'invalid value');
850
+ record.save().catch(function() {
851
+ record.errors.foo;
852
+ // [{message: 'foo should be a number.', attribute: 'foo'}]
853
+ });
854
+ ```
855
+ The `errors` property is useful for displaying error messages to
856
+ the user.
857
+ ```handlebars
858
+ <label>Username: <Input @value={{@model.username}} /> </label>
859
+ {{#each @model.errors.username as |error|}}
860
+ <div class="error">
861
+ {{error.message}}
862
+ </div>
863
+ {{/each}}
864
+ <label>Email: <Input @value={{@model.email}} /> </label>
865
+ {{#each @model.errors.email as |error|}}
866
+ <div class="error">
867
+ {{error.message}}
868
+ </div>
869
+ {{/each}}
870
+ ```
871
+ You can also access the special `messages` property on the error
872
+ object to get an array of all the error strings.
873
+ ```handlebars
874
+ {{#each @model.errors.messages as |message|}}
875
+ <div class="error">
876
+ {{message}}
877
+ </div>
878
+ {{/each}}
879
+ ```
880
+ @public
881
+ */
882
+ get errors() {
883
+ const errors = Errors.create({ __record: this });
884
+ this.currentState.updateInvalidErrors(errors);
885
+ return errors;
886
+ }
887
+ /**
888
+ This property holds the `AdapterError` object with which
889
+ last adapter operation was rejected.
890
+ @public
891
+ */
892
+ static {
893
+ decorateMethodV2(this.prototype, "errors", [computeOnce]);
894
+ }
895
+ get adapterError() {
896
+ return this.currentState.adapterError;
897
+ }
898
+ /**
899
+ * `adapterError` is read-only and cannot be set directly.
900
+ */
901
+ static {
902
+ decorateMethodV2(this.prototype, "adapterError", [memoized]);
903
+ }
904
+ set adapterError(v) {
905
+ throw new Error(`adapterError is not directly settable`);
906
+ }
907
+ notifyPropertyChange(prop) {
908
+ const signals = withSignalStore(this);
909
+ entangleSignal(signals, this, prop, void 0);
910
+ super.notifyPropertyChange(prop);
911
+ }
912
+ /** @internal */
913
+ attr() {
914
+ ((test) => {
915
+ if (!test) 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?");
916
+ })(false);
917
+ }
918
+ /**
919
+ Given a callback, iterates over each of the relationships in the model,
920
+ invoking the callback with the name of each relationship and its relationship
921
+ descriptor.
922
+ The callback method you provide should have the following signature (all
923
+ parameters are optional):
924
+ ```javascript
925
+ function(name, descriptor);
926
+ ```
927
+ - `name` the name of the current property in the iteration
928
+ - `descriptor` the meta object that describes this relationship
929
+ The relationship descriptor argument is an object with the following properties.
930
+ - **name** <span class="type">String</span> the name of this relationship on the Model
931
+ - **kind** <span class="type">String</span> "hasMany" or "belongsTo"
932
+ - **options** <span class="type">Object</span> the original options hash passed when the relationship was declared
933
+ - **parentType** <span class="type">Model</span> the type of the Model that owns this relationship
934
+ - **type** <span class="type">String</span> the type name of the related Model
935
+ Note that in addition to a callback, you can also pass an optional target
936
+ object that will be set as `this` on the context.
937
+ Example
938
+ ```js [app/serializers/application.js]
939
+ import JSONSerializer from '@ember-data/serializer/json';
940
+ export default class ApplicationSerializer extends JSONSerializer {
941
+ serialize(record, options) {
942
+ let json = {};
943
+ record.eachRelationship(function(name, descriptor) {
944
+ if (descriptor.kind === 'hasMany') {
945
+ let serializedHasManyName = name.toUpperCase() + '_IDS';
946
+ json[serializedHasManyName] = record.get(name).map(r => r.id);
947
+ }
948
+ });
949
+ return json;
950
+ }
951
+ }
952
+ ```
953
+ @public
954
+ @param callback the callback to invoke
955
+ @param binding the value to which the callback's `this` should be bound
956
+ */
957
+ eachRelationship(callback, binding) {
958
+ this.constructor.eachRelationship(callback, binding);
959
+ }
960
+ /**
961
+ * Returns the relationship schema for the given relationship name, if any.
962
+ */
963
+ relationshipFor(name) {
964
+ return this.constructor.relationshipsByName.get(name);
965
+ }
966
+ /**
967
+ * Returns the inverse relationship schema for the given relationship
968
+ * name, if one exists. See {@link Model.inverseFor | the static inverseFor}.
969
+ */
970
+ inverseFor(name) {
971
+ return this.constructor.inverseFor(name, storeFor(this, false));
972
+ }
973
+ /**
974
+ * Iterates over the attributes defined on this record's class, calling
975
+ * `callback` for each one. See {@link Model.eachAttribute | the static eachAttribute}.
976
+ *
977
+ * @param callback the callback to invoke
978
+ * @param binding the value to which the callback's `this` should be bound
979
+ */
980
+ eachAttribute(callback, binding) {
981
+ this.constructor.eachAttribute(callback, binding);
982
+ }
983
+ /**
984
+ * @internal
985
+ */
986
+ static isModel = true;
987
+ /**
988
+ Represents the model's class name as a string. This can be used to look up the model's class name through
989
+ `Store`'s modelFor method.
990
+ `modelName` is generated for you by WarpDrive. It will be a lowercased, dasherized string.
991
+ For example:
992
+ ```javascript
993
+ store.modelFor('post').modelName; // 'post'
994
+ store.modelFor('blog-post').modelName; // 'blog-post'
995
+ ```
996
+ The most common place you'll want to access `modelName` is in your serializer's `payloadKeyFromModelName` method. For example, to change payload
997
+ keys to underscore (instead of dasherized), you might use the following code:
998
+ ```javascript
999
+ import RESTSerializer from '@ember-data/serializer/rest';
1000
+ import { underscore } from '<app-name>/utils/string-utils';
1001
+ export default const PostSerializer = RESTSerializer.extend({
1002
+ payloadKeyFromModelName(modelName) {
1003
+ return underscore(modelName);
1004
+ }
1005
+ });
1006
+ ```
1007
+ @public
1008
+ */
1009
+ static modelName = null;
1010
+ /**
1011
+ For a given relationship name, returns the model type of the relationship.
1012
+ For example, if you define a model like this:
1013
+ ```js [app/models/post.js]
1014
+ import { Model, hasMany } from '@warp-drive/legacy/model';
1015
+ export default class PostModel extends Model {
1016
+ @hasMany('comment') comments;
1017
+ }
1018
+ ```
1019
+ Calling `store.modelFor('post').typeForRelationship('comments', store)` will return `Comment`.
1020
+ @public
1021
+ @param name the name of the relationship
1022
+ @param store an instance of Store
1023
+ @return the type of the relationship, or undefined
1024
+ */
1025
+ static typeForRelationship(name, store) {
1026
+ ((test) => {
1027
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1028
+ })(this.modelName);
1029
+ const relationship = this.relationshipsByName.get(name);
1030
+ return relationship && store.modelFor(relationship.type);
1031
+ }
1032
+ /**
1033
+ * A cache of resolved inverse relationships by name, populated lazily by
1034
+ * {@link Model.inverseFor | inverseFor}.
1035
+ */
1036
+ static get inverseMap() {
1037
+ ((test) => {
1038
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1039
+ })(this.modelName);
1040
+ return Object.create(null);
1041
+ }
1042
+ /**
1043
+ Find the relationship which is the inverse of the one asked for.
1044
+ For example, if you define models like this:
1045
+ ```js [app/models/post.js]
1046
+ import { Model, hasMany } from '@warp-drive/legacy/model';
1047
+ export default class PostModel extends Model {
1048
+ @hasMany('message') comments;
1049
+ }
1050
+ ```
1051
+ ```js [app/models/message.js]
1052
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1053
+ export default class MessageModel extends Model {
1054
+ @belongsTo('post') owner;
1055
+ }
1056
+ ```
1057
+ ``` js
1058
+ store.modelFor('post').inverseFor('comments', store) // { type: 'message', name: 'owner', kind: 'belongsTo' }
1059
+ store.modelFor('message').inverseFor('owner', store) // { type: 'post', name: 'comments', kind: 'hasMany' }
1060
+ ```
1061
+ @public
1062
+ @param name the name of the relationship
1063
+ @param store
1064
+ @return the inverse relationship, or null
1065
+ */
1066
+ static {
1067
+ decorateMethodV2(this, "inverseMap", [computeOnce]);
1068
+ }
1069
+ static inverseFor(name, store) {
1070
+ ((test) => {
1071
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1072
+ })(this.modelName);
1073
+ const inverseMap = this.inverseMap;
1074
+ if (inverseMap[name]) return inverseMap[name];
1075
+ else {
1076
+ const inverse = this._findInverseFor(name, store);
1077
+ inverseMap[name] = inverse;
1078
+ return inverse;
1079
+ }
1080
+ }
1081
+ /**
1082
+ * @private
1083
+ */
1084
+ static _findInverseFor(name, store) {
1085
+ ((test) => {
1086
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1087
+ })(this.modelName);
1088
+ const relationship = this.relationshipsByName.get(name);
1089
+ ((test) => {
1090
+ if (!test) throw new Error(`No relationship named '${name}' on '${this.modelName}' exists.`);
1091
+ })(relationship);
1092
+ if (!relationship) return null;
1093
+ const { options } = relationship;
1094
+ ((test) => {
1095
+ if (!test) throw new Error(`Expected the relationship ${name} on ${this.modelName} to define an inverse.`);
1096
+ })(options.inverse === null || typeof options.inverse === "string" && options.inverse.length > 0);
1097
+ if (options.inverse === null) return null;
1098
+ const schemaExists = store.schema.hasResource(relationship);
1099
+ ((test) => {
1100
+ if (!test) throw new Error(`No associated schema found for '${relationship.type}' while calculating the inverse of ${name} on ${this.modelName}`);
1101
+ })(schemaExists);
1102
+ if (!schemaExists) return null;
1103
+ const inverseField = store.schema.fields(relationship).get(options.inverse);
1104
+ ((test) => {
1105
+ if (!test) throw new Error(`No inverse relationship found for '${name}' on '${this.modelName}'`);
1106
+ })(inverseField && (inverseField.kind === "belongsTo" || inverseField.kind === "hasMany"));
1107
+ return inverseField || null;
1108
+ }
1109
+ /**
1110
+ The model's relationships as a map, keyed on the type of the
1111
+ relationship. The value of each entry is an array containing a descriptor
1112
+ for each relationship with that type, describing the name of the relationship
1113
+ as well as the type.
1114
+ For example, given the following model definition:
1115
+ ```js [app/models/blog.js]
1116
+ import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';
1117
+ export default class BlogModel extends Model {
1118
+ @hasMany('user') users;
1119
+ @belongsTo('user') owner;
1120
+ @hasMany('post') posts;
1121
+ }
1122
+ ```
1123
+ This computed property would return a map describing these
1124
+ relationships, like this:
1125
+ ```javascript
1126
+ import Blog from 'app/models/blog';
1127
+ import User from 'app/models/user';
1128
+ import Post from 'app/models/post';
1129
+ let relationships = Blog.relationships;
1130
+ relationships.user;
1131
+ //=> [ { name: 'users', kind: 'hasMany' },
1132
+ // { name: 'owner', kind: 'belongsTo' } ]
1133
+ relationships.post;
1134
+ //=> [ { name: 'posts', kind: 'hasMany' } ]
1135
+ ```
1136
+ @public
1137
+ */
1138
+ static get relationships() {
1139
+ ((test) => {
1140
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1141
+ })(this.modelName);
1142
+ const map = /* @__PURE__ */ new Map();
1143
+ this.relationshipsByName.forEach((desc) => {
1144
+ const { type } = desc;
1145
+ if (!map.has(type)) map.set(type, []);
1146
+ map.get(type).push(desc);
1147
+ });
1148
+ return map;
1149
+ }
1150
+ /**
1151
+ A hash containing lists of the model's relationships, grouped
1152
+ by the relationship kind. For example, given a model with this
1153
+ definition:
1154
+ ```js [app/models/blog.js]
1155
+ import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';
1156
+ export default class BlogModel extends Model {
1157
+ @hasMany('user') users;
1158
+ @belongsTo('user') owner;
1159
+ @hasMany('post') posts;
1160
+ }
1161
+ ```
1162
+ This property would contain the following:
1163
+ ```javascript
1164
+ import Blog from 'app/models/blog';
1165
+ let relationshipNames = Blog.relationshipNames;
1166
+ relationshipNames.hasMany;
1167
+ //=> ['users', 'posts']
1168
+ relationshipNames.belongsTo;
1169
+ //=> ['owner']
1170
+ ```
1171
+ @public
1172
+ */
1173
+ static {
1174
+ decorateMethodV2(this, "relationships", [computeOnce]);
1175
+ }
1176
+ static get relationshipNames() {
1177
+ ((test) => {
1178
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1179
+ })(this.modelName);
1180
+ const names = {
1181
+ hasMany: [],
1182
+ belongsTo: []
1183
+ };
1184
+ this.eachComputedProperty((name, meta) => {
1185
+ if (isRelationshipSchema(meta)) names[meta.kind].push(name);
1186
+ });
1187
+ return names;
1188
+ }
1189
+ /**
1190
+ An array of types directly related to a model. Each type will be
1191
+ included once, regardless of the number of relationships it has with
1192
+ the model.
1193
+ For example, given a model with this definition:
1194
+ ```js [app/models/blog.js]
1195
+ import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';
1196
+ export default class BlogModel extends Model {
1197
+ @hasMany('user') users;
1198
+ @belongsTo('user') owner;
1199
+ @hasMany('post') posts;
1200
+ }
1201
+ ```
1202
+ This property would contain the following:
1203
+ ```javascript
1204
+ import Blog from 'app/models/blog';
1205
+ let relatedTypes = Blog.relatedTypes');
1206
+ //=> ['user', 'post']
1207
+ ```
1208
+ @public
1209
+ */
1210
+ static {
1211
+ decorateMethodV2(this, "relationshipNames", [computeOnce]);
1212
+ }
1213
+ static get relatedTypes() {
1214
+ ((test) => {
1215
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1216
+ })(this.modelName);
1217
+ const types = [];
1218
+ const rels = this.relationshipsObject;
1219
+ const relationships = Object.keys(rels);
1220
+ for (let i = 0; i < relationships.length; i++) {
1221
+ const modelName = rels[relationships[i]].type;
1222
+ if (!types.includes(modelName)) types.push(modelName);
1223
+ }
1224
+ return types;
1225
+ }
1226
+ /**
1227
+ A map whose keys are the relationships of a model and whose values are
1228
+ relationship descriptors.
1229
+ For example, given a model with this
1230
+ definition:
1231
+ ```js [app/models/blog.js]
1232
+ import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';
1233
+ export default class BlogModel extends Model {
1234
+ @hasMany('user') users;
1235
+ @belongsTo('user') owner;
1236
+ @hasMany('post') posts;
1237
+ }
1238
+ ```
1239
+ This property would contain the following:
1240
+ ```javascript
1241
+ import Blog from 'app/models/blog';
1242
+ let relationshipsByName = Blog.relationshipsByName;
1243
+ relationshipsByName.users;
1244
+ //=> { name: 'users', kind: 'hasMany', type: 'user', options: Object }
1245
+ relationshipsByName.owner;
1246
+ //=> { name: 'owner', kind: 'belongsTo', type: 'user', options: Object }
1247
+ ```
1248
+ @public
1249
+ */
1250
+ static {
1251
+ decorateMethodV2(this, "relatedTypes", [computeOnce]);
1252
+ }
1253
+ static get relationshipsByName() {
1254
+ ((test) => {
1255
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1256
+ })(this.modelName);
1257
+ const map = /* @__PURE__ */ new Map();
1258
+ const rels = this.relationshipsObject;
1259
+ const relationships = Object.keys(rels);
1260
+ for (let i = 0; i < relationships.length; i++) {
1261
+ const value = rels[relationships[i]];
1262
+ map.set(value.name, value);
1263
+ }
1264
+ return map;
1265
+ }
1266
+ /**
1267
+ * A hash of the model's relationship schemas keyed by relationship name.
1268
+ * See also {@link Model.relationshipsByName | relationshipsByName}, which
1269
+ * provides the same information as a `Map`.
1270
+ */
1271
+ static {
1272
+ decorateMethodV2(this, "relationshipsByName", [computeOnce]);
1273
+ }
1274
+ static get relationshipsObject() {
1275
+ ((test) => {
1276
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1277
+ })(this.modelName);
1278
+ const relationships = Object.create(null);
1279
+ const modelName = this.modelName;
1280
+ this.eachComputedProperty((name, meta) => {
1281
+ if (!isRelationshipSchema(meta)) return;
1282
+ meta.key = name;
1283
+ meta.name = name;
1284
+ relationships[name] = meta;
1285
+ ((test) => {
1286
+ if (!test) throw new Error(`Expected options in meta`);
1287
+ })(meta.options && typeof meta.options === "object");
1288
+ ((test) => {
1289
+ if (!test) 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.`);
1290
+ })(!(meta.options.inverse === null && meta.options.as?.length));
1291
+ });
1292
+ return relationships;
1293
+ }
1294
+ /**
1295
+ A map whose keys are the fields of the model and whose values are strings
1296
+ describing the kind of the field. A model's fields are the union of all of its
1297
+ attributes and relationships.
1298
+ For example:
1299
+ ```js [app/models/blog.js]
1300
+ import { Model, attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
1301
+ export default class BlogModel extends Model {
1302
+ @hasMany('user') users;
1303
+ @belongsTo('user') owner;
1304
+ @hasMany('post') posts;
1305
+ @attr('string') title;
1306
+ }
1307
+ ```
1308
+ ```js
1309
+ import Blog from 'app/models/blog'
1310
+ let fields = Blog.fields;
1311
+ fields.forEach(function(kind, field) {
1312
+ // do thing
1313
+ });
1314
+ // prints:
1315
+ // users, hasMany
1316
+ // owner, belongsTo
1317
+ // posts, hasMany
1318
+ // title, attribute
1319
+ ```
1320
+ @public
1321
+ */
1322
+ static {
1323
+ decorateMethodV2(this, "relationshipsObject", [computeOnce]);
1324
+ }
1325
+ static get fields() {
1326
+ ((test) => {
1327
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1328
+ })(this.modelName);
1329
+ const map = /* @__PURE__ */ new Map();
1330
+ this.eachComputedProperty((name, meta) => {
1331
+ if (isRelationshipSchema(meta)) map.set(name, meta.kind);
1332
+ else if (isAttributeSchema(meta)) map.set(name, "attribute");
1333
+ });
1334
+ return map;
1335
+ }
1336
+ /**
1337
+ Given a callback, iterates over each of the relationships in the model,
1338
+ invoking the callback with the name of each relationship and its relationship
1339
+ descriptor.
1340
+ @public
1341
+ @param callback the callback to invoke
1342
+ @param binding the value to which the callback's `this` should be bound
1343
+ */
1344
+ static {
1345
+ decorateMethodV2(this, "fields", [computeOnce]);
1346
+ }
1347
+ static eachRelationship(callback, binding) {
1348
+ ((test) => {
1349
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1350
+ })(this.modelName);
1351
+ this.relationshipsByName.forEach((relationship, name) => {
1352
+ callback.call(binding, name, relationship);
1353
+ });
1354
+ }
1355
+ /**
1356
+ Given a callback, iterates over each of the types related to a model,
1357
+ invoking the callback with the related type's class. Each type will be
1358
+ returned just once, regardless of how many different relationships it has
1359
+ with a model.
1360
+ @public
1361
+ @param callback the callback to invoke
1362
+ @param binding the value to which the callback's `this` should be bound
1363
+ */
1364
+ static eachRelatedType(callback, binding) {
1365
+ ((test) => {
1366
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1367
+ })(this.modelName);
1368
+ const relationshipTypes = this.relatedTypes;
1369
+ for (let i = 0; i < relationshipTypes.length; i++) {
1370
+ const type = relationshipTypes[i];
1371
+ callback.call(binding, type);
1372
+ }
1373
+ }
1374
+ /**
1375
+ *
1376
+ * @private
1377
+ * @deprecated
1378
+ */
1379
+ static determineRelationshipType(knownSide, store) {
1380
+ ((test) => {
1381
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1382
+ })(this.modelName);
1383
+ const knownKey = knownSide.name;
1384
+ const knownKind = knownSide.kind;
1385
+ const inverse = this.inverseFor(knownKey, store);
1386
+ if (!inverse) return knownKind === "belongsTo" ? "oneToNone" : "manyToNone";
1387
+ if (inverse.kind === "belongsTo") return knownKind === "belongsTo" ? "oneToOne" : "manyToOne";
1388
+ else return knownKind === "belongsTo" ? "oneToMany" : "manyToMany";
1389
+ }
1390
+ /**
1391
+ A map whose keys are the attributes of the model (properties
1392
+ described by attr) and whose values are the meta object for the
1393
+ property.
1394
+ Example
1395
+ ```js [app/models/person.js]
1396
+ import { Model, attr } from '@warp-drive/legacy/model';
1397
+ export default class PersonModel extends Model {
1398
+ @attr('string') firstName;
1399
+ @attr('string') lastName;
1400
+ @attr('date') birthday;
1401
+ }
1402
+ ```
1403
+ ```javascript
1404
+ import Person from 'app/models/person'
1405
+ let attributes = Person.attributes
1406
+ attributes.forEach(function(meta, name) {
1407
+ // do thing
1408
+ });
1409
+ // prints:
1410
+ // firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
1411
+ // lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
1412
+ // birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
1413
+ ```
1414
+ @public
1415
+ */
1416
+ static get attributes() {
1417
+ ((test) => {
1418
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1419
+ })(this.modelName);
1420
+ const map = /* @__PURE__ */ new Map();
1421
+ this.eachComputedProperty((name, meta) => {
1422
+ if (isAttributeSchema(meta)) {
1423
+ ((test) => {
1424
+ if (!test) 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());
1425
+ })(name !== "id");
1426
+ meta.key = name;
1427
+ meta.name = name;
1428
+ map.set(name, meta);
1429
+ }
1430
+ });
1431
+ return map;
1432
+ }
1433
+ /**
1434
+ A map whose keys are the attributes of the model (properties
1435
+ described by attr) and whose values are type of transformation
1436
+ applied to each attribute. This map does not include any
1437
+ attributes that do not have an transformation type.
1438
+ Example
1439
+ ```js [app/models/person.js]
1440
+ import { Model, attr } from '@warp-drive/legacy/model';
1441
+ export default class PersonModel extends Model {
1442
+ @attr firstName;
1443
+ @attr('string') lastName;
1444
+ @attr('date') birthday;
1445
+ }
1446
+ ```
1447
+ ```javascript
1448
+ import Person from 'app/models/person';
1449
+ let transformedAttributes = Person.transformedAttributes
1450
+ transformedAttributes.forEach(function(field, type) {
1451
+ // do thing
1452
+ });
1453
+ // prints:
1454
+ // lastName string
1455
+ // birthday date
1456
+ ```
1457
+ @public
1458
+ */
1459
+ static {
1460
+ decorateMethodV2(this, "attributes", [computeOnce]);
1461
+ }
1462
+ static get transformedAttributes() {
1463
+ ((test) => {
1464
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1465
+ })(this.modelName);
1466
+ const map = /* @__PURE__ */ new Map();
1467
+ this.eachAttribute((name, meta) => {
1468
+ if (meta.type) map.set(name, meta.type);
1469
+ });
1470
+ return map;
1471
+ }
1472
+ /**
1473
+ Iterates through the attributes of the model, calling the passed function on each
1474
+ attribute.
1475
+ The callback method you provide should have the following signature (all
1476
+ parameters are optional):
1477
+ ```javascript
1478
+ function(name, meta);
1479
+ ```
1480
+ - `name` the name of the current property in the iteration
1481
+ - `meta` the meta object for the attribute property in the iteration
1482
+ Note that in addition to a callback, you can also pass an optional target
1483
+ object that will be set as `this` on the context.
1484
+ Example
1485
+ ```javascript
1486
+ import { Model, attr } from '@warp-drive/legacy/model';
1487
+ class PersonModel extends Model {
1488
+ @attr('string') firstName;
1489
+ @attr('string') lastName;
1490
+ @attr('date') birthday;
1491
+ }
1492
+ PersonModel.eachAttribute(function(name, meta) {
1493
+ // do thing
1494
+ });
1495
+ // prints:
1496
+ // firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
1497
+ // lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
1498
+ // birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
1499
+ ```
1500
+ @public
1501
+ @param callback The callback to execute
1502
+ @param binding [optional] the value to which the callback's `this` should be bound
1503
+ */
1504
+ static {
1505
+ decorateMethodV2(this, "transformedAttributes", [computeOnce]);
1506
+ }
1507
+ static eachAttribute(callback, binding) {
1508
+ ((test) => {
1509
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1510
+ })(this.modelName);
1511
+ this.attributes.forEach((meta, name) => {
1512
+ callback.call(binding, name, meta);
1513
+ });
1514
+ }
1515
+ /**
1516
+ Iterates through the transformedAttributes of the model, calling
1517
+ the passed function on each attribute. Note the callback will not be
1518
+ called for any attributes that do not have an transformation type.
1519
+ The callback method you provide should have the following signature (all
1520
+ parameters are optional):
1521
+ ```javascript
1522
+ function(name, type);
1523
+ ```
1524
+ - `name` the name of the current property in the iteration
1525
+ - `type` a string containing the name of the type of transformed
1526
+ applied to the attribute
1527
+ Note that in addition to a callback, you can also pass an optional target
1528
+ object that will be set as `this` on the context.
1529
+ Example
1530
+ ```javascript
1531
+ import { Model, attr } from '@warp-drive/legacy/model';
1532
+ let Person = Model.extend({
1533
+ firstName: attr(),
1534
+ lastName: attr('string'),
1535
+ birthday: attr('date')
1536
+ });
1537
+ Person.eachTransformedAttribute(function(name, type) {
1538
+ // do thing
1539
+ });
1540
+ // prints:
1541
+ // lastName string
1542
+ // birthday date
1543
+ ```
1544
+ @public
1545
+ @param callback The callback to execute
1546
+ @param binding [optional] the value to which the callback's `this` should be bound
1547
+ */
1548
+ static eachTransformedAttribute(callback, binding) {
1549
+ ((test) => {
1550
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1551
+ })(this.modelName);
1552
+ this.transformedAttributes.forEach((type, name) => {
1553
+ callback.call(binding, name, type);
1554
+ });
1555
+ }
1556
+ /**
1557
+ Returns the name of the model class.
1558
+ @public
1559
+ */
1560
+ static toString() {
1561
+ ((test) => {
1562
+ if (!test) throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
1563
+ })(this.modelName);
1564
+ return `model:${this.modelName}`;
1565
+ }
1566
+ };
1567
+ Model.prototype.save = save;
1568
+ Model.prototype.destroyRecord = destroyRecord;
1569
+ Model.prototype.unloadRecord = unloadRecord;
1570
+ Model.prototype.hasMany = hasMany;
1571
+ Model.prototype.belongsTo = belongsTo;
1572
+ Model.prototype.serialize = serialize;
1573
+ Model.prototype._createSnapshot = createSnapshot;
1574
+ Model.prototype.deleteRecord = deleteRecord;
1575
+ Model.prototype.changedAttributes = changedAttributes;
1576
+ Model.prototype.rollbackAttributes = rollbackAttributes;
1577
+ Model.prototype.reload = reload;
1578
+ defineGate(Model.prototype, "isReloading", {
1579
+ get() {
1580
+ console.warn(`record.isReloading is deprecated, please use store.request and either <Request> or getRequuestState to keep track of the request state instead.`);
1581
+ return this._isReloading ?? false;
1582
+ },
1583
+ set(v) {
1584
+ this._isReloading = v;
1585
+ },
1586
+ configurable: true,
1587
+ isLocal: true
1588
+ });
1589
+ /**
1590
+ * Restores the pre-`RequestManager` implementations of `save`,
1591
+ * `destroyRecord`, and `reload` onto the given `Model` subclass, for
1592
+ * apps that have not yet migrated off of the deprecated
1593
+ * `ENABLE_LEGACY_REQUEST_METHODS` behaviors.
1594
+ */
1595
+ function restoreDeprecatedModelRequestBehaviors(ModelKlass) {
1596
+ ModelKlass.prototype.save = _save;
1597
+ ModelKlass.prototype.destroyRecord = _destroyRecord;
1598
+ ModelKlass.prototype.reload = _reload;
1599
+ defineGate(Model.prototype, "isReloading", {
1600
+ get() {
1601
+ return this._isReloading ?? false;
1602
+ },
1603
+ set(v) {
1604
+ this._isReloading = v;
1605
+ },
1606
+ isLocal: true
1607
+ });
1608
+ }
1609
+ Model.prototype._createProps = null;
1610
+ Model.prototype._secretInit = null;
1611
+ {
1612
+ const lookupDescriptor = function lookupDescriptor(obj, keyName) {
1613
+ let current = obj;
1614
+ do {
1615
+ const descriptor = Object.getOwnPropertyDescriptor(current, keyName);
1616
+ if (descriptor !== void 0) return descriptor;
1617
+ current = Object.getPrototypeOf(current);
1618
+ } while (current !== null);
1619
+ return null;
1620
+ };
1621
+ const init = Model.prototype.init;
1622
+ Model.prototype.init = function(createArgs) {
1623
+ init.call(this, createArgs);
1624
+ const ourDescriptor = lookupDescriptor(Model.prototype, "currentState");
1625
+ const theirDescriptor = lookupDescriptor(this, "currentState");
1626
+ if (!ourDescriptor || !theirDescriptor) 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()}`);
1627
+ const realState = this.___recordState;
1628
+ if (ourDescriptor.get !== theirDescriptor.get || realState !== this.currentState) 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()}`);
1629
+ const ID_DESCRIPTOR = lookupDescriptor(Model.prototype, "id");
1630
+ const idDesc = lookupDescriptor(this, "id");
1631
+ if (!ID_DESCRIPTOR || !idDesc) 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()}`);
1632
+ if (idDesc.get !== ID_DESCRIPTOR.get) 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()}`);
1633
+ };
1634
+ delete Model.reopen;
1635
+ delete Model.reopenClass;
1636
+ }
1637
+ function isRelationshipSchema(meta) {
1638
+ return typeof meta === "object" && meta !== null && "kind" in meta && "options" in meta && (meta.kind === "hasMany" || meta.kind === "belongsTo");
1639
+ }
1640
+ function isAttributeSchema(meta) {
1641
+ return typeof meta === "object" && meta !== null && "kind" in meta && meta.kind === "attribute";
1642
+ }
1643
+
1644
+ //#endregion
1645
+ //#region src/model/-private/model-for-mixin.ts
1646
+ function modelForMixin(store, normalizedModelName) {
1647
+ const owner = getOwner(store);
1648
+ const MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);
1649
+ const mixin = MaybeMixin && MaybeMixin.class;
1650
+ if (mixin) {
1651
+ const ModelForMixin = Model.extend(mixin);
1652
+ ModelForMixin.__isMixin = true;
1653
+ ModelForMixin.__mixin = mixin;
1654
+ owner.register(`model:${normalizedModelName}`, ModelForMixin);
1655
+ }
1656
+ return owner.factoryFor(`model:${normalizedModelName}`);
1657
+ }
1658
+
1659
+ //#endregion
1660
+ //#region src/model/-private/schema-provider.ts
1661
+ var ModelSchemaProvider = class {
1662
+ /** @internal */
1663
+ /** @internal */
1664
+ /** @internal */
1665
+ constructor(store) {
1666
+ this.store = store;
1667
+ this._schemas = /* @__PURE__ */ new Map();
1668
+ this._typeMisses = /* @__PURE__ */ new Set();
1669
+ }
1670
+ resourceTypes() {
1671
+ return Array.from(this._schemas.keys());
1672
+ }
1673
+ hasTrait(type) {
1674
+ ((test) => {
1675
+ if (!test) throw new Error(`hasTrait is not available with @warp-drive/legacy/model's SchemaService`);
1676
+ })(false);
1677
+ return false;
1678
+ }
1679
+ resourceHasTrait(resource, trait) {
1680
+ ((test) => {
1681
+ if (!test) throw new Error(`resourceHasTrait is not available with @warp-drive/legacy/model's SchemaService`);
1682
+ })(false);
1683
+ return false;
1684
+ }
1685
+ transformation(field) {
1686
+ ((test) => {
1687
+ if (!test) throw new Error(`transformation is not available with @warp-drive/legacy/model's SchemaService`);
1688
+ })(false);
1689
+ }
1690
+ derivation(field) {
1691
+ ((test) => {
1692
+ if (!test) throw new Error(`derivation is not available with @warp-drive/legacy/model's SchemaService`);
1693
+ })(false);
1694
+ }
1695
+ hashFn(field) {
1696
+ ((test) => {
1697
+ if (!test) throw new Error(`hashFn is not available with @warp-drive/legacy/model's SchemaService`);
1698
+ })(false);
1699
+ }
1700
+ resource(resource) {
1701
+ const type = normalizeModelName(resource.type);
1702
+ if (!this._schemas.has(type)) this._loadModelSchema(type);
1703
+ return this._schemas.get(type).schema;
1704
+ }
1705
+ registerResources(schemas) {
1706
+ ((test) => {
1707
+ if (!test) throw new Error(`registerResources is not available with @warp-drive/legacy/model's SchemaService`);
1708
+ })(false);
1709
+ }
1710
+ registerResource(schema) {
1711
+ ((test) => {
1712
+ if (!test) throw new Error(`registerResource is not available with @warp-drive/legacy/model's SchemaService`);
1713
+ })(false);
1714
+ }
1715
+ registerTransformation(transform) {
1716
+ ((test) => {
1717
+ if (!test) throw new Error(`registerTransformation is not available with @warp-drive/legacy/model's SchemaService`);
1718
+ })(false);
1719
+ }
1720
+ registerDerivation(derivation) {
1721
+ ((test) => {
1722
+ if (!test) throw new Error(`registerDerivation is not available with @warp-drive/legacy/model's SchemaService`);
1723
+ })(false);
1724
+ }
1725
+ registerHashFn(hashFn) {
1726
+ ((test) => {
1727
+ if (!test) throw new Error(`registerHashFn is not available with @warp-drive/legacy/model's SchemaService`);
1728
+ })(false);
1729
+ }
1730
+ /** @internal */
1731
+ _loadModelSchema(type) {
1732
+ const factory = getModelFactory(this.store, type);
1733
+ if (!factory) throw new Error(`No model was found for '${type}'`);
1734
+ const modelClass = factory.class;
1735
+ const attributeMap = modelClass.attributes;
1736
+ const attributes = Object.create(null);
1737
+ attributeMap.forEach((meta, name) => attributes[name] = meta);
1738
+ const relationships = modelClass.relationshipsObject || null;
1739
+ const fields = /* @__PURE__ */ new Map();
1740
+ for (const attr of Object.values(attributes)) fields.set(attr.name, attr);
1741
+ for (const rel of Object.values(relationships)) fields.set(rel.name, rel);
1742
+ const schema = {
1743
+ legacy: true,
1744
+ identity: {
1745
+ name: "id",
1746
+ kind: "@id"
1747
+ },
1748
+ type,
1749
+ fields: Array.from(fields.values())
1750
+ };
1751
+ const cacheFields = /* @__PURE__ */ new Map();
1752
+ for (const field of fields.values()) {
1753
+ const cacheKey = field.sourceKey ?? field.name;
1754
+ ((test) => {
1755
+ if (!test) throw new Error(`The sourceKey '${field.sourceKey}' for the field '${field.name}' on '${type}' is invalid because it matches the name of an existing field`);
1756
+ })(!field.sourceKey || field.sourceKey === field.name || !fields.has(field.sourceKey));
1757
+ cacheFields.set(cacheKey, field);
1758
+ }
1759
+ const internalSchema = {
1760
+ schema,
1761
+ attributes,
1762
+ relationships,
1763
+ fields,
1764
+ cacheFields
1765
+ };
1766
+ this._schemas.set(type, internalSchema);
1767
+ return internalSchema;
1768
+ }
1769
+ fields(resource) {
1770
+ const type = normalizeModelName(resource.type);
1771
+ if (!this._schemas.has(type)) this._loadModelSchema(type);
1772
+ return this._schemas.get(type).fields;
1773
+ }
1774
+ cacheFields(resource) {
1775
+ const type = normalizeModelName(resource.type);
1776
+ if (!this._schemas.has(type)) this._loadModelSchema(type);
1777
+ return this._schemas.get(type).cacheFields;
1778
+ }
1779
+ hasResource(resource) {
1780
+ const type = normalizeModelName(resource.type);
1781
+ if (this._schemas.has(type)) return true;
1782
+ if (this._typeMisses.has(type)) return false;
1783
+ if (!(getModelFactory(this.store, type) !== null)) {
1784
+ this._typeMisses.add(type);
1785
+ return false;
1786
+ }
1787
+ return true;
1788
+ }
1789
+ };
1790
+ ModelSchemaProvider.prototype.doesTypeExist = function(type) {
1791
+ console.warn(`Use \`schema.hasResource({ type })\` instead of \`schema.doesTypeExist(type)\``);
1792
+ return this.hasResource({ type });
1793
+ };
1794
+ ModelSchemaProvider.prototype.attributesDefinitionFor = function(resource) {
1795
+ console.warn(`Use \`schema.fields({ type })\` instead of \`schema.attributesDefinitionFor({ type })\``);
1796
+ const type = normalizeModelName(resource.type);
1797
+ if (!this._schemas.has(type)) this._loadModelSchema(type);
1798
+ return this._schemas.get(type).attributes;
1799
+ };
1800
+ ModelSchemaProvider.prototype.relationshipsDefinitionFor = function(resource) {
1801
+ console.warn(`Use \`schema.fields({ type })\` instead of \`schema.relationshipsDefinitionFor({ type })\``);
1802
+ const type = normalizeModelName(resource.type);
1803
+ if (!this._schemas.has(type)) this._loadModelSchema(type);
1804
+ return this._schemas.get(type).relationships;
1805
+ };
1806
+ /**
1807
+ * The `createSchemaService` implementation for use with `Model`. Pass
1808
+ * the result of this to your store's `createSchemaService` method when
1809
+ * configuring the store to use `Model` for schema information.
1810
+ *
1811
+ * @public
1812
+ */
1813
+ function buildSchema(store) {
1814
+ return new ModelSchemaProvider(store);
1815
+ }
1816
+ function getModelFactory(store, type) {
1817
+ if (!store._modelFactoryCache) store._modelFactoryCache = Object.create(null);
1818
+ const cache = store._modelFactoryCache;
1819
+ let factory = cache[type];
1820
+ if (!factory) {
1821
+ factory = getOwner(store).factoryFor(`model:${type}`);
1822
+ if (!factory) factory = modelForMixin(store, type);
1823
+ if (!factory) return null;
1824
+ const klass = factory.class;
1825
+ if (klass.isModel) {
1826
+ if (!(klass.modelName && Object.prototype.hasOwnProperty.call(klass, "modelName"))) Object.defineProperty(klass, "modelName", { value: type });
1827
+ }
1828
+ cache[type] = factory;
1829
+ }
1830
+ return factory;
1831
+ }
1832
+
1833
+ //#endregion
1834
+ export { save as _, RecordState as a, _save as c, createSnapshot as d, deleteRecord as f, rollbackAttributes as g, reload as h, restoreDeprecatedModelRequestBehaviors as i, belongsTo as l, hasMany as m, getModelFactory as n, _destroyRecord as o, destroyRecord as p, Model as r, _reload as s, buildSchema as t, changedAttributes as u, serialize as v, unloadRecord as y };
1835
+ //# sourceMappingURL=schema-provider-D2ESMsA8.js.map