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