@warp-drive/legacy 5.9.0-alpha.21 → 5.9.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (467) hide show
  1. package/dist/-private-DQ6Iap2t.js +193 -0
  2. package/dist/-private-DQ6Iap2t.js.map +1 -0
  3. package/dist/-private-DccRZQsm.js +904 -0
  4. package/dist/-private-DccRZQsm.js.map +1 -0
  5. package/dist/adapter/-private.d.ts +33 -0
  6. package/dist/adapter/-private.d.ts.map +1 -0
  7. package/dist/adapter/-private.js +3 -1
  8. package/dist/adapter/error.d.ts +2 -0
  9. package/dist/adapter/error.js +422 -453
  10. package/dist/adapter/error.js.map +1 -0
  11. package/{declarations → dist}/adapter/json-api.d.ts +30 -29
  12. package/dist/adapter/json-api.d.ts.map +1 -0
  13. package/dist/adapter/json-api.js +265 -143
  14. package/dist/adapter/json-api.js.map +1 -0
  15. package/dist/adapter/rest.d.ts +2 -0
  16. package/dist/adapter/rest.js +937 -1136
  17. package/dist/adapter/rest.js.map +1 -0
  18. package/dist/adapter-CARrK3-8.d.ts +784 -0
  19. package/dist/adapter-CARrK3-8.d.ts.map +1 -0
  20. package/dist/adapter-DFVAuivO.js +1130 -0
  21. package/dist/adapter-DFVAuivO.js.map +1 -0
  22. package/dist/adapter.d.ts +2 -0
  23. package/dist/adapter.js +1 -1248
  24. package/dist/compat/-private.d.ts +2 -0
  25. package/dist/compat/-private.js +3 -1
  26. package/dist/compat/builders.d.ts +169 -0
  27. package/dist/compat/builders.d.ts.map +1 -0
  28. package/dist/compat/builders.js +205 -245
  29. package/dist/compat/builders.js.map +1 -0
  30. package/dist/compat/extensions.d.ts +2 -0
  31. package/dist/compat/extensions.js +265 -304
  32. package/dist/compat/extensions.js.map +1 -0
  33. package/dist/compat/utils.d.ts +151 -0
  34. package/dist/compat/utils.d.ts.map +1 -0
  35. package/dist/compat/utils.js +187 -206
  36. package/dist/compat/utils.js.map +1 -0
  37. package/dist/compat-BbNNmTM-.d.ts +1386 -0
  38. package/dist/compat-BbNNmTM-.d.ts.map +1 -0
  39. package/dist/compat-g__Pfy2S.js +734 -0
  40. package/dist/compat-g__Pfy2S.js.map +1 -0
  41. package/dist/compat.d.ts +2 -0
  42. package/dist/compat.js +1 -1036
  43. package/dist/error-CzkyXr1Q.d.ts +435 -0
  44. package/dist/error-CzkyXr1Q.d.ts.map +1 -0
  45. package/dist/errors-BbCo7Tut.js +2134 -0
  46. package/dist/errors-BbCo7Tut.js.map +1 -0
  47. package/dist/extensions-DumNm4dA.d.ts +102 -0
  48. package/dist/extensions-DumNm4dA.d.ts.map +1 -0
  49. package/dist/index.d.ts +243 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +267 -339
  52. package/dist/index.js.map +1 -0
  53. package/dist/json-BXNPTlcH.js +1106 -0
  54. package/dist/json-BXNPTlcH.js.map +1 -0
  55. package/dist/model/-private.d.ts +3 -0
  56. package/dist/model/-private.js +3 -1
  57. package/dist/model/migration-support.d.ts +335 -0
  58. package/dist/model/migration-support.d.ts.map +1 -0
  59. package/dist/model/migration-support.js +504 -575
  60. package/dist/model/migration-support.js.map +1 -0
  61. package/dist/model-62hn5_PD.d.ts +3107 -0
  62. package/dist/model-62hn5_PD.d.ts.map +1 -0
  63. package/dist/model-C7-ZIbd5.js +683 -0
  64. package/dist/model-C7-ZIbd5.js.map +1 -0
  65. package/dist/model-fragments-tlMYPSd_.js +334 -0
  66. package/dist/model-fragments-tlMYPSd_.js.map +1 -0
  67. package/dist/model-fragments.d.ts +294 -0
  68. package/dist/model-fragments.d.ts.map +1 -0
  69. package/dist/model-fragments.js +2 -94
  70. package/dist/model.d.ts +404 -0
  71. package/dist/model.d.ts.map +1 -0
  72. package/dist/model.js +3 -670
  73. package/{declarations/adapter/rest.d.ts → dist/rest-0NhtexIq.d.ts} +183 -173
  74. package/dist/rest-0NhtexIq.d.ts.map +1 -0
  75. package/dist/runtime-BPCpkOf1-CVHWB0MF.js +53 -0
  76. package/dist/runtime-BPCpkOf1-CVHWB0MF.js.map +1 -0
  77. package/dist/schema-provider-7RHVFTdb.js +1929 -0
  78. package/dist/schema-provider-7RHVFTdb.js.map +1 -0
  79. package/{declarations → dist}/serializer/json-api.d.ts +3 -0
  80. package/dist/serializer/json-api.d.ts.map +1 -0
  81. package/dist/serializer/json-api.js +527 -519
  82. package/dist/serializer/json-api.js.map +1 -0
  83. package/{declarations → dist}/serializer/json.d.ts +3 -0
  84. package/dist/serializer/json.d.ts.map +1 -0
  85. package/dist/serializer/json.js +3 -6
  86. package/{declarations/serializer/-private/embedded-records-mixin.d.ts → dist/serializer/rest.d.ts} +56 -1
  87. package/dist/serializer/rest.d.ts.map +1 -0
  88. package/dist/serializer/rest.js +958 -1199
  89. package/dist/serializer/rest.js.map +1 -0
  90. package/dist/serializer/transform.d.ts +313 -0
  91. package/dist/serializer/transform.d.ts.map +1 -0
  92. package/dist/serializer/transform.js +283 -308
  93. package/dist/serializer/transform.js.map +1 -0
  94. package/dist/serializer.d.ts +151 -0
  95. package/dist/serializer.d.ts.map +1 -0
  96. package/dist/serializer.js +205 -205
  97. package/dist/serializer.js.map +1 -0
  98. package/dist/store-C4qYzXei.js +473 -0
  99. package/dist/store-C4qYzXei.js.map +1 -0
  100. package/dist/store.d.ts +13 -0
  101. package/dist/store.d.ts.map +1 -0
  102. package/dist/store.js +1 -641
  103. package/dist/unpkg/dev/-private-CrEyBE-B.js +189 -0
  104. package/dist/unpkg/dev/-private-CrEyBE-B.js.map +1 -0
  105. package/dist/unpkg/dev/-private-vOhxVExH.js +896 -0
  106. package/dist/unpkg/dev/-private-vOhxVExH.js.map +1 -0
  107. package/dist/unpkg/dev/adapter/-private.js +3 -1
  108. package/dist/unpkg/dev/adapter/error.js +421 -452
  109. package/dist/unpkg/dev/adapter/error.js.map +1 -0
  110. package/dist/unpkg/dev/adapter/json-api.js +239 -257
  111. package/dist/unpkg/dev/adapter/json-api.js.map +1 -0
  112. package/dist/unpkg/dev/adapter/rest.js +935 -1134
  113. package/dist/unpkg/dev/adapter/rest.js.map +1 -0
  114. package/dist/unpkg/dev/adapter-RlAbN461.js +1129 -0
  115. package/dist/unpkg/dev/adapter-RlAbN461.js.map +1 -0
  116. package/dist/unpkg/dev/adapter.js +1 -1247
  117. package/dist/unpkg/dev/compat/-private.js +3 -1
  118. package/dist/unpkg/dev/compat/builders.js +204 -247
  119. package/dist/unpkg/dev/compat/builders.js.map +1 -0
  120. package/dist/unpkg/dev/compat/extensions.js +264 -303
  121. package/dist/unpkg/dev/compat/extensions.js.map +1 -0
  122. package/dist/unpkg/dev/compat/utils.js +186 -205
  123. package/dist/unpkg/dev/compat/utils.js.map +1 -0
  124. package/dist/unpkg/dev/compat-B2O7jZLN.js +825 -0
  125. package/dist/unpkg/dev/compat-B2O7jZLN.js.map +1 -0
  126. package/dist/unpkg/dev/compat.js +1 -1178
  127. package/dist/unpkg/dev/errors-DiBJX1gq.js +2127 -0
  128. package/dist/unpkg/dev/errors-DiBJX1gq.js.map +1 -0
  129. package/dist/unpkg/dev/index.js +266 -344
  130. package/dist/unpkg/dev/index.js.map +1 -0
  131. package/dist/unpkg/dev/json-DDJji3V3.js +1104 -0
  132. package/dist/unpkg/dev/json-DDJji3V3.js.map +1 -0
  133. package/dist/unpkg/dev/model/-private.js +3 -1
  134. package/dist/unpkg/dev/model/migration-support.js +481 -549
  135. package/dist/unpkg/dev/model/migration-support.js.map +1 -0
  136. package/dist/unpkg/dev/model-BrJ3pFM-.js +655 -0
  137. package/dist/unpkg/dev/model-BrJ3pFM-.js.map +1 -0
  138. package/dist/unpkg/dev/model-fragments-tlMYPSd_.js +334 -0
  139. package/dist/unpkg/dev/model-fragments-tlMYPSd_.js.map +1 -0
  140. package/dist/unpkg/dev/model-fragments.js +2 -94
  141. package/dist/unpkg/dev/model.js +3 -681
  142. package/dist/unpkg/dev/runtime-BPCpkOf1-CVHWB0MF.js +53 -0
  143. package/dist/unpkg/dev/runtime-BPCpkOf1-CVHWB0MF.js.map +1 -0
  144. package/dist/unpkg/dev/schema-provider-Z5GzOhu-.js +1834 -0
  145. package/dist/unpkg/dev/schema-provider-Z5GzOhu-.js.map +1 -0
  146. package/dist/unpkg/dev/serializer/json-api.js +514 -634
  147. package/dist/unpkg/dev/serializer/json-api.js.map +1 -0
  148. package/dist/unpkg/dev/serializer/json.js +3 -4
  149. package/dist/unpkg/dev/serializer/rest.js +954 -1196
  150. package/dist/unpkg/dev/serializer/rest.js.map +1 -0
  151. package/dist/unpkg/dev/serializer/transform.js +283 -308
  152. package/dist/unpkg/dev/serializer/transform.js.map +1 -0
  153. package/dist/unpkg/dev/serializer.js +205 -205
  154. package/dist/unpkg/dev/serializer.js.map +1 -0
  155. package/dist/unpkg/dev/store-D_V8-HQl.js +472 -0
  156. package/dist/unpkg/dev/store-D_V8-HQl.js.map +1 -0
  157. package/dist/unpkg/dev/store.js +1 -649
  158. package/dist/unpkg/dev/util-dSKEgQDp.js +12 -0
  159. package/dist/unpkg/dev/util-dSKEgQDp.js.map +1 -0
  160. package/dist/unpkg/dev/utils-DYC9utVJ.js +11 -0
  161. package/dist/unpkg/dev/utils-DYC9utVJ.js.map +1 -0
  162. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js +189 -0
  163. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js.map +1 -0
  164. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js +896 -0
  165. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js.map +1 -0
  166. package/dist/unpkg/dev-deprecated/adapter/-private.js +3 -1
  167. package/dist/unpkg/dev-deprecated/adapter/error.js +421 -452
  168. package/dist/unpkg/dev-deprecated/adapter/error.js.map +1 -0
  169. package/dist/unpkg/dev-deprecated/adapter/json-api.js +239 -257
  170. package/dist/unpkg/dev-deprecated/adapter/json-api.js.map +1 -0
  171. package/dist/unpkg/dev-deprecated/adapter/rest.js +935 -1134
  172. package/dist/unpkg/dev-deprecated/adapter/rest.js.map +1 -0
  173. package/dist/unpkg/dev-deprecated/adapter-RlAbN461.js +1129 -0
  174. package/dist/unpkg/dev-deprecated/adapter-RlAbN461.js.map +1 -0
  175. package/dist/unpkg/dev-deprecated/adapter.js +1 -1247
  176. package/dist/unpkg/dev-deprecated/compat/-private.js +3 -1
  177. package/dist/unpkg/dev-deprecated/compat/builders.js +204 -247
  178. package/dist/unpkg/dev-deprecated/compat/builders.js.map +1 -0
  179. package/dist/unpkg/dev-deprecated/compat/extensions.js +264 -303
  180. package/dist/unpkg/dev-deprecated/compat/extensions.js.map +1 -0
  181. package/dist/unpkg/dev-deprecated/compat/utils.js +186 -205
  182. package/dist/unpkg/dev-deprecated/compat/utils.js.map +1 -0
  183. package/dist/unpkg/dev-deprecated/compat-CgUa-VIF.js +825 -0
  184. package/dist/unpkg/dev-deprecated/compat-CgUa-VIF.js.map +1 -0
  185. package/dist/unpkg/dev-deprecated/compat.js +1 -1178
  186. package/dist/unpkg/dev-deprecated/errors-Cba2PDIB.js +2128 -0
  187. package/dist/unpkg/dev-deprecated/errors-Cba2PDIB.js.map +1 -0
  188. package/dist/unpkg/dev-deprecated/index.js +266 -343
  189. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  190. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js +1104 -0
  191. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js.map +1 -0
  192. package/dist/unpkg/dev-deprecated/model/-private.js +3 -1
  193. package/dist/unpkg/dev-deprecated/model/migration-support.js +492 -566
  194. package/dist/unpkg/dev-deprecated/model/migration-support.js.map +1 -0
  195. package/dist/unpkg/dev-deprecated/model-D-JSD2Bx.js +660 -0
  196. package/dist/unpkg/dev-deprecated/model-D-JSD2Bx.js.map +1 -0
  197. package/dist/unpkg/dev-deprecated/model-fragments-tlMYPSd_.js +334 -0
  198. package/dist/unpkg/dev-deprecated/model-fragments-tlMYPSd_.js.map +1 -0
  199. package/dist/unpkg/dev-deprecated/model-fragments.js +2 -94
  200. package/dist/unpkg/dev-deprecated/model.js +3 -685
  201. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-CVHWB0MF.js +53 -0
  202. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-CVHWB0MF.js.map +1 -0
  203. package/dist/unpkg/dev-deprecated/schema-provider-n96uVRhl.js +1835 -0
  204. package/dist/unpkg/dev-deprecated/schema-provider-n96uVRhl.js.map +1 -0
  205. package/dist/unpkg/dev-deprecated/serializer/json-api.js +514 -634
  206. package/dist/unpkg/dev-deprecated/serializer/json-api.js.map +1 -0
  207. package/dist/unpkg/dev-deprecated/serializer/json.js +3 -4
  208. package/dist/unpkg/dev-deprecated/serializer/rest.js +954 -1196
  209. package/dist/unpkg/dev-deprecated/serializer/rest.js.map +1 -0
  210. package/dist/unpkg/dev-deprecated/serializer/transform.js +283 -308
  211. package/dist/unpkg/dev-deprecated/serializer/transform.js.map +1 -0
  212. package/dist/unpkg/dev-deprecated/serializer.js +205 -205
  213. package/dist/unpkg/dev-deprecated/serializer.js.map +1 -0
  214. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js +472 -0
  215. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js.map +1 -0
  216. package/dist/unpkg/dev-deprecated/store.js +1 -649
  217. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js +18 -0
  218. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js.map +1 -0
  219. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js +17 -0
  220. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js.map +1 -0
  221. package/dist/unpkg/prod/-private-B4bxoTuK.js +160 -0
  222. package/dist/unpkg/prod/-private-B4bxoTuK.js.map +1 -0
  223. package/dist/unpkg/prod/-private-SfXkkHKd.js +745 -0
  224. package/dist/unpkg/prod/-private-SfXkkHKd.js.map +1 -0
  225. package/dist/unpkg/prod/adapter/-private.js +3 -1
  226. package/dist/unpkg/prod/adapter/error.js +418 -447
  227. package/dist/unpkg/prod/adapter/error.js.map +1 -0
  228. package/dist/unpkg/prod/adapter/json-api.js +236 -252
  229. package/dist/unpkg/prod/adapter/json-api.js.map +1 -0
  230. package/dist/unpkg/prod/adapter/rest.js +911 -1097
  231. package/dist/unpkg/prod/adapter/rest.js.map +1 -0
  232. package/dist/unpkg/prod/adapter-DAx_reer.js +1111 -0
  233. package/dist/unpkg/prod/adapter-DAx_reer.js.map +1 -0
  234. package/dist/unpkg/prod/adapter.js +1 -1214
  235. package/dist/unpkg/prod/compat/-private.js +3 -1
  236. package/dist/unpkg/prod/compat/builders.js +165 -182
  237. package/dist/unpkg/prod/compat/builders.js.map +1 -0
  238. package/dist/unpkg/prod/compat/extensions.js +252 -283
  239. package/dist/unpkg/prod/compat/extensions.js.map +1 -0
  240. package/dist/unpkg/prod/compat/utils.js +183 -200
  241. package/dist/unpkg/prod/compat/utils.js.map +1 -0
  242. package/dist/unpkg/prod/compat-CJ87MzDn.js +547 -0
  243. package/dist/unpkg/prod/compat-CJ87MzDn.js.map +1 -0
  244. package/dist/unpkg/prod/compat.js +1 -742
  245. package/dist/unpkg/prod/errors-CoKAYQJi.js +1977 -0
  246. package/dist/unpkg/prod/errors-CoKAYQJi.js.map +1 -0
  247. package/dist/unpkg/prod/index.js +245 -308
  248. package/dist/unpkg/prod/index.js.map +1 -0
  249. package/dist/unpkg/prod/json-BD1kRTfB.js +1080 -0
  250. package/dist/unpkg/prod/json-BD1kRTfB.js.map +1 -0
  251. package/dist/unpkg/prod/model/-private.js +3 -1
  252. package/dist/unpkg/prod/model/migration-support.js +477 -542
  253. package/dist/unpkg/prod/model/migration-support.js.map +1 -0
  254. package/dist/unpkg/prod/model-D2zzdmP8.js +603 -0
  255. package/dist/unpkg/prod/model-D2zzdmP8.js.map +1 -0
  256. package/dist/unpkg/prod/model-fragments-tlMYPSd_.js +334 -0
  257. package/dist/unpkg/prod/model-fragments-tlMYPSd_.js.map +1 -0
  258. package/dist/unpkg/prod/model-fragments.js +2 -94
  259. package/dist/unpkg/prod/model.js +3 -596
  260. package/dist/unpkg/prod/runtime-BPCpkOf1-CVHWB0MF.js +53 -0
  261. package/dist/unpkg/prod/runtime-BPCpkOf1-CVHWB0MF.js.map +1 -0
  262. package/dist/unpkg/prod/schema-provider-BUXipKQV.js +1622 -0
  263. package/dist/unpkg/prod/schema-provider-BUXipKQV.js.map +1 -0
  264. package/dist/unpkg/prod/serializer/json-api.js +497 -592
  265. package/dist/unpkg/prod/serializer/json-api.js.map +1 -0
  266. package/dist/unpkg/prod/serializer/json.js +3 -4
  267. package/dist/unpkg/prod/serializer/rest.js +938 -1166
  268. package/dist/unpkg/prod/serializer/rest.js.map +1 -0
  269. package/dist/unpkg/prod/serializer/transform.js +283 -308
  270. package/dist/unpkg/prod/serializer/transform.js.map +1 -0
  271. package/dist/unpkg/prod/serializer.js +205 -205
  272. package/dist/unpkg/prod/serializer.js.map +1 -0
  273. package/dist/unpkg/prod/store-RGGc1ilN.js +392 -0
  274. package/dist/unpkg/prod/store-RGGc1ilN.js.map +1 -0
  275. package/dist/unpkg/prod/store.js +1 -517
  276. package/dist/unpkg/prod/util-dSKEgQDp.js +12 -0
  277. package/dist/unpkg/prod/util-dSKEgQDp.js.map +1 -0
  278. package/dist/unpkg/prod/utils-DYC9utVJ.js +11 -0
  279. package/dist/unpkg/prod/utils-DYC9utVJ.js.map +1 -0
  280. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js +160 -0
  281. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js.map +1 -0
  282. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js +745 -0
  283. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js.map +1 -0
  284. package/dist/unpkg/prod-deprecated/adapter/-private.js +3 -1
  285. package/dist/unpkg/prod-deprecated/adapter/error.js +418 -447
  286. package/dist/unpkg/prod-deprecated/adapter/error.js.map +1 -0
  287. package/dist/unpkg/prod-deprecated/adapter/json-api.js +236 -252
  288. package/dist/unpkg/prod-deprecated/adapter/json-api.js.map +1 -0
  289. package/dist/unpkg/prod-deprecated/adapter/rest.js +911 -1097
  290. package/dist/unpkg/prod-deprecated/adapter/rest.js.map +1 -0
  291. package/{declarations/adapter.d.ts → dist/unpkg/prod-deprecated/adapter-DAx_reer.js} +445 -110
  292. package/dist/unpkg/prod-deprecated/adapter-DAx_reer.js.map +1 -0
  293. package/dist/unpkg/prod-deprecated/adapter.js +1 -1214
  294. package/dist/unpkg/prod-deprecated/compat/-private.js +3 -1
  295. package/dist/unpkg/prod-deprecated/compat/builders.js +165 -182
  296. package/dist/unpkg/prod-deprecated/compat/builders.js.map +1 -0
  297. package/dist/unpkg/prod-deprecated/compat/extensions.js +252 -283
  298. package/dist/unpkg/prod-deprecated/compat/extensions.js.map +1 -0
  299. package/dist/unpkg/prod-deprecated/compat/utils.js +183 -200
  300. package/dist/unpkg/prod-deprecated/compat/utils.js.map +1 -0
  301. package/dist/unpkg/prod-deprecated/compat-CJ87MzDn.js +547 -0
  302. package/dist/unpkg/prod-deprecated/compat-CJ87MzDn.js.map +1 -0
  303. package/dist/unpkg/prod-deprecated/compat.js +1 -742
  304. package/dist/unpkg/prod-deprecated/errors-BUVJ3jcW.js +1978 -0
  305. package/dist/unpkg/prod-deprecated/errors-BUVJ3jcW.js.map +1 -0
  306. package/dist/unpkg/prod-deprecated/index.js +245 -307
  307. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  308. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js +1080 -0
  309. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js.map +1 -0
  310. package/dist/unpkg/prod-deprecated/model/-private.js +3 -1
  311. package/dist/unpkg/prod-deprecated/model/migration-support.js +488 -559
  312. package/dist/unpkg/prod-deprecated/model/migration-support.js.map +1 -0
  313. package/dist/unpkg/prod-deprecated/model-66Pl5niO.js +604 -0
  314. package/dist/unpkg/prod-deprecated/model-66Pl5niO.js.map +1 -0
  315. package/dist/unpkg/prod-deprecated/model-fragments-tlMYPSd_.js +334 -0
  316. package/dist/unpkg/prod-deprecated/model-fragments-tlMYPSd_.js.map +1 -0
  317. package/dist/unpkg/prod-deprecated/model-fragments.js +2 -94
  318. package/dist/unpkg/prod-deprecated/model.js +3 -599
  319. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-CVHWB0MF.js +53 -0
  320. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-CVHWB0MF.js.map +1 -0
  321. package/dist/unpkg/prod-deprecated/schema-provider-DtyBaLoG.js +1635 -0
  322. package/dist/unpkg/prod-deprecated/schema-provider-DtyBaLoG.js.map +1 -0
  323. package/dist/unpkg/prod-deprecated/serializer/json-api.js +497 -592
  324. package/dist/unpkg/prod-deprecated/serializer/json-api.js.map +1 -0
  325. package/dist/unpkg/prod-deprecated/serializer/json.js +3 -4
  326. package/dist/unpkg/prod-deprecated/serializer/rest.js +938 -1166
  327. package/dist/unpkg/prod-deprecated/serializer/rest.js.map +1 -0
  328. package/dist/unpkg/prod-deprecated/serializer/transform.js +283 -308
  329. package/dist/unpkg/prod-deprecated/serializer/transform.js.map +1 -0
  330. package/dist/unpkg/prod-deprecated/serializer.js +205 -205
  331. package/dist/unpkg/prod-deprecated/serializer.js.map +1 -0
  332. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js +392 -0
  333. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js.map +1 -0
  334. package/dist/unpkg/prod-deprecated/store.js +1 -517
  335. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js +14 -0
  336. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js.map +1 -0
  337. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js +13 -0
  338. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js.map +1 -0
  339. package/dist/util-Bnx8nm-D.js +29 -0
  340. package/dist/util-Bnx8nm-D.js.map +1 -0
  341. package/dist/utils-ZAytYep8.js +28 -0
  342. package/dist/utils-ZAytYep8.js.map +1 -0
  343. package/package.json +16 -16
  344. package/declarations/adapter/-private/build-url-mixin.d.ts +0 -189
  345. package/declarations/adapter/-private/fastboot-interface.d.ts +0 -8
  346. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +0 -1
  347. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +0 -4
  348. package/declarations/adapter/-private/utils/fetch.d.ts +0 -8
  349. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
  350. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +0 -6
  351. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -5
  352. package/declarations/adapter/-private.d.ts +0 -5
  353. package/declarations/adapter/error.d.ts +0 -431
  354. package/declarations/compat/-private.d.ts +0 -13
  355. package/declarations/compat/builders/find-all.d.ts +0 -34
  356. package/declarations/compat/builders/find-record.d.ts +0 -56
  357. package/declarations/compat/builders/query.d.ts +0 -66
  358. package/declarations/compat/builders/save-record.d.ts +0 -34
  359. package/declarations/compat/builders/utils.d.ts +0 -3
  360. package/declarations/compat/builders.d.ts +0 -14
  361. package/declarations/compat/extensions.d.ts +0 -99
  362. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +0 -55
  363. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +0 -2
  364. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +0 -11
  365. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +0 -5
  366. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +0 -9
  367. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +0 -528
  368. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +0 -220
  369. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +0 -6
  370. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +0 -110
  371. package/declarations/compat/legacy-network-handler/snapshot.d.ts +0 -255
  372. package/declarations/compat/utils.d.ts +0 -148
  373. package/declarations/compat.d.ts +0 -189
  374. package/declarations/index.d.ts +0 -244
  375. package/declarations/model/-private/attr.d.ts +0 -191
  376. package/declarations/model/-private/belongs-to.d.ts +0 -195
  377. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +0 -5
  378. package/declarations/model/-private/errors.d.ts +0 -289
  379. package/declarations/model/-private/has-many.d.ts +0 -162
  380. package/declarations/model/-private/hooks.d.ts +0 -36
  381. package/declarations/model/-private/legacy-relationships-support.d.ts +0 -47
  382. package/declarations/model/-private/model-for-mixin.d.ts +0 -3
  383. package/declarations/model/-private/model-methods.d.ts +0 -39
  384. package/declarations/model/-private/model.d.ts +0 -1279
  385. package/declarations/model/-private/notify-changes.d.ts +0 -4
  386. package/declarations/model/-private/promise-belongs-to.d.ts +0 -40
  387. package/declarations/model/-private/promise-many-array.d.ts +0 -130
  388. package/declarations/model/-private/record-state.d.ts +0 -58
  389. package/declarations/model/-private/references/belongs-to.d.ts +0 -488
  390. package/declarations/model/-private/references/has-many.d.ts +0 -498
  391. package/declarations/model/-private/schema-provider.d.ts +0 -66
  392. package/declarations/model/-private/type-utils.d.ts +0 -57
  393. package/declarations/model/-private/util.d.ts +0 -5
  394. package/declarations/model/-private.d.ts +0 -8
  395. package/declarations/model/migration-support.d.ts +0 -306
  396. package/declarations/model-fragments/extensions/fragment-array.d.ts +0 -54
  397. package/declarations/model-fragments/extensions/fragment.d.ts +0 -50
  398. package/declarations/model-fragments/hooks/model-for.d.ts +0 -27
  399. package/declarations/model-fragments/index.d.ts +0 -13
  400. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +0 -15
  401. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +0 -56
  402. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +0 -38
  403. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +0 -34
  404. package/declarations/model-fragments/utilities/with-legacy.d.ts +0 -11
  405. package/declarations/model-fragments.d.ts +0 -9
  406. package/declarations/model.d.ts +0 -49
  407. package/declarations/serializer/-private/transforms/boolean.d.ts +0 -60
  408. package/declarations/serializer/-private/transforms/date.d.ts +0 -42
  409. package/declarations/serializer/-private/transforms/number.d.ts +0 -42
  410. package/declarations/serializer/-private/transforms/string.d.ts +0 -42
  411. package/declarations/serializer/-private/transforms/transform.d.ts +0 -118
  412. package/declarations/serializer/-private/utils.d.ts +0 -27
  413. package/declarations/serializer/rest.d.ts +0 -51
  414. package/declarations/serializer/transform.d.ts +0 -5
  415. package/declarations/serializer.d.ts +0 -252
  416. package/declarations/store/-private.d.ts +0 -223
  417. package/declarations/store.d.ts +0 -10
  418. package/dist/-private-BG3bMiKp.js +0 -1211
  419. package/dist/errors-DZKA206g.js +0 -2589
  420. package/dist/hooks-BvOqJBei.js +0 -105
  421. package/dist/json-DU8m1pGf.js +0 -1336
  422. package/dist/model-for-CXkJw59V.js +0 -297
  423. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  424. package/dist/schema-provider-DtPOp0d7.js +0 -2382
  425. package/dist/serialize-into-hash-DPZYoF-i.js +0 -261
  426. package/dist/unpkg/dev/-private-DtjBbEgy.js +0 -1206
  427. package/dist/unpkg/dev/errors-DngRU-If.js +0 -2585
  428. package/dist/unpkg/dev/hooks-UuiLxWxS.js +0 -104
  429. package/dist/unpkg/dev/json-K2Y9z6MN.js +0 -1333
  430. package/dist/unpkg/dev/model-for-CXkJw59V.js +0 -297
  431. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  432. package/dist/unpkg/dev/schema-provider-0D7f-QOn.js +0 -2272
  433. package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +0 -259
  434. package/dist/unpkg/dev/util-DvanW33H.js +0 -20
  435. package/dist/unpkg/dev/utils-BhvS1iTS.js +0 -8
  436. package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +0 -1206
  437. package/dist/unpkg/dev-deprecated/errors-Bzidntpi.js +0 -2588
  438. package/dist/unpkg/dev-deprecated/hooks-DVXhMW14.js +0 -104
  439. package/dist/unpkg/dev-deprecated/json-K2Y9z6MN.js +0 -1333
  440. package/dist/unpkg/dev-deprecated/model-for-CXkJw59V.js +0 -297
  441. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  442. package/dist/unpkg/dev-deprecated/schema-provider-ZwO5_fZw.js +0 -2292
  443. package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +0 -259
  444. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +0 -24
  445. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +0 -12
  446. package/dist/unpkg/prod/-private-BdyZaGEh.js +0 -971
  447. package/dist/unpkg/prod/errors-B-PWeYlW.js +0 -2337
  448. package/dist/unpkg/prod/hooks-Bx-zBziU.js +0 -72
  449. package/dist/unpkg/prod/json-Qewu-UN9.js +0 -1300
  450. package/dist/unpkg/prod/model-for-CXkJw59V.js +0 -297
  451. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  452. package/dist/unpkg/prod/schema-provider-BgRqk8i9.js +0 -1951
  453. package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +0 -215
  454. package/dist/unpkg/prod/util-DvanW33H.js +0 -20
  455. package/dist/unpkg/prod/utils-BhvS1iTS.js +0 -8
  456. package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +0 -971
  457. package/dist/unpkg/prod-deprecated/errors-Dl2J9d1D.js +0 -2340
  458. package/dist/unpkg/prod-deprecated/hooks-Cm60wWTf.js +0 -72
  459. package/dist/unpkg/prod-deprecated/json-Qewu-UN9.js +0 -1300
  460. package/dist/unpkg/prod-deprecated/model-for-CXkJw59V.js +0 -297
  461. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  462. package/dist/unpkg/prod-deprecated/schema-provider-Dh6tRqVI.js +0 -1980
  463. package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +0 -215
  464. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +0 -23
  465. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +0 -11
  466. package/dist/util-Dul6TZts.js +0 -35
  467. package/dist/utils-Cqw9eRj5.js +0 -23
@@ -1,1300 +0,0 @@
1
- import { getOwner } from '@ember/application';
2
- import { dasherize, singularize } from '@warp-drive/utilities/string';
3
- import { Serializer } from './serializer.js';
4
- function coerceId(id) {
5
- if (id === null || id === undefined || id === '') {
6
- return null;
7
- } else if (typeof id === 'string') {
8
- return id;
9
- } else if (typeof id === 'symbol') {
10
- return id.toString();
11
- } else {
12
- return String(id);
13
- }
14
- }
15
-
16
- /**
17
- Given the name of a relationship on a resource `type`, determines the
18
- inverse relationship field (if any) using only the schema service.
19
-
20
- Unlike `Model.inverseFor`, this does not require `type` to be backed by
21
- a `Model` class, so it works for both `Model`-based and schema-only
22
- (e.g. `withDefaults` migration-support) resources.
23
-
24
- @private
25
- */
26
- function inverseForRelationship(store, type, name) {
27
- const relationship = store.schema.fields({
28
- type
29
- }).get(name);
30
- const {
31
- options
32
- } = relationship;
33
- if (options.inverse === null) {
34
- return null;
35
- }
36
- const schemaExists = store.schema.hasResource(relationship);
37
- if (!schemaExists) {
38
- return null;
39
- }
40
- const inverseField = store.schema.fields(relationship).get(options.inverse);
41
- return inverseField ?? null;
42
- }
43
-
44
- /**
45
- Given a relationship field on a resource `type`, determines the
46
- cardinality of the relationship using only the schema service.
47
-
48
- Unlike `Model.determineRelationshipType`, this does not require `type`
49
- to be backed by a `Model` class, so it works for both `Model`-based and
50
- schema-only (e.g. `withDefaults` migration-support) resources.
51
-
52
- @private
53
- */
54
- function determineRelationshipType(store, type, knownSide) {
55
- const knownKind = knownSide.kind;
56
- const inverse = inverseForRelationship(store, type, knownSide.name);
57
- if (!inverse) {
58
- return knownKind === 'belongsTo' ? 'oneToNone' : 'manyToNone';
59
- }
60
- const otherKind = inverse.kind;
61
- if (otherKind === 'belongsTo') {
62
- return knownKind === 'belongsTo' ? 'oneToOne' : 'manyToOne';
63
- } else {
64
- return knownKind === 'belongsTo' ? 'oneToMany' : 'manyToMany';
65
- }
66
- }
67
-
68
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
69
- /* eslint-disable @typescript-eslint/no-unsafe-call */
70
- /* eslint-disable @typescript-eslint/no-unsafe-return */
71
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
72
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
73
- const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
74
- const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
75
- const PRIMARY_ATTRIBUTE_KEY = 'base';
76
-
77
- /**
78
- * :::danger
79
- ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
80
- If starting a new app or thinking of implementing a new adapter, consider writing a
81
- {@link Handler} instead to be used with the {@link RequestManager}
82
- :::
83
-
84
- In WarpDrive a Serializer is used to serialize and deserialize
85
- records when they are transferred in and out of an external source.
86
- This process involves normalizing property names, transforming
87
- attribute values and serializing relationships.
88
-
89
- By default, WarpDrive uses and recommends the `JSONAPISerializer`.
90
-
91
- `JSONSerializer` is useful for simpler or legacy backends that may
92
- not support the http://jsonapi.org/ spec.
93
-
94
- For example, given the following `User` model and JSON payload:
95
-
96
- ```js [app/models/user.js]
97
- import Model, { attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
98
-
99
- export default class UserModel extends Model {
100
- @hasMany('user') friends;
101
- @belongsTo('location') house;
102
-
103
- @attr('string') name;
104
- }
105
- ```
106
-
107
- ```js
108
- {
109
- id: 1,
110
- name: 'Sebastian',
111
- friends: [3, 4],
112
- links: {
113
- house: '/houses/lefkada'
114
- }
115
- }
116
- ```
117
-
118
- `JSONSerializer` will normalize the JSON payload to the {json:api} format that the
119
- JSONAPICache uses to cache data in the Store.
120
-
121
- You can customize how JSONSerializer processes its payload by passing options in
122
- the `attrs` hash or by subclassing the `JSONSerializer` and overriding hooks:
123
-
124
- - To customize how a single record is normalized, use the `normalize` hook.
125
- - To customize how `JSONSerializer` normalizes the whole server response, use the
126
- `normalizeResponse` hook.
127
- - To customize how `JSONSerializer` normalizes a specific response from the server,
128
- use one of the many specific `normalizeResponse` hooks.
129
- - To customize how `JSONSerializer` normalizes your id, attributes or relationships,
130
- use the `extractId`, `extractAttributes` and `extractRelationships` hooks.
131
-
132
- The `JSONSerializer` normalization process follows these steps:
133
-
134
- 1. `normalizeResponse`
135
- - entry method to the serializer.
136
- 2. `normalizeCreateRecordResponse`
137
- - a `normalizeResponse` for a specific operation is called.
138
- 3. `normalizeSingleResponse`|`normalizeArrayResponse`
139
- - for methods like `createRecord` we expect a single record back, while for methods like `findAll` we expect multiple records back.
140
- 4. `normalize`
141
- - `normalizeArrayResponse` iterates and calls `normalize` for each of its records while `normalizeSingle`
142
- calls it once. This is the method you most likely want to subclass.
143
- 5. `extractId` | `extractAttributes` | `extractRelationships`
144
- - `normalize` delegates to these methods to
145
- turn the record payload into the JSON API format.
146
-
147
- @class JSONSerializer
148
- @public
149
- */
150
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
- const JSONSerializer = Serializer.extend({
152
- /**
153
- The `primaryKey` is used when serializing and deserializing
154
- data. WarpDrive always uses the `id` property to store the id of
155
- the record. The external source may not always follow this
156
- convention. In these cases it is useful to override the
157
- `primaryKey` property to match the `primaryKey` of your external
158
- store.
159
- Example
160
- ```js [app/serializers/application.js]
161
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
162
- export default class ApplicationSerializer extends JSONSerializer {
163
- primaryKey = '_id'
164
- }
165
- ```
166
- @public
167
- @default 'id'
168
- */
169
- primaryKey: 'id',
170
- /**
171
- The `attrs` object can be used to declare a simple mapping between
172
- property names on `Model` records and payload keys in the
173
- serialized JSON object representing the record. An object with the
174
- property `key` can also be used to designate the attribute's key on
175
- the response payload.
176
- Example
177
- ```js [app/models/person.js]
178
- import Model, { attr } from '@warp-drive/legacy/model';
179
- export default class PersonModel extends Model {
180
- @attr('string') firstName;
181
- @attr('string') lastName;
182
- @attr('string') occupation;
183
- @attr('boolean') admin;
184
- }
185
- ```
186
- ```js [app/serializers/person.js]
187
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
188
- export default class PersonSerializer extends JSONSerializer {
189
- attrs = {
190
- admin: 'is_admin',
191
- occupation: { key: 'career' }
192
- }
193
- }
194
- ```
195
- You can also remove attributes and relationships by setting the `serialize`
196
- key to `false` in your mapping object.
197
- Example
198
- ```js [app/serializers/person.js]
199
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
200
- export default class PostSerializer extends JSONSerializer {
201
- attrs = {
202
- admin: { serialize: false },
203
- occupation: { key: 'career' }
204
- }
205
- }
206
- ```
207
- When serialized:
208
- ```js
209
- {
210
- "firstName": "Harry",
211
- "lastName": "Houdini",
212
- "career": "magician"
213
- }
214
- ```
215
- Note that the `admin` is now not included in the payload.
216
- Setting `serialize` to `true` enforces serialization for hasMany
217
- relationships even if it's neither a many-to-many nor many-to-none
218
- relationship.
219
- @public
220
- */
221
- mergedProperties: ['attrs'],
222
- /**
223
- Given a subclass of `Model` and a JSON object this method will
224
- iterate through each attribute of the `Model` and invoke the
225
- `Transform#deserialize` method on the matching property of the
226
- JSON object. This method is typically called after the
227
- serializer's `normalize` method.
228
- @private
229
- */
230
- applyTransforms(typeClass, data) {
231
- const attributes = typeClass.attributes;
232
- typeClass.eachTransformedAttribute((key, type) => {
233
- if (data[key] === undefined) {
234
- return;
235
- }
236
- const transform = this.transformFor(type);
237
- const transformMeta = attributes.get(key);
238
- data[key] = transform.deserialize(data[key], transformMeta.options);
239
- });
240
- return data;
241
- },
242
- /**
243
- The `normalizeResponse` method is used to normalize a payload from the
244
- server to a JSON-API Document.
245
- http://jsonapi.org/format/#document-structure
246
- This method delegates to a more specific normalize method based on
247
- the `requestType`.
248
- To override this method with a custom one, make sure to call
249
- `return super.normalizeResponse(store, primaryModelClass, payload, id, requestType)` with your
250
- pre-processed data.
251
- Here's an example of using `normalizeResponse` manually:
252
- ```javascript
253
- socket.on('message', function(message) {
254
- let data = message.data;
255
- let modelClass = store.modelFor(data.modelName);
256
- let serializer = store.serializerFor(data.modelName);
257
- let normalized = serializer.normalizeSingleResponse(store, modelClass, data, data.id);
258
- store.push(normalized);
259
- });
260
- ```
261
- @since 1.13.0
262
- @public
263
- */
264
- normalizeResponse(store, primaryModelClass, payload, id, requestType) {
265
- switch (requestType) {
266
- case 'findRecord':
267
- // @ts-expect-error
268
- return this.normalizeFindRecordResponse(...arguments);
269
- case 'queryRecord':
270
- // @ts-expect-error
271
- return this.normalizeQueryRecordResponse(...arguments);
272
- case 'findAll':
273
- // @ts-expect-error
274
- return this.normalizeFindAllResponse(...arguments);
275
- case 'findBelongsTo':
276
- // @ts-expect-error
277
- return this.normalizeFindBelongsToResponse(...arguments);
278
- case 'findHasMany':
279
- // @ts-expect-error
280
- return this.normalizeFindHasManyResponse(...arguments);
281
- case 'findMany':
282
- // @ts-expect-error
283
- return this.normalizeFindManyResponse(...arguments);
284
- case 'query':
285
- // @ts-expect-error
286
- return this.normalizeQueryResponse(...arguments);
287
- case 'createRecord':
288
- // @ts-expect-error
289
- return this.normalizeCreateRecordResponse(...arguments);
290
- case 'deleteRecord':
291
- // @ts-expect-error
292
- return this.normalizeDeleteRecordResponse(...arguments);
293
- case 'updateRecord':
294
- // @ts-expect-error
295
- return this.normalizeUpdateRecordResponse(...arguments);
296
- }
297
- },
298
- /**
299
- Called by the default normalizeResponse implementation when the
300
- type of request is `findRecord`
301
- @since 1.13.0
302
- @public
303
- */
304
- normalizeFindRecordResponse(store, primaryModelClass, payload, id, requestType) {
305
- // @ts-expect-error
306
- return this.normalizeSingleResponse(...arguments);
307
- },
308
- /**
309
- Called by the default normalizeResponse implementation when the
310
- type of request is `queryRecord`
311
- @since 1.13.0
312
- @public
313
- */
314
- normalizeQueryRecordResponse(store, primaryModelClass, payload, id, requestType) {
315
- // @ts-expect-error
316
- return this.normalizeSingleResponse(...arguments);
317
- },
318
- /**
319
- Called by the default normalizeResponse implementation when the
320
- type of request is `findAll`
321
- @since 1.13.0
322
- @public
323
- */
324
- normalizeFindAllResponse(store, primaryModelClass, payload, id, requestType) {
325
- // @ts-expect-error
326
- return this.normalizeArrayResponse(...arguments);
327
- },
328
- /**
329
- Called by the default normalizeResponse implementation when the
330
- type of request is `findBelongsTo`
331
- @since 1.13.0
332
- @public
333
- */
334
- normalizeFindBelongsToResponse(store, primaryModelClass, payload, id, requestType) {
335
- // @ts-expect-error
336
- return this.normalizeSingleResponse(...arguments);
337
- },
338
- /**
339
- Called by the default normalizeResponse implementation when the
340
- type of request is `findHasMany`
341
- @since 1.13.0
342
- @public
343
- */
344
- normalizeFindHasManyResponse(store, primaryModelClass, payload, id, requestType) {
345
- // @ts-expect-error
346
- return this.normalizeArrayResponse(...arguments);
347
- },
348
- /**
349
- Called by the default normalizeResponse implementation when the
350
- type of request is `findMany`
351
- @since 1.13.0
352
- @public
353
- */
354
- normalizeFindManyResponse(store, primaryModelClass, payload, id, requestType) {
355
- // @ts-expect-error
356
- return this.normalizeArrayResponse(...arguments);
357
- },
358
- /**
359
- Called by the default normalizeResponse implementation when the
360
- type of request is `query`
361
- @since 1.13.0
362
- @public
363
- */
364
- normalizeQueryResponse(store, primaryModelClass, payload, id, requestType) {
365
- // @ts-expect-error
366
- return this.normalizeArrayResponse(...arguments);
367
- },
368
- /**
369
- Called by the default normalizeResponse implementation when the
370
- type of request is `createRecord`
371
- @since 1.13.0
372
- @public
373
- */
374
- normalizeCreateRecordResponse(store, primaryModelClass, payload, id, requestType) {
375
- // @ts-expect-error
376
- return this.normalizeSaveResponse(...arguments);
377
- },
378
- /**
379
- Called by the default normalizeResponse implementation when the
380
- type of request is `deleteRecord`
381
- @since 1.13.0
382
- @public
383
- */
384
- normalizeDeleteRecordResponse(store, primaryModelClass, payload, id, requestType) {
385
- // @ts-expect-error
386
- return this.normalizeSaveResponse(...arguments);
387
- },
388
- /**
389
- Called by the default normalizeResponse implementation when the
390
- type of request is `updateRecord`
391
- @since 1.13.0
392
- @public
393
- */
394
- normalizeUpdateRecordResponse(store, primaryModelClass, payload, id, requestType) {
395
- // @ts-expect-error
396
- return this.normalizeSaveResponse(...arguments);
397
- },
398
- /**
399
- normalizeUpdateRecordResponse, normalizeCreateRecordResponse and
400
- normalizeDeleteRecordResponse delegate to this method by default.
401
- @since 1.13.0
402
- @public
403
- */
404
- normalizeSaveResponse(store, primaryModelClass, payload, id, requestType) {
405
- // @ts-expect-error
406
- return this.normalizeSingleResponse(...arguments);
407
- },
408
- /**
409
- normalizeQueryResponse and normalizeFindRecordResponse delegate to this
410
- method by default.
411
- @since 1.13.0
412
- @public
413
- */
414
- normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
415
- return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, true);
416
- },
417
- /**
418
- normalizeQueryResponse, normalizeFindManyResponse, and normalizeFindHasManyResponse delegate
419
- to this method by default.
420
- @since 1.13.0
421
- @public
422
- */
423
- normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
424
- return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, false);
425
- },
426
- /**
427
- @private
428
- */
429
- _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
430
- const documentHash = {
431
- data: null,
432
- included: []
433
- };
434
- const meta = this.extractMeta(store, primaryModelClass, payload);
435
- if (meta) {
436
- // @ts-expect-error untyped
437
- documentHash.meta = meta;
438
- }
439
- if (isSingle) {
440
- // @ts-expect-error untyped
441
- const {
442
- data,
443
- included
444
- } = this.normalize(primaryModelClass, payload);
445
- documentHash.data = data;
446
- if (included) {
447
- documentHash.included = included;
448
- }
449
- } else {
450
- // @ts-expect-error untyped
451
- const ret = new Array(payload.length);
452
- // @ts-expect-error untyped
453
- for (let i = 0, l = payload.length; i < l; i++) {
454
- const item = payload[i];
455
- // @ts-expect-error untyped
456
- const {
457
- data,
458
- included
459
- } = this.normalize(primaryModelClass, item);
460
- if (included) {
461
- documentHash.included = documentHash.included.concat(included);
462
- }
463
- ret[i] = data;
464
- }
465
-
466
- // @ts-expect-error untyped
467
- documentHash.data = ret;
468
- }
469
- return documentHash;
470
- },
471
- /**
472
- Normalizes a part of the JSON payload returned by
473
- the server. You should override this method, munge the hash
474
- and call super if you have generic normalization to do.
475
- It takes the type of the record that is being normalized
476
- (as a Model class), the property where the hash was
477
- originally found, and the hash to normalize.
478
- You can use this method, for example, to normalize underscored keys to camelized
479
- or other general-purpose normalizations.
480
- Example
481
- ```js [app/serializers/application.js]
482
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
483
- import { underscore } from '<app-name>/utils/string-utils';
484
- import { get } from '@ember/object';
485
- export default class ApplicationSerializer extends JSONSerializer {
486
- normalize(typeClass, hash) {
487
- let fields = typeClass.fields;
488
- fields.forEach(function(type, field) {
489
- let payloadField = underscore(field);
490
- if (field === payloadField) { return; }
491
- hash[field] = hash[payloadField];
492
- delete hash[payloadField];
493
- });
494
- return super.normalize(...arguments);
495
- }
496
- }
497
- ```
498
- @public
499
- */
500
- normalize(modelClass, resourceHash) {
501
- let data = null;
502
- if (resourceHash) {
503
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash);
504
- // @ts-expect-error untyped
505
- if (typeof resourceHash.links === 'object') {
506
- // @ts-expect-error untyped
507
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash.links);
508
- }
509
-
510
- // @ts-expect-error untyped
511
- data = {
512
- id: this.extractId(modelClass, resourceHash),
513
- type: modelClass.modelName,
514
- attributes: this.extractAttributes(modelClass, resourceHash),
515
- relationships: this.extractRelationships(modelClass, resourceHash)
516
- };
517
-
518
- // @ts-expect-error untyped
519
- if (resourceHash.lid) {
520
- // @ts-expect-error untyped
521
- data.lid = resourceHash.lid;
522
- }
523
-
524
- // @ts-expect-error untyped
525
- this.applyTransforms(modelClass, data.attributes);
526
- }
527
- return {
528
- data
529
- };
530
- },
531
- /**
532
- Returns the resource's ID.
533
- @public
534
- */
535
- extractId(modelClass, resourceHash) {
536
- const primaryKey = this.primaryKey;
537
- const id = resourceHash[primaryKey];
538
- return coerceId(id);
539
- },
540
- /**
541
- Returns the resource's attributes formatted as a JSON-API "attributes object".
542
- http://jsonapi.org/format/#document-resource-object-attributes
543
- @public
544
- */
545
- extractAttributes(modelClass, resourceHash) {
546
- let attributeKey;
547
- const attributes = {};
548
- modelClass.eachAttribute(key => {
549
- attributeKey = this.keyForAttribute(key, 'deserialize');
550
- if (resourceHash[attributeKey] !== undefined) {
551
- attributes[key] = resourceHash[attributeKey];
552
- }
553
- });
554
- return attributes;
555
- },
556
- /**
557
- Returns a relationship formatted as a JSON-API "relationship object".
558
- http://jsonapi.org/format/#document-resource-object-relationships
559
- @public
560
- */
561
- extractRelationship(relationshipModelName, relationshipHash) {
562
- if (!relationshipHash) {
563
- return null;
564
- }
565
- /*
566
- When `relationshipHash` is an object it usually means that the relationship
567
- is polymorphic. It could however also be embedded resources that the
568
- EmbeddedRecordsMixin has be able to process.
569
- */
570
- if (relationshipHash && typeof relationshipHash === 'object' && !Array.isArray(relationshipHash)) {
571
- // @ts-expect-error untyped
572
- if (relationshipHash.id) {
573
- // @ts-expect-error untyped
574
- relationshipHash.id = coerceId(relationshipHash.id);
575
- }
576
-
577
- // @ts-expect-error store is dynamically injected
578
- const modelClass = this.store.modelFor(relationshipModelName);
579
- // @ts-expect-error untyped
580
- if (relationshipHash.type && !modelClass.fields.has('type')) {
581
- // @ts-expect-error untyped
582
- relationshipHash.type = this.modelNameFromPayloadKey(relationshipHash.type);
583
- }
584
- return relationshipHash;
585
- }
586
- return {
587
- id: coerceId(relationshipHash),
588
- type: dasherize(singularize(relationshipModelName))
589
- };
590
- },
591
- /**
592
- Returns a polymorphic relationship formatted as a JSON-API "relationship object".
593
- http://jsonapi.org/format/#document-resource-object-relationships
594
- `relationshipOptions` is a hash which contains more information about the
595
- polymorphic relationship which should be extracted:
596
- - `resourceHash` complete hash of the resource the relationship should be
597
- extracted from
598
- - `relationshipKey` key under which the value for the relationship is
599
- extracted from the resourceHash
600
- - `relationshipMeta` meta information about the relationship
601
- @public
602
- */
603
- extractPolymorphicRelationship(relationshipModelName, relationshipHash, relationshipOptions) {
604
- return this.extractRelationship(relationshipModelName, relationshipHash);
605
- },
606
- /**
607
- Returns the resource's relationships formatted as a JSON-API "relationships object".
608
- http://jsonapi.org/format/#document-resource-object-relationships
609
- @public
610
- */
611
- extractRelationships(modelClass, resourceHash) {
612
- const relationships = {};
613
- modelClass.eachRelationship((key, relationshipMeta) => {
614
- let relationship = null;
615
- const relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
616
- if (resourceHash[relationshipKey] !== undefined) {
617
- let data = null;
618
- const relationshipHash = resourceHash[relationshipKey];
619
- if (relationshipMeta.kind === 'belongsTo') {
620
- if (relationshipMeta.options.polymorphic) {
621
- // extracting a polymorphic belongsTo may need more information
622
- // than the type and the hash (which might only be an id) for the
623
- // relationship, hence we pass the key, resource and
624
- // relationshipMeta too
625
- // @ts-expect-error untyped
626
- data = this.extractPolymorphicRelationship(relationshipMeta.type, relationshipHash, {
627
- key,
628
- resourceHash,
629
- relationshipMeta
630
- });
631
- } else {
632
- // @ts-expect-error untyped
633
- data = this.extractRelationship(relationshipMeta.type, relationshipHash);
634
- }
635
- } else if (relationshipMeta.kind === 'hasMany') {
636
- if (relationshipHash) {
637
- // @ts-expect-error untyped
638
- data = new Array(relationshipHash.length);
639
- if (relationshipMeta.options.polymorphic) {
640
- for (let i = 0, l = relationshipHash.length; i < l; i++) {
641
- const item = relationshipHash[i];
642
- // @ts-expect-error untyped
643
- data[i] = this.extractPolymorphicRelationship(relationshipMeta.type, item, {
644
- key,
645
- resourceHash,
646
- relationshipMeta
647
- });
648
- }
649
- } else {
650
- for (let i = 0, l = relationshipHash.length; i < l; i++) {
651
- const item = relationshipHash[i];
652
- // @ts-expect-error untyped
653
- data[i] = this.extractRelationship(relationshipMeta.type, item);
654
- }
655
- }
656
- }
657
- }
658
- // @ts-expect-error untyped
659
- relationship = {
660
- data
661
- };
662
- }
663
- const linkKey = this.keyForLink(key, relationshipMeta.kind);
664
- // @ts-expect-error untyped
665
- if (resourceHash.links && resourceHash.links[linkKey] !== undefined) {
666
- // @ts-expect-error untyped
667
- const related = resourceHash.links[linkKey];
668
- // @ts-expect-error untyped
669
- relationship = relationship || {};
670
- // @ts-expect-error untyped
671
- relationship.links = {
672
- related
673
- };
674
- }
675
- if (relationship) {
676
- relationships[key] = relationship;
677
- }
678
- });
679
- return relationships;
680
- },
681
- /**
682
- Dasherizes the model name in the payload
683
- @public
684
- @return the model's modelName
685
- */
686
- modelNameFromPayloadKey(key) {
687
- return dasherize(singularize(key));
688
- },
689
- /**
690
- @private
691
- */
692
- normalizeRelationships(typeClass, hash) {
693
- let payloadKey;
694
- if (this.keyForRelationship) {
695
- typeClass.eachRelationship((key, relationship) => {
696
- payloadKey = this.keyForRelationship(key, relationship.kind, 'deserialize');
697
- if (key === payloadKey) {
698
- return;
699
- }
700
- if (hash[payloadKey] === undefined) {
701
- return;
702
- }
703
- hash[key] = hash[payloadKey];
704
- delete hash[payloadKey];
705
- });
706
- }
707
- },
708
- /**
709
- @private
710
- */
711
- normalizeUsingDeclaredMapping(modelClass, hash) {
712
- // @ts-expect-error attrs is dynamically injected
713
- const attrs = this.attrs;
714
- let normalizedKey;
715
- let payloadKey;
716
- if (attrs) {
717
- for (const key in attrs) {
718
- normalizedKey = payloadKey = this._getMappedKey(key, modelClass);
719
- if (hash[payloadKey] === undefined) {
720
- continue;
721
- }
722
- if (modelClass.attributes.has(key)) {
723
- normalizedKey = this.keyForAttribute(key, 'deserialize');
724
- }
725
- if (modelClass.relationshipsByName.has(key)) {
726
- normalizedKey = this.keyForRelationship(key, modelClass, 'deserialize');
727
- }
728
- if (payloadKey !== normalizedKey) {
729
- hash[normalizedKey] = hash[payloadKey];
730
- delete hash[payloadKey];
731
- }
732
- }
733
- }
734
- },
735
- /**
736
- Looks up the property key that was set by the custom `attr` mapping
737
- passed to the serializer.
738
- @private
739
- */
740
- _getMappedKey(key, modelClass) {
741
- const attrs = this.attrs;
742
- let mappedKey;
743
- if (attrs && attrs[key]) {
744
- mappedKey = attrs[key];
745
- //We need to account for both the { title: 'post_title' } and
746
- //{ title: { key: 'post_title' }} forms
747
- if (mappedKey.key) {
748
- mappedKey = mappedKey.key;
749
- }
750
- if (typeof mappedKey === 'string') {
751
- key = mappedKey;
752
- }
753
- }
754
- return key;
755
- },
756
- /**
757
- Check attrs.key.serialize property to inform if the `key`
758
- can be serialized
759
- @private
760
- @return true if the key can be serialized
761
- */
762
- _canSerialize(key) {
763
- // @ts-expect-error no idea what attrs is here
764
- const attrs = this.attrs;
765
- return !attrs || !attrs[key] || attrs[key].serialize !== false;
766
- },
767
- /**
768
- When attrs.key.serialize is set to true then
769
- it takes priority over the other checks and the related
770
- attribute/relationship will be serialized
771
- @private
772
- @return true if the key must be serialized
773
- */
774
- _mustSerialize(key) {
775
- // @ts-expect-error no idea what attrs is here
776
- const attrs = this.attrs;
777
- return attrs && attrs[key] && attrs[key].serialize === true;
778
- },
779
- /**
780
- Check if the given hasMany relationship should be serialized
781
- By default only many-to-many and many-to-none relationships are serialized.
782
- This could be configured per relationship by Serializer's `attrs` object.
783
- @public
784
- @return true if the hasMany relationship should be serialized
785
- */
786
- shouldSerializeHasMany(snapshot, key, relationship) {
787
- // @ts-expect-error store is dynamically injected
788
- const relationshipType = determineRelationshipType(this.store, snapshot.modelName, relationship);
789
- if (this._mustSerialize(key)) {
790
- return true;
791
- }
792
- return this._canSerialize(key) && (relationshipType === 'manyToNone' || relationshipType === 'manyToMany');
793
- },
794
- // SERIALIZE
795
- /**
796
- Called when a record is saved in order to convert the
797
- record into JSON.
798
- By default, it creates a JSON object with a key for
799
- each attribute and belongsTo relationship.
800
- For example, consider this model:
801
- ```js [app/models/comment.js]
802
- import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
803
- export default class CommentModel extends Model {
804
- @attr title;
805
- @attr body;
806
- @belongsTo('user') author;
807
- }
808
- ```
809
- The default serialization would create a JSON object like:
810
- ```javascript
811
- {
812
- "title": "Rails is unagi",
813
- "body": "Rails? Omakase? O_O",
814
- "author": 12
815
- }
816
- ```
817
- By default, attributes are passed through as-is, unless
818
- you specified an attribute type (`attr('date')`). If
819
- you specify a transform, the JavaScript value will be
820
- serialized when inserted into the JSON hash.
821
- By default, belongs-to relationships are converted into
822
- IDs when inserted into the JSON hash.
823
- ## IDs
824
- `serialize` takes an options hash with a single option:
825
- `includeId`. If this option is `true`, `serialize` will,
826
- by default include the ID in the JSON object it builds.
827
- Whether `includeId` is `true` or `false` depends on the
828
- adapter and the operation being performed, since it is the
829
- adapter that invokes `serialize` and decides which options
830
- to pass. For instance, `RESTAdapter` passes `includeId: true`
831
- when serializing a record for `createRecord`, but not for
832
- `updateRecord`, while `JSONAPIAdapter` passes `includeId: true`
833
- for both `createRecord` and `updateRecord`. Refer to the
834
- documentation for the adapter and serializer pairing you are
835
- using for specifics.
836
- ## Customization
837
- Your server may expect a different JSON format than the
838
- built-in serialization format.
839
- In that case, you can implement `serialize` yourself and
840
- return a JSON hash of your choosing.
841
- ```js [app/serializers/post.js]
842
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
843
- export default class PostSerializer extends JSONSerializer {
844
- serialize(snapshot, options) {
845
- let json = {
846
- POST_TTL: snapshot.attr('title'),
847
- POST_BDY: snapshot.attr('body'),
848
- POST_CMS: snapshot.hasMany('comments', { ids: true })
849
- };
850
- if (options.includeId) {
851
- json.POST_ID_ = snapshot.id;
852
- }
853
- return json;
854
- }
855
- }
856
- ```
857
- ## Customizing an App-Wide Serializer
858
- If you want to define a serializer for your entire
859
- application, you'll probably want to use `eachAttribute`
860
- and `eachRelationship` on the record.
861
- ```js [app/serializers/application.js]
862
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
863
- import { singularize } from '<app-name>/utils/string-utils';
864
- export default class ApplicationSerializer extends JSONSerializer {
865
- serialize(snapshot, options) {
866
- let json = {};
867
- snapshot.eachAttribute((name) => {
868
- json[serverAttributeName(name)] = snapshot.attr(name);
869
- });
870
- snapshot.eachRelationship((name, relationship) => {
871
- if (relationship.kind === 'hasMany') {
872
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
873
- }
874
- });
875
- if (options.includeId) {
876
- json.ID_ = snapshot.id;
877
- }
878
- return json;
879
- }
880
- }
881
- function serverAttributeName(attribute) {
882
- return attribute.underscore().toUpperCase();
883
- }
884
- function serverHasManyName(name) {
885
- return serverAttributeName(singularize(name)) + "_IDS";
886
- }
887
- ```
888
- This serializer will generate JSON that looks like this:
889
- ```javascript
890
- {
891
- "TITLE": "Rails is omakase",
892
- "BODY": "Yep. Omakase.",
893
- "COMMENT_IDS": [ "1", "2", "3" ]
894
- }
895
- ```
896
- ## Tweaking the Default JSON
897
- If you just want to do some small tweaks on the default JSON,
898
- you can call `super.serialize` first and make the tweaks on
899
- the returned JSON.
900
- ```js [app/serializers/post.js]
901
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
902
- export default class PostSerializer extends JSONSerializer {
903
- serialize(snapshot, options) {
904
- let json = super.serialize(...arguments);
905
- json.subject = json.title;
906
- delete json.title;
907
- return json;
908
- }
909
- }
910
- ```
911
- @public
912
- */
913
- serialize(snapshot, options) {
914
- const json = {};
915
-
916
- // @ts-expect-error super loose typing here right now
917
- if (options && options.includeId) {
918
- const id = snapshot.id;
919
- if (id) {
920
- json[this.primaryKey] = id;
921
- }
922
- }
923
- snapshot.eachAttribute((key, attribute) => {
924
- this.serializeAttribute(snapshot, json, key, attribute);
925
- });
926
- snapshot.eachRelationship((key, relationship) => {
927
- if (relationship.kind === 'belongsTo') {
928
- this.serializeBelongsTo(snapshot, json, relationship);
929
- } else if (relationship.kind === 'hasMany') {
930
- this.serializeHasMany(snapshot, json, relationship);
931
- }
932
- });
933
- return json;
934
- },
935
- /**
936
- You can use this method to customize how a serialized record is added to the complete
937
- JSON hash to be sent to the server. By default the JSON Serializer does not namespace
938
- the payload and just sends the raw serialized JSON object.
939
- If your server expects namespaced keys, you should consider using the RESTSerializer.
940
- Otherwise you can override this method to customize how the record is added to the hash.
941
- The hash property should be modified by reference.
942
- For example, your server may expect underscored root objects.
943
- ```js [app/serializers/application.js]
944
- import RESTSerializer from '@warp-drive/legacy/serializer/rest';
945
- import { underscoren} from '<app-name>/utils/string-utils';
946
- export default class ApplicationSerializer extends RESTSerializer {
947
- serializeIntoHash(data, type, snapshot, options) {
948
- let root = underscore(type.modelName);
949
- data[root] = this.serialize(snapshot, options);
950
- }
951
- }
952
- ```
953
- @public
954
- */
955
- serializeIntoHash(hash, typeClass, snapshot, options) {
956
- Object.assign(hash, this.serialize(snapshot, options));
957
- },
958
- /**
959
- `serializeAttribute` can be used to customize how `attr`
960
- properties are serialized
961
- For example if you wanted to ensure all your attributes were always
962
- serialized as properties on an `attributes` object you could
963
- write:
964
- ```js [app/serializers/application.js]
965
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
966
- export default class ApplicationSerializer extends JSONSerializer {
967
- serializeAttribute(snapshot, json, key, attributes) {
968
- json.attributes = json.attributes || {};
969
- super.serializeAttribute(snapshot, json.attributes, key, attributes);
970
- }
971
- }
972
- ```
973
- @public
974
- */
975
- serializeAttribute(snapshot, json, key, attribute) {
976
- if (this._canSerialize(key)) {
977
- const type = attribute.type;
978
- // @ts-expect-error we don't know what is on the snapshot
979
- let value = snapshot.attr(key);
980
- if (type) {
981
- const transform = this.transformFor(type);
982
- value = transform.serialize(value, attribute.options);
983
- }
984
-
985
- // if provided, use the mapping provided by `attrs` in
986
- // the serializer
987
- // @ts-expect-error store added dynamically
988
- const schema = this.store.modelFor(snapshot.modelName);
989
- let payloadKey = this._getMappedKey(key, schema);
990
- if (payloadKey === key && this.keyForAttribute) {
991
- payloadKey = this.keyForAttribute(key, 'serialize');
992
- }
993
- json[payloadKey] = value;
994
- }
995
- },
996
- /**
997
- `serializeBelongsTo` can be used to customize how `belongsTo`
998
- properties are serialized.
999
- Example
1000
- ```js [app/serializers/post.js]
1001
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1002
- export default class PostSerializer extends JSONSerializer {
1003
- serializeBelongsTo(snapshot, json, relationship) {
1004
- let key = relationship.name;
1005
- let belongsTo = snapshot.belongsTo(key);
1006
- key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;
1007
- json[key] = !belongsTo ? null : belongsTo.record.toJSON();
1008
- }
1009
- }
1010
- ```
1011
- @public
1012
- */
1013
- serializeBelongsTo(snapshot, json, relationship) {
1014
- const name = relationship.name;
1015
- if (this._canSerialize(name)) {
1016
- const belongsToId = snapshot.belongsTo(name, {
1017
- id: true
1018
- });
1019
-
1020
- // if provided, use the mapping provided by `attrs` in
1021
- // the serializer
1022
- // @ts-expect-error store added dynamically
1023
- const schema = this.store.modelFor(snapshot.modelName);
1024
- let payloadKey = this._getMappedKey(name, schema);
1025
- if (payloadKey === name && this.keyForRelationship) {
1026
- payloadKey = this.keyForRelationship(name, 'belongsTo', 'serialize');
1027
- }
1028
-
1029
- //Need to check whether the id is there for new&async records
1030
- if (!belongsToId) {
1031
- json[payloadKey] = null;
1032
- } else {
1033
- json[payloadKey] = belongsToId;
1034
- }
1035
- if (relationship.options.polymorphic) {
1036
- this.serializePolymorphicType(snapshot, json, relationship);
1037
- }
1038
- }
1039
- },
1040
- /**
1041
- `serializeHasMany` can be used to customize how `hasMany`
1042
- properties are serialized.
1043
- Example
1044
- ```js [app/serializers/post.js]
1045
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1046
- export default class PostSerializer extends JSONSerializer {
1047
- serializeHasMany(snapshot, json, relationship) {
1048
- let key = relationship.name;
1049
- if (key === 'comments') {
1050
- return;
1051
- } else {
1052
- super.serializeHasMany(...arguments);
1053
- }
1054
- }
1055
- }
1056
- ```
1057
- @public
1058
- */
1059
- serializeHasMany(snapshot, json, relationship) {
1060
- const name = relationship.name;
1061
- if (this.shouldSerializeHasMany(snapshot, name, relationship)) {
1062
- const hasMany = snapshot.hasMany(name, {
1063
- ids: true
1064
- });
1065
- if (hasMany !== undefined) {
1066
- // if provided, use the mapping provided by `attrs` in
1067
- // the serializer
1068
- // @ts-expect-error store added dynamically
1069
- const schema = this.store.modelFor(snapshot.modelName);
1070
- let payloadKey = this._getMappedKey(name, schema);
1071
- if (payloadKey === name && this.keyForRelationship) {
1072
- payloadKey = this.keyForRelationship(name, 'hasMany', 'serialize');
1073
- }
1074
- json[payloadKey] = hasMany;
1075
- // TODO support for polymorphic manyToNone and manyToMany relationships
1076
- }
1077
- }
1078
- },
1079
- /**
1080
- You can use this method to customize how polymorphic objects are
1081
- serialized. Objects are considered to be polymorphic if
1082
- `{ polymorphic: true }` is pass as the second argument to the
1083
- `belongsTo` function.
1084
- Example
1085
- ```js [app/serializers/comment.js]
1086
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1087
- export default class CommentSerializer extends JSONSerializer {
1088
- serializePolymorphicType(snapshot, json, relationship) {
1089
- let key = relationship.name;
1090
- let belongsTo = snapshot.belongsTo(key);
1091
- key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;
1092
- if (!belongsTo) {
1093
- json[key + '_type'] = null;
1094
- } else {
1095
- json[key + '_type'] = belongsTo.modelName;
1096
- }
1097
- }
1098
- }
1099
- ```
1100
- @public
1101
- */
1102
- serializePolymorphicType(snapshot, json, relationship) {},
1103
- /**
1104
- `extractMeta` is used to deserialize any meta information in the
1105
- adapter payload. By default Ember Data expects meta information to
1106
- be located on the `meta` property of the payload object.
1107
- Example
1108
- ```js [app/serializers/post.js]
1109
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1110
- export default class PostSerializer extends JSONSerializer {
1111
- extractMeta(store, typeClass, payload) {
1112
- if (payload && payload.hasOwnProperty('_pagination')) {
1113
- let meta = payload._pagination;
1114
- delete payload._pagination;
1115
- return meta;
1116
- }
1117
- }
1118
- }
1119
- ```
1120
- @public
1121
- */
1122
- extractMeta(store, modelClass, payload) {
1123
- if (payload && payload['meta'] !== undefined) {
1124
- // @ts-expect-error
1125
- const meta = payload.meta;
1126
- // @ts-expect-error
1127
- delete payload.meta;
1128
- return meta;
1129
- }
1130
- },
1131
- /**
1132
- `extractErrors` is used to extract model errors when a call
1133
- to `Model#save` fails with an `InvalidError`. By default
1134
- Ember Data expects error information to be located on the `errors`
1135
- property of the payload object.
1136
- This serializer expects this `errors` object to be an Array similar
1137
- to the following, compliant with the https://jsonapi.org/format/#errors specification:
1138
- ```js
1139
- {
1140
- "errors": [
1141
- {
1142
- "detail": "This username is already taken!",
1143
- "source": {
1144
- "pointer": "data/attributes/username"
1145
- }
1146
- }, {
1147
- "detail": "Doesn't look like a valid email.",
1148
- "source": {
1149
- "pointer": "data/attributes/email"
1150
- }
1151
- }
1152
- ]
1153
- }
1154
- ```
1155
- The key `detail` provides a textual description of the problem.
1156
- Alternatively, the key `title` can be used for the same purpose.
1157
- The nested keys `source.pointer` detail which specific element
1158
- of the request data was invalid.
1159
- Note that JSON-API also allows for object-level errors to be placed
1160
- in an object with pointer `data`, signifying that the problem
1161
- cannot be traced to a specific attribute:
1162
- ```javascript
1163
- {
1164
- "errors": [
1165
- {
1166
- "detail": "Some generic non property error message",
1167
- "source": {
1168
- "pointer": "data"
1169
- }
1170
- }
1171
- ]
1172
- }
1173
- ```
1174
- When turn into a `Errors` object, you can read these errors
1175
- through the property `base`:
1176
- ```handlebars
1177
- {{#each @model.errors.base as |error|}}
1178
- <div class="error">
1179
- {{error.message}}
1180
- </div>
1181
- {{/each}}
1182
- ```
1183
- Example of alternative implementation, overriding the default
1184
- behavior to deal with a different format of errors:
1185
- ```js [app/serializers/post.js]
1186
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1187
- export default class PostSerializer extends JSONSerializer {
1188
- extractErrors(store, typeClass, payload, id) {
1189
- if (payload && typeof payload === 'object' && payload._problems) {
1190
- payload = payload._problems;
1191
- this.normalizeErrors(typeClass, payload);
1192
- }
1193
- return payload;
1194
- }
1195
- }
1196
- ```
1197
- @public
1198
- @return json The deserialized errors
1199
- */
1200
- extractErrors(store, typeClass, payload, id) {
1201
- // @ts-expect-error
1202
- if (payload && typeof payload === 'object' && payload.errors) {
1203
- // the default assumption is that errors is already in JSON:API format
1204
- const extracted = {};
1205
-
1206
- // @ts-expect-error
1207
- payload.errors.forEach(error => {
1208
- if (error.source && error.source.pointer) {
1209
- let key = error.source.pointer.match(SOURCE_POINTER_REGEXP);
1210
- if (key) {
1211
- key = key[2];
1212
- } else if (error.source.pointer.search(SOURCE_POINTER_PRIMARY_REGEXP) !== -1) {
1213
- key = PRIMARY_ATTRIBUTE_KEY;
1214
- }
1215
- if (key) {
1216
- extracted[key] = extracted[key] || [];
1217
- extracted[key].push(error.detail || error.title);
1218
- }
1219
- }
1220
- });
1221
-
1222
- // if the user has an attrs hash, convert keys using it
1223
- this.normalizeUsingDeclaredMapping(typeClass, extracted);
1224
-
1225
- // for each attr and relationship, make sure that we use
1226
- // the normalized key
1227
- typeClass.eachAttribute(name => {
1228
- const key = this.keyForAttribute(name, 'deserialize');
1229
- if (key !== name && extracted[key] !== undefined) {
1230
- extracted[name] = extracted[key];
1231
- delete extracted[key];
1232
- }
1233
- });
1234
- typeClass.eachRelationship(name => {
1235
- const key = this.keyForRelationship(name, 'deserialize');
1236
- if (key !== name && extracted[key] !== undefined) {
1237
- extracted[name] = extracted[key];
1238
- delete extracted[key];
1239
- }
1240
- });
1241
- return extracted;
1242
- }
1243
- return payload;
1244
- },
1245
- /**
1246
- `keyForAttribute` can be used to define rules for how to convert an
1247
- attribute name in your model to a key in your JSON.
1248
- Example
1249
- ```js [app/serializers/application.js]
1250
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1251
- import { underscore } from '<app-name>/utils/string-utils';
1252
- export default class ApplicationSerializer extends JSONSerializer {
1253
- keyForAttribute(attr, method) {
1254
- return underscore(attr).toUpperCase();
1255
- }
1256
- }
1257
- ```
1258
- @public
1259
- */
1260
- keyForAttribute(key, method) {
1261
- return key;
1262
- },
1263
- /**
1264
- `keyForRelationship` can be used to define a custom key when
1265
- serializing and deserializing relationship properties. By default
1266
- `JSONSerializer` does not provide an implementation of this method.
1267
- Example
1268
- ```js [app/serializers/post.js]
1269
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1270
- import { underscore } from '<app-name>/utils/string-utils';
1271
- export default class PostSerializer extends JSONSerializer {
1272
- keyForRelationship(key, relationship, method) {
1273
- return `rel_${underscore(key)}`;
1274
- }
1275
- }
1276
- ```
1277
- @public
1278
- */
1279
- keyForRelationship(key, typeClass, method) {
1280
- return key;
1281
- },
1282
- /**
1283
- `keyForLink` can be used to define a custom key when deserializing link
1284
- properties.
1285
- @public
1286
- */
1287
- keyForLink(key, kind) {
1288
- return key;
1289
- },
1290
- // HELPERS
1291
-
1292
- /**
1293
- @private
1294
- */
1295
- transformFor(attributeType, skipAssertion) {
1296
- const transform = getOwner(this).lookup(`transform:${attributeType}`);
1297
- return transform;
1298
- }
1299
- });
1300
- export { JSONSerializer as J, coerceId as c, inverseForRelationship as i };