@warp-drive/legacy 5.9.0-beta.0 → 5.9.0-beta.2

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