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.
- package/builtin.cjs +27 -0
- package/builtin.cjs.map +1 -0
- package/builtin.d.ts +6 -0
- package/builtin.js +27 -0
- package/builtin.js.map +1 -0
- package/cli.cjs +1279 -0
- package/cli.cjs.map +1 -0
- package/{codegen/types/generate-query-api-params.d.cts → cli.d.ts} +55 -10
- package/cli.js +1278 -0
- package/cli.js.map +1 -0
- package/index.cjs +771 -16
- package/index.cjs.map +1 -0
- package/index.d.ts +322 -2
- package/index.js +768 -2
- package/index.js.map +1 -0
- package/package.json +21 -64
- package/builtin/index.cjs +0 -25
- package/builtin/index.d.cts +0 -4
- package/builtin/index.d.cts.map +0 -1
- package/builtin/index.d.ts +0 -4
- package/builtin/index.d.ts.map +0 -1
- package/builtin/index.js +0 -22
- package/cli/bin.cjs +0 -17
- package/cli/bin.d.cts +0 -2
- package/cli/bin.d.cts.map +0 -1
- package/cli/bin.d.ts +0 -2
- package/cli/bin.d.ts.map +0 -1
- package/cli/bin.js +0 -15
- package/cli/index.cjs +0 -18
- package/cli/index.d.cts +0 -3
- package/cli/index.d.cts.map +0 -1
- package/cli/index.d.ts +0 -3
- package/cli/index.d.ts.map +0 -1
- package/cli/index.js +0 -2
- package/cli/utils/define-config.cjs +0 -9
- package/cli/utils/define-config.d.cts +0 -4
- package/cli/utils/define-config.d.cts.map +0 -1
- package/cli/utils/define-config.d.ts +0 -4
- package/cli/utils/define-config.d.ts.map +0 -1
- package/cli/utils/define-config.js +0 -5
- package/cli/utils/exec-config-path.cjs +0 -16
- package/cli/utils/exec-config-path.d.cts +0 -2
- package/cli/utils/exec-config-path.d.cts.map +0 -1
- package/cli/utils/exec-config-path.d.ts +0 -2
- package/cli/utils/exec-config-path.d.ts.map +0 -1
- package/cli/utils/exec-config-path.js +0 -12
- package/cli/utils/resolve-config-path.cjs +0 -65
- package/cli/utils/resolve-config-path.d.cts +0 -3
- package/cli/utils/resolve-config-path.d.cts.map +0 -1
- package/cli/utils/resolve-config-path.d.ts +0 -3
- package/cli/utils/resolve-config-path.d.ts.map +0 -1
- package/cli/utils/resolve-config-path.js +0 -25
- package/codegen/index.cjs +0 -545
- package/codegen/index.d.cts +0 -4
- package/codegen/index.d.cts.map +0 -1
- package/codegen/index.d.ts +0 -4
- package/codegen/index.d.ts.map +0 -1
- package/codegen/index.js +0 -524
- package/codegen/templates/all-endpoints-per-file.tmpl.cjs +0 -94
- package/codegen/templates/all-endpoints-per-file.tmpl.d.cts +0 -14
- package/codegen/templates/all-endpoints-per-file.tmpl.d.cts.map +0 -1
- package/codegen/templates/all-endpoints-per-file.tmpl.d.ts +0 -14
- package/codegen/templates/all-endpoints-per-file.tmpl.d.ts.map +0 -1
- package/codegen/templates/all-endpoints-per-file.tmpl.js +0 -90
- package/codegen/templates/all-exports.tmpl.cjs +0 -14
- package/codegen/templates/all-exports.tmpl.d.cts +0 -9
- package/codegen/templates/all-exports.tmpl.d.cts.map +0 -1
- package/codegen/templates/all-exports.tmpl.d.ts +0 -9
- package/codegen/templates/all-exports.tmpl.d.ts.map +0 -1
- package/codegen/templates/all-exports.tmpl.js +0 -9
- package/codegen/templates/constants.cjs +0 -5
- package/codegen/templates/constants.d.cts +0 -2
- package/codegen/templates/constants.d.cts.map +0 -1
- package/codegen/templates/constants.d.ts +0 -2
- package/codegen/templates/constants.d.ts.map +0 -1
- package/codegen/templates/constants.js +0 -2
- package/codegen/templates/data-contract.tmpl.cjs +0 -49
- package/codegen/templates/data-contract.tmpl.d.cts +0 -8
- package/codegen/templates/data-contract.tmpl.d.cts.map +0 -1
- package/codegen/templates/data-contract.tmpl.d.ts +0 -8
- package/codegen/templates/data-contract.tmpl.d.ts.map +0 -1
- package/codegen/templates/data-contract.tmpl.js +0 -45
- package/codegen/templates/data-contracts-file.tmpl.cjs +0 -27
- package/codegen/templates/data-contracts-file.tmpl.d.cts +0 -6
- package/codegen/templates/data-contracts-file.tmpl.d.cts.map +0 -1
- package/codegen/templates/data-contracts-file.tmpl.d.ts +0 -6
- package/codegen/templates/data-contracts-file.tmpl.d.ts.map +0 -1
- package/codegen/templates/data-contracts-file.tmpl.js +0 -23
- package/codegen/templates/endpoint-jsdoc.tmpl.cjs +0 -111
- package/codegen/templates/endpoint-jsdoc.tmpl.d.cts +0 -8
- package/codegen/templates/endpoint-jsdoc.tmpl.d.cts.map +0 -1
- package/codegen/templates/endpoint-jsdoc.tmpl.d.ts +0 -8
- package/codegen/templates/endpoint-jsdoc.tmpl.d.ts.map +0 -1
- package/codegen/templates/endpoint-jsdoc.tmpl.js +0 -107
- package/codegen/templates/endpoint-per-file.tmpl.cjs +0 -87
- package/codegen/templates/endpoint-per-file.tmpl.d.cts +0 -14
- package/codegen/templates/endpoint-per-file.tmpl.d.cts.map +0 -1
- package/codegen/templates/endpoint-per-file.tmpl.d.ts +0 -14
- package/codegen/templates/endpoint-per-file.tmpl.d.ts.map +0 -1
- package/codegen/templates/endpoint-per-file.tmpl.js +0 -83
- package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.cjs +0 -10
- package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts +0 -6
- package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts.map +0 -1
- package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts +0 -6
- package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts.map +0 -1
- package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.js +0 -6
- package/codegen/templates/meta-info.tmpl.cjs +0 -48
- package/codegen/templates/meta-info.tmpl.d.cts +0 -9
- package/codegen/templates/meta-info.tmpl.d.cts.map +0 -1
- package/codegen/templates/meta-info.tmpl.d.ts +0 -9
- package/codegen/templates/meta-info.tmpl.d.ts.map +0 -1
- package/codegen/templates/meta-info.tmpl.js +0 -42
- package/codegen/templates/new-endpoint.tmpl.cjs +0 -188
- package/codegen/templates/new-endpoint.tmpl.d.cts +0 -15
- package/codegen/templates/new-endpoint.tmpl.d.cts.map +0 -1
- package/codegen/templates/new-endpoint.tmpl.d.ts +0 -15
- package/codegen/templates/new-endpoint.tmpl.d.ts.map +0 -1
- package/codegen/templates/new-endpoint.tmpl.js +0 -184
- package/codegen/types/all-import-file-params.cjs +0 -2
- package/codegen/types/all-import-file-params.d.cts +0 -5
- package/codegen/types/all-import-file-params.d.cts.map +0 -1
- package/codegen/types/all-import-file-params.d.ts +0 -5
- package/codegen/types/all-import-file-params.d.ts.map +0 -1
- package/codegen/types/all-import-file-params.js +0 -1
- package/codegen/types/base-tmpl-params.cjs +0 -2
- package/codegen/types/base-tmpl-params.d.cts +0 -16
- package/codegen/types/base-tmpl-params.d.cts.map +0 -1
- package/codegen/types/base-tmpl-params.d.ts +0 -16
- package/codegen/types/base-tmpl-params.d.ts.map +0 -1
- package/codegen/types/base-tmpl-params.js +0 -1
- package/codegen/types/codegen-data-utils.cjs +0 -2
- package/codegen/types/codegen-data-utils.d.cts +0 -8
- package/codegen/types/codegen-data-utils.d.cts.map +0 -1
- package/codegen/types/codegen-data-utils.d.ts +0 -8
- package/codegen/types/codegen-data-utils.d.ts.map +0 -1
- package/codegen/types/codegen-data-utils.js +0 -1
- package/codegen/types/endpoint-data.cjs +0 -2
- package/codegen/types/endpoint-data.d.cts +0 -3
- package/codegen/types/endpoint-data.d.cts.map +0 -1
- package/codegen/types/endpoint-data.d.ts +0 -3
- package/codegen/types/endpoint-data.d.ts.map +0 -1
- package/codegen/types/endpoint-data.js +0 -1
- package/codegen/types/generate-query-api-params.cjs +0 -2
- package/codegen/types/generate-query-api-params.d.cts.map +0 -1
- package/codegen/types/generate-query-api-params.d.ts +0 -162
- package/codegen/types/generate-query-api-params.d.ts.map +0 -1
- package/codegen/types/generate-query-api-params.js +0 -1
- package/codegen/types/import-file-params.cjs +0 -2
- package/codegen/types/import-file-params.d.cts +0 -5
- package/codegen/types/import-file-params.d.cts.map +0 -1
- package/codegen/types/import-file-params.d.ts +0 -5
- package/codegen/types/import-file-params.d.ts.map +0 -1
- package/codegen/types/import-file-params.js +0 -1
- package/codegen/types/index.cjs +0 -23
- package/codegen/types/index.d.cts +0 -8
- package/codegen/types/index.d.cts.map +0 -1
- package/codegen/types/index.d.ts +0 -8
- package/codegen/types/index.d.ts.map +0 -1
- package/codegen/types/index.js +0 -7
- package/codegen/types/meta-info.cjs +0 -2
- package/codegen/types/meta-info.d.cts +0 -6
- package/codegen/types/meta-info.d.cts.map +0 -1
- package/codegen/types/meta-info.d.ts +0 -6
- package/codegen/types/meta-info.d.ts.map +0 -1
- package/codegen/types/meta-info.js +0 -1
- package/codegen/types/type-info.cjs +0 -2
- package/codegen/types/type-info.d.cts +0 -4
- package/codegen/types/type-info.d.cts.map +0 -1
- package/codegen/types/type-info.d.ts +0 -4
- package/codegen/types/type-info.d.ts.map +0 -1
- package/codegen/types/type-info.js +0 -1
- package/codegen/utils/create-short-model-type.cjs +0 -12
- package/codegen/utils/create-short-model-type.d.cts +0 -5
- package/codegen/utils/create-short-model-type.d.cts.map +0 -1
- package/codegen/utils/create-short-model-type.d.ts +0 -5
- package/codegen/utils/create-short-model-type.d.ts.map +0 -1
- package/codegen/utils/create-short-model-type.js +0 -8
- package/codegen/utils/remove-unused-types.cjs +0 -117
- package/codegen/utils/remove-unused-types.d.cts +0 -7
- package/codegen/utils/remove-unused-types.d.cts.map +0 -1
- package/codegen/utils/remove-unused-types.d.ts +0 -7
- package/codegen/utils/remove-unused-types.d.ts.map +0 -1
- package/codegen/utils/remove-unused-types.js +0 -110
- package/codegen/utils/unpack-filter-option.cjs +0 -23
- package/codegen/utils/unpack-filter-option.d.cts +0 -7
- package/codegen/utils/unpack-filter-option.d.cts.map +0 -1
- package/codegen/utils/unpack-filter-option.d.ts +0 -7
- package/codegen/utils/unpack-filter-option.d.ts.map +0 -1
- package/codegen/utils/unpack-filter-option.js +0 -19
- package/index.d.cts +0 -3
- package/index.d.cts.map +0 -1
- package/index.d.ts.map +0 -1
- package/runtime/endpoint-infinite-query.cjs +0 -101
- package/runtime/endpoint-infinite-query.d.cts +0 -17
- package/runtime/endpoint-infinite-query.d.cts.map +0 -1
- package/runtime/endpoint-infinite-query.d.ts +0 -17
- package/runtime/endpoint-infinite-query.d.ts.map +0 -1
- package/runtime/endpoint-infinite-query.js +0 -97
- package/runtime/endpoint-infinite-query.types.cjs +0 -2
- package/runtime/endpoint-infinite-query.types.d.cts +0 -30
- package/runtime/endpoint-infinite-query.types.d.cts.map +0 -1
- package/runtime/endpoint-infinite-query.types.d.ts +0 -30
- package/runtime/endpoint-infinite-query.types.d.ts.map +0 -1
- package/runtime/endpoint-infinite-query.types.js +0 -1
- package/runtime/endpoint-mutation.cjs +0 -74
- package/runtime/endpoint-mutation.d.cts +0 -13
- package/runtime/endpoint-mutation.d.cts.map +0 -1
- package/runtime/endpoint-mutation.d.ts +0 -13
- package/runtime/endpoint-mutation.d.ts.map +0 -1
- package/runtime/endpoint-mutation.js +0 -70
- package/runtime/endpoint-mutation.types.cjs +0 -2
- package/runtime/endpoint-mutation.types.d.cts +0 -36
- package/runtime/endpoint-mutation.types.d.cts.map +0 -1
- package/runtime/endpoint-mutation.types.d.ts +0 -36
- package/runtime/endpoint-mutation.types.d.ts.map +0 -1
- package/runtime/endpoint-mutation.types.js +0 -1
- package/runtime/endpoint-query-client.cjs +0 -79
- package/runtime/endpoint-query-client.d.cts +0 -13
- package/runtime/endpoint-query-client.d.cts.map +0 -1
- package/runtime/endpoint-query-client.d.ts +0 -13
- package/runtime/endpoint-query-client.d.ts.map +0 -1
- package/runtime/endpoint-query-client.js +0 -75
- package/runtime/endpoint-query-client.types.cjs +0 -2
- package/runtime/endpoint-query-client.types.d.cts +0 -16
- package/runtime/endpoint-query-client.types.d.cts.map +0 -1
- package/runtime/endpoint-query-client.types.d.ts +0 -16
- package/runtime/endpoint-query-client.types.d.ts.map +0 -1
- package/runtime/endpoint-query-client.types.js +0 -1
- package/runtime/endpoint-query.cjs +0 -214
- package/runtime/endpoint-query.d.cts +0 -29
- package/runtime/endpoint-query.d.cts.map +0 -1
- package/runtime/endpoint-query.d.ts +0 -29
- package/runtime/endpoint-query.d.ts.map +0 -1
- package/runtime/endpoint-query.js +0 -208
- package/runtime/endpoint-query.types.cjs +0 -2
- package/runtime/endpoint-query.types.d.cts +0 -42
- package/runtime/endpoint-query.types.d.cts.map +0 -1
- package/runtime/endpoint-query.types.d.ts +0 -42
- package/runtime/endpoint-query.types.d.ts.map +0 -1
- package/runtime/endpoint-query.types.js +0 -1
- package/runtime/endpoint.cjs +0 -131
- package/runtime/endpoint.d.cts +0 -73
- package/runtime/endpoint.d.cts.map +0 -1
- package/runtime/endpoint.d.ts +0 -73
- package/runtime/endpoint.d.ts.map +0 -1
- package/runtime/endpoint.js +0 -127
- package/runtime/endpoint.types.cjs +0 -2
- package/runtime/endpoint.types.d.cts +0 -24
- package/runtime/endpoint.types.d.cts.map +0 -1
- package/runtime/endpoint.types.d.ts +0 -24
- package/runtime/endpoint.types.d.ts.map +0 -1
- package/runtime/endpoint.types.js +0 -1
- package/runtime/http-client.cjs +0 -190
- package/runtime/http-client.d.cts +0 -85
- package/runtime/http-client.d.cts.map +0 -1
- package/runtime/http-client.d.ts +0 -85
- package/runtime/http-client.d.ts.map +0 -1
- package/runtime/http-client.js +0 -184
- package/runtime/index.cjs +0 -25
- package/runtime/index.d.cts +0 -10
- package/runtime/index.d.cts.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/index.cjs
CHANGED
|
@@ -1,18 +1,773 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const queryCore = require("@tanstack/query-core");
|
|
4
|
+
const common = require("yummies/common");
|
|
5
|
+
const mobx = require("mobx");
|
|
6
|
+
const mobxTanstackQuery = require("mobx-tanstack-query");
|
|
7
|
+
const mobx$1 = require("yummies/mobx");
|
|
8
|
+
const qs = require("qs");
|
|
9
|
+
class EndpointQuery extends mobxTanstackQuery.Query {
|
|
10
|
+
constructor(endpoint, inputQueryClient, queryOptionsInput) {
|
|
11
|
+
const isQueryOptionsInputFn = typeof queryOptionsInput === "function";
|
|
12
|
+
const unpackedQueryOptionsInput = isQueryOptionsInputFn ? queryOptionsInput() : queryOptionsInput;
|
|
13
|
+
const {
|
|
14
|
+
uniqKey,
|
|
15
|
+
transform: transformResponse,
|
|
16
|
+
params,
|
|
17
|
+
queryClient: overridedQueryClient,
|
|
18
|
+
...queryOptions
|
|
19
|
+
} = unpackedQueryOptionsInput;
|
|
20
|
+
const queryClient = overridedQueryClient ?? inputQueryClient;
|
|
21
|
+
const _observableData = {
|
|
22
|
+
params: null,
|
|
23
|
+
dynamicOptions: void 0,
|
|
24
|
+
response: null,
|
|
25
|
+
uniqKey: unpackedQueryOptionsInput.uniqKey
|
|
26
|
+
};
|
|
27
|
+
if (!isQueryOptionsInputFn && typeof params !== "function") {
|
|
28
|
+
if ("params" in unpackedQueryOptionsInput) {
|
|
29
|
+
_observableData.params = params;
|
|
30
|
+
} else {
|
|
31
|
+
_observableData.params = {};
|
|
32
|
+
}
|
|
33
|
+
_observableData.initialized = true;
|
|
34
|
+
}
|
|
35
|
+
mobx.makeObservable(_observableData, {
|
|
36
|
+
params: mobx.observable.ref,
|
|
37
|
+
response: mobx.observable.ref,
|
|
38
|
+
dynamicOptions: mobx.observable
|
|
39
|
+
});
|
|
40
|
+
super({
|
|
41
|
+
...queryOptions,
|
|
42
|
+
queryClient,
|
|
43
|
+
meta: endpoint.toQueryMeta(queryOptions.meta),
|
|
44
|
+
options: () => {
|
|
45
|
+
const builtOptions = buildOptionsFromParams(
|
|
46
|
+
endpoint,
|
|
47
|
+
_observableData.params,
|
|
48
|
+
_observableData.uniqKey
|
|
49
|
+
);
|
|
50
|
+
let isEnabled = !!_observableData.initialized && builtOptions.enabled;
|
|
51
|
+
if (typeof queryOptionsInput !== "function" && queryOptionsInput.enabled === false) {
|
|
52
|
+
isEnabled = false;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
...builtOptions,
|
|
56
|
+
enabled: isEnabled,
|
|
57
|
+
..._observableData.dynamicOptions
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
queryFn: async (ctx) => {
|
|
61
|
+
const params2 = endpoint.getParamsFromContext(ctx);
|
|
62
|
+
mobx.runInAction(() => {
|
|
63
|
+
_observableData.response = null;
|
|
64
|
+
if (!mobx.comparer.structural(params2, _observableData.params)) {
|
|
65
|
+
_observableData.params = params2;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
let requestParams = params2.requestParams;
|
|
69
|
+
if (requestParams) {
|
|
70
|
+
if (!requestParams.signal) {
|
|
71
|
+
requestParams.signal = ctx.signal;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
requestParams = { signal: ctx.signal };
|
|
75
|
+
}
|
|
76
|
+
const fixedInput = {
|
|
77
|
+
...params2,
|
|
78
|
+
requestParams
|
|
79
|
+
};
|
|
80
|
+
const response = await endpoint.request(fixedInput);
|
|
81
|
+
mobx.runInAction(() => {
|
|
82
|
+
_observableData.response = response;
|
|
83
|
+
});
|
|
84
|
+
return await transformResponse?.(response) ?? response.data;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.endpoint = endpoint;
|
|
88
|
+
const parentAtom = mobx$1.getMobxAdministration(this);
|
|
89
|
+
mobx.computed.struct(this, "params");
|
|
90
|
+
mobx.computed.struct(this, "response");
|
|
91
|
+
mobx.makeObservable(this);
|
|
92
|
+
if (isQueryOptionsInputFn || typeof params === "function") {
|
|
93
|
+
const createParamsReaction = () => mobx.reaction(
|
|
94
|
+
() => {
|
|
95
|
+
let outDynamicOptions;
|
|
96
|
+
let outParams;
|
|
97
|
+
let uniqKey2;
|
|
98
|
+
if (isQueryOptionsInputFn) {
|
|
99
|
+
const result = queryOptionsInput();
|
|
100
|
+
const {
|
|
101
|
+
params: params2,
|
|
102
|
+
abortSignal,
|
|
103
|
+
select,
|
|
104
|
+
onDone,
|
|
105
|
+
onError,
|
|
106
|
+
onInit,
|
|
107
|
+
enableOnDemand,
|
|
108
|
+
uniqKey: _uniqKey,
|
|
109
|
+
...dynamicOptions
|
|
110
|
+
} = result;
|
|
111
|
+
uniqKey2 = _uniqKey;
|
|
112
|
+
if ("params" in result) {
|
|
113
|
+
outParams = result.params;
|
|
114
|
+
} else {
|
|
115
|
+
outParams = {};
|
|
116
|
+
}
|
|
117
|
+
outDynamicOptions = Object.keys(dynamicOptions).length > 0 ? dynamicOptions : void 0;
|
|
118
|
+
} else if ("params" in unpackedQueryOptionsInput) {
|
|
119
|
+
outParams = unpackedQueryOptionsInput.params;
|
|
120
|
+
uniqKey2 = unpackedQueryOptionsInput.uniqKey;
|
|
121
|
+
} else {
|
|
122
|
+
outParams = {};
|
|
123
|
+
uniqKey2 = unpackedQueryOptionsInput.uniqKey;
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
params: common.callFunction(outParams),
|
|
127
|
+
dynamicOptions: outDynamicOptions,
|
|
128
|
+
uniqKey: uniqKey2
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
({ params: params2, dynamicOptions, uniqKey: uniqKey2 }) => {
|
|
132
|
+
mobx.runInAction(() => {
|
|
133
|
+
_observableData.initialized = true;
|
|
134
|
+
_observableData.params = params2;
|
|
135
|
+
_observableData.dynamicOptions = dynamicOptions;
|
|
136
|
+
_observableData.uniqKey = uniqKey2;
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
fireImmediately: true
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
if (this.features.lazy) {
|
|
144
|
+
mobx$1.lazyObserve({
|
|
145
|
+
property: parentAtom.values_.get("_result"),
|
|
146
|
+
onStart: createParamsReaction,
|
|
147
|
+
onEnd: (disposeFn) => disposeFn()
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
this.abortController.signal.addEventListener(
|
|
151
|
+
"abort",
|
|
152
|
+
createParamsReaction()
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
this._observableData = _observableData;
|
|
157
|
+
}
|
|
158
|
+
_observableData;
|
|
159
|
+
get params() {
|
|
160
|
+
return this._observableData.params;
|
|
161
|
+
}
|
|
162
|
+
get response() {
|
|
163
|
+
return this._observableData.response;
|
|
164
|
+
}
|
|
165
|
+
update(updateParams) {
|
|
166
|
+
if ("params" in updateParams) {
|
|
167
|
+
const { params, ...options } = updateParams;
|
|
168
|
+
mobx.runInAction(() => {
|
|
169
|
+
this._observableData.params = params;
|
|
170
|
+
});
|
|
171
|
+
return super.update({
|
|
172
|
+
...buildOptionsFromParams(
|
|
173
|
+
this.endpoint,
|
|
174
|
+
params,
|
|
175
|
+
this._observableData.uniqKey
|
|
176
|
+
),
|
|
177
|
+
...options
|
|
178
|
+
});
|
|
179
|
+
} else if (this._observableData) {
|
|
180
|
+
return super.update({
|
|
181
|
+
...buildOptionsFromParams(
|
|
182
|
+
this.endpoint,
|
|
183
|
+
this._observableData.params,
|
|
184
|
+
this._observableData.uniqKey
|
|
185
|
+
),
|
|
186
|
+
...updateParams
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
return super.update(updateParams);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
refetch(options) {
|
|
193
|
+
if (this.params) {
|
|
194
|
+
return super.refetch(options);
|
|
195
|
+
}
|
|
196
|
+
return Promise.resolve(this.queryObserver.getCurrentResult());
|
|
197
|
+
}
|
|
198
|
+
async start(params) {
|
|
199
|
+
mobx.runInAction(() => {
|
|
200
|
+
this._observableData.params = params;
|
|
201
|
+
});
|
|
202
|
+
return await super.start(
|
|
203
|
+
buildOptionsFromParams(
|
|
204
|
+
this.endpoint,
|
|
205
|
+
params,
|
|
206
|
+
this._observableData.uniqKey
|
|
207
|
+
)
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
handleDestroy() {
|
|
211
|
+
super.handleDestroy();
|
|
212
|
+
mobx.runInAction(() => {
|
|
213
|
+
this._observableData.params = void 0;
|
|
214
|
+
this._observableData.dynamicOptions = void 0;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const getParamsFromContext = (ctx) => {
|
|
219
|
+
return ctx.queryKey.at(-2) || {};
|
|
220
|
+
};
|
|
221
|
+
const buildOptionsFromParams = (endpoint, params, uniqKey) => {
|
|
222
|
+
const { requiredParams } = endpoint.configuration;
|
|
223
|
+
let hasRequiredParams = false;
|
|
224
|
+
if (requiredParams.length > 0) {
|
|
225
|
+
hasRequiredParams = !!params && requiredParams.every((param) => param in params);
|
|
226
|
+
} else {
|
|
227
|
+
hasRequiredParams = !!params;
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
enabled: hasRequiredParams,
|
|
231
|
+
queryKey: endpoint.toQueryKey(params || {}, uniqKey)
|
|
232
|
+
};
|
|
15
233
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
234
|
+
class EndpointInfiniteQuery extends mobxTanstackQuery.InfiniteQuery {
|
|
235
|
+
constructor(endpoint, queryClient, queryOptionsInput) {
|
|
236
|
+
const {
|
|
237
|
+
uniqKey,
|
|
238
|
+
transform: transformResponse,
|
|
239
|
+
params: paramsFn,
|
|
240
|
+
...queryOptions
|
|
241
|
+
} = typeof queryOptionsInput === "function" ? queryOptionsInput() : queryOptionsInput;
|
|
242
|
+
super({
|
|
243
|
+
...queryOptions,
|
|
244
|
+
queryClient,
|
|
245
|
+
meta: endpoint.toQueryMeta(queryOptions.meta),
|
|
246
|
+
options: (query) => {
|
|
247
|
+
const extraOptions = {};
|
|
248
|
+
let willEnableManually;
|
|
249
|
+
let params;
|
|
250
|
+
const pageParam = query.options.initialPageParam;
|
|
251
|
+
if (typeof queryOptionsInput === "function") {
|
|
252
|
+
Object.assign(extraOptions, queryOptionsInput());
|
|
253
|
+
params = paramsFn(pageParam);
|
|
254
|
+
willEnableManually = false;
|
|
255
|
+
} else {
|
|
256
|
+
willEnableManually = queryOptionsInput.enabled === false;
|
|
257
|
+
params = paramsFn(pageParam);
|
|
258
|
+
}
|
|
259
|
+
const builtOptions = buildOptionsFromParams(endpoint, params, uniqKey);
|
|
260
|
+
let isEnabled = false;
|
|
261
|
+
if (willEnableManually) ;
|
|
262
|
+
else {
|
|
263
|
+
isEnabled = builtOptions.enabled;
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
...query.options,
|
|
267
|
+
...builtOptions,
|
|
268
|
+
// ...dynamicOuterOptions,
|
|
269
|
+
enabled: isEnabled,
|
|
270
|
+
...extraOptions
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
queryFn: async (ctx) => {
|
|
274
|
+
const params = paramsFn(
|
|
275
|
+
ctx.pageParam ?? queryOptions.initialPageParam
|
|
276
|
+
);
|
|
277
|
+
mobx.runInAction(() => {
|
|
278
|
+
this.response = null;
|
|
279
|
+
this.params = params;
|
|
280
|
+
});
|
|
281
|
+
let requestParams = params.request;
|
|
282
|
+
if (requestParams) {
|
|
283
|
+
if (!requestParams.signal) {
|
|
284
|
+
requestParams.signal = ctx.signal;
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
requestParams = { signal: ctx.signal };
|
|
288
|
+
}
|
|
289
|
+
const fixedInput = {
|
|
290
|
+
...params,
|
|
291
|
+
request: requestParams
|
|
292
|
+
};
|
|
293
|
+
const response = await endpoint.request(fixedInput);
|
|
294
|
+
mobx.runInAction(() => {
|
|
295
|
+
this.response = response;
|
|
296
|
+
});
|
|
297
|
+
return await transformResponse?.(response) ?? response.data;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
this.endpoint = endpoint;
|
|
301
|
+
this.paramsFn = paramsFn;
|
|
302
|
+
this.uniqKey = uniqKey;
|
|
303
|
+
mobx.observable.ref(this, "response");
|
|
304
|
+
mobx.observable.ref(this, "params");
|
|
305
|
+
mobx.makeObservable(this);
|
|
306
|
+
}
|
|
307
|
+
response = null;
|
|
308
|
+
params = null;
|
|
309
|
+
uniqKey;
|
|
310
|
+
paramsFn;
|
|
311
|
+
update({
|
|
312
|
+
params,
|
|
313
|
+
...options
|
|
314
|
+
}) {
|
|
315
|
+
return super.update({
|
|
316
|
+
...buildOptionsFromParams(this.endpoint, params, this.uniqKey),
|
|
317
|
+
...options
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
async start(params) {
|
|
321
|
+
return await super.start(
|
|
322
|
+
buildOptionsFromParams(this.endpoint, params, this.uniqKey)
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
class EndpointMutation extends mobxTanstackQuery.Mutation {
|
|
327
|
+
constructor(endpoint, inputQueryClient, {
|
|
328
|
+
transform: transformResponse,
|
|
329
|
+
invalidateEndpoints,
|
|
330
|
+
queryClient: overridedQueryClient,
|
|
331
|
+
...mutationOptions
|
|
332
|
+
}) {
|
|
333
|
+
const queryClient = overridedQueryClient ?? inputQueryClient;
|
|
334
|
+
super({
|
|
335
|
+
...mutationOptions,
|
|
336
|
+
queryClient,
|
|
337
|
+
onSuccess: (data, variables, onMutateResult, context) => {
|
|
338
|
+
mutationOptions.onSuccess?.(data, variables, onMutateResult, context);
|
|
339
|
+
if (invalidateEndpoints) {
|
|
340
|
+
if (typeof invalidateEndpoints === "object") {
|
|
341
|
+
queryClient.invalidateEndpoints(invalidateEndpoints);
|
|
342
|
+
} else {
|
|
343
|
+
let filters;
|
|
344
|
+
switch (`${invalidateEndpoints}`) {
|
|
345
|
+
case "true": {
|
|
346
|
+
filters = endpoint.group ? {
|
|
347
|
+
group: endpoint.group
|
|
348
|
+
} : {
|
|
349
|
+
tag: endpoint.tags
|
|
350
|
+
};
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
case "by-group": {
|
|
354
|
+
filters = {
|
|
355
|
+
group: endpoint.group
|
|
356
|
+
};
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
case "by-tag": {
|
|
360
|
+
filters = {
|
|
361
|
+
tag: endpoint.tags
|
|
362
|
+
};
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (filters) {
|
|
367
|
+
queryClient.invalidateEndpoints(filters);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
mutationFn: async (input, context) => {
|
|
373
|
+
let requestParams = input?.requestParams;
|
|
374
|
+
if (requestParams) {
|
|
375
|
+
if (!requestParams.signal) {
|
|
376
|
+
requestParams.signal = context.signal;
|
|
377
|
+
}
|
|
378
|
+
} else {
|
|
379
|
+
requestParams = { signal: context.signal };
|
|
380
|
+
}
|
|
381
|
+
const fixedInput = {
|
|
382
|
+
...input,
|
|
383
|
+
requestParams
|
|
384
|
+
};
|
|
385
|
+
const response = await endpoint.request(fixedInput);
|
|
386
|
+
return await transformResponse?.(response) ?? response.data;
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
this.endpoint = endpoint;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
class Endpoint {
|
|
393
|
+
constructor(configuration, queryClient, httpClient) {
|
|
394
|
+
this.configuration = configuration;
|
|
395
|
+
this.queryClient = queryClient;
|
|
396
|
+
this.httpClient = httpClient;
|
|
397
|
+
this.endpointId = globalThis.crypto.randomUUID();
|
|
398
|
+
this.meta = configuration.meta ?? {};
|
|
399
|
+
const instance = this;
|
|
400
|
+
const callable = function(...args) {
|
|
401
|
+
return instance.request.apply(instance, args);
|
|
402
|
+
};
|
|
403
|
+
Object.setPrototypeOf(callable, new.target.prototype);
|
|
404
|
+
Object.getOwnPropertyNames(instance).concat(Object.getOwnPropertyNames(new.target.prototype)).forEach((key) => {
|
|
405
|
+
if (key === "constructor") return;
|
|
406
|
+
const desc = Object.getOwnPropertyDescriptor(instance, key) || Object.getOwnPropertyDescriptor(new.target.prototype, key);
|
|
407
|
+
if (desc) Object.defineProperty(callable, key, desc);
|
|
408
|
+
});
|
|
409
|
+
return callable;
|
|
410
|
+
}
|
|
411
|
+
endpointId;
|
|
412
|
+
presets = {
|
|
413
|
+
mutations: {}
|
|
414
|
+
};
|
|
415
|
+
__params;
|
|
416
|
+
__response;
|
|
417
|
+
meta;
|
|
418
|
+
getFullUrl(...args) {
|
|
419
|
+
const params = this.configuration.params(args[0] ?? {});
|
|
420
|
+
return this.httpClient.buildUrl(params);
|
|
421
|
+
}
|
|
422
|
+
getPath(...args) {
|
|
423
|
+
const params = this.configuration.params(args[0] ?? {});
|
|
424
|
+
return params.path;
|
|
425
|
+
}
|
|
426
|
+
getParamsFromContext(ctx) {
|
|
427
|
+
return ctx.queryKey.at(-2) || {};
|
|
428
|
+
}
|
|
429
|
+
get tags() {
|
|
430
|
+
return this.configuration.tags;
|
|
431
|
+
}
|
|
432
|
+
get path() {
|
|
433
|
+
return this.configuration.path;
|
|
434
|
+
}
|
|
435
|
+
get pathDeclaration() {
|
|
436
|
+
return this.path.join("/");
|
|
437
|
+
}
|
|
438
|
+
get operationId() {
|
|
439
|
+
return this.configuration.operationId;
|
|
440
|
+
}
|
|
441
|
+
get group() {
|
|
442
|
+
return this.configuration.group;
|
|
443
|
+
}
|
|
444
|
+
get namespace() {
|
|
445
|
+
return this.configuration.namespace;
|
|
446
|
+
}
|
|
447
|
+
request(...args) {
|
|
448
|
+
return this.httpClient.request(
|
|
449
|
+
this.configuration.params(args[0] ?? {}),
|
|
450
|
+
this
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
toQueryMeta = (meta) => ({
|
|
454
|
+
...meta,
|
|
455
|
+
tags: this.tags,
|
|
456
|
+
operationId: this.operationId,
|
|
457
|
+
path: this.path,
|
|
458
|
+
pathDeclaration: this.pathDeclaration,
|
|
459
|
+
endpointId: this.endpointId,
|
|
460
|
+
endpointQuery: true
|
|
461
|
+
});
|
|
462
|
+
toQueryKey(params, uniqKey) {
|
|
463
|
+
return [
|
|
464
|
+
...this.configuration.path,
|
|
465
|
+
this.configuration.operationId,
|
|
466
|
+
params ?? {},
|
|
467
|
+
common.callFunction(uniqKey)
|
|
468
|
+
];
|
|
469
|
+
}
|
|
470
|
+
toInfiniteQueryKey(params, uniqKey) {
|
|
471
|
+
return [
|
|
472
|
+
{ infiniteQuery: true },
|
|
473
|
+
...this.configuration.path,
|
|
474
|
+
this.configuration.operationId,
|
|
475
|
+
params ?? {},
|
|
476
|
+
common.callFunction(uniqKey)
|
|
477
|
+
];
|
|
478
|
+
}
|
|
479
|
+
invalidateQuery(...args) {
|
|
480
|
+
this.queryClient.invalidateQueries(
|
|
481
|
+
{
|
|
482
|
+
queryKey: this.toQueryKey(args[0], args[1]?.uniqKey),
|
|
483
|
+
exact: true,
|
|
484
|
+
...args[1]
|
|
485
|
+
},
|
|
486
|
+
args[2]
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
toMutation(options) {
|
|
490
|
+
return new EndpointMutation(
|
|
491
|
+
this,
|
|
492
|
+
this.queryClient,
|
|
493
|
+
{
|
|
494
|
+
...options,
|
|
495
|
+
invalidateEndpoints: options.invalidateEndpoints ?? this.presets.mutations?.invalidateQueries
|
|
496
|
+
}
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
toQuery(options) {
|
|
500
|
+
return new EndpointQuery(
|
|
501
|
+
this,
|
|
502
|
+
this.queryClient,
|
|
503
|
+
options
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
toInfiniteQuery(options) {
|
|
507
|
+
return new EndpointInfiniteQuery(
|
|
508
|
+
this,
|
|
509
|
+
this.queryClient,
|
|
510
|
+
options
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
class EndpointQueryClient extends mobxTanstackQuery.QueryClient {
|
|
515
|
+
constructor(config) {
|
|
516
|
+
super({
|
|
517
|
+
...config,
|
|
518
|
+
defaultOptions: {
|
|
519
|
+
...config?.defaultOptions,
|
|
520
|
+
queries: {
|
|
521
|
+
...config?.defaultOptions?.queries,
|
|
522
|
+
queryKeyHashFn: config?.defaultOptions?.queries?.queryKeyHashFn ?? queryCore.hashKey
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
invalidateEndpoints({
|
|
528
|
+
group,
|
|
529
|
+
namespace,
|
|
530
|
+
operationId,
|
|
531
|
+
tag,
|
|
532
|
+
predicate,
|
|
533
|
+
endpoint,
|
|
534
|
+
...queryFilters
|
|
535
|
+
}, options) {
|
|
536
|
+
let endpointIdsToFilter;
|
|
537
|
+
if (Array.isArray(endpoint)) {
|
|
538
|
+
endpointIdsToFilter = new Set(endpoint.map((it) => it.endpointId));
|
|
539
|
+
} else if (endpoint) {
|
|
540
|
+
endpointIdsToFilter = /* @__PURE__ */ new Set([endpoint.endpointId]);
|
|
541
|
+
}
|
|
542
|
+
return this.invalidateQueries(
|
|
543
|
+
{
|
|
544
|
+
...queryFilters,
|
|
545
|
+
predicate: (query) => {
|
|
546
|
+
if (!query.meta?.endpointQuery) {
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
const meta = query.meta;
|
|
550
|
+
if (endpointIdsToFilter && !endpointIdsToFilter.has(meta.endpointId)) {
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
if (namespace && meta.namespace && !applyStringFilter(namespace, meta.namespace)) {
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
if (group && meta.group && !applyStringFilter(group, meta.group)) {
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
if (tag && meta.tags && !applyStringFilter(tag, meta.tags)) {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
if (tag && meta.tags && !applyStringFilter(tag, meta.tags)) {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
if (operationId && !applyStringFilter(operationId, meta.operationId)) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
if (predicate && !predicate(meta, query)) {
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
options
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const applyStringFilter = (filter, value) => {
|
|
579
|
+
const values = Array.isArray(value) ? value : [value];
|
|
580
|
+
if (filter instanceof RegExp) {
|
|
581
|
+
return values.some((value2) => filter.test(value2));
|
|
582
|
+
}
|
|
583
|
+
if (Array.isArray(filter)) {
|
|
584
|
+
return filter.some((filter2) => values.includes(filter2));
|
|
585
|
+
}
|
|
586
|
+
return values.includes(filter);
|
|
587
|
+
};
|
|
588
|
+
const isHttpResponse = (response, status) => !!response && typeof response === "object" && response instanceof Response && "data" in response && (!status || response.status === status);
|
|
589
|
+
const isHttpBadResponse = (response) => {
|
|
590
|
+
return isHttpResponse(response) && (!response.ok || !!response.error);
|
|
591
|
+
};
|
|
592
|
+
class HttpClient {
|
|
593
|
+
config;
|
|
594
|
+
fetch;
|
|
595
|
+
meta;
|
|
596
|
+
baseApiParams;
|
|
597
|
+
badResponse;
|
|
598
|
+
toQueryString;
|
|
599
|
+
constructor(config) {
|
|
600
|
+
this.config = config ?? {};
|
|
601
|
+
this.badResponse = null;
|
|
602
|
+
this.meta = config?.meta ?? null;
|
|
603
|
+
this.fetch = config?.fetch ?? ((...fetchParams) => globalThis.fetch(...fetchParams));
|
|
604
|
+
this.toQueryString = config?.toQueryString ?? ((query) => qs.stringify(query, config?.queryStringifyOptions));
|
|
605
|
+
this.baseApiParams = {
|
|
606
|
+
credentials: "same-origin",
|
|
607
|
+
headers: {},
|
|
608
|
+
redirect: "follow",
|
|
609
|
+
referrerPolicy: "no-referrer"
|
|
610
|
+
};
|
|
611
|
+
this.updateConfig(this.config);
|
|
612
|
+
mobx.observable.ref(this, "badResponse");
|
|
613
|
+
mobx.observable.ref(this, "meta");
|
|
614
|
+
mobx.action(this, "setMeta");
|
|
615
|
+
mobx.action(this, "setBadResponse");
|
|
616
|
+
mobx.makeObservable(this);
|
|
617
|
+
}
|
|
618
|
+
get baseUrl() {
|
|
619
|
+
return this.config.baseUrl ?? "";
|
|
620
|
+
}
|
|
621
|
+
updateConfig(update) {
|
|
622
|
+
Object.assign(this.config, update);
|
|
623
|
+
if (update.baseApiParams) {
|
|
624
|
+
Object.assign(this.baseApiParams, update.baseApiParams);
|
|
625
|
+
}
|
|
626
|
+
if (update.contentFormatters) {
|
|
627
|
+
Object.assign(this.contentFormatters, update.contentFormatters);
|
|
628
|
+
}
|
|
629
|
+
if (update.fetch) {
|
|
630
|
+
this.fetch = update.fetch;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
setMeta = (data) => {
|
|
634
|
+
this.meta = data;
|
|
635
|
+
};
|
|
636
|
+
setBadResponse = (response) => {
|
|
637
|
+
this.badResponse = response;
|
|
638
|
+
};
|
|
639
|
+
contentFormatters = {
|
|
640
|
+
"application/json": (input) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
|
|
641
|
+
"text/plain": (input) => input !== null && typeof input !== "string" ? JSON.stringify(input) : input,
|
|
642
|
+
"multipart/form-data": (input) => Object.keys(input || {}).reduce((formData, key) => {
|
|
643
|
+
const property = input[key];
|
|
644
|
+
if (property instanceof Blob) {
|
|
645
|
+
formData.append(key, property);
|
|
646
|
+
} else if (typeof property === "object" && property !== null) {
|
|
647
|
+
formData.append(key, JSON.stringify(property));
|
|
648
|
+
} else {
|
|
649
|
+
formData.append(key, `${property}`);
|
|
650
|
+
}
|
|
651
|
+
return formData;
|
|
652
|
+
}, new FormData()),
|
|
653
|
+
"application/x-www-form-urlencoded": (input) => this.toQueryString(input),
|
|
654
|
+
"application/octet-stream": (input) => input
|
|
655
|
+
};
|
|
656
|
+
mergeRequestParams(params1, params2) {
|
|
657
|
+
return {
|
|
658
|
+
...this.baseApiParams,
|
|
659
|
+
...params1,
|
|
660
|
+
...params2,
|
|
661
|
+
headers: {
|
|
662
|
+
...this.baseApiParams.headers,
|
|
663
|
+
...params1.headers,
|
|
664
|
+
...params2?.headers
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
async createResponse(responseFormat, raw, url, params) {
|
|
669
|
+
const response = raw;
|
|
670
|
+
response.request = {
|
|
671
|
+
url,
|
|
672
|
+
params
|
|
673
|
+
};
|
|
674
|
+
response.data = null;
|
|
675
|
+
response.error = null;
|
|
676
|
+
if (responseFormat) {
|
|
677
|
+
try {
|
|
678
|
+
const formatted = await response[responseFormat]();
|
|
679
|
+
if (response.ok) {
|
|
680
|
+
response.data = formatted;
|
|
681
|
+
} else {
|
|
682
|
+
response.error = formatted;
|
|
683
|
+
}
|
|
684
|
+
} catch (error) {
|
|
685
|
+
if (response.ok) {
|
|
686
|
+
response.error = error;
|
|
687
|
+
} else {
|
|
688
|
+
response.error = null;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (!response.ok || response.error) {
|
|
693
|
+
this.setBadResponse(response);
|
|
694
|
+
}
|
|
695
|
+
return response;
|
|
696
|
+
}
|
|
697
|
+
buildUrl = (params) => {
|
|
698
|
+
const baseUrl = params.baseUrl ?? this.baseUrl ?? "";
|
|
699
|
+
const path = params.path;
|
|
700
|
+
const queryString = params.query && this.toQueryString(params.query);
|
|
701
|
+
const query = queryString ? `?${queryString}` : "";
|
|
702
|
+
if (this.config.buildUrl) {
|
|
703
|
+
return this.config.buildUrl(params, { baseUrl, path, query }, this.meta);
|
|
704
|
+
}
|
|
705
|
+
const url = baseUrl + path + query;
|
|
706
|
+
return url;
|
|
707
|
+
};
|
|
708
|
+
async request(fullParams, endpoint) {
|
|
709
|
+
this.setBadResponse(null);
|
|
710
|
+
const {
|
|
711
|
+
body,
|
|
712
|
+
contentType = "application/json",
|
|
713
|
+
format = "json",
|
|
714
|
+
...params
|
|
715
|
+
} = fullParams;
|
|
716
|
+
let requestParams = this.mergeRequestParams(params);
|
|
717
|
+
if (this.config.interceptor) {
|
|
718
|
+
requestParams = await this.config.interceptor(requestParams, this.meta, endpoint) ?? requestParams;
|
|
719
|
+
}
|
|
720
|
+
const payloadFormatter = this.contentFormatters[contentType];
|
|
721
|
+
const responseFormat = format || requestParams.format;
|
|
722
|
+
const url = this.buildUrl(fullParams);
|
|
723
|
+
let headers;
|
|
724
|
+
if (requestParams.headers instanceof Headers) {
|
|
725
|
+
headers = requestParams.headers;
|
|
726
|
+
} else if (Array.isArray(requestParams.headers)) {
|
|
727
|
+
headers = new Headers(requestParams.headers);
|
|
728
|
+
} else {
|
|
729
|
+
headers = new Headers(requestParams.headers);
|
|
730
|
+
}
|
|
731
|
+
if (!headers.has("Content-Type")) {
|
|
732
|
+
headers.set("Content-Type", contentType);
|
|
733
|
+
}
|
|
734
|
+
const fetchUrl = url;
|
|
735
|
+
const fetchParams = {
|
|
736
|
+
...requestParams,
|
|
737
|
+
headers,
|
|
738
|
+
body: body == null ? null : payloadFormatter(body)
|
|
739
|
+
};
|
|
740
|
+
let response;
|
|
741
|
+
try {
|
|
742
|
+
response = await this.fetch(fetchUrl, fetchParams);
|
|
743
|
+
} catch (error) {
|
|
744
|
+
response = error;
|
|
745
|
+
}
|
|
746
|
+
const httpResponse = await this.createResponse(
|
|
747
|
+
responseFormat,
|
|
748
|
+
response,
|
|
749
|
+
fetchUrl,
|
|
750
|
+
fetchParams
|
|
751
|
+
);
|
|
752
|
+
if (!httpResponse.ok || httpResponse.error) {
|
|
753
|
+
throw httpResponse;
|
|
754
|
+
}
|
|
755
|
+
return httpResponse;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
exports.Endpoint = Endpoint;
|
|
759
|
+
exports.EndpointMutation = EndpointMutation;
|
|
760
|
+
exports.EndpointQuery = EndpointQuery;
|
|
761
|
+
exports.EndpointQueryClient = EndpointQueryClient;
|
|
762
|
+
exports.HttpClient = HttpClient;
|
|
763
|
+
exports.buildOptionsFromParams = buildOptionsFromParams;
|
|
764
|
+
exports.getParamsFromContext = getParamsFromContext;
|
|
765
|
+
exports.isHttpBadResponse = isHttpBadResponse;
|
|
766
|
+
exports.isHttpResponse = isHttpResponse;
|
|
767
|
+
Object.keys(queryCore).forEach((k) => {
|
|
768
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
769
|
+
enumerable: true,
|
|
770
|
+
get: () => queryCore[k]
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
//# sourceMappingURL=index.cjs.map
|