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

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