mobx-tanstack-query-api 0.0.37 → 0.0.38
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/codegen/templates/new-request-info.tmpl.d.ts.map +1 -1
- package/codegen/templates/new-request-info.tmpl.js +15 -69
- package/package.json +3 -3
- package/runtime/endpoint-mutation.d.ts.map +1 -1
- package/runtime/endpoint-mutation.js +1 -1
- package/runtime/endpoint-query-client.d.ts +1 -0
- package/runtime/endpoint-query-client.d.ts.map +1 -1
- package/runtime/endpoint-query-client.js +14 -0
- package/runtime/endpoint-query.d.ts +5 -6
- package/runtime/endpoint-query.d.ts.map +1 -1
- package/runtime/endpoint-query.js +33 -21
- package/runtime/endpoint.d.ts +14 -27
- package/runtime/endpoint.d.ts.map +1 -1
- package/runtime/endpoint.js +26 -63
- package/runtime/endpoint.types.d.ts +14 -6
- package/runtime/endpoint.types.d.ts.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-request-info.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/new-request-info.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAiBD,eAAO,MAAM,kBAAkB,GAAI,gDAKhC,wBAAwB;;;
|
|
1
|
+
{"version":3,"file":"new-request-info.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/new-request-info.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAiBD,eAAO,MAAM,kBAAkB,GAAI,gDAKhC,wBAAwB;;;CA2K1B,CAAC"}
|
|
@@ -29,9 +29,9 @@ export const newRequestInfoTmpl = ({ route, apiParams, importFileParams, utils,
|
|
|
29
29
|
type: 'RequestParams',
|
|
30
30
|
defaultValue: '{}',
|
|
31
31
|
};
|
|
32
|
-
const getArgs = ({ withPayload, withRequestConfigParam,
|
|
32
|
+
const getArgs = ({ withPayload, withRequestConfigParam, }) => {
|
|
33
33
|
return _.sortBy(_.compact([
|
|
34
|
-
...(
|
|
34
|
+
...(requestParams
|
|
35
35
|
? [
|
|
36
36
|
{
|
|
37
37
|
name: pathParams.length > 0
|
|
@@ -46,38 +46,18 @@ export const newRequestInfoTmpl = ({ route, apiParams, importFileParams, utils,
|
|
|
46
46
|
withRequestConfigParam && requestConfigParam,
|
|
47
47
|
]), [(o) => o.optional]);
|
|
48
48
|
};
|
|
49
|
+
const tags = (raw.tags || []).filter(Boolean);
|
|
50
|
+
const allArgs = getArgs({
|
|
51
|
+
withPayload: true,
|
|
52
|
+
withRequestConfigParam: true,
|
|
53
|
+
});
|
|
54
|
+
const requiredArgs = allArgs.filter((it) => !it.optional);
|
|
49
55
|
const requestOutputDataTypes = positiveResponseTypes.map((it) => it.type);
|
|
50
56
|
const requestOutputErrorType = routeResponse.errorType;
|
|
51
57
|
let requestInputCombinedType;
|
|
52
|
-
const requestInfoFnArgNames =
|
|
53
|
-
withRequestParams: true,
|
|
54
|
-
withRequestConfigParam: true,
|
|
55
|
-
withPayload: true,
|
|
56
|
-
}).map(({ name }) => name);
|
|
58
|
+
const requestInfoFnArgNames = allArgs.map(({ name }) => name);
|
|
57
59
|
const pathParamsToInline = path.split('/').slice(1);
|
|
58
60
|
let lastDynamicStructPos = 0;
|
|
59
|
-
const pathParamsStructs = pathParamsToInline.map((param, i) => {
|
|
60
|
-
if (param.includes('${')) {
|
|
61
|
-
const paramName = param.replace('${', '').replace('}', '');
|
|
62
|
-
return {
|
|
63
|
-
type: 'dynamic',
|
|
64
|
-
key: paramName,
|
|
65
|
-
i,
|
|
66
|
-
param: lastDynamicStructPos++,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
type: 'static',
|
|
71
|
-
value: param,
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
const dataParamStruct = payload == null
|
|
75
|
-
? null
|
|
76
|
-
: {
|
|
77
|
-
type: 'dynamic',
|
|
78
|
-
key: payload.name,
|
|
79
|
-
param: lastDynamicStructPos++,
|
|
80
|
-
};
|
|
81
61
|
const queryParamStruct = query == null
|
|
82
62
|
? null
|
|
83
63
|
: {
|
|
@@ -90,11 +70,7 @@ export const newRequestInfoTmpl = ({ route, apiParams, importFileParams, utils,
|
|
|
90
70
|
lastDynamicStructPos++;
|
|
91
71
|
}
|
|
92
72
|
let requestInputType = `{
|
|
93
|
-
${
|
|
94
|
-
withRequestParams: true,
|
|
95
|
-
withRequestConfigParam: true,
|
|
96
|
-
withPayload: true,
|
|
97
|
-
})
|
|
73
|
+
${allArgs
|
|
98
74
|
.map(({ name, optional, type, defaultValue }) => {
|
|
99
75
|
const isCombinedType = name.includes('...') || name === 'query';
|
|
100
76
|
if (isCombinedType) {
|
|
@@ -109,17 +85,6 @@ export const newRequestInfoTmpl = ({ route, apiParams, importFileParams, utils,
|
|
|
109
85
|
if (requestInputCombinedType) {
|
|
110
86
|
requestInputType = `${requestInputCombinedType.type} & ${requestInputType}`;
|
|
111
87
|
}
|
|
112
|
-
const requestKeyType = `[
|
|
113
|
-
${getArgs({
|
|
114
|
-
withRequestParams: true,
|
|
115
|
-
withRequestConfigParam: true,
|
|
116
|
-
withPayload: true,
|
|
117
|
-
})
|
|
118
|
-
.map(({ name, optional, type }) => {
|
|
119
|
-
return `${name.includes('...') || name === 'query' ? 'params' : name}${optional ? '?' : ''}:${type}`;
|
|
120
|
-
})
|
|
121
|
-
.join(', ')}
|
|
122
|
-
]`;
|
|
123
88
|
const requestInfoMeta = apiParams.getEndpointMeta?.(route, utils);
|
|
124
89
|
const requestMeta = apiParams.getRequestMeta?.(route, utils);
|
|
125
90
|
const resultPath = (apiParams.requestPathPrefix ?? '') +
|
|
@@ -131,10 +96,10 @@ export const newRequestInfoTmpl = ({ route, apiParams, importFileParams, utils,
|
|
|
131
96
|
...requestOutputDataTypes,
|
|
132
97
|
requestOutputErrorType,
|
|
133
98
|
...getArgs({
|
|
134
|
-
withRequestParams: true,
|
|
135
99
|
withPayload: true,
|
|
136
100
|
}).map((it) => it.type),
|
|
137
101
|
]);
|
|
102
|
+
const pathDeclaration = resultPath.replaceAll('$', '');
|
|
138
103
|
return {
|
|
139
104
|
reservedDataContractNames,
|
|
140
105
|
content: `
|
|
@@ -142,11 +107,10 @@ new ${importFileParams.endpoint.exportName}<
|
|
|
142
107
|
${requestOutputDataTypes.join('|') || 'any'},
|
|
143
108
|
${requestOutputErrorType},
|
|
144
109
|
${requestInputType},
|
|
145
|
-
${requestKeyType},
|
|
146
110
|
${requestInfoMeta?.typeName ?? 'any'}
|
|
147
111
|
>(
|
|
148
112
|
{
|
|
149
|
-
params: (${requestInfoFnArgNames
|
|
113
|
+
params: ({ ${requestInfoFnArgNames} }) => ({
|
|
150
114
|
path: \`${resultPath}\`,
|
|
151
115
|
method: '${_.upperCase(method)}',
|
|
152
116
|
${requestMeta?.tmplData ? `meta: ${requestMeta.tmplData},` : ''}
|
|
@@ -157,29 +121,11 @@ new ${importFileParams.endpoint.exportName}<
|
|
|
157
121
|
${responseFormat ? `format: ${responseFormat},` : ''}
|
|
158
122
|
...${requestInfoFnArgNames.at(-1)},
|
|
159
123
|
}),
|
|
124
|
+
requiredParams: [${requiredArgs.map((it) => `"${it.name}"`)}],
|
|
160
125
|
operationId: "${raw.operationId}",
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
],
|
|
126
|
+
pathDeclaration: "${pathDeclaration}",
|
|
127
|
+
tags: [${tags.map((tag) => `"${tag}"`)}],
|
|
164
128
|
meta: ${requestInfoMeta?.tmplData ?? '{} as any'},
|
|
165
|
-
keys: [
|
|
166
|
-
${_.compact([
|
|
167
|
-
...pathParamsStructs.map((struct) => {
|
|
168
|
-
if (struct.type === 'dynamic') {
|
|
169
|
-
return `{ name: '${struct.key}', param: ${struct.param} }`;
|
|
170
|
-
}
|
|
171
|
-
return `"${struct.value}"`;
|
|
172
|
-
}),
|
|
173
|
-
dataParamStruct &&
|
|
174
|
-
`
|
|
175
|
-
{ name: "${dataParamStruct.key}", param: ${dataParamStruct.param} }
|
|
176
|
-
`,
|
|
177
|
-
queryParamStruct &&
|
|
178
|
-
`{ name: "${queryParamStruct.key}", rest: true }`,
|
|
179
|
-
requestConfigParam &&
|
|
180
|
-
`{ name: "${requestConfigParam.name}", param: ${lastDynamicStructPos} }`,
|
|
181
|
-
]).join(',')}
|
|
182
|
-
],
|
|
183
129
|
},
|
|
184
130
|
${importFileParams.queryClient.exportName},
|
|
185
131
|
${importFileParams.httpClient.exportName},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-tanstack-query-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": "js2me",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"jsdom": "^26.0.0",
|
|
35
35
|
"nodemon": "^3.1.9",
|
|
36
36
|
"rimraf": "^6.0.1",
|
|
37
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
38
|
"unplugin-swc": "^1.5.1",
|
|
39
39
|
"vitest": "^3.0.5"
|
|
40
40
|
},
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
"test": "vitest run",
|
|
157
157
|
"test:watch": "vitest watch",
|
|
158
158
|
"test:coverage": "vitest run --coverage",
|
|
159
|
-
"dev": "pnpm
|
|
159
|
+
"dev": "pnpm build && nodemon --delay 0.5 --watch src --ext ts,tsx --exec \"pnpm build && pnpm playground\"",
|
|
160
160
|
"playground": "node ./playground/index.mjs"
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-mutation.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-mutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,SAAS,EACV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,qBAAqB,CAC/B,UAAU,SAAS,SAAS,EAC5B,aAAa,SAAS,SAAS,GAAG,IAAI,GAAG,IAAI,IAC3C,UAAU,GACZ,CAAC,aAAa,SAAS,IAAI,GAEvB,EAAE,GACF,qBAAqB,CAAC,aAAa,CAAC,SAAS,IAAI,GAC/C;IAAE,IAAI,CAAC,EAAE,aAAa,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AAEjC,MAAM,WAAW,uBAAuB,CACtC,SAAS,SAAS,WAAW,EAC7B,aAAa,SAAS,SAAS,GAAG,IAAI,GAAG,IAAI,CAC7C,SAAQ,IAAI,CACV,kBAAkB,CAChB,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AE,CAAC,CAAC;AAEjC,MAAM,WAAW,uBAAuB,CACtC,SAAS,SAAS,WAAW,EAC7B,aAAa,SAAS,SAAS,GAAG,IAAI,GAAG,IAAI,CAC7C,SAAQ,IAAI,CACV,kBAAkB,CAChB,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,EAC3C,qBAAqB,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,EACnE,kBAAkB,CAAC,SAAS,CAAC,CAC9B,EACD,aAAa,GAAG,YAAY,CAC7B;CAAG;AAEN,qBAAa,gBAAgB,CAC3B,SAAS,SAAS,WAAW,EAC7B,aAAa,SAAS,SAAS,GAAG,IAAI,GAAG,IAAI,CAC7C,SAAQ,YAAY,CACpB,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,EAC3C,qBAAqB,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,CACpE;IAEG,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,SAAS,EAC3B,WAAW,EAAE,mBAAmB,EAChC,OAAO,EAAE,uBAAuB,CAAC,SAAS,EAAE,aAAa,CAAC;CAa7D"}
|
|
@@ -8,7 +8,7 @@ export class EndpointMutation extends MobxMutation {
|
|
|
8
8
|
...options,
|
|
9
9
|
queryClient,
|
|
10
10
|
mutationFn: async (input) => {
|
|
11
|
-
const response = await endpoint.request(
|
|
11
|
+
const response = await endpoint.request(input);
|
|
12
12
|
return response;
|
|
13
13
|
},
|
|
14
14
|
});
|
|
@@ -2,6 +2,7 @@ import { InvalidateOptions, InvalidateQueryFilters } from '@tanstack/query-core'
|
|
|
2
2
|
import { MobxQueryClient } from 'mobx-tanstack-query';
|
|
3
3
|
export declare class EndpointQueryClient extends MobxQueryClient {
|
|
4
4
|
invalidateByOperationId(operationId: string | RegExp, filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
5
|
+
invalidateByPath(path: string | RegExp, filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
5
6
|
invalidateByTags(tags: any[], filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=endpoint-query-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-query-client.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,qBAAa,mBAAoB,SAAQ,eAAe;IACtD,uBAAuB,CACrB,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,OAAO,CAAC,EAAE,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC,EACvE,OAAO,CAAC,EAAE,iBAAiB;IAoB7B,gBAAgB,CACd,IAAI,EAAE,GAAG,EAAE,EACX,OAAO,CAAC,EAAE,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC,EACvE,OAAO,CAAC,EAAE,iBAAiB;CAgB9B"}
|
|
1
|
+
{"version":3,"file":"endpoint-query-client.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,qBAAa,mBAAoB,SAAQ,eAAe;IACtD,uBAAuB,CACrB,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,OAAO,CAAC,EAAE,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC,EACvE,OAAO,CAAC,EAAE,iBAAiB;IAoB7B,gBAAgB,CACd,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,OAAO,CAAC,EAAE,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC,EACvE,OAAO,CAAC,EAAE,iBAAiB;IAoB7B,gBAAgB,CACd,IAAI,EAAE,GAAG,EAAE,EACX,OAAO,CAAC,EAAE,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC,EACvE,OAAO,CAAC,EAAE,iBAAiB;CAgB9B"}
|
|
@@ -14,6 +14,20 @@ export class EndpointQueryClient extends MobxQueryClient {
|
|
|
14
14
|
},
|
|
15
15
|
}, options);
|
|
16
16
|
}
|
|
17
|
+
invalidateByPath(path, filters, options) {
|
|
18
|
+
return this.invalidateQueries({
|
|
19
|
+
...filters,
|
|
20
|
+
predicate: (query) => {
|
|
21
|
+
if (query.meta?.pathDeclaration) {
|
|
22
|
+
if (typeof path === 'string') {
|
|
23
|
+
return String(query.meta.pathDeclaration).startsWith(path);
|
|
24
|
+
}
|
|
25
|
+
return path.test(String(query.meta.pathDeclaration));
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
},
|
|
29
|
+
}, options);
|
|
30
|
+
}
|
|
17
31
|
invalidateByTags(tags, filters, options) {
|
|
18
32
|
return this.invalidateQueries({
|
|
19
33
|
...filters,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { QueryFunctionContext } from '@tanstack/query-core';
|
|
2
|
-
import { MobxQuery, MobxQueryConfig
|
|
2
|
+
import { MobxQuery, MobxQueryConfig } from 'mobx-tanstack-query';
|
|
3
3
|
import { MaybeFalsy, Unpromise } from 'yummies/utils/types';
|
|
4
4
|
import { EndpointQueryClient } from './endpoint-query-client.js';
|
|
5
5
|
import { AnyEndpoint, InferEndpointError, InferEndpointInput, InferEndpointResponse } from './endpoint.types.js';
|
|
6
6
|
export type EndpointQueryOptions<TOutput, TEndpoint extends AnyEndpoint> = {
|
|
7
|
-
input
|
|
7
|
+
input?: () => MaybeFalsy<InferEndpointInput<TEndpoint>>;
|
|
8
8
|
transform?: (response: Unpromise<InferEndpointResponse<TEndpoint>>) => TOutput;
|
|
9
9
|
} & Omit<MobxQueryConfig<TOutput, InferEndpointError<TEndpoint>>, 'options' | 'queryFn' | 'queryClient'>;
|
|
10
10
|
export declare class EndpointQuery<TOutput, TEndpoint extends AnyEndpoint> extends MobxQuery<TOutput, InferEndpointError<TEndpoint>> {
|
|
@@ -12,11 +12,10 @@ export declare class EndpointQuery<TOutput, TEndpoint extends AnyEndpoint> exten
|
|
|
12
12
|
response: Unpromise<InferEndpointResponse<TEndpoint>> | null;
|
|
13
13
|
constructor(endpoint: TEndpoint, queryClient: EndpointQueryClient, { input: getInput, ...queryOptions }: EndpointQueryOptions<TOutput, TEndpoint>);
|
|
14
14
|
setInput(input: MaybeFalsy<InferEndpointInput<TEndpoint>>): Promise<Unpromise<InferEndpointResponse<TEndpoint>>>;
|
|
15
|
-
|
|
15
|
+
buildOptionsFromInput(input: MaybeFalsy<Partial<InferEndpointInput<TEndpoint>>>): {
|
|
16
16
|
enabled: boolean;
|
|
17
|
-
queryKey: any;
|
|
17
|
+
queryKey: any[];
|
|
18
18
|
};
|
|
19
|
-
protected
|
|
20
|
-
protected buildParamsFromContext(ctx: QueryFunctionContext<any, any>): any;
|
|
19
|
+
protected getInputFromContext(ctx: QueryFunctionContext<any, any>): InferEndpointInput<TEndpoint>;
|
|
21
20
|
}
|
|
22
21
|
//# sourceMappingURL=endpoint-query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-query.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB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,EAAE,UAAU,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,GAC/C,OAAO,CAAC,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC;IAOvD,qBAAqB,CACnB,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAC;;;;IAkB3D,SAAS,CAAC,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAG,CAAC,GAC7B,kBAAkB,CAAC,SAAS,CAAC;CAElE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { makeObservable, observable, runInAction, when } from 'mobx';
|
|
2
|
-
import { MobxQuery
|
|
2
|
+
import { MobxQuery } from 'mobx-tanstack-query';
|
|
3
3
|
export class EndpointQuery extends MobxQuery {
|
|
4
4
|
endpoint;
|
|
5
5
|
response = null;
|
|
@@ -14,25 +14,33 @@ export class EndpointQuery extends MobxQuery {
|
|
|
14
14
|
},
|
|
15
15
|
options: ({ options }) => {
|
|
16
16
|
const willEnableManually = options?.enabled === false;
|
|
17
|
-
const input = getInput();
|
|
18
|
-
|
|
17
|
+
const input = (getInput?.() || {});
|
|
18
|
+
const builtOptions = this.buildOptionsFromInput(input);
|
|
19
|
+
return {
|
|
20
|
+
...options,
|
|
21
|
+
...builtOptions,
|
|
22
|
+
enabled: willEnableManually ? false : builtOptions.enabled,
|
|
23
|
+
};
|
|
19
24
|
},
|
|
20
25
|
queryFn: async (ctx) => {
|
|
21
26
|
runInAction(() => {
|
|
22
27
|
this.response = null;
|
|
23
28
|
});
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
+
const input = this.getInputFromContext(ctx);
|
|
30
|
+
let requestParams = input.request;
|
|
31
|
+
if (requestParams) {
|
|
32
|
+
if (!requestParams.signal) {
|
|
33
|
+
requestParams.signal = ctx.signal;
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
else {
|
|
32
|
-
|
|
37
|
+
requestParams = { signal: ctx.signal };
|
|
33
38
|
}
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
const fixedInput = {
|
|
40
|
+
...input,
|
|
41
|
+
request: requestParams,
|
|
42
|
+
};
|
|
43
|
+
const response = await endpoint.request(fixedInput);
|
|
36
44
|
runInAction(() => {
|
|
37
45
|
this.response = response;
|
|
38
46
|
});
|
|
@@ -44,23 +52,27 @@ export class EndpointQuery extends MobxQuery {
|
|
|
44
52
|
makeObservable(this);
|
|
45
53
|
}
|
|
46
54
|
async setInput(input) {
|
|
47
|
-
// @ts-ignore
|
|
48
55
|
this.update(this.buildOptionsFromInput(input));
|
|
49
56
|
await when(() => !this.result.isFetching);
|
|
50
57
|
// @ts-ignore
|
|
51
58
|
return this.result.data;
|
|
52
59
|
}
|
|
53
|
-
|
|
60
|
+
buildOptionsFromInput(input) {
|
|
61
|
+
const { requiredParams } = this.endpoint.configuration;
|
|
62
|
+
let hasRequiredParams = false;
|
|
63
|
+
if (requiredParams.length > 0) {
|
|
64
|
+
hasRequiredParams =
|
|
65
|
+
!!input && requiredParams.every((param) => param in input);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
hasRequiredParams = true;
|
|
69
|
+
}
|
|
54
70
|
return {
|
|
55
|
-
enabled:
|
|
56
|
-
queryKey:
|
|
71
|
+
enabled: hasRequiredParams,
|
|
72
|
+
queryKey: this.endpoint.getQueryKey(input || {}),
|
|
57
73
|
};
|
|
58
74
|
}
|
|
59
|
-
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
buildParamsFromContext(ctx) {
|
|
63
|
-
const input = this.endpoint.getQueryKey(ctx.queryKey);
|
|
64
|
-
return this.endpoint.getParamsFromInput(input);
|
|
75
|
+
getInputFromContext(ctx) {
|
|
76
|
+
return (ctx.queryKey[2] || {});
|
|
65
77
|
}
|
|
66
78
|
}
|
package/runtime/endpoint.d.ts
CHANGED
|
@@ -1,40 +1,27 @@
|
|
|
1
1
|
import { InvalidateOptions, InvalidateQueryFilters } from '@tanstack/query-core';
|
|
2
|
-
import { AnyObject } from 'yummies/utils/types';
|
|
2
|
+
import { AllPropertiesOptional, AnyObject } from 'yummies/utils/types';
|
|
3
3
|
import { EndpointMutation, EndpointMutationOptions } from './endpoint-mutation.js';
|
|
4
4
|
import { EndpointQueryClient } from './endpoint-query-client.js';
|
|
5
5
|
import { EndpointQuery, EndpointQueryOptions } from './endpoint-query.js';
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
params: (...params: TParams) => FullRequestParams;
|
|
11
|
-
keys: (string | {
|
|
12
|
-
name: string;
|
|
13
|
-
param: number;
|
|
14
|
-
} | {
|
|
15
|
-
name: string;
|
|
16
|
-
rest: true;
|
|
17
|
-
})[];
|
|
18
|
-
tags: string[];
|
|
6
|
+
import { EndpointConfiguration } from './endpoint.types.js';
|
|
7
|
+
import type { HttpClient } from './http-client.js';
|
|
8
|
+
export interface Endpoint<TData, TError, TInput extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
9
|
+
(...args: AllPropertiesOptional<TInput> extends true ? [input?: TInput] : [input: TInput]): ReturnType<Endpoint<TData, TError, TInput, TMetaData>['request']>;
|
|
19
10
|
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
export declare class Endpoint<TData, TError, TInput extends AnyObject, TParams extends any[] = any[], TMetaData extends AnyObject = AnyObject> {
|
|
24
|
-
configuration: EndpointConfiguration<TParams, TMetaData>;
|
|
11
|
+
export declare class Endpoint<TData, TError, TInput extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
12
|
+
configuration: EndpointConfiguration<NoInfer<TInput>, TMetaData>;
|
|
25
13
|
protected queryClient: EndpointQueryClient;
|
|
26
14
|
protected http: HttpClient;
|
|
27
15
|
meta: TMetaData;
|
|
28
|
-
constructor(configuration: EndpointConfiguration<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
getParamsFromInput(input: TInput): TParams;
|
|
32
|
-
getFullUrl(input: TInput): string;
|
|
33
|
-
getPath(input: TInput): string;
|
|
16
|
+
constructor(configuration: EndpointConfiguration<NoInfer<TInput>, TMetaData>, queryClient: EndpointQueryClient, http: HttpClient);
|
|
17
|
+
getFullUrl(...args: AllPropertiesOptional<TInput> extends true ? [input?: TInput] : [input: TInput]): string;
|
|
18
|
+
getPath(...args: AllPropertiesOptional<TInput> extends true ? [input?: TInput] : [input: TInput]): string;
|
|
34
19
|
get tags(): string[];
|
|
20
|
+
get pathDeclaration(): string;
|
|
35
21
|
get operationId(): string;
|
|
36
|
-
request(...
|
|
37
|
-
getQueryKey(input: TInput): any[];
|
|
22
|
+
request(...args: AllPropertiesOptional<TInput> extends true ? [input?: TInput] : [input: TInput]): Promise<import("./http-client.js").HttpResponse<TData, TError>>;
|
|
23
|
+
getQueryKey(...args: AllPropertiesOptional<TInput> extends true ? [input?: TInput] : [input: TInput]): any[];
|
|
24
|
+
invalidateByPath(filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
38
25
|
invalidateByOperationId(filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
39
26
|
invalidateByTags(filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
40
27
|
invalidate(input: TInput, filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,sBAAsB,CAA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AAC,EAAE,MAAM,CAAC;KACxB,EACD,OAAO,CAAC,EAAE,iBAAiB;IAY7B,UAAU,CAAC,aAAa,SAAS,SAAS,GAAG,IAAI,GAAG,IAAI,EAEtD,OAAO,EAAE,uBAAuB,CAAC,OAAO,IAAI,EAAE,aAAa,CAAC;IAM9D,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,oBAAoB,CAAC,OAAO,EAAE,OAAO,IAAI,CAAC;CAOrE"}
|
package/runtime/endpoint.js
CHANGED
|
@@ -13,8 +13,8 @@ export class Endpoint {
|
|
|
13
13
|
// Сохраняем оригинальный инстанс
|
|
14
14
|
const instance = this;
|
|
15
15
|
// Создаем функцию-обертку
|
|
16
|
-
const callable = function (...
|
|
17
|
-
return instance.request.apply(instance,
|
|
16
|
+
const callable = function (...args) {
|
|
17
|
+
return instance.request.apply(instance, args);
|
|
18
18
|
};
|
|
19
19
|
// Копируем прототип
|
|
20
20
|
Object.setPrototypeOf(callable, new.target.prototype);
|
|
@@ -31,76 +31,36 @@ export class Endpoint {
|
|
|
31
31
|
});
|
|
32
32
|
return callable;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (this._hasRestParam === undefined) {
|
|
37
|
-
this._hasRestParam = this.configuration.keys.some((key) => {
|
|
38
|
-
if (typeof key !== 'string' && 'rest' in key) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return this._hasRestParam;
|
|
44
|
-
}
|
|
45
|
-
getParamsFromInput(input) {
|
|
46
|
-
const args = [];
|
|
47
|
-
const restParams = {};
|
|
48
|
-
if (this.hasRestParam) {
|
|
49
|
-
args[0] = restParams;
|
|
50
|
-
}
|
|
51
|
-
this.configuration.keys.forEach((key) => {
|
|
52
|
-
if (typeof key === 'object') {
|
|
53
|
-
if (key.name === 'request') {
|
|
54
|
-
args.push(input[key.name]);
|
|
55
|
-
}
|
|
56
|
-
else if (this.hasRestParam) {
|
|
57
|
-
if ('rest' in key) {
|
|
58
|
-
Object.assign(restParams, input);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else if ('param' in key) {
|
|
62
|
-
args[key.param] = input[key.name];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return args;
|
|
67
|
-
}
|
|
68
|
-
getFullUrl(input) {
|
|
69
|
-
const params = this.configuration.params(...this.getParamsFromInput(input));
|
|
34
|
+
getFullUrl(...args) {
|
|
35
|
+
const params = this.configuration.params(args[0] ?? {});
|
|
70
36
|
return this.http.buildUrl(params);
|
|
71
37
|
}
|
|
72
|
-
getPath(
|
|
73
|
-
|
|
38
|
+
getPath(...args) {
|
|
39
|
+
const params = this.configuration.params(args[0] ?? {});
|
|
40
|
+
return params.path;
|
|
74
41
|
}
|
|
75
42
|
get tags() {
|
|
76
43
|
return this.configuration.tags;
|
|
77
44
|
}
|
|
45
|
+
get pathDeclaration() {
|
|
46
|
+
return this.configuration.pathDeclaration;
|
|
47
|
+
}
|
|
78
48
|
get operationId() {
|
|
79
49
|
return this.configuration.operationId;
|
|
80
50
|
}
|
|
81
|
-
request(...
|
|
82
|
-
return this.http.request(this.configuration.params(
|
|
51
|
+
request(...args) {
|
|
52
|
+
return this.http.request(this.configuration.params(args[0] ?? {}));
|
|
83
53
|
}
|
|
84
|
-
getQueryKey(
|
|
85
|
-
const
|
|
86
|
-
return
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
else {
|
|
95
|
-
const param = restParams[key.name];
|
|
96
|
-
delete restParams[key.name];
|
|
97
|
-
return param;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
return input[key.name];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
54
|
+
getQueryKey(...args) {
|
|
55
|
+
const input = args[0] ?? {};
|
|
56
|
+
return [
|
|
57
|
+
this.configuration.operationId,
|
|
58
|
+
this.configuration.pathDeclaration,
|
|
59
|
+
input,
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
invalidateByPath(filters, options) {
|
|
63
|
+
return this.queryClient.invalidateByPath(this.configuration.pathDeclaration, filters, options);
|
|
104
64
|
}
|
|
105
65
|
invalidateByOperationId(filters, options) {
|
|
106
66
|
return this.queryClient.invalidateByOperationId(this.operationId, filters, options);
|
|
@@ -115,9 +75,12 @@ export class Endpoint {
|
|
|
115
75
|
exact: filters?.exact ?? false,
|
|
116
76
|
}, options);
|
|
117
77
|
}
|
|
118
|
-
toMutation(
|
|
78
|
+
toMutation(
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
options) {
|
|
119
81
|
return new EndpointMutation(this, this.queryClient, options);
|
|
120
82
|
}
|
|
83
|
+
// @ts-expect-error
|
|
121
84
|
toQuery(options) {
|
|
122
85
|
return new EndpointQuery(this, this.queryClient, options);
|
|
123
86
|
}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { AllPropertiesOptional, AnyObject } from 'yummies/utils/types';
|
|
2
2
|
import type { Endpoint } from './endpoint.js';
|
|
3
|
+
import { FullRequestParams } from './http-client.js';
|
|
4
|
+
export interface EndpointConfiguration<TInput extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
5
|
+
operationId: string;
|
|
6
|
+
pathDeclaration: string;
|
|
7
|
+
meta?: TMetaData;
|
|
8
|
+
requiredParams: string[];
|
|
9
|
+
params: (...args: AllPropertiesOptional<TInput> extends true ? [input: Partial<TInput>] : [input: TInput]) => FullRequestParams;
|
|
10
|
+
tags: string[];
|
|
11
|
+
}
|
|
3
12
|
export type EndpointMutationInput<TBaseInput extends AnyObject, TMutationMeta extends AnyObject | void = void> = TBaseInput & (TMutationMeta extends void ? {} : AllPropertiesOptional<TMutationMeta> extends true ? {
|
|
4
13
|
meta?: TMutationMeta;
|
|
5
14
|
} : {
|
|
6
15
|
meta: TMutationMeta;
|
|
7
16
|
});
|
|
8
|
-
export type AnyEndpoint = Endpoint<any, any, any, any
|
|
9
|
-
export type InferEndpointData<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<infer T, any, any, any
|
|
17
|
+
export type AnyEndpoint = Endpoint<any, any, any, any>;
|
|
18
|
+
export type InferEndpointData<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<infer T, any, any, any> ? T : never;
|
|
10
19
|
export type InferEndpointResponse<TEndpoint extends AnyEndpoint> = ReturnType<TEndpoint['request']>;
|
|
11
|
-
export type InferEndpointError<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<any, infer T, any, any
|
|
12
|
-
export type InferEndpointInput<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<any, any, infer T, any
|
|
13
|
-
export type
|
|
14
|
-
export type InferEndpointMetaData<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<any, any, any, any, infer T> ? T : never;
|
|
20
|
+
export type InferEndpointError<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<any, infer T, any, any> ? T : never;
|
|
21
|
+
export type InferEndpointInput<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<any, any, infer T, any> ? T : never;
|
|
22
|
+
export type InferEndpointMetaData<TEndpoint extends AnyEndpoint> = TEndpoint extends Endpoint<any, any, any, infer T> ? T : never;
|
|
15
23
|
//# sourceMappingURL=endpoint.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.types.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"endpoint.types.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,qBAAqB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