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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. package/README.md +6 -0
  2. package/dist/-private-DQ6Iap2t.js +193 -0
  3. package/dist/-private-DQ6Iap2t.js.map +1 -0
  4. package/dist/-private-DccRZQsm.js +904 -0
  5. package/dist/-private-DccRZQsm.js.map +1 -0
  6. package/dist/adapter/-private.d.ts +33 -0
  7. package/dist/adapter/-private.d.ts.map +1 -0
  8. package/dist/adapter/-private.js +3 -1
  9. package/dist/adapter/error.d.ts +2 -0
  10. package/dist/adapter/error.js +425 -311
  11. package/dist/adapter/error.js.map +1 -0
  12. package/{declarations → dist}/adapter/json-api.d.ts +31 -19
  13. package/dist/adapter/json-api.d.ts.map +1 -0
  14. package/dist/adapter/json-api.js +265 -131
  15. package/dist/adapter/json-api.js.map +1 -0
  16. package/dist/adapter/rest.d.ts +2 -0
  17. package/dist/adapter/rest.js +937 -1100
  18. package/dist/adapter/rest.js.map +1 -0
  19. package/dist/adapter-CARrK3-8.d.ts +784 -0
  20. package/dist/adapter-CARrK3-8.d.ts.map +1 -0
  21. package/dist/adapter-eYo2pIuM.js +1130 -0
  22. package/dist/adapter-eYo2pIuM.js.map +1 -0
  23. package/dist/adapter.d.ts +2 -0
  24. package/dist/adapter.js +1 -1251
  25. package/dist/compat/-private.d.ts +2 -0
  26. package/dist/compat/-private.js +3 -1
  27. package/dist/compat/builders.d.ts +169 -0
  28. package/dist/compat/builders.d.ts.map +1 -0
  29. package/dist/compat/builders.js +205 -246
  30. package/dist/compat/builders.js.map +1 -0
  31. package/dist/compat/extensions.d.ts +2 -0
  32. package/dist/compat/extensions.js +271 -233
  33. package/dist/compat/extensions.js.map +1 -0
  34. package/dist/compat/utils.d.ts +151 -0
  35. package/dist/compat/utils.d.ts.map +1 -0
  36. package/dist/compat/utils.js +189 -194
  37. package/dist/compat/utils.js.map +1 -0
  38. package/dist/compat-BbNNmTM-.d.ts +1386 -0
  39. package/dist/compat-BbNNmTM-.d.ts.map +1 -0
  40. package/dist/compat-DcHVxuuZ.js +734 -0
  41. package/dist/compat-DcHVxuuZ.js.map +1 -0
  42. package/dist/compat.d.ts +2 -0
  43. package/dist/compat.js +1 -1019
  44. package/dist/error-CzkyXr1Q.d.ts +435 -0
  45. package/dist/error-CzkyXr1Q.d.ts.map +1 -0
  46. package/dist/errors-BEEsrHbl.js +2134 -0
  47. package/dist/errors-BEEsrHbl.js.map +1 -0
  48. package/dist/extensions-DumNm4dA.d.ts +102 -0
  49. package/dist/extensions-DumNm4dA.d.ts.map +1 -0
  50. package/dist/index.d.ts +243 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +271 -188
  53. package/dist/index.js.map +1 -0
  54. package/dist/json-BXNPTlcH.js +1106 -0
  55. package/dist/json-BXNPTlcH.js.map +1 -0
  56. package/dist/model/-private.d.ts +3 -0
  57. package/dist/model/-private.js +3 -1
  58. package/dist/model/migration-support.d.ts +335 -0
  59. package/dist/model/migration-support.d.ts.map +1 -0
  60. package/dist/model/migration-support.js +506 -564
  61. package/dist/model/migration-support.js.map +1 -0
  62. package/dist/model-62hn5_PD.d.ts +3107 -0
  63. package/dist/model-62hn5_PD.d.ts.map +1 -0
  64. package/dist/model-DcXZdNMu.js +683 -0
  65. package/dist/model-DcXZdNMu.js.map +1 -0
  66. package/dist/model-fragments-DSqu0ptR.js +334 -0
  67. package/dist/model-fragments-DSqu0ptR.js.map +1 -0
  68. package/dist/model-fragments.d.ts +294 -0
  69. package/dist/model-fragments.d.ts.map +1 -0
  70. package/dist/model-fragments.js +2 -75
  71. package/dist/model.d.ts +404 -0
  72. package/dist/model.d.ts.map +1 -0
  73. package/dist/model.js +3 -666
  74. package/{declarations/adapter/rest.d.ts → dist/rest-0NhtexIq.d.ts} +187 -103
  75. package/dist/rest-0NhtexIq.d.ts.map +1 -0
  76. package/dist/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  77. package/dist/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  78. package/dist/schema-provider-H4zNXtry.js +1929 -0
  79. package/dist/schema-provider-H4zNXtry.js.map +1 -0
  80. package/{declarations → dist}/serializer/json-api.d.ts +4 -1
  81. package/dist/serializer/json-api.d.ts.map +1 -0
  82. package/dist/serializer/json-api.js +527 -514
  83. package/dist/serializer/json-api.js.map +1 -0
  84. package/{declarations → dist}/serializer/json.d.ts +3 -0
  85. package/dist/serializer/json.d.ts.map +1 -0
  86. package/dist/serializer/json.js +3 -6
  87. package/{declarations/serializer/-private/embedded-records-mixin.d.ts → dist/serializer/rest.d.ts} +56 -1
  88. package/dist/serializer/rest.d.ts.map +1 -0
  89. package/dist/serializer/rest.js +958 -1200
  90. package/dist/serializer/rest.js.map +1 -0
  91. package/dist/serializer/transform.d.ts +313 -0
  92. package/dist/serializer/transform.d.ts.map +1 -0
  93. package/dist/serializer/transform.js +283 -260
  94. package/dist/serializer/transform.js.map +1 -0
  95. package/dist/serializer.d.ts +151 -0
  96. package/dist/serializer.d.ts.map +1 -0
  97. package/dist/serializer.js +205 -208
  98. package/dist/serializer.js.map +1 -0
  99. package/dist/store-C4qYzXei.js +473 -0
  100. package/dist/store-C4qYzXei.js.map +1 -0
  101. package/dist/store.d.ts +13 -0
  102. package/dist/store.d.ts.map +1 -0
  103. package/dist/store.js +1 -635
  104. package/dist/unpkg/dev/-private-CrEyBE-B.js +189 -0
  105. package/dist/unpkg/dev/-private-CrEyBE-B.js.map +1 -0
  106. package/dist/unpkg/dev/-private-vOhxVExH.js +896 -0
  107. package/dist/unpkg/dev/-private-vOhxVExH.js.map +1 -0
  108. package/dist/unpkg/dev/adapter/-private.js +3 -1
  109. package/dist/unpkg/dev/adapter/error.js +424 -310
  110. package/dist/unpkg/dev/adapter/error.js.map +1 -0
  111. package/dist/unpkg/dev/adapter/json-api.js +239 -245
  112. package/dist/unpkg/dev/adapter/json-api.js.map +1 -0
  113. package/dist/unpkg/dev/adapter/rest.js +935 -1098
  114. package/dist/unpkg/dev/adapter/rest.js.map +1 -0
  115. package/dist/unpkg/dev/adapter-oLwyr47q.js +1129 -0
  116. package/dist/unpkg/dev/adapter-oLwyr47q.js.map +1 -0
  117. package/dist/unpkg/dev/adapter.js +1 -1250
  118. package/dist/unpkg/dev/compat/-private.js +3 -1
  119. package/dist/unpkg/dev/compat/builders.js +204 -248
  120. package/dist/unpkg/dev/compat/builders.js.map +1 -0
  121. package/dist/unpkg/dev/compat/extensions.js +270 -232
  122. package/dist/unpkg/dev/compat/extensions.js.map +1 -0
  123. package/dist/unpkg/dev/compat/utils.js +188 -193
  124. package/dist/unpkg/dev/compat/utils.js.map +1 -0
  125. package/dist/unpkg/dev/compat-D48B8sXv.js +825 -0
  126. package/dist/unpkg/dev/compat-D48B8sXv.js.map +1 -0
  127. package/dist/unpkg/dev/compat.js +1 -1145
  128. package/dist/unpkg/dev/errors-8GnRWcxo.js +2127 -0
  129. package/dist/unpkg/dev/errors-8GnRWcxo.js.map +1 -0
  130. package/dist/unpkg/dev/index.js +270 -190
  131. package/dist/unpkg/dev/index.js.map +1 -0
  132. package/dist/unpkg/dev/json-DDJji3V3.js +1104 -0
  133. package/dist/unpkg/dev/json-DDJji3V3.js.map +1 -0
  134. package/dist/unpkg/dev/model/-private.js +3 -1
  135. package/dist/unpkg/dev/model/migration-support.js +483 -537
  136. package/dist/unpkg/dev/model/migration-support.js.map +1 -0
  137. package/dist/unpkg/dev/model-LK7ethC5.js +655 -0
  138. package/dist/unpkg/dev/model-LK7ethC5.js.map +1 -0
  139. package/dist/unpkg/dev/model-fragments-DSqu0ptR.js +334 -0
  140. package/dist/unpkg/dev/model-fragments-DSqu0ptR.js.map +1 -0
  141. package/dist/unpkg/dev/model-fragments.js +2 -75
  142. package/dist/unpkg/dev/model.js +3 -677
  143. package/dist/unpkg/dev/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  144. package/dist/unpkg/dev/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  145. package/dist/unpkg/dev/schema-provider-CRzoMoTO.js +1834 -0
  146. package/dist/unpkg/dev/schema-provider-CRzoMoTO.js.map +1 -0
  147. package/dist/unpkg/dev/serializer/json-api.js +514 -629
  148. package/dist/unpkg/dev/serializer/json-api.js.map +1 -0
  149. package/dist/unpkg/dev/serializer/json.js +3 -4
  150. package/dist/unpkg/dev/serializer/rest.js +954 -1197
  151. package/dist/unpkg/dev/serializer/rest.js.map +1 -0
  152. package/dist/unpkg/dev/serializer/transform.js +283 -260
  153. package/dist/unpkg/dev/serializer/transform.js.map +1 -0
  154. package/dist/unpkg/dev/serializer.js +205 -208
  155. package/dist/unpkg/dev/serializer.js.map +1 -0
  156. package/dist/unpkg/dev/store-D_V8-HQl.js +472 -0
  157. package/dist/unpkg/dev/store-D_V8-HQl.js.map +1 -0
  158. package/dist/unpkg/dev/store.js +1 -635
  159. package/dist/unpkg/dev/util-dSKEgQDp.js +12 -0
  160. package/dist/unpkg/dev/util-dSKEgQDp.js.map +1 -0
  161. package/dist/unpkg/dev/utils-DYC9utVJ.js +11 -0
  162. package/dist/unpkg/dev/utils-DYC9utVJ.js.map +1 -0
  163. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js +189 -0
  164. package/dist/unpkg/dev-deprecated/-private-CrEyBE-B.js.map +1 -0
  165. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js +896 -0
  166. package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js.map +1 -0
  167. package/dist/unpkg/dev-deprecated/adapter/-private.js +3 -1
  168. package/dist/unpkg/dev-deprecated/adapter/error.js +424 -310
  169. package/dist/unpkg/dev-deprecated/adapter/error.js.map +1 -0
  170. package/dist/unpkg/dev-deprecated/adapter/json-api.js +239 -245
  171. package/dist/unpkg/dev-deprecated/adapter/json-api.js.map +1 -0
  172. package/dist/unpkg/dev-deprecated/adapter/rest.js +935 -1098
  173. package/dist/unpkg/dev-deprecated/adapter/rest.js.map +1 -0
  174. package/dist/unpkg/dev-deprecated/adapter-oLwyr47q.js +1129 -0
  175. package/dist/unpkg/dev-deprecated/adapter-oLwyr47q.js.map +1 -0
  176. package/dist/unpkg/dev-deprecated/adapter.js +1 -1250
  177. package/dist/unpkg/dev-deprecated/compat/-private.js +3 -1
  178. package/dist/unpkg/dev-deprecated/compat/builders.js +204 -248
  179. package/dist/unpkg/dev-deprecated/compat/builders.js.map +1 -0
  180. package/dist/unpkg/dev-deprecated/compat/extensions.js +270 -232
  181. package/dist/unpkg/dev-deprecated/compat/extensions.js.map +1 -0
  182. package/dist/unpkg/dev-deprecated/compat/utils.js +188 -193
  183. package/dist/unpkg/dev-deprecated/compat/utils.js.map +1 -0
  184. package/dist/unpkg/dev-deprecated/compat-DGSurLh7.js +825 -0
  185. package/dist/unpkg/dev-deprecated/compat-DGSurLh7.js.map +1 -0
  186. package/dist/unpkg/dev-deprecated/compat.js +1 -1145
  187. package/dist/unpkg/dev-deprecated/errors-0ydn94s0.js +2128 -0
  188. package/dist/unpkg/dev-deprecated/errors-0ydn94s0.js.map +1 -0
  189. package/dist/unpkg/dev-deprecated/index.js +270 -189
  190. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  191. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js +1104 -0
  192. package/dist/unpkg/dev-deprecated/json-DDJji3V3.js.map +1 -0
  193. package/dist/unpkg/dev-deprecated/model/-private.js +3 -1
  194. package/dist/unpkg/dev-deprecated/model/migration-support.js +494 -554
  195. package/dist/unpkg/dev-deprecated/model/migration-support.js.map +1 -0
  196. package/dist/unpkg/dev-deprecated/model-C1ts6Mod.js +660 -0
  197. package/dist/unpkg/dev-deprecated/model-C1ts6Mod.js.map +1 -0
  198. package/dist/unpkg/dev-deprecated/model-fragments-DSqu0ptR.js +334 -0
  199. package/dist/unpkg/dev-deprecated/model-fragments-DSqu0ptR.js.map +1 -0
  200. package/dist/unpkg/dev-deprecated/model-fragments.js +2 -75
  201. package/dist/unpkg/dev-deprecated/model.js +3 -681
  202. package/dist/unpkg/dev-deprecated/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  203. package/dist/unpkg/dev-deprecated/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  204. package/dist/unpkg/dev-deprecated/schema-provider-D2ESMsA8.js +1835 -0
  205. package/dist/unpkg/dev-deprecated/schema-provider-D2ESMsA8.js.map +1 -0
  206. package/dist/unpkg/dev-deprecated/serializer/json-api.js +514 -629
  207. package/dist/unpkg/dev-deprecated/serializer/json-api.js.map +1 -0
  208. package/dist/unpkg/dev-deprecated/serializer/json.js +3 -4
  209. package/dist/unpkg/dev-deprecated/serializer/rest.js +954 -1197
  210. package/dist/unpkg/dev-deprecated/serializer/rest.js.map +1 -0
  211. package/dist/unpkg/dev-deprecated/serializer/transform.js +283 -260
  212. package/dist/unpkg/dev-deprecated/serializer/transform.js.map +1 -0
  213. package/dist/unpkg/dev-deprecated/serializer.js +205 -208
  214. package/dist/unpkg/dev-deprecated/serializer.js.map +1 -0
  215. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js +472 -0
  216. package/dist/unpkg/dev-deprecated/store-BX7GvXC_.js.map +1 -0
  217. package/dist/unpkg/dev-deprecated/store.js +1 -635
  218. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js +18 -0
  219. package/dist/unpkg/dev-deprecated/util-9mgEBJ3W.js.map +1 -0
  220. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js +17 -0
  221. package/dist/unpkg/dev-deprecated/utils-Cl86-e7F.js.map +1 -0
  222. package/dist/unpkg/prod/-private-B4bxoTuK.js +160 -0
  223. package/dist/unpkg/prod/-private-B4bxoTuK.js.map +1 -0
  224. package/dist/unpkg/prod/-private-SfXkkHKd.js +745 -0
  225. package/dist/unpkg/prod/-private-SfXkkHKd.js.map +1 -0
  226. package/dist/unpkg/prod/adapter/-private.js +3 -1
  227. package/dist/unpkg/prod/adapter/error.js +421 -305
  228. package/dist/unpkg/prod/adapter/error.js.map +1 -0
  229. package/dist/unpkg/prod/adapter/json-api.js +236 -240
  230. package/dist/unpkg/prod/adapter/json-api.js.map +1 -0
  231. package/dist/unpkg/prod/adapter/rest.js +911 -1061
  232. package/dist/unpkg/prod/adapter/rest.js.map +1 -0
  233. package/dist/unpkg/prod/adapter-DQ9UA7FC.js +1111 -0
  234. package/dist/unpkg/prod/adapter-DQ9UA7FC.js.map +1 -0
  235. package/dist/unpkg/prod/adapter.js +1 -1217
  236. package/dist/unpkg/prod/compat/-private.js +3 -1
  237. package/dist/unpkg/prod/compat/builders.js +165 -183
  238. package/dist/unpkg/prod/compat/builders.js.map +1 -0
  239. package/dist/unpkg/prod/compat/extensions.js +258 -222
  240. package/dist/unpkg/prod/compat/extensions.js.map +1 -0
  241. package/dist/unpkg/prod/compat/utils.js +185 -188
  242. package/dist/unpkg/prod/compat/utils.js.map +1 -0
  243. package/dist/unpkg/prod/compat-DxiVkCUb.js +547 -0
  244. package/dist/unpkg/prod/compat-DxiVkCUb.js.map +1 -0
  245. package/dist/unpkg/prod/compat.js +1 -725
  246. package/dist/unpkg/prod/errors-CVXWrUjP.js +1977 -0
  247. package/dist/unpkg/prod/errors-CVXWrUjP.js.map +1 -0
  248. package/dist/unpkg/prod/index.js +249 -146
  249. package/dist/unpkg/prod/index.js.map +1 -0
  250. package/dist/unpkg/prod/json-BD1kRTfB.js +1080 -0
  251. package/dist/unpkg/prod/json-BD1kRTfB.js.map +1 -0
  252. package/dist/unpkg/prod/model/-private.js +3 -1
  253. package/dist/unpkg/prod/model/migration-support.js +479 -530
  254. package/dist/unpkg/prod/model/migration-support.js.map +1 -0
  255. package/dist/unpkg/prod/model-D3WMsNNE.js +603 -0
  256. package/dist/unpkg/prod/model-D3WMsNNE.js.map +1 -0
  257. package/dist/unpkg/prod/model-fragments-DSqu0ptR.js +334 -0
  258. package/dist/unpkg/prod/model-fragments-DSqu0ptR.js.map +1 -0
  259. package/dist/unpkg/prod/model-fragments.js +2 -75
  260. package/dist/unpkg/prod/model.js +3 -592
  261. package/dist/unpkg/prod/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  262. package/dist/unpkg/prod/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  263. package/dist/unpkg/prod/schema-provider-_pimTZ3P.js +1622 -0
  264. package/dist/unpkg/prod/schema-provider-_pimTZ3P.js.map +1 -0
  265. package/dist/unpkg/prod/serializer/json-api.js +497 -587
  266. package/dist/unpkg/prod/serializer/json-api.js.map +1 -0
  267. package/dist/unpkg/prod/serializer/json.js +3 -4
  268. package/dist/unpkg/prod/serializer/rest.js +938 -1167
  269. package/dist/unpkg/prod/serializer/rest.js.map +1 -0
  270. package/dist/unpkg/prod/serializer/transform.js +283 -260
  271. package/dist/unpkg/prod/serializer/transform.js.map +1 -0
  272. package/dist/unpkg/prod/serializer.js +205 -208
  273. package/dist/unpkg/prod/serializer.js.map +1 -0
  274. package/dist/unpkg/prod/store-RGGc1ilN.js +392 -0
  275. package/dist/unpkg/prod/store-RGGc1ilN.js.map +1 -0
  276. package/dist/unpkg/prod/store.js +1 -503
  277. package/dist/unpkg/prod/util-dSKEgQDp.js +12 -0
  278. package/dist/unpkg/prod/util-dSKEgQDp.js.map +1 -0
  279. package/dist/unpkg/prod/utils-DYC9utVJ.js +11 -0
  280. package/dist/unpkg/prod/utils-DYC9utVJ.js.map +1 -0
  281. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js +160 -0
  282. package/dist/unpkg/prod-deprecated/-private-B4bxoTuK.js.map +1 -0
  283. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js +745 -0
  284. package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js.map +1 -0
  285. package/dist/unpkg/prod-deprecated/adapter/-private.js +3 -1
  286. package/dist/unpkg/prod-deprecated/adapter/error.js +421 -305
  287. package/dist/unpkg/prod-deprecated/adapter/error.js.map +1 -0
  288. package/dist/unpkg/prod-deprecated/adapter/json-api.js +236 -240
  289. package/dist/unpkg/prod-deprecated/adapter/json-api.js.map +1 -0
  290. package/dist/unpkg/prod-deprecated/adapter/rest.js +911 -1061
  291. package/dist/unpkg/prod-deprecated/adapter/rest.js.map +1 -0
  292. package/{declarations/adapter.d.ts → dist/unpkg/prod-deprecated/adapter-DQ9UA7FC.js} +451 -110
  293. package/dist/unpkg/prod-deprecated/adapter-DQ9UA7FC.js.map +1 -0
  294. package/dist/unpkg/prod-deprecated/adapter.js +1 -1217
  295. package/dist/unpkg/prod-deprecated/compat/-private.js +3 -1
  296. package/dist/unpkg/prod-deprecated/compat/builders.js +165 -183
  297. package/dist/unpkg/prod-deprecated/compat/builders.js.map +1 -0
  298. package/dist/unpkg/prod-deprecated/compat/extensions.js +258 -222
  299. package/dist/unpkg/prod-deprecated/compat/extensions.js.map +1 -0
  300. package/dist/unpkg/prod-deprecated/compat/utils.js +185 -188
  301. package/dist/unpkg/prod-deprecated/compat/utils.js.map +1 -0
  302. package/dist/unpkg/prod-deprecated/compat-DxiVkCUb.js +547 -0
  303. package/dist/unpkg/prod-deprecated/compat-DxiVkCUb.js.map +1 -0
  304. package/dist/unpkg/prod-deprecated/compat.js +1 -725
  305. package/dist/unpkg/prod-deprecated/errors-9LXqpfRd.js +1978 -0
  306. package/dist/unpkg/prod-deprecated/errors-9LXqpfRd.js.map +1 -0
  307. package/dist/unpkg/prod-deprecated/index.js +249 -145
  308. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  309. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js +1080 -0
  310. package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js.map +1 -0
  311. package/dist/unpkg/prod-deprecated/model/-private.js +3 -1
  312. package/dist/unpkg/prod-deprecated/model/migration-support.js +490 -547
  313. package/dist/unpkg/prod-deprecated/model/migration-support.js.map +1 -0
  314. package/dist/unpkg/prod-deprecated/model-aiVrr1fz.js +604 -0
  315. package/dist/unpkg/prod-deprecated/model-aiVrr1fz.js.map +1 -0
  316. package/dist/unpkg/prod-deprecated/model-fragments-DSqu0ptR.js +334 -0
  317. package/dist/unpkg/prod-deprecated/model-fragments-DSqu0ptR.js.map +1 -0
  318. package/dist/unpkg/prod-deprecated/model-fragments.js +2 -75
  319. package/dist/unpkg/prod-deprecated/model.js +3 -595
  320. package/dist/unpkg/prod-deprecated/runtime--fcdnjmJ-DMTJ0Kb3.js +53 -0
  321. package/dist/unpkg/prod-deprecated/runtime--fcdnjmJ-DMTJ0Kb3.js.map +1 -0
  322. package/dist/unpkg/prod-deprecated/schema-provider-DyfSd9Cv.js +1635 -0
  323. package/dist/unpkg/prod-deprecated/schema-provider-DyfSd9Cv.js.map +1 -0
  324. package/dist/unpkg/prod-deprecated/serializer/json-api.js +497 -587
  325. package/dist/unpkg/prod-deprecated/serializer/json-api.js.map +1 -0
  326. package/dist/unpkg/prod-deprecated/serializer/json.js +3 -4
  327. package/dist/unpkg/prod-deprecated/serializer/rest.js +938 -1167
  328. package/dist/unpkg/prod-deprecated/serializer/rest.js.map +1 -0
  329. package/dist/unpkg/prod-deprecated/serializer/transform.js +283 -260
  330. package/dist/unpkg/prod-deprecated/serializer/transform.js.map +1 -0
  331. package/dist/unpkg/prod-deprecated/serializer.js +205 -208
  332. package/dist/unpkg/prod-deprecated/serializer.js.map +1 -0
  333. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js +392 -0
  334. package/dist/unpkg/prod-deprecated/store-0L2CkYzh.js.map +1 -0
  335. package/dist/unpkg/prod-deprecated/store.js +1 -503
  336. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js +14 -0
  337. package/dist/unpkg/prod-deprecated/util-CQQdHX3n.js.map +1 -0
  338. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js +13 -0
  339. package/dist/unpkg/prod-deprecated/utils-BMI_JwFP.js.map +1 -0
  340. package/dist/util-Bnx8nm-D.js +29 -0
  341. package/dist/util-Bnx8nm-D.js.map +1 -0
  342. package/dist/utils-ZAytYep8.js +28 -0
  343. package/dist/utils-ZAytYep8.js.map +1 -0
  344. package/package.json +21 -25
  345. package/declarations/adapter/-private/build-url-mixin.d.ts +0 -33
  346. package/declarations/adapter/-private/fastboot-interface.d.ts +0 -8
  347. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +0 -1
  348. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +0 -4
  349. package/declarations/adapter/-private/utils/fetch.d.ts +0 -8
  350. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
  351. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +0 -6
  352. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -5
  353. package/declarations/adapter/-private.d.ts +0 -5
  354. package/declarations/adapter/error.d.ts +0 -215
  355. package/declarations/compat/-private.d.ts +0 -13
  356. package/declarations/compat/builders/find-all.d.ts +0 -35
  357. package/declarations/compat/builders/find-record.d.ts +0 -56
  358. package/declarations/compat/builders/query.d.ts +0 -66
  359. package/declarations/compat/builders/save-record.d.ts +0 -34
  360. package/declarations/compat/builders/utils.d.ts +0 -3
  361. package/declarations/compat/builders.d.ts +0 -14
  362. package/declarations/compat/extensions.d.ts +0 -59
  363. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +0 -55
  364. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +0 -2
  365. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +0 -11
  366. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +0 -5
  367. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +0 -2
  368. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +0 -524
  369. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +0 -213
  370. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +0 -6
  371. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +0 -110
  372. package/declarations/compat/legacy-network-handler/snapshot.d.ts +0 -255
  373. package/declarations/compat/utils.d.ts +0 -137
  374. package/declarations/compat.d.ts +0 -157
  375. package/declarations/index.d.ts +0 -102
  376. package/declarations/model/-private/attr.d.ts +0 -170
  377. package/declarations/model/-private/belongs-to.d.ts +0 -174
  378. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +0 -5
  379. package/declarations/model/-private/errors.d.ts +0 -289
  380. package/declarations/model/-private/has-many.d.ts +0 -162
  381. package/declarations/model/-private/hooks.d.ts +0 -10
  382. package/declarations/model/-private/legacy-relationships-support.d.ts +0 -47
  383. package/declarations/model/-private/model-for-mixin.d.ts +0 -3
  384. package/declarations/model/-private/model-methods.d.ts +0 -39
  385. package/declarations/model/-private/model.d.ts +0 -1228
  386. package/declarations/model/-private/notify-changes.d.ts +0 -4
  387. package/declarations/model/-private/promise-belongs-to.d.ts +0 -40
  388. package/declarations/model/-private/promise-many-array.d.ts +0 -106
  389. package/declarations/model/-private/record-state.d.ts +0 -58
  390. package/declarations/model/-private/references/belongs-to.d.ts +0 -488
  391. package/declarations/model/-private/references/has-many.d.ts +0 -498
  392. package/declarations/model/-private/schema-provider.d.ts +0 -56
  393. package/declarations/model/-private/type-utils.d.ts +0 -57
  394. package/declarations/model/-private/util.d.ts +0 -5
  395. package/declarations/model/-private.d.ts +0 -8
  396. package/declarations/model/migration-support.d.ts +0 -280
  397. package/declarations/model-fragments/extensions/fragment-array.d.ts +0 -16
  398. package/declarations/model-fragments/extensions/fragment.d.ts +0 -15
  399. package/declarations/model-fragments/hooks/model-for.d.ts +0 -20
  400. package/declarations/model-fragments/index.d.ts +0 -5
  401. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +0 -9
  402. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +0 -15
  403. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +0 -20
  404. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +0 -19
  405. package/declarations/model-fragments/utilities/with-legacy.d.ts +0 -3
  406. package/declarations/model-fragments.d.ts +0 -9
  407. package/declarations/model.d.ts +0 -49
  408. package/declarations/serializer/-private/transforms/boolean.d.ts +0 -47
  409. package/declarations/serializer/-private/transforms/date.d.ts +0 -28
  410. package/declarations/serializer/-private/transforms/number.d.ts +0 -29
  411. package/declarations/serializer/-private/transforms/string.d.ts +0 -29
  412. package/declarations/serializer/-private/transforms/transform.d.ts +0 -118
  413. package/declarations/serializer/-private/utils.d.ts +0 -3
  414. package/declarations/serializer/rest.d.ts +0 -51
  415. package/declarations/serializer/transform.d.ts +0 -5
  416. package/declarations/serializer.d.ts +0 -254
  417. package/declarations/store/-private.d.ts +0 -223
  418. package/declarations/store.d.ts +0 -3
  419. package/dist/-private-BG3bMiKp.js +0 -1211
  420. package/dist/errors-Cz5KrzBk.js +0 -2566
  421. package/dist/hooks-D6diaM34.js +0 -74
  422. package/dist/json-ChdEfB0X.js +0 -1259
  423. package/dist/model-for-CqXsIKws.js +0 -221
  424. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  425. package/dist/schema-provider-DJCV_6AF.js +0 -2295
  426. package/dist/serialize-into-hash-DPZYoF-i.js +0 -261
  427. package/dist/unpkg/dev/-private-DtjBbEgy.js +0 -1206
  428. package/dist/unpkg/dev/errors-DmGGJr3T.js +0 -2562
  429. package/dist/unpkg/dev/hooks-CkYiE6Ud.js +0 -73
  430. package/dist/unpkg/dev/json-Cu1LNgmQ.js +0 -1256
  431. package/dist/unpkg/dev/model-for-CqXsIKws.js +0 -221
  432. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  433. package/dist/unpkg/dev/schema-provider-DDVYxmUV.js +0 -2186
  434. package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +0 -259
  435. package/dist/unpkg/dev/util-DvanW33H.js +0 -20
  436. package/dist/unpkg/dev/utils-BhvS1iTS.js +0 -8
  437. package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +0 -1206
  438. package/dist/unpkg/dev-deprecated/errors-Spt6ubMd.js +0 -2565
  439. package/dist/unpkg/dev-deprecated/hooks-DOXegvhL.js +0 -73
  440. package/dist/unpkg/dev-deprecated/json-Cu1LNgmQ.js +0 -1256
  441. package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +0 -221
  442. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  443. package/dist/unpkg/dev-deprecated/schema-provider-BP6_8N-V.js +0 -2211
  444. package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +0 -259
  445. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +0 -24
  446. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +0 -12
  447. package/dist/unpkg/prod/-private-BdyZaGEh.js +0 -971
  448. package/dist/unpkg/prod/errors-BGVFCBmi.js +0 -2314
  449. package/dist/unpkg/prod/hooks-BztVA_x0.js +0 -41
  450. package/dist/unpkg/prod/json-BWrZ5546.js +0 -1243
  451. package/dist/unpkg/prod/model-for-CqXsIKws.js +0 -221
  452. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  453. package/dist/unpkg/prod/schema-provider-DJtD_8jZ.js +0 -1861
  454. package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +0 -215
  455. package/dist/unpkg/prod/util-DvanW33H.js +0 -20
  456. package/dist/unpkg/prod/utils-BhvS1iTS.js +0 -8
  457. package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +0 -971
  458. package/dist/unpkg/prod-deprecated/errors-CdDaK81x.js +0 -2317
  459. package/dist/unpkg/prod-deprecated/hooks-yId87yyG.js +0 -41
  460. package/dist/unpkg/prod-deprecated/json-BWrZ5546.js +0 -1243
  461. package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +0 -221
  462. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +0 -65
  463. package/dist/unpkg/prod-deprecated/schema-provider-CjX55uSY.js +0 -1904
  464. package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +0 -215
  465. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +0 -23
  466. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +0 -11
  467. package/dist/util-Dul6TZts.js +0 -35
  468. package/dist/utils-Cqw9eRj5.js +0 -23
@@ -1,649 +1,534 @@
1
- import { dasherize, pluralize, singularize } from '@warp-drive/utilities/string';
2
- import { J as JSONSerializer } from "../json-Cu1LNgmQ.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-DDJji3V3.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
- ```
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
+ ```
38
33
 
39
- ```js [app/models/club.js]
40
- import Model, { attr, hasMany } from '@warp-drive/legacy/model';
34
+ ```js [app/models/club.js]
35
+ import Model, { attr, hasMany } from '@warp-drive/legacy/model';
41
36
 
42
- export default class Club extends Model {
43
- @attr('string') name;
44
- @attr('string') location;
45
- @hasMany('player') players;
46
- }
47
- ```
37
+ export default class Club extends Model {
38
+ @attr('string') name;
39
+ @attr('string') location;
40
+ @hasMany('player') players;
41
+ }
42
+ ```
48
43
 
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
- ```
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
+ ```
92
87
 
93
- to the format that the JSONAPICache expects.
88
+ to the format that the JSONAPICache expects.
94
89
 
95
- ### Customizing meta
90
+ ### Customizing meta
96
91
 
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.
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.
99
94
 
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`.
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`.
103
98
 
104
- ```js [app/serializers/application.js]
105
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
99
+ ```js [app/serializers/application.js]
100
+ import { JSONAPISerializer } from '@warp-drive/legacy/serializer/json-api';
106
101
 
107
- export default class ApplicationSerializer extends JSONAPISerializer {
108
- normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
109
- let normalizedDocument = super.normalizeArrayResponse(...arguments);
102
+ export default class ApplicationSerializer extends JSONAPISerializer {
103
+ normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
104
+ let normalizedDocument = super.normalizeArrayResponse(...arguments);
110
105
 
111
- // Customize document meta
112
- normalizedDocument.meta = camelCaseKeys(normalizedDocument.meta);
106
+ // Customize document meta
107
+ normalizedDocument.meta = camelCaseKeys(normalizedDocument.meta);
113
108
 
114
- return normalizedDocument;
115
- }
109
+ return normalizedDocument;
110
+ }
116
111
 
117
- extractRelationship(relationshipHash) {
118
- let normalizedRelationship = super.extractRelationship(...arguments);
112
+ extractRelationship(relationshipHash) {
113
+ let normalizedRelationship = super.extractRelationship(...arguments);
119
114
 
120
- // Customize relationship meta
121
- normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);
115
+ // Customize relationship meta
116
+ normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);
122
117
 
123
- return normalizedRelationship;
124
- }
125
- }
126
- ```
118
+ return normalizedRelationship;
119
+ }
120
+ }
121
+ ```
127
122
 
128
- @since 1.13.0
129
- @class JSONAPISerializer
130
- @public
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 = new Array(documentHash.data.length);
140
- for (let i = 0; i < documentHash.data.length; i++) {
141
- const data = documentHash.data[i];
142
- ret[i] = this._normalizeResourceHelper(data);
143
- }
144
- documentHash.data = ret;
145
- } else if (documentHash.data && typeof documentHash.data === 'object') {
146
- documentHash.data = this._normalizeResourceHelper(documentHash.data);
147
- }
148
- if (Array.isArray(documentHash.included)) {
149
- const ret = [];
150
- for (let i = 0; i < documentHash.included.length; i++) {
151
- const included = documentHash.included[i];
152
- const normalized = this._normalizeResourceHelper(included);
153
- if (normalized !== null) {
154
- // @ts-expect-error untyped
155
- // can be null when unknown type is encountered
156
- ret.push(normalized);
157
- }
158
- }
159
- documentHash.included = ret;
160
- }
161
- return documentHash;
162
- },
163
- /**
164
- @private
165
- */
166
- _normalizeRelationshipDataHelper(relationshipDataHash) {
167
- relationshipDataHash.type = this.modelNameFromPayloadKey(relationshipDataHash.type);
168
- return relationshipDataHash;
169
- },
170
- /**
171
- @private
172
- */
173
- _normalizeResourceHelper(resourceHash) {
174
- // @ts-expect-error untyped
175
- (test => {
176
- if (!test) {
177
- throw new Error(this.warnMessageForUndefinedType());
178
- }
179
- })(resourceHash.type);
180
- const type = this.modelNameFromPayloadKey(resourceHash.type);
181
-
182
- // @ts-expect-error store is dynamically added
183
- if (!this.store.schema.hasResource({
184
- type
185
- })) {
186
- {
187
- // @ts-expect-error untyped
188
- console.warn(this.warnMessageNoModelForType(type, resourceHash.type, 'modelNameFromPayloadKey'), false, {
189
- id: 'ds.serializer.model-for-type-missing'
190
- });
191
- }
192
- return null;
193
- }
194
-
195
- // @ts-expect-error store is dynamically added
196
- const modelClass = this.store.modelFor(type);
197
- // @ts-expect-error store is dynamically added
198
- const serializer = this.store.serializerFor(type);
199
- const {
200
- data
201
- } = serializer.normalize(modelClass, resourceHash);
202
- return data;
203
- },
204
- /**
205
- Normalize some data and push it into the store.
206
- @public
207
- */
208
- pushPayload(store, payload) {
209
- const normalizedPayload = this._normalizeDocumentHelper(payload);
210
- store.push(normalizedPayload);
211
- },
212
- /**
213
- @return A {json:api} Document
214
- @private
215
- */
216
- _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
217
- const normalizedPayload = this._normalizeDocumentHelper(payload);
218
- return normalizedPayload;
219
- },
220
- normalizeQueryRecordResponse() {
221
- // @ts-expect-error untyped
222
- const normalized = this._super(...arguments);
223
- (test => {
224
- if (!test) {
225
- 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.');
226
- }
227
- })(!Array.isArray(normalized.data));
228
- return normalized;
229
- },
230
- extractAttributes(modelClass, resourceHash) {
231
- const attributes = {};
232
- if (resourceHash.attributes) {
233
- modelClass.eachAttribute(key => {
234
- const attributeKey = this.keyForAttribute(key, 'deserialize');
235
- if (resourceHash.attributes[attributeKey] !== undefined) {
236
- attributes[key] = resourceHash.attributes[attributeKey];
237
- }
238
- {
239
- if (resourceHash.attributes[attributeKey] === undefined && resourceHash.attributes[key] !== undefined) {
240
- (test => {
241
- {
242
- 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.`);
243
- }
244
- })();
245
- }
246
- }
247
- });
248
- }
249
- return attributes;
250
- },
251
- /**
252
- Returns a relationship formatted as a JSON-API "relationship object".
253
- http://jsonapi.org/format/#document-resource-object-relationships
254
- @public
255
- */
256
- extractRelationship(relationshipHash) {
257
- if (Array.isArray(relationshipHash.data)) {
258
- const ret = new Array(relationshipHash.data.length);
259
- for (let i = 0; i < relationshipHash.data.length; i++) {
260
- const data = relationshipHash.data[i];
261
- ret[i] = this._normalizeRelationshipDataHelper(data);
262
- }
263
- relationshipHash.data = ret;
264
- } else if (relationshipHash.data && typeof relationshipHash.data === 'object') {
265
- relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data);
266
- }
267
- return relationshipHash;
268
- },
269
- /**
270
- Returns the resource's relationships formatted as a JSON-API "relationships object".
271
- http://jsonapi.org/format/#document-resource-object-relationships
272
- @public
273
- */
274
- extractRelationships(modelClass, resourceHash) {
275
- const relationships = {};
276
- if (resourceHash.relationships) {
277
- modelClass.eachRelationship((key, relationshipMeta) => {
278
- const relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
279
- if (resourceHash.relationships[relationshipKey] !== undefined) {
280
- const relationshipHash = resourceHash.relationships[relationshipKey];
281
- relationships[key] = this.extractRelationship(relationshipHash);
282
- }
283
- {
284
- if (resourceHash.relationships[relationshipKey] === undefined && resourceHash.relationships[key] !== undefined) {
285
- (test => {
286
- {
287
- 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.`);
288
- }
289
- })();
290
- }
291
- }
292
- });
293
- }
294
- return relationships;
295
- },
296
- /**
297
- @private
298
- */
299
- _extractType(modelClass, resourceHash) {
300
- return this.modelNameFromPayloadKey(resourceHash.type);
301
- },
302
- /**
303
- Dasherizes and singularizes the model name in the payload to match
304
- the common convention for model names.
305
- For example the key `posts` would be converted to `post` and the
306
- key `studentAssesments` would be converted to `student-assesment`.
307
- @public
308
- @return the model's modelName
309
- */
310
- modelNameFromPayloadKey(key) {
311
- return dasherize(singularize(key));
312
- },
313
- /**
314
- Converts the model name to a pluralized version of the model name.
315
- For example `post` would be converted to `posts` and
316
- `student-assesment` would be converted to `student-assesments`.
317
- @public
318
- */
319
- payloadKeyFromModelName(modelName) {
320
- return pluralize(modelName);
321
- },
322
- normalize(modelClass, resourceHash) {
323
- if (resourceHash.attributes) {
324
- // @ts-expect-error untyped
325
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash.attributes);
326
- }
327
- if (resourceHash.relationships) {
328
- // @ts-expect-error untyped
329
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash.relationships);
330
- }
331
- const data = {
332
- // @ts-expect-error untyped
333
- id: this.extractId(modelClass, resourceHash),
334
- type: this._extractType(modelClass, resourceHash),
335
- attributes: this.extractAttributes(modelClass, resourceHash),
336
- relationships: this.extractRelationships(modelClass, resourceHash)
337
- };
338
- if (resourceHash.lid) {
339
- // @ts-expect-error untyped
340
- data.lid = resourceHash.lid;
341
- }
342
-
343
- // @ts-expect-error untyped
344
- this.applyTransforms(modelClass, data.attributes);
345
- return {
346
- data
347
- };
348
- },
349
- /**
350
- `keyForAttribute` can be used to define rules for how to convert an
351
- attribute name in your model to a key in your JSON.
352
- By default `JSONAPISerializer` follows the format used on the examples of
353
- http://jsonapi.org/format and uses dashes as the word separator in the JSON
354
- attribute keys.
355
- This behaviour can be easily customized by extending this method.
356
- Example
357
- ```js [app/serializers/application.js]
358
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
359
- import { dasherize } from '<app-name>/utils/string-utils';
360
- export default class ApplicationSerializer extends JSONAPISerializer {
361
- keyForAttribute(attr, method) {
362
- return dasherize(attr).toUpperCase();
363
- }
364
- }
365
- ```
366
- @public
367
- @return normalized key
368
- */
369
- keyForAttribute(key, method) {
370
- return dasherize(key);
371
- },
372
- /**
373
- `keyForRelationship` can be used to define a custom key when
374
- serializing and deserializing relationship properties.
375
- By default `JSONAPISerializer` follows the format used on the examples of
376
- http://jsonapi.org/format and uses dashes as word separators in
377
- relationship properties.
378
- This behaviour can be easily customized by extending this method.
379
- Example
380
- ```js [app/serializers/post.js]
381
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
382
- import { underscore } from '<app-name>/utils/string-utils';
383
- export default class ApplicationSerializer extends JSONAPISerializer {
384
- keyForRelationship(key, relationship, method) {
385
- return underscore(key);
386
- }
387
- }
388
- ```
389
- @public
390
- @return the normalized key
391
- */
392
- keyForRelationship(key, typeClass, method) {
393
- return dasherize(key);
394
- },
395
- /**
396
- Called when a record is saved in order to convert the
397
- record into JSON.
398
- For example, consider this model:
399
- ```js [app/models/comment.js]
400
- import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
401
- export default class CommentModel extends Model {
402
- @attr title;
403
- @attr body;
404
- @belongsTo('user', { async: false, inverse: null })
405
- author;
406
- }
407
- ```
408
- The default serialization would create a JSON-API resource object like:
409
- ```javascript
410
- {
411
- "data": {
412
- "type": "comments",
413
- "attributes": {
414
- "title": "Rails is unagi",
415
- "body": "Rails? Omakase? O_O",
416
- },
417
- "relationships": {
418
- "author": {
419
- "data": {
420
- "id": "12",
421
- "type": "users"
422
- }
423
- }
424
- }
425
- }
426
- }
427
- ```
428
- By default, attributes are passed through as-is, unless
429
- you specified an attribute type (`attr('date')`). If
430
- you specify a transform, the JavaScript value will be
431
- serialized when inserted into the attributes hash.
432
- Belongs-to relationships are converted into JSON-API
433
- resource identifier objects.
434
- ## IDs
435
- `serialize` takes an options hash with a single option:
436
- `includeId`. If this option is `true`, `serialize` will,
437
- by default include the ID in the JSON object it builds.
438
- The JSONAPIAdapter passes in `includeId: true` when serializing a record
439
- for `createRecord` or `updateRecord`.
440
- ## Customization
441
- Your server may expect data in a different format than the
442
- built-in serialization format.
443
- In that case, you can implement `serialize` yourself and
444
- return data formatted to match your API's expectations, or override
445
- the invoked adapter method and do the serialization in the adapter directly
446
- by using the provided snapshot.
447
- If your API's format differs greatly from the JSON:API spec, you should
448
- consider authoring your own adapter and serializer instead of extending
449
- this class.
450
- ```js [app/serializers/post.js]
451
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
452
- export default class PostSerializer extends JSONAPISerializer {
453
- serialize(snapshot, options) {
454
- let json = {
455
- POST_TTL: snapshot.attr('title'),
456
- POST_BDY: snapshot.attr('body'),
457
- POST_CMS: snapshot.hasMany('comments', { ids: true })
458
- };
459
- if (options.includeId) {
460
- json.POST_ID_ = snapshot.id;
461
- }
462
- return json;
463
- }
464
- }
465
- ```
466
- ## Customizing an App-Wide Serializer
467
- If you want to define a serializer for your entire
468
- application, you'll probably want to use `eachAttribute`
469
- and `eachRelationship` on the record.
470
- ```js [app/serializers/application.js]
471
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
472
- import { underscore, singularize } from '<app-name>/utils/string-utils';
473
- export default class ApplicationSerializer extends JSONAPISerializer {
474
- serialize(snapshot, options) {
475
- let json = {};
476
- snapshot.eachAttribute((name) => {
477
- json[serverAttributeName(name)] = snapshot.attr(name);
478
- });
479
- snapshot.eachRelationship((name, relationship) => {
480
- if (relationship.kind === 'hasMany') {
481
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
482
- }
483
- });
484
- if (options.includeId) {
485
- json.ID_ = snapshot.id;
486
- }
487
- return json;
488
- }
489
- }
490
- function serverAttributeName(attribute) {
491
- return underscore(attribute).toUpperCase();
492
- }
493
- function serverHasManyName(name) {
494
- return serverAttributeName(singularize(name)) + '_IDS';
495
- }
496
- ```
497
- This serializer will generate JSON that looks like this:
498
- ```javascript
499
- {
500
- "TITLE": "Rails is omakase",
501
- "BODY": "Yep. Omakase.",
502
- "COMMENT_IDS": [ "1", "2", "3" ]
503
- }
504
- ```
505
- ## Tweaking the Default Formatting
506
- If you just want to do some small tweaks on the default JSON:API formatted response,
507
- you can call `super.serialize` first and make the tweaks
508
- on the returned object.
509
- ```js [app/serializers/post.js]
510
- import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
511
- export default class PostSerializer extends JSONAPISerializer {
512
- serialize(snapshot, options) {
513
- let json = super.serialize(...arguments);
514
- json.data.attributes.subject = json.data.attributes.title;
515
- delete json.data.attributes.title;
516
- return json;
517
- }
518
- }
519
- ```
520
- @public
521
- */
522
- serialize(snapshot, options) {
523
- // @ts-expect-error untyped
524
- const data = this._super(...arguments);
525
- data.type = this.payloadKeyFromModelName(snapshot.modelName);
526
- return {
527
- data
528
- };
529
- },
530
- serializeAttribute(snapshot, json, key, attribute) {
531
- const type = attribute.type;
532
-
533
- // @ts-expect-error untyped
534
- if (this._canSerialize(key)) {
535
- json.attributes = json.attributes || {};
536
- let value = snapshot.attr(key);
537
- if (type) {
538
- // @ts-expect-error untyped
539
- const transform = this.transformFor(type);
540
- value = transform.serialize(value, attribute.options);
541
- }
542
-
543
- // @ts-expect-error store is dynamically added
544
- const schema = this.store.modelFor(snapshot.modelName);
545
- // @ts-expect-error untyped
546
- let payloadKey = this._getMappedKey(key, schema);
547
- if (payloadKey === key) {
548
- payloadKey = this.keyForAttribute(key, 'serialize');
549
- }
550
- json.attributes[payloadKey] = value;
551
- }
552
- },
553
- serializeBelongsTo(snapshot, json, relationship) {
554
- const name = relationship.name;
555
-
556
- // @ts-expect-error untyped
557
- if (this._canSerialize(name)) {
558
- const belongsTo = snapshot.belongsTo(name);
559
- // @ts-expect-error not narrowed
560
- const belongsToIsNotNew = belongsTo && !belongsTo.isNew;
561
- if (belongsTo === null || belongsToIsNotNew) {
562
- json.relationships = json.relationships || {};
563
-
564
- // @ts-expect-error store is dynamically added
565
- const schema = this.store.modelFor(snapshot.modelName);
566
- // @ts-expect-error untyped
567
- let payloadKey = this._getMappedKey(name, schema);
568
- if (payloadKey === name) {
569
- payloadKey = this.keyForRelationship(name, 'belongsTo', 'serialize');
570
- }
571
- let data = null;
572
- if (belongsTo) {
573
- // @ts-expect-error not narrowed
574
- const payloadType = this.payloadKeyFromModelName(belongsTo.modelName);
575
-
576
- // @ts-expect-error untyped
577
- data = {
578
- type: payloadType,
579
- // @ts-expect-error not narrowed
580
- id: belongsTo.id
581
- };
582
- }
583
- json.relationships[payloadKey] = {
584
- data
585
- };
586
- }
587
- }
588
- },
589
- serializeHasMany(snapshot, json, relationship) {
590
- const name = relationship.name;
591
-
592
- // @ts-expect-error untyped
593
- if (this.shouldSerializeHasMany(snapshot, name, relationship)) {
594
- const hasMany = snapshot.hasMany(name);
595
- if (hasMany !== undefined) {
596
- json.relationships = json.relationships || {};
597
-
598
- // @ts-expect-error store is dynamically added
599
- const schema = this.store.modelFor(snapshot.modelName);
600
- // @ts-expect-error untyped
601
- let payloadKey = this._getMappedKey(name, schema);
602
- if (payloadKey === name && this.keyForRelationship) {
603
- payloadKey = this.keyForRelationship(name, 'hasMany', 'serialize');
604
- }
605
-
606
- // only serialize has many relationships that are not new
607
- // @ts-expect-error not narrowed
608
- const nonNewHasMany = hasMany.filter(item => !item.isNew);
609
- const data = new Array(nonNewHasMany.length);
610
- for (let i = 0; i < nonNewHasMany.length; i++) {
611
- const item = hasMany[i];
612
- // @ts-expect-error not narrowed
613
- const payloadType = this.payloadKeyFromModelName(item.modelName);
614
- data[i] = {
615
- type: payloadType,
616
- // @ts-expect-error not narrowed
617
- id: item.id
618
- };
619
- }
620
- json.relationships[payloadKey] = {
621
- data
622
- };
623
- }
624
- }
625
- }
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
+ ((test) => {
164
+ if (!test) throw new Error(this.warnMessageForUndefinedType());
165
+ })(resourceHash.type);
166
+ const type = this.modelNameFromPayloadKey(resourceHash.type);
167
+ if (!this.store.schema.hasResource({ type })) {
168
+ console.warn(this.warnMessageNoModelForType(type, resourceHash.type, "modelNameFromPayloadKey"), false, { id: "ds.serializer.model-for-type-missing" });
169
+ return null;
170
+ }
171
+ const modelClass = this.store.modelFor(type);
172
+ const { data } = this.store.serializerFor(type).normalize(modelClass, resourceHash);
173
+ return data;
174
+ },
175
+ /**
176
+ Normalize some data and push it into the store.
177
+ @public
178
+ */
179
+ pushPayload(store, payload) {
180
+ const normalizedPayload = this._normalizeDocumentHelper(payload);
181
+ store.push(normalizedPayload);
182
+ },
183
+ /**
184
+ @return A {json:api} Document
185
+ @private
186
+ */
187
+ _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
188
+ return this._normalizeDocumentHelper(payload);
189
+ },
190
+ normalizeQueryRecordResponse() {
191
+ const normalized = this._super(...arguments);
192
+ ((test) => {
193
+ 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.");
194
+ })(!Array.isArray(normalized.data));
195
+ return normalized;
196
+ },
197
+ extractAttributes(modelClass, resourceHash) {
198
+ const attributes = {};
199
+ if (resourceHash.attributes) modelClass.eachAttribute((key) => {
200
+ const attributeKey = this.keyForAttribute(key, "deserialize");
201
+ if (resourceHash.attributes[attributeKey] !== void 0) attributes[key] = resourceHash.attributes[attributeKey];
202
+ if (resourceHash.attributes[attributeKey] === void 0 && resourceHash.attributes[key] !== void 0) ((test) => {
203
+ 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.`);
204
+ })(false);
205
+ });
206
+ return attributes;
207
+ },
208
+ /**
209
+ Returns a relationship formatted as a JSON-API "relationship object".
210
+ http://jsonapi.org/format/#document-resource-object-relationships
211
+ @public
212
+ */
213
+ extractRelationship(relationshipHash) {
214
+ if (Array.isArray(relationshipHash.data)) {
215
+ const ret = new Array(relationshipHash.data.length);
216
+ for (let i = 0; i < relationshipHash.data.length; i++) {
217
+ const data = relationshipHash.data[i];
218
+ ret[i] = this._normalizeRelationshipDataHelper(data);
219
+ }
220
+ relationshipHash.data = ret;
221
+ } else if (relationshipHash.data && typeof relationshipHash.data === "object") relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data);
222
+ return relationshipHash;
223
+ },
224
+ /**
225
+ Returns the resource's relationships formatted as a JSON-API "relationships object".
226
+ http://jsonapi.org/format/#document-resource-object-relationships
227
+ @public
228
+ */
229
+ extractRelationships(modelClass, resourceHash) {
230
+ const relationships = {};
231
+ if (resourceHash.relationships) modelClass.eachRelationship((key, relationshipMeta) => {
232
+ const relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, "deserialize");
233
+ if (resourceHash.relationships[relationshipKey] !== void 0) {
234
+ const relationshipHash = resourceHash.relationships[relationshipKey];
235
+ relationships[key] = this.extractRelationship(relationshipHash);
236
+ }
237
+ if (resourceHash.relationships[relationshipKey] === void 0 && resourceHash.relationships[key] !== void 0) ((test) => {
238
+ 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.`);
239
+ })(false);
240
+ });
241
+ return relationships;
242
+ },
243
+ /**
244
+ @private
245
+ */
246
+ _extractType(modelClass, resourceHash) {
247
+ return this.modelNameFromPayloadKey(resourceHash.type);
248
+ },
249
+ /**
250
+ Dasherizes and singularizes the model name in the payload to match
251
+ the common convention for model names.
252
+ For example the key `posts` would be converted to `post` and the
253
+ key `studentAssesments` would be converted to `student-assesment`.
254
+ @public
255
+ @return the model's modelName
256
+ */
257
+ modelNameFromPayloadKey(key) {
258
+ return dasherize(singularize(key));
259
+ },
260
+ /**
261
+ Converts the model name to a pluralized version of the model name.
262
+ For example `post` would be converted to `posts` and
263
+ `student-assesment` would be converted to `student-assesments`.
264
+ @public
265
+ */
266
+ payloadKeyFromModelName(modelName) {
267
+ return pluralize(modelName);
268
+ },
269
+ normalize(modelClass, resourceHash) {
270
+ if (resourceHash.attributes) this.normalizeUsingDeclaredMapping(modelClass, resourceHash.attributes);
271
+ if (resourceHash.relationships) this.normalizeUsingDeclaredMapping(modelClass, resourceHash.relationships);
272
+ const data = {
273
+ id: this.extractId(modelClass, resourceHash),
274
+ type: this._extractType(modelClass, resourceHash),
275
+ attributes: this.extractAttributes(modelClass, resourceHash),
276
+ relationships: this.extractRelationships(modelClass, resourceHash)
277
+ };
278
+ if (resourceHash.lid) data.lid = resourceHash.lid;
279
+ this.applyTransforms(modelClass, data.attributes);
280
+ return { data };
281
+ },
282
+ /**
283
+ `keyForAttribute` can be used to define rules for how to convert an
284
+ attribute name in your model to a key in your JSON.
285
+ By default `JSONAPISerializer` follows the format used on the examples of
286
+ http://jsonapi.org/format and uses dashes as the word separator in the JSON
287
+ attribute keys.
288
+ This behaviour can be easily customized by extending this method.
289
+ Example
290
+ ```js [app/serializers/application.js]
291
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
292
+ import { dasherize } from '<app-name>/utils/string-utils';
293
+ export default class ApplicationSerializer extends JSONAPISerializer {
294
+ keyForAttribute(attr, method) {
295
+ return dasherize(attr).toUpperCase();
296
+ }
297
+ }
298
+ ```
299
+ @public
300
+ @return normalized key
301
+ */
302
+ keyForAttribute(key, method) {
303
+ return dasherize(key);
304
+ },
305
+ /**
306
+ `keyForRelationship` can be used to define a custom key when
307
+ serializing and deserializing relationship properties.
308
+ By default `JSONAPISerializer` follows the format used on the examples of
309
+ http://jsonapi.org/format and uses dashes as word separators in
310
+ relationship properties.
311
+ This behaviour can be easily customized by extending this method.
312
+ Example
313
+ ```js [app/serializers/post.js]
314
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
315
+ import { underscore } from '<app-name>/utils/string-utils';
316
+ export default class ApplicationSerializer extends JSONAPISerializer {
317
+ keyForRelationship(key, relationship, method) {
318
+ return underscore(key);
319
+ }
320
+ }
321
+ ```
322
+ @public
323
+ @return the normalized key
324
+ */
325
+ keyForRelationship(key, typeClass, method) {
326
+ return dasherize(key);
327
+ },
328
+ /**
329
+ Called when a record is saved in order to convert the
330
+ record into JSON.
331
+ For example, consider this model:
332
+ ```js [app/models/comment.js]
333
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
334
+ export default class CommentModel extends Model {
335
+ @attr title;
336
+ @attr body;
337
+ @belongsTo('user', { async: false, inverse: null })
338
+ author;
339
+ }
340
+ ```
341
+ The default serialization would create a JSON-API resource object like:
342
+ ```javascript
343
+ {
344
+ "data": {
345
+ "type": "comments",
346
+ "attributes": {
347
+ "title": "Rails is unagi",
348
+ "body": "Rails? Omakase? O_O",
349
+ },
350
+ "relationships": {
351
+ "author": {
352
+ "data": {
353
+ "id": "12",
354
+ "type": "users"
355
+ }
356
+ }
357
+ }
358
+ }
359
+ }
360
+ ```
361
+ By default, attributes are passed through as-is, unless
362
+ you specified an attribute type (`attr('date')`). If
363
+ you specify a transform, the JavaScript value will be
364
+ serialized when inserted into the attributes hash.
365
+ Belongs-to relationships are converted into JSON-API
366
+ resource identifier objects.
367
+ ## IDs
368
+ `serialize` takes an options hash with a single option:
369
+ `includeId`. If this option is `true`, `serialize` will,
370
+ by default include the ID in the JSON object it builds.
371
+ The JSONAPIAdapter passes in `includeId: true` when serializing a record
372
+ for `createRecord` or `updateRecord`.
373
+ ## Customization
374
+ Your server may expect data in a different format than the
375
+ built-in serialization format.
376
+ In that case, you can implement `serialize` yourself and
377
+ return data formatted to match your API's expectations, or override
378
+ the invoked adapter method and do the serialization in the adapter directly
379
+ by using the provided snapshot.
380
+ If your API's format differs greatly from the JSON:API spec, you should
381
+ consider authoring your own adapter and serializer instead of extending
382
+ this class.
383
+ ```js [app/serializers/post.js]
384
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
385
+ export default class PostSerializer extends JSONAPISerializer {
386
+ serialize(snapshot, options) {
387
+ let json = {
388
+ POST_TTL: snapshot.attr('title'),
389
+ POST_BDY: snapshot.attr('body'),
390
+ POST_CMS: snapshot.hasMany('comments', { ids: true })
391
+ };
392
+ if (options.includeId) {
393
+ json.POST_ID_ = snapshot.id;
394
+ }
395
+ return json;
396
+ }
397
+ }
398
+ ```
399
+ ## Customizing an App-Wide Serializer
400
+ If you want to define a serializer for your entire
401
+ application, you'll probably want to use `eachAttribute`
402
+ and `eachRelationship` on the record.
403
+ ```js [app/serializers/application.js]
404
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
405
+ import { underscore, singularize } from '<app-name>/utils/string-utils';
406
+ export default class ApplicationSerializer extends JSONAPISerializer {
407
+ serialize(snapshot, options) {
408
+ let json = {};
409
+ snapshot.eachAttribute((name) => {
410
+ json[serverAttributeName(name)] = snapshot.attr(name);
411
+ });
412
+ snapshot.eachRelationship((name, relationship) => {
413
+ if (relationship.kind === 'hasMany') {
414
+ json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
415
+ }
416
+ });
417
+ if (options.includeId) {
418
+ json.ID_ = snapshot.id;
419
+ }
420
+ return json;
421
+ }
422
+ }
423
+ function serverAttributeName(attribute) {
424
+ return underscore(attribute).toUpperCase();
425
+ }
426
+ function serverHasManyName(name) {
427
+ return serverAttributeName(singularize(name)) + '_IDS';
428
+ }
429
+ ```
430
+ This serializer will generate JSON that looks like this:
431
+ ```javascript
432
+ {
433
+ "TITLE": "Rails is omakase",
434
+ "BODY": "Yep. Omakase.",
435
+ "COMMENT_IDS": [ "1", "2", "3" ]
436
+ }
437
+ ```
438
+ ## Tweaking the Default Formatting
439
+ If you just want to do some small tweaks on the default JSON:API formatted response,
440
+ you can call `super.serialize` first and make the tweaks
441
+ on the returned object.
442
+ ```js [app/serializers/post.js]
443
+ import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
444
+ export default class PostSerializer extends JSONAPISerializer {
445
+ serialize(snapshot, options) {
446
+ let json = super.serialize(...arguments);
447
+ json.data.attributes.subject = json.data.attributes.title;
448
+ delete json.data.attributes.title;
449
+ return json;
450
+ }
451
+ }
452
+ ```
453
+ @public
454
+ */
455
+ serialize(snapshot, options) {
456
+ const data = this._super(...arguments);
457
+ data.type = this.payloadKeyFromModelName(snapshot.modelName);
458
+ return { data };
459
+ },
460
+ serializeAttribute(snapshot, json, key, attribute) {
461
+ const type = attribute.type;
462
+ if (this._canSerialize(key)) {
463
+ json.attributes = json.attributes || {};
464
+ let value = snapshot.attr(key);
465
+ if (type) value = this.transformFor(type).serialize(value, attribute.options);
466
+ const schema = this.store.modelFor(snapshot.modelName);
467
+ let payloadKey = this._getMappedKey(key, schema);
468
+ if (payloadKey === key) payloadKey = this.keyForAttribute(key, "serialize");
469
+ json.attributes[payloadKey] = value;
470
+ }
471
+ },
472
+ serializeBelongsTo(snapshot, json, relationship) {
473
+ const name = relationship.name;
474
+ if (this._canSerialize(name)) {
475
+ const belongsTo = snapshot.belongsTo(name);
476
+ const belongsToIsNotNew = belongsTo && !belongsTo.isNew;
477
+ if (belongsTo === null || belongsToIsNotNew) {
478
+ json.relationships = json.relationships || {};
479
+ const schema = this.store.modelFor(snapshot.modelName);
480
+ let payloadKey = this._getMappedKey(name, schema);
481
+ if (payloadKey === name) payloadKey = this.keyForRelationship(name, "belongsTo", "serialize");
482
+ let data = null;
483
+ if (belongsTo) data = {
484
+ type: this.payloadKeyFromModelName(belongsTo.modelName),
485
+ id: belongsTo.id
486
+ };
487
+ json.relationships[payloadKey] = { data };
488
+ }
489
+ }
490
+ },
491
+ serializeHasMany(snapshot, json, relationship) {
492
+ const name = relationship.name;
493
+ if (this.shouldSerializeHasMany(snapshot, name, relationship)) {
494
+ const hasMany = snapshot.hasMany(name);
495
+ if (hasMany !== void 0) {
496
+ json.relationships = json.relationships || {};
497
+ const schema = this.store.modelFor(snapshot.modelName);
498
+ let payloadKey = this._getMappedKey(name, schema);
499
+ if (payloadKey === name && this.keyForRelationship) payloadKey = this.keyForRelationship(name, "hasMany", "serialize");
500
+ const nonNewHasMany = hasMany.filter((item) => !item.isNew);
501
+ const data = new Array(nonNewHasMany.length);
502
+ for (let i = 0; i < nonNewHasMany.length; i++) {
503
+ const item = hasMany[i];
504
+ const payloadType = this.payloadKeyFromModelName(item.modelName);
505
+ data[i] = {
506
+ type: payloadType,
507
+ id: item.id
508
+ };
509
+ }
510
+ json.relationships[payloadKey] = { data };
511
+ }
512
+ }
513
+ }
626
514
  });
627
- {
628
- JSONAPISerializer.reopen({
629
- init(...args) {
630
- this._super(...args);
631
- (test => {
632
- if (!test) {
633
- 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.`);
634
- }
635
- })(!this.isEmbeddedRecordsMixin || this.isEmbeddedRecordsMixinCompatible === true);
636
- const constructor = this.constructor;
637
- console.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, {
638
- id: 'ds.serializer.json-api.extractMeta'
639
- });
640
- },
641
- warnMessageForUndefinedType() {
642
- return 'Encountered a resource object with an undefined type (resolved resource using ' + this.constructor.toString() + ')';
643
- },
644
- warnMessageNoModelForType(modelName, originalType, usedLookup) {
645
- 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}")').`;
646
- }
647
- });
648
- }
649
- export { JSONAPISerializer };
515
+ JSONAPISerializer.reopen({
516
+ init(...args) {
517
+ this._super(...args);
518
+ ((test) => {
519
+ 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.`);
520
+ })(!this.isEmbeddedRecordsMixin || this.isEmbeddedRecordsMixinCompatible === true);
521
+ const constructor = this.constructor;
522
+ console.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" });
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
+ });
531
+
532
+ //#endregion
533
+ export { JSONAPISerializer };
534
+ //# sourceMappingURL=json-api.js.map