Skip to content

Commit 1a89387

Browse files
committed
docs: fix precreated transform example
docs: split transform tsdoc examples docs: add precreated transform examples docs: expand transform tsdoc examples
1 parent e0e6a4a commit 1a89387

2 files changed

Lines changed: 63 additions & 5 deletions

File tree

packages/tree-shaking-plugin/src/lib/transform/mutate.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,38 @@ const traverse =
2222
*
2323
* @example
2424
* ```ts
25+
* const source = `
26+
* import { createAPIClient } from './api';
27+
*
28+
* const api = createAPIClient();
29+
*
30+
* export function App() {
31+
* api.pets.getPets.useQuery();
32+
* }
33+
* `;
34+
*
35+
* const plan = await createTransformPlan(source, id, options);
36+
*
37+
* applyTransformPlan(plan, plan.runtimeLocalNames);
38+
*
39+
* // `plan.ast` now contains the rewritten named client call and imports.
40+
* ```
41+
*
42+
* @example
43+
* ```ts
44+
* const source = `
45+
* import { client } from './client';
46+
*
47+
* export function App() {
48+
* client.pets.getPets.useQuery();
49+
* }
50+
* `;
51+
*
2552
* const plan = await createTransformPlan(source, id, options);
2653
*
2754
* applyTransformPlan(plan, plan.runtimeLocalNames);
2855
*
29-
* // `plan.ast` is now mutated in place and ready for code generation.
56+
* // `plan.ast` now contains the rewritten precreated client call.
3057
* ```
3158
*/
3259
export function applyTransformPlan(

packages/tree-shaking-plugin/src/lib/transform/plan.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ type ExportedDeclarationResolution = {
9393
*
9494
* @example
9595
* ```ts
96+
* const source = `
97+
* import { createAPIClient } from './api';
98+
*
99+
* const api = createAPIClient();
100+
*
101+
* export function App() {
102+
* api.pets.getPets.useQuery();
103+
* }
104+
* `;
105+
*
96106
* const plan = await createTransformPlan(source, id, options);
97107
*
98108
* plan.clients[0]
@@ -110,12 +120,33 @@ type ExportedDeclarationResolution = {
110120
* // callbackName: 'useQuery',
111121
* // ...
112122
* // }
123+
* ```
124+
*
125+
* @example
126+
* ```ts
127+
* const source = `
128+
* import { client } from './client';
129+
*
130+
* export function App() {
131+
* client.pets.getPets.useQuery();
132+
* }
133+
* `;
134+
*
135+
* const plan = await createTransformPlan(source, id, options);
113136
*
114-
* plan.inlineUsages[0]
137+
* plan.clients[0]
115138
* // {
116-
* // callbackName: 'invalidateQueries',
117-
* // callbackLocalName: 'invalidateQueries',
118-
* // operationImport: { importPath: './api/services/PetsService' },
139+
* // name: 'client',
140+
* // mode: { type: 'precreated' },
141+
* // ...
142+
* // }
143+
*
144+
* plan.namedUsages[0]
145+
* // {
146+
* // client: { name: 'client' },
147+
* // serviceName: 'pets',
148+
* // operationName: 'getPets',
149+
* // callbackName: 'useQuery',
119150
* // ...
120151
* // }
121152
* ```

0 commit comments

Comments
 (0)