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