tangled
alpha
login
or
join now
mokkenstorm.dev
/
openapi-ts
0
fork
atom
fork of hey-api/openapi-ts because I need some additional things
0
fork
atom
overview
issues
pulls
pipelines
chore: add lazy dsl node
Lubos
3 months ago
fb8bdf19
e2f194d5
+95
-49
8 changed files
expand all
collapse all
unified
split
packages
openapi-ts
src
plugins
@pinia
colada
mutationOptions.ts
queryOptions.ts
@tanstack
query-core
v5
infiniteQueryOptions.ts
mutationOptions.ts
queryOptions.ts
swr
v2
useSwr.ts
ts-dsl
index.ts
utils
lazy.ts
+11
-9
packages/openapi-ts/src/plugins/@pinia/colada/mutationOptions.ts
···
31
31
const options = plugin.symbol('options');
32
32
const fnOptions = plugin.symbol('vars');
33
33
34
34
-
const awaitSdkFn = $(queryFn)
35
35
-
.call(
36
36
-
$.object()
37
37
-
.pretty()
38
38
-
.spread(options)
39
39
-
.spread(fnOptions)
40
40
-
.prop('throwOnError', $.literal(true)),
41
41
-
)
42
42
-
.await();
34
34
+
const awaitSdkFn = $.lazy(() =>
35
35
+
$(queryFn)
36
36
+
.call(
37
37
+
$.object()
38
38
+
.pretty()
39
39
+
.spread(options)
40
40
+
.spread(fnOptions)
41
41
+
.prop('throwOnError', $.literal(true)),
42
42
+
)
43
43
+
.await(),
44
44
+
);
43
45
44
46
const statements: Array<ReturnType<typeof $.var | typeof $.return>> = [];
45
47
+10
-8
packages/openapi-ts/src/plugins/@pinia/colada/queryOptions.ts
···
88
88
const client = getClientPlugin(plugin.context.config);
89
89
const isNuxtClient = client.name === '@hey-api/client-nuxt';
90
90
const typeData = getPublicTypeData({ isNuxtClient, operation, plugin });
91
91
-
const awaitSdkFn = $(queryFn)
92
92
-
.call(
93
93
-
$.object()
94
94
-
.spread(optionsParamName)
95
95
-
.spread(fnOptions)
96
96
-
.prop('throwOnError', $.literal(true)),
97
97
-
)
98
98
-
.await();
91
91
+
const awaitSdkFn = $.lazy(() =>
92
92
+
$(queryFn)
93
93
+
.call(
94
94
+
$.object()
95
95
+
.spread(optionsParamName)
96
96
+
.spread(fnOptions)
97
97
+
.prop('throwOnError', $.literal(true)),
98
98
+
)
99
99
+
.await(),
100
100
+
);
99
101
100
102
const statements: Array<ReturnType<typeof $.return | typeof $.const>> = [];
101
103
if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') {
+11
-9
packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts
···
198
198
});
199
199
plugin.node(node);
200
200
201
201
-
const awaitSdkFn = $(queryFn)
202
202
-
.call(
203
203
-
$.object()
204
204
-
.spread('options')
205
205
-
.spread('params')
206
206
-
.prop('signal', $('signal'))
207
207
-
.prop('throwOnError', $.literal(true)),
208
208
-
)
209
209
-
.await();
201
201
+
const awaitSdkFn = $.lazy(() =>
202
202
+
$(queryFn)
203
203
+
.call(
204
204
+
$.object()
205
205
+
.spread('options')
206
206
+
.spread('params')
207
207
+
.prop('signal', $('signal'))
208
208
+
.prop('throwOnError', $.literal(true)),
209
209
+
)
210
210
+
.await(),
211
211
+
);
210
212
211
213
const symbolCreateInfiniteParams = plugin.referenceSymbol({
212
214
category: 'utility',
+10
-8
packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts
···
30
30
31
31
const fnOptions = 'fnOptions';
32
32
33
33
-
const awaitSdkFn = $(queryFn)
34
34
-
.call(
35
35
-
$.object()
36
36
-
.spread('options')
37
37
-
.spread(fnOptions)
38
38
-
.prop('throwOnError', $.literal(true)),
39
39
-
)
40
40
-
.await();
33
33
+
const awaitSdkFn = $.lazy(() =>
34
34
+
$(queryFn)
35
35
+
.call(
36
36
+
$.object()
37
37
+
.spread('options')
38
38
+
.spread(fnOptions)
39
39
+
.prop('throwOnError', $.literal(true)),
40
40
+
)
41
41
+
.await(),
42
42
+
);
41
43
42
44
const statements: Array<TsDsl<any>> = [];
43
45
if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') {
+11
-9
packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts
···
69
69
70
70
const typeResponse = useTypeResponse({ operation, plugin });
71
71
72
72
-
const awaitSdkFn = $(queryFn)
73
73
-
.call(
74
74
-
$.object()
75
75
-
.spread(optionsParamName)
76
76
-
.spread($('queryKey').attr(0))
77
77
-
.prop('signal', $('signal'))
78
78
-
.prop('throwOnError', $.literal(true)),
79
79
-
)
80
80
-
.await();
72
72
+
const awaitSdkFn = $.lazy(() =>
73
73
+
$(queryFn)
74
74
+
.call(
75
75
+
$.object()
76
76
+
.spread(optionsParamName)
77
77
+
.spread($('queryKey').attr(0))
78
78
+
.prop('signal', $('signal'))
79
79
+
.prop('throwOnError', $.literal(true)),
80
80
+
)
81
81
+
.await(),
82
82
+
);
81
83
82
84
const statements: Array<TsDsl<any>> = [];
83
85
if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') {
+5
-3
packages/openapi-ts/src/plugins/swr/v2/useSwr.ts
···
33
33
}),
34
34
});
35
35
36
36
-
const awaitSdkFn = $(queryFn)
37
37
-
.call($.object().prop('throwOnError', $.literal(true)))
38
38
-
.await();
36
36
+
const awaitSdkFn = $.lazy(() =>
37
37
+
$(queryFn)
38
38
+
.call($.object().prop('throwOnError', $.literal(true)))
39
39
+
.await(),
40
40
+
);
39
41
40
42
const statements: Array<TsDsl<any>> = [];
41
43
if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') {
+11
-3
packages/openapi-ts/src/ts-dsl/index.ts
···
1
1
+
import type ts from 'typescript';
2
2
+
1
3
import { ClassTsDsl } from './decl/class';
2
4
import { DecoratorTsDsl } from './decl/decorator';
3
5
import { EnumTsDsl } from './decl/enum';
···
56
58
import { TypeQueryTsDsl } from './type/query';
57
59
import { TypeTemplateTsDsl } from './type/template';
58
60
import { TypeTupleTsDsl } from './type/tuple';
61
61
+
import { LazyTsDsl } from './utils/lazy';
59
62
60
60
-
const base = {
63
63
+
const tsDsl = {
61
64
/** Creates an array literal expression (e.g. `[1, 2, 3]`). */
62
65
array: (...args: ConstructorParameters<typeof ArrayTsDsl>) =>
63
66
new ArrayTsDsl(...args),
···
151
154
init: (...args: ConstructorParameters<typeof InitTsDsl>) =>
152
155
new InitTsDsl(...args),
153
156
157
157
+
/** Creates a lazy, context-aware node with deferred evaluation. */
158
158
+
lazy: <T extends ts.Node>(
159
159
+
...args: ConstructorParameters<typeof LazyTsDsl<T>>
160
160
+
) => new LazyTsDsl<T>(...args),
161
161
+
154
162
/** Creates a let variable declaration (`let`). */
155
163
let: (...args: ConstructorParameters<typeof VarTsDsl>) =>
156
164
new VarTsDsl(...args).let(),
···
324
332
325
333
export const $ = Object.assign(
326
334
(...args: ConstructorParameters<typeof ExprTsDsl>) => new ExprTsDsl(...args),
327
327
-
base,
335
335
+
tsDsl,
328
336
);
329
337
330
338
export type DollarTsDsl = {
···
342
350
*
343
351
* Returns:
344
352
* - A new `ExprTsDsl` instance when called directly.
345
345
-
* - The `base` factory object for constructing more specific nodes.
353
353
+
* - The `tsDsl` object for constructing more specific nodes.
346
354
*/
347
355
$: typeof $;
348
356
};
+26
packages/openapi-ts/src/ts-dsl/utils/lazy.ts
···
1
1
+
import type { AnalysisContext } from '@hey-api/codegen-core';
2
2
+
import type ts from 'typescript';
3
3
+
4
4
+
import { TsDsl } from '../base';
5
5
+
6
6
+
export type LazyThunk<T extends ts.Node> = () => TsDsl<T>;
7
7
+
8
8
+
export class LazyTsDsl<T extends ts.Node = ts.Node> extends TsDsl<T> {
9
9
+
readonly '~dsl' = 'LazyTsDsl';
10
10
+
11
11
+
private _thunk: LazyThunk<T>;
12
12
+
13
13
+
constructor(thunk: LazyThunk<T>) {
14
14
+
super();
15
15
+
this._thunk = thunk;
16
16
+
}
17
17
+
18
18
+
override analyze(ctx: AnalysisContext): void {
19
19
+
super.analyze(ctx);
20
20
+
ctx.analyze(this._thunk());
21
21
+
}
22
22
+
23
23
+
override toAst() {
24
24
+
return this._thunk().toAst();
25
25
+
}
26
26
+
}