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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (467) hide show
  1. package/dist/-private-DQ6Iap2t.js +193 -0
  2. package/dist/-private-DQ6Iap2t.js.map +1 -0
  3. package/dist/-private-DccRZQsm.js +904 -0
  4. package/dist/-private-DccRZQsm.js.map +1 -0
  5. package/dist/adapter/-private.d.ts +33 -0
  6. package/dist/adapter/-private.d.ts.map +1 -0
  7. package/dist/adapter/-private.js +3 -1
  8. package/dist/adapter/error.d.ts +2 -0
  9. package/dist/adapter/error.js +422 -453
  10. package/dist/adapter/error.js.map +1 -0
  11. package/{declarations → dist}/adapter/json-api.d.ts +30 -29
  12. package/dist/adapter/json-api.d.ts.map +1 -0
  13. package/dist/adapter/json-api.js +265 -143
  14. package/dist/adapter/json-api.js.map +1 -0
  15. package/dist/adapter/rest.d.ts +2 -0
  16. package/dist/adapter/rest.js +937 -1136
  17. package/dist/adapter/rest.js.map +1 -0
  18. package/dist/adapter-CARrK3-8.d.ts +784 -0
  19. package/dist/adapter-CARrK3-8.d.ts.map +1 -0
  20. package/dist/adapter-XgLAkYVs.js +1130 -0
  21. package/dist/adapter-XgLAkYVs.js.map +1 -0
  22. package/dist/adapter.d.ts +2 -0
  23. package/dist/adapter.js +1 -1248
  24. package/dist/compat/-private.d.ts +2 -0
  25. package/dist/compat/-private.js +3 -1
  26. package/dist/compat/builders.d.ts +169 -0
  27. package/dist/compat/builders.d.ts.map +1 -0
  28. package/dist/compat/builders.js +205 -245
  29. package/dist/compat/builders.js.map +1 -0
  30. package/dist/compat/extensions.d.ts +2 -0
  31. package/dist/compat/extensions.js +265 -304
  32. package/dist/compat/extensions.js.map +1 -0
  33. package/dist/compat/utils.d.ts +151 -0
  34. package/dist/compat/utils.d.ts.map +1 -0
  35. package/dist/compat/utils.js +187 -206
  36. package/dist/compat/utils.js.map +1 -0
  37. package/dist/compat-BbNNmTM-.d.ts +1386 -0
  38. package/dist/compat-BbNNmTM-.d.ts.map +1 -0
  39. package/dist/compat-g__Pfy2S.js +734 -0
  40. package/dist/compat-g__Pfy2S.js.map +1 -0
  41. package/dist/compat.d.ts +2 -0
  42. package/dist/compat.js +1 -1036
  43. package/dist/error-CzkyXr1Q.d.ts +435 -0
  44. package/dist/error-CzkyXr1Q.d.ts.map +1 -0
  45. package/dist/errors-LQhmDVdd.js +2134 -0
  46. package/dist/errors-LQhmDVdd.js.map +1 -0
  47. package/dist/extensions-DumNm4dA.d.ts +102 -0
  48. package/dist/extensions-DumNm4dA.d.ts.map +1 -0
  49. package/dist/index.d.ts +243 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +267 -339
  52. package/dist/index.js.map +1 -0
  53. package/dist/json-BXNPTlcH.js +1106 -0
  54. package/dist/json-BXNPTlcH.js.map +1 -0
  55. package/dist/model/-private.d.ts +3 -0
  56. package/dist/model/-private.js +3 -1
  57. package/dist/model/migration-support.d.ts +335 -0
  58. package/dist/model/migration-support.d.ts.map +1 -0
  59. package/dist/model/migration-support.js +504 -575
  60. package/dist/model/migration-support.js.map +1 -0
  61. package/dist/model-62hn5_PD.d.ts +3107 -0
  62. package/dist/model-62hn5_PD.d.ts.map +1 -0
  63. package/dist/model-BtIEHqYZ.js +683 -0
  64. package/dist/model-BtIEHqYZ.js.map +1 -0
  65. package/dist/model-fragments-Dpn9285r.js +334 -0
  66. package/dist/model-fragments-Dpn9285r.js.map +1 -0
  67. package/dist/model-fragments.d.ts +294 -0
  68. package/dist/model-fragments.d.ts.map +1 -0
  69. package/dist/model-fragments.js +2 -94
  70. package/dist/model.d.ts +404 -0
  71. package/dist/model.d.ts.map +1 -0
  72. package/dist/model.js +3 -670
  73. package/{declarations/adapter/rest.d.ts → dist/rest-0NhtexIq.d.ts} +183 -173
  74. package/dist/rest-0NhtexIq.d.ts.map +1 -0
  75. package/dist/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  76. package/dist/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  77. package/dist/schema-provider-DsKuB5Wb.js +1929 -0
  78. package/dist/schema-provider-DsKuB5Wb.js.map +1 -0
  79. package/{declarations → dist}/serializer/json-api.d.ts +3 -0
  80. package/dist/serializer/json-api.d.ts.map +1 -0
  81. package/dist/serializer/json-api.js +527 -519
  82. package/dist/serializer/json-api.js.map +1 -0
  83. package/{declarations → dist}/serializer/json.d.ts +3 -0
  84. package/dist/serializer/json.d.ts.map +1 -0
  85. package/dist/serializer/json.js +3 -6
  86. package/{declarations/serializer/-private/embedded-records-mixin.d.ts → dist/serializer/rest.d.ts} +56 -1
  87. package/dist/serializer/rest.d.ts.map +1 -0
  88. package/dist/serializer/rest.js +958 -1199
  89. package/dist/serializer/rest.js.map +1 -0
  90. package/dist/serializer/transform.d.ts +313 -0
  91. package/dist/serializer/transform.d.ts.map +1 -0
  92. package/dist/serializer/transform.js +283 -308
  93. package/dist/serializer/transform.js.map +1 -0
  94. package/dist/serializer.d.ts +151 -0
  95. package/dist/serializer.d.ts.map +1 -0
  96. package/dist/serializer.js +205 -205
  97. package/dist/serializer.js.map +1 -0
  98. package/dist/store-C4qYzXei.js +473 -0
  99. package/dist/store-C4qYzXei.js.map +1 -0
  100. package/dist/store.d.ts +13 -0
  101. package/dist/store.d.ts.map +1 -0
  102. package/dist/store.js +1 -641
  103. package/dist/unpkg/dev/-private-CrEyBE-B.js +189 -0
  104. package/dist/unpkg/dev/-private-CrEyBE-B.js.map +1 -0
  105. package/dist/unpkg/dev/-private-vOhxVExH.js +896 -0
  106. package/dist/unpkg/dev/-private-vOhxVExH.js.map +1 -0
  107. package/dist/unpkg/dev/adapter/-private.js +3 -1
  108. package/dist/unpkg/dev/adapter/error.js +421 -452
  109. package/dist/unpkg/dev/adapter/error.js.map +1 -0
  110. package/dist/unpkg/dev/adapter/json-api.js +239 -257
  111. package/dist/unpkg/dev/adapter/json-api.js.map +1 -0
  112. package/dist/unpkg/dev/adapter/rest.js +935 -1134
  113. package/dist/unpkg/dev/adapter/rest.js.map +1 -0
  114. package/dist/unpkg/dev/adapter-Cw0uSl8d.js +1129 -0
  115. package/dist/unpkg/dev/adapter-Cw0uSl8d.js.map +1 -0
  116. package/dist/unpkg/dev/adapter.js +1 -1247
  117. package/dist/unpkg/dev/compat/-private.js +3 -1
  118. package/dist/unpkg/dev/compat/builders.js +204 -247
  119. package/dist/unpkg/dev/compat/builders.js.map +1 -0
  120. package/dist/unpkg/dev/compat/extensions.js +264 -303
  121. package/dist/unpkg/dev/compat/extensions.js.map +1 -0
  122. package/dist/unpkg/dev/compat/utils.js +186 -205
  123. package/dist/unpkg/dev/compat/utils.js.map +1 -0
  124. package/dist/unpkg/dev/compat-CeyxXB7K.js +825 -0
  125. package/dist/unpkg/dev/compat-CeyxXB7K.js.map +1 -0
  126. package/dist/unpkg/dev/compat.js +1 -1178
  127. package/dist/unpkg/dev/errors-1javxsPo.js +2127 -0
  128. package/dist/unpkg/dev/errors-1javxsPo.js.map +1 -0
  129. package/dist/unpkg/dev/index.js +266 -344
  130. package/dist/unpkg/dev/index.js.map +1 -0
  131. package/dist/unpkg/dev/json-DDJji3V3.js +1104 -0
  132. package/dist/unpkg/dev/json-DDJji3V3.js.map +1 -0
  133. package/dist/unpkg/dev/model/-private.js +3 -1
  134. package/dist/unpkg/dev/model/migration-support.js +481 -549
  135. package/dist/unpkg/dev/model/migration-support.js.map +1 -0
  136. package/dist/unpkg/dev/model-C9Xb1R1x.js +655 -0
  137. package/dist/unpkg/dev/model-C9Xb1R1x.js.map +1 -0
  138. package/dist/unpkg/dev/model-fragments-Dpn9285r.js +334 -0
  139. package/dist/unpkg/dev/model-fragments-Dpn9285r.js.map +1 -0
  140. package/dist/unpkg/dev/model-fragments.js +2 -94
  141. package/dist/unpkg/dev/model.js +3 -681
  142. package/dist/unpkg/dev/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  143. package/dist/unpkg/dev/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  144. package/dist/unpkg/dev/schema-provider-Dy6c1J5f.js +1834 -0
  145. package/dist/unpkg/dev/schema-provider-Dy6c1J5f.js.map +1 -0
  146. package/dist/unpkg/dev/serializer/json-api.js +514 -634
  147. package/dist/unpkg/dev/serializer/json-api.js.map +1 -0
  148. package/dist/unpkg/dev/serializer/json.js +3 -4
  149. package/dist/unpkg/dev/serializer/rest.js +954 -1196
  150. package/dist/unpkg/dev/serializer/rest.js.map +1 -0
  151. package/dist/unpkg/dev/serializer/transform.js +283 -308
  152. package/dist/unpkg/dev/serializer/transform.js.map +1 -0
  153. package/dist/unpkg/dev/serializer.js +205 -205
  154. package/dist/unpkg/dev/serializer.js.map +1 -0
  155. package/dist/unpkg/dev/store-D_V8-HQl.js +472 -0
  156. package/dist/unpkg/dev/store-D_V8-HQl.js.map +1 -0
  157. package/dist/unpkg/dev/store.js +1 -649
  158. package/dist/unpkg/dev/util-dSKEgQDp.js +12 -0
  159. package/dist/unpkg/dev/util-dSKEgQDp.js.map +1 -0
  160. package/dist/unpkg/dev/utils-DYC9utVJ.js +11 -0
  161. package/dist/unpkg/dev/utils-DYC9utVJ.js.map +1 -0
  162. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js +189 -0
  163. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js.map +1 -0
  164. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js +896 -0
  165. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js.map +1 -0
  166. package/dist/unpkg/dev-deprecated/adapter/-private.js +3 -1
  167. package/dist/unpkg/dev-deprecated/adapter/error.js +421 -452
  168. package/dist/unpkg/dev-deprecated/adapter/error.js.map +1 -0
  169. package/dist/unpkg/dev-deprecated/adapter/json-api.js +239 -257
  170. package/dist/unpkg/dev-deprecated/adapter/json-api.js.map +1 -0
  171. package/dist/unpkg/dev-deprecated/adapter/rest.js +935 -1134
  172. package/dist/unpkg/dev-deprecated/adapter/rest.js.map +1 -0
  173. package/dist/unpkg/dev-deprecated/adapter-Cw0uSl8d.js +1129 -0
  174. package/dist/unpkg/dev-deprecated/adapter-Cw0uSl8d.js.map +1 -0
  175. package/dist/unpkg/dev-deprecated/adapter.js +1 -1247
  176. package/dist/unpkg/dev-deprecated/compat/-private.js +3 -1
  177. package/dist/unpkg/dev-deprecated/compat/builders.js +204 -247
  178. package/dist/unpkg/dev-deprecated/compat/builders.js.map +1 -0
  179. package/dist/unpkg/dev-deprecated/compat/extensions.js +264 -303
  180. package/dist/unpkg/dev-deprecated/compat/extensions.js.map +1 -0
  181. package/dist/unpkg/dev-deprecated/compat/utils.js +186 -205
  182. package/dist/unpkg/dev-deprecated/compat/utils.js.map +1 -0
  183. package/dist/unpkg/dev-deprecated/compat-DmAgB2NS.js +825 -0
  184. package/dist/unpkg/dev-deprecated/compat-DmAgB2NS.js.map +1 -0
  185. package/dist/unpkg/dev-deprecated/compat.js +1 -1178
  186. package/dist/unpkg/dev-deprecated/errors-C4_aOhY5.js +2128 -0
  187. package/dist/unpkg/dev-deprecated/errors-C4_aOhY5.js.map +1 -0
  188. package/dist/unpkg/dev-deprecated/index.js +266 -343
  189. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  190. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js +1104 -0
  191. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js.map +1 -0
  192. package/dist/unpkg/dev-deprecated/model/-private.js +3 -1
  193. package/dist/unpkg/dev-deprecated/model/migration-support.js +492 -566
  194. package/dist/unpkg/dev-deprecated/model/migration-support.js.map +1 -0
  195. package/dist/unpkg/dev-deprecated/model-CvSMYkgs.js +660 -0
  196. package/dist/unpkg/dev-deprecated/model-CvSMYkgs.js.map +1 -0
  197. package/dist/unpkg/dev-deprecated/model-fragments-Dpn9285r.js +334 -0
  198. package/dist/unpkg/dev-deprecated/model-fragments-Dpn9285r.js.map +1 -0
  199. package/dist/unpkg/dev-deprecated/model-fragments.js +2 -94
  200. package/dist/unpkg/dev-deprecated/model.js +3 -685
  201. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  202. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  203. package/dist/unpkg/dev-deprecated/schema-provider-Cqttza94.js +1835 -0
  204. package/dist/unpkg/dev-deprecated/schema-provider-Cqttza94.js.map +1 -0
  205. package/dist/unpkg/dev-deprecated/serializer/json-api.js +514 -634
  206. package/dist/unpkg/dev-deprecated/serializer/json-api.js.map +1 -0
  207. package/dist/unpkg/dev-deprecated/serializer/json.js +3 -4
  208. package/dist/unpkg/dev-deprecated/serializer/rest.js +954 -1196
  209. package/dist/unpkg/dev-deprecated/serializer/rest.js.map +1 -0
  210. package/dist/unpkg/dev-deprecated/serializer/transform.js +283 -308
  211. package/dist/unpkg/dev-deprecated/serializer/transform.js.map +1 -0
  212. package/dist/unpkg/dev-deprecated/serializer.js +205 -205
  213. package/dist/unpkg/dev-deprecated/serializer.js.map +1 -0
  214. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js +472 -0
  215. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js.map +1 -0
  216. package/dist/unpkg/dev-deprecated/store.js +1 -649
  217. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js +18 -0
  218. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js.map +1 -0
  219. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js +17 -0
  220. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js.map +1 -0
  221. package/dist/unpkg/prod/-private-B4bxoTuK.js +160 -0
  222. package/dist/unpkg/prod/-private-B4bxoTuK.js.map +1 -0
  223. package/dist/unpkg/prod/-private-SfXkkHKd.js +745 -0
  224. package/dist/unpkg/prod/-private-SfXkkHKd.js.map +1 -0
  225. package/dist/unpkg/prod/adapter/-private.js +3 -1
  226. package/dist/unpkg/prod/adapter/error.js +418 -447
  227. package/dist/unpkg/prod/adapter/error.js.map +1 -0
  228. package/dist/unpkg/prod/adapter/json-api.js +236 -252
  229. package/dist/unpkg/prod/adapter/json-api.js.map +1 -0
  230. package/dist/unpkg/prod/adapter/rest.js +911 -1097
  231. package/dist/unpkg/prod/adapter/rest.js.map +1 -0
  232. package/dist/unpkg/prod/adapter-Wnk7jizX.js +1111 -0
  233. package/dist/unpkg/prod/adapter-Wnk7jizX.js.map +1 -0
  234. package/dist/unpkg/prod/adapter.js +1 -1214
  235. package/dist/unpkg/prod/compat/-private.js +3 -1
  236. package/dist/unpkg/prod/compat/builders.js +165 -182
  237. package/dist/unpkg/prod/compat/builders.js.map +1 -0
  238. package/dist/unpkg/prod/compat/extensions.js +252 -283
  239. package/dist/unpkg/prod/compat/extensions.js.map +1 -0
  240. package/dist/unpkg/prod/compat/utils.js +183 -200
  241. package/dist/unpkg/prod/compat/utils.js.map +1 -0
  242. package/dist/unpkg/prod/compat-CJ87MzDn.js +547 -0
  243. package/dist/unpkg/prod/compat-CJ87MzDn.js.map +1 -0
  244. package/dist/unpkg/prod/compat.js +1 -742
  245. package/dist/unpkg/prod/errors-Co7YWHoA.js +1977 -0
  246. package/dist/unpkg/prod/errors-Co7YWHoA.js.map +1 -0
  247. package/dist/unpkg/prod/index.js +245 -308
  248. package/dist/unpkg/prod/index.js.map +1 -0
  249. package/dist/unpkg/prod/json-BD1kRTfB.js +1080 -0
  250. package/dist/unpkg/prod/json-BD1kRTfB.js.map +1 -0
  251. package/dist/unpkg/prod/model/-private.js +3 -1
  252. package/dist/unpkg/prod/model/migration-support.js +477 -542
  253. package/dist/unpkg/prod/model/migration-support.js.map +1 -0
  254. package/dist/unpkg/prod/model-BzoOmtka.js +603 -0
  255. package/dist/unpkg/prod/model-BzoOmtka.js.map +1 -0
  256. package/dist/unpkg/prod/model-fragments-Dpn9285r.js +334 -0
  257. package/dist/unpkg/prod/model-fragments-Dpn9285r.js.map +1 -0
  258. package/dist/unpkg/prod/model-fragments.js +2 -94
  259. package/dist/unpkg/prod/model.js +3 -596
  260. package/dist/unpkg/prod/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  261. package/dist/unpkg/prod/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  262. package/dist/unpkg/prod/schema-provider-CKZcqWyP.js +1622 -0
  263. package/dist/unpkg/prod/schema-provider-CKZcqWyP.js.map +1 -0
  264. package/dist/unpkg/prod/serializer/json-api.js +497 -592
  265. package/dist/unpkg/prod/serializer/json-api.js.map +1 -0
  266. package/dist/unpkg/prod/serializer/json.js +3 -4
  267. package/dist/unpkg/prod/serializer/rest.js +938 -1166
  268. package/dist/unpkg/prod/serializer/rest.js.map +1 -0
  269. package/dist/unpkg/prod/serializer/transform.js +283 -308
  270. package/dist/unpkg/prod/serializer/transform.js.map +1 -0
  271. package/dist/unpkg/prod/serializer.js +205 -205
  272. package/dist/unpkg/prod/serializer.js.map +1 -0
  273. package/dist/unpkg/prod/store-RGGc1ilN.js +392 -0
  274. package/dist/unpkg/prod/store-RGGc1ilN.js.map +1 -0
  275. package/dist/unpkg/prod/store.js +1 -517
  276. package/dist/unpkg/prod/util-dSKEgQDp.js +12 -0
  277. package/dist/unpkg/prod/util-dSKEgQDp.js.map +1 -0
  278. package/dist/unpkg/prod/utils-DYC9utVJ.js +11 -0
  279. package/dist/unpkg/prod/utils-DYC9utVJ.js.map +1 -0
  280. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js +160 -0
  281. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js.map +1 -0
  282. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js +745 -0
  283. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js.map +1 -0
  284. package/dist/unpkg/prod-deprecated/adapter/-private.js +3 -1
  285. package/dist/unpkg/prod-deprecated/adapter/error.js +418 -447
  286. package/dist/unpkg/prod-deprecated/adapter/error.js.map +1 -0
  287. package/dist/unpkg/prod-deprecated/adapter/json-api.js +236 -252
  288. package/dist/unpkg/prod-deprecated/adapter/json-api.js.map +1 -0
  289. package/dist/unpkg/prod-deprecated/adapter/rest.js +911 -1097
  290. package/dist/unpkg/prod-deprecated/adapter/rest.js.map +1 -0
  291. package/{declarations/adapter.d.ts → dist/unpkg/prod-deprecated/adapter-Wnk7jizX.js} +445 -110
  292. package/dist/unpkg/prod-deprecated/adapter-Wnk7jizX.js.map +1 -0
  293. package/dist/unpkg/prod-deprecated/adapter.js +1 -1214
  294. package/dist/unpkg/prod-deprecated/compat/-private.js +3 -1
  295. package/dist/unpkg/prod-deprecated/compat/builders.js +165 -182
  296. package/dist/unpkg/prod-deprecated/compat/builders.js.map +1 -0
  297. package/dist/unpkg/prod-deprecated/compat/extensions.js +252 -283
  298. package/dist/unpkg/prod-deprecated/compat/extensions.js.map +1 -0
  299. package/dist/unpkg/prod-deprecated/compat/utils.js +183 -200
  300. package/dist/unpkg/prod-deprecated/compat/utils.js.map +1 -0
  301. package/dist/unpkg/prod-deprecated/compat-CJ87MzDn.js +547 -0
  302. package/dist/unpkg/prod-deprecated/compat-CJ87MzDn.js.map +1 -0
  303. package/dist/unpkg/prod-deprecated/compat.js +1 -742
  304. package/dist/unpkg/prod-deprecated/errors-C-opde61.js +1978 -0
  305. package/dist/unpkg/prod-deprecated/errors-C-opde61.js.map +1 -0
  306. package/dist/unpkg/prod-deprecated/index.js +245 -307
  307. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  308. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js +1080 -0
  309. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js.map +1 -0
  310. package/dist/unpkg/prod-deprecated/model/-private.js +3 -1
  311. package/dist/unpkg/prod-deprecated/model/migration-support.js +488 -559
  312. package/dist/unpkg/prod-deprecated/model/migration-support.js.map +1 -0
  313. package/dist/unpkg/prod-deprecated/model-C0bTXzGn.js +604 -0
  314. package/dist/unpkg/prod-deprecated/model-C0bTXzGn.js.map +1 -0
  315. package/dist/unpkg/prod-deprecated/model-fragments-Dpn9285r.js +334 -0
  316. package/dist/unpkg/prod-deprecated/model-fragments-Dpn9285r.js.map +1 -0
  317. package/dist/unpkg/prod-deprecated/model-fragments.js +2 -94
  318. package/dist/unpkg/prod-deprecated/model.js +3 -599
  319. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  320. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  321. package/dist/unpkg/prod-deprecated/schema-provider-lH3qP5tw.js +1635 -0
  322. package/dist/unpkg/prod-deprecated/schema-provider-lH3qP5tw.js.map +1 -0
  323. package/dist/unpkg/prod-deprecated/serializer/json-api.js +497 -592
  324. package/dist/unpkg/prod-deprecated/serializer/json-api.js.map +1 -0
  325. package/dist/unpkg/prod-deprecated/serializer/json.js +3 -4
  326. package/dist/unpkg/prod-deprecated/serializer/rest.js +938 -1166
  327. package/dist/unpkg/prod-deprecated/serializer/rest.js.map +1 -0
  328. package/dist/unpkg/prod-deprecated/serializer/transform.js +283 -308
  329. package/dist/unpkg/prod-deprecated/serializer/transform.js.map +1 -0
  330. package/dist/unpkg/prod-deprecated/serializer.js +205 -205
  331. package/dist/unpkg/prod-deprecated/serializer.js.map +1 -0
  332. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js +392 -0
  333. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js.map +1 -0
  334. package/dist/unpkg/prod-deprecated/store.js +1 -517
  335. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js +14 -0
  336. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js.map +1 -0
  337. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js +13 -0
  338. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js.map +1 -0
  339. package/dist/util-Bnx8nm-D.js +29 -0
  340. package/dist/util-Bnx8nm-D.js.map +1 -0
  341. package/dist/utils-ZAytYep8.js +28 -0
  342. package/dist/utils-ZAytYep8.js.map +1 -0
  343. package/package.json +13 -13
  344. package/declarations/adapter/-private/build-url-mixin.d.ts +0 -189
  345. package/declarations/adapter/-private/fastboot-interface.d.ts +0 -8
  346. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +0 -1
  347. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +0 -4
  348. package/declarations/adapter/-private/utils/fetch.d.ts +0 -8
  349. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
  350. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +0 -6
  351. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -5
  352. package/declarations/adapter/-private.d.ts +0 -5
  353. package/declarations/adapter/error.d.ts +0 -431
  354. package/declarations/compat/-private.d.ts +0 -13
  355. package/declarations/compat/builders/find-all.d.ts +0 -34
  356. package/declarations/compat/builders/find-record.d.ts +0 -56
  357. package/declarations/compat/builders/query.d.ts +0 -66
  358. package/declarations/compat/builders/save-record.d.ts +0 -34
  359. package/declarations/compat/builders/utils.d.ts +0 -3
  360. package/declarations/compat/builders.d.ts +0 -14
  361. package/declarations/compat/extensions.d.ts +0 -99
  362. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +0 -55
  363. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +0 -2
  364. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +0 -11
  365. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +0 -5
  366. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +0 -9
  367. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +0 -528
  368. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +0 -220
  369. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +0 -6
  370. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +0 -110
  371. package/declarations/compat/legacy-network-handler/snapshot.d.ts +0 -255
  372. package/declarations/compat/utils.d.ts +0 -148
  373. package/declarations/compat.d.ts +0 -189
  374. package/declarations/index.d.ts +0 -244
  375. package/declarations/model/-private/attr.d.ts +0 -191
  376. package/declarations/model/-private/belongs-to.d.ts +0 -195
  377. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +0 -5
  378. package/declarations/model/-private/errors.d.ts +0 -289
  379. package/declarations/model/-private/has-many.d.ts +0 -162
  380. package/declarations/model/-private/hooks.d.ts +0 -36
  381. package/declarations/model/-private/legacy-relationships-support.d.ts +0 -47
  382. package/declarations/model/-private/model-for-mixin.d.ts +0 -3
  383. package/declarations/model/-private/model-methods.d.ts +0 -39
  384. package/declarations/model/-private/model.d.ts +0 -1279
  385. package/declarations/model/-private/notify-changes.d.ts +0 -4
  386. package/declarations/model/-private/promise-belongs-to.d.ts +0 -40
  387. package/declarations/model/-private/promise-many-array.d.ts +0 -130
  388. package/declarations/model/-private/record-state.d.ts +0 -58
  389. package/declarations/model/-private/references/belongs-to.d.ts +0 -488
  390. package/declarations/model/-private/references/has-many.d.ts +0 -498
  391. package/declarations/model/-private/schema-provider.d.ts +0 -66
  392. package/declarations/model/-private/type-utils.d.ts +0 -57
  393. package/declarations/model/-private/util.d.ts +0 -5
  394. package/declarations/model/-private.d.ts +0 -8
  395. package/declarations/model/migration-support.d.ts +0 -306
  396. package/declarations/model-fragments/extensions/fragment-array.d.ts +0 -54
  397. package/declarations/model-fragments/extensions/fragment.d.ts +0 -50
  398. package/declarations/model-fragments/hooks/model-for.d.ts +0 -27
  399. package/declarations/model-fragments/index.d.ts +0 -13
  400. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +0 -15
  401. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +0 -56
  402. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +0 -38
  403. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +0 -34
  404. package/declarations/model-fragments/utilities/with-legacy.d.ts +0 -11
  405. package/declarations/model-fragments.d.ts +0 -9
  406. package/declarations/model.d.ts +0 -49
  407. package/declarations/serializer/-private/transforms/boolean.d.ts +0 -60
  408. package/declarations/serializer/-private/transforms/date.d.ts +0 -42
  409. package/declarations/serializer/-private/transforms/number.d.ts +0 -42
  410. package/declarations/serializer/-private/transforms/string.d.ts +0 -42
  411. package/declarations/serializer/-private/transforms/transform.d.ts +0 -118
  412. package/declarations/serializer/-private/utils.d.ts +0 -27
  413. package/declarations/serializer/rest.d.ts +0 -51
  414. package/declarations/serializer/transform.d.ts +0 -5
  415. package/declarations/serializer.d.ts +0 -252
  416. package/declarations/store/-private.d.ts +0 -223
  417. package/declarations/store.d.ts +0 -10
  418. package/dist/-private-BG3bMiKp.js +0 -1211
  419. package/dist/errors-DZKA206g.js +0 -2589
  420. package/dist/hooks-BvOqJBei.js +0 -105
  421. package/dist/json-DU8m1pGf.js +0 -1336
  422. package/dist/model-for-CXkJw59V.js +0 -297
  423. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  424. package/dist/schema-provider-DtPOp0d7.js +0 -2382
  425. package/dist/serialize-into-hash-DPZYoF-i.js +0 -261
  426. package/dist/unpkg/dev/-private-DtjBbEgy.js +0 -1206
  427. package/dist/unpkg/dev/errors-DngRU-If.js +0 -2585
  428. package/dist/unpkg/dev/hooks-UuiLxWxS.js +0 -104
  429. package/dist/unpkg/dev/json-K2Y9z6MN.js +0 -1333
  430. package/dist/unpkg/dev/model-for-CXkJw59V.js +0 -297
  431. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  432. package/dist/unpkg/dev/schema-provider-0D7f-QOn.js +0 -2272
  433. package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +0 -259
  434. package/dist/unpkg/dev/util-DvanW33H.js +0 -20
  435. package/dist/unpkg/dev/utils-BhvS1iTS.js +0 -8
  436. package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +0 -1206
  437. package/dist/unpkg/dev-deprecated/errors-Bzidntpi.js +0 -2588
  438. package/dist/unpkg/dev-deprecated/hooks-DVXhMW14.js +0 -104
  439. package/dist/unpkg/dev-deprecated/json-K2Y9z6MN.js +0 -1333
  440. package/dist/unpkg/dev-deprecated/model-for-CXkJw59V.js +0 -297
  441. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  442. package/dist/unpkg/dev-deprecated/schema-provider-ZwO5_fZw.js +0 -2292
  443. package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +0 -259
  444. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +0 -24
  445. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +0 -12
  446. package/dist/unpkg/prod/-private-BdyZaGEh.js +0 -971
  447. package/dist/unpkg/prod/errors-B-PWeYlW.js +0 -2337
  448. package/dist/unpkg/prod/hooks-Bx-zBziU.js +0 -72
  449. package/dist/unpkg/prod/json-Qewu-UN9.js +0 -1300
  450. package/dist/unpkg/prod/model-for-CXkJw59V.js +0 -297
  451. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  452. package/dist/unpkg/prod/schema-provider-BgRqk8i9.js +0 -1951
  453. package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +0 -215
  454. package/dist/unpkg/prod/util-DvanW33H.js +0 -20
  455. package/dist/unpkg/prod/utils-BhvS1iTS.js +0 -8
  456. package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +0 -971
  457. package/dist/unpkg/prod-deprecated/errors-Dl2J9d1D.js +0 -2340
  458. package/dist/unpkg/prod-deprecated/hooks-Cm60wWTf.js +0 -72
  459. package/dist/unpkg/prod-deprecated/json-Qewu-UN9.js +0 -1300
  460. package/dist/unpkg/prod-deprecated/model-for-CXkJw59V.js +0 -297
  461. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  462. package/dist/unpkg/prod-deprecated/schema-provider-Dh6tRqVI.js +0 -1980
  463. package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +0 -215
  464. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +0 -23
  465. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +0 -11
  466. package/dist/util-Dul6TZts.js +0 -35
  467. package/dist/utils-Cqw9eRj5.js +0 -23
@@ -1,1241 +1,999 @@
1
- import { camelize, dasherize, singularize } from '@warp-drive/utilities/string';
2
- import { i as inverseForRelationship, J as JSONSerializer, c as coerceId } from "../json-K2Y9z6MN.js";
3
- import Mixin from '@ember/object/mixin';
4
-
5
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
6
- /* eslint-disable @typescript-eslint/no-unsafe-return */
7
- /* eslint-disable @typescript-eslint/no-unsafe-call */
8
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
9
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
1
+ import { n as coerceId, r as inverseForRelationship, t as JSONSerializer } from "../json-DDJji3V3.js";
2
+ import { camelize, dasherize, singularize } from "@warp-drive/utilities/string";
3
+ import Mixin from "@ember/object/mixin";
10
4
 
5
+ //#region src/serializer/-private/embedded-records-mixin.ts
11
6
  /**
12
- ## Using Embedded Records
7
+ ## Using Embedded Records
13
8
 
14
- `EmbeddedRecordsMixin` supports serializing embedded records.
9
+ `EmbeddedRecordsMixin` supports serializing embedded records.
15
10
 
16
- To set up embedded records, include the mixin when extending a serializer,
17
- then define and configure embedded (model) relationships.
11
+ To set up embedded records, include the mixin when extending a serializer,
12
+ then define and configure embedded (model) relationships.
18
13
 
19
- Note that embedded records will serialize with the serializer for their model instead of the serializer in which they are defined.
14
+ Note that embedded records will serialize with the serializer for their model instead of the serializer in which they are defined.
20
15
 
21
- Note also that this mixin does not work with JSONAPISerializer because the JSON:API specification does not describe how to format embedded resources.
16
+ Note also that this mixin does not work with JSONAPISerializer because the JSON:API specification does not describe how to format embedded resources.
22
17
 
23
- Below is an example of a per-type serializer (`post` type).
18
+ Below is an example of a per-type serializer (`post` type).
24
19
 
25
- ```js [app/serializers/post.js]
26
- import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
20
+ ```js [app/serializers/post.js]
21
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
27
22
 
28
- export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
29
- attrs = {
30
- author: { embedded: 'always' },
31
- comments: { serialize: 'ids' }
32
- }
33
- }
34
- ```
35
- Note that this use of `{ embedded: 'always' }` is unrelated to
36
- the `{ embedded: 'always' }` that is defined as an option on `attr` as part of
37
- defining a model while working with the `ActiveModelSerializer`. Nevertheless,
38
- using `{ embedded: 'always' }` as an option to `attr` is not a valid way to set up
39
- embedded records.
23
+ export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
24
+ attrs = {
25
+ author: { embedded: 'always' },
26
+ comments: { serialize: 'ids' }
27
+ }
28
+ }
29
+ ```
30
+ Note that this use of `{ embedded: 'always' }` is unrelated to
31
+ the `{ embedded: 'always' }` that is defined as an option on `attr` as part of
32
+ defining a model while working with the `ActiveModelSerializer`. Nevertheless,
33
+ using `{ embedded: 'always' }` as an option to `attr` is not a valid way to set up
34
+ embedded records.
40
35
 
41
- The `attrs` option for a resource `{ embedded: 'always' }` is shorthand for:
36
+ The `attrs` option for a resource `{ embedded: 'always' }` is shorthand for:
42
37
 
43
- ```js
44
- {
45
- serialize: 'records',
46
- deserialize: 'records'
47
- }
48
- ```
38
+ ```js
39
+ {
40
+ serialize: 'records',
41
+ deserialize: 'records'
42
+ }
43
+ ```
49
44
 
50
- ### Configuring Attrs
45
+ ### Configuring Attrs
51
46
 
52
- A resource's `attrs` option may be set to use `ids`, `records` or false for the
53
- `serialize` and `deserialize` settings.
47
+ A resource's `attrs` option may be set to use `ids`, `records` or false for the
48
+ `serialize` and `deserialize` settings.
54
49
 
55
- The `attrs` property can be set on the `ApplicationSerializer` or a per-type
56
- serializer.
50
+ The `attrs` property can be set on the `ApplicationSerializer` or a per-type
51
+ serializer.
57
52
 
58
- In the case where embedded JSON is expected while extracting a payload (reading)
59
- the setting is `deserialize: 'records'`, there is no need to use `ids` when
60
- extracting as that is the default behaviour without this mixin if you are using
61
- the vanilla `EmbeddedRecordsMixin`. Likewise, to embed JSON in the payload while
62
- serializing `serialize: 'records'` is the setting to use. There is an option of
63
- not embedding JSON in the serialized payload by using `serialize: 'ids'`. If you
64
- do not want the relationship sent at all, you can use `serialize: false`.
53
+ In the case where embedded JSON is expected while extracting a payload (reading)
54
+ the setting is `deserialize: 'records'`, there is no need to use `ids` when
55
+ extracting as that is the default behaviour without this mixin if you are using
56
+ the vanilla `EmbeddedRecordsMixin`. Likewise, to embed JSON in the payload while
57
+ serializing `serialize: 'records'` is the setting to use. There is an option of
58
+ not embedding JSON in the serialized payload by using `serialize: 'ids'`. If you
59
+ do not want the relationship sent at all, you can use `serialize: false`.
65
60
 
66
61
 
67
- ### EmbeddedRecordsMixin defaults
68
- If you do not overwrite `attrs` for a specific relationship, the `EmbeddedRecordsMixin`
69
- will behave in the following way:
62
+ ### EmbeddedRecordsMixin defaults
63
+ If you do not overwrite `attrs` for a specific relationship, the `EmbeddedRecordsMixin`
64
+ will behave in the following way:
70
65
 
71
- BelongsTo: `{ serialize: 'id', deserialize: 'id' }`
72
- HasMany: `{ serialize: false, deserialize: 'ids' }`
66
+ BelongsTo: `{ serialize: 'id', deserialize: 'id' }`
67
+ HasMany: `{ serialize: false, deserialize: 'ids' }`
73
68
 
74
- ### Model Relationships
69
+ ### Model Relationships
75
70
 
76
- Embedded records must have a model defined to be extracted and serialized. Note that
77
- when defining any relationships on your model such as `belongsTo` and `hasMany`, you
78
- should not both specify `async: true` and also indicate through the serializer's
79
- `attrs` attribute that the related model should be embedded for deserialization.
80
- If a model is declared embedded for deserialization (`embedded: 'always'` or `deserialize: 'records'`),
81
- then do not use `async: true`.
71
+ Embedded records must have a model defined to be extracted and serialized. Note that
72
+ when defining any relationships on your model such as `belongsTo` and `hasMany`, you
73
+ should not both specify `async: true` and also indicate through the serializer's
74
+ `attrs` attribute that the related model should be embedded for deserialization.
75
+ If a model is declared embedded for deserialization (`embedded: 'always'` or `deserialize: 'records'`),
76
+ then do not use `async: true`.
82
77
 
83
- To successfully extract and serialize embedded records the model relationships
84
- must be set up correctly. See the
85
- [defining relationships](https://guides.emberjs.com/current/models/relationships)
86
- section of the **Defining Models** guide page.
78
+ To successfully extract and serialize embedded records the model relationships
79
+ must be set up correctly. See the
80
+ [defining relationships](https://guides.emberjs.com/current/models/relationships)
81
+ section of the **Defining Models** guide page.
87
82
 
88
- Records without an `id` property are not considered embedded records, model
89
- instances must have an `id` property to be used with Ember Data.
83
+ Records without an `id` property are not considered embedded records, model
84
+ instances must have an `id` property to be used with Ember Data.
90
85
 
91
- ### Example JSON payloads, Models and Serializers
86
+ ### Example JSON payloads, Models and Serializers
92
87
 
93
- **When customizing a serializer it is important to grok what the customizations
94
- are. Please read the docs for the methods this mixin provides, in case you need
95
- to modify it to fit your specific needs.**
88
+ **When customizing a serializer it is important to grok what the customizations
89
+ are. Please read the docs for the methods this mixin provides, in case you need
90
+ to modify it to fit your specific needs.**
96
91
 
97
- @class EmbeddedRecordsMixin
98
- @public
92
+ @class EmbeddedRecordsMixin
93
+ @public
99
94
  */
100
95
  const EmbeddedRecordsMixin = Mixin.create({
101
- /**
102
- Normalize the record and recursively normalize/extract all the embedded records
103
- while pushing them into the store as they are encountered
104
- A payload with an attr configured for embedded records needs to be extracted:
105
- ```js
106
- {
107
- "post": {
108
- "id": "1"
109
- "title": "Rails is omakase",
110
- "comments": [{
111
- "id": "1",
112
- "body": "Rails is unagi"
113
- }, {
114
- "id": "2",
115
- "body": "Omakase O_o"
116
- }]
117
- }
118
- }
119
- ```
120
- @public
121
- @param {Model} typeClass
122
- @param {Object} hash to be normalized
123
- @param {String} prop the hash has been referenced by
124
- @return {Object} the normalized hash
125
- **/
126
- normalize(typeClass, hash, prop) {
127
- const normalizedHash = this._super(typeClass, hash, prop);
128
- return this._extractEmbeddedRecords(this, this.store, typeClass, normalizedHash);
129
- },
130
- keyForRelationship(key, typeClass, method) {
131
- if (method === 'serialize' && this.hasSerializeRecordsOption(key) || method === 'deserialize' && this.hasDeserializeRecordsOption(key)) {
132
- return this.keyForAttribute(key, method);
133
- } else {
134
- return this._super(key, typeClass, method) || key;
135
- }
136
- },
137
- /**
138
- Serialize `belongsTo` relationship when it is configured as an embedded object.
139
- This example of an author model belongs to a post model:
140
- ```js
141
- import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
142
- Post = Model.extend({
143
- title: attr('string'),
144
- body: attr('string'),
145
- author: belongsTo('author')
146
- });
147
- Author = Model.extend({
148
- name: attr('string'),
149
- post: belongsTo('post')
150
- });
151
- ```
152
- Use a custom (type) serializer for the post model to configure embedded author
153
- ```js [app/serializers/post.js]
154
- import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
155
- export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
156
- attrs = {
157
- author: { embedded: 'always' }
158
- }
159
- }
160
- ```
161
- A payload with an attribute configured for embedded records can serialize
162
- the records together under the root attribute's payload:
163
- ```js
164
- {
165
- "post": {
166
- "id": "1"
167
- "title": "Rails is omakase",
168
- "author": {
169
- "id": "2"
170
- "name": "dhh"
171
- }
172
- }
173
- }
174
- ```
175
- @public
176
- @param {Snapshot} snapshot
177
- @param {Object} json
178
- @param {Object} relationship
179
- */
180
- serializeBelongsTo(snapshot, json, relationship) {
181
- const attr = relationship.name;
182
- if (this.noSerializeOptionSpecified(attr)) {
183
- this._super(snapshot, json, relationship);
184
- return;
185
- }
186
- const includeIds = this.hasSerializeIdsOption(attr);
187
- const includeRecords = this.hasSerializeRecordsOption(attr);
188
- const embeddedSnapshot = snapshot.belongsTo(attr);
189
- if (includeIds) {
190
- const schema = this.store.modelFor(snapshot.modelName);
191
- let serializedKey = this._getMappedKey(relationship.name, schema);
192
- if (serializedKey === relationship.name && this.keyForRelationship) {
193
- serializedKey = this.keyForRelationship(relationship.name, relationship.kind, 'serialize');
194
- }
195
- if (!embeddedSnapshot) {
196
- json[serializedKey] = null;
197
- } else {
198
- json[serializedKey] = embeddedSnapshot.id;
199
- if (relationship.options.polymorphic) {
200
- this.serializePolymorphicType(snapshot, json, relationship);
201
- }
202
- }
203
- } else if (includeRecords) {
204
- this._serializeEmbeddedBelongsTo(snapshot, json, relationship);
205
- }
206
- },
207
- _serializeEmbeddedBelongsTo(snapshot, json, relationship) {
208
- const embeddedSnapshot = snapshot.belongsTo(relationship.name);
209
- const schema = this.store.modelFor(snapshot.modelName);
210
- let serializedKey = this._getMappedKey(relationship.name, schema);
211
- if (serializedKey === relationship.name && this.keyForRelationship) {
212
- serializedKey = this.keyForRelationship(relationship.name, relationship.kind, 'serialize');
213
- }
214
- if (!embeddedSnapshot) {
215
- json[serializedKey] = null;
216
- } else {
217
- json[serializedKey] = embeddedSnapshot.serialize({
218
- includeId: true
219
- });
220
- this.removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json[serializedKey]);
221
- if (relationship.options.polymorphic) {
222
- this.serializePolymorphicType(snapshot, json, relationship);
223
- }
224
- }
225
- },
226
- /**
227
- Serializes `hasMany` relationships when it is configured as embedded objects.
228
- This example of a post model has many comments:
229
- ```js
230
- import Model, { attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
231
- Post = Model.extend({
232
- title: attr('string'),
233
- body: attr('string'),
234
- comments: hasMany('comment')
235
- });
236
- Comment = Model.extend({
237
- body: attr('string'),
238
- post: belongsTo('post')
239
- });
240
- ```
241
- Use a custom (type) serializer for the post model to configure embedded comments
242
- ```js [app/serializers/post.js]
243
- import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
244
- export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
245
- attrs = {
246
- comments: { embedded: 'always' }
247
- }
248
- }
249
- ```
250
- A payload with an attribute configured for embedded records can serialize
251
- the records together under the root attribute's payload:
252
- ```js
253
- {
254
- "post": {
255
- "id": "1"
256
- "title": "Rails is omakase",
257
- "body": "I want this for my ORM, I want that for my template language..."
258
- "comments": [{
259
- "id": "1",
260
- "body": "Rails is unagi"
261
- }, {
262
- "id": "2",
263
- "body": "Omakase O_o"
264
- }]
265
- }
266
- }
267
- ```
268
- The attrs options object can use more specific instruction for extracting and
269
- serializing. When serializing, an option to embed `ids`, `ids-and-types` or `records` can be set.
270
- When extracting the only option is `records`.
271
- So `{ embedded: 'always' }` is shorthand for:
272
- `{ serialize: 'records', deserialize: 'records' }`
273
- To embed the `ids` for a related object (using a hasMany relationship):
274
- ```js [app/serializers/post.js]
275
- import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
276
- export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
277
- attrs = {
278
- comments: { serialize: 'ids', deserialize: 'records' }
279
- }
280
- }
281
- ```
282
- ```js
283
- {
284
- "post": {
285
- "id": "1"
286
- "title": "Rails is omakase",
287
- "body": "I want this for my ORM, I want that for my template language..."
288
- "comments": ["1", "2"]
289
- }
290
- }
291
- ```
292
- To embed the relationship as a collection of objects with `id` and `type` keys, set
293
- `ids-and-types` for the related object.
294
- This is particularly useful for polymorphic relationships where records don't share
295
- the same table and the `id` is not enough information.
296
- For example having a user that has many pets:
297
- ```js
298
- User = Model.extend({
299
- name: attr('string'),
300
- pets: hasMany('pet', { polymorphic: true })
301
- });
302
- Pet = Model.extend({
303
- name: attr('string'),
304
- });
305
- Cat = Pet.extend({
306
- // ...
307
- });
308
- Parrot = Pet.extend({
309
- // ...
310
- });
311
- ```
312
- ```js [app/serializers/user.js]
313
- import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
314
- export default class UserSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
315
- attrs = {
316
- pets: { serialize: 'ids-and-types', deserialize: 'records' }
317
- }
318
- }
319
- ```
320
- ```js
321
- {
322
- "user": {
323
- "id": "1"
324
- "name": "Bertin Osborne",
325
- "pets": [
326
- { "id": "1", "type": "Cat" },
327
- { "id": "1", "type": "Parrot"}
328
- ]
329
- }
330
- }
331
- ```
332
- @public
333
- @param {Snapshot} snapshot
334
- @param {Object} json
335
- @param {Object} relationship
336
- */
337
- serializeHasMany(snapshot, json, relationship) {
338
- const attr = relationship.name;
339
- if (this.noSerializeOptionSpecified(attr)) {
340
- this._super(snapshot, json, relationship);
341
- return;
342
- }
343
- if (this.hasSerializeIdsOption(attr)) {
344
- const schema = this.store.modelFor(snapshot.modelName);
345
- let serializedKey = this._getMappedKey(relationship.name, schema);
346
- if (serializedKey === relationship.name && this.keyForRelationship) {
347
- serializedKey = this.keyForRelationship(relationship.name, relationship.kind, 'serialize');
348
- }
349
- json[serializedKey] = snapshot.hasMany(attr, {
350
- ids: true
351
- });
352
- } else if (this.hasSerializeRecordsOption(attr)) {
353
- this._serializeEmbeddedHasMany(snapshot, json, relationship);
354
- } else {
355
- if (this.hasSerializeIdsAndTypesOption(attr)) {
356
- this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship);
357
- }
358
- }
359
- },
360
- /*
361
- Serializes a hasMany relationship as an array of objects containing only `id` and `type`
362
- keys.
363
- This has its use case on polymorphic hasMany relationships where the server is not storing
364
- all records in the same table using STI, and therefore the `id` is not enough information
365
- TODO: Make the default in Ember-data 3.0??
366
- */
367
- _serializeHasManyAsIdsAndTypes(snapshot, json, relationship) {
368
- const serializedKey = this.keyForAttribute(relationship.name, 'serialize');
369
- const hasMany = snapshot.hasMany(relationship.name) || [];
370
- json[serializedKey] = hasMany.map(function (recordSnapshot) {
371
- //
372
- // I'm sure I'm being utterly naive here. Probably id is a configurable property and
373
- // type too, and the modelName has to be normalized somehow.
374
- //
375
- return {
376
- id: recordSnapshot.id,
377
- type: recordSnapshot.modelName
378
- };
379
- });
380
- },
381
- _serializeEmbeddedHasMany(snapshot, json, relationship) {
382
- const schema = this.store.modelFor(snapshot.modelName);
383
- let serializedKey = this._getMappedKey(relationship.name, schema);
384
- if (serializedKey === relationship.name && this.keyForRelationship) {
385
- serializedKey = this.keyForRelationship(relationship.name, relationship.kind, 'serialize');
386
- }
387
- console.warn(`The embedded relationship '${serializedKey}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`, typeof snapshot.hasMany(relationship.name) !== 'undefined', {
388
- id: 'ds.serializer.embedded-relationship-undefined'
389
- });
390
- json[serializedKey] = this._generateSerializedHasMany(snapshot, relationship);
391
- },
392
- /*
393
- Returns an array of embedded records serialized to JSON
394
- */
395
- _generateSerializedHasMany(snapshot, relationship) {
396
- const hasMany = snapshot.hasMany(relationship.name) || [];
397
- const ret = new Array(hasMany.length);
398
- for (let i = 0; i < hasMany.length; i++) {
399
- const embeddedSnapshot = hasMany[i];
400
- const embeddedJson = embeddedSnapshot.serialize({
401
- includeId: true
402
- });
403
- this.removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, embeddedJson);
404
- ret[i] = embeddedJson;
405
- }
406
- return ret;
407
- },
408
- /**
409
- When serializing an embedded record, modify the property (in the `JSON` payload)
410
- that refers to the parent record (foreign key for the relationship).
411
- Serializing a `belongsTo` relationship removes the property that refers to the
412
- parent record
413
- Serializing a `hasMany` relationship does not remove the property that refers to
414
- the parent record.
415
- @public
416
- @param {Snapshot} snapshot
417
- @param {Snapshot} embeddedSnapshot
418
- @param {Object} relationship
419
- @param {Object} json
420
- */
421
- removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json) {
422
- if (relationship.kind === 'belongsTo') {
423
- const parentRecord = inverseForRelationship(this.store, snapshot.modelName, relationship.name);
424
- if (parentRecord) {
425
- const name = parentRecord.name;
426
- const embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName);
427
- const parentKey = embeddedSerializer.keyForRelationship(name, parentRecord.kind, 'deserialize');
428
- if (parentKey) {
429
- delete json[parentKey];
430
- }
431
- }
432
- } /*else if (relationship.kind === 'hasMany') {
433
- return;
434
- }*/
435
- },
436
- // checks config for attrs option to embedded (always) - serialize and deserialize
437
- hasEmbeddedAlwaysOption(attr) {
438
- const option = this.attrsOption(attr);
439
- return option && option.embedded === 'always';
440
- },
441
- // checks config for attrs option to serialize ids
442
- hasSerializeRecordsOption(attr) {
443
- const alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
444
- const option = this.attrsOption(attr);
445
- return alwaysEmbed || option && option.serialize === 'records';
446
- },
447
- // checks config for attrs option to serialize records
448
- hasSerializeIdsOption(attr) {
449
- const option = this.attrsOption(attr);
450
- return option && (option.serialize === 'ids' || option.serialize === 'id');
451
- },
452
- // checks config for attrs option to serialize records as objects containing id and types
453
- hasSerializeIdsAndTypesOption(attr) {
454
- const option = this.attrsOption(attr);
455
- return option && (option.serialize === 'ids-and-types' || option.serialize === 'id-and-type');
456
- },
457
- // checks config for attrs option to serialize records
458
- noSerializeOptionSpecified(attr) {
459
- const option = this.attrsOption(attr);
460
- return !(option && (option.serialize || option.embedded));
461
- },
462
- // checks config for attrs option to deserialize records
463
- // a defined option object for a resource is treated the same as
464
- // `deserialize: 'records'`
465
- hasDeserializeRecordsOption(attr) {
466
- const alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
467
- const option = this.attrsOption(attr);
468
- return alwaysEmbed || option && option.deserialize === 'records';
469
- },
470
- attrsOption(attr) {
471
- const attrs = this.attrs;
472
- return attrs && (attrs[camelize(attr)] || attrs[attr]);
473
- },
474
- /**
475
- @private
476
- */
477
- _extractEmbeddedRecords(serializer, store, typeClass, partial) {
478
- typeClass.eachRelationship((key, relationship) => {
479
- if (serializer.hasDeserializeRecordsOption(key)) {
480
- if (relationship.kind === 'hasMany') {
481
- this._extractEmbeddedHasMany(store, key, partial, relationship);
482
- }
483
- if (relationship.kind === 'belongsTo') {
484
- this._extractEmbeddedBelongsTo(store, key, partial, relationship);
485
- }
486
- }
487
- });
488
- return partial;
489
- },
490
- /**
491
- @private
492
- */
493
- _extractEmbeddedHasMany(store, key, hash, relationshipMeta) {
494
- const relationshipHash = hash.data?.relationships?.[key]?.data;
495
- if (!relationshipHash) {
496
- return;
497
- }
498
- const hasMany = new Array(relationshipHash.length);
499
- for (let i = 0; i < relationshipHash.length; i++) {
500
- const item = relationshipHash[i];
501
- const {
502
- data,
503
- included
504
- } = this._normalizeEmbeddedRelationship(store, relationshipMeta, item);
505
- hash.included = hash.included || [];
506
- hash.included.push(data);
507
- if (included) {
508
- hash.included = hash.included.concat(included);
509
- }
510
- hasMany[i] = {
511
- id: data.id,
512
- type: data.type
513
- };
514
- if (data.lid) {
515
- hasMany[i].lid = data.lid;
516
- }
517
- }
518
- const relationship = {
519
- data: hasMany
520
- };
521
- hash.data.relationships[key] = relationship;
522
- },
523
- /**
524
- @private
525
- */
526
- _extractEmbeddedBelongsTo(store, key, hash, relationshipMeta) {
527
- const relationshipHash = hash.data?.relationships?.[key]?.data;
528
- if (!relationshipHash) {
529
- return;
530
- }
531
- const {
532
- data,
533
- included
534
- } = this._normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash);
535
- hash.included = hash.included || [];
536
- hash.included.push(data);
537
- if (included) {
538
- hash.included = hash.included.concat(included);
539
- }
540
- const belongsTo = {
541
- id: data.id,
542
- type: data.type
543
- };
544
- const relationship = {
545
- data: belongsTo
546
- };
547
- if (data.lid) {
548
- // @ts-expect-error
549
- belongsTo.lid = data.lid;
550
- }
551
- hash.data.relationships[key] = relationship;
552
- },
553
- /**
554
- @private
555
- */
556
- _normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash) {
557
- let modelName = relationshipMeta.type;
558
- if (relationshipMeta.options.polymorphic) {
559
- modelName = relationshipHash.type;
560
- }
561
- const modelClass = store.modelFor(modelName);
562
- const serializer = store.serializerFor(modelName);
563
- return serializer.normalize(modelClass, relationshipHash, null);
564
- },
565
- isEmbeddedRecordsMixin: true
96
+ /**
97
+ Normalize the record and recursively normalize/extract all the embedded records
98
+ while pushing them into the store as they are encountered
99
+ A payload with an attr configured for embedded records needs to be extracted:
100
+ ```js
101
+ {
102
+ "post": {
103
+ "id": "1"
104
+ "title": "Rails is omakase",
105
+ "comments": [{
106
+ "id": "1",
107
+ "body": "Rails is unagi"
108
+ }, {
109
+ "id": "2",
110
+ "body": "Omakase O_o"
111
+ }]
112
+ }
113
+ }
114
+ ```
115
+ @public
116
+ @param {Model} typeClass
117
+ @param {Object} hash to be normalized
118
+ @param {String} prop the hash has been referenced by
119
+ @return {Object} the normalized hash
120
+ **/
121
+ normalize(typeClass, hash, prop) {
122
+ const normalizedHash = this._super(typeClass, hash, prop);
123
+ return this._extractEmbeddedRecords(this, this.store, typeClass, normalizedHash);
124
+ },
125
+ keyForRelationship(key, typeClass, method) {
126
+ if (method === "serialize" && this.hasSerializeRecordsOption(key) || method === "deserialize" && this.hasDeserializeRecordsOption(key)) return this.keyForAttribute(key, method);
127
+ else return this._super(key, typeClass, method) || key;
128
+ },
129
+ /**
130
+ Serialize `belongsTo` relationship when it is configured as an embedded object.
131
+ This example of an author model belongs to a post model:
132
+ ```js
133
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
134
+ Post = Model.extend({
135
+ title: attr('string'),
136
+ body: attr('string'),
137
+ author: belongsTo('author')
138
+ });
139
+ Author = Model.extend({
140
+ name: attr('string'),
141
+ post: belongsTo('post')
142
+ });
143
+ ```
144
+ Use a custom (type) serializer for the post model to configure embedded author
145
+ ```js [app/serializers/post.js]
146
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
147
+ export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
148
+ attrs = {
149
+ author: { embedded: 'always' }
150
+ }
151
+ }
152
+ ```
153
+ A payload with an attribute configured for embedded records can serialize
154
+ the records together under the root attribute's payload:
155
+ ```js
156
+ {
157
+ "post": {
158
+ "id": "1"
159
+ "title": "Rails is omakase",
160
+ "author": {
161
+ "id": "2"
162
+ "name": "dhh"
163
+ }
164
+ }
165
+ }
166
+ ```
167
+ @public
168
+ @param {Snapshot} snapshot
169
+ @param {Object} json
170
+ @param {Object} relationship
171
+ */
172
+ serializeBelongsTo(snapshot, json, relationship) {
173
+ const attr = relationship.name;
174
+ if (this.noSerializeOptionSpecified(attr)) {
175
+ this._super(snapshot, json, relationship);
176
+ return;
177
+ }
178
+ const includeIds = this.hasSerializeIdsOption(attr);
179
+ const includeRecords = this.hasSerializeRecordsOption(attr);
180
+ const embeddedSnapshot = snapshot.belongsTo(attr);
181
+ if (includeIds) {
182
+ const schema = this.store.modelFor(snapshot.modelName);
183
+ let serializedKey = this._getMappedKey(relationship.name, schema);
184
+ if (serializedKey === relationship.name && this.keyForRelationship) serializedKey = this.keyForRelationship(relationship.name, relationship.kind, "serialize");
185
+ if (!embeddedSnapshot) json[serializedKey] = null;
186
+ else {
187
+ json[serializedKey] = embeddedSnapshot.id;
188
+ if (relationship.options.polymorphic) this.serializePolymorphicType(snapshot, json, relationship);
189
+ }
190
+ } else if (includeRecords) this._serializeEmbeddedBelongsTo(snapshot, json, relationship);
191
+ },
192
+ _serializeEmbeddedBelongsTo(snapshot, json, relationship) {
193
+ const embeddedSnapshot = snapshot.belongsTo(relationship.name);
194
+ const schema = this.store.modelFor(snapshot.modelName);
195
+ let serializedKey = this._getMappedKey(relationship.name, schema);
196
+ if (serializedKey === relationship.name && this.keyForRelationship) serializedKey = this.keyForRelationship(relationship.name, relationship.kind, "serialize");
197
+ if (!embeddedSnapshot) json[serializedKey] = null;
198
+ else {
199
+ json[serializedKey] = embeddedSnapshot.serialize({ includeId: true });
200
+ this.removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json[serializedKey]);
201
+ if (relationship.options.polymorphic) this.serializePolymorphicType(snapshot, json, relationship);
202
+ }
203
+ },
204
+ /**
205
+ Serializes `hasMany` relationships when it is configured as embedded objects.
206
+ This example of a post model has many comments:
207
+ ```js
208
+ import Model, { attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
209
+ Post = Model.extend({
210
+ title: attr('string'),
211
+ body: attr('string'),
212
+ comments: hasMany('comment')
213
+ });
214
+ Comment = Model.extend({
215
+ body: attr('string'),
216
+ post: belongsTo('post')
217
+ });
218
+ ```
219
+ Use a custom (type) serializer for the post model to configure embedded comments
220
+ ```js [app/serializers/post.js]
221
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
222
+ export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
223
+ attrs = {
224
+ comments: { embedded: 'always' }
225
+ }
226
+ }
227
+ ```
228
+ A payload with an attribute configured for embedded records can serialize
229
+ the records together under the root attribute's payload:
230
+ ```js
231
+ {
232
+ "post": {
233
+ "id": "1"
234
+ "title": "Rails is omakase",
235
+ "body": "I want this for my ORM, I want that for my template language..."
236
+ "comments": [{
237
+ "id": "1",
238
+ "body": "Rails is unagi"
239
+ }, {
240
+ "id": "2",
241
+ "body": "Omakase O_o"
242
+ }]
243
+ }
244
+ }
245
+ ```
246
+ The attrs options object can use more specific instruction for extracting and
247
+ serializing. When serializing, an option to embed `ids`, `ids-and-types` or `records` can be set.
248
+ When extracting the only option is `records`.
249
+ So `{ embedded: 'always' }` is shorthand for:
250
+ `{ serialize: 'records', deserialize: 'records' }`
251
+ To embed the `ids` for a related object (using a hasMany relationship):
252
+ ```js [app/serializers/post.js]
253
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
254
+ export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
255
+ attrs = {
256
+ comments: { serialize: 'ids', deserialize: 'records' }
257
+ }
258
+ }
259
+ ```
260
+ ```js
261
+ {
262
+ "post": {
263
+ "id": "1"
264
+ "title": "Rails is omakase",
265
+ "body": "I want this for my ORM, I want that for my template language..."
266
+ "comments": ["1", "2"]
267
+ }
268
+ }
269
+ ```
270
+ To embed the relationship as a collection of objects with `id` and `type` keys, set
271
+ `ids-and-types` for the related object.
272
+ This is particularly useful for polymorphic relationships where records don't share
273
+ the same table and the `id` is not enough information.
274
+ For example having a user that has many pets:
275
+ ```js
276
+ User = Model.extend({
277
+ name: attr('string'),
278
+ pets: hasMany('pet', { polymorphic: true })
279
+ });
280
+ Pet = Model.extend({
281
+ name: attr('string'),
282
+ });
283
+ Cat = Pet.extend({
284
+ // ...
285
+ });
286
+ Parrot = Pet.extend({
287
+ // ...
288
+ });
289
+ ```
290
+ ```js [app/serializers/user.js]
291
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
292
+ export default class UserSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
293
+ attrs = {
294
+ pets: { serialize: 'ids-and-types', deserialize: 'records' }
295
+ }
296
+ }
297
+ ```
298
+ ```js
299
+ {
300
+ "user": {
301
+ "id": "1"
302
+ "name": "Bertin Osborne",
303
+ "pets": [
304
+ { "id": "1", "type": "Cat" },
305
+ { "id": "1", "type": "Parrot"}
306
+ ]
307
+ }
308
+ }
309
+ ```
310
+ @public
311
+ @param {Snapshot} snapshot
312
+ @param {Object} json
313
+ @param {Object} relationship
314
+ */
315
+ serializeHasMany(snapshot, json, relationship) {
316
+ const attr = relationship.name;
317
+ if (this.noSerializeOptionSpecified(attr)) {
318
+ this._super(snapshot, json, relationship);
319
+ return;
320
+ }
321
+ if (this.hasSerializeIdsOption(attr)) {
322
+ const schema = this.store.modelFor(snapshot.modelName);
323
+ let serializedKey = this._getMappedKey(relationship.name, schema);
324
+ if (serializedKey === relationship.name && this.keyForRelationship) serializedKey = this.keyForRelationship(relationship.name, relationship.kind, "serialize");
325
+ json[serializedKey] = snapshot.hasMany(attr, { ids: true });
326
+ } else if (this.hasSerializeRecordsOption(attr)) this._serializeEmbeddedHasMany(snapshot, json, relationship);
327
+ else if (this.hasSerializeIdsAndTypesOption(attr)) this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship);
328
+ },
329
+ _serializeHasManyAsIdsAndTypes(snapshot, json, relationship) {
330
+ const serializedKey = this.keyForAttribute(relationship.name, "serialize");
331
+ json[serializedKey] = (snapshot.hasMany(relationship.name) || []).map(function(recordSnapshot) {
332
+ return {
333
+ id: recordSnapshot.id,
334
+ type: recordSnapshot.modelName
335
+ };
336
+ });
337
+ },
338
+ _serializeEmbeddedHasMany(snapshot, json, relationship) {
339
+ const schema = this.store.modelFor(snapshot.modelName);
340
+ let serializedKey = this._getMappedKey(relationship.name, schema);
341
+ if (serializedKey === relationship.name && this.keyForRelationship) serializedKey = this.keyForRelationship(relationship.name, relationship.kind, "serialize");
342
+ console.warn(`The embedded relationship '${serializedKey}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`, typeof snapshot.hasMany(relationship.name) !== "undefined", { id: "ds.serializer.embedded-relationship-undefined" });
343
+ json[serializedKey] = this._generateSerializedHasMany(snapshot, relationship);
344
+ },
345
+ _generateSerializedHasMany(snapshot, relationship) {
346
+ const hasMany = snapshot.hasMany(relationship.name) || [];
347
+ const ret = new Array(hasMany.length);
348
+ for (let i = 0; i < hasMany.length; i++) {
349
+ const embeddedSnapshot = hasMany[i];
350
+ const embeddedJson = embeddedSnapshot.serialize({ includeId: true });
351
+ this.removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, embeddedJson);
352
+ ret[i] = embeddedJson;
353
+ }
354
+ return ret;
355
+ },
356
+ /**
357
+ When serializing an embedded record, modify the property (in the `JSON` payload)
358
+ that refers to the parent record (foreign key for the relationship).
359
+ Serializing a `belongsTo` relationship removes the property that refers to the
360
+ parent record
361
+ Serializing a `hasMany` relationship does not remove the property that refers to
362
+ the parent record.
363
+ @public
364
+ @param {Snapshot} snapshot
365
+ @param {Snapshot} embeddedSnapshot
366
+ @param {Object} relationship
367
+ @param {Object} json
368
+ */
369
+ removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json) {
370
+ if (relationship.kind === "belongsTo") {
371
+ const parentRecord = inverseForRelationship(this.store, snapshot.modelName, relationship.name);
372
+ if (parentRecord) {
373
+ const name = parentRecord.name;
374
+ const parentKey = this.store.serializerFor(embeddedSnapshot.modelName).keyForRelationship(name, parentRecord.kind, "deserialize");
375
+ if (parentKey) delete json[parentKey];
376
+ }
377
+ }
378
+ },
379
+ hasEmbeddedAlwaysOption(attr) {
380
+ const option = this.attrsOption(attr);
381
+ return option && option.embedded === "always";
382
+ },
383
+ hasSerializeRecordsOption(attr) {
384
+ const alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
385
+ const option = this.attrsOption(attr);
386
+ return alwaysEmbed || option && option.serialize === "records";
387
+ },
388
+ hasSerializeIdsOption(attr) {
389
+ const option = this.attrsOption(attr);
390
+ return option && (option.serialize === "ids" || option.serialize === "id");
391
+ },
392
+ hasSerializeIdsAndTypesOption(attr) {
393
+ const option = this.attrsOption(attr);
394
+ return option && (option.serialize === "ids-and-types" || option.serialize === "id-and-type");
395
+ },
396
+ noSerializeOptionSpecified(attr) {
397
+ const option = this.attrsOption(attr);
398
+ return !(option && (option.serialize || option.embedded));
399
+ },
400
+ hasDeserializeRecordsOption(attr) {
401
+ const alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
402
+ const option = this.attrsOption(attr);
403
+ return alwaysEmbed || option && option.deserialize === "records";
404
+ },
405
+ attrsOption(attr) {
406
+ const attrs = this.attrs;
407
+ return attrs && (attrs[camelize(attr)] || attrs[attr]);
408
+ },
409
+ /**
410
+ @private
411
+ */
412
+ _extractEmbeddedRecords(serializer, store, typeClass, partial) {
413
+ typeClass.eachRelationship((key, relationship) => {
414
+ if (serializer.hasDeserializeRecordsOption(key)) {
415
+ if (relationship.kind === "hasMany") this._extractEmbeddedHasMany(store, key, partial, relationship);
416
+ if (relationship.kind === "belongsTo") this._extractEmbeddedBelongsTo(store, key, partial, relationship);
417
+ }
418
+ });
419
+ return partial;
420
+ },
421
+ /**
422
+ @private
423
+ */
424
+ _extractEmbeddedHasMany(store, key, hash, relationshipMeta) {
425
+ const relationshipHash = hash.data?.relationships?.[key]?.data;
426
+ if (!relationshipHash) return;
427
+ const hasMany = new Array(relationshipHash.length);
428
+ for (let i = 0; i < relationshipHash.length; i++) {
429
+ const item = relationshipHash[i];
430
+ const { data, included } = this._normalizeEmbeddedRelationship(store, relationshipMeta, item);
431
+ hash.included = hash.included || [];
432
+ hash.included.push(data);
433
+ if (included) hash.included = hash.included.concat(included);
434
+ hasMany[i] = {
435
+ id: data.id,
436
+ type: data.type
437
+ };
438
+ if (data.lid) hasMany[i].lid = data.lid;
439
+ }
440
+ const relationship = { data: hasMany };
441
+ hash.data.relationships[key] = relationship;
442
+ },
443
+ /**
444
+ @private
445
+ */
446
+ _extractEmbeddedBelongsTo(store, key, hash, relationshipMeta) {
447
+ const relationshipHash = hash.data?.relationships?.[key]?.data;
448
+ if (!relationshipHash) return;
449
+ const { data, included } = this._normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash);
450
+ hash.included = hash.included || [];
451
+ hash.included.push(data);
452
+ if (included) hash.included = hash.included.concat(included);
453
+ const belongsTo = {
454
+ id: data.id,
455
+ type: data.type
456
+ };
457
+ const relationship = { data: belongsTo };
458
+ if (data.lid) belongsTo.lid = data.lid;
459
+ hash.data.relationships[key] = relationship;
460
+ },
461
+ /**
462
+ @private
463
+ */
464
+ _normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash) {
465
+ let modelName = relationshipMeta.type;
466
+ if (relationshipMeta.options.polymorphic) modelName = relationshipHash.type;
467
+ const modelClass = store.modelFor(modelName);
468
+ return store.serializerFor(modelName).normalize(modelClass, relationshipHash, null);
469
+ },
470
+ isEmbeddedRecordsMixin: true
566
471
  });
567
472
 
568
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
569
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
570
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
571
- /* eslint-disable @typescript-eslint/no-unsafe-call */
572
- /* eslint-disable @typescript-eslint/no-unsafe-return */
573
-
473
+ //#endregion
474
+ //#region src/serializer/rest.ts
574
475
  function makeArray(value) {
575
- return Array.isArray(value) ? value : [value];
476
+ return Array.isArray(value) ? value : [value];
576
477
  }
577
-
578
478
  /**
579
- * :::danger
580
- ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
581
- If starting a new app or thinking of implementing a new adapter, consider writing a
582
- {@link Handler} instead to be used with the {@link RequestManager}
583
- :::
479
+ * :::danger
480
+ ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
481
+ If starting a new app or thinking of implementing a new adapter, consider writing a
482
+ {@link Handler} instead to be used with the {@link RequestManager}
483
+ :::
584
484
 
585
- Normally, applications will use the `RESTSerializer` by implementing
586
- the `normalize` method.
485
+ Normally, applications will use the `RESTSerializer` by implementing
486
+ the `normalize` method.
587
487
 
588
- This allows you to do whatever kind of munging you need and is
589
- especially useful if your server is inconsistent and you need to
590
- do munging differently for many different kinds of responses.
488
+ This allows you to do whatever kind of munging you need and is
489
+ especially useful if your server is inconsistent and you need to
490
+ do munging differently for many different kinds of responses.
591
491
 
592
- See the `normalize` documentation for more information.
492
+ See the `normalize` documentation for more information.
593
493
 
594
- ## Across the Board Normalization
494
+ ## Across the Board Normalization
595
495
 
596
- There are also a number of hooks that you might find useful to define
597
- across-the-board rules for your payload. These rules will be useful
598
- if your server is consistent, or if you're building an adapter for
599
- an infrastructure service, like Firebase, and want to encode service
600
- conventions.
496
+ There are also a number of hooks that you might find useful to define
497
+ across-the-board rules for your payload. These rules will be useful
498
+ if your server is consistent, or if you're building an adapter for
499
+ an infrastructure service, like Firebase, and want to encode service
500
+ conventions.
601
501
 
602
- For example, if all of your keys are underscored and all-caps, but
603
- otherwise consistent with the names you use in your models, you
604
- can implement across-the-board rules for how to convert an attribute
605
- name in your model to a key in your JSON.
502
+ For example, if all of your keys are underscored and all-caps, but
503
+ otherwise consistent with the names you use in your models, you
504
+ can implement across-the-board rules for how to convert an attribute
505
+ name in your model to a key in your JSON.
606
506
 
607
- ```js [app/serializers/application.js]
608
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
609
- import { underscore } from '<app-name>/utils/string-utils';
507
+ ```js [app/serializers/application.js]
508
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
509
+ import { underscore } from '<app-name>/utils/string-utils';
610
510
 
611
- export default class ApplicationSerializer extends RESTSerializer {
612
- keyForAttribute(attr, method) {
613
- return underscore(attr).toUpperCase();
614
- }
615
- }
616
- ```
511
+ export default class ApplicationSerializer extends RESTSerializer {
512
+ keyForAttribute(attr, method) {
513
+ return underscore(attr).toUpperCase();
514
+ }
515
+ }
516
+ ```
617
517
 
618
- You can also implement `keyForRelationship`, which takes the name
619
- of the relationship as the first parameter, the kind of
620
- relationship (`hasMany` or `belongsTo`) as the second parameter, and
621
- the method (`serialize` or `deserialize`) as the third parameter.
518
+ You can also implement `keyForRelationship`, which takes the name
519
+ of the relationship as the first parameter, the kind of
520
+ relationship (`hasMany` or `belongsTo`) as the second parameter, and
521
+ the method (`serialize` or `deserialize`) as the third parameter.
622
522
 
623
- @class RESTSerializer
624
- @public
523
+ @class RESTSerializer
524
+ @public
625
525
  */
626
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
627
526
  const RESTSerializer = JSONSerializer.extend({
628
- /**
629
- `keyForPolymorphicType` can be used to define a custom key when
630
- serializing and deserializing a polymorphic type. By default, the
631
- returned key is `${key}Type`.
632
- Example
633
- ```js [app/serializers/post.js]
634
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
635
- export default class ApplicationSerializer extends RESTSerializer {
636
- keyForPolymorphicType(key, relationship) {
637
- let relationshipKey = this.keyForRelationship(key);
638
- return 'type-' + relationshipKey;
639
- }
640
- }
641
- ```
642
- @public
643
- */
644
- keyForPolymorphicType(key, type, method) {
645
- // @ts-expect-error
646
- const relationshipKey = this.keyForRelationship(key);
647
- return `${relationshipKey}Type`;
648
- },
649
- /**
650
- Normalizes a part of the JSON payload returned by
651
- the server. You should override this method, munge the hash
652
- and call super if you have generic normalization to do.
653
- It takes the type of the record that is being normalized
654
- (as a Model class), the property where the hash was
655
- originally found, and the hash to normalize.
656
- For example, if you have a payload that looks like this:
657
- ```js
658
- {
659
- "post": {
660
- "id": 1,
661
- "title": "Rails is omakase",
662
- "comments": [ 1, 2 ]
663
- },
664
- "comments": [{
665
- "id": 1,
666
- "body": "FIRST"
667
- }, {
668
- "id": 2,
669
- "body": "Rails is unagi"
670
- }]
671
- }
672
- ```
673
- The `normalize` method will be called three times:
674
- * With `App.Post`, `"posts"` and `{ id: 1, title: "Rails is omakase", ... }`
675
- * With `App.Comment`, `"comments"` and `{ id: 1, body: "FIRST" }`
676
- * With `App.Comment`, `"comments"` and `{ id: 2, body: "Rails is unagi" }`
677
- You can use this method, for example, to normalize underscored keys to camelized
678
- or other general-purpose normalizations. You will only need to implement
679
- `normalize` and manipulate the payload as desired.
680
- For example, if the `IDs` under `"comments"` are provided as `_id` instead of
681
- `id`, you can specify how to normalize just the comments:
682
- ```js [app/serializers/post.js]
683
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
684
- export default class ApplicationSerializer extends RESTSerializer {
685
- normalize(model, hash, prop) {
686
- if (prop === 'comments') {
687
- hash.id = hash._id;
688
- delete hash._id;
689
- }
690
- return super.normalize(...arguments);
691
- }
692
- }
693
- ```
694
- On each call to the `normalize` method, the third parameter (`prop`) is always
695
- one of the keys that were in the original payload or in the result of another
696
- normalization as `normalizeResponse`.
697
- @public
698
- @param {Model} modelClass
699
- @param {Object} resourceHash
700
- @param {String} prop
701
- @return {Object}
702
- */
703
-
704
- /**
705
- Normalizes an array of resource payloads and returns a JSON-API Document
706
- with primary data and, if any, included data as `{ data, included }`.
707
- @private
708
- */
709
- _normalizeArray(store, modelName, arrayHash, prop) {
710
- const documentHash = {
711
- data: [],
712
- included: []
713
- };
714
- const modelClass = store.modelFor(modelName);
715
- const serializer = store.serializerFor(modelName);
716
- makeArray(arrayHash).forEach(hash => {
717
- // @ts-expect-error
718
- const {
719
- data,
720
- included
721
- } = this._normalizePolymorphicRecord(store, hash, prop, modelClass, serializer);
722
- // @ts-expect-error
723
- documentHash.data.push(data);
724
- if (included) {
725
- documentHash.included = documentHash.included.concat(included);
726
- }
727
- });
728
- return documentHash;
729
- },
730
- _normalizePolymorphicRecord(store, hash, prop, primaryModelClass, primarySerializer) {
731
- let serializer = primarySerializer;
732
- let modelClass = primaryModelClass;
733
- const primaryHasTypeAttribute = primaryModelClass.fields.has('type');
734
-
735
- // @ts-expect-error all the errors
736
- if (!primaryHasTypeAttribute && hash.type) {
737
- // Support polymorphic records in async relationships
738
- // @ts-expect-error all the errors
739
- const type = this.modelNameFromPayloadKey(hash.type);
740
- if (store.schema.hasResource({
741
- type
742
- })) {
743
- serializer = store.serializerFor(type);
744
- modelClass = store.modelFor(type);
745
- }
746
- }
747
-
748
- // @ts-expect-error all the errors
749
- return serializer.normalize(modelClass, hash, prop);
750
- },
751
- /**
752
- @private
753
- */
754
- _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
755
- const documentHash = {
756
- data: null,
757
- included: []
758
- };
759
- // @ts-expect-error
760
- const meta = this.extractMeta(store, primaryModelClass, payload);
761
- if (meta) {
762
- (test => {
763
- if (!test) {
764
- throw new Error('The `meta` returned from `extractMeta` has to be an object, not "' + typeof meta + '".');
765
- }
766
- })(typeof meta === 'object'); // @ts-expect-error
767
- documentHash.meta = meta;
768
- }
769
- const keys = Object.keys(payload);
770
- for (let i = 0, length = keys.length; i < length; i++) {
771
- const prop = keys[i];
772
- let modelName = prop;
773
- let forcedSecondary = false;
774
-
775
- /*
776
- If you want to provide sideloaded records of the same type that the
777
- primary data you can do that by prefixing the key with `_`.
778
- Example
779
- ```
780
- {
781
- users: [
782
- { id: 1, title: 'Tom', manager: 3 },
783
- { id: 2, title: 'Yehuda', manager: 3 }
784
- ],
785
- _users: [
786
- { id: 3, title: 'Tomster' }
787
- ]
788
- }
789
- ```
790
- This forces `_users` to be added to `included` instead of `data`.
791
- */
792
- if (prop.charAt(0) === '_') {
793
- forcedSecondary = true;
794
- modelName = prop.substr(1);
795
- }
796
- const type = this.modelNameFromPayloadKey(modelName);
797
- if (!store.schema.hasResource({
798
- type
799
- })) {
800
- {
801
- // @ts-expect-error
802
- console.warn(this.warnMessageNoModelForKey(modelName, type), false, {
803
- id: 'ds.serializer.model-for-key-missing'
804
- });
805
- }
806
- continue;
807
- }
808
-
809
- // eslint-disable-next-line no-var
810
- var isPrimary = !forcedSecondary && this.isPrimaryType(store, type, primaryModelClass);
811
- const value = payload[prop];
812
- if (value === null) {
813
- continue;
814
- }
815
- (test => {
816
- if (!test) {
817
- throw new Error('The adapter returned an array for the primary data of a `queryRecord` response. `queryRecord` should return a single record.');
818
- }
819
- })(!(requestType === 'queryRecord' && isPrimary && Array.isArray(value)));
820
-
821
- /*
822
- Support primary data as an object instead of an array.
823
- Example
824
- ```
825
- {
826
- user: { id: 1, title: 'Tom', manager: 3 }
827
- }
828
- ```
829
- */
830
- if (isPrimary && !Array.isArray(value)) {
831
- // @ts-expect-error
832
- const {
833
- data,
834
- included
835
- } = this._normalizePolymorphicRecord(store, value, prop, primaryModelClass, this);
836
- documentHash.data = data;
837
- if (included) {
838
- documentHash.included = documentHash.included.concat(included);
839
- }
840
- continue;
841
- }
842
- // @ts-expect-error
843
- const {
844
- data,
845
- included
846
- } = this._normalizeArray(store, type, value, prop);
847
- if (included) {
848
- documentHash.included = documentHash.included.concat(included);
849
- }
850
- if (isSingle) {
851
- // eslint-disable-next-line @typescript-eslint/no-loop-func
852
- data.forEach(resource => {
853
- /*
854
- Figures out if this is the primary record or not.
855
- It's either:
856
- 1. The record with the same ID as the original request
857
- 2. If it's a newly created record without an ID, the first record
858
- in the array
859
- */
860
- const isUpdatedRecord = isPrimary && coerceId(resource.id) === id;
861
- const isFirstCreatedRecord = isPrimary && !id && !documentHash.data;
862
- if (isFirstCreatedRecord || isUpdatedRecord) {
863
- documentHash.data = resource;
864
- } else {
865
- // @ts-expect-error
866
- documentHash.included.push(resource);
867
- }
868
- });
869
- } else {
870
- if (isPrimary) {
871
- documentHash.data = data;
872
- } else {
873
- if (data) {
874
- documentHash.included = documentHash.included.concat(data);
875
- }
876
- }
877
- }
878
- }
879
- return documentHash;
880
- },
881
- isPrimaryType(store, modelName, primaryModelClass) {
882
- return dasherize(modelName) === primaryModelClass.modelName;
883
- },
884
- /**
885
- This method allows you to push a payload containing top-level
886
- collections of records organized per type.
887
- ```js
888
- {
889
- "posts": [{
890
- "id": "1",
891
- "title": "Rails is omakase",
892
- "author", "1",
893
- "comments": [ "1" ]
894
- }],
895
- "comments": [{
896
- "id": "1",
897
- "body": "FIRST"
898
- }],
899
- "users": [{
900
- "id": "1",
901
- "name": "@d2h"
902
- }]
903
- }
904
- ```
905
- It will first normalize the payload, so you can use this to push
906
- in data streaming in from your server structured the same way
907
- that fetches and saves are structured.
908
- @public
909
- */
910
- pushPayload(store, payload) {
911
- const documentHash = {
912
- data: [],
913
- included: []
914
- };
915
- for (const prop in payload) {
916
- const type = this.modelNameFromPayloadKey(prop);
917
- if (!store.schema.hasResource({
918
- type
919
- })) {
920
- {
921
- // @ts-expect-error
922
- console.warn(this.warnMessageNoModelForKey(prop, type), false, {
923
- id: 'ds.serializer.model-for-key-missing'
924
- });
925
- }
926
- continue;
927
- }
928
- const ModelSchema = store.modelFor(type);
929
- const typeSerializer = store.serializerFor(ModelSchema.modelName);
930
- makeArray(payload[prop]).forEach(hash => {
931
- const {
932
- data,
933
- included
934
- } = typeSerializer.normalize(ModelSchema, hash, prop);
935
- // @ts-expect-error
936
- documentHash.data.push(data);
937
- if (included) {
938
- documentHash.included = documentHash.included.concat(included);
939
- }
940
- });
941
- }
942
- store.push(documentHash);
943
- },
944
- /**
945
- This method is used to convert each JSON root key in the payload
946
- into a modelName that it can use to look up the appropriate model for
947
- that part of the payload.
948
- For example, your server may send a model name that does not correspond with
949
- the name of the model in your app. Let's take a look at an example model,
950
- and an example payload:
951
- ```js [app/models/post.js]
952
- import Model from '@warp-drive/legacy/model';
953
- export default class Post extends Model {}
954
- ```
955
- ```javascript
956
- {
957
- "blog/post": {
958
- "id": "1
959
- }
960
- }
961
- ```
962
- Ember Data is going to normalize the payload's root key for the modelName. As a result,
963
- it will try to look up the "blog/post" model. Since we don't have a model called "blog/post"
964
- (or a file called app/models/blog/post.js in ember-cli), Ember Data will throw an error
965
- because it cannot find the "blog/post" model.
966
- Since we want to remove this namespace, we can define a serializer for the application that will
967
- remove "blog/" from the payload key whenver it's encountered by Ember Data:
968
- ```js [app/serializers/application.js]
969
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
970
- export default class ApplicationSerializer extends RESTSerializer {
971
- modelNameFromPayloadKey(payloadKey) {
972
- if (payloadKey === 'blog/post') {
973
- return super.modelNameFromPayloadKey(payloadKey.replace('blog/', ''));
974
- } else {
975
- return super.modelNameFromPayloadKey(payloadKey);
976
- }
977
- }
978
- }
979
- ```
980
- After refreshing, Ember Data will appropriately look up the "post" model.
981
- By default the modelName for a model is its
982
- name in dasherized form. This means that a payload key like "blogPost" would be
983
- normalized to "blog-post" when Ember Data looks up the model. Usually, Ember Data
984
- can use the correct inflection to do this for you. Most of the time, you won't
985
- need to override `modelNameFromPayloadKey` for this purpose.
986
- @public
987
- @return the model's modelName
988
- */
989
- modelNameFromPayloadKey(key) {
990
- return dasherize(singularize(key));
991
- },
992
- // SERIALIZE
993
-
994
- /**
995
- Called when a record is saved in order to convert the
996
- record into JSON.
997
- By default, it creates a JSON object with a key for
998
- each attribute and belongsTo relationship.
999
- For example, consider this model:
1000
- ```js [app/models/comment.js]
1001
- import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
1002
- export default class Comment extends Model {
1003
- @attr title
1004
- @attr body
1005
- @belongsTo('user') author
1006
- }
1007
- ```
1008
- The default serialization would create a JSON object like:
1009
- ```js
1010
- {
1011
- "title": "Rails is unagi",
1012
- "body": "Rails? Omakase? O_O",
1013
- "author": 12
1014
- }
1015
- ```
1016
- By default, attributes are passed through as-is, unless
1017
- you specified an attribute type (`attr('date')`). If
1018
- you specify a transform, the JavaScript value will be
1019
- serialized when inserted into the JSON hash.
1020
- By default, belongs-to relationships are converted into
1021
- IDs when inserted into the JSON hash.
1022
- ## IDs
1023
- `serialize` takes an options hash with a single option:
1024
- `includeId`. If this option is `true`, `serialize` will,
1025
- by default include the ID in the JSON object it builds.
1026
- The RESTAdapter passes in `includeId: true` when serializing
1027
- a record for `createRecord`, but not for `updateRecord`.
1028
- ## Customization
1029
- Your server may expect a different JSON format than the
1030
- built-in serialization format.
1031
- In that case, you can implement `serialize` yourself and
1032
- return a JSON hash of your choosing.
1033
- ```js [app/serializers/post.js]
1034
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1035
- export default class ApplicationSerializer extends RESTSerializer {
1036
- serialize(snapshot, options) {
1037
- let json = {
1038
- POST_TTL: snapshot.attr('title'),
1039
- POST_BDY: snapshot.attr('body'),
1040
- POST_CMS: snapshot.hasMany('comments', { ids: true })
1041
- };
1042
- if (options.includeId) {
1043
- json.POST_ID_ = snapshot.id;
1044
- }
1045
- return json;
1046
- }
1047
- }
1048
- ```
1049
- ## Customizing an App-Wide Serializer
1050
- If you want to define a serializer for your entire
1051
- application, you'll probably want to use `eachAttribute`
1052
- and `eachRelationship` on the record.
1053
- ```js [app/serializers/application.js]
1054
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1055
- import { pluralize } from '<app-name>/utils/string-utils';
1056
- export default class ApplicationSerializer extends RESTSerializer {
1057
- serialize(snapshot, options) {
1058
- let json = {};
1059
- snapshot.eachAttribute(function(name) {
1060
- json[serverAttributeName(name)] = snapshot.attr(name);
1061
- });
1062
- snapshot.eachRelationship(function(name, relationship) {
1063
- if (relationship.kind === 'hasMany') {
1064
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
1065
- }
1066
- });
1067
- if (options.includeId) {
1068
- json.ID_ = snapshot.id;
1069
- }
1070
- return json;
1071
- }
1072
- }
1073
- function serverAttributeName(attribute) {
1074
- return attribute.underscore().toUpperCase();
1075
- }
1076
- function serverHasManyName(name) {
1077
- return serverAttributeName(singularize(name)) + "_IDS";
1078
- }
1079
- ```
1080
- This serializer will generate JSON that looks like this:
1081
- ```js
1082
- {
1083
- "TITLE": "Rails is omakase",
1084
- "BODY": "Yep. Omakase.",
1085
- "COMMENT_IDS": [ 1, 2, 3 ]
1086
- }
1087
- ```
1088
- ## Tweaking the Default JSON
1089
- If you just want to do some small tweaks on the default JSON,
1090
- you can call super first and make the tweaks on the returned
1091
- JSON.
1092
- ```js [app/serializers/post.js]
1093
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1094
- export default class ApplicationSerializer extends RESTSerializer {
1095
- serialize(snapshot, options) {
1096
- let json = super.serialize(snapshot, options);
1097
- json.subject = json.title;
1098
- delete json.title;
1099
- return json;
1100
- }
1101
- }
1102
- ```
1103
- @public
1104
- */
1105
- serialize(snapshot, options) {
1106
- // @ts-expect-error
1107
- return this._super(...arguments);
1108
- },
1109
- /**
1110
- You can use this method to customize the root keys serialized into the JSON.
1111
- The hash property should be modified by reference (possibly using something like _.extend)
1112
- By default the REST Serializer sends the modelName of a model, which is a camelized
1113
- version of the name.
1114
- For example, your server may expect underscored root objects.
1115
- ```js [app/serializers/application.js]
1116
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1117
- import { underscore } from '<app-name>/utils/string-utils';
1118
- export default class ApplicationSerializer extends RESTSerializer {
1119
- serializeIntoHash(data, type, record, options) {
1120
- let root = underscore(type.modelName);
1121
- data[root] = this.serialize(record, options);
1122
- }
1123
- }
1124
- ```
1125
- @public
1126
- */
1127
- serializeIntoHash(hash, typeClass, snapshot, options) {
1128
- const normalizedRootKey = this.payloadKeyFromModelName(typeClass.modelName);
1129
- hash[normalizedRootKey] = this.serialize(snapshot, options);
1130
- },
1131
- /**
1132
- You can use `payloadKeyFromModelName` to override the root key for an outgoing
1133
- request. By default, the RESTSerializer returns a camelized version of the
1134
- model's name.
1135
- For a model called TacoParty, its `modelName` would be the string `taco-party`. The RESTSerializer
1136
- will send it to the server with `tacoParty` as the root key in the JSON payload:
1137
- ```js
1138
- {
1139
- "tacoParty": {
1140
- "id": "1",
1141
- "location": "Matthew Beale's House"
1142
- }
1143
- }
1144
- ```
1145
- For example, your server may expect dasherized root objects:
1146
- ```js [app/serializers/application.js]
1147
- import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1148
- import { dasherize } from '<app-name>/utils/string-utils';
1149
- export default class ApplicationSerializer extends RESTSerializer {
1150
- payloadKeyFromModelName(modelName) {
1151
- return dasherize(modelName);
1152
- }
1153
- }
1154
- ```
1155
- Given a `TacoParty` model, calling `save` on it would produce an outgoing
1156
- request like:
1157
- ```js
1158
- {
1159
- "taco-party": {
1160
- "id": "1",
1161
- "location": "Matthew Beale's House"
1162
- }
1163
- }
1164
- ```
1165
- @public
1166
- */
1167
- payloadKeyFromModelName(modelName) {
1168
- return camelize(modelName);
1169
- },
1170
- /**
1171
- You can use this method to customize how polymorphic objects are serialized.
1172
- By default the REST Serializer creates the key by appending `Type` to
1173
- the attribute and value from the model's camelcased model name.
1174
- @public
1175
- */
1176
- serializePolymorphicType(snapshot, json, relationship) {
1177
- const name = relationship.name;
1178
- const typeKey = this.keyForPolymorphicType(name, relationship.type, 'serialize');
1179
- const belongsTo = snapshot.belongsTo(name);
1180
- if (!belongsTo) {
1181
- json[typeKey] = null;
1182
- } else {
1183
- // @ts-expect-error
1184
- json[typeKey] = camelize(belongsTo.modelName);
1185
- }
1186
- },
1187
- /**
1188
- You can use this method to customize how a polymorphic relationship should
1189
- be extracted.
1190
- @public
1191
- @param {Object} relationshipType
1192
- @param {Object} relationshipHash
1193
- @param {Object} relationshipOptions
1194
- @return {Object}
1195
- */
1196
- extractPolymorphicRelationship(relationshipType, relationshipHash, relationshipOptions) {
1197
- // @ts-expect-error
1198
- const {
1199
- key,
1200
- resourceHash,
1201
- relationshipMeta
1202
- } = relationshipOptions;
1203
-
1204
- // A polymorphic belongsTo relationship can be present in the payload
1205
- // either in the form where the `id` and the `type` are given:
1206
- //
1207
- // {
1208
- // message: { id: 1, type: 'post' }
1209
- // }
1210
- //
1211
- // or by the `id` and a `<relationship>Type` attribute:
1212
- //
1213
- // {
1214
- // message: 1,
1215
- // messageType: 'post'
1216
- // }
1217
- //
1218
- // The next code checks if the latter case is present and returns the
1219
- // corresponding JSON-API representation. The former case is handled within
1220
- // the base class JSONSerializer.
1221
- const isPolymorphic = relationshipMeta.options.polymorphic;
1222
- const typeProperty = this.keyForPolymorphicType(key, relationshipType, 'deserialize');
1223
- if (isPolymorphic && resourceHash[typeProperty] !== undefined && typeof relationshipHash !== 'object') {
1224
- const type = this.modelNameFromPayloadKey(resourceHash[typeProperty]);
1225
- return {
1226
- id: coerceId(relationshipHash),
1227
- type: type
1228
- };
1229
- }
1230
- // @ts-expect-error
1231
- return this._super(...arguments);
1232
- }
527
+ /**
528
+ `keyForPolymorphicType` can be used to define a custom key when
529
+ serializing and deserializing a polymorphic type. By default, the
530
+ returned key is `${key}Type`.
531
+ Example
532
+ ```js [app/serializers/post.js]
533
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
534
+ export default class ApplicationSerializer extends RESTSerializer {
535
+ keyForPolymorphicType(key, relationship) {
536
+ let relationshipKey = this.keyForRelationship(key);
537
+ return 'type-' + relationshipKey;
538
+ }
539
+ }
540
+ ```
541
+ @public
542
+ */
543
+ keyForPolymorphicType(key, type, method) {
544
+ return `${this.keyForRelationship(key)}Type`;
545
+ },
546
+ /**
547
+ Normalizes a part of the JSON payload returned by
548
+ the server. You should override this method, munge the hash
549
+ and call super if you have generic normalization to do.
550
+ It takes the type of the record that is being normalized
551
+ (as a Model class), the property where the hash was
552
+ originally found, and the hash to normalize.
553
+ For example, if you have a payload that looks like this:
554
+ ```js
555
+ {
556
+ "post": {
557
+ "id": 1,
558
+ "title": "Rails is omakase",
559
+ "comments": [ 1, 2 ]
560
+ },
561
+ "comments": [{
562
+ "id": 1,
563
+ "body": "FIRST"
564
+ }, {
565
+ "id": 2,
566
+ "body": "Rails is unagi"
567
+ }]
568
+ }
569
+ ```
570
+ The `normalize` method will be called three times:
571
+ * With `App.Post`, `"posts"` and `{ id: 1, title: "Rails is omakase", ... }`
572
+ * With `App.Comment`, `"comments"` and `{ id: 1, body: "FIRST" }`
573
+ * With `App.Comment`, `"comments"` and `{ id: 2, body: "Rails is unagi" }`
574
+ You can use this method, for example, to normalize underscored keys to camelized
575
+ or other general-purpose normalizations. You will only need to implement
576
+ `normalize` and manipulate the payload as desired.
577
+ For example, if the `IDs` under `"comments"` are provided as `_id` instead of
578
+ `id`, you can specify how to normalize just the comments:
579
+ ```js [app/serializers/post.js]
580
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
581
+ export default class ApplicationSerializer extends RESTSerializer {
582
+ normalize(model, hash, prop) {
583
+ if (prop === 'comments') {
584
+ hash.id = hash._id;
585
+ delete hash._id;
586
+ }
587
+ return super.normalize(...arguments);
588
+ }
589
+ }
590
+ ```
591
+ On each call to the `normalize` method, the third parameter (`prop`) is always
592
+ one of the keys that were in the original payload or in the result of another
593
+ normalization as `normalizeResponse`.
594
+ @public
595
+ @param {Model} modelClass
596
+ @param {Object} resourceHash
597
+ @param {String} prop
598
+ @return {Object}
599
+ */
600
+ /**
601
+ Normalizes an array of resource payloads and returns a JSON-API Document
602
+ with primary data and, if any, included data as `{ data, included }`.
603
+ @private
604
+ */
605
+ _normalizeArray(store, modelName, arrayHash, prop) {
606
+ const documentHash = {
607
+ data: [],
608
+ included: []
609
+ };
610
+ const modelClass = store.modelFor(modelName);
611
+ const serializer = store.serializerFor(modelName);
612
+ makeArray(arrayHash).forEach((hash) => {
613
+ const { data, included } = this._normalizePolymorphicRecord(store, hash, prop, modelClass, serializer);
614
+ documentHash.data.push(data);
615
+ if (included) documentHash.included = documentHash.included.concat(included);
616
+ });
617
+ return documentHash;
618
+ },
619
+ _normalizePolymorphicRecord(store, hash, prop, primaryModelClass, primarySerializer) {
620
+ let serializer = primarySerializer;
621
+ let modelClass = primaryModelClass;
622
+ if (!primaryModelClass.fields.has("type") && hash.type) {
623
+ const type = this.modelNameFromPayloadKey(hash.type);
624
+ if (store.schema.hasResource({ type })) {
625
+ serializer = store.serializerFor(type);
626
+ modelClass = store.modelFor(type);
627
+ }
628
+ }
629
+ return serializer.normalize(modelClass, hash, prop);
630
+ },
631
+ /**
632
+ @private
633
+ */
634
+ _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
635
+ const documentHash = {
636
+ data: null,
637
+ included: []
638
+ };
639
+ const meta = this.extractMeta(store, primaryModelClass, payload);
640
+ if (meta) {
641
+ ((test) => {
642
+ if (!test) throw new Error("The `meta` returned from `extractMeta` has to be an object, not \"" + typeof meta + "\".");
643
+ })(typeof meta === "object");
644
+ documentHash.meta = meta;
645
+ }
646
+ const keys = Object.keys(payload);
647
+ for (let i = 0, length = keys.length; i < length; i++) {
648
+ const prop = keys[i];
649
+ let modelName = prop;
650
+ let forcedSecondary = false;
651
+ if (prop.charAt(0) === "_") {
652
+ forcedSecondary = true;
653
+ modelName = prop.substr(1);
654
+ }
655
+ const type = this.modelNameFromPayloadKey(modelName);
656
+ if (!store.schema.hasResource({ type })) {
657
+ console.warn(this.warnMessageNoModelForKey(modelName, type), false, { id: "ds.serializer.model-for-key-missing" });
658
+ continue;
659
+ }
660
+ var isPrimary = !forcedSecondary && this.isPrimaryType(store, type, primaryModelClass);
661
+ const value = payload[prop];
662
+ if (value === null) continue;
663
+ ((test) => {
664
+ if (!test) throw new Error("The adapter returned an array for the primary data of a `queryRecord` response. `queryRecord` should return a single record.");
665
+ })(!(requestType === "queryRecord" && isPrimary && Array.isArray(value)));
666
+ if (isPrimary && !Array.isArray(value)) {
667
+ const { data, included } = this._normalizePolymorphicRecord(store, value, prop, primaryModelClass, this);
668
+ documentHash.data = data;
669
+ if (included) documentHash.included = documentHash.included.concat(included);
670
+ continue;
671
+ }
672
+ const { data, included } = this._normalizeArray(store, type, value, prop);
673
+ if (included) documentHash.included = documentHash.included.concat(included);
674
+ if (isSingle) data.forEach((resource) => {
675
+ const isUpdatedRecord = isPrimary && coerceId(resource.id) === id;
676
+ if (isPrimary && !id && !documentHash.data || isUpdatedRecord) documentHash.data = resource;
677
+ else documentHash.included.push(resource);
678
+ });
679
+ else if (isPrimary) documentHash.data = data;
680
+ else if (data) documentHash.included = documentHash.included.concat(data);
681
+ }
682
+ return documentHash;
683
+ },
684
+ isPrimaryType(store, modelName, primaryModelClass) {
685
+ return dasherize(modelName) === primaryModelClass.modelName;
686
+ },
687
+ /**
688
+ This method allows you to push a payload containing top-level
689
+ collections of records organized per type.
690
+ ```js
691
+ {
692
+ "posts": [{
693
+ "id": "1",
694
+ "title": "Rails is omakase",
695
+ "author", "1",
696
+ "comments": [ "1" ]
697
+ }],
698
+ "comments": [{
699
+ "id": "1",
700
+ "body": "FIRST"
701
+ }],
702
+ "users": [{
703
+ "id": "1",
704
+ "name": "@d2h"
705
+ }]
706
+ }
707
+ ```
708
+ It will first normalize the payload, so you can use this to push
709
+ in data streaming in from your server structured the same way
710
+ that fetches and saves are structured.
711
+ @public
712
+ */
713
+ pushPayload(store, payload) {
714
+ const documentHash = {
715
+ data: [],
716
+ included: []
717
+ };
718
+ for (const prop in payload) {
719
+ const type = this.modelNameFromPayloadKey(prop);
720
+ if (!store.schema.hasResource({ type })) {
721
+ console.warn(this.warnMessageNoModelForKey(prop, type), false, { id: "ds.serializer.model-for-key-missing" });
722
+ continue;
723
+ }
724
+ const ModelSchema = store.modelFor(type);
725
+ const typeSerializer = store.serializerFor(ModelSchema.modelName);
726
+ makeArray(payload[prop]).forEach((hash) => {
727
+ const { data, included } = typeSerializer.normalize(ModelSchema, hash, prop);
728
+ documentHash.data.push(data);
729
+ if (included) documentHash.included = documentHash.included.concat(included);
730
+ });
731
+ }
732
+ store.push(documentHash);
733
+ },
734
+ /**
735
+ This method is used to convert each JSON root key in the payload
736
+ into a modelName that it can use to look up the appropriate model for
737
+ that part of the payload.
738
+ For example, your server may send a model name that does not correspond with
739
+ the name of the model in your app. Let's take a look at an example model,
740
+ and an example payload:
741
+ ```js [app/models/post.js]
742
+ import Model from '@warp-drive/legacy/model';
743
+ export default class Post extends Model {}
744
+ ```
745
+ ```javascript
746
+ {
747
+ "blog/post": {
748
+ "id": "1
749
+ }
750
+ }
751
+ ```
752
+ Ember Data is going to normalize the payload's root key for the modelName. As a result,
753
+ it will try to look up the "blog/post" model. Since we don't have a model called "blog/post"
754
+ (or a file called app/models/blog/post.js in ember-cli), Ember Data will throw an error
755
+ because it cannot find the "blog/post" model.
756
+ Since we want to remove this namespace, we can define a serializer for the application that will
757
+ remove "blog/" from the payload key whenver it's encountered by Ember Data:
758
+ ```js [app/serializers/application.js]
759
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
760
+ export default class ApplicationSerializer extends RESTSerializer {
761
+ modelNameFromPayloadKey(payloadKey) {
762
+ if (payloadKey === 'blog/post') {
763
+ return super.modelNameFromPayloadKey(payloadKey.replace('blog/', ''));
764
+ } else {
765
+ return super.modelNameFromPayloadKey(payloadKey);
766
+ }
767
+ }
768
+ }
769
+ ```
770
+ After refreshing, Ember Data will appropriately look up the "post" model.
771
+ By default the modelName for a model is its
772
+ name in dasherized form. This means that a payload key like "blogPost" would be
773
+ normalized to "blog-post" when Ember Data looks up the model. Usually, Ember Data
774
+ can use the correct inflection to do this for you. Most of the time, you won't
775
+ need to override `modelNameFromPayloadKey` for this purpose.
776
+ @public
777
+ @return the model's modelName
778
+ */
779
+ modelNameFromPayloadKey(key) {
780
+ return dasherize(singularize(key));
781
+ },
782
+ /**
783
+ Called when a record is saved in order to convert the
784
+ record into JSON.
785
+ By default, it creates a JSON object with a key for
786
+ each attribute and belongsTo relationship.
787
+ For example, consider this model:
788
+ ```js [app/models/comment.js]
789
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
790
+ export default class Comment extends Model {
791
+ @attr title
792
+ @attr body
793
+ @belongsTo('user') author
794
+ }
795
+ ```
796
+ The default serialization would create a JSON object like:
797
+ ```js
798
+ {
799
+ "title": "Rails is unagi",
800
+ "body": "Rails? Omakase? O_O",
801
+ "author": 12
802
+ }
803
+ ```
804
+ By default, attributes are passed through as-is, unless
805
+ you specified an attribute type (`attr('date')`). If
806
+ you specify a transform, the JavaScript value will be
807
+ serialized when inserted into the JSON hash.
808
+ By default, belongs-to relationships are converted into
809
+ IDs when inserted into the JSON hash.
810
+ ## IDs
811
+ `serialize` takes an options hash with a single option:
812
+ `includeId`. If this option is `true`, `serialize` will,
813
+ by default include the ID in the JSON object it builds.
814
+ The RESTAdapter passes in `includeId: true` when serializing
815
+ a record for `createRecord`, but not for `updateRecord`.
816
+ ## Customization
817
+ Your server may expect a different JSON format than the
818
+ built-in serialization format.
819
+ In that case, you can implement `serialize` yourself and
820
+ return a JSON hash of your choosing.
821
+ ```js [app/serializers/post.js]
822
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
823
+ export default class ApplicationSerializer extends RESTSerializer {
824
+ serialize(snapshot, options) {
825
+ let json = {
826
+ POST_TTL: snapshot.attr('title'),
827
+ POST_BDY: snapshot.attr('body'),
828
+ POST_CMS: snapshot.hasMany('comments', { ids: true })
829
+ };
830
+ if (options.includeId) {
831
+ json.POST_ID_ = snapshot.id;
832
+ }
833
+ return json;
834
+ }
835
+ }
836
+ ```
837
+ ## Customizing an App-Wide Serializer
838
+ If you want to define a serializer for your entire
839
+ application, you'll probably want to use `eachAttribute`
840
+ and `eachRelationship` on the record.
841
+ ```js [app/serializers/application.js]
842
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
843
+ import { pluralize } from '<app-name>/utils/string-utils';
844
+ export default class ApplicationSerializer extends RESTSerializer {
845
+ serialize(snapshot, options) {
846
+ let json = {};
847
+ snapshot.eachAttribute(function(name) {
848
+ json[serverAttributeName(name)] = snapshot.attr(name);
849
+ });
850
+ snapshot.eachRelationship(function(name, relationship) {
851
+ if (relationship.kind === 'hasMany') {
852
+ json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
853
+ }
854
+ });
855
+ if (options.includeId) {
856
+ json.ID_ = snapshot.id;
857
+ }
858
+ return json;
859
+ }
860
+ }
861
+ function serverAttributeName(attribute) {
862
+ return attribute.underscore().toUpperCase();
863
+ }
864
+ function serverHasManyName(name) {
865
+ return serverAttributeName(singularize(name)) + "_IDS";
866
+ }
867
+ ```
868
+ This serializer will generate JSON that looks like this:
869
+ ```js
870
+ {
871
+ "TITLE": "Rails is omakase",
872
+ "BODY": "Yep. Omakase.",
873
+ "COMMENT_IDS": [ 1, 2, 3 ]
874
+ }
875
+ ```
876
+ ## Tweaking the Default JSON
877
+ If you just want to do some small tweaks on the default JSON,
878
+ you can call super first and make the tweaks on the returned
879
+ JSON.
880
+ ```js [app/serializers/post.js]
881
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
882
+ export default class ApplicationSerializer extends RESTSerializer {
883
+ serialize(snapshot, options) {
884
+ let json = super.serialize(snapshot, options);
885
+ json.subject = json.title;
886
+ delete json.title;
887
+ return json;
888
+ }
889
+ }
890
+ ```
891
+ @public
892
+ */
893
+ serialize(snapshot, options) {
894
+ return this._super(...arguments);
895
+ },
896
+ /**
897
+ You can use this method to customize the root keys serialized into the JSON.
898
+ The hash property should be modified by reference (possibly using something like _.extend)
899
+ By default the REST Serializer sends the modelName of a model, which is a camelized
900
+ version of the name.
901
+ For example, your server may expect underscored root objects.
902
+ ```js [app/serializers/application.js]
903
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
904
+ import { underscore } from '<app-name>/utils/string-utils';
905
+ export default class ApplicationSerializer extends RESTSerializer {
906
+ serializeIntoHash(data, type, record, options) {
907
+ let root = underscore(type.modelName);
908
+ data[root] = this.serialize(record, options);
909
+ }
910
+ }
911
+ ```
912
+ @public
913
+ */
914
+ serializeIntoHash(hash, typeClass, snapshot, options) {
915
+ const normalizedRootKey = this.payloadKeyFromModelName(typeClass.modelName);
916
+ hash[normalizedRootKey] = this.serialize(snapshot, options);
917
+ },
918
+ /**
919
+ You can use `payloadKeyFromModelName` to override the root key for an outgoing
920
+ request. By default, the RESTSerializer returns a camelized version of the
921
+ model's name.
922
+ For a model called TacoParty, its `modelName` would be the string `taco-party`. The RESTSerializer
923
+ will send it to the server with `tacoParty` as the root key in the JSON payload:
924
+ ```js
925
+ {
926
+ "tacoParty": {
927
+ "id": "1",
928
+ "location": "Matthew Beale's House"
929
+ }
930
+ }
931
+ ```
932
+ For example, your server may expect dasherized root objects:
933
+ ```js [app/serializers/application.js]
934
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
935
+ import { dasherize } from '<app-name>/utils/string-utils';
936
+ export default class ApplicationSerializer extends RESTSerializer {
937
+ payloadKeyFromModelName(modelName) {
938
+ return dasherize(modelName);
939
+ }
940
+ }
941
+ ```
942
+ Given a `TacoParty` model, calling `save` on it would produce an outgoing
943
+ request like:
944
+ ```js
945
+ {
946
+ "taco-party": {
947
+ "id": "1",
948
+ "location": "Matthew Beale's House"
949
+ }
950
+ }
951
+ ```
952
+ @public
953
+ */
954
+ payloadKeyFromModelName(modelName) {
955
+ return camelize(modelName);
956
+ },
957
+ /**
958
+ You can use this method to customize how polymorphic objects are serialized.
959
+ By default the REST Serializer creates the key by appending `Type` to
960
+ the attribute and value from the model's camelcased model name.
961
+ @public
962
+ */
963
+ serializePolymorphicType(snapshot, json, relationship) {
964
+ const name = relationship.name;
965
+ const typeKey = this.keyForPolymorphicType(name, relationship.type, "serialize");
966
+ const belongsTo = snapshot.belongsTo(name);
967
+ if (!belongsTo) json[typeKey] = null;
968
+ else json[typeKey] = camelize(belongsTo.modelName);
969
+ },
970
+ /**
971
+ You can use this method to customize how a polymorphic relationship should
972
+ be extracted.
973
+ @public
974
+ @param {Object} relationshipType
975
+ @param {Object} relationshipHash
976
+ @param {Object} relationshipOptions
977
+ @return {Object}
978
+ */
979
+ extractPolymorphicRelationship(relationshipType, relationshipHash, relationshipOptions) {
980
+ const { key, resourceHash, relationshipMeta } = relationshipOptions;
981
+ const isPolymorphic = relationshipMeta.options.polymorphic;
982
+ const typeProperty = this.keyForPolymorphicType(key, relationshipType, "deserialize");
983
+ if (isPolymorphic && resourceHash[typeProperty] !== void 0 && typeof relationshipHash !== "object") {
984
+ const type = this.modelNameFromPayloadKey(resourceHash[typeProperty]);
985
+ return {
986
+ id: coerceId(relationshipHash),
987
+ type
988
+ };
989
+ }
990
+ return this._super(...arguments);
991
+ }
1233
992
  });
1234
- {
1235
- RESTSerializer.reopen({
1236
- warnMessageNoModelForKey(prop, typeKey) {
1237
- return 'Encountered "' + prop + '" in payload, but no model was found for model name "' + typeKey + '" (resolved model name using ' + this.constructor.toString() + '.modelNameFromPayloadKey("' + prop + '"))';
1238
- }
1239
- });
1240
- }
1241
- export { EmbeddedRecordsMixin, RESTSerializer };
993
+ RESTSerializer.reopen({ warnMessageNoModelForKey(prop, typeKey) {
994
+ return "Encountered \"" + prop + "\" in payload, but no model was found for model name \"" + typeKey + "\" (resolved model name using " + this.constructor.toString() + ".modelNameFromPayloadKey(\"" + prop + "\"))";
995
+ } });
996
+
997
+ //#endregion
998
+ export { EmbeddedRecordsMixin, RESTSerializer };
999
+ //# sourceMappingURL=rest.js.map