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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (467) hide show
  1. package/dist/-private-DQ6Iap2t.js +193 -0
  2. package/dist/-private-DQ6Iap2t.js.map +1 -0
  3. package/dist/-private-DccRZQsm.js +904 -0
  4. package/dist/-private-DccRZQsm.js.map +1 -0
  5. package/dist/adapter/-private.d.ts +33 -0
  6. package/dist/adapter/-private.d.ts.map +1 -0
  7. package/dist/adapter/-private.js +3 -1
  8. package/dist/adapter/error.d.ts +2 -0
  9. package/dist/adapter/error.js +422 -453
  10. package/dist/adapter/error.js.map +1 -0
  11. package/{declarations → dist}/adapter/json-api.d.ts +30 -29
  12. package/dist/adapter/json-api.d.ts.map +1 -0
  13. package/dist/adapter/json-api.js +265 -143
  14. package/dist/adapter/json-api.js.map +1 -0
  15. package/dist/adapter/rest.d.ts +2 -0
  16. package/dist/adapter/rest.js +937 -1136
  17. package/dist/adapter/rest.js.map +1 -0
  18. package/dist/adapter-CARrK3-8.d.ts +784 -0
  19. package/dist/adapter-CARrK3-8.d.ts.map +1 -0
  20. package/dist/adapter-XgLAkYVs.js +1130 -0
  21. package/dist/adapter-XgLAkYVs.js.map +1 -0
  22. package/dist/adapter.d.ts +2 -0
  23. package/dist/adapter.js +1 -1248
  24. package/dist/compat/-private.d.ts +2 -0
  25. package/dist/compat/-private.js +3 -1
  26. package/dist/compat/builders.d.ts +169 -0
  27. package/dist/compat/builders.d.ts.map +1 -0
  28. package/dist/compat/builders.js +205 -245
  29. package/dist/compat/builders.js.map +1 -0
  30. package/dist/compat/extensions.d.ts +2 -0
  31. package/dist/compat/extensions.js +265 -304
  32. package/dist/compat/extensions.js.map +1 -0
  33. package/dist/compat/utils.d.ts +151 -0
  34. package/dist/compat/utils.d.ts.map +1 -0
  35. package/dist/compat/utils.js +187 -206
  36. package/dist/compat/utils.js.map +1 -0
  37. package/dist/compat-BbNNmTM-.d.ts +1386 -0
  38. package/dist/compat-BbNNmTM-.d.ts.map +1 -0
  39. package/dist/compat-g__Pfy2S.js +734 -0
  40. package/dist/compat-g__Pfy2S.js.map +1 -0
  41. package/dist/compat.d.ts +2 -0
  42. package/dist/compat.js +1 -1036
  43. package/dist/error-CzkyXr1Q.d.ts +435 -0
  44. package/dist/error-CzkyXr1Q.d.ts.map +1 -0
  45. package/dist/errors-LQhmDVdd.js +2134 -0
  46. package/dist/errors-LQhmDVdd.js.map +1 -0
  47. package/dist/extensions-DumNm4dA.d.ts +102 -0
  48. package/dist/extensions-DumNm4dA.d.ts.map +1 -0
  49. package/dist/index.d.ts +243 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +267 -339
  52. package/dist/index.js.map +1 -0
  53. package/dist/json-BXNPTlcH.js +1106 -0
  54. package/dist/json-BXNPTlcH.js.map +1 -0
  55. package/dist/model/-private.d.ts +3 -0
  56. package/dist/model/-private.js +3 -1
  57. package/dist/model/migration-support.d.ts +335 -0
  58. package/dist/model/migration-support.d.ts.map +1 -0
  59. package/dist/model/migration-support.js +504 -575
  60. package/dist/model/migration-support.js.map +1 -0
  61. package/dist/model-62hn5_PD.d.ts +3107 -0
  62. package/dist/model-62hn5_PD.d.ts.map +1 -0
  63. package/dist/model-BtIEHqYZ.js +683 -0
  64. package/dist/model-BtIEHqYZ.js.map +1 -0
  65. package/dist/model-fragments-Dpn9285r.js +334 -0
  66. package/dist/model-fragments-Dpn9285r.js.map +1 -0
  67. package/dist/model-fragments.d.ts +294 -0
  68. package/dist/model-fragments.d.ts.map +1 -0
  69. package/dist/model-fragments.js +2 -94
  70. package/dist/model.d.ts +404 -0
  71. package/dist/model.d.ts.map +1 -0
  72. package/dist/model.js +3 -670
  73. package/{declarations/adapter/rest.d.ts → dist/rest-0NhtexIq.d.ts} +183 -173
  74. package/dist/rest-0NhtexIq.d.ts.map +1 -0
  75. package/dist/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  76. package/dist/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  77. package/dist/schema-provider-DsKuB5Wb.js +1929 -0
  78. package/dist/schema-provider-DsKuB5Wb.js.map +1 -0
  79. package/{declarations → dist}/serializer/json-api.d.ts +3 -0
  80. package/dist/serializer/json-api.d.ts.map +1 -0
  81. package/dist/serializer/json-api.js +527 -519
  82. package/dist/serializer/json-api.js.map +1 -0
  83. package/{declarations → dist}/serializer/json.d.ts +3 -0
  84. package/dist/serializer/json.d.ts.map +1 -0
  85. package/dist/serializer/json.js +3 -6
  86. package/{declarations/serializer/-private/embedded-records-mixin.d.ts → dist/serializer/rest.d.ts} +56 -1
  87. package/dist/serializer/rest.d.ts.map +1 -0
  88. package/dist/serializer/rest.js +958 -1199
  89. package/dist/serializer/rest.js.map +1 -0
  90. package/dist/serializer/transform.d.ts +313 -0
  91. package/dist/serializer/transform.d.ts.map +1 -0
  92. package/dist/serializer/transform.js +283 -308
  93. package/dist/serializer/transform.js.map +1 -0
  94. package/dist/serializer.d.ts +151 -0
  95. package/dist/serializer.d.ts.map +1 -0
  96. package/dist/serializer.js +205 -205
  97. package/dist/serializer.js.map +1 -0
  98. package/dist/store-C4qYzXei.js +473 -0
  99. package/dist/store-C4qYzXei.js.map +1 -0
  100. package/dist/store.d.ts +13 -0
  101. package/dist/store.d.ts.map +1 -0
  102. package/dist/store.js +1 -641
  103. package/dist/unpkg/dev/-private-CrEyBE-B.js +189 -0
  104. package/dist/unpkg/dev/-private-CrEyBE-B.js.map +1 -0
  105. package/dist/unpkg/dev/-private-vOhxVExH.js +896 -0
  106. package/dist/unpkg/dev/-private-vOhxVExH.js.map +1 -0
  107. package/dist/unpkg/dev/adapter/-private.js +3 -1
  108. package/dist/unpkg/dev/adapter/error.js +421 -452
  109. package/dist/unpkg/dev/adapter/error.js.map +1 -0
  110. package/dist/unpkg/dev/adapter/json-api.js +239 -257
  111. package/dist/unpkg/dev/adapter/json-api.js.map +1 -0
  112. package/dist/unpkg/dev/adapter/rest.js +935 -1134
  113. package/dist/unpkg/dev/adapter/rest.js.map +1 -0
  114. package/dist/unpkg/dev/adapter-Cw0uSl8d.js +1129 -0
  115. package/dist/unpkg/dev/adapter-Cw0uSl8d.js.map +1 -0
  116. package/dist/unpkg/dev/adapter.js +1 -1247
  117. package/dist/unpkg/dev/compat/-private.js +3 -1
  118. package/dist/unpkg/dev/compat/builders.js +204 -247
  119. package/dist/unpkg/dev/compat/builders.js.map +1 -0
  120. package/dist/unpkg/dev/compat/extensions.js +264 -303
  121. package/dist/unpkg/dev/compat/extensions.js.map +1 -0
  122. package/dist/unpkg/dev/compat/utils.js +186 -205
  123. package/dist/unpkg/dev/compat/utils.js.map +1 -0
  124. package/dist/unpkg/dev/compat-CeyxXB7K.js +825 -0
  125. package/dist/unpkg/dev/compat-CeyxXB7K.js.map +1 -0
  126. package/dist/unpkg/dev/compat.js +1 -1178
  127. package/dist/unpkg/dev/errors-1javxsPo.js +2127 -0
  128. package/dist/unpkg/dev/errors-1javxsPo.js.map +1 -0
  129. package/dist/unpkg/dev/index.js +266 -344
  130. package/dist/unpkg/dev/index.js.map +1 -0
  131. package/dist/unpkg/dev/json-DDJji3V3.js +1104 -0
  132. package/dist/unpkg/dev/json-DDJji3V3.js.map +1 -0
  133. package/dist/unpkg/dev/model/-private.js +3 -1
  134. package/dist/unpkg/dev/model/migration-support.js +481 -549
  135. package/dist/unpkg/dev/model/migration-support.js.map +1 -0
  136. package/dist/unpkg/dev/model-C9Xb1R1x.js +655 -0
  137. package/dist/unpkg/dev/model-C9Xb1R1x.js.map +1 -0
  138. package/dist/unpkg/dev/model-fragments-Dpn9285r.js +334 -0
  139. package/dist/unpkg/dev/model-fragments-Dpn9285r.js.map +1 -0
  140. package/dist/unpkg/dev/model-fragments.js +2 -94
  141. package/dist/unpkg/dev/model.js +3 -681
  142. package/dist/unpkg/dev/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  143. package/dist/unpkg/dev/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  144. package/dist/unpkg/dev/schema-provider-Dy6c1J5f.js +1834 -0
  145. package/dist/unpkg/dev/schema-provider-Dy6c1J5f.js.map +1 -0
  146. package/dist/unpkg/dev/serializer/json-api.js +514 -634
  147. package/dist/unpkg/dev/serializer/json-api.js.map +1 -0
  148. package/dist/unpkg/dev/serializer/json.js +3 -4
  149. package/dist/unpkg/dev/serializer/rest.js +954 -1196
  150. package/dist/unpkg/dev/serializer/rest.js.map +1 -0
  151. package/dist/unpkg/dev/serializer/transform.js +283 -308
  152. package/dist/unpkg/dev/serializer/transform.js.map +1 -0
  153. package/dist/unpkg/dev/serializer.js +205 -205
  154. package/dist/unpkg/dev/serializer.js.map +1 -0
  155. package/dist/unpkg/dev/store-D_V8-HQl.js +472 -0
  156. package/dist/unpkg/dev/store-D_V8-HQl.js.map +1 -0
  157. package/dist/unpkg/dev/store.js +1 -649
  158. package/dist/unpkg/dev/util-dSKEgQDp.js +12 -0
  159. package/dist/unpkg/dev/util-dSKEgQDp.js.map +1 -0
  160. package/dist/unpkg/dev/utils-DYC9utVJ.js +11 -0
  161. package/dist/unpkg/dev/utils-DYC9utVJ.js.map +1 -0
  162. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js +189 -0
  163. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js.map +1 -0
  164. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js +896 -0
  165. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js.map +1 -0
  166. package/dist/unpkg/dev-deprecated/adapter/-private.js +3 -1
  167. package/dist/unpkg/dev-deprecated/adapter/error.js +421 -452
  168. package/dist/unpkg/dev-deprecated/adapter/error.js.map +1 -0
  169. package/dist/unpkg/dev-deprecated/adapter/json-api.js +239 -257
  170. package/dist/unpkg/dev-deprecated/adapter/json-api.js.map +1 -0
  171. package/dist/unpkg/dev-deprecated/adapter/rest.js +935 -1134
  172. package/dist/unpkg/dev-deprecated/adapter/rest.js.map +1 -0
  173. package/dist/unpkg/dev-deprecated/adapter-Cw0uSl8d.js +1129 -0
  174. package/dist/unpkg/dev-deprecated/adapter-Cw0uSl8d.js.map +1 -0
  175. package/dist/unpkg/dev-deprecated/adapter.js +1 -1247
  176. package/dist/unpkg/dev-deprecated/compat/-private.js +3 -1
  177. package/dist/unpkg/dev-deprecated/compat/builders.js +204 -247
  178. package/dist/unpkg/dev-deprecated/compat/builders.js.map +1 -0
  179. package/dist/unpkg/dev-deprecated/compat/extensions.js +264 -303
  180. package/dist/unpkg/dev-deprecated/compat/extensions.js.map +1 -0
  181. package/dist/unpkg/dev-deprecated/compat/utils.js +186 -205
  182. package/dist/unpkg/dev-deprecated/compat/utils.js.map +1 -0
  183. package/dist/unpkg/dev-deprecated/compat-DmAgB2NS.js +825 -0
  184. package/dist/unpkg/dev-deprecated/compat-DmAgB2NS.js.map +1 -0
  185. package/dist/unpkg/dev-deprecated/compat.js +1 -1178
  186. package/dist/unpkg/dev-deprecated/errors-C4_aOhY5.js +2128 -0
  187. package/dist/unpkg/dev-deprecated/errors-C4_aOhY5.js.map +1 -0
  188. package/dist/unpkg/dev-deprecated/index.js +266 -343
  189. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  190. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js +1104 -0
  191. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js.map +1 -0
  192. package/dist/unpkg/dev-deprecated/model/-private.js +3 -1
  193. package/dist/unpkg/dev-deprecated/model/migration-support.js +492 -566
  194. package/dist/unpkg/dev-deprecated/model/migration-support.js.map +1 -0
  195. package/dist/unpkg/dev-deprecated/model-CvSMYkgs.js +660 -0
  196. package/dist/unpkg/dev-deprecated/model-CvSMYkgs.js.map +1 -0
  197. package/dist/unpkg/dev-deprecated/model-fragments-Dpn9285r.js +334 -0
  198. package/dist/unpkg/dev-deprecated/model-fragments-Dpn9285r.js.map +1 -0
  199. package/dist/unpkg/dev-deprecated/model-fragments.js +2 -94
  200. package/dist/unpkg/dev-deprecated/model.js +3 -685
  201. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  202. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  203. package/dist/unpkg/dev-deprecated/schema-provider-Cqttza94.js +1835 -0
  204. package/dist/unpkg/dev-deprecated/schema-provider-Cqttza94.js.map +1 -0
  205. package/dist/unpkg/dev-deprecated/serializer/json-api.js +514 -634
  206. package/dist/unpkg/dev-deprecated/serializer/json-api.js.map +1 -0
  207. package/dist/unpkg/dev-deprecated/serializer/json.js +3 -4
  208. package/dist/unpkg/dev-deprecated/serializer/rest.js +954 -1196
  209. package/dist/unpkg/dev-deprecated/serializer/rest.js.map +1 -0
  210. package/dist/unpkg/dev-deprecated/serializer/transform.js +283 -308
  211. package/dist/unpkg/dev-deprecated/serializer/transform.js.map +1 -0
  212. package/dist/unpkg/dev-deprecated/serializer.js +205 -205
  213. package/dist/unpkg/dev-deprecated/serializer.js.map +1 -0
  214. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js +472 -0
  215. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js.map +1 -0
  216. package/dist/unpkg/dev-deprecated/store.js +1 -649
  217. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js +18 -0
  218. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js.map +1 -0
  219. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js +17 -0
  220. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js.map +1 -0
  221. package/dist/unpkg/prod/-private-B4bxoTuK.js +160 -0
  222. package/dist/unpkg/prod/-private-B4bxoTuK.js.map +1 -0
  223. package/dist/unpkg/prod/-private-SfXkkHKd.js +745 -0
  224. package/dist/unpkg/prod/-private-SfXkkHKd.js.map +1 -0
  225. package/dist/unpkg/prod/adapter/-private.js +3 -1
  226. package/dist/unpkg/prod/adapter/error.js +418 -447
  227. package/dist/unpkg/prod/adapter/error.js.map +1 -0
  228. package/dist/unpkg/prod/adapter/json-api.js +236 -252
  229. package/dist/unpkg/prod/adapter/json-api.js.map +1 -0
  230. package/dist/unpkg/prod/adapter/rest.js +911 -1097
  231. package/dist/unpkg/prod/adapter/rest.js.map +1 -0
  232. package/dist/unpkg/prod/adapter-Wnk7jizX.js +1111 -0
  233. package/dist/unpkg/prod/adapter-Wnk7jizX.js.map +1 -0
  234. package/dist/unpkg/prod/adapter.js +1 -1214
  235. package/dist/unpkg/prod/compat/-private.js +3 -1
  236. package/dist/unpkg/prod/compat/builders.js +165 -182
  237. package/dist/unpkg/prod/compat/builders.js.map +1 -0
  238. package/dist/unpkg/prod/compat/extensions.js +252 -283
  239. package/dist/unpkg/prod/compat/extensions.js.map +1 -0
  240. package/dist/unpkg/prod/compat/utils.js +183 -200
  241. package/dist/unpkg/prod/compat/utils.js.map +1 -0
  242. package/dist/unpkg/prod/compat-CJ87MzDn.js +547 -0
  243. package/dist/unpkg/prod/compat-CJ87MzDn.js.map +1 -0
  244. package/dist/unpkg/prod/compat.js +1 -742
  245. package/dist/unpkg/prod/errors-Co7YWHoA.js +1977 -0
  246. package/dist/unpkg/prod/errors-Co7YWHoA.js.map +1 -0
  247. package/dist/unpkg/prod/index.js +245 -308
  248. package/dist/unpkg/prod/index.js.map +1 -0
  249. package/dist/unpkg/prod/json-BD1kRTfB.js +1080 -0
  250. package/dist/unpkg/prod/json-BD1kRTfB.js.map +1 -0
  251. package/dist/unpkg/prod/model/-private.js +3 -1
  252. package/dist/unpkg/prod/model/migration-support.js +477 -542
  253. package/dist/unpkg/prod/model/migration-support.js.map +1 -0
  254. package/dist/unpkg/prod/model-BzoOmtka.js +603 -0
  255. package/dist/unpkg/prod/model-BzoOmtka.js.map +1 -0
  256. package/dist/unpkg/prod/model-fragments-Dpn9285r.js +334 -0
  257. package/dist/unpkg/prod/model-fragments-Dpn9285r.js.map +1 -0
  258. package/dist/unpkg/prod/model-fragments.js +2 -94
  259. package/dist/unpkg/prod/model.js +3 -596
  260. package/dist/unpkg/prod/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  261. package/dist/unpkg/prod/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  262. package/dist/unpkg/prod/schema-provider-CKZcqWyP.js +1622 -0
  263. package/dist/unpkg/prod/schema-provider-CKZcqWyP.js.map +1 -0
  264. package/dist/unpkg/prod/serializer/json-api.js +497 -592
  265. package/dist/unpkg/prod/serializer/json-api.js.map +1 -0
  266. package/dist/unpkg/prod/serializer/json.js +3 -4
  267. package/dist/unpkg/prod/serializer/rest.js +938 -1166
  268. package/dist/unpkg/prod/serializer/rest.js.map +1 -0
  269. package/dist/unpkg/prod/serializer/transform.js +283 -308
  270. package/dist/unpkg/prod/serializer/transform.js.map +1 -0
  271. package/dist/unpkg/prod/serializer.js +205 -205
  272. package/dist/unpkg/prod/serializer.js.map +1 -0
  273. package/dist/unpkg/prod/store-RGGc1ilN.js +392 -0
  274. package/dist/unpkg/prod/store-RGGc1ilN.js.map +1 -0
  275. package/dist/unpkg/prod/store.js +1 -517
  276. package/dist/unpkg/prod/util-dSKEgQDp.js +12 -0
  277. package/dist/unpkg/prod/util-dSKEgQDp.js.map +1 -0
  278. package/dist/unpkg/prod/utils-DYC9utVJ.js +11 -0
  279. package/dist/unpkg/prod/utils-DYC9utVJ.js.map +1 -0
  280. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js +160 -0
  281. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js.map +1 -0
  282. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js +745 -0
  283. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js.map +1 -0
  284. package/dist/unpkg/prod-deprecated/adapter/-private.js +3 -1
  285. package/dist/unpkg/prod-deprecated/adapter/error.js +418 -447
  286. package/dist/unpkg/prod-deprecated/adapter/error.js.map +1 -0
  287. package/dist/unpkg/prod-deprecated/adapter/json-api.js +236 -252
  288. package/dist/unpkg/prod-deprecated/adapter/json-api.js.map +1 -0
  289. package/dist/unpkg/prod-deprecated/adapter/rest.js +911 -1097
  290. package/dist/unpkg/prod-deprecated/adapter/rest.js.map +1 -0
  291. package/{declarations/adapter.d.ts → dist/unpkg/prod-deprecated/adapter-Wnk7jizX.js} +445 -110
  292. package/dist/unpkg/prod-deprecated/adapter-Wnk7jizX.js.map +1 -0
  293. package/dist/unpkg/prod-deprecated/adapter.js +1 -1214
  294. package/dist/unpkg/prod-deprecated/compat/-private.js +3 -1
  295. package/dist/unpkg/prod-deprecated/compat/builders.js +165 -182
  296. package/dist/unpkg/prod-deprecated/compat/builders.js.map +1 -0
  297. package/dist/unpkg/prod-deprecated/compat/extensions.js +252 -283
  298. package/dist/unpkg/prod-deprecated/compat/extensions.js.map +1 -0
  299. package/dist/unpkg/prod-deprecated/compat/utils.js +183 -200
  300. package/dist/unpkg/prod-deprecated/compat/utils.js.map +1 -0
  301. package/dist/unpkg/prod-deprecated/compat-CJ87MzDn.js +547 -0
  302. package/dist/unpkg/prod-deprecated/compat-CJ87MzDn.js.map +1 -0
  303. package/dist/unpkg/prod-deprecated/compat.js +1 -742
  304. package/dist/unpkg/prod-deprecated/errors-C-opde61.js +1978 -0
  305. package/dist/unpkg/prod-deprecated/errors-C-opde61.js.map +1 -0
  306. package/dist/unpkg/prod-deprecated/index.js +245 -307
  307. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  308. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js +1080 -0
  309. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js.map +1 -0
  310. package/dist/unpkg/prod-deprecated/model/-private.js +3 -1
  311. package/dist/unpkg/prod-deprecated/model/migration-support.js +488 -559
  312. package/dist/unpkg/prod-deprecated/model/migration-support.js.map +1 -0
  313. package/dist/unpkg/prod-deprecated/model-C0bTXzGn.js +604 -0
  314. package/dist/unpkg/prod-deprecated/model-C0bTXzGn.js.map +1 -0
  315. package/dist/unpkg/prod-deprecated/model-fragments-Dpn9285r.js +334 -0
  316. package/dist/unpkg/prod-deprecated/model-fragments-Dpn9285r.js.map +1 -0
  317. package/dist/unpkg/prod-deprecated/model-fragments.js +2 -94
  318. package/dist/unpkg/prod-deprecated/model.js +3 -599
  319. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js +53 -0
  320. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  321. package/dist/unpkg/prod-deprecated/schema-provider-lH3qP5tw.js +1635 -0
  322. package/dist/unpkg/prod-deprecated/schema-provider-lH3qP5tw.js.map +1 -0
  323. package/dist/unpkg/prod-deprecated/serializer/json-api.js +497 -592
  324. package/dist/unpkg/prod-deprecated/serializer/json-api.js.map +1 -0
  325. package/dist/unpkg/prod-deprecated/serializer/json.js +3 -4
  326. package/dist/unpkg/prod-deprecated/serializer/rest.js +938 -1166
  327. package/dist/unpkg/prod-deprecated/serializer/rest.js.map +1 -0
  328. package/dist/unpkg/prod-deprecated/serializer/transform.js +283 -308
  329. package/dist/unpkg/prod-deprecated/serializer/transform.js.map +1 -0
  330. package/dist/unpkg/prod-deprecated/serializer.js +205 -205
  331. package/dist/unpkg/prod-deprecated/serializer.js.map +1 -0
  332. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js +392 -0
  333. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js.map +1 -0
  334. package/dist/unpkg/prod-deprecated/store.js +1 -517
  335. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js +14 -0
  336. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js.map +1 -0
  337. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js +13 -0
  338. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js.map +1 -0
  339. package/dist/util-Bnx8nm-D.js +29 -0
  340. package/dist/util-Bnx8nm-D.js.map +1 -0
  341. package/dist/utils-ZAytYep8.js +28 -0
  342. package/dist/utils-ZAytYep8.js.map +1 -0
  343. package/package.json +13 -13
  344. package/declarations/adapter/-private/build-url-mixin.d.ts +0 -189
  345. package/declarations/adapter/-private/fastboot-interface.d.ts +0 -8
  346. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +0 -1
  347. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +0 -4
  348. package/declarations/adapter/-private/utils/fetch.d.ts +0 -8
  349. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
  350. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +0 -6
  351. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -5
  352. package/declarations/adapter/-private.d.ts +0 -5
  353. package/declarations/adapter/error.d.ts +0 -431
  354. package/declarations/compat/-private.d.ts +0 -13
  355. package/declarations/compat/builders/find-all.d.ts +0 -34
  356. package/declarations/compat/builders/find-record.d.ts +0 -56
  357. package/declarations/compat/builders/query.d.ts +0 -66
  358. package/declarations/compat/builders/save-record.d.ts +0 -34
  359. package/declarations/compat/builders/utils.d.ts +0 -3
  360. package/declarations/compat/builders.d.ts +0 -14
  361. package/declarations/compat/extensions.d.ts +0 -99
  362. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +0 -55
  363. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +0 -2
  364. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +0 -11
  365. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +0 -5
  366. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +0 -9
  367. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +0 -528
  368. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +0 -220
  369. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +0 -6
  370. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +0 -110
  371. package/declarations/compat/legacy-network-handler/snapshot.d.ts +0 -255
  372. package/declarations/compat/utils.d.ts +0 -148
  373. package/declarations/compat.d.ts +0 -189
  374. package/declarations/index.d.ts +0 -244
  375. package/declarations/model/-private/attr.d.ts +0 -191
  376. package/declarations/model/-private/belongs-to.d.ts +0 -195
  377. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +0 -5
  378. package/declarations/model/-private/errors.d.ts +0 -289
  379. package/declarations/model/-private/has-many.d.ts +0 -162
  380. package/declarations/model/-private/hooks.d.ts +0 -36
  381. package/declarations/model/-private/legacy-relationships-support.d.ts +0 -47
  382. package/declarations/model/-private/model-for-mixin.d.ts +0 -3
  383. package/declarations/model/-private/model-methods.d.ts +0 -39
  384. package/declarations/model/-private/model.d.ts +0 -1279
  385. package/declarations/model/-private/notify-changes.d.ts +0 -4
  386. package/declarations/model/-private/promise-belongs-to.d.ts +0 -40
  387. package/declarations/model/-private/promise-many-array.d.ts +0 -130
  388. package/declarations/model/-private/record-state.d.ts +0 -58
  389. package/declarations/model/-private/references/belongs-to.d.ts +0 -488
  390. package/declarations/model/-private/references/has-many.d.ts +0 -498
  391. package/declarations/model/-private/schema-provider.d.ts +0 -66
  392. package/declarations/model/-private/type-utils.d.ts +0 -57
  393. package/declarations/model/-private/util.d.ts +0 -5
  394. package/declarations/model/-private.d.ts +0 -8
  395. package/declarations/model/migration-support.d.ts +0 -306
  396. package/declarations/model-fragments/extensions/fragment-array.d.ts +0 -54
  397. package/declarations/model-fragments/extensions/fragment.d.ts +0 -50
  398. package/declarations/model-fragments/hooks/model-for.d.ts +0 -27
  399. package/declarations/model-fragments/index.d.ts +0 -13
  400. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +0 -15
  401. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +0 -56
  402. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +0 -38
  403. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +0 -34
  404. package/declarations/model-fragments/utilities/with-legacy.d.ts +0 -11
  405. package/declarations/model-fragments.d.ts +0 -9
  406. package/declarations/model.d.ts +0 -49
  407. package/declarations/serializer/-private/transforms/boolean.d.ts +0 -60
  408. package/declarations/serializer/-private/transforms/date.d.ts +0 -42
  409. package/declarations/serializer/-private/transforms/number.d.ts +0 -42
  410. package/declarations/serializer/-private/transforms/string.d.ts +0 -42
  411. package/declarations/serializer/-private/transforms/transform.d.ts +0 -118
  412. package/declarations/serializer/-private/utils.d.ts +0 -27
  413. package/declarations/serializer/rest.d.ts +0 -51
  414. package/declarations/serializer/transform.d.ts +0 -5
  415. package/declarations/serializer.d.ts +0 -252
  416. package/declarations/store/-private.d.ts +0 -223
  417. package/declarations/store.d.ts +0 -10
  418. package/dist/-private-BG3bMiKp.js +0 -1211
  419. package/dist/errors-DZKA206g.js +0 -2589
  420. package/dist/hooks-BvOqJBei.js +0 -105
  421. package/dist/json-DU8m1pGf.js +0 -1336
  422. package/dist/model-for-CXkJw59V.js +0 -297
  423. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  424. package/dist/schema-provider-DtPOp0d7.js +0 -2382
  425. package/dist/serialize-into-hash-DPZYoF-i.js +0 -261
  426. package/dist/unpkg/dev/-private-DtjBbEgy.js +0 -1206
  427. package/dist/unpkg/dev/errors-DngRU-If.js +0 -2585
  428. package/dist/unpkg/dev/hooks-UuiLxWxS.js +0 -104
  429. package/dist/unpkg/dev/json-K2Y9z6MN.js +0 -1333
  430. package/dist/unpkg/dev/model-for-CXkJw59V.js +0 -297
  431. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  432. package/dist/unpkg/dev/schema-provider-0D7f-QOn.js +0 -2272
  433. package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +0 -259
  434. package/dist/unpkg/dev/util-DvanW33H.js +0 -20
  435. package/dist/unpkg/dev/utils-BhvS1iTS.js +0 -8
  436. package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +0 -1206
  437. package/dist/unpkg/dev-deprecated/errors-Bzidntpi.js +0 -2588
  438. package/dist/unpkg/dev-deprecated/hooks-DVXhMW14.js +0 -104
  439. package/dist/unpkg/dev-deprecated/json-K2Y9z6MN.js +0 -1333
  440. package/dist/unpkg/dev-deprecated/model-for-CXkJw59V.js +0 -297
  441. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  442. package/dist/unpkg/dev-deprecated/schema-provider-ZwO5_fZw.js +0 -2292
  443. package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +0 -259
  444. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +0 -24
  445. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +0 -12
  446. package/dist/unpkg/prod/-private-BdyZaGEh.js +0 -971
  447. package/dist/unpkg/prod/errors-B-PWeYlW.js +0 -2337
  448. package/dist/unpkg/prod/hooks-Bx-zBziU.js +0 -72
  449. package/dist/unpkg/prod/json-Qewu-UN9.js +0 -1300
  450. package/dist/unpkg/prod/model-for-CXkJw59V.js +0 -297
  451. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  452. package/dist/unpkg/prod/schema-provider-BgRqk8i9.js +0 -1951
  453. package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +0 -215
  454. package/dist/unpkg/prod/util-DvanW33H.js +0 -20
  455. package/dist/unpkg/prod/utils-BhvS1iTS.js +0 -8
  456. package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +0 -971
  457. package/dist/unpkg/prod-deprecated/errors-Dl2J9d1D.js +0 -2340
  458. package/dist/unpkg/prod-deprecated/hooks-Cm60wWTf.js +0 -72
  459. package/dist/unpkg/prod-deprecated/json-Qewu-UN9.js +0 -1300
  460. package/dist/unpkg/prod-deprecated/model-for-CXkJw59V.js +0 -297
  461. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  462. package/dist/unpkg/prod-deprecated/schema-provider-Dh6tRqVI.js +0 -1980
  463. package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +0 -215
  464. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +0 -23
  465. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +0 -11
  466. package/dist/util-Dul6TZts.js +0 -35
  467. package/dist/utils-Cqw9eRj5.js +0 -23
@@ -1,597 +1,502 @@
1
- import { dasherize, pluralize, singularize } from '@warp-drive/utilities/string';
2
- import { J as JSONSerializer } from "../json-Qewu-UN9.js";
3
-
4
- /* eslint-disable @typescript-eslint/no-unsafe-return */
5
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
6
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
7
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
8
- /* eslint-disable @typescript-eslint/no-unsafe-call */
1
+ import { t as JSONSerializer } from "../json-BD1kRTfB.js";
2
+ import { dasherize, pluralize, singularize } from "@warp-drive/utilities/string";
9
3
 
4
+ //#region src/serializer/json-api.ts
10
5
  /**
11
- * :::danger
12
- ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
13
- If starting a new app or thinking of implementing a new adapter, consider writing a
14
- {@link Handler} instead to be used with the {@link RequestManager}
15
- :::
16
-
17
- In WarpDrive a Serializer is used to serialize and deserialize
18
- records when they are transferred in and out of an external source.
19
- This process involves normalizing property names, transforming
20
- attribute values and serializing relationships.
21
-
22
- `JSONAPISerializer` supports the http://jsonapi.org/ spec, though
23
- even compliant {json:api} servers may find writing an application
24
- specific serializer better suited to their needs and more performant.
25
-
26
- This serializer normalizes a JSON API payload that looks like:
27
-
28
- ```js [app/models/player.js]
29
- import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
30
-
31
- export default class Player extends Model {
32
- @attr('string') name;
33
- @attr('string') skill;
34
- @attr('number') gamesPlayed;
35
- @belongsTo('club') club;
36
- }
37
- ```
38
-
39
- ```js [app/models/club.js]
40
- import Model, { attr, hasMany } from '@warp-drive/legacy/model';
41
-
42
- export default class Club extends Model {
43
- @attr('string') name;
44
- @attr('string') location;
45
- @hasMany('player') players;
46
- }
47
- ```
48
-
49
- ```js
50
- {
51
- "data": [
52
- {
53
- "attributes": {
54
- "name": "Benfica",
55
- "location": "Portugal"
56
- },
57
- "id": "1",
58
- "relationships": {
59
- "players": {
60
- "data": [
61
- {
62
- "id": "3",
63
- "type": "players"
64
- }
65
- ]
66
- }
67
- },
68
- "type": "clubs"
69
- }
70
- ],
71
- "included": [
72
- {
73
- "attributes": {
74
- "name": "Eusebio Silva Ferreira",
75
- "skill": "Rocket shot",
76
- "games-played": 431
77
- },
78
- "id": "3",
79
- "relationships": {
80
- "club": {
81
- "data": {
82
- "id": "1",
83
- "type": "clubs"
84
- }
85
- }
86
- },
87
- "type": "players"
88
- }
89
- ]
90
- }
91
- ```
92
-
93
- to the format that the JSONAPICache expects.
94
-
95
- ### Customizing meta
96
-
97
- Since a JSON API Document can have meta defined in multiple locations you can
98
- use the specific serializer hooks if you need to customize the meta.
99
-
100
- One scenario would be to camelCase the meta keys of your payload. The example
101
- below shows how this could be done using `normalizeArrayResponse` and
102
- `extractRelationship`.
103
-
104
- ```js [app/serializers/application.js]
105
- import { JSONAPISerializer } from '@warp-drive/legacy/serializer/json-api';
106
-
107
- export default class ApplicationSerializer extends JSONAPISerializer {
108
- normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
109
- let normalizedDocument = super.normalizeArrayResponse(...arguments);
110
-
111
- // Customize document meta
112
- normalizedDocument.meta = camelCaseKeys(normalizedDocument.meta);
113
-
114
- return normalizedDocument;
115
- }
116
-
117
- extractRelationship(relationshipHash) {
118
- let normalizedRelationship = super.extractRelationship(...arguments);
119
-
120
- // Customize relationship meta
121
- normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);
122
-
123
- return normalizedRelationship;
124
- }
125
- }
126
- ```
127
-
128
- @since 1.13.0
129
- @class JSONAPISerializer
130
- @public
6
+ * :::danger
7
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
8
+ If starting a new app or thinking of implementing a new adapter, consider writing a
9
+ {@link Handler} instead to be used with the {@link RequestManager}
10
+ :::
11
+
12
+ In WarpDrive a Serializer is used to serialize and deserialize
13
+ records when they are transferred in and out of an external source.
14
+ This process involves normalizing property names, transforming
15
+ attribute values and serializing relationships.
16
+
17
+ `JSONAPISerializer` supports the http://jsonapi.org/ spec, though
18
+ even compliant {json:api} servers may find writing an application
19
+ specific serializer better suited to their needs and more performant.
20
+
21
+ This serializer normalizes a JSON API payload that looks like:
22
+
23
+ ```js [app/models/player.js]
24
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
25
+
26
+ export default class Player extends Model {
27
+ @attr('string') name;
28
+ @attr('string') skill;
29
+ @attr('number') gamesPlayed;
30
+ @belongsTo('club') club;
31
+ }
32
+ ```
33
+
34
+ ```js [app/models/club.js]
35
+ import Model, { attr, hasMany } from '@warp-drive/legacy/model';
36
+
37
+ export default class Club extends Model {
38
+ @attr('string') name;
39
+ @attr('string') location;
40
+ @hasMany('player') players;
41
+ }
42
+ ```
43
+
44
+ ```js
45
+ {
46
+ "data": [
47
+ {
48
+ "attributes": {
49
+ "name": "Benfica",
50
+ "location": "Portugal"
51
+ },
52
+ "id": "1",
53
+ "relationships": {
54
+ "players": {
55
+ "data": [
56
+ {
57
+ "id": "3",
58
+ "type": "players"
59
+ }
60
+ ]
61
+ }
62
+ },
63
+ "type": "clubs"
64
+ }
65
+ ],
66
+ "included": [
67
+ {
68
+ "attributes": {
69
+ "name": "Eusebio Silva Ferreira",
70
+ "skill": "Rocket shot",
71
+ "games-played": 431
72
+ },
73
+ "id": "3",
74
+ "relationships": {
75
+ "club": {
76
+ "data": {
77
+ "id": "1",
78
+ "type": "clubs"
79
+ }
80
+ }
81
+ },
82
+ "type": "players"
83
+ }
84
+ ]
85
+ }
86
+ ```
87
+
88
+ to the format that the JSONAPICache expects.
89
+
90
+ ### Customizing meta
91
+
92
+ Since a JSON API Document can have meta defined in multiple locations you can
93
+ use the specific serializer hooks if you need to customize the meta.
94
+
95
+ One scenario would be to camelCase the meta keys of your payload. The example
96
+ below shows how this could be done using `normalizeArrayResponse` and
97
+ `extractRelationship`.
98
+
99
+ ```js [app/serializers/application.js]
100
+ import { JSONAPISerializer } from '@warp-drive/legacy/serializer/json-api';
101
+
102
+ export default class ApplicationSerializer extends JSONAPISerializer {
103
+ normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
104
+ let normalizedDocument = super.normalizeArrayResponse(...arguments);
105
+
106
+ // Customize document meta
107
+ normalizedDocument.meta = camelCaseKeys(normalizedDocument.meta);
108
+
109
+ return normalizedDocument;
110
+ }
111
+
112
+ extractRelationship(relationshipHash) {
113
+ let normalizedRelationship = super.extractRelationship(...arguments);
114
+
115
+ // Customize relationship meta
116
+ normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);
117
+
118
+ return normalizedRelationship;
119
+ }
120
+ }
121
+ ```
122
+
123
+ @since 1.13.0
124
+ @class JSONAPISerializer
125
+ @public
131
126
  */
132
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
127
  const JSONAPISerializer = JSONSerializer.extend({
134
- /**
135
- @private
136
- */
137
- _normalizeDocumentHelper(documentHash) {
138
- if (Array.isArray(documentHash.data)) {
139
- const ret = [];
140
- for (let i = 0; i < documentHash.data.length; i++) {
141
- const data = documentHash.data[i];
142
- const normalized = this._normalizeResourceHelper(data);
143
- if (normalized !== null) {
144
- // @ts-expect-error untyped
145
- // can be null when unknown type is encountered
146
- ret.push(normalized);
147
- }
148
- }
149
- documentHash.data = ret;
150
- } else if (documentHash.data && typeof documentHash.data === 'object') {
151
- documentHash.data = this._normalizeResourceHelper(documentHash.data);
152
- }
153
- if (Array.isArray(documentHash.included)) {
154
- const ret = [];
155
- for (let i = 0; i < documentHash.included.length; i++) {
156
- const included = documentHash.included[i];
157
- const normalized = this._normalizeResourceHelper(included);
158
- if (normalized !== null) {
159
- // @ts-expect-error untyped
160
- // can be null when unknown type is encountered
161
- ret.push(normalized);
162
- }
163
- }
164
- documentHash.included = ret;
165
- }
166
- return documentHash;
167
- },
168
- /**
169
- @private
170
- */
171
- _normalizeRelationshipDataHelper(relationshipDataHash) {
172
- relationshipDataHash.type = this.modelNameFromPayloadKey(relationshipDataHash.type);
173
- return relationshipDataHash;
174
- },
175
- /**
176
- @private
177
- */
178
- _normalizeResourceHelper(resourceHash) {
179
- const type = this.modelNameFromPayloadKey(resourceHash.type);
180
-
181
- // @ts-expect-error store is dynamically added
182
- if (!this.store.schema.hasResource({
183
- type
184
- })) {
185
- return null;
186
- }
187
-
188
- // @ts-expect-error store is dynamically added
189
- const modelClass = this.store.modelFor(type);
190
- // @ts-expect-error store is dynamically added
191
- const serializer = this.store.serializerFor(type);
192
- const {
193
- data
194
- } = serializer.normalize(modelClass, resourceHash);
195
- return data;
196
- },
197
- /**
198
- Normalize some data and push it into the store.
199
- @public
200
- */
201
- pushPayload(store, payload) {
202
- const normalizedPayload = this._normalizeDocumentHelper(payload);
203
- store.push(normalizedPayload);
204
- },
205
- /**
206
- @return A {json:api} Document
207
- @private
208
- */
209
- _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
210
- const normalizedPayload = this._normalizeDocumentHelper(payload);
211
- return normalizedPayload;
212
- },
213
- normalizeQueryRecordResponse() {
214
- // @ts-expect-error untyped
215
- const normalized = this._super(...arguments);
216
- return normalized;
217
- },
218
- extractAttributes(modelClass, resourceHash) {
219
- const attributes = {};
220
- if (resourceHash.attributes) {
221
- modelClass.eachAttribute(key => {
222
- const attributeKey = this.keyForAttribute(key, 'deserialize');
223
- if (resourceHash.attributes[attributeKey] !== undefined) {
224
- attributes[key] = resourceHash.attributes[attributeKey];
225
- }
226
- });
227
- }
228
- return attributes;
229
- },
230
- /**
231
- Returns a relationship formatted as a JSON-API "relationship object".
232
- http://jsonapi.org/format/#document-resource-object-relationships
233
- @public
234
- */
235
- extractRelationship(relationshipHash) {
236
- if (Array.isArray(relationshipHash.data)) {
237
- const ret = new Array(relationshipHash.data.length);
238
- for (let i = 0; i < relationshipHash.data.length; i++) {
239
- const data = relationshipHash.data[i];
240
- ret[i] = this._normalizeRelationshipDataHelper(data);
241
- }
242
- relationshipHash.data = ret;
243
- } else if (relationshipHash.data && typeof relationshipHash.data === 'object') {
244
- relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data);
245
- }
246
- return relationshipHash;
247
- },
248
- /**
249
- Returns the resource's relationships formatted as a JSON-API "relationships object".
250
- http://jsonapi.org/format/#document-resource-object-relationships
251
- @public
252
- */
253
- extractRelationships(modelClass, resourceHash) {
254
- const relationships = {};
255
- if (resourceHash.relationships) {
256
- modelClass.eachRelationship((key, relationshipMeta) => {
257
- const relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
258
- if (resourceHash.relationships[relationshipKey] !== undefined) {
259
- const relationshipHash = resourceHash.relationships[relationshipKey];
260
- relationships[key] = this.extractRelationship(relationshipHash);
261
- }
262
- });
263
- }
264
- return relationships;
265
- },
266
- /**
267
- @private
268
- */
269
- _extractType(modelClass, resourceHash) {
270
- return this.modelNameFromPayloadKey(resourceHash.type);
271
- },
272
- /**
273
- Dasherizes and singularizes the model name in the payload to match
274
- the common convention for model names.
275
- For example the key `posts` would be converted to `post` and the
276
- key `studentAssesments` would be converted to `student-assesment`.
277
- @public
278
- @return the model's modelName
279
- */
280
- modelNameFromPayloadKey(key) {
281
- return dasherize(singularize(key));
282
- },
283
- /**
284
- Converts the model name to a pluralized version of the model name.
285
- For example `post` would be converted to `posts` and
286
- `student-assesment` would be converted to `student-assesments`.
287
- @public
288
- */
289
- payloadKeyFromModelName(modelName) {
290
- return pluralize(modelName);
291
- },
292
- normalize(modelClass, resourceHash) {
293
- if (resourceHash.attributes) {
294
- // @ts-expect-error untyped
295
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash.attributes);
296
- }
297
- if (resourceHash.relationships) {
298
- // @ts-expect-error untyped
299
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash.relationships);
300
- }
301
- const data = {
302
- // @ts-expect-error untyped
303
- id: this.extractId(modelClass, resourceHash),
304
- type: this._extractType(modelClass, resourceHash),
305
- attributes: this.extractAttributes(modelClass, resourceHash),
306
- relationships: this.extractRelationships(modelClass, resourceHash)
307
- };
308
- if (resourceHash.lid) {
309
- // @ts-expect-error untyped
310
- data.lid = resourceHash.lid;
311
- }
312
-
313
- // @ts-expect-error untyped
314
- this.applyTransforms(modelClass, data.attributes);
315
- return {
316
- data
317
- };
318
- },
319
- /**
320
- `keyForAttribute` can be used to define rules for how to convert an
321
- attribute name in your model to a key in your JSON.
322
- By default `JSONAPISerializer` follows the format used on the examples of
323
- http://jsonapi.org/format and uses dashes as the word separator in the JSON
324
- attribute keys.
325
- This behaviour can be easily customized by extending this method.
326
- Example
327
- ```js [app/serializers/application.js]
328
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
329
- import { dasherize } from '<app-name>/utils/string-utils';
330
- export default class ApplicationSerializer extends JSONAPISerializer {
331
- keyForAttribute(attr, method) {
332
- return dasherize(attr).toUpperCase();
333
- }
334
- }
335
- ```
336
- @public
337
- @return normalized key
338
- */
339
- keyForAttribute(key, method) {
340
- return dasherize(key);
341
- },
342
- /**
343
- `keyForRelationship` can be used to define a custom key when
344
- serializing and deserializing relationship properties.
345
- By default `JSONAPISerializer` follows the format used on the examples of
346
- http://jsonapi.org/format and uses dashes as word separators in
347
- relationship properties.
348
- This behaviour can be easily customized by extending this method.
349
- Example
350
- ```js [app/serializers/post.js]
351
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
352
- import { underscore } from '<app-name>/utils/string-utils';
353
- export default class ApplicationSerializer extends JSONAPISerializer {
354
- keyForRelationship(key, relationship, method) {
355
- return underscore(key);
356
- }
357
- }
358
- ```
359
- @public
360
- @return the normalized key
361
- */
362
- keyForRelationship(key, typeClass, method) {
363
- return dasherize(key);
364
- },
365
- /**
366
- Called when a record is saved in order to convert the
367
- record into JSON.
368
- For example, consider this model:
369
- ```js [app/models/comment.js]
370
- import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
371
- export default class CommentModel extends Model {
372
- @attr title;
373
- @attr body;
374
- @belongsTo('user', { async: false, inverse: null })
375
- author;
376
- }
377
- ```
378
- The default serialization would create a JSON-API resource object like:
379
- ```javascript
380
- {
381
- "data": {
382
- "type": "comments",
383
- "attributes": {
384
- "title": "Rails is unagi",
385
- "body": "Rails? Omakase? O_O",
386
- },
387
- "relationships": {
388
- "author": {
389
- "data": {
390
- "id": "12",
391
- "type": "users"
392
- }
393
- }
394
- }
395
- }
396
- }
397
- ```
398
- By default, attributes are passed through as-is, unless
399
- you specified an attribute type (`attr('date')`). If
400
- you specify a transform, the JavaScript value will be
401
- serialized when inserted into the attributes hash.
402
- Belongs-to relationships are converted into JSON-API
403
- resource identifier objects.
404
- ## IDs
405
- `serialize` takes an options hash with a single option:
406
- `includeId`. If this option is `true`, `serialize` will,
407
- by default include the ID in the JSON object it builds.
408
- The JSONAPIAdapter passes in `includeId: true` when serializing a record
409
- for `createRecord` or `updateRecord`.
410
- ## Customization
411
- Your server may expect data in a different format than the
412
- built-in serialization format.
413
- In that case, you can implement `serialize` yourself and
414
- return data formatted to match your API's expectations, or override
415
- the invoked adapter method and do the serialization in the adapter directly
416
- by using the provided snapshot.
417
- If your API's format differs greatly from the JSON:API spec, you should
418
- consider authoring your own adapter and serializer instead of extending
419
- this class.
420
- ```js [app/serializers/post.js]
421
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
422
- export default class PostSerializer extends JSONAPISerializer {
423
- serialize(snapshot, options) {
424
- let json = {
425
- POST_TTL: snapshot.attr('title'),
426
- POST_BDY: snapshot.attr('body'),
427
- POST_CMS: snapshot.hasMany('comments', { ids: true })
428
- };
429
- if (options.includeId) {
430
- json.POST_ID_ = snapshot.id;
431
- }
432
- return json;
433
- }
434
- }
435
- ```
436
- ## Customizing an App-Wide Serializer
437
- If you want to define a serializer for your entire
438
- application, you'll probably want to use `eachAttribute`
439
- and `eachRelationship` on the record.
440
- ```js [app/serializers/application.js]
441
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
442
- import { underscore, singularize } from '<app-name>/utils/string-utils';
443
- export default class ApplicationSerializer extends JSONAPISerializer {
444
- serialize(snapshot, options) {
445
- let json = {};
446
- snapshot.eachAttribute((name) => {
447
- json[serverAttributeName(name)] = snapshot.attr(name);
448
- });
449
- snapshot.eachRelationship((name, relationship) => {
450
- if (relationship.kind === 'hasMany') {
451
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
452
- }
453
- });
454
- if (options.includeId) {
455
- json.ID_ = snapshot.id;
456
- }
457
- return json;
458
- }
459
- }
460
- function serverAttributeName(attribute) {
461
- return underscore(attribute).toUpperCase();
462
- }
463
- function serverHasManyName(name) {
464
- return serverAttributeName(singularize(name)) + '_IDS';
465
- }
466
- ```
467
- This serializer will generate JSON that looks like this:
468
- ```javascript
469
- {
470
- "TITLE": "Rails is omakase",
471
- "BODY": "Yep. Omakase.",
472
- "COMMENT_IDS": [ "1", "2", "3" ]
473
- }
474
- ```
475
- ## Tweaking the Default Formatting
476
- If you just want to do some small tweaks on the default JSON:API formatted response,
477
- you can call `super.serialize` first and make the tweaks
478
- on the returned object.
479
- ```js [app/serializers/post.js]
480
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
481
- export default class PostSerializer extends JSONAPISerializer {
482
- serialize(snapshot, options) {
483
- let json = super.serialize(...arguments);
484
- json.data.attributes.subject = json.data.attributes.title;
485
- delete json.data.attributes.title;
486
- return json;
487
- }
488
- }
489
- ```
490
- @public
491
- */
492
- serialize(snapshot, options) {
493
- // @ts-expect-error untyped
494
- const data = this._super(...arguments);
495
- data.type = this.payloadKeyFromModelName(snapshot.modelName);
496
- return {
497
- data
498
- };
499
- },
500
- serializeAttribute(snapshot, json, key, attribute) {
501
- const type = attribute.type;
502
-
503
- // @ts-expect-error untyped
504
- if (this._canSerialize(key)) {
505
- json.attributes = json.attributes || {};
506
- let value = snapshot.attr(key);
507
- if (type) {
508
- // @ts-expect-error untyped
509
- const transform = this.transformFor(type);
510
- value = transform.serialize(value, attribute.options);
511
- }
512
-
513
- // @ts-expect-error store is dynamically added
514
- const schema = this.store.modelFor(snapshot.modelName);
515
- // @ts-expect-error untyped
516
- let payloadKey = this._getMappedKey(key, schema);
517
- if (payloadKey === key) {
518
- payloadKey = this.keyForAttribute(key, 'serialize');
519
- }
520
- json.attributes[payloadKey] = value;
521
- }
522
- },
523
- serializeBelongsTo(snapshot, json, relationship) {
524
- const name = relationship.name;
525
-
526
- // @ts-expect-error untyped
527
- if (this._canSerialize(name)) {
528
- const belongsTo = snapshot.belongsTo(name);
529
- // @ts-expect-error not narrowed
530
- const belongsToIsNotNew = belongsTo && !belongsTo.isNew;
531
- if (belongsTo === null || belongsToIsNotNew) {
532
- json.relationships = json.relationships || {};
533
-
534
- // @ts-expect-error store is dynamically added
535
- const schema = this.store.modelFor(snapshot.modelName);
536
- // @ts-expect-error untyped
537
- let payloadKey = this._getMappedKey(name, schema);
538
- if (payloadKey === name) {
539
- payloadKey = this.keyForRelationship(name, 'belongsTo', 'serialize');
540
- }
541
- let data = null;
542
- if (belongsTo) {
543
- // @ts-expect-error not narrowed
544
- const payloadType = this.payloadKeyFromModelName(belongsTo.modelName);
545
-
546
- // @ts-expect-error untyped
547
- data = {
548
- type: payloadType,
549
- // @ts-expect-error not narrowed
550
- id: belongsTo.id
551
- };
552
- }
553
- json.relationships[payloadKey] = {
554
- data
555
- };
556
- }
557
- }
558
- },
559
- serializeHasMany(snapshot, json, relationship) {
560
- const name = relationship.name;
561
-
562
- // @ts-expect-error untyped
563
- if (this.shouldSerializeHasMany(snapshot, name, relationship)) {
564
- const hasMany = snapshot.hasMany(name);
565
- if (hasMany !== undefined) {
566
- json.relationships = json.relationships || {};
567
-
568
- // @ts-expect-error store is dynamically added
569
- const schema = this.store.modelFor(snapshot.modelName);
570
- // @ts-expect-error untyped
571
- let payloadKey = this._getMappedKey(name, schema);
572
- if (payloadKey === name && this.keyForRelationship) {
573
- payloadKey = this.keyForRelationship(name, 'hasMany', 'serialize');
574
- }
575
-
576
- // only serialize has many relationships that are not new
577
- // @ts-expect-error not narrowed
578
- const nonNewHasMany = hasMany.filter(item => !item.isNew);
579
- const data = new Array(nonNewHasMany.length);
580
- for (let i = 0; i < nonNewHasMany.length; i++) {
581
- const item = hasMany[i];
582
- // @ts-expect-error not narrowed
583
- const payloadType = this.payloadKeyFromModelName(item.modelName);
584
- data[i] = {
585
- type: payloadType,
586
- // @ts-expect-error not narrowed
587
- id: item.id
588
- };
589
- }
590
- json.relationships[payloadKey] = {
591
- data
592
- };
593
- }
594
- }
595
- }
128
+ /**
129
+ @private
130
+ */
131
+ _normalizeDocumentHelper(documentHash) {
132
+ if (Array.isArray(documentHash.data)) {
133
+ const ret = [];
134
+ for (let i = 0; i < documentHash.data.length; i++) {
135
+ const data = documentHash.data[i];
136
+ const normalized = this._normalizeResourceHelper(data);
137
+ if (normalized !== null) ret.push(normalized);
138
+ }
139
+ documentHash.data = ret;
140
+ } else if (documentHash.data && typeof documentHash.data === "object") documentHash.data = this._normalizeResourceHelper(documentHash.data);
141
+ if (Array.isArray(documentHash.included)) {
142
+ const ret = [];
143
+ for (let i = 0; i < documentHash.included.length; i++) {
144
+ const included = documentHash.included[i];
145
+ const normalized = this._normalizeResourceHelper(included);
146
+ if (normalized !== null) ret.push(normalized);
147
+ }
148
+ documentHash.included = ret;
149
+ }
150
+ return documentHash;
151
+ },
152
+ /**
153
+ @private
154
+ */
155
+ _normalizeRelationshipDataHelper(relationshipDataHash) {
156
+ relationshipDataHash.type = this.modelNameFromPayloadKey(relationshipDataHash.type);
157
+ return relationshipDataHash;
158
+ },
159
+ /**
160
+ @private
161
+ */
162
+ _normalizeResourceHelper(resourceHash) {
163
+ const type = this.modelNameFromPayloadKey(resourceHash.type);
164
+ if (!this.store.schema.hasResource({ type })) return null;
165
+ const modelClass = this.store.modelFor(type);
166
+ const { data } = this.store.serializerFor(type).normalize(modelClass, resourceHash);
167
+ return data;
168
+ },
169
+ /**
170
+ Normalize some data and push it into the store.
171
+ @public
172
+ */
173
+ pushPayload(store, payload) {
174
+ const normalizedPayload = this._normalizeDocumentHelper(payload);
175
+ store.push(normalizedPayload);
176
+ },
177
+ /**
178
+ @return A {json:api} Document
179
+ @private
180
+ */
181
+ _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
182
+ return this._normalizeDocumentHelper(payload);
183
+ },
184
+ normalizeQueryRecordResponse() {
185
+ return this._super(...arguments);
186
+ },
187
+ extractAttributes(modelClass, resourceHash) {
188
+ const attributes = {};
189
+ if (resourceHash.attributes) modelClass.eachAttribute((key) => {
190
+ const attributeKey = this.keyForAttribute(key, "deserialize");
191
+ if (resourceHash.attributes[attributeKey] !== void 0) attributes[key] = resourceHash.attributes[attributeKey];
192
+ });
193
+ return attributes;
194
+ },
195
+ /**
196
+ Returns a relationship formatted as a JSON-API "relationship object".
197
+ http://jsonapi.org/format/#document-resource-object-relationships
198
+ @public
199
+ */
200
+ extractRelationship(relationshipHash) {
201
+ if (Array.isArray(relationshipHash.data)) {
202
+ const ret = new Array(relationshipHash.data.length);
203
+ for (let i = 0; i < relationshipHash.data.length; i++) {
204
+ const data = relationshipHash.data[i];
205
+ ret[i] = this._normalizeRelationshipDataHelper(data);
206
+ }
207
+ relationshipHash.data = ret;
208
+ } else if (relationshipHash.data && typeof relationshipHash.data === "object") relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data);
209
+ return relationshipHash;
210
+ },
211
+ /**
212
+ Returns the resource's relationships formatted as a JSON-API "relationships object".
213
+ http://jsonapi.org/format/#document-resource-object-relationships
214
+ @public
215
+ */
216
+ extractRelationships(modelClass, resourceHash) {
217
+ const relationships = {};
218
+ if (resourceHash.relationships) modelClass.eachRelationship((key, relationshipMeta) => {
219
+ const relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, "deserialize");
220
+ if (resourceHash.relationships[relationshipKey] !== void 0) {
221
+ const relationshipHash = resourceHash.relationships[relationshipKey];
222
+ relationships[key] = this.extractRelationship(relationshipHash);
223
+ }
224
+ });
225
+ return relationships;
226
+ },
227
+ /**
228
+ @private
229
+ */
230
+ _extractType(modelClass, resourceHash) {
231
+ return this.modelNameFromPayloadKey(resourceHash.type);
232
+ },
233
+ /**
234
+ Dasherizes and singularizes the model name in the payload to match
235
+ the common convention for model names.
236
+ For example the key `posts` would be converted to `post` and the
237
+ key `studentAssesments` would be converted to `student-assesment`.
238
+ @public
239
+ @return the model's modelName
240
+ */
241
+ modelNameFromPayloadKey(key) {
242
+ return dasherize(singularize(key));
243
+ },
244
+ /**
245
+ Converts the model name to a pluralized version of the model name.
246
+ For example `post` would be converted to `posts` and
247
+ `student-assesment` would be converted to `student-assesments`.
248
+ @public
249
+ */
250
+ payloadKeyFromModelName(modelName) {
251
+ return pluralize(modelName);
252
+ },
253
+ normalize(modelClass, resourceHash) {
254
+ if (resourceHash.attributes) this.normalizeUsingDeclaredMapping(modelClass, resourceHash.attributes);
255
+ if (resourceHash.relationships) this.normalizeUsingDeclaredMapping(modelClass, resourceHash.relationships);
256
+ const data = {
257
+ id: this.extractId(modelClass, resourceHash),
258
+ type: this._extractType(modelClass, resourceHash),
259
+ attributes: this.extractAttributes(modelClass, resourceHash),
260
+ relationships: this.extractRelationships(modelClass, resourceHash)
261
+ };
262
+ if (resourceHash.lid) data.lid = resourceHash.lid;
263
+ this.applyTransforms(modelClass, data.attributes);
264
+ return { data };
265
+ },
266
+ /**
267
+ `keyForAttribute` can be used to define rules for how to convert an
268
+ attribute name in your model to a key in your JSON.
269
+ By default `JSONAPISerializer` follows the format used on the examples of
270
+ http://jsonapi.org/format and uses dashes as the word separator in the JSON
271
+ attribute keys.
272
+ This behaviour can be easily customized by extending this method.
273
+ Example
274
+ ```js [app/serializers/application.js]
275
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
276
+ import { dasherize } from '<app-name>/utils/string-utils';
277
+ export default class ApplicationSerializer extends JSONAPISerializer {
278
+ keyForAttribute(attr, method) {
279
+ return dasherize(attr).toUpperCase();
280
+ }
281
+ }
282
+ ```
283
+ @public
284
+ @return normalized key
285
+ */
286
+ keyForAttribute(key, method) {
287
+ return dasherize(key);
288
+ },
289
+ /**
290
+ `keyForRelationship` can be used to define a custom key when
291
+ serializing and deserializing relationship properties.
292
+ By default `JSONAPISerializer` follows the format used on the examples of
293
+ http://jsonapi.org/format and uses dashes as word separators in
294
+ relationship properties.
295
+ This behaviour can be easily customized by extending this method.
296
+ Example
297
+ ```js [app/serializers/post.js]
298
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
299
+ import { underscore } from '<app-name>/utils/string-utils';
300
+ export default class ApplicationSerializer extends JSONAPISerializer {
301
+ keyForRelationship(key, relationship, method) {
302
+ return underscore(key);
303
+ }
304
+ }
305
+ ```
306
+ @public
307
+ @return the normalized key
308
+ */
309
+ keyForRelationship(key, typeClass, method) {
310
+ return dasherize(key);
311
+ },
312
+ /**
313
+ Called when a record is saved in order to convert the
314
+ record into JSON.
315
+ For example, consider this model:
316
+ ```js [app/models/comment.js]
317
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
318
+ export default class CommentModel extends Model {
319
+ @attr title;
320
+ @attr body;
321
+ @belongsTo('user', { async: false, inverse: null })
322
+ author;
323
+ }
324
+ ```
325
+ The default serialization would create a JSON-API resource object like:
326
+ ```javascript
327
+ {
328
+ "data": {
329
+ "type": "comments",
330
+ "attributes": {
331
+ "title": "Rails is unagi",
332
+ "body": "Rails? Omakase? O_O",
333
+ },
334
+ "relationships": {
335
+ "author": {
336
+ "data": {
337
+ "id": "12",
338
+ "type": "users"
339
+ }
340
+ }
341
+ }
342
+ }
343
+ }
344
+ ```
345
+ By default, attributes are passed through as-is, unless
346
+ you specified an attribute type (`attr('date')`). If
347
+ you specify a transform, the JavaScript value will be
348
+ serialized when inserted into the attributes hash.
349
+ Belongs-to relationships are converted into JSON-API
350
+ resource identifier objects.
351
+ ## IDs
352
+ `serialize` takes an options hash with a single option:
353
+ `includeId`. If this option is `true`, `serialize` will,
354
+ by default include the ID in the JSON object it builds.
355
+ The JSONAPIAdapter passes in `includeId: true` when serializing a record
356
+ for `createRecord` or `updateRecord`.
357
+ ## Customization
358
+ Your server may expect data in a different format than the
359
+ built-in serialization format.
360
+ In that case, you can implement `serialize` yourself and
361
+ return data formatted to match your API's expectations, or override
362
+ the invoked adapter method and do the serialization in the adapter directly
363
+ by using the provided snapshot.
364
+ If your API's format differs greatly from the JSON:API spec, you should
365
+ consider authoring your own adapter and serializer instead of extending
366
+ this class.
367
+ ```js [app/serializers/post.js]
368
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
369
+ export default class PostSerializer extends JSONAPISerializer {
370
+ serialize(snapshot, options) {
371
+ let json = {
372
+ POST_TTL: snapshot.attr('title'),
373
+ POST_BDY: snapshot.attr('body'),
374
+ POST_CMS: snapshot.hasMany('comments', { ids: true })
375
+ };
376
+ if (options.includeId) {
377
+ json.POST_ID_ = snapshot.id;
378
+ }
379
+ return json;
380
+ }
381
+ }
382
+ ```
383
+ ## Customizing an App-Wide Serializer
384
+ If you want to define a serializer for your entire
385
+ application, you'll probably want to use `eachAttribute`
386
+ and `eachRelationship` on the record.
387
+ ```js [app/serializers/application.js]
388
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
389
+ import { underscore, singularize } from '<app-name>/utils/string-utils';
390
+ export default class ApplicationSerializer extends JSONAPISerializer {
391
+ serialize(snapshot, options) {
392
+ let json = {};
393
+ snapshot.eachAttribute((name) => {
394
+ json[serverAttributeName(name)] = snapshot.attr(name);
395
+ });
396
+ snapshot.eachRelationship((name, relationship) => {
397
+ if (relationship.kind === 'hasMany') {
398
+ json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
399
+ }
400
+ });
401
+ if (options.includeId) {
402
+ json.ID_ = snapshot.id;
403
+ }
404
+ return json;
405
+ }
406
+ }
407
+ function serverAttributeName(attribute) {
408
+ return underscore(attribute).toUpperCase();
409
+ }
410
+ function serverHasManyName(name) {
411
+ return serverAttributeName(singularize(name)) + '_IDS';
412
+ }
413
+ ```
414
+ This serializer will generate JSON that looks like this:
415
+ ```javascript
416
+ {
417
+ "TITLE": "Rails is omakase",
418
+ "BODY": "Yep. Omakase.",
419
+ "COMMENT_IDS": [ "1", "2", "3" ]
420
+ }
421
+ ```
422
+ ## Tweaking the Default Formatting
423
+ If you just want to do some small tweaks on the default JSON:API formatted response,
424
+ you can call `super.serialize` first and make the tweaks
425
+ on the returned object.
426
+ ```js [app/serializers/post.js]
427
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
428
+ export default class PostSerializer extends JSONAPISerializer {
429
+ serialize(snapshot, options) {
430
+ let json = super.serialize(...arguments);
431
+ json.data.attributes.subject = json.data.attributes.title;
432
+ delete json.data.attributes.title;
433
+ return json;
434
+ }
435
+ }
436
+ ```
437
+ @public
438
+ */
439
+ serialize(snapshot, options) {
440
+ const data = this._super(...arguments);
441
+ data.type = this.payloadKeyFromModelName(snapshot.modelName);
442
+ return { data };
443
+ },
444
+ serializeAttribute(snapshot, json, key, attribute) {
445
+ const type = attribute.type;
446
+ if (this._canSerialize(key)) {
447
+ json.attributes = json.attributes || {};
448
+ let value = snapshot.attr(key);
449
+ if (type) value = this.transformFor(type).serialize(value, attribute.options);
450
+ const schema = this.store.modelFor(snapshot.modelName);
451
+ let payloadKey = this._getMappedKey(key, schema);
452
+ if (payloadKey === key) payloadKey = this.keyForAttribute(key, "serialize");
453
+ json.attributes[payloadKey] = value;
454
+ }
455
+ },
456
+ serializeBelongsTo(snapshot, json, relationship) {
457
+ const name = relationship.name;
458
+ if (this._canSerialize(name)) {
459
+ const belongsTo = snapshot.belongsTo(name);
460
+ const belongsToIsNotNew = belongsTo && !belongsTo.isNew;
461
+ if (belongsTo === null || belongsToIsNotNew) {
462
+ json.relationships = json.relationships || {};
463
+ const schema = this.store.modelFor(snapshot.modelName);
464
+ let payloadKey = this._getMappedKey(name, schema);
465
+ if (payloadKey === name) payloadKey = this.keyForRelationship(name, "belongsTo", "serialize");
466
+ let data = null;
467
+ if (belongsTo) data = {
468
+ type: this.payloadKeyFromModelName(belongsTo.modelName),
469
+ id: belongsTo.id
470
+ };
471
+ json.relationships[payloadKey] = { data };
472
+ }
473
+ }
474
+ },
475
+ serializeHasMany(snapshot, json, relationship) {
476
+ const name = relationship.name;
477
+ if (this.shouldSerializeHasMany(snapshot, name, relationship)) {
478
+ const hasMany = snapshot.hasMany(name);
479
+ if (hasMany !== void 0) {
480
+ json.relationships = json.relationships || {};
481
+ const schema = this.store.modelFor(snapshot.modelName);
482
+ let payloadKey = this._getMappedKey(name, schema);
483
+ if (payloadKey === name && this.keyForRelationship) payloadKey = this.keyForRelationship(name, "hasMany", "serialize");
484
+ const nonNewHasMany = hasMany.filter((item) => !item.isNew);
485
+ const data = new Array(nonNewHasMany.length);
486
+ for (let i = 0; i < nonNewHasMany.length; i++) {
487
+ const item = hasMany[i];
488
+ const payloadType = this.payloadKeyFromModelName(item.modelName);
489
+ data[i] = {
490
+ type: payloadType,
491
+ id: item.id
492
+ };
493
+ }
494
+ json.relationships[payloadKey] = { data };
495
+ }
496
+ }
497
+ }
596
498
  });
597
- export { JSONAPISerializer };
499
+
500
+ //#endregion
501
+ export { JSONAPISerializer };
502
+ //# sourceMappingURL=json-api.js.map