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,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = exports.isHttpBadResponse = exports.isHttpResponse = void 0;
|
|
4
|
+
const mobx_1 = require("mobx");
|
|
5
|
+
const isHttpResponse = (response, status) => !!response &&
|
|
6
|
+
typeof response === 'object' &&
|
|
7
|
+
response instanceof Response &&
|
|
8
|
+
'data' in response &&
|
|
9
|
+
(!status || response.status === status);
|
|
10
|
+
exports.isHttpResponse = isHttpResponse;
|
|
11
|
+
const isHttpBadResponse = (response) => {
|
|
12
|
+
return (0, exports.isHttpResponse)(response) && (!response.ok || !!response.error);
|
|
13
|
+
};
|
|
14
|
+
exports.isHttpBadResponse = isHttpBadResponse;
|
|
15
|
+
class HttpClient {
|
|
16
|
+
config;
|
|
17
|
+
fetch;
|
|
18
|
+
meta;
|
|
19
|
+
baseApiParams;
|
|
20
|
+
badResponse;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.config = config ?? {};
|
|
23
|
+
this.badResponse = null;
|
|
24
|
+
this.meta = config?.meta ?? null;
|
|
25
|
+
this.fetch =
|
|
26
|
+
config?.fetch ??
|
|
27
|
+
((...fetchParams) => globalThis.fetch(...fetchParams));
|
|
28
|
+
this.baseApiParams = {
|
|
29
|
+
credentials: 'same-origin',
|
|
30
|
+
headers: {},
|
|
31
|
+
redirect: 'follow',
|
|
32
|
+
referrerPolicy: 'no-referrer',
|
|
33
|
+
};
|
|
34
|
+
this.updateConfig(this.config);
|
|
35
|
+
mobx_1.observable.ref(this, 'badResponse');
|
|
36
|
+
mobx_1.observable.ref(this, 'meta');
|
|
37
|
+
(0, mobx_1.action)(this, 'setMeta');
|
|
38
|
+
(0, mobx_1.action)(this, 'setBadResponse');
|
|
39
|
+
(0, mobx_1.makeObservable)(this);
|
|
40
|
+
}
|
|
41
|
+
get baseUrl() {
|
|
42
|
+
return this.config.baseUrl ?? '';
|
|
43
|
+
}
|
|
44
|
+
updateConfig(update) {
|
|
45
|
+
Object.assign(this.config, update);
|
|
46
|
+
if (update.baseApiParams) {
|
|
47
|
+
Object.assign(this.baseApiParams, update.baseApiParams);
|
|
48
|
+
}
|
|
49
|
+
if (update.contentFormatters) {
|
|
50
|
+
Object.assign(this.contentFormatters, update.contentFormatters);
|
|
51
|
+
}
|
|
52
|
+
if (update.fetch) {
|
|
53
|
+
this.fetch = update.fetch;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
setMeta = (data) => {
|
|
57
|
+
this.meta = data;
|
|
58
|
+
};
|
|
59
|
+
setBadResponse = (response) => {
|
|
60
|
+
this.badResponse = response;
|
|
61
|
+
};
|
|
62
|
+
encodeQueryParam(key, value) {
|
|
63
|
+
const encodedKey = encodeURIComponent(key);
|
|
64
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === 'number' ? value : `${value}`)}`;
|
|
65
|
+
}
|
|
66
|
+
addQueryParam(query, key) {
|
|
67
|
+
return this.encodeQueryParam(key, query[key]);
|
|
68
|
+
}
|
|
69
|
+
addArrayQueryParam(query, key) {
|
|
70
|
+
const value = query[key];
|
|
71
|
+
return value.map((v) => this.encodeQueryParam(key, v)).join('&');
|
|
72
|
+
}
|
|
73
|
+
toQueryString(rawQuery) {
|
|
74
|
+
if (this.config.toQueryString) {
|
|
75
|
+
return this.config.toQueryString(rawQuery);
|
|
76
|
+
}
|
|
77
|
+
const query = rawQuery || {};
|
|
78
|
+
const keys = Object.keys(query).filter((key) => 'undefined' !== typeof query[key]);
|
|
79
|
+
return keys
|
|
80
|
+
.map((key) => Array.isArray(query[key])
|
|
81
|
+
? this.addArrayQueryParam(query, key)
|
|
82
|
+
: this.addQueryParam(query, key))
|
|
83
|
+
.join('&');
|
|
84
|
+
}
|
|
85
|
+
contentFormatters = {
|
|
86
|
+
'application/json': (input) => input !== null && (typeof input === 'object' || typeof input === 'string')
|
|
87
|
+
? JSON.stringify(input)
|
|
88
|
+
: input,
|
|
89
|
+
'text/plain': (input) => input !== null && typeof input !== 'string'
|
|
90
|
+
? JSON.stringify(input)
|
|
91
|
+
: input,
|
|
92
|
+
'multipart/form-data': (input) => Object.keys(input || {}).reduce((formData, key) => {
|
|
93
|
+
const property = input[key];
|
|
94
|
+
if (property instanceof Blob) {
|
|
95
|
+
formData.append(key, property);
|
|
96
|
+
}
|
|
97
|
+
else if (typeof property === 'object' && property !== null) {
|
|
98
|
+
formData.append(key, JSON.stringify(property));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
formData.append(key, `${property}`);
|
|
102
|
+
}
|
|
103
|
+
return formData;
|
|
104
|
+
}, new FormData()),
|
|
105
|
+
'application/x-www-form-urlencoded': (input) => this.toQueryString(input),
|
|
106
|
+
'application/octet-stream': (input) => input,
|
|
107
|
+
};
|
|
108
|
+
mergeRequestParams(params1, params2) {
|
|
109
|
+
return {
|
|
110
|
+
...this.baseApiParams,
|
|
111
|
+
...params1,
|
|
112
|
+
...params2,
|
|
113
|
+
headers: {
|
|
114
|
+
...this.baseApiParams.headers,
|
|
115
|
+
...params1.headers,
|
|
116
|
+
...params2?.headers,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async createResponse(responseFormat, raw, url, params) {
|
|
121
|
+
const response = raw;
|
|
122
|
+
response.request = {
|
|
123
|
+
url,
|
|
124
|
+
params,
|
|
125
|
+
};
|
|
126
|
+
response.data = null;
|
|
127
|
+
response.error = null;
|
|
128
|
+
if (responseFormat) {
|
|
129
|
+
try {
|
|
130
|
+
const formatted = await response[responseFormat]();
|
|
131
|
+
if (response.ok) {
|
|
132
|
+
response.data = formatted;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
response.error = formatted;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (response.ok) {
|
|
140
|
+
response.error = error;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
response.error = null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!response.ok || response.error) {
|
|
148
|
+
this.setBadResponse(response);
|
|
149
|
+
}
|
|
150
|
+
return response;
|
|
151
|
+
}
|
|
152
|
+
buildUrl = (params) => {
|
|
153
|
+
const baseUrl = params.baseUrl ?? this.baseUrl ?? '';
|
|
154
|
+
const path = params.path;
|
|
155
|
+
const queryString = params.query && this.toQueryString(params.query);
|
|
156
|
+
const query = queryString ? `?${queryString}` : '';
|
|
157
|
+
if (this.config.buildUrl) {
|
|
158
|
+
return this.config.buildUrl(params, { baseUrl, path, query }, this.meta);
|
|
159
|
+
}
|
|
160
|
+
const url = baseUrl + path + query;
|
|
161
|
+
return url;
|
|
162
|
+
};
|
|
163
|
+
async request(fullParams) {
|
|
164
|
+
this.setBadResponse(null);
|
|
165
|
+
const { body, contentType = 'application/json', format = 'json', ...params } = fullParams;
|
|
166
|
+
let requestParams = this.mergeRequestParams(params);
|
|
167
|
+
if (this.config.interceptor) {
|
|
168
|
+
requestParams =
|
|
169
|
+
(await this.config.interceptor(requestParams, this.meta)) ??
|
|
170
|
+
requestParams;
|
|
171
|
+
}
|
|
172
|
+
const payloadFormatter = this.contentFormatters[contentType];
|
|
173
|
+
const responseFormat = format || requestParams.format;
|
|
174
|
+
const url = this.buildUrl(fullParams);
|
|
175
|
+
let headers;
|
|
176
|
+
if (requestParams.headers instanceof Headers) {
|
|
177
|
+
headers = requestParams.headers;
|
|
178
|
+
}
|
|
179
|
+
else if (Array.isArray(requestParams.headers)) {
|
|
180
|
+
headers = new Headers(requestParams.headers);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
headers = new Headers(requestParams.headers);
|
|
184
|
+
}
|
|
185
|
+
if (!headers.has('Content-Type')) {
|
|
186
|
+
headers.set('Content-Type', contentType);
|
|
187
|
+
}
|
|
188
|
+
const fetchUrl = url;
|
|
189
|
+
const fetchParams = {
|
|
190
|
+
...requestParams,
|
|
191
|
+
headers,
|
|
192
|
+
body: body == null ? null : payloadFormatter(body),
|
|
193
|
+
};
|
|
194
|
+
let response;
|
|
195
|
+
try {
|
|
196
|
+
response = await this.fetch(fetchUrl, fetchParams);
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
response = error;
|
|
200
|
+
}
|
|
201
|
+
const httpResponse = await this.createResponse(responseFormat, response, fetchUrl, fetchParams);
|
|
202
|
+
if (!httpResponse.ok || httpResponse.error) {
|
|
203
|
+
throw httpResponse;
|
|
204
|
+
}
|
|
205
|
+
return httpResponse;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.HttpClient = HttpClient;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { HttpStatusCode, HttpSuccessStatusCode } from 'http-status-code-types';
|
|
2
|
+
import type { ValueOf } from 'yummies/utils/types';
|
|
3
|
+
export type QueryParamsType = Record<string | number, any>;
|
|
4
|
+
export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
|
|
5
|
+
export interface FullRequestParams extends Omit<RequestInit, 'body'> {
|
|
6
|
+
/** set parameter to `true` for call `securityWorker` for this request */
|
|
7
|
+
secure?: boolean;
|
|
8
|
+
/** request path */
|
|
9
|
+
path: string;
|
|
10
|
+
/** content type of request body */
|
|
11
|
+
contentType?: string;
|
|
12
|
+
/** query params */
|
|
13
|
+
query?: QueryParamsType;
|
|
14
|
+
/** format of response (i.e. response.json() -> format: "json") */
|
|
15
|
+
format?: ResponseFormat;
|
|
16
|
+
/** request body */
|
|
17
|
+
body?: unknown;
|
|
18
|
+
/** base url */
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
/** meta data */
|
|
21
|
+
meta?: Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path' | 'serviceName'>;
|
|
24
|
+
export interface HttpClientConfig<TMeta = unknown> {
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
meta?: TMeta;
|
|
27
|
+
fetch?: typeof globalThis.fetch;
|
|
28
|
+
baseApiParams?: Omit<RequestParams, 'baseUrl' | 'cancelToken' | 'signal'>;
|
|
29
|
+
contentFormatters?: Record<string, (input: any) => any>;
|
|
30
|
+
toQueryString?: (query?: QueryParamsType) => string;
|
|
31
|
+
buildUrl?: (fullParams: FullRequestParams, formattedParts: {
|
|
32
|
+
baseUrl: string;
|
|
33
|
+
path: string;
|
|
34
|
+
query: string;
|
|
35
|
+
}, metadata: TMeta | null) => string;
|
|
36
|
+
interceptor?: (requestParams: RequestParams, metadata: TMeta | null) => Promise<RequestParams | void> | RequestParams | void;
|
|
37
|
+
}
|
|
38
|
+
export interface HttpResponse<TData, TError = null, TStatus = number> extends Omit<Response, 'status'> {
|
|
39
|
+
data: TData;
|
|
40
|
+
error: TError;
|
|
41
|
+
status: TStatus;
|
|
42
|
+
request: {
|
|
43
|
+
url: string;
|
|
44
|
+
params: globalThis.RequestInit;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export type HttpMultistatusResponse<TResponsesByStatusMap extends Partial<Record<HttpStatusCode, any>>, TDefaultOkResponse, TDefaultBadResponse = unknown> = Omit<Response, 'status'> & (ValueOf<{
|
|
48
|
+
[K in keyof TResponsesByStatusMap]: {
|
|
49
|
+
status: K;
|
|
50
|
+
data: K extends HttpSuccessStatusCode ? TResponsesByStatusMap[K] : TDefaultOkResponse;
|
|
51
|
+
error: K extends HttpSuccessStatusCode ? TDefaultBadResponse : TResponsesByStatusMap[K];
|
|
52
|
+
};
|
|
53
|
+
}> | {
|
|
54
|
+
status: Exclude<HttpStatusCode, keyof TResponsesByStatusMap>;
|
|
55
|
+
data: TDefaultOkResponse;
|
|
56
|
+
error: TDefaultBadResponse;
|
|
57
|
+
});
|
|
58
|
+
export type GetHttpResponse<T> = T extends (...args: any[]) => infer R ? R extends Promise<HttpResponse<any, any>> ? Awaited<R> : R extends Promise<HttpMultistatusResponse<any, any, any>> ? Awaited<R> : HttpResponse<any, any> : HttpResponse<any, any>;
|
|
59
|
+
export type HttpBadResponse<T = any> = HttpResponse<null, T>;
|
|
60
|
+
export type AnyHttpResponse = HttpResponse<any, any>;
|
|
61
|
+
export declare const isHttpResponse: (response: unknown, status?: number) => response is AnyHttpResponse;
|
|
62
|
+
export declare const isHttpBadResponse: (response: unknown) => response is HttpResponse<null, any>;
|
|
63
|
+
export declare class HttpClient<TMeta = unknown> {
|
|
64
|
+
private config;
|
|
65
|
+
private fetch;
|
|
66
|
+
meta: TMeta | null;
|
|
67
|
+
baseApiParams: RequestParams;
|
|
68
|
+
badResponse: unknown;
|
|
69
|
+
constructor(config?: HttpClientConfig<TMeta>);
|
|
70
|
+
get baseUrl(): string;
|
|
71
|
+
updateConfig(update: Partial<HttpClientConfig<TMeta>>): void;
|
|
72
|
+
setMeta: (data: TMeta | null) => void;
|
|
73
|
+
setBadResponse: (response: unknown) => void;
|
|
74
|
+
protected encodeQueryParam(key: string, value: any): string;
|
|
75
|
+
protected addQueryParam(query: QueryParamsType, key: string): string;
|
|
76
|
+
protected addArrayQueryParam(query: QueryParamsType, key: string): any;
|
|
77
|
+
protected toQueryString(rawQuery?: QueryParamsType): string;
|
|
78
|
+
private contentFormatters;
|
|
79
|
+
protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams;
|
|
80
|
+
protected createResponse(responseFormat: FullRequestParams['format'], raw: Response, url: string, params: RequestInit): Promise<AnyHttpResponse>;
|
|
81
|
+
buildUrl: (params: FullRequestParams) => string;
|
|
82
|
+
request<T, E>(fullParams: FullRequestParams): Promise<HttpResponse<T, E>>;
|
|
83
|
+
request<THttpResponse extends HttpResponse<any, any>>(fullParams: FullRequestParams): Promise<THttpResponse>;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/run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
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./endpoint.cjs"), exports);
|
|
18
|
+
__exportStar(require("./endpoint.types.cjs"), exports);
|
|
19
|
+
__exportStar(require("./endpoint-mutation.cjs"), exports);
|
|
20
|
+
__exportStar(require("./endpoint-mutation.types.cjs"), exports);
|
|
21
|
+
__exportStar(require("./endpoint-query.cjs"), exports);
|
|
22
|
+
__exportStar(require("./endpoint-query.types.cjs"), exports);
|
|
23
|
+
__exportStar(require("./endpoint-query-client.cjs"), exports);
|
|
24
|
+
__exportStar(require("./endpoint-query-client.types.cjs"), exports);
|
|
25
|
+
__exportStar(require("./http-client.cjs"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./endpoint.cjs";
|
|
2
|
+
export * from "./endpoint.types.cjs";
|
|
3
|
+
export * from "./endpoint-mutation.cjs";
|
|
4
|
+
export * from "./endpoint-mutation.types.cjs";
|
|
5
|
+
export * from "./endpoint-query.cjs";
|
|
6
|
+
export * from "./endpoint-query.types.cjs";
|
|
7
|
+
export * from "./endpoint-query-client.cjs";
|
|
8
|
+
export * from "./endpoint-query-client.types.cjs";
|
|
9
|
+
export * from "./http-client.cjs";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,+BAA8B;AAC9B,qCAAoC;AACpC,wCAAuC;AACvC,8CAA6C;AAC7C,qCAAoC;AACpC,2CAA0C;AAC1C,4CAA2C;AAC3C,kDAAiD;AACjD,kCAAiC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./endpoint.js";
|
|
2
|
+
export * from "./endpoint.types.js";
|
|
3
|
+
export * from "./endpoint-mutation.js";
|
|
4
|
+
export * from "./endpoint-mutation.types.js";
|
|
5
|
+
export * from "./endpoint-query.js";
|
|
6
|
+
export * from "./endpoint-query.types.js";
|
|
7
|
+
export * from "./endpoint-query-client.js";
|
|
8
|
+
export * from "./endpoint-query-client.types.js";
|
|
9
|
+
export * from "./http-client.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,oCAAoC;AACpC,uCAAuC;AACvC,6CAA6C;AAC7C,oCAAoC;AACpC,0CAA0C;AAC1C,2CAA2C;AAC3C,iDAAiD;AACjD,iCAAiC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./endpoint.js";
|
|
2
|
+
export * from "./endpoint.types.js";
|
|
3
|
+
export * from "./endpoint-mutation.js";
|
|
4
|
+
export * from "./endpoint-mutation.types.js";
|
|
5
|
+
export * from "./endpoint-query.js";
|
|
6
|
+
export * from "./endpoint-query.types.js";
|
|
7
|
+
export * from "./endpoint-query-client.js";
|
|
8
|
+
export * from "./endpoint-query-client.types.js";
|
|
9
|
+
export * from "./http-client.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-tanstack-query-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"mobx",
|
|
6
6
|
"react-query",
|
|
@@ -13,7 +13,15 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"description": "OpenAPI/Swagger client codegen + endpoints integration with mobx-tanstack-query",
|
|
15
15
|
"type": "module",
|
|
16
|
-
"
|
|
16
|
+
"zshy": {
|
|
17
|
+
"bin": "src/cli/bin.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
"./package.json": "./package.json",
|
|
20
|
+
".": "./src/index.ts",
|
|
21
|
+
"./builtin": "./src/builtin/index.ts",
|
|
22
|
+
"./cli": "./src/cli/index.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
17
25
|
"bugs": {
|
|
18
26
|
"url": "https://github.com/js2me/mobx-tanstack-query-api/issues"
|
|
19
27
|
},
|
|
@@ -29,14 +37,14 @@
|
|
|
29
37
|
"@tanstack/query-core": "^5.85.7",
|
|
30
38
|
"@types/lodash": "^4.17.16",
|
|
31
39
|
"@types/lodash-es": "^4.17.12",
|
|
40
|
+
"cac": "^6.7.14",
|
|
32
41
|
"http-status-code-types": "^0.0.2",
|
|
33
42
|
"jiti": "^2.5.1",
|
|
34
|
-
"cac": "^6.7.14",
|
|
35
43
|
"mobx-tanstack-query": "^6.6.1",
|
|
36
44
|
"swagger-typescript-api": "13.2.10",
|
|
37
45
|
"ts-morph": "^26.0.0",
|
|
38
46
|
"undici-types": "^7.11.0",
|
|
39
|
-
"yummies": "^5.
|
|
47
|
+
"yummies": "^5.4.8"
|
|
40
48
|
},
|
|
41
49
|
"devDependencies": {
|
|
42
50
|
"@biomejs/biome": "^2.2.4",
|
|
@@ -48,158 +56,41 @@
|
|
|
48
56
|
"@vitest/coverage-istanbul": "^3.2.4",
|
|
49
57
|
"commitfmt": "^1.0.0",
|
|
50
58
|
"js2me-biome-config": "^1.0.5",
|
|
51
|
-
"
|
|
59
|
+
"sborshik": "^1.0.6",
|
|
52
60
|
"jsdom": "^26.0.0",
|
|
53
61
|
"lefthook": "^1.11.13",
|
|
54
62
|
"nodemon": "^3.1.9",
|
|
55
63
|
"rimraf": "^6.0.1",
|
|
56
64
|
"typescript": "^5.8.3",
|
|
57
65
|
"unplugin-swc": "^1.5.1",
|
|
58
|
-
"vitest": "^3.2.4"
|
|
66
|
+
"vitest": "^3.2.4",
|
|
67
|
+
"zshy": "^0.4.2"
|
|
59
68
|
},
|
|
69
|
+
"files": [
|
|
70
|
+
"dist"
|
|
71
|
+
],
|
|
72
|
+
"main": "./dist/index.cjs",
|
|
73
|
+
"module": "./dist/index.js",
|
|
74
|
+
"types": "./dist/index.d.cts",
|
|
60
75
|
"exports": {
|
|
61
|
-
"./
|
|
62
|
-
"import": "./builtin/index.js",
|
|
63
|
-
"default": "./builtin/index.js",
|
|
64
|
-
"types": "./builtin/index.d.ts"
|
|
65
|
-
},
|
|
66
|
-
"./cli/bin": {
|
|
67
|
-
"import": "./cli/bin.js",
|
|
68
|
-
"default": "./cli/bin.js",
|
|
69
|
-
"types": "./cli/bin.d.ts"
|
|
70
|
-
},
|
|
71
|
-
"./cli": {
|
|
72
|
-
"import": "./cli/index.js",
|
|
73
|
-
"default": "./cli/index.js",
|
|
74
|
-
"types": "./cli/index.d.ts"
|
|
75
|
-
},
|
|
76
|
-
"./cli/utils/define-config": {
|
|
77
|
-
"import": "./cli/utils/define-config.js",
|
|
78
|
-
"default": "./cli/utils/define-config.js",
|
|
79
|
-
"types": "./cli/utils/define-config.d.ts"
|
|
80
|
-
},
|
|
81
|
-
"./cli/utils/exec-config-path": {
|
|
82
|
-
"import": "./cli/utils/exec-config-path.js",
|
|
83
|
-
"default": "./cli/utils/exec-config-path.js",
|
|
84
|
-
"types": "./cli/utils/exec-config-path.d.ts"
|
|
85
|
-
},
|
|
86
|
-
"./cli/utils/resolve-config-path": {
|
|
87
|
-
"import": "./cli/utils/resolve-config-path.js",
|
|
88
|
-
"default": "./cli/utils/resolve-config-path.js",
|
|
89
|
-
"types": "./cli/utils/resolve-config-path.d.ts"
|
|
90
|
-
},
|
|
91
|
-
"./codegen": {
|
|
92
|
-
"import": "./codegen/index.js",
|
|
93
|
-
"default": "./codegen/index.js",
|
|
94
|
-
"types": "./codegen/index.d.ts"
|
|
95
|
-
},
|
|
96
|
-
"./codegen/templates/all-endpoints-per-file.tmpl": {
|
|
97
|
-
"import": "./codegen/templates/all-endpoints-per-file.tmpl.js",
|
|
98
|
-
"default": "./codegen/templates/all-endpoints-per-file.tmpl.js",
|
|
99
|
-
"types": "./codegen/templates/all-endpoints-per-file.tmpl.d.ts"
|
|
100
|
-
},
|
|
101
|
-
"./codegen/templates/all-exports.tmpl": {
|
|
102
|
-
"import": "./codegen/templates/all-exports.tmpl.js",
|
|
103
|
-
"default": "./codegen/templates/all-exports.tmpl.js",
|
|
104
|
-
"types": "./codegen/templates/all-exports.tmpl.d.ts"
|
|
105
|
-
},
|
|
106
|
-
"./codegen/templates/constants": {
|
|
107
|
-
"import": "./codegen/templates/constants.js",
|
|
108
|
-
"default": "./codegen/templates/constants.js",
|
|
109
|
-
"types": "./codegen/templates/constants.d.ts"
|
|
110
|
-
},
|
|
111
|
-
"./codegen/templates/data-contract.tmpl": {
|
|
112
|
-
"import": "./codegen/templates/data-contract.tmpl.js",
|
|
113
|
-
"default": "./codegen/templates/data-contract.tmpl.js",
|
|
114
|
-
"types": "./codegen/templates/data-contract.tmpl.d.ts"
|
|
115
|
-
},
|
|
116
|
-
"./codegen/templates/data-contracts-file.tmpl": {
|
|
117
|
-
"import": "./codegen/templates/data-contracts-file.tmpl.js",
|
|
118
|
-
"default": "./codegen/templates/data-contracts-file.tmpl.js",
|
|
119
|
-
"types": "./codegen/templates/data-contracts-file.tmpl.d.ts"
|
|
120
|
-
},
|
|
121
|
-
"./codegen/templates/endpoint-jsdoc.tmpl": {
|
|
122
|
-
"import": "./codegen/templates/endpoint-jsdoc.tmpl.js",
|
|
123
|
-
"default": "./codegen/templates/endpoint-jsdoc.tmpl.js",
|
|
124
|
-
"types": "./codegen/templates/endpoint-jsdoc.tmpl.d.ts"
|
|
125
|
-
},
|
|
126
|
-
"./codegen/templates/endpoint-per-file.tmpl": {
|
|
127
|
-
"import": "./codegen/templates/endpoint-per-file.tmpl.js",
|
|
128
|
-
"default": "./codegen/templates/endpoint-per-file.tmpl.js",
|
|
129
|
-
"types": "./codegen/templates/endpoint-per-file.tmpl.d.ts"
|
|
130
|
-
},
|
|
131
|
-
"./codegen/templates/index-ts-for-endpoint-per-file.tmpl": {
|
|
132
|
-
"import": "./codegen/templates/index-ts-for-endpoint-per-file.tmpl.js",
|
|
133
|
-
"default": "./codegen/templates/index-ts-for-endpoint-per-file.tmpl.js",
|
|
134
|
-
"types": "./codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts"
|
|
135
|
-
},
|
|
136
|
-
"./codegen/templates/meta-info.tmpl": {
|
|
137
|
-
"import": "./codegen/templates/meta-info.tmpl.js",
|
|
138
|
-
"default": "./codegen/templates/meta-info.tmpl.js",
|
|
139
|
-
"types": "./codegen/templates/meta-info.tmpl.d.ts"
|
|
140
|
-
},
|
|
141
|
-
"./codegen/templates/new-endpoint.tmpl": {
|
|
142
|
-
"import": "./codegen/templates/new-endpoint.tmpl.js",
|
|
143
|
-
"default": "./codegen/templates/new-endpoint.tmpl.js",
|
|
144
|
-
"types": "./codegen/templates/new-endpoint.tmpl.d.ts"
|
|
145
|
-
},
|
|
146
|
-
"./codegen/utils/remove-unused-types": {
|
|
147
|
-
"import": "./codegen/utils/remove-unused-types.js",
|
|
148
|
-
"default": "./codegen/utils/remove-unused-types.js",
|
|
149
|
-
"types": "./codegen/utils/remove-unused-types.d.ts"
|
|
150
|
-
},
|
|
151
|
-
"./codegen/utils/unpack-filter-option": {
|
|
152
|
-
"import": "./codegen/utils/unpack-filter-option.js",
|
|
153
|
-
"default": "./codegen/utils/unpack-filter-option.js",
|
|
154
|
-
"types": "./codegen/utils/unpack-filter-option.d.ts"
|
|
155
|
-
},
|
|
76
|
+
"./package.json": "./package.json",
|
|
156
77
|
".": {
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
},
|
|
161
|
-
"./runtime/endpoint-infinite-query": {
|
|
162
|
-
"import": "./runtime/endpoint-infinite-query.js",
|
|
163
|
-
"default": "./runtime/endpoint-infinite-query.js",
|
|
164
|
-
"types": "./runtime/endpoint-infinite-query.d.ts"
|
|
78
|
+
"types": "./dist/index.d.cts",
|
|
79
|
+
"import": "./dist/index.js",
|
|
80
|
+
"require": "./dist/index.cjs"
|
|
165
81
|
},
|
|
166
|
-
"./
|
|
167
|
-
"
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
},
|
|
171
|
-
"./runtime/endpoint-query-client": {
|
|
172
|
-
"import": "./runtime/endpoint-query-client.js",
|
|
173
|
-
"default": "./runtime/endpoint-query-client.js",
|
|
174
|
-
"types": "./runtime/endpoint-query-client.d.ts"
|
|
175
|
-
},
|
|
176
|
-
"./runtime/endpoint-query": {
|
|
177
|
-
"import": "./runtime/endpoint-query.js",
|
|
178
|
-
"default": "./runtime/endpoint-query.js",
|
|
179
|
-
"types": "./runtime/endpoint-query.d.ts"
|
|
180
|
-
},
|
|
181
|
-
"./runtime/endpoint": {
|
|
182
|
-
"import": "./runtime/endpoint.js",
|
|
183
|
-
"default": "./runtime/endpoint.js",
|
|
184
|
-
"types": "./runtime/endpoint.d.ts"
|
|
185
|
-
},
|
|
186
|
-
"./runtime/http-client": {
|
|
187
|
-
"import": "./runtime/http-client.js",
|
|
188
|
-
"default": "./runtime/http-client.js",
|
|
189
|
-
"types": "./runtime/http-client.d.ts"
|
|
190
|
-
},
|
|
191
|
-
"./runtime": {
|
|
192
|
-
"import": "./runtime/index.js",
|
|
193
|
-
"default": "./runtime/index.js",
|
|
194
|
-
"types": "./runtime/index.d.ts"
|
|
82
|
+
"./builtin": {
|
|
83
|
+
"types": "./dist/builtin/index.d.cts",
|
|
84
|
+
"import": "./dist/builtin/index.js",
|
|
85
|
+
"require": "./dist/builtin/index.cjs"
|
|
195
86
|
},
|
|
196
|
-
"./
|
|
87
|
+
"./cli": {
|
|
88
|
+
"types": "./dist/cli/index.d.cts",
|
|
89
|
+
"import": "./dist/cli/index.js",
|
|
90
|
+
"require": "./dist/cli/index.cjs"
|
|
91
|
+
}
|
|
197
92
|
},
|
|
198
|
-
"
|
|
199
|
-
"*"
|
|
200
|
-
],
|
|
201
|
-
"main": "./index.js",
|
|
202
|
-
"typings": "./index.d.ts",
|
|
93
|
+
"bin": "./dist/cli/bin.cjs",
|
|
203
94
|
"scripts": {
|
|
204
95
|
"clean": "rimraf dist",
|
|
205
96
|
"lint:check": "pnpm exec biome check --write --no-errors-on-unmatched --files-ignore-unknown=true",
|
|
@@ -207,11 +98,11 @@
|
|
|
207
98
|
"check": "npm run lint:check && npm run ts:check",
|
|
208
99
|
"prebuild": "npm run clean && npm run check",
|
|
209
100
|
"build:watch": "pnpm build && nodemon --delay 0.5 --watch src --ext ts,tsx --exec \"pnpm build\"",
|
|
210
|
-
"build": "
|
|
211
|
-
"pub": "
|
|
212
|
-
"pub:patch": "
|
|
213
|
-
"pub:minor": "
|
|
214
|
-
"pub:major": "
|
|
101
|
+
"build": "zshy",
|
|
102
|
+
"pub": "pnpm run build && sborshik publish",
|
|
103
|
+
"pub:patch": "PUBLISH_VERSION=patch pnpm run build",
|
|
104
|
+
"pub:minor": "PUBLISH_VERSION=minor pnpm run build",
|
|
105
|
+
"pub:major": "PUBLISH_VERSION=major pnpm run build",
|
|
215
106
|
"test": "vitest run --config vitest.config.ts",
|
|
216
107
|
"test:watch": "vitest watch --config vitest.config.ts",
|
|
217
108
|
"test:coverage": "vitest run --config vitest.config.ts --coverage",
|
|
Binary file
|
package/assets/logo.png
DELETED
|
Binary file
|
package/assets/logo.pxz
DELETED
|
Binary file
|
package/builtin/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { EndpointQueryClient } from '../runtime/endpoint-query-client.js';
|
|
2
|
-
import { HttpClient } from '../runtime/http-client.js';
|
|
3
|
-
export declare const queryClient: EndpointQueryClient;
|
|
4
|
-
export declare const http: HttpClient<unknown>;
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
package/builtin/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builtin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAqB,MAAM,2BAA2B,CAAC;AAI1E,eAAO,MAAM,WAAW,qBAkBtB,CAAC;AAEH,eAAO,MAAM,IAAI,qBAAqB,CAAC"}
|
package/cli/bin.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { cac } from 'cac';
|
|
2
|
-
import { generateApi } from '../codegen/index.js';
|
|
3
|
-
import { defineConfig } from './utils/define-config.js';
|
|
4
|
-
import { execConfigPath } from './utils/exec-config-path.js';
|
|
5
|
-
import { resolveConfigPath } from './utils/resolve-config-path.js';
|
|
6
|
-
let cli = cac('mobx-tanstack-query-api');
|
|
7
|
-
cli = cli.option('-c, --config <file>', `[string] use specified config file`);
|
|
8
|
-
cli.help();
|
|
9
|
-
const parsed = cli.parse();
|
|
10
|
-
if (!parsed.options.help) {
|
|
11
|
-
const configPath = resolveConfigPath(typeof parsed.options.config === 'string' ? parsed.options.config : null);
|
|
12
|
-
execConfigPath(configPath).then((generateApiParams) => {
|
|
13
|
-
defineConfig(generateApiParams).forEach(generateApi);
|
|
14
|
-
});
|
|
15
|
-
}
|
package/cli/index.d.ts
DELETED
package/cli/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
package/cli/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './utils/define-config.js';
|