mobx-tanstack-query-api 0.16.0 → 0.17.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.
- package/dist/builtin/index.cjs +26 -0
- package/dist/builtin/index.d.cts +5 -0
- package/dist/builtin/index.d.cts.map +1 -0
- package/dist/builtin/index.d.ts +5 -0
- package/dist/builtin/index.d.ts.map +1 -0
- package/{builtin → dist/builtin}/index.js +2 -2
- package/dist/cli/bin.cjs +17 -0
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/{cli → dist/cli}/bin.js +4 -4
- package/dist/cli/index.cjs +18 -0
- package/dist/cli/index.d.cts +3 -0
- package/dist/cli/index.d.cts.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/utils/define-config.cjs +9 -0
- package/dist/cli/utils/define-config.d.cts +4 -0
- package/dist/cli/utils/define-config.d.cts.map +1 -0
- package/{cli → dist/cli}/utils/define-config.d.ts +1 -1
- package/{cli → dist/cli}/utils/define-config.d.ts.map +1 -1
- package/dist/cli/utils/exec-config-path.cjs +16 -0
- package/dist/cli/utils/exec-config-path.d.ts +2 -0
- package/dist/cli/utils/exec-config-path.d.ts.map +1 -0
- package/dist/cli/utils/resolve-config-path.cjs +65 -0
- package/dist/cli/utils/resolve-config-path.d.ts +3 -0
- package/dist/cli/utils/resolve-config-path.d.ts.map +1 -0
- package/dist/codegen/index.cjs +488 -0
- package/dist/codegen/index.d.cts +167 -0
- package/dist/codegen/index.d.cts.map +1 -0
- package/{codegen → dist/codegen}/index.d.ts +1 -1
- package/dist/codegen/index.d.ts.map +1 -0
- package/{codegen → dist/codegen}/index.js +9 -9
- package/dist/codegen/templates/all-endpoints-per-file.tmpl.cjs +99 -0
- package/dist/codegen/templates/all-endpoints-per-file.tmpl.d.cts +18 -0
- package/dist/codegen/templates/all-endpoints-per-file.tmpl.d.cts.map +1 -0
- package/{codegen → dist/codegen}/templates/all-endpoints-per-file.tmpl.d.ts +1 -1
- package/dist/codegen/templates/all-endpoints-per-file.tmpl.d.ts.map +1 -0
- package/{codegen → dist/codegen}/templates/all-endpoints-per-file.tmpl.js +4 -4
- package/dist/codegen/templates/all-exports.tmpl.cjs +14 -0
- package/dist/codegen/templates/all-exports.tmpl.d.cts +11 -0
- package/dist/codegen/templates/all-exports.tmpl.d.cts.map +1 -0
- package/{codegen → dist/codegen}/templates/all-exports.tmpl.d.ts +1 -1
- package/dist/codegen/templates/all-exports.tmpl.d.ts.map +1 -0
- package/{codegen → dist/codegen}/templates/all-exports.tmpl.js +1 -1
- package/dist/codegen/templates/constants.cjs +5 -0
- package/dist/codegen/templates/constants.d.ts +2 -0
- package/dist/codegen/templates/constants.d.ts.map +1 -0
- package/dist/codegen/templates/data-contract.tmpl.cjs +49 -0
- package/dist/codegen/templates/data-contract.tmpl.d.ts +8 -0
- package/dist/codegen/templates/data-contract.tmpl.d.ts.map +1 -0
- package/dist/codegen/templates/data-contracts-file.tmpl.cjs +27 -0
- package/dist/codegen/templates/data-contracts-file.tmpl.d.cts +10 -0
- package/dist/codegen/templates/data-contracts-file.tmpl.d.cts.map +1 -0
- package/{codegen → dist/codegen}/templates/data-contracts-file.tmpl.d.ts +1 -1
- package/dist/codegen/templates/data-contracts-file.tmpl.d.ts.map +1 -0
- package/{codegen → dist/codegen}/templates/data-contracts-file.tmpl.js +2 -2
- package/dist/codegen/templates/endpoint-jsdoc.tmpl.cjs +110 -0
- package/dist/codegen/templates/endpoint-jsdoc.tmpl.d.cts +10 -0
- package/dist/codegen/templates/endpoint-jsdoc.tmpl.d.cts.map +1 -0
- package/{codegen → dist/codegen}/templates/endpoint-jsdoc.tmpl.d.ts +1 -1
- package/dist/codegen/templates/endpoint-jsdoc.tmpl.d.ts.map +1 -0
- package/dist/codegen/templates/endpoint-per-file.tmpl.cjs +90 -0
- package/dist/codegen/templates/endpoint-per-file.tmpl.d.cts +18 -0
- package/dist/codegen/templates/endpoint-per-file.tmpl.d.cts.map +1 -0
- package/{codegen → dist/codegen}/templates/endpoint-per-file.tmpl.d.ts +1 -1
- package/dist/codegen/templates/endpoint-per-file.tmpl.d.ts.map +1 -0
- package/{codegen → dist/codegen}/templates/endpoint-per-file.tmpl.js +4 -4
- package/dist/codegen/templates/index-ts-for-endpoint-per-file.tmpl.cjs +10 -0
- package/dist/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts +10 -0
- package/dist/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts.map +1 -0
- package/{codegen → dist/codegen}/templates/index-ts-for-endpoint-per-file.tmpl.d.ts +1 -1
- package/{codegen → dist/codegen}/templates/index-ts-for-endpoint-per-file.tmpl.d.ts.map +1 -1
- package/{codegen → dist/codegen}/templates/index-ts-for-endpoint-per-file.tmpl.js +1 -1
- package/dist/codegen/templates/meta-info.tmpl.cjs +48 -0
- package/dist/codegen/templates/meta-info.tmpl.d.cts +12 -0
- package/dist/codegen/templates/meta-info.tmpl.d.cts.map +1 -0
- package/{codegen → dist/codegen}/templates/meta-info.tmpl.d.ts +1 -1
- package/dist/codegen/templates/meta-info.tmpl.d.ts.map +1 -0
- package/{codegen → dist/codegen}/templates/meta-info.tmpl.js +1 -1
- package/dist/codegen/templates/new-endpoint.tmpl.cjs +178 -0
- package/dist/codegen/templates/new-endpoint.tmpl.d.cts +21 -0
- package/dist/codegen/templates/new-endpoint.tmpl.d.cts.map +1 -0
- package/{codegen → dist/codegen}/templates/new-endpoint.tmpl.d.ts +1 -1
- package/dist/codegen/templates/new-endpoint.tmpl.d.ts.map +1 -0
- package/{codegen → dist/codegen}/templates/new-endpoint.tmpl.js +1 -1
- package/dist/codegen/utils/remove-unused-types.cjs +117 -0
- package/dist/codegen/utils/remove-unused-types.d.cts +7 -0
- package/dist/codegen/utils/remove-unused-types.d.cts.map +1 -0
- package/{codegen → dist/codegen}/utils/remove-unused-types.d.ts +1 -1
- package/dist/codegen/utils/remove-unused-types.d.ts.map +1 -0
- package/{codegen → dist/codegen}/utils/remove-unused-types.js +1 -1
- package/dist/codegen/utils/unpack-filter-option.cjs +20 -0
- package/dist/codegen/utils/unpack-filter-option.d.cts +4 -0
- package/dist/codegen/utils/unpack-filter-option.d.cts.map +1 -0
- package/{codegen → dist/codegen}/utils/unpack-filter-option.d.ts +1 -1
- package/dist/codegen/utils/unpack-filter-option.d.ts.map +1 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/{index.d.ts.map → dist/index.d.ts.map} +1 -1
- package/{index.js → dist/index.js} +1 -1
- package/dist/runtime/endpoint-infinite-query.cjs +101 -0
- package/dist/runtime/endpoint-infinite-query.d.cts +17 -0
- package/dist/runtime/endpoint-infinite-query.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-infinite-query.d.ts +3 -3
- package/dist/runtime/endpoint-infinite-query.d.ts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-infinite-query.js +1 -1
- package/dist/runtime/endpoint-infinite-query.types.cjs +2 -0
- package/dist/runtime/endpoint-infinite-query.types.d.cts +30 -0
- package/dist/runtime/endpoint-infinite-query.types.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-infinite-query.types.d.ts +2 -2
- package/dist/runtime/endpoint-infinite-query.types.d.ts.map +1 -0
- package/dist/runtime/endpoint-mutation.cjs +73 -0
- package/dist/runtime/endpoint-mutation.d.cts +13 -0
- package/dist/runtime/endpoint-mutation.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-mutation.d.ts +3 -3
- package/dist/runtime/endpoint-mutation.d.ts.map +1 -0
- package/dist/runtime/endpoint-mutation.types.cjs +2 -0
- package/dist/runtime/endpoint-mutation.types.d.cts +30 -0
- package/dist/runtime/endpoint-mutation.types.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-mutation.types.d.ts +2 -2
- package/dist/runtime/endpoint-mutation.types.d.ts.map +1 -0
- package/dist/runtime/endpoint-query-client.cjs +79 -0
- package/dist/runtime/endpoint-query-client.d.cts +13 -0
- package/dist/runtime/endpoint-query-client.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-query-client.d.ts +1 -1
- package/dist/runtime/endpoint-query-client.d.ts.map +1 -0
- package/dist/runtime/endpoint-query-client.types.cjs +2 -0
- package/dist/runtime/endpoint-query-client.types.d.cts +16 -0
- package/dist/runtime/endpoint-query-client.types.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-query-client.types.d.ts +2 -2
- package/dist/runtime/endpoint-query-client.types.d.ts.map +1 -0
- package/dist/runtime/endpoint-query.cjs +213 -0
- package/dist/runtime/endpoint-query.d.cts +29 -0
- package/dist/runtime/endpoint-query.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-query.d.ts +3 -3
- package/dist/runtime/endpoint-query.d.ts.map +1 -0
- package/dist/runtime/endpoint-query.types.cjs +2 -0
- package/dist/runtime/endpoint-query.types.d.cts +37 -0
- package/dist/runtime/endpoint-query.types.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint-query.types.d.ts +1 -1
- package/dist/runtime/endpoint-query.types.d.ts.map +1 -0
- package/dist/runtime/endpoint.cjs +128 -0
- package/dist/runtime/endpoint.d.cts +69 -0
- package/dist/runtime/endpoint.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint.d.ts +9 -9
- package/dist/runtime/endpoint.d.ts.map +1 -0
- package/{runtime → dist/runtime}/endpoint.js +3 -3
- package/dist/runtime/endpoint.types.cjs +2 -0
- package/dist/runtime/endpoint.types.d.cts +23 -0
- package/dist/runtime/endpoint.types.d.cts.map +1 -0
- package/{runtime → dist/runtime}/endpoint.types.d.ts +3 -3
- package/dist/runtime/endpoint.types.d.ts.map +1 -0
- package/dist/runtime/http-client.cjs +208 -0
- package/dist/runtime/http-client.d.ts +85 -0
- package/dist/runtime/http-client.d.ts.map +1 -0
- package/dist/runtime/index.cjs +25 -0
- package/dist/runtime/index.d.cts +10 -0
- package/dist/runtime/index.d.cts.map +1 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +9 -0
- package/package.json +40 -149
- package/assets/gh-repo-template.pxz +0 -0
- package/assets/logo.png +0 -0
- package/assets/logo.pxz +0 -0
- package/builtin/index.d.ts +0 -5
- package/builtin/index.d.ts.map +0 -1
- package/cli/bin.mjs +0 -15
- package/cli/index.d.ts +0 -2
- package/cli/index.d.ts.map +0 -1
- package/cli/index.js +0 -1
- package/codegen/index.d.ts.map +0 -1
- package/codegen/templates/all-endpoints-per-file.tmpl.d.ts.map +0 -1
- package/codegen/templates/all-exports.tmpl.d.ts.map +0 -1
- package/codegen/templates/data-contracts-file.tmpl.d.ts.map +0 -1
- package/codegen/templates/endpoint-jsdoc.tmpl.d.ts.map +0 -1
- package/codegen/templates/endpoint-per-file.tmpl.d.ts.map +0 -1
- package/codegen/templates/meta-info.tmpl.d.ts.map +0 -1
- package/codegen/templates/new-endpoint.tmpl.d.ts.map +0 -1
- package/codegen/utils/remove-unused-types.d.ts.map +0 -1
- package/codegen/utils/unpack-filter-option.d.ts.map +0 -1
- package/index.d.ts +0 -3
- package/runtime/endpoint-infinite-query.d.ts.map +0 -1
- package/runtime/endpoint-infinite-query.types.d.ts.map +0 -1
- package/runtime/endpoint-mutation.d.ts.map +0 -1
- package/runtime/endpoint-mutation.types.d.ts.map +0 -1
- package/runtime/endpoint-query-client.d.ts.map +0 -1
- package/runtime/endpoint-query-client.types.d.ts.map +0 -1
- package/runtime/endpoint-query.d.ts.map +0 -1
- package/runtime/endpoint-query.types.d.ts.map +0 -1
- package/runtime/endpoint.d.ts.map +0 -1
- package/runtime/endpoint.types.d.ts.map +0 -1
- package/runtime/index.d.ts +0 -10
- package/runtime/index.d.ts.map +0 -1
- package/runtime/index.js +0 -9
- /package/{cli/bin.d.ts → dist/cli/bin.d.cts} +0 -0
- /package/{cli/bin.d.ts.map → dist/cli/bin.d.cts.map} +0 -0
- /package/{cli → dist/cli}/utils/define-config.js +0 -0
- /package/{cli/utils/exec-config-path.d.ts → dist/cli/utils/exec-config-path.d.cts} +0 -0
- /package/{cli/utils/exec-config-path.d.ts.map → dist/cli/utils/exec-config-path.d.cts.map} +0 -0
- /package/{cli → dist/cli}/utils/exec-config-path.js +0 -0
- /package/{cli/utils/resolve-config-path.d.ts → dist/cli/utils/resolve-config-path.d.cts} +0 -0
- /package/{cli/utils/resolve-config-path.d.ts.map → dist/cli/utils/resolve-config-path.d.cts.map} +0 -0
- /package/{cli → dist/cli}/utils/resolve-config-path.js +0 -0
- /package/{codegen/templates/constants.d.ts → dist/codegen/templates/constants.d.cts} +0 -0
- /package/{codegen/templates/constants.d.ts.map → dist/codegen/templates/constants.d.cts.map} +0 -0
- /package/{codegen → dist/codegen}/templates/constants.js +0 -0
- /package/{codegen/templates/data-contract.tmpl.d.ts → dist/codegen/templates/data-contract.tmpl.d.cts} +0 -0
- /package/{codegen/templates/data-contract.tmpl.d.ts.map → dist/codegen/templates/data-contract.tmpl.d.cts.map} +0 -0
- /package/{codegen → dist/codegen}/templates/data-contract.tmpl.js +0 -0
- /package/{codegen → dist/codegen}/templates/endpoint-jsdoc.tmpl.js +0 -0
- /package/{codegen → dist/codegen}/utils/unpack-filter-option.js +0 -0
- /package/{runtime → dist/runtime}/endpoint-infinite-query.types.js +0 -0
- /package/{runtime → dist/runtime}/endpoint-mutation.js +0 -0
- /package/{runtime → dist/runtime}/endpoint-mutation.types.js +0 -0
- /package/{runtime → dist/runtime}/endpoint-query-client.js +0 -0
- /package/{runtime → dist/runtime}/endpoint-query-client.types.js +0 -0
- /package/{runtime → dist/runtime}/endpoint-query.js +0 -0
- /package/{runtime → dist/runtime}/endpoint-query.types.js +0 -0
- /package/{runtime → dist/runtime}/endpoint.types.js +0 -0
- /package/{runtime/http-client.d.ts → dist/runtime/http-client.d.cts} +0 -0
- /package/{runtime/http-client.d.ts.map → dist/runtime/http-client.d.cts.map} +0 -0
- /package/{runtime → dist/runtime}/http-client.js +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
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, queryClient, queryOptionsInput) {
|
|
15
|
+
const isQueryOptionsInputFn = typeof queryOptionsInput === 'function';
|
|
16
|
+
const unpackedQueryOptionsInput = isQueryOptionsInputFn
|
|
17
|
+
? queryOptionsInput()
|
|
18
|
+
: queryOptionsInput;
|
|
19
|
+
const { uniqKey, transform: transformResponse, params, ...queryOptions } = unpackedQueryOptionsInput;
|
|
20
|
+
const _observableData = {
|
|
21
|
+
params: null,
|
|
22
|
+
dynamicOptions: undefined,
|
|
23
|
+
response: null,
|
|
24
|
+
uniqKey: unpackedQueryOptionsInput.uniqKey,
|
|
25
|
+
};
|
|
26
|
+
if (!isQueryOptionsInputFn && typeof params !== 'function') {
|
|
27
|
+
if ('params' in unpackedQueryOptionsInput) {
|
|
28
|
+
_observableData.params = params;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
_observableData.params = {};
|
|
32
|
+
}
|
|
33
|
+
_observableData.initialized = true;
|
|
34
|
+
}
|
|
35
|
+
(0, mobx_1.makeObservable)(_observableData, {
|
|
36
|
+
params: mobx_1.observable.ref,
|
|
37
|
+
response: mobx_1.observable.ref,
|
|
38
|
+
dynamicOptions: mobx_1.observable,
|
|
39
|
+
});
|
|
40
|
+
super({
|
|
41
|
+
...queryOptions,
|
|
42
|
+
queryClient,
|
|
43
|
+
meta: endpoint.toQueryMeta(queryOptions.meta),
|
|
44
|
+
options: () => {
|
|
45
|
+
const builtOptions = (0, exports.buildOptionsFromParams)(endpoint, _observableData.params, _observableData.uniqKey);
|
|
46
|
+
let isEnabled = !!_observableData.initialized && builtOptions.enabled;
|
|
47
|
+
if (typeof queryOptionsInput !== 'function' &&
|
|
48
|
+
queryOptionsInput.enabled === false) {
|
|
49
|
+
isEnabled = false;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
...builtOptions,
|
|
53
|
+
enabled: isEnabled,
|
|
54
|
+
..._observableData.dynamicOptions,
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
queryFn: async (ctx) => {
|
|
58
|
+
const params = (0, exports.getParamsFromContext)(ctx);
|
|
59
|
+
(0, mobx_1.runInAction)(() => {
|
|
60
|
+
_observableData.response = null;
|
|
61
|
+
if (!mobx_1.comparer.structural(params, _observableData.params)) {
|
|
62
|
+
_observableData.params = params;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
let requestParams = params.requestParams;
|
|
66
|
+
if (requestParams) {
|
|
67
|
+
if (!requestParams.signal) {
|
|
68
|
+
requestParams.signal = ctx.signal;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
requestParams = { signal: ctx.signal };
|
|
73
|
+
}
|
|
74
|
+
const fixedInput = {
|
|
75
|
+
...params,
|
|
76
|
+
requestParams,
|
|
77
|
+
};
|
|
78
|
+
const response = await endpoint.request(fixedInput);
|
|
79
|
+
(0, mobx_1.runInAction)(() => {
|
|
80
|
+
_observableData.response = response;
|
|
81
|
+
});
|
|
82
|
+
return (await transformResponse?.(response)) ?? response.data;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
this.endpoint = endpoint;
|
|
86
|
+
const parentAtom = (0, mobx_2.getMobxAdministration)(this);
|
|
87
|
+
mobx_1.computed.struct(this, 'params');
|
|
88
|
+
mobx_1.computed.struct(this, 'response');
|
|
89
|
+
(0, mobx_1.makeObservable)(this);
|
|
90
|
+
if (isQueryOptionsInputFn || typeof params === 'function') {
|
|
91
|
+
const createParamsReaction = () => (0, mobx_1.reaction)(() => {
|
|
92
|
+
let outDynamicOptions;
|
|
93
|
+
let outParams;
|
|
94
|
+
let uniqKey;
|
|
95
|
+
if (isQueryOptionsInputFn) {
|
|
96
|
+
const result = queryOptionsInput();
|
|
97
|
+
const { params, abortSignal, select, onDone, onError, onInit, enableOnDemand, uniqKey: _uniqKey, ...dynamicOptions } = result;
|
|
98
|
+
uniqKey = _uniqKey;
|
|
99
|
+
if ('params' in result) {
|
|
100
|
+
outParams = result.params;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
outParams = {};
|
|
104
|
+
}
|
|
105
|
+
outDynamicOptions =
|
|
106
|
+
Object.keys(dynamicOptions).length > 0
|
|
107
|
+
? dynamicOptions
|
|
108
|
+
: undefined;
|
|
109
|
+
}
|
|
110
|
+
else if ('params' in unpackedQueryOptionsInput) {
|
|
111
|
+
outParams = unpackedQueryOptionsInput.params;
|
|
112
|
+
uniqKey = unpackedQueryOptionsInput.uniqKey;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
outParams = {};
|
|
116
|
+
uniqKey = unpackedQueryOptionsInput.uniqKey;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
params: (0, common_1.callFunction)(outParams),
|
|
120
|
+
dynamicOptions: outDynamicOptions,
|
|
121
|
+
uniqKey,
|
|
122
|
+
};
|
|
123
|
+
}, ({ params, dynamicOptions, uniqKey }) => {
|
|
124
|
+
(0, mobx_1.runInAction)(() => {
|
|
125
|
+
_observableData.initialized = true;
|
|
126
|
+
_observableData.params = params;
|
|
127
|
+
_observableData.dynamicOptions = dynamicOptions;
|
|
128
|
+
_observableData.uniqKey = uniqKey;
|
|
129
|
+
});
|
|
130
|
+
}, {
|
|
131
|
+
fireImmediately: true,
|
|
132
|
+
});
|
|
133
|
+
if (this.isLazy) {
|
|
134
|
+
(0, mobx_2.lazyObserve)({
|
|
135
|
+
property: parentAtom.values_.get('_result'),
|
|
136
|
+
onStart: createParamsReaction,
|
|
137
|
+
onEnd: (disposeFn) => disposeFn(),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.abortController.signal.addEventListener('abort', createParamsReaction());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
this._observableData = _observableData;
|
|
145
|
+
}
|
|
146
|
+
get params() {
|
|
147
|
+
return this._observableData.params;
|
|
148
|
+
}
|
|
149
|
+
get response() {
|
|
150
|
+
return this._observableData.response;
|
|
151
|
+
}
|
|
152
|
+
update(updateParams) {
|
|
153
|
+
if ('params' in updateParams) {
|
|
154
|
+
const { params, ...options } = updateParams;
|
|
155
|
+
(0, mobx_1.runInAction)(() => {
|
|
156
|
+
this._observableData.params = params;
|
|
157
|
+
});
|
|
158
|
+
return super.update({
|
|
159
|
+
...(0, exports.buildOptionsFromParams)(this.endpoint, params, this._observableData.uniqKey),
|
|
160
|
+
...options,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
else if (this._observableData) {
|
|
164
|
+
return super.update({
|
|
165
|
+
...(0, exports.buildOptionsFromParams)(this.endpoint, this._observableData.params, this._observableData.uniqKey),
|
|
166
|
+
...updateParams,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
return super.update(updateParams);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
refetch(options) {
|
|
174
|
+
if (this.params) {
|
|
175
|
+
return super.refetch(options);
|
|
176
|
+
}
|
|
177
|
+
return Promise.resolve(this.queryObserver.getCurrentResult());
|
|
178
|
+
}
|
|
179
|
+
async start(params) {
|
|
180
|
+
(0, mobx_1.runInAction)(() => {
|
|
181
|
+
this._observableData.params = params;
|
|
182
|
+
});
|
|
183
|
+
return await super.start((0, exports.buildOptionsFromParams)(this.endpoint, params, this._observableData.uniqKey));
|
|
184
|
+
}
|
|
185
|
+
destroy() {
|
|
186
|
+
super.destroy();
|
|
187
|
+
(0, mobx_1.runInAction)(() => {
|
|
188
|
+
this._observableData.params = undefined;
|
|
189
|
+
this._observableData.dynamicOptions = undefined;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.EndpointQuery = EndpointQuery;
|
|
194
|
+
const getParamsFromContext = (ctx) => {
|
|
195
|
+
return (ctx.queryKey.at(-2) || {});
|
|
196
|
+
};
|
|
197
|
+
exports.getParamsFromContext = getParamsFromContext;
|
|
198
|
+
const buildOptionsFromParams = (endpoint, params, uniqKey) => {
|
|
199
|
+
const { requiredParams } = endpoint.configuration;
|
|
200
|
+
let hasRequiredParams = false;
|
|
201
|
+
if (requiredParams.length > 0) {
|
|
202
|
+
hasRequiredParams =
|
|
203
|
+
!!params && requiredParams.every((param) => param in params);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
hasRequiredParams = !!params;
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
enabled: hasRequiredParams,
|
|
210
|
+
queryKey: endpoint.toQueryKey(params || {}, uniqKey),
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
exports.buildOptionsFromParams = buildOptionsFromParams;
|
|
@@ -0,0 +1,29 @@
|
|
|
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, queryClient: 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
|
+
destroy(): 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
|
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,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,OAAO,IAAI,IAAI;CAOhB;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"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import type { DefaultError, QueryFunctionContext, QueryObserverResult, RefetchOptions } from '@tanstack/query-core';
|
|
3
3
|
import { Query, type QueryUpdateOptionsAllVariants } from 'mobx-tanstack-query';
|
|
4
4
|
import type { AnyObject, Maybe, MaybeFalsy } from 'yummies/utils/types';
|
|
5
|
-
import type { AnyEndpoint } from
|
|
6
|
-
import type { EndpointQueryFlattenOptions, EndpointQueryOptions, EndpointQueryUniqKey, ExcludedQueryKeys } from
|
|
7
|
-
import type { EndpointQueryClient } from
|
|
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
8
|
/**
|
|
9
9
|
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoint-queries/)
|
|
10
10
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
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,WAAW,EAAE,mBAAmB,EAChC,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;IAqLR,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,OAAO,IAAI,IAAI;CAOhB;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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { AnyEndpoint } from "./endpoint.types.cjs";
|
|
5
|
+
export interface EndpointQueryMeta {
|
|
6
|
+
endpointId: string;
|
|
7
|
+
endpointQuery: true;
|
|
8
|
+
tags: string[];
|
|
9
|
+
operationId: string;
|
|
10
|
+
path: string[];
|
|
11
|
+
pathDeclaration: string;
|
|
12
|
+
group?: string;
|
|
13
|
+
namespace?: string;
|
|
14
|
+
}
|
|
15
|
+
export type EndpointQueryUniqKey = Maybe<MaybeFn<string | number | AnyObject | boolean>>;
|
|
16
|
+
export type ExcludedQueryKeys = 'options' | 'queryFn' | 'queryClient' | 'queryKey' | '_defaulted' | '_optimisticResults' | 'experimental_prefetchInRender' | 'enabled' | 'queryHash' | 'queryKeyHashFn';
|
|
17
|
+
type ShortQueryConfig<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData> = Omit<QueryConfig<TQueryFnData, TError, TData, TQueryData>, ExcludedQueryKeys> & {
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type EndpointQueryFlattenOptions<TEndpoint extends AnyEndpoint, TQueryFnData = TEndpoint['__response']['data'], TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData> = ShortQueryConfig<NoInfer<TQueryFnData>, TError, TData, TQueryData> & {
|
|
21
|
+
uniqKey?: EndpointQueryUniqKey;
|
|
22
|
+
params?: MaybeFalsy<TEndpoint['__params']>;
|
|
23
|
+
/**
|
|
24
|
+
* Transform response to QueryFnData
|
|
25
|
+
*/
|
|
26
|
+
transform?: (response: TEndpoint['__response']) => TQueryFnData | Promise<TQueryFnData>;
|
|
27
|
+
};
|
|
28
|
+
export type EndpointQueryOptions<TEndpoint extends AnyEndpoint, TQueryFnData = TEndpoint['__response']['data'], TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData> = ShortQueryConfig<NoInfer<TQueryFnData>, TError, TData, TQueryData> & {
|
|
29
|
+
uniqKey?: EndpointQueryUniqKey;
|
|
30
|
+
params?: MaybeFn<MaybeFalsy<TEndpoint['__params']>, []>;
|
|
31
|
+
/**
|
|
32
|
+
* Transform response to QueryFnData
|
|
33
|
+
*/
|
|
34
|
+
transform?: (response: TEndpoint['__response']) => TQueryFnData | Promise<TQueryFnData>;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=endpoint-query.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-query.types.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,UAAU,EACV,OAAO,EACR,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,WAAW,EAAE,6BAA4B;AAEvD,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG,KAAK,CACtC,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,CAC/C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,SAAS,GACT,aAAa,GACb,UAAU,GACV,YAAY,GACZ,oBAAoB,GACpB,+BAA+B,GAC/B,SAAS,GACT,WAAW,GACX,gBAAgB,CAAC;AAErB,KAAK,gBAAgB,CACnB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,UAAU,GAAG,YAAY,IACvB,IAAI,CACN,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,EACpD,iBAAiB,CAClB,GAAG;IACF,OAAO,CAAC,E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|
|
3
3
|
import type { AnyObject, Maybe, MaybeFalsy, MaybeFn } from 'yummies/utils/types';
|
|
4
|
-
import type { AnyEndpoint } from
|
|
4
|
+
import type { AnyEndpoint } from "./endpoint.types.js";
|
|
5
5
|
export interface EndpointQueryMeta {
|
|
6
6
|
endpointId: string;
|
|
7
7
|
endpointQuery: true;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-query.types.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,UAAU,EACV,OAAO,EACR,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,WAAW,EAAE,4BAA4B;AAEvD,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG,KAAK,CACtC,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,CAC/C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,SAAS,GACT,aAAa,GACb,UAAU,GACV,YAAY,GACZ,oBAAoB,GACpB,+BAA+B,GAC/B,SAAS,GACT,WAAW,GACX,gBAAgB,CAAC;AAErB,KAAK,gBAAgB,CACnB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY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CAAC,YAAY,CAAC,CAAC;CAC3C,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Endpoint = void 0;
|
|
4
|
+
const common_1 = require("yummies/common");
|
|
5
|
+
const endpoint_infinite_query_js_1 = require("./endpoint-infinite-query.cjs");
|
|
6
|
+
const endpoint_mutation_js_1 = require("./endpoint-mutation.cjs");
|
|
7
|
+
const endpoint_query_js_1 = require("./endpoint-query.cjs");
|
|
8
|
+
/**
|
|
9
|
+
* This class is a wrapper for your http request.
|
|
10
|
+
*
|
|
11
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/)
|
|
12
|
+
*/
|
|
13
|
+
class Endpoint {
|
|
14
|
+
configuration;
|
|
15
|
+
queryClient;
|
|
16
|
+
httpClient;
|
|
17
|
+
endpointId;
|
|
18
|
+
presets = {
|
|
19
|
+
mutations: {},
|
|
20
|
+
};
|
|
21
|
+
__params;
|
|
22
|
+
__response;
|
|
23
|
+
meta;
|
|
24
|
+
constructor(configuration, queryClient, httpClient) {
|
|
25
|
+
this.configuration = configuration;
|
|
26
|
+
this.queryClient = queryClient;
|
|
27
|
+
this.httpClient = httpClient;
|
|
28
|
+
this.endpointId = globalThis.crypto.randomUUID();
|
|
29
|
+
this.meta = configuration.meta ?? {};
|
|
30
|
+
// Сохраняем оригинальный инстанс
|
|
31
|
+
const instance = this;
|
|
32
|
+
// Создаем функцию-обертку
|
|
33
|
+
const callable = function (...args) {
|
|
34
|
+
return instance.request.apply(instance, args);
|
|
35
|
+
};
|
|
36
|
+
// Копируем прототип
|
|
37
|
+
Object.setPrototypeOf(callable, new.target.prototype);
|
|
38
|
+
// Копируем методы из оригинального инстанса
|
|
39
|
+
Object.getOwnPropertyNames(instance)
|
|
40
|
+
.concat(Object.getOwnPropertyNames(new.target.prototype))
|
|
41
|
+
.forEach((key) => {
|
|
42
|
+
if (key === 'constructor')
|
|
43
|
+
return;
|
|
44
|
+
const desc = Object.getOwnPropertyDescriptor(instance, key) ||
|
|
45
|
+
Object.getOwnPropertyDescriptor(new.target.prototype, key);
|
|
46
|
+
if (desc)
|
|
47
|
+
Object.defineProperty(callable, key, desc);
|
|
48
|
+
});
|
|
49
|
+
// biome-ignore lint/correctness/noConstructorReturn: this is special trick to add typings for callable class instance
|
|
50
|
+
return callable;
|
|
51
|
+
}
|
|
52
|
+
getFullUrl(...args) {
|
|
53
|
+
const params = this.configuration.params(args[0] ?? {});
|
|
54
|
+
return this.httpClient.buildUrl(params);
|
|
55
|
+
}
|
|
56
|
+
getPath(...args) {
|
|
57
|
+
const params = this.configuration.params(args[0] ?? {});
|
|
58
|
+
return params.path;
|
|
59
|
+
}
|
|
60
|
+
get tags() {
|
|
61
|
+
return this.configuration.tags;
|
|
62
|
+
}
|
|
63
|
+
get path() {
|
|
64
|
+
return this.configuration.path;
|
|
65
|
+
}
|
|
66
|
+
get pathDeclaration() {
|
|
67
|
+
return this.path.join('/');
|
|
68
|
+
}
|
|
69
|
+
get operationId() {
|
|
70
|
+
return this.configuration.operationId;
|
|
71
|
+
}
|
|
72
|
+
get group() {
|
|
73
|
+
return this.configuration.group;
|
|
74
|
+
}
|
|
75
|
+
get namespace() {
|
|
76
|
+
return this.configuration.namespace;
|
|
77
|
+
}
|
|
78
|
+
request(...args) {
|
|
79
|
+
return this.httpClient.request(this.configuration.params(args[0] ?? {}));
|
|
80
|
+
}
|
|
81
|
+
toQueryMeta = (meta) => ({
|
|
82
|
+
...meta,
|
|
83
|
+
tags: this.tags,
|
|
84
|
+
operationId: this.operationId,
|
|
85
|
+
path: this.path,
|
|
86
|
+
pathDeclaration: this.pathDeclaration,
|
|
87
|
+
endpointId: this.endpointId,
|
|
88
|
+
endpointQuery: true,
|
|
89
|
+
});
|
|
90
|
+
toQueryKey(params, uniqKey) {
|
|
91
|
+
return [
|
|
92
|
+
...this.configuration.path,
|
|
93
|
+
this.configuration.operationId,
|
|
94
|
+
params ?? {},
|
|
95
|
+
(0, common_1.callFunction)(uniqKey),
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
toInfiniteQueryKey(params, uniqKey) {
|
|
99
|
+
return [
|
|
100
|
+
{ infiniteQuery: true },
|
|
101
|
+
...this.configuration.path,
|
|
102
|
+
this.configuration.operationId,
|
|
103
|
+
params ?? {},
|
|
104
|
+
(0, common_1.callFunction)(uniqKey),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
invalidateQuery(...args) {
|
|
108
|
+
this.queryClient.invalidateQueries({
|
|
109
|
+
queryKey: this.toQueryKey(args[0], args[1]?.uniqKey),
|
|
110
|
+
exact: true,
|
|
111
|
+
...args[1],
|
|
112
|
+
}, args[2]);
|
|
113
|
+
}
|
|
114
|
+
toMutation(options) {
|
|
115
|
+
return new endpoint_mutation_js_1.EndpointMutation(this, this.queryClient, {
|
|
116
|
+
...options,
|
|
117
|
+
invalidateEndpoints: options.invalidateEndpoints ??
|
|
118
|
+
this.presets.mutations?.invalidateQueries,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
toQuery(options) {
|
|
122
|
+
return new endpoint_query_js_1.EndpointQuery(this, this.queryClient, options);
|
|
123
|
+
}
|
|
124
|
+
toInfiniteQuery(options) {
|
|
125
|
+
return new endpoint_infinite_query_js_1.EndpointInfiniteQuery(this, this.queryClient, options);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.Endpoint = Endpoint;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** biome-ignore-all lint/style/useShorthandFunctionType: this is special trick to add typings for callable class instance */
|
|
2
|
+
import type { DefaultError, InvalidateOptions, InvalidateQueryFilters } from '@tanstack/query-core';
|
|
3
|
+
import type { AnyObject, IsPartial, Maybe } from 'yummies/utils/types';
|
|
4
|
+
import type { EndpointConfiguration, EndpointMutationPresets } from "./endpoint.types.cjs";
|
|
5
|
+
import { EndpointInfiniteQuery } from "./endpoint-infinite-query.cjs";
|
|
6
|
+
import type { EndpointInfiniteQueryFlattenOptions, EndpointInfiniteQueryOptions } from "./endpoint-infinite-query.types.cjs";
|
|
7
|
+
import { EndpointMutation } from "./endpoint-mutation.cjs";
|
|
8
|
+
import type { EndpointMutationOptions } from "./endpoint-mutation.types.cjs";
|
|
9
|
+
import { EndpointQuery } from "./endpoint-query.cjs";
|
|
10
|
+
import type { EndpointQueryFlattenOptions, EndpointQueryOptions, EndpointQueryUniqKey } from "./endpoint-query.types.cjs";
|
|
11
|
+
import type { EndpointQueryClient } from "./endpoint-query-client.cjs";
|
|
12
|
+
import type { HttpClient, HttpResponse } from "./http-client.cjs";
|
|
13
|
+
export interface Endpoint<TResponse extends HttpResponse<any, any>, TParams extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
14
|
+
(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>] : [params: TParams]): ReturnType<Endpoint<TResponse, TParams, TMetaData>['request']>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* This class is a wrapper for your http request.
|
|
18
|
+
*
|
|
19
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/endpoints/)
|
|
20
|
+
*/
|
|
21
|
+
export declare class Endpoint<TResponse extends HttpResponse<any, any>, TParams extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
22
|
+
configuration: EndpointConfiguration<NoInfer<TParams>, TMetaData>;
|
|
23
|
+
queryClient: EndpointQueryClient;
|
|
24
|
+
httpClient: HttpClient;
|
|
25
|
+
endpointId: string;
|
|
26
|
+
presets: {
|
|
27
|
+
mutations: EndpointMutationPresets;
|
|
28
|
+
};
|
|
29
|
+
__params: TParams;
|
|
30
|
+
__response: TResponse;
|
|
31
|
+
meta: TMetaData;
|
|
32
|
+
constructor(configuration: EndpointConfiguration<NoInfer<TParams>, TMetaData>, queryClient: EndpointQueryClient, httpClient: HttpClient);
|
|
33
|
+
getFullUrl(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>] : [params: TParams]): string;
|
|
34
|
+
getPath(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>] : [params: TParams]): string;
|
|
35
|
+
get tags(): string[];
|
|
36
|
+
get path(): string[];
|
|
37
|
+
get pathDeclaration(): string;
|
|
38
|
+
get operationId(): string;
|
|
39
|
+
get group(): string | undefined;
|
|
40
|
+
get namespace(): string | undefined;
|
|
41
|
+
request(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>] : [params: TParams]): Promise<TResponse>;
|
|
42
|
+
toQueryMeta: (meta?: AnyObject) => {
|
|
43
|
+
tags: string[];
|
|
44
|
+
operationId: string;
|
|
45
|
+
path: string[];
|
|
46
|
+
pathDeclaration: string;
|
|
47
|
+
endpointId: string;
|
|
48
|
+
endpointQuery: true;
|
|
49
|
+
};
|
|
50
|
+
toQueryKey(params?: Maybe<TParams>, uniqKey?: EndpointQueryUniqKey): any;
|
|
51
|
+
toInfiniteQueryKey(params?: Maybe<TParams>, uniqKey?: EndpointQueryUniqKey): any;
|
|
52
|
+
invalidateQuery(...args: IsPartial<TParams> extends true ? [
|
|
53
|
+
params?: Maybe<TParams>,
|
|
54
|
+
filters?: InvalidateQueryFilters & {
|
|
55
|
+
uniqKey?: EndpointQueryUniqKey;
|
|
56
|
+
},
|
|
57
|
+
options?: InvalidateOptions
|
|
58
|
+
] : [
|
|
59
|
+
params: TParams,
|
|
60
|
+
filters?: InvalidateQueryFilters & {
|
|
61
|
+
uniqKey?: EndpointQueryUniqKey;
|
|
62
|
+
},
|
|
63
|
+
options?: InvalidateOptions
|
|
64
|
+
]): void;
|
|
65
|
+
toMutation<TData = TResponse['data'], TMutationMeta extends AnyObject | void = void, TContext = unknown>(options: EndpointMutationOptions<this, TData, TParams, TMutationMeta, TContext>): EndpointMutation<this, TData, TParams, TMutationMeta, TContext>;
|
|
66
|
+
toQuery<TQueryFnData = TResponse['data'], TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData>(options: EndpointQueryOptions<this, TQueryFnData, TError, TData, TQueryData> | (() => EndpointQueryFlattenOptions<this, TQueryFnData, TError, TData, TQueryData>)): EndpointQuery<this, TQueryFnData, TError, TData, TQueryData>;
|
|
67
|
+
toInfiniteQuery<TData = TResponse['data'], TError = DefaultError, TPageParam = unknown>(options: EndpointInfiniteQueryOptions<this, TData, TError, TPageParam> | (() => EndpointInfiniteQueryFlattenOptions<this, TData, TError, TPageParam>)): EndpointInfiniteQuery<this, TData, TError, TPageParam, import("@tanstack/query-core").InfiniteData<TData, TPageParam>>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAC7H,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACxB,6BAA4B;AAC7B,OAAO,EAAE,qBAAqB,EAAE,sCAAqC;AACrE,OAAO,KAAK,EACV,mCAAmC,EACnC,4BAA4B,EAC7B,4CAA2C;AAC5C,OAAO,EAAE,gBAAgB,EAAE,gCAA+B;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAqC;AAC5E,OAAO,EAAE,aAAa,EAAE,6BAA4B;AACpD,OAAO,KAAK,EACV,2BAA2B,EAE3B,oBAAoB,EACpB,oBAAoB,EACrB,mCAAkC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAmC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,0BAAyB;AAEjE,MAAM,WAAW,QAAQ,CACvB,SAAS,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EACxC,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,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,EAChC,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,UAAU,GAAG,YAAY,EAEzB,OAAO,EACH,oBAAoB,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,GACnE,CAAC,MAAM,2BAA2B,CAChC,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,CACX,CAAC;IASR,eAAe,CACb,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,EACzB,MAAM,GAAG,YAAY,EACrB,UAAU,GAAG,OAAO,EAEpB,OAAO,EACH,4BAA4B,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,GAC7D,CAAC,MAAM,mCAAmC,CACxC,IAAI,EACJ,KAAK,EACL,MAAM,EACN,UAAU,CACX,CAAC;CAQT"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/** biome-ignore-all lint/style/useShorthandFunctionType: this is special trick to add typings for callable class instance */
|
|
2
2
|
import type { DefaultError, InvalidateOptions, InvalidateQueryFilters } from '@tanstack/query-core';
|
|
3
3
|
import type { AnyObject, IsPartial, Maybe } from 'yummies/utils/types';
|
|
4
|
-
import type { EndpointConfiguration, EndpointMutationPresets } from
|
|
5
|
-
import { EndpointInfiniteQuery } from
|
|
6
|
-
import type { EndpointInfiniteQueryFlattenOptions, EndpointInfiniteQueryOptions } from
|
|
7
|
-
import { EndpointMutation } from
|
|
8
|
-
import type { EndpointMutationOptions } from
|
|
9
|
-
import { EndpointQuery } from
|
|
10
|
-
import type { EndpointQueryFlattenOptions, EndpointQueryOptions, EndpointQueryUniqKey } from
|
|
11
|
-
import type { EndpointQueryClient } from
|
|
12
|
-
import type { HttpClient, HttpResponse } from
|
|
4
|
+
import type { EndpointConfiguration, EndpointMutationPresets } from "./endpoint.types.js";
|
|
5
|
+
import { EndpointInfiniteQuery } from "./endpoint-infinite-query.js";
|
|
6
|
+
import type { EndpointInfiniteQueryFlattenOptions, EndpointInfiniteQueryOptions } from "./endpoint-infinite-query.types.js";
|
|
7
|
+
import { EndpointMutation } from "./endpoint-mutation.js";
|
|
8
|
+
import type { EndpointMutationOptions } from "./endpoint-mutation.types.js";
|
|
9
|
+
import { EndpointQuery } from "./endpoint-query.js";
|
|
10
|
+
import type { EndpointQueryFlattenOptions, EndpointQueryOptions, EndpointQueryUniqKey } from "./endpoint-query.types.js";
|
|
11
|
+
import type { EndpointQueryClient } from "./endpoint-query-client.js";
|
|
12
|
+
import type { HttpClient, HttpResponse } from "./http-client.js";
|
|
13
13
|
export interface Endpoint<TResponse extends HttpResponse<any, any>, TParams extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
14
14
|
(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>] : [params: TParams]): ReturnType<Endpoint<TResponse, TParams, TMetaData>['request']>;
|
|
15
15
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAC7H,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACxB,4BAA4B;AAC7B,OAAO,EAAE,qBAAqB,EAAE,qCAAqC;AACrE,OAAO,KAAK,EACV,mCAAmC,EACnC,4BAA4B,EAC7B,2CAA2C;AAC5C,OAAO,EAAE,gBAAgB,EAAE,+BAA+B;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,qCAAqC;AAC5E,OAAO,EAAE,aAAa,EAAE,4BAA4B;AACpD,OAAO,KAAK,EACV,2BAA2B,EAE3B,oBAAoB,EACpB,oBAAoB,EAC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AS,CAAC,MAAM,CAAC,EACzB,aAAa,SAAS,SAAS,GAAG,IAAI,GAAG,IAAI,EAC7C,QAAQ,GAAG,OAAO,EAElB,OAAO,EAAE,uBAAuB,CAC9B,IAAI,EACJ,KAAK,EACL,OAAO,EACP,aAAa,EACb,QAAQ,CACT;IAcH,OAAO,CACL,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,EAChC,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,UAAU,GAAG,YAAY,EAEzB,OAAO,EACH,oBAAoB,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,GACnE,CAAC,MAAM,2BAA2B,CAChC,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,CACX,CAAC;IASR,eAAe,CACb,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,EACzB,MAAM,GAAG,YAAY,EACrB,UAAU,GAAG,OAAO,EAEpB,OAAO,EACH,4BAA4B,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,GAC7D,CAAC,MAAM,mCAAmC,CACxC,IAAI,EACJ,KAAK,EACL,MAAM,EACN,UAAU,CACX,CAAC;CAQT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { callFunction } from 'yummies/common';
|
|
2
|
-
import { EndpointInfiniteQuery } from
|
|
3
|
-
import { EndpointMutation } from
|
|
4
|
-
import { EndpointQuery } from
|
|
2
|
+
import { EndpointInfiniteQuery } from "./endpoint-infinite-query.js";
|
|
3
|
+
import { EndpointMutation } from "./endpoint-mutation.js";
|
|
4
|
+
import { EndpointQuery } from "./endpoint-query.js";
|
|
5
5
|
/**
|
|
6
6
|
* This class is a wrapper for your http request.
|
|
7
7
|
*
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AnyObject } from 'yummies/utils/types';
|
|
2
|
+
import type { Endpoint } from "./endpoint.cjs";
|
|
3
|
+
import type { InvalidateEndpointsFilters } from "./endpoint-query-client.types.cjs";
|
|
4
|
+
import type { FullRequestParams } from "./http-client.cjs";
|
|
5
|
+
export interface EndpointConfiguration<TInput extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
6
|
+
group?: string;
|
|
7
|
+
namespace?: string;
|
|
8
|
+
operationId: string;
|
|
9
|
+
path: string[];
|
|
10
|
+
meta?: TMetaData;
|
|
11
|
+
requiredParams: string[];
|
|
12
|
+
params: (input: Partial<TInput>) => FullRequestParams;
|
|
13
|
+
tags: string[];
|
|
14
|
+
}
|
|
15
|
+
export type AnyEndpoint = Endpoint<any, any, any>;
|
|
16
|
+
export type InferEndpointData<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<infer T, any, any> ? T : never;
|
|
17
|
+
export type InferEndpointResponse<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<infer T, any, any> ? T : never;
|
|
18
|
+
export type InferEndpointInput<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<any, infer T, any> ? T : never;
|
|
19
|
+
export type InferEndpointMetaData<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<any, any, infer T> ? T : never;
|
|
20
|
+
export interface EndpointMutationPresets {
|
|
21
|
+
invalidateQueries?: InvalidateEndpointsFilters;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=endpoint.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.types.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,uBAAsB;AAC9C,OAAO,KAAK,EAAE,0BAA0B,EAAE,0CAAyC;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAyB;AAE1D,MAAM,WAAW,qBAAqB,CACpC,MAAM,SAAS,SAAS,EACxB,SAAS,SAAS,SAA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
import type { InvalidateEndpointsFilters } from
|
|
4
|
-
import type { FullRequestParams } from
|
|
2
|
+
import type { Endpoint } from "./endpoint.js";
|
|
3
|
+
import type { InvalidateEndpointsFilters } from "./endpoint-query-client.types.js";
|
|
4
|
+
import type { FullRequestParams } from "./http-client.js";
|
|
5
5
|
export interface EndpointConfiguration<TInput extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
6
6
|
group?: string;
|
|
7
7
|
namespace?: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.types.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB;AAC9C,OAAO,KAAK,EAAE,0BAA0B,EAAE,yCAAyC;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB;AAE1D,MAAM,WAAW,qBAAqB,CACpC,MAAM,SAAS,SAAS,EACxB,SAAS,SAAS,SAAS,GAAG,SAAS;IAEvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,iBAAiB,CAAC;IACtD,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAElD,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,WAAW,IACzD,SAAS,SAAS,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,C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