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