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