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