@warp-drive/legacy 5.9.0-alpha.21 → 5.9.0-alpha.22

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