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

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 +6 -6
@@ -0,0 +1,1243 @@
1
+ import { warn } from '@ember/debug';
2
+ import { camelize, dasherize, singularize } from '@warp-drive/utilities/string';
3
+ import { J as JSONSerializer, c as coerceId } from "../json-BNrV8EYG.js";
4
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
5
+ import Mixin from '@ember/object/mixin';
6
+
7
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
8
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
9
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
10
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
11
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
12
+
13
+ /**
14
+ ## Using Embedded Records
15
+
16
+ `EmbeddedRecordsMixin` supports serializing embedded records.
17
+
18
+ To set up embedded records, include the mixin when extending a serializer,
19
+ then define and configure embedded (model) relationships.
20
+
21
+ Note that embedded records will serialize with the serializer for their model instead of the serializer in which they are defined.
22
+
23
+ Note also that this mixin does not work with JSONAPISerializer because the JSON:API specification does not describe how to format embedded resources.
24
+
25
+ Below is an example of a per-type serializer (`post` type).
26
+
27
+ ```js [app/serializers/post.js]
28
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
29
+
30
+ export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
31
+ attrs = {
32
+ author: { embedded: 'always' },
33
+ comments: { serialize: 'ids' }
34
+ }
35
+ }
36
+ ```
37
+ Note that this use of `{ embedded: 'always' }` is unrelated to
38
+ the `{ embedded: 'always' }` that is defined as an option on `attr` as part of
39
+ defining a model while working with the `ActiveModelSerializer`. Nevertheless,
40
+ using `{ embedded: 'always' }` as an option to `attr` is not a valid way to set up
41
+ embedded records.
42
+
43
+ The `attrs` option for a resource `{ embedded: 'always' }` is shorthand for:
44
+
45
+ ```js
46
+ {
47
+ serialize: 'records',
48
+ deserialize: 'records'
49
+ }
50
+ ```
51
+
52
+ ### Configuring Attrs
53
+
54
+ A resource's `attrs` option may be set to use `ids`, `records` or false for the
55
+ `serialize` and `deserialize` settings.
56
+
57
+ The `attrs` property can be set on the `ApplicationSerializer` or a per-type
58
+ serializer.
59
+
60
+ In the case where embedded JSON is expected while extracting a payload (reading)
61
+ the setting is `deserialize: 'records'`, there is no need to use `ids` when
62
+ extracting as that is the default behaviour without this mixin if you are using
63
+ the vanilla `EmbeddedRecordsMixin`. Likewise, to embed JSON in the payload while
64
+ serializing `serialize: 'records'` is the setting to use. There is an option of
65
+ not embedding JSON in the serialized payload by using `serialize: 'ids'`. If you
66
+ do not want the relationship sent at all, you can use `serialize: false`.
67
+
68
+
69
+ ### EmbeddedRecordsMixin defaults
70
+ If you do not overwrite `attrs` for a specific relationship, the `EmbeddedRecordsMixin`
71
+ will behave in the following way:
72
+
73
+ BelongsTo: `{ serialize: 'id', deserialize: 'id' }`
74
+ HasMany: `{ serialize: false, deserialize: 'ids' }`
75
+
76
+ ### Model Relationships
77
+
78
+ Embedded records must have a model defined to be extracted and serialized. Note that
79
+ when defining any relationships on your model such as `belongsTo` and `hasMany`, you
80
+ should not both specify `async: true` and also indicate through the serializer's
81
+ `attrs` attribute that the related model should be embedded for deserialization.
82
+ If a model is declared embedded for deserialization (`embedded: 'always'` or `deserialize: 'records'`),
83
+ then do not use `async: true`.
84
+
85
+ To successfully extract and serialize embedded records the model relationships
86
+ must be set up correctly. See the
87
+ [defining relationships](https://guides.emberjs.com/current/models/relationships)
88
+ section of the **Defining Models** guide page.
89
+
90
+ Records without an `id` property are not considered embedded records, model
91
+ instances must have an `id` property to be used with Ember Data.
92
+
93
+ ### Example JSON payloads, Models and Serializers
94
+
95
+ **When customizing a serializer it is important to grok what the customizations
96
+ are. Please read the docs for the methods this mixin provides, in case you need
97
+ to modify it to fit your specific needs.**
98
+
99
+ @class EmbeddedRecordsMixin
100
+ @public
101
+ */
102
+ const EmbeddedRecordsMixin = Mixin.create({
103
+ /**
104
+ Normalize the record and recursively normalize/extract all the embedded records
105
+ while pushing them into the store as they are encountered
106
+ A payload with an attr configured for embedded records needs to be extracted:
107
+ ```js
108
+ {
109
+ "post": {
110
+ "id": "1"
111
+ "title": "Rails is omakase",
112
+ "comments": [{
113
+ "id": "1",
114
+ "body": "Rails is unagi"
115
+ }, {
116
+ "id": "2",
117
+ "body": "Omakase O_o"
118
+ }]
119
+ }
120
+ }
121
+ ```
122
+ @public
123
+ @param {Model} typeClass
124
+ @param {Object} hash to be normalized
125
+ @param {String} prop the hash has been referenced by
126
+ @return {Object} the normalized hash
127
+ **/
128
+ normalize(typeClass, hash, prop) {
129
+ const normalizedHash = this._super(typeClass, hash, prop);
130
+ return this._extractEmbeddedRecords(this, this.store, typeClass, normalizedHash);
131
+ },
132
+ keyForRelationship(key, typeClass, method) {
133
+ if (method === 'serialize' && this.hasSerializeRecordsOption(key) || method === 'deserialize' && this.hasDeserializeRecordsOption(key)) {
134
+ return this.keyForAttribute(key, method);
135
+ } else {
136
+ return this._super(key, typeClass, method) || key;
137
+ }
138
+ },
139
+ /**
140
+ Serialize `belongsTo` relationship when it is configured as an embedded object.
141
+ This example of an author model belongs to a post model:
142
+ ```js
143
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
144
+ Post = Model.extend({
145
+ title: attr('string'),
146
+ body: attr('string'),
147
+ author: belongsTo('author')
148
+ });
149
+ Author = Model.extend({
150
+ name: attr('string'),
151
+ post: belongsTo('post')
152
+ });
153
+ ```
154
+ Use a custom (type) serializer for the post model to configure embedded author
155
+ ```js [app/serializers/post.js]
156
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
157
+ export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
158
+ attrs = {
159
+ author: { embedded: 'always' }
160
+ }
161
+ }
162
+ ```
163
+ A payload with an attribute configured for embedded records can serialize
164
+ the records together under the root attribute's payload:
165
+ ```js
166
+ {
167
+ "post": {
168
+ "id": "1"
169
+ "title": "Rails is omakase",
170
+ "author": {
171
+ "id": "2"
172
+ "name": "dhh"
173
+ }
174
+ }
175
+ }
176
+ ```
177
+ @public
178
+ @param {Snapshot} snapshot
179
+ @param {Object} json
180
+ @param {Object} relationship
181
+ */
182
+ serializeBelongsTo(snapshot, json, relationship) {
183
+ const attr = relationship.name;
184
+ if (this.noSerializeOptionSpecified(attr)) {
185
+ this._super(snapshot, json, relationship);
186
+ return;
187
+ }
188
+ const includeIds = this.hasSerializeIdsOption(attr);
189
+ const includeRecords = this.hasSerializeRecordsOption(attr);
190
+ const embeddedSnapshot = snapshot.belongsTo(attr);
191
+ if (includeIds) {
192
+ const schema = this.store.modelFor(snapshot.modelName);
193
+ let serializedKey = this._getMappedKey(relationship.name, schema);
194
+ if (serializedKey === relationship.name && this.keyForRelationship) {
195
+ serializedKey = this.keyForRelationship(relationship.name, relationship.kind, 'serialize');
196
+ }
197
+ if (!embeddedSnapshot) {
198
+ json[serializedKey] = null;
199
+ } else {
200
+ json[serializedKey] = embeddedSnapshot.id;
201
+ if (relationship.options.polymorphic) {
202
+ this.serializePolymorphicType(snapshot, json, relationship);
203
+ }
204
+ }
205
+ } else if (includeRecords) {
206
+ this._serializeEmbeddedBelongsTo(snapshot, json, relationship);
207
+ }
208
+ },
209
+ _serializeEmbeddedBelongsTo(snapshot, json, relationship) {
210
+ const embeddedSnapshot = snapshot.belongsTo(relationship.name);
211
+ const schema = this.store.modelFor(snapshot.modelName);
212
+ let serializedKey = this._getMappedKey(relationship.name, schema);
213
+ if (serializedKey === relationship.name && this.keyForRelationship) {
214
+ serializedKey = this.keyForRelationship(relationship.name, relationship.kind, 'serialize');
215
+ }
216
+ if (!embeddedSnapshot) {
217
+ json[serializedKey] = null;
218
+ } else {
219
+ json[serializedKey] = embeddedSnapshot.serialize({
220
+ includeId: true
221
+ });
222
+ this.removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json[serializedKey]);
223
+ if (relationship.options.polymorphic) {
224
+ this.serializePolymorphicType(snapshot, json, relationship);
225
+ }
226
+ }
227
+ },
228
+ /**
229
+ Serializes `hasMany` relationships when it is configured as embedded objects.
230
+ This example of a post model has many comments:
231
+ ```js
232
+ import Model, { attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
233
+ Post = Model.extend({
234
+ title: attr('string'),
235
+ body: attr('string'),
236
+ comments: hasMany('comment')
237
+ });
238
+ Comment = Model.extend({
239
+ body: attr('string'),
240
+ post: belongsTo('post')
241
+ });
242
+ ```
243
+ Use a custom (type) serializer for the post model to configure embedded comments
244
+ ```js [app/serializers/post.js]
245
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
246
+ export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
247
+ attrs = {
248
+ comments: { embedded: 'always' }
249
+ }
250
+ }
251
+ ```
252
+ A payload with an attribute configured for embedded records can serialize
253
+ the records together under the root attribute's payload:
254
+ ```js
255
+ {
256
+ "post": {
257
+ "id": "1"
258
+ "title": "Rails is omakase",
259
+ "body": "I want this for my ORM, I want that for my template language..."
260
+ "comments": [{
261
+ "id": "1",
262
+ "body": "Rails is unagi"
263
+ }, {
264
+ "id": "2",
265
+ "body": "Omakase O_o"
266
+ }]
267
+ }
268
+ }
269
+ ```
270
+ The attrs options object can use more specific instruction for extracting and
271
+ serializing. When serializing, an option to embed `ids`, `ids-and-types` or `records` can be set.
272
+ When extracting the only option is `records`.
273
+ So `{ embedded: 'always' }` is shorthand for:
274
+ `{ serialize: 'records', deserialize: 'records' }`
275
+ To embed the `ids` for a related object (using a hasMany relationship):
276
+ ```js [app/serializers/post.js]
277
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
278
+ export default class PostSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
279
+ attrs = {
280
+ comments: { serialize: 'ids', deserialize: 'records' }
281
+ }
282
+ }
283
+ ```
284
+ ```js
285
+ {
286
+ "post": {
287
+ "id": "1"
288
+ "title": "Rails is omakase",
289
+ "body": "I want this for my ORM, I want that for my template language..."
290
+ "comments": ["1", "2"]
291
+ }
292
+ }
293
+ ```
294
+ To embed the relationship as a collection of objects with `id` and `type` keys, set
295
+ `ids-and-types` for the related object.
296
+ This is particularly useful for polymorphic relationships where records don't share
297
+ the same table and the `id` is not enough information.
298
+ For example having a user that has many pets:
299
+ ```js
300
+ User = Model.extend({
301
+ name: attr('string'),
302
+ pets: hasMany('pet', { polymorphic: true })
303
+ });
304
+ Pet = Model.extend({
305
+ name: attr('string'),
306
+ });
307
+ Cat = Pet.extend({
308
+ // ...
309
+ });
310
+ Parrot = Pet.extend({
311
+ // ...
312
+ });
313
+ ```
314
+ ```js [app/serializers/user.js]
315
+ import RESTSerializer, { EmbeddedRecordsMixin } from '@warp-drive/legacy/serializer/rest';
316
+ export default class UserSerializer extends RESTSerializer.extend(EmbeddedRecordsMixin) {
317
+ attrs = {
318
+ pets: { serialize: 'ids-and-types', deserialize: 'records' }
319
+ }
320
+ }
321
+ ```
322
+ ```js
323
+ {
324
+ "user": {
325
+ "id": "1"
326
+ "name": "Bertin Osborne",
327
+ "pets": [
328
+ { "id": "1", "type": "Cat" },
329
+ { "id": "1", "type": "Parrot"}
330
+ ]
331
+ }
332
+ }
333
+ ```
334
+ @public
335
+ @param {Snapshot} snapshot
336
+ @param {Object} json
337
+ @param {Object} relationship
338
+ */
339
+ serializeHasMany(snapshot, json, relationship) {
340
+ const attr = relationship.name;
341
+ if (this.noSerializeOptionSpecified(attr)) {
342
+ this._super(snapshot, json, relationship);
343
+ return;
344
+ }
345
+ if (this.hasSerializeIdsOption(attr)) {
346
+ const schema = this.store.modelFor(snapshot.modelName);
347
+ let serializedKey = this._getMappedKey(relationship.name, schema);
348
+ if (serializedKey === relationship.name && this.keyForRelationship) {
349
+ serializedKey = this.keyForRelationship(relationship.name, relationship.kind, 'serialize');
350
+ }
351
+ json[serializedKey] = snapshot.hasMany(attr, {
352
+ ids: true
353
+ });
354
+ } else if (this.hasSerializeRecordsOption(attr)) {
355
+ this._serializeEmbeddedHasMany(snapshot, json, relationship);
356
+ } else {
357
+ if (this.hasSerializeIdsAndTypesOption(attr)) {
358
+ this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship);
359
+ }
360
+ }
361
+ },
362
+ /*
363
+ Serializes a hasMany relationship as an array of objects containing only `id` and `type`
364
+ keys.
365
+ This has its use case on polymorphic hasMany relationships where the server is not storing
366
+ all records in the same table using STI, and therefore the `id` is not enough information
367
+ TODO: Make the default in Ember-data 3.0??
368
+ */
369
+ _serializeHasManyAsIdsAndTypes(snapshot, json, relationship) {
370
+ const serializedKey = this.keyForAttribute(relationship.name, 'serialize');
371
+ const hasMany = snapshot.hasMany(relationship.name) || [];
372
+ json[serializedKey] = hasMany.map(function (recordSnapshot) {
373
+ //
374
+ // I'm sure I'm being utterly naive here. Probably id is a configurable property and
375
+ // type too, and the modelName has to be normalized somehow.
376
+ //
377
+ return {
378
+ id: recordSnapshot.id,
379
+ type: recordSnapshot.modelName
380
+ };
381
+ });
382
+ },
383
+ _serializeEmbeddedHasMany(snapshot, json, relationship) {
384
+ const schema = this.store.modelFor(snapshot.modelName);
385
+ let serializedKey = this._getMappedKey(relationship.name, schema);
386
+ if (serializedKey === relationship.name && this.keyForRelationship) {
387
+ serializedKey = this.keyForRelationship(relationship.name, relationship.kind, 'serialize');
388
+ }
389
+ warn(`The embedded relationship '${serializedKey}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`, typeof snapshot.hasMany(relationship.name) !== 'undefined', {
390
+ id: 'ds.serializer.embedded-relationship-undefined'
391
+ });
392
+ json[serializedKey] = this._generateSerializedHasMany(snapshot, relationship);
393
+ },
394
+ /*
395
+ Returns an array of embedded records serialized to JSON
396
+ */
397
+ _generateSerializedHasMany(snapshot, relationship) {
398
+ const hasMany = snapshot.hasMany(relationship.name) || [];
399
+ const ret = new Array(hasMany.length);
400
+ for (let i = 0; i < hasMany.length; i++) {
401
+ const embeddedSnapshot = hasMany[i];
402
+ const embeddedJson = embeddedSnapshot.serialize({
403
+ includeId: true
404
+ });
405
+ this.removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, embeddedJson);
406
+ ret[i] = embeddedJson;
407
+ }
408
+ return ret;
409
+ },
410
+ /**
411
+ When serializing an embedded record, modify the property (in the `JSON` payload)
412
+ that refers to the parent record (foreign key for the relationship).
413
+ Serializing a `belongsTo` relationship removes the property that refers to the
414
+ parent record
415
+ Serializing a `hasMany` relationship does not remove the property that refers to
416
+ the parent record.
417
+ @public
418
+ @param {Snapshot} snapshot
419
+ @param {Snapshot} embeddedSnapshot
420
+ @param {Object} relationship
421
+ @param {Object} json
422
+ */
423
+ removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json) {
424
+ if (relationship.kind === 'belongsTo') {
425
+ const schema = this.store.modelFor(snapshot.modelName);
426
+ const parentRecord = schema.inverseFor(relationship.name, this.store);
427
+ if (parentRecord) {
428
+ const name = parentRecord.name;
429
+ const embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName);
430
+ const parentKey = embeddedSerializer.keyForRelationship(name, parentRecord.kind, 'deserialize');
431
+ if (parentKey) {
432
+ delete json[parentKey];
433
+ }
434
+ }
435
+ } /*else if (relationship.kind === 'hasMany') {
436
+ return;
437
+ }*/
438
+ },
439
+ // checks config for attrs option to embedded (always) - serialize and deserialize
440
+ hasEmbeddedAlwaysOption(attr) {
441
+ const option = this.attrsOption(attr);
442
+ return option && option.embedded === 'always';
443
+ },
444
+ // checks config for attrs option to serialize ids
445
+ hasSerializeRecordsOption(attr) {
446
+ const alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
447
+ const option = this.attrsOption(attr);
448
+ return alwaysEmbed || option && option.serialize === 'records';
449
+ },
450
+ // checks config for attrs option to serialize records
451
+ hasSerializeIdsOption(attr) {
452
+ const option = this.attrsOption(attr);
453
+ return option && (option.serialize === 'ids' || option.serialize === 'id');
454
+ },
455
+ // checks config for attrs option to serialize records as objects containing id and types
456
+ hasSerializeIdsAndTypesOption(attr) {
457
+ const option = this.attrsOption(attr);
458
+ return option && (option.serialize === 'ids-and-types' || option.serialize === 'id-and-type');
459
+ },
460
+ // checks config for attrs option to serialize records
461
+ noSerializeOptionSpecified(attr) {
462
+ const option = this.attrsOption(attr);
463
+ return !(option && (option.serialize || option.embedded));
464
+ },
465
+ // checks config for attrs option to deserialize records
466
+ // a defined option object for a resource is treated the same as
467
+ // `deserialize: 'records'`
468
+ hasDeserializeRecordsOption(attr) {
469
+ const alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
470
+ const option = this.attrsOption(attr);
471
+ return alwaysEmbed || option && option.deserialize === 'records';
472
+ },
473
+ attrsOption(attr) {
474
+ const attrs = this.attrs;
475
+ return attrs && (attrs[camelize(attr)] || attrs[attr]);
476
+ },
477
+ /**
478
+ @private
479
+ */
480
+ _extractEmbeddedRecords(serializer, store, typeClass, partial) {
481
+ typeClass.eachRelationship((key, relationship) => {
482
+ if (serializer.hasDeserializeRecordsOption(key)) {
483
+ if (relationship.kind === 'hasMany') {
484
+ this._extractEmbeddedHasMany(store, key, partial, relationship);
485
+ }
486
+ if (relationship.kind === 'belongsTo') {
487
+ this._extractEmbeddedBelongsTo(store, key, partial, relationship);
488
+ }
489
+ }
490
+ });
491
+ return partial;
492
+ },
493
+ /**
494
+ @private
495
+ */
496
+ _extractEmbeddedHasMany(store, key, hash, relationshipMeta) {
497
+ const relationshipHash = hash.data?.relationships?.[key]?.data;
498
+ if (!relationshipHash) {
499
+ return;
500
+ }
501
+ const hasMany = new Array(relationshipHash.length);
502
+ for (let i = 0; i < relationshipHash.length; i++) {
503
+ const item = relationshipHash[i];
504
+ const {
505
+ data,
506
+ included
507
+ } = this._normalizeEmbeddedRelationship(store, relationshipMeta, item);
508
+ hash.included = hash.included || [];
509
+ hash.included.push(data);
510
+ if (included) {
511
+ hash.included = hash.included.concat(included);
512
+ }
513
+ hasMany[i] = {
514
+ id: data.id,
515
+ type: data.type
516
+ };
517
+ if (data.lid) {
518
+ hasMany[i].lid = data.lid;
519
+ }
520
+ }
521
+ const relationship = {
522
+ data: hasMany
523
+ };
524
+ hash.data.relationships[key] = relationship;
525
+ },
526
+ /**
527
+ @private
528
+ */
529
+ _extractEmbeddedBelongsTo(store, key, hash, relationshipMeta) {
530
+ const relationshipHash = hash.data?.relationships?.[key]?.data;
531
+ if (!relationshipHash) {
532
+ return;
533
+ }
534
+ const {
535
+ data,
536
+ included
537
+ } = this._normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash);
538
+ hash.included = hash.included || [];
539
+ hash.included.push(data);
540
+ if (included) {
541
+ hash.included = hash.included.concat(included);
542
+ }
543
+ const belongsTo = {
544
+ id: data.id,
545
+ type: data.type
546
+ };
547
+ const relationship = {
548
+ data: belongsTo
549
+ };
550
+ if (data.lid) {
551
+ // @ts-expect-error
552
+ belongsTo.lid = data.lid;
553
+ }
554
+ hash.data.relationships[key] = relationship;
555
+ },
556
+ /**
557
+ @private
558
+ */
559
+ _normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash) {
560
+ let modelName = relationshipMeta.type;
561
+ if (relationshipMeta.options.polymorphic) {
562
+ modelName = relationshipHash.type;
563
+ }
564
+ const modelClass = store.modelFor(modelName);
565
+ const serializer = store.serializerFor(modelName);
566
+ return serializer.normalize(modelClass, relationshipHash, null);
567
+ },
568
+ isEmbeddedRecordsMixin: true
569
+ });
570
+
571
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
572
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
573
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
574
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
575
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
576
+ function makeArray(value) {
577
+ return Array.isArray(value) ? value : [value];
578
+ }
579
+
580
+ /**
581
+ * :::danger
582
+ ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
583
+ If starting a new app or thinking of implementing a new adapter, consider writing a
584
+ {@link Handler} instead to be used with the {@link RequestManager}
585
+ :::
586
+
587
+ Normally, applications will use the `RESTSerializer` by implementing
588
+ the `normalize` method.
589
+
590
+ This allows you to do whatever kind of munging you need and is
591
+ especially useful if your server is inconsistent and you need to
592
+ do munging differently for many different kinds of responses.
593
+
594
+ See the `normalize` documentation for more information.
595
+
596
+ ## Across the Board Normalization
597
+
598
+ There are also a number of hooks that you might find useful to define
599
+ across-the-board rules for your payload. These rules will be useful
600
+ if your server is consistent, or if you're building an adapter for
601
+ an infrastructure service, like Firebase, and want to encode service
602
+ conventions.
603
+
604
+ For example, if all of your keys are underscored and all-caps, but
605
+ otherwise consistent with the names you use in your models, you
606
+ can implement across-the-board rules for how to convert an attribute
607
+ name in your model to a key in your JSON.
608
+
609
+ ```js [app/serializers/application.js]
610
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
611
+ import { underscore } from '<app-name>/utils/string-utils';
612
+
613
+ export default class ApplicationSerializer extends RESTSerializer {
614
+ keyForAttribute(attr, method) {
615
+ return underscore(attr).toUpperCase();
616
+ }
617
+ }
618
+ ```
619
+
620
+ You can also implement `keyForRelationship`, which takes the name
621
+ of the relationship as the first parameter, the kind of
622
+ relationship (`hasMany` or `belongsTo`) as the second parameter, and
623
+ the method (`serialize` or `deserialize`) as the third parameter.
624
+
625
+ @class RESTSerializer
626
+ @public
627
+ */
628
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
629
+ const RESTSerializer = JSONSerializer.extend({
630
+ /**
631
+ `keyForPolymorphicType` can be used to define a custom key when
632
+ serializing and deserializing a polymorphic type. By default, the
633
+ returned key is `${key}Type`.
634
+ Example
635
+ ```js [app/serializers/post.js]
636
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
637
+ export default class ApplicationSerializer extends RESTSerializer {
638
+ keyForPolymorphicType(key, relationship) {
639
+ let relationshipKey = this.keyForRelationship(key);
640
+ return 'type-' + relationshipKey;
641
+ }
642
+ }
643
+ ```
644
+ @public
645
+ */
646
+ keyForPolymorphicType(key, type, method) {
647
+ // @ts-expect-error
648
+ const relationshipKey = this.keyForRelationship(key);
649
+ return `${relationshipKey}Type`;
650
+ },
651
+ /**
652
+ Normalizes a part of the JSON payload returned by
653
+ the server. You should override this method, munge the hash
654
+ and call super if you have generic normalization to do.
655
+ It takes the type of the record that is being normalized
656
+ (as a Model class), the property where the hash was
657
+ originally found, and the hash to normalize.
658
+ For example, if you have a payload that looks like this:
659
+ ```js
660
+ {
661
+ "post": {
662
+ "id": 1,
663
+ "title": "Rails is omakase",
664
+ "comments": [ 1, 2 ]
665
+ },
666
+ "comments": [{
667
+ "id": 1,
668
+ "body": "FIRST"
669
+ }, {
670
+ "id": 2,
671
+ "body": "Rails is unagi"
672
+ }]
673
+ }
674
+ ```
675
+ The `normalize` method will be called three times:
676
+ * With `App.Post`, `"posts"` and `{ id: 1, title: "Rails is omakase", ... }`
677
+ * With `App.Comment`, `"comments"` and `{ id: 1, body: "FIRST" }`
678
+ * With `App.Comment`, `"comments"` and `{ id: 2, body: "Rails is unagi" }`
679
+ You can use this method, for example, to normalize underscored keys to camelized
680
+ or other general-purpose normalizations. You will only need to implement
681
+ `normalize` and manipulate the payload as desired.
682
+ For example, if the `IDs` under `"comments"` are provided as `_id` instead of
683
+ `id`, you can specify how to normalize just the comments:
684
+ ```js [app/serializers/post.js]
685
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
686
+ export default class ApplicationSerializer extends RESTSerializer {
687
+ normalize(model, hash, prop) {
688
+ if (prop === 'comments') {
689
+ hash.id = hash._id;
690
+ delete hash._id;
691
+ }
692
+ return super.normalize(...arguments);
693
+ }
694
+ }
695
+ ```
696
+ On each call to the `normalize` method, the third parameter (`prop`) is always
697
+ one of the keys that were in the original payload or in the result of another
698
+ normalization as `normalizeResponse`.
699
+ @public
700
+ @param {Model} modelClass
701
+ @param {Object} resourceHash
702
+ @param {String} prop
703
+ @return {Object}
704
+ */
705
+
706
+ /**
707
+ Normalizes an array of resource payloads and returns a JSON-API Document
708
+ with primary data and, if any, included data as `{ data, included }`.
709
+ @private
710
+ */
711
+ _normalizeArray(store, modelName, arrayHash, prop) {
712
+ const documentHash = {
713
+ data: [],
714
+ included: []
715
+ };
716
+ const modelClass = store.modelFor(modelName);
717
+ const serializer = store.serializerFor(modelName);
718
+ makeArray(arrayHash).forEach(hash => {
719
+ // @ts-expect-error
720
+ const {
721
+ data,
722
+ included
723
+ } = this._normalizePolymorphicRecord(store, hash, prop, modelClass, serializer);
724
+ // @ts-expect-error
725
+ documentHash.data.push(data);
726
+ if (included) {
727
+ documentHash.included = documentHash.included.concat(included);
728
+ }
729
+ });
730
+ return documentHash;
731
+ },
732
+ _normalizePolymorphicRecord(store, hash, prop, primaryModelClass, primarySerializer) {
733
+ let serializer = primarySerializer;
734
+ let modelClass = primaryModelClass;
735
+ const primaryHasTypeAttribute = primaryModelClass.fields.has('type');
736
+
737
+ // @ts-expect-error all the errors
738
+ if (!primaryHasTypeAttribute && hash.type) {
739
+ // Support polymorphic records in async relationships
740
+ // @ts-expect-error all the errors
741
+ const type = this.modelNameFromPayloadKey(hash.type);
742
+ if (store.schema.hasResource({
743
+ type
744
+ })) {
745
+ serializer = store.serializerFor(type);
746
+ modelClass = store.modelFor(type);
747
+ }
748
+ }
749
+
750
+ // @ts-expect-error all the errors
751
+ return serializer.normalize(modelClass, hash, prop);
752
+ },
753
+ /**
754
+ @private
755
+ */
756
+ _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
757
+ const documentHash = {
758
+ data: null,
759
+ included: []
760
+ };
761
+ // @ts-expect-error
762
+ const meta = this.extractMeta(store, primaryModelClass, payload);
763
+ if (meta) {
764
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
765
+ if (!test) {
766
+ throw new Error('The `meta` returned from `extractMeta` has to be an object, not "' + typeof meta + '".');
767
+ }
768
+ })(typeof meta === 'object') : {}; // @ts-expect-error
769
+ documentHash.meta = meta;
770
+ }
771
+ const keys = Object.keys(payload);
772
+ for (let i = 0, length = keys.length; i < length; i++) {
773
+ const prop = keys[i];
774
+ let modelName = prop;
775
+ let forcedSecondary = false;
776
+
777
+ /*
778
+ If you want to provide sideloaded records of the same type that the
779
+ primary data you can do that by prefixing the key with `_`.
780
+ Example
781
+ ```
782
+ {
783
+ users: [
784
+ { id: 1, title: 'Tom', manager: 3 },
785
+ { id: 2, title: 'Yehuda', manager: 3 }
786
+ ],
787
+ _users: [
788
+ { id: 3, title: 'Tomster' }
789
+ ]
790
+ }
791
+ ```
792
+ This forces `_users` to be added to `included` instead of `data`.
793
+ */
794
+ if (prop.charAt(0) === '_') {
795
+ forcedSecondary = true;
796
+ modelName = prop.substr(1);
797
+ }
798
+ const type = this.modelNameFromPayloadKey(modelName);
799
+ if (!store.schema.hasResource({
800
+ type
801
+ })) {
802
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
803
+ // @ts-expect-error
804
+ warn(this.warnMessageNoModelForKey(modelName, type), false, {
805
+ id: 'ds.serializer.model-for-key-missing'
806
+ });
807
+ }
808
+ continue;
809
+ }
810
+
811
+ // eslint-disable-next-line no-var
812
+ var isPrimary = !forcedSecondary && this.isPrimaryType(store, type, primaryModelClass);
813
+ const value = payload[prop];
814
+ if (value === null) {
815
+ continue;
816
+ }
817
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
818
+ if (!test) {
819
+ throw new Error('The adapter returned an array for the primary data of a `queryRecord` response. `queryRecord` should return a single record.');
820
+ }
821
+ })(!(requestType === 'queryRecord' && isPrimary && Array.isArray(value))) : {};
822
+
823
+ /*
824
+ Support primary data as an object instead of an array.
825
+ Example
826
+ ```
827
+ {
828
+ user: { id: 1, title: 'Tom', manager: 3 }
829
+ }
830
+ ```
831
+ */
832
+ if (isPrimary && !Array.isArray(value)) {
833
+ // @ts-expect-error
834
+ const {
835
+ data,
836
+ included
837
+ } = this._normalizePolymorphicRecord(store, value, prop, primaryModelClass, this);
838
+ documentHash.data = data;
839
+ if (included) {
840
+ documentHash.included = documentHash.included.concat(included);
841
+ }
842
+ continue;
843
+ }
844
+ // @ts-expect-error
845
+ const {
846
+ data,
847
+ included
848
+ } = this._normalizeArray(store, type, value, prop);
849
+ if (included) {
850
+ documentHash.included = documentHash.included.concat(included);
851
+ }
852
+ if (isSingle) {
853
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
854
+ data.forEach(resource => {
855
+ /*
856
+ Figures out if this is the primary record or not.
857
+ It's either:
858
+ 1. The record with the same ID as the original request
859
+ 2. If it's a newly created record without an ID, the first record
860
+ in the array
861
+ */
862
+ const isUpdatedRecord = isPrimary && coerceId(resource.id) === id;
863
+ const isFirstCreatedRecord = isPrimary && !id && !documentHash.data;
864
+ if (isFirstCreatedRecord || isUpdatedRecord) {
865
+ documentHash.data = resource;
866
+ } else {
867
+ // @ts-expect-error
868
+ documentHash.included.push(resource);
869
+ }
870
+ });
871
+ } else {
872
+ if (isPrimary) {
873
+ documentHash.data = data;
874
+ } else {
875
+ if (data) {
876
+ documentHash.included = documentHash.included.concat(data);
877
+ }
878
+ }
879
+ }
880
+ }
881
+ return documentHash;
882
+ },
883
+ isPrimaryType(store, modelName, primaryModelClass) {
884
+ return dasherize(modelName) === primaryModelClass.modelName;
885
+ },
886
+ /**
887
+ This method allows you to push a payload containing top-level
888
+ collections of records organized per type.
889
+ ```js
890
+ {
891
+ "posts": [{
892
+ "id": "1",
893
+ "title": "Rails is omakase",
894
+ "author", "1",
895
+ "comments": [ "1" ]
896
+ }],
897
+ "comments": [{
898
+ "id": "1",
899
+ "body": "FIRST"
900
+ }],
901
+ "users": [{
902
+ "id": "1",
903
+ "name": "@d2h"
904
+ }]
905
+ }
906
+ ```
907
+ It will first normalize the payload, so you can use this to push
908
+ in data streaming in from your server structured the same way
909
+ that fetches and saves are structured.
910
+ @public
911
+ */
912
+ pushPayload(store, payload) {
913
+ const documentHash = {
914
+ data: [],
915
+ included: []
916
+ };
917
+ for (const prop in payload) {
918
+ const type = this.modelNameFromPayloadKey(prop);
919
+ if (!store.schema.hasResource({
920
+ type
921
+ })) {
922
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
923
+ // @ts-expect-error
924
+ warn(this.warnMessageNoModelForKey(prop, type), false, {
925
+ id: 'ds.serializer.model-for-key-missing'
926
+ });
927
+ }
928
+ continue;
929
+ }
930
+ const ModelSchema = store.modelFor(type);
931
+ const typeSerializer = store.serializerFor(ModelSchema.modelName);
932
+ makeArray(payload[prop]).forEach(hash => {
933
+ const {
934
+ data,
935
+ included
936
+ } = typeSerializer.normalize(ModelSchema, hash, prop);
937
+ // @ts-expect-error
938
+ documentHash.data.push(data);
939
+ if (included) {
940
+ documentHash.included = documentHash.included.concat(included);
941
+ }
942
+ });
943
+ }
944
+ store.push(documentHash);
945
+ },
946
+ /**
947
+ This method is used to convert each JSON root key in the payload
948
+ into a modelName that it can use to look up the appropriate model for
949
+ that part of the payload.
950
+ For example, your server may send a model name that does not correspond with
951
+ the name of the model in your app. Let's take a look at an example model,
952
+ and an example payload:
953
+ ```js [app/models/post.js]
954
+ import Model from '@warp-drive/legacy/model';
955
+ export default class Post extends Model {}
956
+ ```
957
+ ```javascript
958
+ {
959
+ "blog/post": {
960
+ "id": "1
961
+ }
962
+ }
963
+ ```
964
+ Ember Data is going to normalize the payload's root key for the modelName. As a result,
965
+ it will try to look up the "blog/post" model. Since we don't have a model called "blog/post"
966
+ (or a file called app/models/blog/post.js in ember-cli), Ember Data will throw an error
967
+ because it cannot find the "blog/post" model.
968
+ Since we want to remove this namespace, we can define a serializer for the application that will
969
+ remove "blog/" from the payload key whenver it's encountered by Ember Data:
970
+ ```js [app/serializers/application.js]
971
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
972
+ export default class ApplicationSerializer extends RESTSerializer {
973
+ modelNameFromPayloadKey(payloadKey) {
974
+ if (payloadKey === 'blog/post') {
975
+ return super.modelNameFromPayloadKey(payloadKey.replace('blog/', ''));
976
+ } else {
977
+ return super.modelNameFromPayloadKey(payloadKey);
978
+ }
979
+ }
980
+ }
981
+ ```
982
+ After refreshing, Ember Data will appropriately look up the "post" model.
983
+ By default the modelName for a model is its
984
+ name in dasherized form. This means that a payload key like "blogPost" would be
985
+ normalized to "blog-post" when Ember Data looks up the model. Usually, Ember Data
986
+ can use the correct inflection to do this for you. Most of the time, you won't
987
+ need to override `modelNameFromPayloadKey` for this purpose.
988
+ @public
989
+ @return the model's modelName
990
+ */
991
+ modelNameFromPayloadKey(key) {
992
+ return dasherize(singularize(key));
993
+ },
994
+ // SERIALIZE
995
+
996
+ /**
997
+ Called when a record is saved in order to convert the
998
+ record into JSON.
999
+ By default, it creates a JSON object with a key for
1000
+ each attribute and belongsTo relationship.
1001
+ For example, consider this model:
1002
+ ```js [app/models/comment.js]
1003
+ import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
1004
+ export default class Comment extends Model {
1005
+ @attr title
1006
+ @attr body
1007
+ @belongsTo('user') author
1008
+ }
1009
+ ```
1010
+ The default serialization would create a JSON object like:
1011
+ ```js
1012
+ {
1013
+ "title": "Rails is unagi",
1014
+ "body": "Rails? Omakase? O_O",
1015
+ "author": 12
1016
+ }
1017
+ ```
1018
+ By default, attributes are passed through as-is, unless
1019
+ you specified an attribute type (`attr('date')`). If
1020
+ you specify a transform, the JavaScript value will be
1021
+ serialized when inserted into the JSON hash.
1022
+ By default, belongs-to relationships are converted into
1023
+ IDs when inserted into the JSON hash.
1024
+ ## IDs
1025
+ `serialize` takes an options hash with a single option:
1026
+ `includeId`. If this option is `true`, `serialize` will,
1027
+ by default include the ID in the JSON object it builds.
1028
+ The adapter passes in `includeId: true` when serializing
1029
+ a record for `createRecord`, but not for `updateRecord`.
1030
+ ## Customization
1031
+ Your server may expect a different JSON format than the
1032
+ built-in serialization format.
1033
+ In that case, you can implement `serialize` yourself and
1034
+ return a JSON hash of your choosing.
1035
+ ```js [app/serializers/post.js]
1036
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1037
+ export default class ApplicationSerializer extends RESTSerializer {
1038
+ serialize(snapshot, options) {
1039
+ let json = {
1040
+ POST_TTL: snapshot.attr('title'),
1041
+ POST_BDY: snapshot.attr('body'),
1042
+ POST_CMS: snapshot.hasMany('comments', { ids: true })
1043
+ };
1044
+ if (options.includeId) {
1045
+ json.POST_ID_ = snapshot.id;
1046
+ }
1047
+ return json;
1048
+ }
1049
+ }
1050
+ ```
1051
+ ## Customizing an App-Wide Serializer
1052
+ If you want to define a serializer for your entire
1053
+ application, you'll probably want to use `eachAttribute`
1054
+ and `eachRelationship` on the record.
1055
+ ```js [app/serializers/application.js]
1056
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1057
+ import { pluralize } from '<app-name>/utils/string-utils';
1058
+ export default class ApplicationSerializer extends RESTSerializer {
1059
+ serialize(snapshot, options) {
1060
+ let json = {};
1061
+ snapshot.eachAttribute(function(name) {
1062
+ json[serverAttributeName(name)] = snapshot.attr(name);
1063
+ });
1064
+ snapshot.eachRelationship(function(name, relationship) {
1065
+ if (relationship.kind === 'hasMany') {
1066
+ json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
1067
+ }
1068
+ });
1069
+ if (options.includeId) {
1070
+ json.ID_ = snapshot.id;
1071
+ }
1072
+ return json;
1073
+ }
1074
+ }
1075
+ function serverAttributeName(attribute) {
1076
+ return attribute.underscore().toUpperCase();
1077
+ }
1078
+ function serverHasManyName(name) {
1079
+ return serverAttributeName(singularize(name)) + "_IDS";
1080
+ }
1081
+ ```
1082
+ This serializer will generate JSON that looks like this:
1083
+ ```js
1084
+ {
1085
+ "TITLE": "Rails is omakase",
1086
+ "BODY": "Yep. Omakase.",
1087
+ "COMMENT_IDS": [ 1, 2, 3 ]
1088
+ }
1089
+ ```
1090
+ ## Tweaking the Default JSON
1091
+ If you just want to do some small tweaks on the default JSON,
1092
+ you can call super first and make the tweaks on the returned
1093
+ JSON.
1094
+ ```js [app/serializers/post.js]
1095
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1096
+ export default class ApplicationSerializer extends RESTSerializer {
1097
+ serialize(snapshot, options) {
1098
+ let json = super.serialize(snapshot, options);
1099
+ json.subject = json.title;
1100
+ delete json.title;
1101
+ return json;
1102
+ }
1103
+ }
1104
+ ```
1105
+ @public
1106
+ */
1107
+ serialize(snapshot, options) {
1108
+ // @ts-expect-error
1109
+ return this._super(...arguments);
1110
+ },
1111
+ /**
1112
+ You can use this method to customize the root keys serialized into the JSON.
1113
+ The hash property should be modified by reference (possibly using something like _.extend)
1114
+ By default the REST Serializer sends the modelName of a model, which is a camelized
1115
+ version of the name.
1116
+ For example, your server may expect underscored root objects.
1117
+ ```js [app/serializers/application.js]
1118
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1119
+ import { underscore } from '<app-name>/utils/string-utils';
1120
+ export default class ApplicationSerializer extends RESTSerializer {
1121
+ serializeIntoHash(data, type, record, options) {
1122
+ let root = underscore(type.modelName);
1123
+ data[root] = this.serialize(record, options);
1124
+ }
1125
+ }
1126
+ ```
1127
+ @public
1128
+ */
1129
+ serializeIntoHash(hash, typeClass, snapshot, options) {
1130
+ const normalizedRootKey = this.payloadKeyFromModelName(typeClass.modelName);
1131
+ hash[normalizedRootKey] = this.serialize(snapshot, options);
1132
+ },
1133
+ /**
1134
+ You can use `payloadKeyFromModelName` to override the root key for an outgoing
1135
+ request. By default, the RESTSerializer returns a camelized version of the
1136
+ model's name.
1137
+ For a model called TacoParty, its `modelName` would be the string `taco-party`. The RESTSerializer
1138
+ will send it to the server with `tacoParty` as the root key in the JSON payload:
1139
+ ```js
1140
+ {
1141
+ "tacoParty": {
1142
+ "id": "1",
1143
+ "location": "Matthew Beale's House"
1144
+ }
1145
+ }
1146
+ ```
1147
+ For example, your server may expect dasherized root objects:
1148
+ ```js [app/serializers/application.js]
1149
+ import { RESTSerializer } from '@warp-drive/legacy/serializer/rest';
1150
+ import { dasherize } from '<app-name>/utils/string-utils';
1151
+ export default class ApplicationSerializer extends RESTSerializer {
1152
+ payloadKeyFromModelName(modelName) {
1153
+ return dasherize(modelName);
1154
+ }
1155
+ }
1156
+ ```
1157
+ Given a `TacoParty` model, calling `save` on it would produce an outgoing
1158
+ request like:
1159
+ ```js
1160
+ {
1161
+ "taco-party": {
1162
+ "id": "1",
1163
+ "location": "Matthew Beale's House"
1164
+ }
1165
+ }
1166
+ ```
1167
+ @public
1168
+ */
1169
+ payloadKeyFromModelName(modelName) {
1170
+ return camelize(modelName);
1171
+ },
1172
+ /**
1173
+ You can use this method to customize how polymorphic objects are serialized.
1174
+ By default the REST Serializer creates the key by appending `Type` to
1175
+ the attribute and value from the model's camelcased model name.
1176
+ @public
1177
+ */
1178
+ serializePolymorphicType(snapshot, json, relationship) {
1179
+ const name = relationship.name;
1180
+ const typeKey = this.keyForPolymorphicType(name, relationship.type, 'serialize');
1181
+ const belongsTo = snapshot.belongsTo(name);
1182
+ if (!belongsTo) {
1183
+ json[typeKey] = null;
1184
+ } else {
1185
+ // @ts-expect-error
1186
+ json[typeKey] = camelize(belongsTo.modelName);
1187
+ }
1188
+ },
1189
+ /**
1190
+ You can use this method to customize how a polymorphic relationship should
1191
+ be extracted.
1192
+ @public
1193
+ @param {Object} relationshipType
1194
+ @param {Object} relationshipHash
1195
+ @param {Object} relationshipOptions
1196
+ @return {Object}
1197
+ */
1198
+ extractPolymorphicRelationship(relationshipType, relationshipHash, relationshipOptions) {
1199
+ // @ts-expect-error
1200
+ const {
1201
+ key,
1202
+ resourceHash,
1203
+ relationshipMeta
1204
+ } = relationshipOptions;
1205
+
1206
+ // A polymorphic belongsTo relationship can be present in the payload
1207
+ // either in the form where the `id` and the `type` are given:
1208
+ //
1209
+ // {
1210
+ // message: { id: 1, type: 'post' }
1211
+ // }
1212
+ //
1213
+ // or by the `id` and a `<relationship>Type` attribute:
1214
+ //
1215
+ // {
1216
+ // message: 1,
1217
+ // messageType: 'post'
1218
+ // }
1219
+ //
1220
+ // The next code checks if the latter case is present and returns the
1221
+ // corresponding JSON-API representation. The former case is handled within
1222
+ // the base class JSONSerializer.
1223
+ const isPolymorphic = relationshipMeta.options.polymorphic;
1224
+ const typeProperty = this.keyForPolymorphicType(key, relationshipType, 'deserialize');
1225
+ if (isPolymorphic && resourceHash[typeProperty] !== undefined && typeof relationshipHash !== 'object') {
1226
+ const type = this.modelNameFromPayloadKey(resourceHash[typeProperty]);
1227
+ return {
1228
+ id: coerceId(relationshipHash),
1229
+ type: type
1230
+ };
1231
+ }
1232
+ // @ts-expect-error
1233
+ return this._super(...arguments);
1234
+ }
1235
+ });
1236
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1237
+ RESTSerializer.reopen({
1238
+ warnMessageNoModelForKey(prop, typeKey) {
1239
+ return 'Encountered "' + prop + '" in payload, but no model was found for model name "' + typeKey + '" (resolved model name using ' + this.constructor.toString() + '.modelNameFromPayloadKey("' + prop + '"))';
1240
+ }
1241
+ });
1242
+ }
1243
+ export { EmbeddedRecordsMixin, RESTSerializer };