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

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