@openapi-qraft/tanstack-query-react-plugin 1.8.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/CHANGELOG.md +12 -0
- package/README.md +1 -0
- package/dist/__snapshots__/create-api-client.ts.snapshot.d.ts +1 -0
- package/dist/__snapshots__/create-api-client.ts.snapshot.js +88 -0
- package/dist/__snapshots__/create-api-client.ts.snapshot.js.map +1 -0
- package/dist/__snapshots__/index.ts.snapshot.d.ts +1 -0
- package/dist/__snapshots__/index.ts.snapshot.js +13 -0
- package/dist/__snapshots__/index.ts.snapshot.js.map +1 -0
- package/dist/__snapshots__/services/ApprovalPoliciesService.ts.snapshot.d.ts +1 -0
- package/dist/__snapshots__/services/ApprovalPoliciesService.ts.snapshot.js +62 -0
- package/dist/__snapshots__/services/ApprovalPoliciesService.ts.snapshot.js.map +1 -0
- package/dist/__snapshots__/services/FilesService.ts.snapshot.d.ts +1 -0
- package/dist/__snapshots__/services/FilesService.ts.snapshot.js +57 -0
- package/dist/__snapshots__/services/FilesService.ts.snapshot.js.map +1 -0
- package/dist/__snapshots__/services/index.ts.snapshot.d.ts +1 -0
- package/dist/__snapshots__/services/index.ts.snapshot.js +24 -0
- package/dist/__snapshots__/services/index.ts.snapshot.js.map +1 -0
- package/dist/generateCode.d.ts +18 -0
- package/dist/generateCode.js +116 -0
- package/dist/generateCode.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +30 -0
- package/dist/plugin.js.map +1 -0
- package/dist/ts-factory/astToString.d.ts +8 -0
- package/dist/ts-factory/astToString.js +14 -0
- package/dist/ts-factory/astToString.js.map +1 -0
- package/dist/ts-factory/getClientFactory.d.ts +7 -0
- package/dist/ts-factory/getClientFactory.js +84 -0
- package/dist/ts-factory/getClientFactory.js.map +1 -0
- package/dist/ts-factory/getIndexFactory.d.ts +5 -0
- package/dist/ts-factory/getIndexFactory.js +17 -0
- package/dist/ts-factory/getIndexFactory.js.map +1 -0
- package/dist/ts-factory/getServiceFactory.d.ts +10 -0
- package/dist/ts-factory/getServiceFactory.js +120 -0
- package/dist/ts-factory/getServiceFactory.js.map +1 -0
- package/dist/ts-factory/getServiceIndexFactory.d.ts +7 -0
- package/dist/ts-factory/getServiceIndexFactory.js +26 -0
- package/dist/ts-factory/getServiceIndexFactory.js.map +1 -0
- package/package.json +48 -0
- package/src/__snapshots__/create-api-client.ts.snapshot.ts +88 -0
- package/src/__snapshots__/index.ts.snapshot.ts +13 -0
- package/src/__snapshots__/services/ApprovalPoliciesService.ts.snapshot.ts +64 -0
- package/src/__snapshots__/services/FilesService.ts.snapshot.ts +57 -0
- package/src/__snapshots__/services/index.ts.snapshot.ts +24 -0
- package/src/generateCode.ts +201 -0
- package/src/index.ts +3 -0
- package/src/plugin.ts +45 -0
- package/src/ts-factory/astToString.ts +34 -0
- package/src/ts-factory/getClientFactory.ts +207 -0
- package/src/ts-factory/getIndexFactory.ts +58 -0
- package/src/ts-factory/getServiceFactory.ts +410 -0
- package/src/ts-factory/getServiceIndexFactory.ts +104 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @openapi-qraft/tanstack-query-react-plugin
|
|
2
|
+
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 27d501a: Removed `ServicesCallbacksFilter` types from react-client to resolve conflict with the Operation Invoke method.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [788fa00]
|
|
12
|
+
- @openapi-qraft/plugin@1.8.0
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# tanstack-react-plugin
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): void;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { expect } from 'vitest';
|
|
3
|
+
export default function () {
|
|
4
|
+
expect(fs.readFileSync('/mock-fs/create-api-client.ts', 'utf-8'))
|
|
5
|
+
.toMatchInlineSnapshot(`
|
|
6
|
+
"/* generated using @openapi-qraft/cli -- do no edit */
|
|
7
|
+
/* istanbul ignore file */
|
|
8
|
+
import { qraftAPIClient, QraftClientOptions } from "@openapi-qraft/react";
|
|
9
|
+
import { getInfiniteQueryData } from "@openapi-qraft/react/callbacks/getInfiniteQueryData";
|
|
10
|
+
import { getInfiniteQueryKey } from "@openapi-qraft/react/callbacks/getInfiniteQueryKey";
|
|
11
|
+
import { getMutationKey } from "@openapi-qraft/react/callbacks/getMutationKey";
|
|
12
|
+
import { getQueryData } from "@openapi-qraft/react/callbacks/getQueryData";
|
|
13
|
+
import { getQueriesData } from "@openapi-qraft/react/callbacks/getQueriesData";
|
|
14
|
+
import { getQueryKey } from "@openapi-qraft/react/callbacks/getQueryKey";
|
|
15
|
+
import { mutationFn } from "@openapi-qraft/react/callbacks/mutationFn";
|
|
16
|
+
import { queryFn } from "@openapi-qraft/react/callbacks/queryFn";
|
|
17
|
+
import { setInfiniteQueryData } from "@openapi-qraft/react/callbacks/setInfiniteQueryData";
|
|
18
|
+
import { setQueryData } from "@openapi-qraft/react/callbacks/setQueryData";
|
|
19
|
+
import { setQueriesData } from "@openapi-qraft/react/callbacks/setQueriesData";
|
|
20
|
+
import { useInfiniteQuery } from "@openapi-qraft/react/callbacks/useInfiniteQuery";
|
|
21
|
+
import { useMutation } from "@openapi-qraft/react/callbacks/useMutation";
|
|
22
|
+
import { useQuery } from "@openapi-qraft/react/callbacks/useQuery";
|
|
23
|
+
import { useSuspenseQuery } from "@openapi-qraft/react/callbacks/useSuspenseQuery";
|
|
24
|
+
import { useSuspenseInfiniteQuery } from "@openapi-qraft/react/callbacks/useSuspenseInfiniteQuery";
|
|
25
|
+
import { useMutationState } from "@openapi-qraft/react/callbacks/useMutationState";
|
|
26
|
+
import { useIsMutating } from "@openapi-qraft/react/callbacks/useIsMutating";
|
|
27
|
+
import { useQueries } from "@openapi-qraft/react/callbacks/useQueries";
|
|
28
|
+
import { useSuspenseQueries } from "@openapi-qraft/react/callbacks/useSuspenseQueries";
|
|
29
|
+
import { invalidateQueries } from "@openapi-qraft/react/callbacks/invalidateQueries";
|
|
30
|
+
import { cancelQueries } from "@openapi-qraft/react/callbacks/cancelQueries";
|
|
31
|
+
import { resetQueries } from "@openapi-qraft/react/callbacks/resetQueries";
|
|
32
|
+
import { removeQueries } from "@openapi-qraft/react/callbacks/removeQueries";
|
|
33
|
+
import { refetchQueries } from "@openapi-qraft/react/callbacks/refetchQueries";
|
|
34
|
+
import { isFetching } from "@openapi-qraft/react/callbacks/isFetching";
|
|
35
|
+
import { isMutating } from "@openapi-qraft/react/callbacks/isMutating";
|
|
36
|
+
import { useIsFetching } from "@openapi-qraft/react/callbacks/useIsFetching";
|
|
37
|
+
import { fetchQuery } from "@openapi-qraft/react/callbacks/fetchQuery";
|
|
38
|
+
import { prefetchQuery } from "@openapi-qraft/react/callbacks/prefetchQuery";
|
|
39
|
+
import { fetchInfiniteQuery } from "@openapi-qraft/react/callbacks/fetchInfiniteQuery";
|
|
40
|
+
import { prefetchInfiniteQuery } from "@openapi-qraft/react/callbacks/prefetchInfiniteQuery";
|
|
41
|
+
import { getQueryState } from "@openapi-qraft/react/callbacks/getQueryState";
|
|
42
|
+
import { getInfiniteQueryState } from "@openapi-qraft/react/callbacks/getInfiniteQueryState";
|
|
43
|
+
import { operationInvokeFn } from "@openapi-qraft/react/callbacks/operationInvokeFn";
|
|
44
|
+
import { services, Services } from "./services/index.js";
|
|
45
|
+
const callbacks = {
|
|
46
|
+
getInfiniteQueryData,
|
|
47
|
+
getInfiniteQueryKey,
|
|
48
|
+
getMutationKey,
|
|
49
|
+
getQueryData,
|
|
50
|
+
getQueriesData,
|
|
51
|
+
getQueryKey,
|
|
52
|
+
mutationFn,
|
|
53
|
+
queryFn,
|
|
54
|
+
setInfiniteQueryData,
|
|
55
|
+
setQueryData,
|
|
56
|
+
setQueriesData,
|
|
57
|
+
useInfiniteQuery,
|
|
58
|
+
useMutation,
|
|
59
|
+
useQuery,
|
|
60
|
+
useSuspenseQuery,
|
|
61
|
+
useSuspenseInfiniteQuery,
|
|
62
|
+
useMutationState,
|
|
63
|
+
useIsMutating,
|
|
64
|
+
useQueries,
|
|
65
|
+
useSuspenseQueries,
|
|
66
|
+
invalidateQueries,
|
|
67
|
+
cancelQueries,
|
|
68
|
+
resetQueries,
|
|
69
|
+
removeQueries,
|
|
70
|
+
refetchQueries,
|
|
71
|
+
isFetching,
|
|
72
|
+
isMutating,
|
|
73
|
+
useIsFetching,
|
|
74
|
+
fetchQuery,
|
|
75
|
+
prefetchQuery,
|
|
76
|
+
fetchInfiniteQuery,
|
|
77
|
+
prefetchInfiniteQuery,
|
|
78
|
+
getQueryState,
|
|
79
|
+
getInfiniteQueryState,
|
|
80
|
+
operationInvokeFn
|
|
81
|
+
};
|
|
82
|
+
export function createAPIClient(options?: QraftClientOptions): Services {
|
|
83
|
+
return qraftAPIClient<Services, typeof callbacks>(services, callbacks, options);
|
|
84
|
+
}
|
|
85
|
+
"
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=create-api-client.ts.snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-api-client.ts.snapshot.js","sourceRoot":"","sources":["../../src/__snapshots__/create-api-client.ts.snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO;IACZ,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,+BAA+B,EAAE,OAAO,CAAC,CAAC;SAC9D,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiFtB,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { expect } from 'vitest';
|
|
3
|
+
export default function () {
|
|
4
|
+
expect(fs.readFileSync('/mock-fs/index.ts', 'utf-8')).toMatchInlineSnapshot(`
|
|
5
|
+
"/* generated using @openapi-qraft/cli -- do no edit */
|
|
6
|
+
/* istanbul ignore file */
|
|
7
|
+
export { services } from "./services/index.js";
|
|
8
|
+
export type { Services } from "./services/index.js";
|
|
9
|
+
export { createAPIClient } from "./create-api-client.js";
|
|
10
|
+
"
|
|
11
|
+
`);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.ts.snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.ts.snapshot.js","sourceRoot":"","sources":["../../src/__snapshots__/index.ts.snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO;IACZ,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;GAO3E,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { expect } from 'vitest';
|
|
3
|
+
export default function () {
|
|
4
|
+
expect(fs.readFileSync('/mock-fs/services/ApprovalPoliciesService.ts', 'utf-8')).toMatchInlineSnapshot(`
|
|
5
|
+
"/* generated using @openapi-qraft/cli -- do no edit */
|
|
6
|
+
/* istanbul ignore file */
|
|
7
|
+
import type { paths } from "../../openapi.js";
|
|
8
|
+
import type { ServiceOperationQuery, ServiceOperationMutation } from "@openapi-qraft/react";
|
|
9
|
+
export interface ApprovalPoliciesService {
|
|
10
|
+
/**
|
|
11
|
+
* @summary Get an approval policy by ID
|
|
12
|
+
* @description Retrieve a specific approval policy.
|
|
13
|
+
*/
|
|
14
|
+
getApprovalPoliciesId: ServiceOperationQuery<{
|
|
15
|
+
method: "get";
|
|
16
|
+
url: "/approval_policies/{approval_policy_id}";
|
|
17
|
+
}, paths["/approval_policies/{approval_policy_id}"]["get"]["responses"]["200"]["content"]["application/json"], paths["/approval_policies/{approval_policy_id}"]["get"]["parameters"], paths["/approval_policies/{approval_policy_id}"]["get"]["responses"]["401"]["content"]["application/json"] | paths["/approval_policies/{approval_policy_id}"]["get"]["responses"]["422"]["content"]["application/json"] | paths["/approval_policies/{approval_policy_id}"]["get"]["responses"]["default"]["content"]["application/json"]>;
|
|
18
|
+
/**
|
|
19
|
+
* @summary Delete an approval policy
|
|
20
|
+
* @description Delete an existing approval policy.
|
|
21
|
+
*/
|
|
22
|
+
deleteApprovalPoliciesId: ServiceOperationMutation<{
|
|
23
|
+
method: "delete";
|
|
24
|
+
url: "/approval_policies/{approval_policy_id}";
|
|
25
|
+
}, undefined, paths["/approval_policies/{approval_policy_id}"]["delete"]["responses"]["200"]["content"]["application/json"], paths["/approval_policies/{approval_policy_id}"]["delete"]["parameters"], paths["/approval_policies/{approval_policy_id}"]["delete"]["responses"]["401"]["content"]["application/json"] | paths["/approval_policies/{approval_policy_id}"]["delete"]["responses"]["422"]["content"]["application/json"] | paths["/approval_policies/{approval_policy_id}"]["delete"]["responses"]["default"]["content"]["application/json"]>;
|
|
26
|
+
/**
|
|
27
|
+
* @summary Update an approval policy
|
|
28
|
+
* @description Update an existing approval policy.
|
|
29
|
+
*/
|
|
30
|
+
patchApprovalPoliciesId: ServiceOperationMutation<{
|
|
31
|
+
method: "patch";
|
|
32
|
+
url: "/approval_policies/{approval_policy_id}";
|
|
33
|
+
mediaType: "application/json";
|
|
34
|
+
}, NonNullable<paths["/approval_policies/{approval_policy_id}"]["patch"]["requestBody"]>["content"]["application/json"], paths["/approval_policies/{approval_policy_id}"]["patch"]["responses"]["200"]["content"]["application/json"], paths["/approval_policies/{approval_policy_id}"]["patch"]["parameters"], paths["/approval_policies/{approval_policy_id}"]["patch"]["responses"]["401"]["content"]["application/json"] | paths["/approval_policies/{approval_policy_id}"]["patch"]["responses"]["422"]["content"]["application/json"] | paths["/approval_policies/{approval_policy_id}"]["patch"]["responses"]["default"]["content"]["application/json"]>;
|
|
35
|
+
}
|
|
36
|
+
export const approvalPoliciesService: {
|
|
37
|
+
[key in keyof ApprovalPoliciesService]: Pick<ApprovalPoliciesService[key], "schema">;
|
|
38
|
+
} = {
|
|
39
|
+
getApprovalPoliciesId: {
|
|
40
|
+
schema: {
|
|
41
|
+
method: "get",
|
|
42
|
+
url: "/approval_policies/{approval_policy_id}"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
deleteApprovalPoliciesId: {
|
|
46
|
+
schema: {
|
|
47
|
+
method: "delete",
|
|
48
|
+
url: "/approval_policies/{approval_policy_id}"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
patchApprovalPoliciesId: {
|
|
52
|
+
schema: {
|
|
53
|
+
method: "patch",
|
|
54
|
+
url: "/approval_policies/{approval_policy_id}",
|
|
55
|
+
mediaType: "application/json"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} as const;
|
|
59
|
+
"
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=ApprovalPoliciesService.ts.snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApprovalPoliciesService.ts.snapshot.js","sourceRoot":"","sources":["../../../src/__snapshots__/services/ApprovalPoliciesService.ts.snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO;IACZ,MAAM,CACJ,EAAE,CAAC,YAAY,CAAC,8CAA8C,EAAE,OAAO,CAAC,CACzE,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDvB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { expect } from 'vitest';
|
|
3
|
+
export default function () {
|
|
4
|
+
expect(fs.readFileSync('/mock-fs/services/FilesService.ts', 'utf-8'))
|
|
5
|
+
.toMatchInlineSnapshot(`
|
|
6
|
+
"/* generated using @openapi-qraft/cli -- do no edit */
|
|
7
|
+
/* istanbul ignore file */
|
|
8
|
+
import type { paths } from "../../openapi.js";
|
|
9
|
+
import type { ServiceOperationQuery, ServiceOperationMutation } from "@openapi-qraft/react";
|
|
10
|
+
export interface FilesService {
|
|
11
|
+
/** @summary Get a files by ID */
|
|
12
|
+
getFiles: ServiceOperationQuery<{
|
|
13
|
+
method: "get";
|
|
14
|
+
url: "/files";
|
|
15
|
+
}, paths["/files"]["get"]["responses"]["200"]["content"]["application/json"], paths["/files"]["get"]["parameters"], paths["/files"]["get"]["responses"]["405"]["content"]["application/json"] | paths["/files"]["get"]["responses"]["422"]["content"]["application/json"] | paths["/files"]["get"]["responses"]["default"]["content"]["application/json"]>;
|
|
16
|
+
/** @summary Upload a files by ID */
|
|
17
|
+
postFiles: ServiceOperationMutation<{
|
|
18
|
+
method: "post";
|
|
19
|
+
url: "/files";
|
|
20
|
+
mediaType: "multipart/form-data";
|
|
21
|
+
}, NonNullable<paths["/files"]["post"]["requestBody"]>["content"]["multipart/form-data"], paths["/files"]["post"]["responses"]["200"]["content"]["application/json"], undefined, paths["/files"]["post"]["responses"]["default"]["content"]["application/json"]>;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated
|
|
24
|
+
* @summary Get a file list
|
|
25
|
+
*/
|
|
26
|
+
getFileList: ServiceOperationQuery<{
|
|
27
|
+
method: "get";
|
|
28
|
+
url: "/files/list";
|
|
29
|
+
}, paths["/files/list"]["get"]["responses"]["200"]["content"]["application/json"], paths["/files/list"]["get"]["parameters"], paths["/files/list"]["get"]["responses"]["default"]["content"]["application/json"]>;
|
|
30
|
+
}
|
|
31
|
+
export const filesService: {
|
|
32
|
+
[key in keyof FilesService]: Pick<FilesService[key], "schema">;
|
|
33
|
+
} = {
|
|
34
|
+
getFiles: {
|
|
35
|
+
schema: {
|
|
36
|
+
method: "get",
|
|
37
|
+
url: "/files"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
postFiles: {
|
|
41
|
+
schema: {
|
|
42
|
+
method: "post",
|
|
43
|
+
url: "/files",
|
|
44
|
+
mediaType: "multipart/form-data"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
getFileList: {
|
|
48
|
+
schema: {
|
|
49
|
+
method: "get",
|
|
50
|
+
url: "/files/list"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} as const;
|
|
54
|
+
"
|
|
55
|
+
`);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=FilesService.ts.snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilesService.ts.snapshot.js","sourceRoot":"","sources":["../../../src/__snapshots__/services/FilesService.ts.snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO;IACZ,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,mCAAmC,EAAE,OAAO,CAAC,CAAC;SAClE,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkDtB,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { expect } from 'vitest';
|
|
3
|
+
export default function () {
|
|
4
|
+
expect(fs.readFileSync('/mock-fs/services/index.ts', 'utf-8'))
|
|
5
|
+
.toMatchInlineSnapshot(`
|
|
6
|
+
"/* generated using @openapi-qraft/cli -- do no edit */
|
|
7
|
+
/* istanbul ignore file */
|
|
8
|
+
import { EntitiesService, entitiesService } from "./EntitiesService.js";
|
|
9
|
+
import { ApprovalPoliciesService, approvalPoliciesService } from "./ApprovalPoliciesService.js";
|
|
10
|
+
import { FilesService, filesService } from "./FilesService.js";
|
|
11
|
+
export type Services = {
|
|
12
|
+
entities: EntitiesService;
|
|
13
|
+
approvalPolicies: ApprovalPoliciesService;
|
|
14
|
+
files: FilesService;
|
|
15
|
+
};
|
|
16
|
+
export const services = {
|
|
17
|
+
entities: entitiesService,
|
|
18
|
+
approvalPolicies: approvalPoliciesService,
|
|
19
|
+
files: filesService
|
|
20
|
+
} as const;
|
|
21
|
+
"
|
|
22
|
+
`);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=index.ts.snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.ts.snapshot.js","sourceRoot":"","sources":["../../../src/__snapshots__/services/index.ts.snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO;IACZ,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;SAC3D,qBAAqB,CAAC;;;;;;;;;;;;;;;;;KAiBtB,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GeneratorFile } from '@openapi-qraft/plugin/lib/GeneratorFile';
|
|
2
|
+
import { Service } from '@openapi-qraft/plugin/lib/open-api/getServices';
|
|
3
|
+
import { OutputOptions as OutputOptionsBase } from '@openapi-qraft/plugin/lib/OutputOptions';
|
|
4
|
+
import { Ora } from 'ora';
|
|
5
|
+
import { ServiceImportsFactoryOptions } from './ts-factory/getServiceFactory.js';
|
|
6
|
+
interface OutputOptions extends OutputOptionsBase {
|
|
7
|
+
fileHeader: string | undefined;
|
|
8
|
+
servicesDirName: string;
|
|
9
|
+
explicitImportExtensions: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const generateCode: ({ spinner, services, serviceImports, output, }: {
|
|
12
|
+
spinner: Ora;
|
|
13
|
+
services: Service[];
|
|
14
|
+
serviceImports: ServiceImportsFactoryOptions;
|
|
15
|
+
output: OutputOptions;
|
|
16
|
+
}) => Promise<GeneratorFile[]>;
|
|
17
|
+
export declare const getFileHeader: ({ fileHeader, }: Pick<OutputOptions, 'fileHeader'>) => string | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import c from 'ansi-colors';
|
|
2
|
+
import { URL } from 'node:url';
|
|
3
|
+
import { astToString } from './ts-factory/astToString.js';
|
|
4
|
+
import { getClientFactory } from './ts-factory/getClientFactory.js';
|
|
5
|
+
import { getIndexFactory } from './ts-factory/getIndexFactory.js';
|
|
6
|
+
import { getServiceFactory, } from './ts-factory/getServiceFactory.js';
|
|
7
|
+
import { getServiceIndexFactory } from './ts-factory/getServiceIndexFactory.js';
|
|
8
|
+
export const generateCode = async ({ spinner, services, serviceImports, output, }) => {
|
|
9
|
+
return [
|
|
10
|
+
...(await generateServices(spinner, services, serviceImports, output)),
|
|
11
|
+
...(await generateServiceIndex(spinner, services, output)),
|
|
12
|
+
...(await generateClient(spinner, output)),
|
|
13
|
+
...(await generateIndex(spinner, output)),
|
|
14
|
+
];
|
|
15
|
+
};
|
|
16
|
+
const composeServicesDirPath = (output) => {
|
|
17
|
+
return new URL(`${output.servicesDirName}/`, output.dir);
|
|
18
|
+
};
|
|
19
|
+
const generateServices = async (spinner, services, serviceImports, output) => {
|
|
20
|
+
const servicesDir = composeServicesDirPath(output);
|
|
21
|
+
spinner.start('Generating services');
|
|
22
|
+
const serviceFiles = [
|
|
23
|
+
{
|
|
24
|
+
directory: servicesDir,
|
|
25
|
+
clean: output.clean,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
for (const service of services) {
|
|
29
|
+
const { operations, name, typeName, variableName, fileBaseName } = service;
|
|
30
|
+
spinner.text = `Generating ${c.magenta(name)} service`;
|
|
31
|
+
try {
|
|
32
|
+
const code = astToString(getServiceFactory({
|
|
33
|
+
typeName,
|
|
34
|
+
variableName,
|
|
35
|
+
}, operations, serviceImports));
|
|
36
|
+
serviceFiles.push({
|
|
37
|
+
file: new URL(`${fileBaseName}.ts`, servicesDir),
|
|
38
|
+
code: getFileHeader(output) + code,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
spinner.fail(c.redBright(`Error occurred during ${c.magenta(name)} service generation`));
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
spinner.succeed(c.green('Services has been generated'));
|
|
47
|
+
return serviceFiles;
|
|
48
|
+
};
|
|
49
|
+
const generateServiceIndex = async (spinner, services, output) => {
|
|
50
|
+
spinner.start('Generating services index');
|
|
51
|
+
const serviceIndexFiles = [
|
|
52
|
+
{
|
|
53
|
+
directory: composeServicesDirPath(output),
|
|
54
|
+
clean: output.clean,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
try {
|
|
58
|
+
const code = astToString(getServiceIndexFactory(services, {
|
|
59
|
+
explicitImportExtensions: Boolean(output.explicitImportExtensions),
|
|
60
|
+
}));
|
|
61
|
+
serviceIndexFiles.push({
|
|
62
|
+
file: new URL('index.ts', composeServicesDirPath(output)),
|
|
63
|
+
code: getFileHeader(output) + code,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
spinner.fail(c.redBright('Error occurred during services index generation'));
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
spinner.succeed(c.green('Services index has been generated'));
|
|
71
|
+
return serviceIndexFiles;
|
|
72
|
+
};
|
|
73
|
+
const generateClient = async (spinner, output) => {
|
|
74
|
+
spinner.start('Generating client');
|
|
75
|
+
const clientFiles = [];
|
|
76
|
+
try {
|
|
77
|
+
const code = astToString(getClientFactory({
|
|
78
|
+
servicesDirName: output.servicesDirName,
|
|
79
|
+
explicitImportExtensions: Boolean(output.explicitImportExtensions),
|
|
80
|
+
}));
|
|
81
|
+
clientFiles.push({
|
|
82
|
+
file: new URL('create-api-client.ts', output.dir),
|
|
83
|
+
code: getFileHeader(output) + code,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
spinner.fail(c.redBright('Error occurred during client generation'));
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
spinner.succeed(c.green('Client has been generated'));
|
|
91
|
+
return clientFiles;
|
|
92
|
+
};
|
|
93
|
+
const generateIndex = async (spinner, output) => {
|
|
94
|
+
spinner.start('Generating index');
|
|
95
|
+
const indexFiles = [];
|
|
96
|
+
try {
|
|
97
|
+
const code = astToString(getIndexFactory({
|
|
98
|
+
servicesDirName: output.servicesDirName,
|
|
99
|
+
explicitImportExtensions: Boolean(output.explicitImportExtensions),
|
|
100
|
+
}));
|
|
101
|
+
indexFiles.push({
|
|
102
|
+
file: new URL('index.ts', output.dir),
|
|
103
|
+
code: getFileHeader(output) + code,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
spinner.fail(c.redBright('Error occurred during index generation'));
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
spinner.succeed(c.green('Index has been generated'));
|
|
111
|
+
return indexFiles;
|
|
112
|
+
};
|
|
113
|
+
export const getFileHeader = ({ fileHeader, }) => {
|
|
114
|
+
return fileHeader && `${fileHeader}\n`;
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=generateCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCode.js","sourceRoot":"","sources":["../src/generateCode.ts"],"names":[],"mappings":"AAIA,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EACL,iBAAiB,GAElB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAQhF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,OAAO,EACP,QAAQ,EACR,cAAc,EACd,MAAM,GAMP,EAAE,EAAE;IACH,OAAO;QACL,GAAG,CAAC,MAAM,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;QACtE,GAAG,CAAC,MAAM,oBAAoB,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC1D,GAAG,CAAC,MAAM,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1C,GAAG,CAAC,MAAM,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAC1C,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAC7B,MAAsD,EACtD,EAAE;IACF,OAAO,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,eAAe,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,KAAK,EAC5B,OAAY,EACZ,QAAmB,EACnB,cAA4C,EAC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U,IAAI,CAAC;AACzC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAe,MAAM,CAAC"}
|
package/dist/plugin.d.ts
ADDED
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { fileHeader } from '@openapi-qraft/plugin/lib/fileHeader';
|
|
2
|
+
import { generateCode } from './generateCode.js';
|
|
3
|
+
export const plugin = {
|
|
4
|
+
setupCommand(command) {
|
|
5
|
+
command
|
|
6
|
+
.description('Generate TanStack Query React client from OpenAPI Schema')
|
|
7
|
+
.requiredOption('--openapi-types-import-path <path>', // todo::specify better param name to avoid confusion with real path
|
|
8
|
+
'Path to schema types file (.d.ts), eg: "../openapi.d.ts"')
|
|
9
|
+
.option('--file-header <string>', 'Header to be added to the generated file (eg: /* eslint-disable */)')
|
|
10
|
+
.option('--explicit-import-extensions', 'All import statements will include explicit `.js` extensions. Ideal for projects using ECMAScript modules.')
|
|
11
|
+
.option('--operation-generics-import-path <path>', 'Path to operation generics file', '@openapi-qraft/react')
|
|
12
|
+
.action(({ spinner, output, args, services }, resolve) => {
|
|
13
|
+
return void generateCode({
|
|
14
|
+
spinner,
|
|
15
|
+
services,
|
|
16
|
+
serviceImports: {
|
|
17
|
+
operationGenericsImportPath: args.operationGenericsImportPath,
|
|
18
|
+
openapiTypesImportPath: args.openapiTypesImportPath,
|
|
19
|
+
},
|
|
20
|
+
output: {
|
|
21
|
+
...output,
|
|
22
|
+
fileHeader: args.fileHeader ?? fileHeader,
|
|
23
|
+
explicitImportExtensions: args.explicitImportExtensions,
|
|
24
|
+
servicesDirName: 'services',
|
|
25
|
+
},
|
|
26
|
+
}).then(resolve);
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAIlE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,MAAM,MAAM,GAAuB;IACxC,YAAY,CAAC,OAAqB;QAChC,OAAO;aACJ,WAAW,CAAC,0DAA0D,CAAC;aACvE,cAAc,CACb,oCAAoC,EAAE,oEAAoE;QAC1G,0DAA0D,CAC3D;aACA,MAAM,CACL,wBAAwB,EACxB,qEAAqE,CACtE;aACA,MAAM,CACL,8BAA8B,EAC9B,4GAA4G,CAC7G;aACA,MAAM,CACL,yCAAyC,EACzC,iCAAiC,EACjC,sBAAsB,CACvB;aACA,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,EAAE;YACvD,OAAO,KAAK,YAAY,CAAC;gBACvB,OAAO;gBACP,QAAQ;gBACR,cAAc,EAAE;oBACd,2BAA2B,EAAE,IAAI,CAAC,2BAA2B;oBAC7D,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;iBACpD;gBACD,MAAM,EAAE;oBACN,GAAG,MAAM;oBACT,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,UAAU;oBACzC,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;oBACvD,eAAe,EAAE,UAAU;iBAC5B;aACF,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACP,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export interface AstToStringOptions {
|
|
3
|
+
fileName?: string;
|
|
4
|
+
sourceText?: string;
|
|
5
|
+
formatOptions?: ts.PrinterOptions;
|
|
6
|
+
}
|
|
7
|
+
/** Convert TypeScript AST to string */
|
|
8
|
+
export declare function astToString(ast: ts.Node | ts.Node[] | ts.TypeElement | ts.TypeElement[], options?: AstToStringOptions): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
/** Convert TypeScript AST to string */
|
|
3
|
+
export function astToString(ast, options) {
|
|
4
|
+
const sourceFile = ts.createSourceFile(options?.fileName ?? 'openapi-ts.ts', options?.sourceText ?? '', ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
5
|
+
// @ts-expect-error it’s OK to overwrite statements once
|
|
6
|
+
sourceFile.statements = ts.factory.createNodeArray(Array.isArray(ast) ? ast : [ast]);
|
|
7
|
+
const printer = ts.createPrinter({
|
|
8
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
9
|
+
removeComments: false,
|
|
10
|
+
...options?.formatOptions,
|
|
11
|
+
});
|
|
12
|
+
return printer.printFile(sourceFile);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=astToString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astToString.js","sourceRoot":"","sources":["../../src/ts-factory/astToString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAQ5B,uCAAuC;AACvC,MAAM,UAAU,WAAW,CACzB,GAA4D,EAC5D,OAA4B;IAE5B,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,OAAO,EAAE,QAAQ,IAAI,eAAe,EACpC,OAAO,EAAE,UAAU,IAAI,EAAE,EACzB,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,KAAK,EACL,EAAE,CAAC,UAAU,CAAC,EAAE,CACjB,CAAC;IAEF,wDAAwD;IACxD,UAAU,CAAC,UAAU,GAAG,EAAE,CAAC,OAAO,CAAC,eAAe,CAChD,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CACjC,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC;QAC/B,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ;QAChC,cAAc,EAAE,KAAK;QACrB,GAAG,OAAO,EAAE,aAAa;KAC1B,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export const getClientFactory = (options) => {
|
|
3
|
+
return [
|
|
4
|
+
...getClientImportsFactory(options),
|
|
5
|
+
getCallbacksVariableFactory(),
|
|
6
|
+
getCreateClientFunctionFactory(),
|
|
7
|
+
];
|
|
8
|
+
};
|
|
9
|
+
const getClientImportsFactory = ({ servicesDirName, explicitImportExtensions, }) => {
|
|
10
|
+
const factory = ts.factory;
|
|
11
|
+
return [
|
|
12
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
13
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('qraftAPIClient')),
|
|
14
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('QraftClientOptions')),
|
|
15
|
+
])), factory.createStringLiteral('@openapi-qraft/react'), undefined),
|
|
16
|
+
...serviceCallbacks.map((propertyName) => factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
17
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier(propertyName)),
|
|
18
|
+
])), factory.createStringLiteral(`@openapi-qraft/react/callbacks/${propertyName}`), undefined)),
|
|
19
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
20
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('services')),
|
|
21
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Services')),
|
|
22
|
+
])), factory.createStringLiteral(`./${servicesDirName}/index${explicitImportExtensions ? '.js' : ''}`), undefined),
|
|
23
|
+
];
|
|
24
|
+
};
|
|
25
|
+
const getCallbacksVariableFactory = () => {
|
|
26
|
+
const factory = ts.factory;
|
|
27
|
+
return factory.createVariableStatement(undefined, factory.createVariableDeclarationList([
|
|
28
|
+
factory.createVariableDeclaration(factory.createIdentifier('callbacks'), undefined, undefined, factory.createObjectLiteralExpression(serviceCallbacks.map((propertyName) => factory.createShorthandPropertyAssignment(factory.createIdentifier(propertyName), undefined)), true)),
|
|
29
|
+
], ts.NodeFlags.Const));
|
|
30
|
+
};
|
|
31
|
+
const getCreateClientFunctionFactory = () => {
|
|
32
|
+
const factory = ts.factory;
|
|
33
|
+
return factory.createFunctionDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], undefined, factory.createIdentifier('createAPIClient'), undefined, [
|
|
34
|
+
factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier('options'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(factory.createIdentifier('QraftClientOptions'), undefined), undefined),
|
|
35
|
+
], factory.createTypeReferenceNode(factory.createIdentifier('Services'), undefined), factory.createBlock([
|
|
36
|
+
factory.createReturnStatement(factory.createCallExpression(factory.createIdentifier('qraftAPIClient'), [
|
|
37
|
+
factory.createTypeReferenceNode(factory.createIdentifier('Services'), undefined),
|
|
38
|
+
factory.createTypeQueryNode(factory.createIdentifier('callbacks'), undefined),
|
|
39
|
+
], [
|
|
40
|
+
factory.createIdentifier('services'),
|
|
41
|
+
factory.createIdentifier('callbacks'),
|
|
42
|
+
factory.createIdentifier('options'),
|
|
43
|
+
])),
|
|
44
|
+
], true));
|
|
45
|
+
};
|
|
46
|
+
// todo::make callbacks type-safe
|
|
47
|
+
const serviceCallbacks = [
|
|
48
|
+
'getInfiniteQueryData',
|
|
49
|
+
'getInfiniteQueryKey',
|
|
50
|
+
'getMutationKey',
|
|
51
|
+
'getQueryData',
|
|
52
|
+
'getQueriesData',
|
|
53
|
+
'getQueryKey',
|
|
54
|
+
'mutationFn',
|
|
55
|
+
'queryFn',
|
|
56
|
+
'setInfiniteQueryData',
|
|
57
|
+
'setQueryData',
|
|
58
|
+
'setQueriesData',
|
|
59
|
+
'useInfiniteQuery',
|
|
60
|
+
'useMutation',
|
|
61
|
+
'useQuery',
|
|
62
|
+
'useSuspenseQuery',
|
|
63
|
+
'useSuspenseInfiniteQuery',
|
|
64
|
+
'useMutationState',
|
|
65
|
+
'useIsMutating',
|
|
66
|
+
'useQueries',
|
|
67
|
+
'useSuspenseQueries',
|
|
68
|
+
'invalidateQueries',
|
|
69
|
+
'cancelQueries',
|
|
70
|
+
'resetQueries',
|
|
71
|
+
'removeQueries',
|
|
72
|
+
'refetchQueries',
|
|
73
|
+
'isFetching',
|
|
74
|
+
'isMutating',
|
|
75
|
+
'useIsFetching',
|
|
76
|
+
'fetchQuery',
|
|
77
|
+
'prefetchQuery',
|
|
78
|
+
'fetchInfiniteQuery',
|
|
79
|
+
'prefetchInfiniteQuery',
|
|
80
|
+
'getQueryState',
|
|
81
|
+
'getInfiniteQueryState',
|
|
82
|
+
'operationInvokeFn',
|
|
83
|
+
];
|
|
84
|
+
//# sourceMappingURL=getClientFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClientFactory.js","sourceRoot":"","sources":["../../src/ts-factory/getClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAO5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACnD,OAAO;QACL,GAAG,uBAAuB,CAAC,OAAO,CAAC;QACnC,2BAA2B,EAAE;QAC7B,8BAA8B,EAAE;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,EAC/B,eAAe,EACf,wBAAwB,GAChB,EAAE,EAAE;IACZ,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAE3B,OAAO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