@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,532 +1,540 @@
1
- import { warn } from '@ember/debug';
2
- import { dasherize, pluralize, singularize } from '@warp-drive/utilities/string';
3
- import { J as JSONSerializer } from "../json-DU8m1pGf.js";
4
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
1
+ import { t as JSONSerializer } from "../json-BXNPTlcH.js";
2
+ import { warn } from "@ember/debug";
3
+ import { getGlobalConfig, macroCondition } from "@embroider/macros";
4
+ import { dasherize, pluralize, singularize } from "@warp-drive/utilities/string";
5
5
 
6
- /* eslint-disable @typescript-eslint/no-unsafe-return */
7
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
8
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
9
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
10
- /* eslint-disable @typescript-eslint/no-unsafe-call */
11
- const JSONAPISerializer = JSONSerializer.extend({
12
- /**
13
- @private
14
- */
15
- _normalizeDocumentHelper(documentHash) {
16
- if (Array.isArray(documentHash.data)) {
17
- const ret = [];
18
- for (let i = 0; i < documentHash.data.length; i++) {
19
- const data = documentHash.data[i];
20
- const normalized = this._normalizeResourceHelper(data);
21
- if (normalized !== null) {
22
- // @ts-expect-error untyped
23
- // can be null when unknown type is encountered
24
- ret.push(normalized);
25
- }
26
- }
27
- documentHash.data = ret;
28
- } else if (documentHash.data && typeof documentHash.data === 'object') {
29
- documentHash.data = this._normalizeResourceHelper(documentHash.data);
30
- }
31
- if (Array.isArray(documentHash.included)) {
32
- const ret = [];
33
- for (let i = 0; i < documentHash.included.length; i++) {
34
- const included = documentHash.included[i];
35
- const normalized = this._normalizeResourceHelper(included);
36
- if (normalized !== null) {
37
- // @ts-expect-error untyped
38
- // can be null when unknown type is encountered
39
- ret.push(normalized);
40
- }
41
- }
42
- documentHash.included = ret;
43
- }
44
- return documentHash;
45
- },
46
- /**
47
- @private
48
- */
49
- _normalizeRelationshipDataHelper(relationshipDataHash) {
50
- relationshipDataHash.type = this.modelNameFromPayloadKey(relationshipDataHash.type);
51
- return relationshipDataHash;
52
- },
53
- /**
54
- @private
55
- */
56
- _normalizeResourceHelper(resourceHash) {
57
- // @ts-expect-error untyped
58
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
59
- if (!test) {
60
- throw new Error(this.warnMessageForUndefinedType());
61
- }
62
- })(resourceHash.type) : {};
63
- const type = this.modelNameFromPayloadKey(resourceHash.type);
6
+ //#region src/serializer/json-api.ts
7
+ /**
8
+ * :::danger
9
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
10
+ If starting a new app or thinking of implementing a new adapter, consider writing a
11
+ {@link Handler} instead to be used with the {@link RequestManager}
12
+ :::
64
13
 
65
- // @ts-expect-error store is dynamically added
66
- if (!this.store.schema.hasResource({
67
- type
68
- })) {
69
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
70
- // @ts-expect-error untyped
71
- warn(this.warnMessageNoModelForType(type, resourceHash.type, 'modelNameFromPayloadKey'), false, {
72
- id: 'ds.serializer.model-for-type-missing'
73
- });
74
- }
75
- return null;
76
- }
14
+ In WarpDrive a Serializer is used to serialize and deserialize
15
+ records when they are transferred in and out of an external source.
16
+ This process involves normalizing property names, transforming
17
+ attribute values and serializing relationships.
77
18
 
78
- // @ts-expect-error store is dynamically added
79
- const modelClass = this.store.modelFor(type);
80
- // @ts-expect-error store is dynamically added
81
- const serializer = this.store.serializerFor(type);
82
- const {
83
- data
84
- } = serializer.normalize(modelClass, resourceHash);
85
- return data;
86
- },
87
- /**
88
- Normalize some data and push it into the store.
89
- @public
90
- */
91
- pushPayload(store, payload) {
92
- const normalizedPayload = this._normalizeDocumentHelper(payload);
93
- store.push(normalizedPayload);
94
- },
95
- /**
96
- @return A {json:api} Document
97
- @private
98
- */
99
- _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
100
- const normalizedPayload = this._normalizeDocumentHelper(payload);
101
- return normalizedPayload;
102
- },
103
- normalizeQueryRecordResponse() {
104
- // @ts-expect-error untyped
105
- const normalized = this._super(...arguments);
106
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
107
- if (!test) {
108
- throw new Error('Expected the primary data returned by the serializer for a `queryRecord` response to be a single object but instead it was an array.');
109
- }
110
- })(!Array.isArray(normalized.data)) : {};
111
- return normalized;
112
- },
113
- extractAttributes(modelClass, resourceHash) {
114
- const attributes = {};
115
- if (resourceHash.attributes) {
116
- modelClass.eachAttribute(key => {
117
- const attributeKey = this.keyForAttribute(key, 'deserialize');
118
- if (resourceHash.attributes[attributeKey] !== undefined) {
119
- attributes[key] = resourceHash.attributes[attributeKey];
120
- }
121
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
122
- if (resourceHash.attributes[attributeKey] === undefined && resourceHash.attributes[key] !== undefined) {
123
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
124
- {
125
- throw new Error(`Your payload for '${modelClass.modelName}' contains '${key}', but your serializer is setup to look for '${attributeKey}'. This is most likely because Ember Data's JSON API serializer dasherizes attribute keys by default. You should subclass JSONAPISerializer and implement 'keyForAttribute(key) { return key; }' to prevent Ember Data from customizing your attribute keys.`);
126
- }
127
- })() : {};
128
- }
129
- }
130
- });
131
- }
132
- return attributes;
133
- },
134
- /**
135
- Returns a relationship formatted as a JSON-API "relationship object".
136
- http://jsonapi.org/format/#document-resource-object-relationships
137
- @public
138
- */
139
- extractRelationship(relationshipHash) {
140
- if (Array.isArray(relationshipHash.data)) {
141
- const ret = new Array(relationshipHash.data.length);
142
- for (let i = 0; i < relationshipHash.data.length; i++) {
143
- const data = relationshipHash.data[i];
144
- ret[i] = this._normalizeRelationshipDataHelper(data);
145
- }
146
- relationshipHash.data = ret;
147
- } else if (relationshipHash.data && typeof relationshipHash.data === 'object') {
148
- relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data);
149
- }
150
- return relationshipHash;
151
- },
152
- /**
153
- Returns the resource's relationships formatted as a JSON-API "relationships object".
154
- http://jsonapi.org/format/#document-resource-object-relationships
155
- @public
156
- */
157
- extractRelationships(modelClass, resourceHash) {
158
- const relationships = {};
159
- if (resourceHash.relationships) {
160
- modelClass.eachRelationship((key, relationshipMeta) => {
161
- const relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
162
- if (resourceHash.relationships[relationshipKey] !== undefined) {
163
- const relationshipHash = resourceHash.relationships[relationshipKey];
164
- relationships[key] = this.extractRelationship(relationshipHash);
165
- }
166
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
167
- if (resourceHash.relationships[relationshipKey] === undefined && resourceHash.relationships[key] !== undefined) {
168
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
169
- {
170
- throw new Error(`Your payload for '${modelClass.modelName}' contains '${key}', but your serializer is setup to look for '${relationshipKey}'. This is most likely because Ember Data's JSON API serializer dasherizes relationship keys by default. You should subclass JSONAPISerializer and implement 'keyForRelationship(key) { return key; }' to prevent Ember Data from customizing your relationship keys.`);
171
- }
172
- })() : {};
173
- }
174
- }
175
- });
176
- }
177
- return relationships;
178
- },
179
- /**
180
- @private
181
- */
182
- _extractType(modelClass, resourceHash) {
183
- return this.modelNameFromPayloadKey(resourceHash.type);
184
- },
185
- /**
186
- Dasherizes and singularizes the model name in the payload to match
187
- the common convention for model names.
188
- For example the key `posts` would be converted to `post` and the
189
- key `studentAssesments` would be converted to `student-assesment`.
190
- @public
191
- @return the model's modelName
192
- */
193
- modelNameFromPayloadKey(key) {
194
- return dasherize(singularize(key));
195
- },
196
- /**
197
- Converts the model name to a pluralized version of the model name.
198
- For example `post` would be converted to `posts` and
199
- `student-assesment` would be converted to `student-assesments`.
200
- @public
201
- */
202
- payloadKeyFromModelName(modelName) {
203
- return pluralize(modelName);
204
- },
205
- normalize(modelClass, resourceHash) {
206
- if (resourceHash.attributes) {
207
- // @ts-expect-error untyped
208
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash.attributes);
209
- }
210
- if (resourceHash.relationships) {
211
- // @ts-expect-error untyped
212
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash.relationships);
213
- }
214
- const data = {
215
- // @ts-expect-error untyped
216
- id: this.extractId(modelClass, resourceHash),
217
- type: this._extractType(modelClass, resourceHash),
218
- attributes: this.extractAttributes(modelClass, resourceHash),
219
- relationships: this.extractRelationships(modelClass, resourceHash)
220
- };
221
- if (resourceHash.lid) {
222
- // @ts-expect-error untyped
223
- data.lid = resourceHash.lid;
224
- }
19
+ `JSONAPISerializer` supports the http://jsonapi.org/ spec, though
20
+ even compliant {json:api} servers may find writing an application
21
+ specific serializer better suited to their needs and more performant.
225
22
 
226
- // @ts-expect-error untyped
227
- this.applyTransforms(modelClass, data.attributes);
228
- return {
229
- data
230
- };
231
- },
232
- /**
233
- `keyForAttribute` can be used to define rules for how to convert an
234
- attribute name in your model to a key in your JSON.
235
- By default `JSONAPISerializer` follows the format used on the examples of
236
- http://jsonapi.org/format and uses dashes as the word separator in the JSON
237
- attribute keys.
238
- This behaviour can be easily customized by extending this method.
239
- Example
240
- ```js [app/serializers/application.js]
241
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
242
- import { dasherize } from '<app-name>/utils/string-utils';
243
- export default class ApplicationSerializer extends JSONAPISerializer {
244
- keyForAttribute(attr, method) {
245
- return dasherize(attr).toUpperCase();
246
- }
247
- }
248
- ```
249
- @public
250
- @return normalized key
251
- */
252
- keyForAttribute(key, method) {
253
- return dasherize(key);
254
- },
255
- /**
256
- `keyForRelationship` can be used to define a custom key when
257
- serializing and deserializing relationship properties.
258
- By default `JSONAPISerializer` follows the format used on the examples of
259
- http://jsonapi.org/format and uses dashes as word separators in
260
- relationship properties.
261
- This behaviour can be easily customized by extending this method.
262
- Example
263
- ```js [app/serializers/post.js]
264
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
265
- import { underscore } from '<app-name>/utils/string-utils';
266
- export default class ApplicationSerializer extends JSONAPISerializer {
267
- keyForRelationship(key, relationship, method) {
268
- return underscore(key);
269
- }
270
- }
271
- ```
272
- @public
273
- @return the normalized key
274
- */
275
- keyForRelationship(key, typeClass, method) {
276
- return dasherize(key);
277
- },
278
- /**
279
- Called when a record is saved in order to convert the
280
- record into JSON.
281
- For example, consider this model:
282
- ```js [app/models/comment.js]
283
- import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
284
- export default class CommentModel extends Model {
285
- @attr title;
286
- @attr body;
287
- @belongsTo('user', { async: false, inverse: null })
288
- author;
289
- }
290
- ```
291
- The default serialization would create a JSON-API resource object like:
292
- ```javascript
293
- {
294
- "data": {
295
- "type": "comments",
296
- "attributes": {
297
- "title": "Rails is unagi",
298
- "body": "Rails? Omakase? O_O",
299
- },
300
- "relationships": {
301
- "author": {
302
- "data": {
303
- "id": "12",
304
- "type": "users"
305
- }
306
- }
307
- }
308
- }
309
- }
310
- ```
311
- By default, attributes are passed through as-is, unless
312
- you specified an attribute type (`attr('date')`). If
313
- you specify a transform, the JavaScript value will be
314
- serialized when inserted into the attributes hash.
315
- Belongs-to relationships are converted into JSON-API
316
- resource identifier objects.
317
- ## IDs
318
- `serialize` takes an options hash with a single option:
319
- `includeId`. If this option is `true`, `serialize` will,
320
- by default include the ID in the JSON object it builds.
321
- The JSONAPIAdapter passes in `includeId: true` when serializing a record
322
- for `createRecord` or `updateRecord`.
323
- ## Customization
324
- Your server may expect data in a different format than the
325
- built-in serialization format.
326
- In that case, you can implement `serialize` yourself and
327
- return data formatted to match your API's expectations, or override
328
- the invoked adapter method and do the serialization in the adapter directly
329
- by using the provided snapshot.
330
- If your API's format differs greatly from the JSON:API spec, you should
331
- consider authoring your own adapter and serializer instead of extending
332
- this class.
333
- ```js [app/serializers/post.js]
334
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
335
- export default class PostSerializer extends JSONAPISerializer {
336
- serialize(snapshot, options) {
337
- let json = {
338
- POST_TTL: snapshot.attr('title'),
339
- POST_BDY: snapshot.attr('body'),
340
- POST_CMS: snapshot.hasMany('comments', { ids: true })
341
- };
342
- if (options.includeId) {
343
- json.POST_ID_ = snapshot.id;
344
- }
345
- return json;
346
- }
347
- }
348
- ```
349
- ## Customizing an App-Wide Serializer
350
- If you want to define a serializer for your entire
351
- application, you'll probably want to use `eachAttribute`
352
- and `eachRelationship` on the record.
353
- ```js [app/serializers/application.js]
354
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
355
- import { underscore, singularize } from '<app-name>/utils/string-utils';
356
- export default class ApplicationSerializer extends JSONAPISerializer {
357
- serialize(snapshot, options) {
358
- let json = {};
359
- snapshot.eachAttribute((name) => {
360
- json[serverAttributeName(name)] = snapshot.attr(name);
361
- });
362
- snapshot.eachRelationship((name, relationship) => {
363
- if (relationship.kind === 'hasMany') {
364
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
365
- }
366
- });
367
- if (options.includeId) {
368
- json.ID_ = snapshot.id;
369
- }
370
- return json;
371
- }
372
- }
373
- function serverAttributeName(attribute) {
374
- return underscore(attribute).toUpperCase();
375
- }
376
- function serverHasManyName(name) {
377
- return serverAttributeName(singularize(name)) + '_IDS';
378
- }
379
- ```
380
- This serializer will generate JSON that looks like this:
381
- ```javascript
382
- {
383
- "TITLE": "Rails is omakase",
384
- "BODY": "Yep. Omakase.",
385
- "COMMENT_IDS": [ "1", "2", "3" ]
386
- }
387
- ```
388
- ## Tweaking the Default Formatting
389
- If you just want to do some small tweaks on the default JSON:API formatted response,
390
- you can call `super.serialize` first and make the tweaks
391
- on the returned object.
392
- ```js [app/serializers/post.js]
393
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
394
- export default class PostSerializer extends JSONAPISerializer {
395
- serialize(snapshot, options) {
396
- let json = super.serialize(...arguments);
397
- json.data.attributes.subject = json.data.attributes.title;
398
- delete json.data.attributes.title;
399
- return json;
400
- }
401
- }
402
- ```
403
- @public
404
- */
405
- serialize(snapshot, options) {
406
- // @ts-expect-error untyped
407
- const data = this._super(...arguments);
408
- data.type = this.payloadKeyFromModelName(snapshot.modelName);
409
- return {
410
- data
411
- };
412
- },
413
- serializeAttribute(snapshot, json, key, attribute) {
414
- const type = attribute.type;
23
+ This serializer normalizes a JSON API payload that looks like:
415
24
 
416
- // @ts-expect-error untyped
417
- if (this._canSerialize(key)) {
418
- json.attributes = json.attributes || {};
419
- let value = snapshot.attr(key);
420
- if (type) {
421
- // @ts-expect-error untyped
422
- const transform = this.transformFor(type);
423
- value = transform.serialize(value, attribute.options);
424
- }
25
+ ```js [app/models/player.js]
26
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
425
27
 
426
- // @ts-expect-error store is dynamically added
427
- const schema = this.store.modelFor(snapshot.modelName);
428
- // @ts-expect-error untyped
429
- let payloadKey = this._getMappedKey(key, schema);
430
- if (payloadKey === key) {
431
- payloadKey = this.keyForAttribute(key, 'serialize');
432
- }
433
- json.attributes[payloadKey] = value;
434
- }
435
- },
436
- serializeBelongsTo(snapshot, json, relationship) {
437
- const name = relationship.name;
28
+ export default class Player extends Model {
29
+ @attr('string') name;
30
+ @attr('string') skill;
31
+ @attr('number') gamesPlayed;
32
+ @belongsTo('club') club;
33
+ }
34
+ ```
438
35
 
439
- // @ts-expect-error untyped
440
- if (this._canSerialize(name)) {
441
- const belongsTo = snapshot.belongsTo(name);
442
- // @ts-expect-error not narrowed
443
- const belongsToIsNotNew = belongsTo && !belongsTo.isNew;
444
- if (belongsTo === null || belongsToIsNotNew) {
445
- json.relationships = json.relationships || {};
36
+ ```js [app/models/club.js]
37
+ import Model, { attr, hasMany } from '@warp-drive/legacy/model';
446
38
 
447
- // @ts-expect-error store is dynamically added
448
- const schema = this.store.modelFor(snapshot.modelName);
449
- // @ts-expect-error untyped
450
- let payloadKey = this._getMappedKey(name, schema);
451
- if (payloadKey === name) {
452
- payloadKey = this.keyForRelationship(name, 'belongsTo', 'serialize');
453
- }
454
- let data = null;
455
- if (belongsTo) {
456
- // @ts-expect-error not narrowed
457
- const payloadType = this.payloadKeyFromModelName(belongsTo.modelName);
39
+ export default class Club extends Model {
40
+ @attr('string') name;
41
+ @attr('string') location;
42
+ @hasMany('player') players;
43
+ }
44
+ ```
458
45
 
459
- // @ts-expect-error untyped
460
- data = {
461
- type: payloadType,
462
- // @ts-expect-error not narrowed
463
- id: belongsTo.id
464
- };
465
- }
466
- json.relationships[payloadKey] = {
467
- data
468
- };
469
- }
470
- }
471
- },
472
- serializeHasMany(snapshot, json, relationship) {
473
- const name = relationship.name;
46
+ ```js
47
+ {
48
+ "data": [
49
+ {
50
+ "attributes": {
51
+ "name": "Benfica",
52
+ "location": "Portugal"
53
+ },
54
+ "id": "1",
55
+ "relationships": {
56
+ "players": {
57
+ "data": [
58
+ {
59
+ "id": "3",
60
+ "type": "players"
61
+ }
62
+ ]
63
+ }
64
+ },
65
+ "type": "clubs"
66
+ }
67
+ ],
68
+ "included": [
69
+ {
70
+ "attributes": {
71
+ "name": "Eusebio Silva Ferreira",
72
+ "skill": "Rocket shot",
73
+ "games-played": 431
74
+ },
75
+ "id": "3",
76
+ "relationships": {
77
+ "club": {
78
+ "data": {
79
+ "id": "1",
80
+ "type": "clubs"
81
+ }
82
+ }
83
+ },
84
+ "type": "players"
85
+ }
86
+ ]
87
+ }
88
+ ```
474
89
 
475
- // @ts-expect-error untyped
476
- if (this.shouldSerializeHasMany(snapshot, name, relationship)) {
477
- const hasMany = snapshot.hasMany(name);
478
- if (hasMany !== undefined) {
479
- json.relationships = json.relationships || {};
90
+ to the format that the JSONAPICache expects.
480
91
 
481
- // @ts-expect-error store is dynamically added
482
- const schema = this.store.modelFor(snapshot.modelName);
483
- // @ts-expect-error untyped
484
- let payloadKey = this._getMappedKey(name, schema);
485
- if (payloadKey === name && this.keyForRelationship) {
486
- payloadKey = this.keyForRelationship(name, 'hasMany', 'serialize');
487
- }
92
+ ### Customizing meta
488
93
 
489
- // only serialize has many relationships that are not new
490
- // @ts-expect-error not narrowed
491
- const nonNewHasMany = hasMany.filter(item => !item.isNew);
492
- const data = new Array(nonNewHasMany.length);
493
- for (let i = 0; i < nonNewHasMany.length; i++) {
494
- const item = hasMany[i];
495
- // @ts-expect-error not narrowed
496
- const payloadType = this.payloadKeyFromModelName(item.modelName);
497
- data[i] = {
498
- type: payloadType,
499
- // @ts-expect-error not narrowed
500
- id: item.id
501
- };
502
- }
503
- json.relationships[payloadKey] = {
504
- data
505
- };
506
- }
507
- }
508
- }
509
- });
510
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
511
- JSONAPISerializer.reopen({
512
- init(...args) {
513
- this._super(...args);
514
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
515
- if (!test) {
516
- throw new Error(`You've used the EmbeddedRecordsMixin in ${this.toString()} which is not fully compatible with the JSON:API specification. Please confirm that this works for your specific API and add \`this.isEmbeddedRecordsMixinCompatible = true\` to your serializer.`);
517
- }
518
- })(!this.isEmbeddedRecordsMixin || this.isEmbeddedRecordsMixinCompatible === true) : {};
519
- const constructor = this.constructor;
520
- warn(`You've defined 'extractMeta' in ${constructor.toString()} which is not used for serializers extending JSONAPISerializer. Read more at https://api.emberjs.com/ember-data/release/classes/JSONAPISerializer on how to customize meta when using JSON API.`, this.extractMeta === JSONSerializer.prototype.extractMeta, {
521
- id: 'ds.serializer.json-api.extractMeta'
522
- });
523
- },
524
- warnMessageForUndefinedType() {
525
- return 'Encountered a resource object with an undefined type (resolved resource using ' + this.constructor.toString() + ')';
526
- },
527
- warnMessageNoModelForType(modelName, originalType, usedLookup) {
528
- return `Encountered a resource object with type "${originalType}", but no model was found for model name "${modelName}" (resolved model name using '${this.constructor.toString()}.${usedLookup}("${originalType}")').`;
529
- }
530
- });
94
+ Since a JSON API Document can have meta defined in multiple locations you can
95
+ use the specific serializer hooks if you need to customize the meta.
96
+
97
+ One scenario would be to camelCase the meta keys of your payload. The example
98
+ below shows how this could be done using `normalizeArrayResponse` and
99
+ `extractRelationship`.
100
+
101
+ ```js [app/serializers/application.js]
102
+ import { JSONAPISerializer } from '@warp-drive/legacy/serializer/json-api';
103
+
104
+ export default class ApplicationSerializer extends JSONAPISerializer {
105
+ normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
106
+ let normalizedDocument = super.normalizeArrayResponse(...arguments);
107
+
108
+ // Customize document meta
109
+ normalizedDocument.meta = camelCaseKeys(normalizedDocument.meta);
110
+
111
+ return normalizedDocument;
112
+ }
113
+
114
+ extractRelationship(relationshipHash) {
115
+ let normalizedRelationship = super.extractRelationship(...arguments);
116
+
117
+ // Customize relationship meta
118
+ normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);
119
+
120
+ return normalizedRelationship;
531
121
  }
532
- export { JSONAPISerializer };
122
+ }
123
+ ```
124
+
125
+ @since 1.13.0
126
+ @class JSONAPISerializer
127
+ @public
128
+ */
129
+ const JSONAPISerializer = JSONSerializer.extend({
130
+ /**
131
+ @private
132
+ */
133
+ _normalizeDocumentHelper(documentHash) {
134
+ if (Array.isArray(documentHash.data)) {
135
+ const ret = [];
136
+ for (let i = 0; i < documentHash.data.length; i++) {
137
+ const data = documentHash.data[i];
138
+ const normalized = this._normalizeResourceHelper(data);
139
+ if (normalized !== null) ret.push(normalized);
140
+ }
141
+ documentHash.data = ret;
142
+ } else if (documentHash.data && typeof documentHash.data === "object") documentHash.data = this._normalizeResourceHelper(documentHash.data);
143
+ if (Array.isArray(documentHash.included)) {
144
+ const ret = [];
145
+ for (let i = 0; i < documentHash.included.length; i++) {
146
+ const included = documentHash.included[i];
147
+ const normalized = this._normalizeResourceHelper(included);
148
+ if (normalized !== null) ret.push(normalized);
149
+ }
150
+ documentHash.included = ret;
151
+ }
152
+ return documentHash;
153
+ },
154
+ /**
155
+ @private
156
+ */
157
+ _normalizeRelationshipDataHelper(relationshipDataHash) {
158
+ relationshipDataHash.type = this.modelNameFromPayloadKey(relationshipDataHash.type);
159
+ return relationshipDataHash;
160
+ },
161
+ /**
162
+ @private
163
+ */
164
+ _normalizeResourceHelper(resourceHash) {
165
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
166
+ if (!test) throw new Error(this.warnMessageForUndefinedType());
167
+ })(resourceHash.type);
168
+ const type = this.modelNameFromPayloadKey(resourceHash.type);
169
+ if (!this.store.schema.hasResource({ type })) {
170
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) warn(this.warnMessageNoModelForType(type, resourceHash.type, "modelNameFromPayloadKey"), false, { id: "ds.serializer.model-for-type-missing" });
171
+ return null;
172
+ }
173
+ const modelClass = this.store.modelFor(type);
174
+ const { data } = this.store.serializerFor(type).normalize(modelClass, resourceHash);
175
+ return data;
176
+ },
177
+ /**
178
+ Normalize some data and push it into the store.
179
+ @public
180
+ */
181
+ pushPayload(store, payload) {
182
+ const normalizedPayload = this._normalizeDocumentHelper(payload);
183
+ store.push(normalizedPayload);
184
+ },
185
+ /**
186
+ @return A {json:api} Document
187
+ @private
188
+ */
189
+ _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
190
+ return this._normalizeDocumentHelper(payload);
191
+ },
192
+ normalizeQueryRecordResponse() {
193
+ const normalized = this._super(...arguments);
194
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
195
+ if (!test) throw new Error("Expected the primary data returned by the serializer for a `queryRecord` response to be a single object but instead it was an array.");
196
+ })(!Array.isArray(normalized.data));
197
+ return normalized;
198
+ },
199
+ extractAttributes(modelClass, resourceHash) {
200
+ const attributes = {};
201
+ if (resourceHash.attributes) modelClass.eachAttribute((key) => {
202
+ const attributeKey = this.keyForAttribute(key, "deserialize");
203
+ if (resourceHash.attributes[attributeKey] !== void 0) attributes[key] = resourceHash.attributes[attributeKey];
204
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
205
+ if (resourceHash.attributes[attributeKey] === void 0 && resourceHash.attributes[key] !== void 0) macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
206
+ if (!test) throw new Error(`Your payload for '${modelClass.modelName}' contains '${key}', but your serializer is setup to look for '${attributeKey}'. This is most likely because Ember Data's JSON API serializer dasherizes attribute keys by default. You should subclass JSONAPISerializer and implement 'keyForAttribute(key) { return key; }' to prevent Ember Data from customizing your attribute keys.`);
207
+ })(false);
208
+ }
209
+ });
210
+ return attributes;
211
+ },
212
+ /**
213
+ Returns a relationship formatted as a JSON-API "relationship object".
214
+ http://jsonapi.org/format/#document-resource-object-relationships
215
+ @public
216
+ */
217
+ extractRelationship(relationshipHash) {
218
+ if (Array.isArray(relationshipHash.data)) {
219
+ const ret = new Array(relationshipHash.data.length);
220
+ for (let i = 0; i < relationshipHash.data.length; i++) {
221
+ const data = relationshipHash.data[i];
222
+ ret[i] = this._normalizeRelationshipDataHelper(data);
223
+ }
224
+ relationshipHash.data = ret;
225
+ } else if (relationshipHash.data && typeof relationshipHash.data === "object") relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data);
226
+ return relationshipHash;
227
+ },
228
+ /**
229
+ Returns the resource's relationships formatted as a JSON-API "relationships object".
230
+ http://jsonapi.org/format/#document-resource-object-relationships
231
+ @public
232
+ */
233
+ extractRelationships(modelClass, resourceHash) {
234
+ const relationships = {};
235
+ if (resourceHash.relationships) modelClass.eachRelationship((key, relationshipMeta) => {
236
+ const relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, "deserialize");
237
+ if (resourceHash.relationships[relationshipKey] !== void 0) {
238
+ const relationshipHash = resourceHash.relationships[relationshipKey];
239
+ relationships[key] = this.extractRelationship(relationshipHash);
240
+ }
241
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
242
+ if (resourceHash.relationships[relationshipKey] === void 0 && resourceHash.relationships[key] !== void 0) macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
243
+ if (!test) throw new Error(`Your payload for '${modelClass.modelName}' contains '${key}', but your serializer is setup to look for '${relationshipKey}'. This is most likely because Ember Data's JSON API serializer dasherizes relationship keys by default. You should subclass JSONAPISerializer and implement 'keyForRelationship(key) { return key; }' to prevent Ember Data from customizing your relationship keys.`);
244
+ })(false);
245
+ }
246
+ });
247
+ return relationships;
248
+ },
249
+ /**
250
+ @private
251
+ */
252
+ _extractType(modelClass, resourceHash) {
253
+ return this.modelNameFromPayloadKey(resourceHash.type);
254
+ },
255
+ /**
256
+ Dasherizes and singularizes the model name in the payload to match
257
+ the common convention for model names.
258
+ For example the key `posts` would be converted to `post` and the
259
+ key `studentAssesments` would be converted to `student-assesment`.
260
+ @public
261
+ @return the model's modelName
262
+ */
263
+ modelNameFromPayloadKey(key) {
264
+ return dasherize(singularize(key));
265
+ },
266
+ /**
267
+ Converts the model name to a pluralized version of the model name.
268
+ For example `post` would be converted to `posts` and
269
+ `student-assesment` would be converted to `student-assesments`.
270
+ @public
271
+ */
272
+ payloadKeyFromModelName(modelName) {
273
+ return pluralize(modelName);
274
+ },
275
+ normalize(modelClass, resourceHash) {
276
+ if (resourceHash.attributes) this.normalizeUsingDeclaredMapping(modelClass, resourceHash.attributes);
277
+ if (resourceHash.relationships) this.normalizeUsingDeclaredMapping(modelClass, resourceHash.relationships);
278
+ const data = {
279
+ id: this.extractId(modelClass, resourceHash),
280
+ type: this._extractType(modelClass, resourceHash),
281
+ attributes: this.extractAttributes(modelClass, resourceHash),
282
+ relationships: this.extractRelationships(modelClass, resourceHash)
283
+ };
284
+ if (resourceHash.lid) data.lid = resourceHash.lid;
285
+ this.applyTransforms(modelClass, data.attributes);
286
+ return { data };
287
+ },
288
+ /**
289
+ `keyForAttribute` can be used to define rules for how to convert an
290
+ attribute name in your model to a key in your JSON.
291
+ By default `JSONAPISerializer` follows the format used on the examples of
292
+ http://jsonapi.org/format and uses dashes as the word separator in the JSON
293
+ attribute keys.
294
+ This behaviour can be easily customized by extending this method.
295
+ Example
296
+ ```js [app/serializers/application.js]
297
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
298
+ import { dasherize } from '<app-name>/utils/string-utils';
299
+ export default class ApplicationSerializer extends JSONAPISerializer {
300
+ keyForAttribute(attr, method) {
301
+ return dasherize(attr).toUpperCase();
302
+ }
303
+ }
304
+ ```
305
+ @public
306
+ @return normalized key
307
+ */
308
+ keyForAttribute(key, method) {
309
+ return dasherize(key);
310
+ },
311
+ /**
312
+ `keyForRelationship` can be used to define a custom key when
313
+ serializing and deserializing relationship properties.
314
+ By default `JSONAPISerializer` follows the format used on the examples of
315
+ http://jsonapi.org/format and uses dashes as word separators in
316
+ relationship properties.
317
+ This behaviour can be easily customized by extending this method.
318
+ Example
319
+ ```js [app/serializers/post.js]
320
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
321
+ import { underscore } from '<app-name>/utils/string-utils';
322
+ export default class ApplicationSerializer extends JSONAPISerializer {
323
+ keyForRelationship(key, relationship, method) {
324
+ return underscore(key);
325
+ }
326
+ }
327
+ ```
328
+ @public
329
+ @return the normalized key
330
+ */
331
+ keyForRelationship(key, typeClass, method) {
332
+ return dasherize(key);
333
+ },
334
+ /**
335
+ Called when a record is saved in order to convert the
336
+ record into JSON.
337
+ For example, consider this model:
338
+ ```js [app/models/comment.js]
339
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
340
+ export default class CommentModel extends Model {
341
+ @attr title;
342
+ @attr body;
343
+ @belongsTo('user', { async: false, inverse: null })
344
+ author;
345
+ }
346
+ ```
347
+ The default serialization would create a JSON-API resource object like:
348
+ ```javascript
349
+ {
350
+ "data": {
351
+ "type": "comments",
352
+ "attributes": {
353
+ "title": "Rails is unagi",
354
+ "body": "Rails? Omakase? O_O",
355
+ },
356
+ "relationships": {
357
+ "author": {
358
+ "data": {
359
+ "id": "12",
360
+ "type": "users"
361
+ }
362
+ }
363
+ }
364
+ }
365
+ }
366
+ ```
367
+ By default, attributes are passed through as-is, unless
368
+ you specified an attribute type (`attr('date')`). If
369
+ you specify a transform, the JavaScript value will be
370
+ serialized when inserted into the attributes hash.
371
+ Belongs-to relationships are converted into JSON-API
372
+ resource identifier objects.
373
+ ## IDs
374
+ `serialize` takes an options hash with a single option:
375
+ `includeId`. If this option is `true`, `serialize` will,
376
+ by default include the ID in the JSON object it builds.
377
+ The JSONAPIAdapter passes in `includeId: true` when serializing a record
378
+ for `createRecord` or `updateRecord`.
379
+ ## Customization
380
+ Your server may expect data in a different format than the
381
+ built-in serialization format.
382
+ In that case, you can implement `serialize` yourself and
383
+ return data formatted to match your API's expectations, or override
384
+ the invoked adapter method and do the serialization in the adapter directly
385
+ by using the provided snapshot.
386
+ If your API's format differs greatly from the JSON:API spec, you should
387
+ consider authoring your own adapter and serializer instead of extending
388
+ this class.
389
+ ```js [app/serializers/post.js]
390
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
391
+ export default class PostSerializer extends JSONAPISerializer {
392
+ serialize(snapshot, options) {
393
+ let json = {
394
+ POST_TTL: snapshot.attr('title'),
395
+ POST_BDY: snapshot.attr('body'),
396
+ POST_CMS: snapshot.hasMany('comments', { ids: true })
397
+ };
398
+ if (options.includeId) {
399
+ json.POST_ID_ = snapshot.id;
400
+ }
401
+ return json;
402
+ }
403
+ }
404
+ ```
405
+ ## Customizing an App-Wide Serializer
406
+ If you want to define a serializer for your entire
407
+ application, you'll probably want to use `eachAttribute`
408
+ and `eachRelationship` on the record.
409
+ ```js [app/serializers/application.js]
410
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
411
+ import { underscore, singularize } from '<app-name>/utils/string-utils';
412
+ export default class ApplicationSerializer extends JSONAPISerializer {
413
+ serialize(snapshot, options) {
414
+ let json = {};
415
+ snapshot.eachAttribute((name) => {
416
+ json[serverAttributeName(name)] = snapshot.attr(name);
417
+ });
418
+ snapshot.eachRelationship((name, relationship) => {
419
+ if (relationship.kind === 'hasMany') {
420
+ json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
421
+ }
422
+ });
423
+ if (options.includeId) {
424
+ json.ID_ = snapshot.id;
425
+ }
426
+ return json;
427
+ }
428
+ }
429
+ function serverAttributeName(attribute) {
430
+ return underscore(attribute).toUpperCase();
431
+ }
432
+ function serverHasManyName(name) {
433
+ return serverAttributeName(singularize(name)) + '_IDS';
434
+ }
435
+ ```
436
+ This serializer will generate JSON that looks like this:
437
+ ```javascript
438
+ {
439
+ "TITLE": "Rails is omakase",
440
+ "BODY": "Yep. Omakase.",
441
+ "COMMENT_IDS": [ "1", "2", "3" ]
442
+ }
443
+ ```
444
+ ## Tweaking the Default Formatting
445
+ If you just want to do some small tweaks on the default JSON:API formatted response,
446
+ you can call `super.serialize` first and make the tweaks
447
+ on the returned object.
448
+ ```js [app/serializers/post.js]
449
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
450
+ export default class PostSerializer extends JSONAPISerializer {
451
+ serialize(snapshot, options) {
452
+ let json = super.serialize(...arguments);
453
+ json.data.attributes.subject = json.data.attributes.title;
454
+ delete json.data.attributes.title;
455
+ return json;
456
+ }
457
+ }
458
+ ```
459
+ @public
460
+ */
461
+ serialize(snapshot, options) {
462
+ const data = this._super(...arguments);
463
+ data.type = this.payloadKeyFromModelName(snapshot.modelName);
464
+ return { data };
465
+ },
466
+ serializeAttribute(snapshot, json, key, attribute) {
467
+ const type = attribute.type;
468
+ if (this._canSerialize(key)) {
469
+ json.attributes = json.attributes || {};
470
+ let value = snapshot.attr(key);
471
+ if (type) value = this.transformFor(type).serialize(value, attribute.options);
472
+ const schema = this.store.modelFor(snapshot.modelName);
473
+ let payloadKey = this._getMappedKey(key, schema);
474
+ if (payloadKey === key) payloadKey = this.keyForAttribute(key, "serialize");
475
+ json.attributes[payloadKey] = value;
476
+ }
477
+ },
478
+ serializeBelongsTo(snapshot, json, relationship) {
479
+ const name = relationship.name;
480
+ if (this._canSerialize(name)) {
481
+ const belongsTo = snapshot.belongsTo(name);
482
+ const belongsToIsNotNew = belongsTo && !belongsTo.isNew;
483
+ if (belongsTo === null || belongsToIsNotNew) {
484
+ json.relationships = json.relationships || {};
485
+ const schema = this.store.modelFor(snapshot.modelName);
486
+ let payloadKey = this._getMappedKey(name, schema);
487
+ if (payloadKey === name) payloadKey = this.keyForRelationship(name, "belongsTo", "serialize");
488
+ let data = null;
489
+ if (belongsTo) data = {
490
+ type: this.payloadKeyFromModelName(belongsTo.modelName),
491
+ id: belongsTo.id
492
+ };
493
+ json.relationships[payloadKey] = { data };
494
+ }
495
+ }
496
+ },
497
+ serializeHasMany(snapshot, json, relationship) {
498
+ const name = relationship.name;
499
+ if (this.shouldSerializeHasMany(snapshot, name, relationship)) {
500
+ const hasMany = snapshot.hasMany(name);
501
+ if (hasMany !== void 0) {
502
+ json.relationships = json.relationships || {};
503
+ const schema = this.store.modelFor(snapshot.modelName);
504
+ let payloadKey = this._getMappedKey(name, schema);
505
+ if (payloadKey === name && this.keyForRelationship) payloadKey = this.keyForRelationship(name, "hasMany", "serialize");
506
+ const nonNewHasMany = hasMany.filter((item) => !item.isNew);
507
+ const data = new Array(nonNewHasMany.length);
508
+ for (let i = 0; i < nonNewHasMany.length; i++) {
509
+ const item = hasMany[i];
510
+ const payloadType = this.payloadKeyFromModelName(item.modelName);
511
+ data[i] = {
512
+ type: payloadType,
513
+ id: item.id
514
+ };
515
+ }
516
+ json.relationships[payloadKey] = { data };
517
+ }
518
+ }
519
+ }
520
+ });
521
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) JSONAPISerializer.reopen({
522
+ init(...args) {
523
+ this._super(...args);
524
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
525
+ if (!test) throw new Error(`You've used the EmbeddedRecordsMixin in ${this.toString()} which is not fully compatible with the JSON:API specification. Please confirm that this works for your specific API and add \`this.isEmbeddedRecordsMixinCompatible = true\` to your serializer.`);
526
+ })(!this.isEmbeddedRecordsMixin || this.isEmbeddedRecordsMixinCompatible === true);
527
+ const constructor = this.constructor;
528
+ warn(`You've defined 'extractMeta' in ${constructor.toString()} which is not used for serializers extending JSONAPISerializer. Read more at https://api.emberjs.com/ember-data/release/classes/JSONAPISerializer on how to customize meta when using JSON API.`, this.extractMeta === JSONSerializer.prototype.extractMeta, { id: "ds.serializer.json-api.extractMeta" });
529
+ },
530
+ warnMessageForUndefinedType() {
531
+ return "Encountered a resource object with an undefined type (resolved resource using " + this.constructor.toString() + ")";
532
+ },
533
+ warnMessageNoModelForType(modelName, originalType, usedLookup) {
534
+ return `Encountered a resource object with type "${originalType}", but no model was found for model name "${modelName}" (resolved model name using '${this.constructor.toString()}.${usedLookup}("${originalType}")').`;
535
+ }
536
+ });
537
+
538
+ //#endregion
539
+ export { JSONAPISerializer };
540
+ //# sourceMappingURL=json-api.js.map