@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,1259 +0,0 @@
1
- import { getOwner } from '@ember/application';
2
- import { warn } from '@ember/debug';
3
- import { dasherize, singularize } from '@warp-drive/utilities/string';
4
- import { Serializer } from './serializer.js';
5
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
- function coerceId(id) {
7
- if (id === null || id === undefined || id === '') {
8
- return null;
9
- } else if (typeof id === 'string') {
10
- return id;
11
- } else if (typeof id === 'symbol') {
12
- return id.toString();
13
- } else {
14
- return String(id);
15
- }
16
- }
17
-
18
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
19
- /* eslint-disable @typescript-eslint/no-unsafe-call */
20
- /* eslint-disable @typescript-eslint/no-unsafe-return */
21
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
22
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
23
- const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
24
- const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
25
- const PRIMARY_ATTRIBUTE_KEY = 'base';
26
-
27
- /**
28
- * :::danger
29
- ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
30
- If starting a new app or thinking of implementing a new adapter, consider writing a
31
- {@link Handler} instead to be used with the {@link RequestManager}
32
- :::
33
-
34
- In WarpDrive a Serializer is used to serialize and deserialize
35
- records when they are transferred in and out of an external source.
36
- This process involves normalizing property names, transforming
37
- attribute values and serializing relationships.
38
-
39
- By default, WarpDrive uses and recommends the `JSONAPISerializer`.
40
-
41
- `JSONSerializer` is useful for simpler or legacy backends that may
42
- not support the http://jsonapi.org/ spec.
43
-
44
- For example, given the following `User` model and JSON payload:
45
-
46
- ```js [app/models/user.js]
47
- import Model, { attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
48
-
49
- export default class UserModel extends Model {
50
- @hasMany('user') friends;
51
- @belongsTo('location') house;
52
-
53
- @attr('string') name;
54
- }
55
- ```
56
-
57
- ```js
58
- {
59
- id: 1,
60
- name: 'Sebastian',
61
- friends: [3, 4],
62
- links: {
63
- house: '/houses/lefkada'
64
- }
65
- }
66
- ```
67
-
68
- `JSONSerializer` will normalize the JSON payload to the {json:api} format that the
69
- JSONAPICache uses to cache data in the Store.
70
-
71
- You can customize how JSONSerializer processes its payload by passing options in
72
- the `attrs` hash or by subclassing the `JSONSerializer` and overriding hooks:
73
-
74
- - To customize how a single record is normalized, use the `normalize` hook.
75
- - To customize how `JSONSerializer` normalizes the whole server response, use the
76
- `normalizeResponse` hook.
77
- - To customize how `JSONSerializer` normalizes a specific response from the server,
78
- use one of the many specific `normalizeResponse` hooks.
79
- - To customize how `JSONSerializer` normalizes your id, attributes or relationships,
80
- use the `extractId`, `extractAttributes` and `extractRelationships` hooks.
81
-
82
- The `JSONSerializer` normalization process follows these steps:
83
-
84
- 1. `normalizeResponse`
85
- - entry method to the serializer.
86
- 2. `normalizeCreateRecordResponse`
87
- - a `normalizeResponse` for a specific operation is called.
88
- 3. `normalizeSingleResponse`|`normalizeArrayResponse`
89
- - for methods like `createRecord` we expect a single record back, while for methods like `findAll` we expect multiple records back.
90
- 4. `normalize`
91
- - `normalizeArrayResponse` iterates and calls `normalize` for each of its records while `normalizeSingle`
92
- calls it once. This is the method you most likely want to subclass.
93
- 5. `extractId` | `extractAttributes` | `extractRelationships`
94
- - `normalize` delegates to these methods to
95
- turn the record payload into the JSON API format.
96
-
97
- @class JSONSerializer
98
- @public
99
- */
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- const JSONSerializer = Serializer.extend({
102
- /**
103
- The `primaryKey` is used when serializing and deserializing
104
- data. WarpDrive always uses the `id` property to store the id of
105
- the record. The external source may not always follow this
106
- convention. In these cases it is useful to override the
107
- `primaryKey` property to match the `primaryKey` of your external
108
- store.
109
- Example
110
- ```js [app/serializers/application.js]
111
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
112
- export default class ApplicationSerializer extends JSONSerializer {
113
- primaryKey = '_id'
114
- }
115
- ```
116
- @public
117
- @default 'id'
118
- */
119
- primaryKey: 'id',
120
- /**
121
- The `attrs` object can be used to declare a simple mapping between
122
- property names on `Model` records and payload keys in the
123
- serialized JSON object representing the record. An object with the
124
- property `key` can also be used to designate the attribute's key on
125
- the response payload.
126
- Example
127
- ```js [app/models/person.js]
128
- import Model, { attr } from '@warp-drive/legacy/model';
129
- export default class PersonModel extends Model {
130
- @attr('string') firstName;
131
- @attr('string') lastName;
132
- @attr('string') occupation;
133
- @attr('boolean') admin;
134
- }
135
- ```
136
- ```js [app/serializers/person.js]
137
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
138
- export default class PersonSerializer extends JSONSerializer {
139
- attrs = {
140
- admin: 'is_admin',
141
- occupation: { key: 'career' }
142
- }
143
- }
144
- ```
145
- You can also remove attributes and relationships by setting the `serialize`
146
- key to `false` in your mapping object.
147
- Example
148
- ```js [app/serializers/person.js]
149
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
150
- export default class PostSerializer extends JSONSerializer {
151
- attrs = {
152
- admin: { serialize: false },
153
- occupation: { key: 'career' }
154
- }
155
- }
156
- ```
157
- When serialized:
158
- ```js
159
- {
160
- "firstName": "Harry",
161
- "lastName": "Houdini",
162
- "career": "magician"
163
- }
164
- ```
165
- Note that the `admin` is now not included in the payload.
166
- Setting `serialize` to `true` enforces serialization for hasMany
167
- relationships even if it's neither a many-to-many nor many-to-none
168
- relationship.
169
- @public
170
- */
171
- mergedProperties: ['attrs'],
172
- /**
173
- Given a subclass of `Model` and a JSON object this method will
174
- iterate through each attribute of the `Model` and invoke the
175
- `Transform#deserialize` method on the matching property of the
176
- JSON object. This method is typically called after the
177
- serializer's `normalize` method.
178
- @private
179
- */
180
- applyTransforms(typeClass, data) {
181
- const attributes = typeClass.attributes;
182
- typeClass.eachTransformedAttribute((key, type) => {
183
- if (data[key] === undefined) {
184
- return;
185
- }
186
- const transform = this.transformFor(type);
187
- const transformMeta = attributes.get(key);
188
- data[key] = transform.deserialize(data[key], transformMeta.options);
189
- });
190
- return data;
191
- },
192
- /**
193
- The `normalizeResponse` method is used to normalize a payload from the
194
- server to a JSON-API Document.
195
- http://jsonapi.org/format/#document-structure
196
- This method delegates to a more specific normalize method based on
197
- the `requestType`.
198
- To override this method with a custom one, make sure to call
199
- `return super.normalizeResponse(store, primaryModelClass, payload, id, requestType)` with your
200
- pre-processed data.
201
- Here's an example of using `normalizeResponse` manually:
202
- ```javascript
203
- socket.on('message', function(message) {
204
- let data = message.data;
205
- let modelClass = store.modelFor(data.modelName);
206
- let serializer = store.serializerFor(data.modelName);
207
- let normalized = serializer.normalizeSingleResponse(store, modelClass, data, data.id);
208
- store.push(normalized);
209
- });
210
- ```
211
- @since 1.13.0
212
- @public
213
- */
214
- normalizeResponse(store, primaryModelClass, payload, id, requestType) {
215
- switch (requestType) {
216
- case 'findRecord':
217
- // @ts-expect-error
218
- return this.normalizeFindRecordResponse(...arguments);
219
- case 'queryRecord':
220
- // @ts-expect-error
221
- return this.normalizeQueryRecordResponse(...arguments);
222
- case 'findAll':
223
- // @ts-expect-error
224
- return this.normalizeFindAllResponse(...arguments);
225
- case 'findBelongsTo':
226
- // @ts-expect-error
227
- return this.normalizeFindBelongsToResponse(...arguments);
228
- case 'findHasMany':
229
- // @ts-expect-error
230
- return this.normalizeFindHasManyResponse(...arguments);
231
- case 'findMany':
232
- // @ts-expect-error
233
- return this.normalizeFindManyResponse(...arguments);
234
- case 'query':
235
- // @ts-expect-error
236
- return this.normalizeQueryResponse(...arguments);
237
- case 'createRecord':
238
- // @ts-expect-error
239
- return this.normalizeCreateRecordResponse(...arguments);
240
- case 'deleteRecord':
241
- // @ts-expect-error
242
- return this.normalizeDeleteRecordResponse(...arguments);
243
- case 'updateRecord':
244
- // @ts-expect-error
245
- return this.normalizeUpdateRecordResponse(...arguments);
246
- }
247
- },
248
- /**
249
- Called by the default normalizeResponse implementation when the
250
- type of request is `findRecord`
251
- @since 1.13.0
252
- @public
253
- */
254
- normalizeFindRecordResponse(store, primaryModelClass, payload, id, requestType) {
255
- // @ts-expect-error
256
- return this.normalizeSingleResponse(...arguments);
257
- },
258
- /**
259
- Called by the default normalizeResponse implementation when the
260
- type of request is `queryRecord`
261
- @since 1.13.0
262
- @public
263
- */
264
- normalizeQueryRecordResponse(store, primaryModelClass, payload, id, requestType) {
265
- // @ts-expect-error
266
- return this.normalizeSingleResponse(...arguments);
267
- },
268
- /**
269
- Called by the default normalizeResponse implementation when the
270
- type of request is `findAll`
271
- @since 1.13.0
272
- @public
273
- */
274
- normalizeFindAllResponse(store, primaryModelClass, payload, id, requestType) {
275
- // @ts-expect-error
276
- return this.normalizeArrayResponse(...arguments);
277
- },
278
- /**
279
- Called by the default normalizeResponse implementation when the
280
- type of request is `findBelongsTo`
281
- @since 1.13.0
282
- @public
283
- */
284
- normalizeFindBelongsToResponse(store, primaryModelClass, payload, id, requestType) {
285
- // @ts-expect-error
286
- return this.normalizeSingleResponse(...arguments);
287
- },
288
- /**
289
- Called by the default normalizeResponse implementation when the
290
- type of request is `findHasMany`
291
- @since 1.13.0
292
- @public
293
- */
294
- normalizeFindHasManyResponse(store, primaryModelClass, payload, id, requestType) {
295
- // @ts-expect-error
296
- return this.normalizeArrayResponse(...arguments);
297
- },
298
- /**
299
- Called by the default normalizeResponse implementation when the
300
- type of request is `findMany`
301
- @since 1.13.0
302
- @public
303
- */
304
- normalizeFindManyResponse(store, primaryModelClass, payload, id, requestType) {
305
- // @ts-expect-error
306
- return this.normalizeArrayResponse(...arguments);
307
- },
308
- /**
309
- Called by the default normalizeResponse implementation when the
310
- type of request is `query`
311
- @since 1.13.0
312
- @public
313
- */
314
- normalizeQueryResponse(store, primaryModelClass, payload, id, requestType) {
315
- // @ts-expect-error
316
- return this.normalizeArrayResponse(...arguments);
317
- },
318
- /**
319
- Called by the default normalizeResponse implementation when the
320
- type of request is `createRecord`
321
- @since 1.13.0
322
- @public
323
- */
324
- normalizeCreateRecordResponse(store, primaryModelClass, payload, id, requestType) {
325
- // @ts-expect-error
326
- return this.normalizeSaveResponse(...arguments);
327
- },
328
- /**
329
- Called by the default normalizeResponse implementation when the
330
- type of request is `deleteRecord`
331
- @since 1.13.0
332
- @public
333
- */
334
- normalizeDeleteRecordResponse(store, primaryModelClass, payload, id, requestType) {
335
- // @ts-expect-error
336
- return this.normalizeSaveResponse(...arguments);
337
- },
338
- /**
339
- Called by the default normalizeResponse implementation when the
340
- type of request is `updateRecord`
341
- @since 1.13.0
342
- @public
343
- */
344
- normalizeUpdateRecordResponse(store, primaryModelClass, payload, id, requestType) {
345
- // @ts-expect-error
346
- return this.normalizeSaveResponse(...arguments);
347
- },
348
- /**
349
- normalizeUpdateRecordResponse, normalizeCreateRecordResponse and
350
- normalizeDeleteRecordResponse delegate to this method by default.
351
- @since 1.13.0
352
- @public
353
- */
354
- normalizeSaveResponse(store, primaryModelClass, payload, id, requestType) {
355
- // @ts-expect-error
356
- return this.normalizeSingleResponse(...arguments);
357
- },
358
- /**
359
- normalizeQueryResponse and normalizeFindRecordResponse delegate to this
360
- method by default.
361
- @since 1.13.0
362
- @public
363
- */
364
- normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
365
- return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, true);
366
- },
367
- /**
368
- normalizeQueryResponse, normalizeFindManyResponse, and normalizeFindHasManyResponse delegate
369
- to this method by default.
370
- @since 1.13.0
371
- @public
372
- */
373
- normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
374
- return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, false);
375
- },
376
- /**
377
- @private
378
- */
379
- _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
380
- const documentHash = {
381
- data: null,
382
- included: []
383
- };
384
- const meta = this.extractMeta(store, primaryModelClass, payload);
385
- if (meta) {
386
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
387
- if (!test) {
388
- throw new Error('The `meta` returned from `extractMeta` has to be an object, not "' + typeof meta + '".');
389
- }
390
- })(typeof meta === 'object') : {};
391
- // @ts-expect-error untyped
392
- documentHash.meta = meta;
393
- }
394
- if (isSingle) {
395
- // @ts-expect-error untyped
396
- const {
397
- data,
398
- included
399
- } = this.normalize(primaryModelClass, payload);
400
- documentHash.data = data;
401
- if (included) {
402
- documentHash.included = included;
403
- }
404
- } else {
405
- // @ts-expect-error untyped
406
- const ret = new Array(payload.length);
407
- // @ts-expect-error untyped
408
- for (let i = 0, l = payload.length; i < l; i++) {
409
- const item = payload[i];
410
- // @ts-expect-error untyped
411
- const {
412
- data,
413
- included
414
- } = this.normalize(primaryModelClass, item);
415
- if (included) {
416
- documentHash.included = documentHash.included.concat(included);
417
- }
418
- ret[i] = data;
419
- }
420
-
421
- // @ts-expect-error untyped
422
- documentHash.data = ret;
423
- }
424
- return documentHash;
425
- },
426
- /**
427
- Normalizes a part of the JSON payload returned by
428
- the server. You should override this method, munge the hash
429
- and call super if you have generic normalization to do.
430
- It takes the type of the record that is being normalized
431
- (as a Model class), the property where the hash was
432
- originally found, and the hash to normalize.
433
- You can use this method, for example, to normalize underscored keys to camelized
434
- or other general-purpose normalizations.
435
- Example
436
- ```js [app/serializers/application.js]
437
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
438
- import { underscore } from '<app-name>/utils/string-utils';
439
- import { get } from '@ember/object';
440
- export default class ApplicationSerializer extends JSONSerializer {
441
- normalize(typeClass, hash) {
442
- let fields = typeClass.fields;
443
- fields.forEach(function(type, field) {
444
- let payloadField = underscore(field);
445
- if (field === payloadField) { return; }
446
- hash[field] = hash[payloadField];
447
- delete hash[payloadField];
448
- });
449
- return super.normalize(...arguments);
450
- }
451
- }
452
- ```
453
- @public
454
- */
455
- normalize(modelClass, resourceHash) {
456
- let data = null;
457
- if (resourceHash) {
458
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash);
459
- // @ts-expect-error untyped
460
- if (typeof resourceHash.links === 'object') {
461
- // @ts-expect-error untyped
462
- this.normalizeUsingDeclaredMapping(modelClass, resourceHash.links);
463
- }
464
-
465
- // @ts-expect-error untyped
466
- data = {
467
- id: this.extractId(modelClass, resourceHash),
468
- type: modelClass.modelName,
469
- attributes: this.extractAttributes(modelClass, resourceHash),
470
- relationships: this.extractRelationships(modelClass, resourceHash)
471
- };
472
-
473
- // @ts-expect-error untyped
474
- if (resourceHash.lid) {
475
- // @ts-expect-error untyped
476
- data.lid = resourceHash.lid;
477
- }
478
-
479
- // @ts-expect-error untyped
480
- this.applyTransforms(modelClass, data.attributes);
481
- }
482
- return {
483
- data
484
- };
485
- },
486
- /**
487
- Returns the resource's ID.
488
- @public
489
- */
490
- extractId(modelClass, resourceHash) {
491
- const primaryKey = this.primaryKey;
492
- const id = resourceHash[primaryKey];
493
- return coerceId(id);
494
- },
495
- /**
496
- Returns the resource's attributes formatted as a JSON-API "attributes object".
497
- http://jsonapi.org/format/#document-resource-object-attributes
498
- @public
499
- */
500
- extractAttributes(modelClass, resourceHash) {
501
- let attributeKey;
502
- const attributes = {};
503
- modelClass.eachAttribute(key => {
504
- attributeKey = this.keyForAttribute(key, 'deserialize');
505
- if (resourceHash[attributeKey] !== undefined) {
506
- attributes[key] = resourceHash[attributeKey];
507
- }
508
- });
509
- return attributes;
510
- },
511
- /**
512
- Returns a relationship formatted as a JSON-API "relationship object".
513
- http://jsonapi.org/format/#document-resource-object-relationships
514
- @public
515
- */
516
- extractRelationship(relationshipModelName, relationshipHash) {
517
- if (!relationshipHash) {
518
- return null;
519
- }
520
- /*
521
- When `relationshipHash` is an object it usually means that the relationship
522
- is polymorphic. It could however also be embedded resources that the
523
- EmbeddedRecordsMixin has be able to process.
524
- */
525
- if (relationshipHash && typeof relationshipHash === 'object' && !Array.isArray(relationshipHash)) {
526
- // @ts-expect-error untyped
527
- if (relationshipHash.id) {
528
- // @ts-expect-error untyped
529
- relationshipHash.id = coerceId(relationshipHash.id);
530
- }
531
-
532
- // @ts-expect-error store is dynamically injected
533
- const modelClass = this.store.modelFor(relationshipModelName);
534
- // @ts-expect-error untyped
535
- if (relationshipHash.type && !modelClass.fields.has('type')) {
536
- // @ts-expect-error untyped
537
- relationshipHash.type = this.modelNameFromPayloadKey(relationshipHash.type);
538
- }
539
- return relationshipHash;
540
- }
541
- return {
542
- id: coerceId(relationshipHash),
543
- type: dasherize(singularize(relationshipModelName))
544
- };
545
- },
546
- /**
547
- Returns a polymorphic relationship formatted as a JSON-API "relationship object".
548
- http://jsonapi.org/format/#document-resource-object-relationships
549
- `relationshipOptions` is a hash which contains more information about the
550
- polymorphic relationship which should be extracted:
551
- - `resourceHash` complete hash of the resource the relationship should be
552
- extracted from
553
- - `relationshipKey` key under which the value for the relationship is
554
- extracted from the resourceHash
555
- - `relationshipMeta` meta information about the relationship
556
- @public
557
- */
558
- extractPolymorphicRelationship(relationshipModelName, relationshipHash, relationshipOptions) {
559
- return this.extractRelationship(relationshipModelName, relationshipHash);
560
- },
561
- /**
562
- Returns the resource's relationships formatted as a JSON-API "relationships object".
563
- http://jsonapi.org/format/#document-resource-object-relationships
564
- @public
565
- */
566
- extractRelationships(modelClass, resourceHash) {
567
- const relationships = {};
568
- modelClass.eachRelationship((key, relationshipMeta) => {
569
- let relationship = null;
570
- const relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
571
- if (resourceHash[relationshipKey] !== undefined) {
572
- let data = null;
573
- const relationshipHash = resourceHash[relationshipKey];
574
- if (relationshipMeta.kind === 'belongsTo') {
575
- if (relationshipMeta.options.polymorphic) {
576
- // extracting a polymorphic belongsTo may need more information
577
- // than the type and the hash (which might only be an id) for the
578
- // relationship, hence we pass the key, resource and
579
- // relationshipMeta too
580
- // @ts-expect-error untyped
581
- data = this.extractPolymorphicRelationship(relationshipMeta.type, relationshipHash, {
582
- key,
583
- resourceHash,
584
- relationshipMeta
585
- });
586
- } else {
587
- // @ts-expect-error untyped
588
- data = this.extractRelationship(relationshipMeta.type, relationshipHash);
589
- }
590
- } else if (relationshipMeta.kind === 'hasMany') {
591
- if (relationshipHash) {
592
- // @ts-expect-error untyped
593
- data = new Array(relationshipHash.length);
594
- if (relationshipMeta.options.polymorphic) {
595
- for (let i = 0, l = relationshipHash.length; i < l; i++) {
596
- const item = relationshipHash[i];
597
- // @ts-expect-error untyped
598
- data[i] = this.extractPolymorphicRelationship(relationshipMeta.type, item, {
599
- key,
600
- resourceHash,
601
- relationshipMeta
602
- });
603
- }
604
- } else {
605
- for (let i = 0, l = relationshipHash.length; i < l; i++) {
606
- const item = relationshipHash[i];
607
- // @ts-expect-error untyped
608
- data[i] = this.extractRelationship(relationshipMeta.type, item);
609
- }
610
- }
611
- }
612
- }
613
- // @ts-expect-error untyped
614
- relationship = {
615
- data
616
- };
617
- }
618
- const linkKey = this.keyForLink(key, relationshipMeta.kind);
619
- // @ts-expect-error untyped
620
- if (resourceHash.links && resourceHash.links[linkKey] !== undefined) {
621
- // @ts-expect-error untyped
622
- const related = resourceHash.links[linkKey];
623
- // @ts-expect-error untyped
624
- relationship = relationship || {};
625
- // @ts-expect-error untyped
626
- relationship.links = {
627
- related
628
- };
629
- }
630
- if (relationship) {
631
- relationships[key] = relationship;
632
- }
633
- });
634
- return relationships;
635
- },
636
- /**
637
- Dasherizes the model name in the payload
638
- @public
639
- @return the model's modelName
640
- */
641
- modelNameFromPayloadKey(key) {
642
- return dasherize(singularize(key));
643
- },
644
- /**
645
- @private
646
- */
647
- normalizeRelationships(typeClass, hash) {
648
- let payloadKey;
649
- if (this.keyForRelationship) {
650
- typeClass.eachRelationship((key, relationship) => {
651
- payloadKey = this.keyForRelationship(key, relationship.kind, 'deserialize');
652
- if (key === payloadKey) {
653
- return;
654
- }
655
- if (hash[payloadKey] === undefined) {
656
- return;
657
- }
658
- hash[key] = hash[payloadKey];
659
- delete hash[payloadKey];
660
- });
661
- }
662
- },
663
- /**
664
- @private
665
- */
666
- normalizeUsingDeclaredMapping(modelClass, hash) {
667
- // @ts-expect-error attrs is dynamically injected
668
- const attrs = this.attrs;
669
- let normalizedKey;
670
- let payloadKey;
671
- if (attrs) {
672
- for (const key in attrs) {
673
- normalizedKey = payloadKey = this._getMappedKey(key, modelClass);
674
- if (hash[payloadKey] === undefined) {
675
- continue;
676
- }
677
- if (modelClass.attributes.has(key)) {
678
- normalizedKey = this.keyForAttribute(key, 'deserialize');
679
- }
680
- if (modelClass.relationshipsByName.has(key)) {
681
- normalizedKey = this.keyForRelationship(key, modelClass, 'deserialize');
682
- }
683
- if (payloadKey !== normalizedKey) {
684
- hash[normalizedKey] = hash[payloadKey];
685
- delete hash[payloadKey];
686
- }
687
- }
688
- }
689
- },
690
- /**
691
- Looks up the property key that was set by the custom `attr` mapping
692
- passed to the serializer.
693
- @private
694
- */
695
- _getMappedKey(key, modelClass) {
696
- warn('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', modelClass.attributes.has(key) || modelClass.relationshipsByName.has(key), {
697
- id: 'ds.serializer.no-mapped-attrs-key'
698
- });
699
- // @ts-expect-error attrs is dynamically injected
700
- const attrs = this.attrs;
701
- let mappedKey;
702
- if (attrs && attrs[key]) {
703
- mappedKey = attrs[key];
704
- //We need to account for both the { title: 'post_title' } and
705
- //{ title: { key: 'post_title' }} forms
706
- if (mappedKey.key) {
707
- mappedKey = mappedKey.key;
708
- }
709
- if (typeof mappedKey === 'string') {
710
- key = mappedKey;
711
- }
712
- }
713
- return key;
714
- },
715
- /**
716
- Check attrs.key.serialize property to inform if the `key`
717
- can be serialized
718
- @private
719
- @return true if the key can be serialized
720
- */
721
- _canSerialize(key) {
722
- // @ts-expect-error no idea what attrs is here
723
- const attrs = this.attrs;
724
- return !attrs || !attrs[key] || attrs[key].serialize !== false;
725
- },
726
- /**
727
- When attrs.key.serialize is set to true then
728
- it takes priority over the other checks and the related
729
- attribute/relationship will be serialized
730
- @private
731
- @return true if the key must be serialized
732
- */
733
- _mustSerialize(key) {
734
- // @ts-expect-error no idea what attrs is here
735
- const attrs = this.attrs;
736
- return attrs && attrs[key] && attrs[key].serialize === true;
737
- },
738
- /**
739
- Check if the given hasMany relationship should be serialized
740
- By default only many-to-many and many-to-none relationships are serialized.
741
- This could be configured per relationship by Serializer's `attrs` object.
742
- @public
743
- @return true if the hasMany relationship should be serialized
744
- */
745
- shouldSerializeHasMany(snapshot, key, relationship) {
746
- // @ts-expect-error store is dynamically injected
747
- const schema = this.store.modelFor(snapshot.modelName);
748
- // @ts-expect-error store is dynamically injected
749
- const relationshipType = schema.determineRelationshipType(relationship, this.store);
750
- if (this._mustSerialize(key)) {
751
- return true;
752
- }
753
- return this._canSerialize(key) && (relationshipType === 'manyToNone' || relationshipType === 'manyToMany');
754
- },
755
- // SERIALIZE
756
- /**
757
- Called when a record is saved in order to convert the
758
- record into JSON.
759
- By default, it creates a JSON object with a key for
760
- each attribute and belongsTo relationship.
761
- For example, consider this model:
762
- ```js [app/models/comment.js]
763
- import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
764
- export default class CommentModel extends Model {
765
- @attr title;
766
- @attr body;
767
- @belongsTo('user') author;
768
- }
769
- ```
770
- The default serialization would create a JSON object like:
771
- ```javascript
772
- {
773
- "title": "Rails is unagi",
774
- "body": "Rails? Omakase? O_O",
775
- "author": 12
776
- }
777
- ```
778
- By default, attributes are passed through as-is, unless
779
- you specified an attribute type (`attr('date')`). If
780
- you specify a transform, the JavaScript value will be
781
- serialized when inserted into the JSON hash.
782
- By default, belongs-to relationships are converted into
783
- IDs when inserted into the JSON hash.
784
- ## IDs
785
- `serialize` takes an options hash with a single option:
786
- `includeId`. If this option is `true`, `serialize` will,
787
- by default include the ID in the JSON object it builds.
788
- The adapter passes in `includeId: true` when serializing
789
- a record for `createRecord`, but not for `updateRecord`.
790
- ## Customization
791
- Your server may expect a different JSON format than the
792
- built-in serialization format.
793
- In that case, you can implement `serialize` yourself and
794
- return a JSON hash of your choosing.
795
- ```js [app/serializers/post.js]
796
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
797
- export default class PostSerializer extends JSONSerializer {
798
- serialize(snapshot, options) {
799
- let json = {
800
- POST_TTL: snapshot.attr('title'),
801
- POST_BDY: snapshot.attr('body'),
802
- POST_CMS: snapshot.hasMany('comments', { ids: true })
803
- };
804
- if (options.includeId) {
805
- json.POST_ID_ = snapshot.id;
806
- }
807
- return json;
808
- }
809
- }
810
- ```
811
- ## Customizing an App-Wide Serializer
812
- If you want to define a serializer for your entire
813
- application, you'll probably want to use `eachAttribute`
814
- and `eachRelationship` on the record.
815
- ```js [app/serializers/application.js]
816
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
817
- import { singularize } from '<app-name>/utils/string-utils';
818
- export default class ApplicationSerializer extends JSONSerializer {
819
- serialize(snapshot, options) {
820
- let json = {};
821
- snapshot.eachAttribute((name) => {
822
- json[serverAttributeName(name)] = snapshot.attr(name);
823
- });
824
- snapshot.eachRelationship((name, relationship) => {
825
- if (relationship.kind === 'hasMany') {
826
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
827
- }
828
- });
829
- if (options.includeId) {
830
- json.ID_ = snapshot.id;
831
- }
832
- return json;
833
- }
834
- }
835
- function serverAttributeName(attribute) {
836
- return attribute.underscore().toUpperCase();
837
- }
838
- function serverHasManyName(name) {
839
- return serverAttributeName(singularize(name)) + "_IDS";
840
- }
841
- ```
842
- This serializer will generate JSON that looks like this:
843
- ```javascript
844
- {
845
- "TITLE": "Rails is omakase",
846
- "BODY": "Yep. Omakase.",
847
- "COMMENT_IDS": [ "1", "2", "3" ]
848
- }
849
- ```
850
- ## Tweaking the Default JSON
851
- If you just want to do some small tweaks on the default JSON,
852
- you can call `super.serialize` first and make the tweaks on
853
- the returned JSON.
854
- ```js [app/serializers/post.js]
855
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
856
- export default class PostSerializer extends JSONSerializer {
857
- serialize(snapshot, options) {
858
- let json = super.serialize(...arguments);
859
- json.subject = json.title;
860
- delete json.title;
861
- return json;
862
- }
863
- }
864
- ```
865
- @public
866
- */
867
- serialize(snapshot, options) {
868
- const json = {};
869
-
870
- // @ts-expect-error super loose typing here right now
871
- if (options && options.includeId) {
872
- const id = snapshot.id;
873
- if (id) {
874
- json[this.primaryKey] = id;
875
- }
876
- }
877
- snapshot.eachAttribute((key, attribute) => {
878
- this.serializeAttribute(snapshot, json, key, attribute);
879
- });
880
- snapshot.eachRelationship((key, relationship) => {
881
- if (relationship.kind === 'belongsTo') {
882
- this.serializeBelongsTo(snapshot, json, relationship);
883
- } else if (relationship.kind === 'hasMany') {
884
- this.serializeHasMany(snapshot, json, relationship);
885
- }
886
- });
887
- return json;
888
- },
889
- /**
890
- You can use this method to customize how a serialized record is added to the complete
891
- JSON hash to be sent to the server. By default the JSON Serializer does not namespace
892
- the payload and just sends the raw serialized JSON object.
893
- If your server expects namespaced keys, you should consider using the RESTSerializer.
894
- Otherwise you can override this method to customize how the record is added to the hash.
895
- The hash property should be modified by reference.
896
- For example, your server may expect underscored root objects.
897
- ```js [app/serializers/application.js]
898
- import RESTSerializer from '@warp-drive/legacy/serializer/rest';
899
- import { underscoren} from '<app-name>/utils/string-utils';
900
- export default class ApplicationSerializer extends RESTSerializer {
901
- serializeIntoHash(data, type, snapshot, options) {
902
- let root = underscore(type.modelName);
903
- data[root] = this.serialize(snapshot, options);
904
- }
905
- }
906
- ```
907
- @public
908
- */
909
- serializeIntoHash(hash, typeClass, snapshot, options) {
910
- Object.assign(hash, this.serialize(snapshot, options));
911
- },
912
- /**
913
- `serializeAttribute` can be used to customize how `attr`
914
- properties are serialized
915
- For example if you wanted to ensure all your attributes were always
916
- serialized as properties on an `attributes` object you could
917
- write:
918
- ```js [app/serializers/application.js]
919
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
920
- export default class ApplicationSerializer extends JSONSerializer {
921
- serializeAttribute(snapshot, json, key, attributes) {
922
- json.attributes = json.attributes || {};
923
- super.serializeAttribute(snapshot, json.attributes, key, attributes);
924
- }
925
- }
926
- ```
927
- @public
928
- */
929
- serializeAttribute(snapshot, json, key, attribute) {
930
- if (this._canSerialize(key)) {
931
- const type = attribute.type;
932
- // @ts-expect-error we don't know what is on the snapshot
933
- let value = snapshot.attr(key);
934
- if (type) {
935
- const transform = this.transformFor(type);
936
- value = transform.serialize(value, attribute.options);
937
- }
938
-
939
- // if provided, use the mapping provided by `attrs` in
940
- // the serializer
941
- // @ts-expect-error store added dynamically
942
- const schema = this.store.modelFor(snapshot.modelName);
943
- let payloadKey = this._getMappedKey(key, schema);
944
- if (payloadKey === key && this.keyForAttribute) {
945
- payloadKey = this.keyForAttribute(key, 'serialize');
946
- }
947
- json[payloadKey] = value;
948
- }
949
- },
950
- /**
951
- `serializeBelongsTo` can be used to customize how `belongsTo`
952
- properties are serialized.
953
- Example
954
- ```js [app/serializers/post.js]
955
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
956
- export default class PostSerializer extends JSONSerializer {
957
- serializeBelongsTo(snapshot, json, relationship) {
958
- let key = relationship.name;
959
- let belongsTo = snapshot.belongsTo(key);
960
- key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;
961
- json[key] = !belongsTo ? null : belongsTo.record.toJSON();
962
- }
963
- }
964
- ```
965
- @public
966
- */
967
- serializeBelongsTo(snapshot, json, relationship) {
968
- const name = relationship.name;
969
- if (this._canSerialize(name)) {
970
- const belongsToId = snapshot.belongsTo(name, {
971
- id: true
972
- });
973
-
974
- // if provided, use the mapping provided by `attrs` in
975
- // the serializer
976
- // @ts-expect-error store added dynamically
977
- const schema = this.store.modelFor(snapshot.modelName);
978
- let payloadKey = this._getMappedKey(name, schema);
979
- if (payloadKey === name && this.keyForRelationship) {
980
- payloadKey = this.keyForRelationship(name, 'belongsTo', 'serialize');
981
- }
982
-
983
- //Need to check whether the id is there for new&async records
984
- if (!belongsToId) {
985
- json[payloadKey] = null;
986
- } else {
987
- json[payloadKey] = belongsToId;
988
- }
989
- if (relationship.options.polymorphic) {
990
- this.serializePolymorphicType(snapshot, json, relationship);
991
- }
992
- }
993
- },
994
- /**
995
- `serializeHasMany` can be used to customize how `hasMany`
996
- properties are serialized.
997
- Example
998
- ```js [app/serializers/post.js]
999
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1000
- export default class PostSerializer extends JSONSerializer {
1001
- serializeHasMany(snapshot, json, relationship) {
1002
- let key = relationship.name;
1003
- if (key === 'comments') {
1004
- return;
1005
- } else {
1006
- super.serializeHasMany(...arguments);
1007
- }
1008
- }
1009
- }
1010
- ```
1011
- @public
1012
- */
1013
- serializeHasMany(snapshot, json, relationship) {
1014
- const name = relationship.name;
1015
- if (this.shouldSerializeHasMany(snapshot, name, relationship)) {
1016
- const hasMany = snapshot.hasMany(name, {
1017
- ids: true
1018
- });
1019
- if (hasMany !== undefined) {
1020
- // if provided, use the mapping provided by `attrs` in
1021
- // the serializer
1022
- // @ts-expect-error store added dynamically
1023
- const schema = this.store.modelFor(snapshot.modelName);
1024
- let payloadKey = this._getMappedKey(name, schema);
1025
- if (payloadKey === name && this.keyForRelationship) {
1026
- payloadKey = this.keyForRelationship(name, 'hasMany', 'serialize');
1027
- }
1028
- json[payloadKey] = hasMany;
1029
- // TODO support for polymorphic manyToNone and manyToMany relationships
1030
- }
1031
- }
1032
- },
1033
- /**
1034
- You can use this method to customize how polymorphic objects are
1035
- serialized. Objects are considered to be polymorphic if
1036
- `{ polymorphic: true }` is pass as the second argument to the
1037
- `belongsTo` function.
1038
- Example
1039
- ```js [app/serializers/comment.js]
1040
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1041
- export default class CommentSerializer extends JSONSerializer {
1042
- serializePolymorphicType(snapshot, json, relationship) {
1043
- let key = relationship.name;
1044
- let belongsTo = snapshot.belongsTo(key);
1045
- key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;
1046
- if (!belongsTo) {
1047
- json[key + '_type'] = null;
1048
- } else {
1049
- json[key + '_type'] = belongsTo.modelName;
1050
- }
1051
- }
1052
- }
1053
- ```
1054
- @public
1055
- */
1056
- serializePolymorphicType(snapshot, json, relationship) {},
1057
- /**
1058
- `extractMeta` is used to deserialize any meta information in the
1059
- adapter payload. By default Ember Data expects meta information to
1060
- be located on the `meta` property of the payload object.
1061
- Example
1062
- ```js [app/serializers/post.js]
1063
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1064
- export default class PostSerializer extends JSONSerializer {
1065
- extractMeta(store, typeClass, payload) {
1066
- if (payload && payload.hasOwnProperty('_pagination')) {
1067
- let meta = payload._pagination;
1068
- delete payload._pagination;
1069
- return meta;
1070
- }
1071
- }
1072
- }
1073
- ```
1074
- @public
1075
- */
1076
- extractMeta(store, modelClass, payload) {
1077
- if (payload && payload['meta'] !== undefined) {
1078
- // @ts-expect-error
1079
- const meta = payload.meta;
1080
- // @ts-expect-error
1081
- delete payload.meta;
1082
- return meta;
1083
- }
1084
- },
1085
- /**
1086
- `extractErrors` is used to extract model errors when a call
1087
- to `Model#save` fails with an `InvalidError`. By default
1088
- Ember Data expects error information to be located on the `errors`
1089
- property of the payload object.
1090
- This serializer expects this `errors` object to be an Array similar
1091
- to the following, compliant with the https://jsonapi.org/format/#errors specification:
1092
- ```js
1093
- {
1094
- "errors": [
1095
- {
1096
- "detail": "This username is already taken!",
1097
- "source": {
1098
- "pointer": "data/attributes/username"
1099
- }
1100
- }, {
1101
- "detail": "Doesn't look like a valid email.",
1102
- "source": {
1103
- "pointer": "data/attributes/email"
1104
- }
1105
- }
1106
- ]
1107
- }
1108
- ```
1109
- The key `detail` provides a textual description of the problem.
1110
- Alternatively, the key `title` can be used for the same purpose.
1111
- The nested keys `source.pointer` detail which specific element
1112
- of the request data was invalid.
1113
- Note that JSON-API also allows for object-level errors to be placed
1114
- in an object with pointer `data`, signifying that the problem
1115
- cannot be traced to a specific attribute:
1116
- ```javascript
1117
- {
1118
- "errors": [
1119
- {
1120
- "detail": "Some generic non property error message",
1121
- "source": {
1122
- "pointer": "data"
1123
- }
1124
- }
1125
- ]
1126
- }
1127
- ```
1128
- When turn into a `Errors` object, you can read these errors
1129
- through the property `base`:
1130
- ```handlebars
1131
- {{#each @model.errors.base as |error|}}
1132
- <div class="error">
1133
- {{error.message}}
1134
- </div>
1135
- {{/each}}
1136
- ```
1137
- Example of alternative implementation, overriding the default
1138
- behavior to deal with a different format of errors:
1139
- ```js [app/serializers/post.js]
1140
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1141
- export default class PostSerializer extends JSONSerializer {
1142
- extractErrors(store, typeClass, payload, id) {
1143
- if (payload && typeof payload === 'object' && payload._problems) {
1144
- payload = payload._problems;
1145
- this.normalizeErrors(typeClass, payload);
1146
- }
1147
- return payload;
1148
- }
1149
- }
1150
- ```
1151
- @public
1152
- @return json The deserialized errors
1153
- */
1154
- extractErrors(store, typeClass, payload, id) {
1155
- // @ts-expect-error
1156
- if (payload && typeof payload === 'object' && payload.errors) {
1157
- // the default assumption is that errors is already in JSON:API format
1158
- const extracted = {};
1159
-
1160
- // @ts-expect-error
1161
- payload.errors.forEach(error => {
1162
- if (error.source && error.source.pointer) {
1163
- let key = error.source.pointer.match(SOURCE_POINTER_REGEXP);
1164
- if (key) {
1165
- key = key[2];
1166
- } else if (error.source.pointer.search(SOURCE_POINTER_PRIMARY_REGEXP) !== -1) {
1167
- key = PRIMARY_ATTRIBUTE_KEY;
1168
- }
1169
- if (key) {
1170
- extracted[key] = extracted[key] || [];
1171
- extracted[key].push(error.detail || error.title);
1172
- }
1173
- }
1174
- });
1175
-
1176
- // if the user has an attrs hash, convert keys using it
1177
- this.normalizeUsingDeclaredMapping(typeClass, extracted);
1178
-
1179
- // for each attr and relationship, make sure that we use
1180
- // the normalized key
1181
- typeClass.eachAttribute(name => {
1182
- const key = this.keyForAttribute(name, 'deserialize');
1183
- if (key !== name && extracted[key] !== undefined) {
1184
- extracted[name] = extracted[key];
1185
- delete extracted[key];
1186
- }
1187
- });
1188
- typeClass.eachRelationship(name => {
1189
- const key = this.keyForRelationship(name, 'deserialize');
1190
- if (key !== name && extracted[key] !== undefined) {
1191
- extracted[name] = extracted[key];
1192
- delete extracted[key];
1193
- }
1194
- });
1195
- return extracted;
1196
- }
1197
- return payload;
1198
- },
1199
- /**
1200
- `keyForAttribute` can be used to define rules for how to convert an
1201
- attribute name in your model to a key in your JSON.
1202
- Example
1203
- ```js [app/serializers/application.js]
1204
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1205
- import { underscore } from '<app-name>/utils/string-utils';
1206
- export default class ApplicationSerializer extends JSONSerializer {
1207
- keyForAttribute(attr, method) {
1208
- return underscore(attr).toUpperCase();
1209
- }
1210
- }
1211
- ```
1212
- @public
1213
- */
1214
- keyForAttribute(key, method) {
1215
- return key;
1216
- },
1217
- /**
1218
- `keyForRelationship` can be used to define a custom key when
1219
- serializing and deserializing relationship properties. By default
1220
- `JSONSerializer` does not provide an implementation of this method.
1221
- Example
1222
- ```js [app/serializers/post.js]
1223
- import { JSONSerializer } from '@warp-drive/legacy/serializer/json';
1224
- import { underscore } from '<app-name>/utils/string-utils';
1225
- export default class PostSerializer extends JSONSerializer {
1226
- keyForRelationship(key, relationship, method) {
1227
- return `rel_${underscore(key)}`;
1228
- }
1229
- }
1230
- ```
1231
- @public
1232
- */
1233
- keyForRelationship(key, typeClass, method) {
1234
- return key;
1235
- },
1236
- /**
1237
- `keyForLink` can be used to define a custom key when deserializing link
1238
- properties.
1239
- @public
1240
- */
1241
- keyForLink(key, kind) {
1242
- return key;
1243
- },
1244
- // HELPERS
1245
-
1246
- /**
1247
- @private
1248
- */
1249
- transformFor(attributeType, skipAssertion) {
1250
- const transform = getOwner(this).lookup(`transform:${attributeType}`);
1251
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1252
- if (!test) {
1253
- throw new Error(`Unable to find the transform for \`attr('${attributeType}')\``);
1254
- }
1255
- })(skipAssertion || !!transform) : {};
1256
- return transform;
1257
- }
1258
- });
1259
- export { JSONSerializer as J, coerceId as c };