mobx-tanstack-query-api 0.24.0 → 0.26.0

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 (264) hide show
  1. package/builtin.cjs +27 -0
  2. package/builtin.cjs.map +1 -0
  3. package/builtin.d.ts +6 -0
  4. package/builtin.js +27 -0
  5. package/builtin.js.map +1 -0
  6. package/cli.cjs +1279 -0
  7. package/cli.cjs.map +1 -0
  8. package/{codegen/types/generate-query-api-params.d.cts → cli.d.ts} +55 -10
  9. package/cli.js +1278 -0
  10. package/cli.js.map +1 -0
  11. package/index.cjs +771 -16
  12. package/index.cjs.map +1 -0
  13. package/index.d.ts +322 -2
  14. package/index.js +768 -2
  15. package/index.js.map +1 -0
  16. package/package.json +21 -64
  17. package/builtin/index.cjs +0 -25
  18. package/builtin/index.d.cts +0 -4
  19. package/builtin/index.d.cts.map +0 -1
  20. package/builtin/index.d.ts +0 -4
  21. package/builtin/index.d.ts.map +0 -1
  22. package/builtin/index.js +0 -22
  23. package/cli/bin.cjs +0 -17
  24. package/cli/bin.d.cts +0 -2
  25. package/cli/bin.d.cts.map +0 -1
  26. package/cli/bin.d.ts +0 -2
  27. package/cli/bin.d.ts.map +0 -1
  28. package/cli/bin.js +0 -15
  29. package/cli/index.cjs +0 -18
  30. package/cli/index.d.cts +0 -3
  31. package/cli/index.d.cts.map +0 -1
  32. package/cli/index.d.ts +0 -3
  33. package/cli/index.d.ts.map +0 -1
  34. package/cli/index.js +0 -2
  35. package/cli/utils/define-config.cjs +0 -9
  36. package/cli/utils/define-config.d.cts +0 -4
  37. package/cli/utils/define-config.d.cts.map +0 -1
  38. package/cli/utils/define-config.d.ts +0 -4
  39. package/cli/utils/define-config.d.ts.map +0 -1
  40. package/cli/utils/define-config.js +0 -5
  41. package/cli/utils/exec-config-path.cjs +0 -16
  42. package/cli/utils/exec-config-path.d.cts +0 -2
  43. package/cli/utils/exec-config-path.d.cts.map +0 -1
  44. package/cli/utils/exec-config-path.d.ts +0 -2
  45. package/cli/utils/exec-config-path.d.ts.map +0 -1
  46. package/cli/utils/exec-config-path.js +0 -12
  47. package/cli/utils/resolve-config-path.cjs +0 -65
  48. package/cli/utils/resolve-config-path.d.cts +0 -3
  49. package/cli/utils/resolve-config-path.d.cts.map +0 -1
  50. package/cli/utils/resolve-config-path.d.ts +0 -3
  51. package/cli/utils/resolve-config-path.d.ts.map +0 -1
  52. package/cli/utils/resolve-config-path.js +0 -25
  53. package/codegen/index.cjs +0 -545
  54. package/codegen/index.d.cts +0 -4
  55. package/codegen/index.d.cts.map +0 -1
  56. package/codegen/index.d.ts +0 -4
  57. package/codegen/index.d.ts.map +0 -1
  58. package/codegen/index.js +0 -524
  59. package/codegen/templates/all-endpoints-per-file.tmpl.cjs +0 -94
  60. package/codegen/templates/all-endpoints-per-file.tmpl.d.cts +0 -14
  61. package/codegen/templates/all-endpoints-per-file.tmpl.d.cts.map +0 -1
  62. package/codegen/templates/all-endpoints-per-file.tmpl.d.ts +0 -14
  63. package/codegen/templates/all-endpoints-per-file.tmpl.d.ts.map +0 -1
  64. package/codegen/templates/all-endpoints-per-file.tmpl.js +0 -90
  65. package/codegen/templates/all-exports.tmpl.cjs +0 -14
  66. package/codegen/templates/all-exports.tmpl.d.cts +0 -9
  67. package/codegen/templates/all-exports.tmpl.d.cts.map +0 -1
  68. package/codegen/templates/all-exports.tmpl.d.ts +0 -9
  69. package/codegen/templates/all-exports.tmpl.d.ts.map +0 -1
  70. package/codegen/templates/all-exports.tmpl.js +0 -9
  71. package/codegen/templates/constants.cjs +0 -5
  72. package/codegen/templates/constants.d.cts +0 -2
  73. package/codegen/templates/constants.d.cts.map +0 -1
  74. package/codegen/templates/constants.d.ts +0 -2
  75. package/codegen/templates/constants.d.ts.map +0 -1
  76. package/codegen/templates/constants.js +0 -2
  77. package/codegen/templates/data-contract.tmpl.cjs +0 -49
  78. package/codegen/templates/data-contract.tmpl.d.cts +0 -8
  79. package/codegen/templates/data-contract.tmpl.d.cts.map +0 -1
  80. package/codegen/templates/data-contract.tmpl.d.ts +0 -8
  81. package/codegen/templates/data-contract.tmpl.d.ts.map +0 -1
  82. package/codegen/templates/data-contract.tmpl.js +0 -45
  83. package/codegen/templates/data-contracts-file.tmpl.cjs +0 -27
  84. package/codegen/templates/data-contracts-file.tmpl.d.cts +0 -6
  85. package/codegen/templates/data-contracts-file.tmpl.d.cts.map +0 -1
  86. package/codegen/templates/data-contracts-file.tmpl.d.ts +0 -6
  87. package/codegen/templates/data-contracts-file.tmpl.d.ts.map +0 -1
  88. package/codegen/templates/data-contracts-file.tmpl.js +0 -23
  89. package/codegen/templates/endpoint-jsdoc.tmpl.cjs +0 -111
  90. package/codegen/templates/endpoint-jsdoc.tmpl.d.cts +0 -8
  91. package/codegen/templates/endpoint-jsdoc.tmpl.d.cts.map +0 -1
  92. package/codegen/templates/endpoint-jsdoc.tmpl.d.ts +0 -8
  93. package/codegen/templates/endpoint-jsdoc.tmpl.d.ts.map +0 -1
  94. package/codegen/templates/endpoint-jsdoc.tmpl.js +0 -107
  95. package/codegen/templates/endpoint-per-file.tmpl.cjs +0 -87
  96. package/codegen/templates/endpoint-per-file.tmpl.d.cts +0 -14
  97. package/codegen/templates/endpoint-per-file.tmpl.d.cts.map +0 -1
  98. package/codegen/templates/endpoint-per-file.tmpl.d.ts +0 -14
  99. package/codegen/templates/endpoint-per-file.tmpl.d.ts.map +0 -1
  100. package/codegen/templates/endpoint-per-file.tmpl.js +0 -83
  101. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.cjs +0 -10
  102. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts +0 -6
  103. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts.map +0 -1
  104. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts +0 -6
  105. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts.map +0 -1
  106. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.js +0 -6
  107. package/codegen/templates/meta-info.tmpl.cjs +0 -48
  108. package/codegen/templates/meta-info.tmpl.d.cts +0 -9
  109. package/codegen/templates/meta-info.tmpl.d.cts.map +0 -1
  110. package/codegen/templates/meta-info.tmpl.d.ts +0 -9
  111. package/codegen/templates/meta-info.tmpl.d.ts.map +0 -1
  112. package/codegen/templates/meta-info.tmpl.js +0 -42
  113. package/codegen/templates/new-endpoint.tmpl.cjs +0 -188
  114. package/codegen/templates/new-endpoint.tmpl.d.cts +0 -15
  115. package/codegen/templates/new-endpoint.tmpl.d.cts.map +0 -1
  116. package/codegen/templates/new-endpoint.tmpl.d.ts +0 -15
  117. package/codegen/templates/new-endpoint.tmpl.d.ts.map +0 -1
  118. package/codegen/templates/new-endpoint.tmpl.js +0 -184
  119. package/codegen/types/all-import-file-params.cjs +0 -2
  120. package/codegen/types/all-import-file-params.d.cts +0 -5
  121. package/codegen/types/all-import-file-params.d.cts.map +0 -1
  122. package/codegen/types/all-import-file-params.d.ts +0 -5
  123. package/codegen/types/all-import-file-params.d.ts.map +0 -1
  124. package/codegen/types/all-import-file-params.js +0 -1
  125. package/codegen/types/base-tmpl-params.cjs +0 -2
  126. package/codegen/types/base-tmpl-params.d.cts +0 -16
  127. package/codegen/types/base-tmpl-params.d.cts.map +0 -1
  128. package/codegen/types/base-tmpl-params.d.ts +0 -16
  129. package/codegen/types/base-tmpl-params.d.ts.map +0 -1
  130. package/codegen/types/base-tmpl-params.js +0 -1
  131. package/codegen/types/codegen-data-utils.cjs +0 -2
  132. package/codegen/types/codegen-data-utils.d.cts +0 -8
  133. package/codegen/types/codegen-data-utils.d.cts.map +0 -1
  134. package/codegen/types/codegen-data-utils.d.ts +0 -8
  135. package/codegen/types/codegen-data-utils.d.ts.map +0 -1
  136. package/codegen/types/codegen-data-utils.js +0 -1
  137. package/codegen/types/endpoint-data.cjs +0 -2
  138. package/codegen/types/endpoint-data.d.cts +0 -3
  139. package/codegen/types/endpoint-data.d.cts.map +0 -1
  140. package/codegen/types/endpoint-data.d.ts +0 -3
  141. package/codegen/types/endpoint-data.d.ts.map +0 -1
  142. package/codegen/types/endpoint-data.js +0 -1
  143. package/codegen/types/generate-query-api-params.cjs +0 -2
  144. package/codegen/types/generate-query-api-params.d.cts.map +0 -1
  145. package/codegen/types/generate-query-api-params.d.ts +0 -162
  146. package/codegen/types/generate-query-api-params.d.ts.map +0 -1
  147. package/codegen/types/generate-query-api-params.js +0 -1
  148. package/codegen/types/import-file-params.cjs +0 -2
  149. package/codegen/types/import-file-params.d.cts +0 -5
  150. package/codegen/types/import-file-params.d.cts.map +0 -1
  151. package/codegen/types/import-file-params.d.ts +0 -5
  152. package/codegen/types/import-file-params.d.ts.map +0 -1
  153. package/codegen/types/import-file-params.js +0 -1
  154. package/codegen/types/index.cjs +0 -23
  155. package/codegen/types/index.d.cts +0 -8
  156. package/codegen/types/index.d.cts.map +0 -1
  157. package/codegen/types/index.d.ts +0 -8
  158. package/codegen/types/index.d.ts.map +0 -1
  159. package/codegen/types/index.js +0 -7
  160. package/codegen/types/meta-info.cjs +0 -2
  161. package/codegen/types/meta-info.d.cts +0 -6
  162. package/codegen/types/meta-info.d.cts.map +0 -1
  163. package/codegen/types/meta-info.d.ts +0 -6
  164. package/codegen/types/meta-info.d.ts.map +0 -1
  165. package/codegen/types/meta-info.js +0 -1
  166. package/codegen/types/type-info.cjs +0 -2
  167. package/codegen/types/type-info.d.cts +0 -4
  168. package/codegen/types/type-info.d.cts.map +0 -1
  169. package/codegen/types/type-info.d.ts +0 -4
  170. package/codegen/types/type-info.d.ts.map +0 -1
  171. package/codegen/types/type-info.js +0 -1
  172. package/codegen/utils/create-short-model-type.cjs +0 -12
  173. package/codegen/utils/create-short-model-type.d.cts +0 -5
  174. package/codegen/utils/create-short-model-type.d.cts.map +0 -1
  175. package/codegen/utils/create-short-model-type.d.ts +0 -5
  176. package/codegen/utils/create-short-model-type.d.ts.map +0 -1
  177. package/codegen/utils/create-short-model-type.js +0 -8
  178. package/codegen/utils/remove-unused-types.cjs +0 -117
  179. package/codegen/utils/remove-unused-types.d.cts +0 -7
  180. package/codegen/utils/remove-unused-types.d.cts.map +0 -1
  181. package/codegen/utils/remove-unused-types.d.ts +0 -7
  182. package/codegen/utils/remove-unused-types.d.ts.map +0 -1
  183. package/codegen/utils/remove-unused-types.js +0 -110
  184. package/codegen/utils/unpack-filter-option.cjs +0 -23
  185. package/codegen/utils/unpack-filter-option.d.cts +0 -7
  186. package/codegen/utils/unpack-filter-option.d.cts.map +0 -1
  187. package/codegen/utils/unpack-filter-option.d.ts +0 -7
  188. package/codegen/utils/unpack-filter-option.d.ts.map +0 -1
  189. package/codegen/utils/unpack-filter-option.js +0 -19
  190. package/index.d.cts +0 -3
  191. package/index.d.cts.map +0 -1
  192. package/index.d.ts.map +0 -1
  193. package/runtime/endpoint-infinite-query.cjs +0 -101
  194. package/runtime/endpoint-infinite-query.d.cts +0 -17
  195. package/runtime/endpoint-infinite-query.d.cts.map +0 -1
  196. package/runtime/endpoint-infinite-query.d.ts +0 -17
  197. package/runtime/endpoint-infinite-query.d.ts.map +0 -1
  198. package/runtime/endpoint-infinite-query.js +0 -97
  199. package/runtime/endpoint-infinite-query.types.cjs +0 -2
  200. package/runtime/endpoint-infinite-query.types.d.cts +0 -30
  201. package/runtime/endpoint-infinite-query.types.d.cts.map +0 -1
  202. package/runtime/endpoint-infinite-query.types.d.ts +0 -30
  203. package/runtime/endpoint-infinite-query.types.d.ts.map +0 -1
  204. package/runtime/endpoint-infinite-query.types.js +0 -1
  205. package/runtime/endpoint-mutation.cjs +0 -74
  206. package/runtime/endpoint-mutation.d.cts +0 -13
  207. package/runtime/endpoint-mutation.d.cts.map +0 -1
  208. package/runtime/endpoint-mutation.d.ts +0 -13
  209. package/runtime/endpoint-mutation.d.ts.map +0 -1
  210. package/runtime/endpoint-mutation.js +0 -70
  211. package/runtime/endpoint-mutation.types.cjs +0 -2
  212. package/runtime/endpoint-mutation.types.d.cts +0 -36
  213. package/runtime/endpoint-mutation.types.d.cts.map +0 -1
  214. package/runtime/endpoint-mutation.types.d.ts +0 -36
  215. package/runtime/endpoint-mutation.types.d.ts.map +0 -1
  216. package/runtime/endpoint-mutation.types.js +0 -1
  217. package/runtime/endpoint-query-client.cjs +0 -79
  218. package/runtime/endpoint-query-client.d.cts +0 -13
  219. package/runtime/endpoint-query-client.d.cts.map +0 -1
  220. package/runtime/endpoint-query-client.d.ts +0 -13
  221. package/runtime/endpoint-query-client.d.ts.map +0 -1
  222. package/runtime/endpoint-query-client.js +0 -75
  223. package/runtime/endpoint-query-client.types.cjs +0 -2
  224. package/runtime/endpoint-query-client.types.d.cts +0 -16
  225. package/runtime/endpoint-query-client.types.d.cts.map +0 -1
  226. package/runtime/endpoint-query-client.types.d.ts +0 -16
  227. package/runtime/endpoint-query-client.types.d.ts.map +0 -1
  228. package/runtime/endpoint-query-client.types.js +0 -1
  229. package/runtime/endpoint-query.cjs +0 -214
  230. package/runtime/endpoint-query.d.cts +0 -29
  231. package/runtime/endpoint-query.d.cts.map +0 -1
  232. package/runtime/endpoint-query.d.ts +0 -29
  233. package/runtime/endpoint-query.d.ts.map +0 -1
  234. package/runtime/endpoint-query.js +0 -208
  235. package/runtime/endpoint-query.types.cjs +0 -2
  236. package/runtime/endpoint-query.types.d.cts +0 -42
  237. package/runtime/endpoint-query.types.d.cts.map +0 -1
  238. package/runtime/endpoint-query.types.d.ts +0 -42
  239. package/runtime/endpoint-query.types.d.ts.map +0 -1
  240. package/runtime/endpoint-query.types.js +0 -1
  241. package/runtime/endpoint.cjs +0 -131
  242. package/runtime/endpoint.d.cts +0 -73
  243. package/runtime/endpoint.d.cts.map +0 -1
  244. package/runtime/endpoint.d.ts +0 -73
  245. package/runtime/endpoint.d.ts.map +0 -1
  246. package/runtime/endpoint.js +0 -127
  247. package/runtime/endpoint.types.cjs +0 -2
  248. package/runtime/endpoint.types.d.cts +0 -24
  249. package/runtime/endpoint.types.d.cts.map +0 -1
  250. package/runtime/endpoint.types.d.ts +0 -24
  251. package/runtime/endpoint.types.d.ts.map +0 -1
  252. package/runtime/endpoint.types.js +0 -1
  253. package/runtime/http-client.cjs +0 -190
  254. package/runtime/http-client.d.cts +0 -85
  255. package/runtime/http-client.d.cts.map +0 -1
  256. package/runtime/http-client.d.ts +0 -85
  257. package/runtime/http-client.d.ts.map +0 -1
  258. package/runtime/http-client.js +0 -184
  259. package/runtime/index.cjs +0 -25
  260. package/runtime/index.d.cts +0 -10
  261. package/runtime/index.d.cts.map +0 -1
  262. package/runtime/index.d.ts +0 -10
  263. package/runtime/index.d.ts.map +0 -1
  264. package/runtime/index.js +0 -9
@@ -1,75 +0,0 @@
1
- import { hashKey } from '@tanstack/query-core';
2
- import { QueryClient } from 'mobx-tanstack-query';
3
- /**
4
- * Class that extends `QueryClient` and gives a bit more control over endpoint queries and mutations.
5
- *
6
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-query-client/)
7
- */
8
- export class EndpointQueryClient extends QueryClient {
9
- constructor(config) {
10
- super({
11
- ...config,
12
- defaultOptions: {
13
- ...config?.defaultOptions,
14
- queries: {
15
- ...config?.defaultOptions?.queries,
16
- queryKeyHashFn: config?.defaultOptions?.queries?.queryKeyHashFn ?? hashKey,
17
- },
18
- },
19
- });
20
- }
21
- invalidateEndpoints({ group, namespace, operationId, tag, predicate, endpoint, ...queryFilters }, options) {
22
- let endpointIdsToFilter;
23
- if (Array.isArray(endpoint)) {
24
- endpointIdsToFilter = new Set(endpoint.map((it) => it.endpointId));
25
- }
26
- else if (endpoint) {
27
- endpointIdsToFilter = new Set([endpoint.endpointId]);
28
- }
29
- return this.invalidateQueries({
30
- ...queryFilters,
31
- predicate: (query) => {
32
- if (!query.meta?.endpointQuery) {
33
- return false;
34
- }
35
- const meta = query.meta;
36
- if (endpointIdsToFilter &&
37
- !endpointIdsToFilter.has(meta.endpointId)) {
38
- return false;
39
- }
40
- if (namespace &&
41
- meta.namespace &&
42
- !applyStringFilter(namespace, meta.namespace)) {
43
- return false;
44
- }
45
- if (group && meta.group && !applyStringFilter(group, meta.group)) {
46
- return false;
47
- }
48
- if (tag && meta.tags && !applyStringFilter(tag, meta.tags)) {
49
- return false;
50
- }
51
- if (tag && meta.tags && !applyStringFilter(tag, meta.tags)) {
52
- return false;
53
- }
54
- if (operationId &&
55
- !applyStringFilter(operationId, meta.operationId)) {
56
- return false;
57
- }
58
- if (predicate && !predicate(meta, query)) {
59
- return false;
60
- }
61
- return true;
62
- },
63
- }, options);
64
- }
65
- }
66
- const applyStringFilter = (filter, value) => {
67
- const values = Array.isArray(value) ? value : [value];
68
- if (filter instanceof RegExp) {
69
- return values.some((value) => filter.test(value));
70
- }
71
- if (Array.isArray(filter)) {
72
- return filter.some((filter) => values.includes(filter));
73
- }
74
- return values.includes(filter);
75
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- import type { InvalidateQueryFilters } from '@tanstack/query-core';
2
- import type { AnyEndpoint } from "./endpoint.types.cjs";
3
- import type { EndpointQueryMeta } from "./endpoint-query.types.cjs";
4
- interface InvalidateEndpointQueryFilters extends Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'> {
5
- }
6
- export type EndpointStringFilter = string[] | string | RegExp;
7
- export interface InvalidateEndpointsFilters extends InvalidateEndpointQueryFilters {
8
- predicate?: (meta: EndpointQueryMeta, query: Parameters<Required<InvalidateQueryFilters>['predicate']>[0]) => boolean;
9
- endpoint?: AnyEndpoint | AnyEndpoint[];
10
- namespace?: EndpointStringFilter;
11
- group?: EndpointStringFilter;
12
- operationId?: EndpointStringFilter;
13
- tag?: EndpointStringFilter;
14
- }
15
- export {};
16
- //# sourceMappingURL=endpoint-query-client.types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"endpoint-query-client.types.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query-client.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,6BAA4B;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,mCAAkC;AAEnE,UAAU,8BACR,SAAQ,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;CAAG;AAE1E,MAAM,MAAM,oBAAoB,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9D,MAAM,WAAW,0BACf,SAAQ,8BAA8B;IACtC,SAAS,CAAC,EAAE,CACV,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAChE,OAAO,CAAC;IACb,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE,CAAC;IACvC,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,WAAW,CAAC,EAAE,oBAAoB,CAAC;IACnC,GAAG,CAAC,EAAE,oBAAoB,CAAC;CAC5B"}
@@ -1,16 +0,0 @@
1
- import type { InvalidateQueryFilters } from '@tanstack/query-core';
2
- import type { AnyEndpoint } from "./endpoint.types.js";
3
- import type { EndpointQueryMeta } from "./endpoint-query.types.js";
4
- interface InvalidateEndpointQueryFilters extends Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'> {
5
- }
6
- export type EndpointStringFilter = string[] | string | RegExp;
7
- export interface InvalidateEndpointsFilters extends InvalidateEndpointQueryFilters {
8
- predicate?: (meta: EndpointQueryMeta, query: Parameters<Required<InvalidateQueryFilters>['predicate']>[0]) => boolean;
9
- endpoint?: AnyEndpoint | AnyEndpoint[];
10
- namespace?: EndpointStringFilter;
11
- group?: EndpointStringFilter;
12
- operationId?: EndpointStringFilter;
13
- tag?: EndpointStringFilter;
14
- }
15
- export {};
16
- //# sourceMappingURL=endpoint-query-client.types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"endpoint-query-client.types.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query-client.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,4BAA4B;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,UAAU,8BACR,SAAQ,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;CAAG;AAE1E,MAAM,MAAM,oBAAoB,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9D,MAAM,WAAW,0BACf,SAAQ,8BAA8B;IACtC,SAAS,CAAC,EAAE,CACV,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAChE,OAAO,CAAC;IACb,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE,CAAC;IACvC,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,WAAW,CAAC,EAAE,oBAAoB,CAAC;IACnC,GAAG,CAAC,EAAE,oBAAoB,CAAC;CAC5B"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,214 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildOptionsFromParams = exports.getParamsFromContext = exports.EndpointQuery = void 0;
4
- const mobx_1 = require("mobx");
5
- const mobx_tanstack_query_1 = require("mobx-tanstack-query");
6
- const common_1 = require("yummies/common");
7
- const mobx_2 = require("yummies/mobx");
8
- /**
9
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/)
10
- */
11
- class EndpointQuery extends mobx_tanstack_query_1.Query {
12
- endpoint;
13
- _observableData;
14
- constructor(endpoint, inputQueryClient, queryOptionsInput) {
15
- const isQueryOptionsInputFn = typeof queryOptionsInput === 'function';
16
- const unpackedQueryOptionsInput = isQueryOptionsInputFn
17
- ? queryOptionsInput()
18
- : queryOptionsInput;
19
- const { uniqKey, transform: transformResponse, params, queryClient: overridedQueryClient, ...queryOptions } = unpackedQueryOptionsInput;
20
- const queryClient = overridedQueryClient ?? inputQueryClient;
21
- const _observableData = {
22
- params: null,
23
- dynamicOptions: undefined,
24
- response: null,
25
- uniqKey: unpackedQueryOptionsInput.uniqKey,
26
- };
27
- if (!isQueryOptionsInputFn && typeof params !== 'function') {
28
- if ('params' in unpackedQueryOptionsInput) {
29
- _observableData.params = params;
30
- }
31
- else {
32
- _observableData.params = {};
33
- }
34
- _observableData.initialized = true;
35
- }
36
- (0, mobx_1.makeObservable)(_observableData, {
37
- params: mobx_1.observable.ref,
38
- response: mobx_1.observable.ref,
39
- dynamicOptions: mobx_1.observable,
40
- });
41
- super({
42
- ...queryOptions,
43
- queryClient,
44
- meta: endpoint.toQueryMeta(queryOptions.meta),
45
- options: () => {
46
- const builtOptions = (0, exports.buildOptionsFromParams)(endpoint, _observableData.params, _observableData.uniqKey);
47
- let isEnabled = !!_observableData.initialized && builtOptions.enabled;
48
- if (typeof queryOptionsInput !== 'function' &&
49
- queryOptionsInput.enabled === false) {
50
- isEnabled = false;
51
- }
52
- return {
53
- ...builtOptions,
54
- enabled: isEnabled,
55
- ..._observableData.dynamicOptions,
56
- };
57
- },
58
- queryFn: async (ctx) => {
59
- const params = endpoint.getParamsFromContext(ctx);
60
- (0, mobx_1.runInAction)(() => {
61
- _observableData.response = null;
62
- if (!mobx_1.comparer.structural(params, _observableData.params)) {
63
- _observableData.params = params;
64
- }
65
- });
66
- let requestParams = params.requestParams;
67
- if (requestParams) {
68
- if (!requestParams.signal) {
69
- requestParams.signal = ctx.signal;
70
- }
71
- }
72
- else {
73
- requestParams = { signal: ctx.signal };
74
- }
75
- const fixedInput = {
76
- ...params,
77
- requestParams,
78
- };
79
- const response = await endpoint.request(fixedInput);
80
- (0, mobx_1.runInAction)(() => {
81
- _observableData.response = response;
82
- });
83
- return (await transformResponse?.(response)) ?? response.data;
84
- },
85
- });
86
- this.endpoint = endpoint;
87
- const parentAtom = (0, mobx_2.getMobxAdministration)(this);
88
- mobx_1.computed.struct(this, 'params');
89
- mobx_1.computed.struct(this, 'response');
90
- (0, mobx_1.makeObservable)(this);
91
- if (isQueryOptionsInputFn || typeof params === 'function') {
92
- const createParamsReaction = () => (0, mobx_1.reaction)(() => {
93
- let outDynamicOptions;
94
- let outParams;
95
- let uniqKey;
96
- if (isQueryOptionsInputFn) {
97
- const result = queryOptionsInput();
98
- const { params, abortSignal, select, onDone, onError, onInit, enableOnDemand, uniqKey: _uniqKey, ...dynamicOptions } = result;
99
- uniqKey = _uniqKey;
100
- if ('params' in result) {
101
- outParams = result.params;
102
- }
103
- else {
104
- outParams = {};
105
- }
106
- outDynamicOptions =
107
- Object.keys(dynamicOptions).length > 0
108
- ? dynamicOptions
109
- : undefined;
110
- }
111
- else if ('params' in unpackedQueryOptionsInput) {
112
- outParams = unpackedQueryOptionsInput.params;
113
- uniqKey = unpackedQueryOptionsInput.uniqKey;
114
- }
115
- else {
116
- outParams = {};
117
- uniqKey = unpackedQueryOptionsInput.uniqKey;
118
- }
119
- return {
120
- params: (0, common_1.callFunction)(outParams),
121
- dynamicOptions: outDynamicOptions,
122
- uniqKey,
123
- };
124
- }, ({ params, dynamicOptions, uniqKey }) => {
125
- (0, mobx_1.runInAction)(() => {
126
- _observableData.initialized = true;
127
- _observableData.params = params;
128
- _observableData.dynamicOptions = dynamicOptions;
129
- _observableData.uniqKey = uniqKey;
130
- });
131
- }, {
132
- fireImmediately: true,
133
- });
134
- if (this.features.lazy) {
135
- (0, mobx_2.lazyObserve)({
136
- property: parentAtom.values_.get('_result'),
137
- onStart: createParamsReaction,
138
- onEnd: (disposeFn) => disposeFn(),
139
- });
140
- }
141
- else {
142
- this.abortController.signal.addEventListener('abort', createParamsReaction());
143
- }
144
- }
145
- this._observableData = _observableData;
146
- }
147
- get params() {
148
- return this._observableData.params;
149
- }
150
- get response() {
151
- return this._observableData.response;
152
- }
153
- update(updateParams) {
154
- if ('params' in updateParams) {
155
- const { params, ...options } = updateParams;
156
- (0, mobx_1.runInAction)(() => {
157
- this._observableData.params = params;
158
- });
159
- return super.update({
160
- ...(0, exports.buildOptionsFromParams)(this.endpoint, params, this._observableData.uniqKey),
161
- ...options,
162
- });
163
- }
164
- else if (this._observableData) {
165
- return super.update({
166
- ...(0, exports.buildOptionsFromParams)(this.endpoint, this._observableData.params, this._observableData.uniqKey),
167
- ...updateParams,
168
- });
169
- }
170
- else {
171
- return super.update(updateParams);
172
- }
173
- }
174
- refetch(options) {
175
- if (this.params) {
176
- return super.refetch(options);
177
- }
178
- return Promise.resolve(this.queryObserver.getCurrentResult());
179
- }
180
- async start(params) {
181
- (0, mobx_1.runInAction)(() => {
182
- this._observableData.params = params;
183
- });
184
- return await super.start((0, exports.buildOptionsFromParams)(this.endpoint, params, this._observableData.uniqKey));
185
- }
186
- handleDestroy() {
187
- super.handleDestroy();
188
- (0, mobx_1.runInAction)(() => {
189
- this._observableData.params = undefined;
190
- this._observableData.dynamicOptions = undefined;
191
- });
192
- }
193
- }
194
- exports.EndpointQuery = EndpointQuery;
195
- const getParamsFromContext = (ctx) => {
196
- return (ctx.queryKey.at(-2) || {});
197
- };
198
- exports.getParamsFromContext = getParamsFromContext;
199
- const buildOptionsFromParams = (endpoint, params, uniqKey) => {
200
- const { requiredParams } = endpoint.configuration;
201
- let hasRequiredParams = false;
202
- if (requiredParams.length > 0) {
203
- hasRequiredParams =
204
- !!params && requiredParams.every((param) => param in params);
205
- }
206
- else {
207
- hasRequiredParams = !!params;
208
- }
209
- return {
210
- enabled: hasRequiredParams,
211
- queryKey: endpoint.toQueryKey(params || {}, uniqKey),
212
- };
213
- };
214
- exports.buildOptionsFromParams = buildOptionsFromParams;
@@ -1,29 +0,0 @@
1
- /** biome-ignore-all lint/correctness/noUnusedVariables: <explanation> */
2
- import type { DefaultError, QueryFunctionContext, QueryObserverResult, RefetchOptions } from '@tanstack/query-core';
3
- import { Query, type QueryUpdateOptionsAllVariants } from 'mobx-tanstack-query';
4
- import type { AnyObject, Maybe, MaybeFalsy } from 'yummies/utils/types';
5
- import type { AnyEndpoint } from "./endpoint.types.cjs";
6
- import type { EndpointQueryFlattenOptions, EndpointQueryOptions, EndpointQueryUniqKey, ExcludedQueryKeys } from "./endpoint-query.types.cjs";
7
- import type { EndpointQueryClient } from "./endpoint-query-client.cjs";
8
- /**
9
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/)
10
- */
11
- export declare class EndpointQuery<TEndpoint extends AnyEndpoint, TQueryFnData = TEndpoint['__response']['data'], TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData> extends Query<TQueryFnData, TError, TData, TQueryData> {
12
- private endpoint;
13
- private _observableData;
14
- constructor(endpoint: AnyEndpoint, inputQueryClient: EndpointQueryClient, queryOptionsInput: EndpointQueryOptions<TEndpoint, TQueryFnData, TError, TData, TQueryData> | (() => EndpointQueryFlattenOptions<TEndpoint, TQueryFnData, TError, TData, TQueryData>));
15
- get params(): MaybeFalsy<TEndpoint["__params"]>;
16
- get response(): TEndpoint["__response"] | null;
17
- update(updateParams: Omit<QueryUpdateOptionsAllVariants<TQueryFnData, TError, TData, TQueryData>, ExcludedQueryKeys> & {
18
- params?: MaybeFalsy<TEndpoint['__params']>;
19
- }): void;
20
- refetch(options?: RefetchOptions): Promise<QueryObserverResult<TData, TError>>;
21
- start(params: MaybeFalsy<TEndpoint['__params']>): Promise<QueryObserverResult<TData, TError>>;
22
- protected handleDestroy(): void;
23
- }
24
- export declare const getParamsFromContext: (ctx: QueryFunctionContext<any, any>) => AnyEndpoint["__params"];
25
- export declare const buildOptionsFromParams: (endpoint: AnyEndpoint, params: MaybeFalsy<AnyObject>, uniqKey: Maybe<EndpointQueryUniqKey>) => {
26
- enabled: boolean;
27
- queryKey: any[];
28
- };
29
- //# sourceMappingURL=endpoint-query.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"endpoint-query.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAS9B,OAAO,EAAE,KAAK,EAAE,KAAK,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAGhF,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,UAAU,EAEX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,6BAA4B;AACvD,OAAO,KAAK,EACV,2BAA2B,EAC3B,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EAClB,mCAAkC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAmC;AAWtE;;GAEG;AACH,qBAAa,aAAa,CACxB,SAAS,SAAS,WAAW,EAC7B,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAC9C,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,UAAU,GAAG,YAAY,CACzB,SAAQ,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC;IAIpD,OAAO,CAAC,QAAQ;IAHlB,OAAO,CAAC,eAAe,CAAoC;gBAGjD,QAAQ,EAAE,WAAW,EAC7B,gBAAgB,EAAE,mBAAmB,EACrC,iBAAiB,EACb,oBAAoB,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,GACxE,CAAC,MAAM,2BAA2B,CAChC,SAAS,EACT,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,CACX,CAAC;IAwLR,IAAI,MAAM,sCAET;IAED,IAAI,QAAQ,mCAEX;IAED,MAAM,CACJ,YAAY,EAAE,IAAI,CAChB,6BAA6B,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,EACtE,iBAAiB,CAClB,GAAG;QACF,MAAM,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;KAC5C;IA6BH,OAAO,CACL,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAOxC,KAAK,CACT,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,GACxC,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAa9C,SAAS,CAAC,aAAa,IAAI,IAAI;CAOhC;AAED,eAAO,MAAM,oBAAoB,GAAI,KAAK,oBAAoB,CAAC,GAAG,EAAE,GAAG,CAAC,KAChC,WAAW,CAAC,UAAU,CAC7D,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,UAAU,WAAW,EACrB,QAAQ,UAAU,CAAC,SAAS,CAAC,EAC7B,SAAS,KAAK,CAAC,oBAAoB,CAAC,KACnC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,GAAG,EAAE,CAAA;CAerC,CAAC"}
@@ -1,29 +0,0 @@
1
- /** biome-ignore-all lint/correctness/noUnusedVariables: <explanation> */
2
- import type { DefaultError, QueryFunctionContext, QueryObserverResult, RefetchOptions } from '@tanstack/query-core';
3
- import { Query, type QueryUpdateOptionsAllVariants } from 'mobx-tanstack-query';
4
- import type { AnyObject, Maybe, MaybeFalsy } from 'yummies/utils/types';
5
- import type { AnyEndpoint } from "./endpoint.types.js";
6
- import type { EndpointQueryFlattenOptions, EndpointQueryOptions, EndpointQueryUniqKey, ExcludedQueryKeys } from "./endpoint-query.types.js";
7
- import type { EndpointQueryClient } from "./endpoint-query-client.js";
8
- /**
9
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/)
10
- */
11
- export declare class EndpointQuery<TEndpoint extends AnyEndpoint, TQueryFnData = TEndpoint['__response']['data'], TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData> extends Query<TQueryFnData, TError, TData, TQueryData> {
12
- private endpoint;
13
- private _observableData;
14
- constructor(endpoint: AnyEndpoint, inputQueryClient: EndpointQueryClient, queryOptionsInput: EndpointQueryOptions<TEndpoint, TQueryFnData, TError, TData, TQueryData> | (() => EndpointQueryFlattenOptions<TEndpoint, TQueryFnData, TError, TData, TQueryData>));
15
- get params(): MaybeFalsy<TEndpoint["__params"]>;
16
- get response(): TEndpoint["__response"] | null;
17
- update(updateParams: Omit<QueryUpdateOptionsAllVariants<TQueryFnData, TError, TData, TQueryData>, ExcludedQueryKeys> & {
18
- params?: MaybeFalsy<TEndpoint['__params']>;
19
- }): void;
20
- refetch(options?: RefetchOptions): Promise<QueryObserverResult<TData, TError>>;
21
- start(params: MaybeFalsy<TEndpoint['__params']>): Promise<QueryObserverResult<TData, TError>>;
22
- protected handleDestroy(): void;
23
- }
24
- export declare const getParamsFromContext: (ctx: QueryFunctionContext<any, any>) => AnyEndpoint["__params"];
25
- export declare const buildOptionsFromParams: (endpoint: AnyEndpoint, params: MaybeFalsy<AnyObject>, uniqKey: Maybe<EndpointQueryUniqKey>) => {
26
- enabled: boolean;
27
- queryKey: any[];
28
- };
29
- //# sourceMappingURL=endpoint-query.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"endpoint-query.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAS9B,OAAO,EAAE,KAAK,EAAE,KAAK,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAGhF,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,UAAU,EAEX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,4BAA4B;AACvD,OAAO,KAAK,EACV,2BAA2B,EAC3B,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EAClB,kCAAkC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,mCAAmC;AAWtE;;GAEG;AACH,qBAAa,aAAa,CACxB,SAAS,SAAS,WAAW,EAC7B,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAC9C,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,UAAU,GAAG,YAAY,CACzB,SAAQ,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC;IAIpD,OAAO,CAAC,QAAQ;IAHlB,OAAO,CAAC,eAAe,CAAoC;gBAGjD,QAAQ,EAAE,WAAW,EAC7B,gBAAgB,EAAE,mBAAmB,EACrC,iBAAiB,EACb,oBAAoB,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,GACxE,CAAC,MAAM,2BAA2B,CAChC,SAAS,EACT,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,CACX,CAAC;IAwLR,IAAI,MAAM,sCAET;IAED,IAAI,QAAQ,mCAEX;IAED,MAAM,CACJ,YAAY,EAAE,IAAI,CAChB,6BAA6B,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,EACtE,iBAAiB,CAClB,GAAG;QACF,MAAM,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;KAC5C;IA6BH,OAAO,CACL,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAOxC,KAAK,CACT,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,GACxC,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAa9C,SAAS,CAAC,aAAa,IAAI,IAAI;CAOhC;AAED,eAAO,MAAM,oBAAoB,GAAI,KAAK,oBAAoB,CAAC,GAAG,EAAE,GAAG,CAAC,KAChC,WAAW,CAAC,UAAU,CAC7D,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,UAAU,WAAW,EACrB,QAAQ,UAAU,CAAC,SAAS,CAAC,EAC7B,SAAS,KAAK,CAAC,oBAAoB,CAAC,KACnC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,GAAG,EAAE,CAAA;CAerC,CAAC"}
@@ -1,208 +0,0 @@
1
- import { comparer, computed, makeObservable, observable, reaction, runInAction, } from 'mobx';
2
- import { Query } from 'mobx-tanstack-query';
3
- import { callFunction } from 'yummies/common';
4
- import { getMobxAdministration, lazyObserve } from 'yummies/mobx';
5
- /**
6
- * [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/)
7
- */
8
- export class EndpointQuery extends Query {
9
- endpoint;
10
- _observableData;
11
- constructor(endpoint, inputQueryClient, queryOptionsInput) {
12
- const isQueryOptionsInputFn = typeof queryOptionsInput === 'function';
13
- const unpackedQueryOptionsInput = isQueryOptionsInputFn
14
- ? queryOptionsInput()
15
- : queryOptionsInput;
16
- const { uniqKey, transform: transformResponse, params, queryClient: overridedQueryClient, ...queryOptions } = unpackedQueryOptionsInput;
17
- const queryClient = overridedQueryClient ?? inputQueryClient;
18
- const _observableData = {
19
- params: null,
20
- dynamicOptions: undefined,
21
- response: null,
22
- uniqKey: unpackedQueryOptionsInput.uniqKey,
23
- };
24
- if (!isQueryOptionsInputFn && typeof params !== 'function') {
25
- if ('params' in unpackedQueryOptionsInput) {
26
- _observableData.params = params;
27
- }
28
- else {
29
- _observableData.params = {};
30
- }
31
- _observableData.initialized = true;
32
- }
33
- makeObservable(_observableData, {
34
- params: observable.ref,
35
- response: observable.ref,
36
- dynamicOptions: observable,
37
- });
38
- super({
39
- ...queryOptions,
40
- queryClient,
41
- meta: endpoint.toQueryMeta(queryOptions.meta),
42
- options: () => {
43
- const builtOptions = buildOptionsFromParams(endpoint, _observableData.params, _observableData.uniqKey);
44
- let isEnabled = !!_observableData.initialized && builtOptions.enabled;
45
- if (typeof queryOptionsInput !== 'function' &&
46
- queryOptionsInput.enabled === false) {
47
- isEnabled = false;
48
- }
49
- return {
50
- ...builtOptions,
51
- enabled: isEnabled,
52
- ..._observableData.dynamicOptions,
53
- };
54
- },
55
- queryFn: async (ctx) => {
56
- const params = endpoint.getParamsFromContext(ctx);
57
- runInAction(() => {
58
- _observableData.response = null;
59
- if (!comparer.structural(params, _observableData.params)) {
60
- _observableData.params = params;
61
- }
62
- });
63
- let requestParams = params.requestParams;
64
- if (requestParams) {
65
- if (!requestParams.signal) {
66
- requestParams.signal = ctx.signal;
67
- }
68
- }
69
- else {
70
- requestParams = { signal: ctx.signal };
71
- }
72
- const fixedInput = {
73
- ...params,
74
- requestParams,
75
- };
76
- const response = await endpoint.request(fixedInput);
77
- runInAction(() => {
78
- _observableData.response = response;
79
- });
80
- return (await transformResponse?.(response)) ?? response.data;
81
- },
82
- });
83
- this.endpoint = endpoint;
84
- const parentAtom = getMobxAdministration(this);
85
- computed.struct(this, 'params');
86
- computed.struct(this, 'response');
87
- makeObservable(this);
88
- if (isQueryOptionsInputFn || typeof params === 'function') {
89
- const createParamsReaction = () => reaction(() => {
90
- let outDynamicOptions;
91
- let outParams;
92
- let uniqKey;
93
- if (isQueryOptionsInputFn) {
94
- const result = queryOptionsInput();
95
- const { params, abortSignal, select, onDone, onError, onInit, enableOnDemand, uniqKey: _uniqKey, ...dynamicOptions } = result;
96
- uniqKey = _uniqKey;
97
- if ('params' in result) {
98
- outParams = result.params;
99
- }
100
- else {
101
- outParams = {};
102
- }
103
- outDynamicOptions =
104
- Object.keys(dynamicOptions).length > 0
105
- ? dynamicOptions
106
- : undefined;
107
- }
108
- else if ('params' in unpackedQueryOptionsInput) {
109
- outParams = unpackedQueryOptionsInput.params;
110
- uniqKey = unpackedQueryOptionsInput.uniqKey;
111
- }
112
- else {
113
- outParams = {};
114
- uniqKey = unpackedQueryOptionsInput.uniqKey;
115
- }
116
- return {
117
- params: callFunction(outParams),
118
- dynamicOptions: outDynamicOptions,
119
- uniqKey,
120
- };
121
- }, ({ params, dynamicOptions, uniqKey }) => {
122
- runInAction(() => {
123
- _observableData.initialized = true;
124
- _observableData.params = params;
125
- _observableData.dynamicOptions = dynamicOptions;
126
- _observableData.uniqKey = uniqKey;
127
- });
128
- }, {
129
- fireImmediately: true,
130
- });
131
- if (this.features.lazy) {
132
- lazyObserve({
133
- property: parentAtom.values_.get('_result'),
134
- onStart: createParamsReaction,
135
- onEnd: (disposeFn) => disposeFn(),
136
- });
137
- }
138
- else {
139
- this.abortController.signal.addEventListener('abort', createParamsReaction());
140
- }
141
- }
142
- this._observableData = _observableData;
143
- }
144
- get params() {
145
- return this._observableData.params;
146
- }
147
- get response() {
148
- return this._observableData.response;
149
- }
150
- update(updateParams) {
151
- if ('params' in updateParams) {
152
- const { params, ...options } = updateParams;
153
- runInAction(() => {
154
- this._observableData.params = params;
155
- });
156
- return super.update({
157
- ...buildOptionsFromParams(this.endpoint, params, this._observableData.uniqKey),
158
- ...options,
159
- });
160
- }
161
- else if (this._observableData) {
162
- return super.update({
163
- ...buildOptionsFromParams(this.endpoint, this._observableData.params, this._observableData.uniqKey),
164
- ...updateParams,
165
- });
166
- }
167
- else {
168
- return super.update(updateParams);
169
- }
170
- }
171
- refetch(options) {
172
- if (this.params) {
173
- return super.refetch(options);
174
- }
175
- return Promise.resolve(this.queryObserver.getCurrentResult());
176
- }
177
- async start(params) {
178
- runInAction(() => {
179
- this._observableData.params = params;
180
- });
181
- return await super.start(buildOptionsFromParams(this.endpoint, params, this._observableData.uniqKey));
182
- }
183
- handleDestroy() {
184
- super.handleDestroy();
185
- runInAction(() => {
186
- this._observableData.params = undefined;
187
- this._observableData.dynamicOptions = undefined;
188
- });
189
- }
190
- }
191
- export const getParamsFromContext = (ctx) => {
192
- return (ctx.queryKey.at(-2) || {});
193
- };
194
- export const buildOptionsFromParams = (endpoint, params, uniqKey) => {
195
- const { requiredParams } = endpoint.configuration;
196
- let hasRequiredParams = false;
197
- if (requiredParams.length > 0) {
198
- hasRequiredParams =
199
- !!params && requiredParams.every((param) => param in params);
200
- }
201
- else {
202
- hasRequiredParams = !!params;
203
- }
204
- return {
205
- enabled: hasRequiredParams,
206
- queryKey: endpoint.toQueryKey(params || {}, uniqKey),
207
- };
208
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,42 +0,0 @@
1
- import type { DefaultError } from '@tanstack/query-core';
2
- import type { QueryConfig } from 'mobx-tanstack-query';
3
- import type { AnyObject, Maybe, MaybeFalsy, MaybeFn } from 'yummies/utils/types';
4
- import type { Endpoint } from "./endpoint.cjs";
5
- import type { AnyEndpoint, ToEndpoint } from "./endpoint.types.cjs";
6
- import type { EndpointQuery } from "./endpoint-query.cjs";
7
- import type { EndpointQueryClient } from "./endpoint-query-client.cjs";
8
- export interface EndpointQueryMeta {
9
- endpointId: string;
10
- endpointQuery: true;
11
- tags: string[];
12
- operationId: string;
13
- path: string[];
14
- pathDeclaration: string;
15
- group?: string;
16
- namespace?: string;
17
- }
18
- export type EndpointQueryUniqKey = Maybe<MaybeFn<string | number | AnyObject | boolean>>;
19
- export type ExcludedQueryKeys = 'options' | 'queryFn' | 'queryClient' | 'queryKey' | '_defaulted' | '_optimisticResults' | 'experimental_prefetchInRender' | 'enabled' | 'queryHash' | 'queryKeyHashFn';
20
- type ShortQueryConfig<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData> = Omit<QueryConfig<TQueryFnData, TError, TData, TQueryData>, ExcludedQueryKeys> & {
21
- enabled?: boolean;
22
- queryClient?: EndpointQueryClient;
23
- };
24
- export type EndpointQueryFlattenOptions<TEndpoint extends AnyEndpoint, TQueryFnData = TEndpoint['__response']['data'], TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData> = ShortQueryConfig<NoInfer<TQueryFnData>, TError, TData, TQueryData> & {
25
- uniqKey?: EndpointQueryUniqKey;
26
- params?: MaybeFalsy<TEndpoint['__params']>;
27
- /**
28
- * Transform response to QueryFnData
29
- */
30
- transform?: (response: TEndpoint['__response']) => TQueryFnData | Promise<TQueryFnData>;
31
- };
32
- export type EndpointQueryOptions<TEndpoint extends AnyEndpoint, TQueryFnData = TEndpoint['__response']['data'], TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData> = ShortQueryConfig<NoInfer<TQueryFnData>, TError, TData, TQueryData> & {
33
- uniqKey?: EndpointQueryUniqKey;
34
- params?: MaybeFn<MaybeFalsy<TEndpoint['__params']>, []>;
35
- /**
36
- * Transform response to QueryFnData
37
- */
38
- transform?: (response: TEndpoint['__response']) => TQueryFnData | Promise<TQueryFnData>;
39
- };
40
- export type ToEndpointQuery<T extends AnyEndpoint, TData = ToEndpoint<T>['__response']['data'], TQueryData = ToEndpoint<T>['__response']['data']> = T extends Endpoint<infer TResponse, any, any> ? EndpointQuery<T, TResponse['data'], TResponse['error'], TData, TQueryData> : ToEndpointQuery<AnyEndpoint>;
41
- export {};
42
- //# sourceMappingURL=endpoint-query.types.d.ts.map