mobx-tanstack-query-api 0.0.36 → 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/builtin/index.d.ts +2 -1
- package/builtin/index.d.ts.map +1 -1
- package/builtin/index.js +24 -2
- package/cli/define-config.d.ts.map +1 -1
- package/codegen/index.d.ts +10 -2
- package/codegen/index.d.ts.map +1 -1
- package/codegen/index.js +4 -2
- package/codegen/templates/data-contract.tmpl.d.ts.map +1 -1
- package/codegen/templates/data-contracts-file.tmpl.d.ts.map +1 -1
- package/codegen/templates/index-ts-for-request-per-file.tmpl.d.ts.map +1 -1
- package/codegen/templates/new-request-info.tmpl.d.ts.map +1 -1
- package/codegen/templates/new-request-info.tmpl.js +15 -69
- package/codegen/templates/request-info-jsdoc.tmpl.d.ts.map +1 -1
- package/codegen/templates/request-info-per-file.tmpl.d.ts.map +1 -1
- package/codegen/templates/request-info-per-file.tmpl.js +1 -1
- package/package.json +13 -6
- package/runtime/endpoint-mutation.d.ts +2 -2
- package/runtime/endpoint-mutation.d.ts.map +1 -1
- package/runtime/endpoint-mutation.js +3 -4
- package/runtime/endpoint-query-client.d.ts +8 -0
- package/runtime/endpoint-query-client.d.ts.map +1 -0
- package/runtime/endpoint-query-client.js +42 -0
- package/runtime/endpoint-query.d.ts +12 -11
- package/runtime/endpoint-query.d.ts.map +1 -1
- package/runtime/endpoint-query.js +34 -22
- package/runtime/endpoint.d.ts +21 -33
- package/runtime/endpoint.d.ts.map +1 -1
- package/runtime/endpoint.js +28 -81
- package/runtime/endpoint.types.d.ts +14 -6
- package/runtime/endpoint.types.d.ts.map +1 -1
- package/runtime/http-client.d.ts.map +1 -1
- package/runtime/index.d.ts +1 -0
- package/runtime/index.d.ts.map +1 -1
- package/runtime/index.js +1 -0
package/builtin/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { EndpointQueryClient } from '../runtime/endpoint-query-client.js';
|
|
1
2
|
import { HttpClient } from '../runtime/http-client.js';
|
|
2
|
-
export
|
|
3
|
+
export declare const queryClient: EndpointQueryClient;
|
|
3
4
|
export declare const http: HttpClient<unknown>;
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/builtin/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builtin/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builtin/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAqB,MAAM,2BAA2B,CAAC;AAI1E,eAAO,MAAM,WAAW,qBAmBtB,CAAC;AAEH,eAAO,MAAM,IAAI,qBAAqB,CAAC"}
|
package/builtin/index.js
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { hashKey } from '@tanstack/query-core';
|
|
2
|
+
import { EndpointQueryClient } from '../runtime/endpoint-query-client.js';
|
|
3
|
+
import { HttpClient, isHttpBadResponse } from '../runtime/http-client.js';
|
|
4
|
+
const MAX_FAILURE_COUNT = 3;
|
|
5
|
+
export const queryClient = new EndpointQueryClient({
|
|
6
|
+
defaultOptions: {
|
|
7
|
+
queries: {
|
|
8
|
+
throwOnError: true,
|
|
9
|
+
queryKeyHashFn: hashKey,
|
|
10
|
+
refetchOnWindowFocus: true,
|
|
11
|
+
refetchOnReconnect: true,
|
|
12
|
+
staleTime: 5 * 60 * 1000,
|
|
13
|
+
retry: (failureCount, error) => {
|
|
14
|
+
if (isHttpBadResponse(error) && error.status >= 500) {
|
|
15
|
+
return MAX_FAILURE_COUNT - failureCount > 0;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
mutations: {
|
|
21
|
+
throwOnError: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
3
25
|
export const http = new HttpClient({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../src/cli/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../src/cli/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,eAAO,MAAM,YAAY,GACvB,GAAG,SAAS,KAAK,CAAC,sBAAsB,GAAG,sBAAsB,EAAE,CAAC,EAAE,KACrE,sBAAsB,EAIxB,CAAC"}
|
package/codegen/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { LoDashStatic } from 'lodash';
|
|
1
2
|
import { AnyObject, KeyOfByValue } from 'yummies/utils/types';
|
|
2
|
-
export type CodegenDataUtils =
|
|
3
|
+
export type CodegenDataUtils = {
|
|
4
|
+
_: LoDashStatic;
|
|
5
|
+
getInlineParseContent: (requestParams: AnyObject) => string;
|
|
6
|
+
formatModelName: (modelName: string) => string;
|
|
7
|
+
};
|
|
3
8
|
export type CodegenProcess = AnyObject;
|
|
4
9
|
export interface ImportFileParams {
|
|
5
10
|
path: string;
|
|
@@ -11,7 +16,7 @@ export interface GenerateQueryApiParams {
|
|
|
11
16
|
requestPathPrefix?: string;
|
|
12
17
|
requestPathSuffix?: string;
|
|
13
18
|
requestInfoPrefix?: string;
|
|
14
|
-
formatExportGroupName?: (groupName: string, utils:
|
|
19
|
+
formatExportGroupName?: (groupName: string, utils: CodegenDataUtils) => string;
|
|
15
20
|
/**
|
|
16
21
|
* Group endpoints and collect it into object
|
|
17
22
|
*/
|
|
@@ -56,6 +61,9 @@ export interface GenerateQueryApiParams {
|
|
|
56
61
|
};
|
|
57
62
|
requestOptions?: AnyObject;
|
|
58
63
|
otherCodegenParams?: AnyObject;
|
|
64
|
+
libImports?: {
|
|
65
|
+
'mobx-tanstack-query-api'?: string;
|
|
66
|
+
};
|
|
59
67
|
}
|
|
60
68
|
export type AllImportFileParams = Record<KeyOfByValue<Required<GenerateQueryApiParams>, 'builtin' | ImportFileParams>, ImportFileParams>;
|
|
61
69
|
export declare const generateApi: (params: GenerateQueryApiParams | GenerateQueryApiParams[]) => Promise<void>;
|
package/codegen/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAc9D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,EAAE,YAAY,CAAC;IAChB,qBAAqB,EAAE,CAAC,aAAa,EAAE,SAAS,KAAK,MAAM,CAAC;IAC5D,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC;AAEvC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B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AAC;AAEF,eAAO,MAAM,WAAW,GACtB,QAAQ,sBAAsB,GAAG,sBAAsB,EAAE,KACxD,OAAO,CAAC,IAAI,CAkXd,CAAC"}
|
package/codegen/index.js
CHANGED
|
@@ -99,14 +99,16 @@ export const generateApi = async (params) => {
|
|
|
99
99
|
? params.addPathSegmentToRouteName
|
|
100
100
|
: 0;
|
|
101
101
|
const pathSegments = routeInfo.route.split('/').filter(Boolean);
|
|
102
|
-
const { _ } = codegenProcess.getRenderTemplateData()
|
|
102
|
+
const { _ } = codegenProcess.getRenderTemplateData()
|
|
103
|
+
.utils;
|
|
103
104
|
formattedRouteName = _.camelCase(`${pathSegments[pathSegmentForSuffix] || ''}_${formattedRouteName}`);
|
|
104
105
|
}
|
|
105
106
|
return (codegenParams?.hooks?.onFormatRouteName?.(routeInfo, formattedRouteName) ?? formattedRouteName);
|
|
106
107
|
},
|
|
107
108
|
},
|
|
108
109
|
});
|
|
109
|
-
const utils = codegenProcess.getRenderTemplateData()
|
|
110
|
+
const utils = codegenProcess.getRenderTemplateData()
|
|
111
|
+
.utils;
|
|
110
112
|
const { _ } = utils;
|
|
111
113
|
const codegenFs = codegenProcess.fileSystem;
|
|
112
114
|
codegenFs.cleanDir(params.output);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-contract.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/data-contract.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,SAAS,CAAC;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAuBD,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"data-contract.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/data-contract.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,SAAS,CAAC;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAuBD,eAAO,MAAM,gBAAgB,GAAU,gDAIpC,sBAAsB,oBAmCxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-contracts-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/data-contracts-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAK1E,MAAM,WAAW,uBAAwB,SAAQ,SAAS;IACxD,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;CACtC;AAED,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"data-contracts-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/data-contracts-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAK1E,MAAM,WAAW,uBAAwB,SAAQ,SAAS;IACxD,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;CACtC;AAED,eAAO,MAAM,qBAAqB,GAAU,gEAIzC,uBAAuB,iBA6BzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-ts-for-request-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/index-ts-for-request-per-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAIrE,MAAM,WAAW,kCAAmC,SAAQ,SAAS;IACnE,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,yBAAyB,EAAE,MAAM,EAAE,CAAC;CACrC;AAED,eAAO,MAAM,4BAA4B,
|
|
1
|
+
{"version":3,"file":"index-ts-for-request-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/index-ts-for-request-per-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAIrE,MAAM,WAAW,kCAAmC,SAAQ,SAAS;IACnE,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,yBAAyB,EAAE,MAAM,EAAE,CAAC;CACrC;AAED,eAAO,MAAM,4BAA4B,GAAU,gCAEhD,kCAAkC,oBAIpC,CAAC"}
|
|
@@ -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,
|
|
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},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-info-jsdoc.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/request-info-jsdoc.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"request-info-jsdoc.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/request-info-jsdoc.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,oBAAoB,GAAI,mCAIlC,0BAA0B,WAkH5B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-info-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/request-info-per-file.tmpl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,4BAA6B,SAAQ,SAAS;IAC7D,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"request-info-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/request-info-per-file.tmpl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,4BAA6B,SAAQ,SAAS;IAC7D,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,sBAAsB,GAAU,2GAQ1C,4BAA4B;;;EA6E9B,CAAC"}
|
|
@@ -21,7 +21,7 @@ export const requestInfoPerFileTmpl = async ({ route, configuration, apiParams,
|
|
|
21
21
|
return {
|
|
22
22
|
reservedDataContractNames: dataContractNamesInThisFile,
|
|
23
23
|
content: await formatTSContent(`${LINTERS_IGNORE}
|
|
24
|
-
import { RequestParams } from "mobx-tanstack-query-api";
|
|
24
|
+
import { RequestParams } from "${apiParams.libImports?.['mobx-tanstack-query-api'] ?? 'mobx-tanstack-query-api'}";
|
|
25
25
|
import { ${importFileParams.endpoint.exportName} } from "${importFileParams.endpoint.path}";
|
|
26
26
|
import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
|
|
27
27
|
import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
|
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",
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
"url": "git://github.com/js2me/mobx-tanstack-query-api"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"
|
|
20
|
-
"mobx": "^6.13.6",
|
|
21
|
-
"mobx-tanstack-query": "^4.2.5"
|
|
19
|
+
"mobx": "^6.13.6"
|
|
22
20
|
},
|
|
23
21
|
"dependencies": {
|
|
22
|
+
"@tanstack/query-core": "^5.75.0",
|
|
23
|
+
"@types/lodash": "^4.17.16",
|
|
24
|
+
"@types/lodash-es": "^4.17.12",
|
|
25
|
+
"mobx-tanstack-query": "^4.4.4",
|
|
24
26
|
"swagger-typescript-api": "13.1.3",
|
|
25
27
|
"yummies": "^3.0.37"
|
|
26
28
|
},
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
"jsdom": "^26.0.0",
|
|
33
35
|
"nodemon": "^3.1.9",
|
|
34
36
|
"rimraf": "^6.0.1",
|
|
35
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.8.3",
|
|
36
38
|
"unplugin-swc": "^1.5.1",
|
|
37
39
|
"vitest": "^3.0.5"
|
|
38
40
|
},
|
|
@@ -107,6 +109,11 @@
|
|
|
107
109
|
"default": "./runtime/endpoint-mutation.js",
|
|
108
110
|
"types": "./runtime/endpoint-mutation.d.ts"
|
|
109
111
|
},
|
|
112
|
+
"./runtime/endpoint-query-client": {
|
|
113
|
+
"import": "./runtime/endpoint-query-client.js",
|
|
114
|
+
"default": "./runtime/endpoint-query-client.js",
|
|
115
|
+
"types": "./runtime/endpoint-query-client.d.ts"
|
|
116
|
+
},
|
|
110
117
|
"./runtime/endpoint-query": {
|
|
111
118
|
"import": "./runtime/endpoint-query.js",
|
|
112
119
|
"default": "./runtime/endpoint-query.js",
|
|
@@ -149,7 +156,7 @@
|
|
|
149
156
|
"test": "vitest run",
|
|
150
157
|
"test:watch": "vitest watch",
|
|
151
158
|
"test:coverage": "vitest run --coverage",
|
|
152
|
-
"dev": "pnpm
|
|
159
|
+
"dev": "pnpm build && nodemon --delay 0.5 --watch src --ext ts,tsx --exec \"pnpm build && pnpm playground\"",
|
|
153
160
|
"playground": "node ./playground/index.mjs"
|
|
154
161
|
}
|
|
155
162
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { QueryClient } from '@tanstack/query-core';
|
|
2
1
|
import { MobxMutation, MobxMutationConfig } from 'mobx-tanstack-query';
|
|
3
2
|
import { AllPropertiesOptional, AnyObject, Unpromise } from 'yummies/utils/types';
|
|
3
|
+
import { EndpointQueryClient } from './endpoint-query-client.js';
|
|
4
4
|
import { AnyEndpoint, InferEndpointError, InferEndpointInput, InferEndpointResponse } from './endpoint.types.js';
|
|
5
5
|
export type EndpointMutationInput<TBaseInput extends AnyObject, TMutationMeta extends AnyObject | void = void> = TBaseInput & (TMutationMeta extends void ? {} : AllPropertiesOptional<TMutationMeta> extends true ? {
|
|
6
6
|
meta?: TMutationMeta;
|
|
@@ -11,6 +11,6 @@ export interface EndpointMutationOptions<TEndpoint extends AnyEndpoint, TMutatio
|
|
|
11
11
|
}
|
|
12
12
|
export declare class EndpointMutation<TEndpoint extends AnyEndpoint, TMutationMeta extends AnyObject | void = void> extends MobxMutation<Unpromise<InferEndpointResponse<TEndpoint>>, EndpointMutationInput<InferEndpointInput<TEndpoint>, TMutationMeta>> {
|
|
13
13
|
private endpoint;
|
|
14
|
-
constructor(endpoint: TEndpoint, queryClient:
|
|
14
|
+
constructor(endpoint: TEndpoint, queryClient: EndpointQueryClient, options: EndpointMutationOptions<TEndpoint, TMutationMeta>);
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=endpoint-mutation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-mutation.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-mutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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,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"}
|
|
@@ -2,14 +2,13 @@ import { MobxMutation } from 'mobx-tanstack-query';
|
|
|
2
2
|
export class EndpointMutation extends MobxMutation {
|
|
3
3
|
endpoint;
|
|
4
4
|
constructor(endpoint, queryClient, options) {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
// @ts-expect-error
|
|
5
7
|
super({
|
|
6
8
|
...options,
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
-
// @ts-expect-error
|
|
9
9
|
queryClient,
|
|
10
10
|
mutationFn: async (input) => {
|
|
11
|
-
|
|
12
|
-
const response = await endpoint.request(...endpoint.getParamsFromInput(input));
|
|
11
|
+
const response = await endpoint.request(input);
|
|
13
12
|
return response;
|
|
14
13
|
},
|
|
15
14
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InvalidateOptions, InvalidateQueryFilters } from '@tanstack/query-core';
|
|
2
|
+
import { MobxQueryClient } from 'mobx-tanstack-query';
|
|
3
|
+
export declare class EndpointQueryClient extends MobxQueryClient {
|
|
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>;
|
|
6
|
+
invalidateByTags(tags: any[], filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=endpoint-query-client.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MobxQueryClient } from 'mobx-tanstack-query';
|
|
2
|
+
export class EndpointQueryClient extends MobxQueryClient {
|
|
3
|
+
invalidateByOperationId(operationId, filters, options) {
|
|
4
|
+
return this.invalidateQueries({
|
|
5
|
+
...filters,
|
|
6
|
+
predicate: (query) => {
|
|
7
|
+
if (query.meta?.operationId) {
|
|
8
|
+
if (typeof operationId === 'string') {
|
|
9
|
+
return query.meta?.operationId === operationId;
|
|
10
|
+
}
|
|
11
|
+
return operationId.test(String(query.meta.operationId));
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
},
|
|
15
|
+
}, options);
|
|
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
|
+
}
|
|
31
|
+
invalidateByTags(tags, filters, options) {
|
|
32
|
+
return this.invalidateQueries({
|
|
33
|
+
...filters,
|
|
34
|
+
predicate: (query) => {
|
|
35
|
+
if (Array.isArray(query.meta?.tags)) {
|
|
36
|
+
return query.meta.tags.some((tag) => tags.includes(tag));
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
40
|
+
}, options);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MobxQuery, MobxQueryConfig
|
|
1
|
+
import { QueryFunctionContext } from '@tanstack/query-core';
|
|
2
|
+
import { MobxQuery, MobxQueryConfig } from 'mobx-tanstack-query';
|
|
3
3
|
import { MaybeFalsy, Unpromise } from 'yummies/utils/types';
|
|
4
|
+
import { EndpointQueryClient } from './endpoint-query-client.js';
|
|
4
5
|
import { AnyEndpoint, InferEndpointError, InferEndpointInput, InferEndpointResponse } from './endpoint.types.js';
|
|
5
|
-
export
|
|
6
|
-
input
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export type EndpointQueryOptions<TOutput, TEndpoint extends AnyEndpoint> = {
|
|
7
|
+
input?: () => MaybeFalsy<InferEndpointInput<TEndpoint>>;
|
|
8
|
+
transform?: (response: Unpromise<InferEndpointResponse<TEndpoint>>) => TOutput;
|
|
9
|
+
} & Omit<MobxQueryConfig<TOutput, InferEndpointError<TEndpoint>>, 'options' | 'queryFn' | 'queryClient'>;
|
|
10
|
+
export declare class EndpointQuery<TOutput, TEndpoint extends AnyEndpoint> extends MobxQuery<TOutput, InferEndpointError<TEndpoint>> {
|
|
9
11
|
private endpoint;
|
|
10
12
|
response: Unpromise<InferEndpointResponse<TEndpoint>> | null;
|
|
11
|
-
constructor(endpoint: TEndpoint, queryClient:
|
|
13
|
+
constructor(endpoint: TEndpoint, queryClient: EndpointQueryClient, { input: getInput, ...queryOptions }: EndpointQueryOptions<TOutput, TEndpoint>);
|
|
12
14
|
setInput(input: MaybeFalsy<InferEndpointInput<TEndpoint>>): Promise<Unpromise<InferEndpointResponse<TEndpoint>>>;
|
|
13
|
-
|
|
15
|
+
buildOptionsFromInput(input: MaybeFalsy<Partial<InferEndpointInput<TEndpoint>>>): {
|
|
14
16
|
enabled: boolean;
|
|
15
|
-
queryKey: any;
|
|
17
|
+
queryKey: any[];
|
|
16
18
|
};
|
|
17
|
-
protected
|
|
18
|
-
protected buildParamsFromContext(ctx: QueryFunctionContext<any, any>): any;
|
|
19
|
+
protected getInputFromContext(ctx: QueryFunctionContext<any, any>): InferEndpointInput<TEndpoint>;
|
|
19
20
|
}
|
|
20
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,
|
|
1
|
+
{"version":3,"file":"endpoint-query.d.ts","sourceRoot":"","sources":["../../src/runtime/endpoint-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAS,UA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B,CAAC,GAAG,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAG,CAAC,GAC7B,kBAAkB,CAAC,SAAS,CAAC;CAElE"}
|
|
@@ -1,13 +1,11 @@
|
|
|
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;
|
|
6
6
|
constructor(endpoint, queryClient, { input: getInput, ...queryOptions }) {
|
|
7
7
|
super({
|
|
8
8
|
...queryOptions,
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
-
// @ts-expect-error
|
|
11
9
|
queryClient,
|
|
12
10
|
meta: {
|
|
13
11
|
tags: endpoint.tags,
|
|
@@ -16,25 +14,33 @@ export class EndpointQuery extends MobxQuery {
|
|
|
16
14
|
},
|
|
17
15
|
options: ({ options }) => {
|
|
18
16
|
const willEnableManually = options?.enabled === false;
|
|
19
|
-
const input = getInput();
|
|
20
|
-
|
|
17
|
+
const input = (getInput?.() || {});
|
|
18
|
+
const builtOptions = this.buildOptionsFromInput(input);
|
|
19
|
+
return {
|
|
20
|
+
...options,
|
|
21
|
+
...builtOptions,
|
|
22
|
+
enabled: willEnableManually ? false : builtOptions.enabled,
|
|
23
|
+
};
|
|
21
24
|
},
|
|
22
25
|
queryFn: async (ctx) => {
|
|
23
26
|
runInAction(() => {
|
|
24
27
|
this.response = null;
|
|
25
28
|
});
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
if (!
|
|
30
|
-
|
|
29
|
+
const input = this.getInputFromContext(ctx);
|
|
30
|
+
let requestParams = input.request;
|
|
31
|
+
if (requestParams) {
|
|
32
|
+
if (!requestParams.signal) {
|
|
33
|
+
requestParams.signal = ctx.signal;
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
else {
|
|
34
|
-
|
|
37
|
+
requestParams = { signal: ctx.signal };
|
|
35
38
|
}
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
const fixedInput = {
|
|
40
|
+
...input,
|
|
41
|
+
request: requestParams,
|
|
42
|
+
};
|
|
43
|
+
const response = await endpoint.request(fixedInput);
|
|
38
44
|
runInAction(() => {
|
|
39
45
|
this.response = response;
|
|
40
46
|
});
|
|
@@ -48,19 +54,25 @@ export class EndpointQuery extends MobxQuery {
|
|
|
48
54
|
async setInput(input) {
|
|
49
55
|
this.update(this.buildOptionsFromInput(input));
|
|
50
56
|
await when(() => !this.result.isFetching);
|
|
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,45 +1,33 @@
|
|
|
1
|
-
import { InvalidateOptions, InvalidateQueryFilters
|
|
2
|
-
import { AnyObject } from 'yummies/utils/types';
|
|
1
|
+
import { InvalidateOptions, InvalidateQueryFilters } from '@tanstack/query-core';
|
|
2
|
+
import { AllPropertiesOptional, AnyObject } from 'yummies/utils/types';
|
|
3
3
|
import { EndpointMutation, EndpointMutationOptions } from './endpoint-mutation.js';
|
|
4
|
+
import { EndpointQueryClient } from './endpoint-query-client.js';
|
|
4
5
|
import { EndpointQuery, EndpointQueryOptions } from './endpoint-query.js';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
params: (...params: TParams) => FullRequestParams;
|
|
10
|
-
keys: (string | {
|
|
11
|
-
name: string;
|
|
12
|
-
param: number;
|
|
13
|
-
} | {
|
|
14
|
-
name: string;
|
|
15
|
-
rest: true;
|
|
16
|
-
})[];
|
|
17
|
-
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']>;
|
|
18
10
|
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export declare class Endpoint<TData, TError, TInput extends AnyObject, TParams extends any[] = any[], TMetaData extends AnyObject = AnyObject> {
|
|
23
|
-
configuration: EndpointConfiguration<TParams, TMetaData>;
|
|
24
|
-
protected queryClient: QueryClient;
|
|
11
|
+
export declare class Endpoint<TData, TError, TInput extends AnyObject, TMetaData extends AnyObject = AnyObject> {
|
|
12
|
+
configuration: EndpointConfiguration<NoInfer<TInput>, TMetaData>;
|
|
13
|
+
protected queryClient: EndpointQueryClient;
|
|
25
14
|
protected http: HttpClient;
|
|
26
15
|
meta: TMetaData;
|
|
27
|
-
constructor(configuration: EndpointConfiguration<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
getParamsFromInput(input: TInput): TParams;
|
|
31
|
-
getFullUrl(input: TInput): string;
|
|
32
|
-
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;
|
|
33
19
|
get tags(): string[];
|
|
20
|
+
get pathDeclaration(): string;
|
|
34
21
|
get operationId(): string;
|
|
35
|
-
request(...
|
|
36
|
-
getQueryKey(input: TInput): any[];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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>;
|
|
25
|
+
invalidateByOperationId(filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
26
|
+
invalidateByTags(filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'>, options?: InvalidateOptions): Promise<void>;
|
|
27
|
+
invalidate(input: TInput, filters?: Omit<InvalidateQueryFilters<any[]>, 'queryKey' | 'predicate'> & {
|
|
40
28
|
queryKeyIndex?: number;
|
|
41
29
|
}, options?: InvalidateOptions): Promise<void>;
|
|
42
30
|
toMutation<TMutationMeta extends AnyObject | void = void>(options: EndpointMutationOptions<typeof this, TMutationMeta>): EndpointMutation<this, TMutationMeta>;
|
|
43
|
-
toQuery(options: EndpointQueryOptions<typeof this>): EndpointQuery<this>;
|
|
31
|
+
toQuery<TOutput>(options: EndpointQueryOptions<TOutput, typeof this>): EndpointQuery<TOutput, this>;
|
|
44
32
|
}
|
|
45
33
|
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -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,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,QAAQ,CACvB,KAAK,EACL,MAAM,EACN,MAAM,SAAS,SAAS,EACxB,SAAS,SAAS,SAAS,GAAG,SAAS;IAEvC,CACE,GAAG,IAAI,EAAE,qBAAqB,CAAC,MAAM,CAAC,SAAS,IAAI,GAC/C,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAChB,CAAC,KAAK,EAAE,MAAM,CAAC,GAClB,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;CACtE;AAED,qBAAa,QAAQ,CACnB,KAAK,EACL,MAAM,EACN,MAAM,SAAS,SAAS,EACxB,SAAS,SAAS,SAAS,GAAG,SAAS;IAK9B,aAAa,EAAE,qBAAqB,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AAC,EAAE,UAAU,GAAG,WAAW,CAAC,EACvE,OAAO,CAAC,EAAE,iBAAiB;IAS7B,gBAAgB,CACd,OAAO,CAAC,EAAE,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC,EACvE,OAAO,CAAC,EAAE,iBAAiB;IAK7B,UAAU,CACR,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC,GAAG;QACxE,aAAa,CAAC,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,98 +31,42 @@ 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
|
-
return this.queryClient.
|
|
107
|
-
...filters,
|
|
108
|
-
predicate: (query) => {
|
|
109
|
-
if (query.meta?.operationId) {
|
|
110
|
-
return query.meta?.operationId === this.configuration.operationId;
|
|
111
|
-
}
|
|
112
|
-
return false;
|
|
113
|
-
},
|
|
114
|
-
}, options);
|
|
66
|
+
return this.queryClient.invalidateByOperationId(this.operationId, filters, options);
|
|
115
67
|
}
|
|
116
68
|
invalidateByTags(filters, options) {
|
|
117
|
-
return this.queryClient.
|
|
118
|
-
...filters,
|
|
119
|
-
predicate: (query) => {
|
|
120
|
-
if (Array.isArray(query.meta?.tags)) {
|
|
121
|
-
return query.meta.tags.some((tag) => this.tags.includes(tag));
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
},
|
|
125
|
-
}, options);
|
|
69
|
+
return this.queryClient.invalidateByTags(this.tags, filters, options);
|
|
126
70
|
}
|
|
127
71
|
invalidate(input, filters, options) {
|
|
128
72
|
return this.queryClient.invalidateQueries({
|
|
@@ -131,9 +75,12 @@ export class Endpoint {
|
|
|
131
75
|
exact: filters?.exact ?? false,
|
|
132
76
|
}, options);
|
|
133
77
|
}
|
|
134
|
-
toMutation(
|
|
78
|
+
toMutation(
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
options) {
|
|
135
81
|
return new EndpointMutation(this, this.queryClient, options);
|
|
136
82
|
}
|
|
83
|
+
// @ts-expect-error
|
|
137
84
|
toQuery(options) {
|
|
138
85
|
return new EndpointQuery(this, this.queryClient, options);
|
|
139
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,CAAC;AAEvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,WAAW,qBAAqB,CACpC,MAAM,SAAS,SAAS,EACxB,SAAS,SAAS,SAAS,GAAG,SAAS;IAEvC,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,SAAS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AAC,aAAa,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,MAAM;IAkB3D,OAAO,CAAC,iBAAiB,CA0BvB;IAEF,SAAS,CAAC,kBAAkB,CAC1B,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,aAAa,GACtB,aAAa;YAaF,cAAc;IAiCrB,QAAQ,GAAI,QAAQ,iBAAiB,YAgB1C;IAEK,OAAO,GAAU,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EACtC,YAAY,iBAAiB,KAC5B,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CA6C5B;CACH"}
|
package/runtime/index.d.ts
CHANGED
package/runtime/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC"}
|
package/runtime/index.js
CHANGED