@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,1257 @@
1
+ import { getOwner } from '@ember/application';
2
+ import { warn } from '@ember/debug';
3
+ import { computed } from '@ember/object';
4
+ import { Adapter, BuildURLMixin } from '../adapter.js';
5
+ import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-BnYvPex3.js";
6
+ import { InvalidError, ServerError, ConflictError, NotFoundError, ForbiddenError, UnauthorizedError, AdapterError, TimeoutError, AbortError } from './error.js';
7
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
8
+ import { d as decorateMethodV2 } from "../runtime-BPCpkOf1-BKOwiRJp.js";
9
+
10
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
11
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
12
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
13
+
14
+ const AdapterWithBuildURLMixin = Adapter.extend(BuildURLMixin);
15
+
16
+ /**
17
+ * :::danger
18
+ ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
19
+ If starting a new app or thinking of implementing a new adapter, consider writing a
20
+ {@link Handler} instead to be used with the {@link RequestManager}
21
+ :::
22
+
23
+ The REST adapter allows your store to communicate with an HTTP server by
24
+ transmitting JSON via XHR.
25
+
26
+ This adapter is designed around the idea that the JSON exchanged with
27
+ the server should be conventional. It builds URLs in a manner that follows
28
+ the structure of most common REST-style web services.
29
+
30
+ ## Success and failure
31
+
32
+ The REST adapter will consider a success any response with a status code
33
+ of the 2xx family ("Success"), as well as 304 ("Not Modified"). Any other
34
+ status code will be considered a failure.
35
+
36
+ On success, the request promise will be resolved with the full response
37
+ payload.
38
+
39
+ Failed responses with status code 422 ("Unprocessable Entity") will be
40
+ considered "invalid". The response will be discarded, except for the
41
+ `errors` key. The request promise will be rejected with a `InvalidError`.
42
+ This error object will encapsulate the saved `errors` value.
43
+
44
+ Any other status codes will be treated as an "adapter error". The request
45
+ promise will be rejected, similarly to the "invalid" case, but with
46
+ an instance of `AdapterError` instead.
47
+
48
+ ## JSON Structure
49
+
50
+ The REST adapter expects the JSON returned from your server to follow
51
+ these conventions.
52
+
53
+ ### Object Root
54
+
55
+ The JSON payload should be an object that contains the record inside a
56
+ root property. For example, in response to a `GET` request for
57
+ `/posts/1`, the JSON should look like this:
58
+
59
+ ```js
60
+ {
61
+ "posts": {
62
+ "id": 1,
63
+ "title": "I'm Running to Reform the W3C",
64
+ "author": "Yehuda Katz"
65
+ }
66
+ }
67
+ ```
68
+
69
+ Similarly, in response to a `GET` request for `/posts`, the JSON should
70
+ look like this:
71
+
72
+ ```js
73
+ {
74
+ "posts": [
75
+ {
76
+ "id": 1,
77
+ "title": "I'm Running to Reform the W3C",
78
+ "author": "Yehuda Katz"
79
+ },
80
+ {
81
+ "id": 2,
82
+ "title": "Rails is omakase",
83
+ "author": "D2H"
84
+ }
85
+ ]
86
+ }
87
+ ```
88
+
89
+ Note that the object root can be pluralized for both a single-object response
90
+ and an array response: the REST adapter is not strict on this. Further, if the
91
+ HTTP server responds to a `GET` request to `/posts/1` (e.g. the response to a
92
+ `findRecord` query) with more than one object in the array, Ember Data will
93
+ only display the object with the matching ID.
94
+
95
+ ### Conventional Names
96
+
97
+ Attribute names in your JSON payload should be the camelCased versions of
98
+ the attributes in your Ember.js models.
99
+
100
+ For example, if you have a `Person` model:
101
+
102
+ ```js [app/models/person.js]
103
+ import { Model, attr } from '@warp-drive/legacy/model';
104
+
105
+ export default Model.extend({
106
+ firstName: attr('string'),
107
+ lastName: attr('string'),
108
+ occupation: attr('string')
109
+ });
110
+ ```
111
+
112
+ The JSON returned should look like this:
113
+
114
+ ```js
115
+ {
116
+ "people": {
117
+ "id": 5,
118
+ "firstName": "Zaphod",
119
+ "lastName": "Beeblebrox",
120
+ "occupation": "President"
121
+ }
122
+ }
123
+ ```
124
+
125
+ #### Relationships
126
+
127
+ Relationships are usually represented by ids to the record in the
128
+ relationship. The related records can then be sideloaded in the
129
+ response under a key for the type.
130
+
131
+ ```js
132
+ {
133
+ "posts": {
134
+ "id": 5,
135
+ "title": "I'm Running to Reform the W3C",
136
+ "author": "Yehuda Katz",
137
+ "comments": [1, 2]
138
+ },
139
+ "comments": [{
140
+ "id": 1,
141
+ "author": "User 1",
142
+ "message": "First!",
143
+ }, {
144
+ "id": 2,
145
+ "author": "User 2",
146
+ "message": "Good Luck!",
147
+ }]
148
+ }
149
+ ```
150
+
151
+ If the records in the relationship are not known when the response
152
+ is serialized it's also possible to represent the relationship as a
153
+ URL using the `links` key in the response. Ember Data will fetch
154
+ this URL to resolve the relationship when it is accessed for the
155
+ first time.
156
+
157
+ ```js
158
+ {
159
+ "posts": {
160
+ "id": 5,
161
+ "title": "I'm Running to Reform the W3C",
162
+ "author": "Yehuda Katz",
163
+ "links": {
164
+ "comments": "/posts/5/comments"
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ ### Errors
171
+
172
+ If a response is considered a failure, the JSON payload is expected to include
173
+ a top-level key `errors`, detailing any specific issues. For example:
174
+
175
+ ```js
176
+ {
177
+ "errors": {
178
+ "msg": "Something went wrong"
179
+ }
180
+ }
181
+ ```
182
+
183
+ This adapter does not make any assumptions as to the format of the `errors`
184
+ object. It will simply be passed along as is, wrapped in an instance
185
+ of `InvalidError` or `AdapterError`. The serializer can interpret it
186
+ afterwards.
187
+
188
+ ## Customization
189
+
190
+ ### Endpoint path customization
191
+
192
+ Endpoint paths can be prefixed with a `namespace` by setting the namespace
193
+ property on the adapter:
194
+
195
+ ```js [app/adapters/application.js]
196
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
197
+
198
+ export default class ApplicationAdapter extends RESTAdapter {
199
+ namespace = 'api/1';
200
+ }
201
+ ```
202
+ Requests for the `Person` model would now target `/api/1/people/1`.
203
+
204
+ ### Host customization
205
+
206
+ An adapter can target other hosts by setting the `host` property.
207
+
208
+ ```js [app/adapters/application.js]
209
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
210
+
211
+ export default class ApplicationAdapter extends RESTAdapter {
212
+ host = 'https://api.example.com';
213
+ }
214
+ ```
215
+
216
+ ### Headers customization
217
+
218
+ Some APIs require HTTP headers, e.g. to provide an API key. Arbitrary
219
+ headers can be set as key/value pairs on the `RESTAdapter`'s `headers`
220
+ object and WarpDrive will send them along with each ajax request.
221
+
222
+
223
+ ```js [app/adapters/application.js]
224
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
225
+
226
+ export default class ApplicationAdapter extends RESTAdapter {
227
+ get headers() {
228
+ return {
229
+ 'API_KEY': 'secret key',
230
+ 'ANOTHER_HEADER': 'Some header value'
231
+ };
232
+ }
233
+ }
234
+ ```
235
+
236
+ @class RESTAdapter
237
+ @public
238
+ @constructor
239
+ @uses BuildURLMixin
240
+ */
241
+ class RESTAdapter extends AdapterWithBuildURLMixin {
242
+ /**
243
+ This property allows ajax to still be used instead when `false`.
244
+ @property useFetch
245
+ @type {Boolean}
246
+ @default true
247
+ @public
248
+ */
249
+ useFetch = true;
250
+ _defaultContentType = 'application/json; charset=utf-8';
251
+ get fastboot() {
252
+ // Avoid computed property override deprecation in fastboot as suggested by:
253
+ // https://deprecations.emberjs.com/v3.x/#toc_computed-property-override
254
+ const fastboot = this._fastboot;
255
+ if (fastboot) {
256
+ return fastboot;
257
+ }
258
+ return this._fastboot = getOwner(this).lookup('service:fastboot');
259
+ }
260
+ static {
261
+ decorateMethodV2(this.prototype, "fastboot", [computed()]);
262
+ }
263
+ set fastboot(value) {
264
+ this._fastboot = value;
265
+ }
266
+
267
+ /**
268
+ By default, the RESTAdapter will send the query params sorted alphabetically to the
269
+ server.
270
+ For example:
271
+ ```js
272
+ store.query('posts', { sort: 'price', category: 'pets' });
273
+ ```
274
+ will generate a requests like this `/posts?category=pets&sort=price`, even if the
275
+ parameters were specified in a different order.
276
+ That way the generated URL will be deterministic and that simplifies caching mechanisms
277
+ in the backend.
278
+ Setting `sortQueryParams` to a falsey value will respect the original order.
279
+ In case you want to sort the query parameters with a different criteria, set
280
+ `sortQueryParams` to your custom sort function.
281
+ ```js [app/adapters/application.js]
282
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
283
+ export default class ApplicationAdapter extends RESTAdapter {
284
+ sortQueryParams(params) {
285
+ let sortedKeys = Object.keys(params).sort().reverse();
286
+ let len = sortedKeys.length, newParams = {};
287
+ for (let i = 0; i < len; i++) {
288
+ newParams[sortedKeys[i]] = params[sortedKeys[i]];
289
+ }
290
+ return newParams;
291
+ }
292
+ }
293
+ ```
294
+ @param {Object} obj
295
+ @return {Object}
296
+ @public
297
+ */
298
+ sortQueryParams(obj) {
299
+ const keys = Object.keys(obj);
300
+ const len = keys.length;
301
+ if (len < 2) {
302
+ return obj;
303
+ }
304
+ const newQueryParams = {};
305
+ const sortedKeys = keys.sort();
306
+ for (let i = 0; i < len; i++) {
307
+ newQueryParams[sortedKeys[i]] = obj[sortedKeys[i]];
308
+ }
309
+ return newQueryParams;
310
+ }
311
+
312
+ /**
313
+ By default the RESTAdapter will send each find request coming from a `store.find`
314
+ or from accessing a relationship separately to the server. If your server supports passing
315
+ ids as a query string, you can set coalesceFindRequests to true to coalesce all find requests
316
+ within a single runloop.
317
+ For example, if you have an initial payload of:
318
+ ```javascript
319
+ {
320
+ post: {
321
+ id: 1,
322
+ comments: [1, 2]
323
+ }
324
+ }
325
+ ```
326
+ By default calling `post.comments` will trigger the following requests(assuming the
327
+ comments haven't been loaded before):
328
+ ```
329
+ GET /comments/1
330
+ GET /comments/2
331
+ ```
332
+ If you set coalesceFindRequests to `true` it will instead trigger the following request:
333
+ ```
334
+ GET /comments?ids[]=1&ids[]=2
335
+ ```
336
+ Setting coalesceFindRequests to `true` also works for `store.find` requests and `belongsTo`
337
+ relationships accessed within the same runloop. If you set `coalesceFindRequests: true`
338
+ ```javascript
339
+ store.findRecord('comment', 1);
340
+ store.findRecord('comment', 2);
341
+ ```
342
+ will also send a request to: `GET /comments?ids[]=1&ids[]=2`
343
+ Note: Requests coalescing rely on URL building strategy. So if you override `buildURL` in your app
344
+ `groupRecordsForFindMany` more likely should be overridden as well in order for coalescing to work.
345
+ @property coalesceFindRequests
346
+ @public
347
+ @type {Boolean}
348
+ */
349
+ get coalesceFindRequests() {
350
+ const coalesceFindRequests = this._coalesceFindRequests;
351
+ if (typeof coalesceFindRequests === 'boolean') {
352
+ return coalesceFindRequests;
353
+ }
354
+ return this._coalesceFindRequests = false;
355
+ }
356
+ set coalesceFindRequests(value) {
357
+ this._coalesceFindRequests = value;
358
+ }
359
+
360
+ /**
361
+ Endpoint paths can be prefixed with a `namespace` by setting the namespace
362
+ property on the adapter:
363
+ ```js [app/adapters/application.js]
364
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
365
+ export default class ApplicationAdapter extends RESTAdapter {
366
+ namespace = 'api/1';
367
+ }
368
+ ```
369
+ Requests for the `Post` model would now target `/api/1/post/`.
370
+ @property namespace
371
+ @public
372
+ @type {String}
373
+ */
374
+
375
+ /**
376
+ An adapter can target other hosts by setting the `host` property.
377
+ ```js [app/adapters/application.js]
378
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
379
+ export default class ApplicationAdapter extends RESTAdapter {
380
+ host = 'https://api.example.com';
381
+ }
382
+ ```
383
+ Requests for the `Post` model would now target `https://api.example.com/post/`.
384
+ @property host
385
+ @public
386
+ @type {String}
387
+ */
388
+
389
+ /**
390
+ Some APIs require HTTP headers, e.g. to provide an API
391
+ key. Arbitrary headers can be set as key/value pairs on the
392
+ `RESTAdapter`'s `headers` object and Ember Data will send them
393
+ along with each ajax request..
394
+ ```js [app/adapters/application.js]
395
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
396
+ export default class ApplicationAdapter extends RESTAdapter {
397
+ get headers() {
398
+ return {
399
+ 'API_KEY': 'secret key',
400
+ 'ANOTHER_HEADER': 'Some header value'
401
+ };
402
+ }
403
+ }
404
+ ```
405
+ @property headers
406
+ @public
407
+ @type {Object}
408
+ */
409
+
410
+ /**
411
+ Called by the store in order to fetch the JSON for a given
412
+ type and ID.
413
+ The `findRecord` method makes an Ajax request to a URL computed by
414
+ `buildURL`, and returns a promise for the resulting payload.
415
+ This method performs an HTTP `GET` request with the id provided as part of the query string.
416
+ @since 1.13.0
417
+ @public
418
+ @param {Store} store
419
+ @param {Model} type
420
+ @param {String} id
421
+ @param {Snapshot} snapshot
422
+ @return {Promise} promise
423
+ */
424
+ findRecord(store, type, id, snapshot) {
425
+ const url = this.buildURL(type.modelName, id, snapshot, 'findRecord');
426
+ const query = this.buildQuery(snapshot);
427
+ return this.ajax(url, 'GET', {
428
+ data: query
429
+ });
430
+ }
431
+
432
+ /**
433
+ Called by the store in order to fetch a JSON array for all
434
+ of the records for a given type.
435
+ The `findAll` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
436
+ promise for the resulting payload.
437
+ @public
438
+ @param {Store} store
439
+ @param {Model} type
440
+ @param {undefined} neverSet a value is never provided to this argument
441
+ @param {SnapshotRecordArray} snapshotRecordArray
442
+ @return {Promise} promise
443
+ */
444
+ findAll(store, type, sinceToken, snapshotRecordArray) {
445
+ const query = this.buildQuery(snapshotRecordArray);
446
+ const url = this.buildURL(type.modelName, null, snapshotRecordArray, 'findAll');
447
+ if (sinceToken) {
448
+ query.since = sinceToken;
449
+ }
450
+ return this.ajax(url, 'GET', {
451
+ data: query
452
+ });
453
+ }
454
+
455
+ /**
456
+ Called by the store in order to fetch a JSON array for
457
+ the records that match a particular query.
458
+ The `query` method makes an Ajax (HTTP GET) request to a URL
459
+ computed by `buildURL`, and returns a promise for the resulting
460
+ payload.
461
+ The `query` argument is a simple JavaScript object that will be passed directly
462
+ to the server as parameters.
463
+ @public
464
+ @param {Store} store
465
+ @param {Model} type
466
+ @param {Object} query
467
+ @param {Collection} recordArray
468
+ @param {Object} adapterOptions
469
+ @return {Promise} promise
470
+ */
471
+ query(store, type, query) {
472
+ const url = this.buildURL(type.modelName, null, null, 'query', query);
473
+ if (this.sortQueryParams) {
474
+ query = this.sortQueryParams(query);
475
+ }
476
+ return this.ajax(url, 'GET', {
477
+ data: query
478
+ });
479
+ }
480
+
481
+ /**
482
+ Called by the store in order to fetch a JSON object for
483
+ the record that matches a particular query.
484
+ The `queryRecord` method makes an Ajax (HTTP GET) request to a URL
485
+ computed by `buildURL`, and returns a promise for the resulting
486
+ payload.
487
+ The `query` argument is a simple JavaScript object that will be passed directly
488
+ to the server as parameters.
489
+ @since 1.13.0
490
+ @public
491
+ @param {Store} store
492
+ @param {Model} type
493
+ @param {Object} query
494
+ @param {Object} adapterOptions
495
+ @return {Promise} promise
496
+ */
497
+ queryRecord(store, type, query, adapterOptions) {
498
+ const url = this.buildURL(type.modelName, null, null, 'queryRecord', query);
499
+ if (this.sortQueryParams) {
500
+ query = this.sortQueryParams(query);
501
+ }
502
+ return this.ajax(url, 'GET', {
503
+ data: query
504
+ });
505
+ }
506
+
507
+ /**
508
+ Called by the store in order to fetch several records together if `coalesceFindRequests` is true
509
+ For example, if the original payload looks like:
510
+ ```js
511
+ {
512
+ "id": 1,
513
+ "title": "Rails is omakase",
514
+ "comments": [ 1, 2, 3 ]
515
+ }
516
+ ```
517
+ The IDs will be passed as a URL-encoded Array of IDs, in this form:
518
+ ```
519
+ ids[]=1&ids[]=2&ids[]=3
520
+ ```
521
+ Many servers, such as Rails and PHP, will automatically convert this URL-encoded array
522
+ into an Array for you on the server-side. If you want to encode the
523
+ IDs, differently, just override this (one-line) method.
524
+ The `findMany` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
525
+ promise for the resulting payload.
526
+ @public
527
+ @param {Store} store
528
+ @param {Model} type
529
+ @param {Array} ids
530
+ @param {Array} snapshots
531
+ @return {Promise} promise
532
+ */
533
+ findMany(store, type, ids, snapshots) {
534
+ const url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
535
+ return this.ajax(url, 'GET', {
536
+ data: {
537
+ ids: ids
538
+ }
539
+ });
540
+ }
541
+
542
+ /**
543
+ Called by the store in order to fetch a JSON array for
544
+ the unloaded records in a has-many relationship that were originally
545
+ specified as a URL (inside of `links`).
546
+ For example, if your original payload looks like this:
547
+ ```js
548
+ {
549
+ "post": {
550
+ "id": 1,
551
+ "title": "Rails is omakase",
552
+ "links": { "comments": "/posts/1/comments" }
553
+ }
554
+ }
555
+ ```
556
+ This method will be called with the parent record and `/posts/1/comments`.
557
+ The `findHasMany` method will make an Ajax (HTTP GET) request to the originally specified URL.
558
+ The format of your `links` value will influence the final request URL via the `urlPrefix` method:
559
+ * Links beginning with `//`, `http://`, `https://`, will be used as is, with no further manipulation.
560
+ * Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
561
+ * Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
562
+ @public
563
+ @param {Store} store
564
+ @param {Snapshot} snapshot
565
+ @param {String} url
566
+ @param {Object} relationship meta object describing the relationship
567
+ @return {Promise} promise
568
+ */
569
+ findHasMany(store, snapshot, url, relationship) {
570
+ const id = snapshot.id;
571
+ const type = snapshot.modelName;
572
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
573
+ if (!test) {
574
+ throw new Error(`Attempted to fetch the hasMany relationship for ${type}, but the record has no id`);
575
+ }
576
+ })(typeof id === 'string' && id.length > 0) : {};
577
+ url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findHasMany'));
578
+ return this.ajax(url, 'GET');
579
+ }
580
+
581
+ /**
582
+ Called by the store in order to fetch the JSON for the unloaded record in a
583
+ belongs-to relationship that was originally specified as a URL (inside of
584
+ `links`).
585
+ For example, if your original payload looks like this:
586
+ ```js
587
+ {
588
+ "person": {
589
+ "id": 1,
590
+ "name": "Tom Dale",
591
+ "links": { "group": "/people/1/group" }
592
+ }
593
+ }
594
+ ```
595
+ This method will be called with the parent record and `/people/1/group`.
596
+ The `findBelongsTo` method will make an Ajax (HTTP GET) request to the originally specified URL.
597
+ The format of your `links` value will influence the final request URL via the `urlPrefix` method:
598
+ * Links beginning with `//`, `http://`, `https://`, will be used as is, with no further manipulation.
599
+ * Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
600
+ * Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
601
+ @public
602
+ */
603
+ findBelongsTo(store, snapshot, url, relationship) {
604
+ const id = snapshot.id;
605
+ const type = snapshot.modelName;
606
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
607
+ if (!test) {
608
+ throw new Error(`Attempted to fetch the belongsTo relationship for ${type}, but the record has no id`);
609
+ }
610
+ })(typeof id === 'string' && id.length > 0) : {};
611
+ url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findBelongsTo'));
612
+ return this.ajax(url, 'GET');
613
+ }
614
+
615
+ /**
616
+ Called by the store when a newly created record is
617
+ saved via the `save` method on a model record instance.
618
+ The `createRecord` method serializes the record and makes an Ajax (HTTP POST) request
619
+ to a URL computed by `buildURL`.
620
+ See `serialize` for information on how to customize the serialized form
621
+ of a record.
622
+ @public
623
+ @param {Store} store
624
+ @param {Model} type
625
+ @param {Snapshot} snapshot
626
+ @return {Promise} promise
627
+ */
628
+ createRecord(store, type, snapshot) {
629
+ const url = this.buildURL(type.modelName, null, snapshot, 'createRecord');
630
+ const data = serializeIntoHash(store, type, snapshot);
631
+ return this.ajax(url, 'POST', {
632
+ data
633
+ });
634
+ }
635
+
636
+ /**
637
+ Called by the store when an existing record is saved
638
+ via the `save` method on a model record instance.
639
+ The `updateRecord` method serializes the record and makes an Ajax (HTTP PUT) request
640
+ to a URL computed by `buildURL`.
641
+ See `serialize` for information on how to customize the serialized form
642
+ of a record.
643
+ @public
644
+ @param {Store} store
645
+ @param {Model} schema
646
+ @param {Snapshot} snapshot
647
+ @return {Promise} promise
648
+ */
649
+ updateRecord(store, schema, snapshot) {
650
+ const data = serializeIntoHash(store, schema, snapshot, {});
651
+ const type = snapshot.modelName;
652
+ const id = snapshot.id;
653
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
654
+ if (!test) {
655
+ throw new Error(`Attempted to update the ${type} record, but the record has no id`);
656
+ }
657
+ })(typeof id === 'string' && id.length > 0) : {};
658
+ const url = this.buildURL(type, id, snapshot, 'updateRecord');
659
+ return this.ajax(url, 'PUT', {
660
+ data
661
+ });
662
+ }
663
+
664
+ /**
665
+ Called by the store when a record is deleted.
666
+ The `deleteRecord` method makes an Ajax (HTTP DELETE) request to a URL computed by `buildURL`.
667
+ @public
668
+ @param {Store} store
669
+ @param {Model} type
670
+ @param {Snapshot} snapshot
671
+ @return {Promise} promise
672
+ */
673
+ deleteRecord(store, schema, snapshot) {
674
+ const type = snapshot.modelName;
675
+ const id = snapshot.id;
676
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
677
+ if (!test) {
678
+ throw new Error(`Attempted to delete the ${type} record, but the record has no id`);
679
+ }
680
+ })(typeof id === 'string' && id.length > 0) : {};
681
+ return this.ajax(this.buildURL(type, id, snapshot, 'deleteRecord'), 'DELETE');
682
+ }
683
+ _stripIDFromURL(store, snapshot) {
684
+ const type = snapshot.modelName;
685
+ const id = snapshot.id;
686
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
687
+ if (!test) {
688
+ throw new Error(`Attempted to strip the url from the ${type} record for coalescing, but the record has no id`);
689
+ }
690
+ })(typeof id === 'string' && id.length > 0) : {};
691
+ const url = this.buildURL(type, id, snapshot);
692
+ const expandedURL = url.split('/');
693
+ // Case when the url is of the format ...something/:id
694
+ // We are decodeURIComponent-ing the lastSegment because if it represents
695
+ // the id, it has been encodeURIComponent-ified within `buildURL`. If we
696
+ // don't do this, then records with id having special characters are not
697
+ // coalesced correctly (see GH #4190 for the reported bug)
698
+ const lastSegment = expandedURL[expandedURL.length - 1];
699
+ if (decodeURIComponent(lastSegment) === id) {
700
+ expandedURL[expandedURL.length - 1] = '';
701
+ } else if (id && endsWith(lastSegment, '?id=' + id)) {
702
+ //Case when the url is of the format ...something?id=:id
703
+ expandedURL[expandedURL.length - 1] = lastSegment.substring(0, lastSegment.length - id.length - 1);
704
+ }
705
+ return expandedURL.join('/');
706
+ }
707
+
708
+ // http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
709
+ maxURLLength = 2048;
710
+
711
+ /**
712
+ Organize records into groups, each of which is to be passed to separate
713
+ calls to `findMany`.
714
+ This implementation groups together records that have the same base URL but
715
+ differing ids. For example `/comments/1` and `/comments/2` will be grouped together
716
+ because we know findMany can coalesce them together as `/comments?ids[]=1&ids[]=2`
717
+ It also supports urls where ids are passed as a query param, such as `/comments?id=1`
718
+ but not those where there is more than 1 query param such as `/comments?id=2&name=David`
719
+ Currently only the query param of `id` is supported. If you need to support others, please
720
+ override this or the `_stripIDFromURL` method.
721
+ It does not group records that have differing base urls, such as for example: `/posts/1/comments/2`
722
+ and `/posts/2/comments/3`
723
+ @public
724
+ @param {Store} store
725
+ @param {Array} snapshots
726
+ @return {Array} an array of arrays of records, each of which is to be
727
+ loaded separately by `findMany`.
728
+ */
729
+ groupRecordsForFindMany(store, snapshots) {
730
+ const groups = new Map();
731
+ const maxURLLength = this.maxURLLength;
732
+ snapshots.forEach(snapshot => {
733
+ const baseUrl = this._stripIDFromURL(store, snapshot);
734
+ if (!groups.has(baseUrl)) {
735
+ groups.set(baseUrl, []);
736
+ }
737
+ groups.get(baseUrl).push(snapshot);
738
+ });
739
+ const groupsArray = [];
740
+ groups.forEach((group, key) => {
741
+ const paramNameLength = '&ids%5B%5D='.length;
742
+ const splitGroups = splitGroupToFitInUrl(store, this, group, maxURLLength, paramNameLength);
743
+ splitGroups.forEach(splitGroup => groupsArray.push(splitGroup));
744
+ });
745
+ return groupsArray;
746
+ }
747
+
748
+ /**
749
+ Takes an ajax response, and returns the json payload or an error.
750
+ By default this hook just returns the json payload passed to it.
751
+ You might want to override it in two cases:
752
+ 1. Your API might return useful results in the response headers.
753
+ Response headers are passed in as the second argument.
754
+ 2. Your API might return errors as successful responses with status code
755
+ 200 and an Errors text or object. You can return a `InvalidError` or a
756
+ `AdapterError` (or a sub class) from this hook and it will automatically
757
+ reject the promise and put your record into the invalid or error state.
758
+ Returning a `InvalidError` from this method will cause the
759
+ record to transition into the `invalid` state and make the
760
+ `errors` object available on the record. When returning an
761
+ `InvalidError` the store will attempt to normalize the error data
762
+ returned from the server using the serializer's `extractErrors`
763
+ method.
764
+ @since 1.13.0
765
+ @public
766
+ @param {Number} status
767
+ @param {Object} headers
768
+ @param {Object} payload
769
+ @param {Object} requestData - the original request information
770
+ @return {Object | AdapterError} response
771
+ */
772
+ handleResponse(status, headers, payload, requestData) {
773
+ if (this.isSuccess(status, headers, payload)) {
774
+ return payload;
775
+ } else if (this.isInvalid(status, headers, payload)) {
776
+ // @ts-expect-error needs cast to ApiError
777
+ return new InvalidError(typeof payload === 'object' && 'errors' in payload ? payload.errors : undefined);
778
+ }
779
+ const errors = this.normalizeErrorResponse(status, headers, payload);
780
+ const detailedMessage = this.generatedDetailedMessage(status, headers, payload, requestData);
781
+ switch (status) {
782
+ case 401:
783
+ return new UnauthorizedError(errors, detailedMessage);
784
+ case 403:
785
+ return new ForbiddenError(errors, detailedMessage);
786
+ case 404:
787
+ return new NotFoundError(errors, detailedMessage);
788
+ case 409:
789
+ return new ConflictError(errors, detailedMessage);
790
+ default:
791
+ if (status >= 500) {
792
+ return new ServerError(errors, detailedMessage);
793
+ }
794
+ }
795
+ return new AdapterError(errors, detailedMessage);
796
+ }
797
+
798
+ /**
799
+ Default `handleResponse` implementation uses this hook to decide if the
800
+ response is a success.
801
+ @since 1.13.0
802
+ @public
803
+ @param {Number} status
804
+ @param {Object} headers
805
+ @param {Object} payload
806
+ @return {Boolean}
807
+ */
808
+ isSuccess(status, _headers, _payload) {
809
+ return status >= 200 && status < 300 || status === 304;
810
+ }
811
+
812
+ /**
813
+ Default `handleResponse` implementation uses this hook to decide if the
814
+ response is an invalid error.
815
+ @since 1.13.0
816
+ @public
817
+ @param {Number} status
818
+ @param {Object} headers
819
+ @param {Object} payload
820
+ @return {Boolean}
821
+ */
822
+ isInvalid(status, _headers, _payload) {
823
+ return status === 422;
824
+ }
825
+
826
+ /**
827
+ Takes a URL, an HTTP method and a hash of data, and makes an
828
+ HTTP request.
829
+ When the server responds with a payload, Ember Data will call into `extractSingle`
830
+ or `extractArray` (depending on whether the original query was for one record or
831
+ many records).
832
+ By default, `ajax` method has the following behavior:
833
+ * It sets the response `dataType` to `"json"`
834
+ * If the HTTP method is not `"GET"`, it sets the `Content-Type` to be
835
+ `application/json; charset=utf-8`
836
+ * If the HTTP method is not `"GET"`, it stringifies the data passed in. The
837
+ data is the serialized record in the case of a save.
838
+ * Registers success and failure handlers.
839
+ @private
840
+ @param {String} url
841
+ @param {String} type The request type GET, POST, PUT, DELETE etc.
842
+ @param {Object} options
843
+ @return {Promise} promise
844
+ */
845
+ async ajax(url, type, options = {}) {
846
+ const requestData = {
847
+ url: url,
848
+ method: type
849
+ };
850
+ if (this.useFetch) {
851
+ // @ts-expect-error poorly typed
852
+ const hash = this.ajaxOptions(url, type, options);
853
+ const response = await this._fetchRequest(hash);
854
+ const payload = await determineBodyPromise(response, requestData);
855
+ if (response.ok && !(payload instanceof Error)) {
856
+ return fetchSuccessHandler(this, payload, response, requestData);
857
+ } else {
858
+ // eslint-disable-next-line @typescript-eslint/only-throw-error
859
+ throw fetchErrorHandler(this, payload, response, null, requestData);
860
+ }
861
+ } else {
862
+ return execjQAjax(this, requestData, options);
863
+ }
864
+ }
865
+
866
+ /**
867
+ @private
868
+ @param {Object} options jQuery ajax options to be used for the ajax request
869
+ */
870
+ _ajaxRequest(options) {
871
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
872
+ if (!test) {
873
+ throw new Error('You must install jQuery globally when `useFetch` is false');
874
+ }
875
+ })(typeof jQuery !== 'undefined') : {};
876
+ void jQuery.ajax(options);
877
+ }
878
+ _fetchRequest(options) {
879
+ const fetchFunction = getFetchFunction();
880
+ return fetchFunction(options.url, options);
881
+ }
882
+ _ajax(options) {
883
+ if (this.useFetch) {
884
+ void this._fetchRequest(options);
885
+ } else {
886
+ this._ajaxRequest(options);
887
+ }
888
+ }
889
+
890
+ /**
891
+ @private
892
+ @param {String} url
893
+ @param {String} type The request type GET, POST, PUT, DELETE etc.
894
+ @param {Object} options
895
+ @return {Object}
896
+ */
897
+ ajaxOptions(url, method, options) {
898
+ let reqOptions = Object.assign({
899
+ url,
900
+ method,
901
+ type: method
902
+ }, options);
903
+ if (this.headers !== undefined) {
904
+ // @ts-expect-error poorly typed
905
+ reqOptions.headers = {
906
+ ...this.headers,
907
+ ...reqOptions.headers
908
+ };
909
+ } else if (!options.headers) {
910
+ reqOptions.headers = {};
911
+ }
912
+
913
+ // @ts-expect-error poorly typed
914
+ const contentType = reqOptions.contentType || this._defaultContentType;
915
+ if (this.useFetch) {
916
+ // @ts-expect-error poorly typed
917
+ if (reqOptions.data && reqOptions.type !== 'GET' && reqOptions.headers) {
918
+ if (!reqOptions.headers['Content-Type'] && !reqOptions.headers['content-type']) {
919
+ reqOptions.headers['content-type'] = contentType;
920
+ }
921
+ }
922
+ // @ts-expect-error poorly typed
923
+ reqOptions = fetchOptions(reqOptions);
924
+ } else {
925
+ // GET requests without a body should not have a content-type header
926
+ // and may be unexpected by a server
927
+ // @ts-expect-error poorly typed
928
+ if (reqOptions.data && reqOptions.type !== 'GET') {
929
+ reqOptions = {
930
+ ...reqOptions,
931
+ contentType
932
+ };
933
+ }
934
+ // @ts-expect-error poorly typed
935
+ reqOptions = ajaxOptions(reqOptions, this);
936
+ }
937
+ reqOptions.url = this._ajaxURL(reqOptions.url);
938
+ return reqOptions;
939
+ }
940
+ _ajaxURL(url) {
941
+ if (this.fastboot?.isFastBoot) {
942
+ const httpRegex = /^https?:\/\//;
943
+ const protocolRelativeRegex = /^\/\//;
944
+ const protocol = this.fastboot.request.protocol;
945
+ const host = this.fastboot.request.host;
946
+ if (protocolRelativeRegex.test(url)) {
947
+ return `${protocol}${url}`;
948
+ } else if (!httpRegex.test(url)) {
949
+ try {
950
+ return `${protocol}//${host}${url}`;
951
+ } catch (fbError) {
952
+ throw new Error('You are using Ember Data with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostWhitelist property for in your environment.js. FastBoot Error: ' + fbError.message);
953
+ }
954
+ }
955
+ }
956
+ return url;
957
+ }
958
+
959
+ /**
960
+ @private
961
+ @param {String} responseText
962
+ @return {Object}
963
+ */
964
+ parseErrorResponse(responseText) {
965
+ let json = responseText;
966
+ try {
967
+ json = JSON.parse(responseText);
968
+ } catch {
969
+ // ignored
970
+ }
971
+ return json;
972
+ }
973
+
974
+ /**
975
+ @private
976
+ @param {Number} status
977
+ @param {Object} headers
978
+ @param {Object} payload
979
+ @return {Array} errors payload
980
+ */
981
+ normalizeErrorResponse(status, _headers, payload) {
982
+ if (payload && typeof payload === 'object' && 'errors' in payload && Array.isArray(payload.errors)) {
983
+ return payload.errors;
984
+ } else {
985
+ return [{
986
+ status: `${status}`,
987
+ // Set to a string per the JSON API spec: https://jsonapi.org/format/#errors
988
+ title: 'The backend responded with an error',
989
+ // Detail is intended to be a string, but backends be non-compliant.
990
+ // stringifying gives the user a more friendly error in this situation, whereas
991
+ // they'd instead receive [object Object].
992
+ // JSON.stringify will convert *anything* to a string without erroring.
993
+ detail: typeof payload === 'string' ? payload : JSON.stringify(payload)
994
+ }];
995
+ }
996
+ }
997
+
998
+ /**
999
+ Generates a detailed ("friendly") error message, with plenty
1000
+ of information for debugging (good luck!)
1001
+ @private
1002
+ @param {Number} status
1003
+ @param {Object} headers
1004
+ @param {Object} payload
1005
+ @param {Object} requestData
1006
+ @return {String} detailed error message
1007
+ */
1008
+ generatedDetailedMessage(status, headers, payload, requestData) {
1009
+ let shortenedPayload;
1010
+ const payloadContentType = headers['content-type'] || 'Empty Content-Type';
1011
+ if (payloadContentType === 'text/html' && typeof payload === 'string' && payload.length > 250) {
1012
+ shortenedPayload = '[Omitted Lengthy HTML]';
1013
+ } else if (typeof payload === 'object' && payload !== null) {
1014
+ shortenedPayload = JSON.stringify(payload, null, 2);
1015
+ } else {
1016
+ shortenedPayload = payload;
1017
+ }
1018
+ const requestDescription = requestData.method + ' ' + requestData.url;
1019
+ const payloadDescription = 'Payload (' + payloadContentType + ')';
1020
+ return ['Ember Data Request ' + requestDescription + ' returned a ' + status, payloadDescription, shortenedPayload].join('\n');
1021
+ }
1022
+
1023
+ /**
1024
+ Used by `findAll` and `findRecord` to build the query's `data` hash
1025
+ supplied to the ajax method.
1026
+ @since 2.5.0
1027
+ @public
1028
+ @param {Snapshot} snapshot
1029
+ @return {Object}
1030
+ */
1031
+ buildQuery(snapshot) {
1032
+ const query = {};
1033
+ if (snapshot) {
1034
+ const {
1035
+ include
1036
+ } = snapshot;
1037
+ if (include) {
1038
+ // note: if user passed in an array, this will serialize like `?include[]=foo&include[]=bar`
1039
+ // but if user passed in a string, this will serialize like `?include=foo,bar`
1040
+ // users that want consistent behavior should override this method
1041
+ query.include = include;
1042
+ }
1043
+ }
1044
+ return query;
1045
+ }
1046
+ }
1047
+
1048
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
1049
+
1050
+ function ajaxSuccess(adapter, payload, requestData, responseData) {
1051
+ let response;
1052
+ try {
1053
+ response = adapter.handleResponse(responseData.status, responseData.headers, payload, requestData);
1054
+ } catch (error) {
1055
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
1056
+ return Promise.reject(error);
1057
+ }
1058
+ if (response && response.isAdapterError) {
1059
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
1060
+ return Promise.reject(response);
1061
+ } else {
1062
+ return response;
1063
+ }
1064
+ }
1065
+ function ajaxError(adapter, payload, requestData, responseData) {
1066
+ let error;
1067
+ if (responseData.errorThrown instanceof Error && payload !== '') {
1068
+ error = responseData.errorThrown;
1069
+ } else if (responseData.textStatus === 'timeout') {
1070
+ error = new TimeoutError();
1071
+ } else if (responseData.textStatus === 'abort' || responseData.status === 0) {
1072
+ error = handleAbort(requestData, responseData);
1073
+ } else {
1074
+ try {
1075
+ error = adapter.handleResponse(responseData.status, responseData.headers, payload || responseData.errorThrown, requestData);
1076
+ } catch (e) {
1077
+ error = e;
1078
+ }
1079
+ }
1080
+ return error;
1081
+ }
1082
+
1083
+ // Adapter abort error to include any relevent info, e.g. request/response:
1084
+ function handleAbort(requestData, responseData) {
1085
+ const {
1086
+ method,
1087
+ url,
1088
+ errorThrown
1089
+ } = requestData;
1090
+ const {
1091
+ status
1092
+ } = responseData;
1093
+ const msg = `Request failed: ${method} ${url} ${String(errorThrown ?? '')}`;
1094
+ const errors = [{
1095
+ title: 'Adapter Error',
1096
+ detail: msg.trim(),
1097
+ status
1098
+ }];
1099
+ return new AbortError(errors);
1100
+ }
1101
+
1102
+ //From http://stackoverflow.com/questions/280634/endswith-in-javascript
1103
+ function endsWith(string, suffix) {
1104
+ if (typeof String.prototype.endsWith !== 'function') {
1105
+ return string.includes(suffix, string.length - suffix.length);
1106
+ } else {
1107
+ return string.endsWith(suffix);
1108
+ }
1109
+ }
1110
+ function fetchSuccessHandler(adapter, payload, response, requestData) {
1111
+ const responseData = fetchResponseData(response);
1112
+ return ajaxSuccess(adapter, payload, requestData, responseData);
1113
+ }
1114
+ function fetchErrorHandler(adapter, payload, response, errorThrown, requestData) {
1115
+ const responseData = fetchResponseData(response);
1116
+ if (responseData.status === 200 && payload instanceof Error) {
1117
+ responseData.errorThrown = payload;
1118
+ // @ts-expect-error poorly typed
1119
+ payload = responseData.errorThrown.payload;
1120
+ } else {
1121
+ responseData.errorThrown = errorThrown;
1122
+ if (typeof payload === 'string') {
1123
+ payload = adapter.parseErrorResponse(payload);
1124
+ }
1125
+ }
1126
+ return ajaxError(adapter, payload, requestData, responseData);
1127
+ }
1128
+ function ajaxSuccessHandler(adapter, payload, jqXHR, requestData) {
1129
+ const responseData = ajaxResponseData(jqXHR);
1130
+ return ajaxSuccess(adapter, payload, requestData, responseData);
1131
+ }
1132
+ function ajaxErrorHandler(adapter, jqXHR, errorThrown, requestData) {
1133
+ const responseData = ajaxResponseData(jqXHR);
1134
+ responseData.errorThrown = errorThrown;
1135
+ const payload = adapter.parseErrorResponse(jqXHR.responseText);
1136
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1137
+ const message = `The server returned an empty string for ${requestData.method} ${requestData.url}, which cannot be parsed into a valid JSON. Return either null or {}.`;
1138
+ const validJSONString = !(responseData.textStatus === 'parsererror' && payload === '');
1139
+ warn(message, validJSONString, {
1140
+ id: 'ds.adapter.returned-empty-string-as-JSON'
1141
+ });
1142
+ }
1143
+ return ajaxError(adapter, payload, requestData, responseData);
1144
+ }
1145
+ function fetchResponseData(response) {
1146
+ return {
1147
+ status: response.status,
1148
+ textStatus: response.statusText,
1149
+ headers: headersToObject(response.headers)
1150
+ };
1151
+ }
1152
+ function ajaxResponseData(jqXHR) {
1153
+ return {
1154
+ status: jqXHR.status,
1155
+ textStatus: jqXHR.statusText,
1156
+ headers: parseResponseHeaders(jqXHR.getAllResponseHeaders())
1157
+ };
1158
+ }
1159
+ function headersToObject(headers) {
1160
+ const headersObject = {};
1161
+ if (headers) {
1162
+ headers.forEach((value, key) => headersObject[key] = value);
1163
+ }
1164
+ return headersObject;
1165
+ }
1166
+
1167
+ /**
1168
+ * Helper function that translates the options passed to `jQuery.ajax` into a format that `fetch` expects.
1169
+ *
1170
+ * @param {Object} _options
1171
+ * @param {Adapter} adapter
1172
+ * @private
1173
+ * @return {Object}
1174
+ */
1175
+ function fetchOptions(options, adapter) {
1176
+ options.credentials = options.credentials || 'same-origin';
1177
+ if (options.data) {
1178
+ // GET and HEAD requests can't have a `body`
1179
+ if (options.method === 'GET' || options.method === 'HEAD') {
1180
+ // If no options are passed, Ember Data sets `data` to an empty object, which we test for.
1181
+ if (Object.keys(options.data).length && options.url) {
1182
+ // Test if there are already query params in the url (mimics jQuey.ajax).
1183
+ const queryParamDelimiter = options.url.includes('?') ? '&' : '?';
1184
+ options.url += `${queryParamDelimiter}${serializeQueryParams(options.data)}`;
1185
+ }
1186
+ } else {
1187
+ // NOTE: a request's body cannot be an object, so we stringify it if it is.
1188
+ // JSON.stringify removes keys with values of `undefined` (mimics jQuery.ajax).
1189
+ // If the data is not a POJO (it's a String, FormData, etc), we just set it.
1190
+ // If the data is a string, we assume it's a stringified object.
1191
+
1192
+ /* We check for Objects this way because we want the logic inside the consequent to run
1193
+ * if `options.data` is a POJO, not if it is a data structure whose `typeof` returns "object"
1194
+ * when it's not (Array, FormData, etc). The reason we don't use `options.data.constructor`
1195
+ * to check is in case `data` is an object with no prototype (e.g. created with null).
1196
+ */
1197
+ if (Object.prototype.toString.call(options.data) === '[object Object]') {
1198
+ options.body = JSON.stringify(options.data);
1199
+ } else {
1200
+ // @ts-expect-error poorly typed
1201
+ options.body = options.data;
1202
+ }
1203
+ }
1204
+ }
1205
+ return options;
1206
+ }
1207
+ function ajaxOptions(options, adapter) {
1208
+ options.dataType = 'json';
1209
+ options.context = adapter;
1210
+ if (options.data && options.type !== 'GET') {
1211
+ options.data = JSON.stringify(options.data);
1212
+ }
1213
+ options.beforeSend = function (xhr) {
1214
+ if (options.headers) {
1215
+ Object.keys(options.headers).forEach(key => {
1216
+ const headerValue = options.headers && options.headers[key];
1217
+ const isString = value => typeof value === 'string';
1218
+ if (isString(headerValue)) {
1219
+ xhr.setRequestHeader(key, headerValue);
1220
+ }
1221
+ });
1222
+ }
1223
+ };
1224
+ return options;
1225
+ }
1226
+ function execjQAjax(adapter, requestData, options) {
1227
+ const hash = adapter.ajaxOptions(requestData.url, requestData.method, options);
1228
+ return new Promise((resolve, reject) => {
1229
+ hash.success = function (payload, textStatus, jqXHR) {
1230
+ const response = ajaxSuccessHandler(adapter, payload, jqXHR, requestData);
1231
+ resolve(response);
1232
+ };
1233
+ hash.error = function (jqXHR, textStatus, errorThrown) {
1234
+ const error = ajaxErrorHandler(adapter, jqXHR, errorThrown, requestData);
1235
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
1236
+ reject(error);
1237
+ };
1238
+ adapter._ajax(hash);
1239
+ });
1240
+ }
1241
+ function splitGroupToFitInUrl(store, adapter, group, maxURLLength, paramNameLength) {
1242
+ let idsSize = 0;
1243
+ const baseUrl = adapter._stripIDFromURL(store, group[0]);
1244
+ const splitGroups = [[]];
1245
+ group.forEach(snapshot => {
1246
+ const additionalLength = encodeURIComponent(snapshot.id).length + paramNameLength;
1247
+ if (baseUrl.length + idsSize + additionalLength >= maxURLLength) {
1248
+ idsSize = 0;
1249
+ splitGroups.push([]);
1250
+ }
1251
+ idsSize += additionalLength;
1252
+ const lastGroupIndex = splitGroups.length - 1;
1253
+ splitGroups[lastGroupIndex].push(snapshot);
1254
+ });
1255
+ return splitGroups;
1256
+ }
1257
+ export { RESTAdapter, fetchOptions };