@warp-drive/legacy 5.8.0-alpha.30 → 5.8.0-alpha.34

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