@aws/nx-plugin 0.69.0 → 0.69.1
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/package.json +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/infra/app/generator.js +1 -1
- package/src/infra/app/generator.js.map +1 -1
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +103 -46
- package/src/trpc/react/files/src/components/__apiNameClassName__ClientProvider.tsx.template +21 -10
- package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +16 -1
package/package.json
CHANGED
|
@@ -84,7 +84,7 @@ exports[`infra generator > should configure Checkov target correctly > checkov-t
|
|
|
84
84
|
"{workspaceRoot}/dist/{projectRoot}/cdk.out",
|
|
85
85
|
],
|
|
86
86
|
"options": {
|
|
87
|
-
"command": "uvx --with pycares==4.11.0 checkov==3.2.500 --config-file packages/test/checkov.yml --
|
|
87
|
+
"command": "uvx --with pycares==4.11.0 checkov==3.2.500 --config-file packages/test/checkov.yml --directory dist/packages/test/cdk.out --framework cloudformation",
|
|
88
88
|
},
|
|
89
89
|
"outputs": [
|
|
90
90
|
"{workspaceRoot}/dist/{projectRoot}/checkov",
|
|
@@ -177,7 +177,7 @@ exports[`infra generator > should configure project.json with correct targets >
|
|
|
177
177
|
"{workspaceRoot}/dist/{projectRoot}/cdk.out",
|
|
178
178
|
],
|
|
179
179
|
"options": {
|
|
180
|
-
"command": "uvx --with pycares==4.11.0 checkov==3.2.500 --config-file packages/test/checkov.yml --
|
|
180
|
+
"command": "uvx --with pycares==4.11.0 checkov==3.2.500 --config-file packages/test/checkov.yml --directory dist/packages/test/cdk.out --framework cloudformation",
|
|
181
181
|
},
|
|
182
182
|
"outputs": [
|
|
183
183
|
"{workspaceRoot}/dist/{projectRoot}/checkov",
|
|
@@ -724,7 +724,7 @@ exports[`infra generator > should handle custom project names correctly > custom
|
|
|
724
724
|
"{workspaceRoot}/dist/{projectRoot}/cdk.out",
|
|
725
725
|
],
|
|
726
726
|
"options": {
|
|
727
|
-
"command": "uvx --with pycares==4.11.0 checkov==3.2.500 --config-file packages/custom-infra/checkov.yml --
|
|
727
|
+
"command": "uvx --with pycares==4.11.0 checkov==3.2.500 --config-file packages/custom-infra/checkov.yml --directory dist/packages/custom-infra/cdk.out --framework cloudformation",
|
|
728
728
|
},
|
|
729
729
|
"outputs": [
|
|
730
730
|
"{workspaceRoot}/dist/{projectRoot}/checkov",
|
|
@@ -72,7 +72,7 @@ function tsInfraGenerator(tree, schema) {
|
|
|
72
72
|
outputs: ['{workspaceRoot}/dist/{projectRoot}/checkov'],
|
|
73
73
|
dependsOn: ['synth'],
|
|
74
74
|
options: {
|
|
75
|
-
command: (0, py_1.uvxCommand)('checkov', `--config-file ${lib.dir}/checkov.yml --
|
|
75
|
+
command: (0, py_1.uvxCommand)('checkov', `--config-file ${lib.dir}/checkov.yml --directory dist/${lib.dir}/cdk.out --framework cloudformation`, [{ dep: 'pycares', version: '4.11.0' }]),
|
|
76
76
|
},
|
|
77
77
|
};
|
|
78
78
|
config.targets.deploy = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/infra/app/generator.ts"],"names":[],"mappings":";;;AA0CA,4CAgKC;;AA1MD;;;GAGG;AACH,uCAYoB;AAEpB,4EAA6E;AAC7E,mDAAoD;AACpD,qDAAwE;AACxE,qEAA0E;AAC1E,yFAGiD;AAEjD,wDAAwB;AACxB,+CAA0D;AAC1D,+CAAoD;AACpD,uCAIwB;AACxB,iDAAsE;AACtE,6CAA8C;AAC9C,uCAA4C;AAE/B,QAAA,wBAAwB,GACnC,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAE/B,SAAsB,gBAAgB,CACpC,IAAU,EACV,MAA8B;;QAE9B,MAAM,GAAG,GAAG,IAAA,2BAAe,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,IAA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AAM,GAEX;YACE,iBAAiB,EAAE,0BAAiB,CAAC,SAAS;SAC/C,CACF,CAAC;QAEF,IAAA,mBAAU,EACR,IAAI,EACJ,GAAG,WAAW,eAAe,EAC7B,CAAC,MAA4B,EAAE,EAAE;;YAC/B,MAAM,CAAC,WAAW,GAAG,aAAa,CAAC;YACnC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,GAAG;gBAC/B,GAAG,CAAC,MAAA,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,mCAAI,EAAE,CAAC;gBACzC,OAAO;gBACP,SAAS;aACV,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,KAAK,GAAG;gBACrB,KAAK,EAAE,IAAI;gBACX,QAAQ,EAAE,iBAAiB;gBAC3B,MAAM,EAAE,CAAC,SAAS,CAAC;gBACnB,OAAO,EAAE,CAAC,kBAAkB,gBAAgB,EAAE,CAAC;gBAC/C,SAAS,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,mEAAmE;gBACrG,OAAO,EAAE;oBACP,GAAG,EAAE,WAAW;oBAChB,OAAO,EAAE,WAAW;iBACrB;aACF,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG;gBACvB,KAAK,EAAE,IAAI;gBACX,QAAQ,EAAE,iBAAiB;gBAC3B,MAAM,EAAE,CAAC,4CAA4C,CAAC;gBACtD,OAAO,EAAE,CAAC,4CAA4C,CAAC;gBACvD,SAAS,EAAE,CAAC,OAAO,CAAC;gBACpB,OAAO,EAAE;oBACP,OAAO,EAAE,IAAA,eAAU,EACjB,SAAS,EACT,iBAAiB,GAAG,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/infra/app/generator.ts"],"names":[],"mappings":";;;AA0CA,4CAgKC;;AA1MD;;;GAGG;AACH,uCAYoB;AAEpB,4EAA6E;AAC7E,mDAAoD;AACpD,qDAAwE;AACxE,qEAA0E;AAC1E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,QAAQ,EAAE,iBAAiB;gBAC3B,OAAO,EAAE;oBACP,GAAG,EAAE,WAAW;oBAChB,OAAO,EAAE,eAAe;iBACzB;aACF,CAAC;YACF,MAAM,CAAC,OAAO,GAAG,IAAA,uBAAc,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAChD,OAAO,MAAM,CAAC;QAChB,CAAC,CACF,CAAC;QAEF,IAAA,qCAA4B,EAC1B,IAAI,EACJ,IAAA,uBAAY,EAAC;YACX,aAAa;YACb,SAAS;YACT,SAAS;YACT,YAAY;YACZ,oBAAoB;SACrB,CAAC,EACF,IAAA,uBAAY,EAAC,CAAC,KAAK,CAAC,CAAC,CACtB,CAAC;QAEF,IAAA,mBAAU,EAAC,IAAI,EAAE,GAAG,WAAW,gBAAgB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,iCAC1D,QAAQ,KACX,UAAU,EAAE;gBACV,GAAG,CAAC,QAAQ,CAAC,UAAU,IAAI,EAAE,CAAC;gBAC9B;oBACE,IAAI,EAAE,GAAG,cAAI,CAAC,QAAQ,CACpB,WAAW,EACX,GAAG,IAAI,CAAC,IAAI,IAAI,0CAAY,EAAE,CAC/B,IAAI,mDAAqB,gBAAgB;iBAC3C;aACF,IACD,CAAC,CAAC;QAEJ,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE,CAAC,gCAAwB,CAAC,CAAC,CAAC;QAExE,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;QACjC,OAAO,GAAG,EAAE;YACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC;CAAA;AACD,kBAAe,gBAAgB,CAAC"}
|
|
@@ -3,37 +3,51 @@
|
|
|
3
3
|
exports[`trpc react generator > should generate trpc react files > TestApiClientProvider.tsx 1`] = `
|
|
4
4
|
"import { AppRouter } from 'backend';
|
|
5
5
|
import { useQueryClient } from '@tanstack/react-query';
|
|
6
|
-
import {
|
|
7
|
-
import { FC, PropsWithChildren, useMemo } from 'react';
|
|
6
|
+
import { createTRPCOptionsProxy } from '@trpc/tanstack-react-query';
|
|
7
|
+
import { createContext, FC, PropsWithChildren, useMemo } from 'react';
|
|
8
8
|
import { useRuntimeConfig } from '../hooks/useRuntimeConfig';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
HTTPLinkOptions,
|
|
11
|
+
TRPCClient,
|
|
12
|
+
createTRPCClient,
|
|
13
|
+
httpLink,
|
|
14
|
+
} from '@trpc/client';
|
|
15
|
+
|
|
16
|
+
interface TestApiTRPCContextValue {
|
|
17
|
+
optionsProxy: ReturnType<typeof createTRPCOptionsProxy<AppRouter>>;
|
|
18
|
+
client: TRPCClient<AppRouter>;
|
|
19
|
+
}
|
|
10
20
|
|
|
11
|
-
export const TestApiTRPCContext
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
export const TestApiTRPCContext = createContext<TestApiTRPCContextValue | null>(
|
|
22
|
+
null,
|
|
23
|
+
);
|
|
14
24
|
|
|
15
25
|
export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
16
26
|
const queryClient = useQueryClient();
|
|
17
27
|
const runtimeConfig = useRuntimeConfig();
|
|
18
28
|
const apiUrl = runtimeConfig.apis.TestApi;
|
|
19
29
|
|
|
20
|
-
const
|
|
30
|
+
const container = useMemo<TestApiTRPCContextValue>(() => {
|
|
21
31
|
const linkOptions: HTTPLinkOptions<any> = {
|
|
22
32
|
url: apiUrl,
|
|
23
33
|
};
|
|
24
34
|
|
|
25
|
-
|
|
35
|
+
const client = createTRPCClient<AppRouter>({
|
|
26
36
|
links: [httpLink(linkOptions)],
|
|
27
37
|
});
|
|
28
|
-
|
|
38
|
+
|
|
39
|
+
const optionsProxy = createTRPCOptionsProxy<AppRouter>({
|
|
40
|
+
client,
|
|
41
|
+
queryClient,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return { optionsProxy, client };
|
|
45
|
+
}, [apiUrl, queryClient]);
|
|
29
46
|
|
|
30
47
|
return (
|
|
31
|
-
<TestApiTRPCContext.
|
|
32
|
-
trpcClient={trpcClient}
|
|
33
|
-
queryClient={queryClient}
|
|
34
|
-
>
|
|
48
|
+
<TestApiTRPCContext.Provider value={container}>
|
|
35
49
|
{children}
|
|
36
|
-
</TestApiTRPCContext.
|
|
50
|
+
</TestApiTRPCContext.Provider>
|
|
37
51
|
);
|
|
38
52
|
};
|
|
39
53
|
|
|
@@ -42,34 +56,60 @@ export default TestApiClientProvider;
|
|
|
42
56
|
`;
|
|
43
57
|
|
|
44
58
|
exports[`trpc react generator > should generate trpc react files > useTestApi.tsx 1`] = `
|
|
45
|
-
"import {
|
|
59
|
+
"import { useContext } from 'react';
|
|
60
|
+
import { TestApiTRPCContext } from '../components/TestApiClientProvider';
|
|
61
|
+
|
|
62
|
+
export const useTestApi = () => {
|
|
63
|
+
const container = useContext(TestApiTRPCContext);
|
|
64
|
+
if (!container) {
|
|
65
|
+
throw new Error('useTestApi must be used within TestApiClientProvider');
|
|
66
|
+
}
|
|
67
|
+
return container.optionsProxy;
|
|
68
|
+
};
|
|
46
69
|
|
|
47
|
-
export const
|
|
70
|
+
export const useTestApiClient = () => {
|
|
71
|
+
const container = useContext(TestApiTRPCContext);
|
|
72
|
+
if (!container) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
'useTestApiClient must be used within TestApiClientProvider',
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return container.client;
|
|
78
|
+
};
|
|
48
79
|
"
|
|
49
80
|
`;
|
|
50
81
|
|
|
51
82
|
exports[`trpc react generator > should handle Cognito auth option > TestApiClientProvider-Cognito.tsx 1`] = `
|
|
52
83
|
"import { AppRouter } from 'backend';
|
|
53
84
|
import { useQueryClient } from '@tanstack/react-query';
|
|
54
|
-
import {
|
|
55
|
-
import { FC, PropsWithChildren, useMemo } from 'react';
|
|
85
|
+
import { createTRPCOptionsProxy } from '@trpc/tanstack-react-query';
|
|
86
|
+
import { createContext, FC, PropsWithChildren, useMemo } from 'react';
|
|
56
87
|
import { useRuntimeConfig } from '../hooks/useRuntimeConfig';
|
|
57
|
-
import {
|
|
88
|
+
import {
|
|
89
|
+
HTTPLinkOptions,
|
|
90
|
+
TRPCClient,
|
|
91
|
+
createTRPCClient,
|
|
92
|
+
httpLink,
|
|
93
|
+
} from '@trpc/client';
|
|
58
94
|
import { useAuth } from 'react-oidc-context';
|
|
59
95
|
|
|
60
|
-
|
|
61
|
-
typeof
|
|
62
|
-
|
|
96
|
+
interface TestApiTRPCContextValue {
|
|
97
|
+
optionsProxy: ReturnType<typeof createTRPCOptionsProxy<AppRouter>>;
|
|
98
|
+
client: TRPCClient<AppRouter>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const TestApiTRPCContext = createContext<TestApiTRPCContextValue | null>(
|
|
102
|
+
null,
|
|
103
|
+
);
|
|
63
104
|
|
|
64
105
|
export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
65
106
|
const queryClient = useQueryClient();
|
|
66
107
|
const runtimeConfig = useRuntimeConfig();
|
|
67
108
|
const apiUrl = runtimeConfig.apis.TestApi;
|
|
68
|
-
|
|
69
109
|
const auth = useAuth();
|
|
70
110
|
const user = auth?.user;
|
|
71
111
|
|
|
72
|
-
const
|
|
112
|
+
const container = useMemo<TestApiTRPCContextValue>(() => {
|
|
73
113
|
const linkOptions: HTTPLinkOptions<any> = {
|
|
74
114
|
url: apiUrl,
|
|
75
115
|
headers: {
|
|
@@ -77,18 +117,22 @@ export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
|
77
117
|
},
|
|
78
118
|
};
|
|
79
119
|
|
|
80
|
-
|
|
120
|
+
const client = createTRPCClient<AppRouter>({
|
|
81
121
|
links: [httpLink(linkOptions)],
|
|
82
122
|
});
|
|
83
|
-
|
|
123
|
+
|
|
124
|
+
const optionsProxy = createTRPCOptionsProxy<AppRouter>({
|
|
125
|
+
client,
|
|
126
|
+
queryClient,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return { optionsProxy, client };
|
|
130
|
+
}, [apiUrl, queryClient, user]);
|
|
84
131
|
|
|
85
132
|
return (
|
|
86
|
-
<TestApiTRPCContext.
|
|
87
|
-
trpcClient={trpcClient}
|
|
88
|
-
queryClient={queryClient}
|
|
89
|
-
>
|
|
133
|
+
<TestApiTRPCContext.Provider value={container}>
|
|
90
134
|
{children}
|
|
91
|
-
</TestApiTRPCContext.
|
|
135
|
+
</TestApiTRPCContext.Provider>
|
|
92
136
|
);
|
|
93
137
|
};
|
|
94
138
|
|
|
@@ -99,41 +143,54 @@ export default TestApiClientProvider;
|
|
|
99
143
|
exports[`trpc react generator > should handle IAM auth option > TestApiClientProvider-IAM.tsx 1`] = `
|
|
100
144
|
"import { AppRouter } from 'backend';
|
|
101
145
|
import { useQueryClient } from '@tanstack/react-query';
|
|
102
|
-
import {
|
|
103
|
-
import { FC, PropsWithChildren, useMemo } from 'react';
|
|
146
|
+
import { createTRPCOptionsProxy } from '@trpc/tanstack-react-query';
|
|
147
|
+
import { createContext, FC, PropsWithChildren, useMemo } from 'react';
|
|
104
148
|
import { useRuntimeConfig } from '../hooks/useRuntimeConfig';
|
|
105
|
-
import {
|
|
149
|
+
import {
|
|
150
|
+
HTTPLinkOptions,
|
|
151
|
+
TRPCClient,
|
|
152
|
+
createTRPCClient,
|
|
153
|
+
httpLink,
|
|
154
|
+
} from '@trpc/client';
|
|
106
155
|
import { useSigV4 } from '../hooks/useSigV4';
|
|
107
156
|
|
|
108
|
-
|
|
109
|
-
typeof
|
|
110
|
-
|
|
157
|
+
interface TestApiTRPCContextValue {
|
|
158
|
+
optionsProxy: ReturnType<typeof createTRPCOptionsProxy<AppRouter>>;
|
|
159
|
+
client: TRPCClient<AppRouter>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const TestApiTRPCContext = createContext<TestApiTRPCContextValue | null>(
|
|
163
|
+
null,
|
|
164
|
+
);
|
|
111
165
|
|
|
112
166
|
export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
113
167
|
const queryClient = useQueryClient();
|
|
114
168
|
const runtimeConfig = useRuntimeConfig();
|
|
115
169
|
const apiUrl = runtimeConfig.apis.TestApi;
|
|
116
|
-
|
|
117
170
|
const sigv4Client = useSigV4();
|
|
118
171
|
|
|
119
|
-
const
|
|
172
|
+
const container = useMemo<TestApiTRPCContextValue>(() => {
|
|
120
173
|
const linkOptions: HTTPLinkOptions<any> = {
|
|
121
174
|
url: apiUrl,
|
|
122
175
|
fetch: sigv4Client,
|
|
123
176
|
};
|
|
124
177
|
|
|
125
|
-
|
|
178
|
+
const client = createTRPCClient<AppRouter>({
|
|
126
179
|
links: [httpLink(linkOptions)],
|
|
127
180
|
});
|
|
128
|
-
|
|
181
|
+
|
|
182
|
+
const optionsProxy = createTRPCOptionsProxy<AppRouter>({
|
|
183
|
+
client,
|
|
184
|
+
queryClient,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return { optionsProxy, client };
|
|
188
|
+
}, [apiUrl, queryClient, sigv4Client]);
|
|
129
189
|
|
|
130
190
|
return (
|
|
131
|
-
<TestApiTRPCContext.
|
|
132
|
-
trpcClient={trpcClient}
|
|
133
|
-
queryClient={queryClient}
|
|
134
|
-
>
|
|
191
|
+
<TestApiTRPCContext.Provider value={container}>
|
|
135
192
|
{children}
|
|
136
|
-
</TestApiTRPCContext.
|
|
193
|
+
</TestApiTRPCContext.Provider>
|
|
137
194
|
);
|
|
138
195
|
};
|
|
139
196
|
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { AppRouter } from "<%- backendProjectAlias %>";
|
|
2
2
|
import { useQueryClient } from "@tanstack/react-query";
|
|
3
|
-
import {
|
|
4
|
-
import { FC, PropsWithChildren, useMemo } from "react";
|
|
3
|
+
import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";
|
|
4
|
+
import { createContext, FC, PropsWithChildren, useMemo } from "react";
|
|
5
5
|
import { useRuntimeConfig } from "../hooks/useRuntimeConfig";
|
|
6
|
-
import { HTTPLinkOptions, createTRPCClient, httpLink } from "@trpc/client";
|
|
6
|
+
import { HTTPLinkOptions, TRPCClient, createTRPCClient, httpLink } from "@trpc/client";
|
|
7
7
|
<%_ if (auth === 'IAM') { _%>
|
|
8
8
|
import { useSigV4 } from "../hooks/useSigV4";
|
|
9
9
|
<%_ } else if (auth === 'Cognito') { _%>
|
|
10
10
|
import { useAuth } from "react-oidc-context";
|
|
11
11
|
<%_ } _%>
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
interface <%= apiNameClassName %>TRPCContextValue {
|
|
14
|
+
optionsProxy: ReturnType<typeof createTRPCOptionsProxy<AppRouter>>;
|
|
15
|
+
client: TRPCClient<AppRouter>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const <%= apiNameClassName %>TRPCContext = createContext<<%= apiNameClassName %>TRPCContextValue | null>(null);
|
|
14
19
|
|
|
15
20
|
export const <%= apiNameClassName %>ClientProvider: FC<PropsWithChildren> = ({
|
|
16
21
|
children,
|
|
@@ -18,7 +23,6 @@ export const <%= apiNameClassName %>ClientProvider: FC<PropsWithChildren> = ({
|
|
|
18
23
|
const queryClient = useQueryClient();
|
|
19
24
|
const runtimeConfig = useRuntimeConfig();
|
|
20
25
|
const apiUrl = runtimeConfig.apis.<%= apiNameClassName %>;
|
|
21
|
-
|
|
22
26
|
<%_ if (auth === 'IAM') { _%>
|
|
23
27
|
const sigv4Client = useSigV4();
|
|
24
28
|
<%_ } else if (auth === 'Cognito') { _%>
|
|
@@ -26,7 +30,7 @@ export const <%= apiNameClassName %>ClientProvider: FC<PropsWithChildren> = ({
|
|
|
26
30
|
const user = auth?.user;
|
|
27
31
|
<%_ } _%>
|
|
28
32
|
|
|
29
|
-
const
|
|
33
|
+
const container = useMemo<<%= apiNameClassName %>TRPCContextValue>(() => {
|
|
30
34
|
const linkOptions: HTTPLinkOptions<any> = {
|
|
31
35
|
url: apiUrl,
|
|
32
36
|
<%_ if (auth === 'IAM') { _%>
|
|
@@ -38,15 +42,22 @@ export const <%= apiNameClassName %>ClientProvider: FC<PropsWithChildren> = ({
|
|
|
38
42
|
<%_ } _%>
|
|
39
43
|
};
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
const client = createTRPCClient<AppRouter>({
|
|
42
46
|
links: [httpLink(linkOptions)],
|
|
43
47
|
});
|
|
44
|
-
|
|
48
|
+
|
|
49
|
+
const optionsProxy = createTRPCOptionsProxy<AppRouter>({
|
|
50
|
+
client,
|
|
51
|
+
queryClient,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return { optionsProxy, client };
|
|
55
|
+
}, [apiUrl, queryClient<% if (auth === 'IAM') { %>, sigv4Client<% } else if (auth === 'Cognito') { %>, user<% } %>]);
|
|
45
56
|
|
|
46
57
|
return (
|
|
47
|
-
<<%= apiNameClassName %>TRPCContext.
|
|
58
|
+
<<%= apiNameClassName %>TRPCContext.Provider value={container}>
|
|
48
59
|
{children}
|
|
49
|
-
</<%= apiNameClassName %>TRPCContext.
|
|
60
|
+
</<%= apiNameClassName %>TRPCContext.Provider>
|
|
50
61
|
);
|
|
51
62
|
};
|
|
52
63
|
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
1
2
|
import { <%= apiNameClassName %>TRPCContext } from '../components/<%- apiNameClassName %>ClientProvider';
|
|
2
3
|
|
|
3
|
-
export const use<%- apiNameClassName %> =
|
|
4
|
+
export const use<%- apiNameClassName %> = () => {
|
|
5
|
+
const container = useContext(<%= apiNameClassName %>TRPCContext);
|
|
6
|
+
if (!container) {
|
|
7
|
+
throw new Error('use<%- apiNameClassName %> must be used within <%= apiNameClassName %>ClientProvider');
|
|
8
|
+
}
|
|
9
|
+
return container.optionsProxy;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const use<%- apiNameClassName %>Client = () => {
|
|
13
|
+
const container = useContext(<%= apiNameClassName %>TRPCContext);
|
|
14
|
+
if (!container) {
|
|
15
|
+
throw new Error('use<%- apiNameClassName %>Client must be used within <%= apiNameClassName %>ClientProvider');
|
|
16
|
+
}
|
|
17
|
+
return container.client;
|
|
18
|
+
};
|