@typespec/http-client-js 0.4.0-dev.1 → 0.4.0-dev.3
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 +0 -1
- package/dist/src/components/client-context/client-context-factory.js +1 -1
- package/dist/src/components/client-context/client-context-factory.js.map +1 -1
- package/dist/src/components/client-operation.d.ts +4 -1
- package/dist/src/components/client-operation.d.ts.map +1 -1
- package/dist/src/components/client-operation.js +68 -38
- package/dist/src/components/client-operation.js.map +1 -1
- package/dist/src/components/client.d.ts.map +1 -1
- package/dist/src/components/client.js +7 -4
- package/dist/src/components/client.js.map +1 -1
- package/dist/src/components/http-request-options.d.ts +5 -5
- package/dist/src/components/http-request-options.d.ts.map +1 -1
- package/dist/src/components/http-request-options.js +12 -12
- package/dist/src/components/http-request-options.js.map +1 -1
- package/dist/src/components/http-request-parameters-expression.d.ts +2 -1
- package/dist/src/components/http-request-parameters-expression.d.ts.map +1 -1
- package/dist/src/components/http-request-parameters-expression.js +125 -18
- package/dist/src/components/http-request-parameters-expression.js.map +1 -1
- package/dist/src/components/http-request.d.ts +3 -3
- package/dist/src/components/http-request.d.ts.map +1 -1
- package/dist/src/components/http-request.js +35 -30
- package/dist/src/components/http-request.js.map +1 -1
- package/dist/src/components/http-response.d.ts +3 -3
- package/dist/src/components/http-response.d.ts.map +1 -1
- package/dist/src/components/http-response.js +11 -6
- package/dist/src/components/http-response.js.map +1 -1
- package/dist/src/components/operation-handlers/index.d.ts +3 -0
- package/dist/src/components/operation-handlers/index.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/index.js +3 -0
- package/dist/src/components/operation-handlers/index.js.map +1 -0
- package/dist/src/components/operation-handlers/operation-pipeline.d.ts +15 -0
- package/dist/src/components/operation-handlers/operation-pipeline.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/operation-pipeline.js +28 -0
- package/dist/src/components/operation-handlers/operation-pipeline.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-item.d.ts +3 -0
- package/dist/src/components/operation-handlers/paging/page-item.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-item.js +17 -0
- package/dist/src/components/operation-handlers/paging/page-item.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-response.d.ts +10 -0
- package/dist/src/components/operation-handlers/paging/page-response.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-response.js +50 -0
- package/dist/src/components/operation-handlers/paging/page-response.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-settings.d.ts +11 -0
- package/dist/src/components/operation-handlers/paging/page-settings.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-settings.js +52 -0
- package/dist/src/components/operation-handlers/paging/page-settings.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.d.ts +3 -0
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.js +170 -0
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/request-send.d.ts +12 -0
- package/dist/src/components/operation-handlers/paging/request-send.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/request-send.js +78 -0
- package/dist/src/components/operation-handlers/paging/request-send.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.d.ts +11 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.js +51 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/util.d.ts +17 -0
- package/dist/src/components/operation-handlers/paging/util.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/util.js +46 -0
- package/dist/src/components/operation-handlers/paging/util.js.map +1 -0
- package/dist/src/components/operation-handlers/types.d.ts +16 -0
- package/dist/src/components/operation-handlers/types.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/types.js +1 -0
- package/dist/src/components/operation-handlers/types.js.map +1 -0
- package/dist/src/components/operation-options.d.ts +2 -0
- package/dist/src/components/operation-options.d.ts.map +1 -1
- package/dist/src/components/operation-options.js +2 -1
- package/dist/src/components/operation-options.js.map +1 -1
- package/dist/src/components/operation-parameters.d.ts +1 -1
- package/dist/src/components/operation-parameters.d.ts.map +1 -1
- package/dist/src/components/operation-parameters.js +7 -5
- package/dist/src/components/operation-parameters.js.map +1 -1
- package/dist/src/components/output.d.ts.map +1 -1
- package/dist/src/components/output.js +4 -0
- package/dist/src/components/output.js.map +1 -1
- package/dist/src/components/static-helpers/bytes-encoding.js +14 -16
- package/dist/src/components/static-helpers/bytes-encoding.js.map +1 -1
- package/dist/src/components/static-helpers/multipart-helpers.js +12 -10
- package/dist/src/components/static-helpers/multipart-helpers.js.map +1 -1
- package/dist/src/components/static-helpers/paging-helper.d.ts +5 -0
- package/dist/src/components/static-helpers/paging-helper.d.ts.map +1 -0
- package/dist/src/components/static-helpers/paging-helper.js +197 -0
- package/dist/src/components/static-helpers/paging-helper.js.map +1 -0
- package/dist/src/components/static-helpers/rest-error.d.ts.map +1 -1
- package/dist/src/components/static-helpers/rest-error.js +15 -10
- package/dist/src/components/static-helpers/rest-error.js.map +1 -1
- package/dist/src/components/testing/client-options.d.ts +1 -1
- package/dist/src/components/testing/client-options.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-array-transform.d.ts +1 -1
- package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-array-transform.js +6 -7
- package/dist/src/components/transforms/json/json-array-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-property-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-property-transform.js +15 -2
- package/dist/src/components/transforms/json/json-model-property-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-transform.js +8 -8
- package/dist/src/components/transforms/json/json-model-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-record-transform.d.ts +1 -1
- package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-record-transform.js +6 -7
- package/dist/src/components/transforms/json/json-record-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-transform-discriminator.js +6 -7
- package/dist/src/components/transforms/json/json-transform-discriminator.js.map +1 -1
- package/dist/src/components/transforms/json/union-transform.js +6 -7
- package/dist/src/components/transforms/json/union-transform.js.map +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.js +2 -3
- package/dist/src/components/transforms/operation-transform-declaration.js.map +1 -1
- package/dist/src/components/transforms/operation-transform-expression.d.ts +2 -2
- package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-expression.js +1 -1
- package/dist/src/components/transforms/operation-transform-expression.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +2 -1
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts +17 -2
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +6 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/utils/parameters.d.ts +1 -1
- package/dist/src/utils/parameters.d.ts.map +1 -1
- package/dist/src/utils/parameters.js +13 -12
- package/dist/src/utils/parameters.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/client-context/client-context-factory.tsx +1 -1
- package/src/components/client-operation.tsx +40 -16
- package/src/components/client.tsx +8 -10
- package/src/components/http-request-options.tsx +17 -13
- package/src/components/http-request-parameters-expression.tsx +142 -18
- package/src/components/http-request.tsx +22 -20
- package/src/components/http-response.tsx +8 -9
- package/src/components/operation-handlers/index.tsx +2 -0
- package/src/components/operation-handlers/operation-pipeline.tsx +33 -0
- package/src/components/operation-handlers/paging/page-item.tsx +13 -0
- package/src/components/operation-handlers/paging/page-response.tsx +55 -0
- package/src/components/operation-handlers/paging/page-settings.tsx +53 -0
- package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +192 -0
- package/src/components/operation-handlers/paging/request-send.tsx +70 -0
- package/src/components/operation-handlers/paging/response-deserialize.tsx +54 -0
- package/src/components/operation-handlers/paging/util.ts +70 -0
- package/src/components/operation-handlers/types.tsx +18 -0
- package/src/components/operation-options.tsx +6 -3
- package/src/components/operation-parameters.tsx +9 -8
- package/src/components/output.tsx +2 -1
- package/src/components/static-helpers/bytes-encoding.tsx +5 -5
- package/src/components/static-helpers/multipart-helpers.tsx +7 -7
- package/src/components/static-helpers/paging-helper.tsx +195 -0
- package/src/components/static-helpers/rest-error.tsx +6 -3
- package/src/components/transforms/json/json-array-transform.tsx +3 -3
- package/src/components/transforms/json/json-model-property-transform.tsx +13 -1
- package/src/components/transforms/json/json-model-transform.tsx +3 -3
- package/src/components/transforms/json/json-record-transform.tsx +3 -3
- package/src/components/transforms/json/json-transform-discriminator.tsx +3 -3
- package/src/components/transforms/json/union-transform.tsx +3 -3
- package/src/components/transforms/operation-transform-declaration.tsx +2 -1
- package/src/components/transforms/operation-transform-expression.tsx +3 -3
- package/src/emitter.tsx +2 -0
- package/src/lib.ts +6 -0
- package/src/utils/parameters.tsx +23 -25
- package/test/e2e/http/payload/pageable/main.test.ts +78 -22
- package/test/scenarios/encoding/header_bytes.md +1 -1
- package/test/scenarios/encoding/header_date.md +1 -1
- package/test/scenarios/encoding/query_date.md +1 -1
- package/test/scenarios/http-operations/paging.md +244 -0
- package/test/scenarios/http-operations/query-parameter.md +1 -1
- package/test/scenarios/operation-parameters/body_root_anonymous.md +1 -1
- package/test/scenarios/operation-parameters/with_body_property.md +1 -1
- package/test/scenarios/operation-parameters/with_body_root.md +1 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
|
|
4
|
+
export function getPagedAsyncIterableIteratorRefkey() {
|
|
5
|
+
return ay.refkey("PagedAsyncIterableIterator", "interface");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getBuildPagedAsyncIteratorRefkey() {
|
|
9
|
+
return ay.refkey("buildPagedAsyncIterator", "function");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getPagedResultRefkey() {
|
|
13
|
+
return ay.refkey("PagedResult", "interface");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getBuildPagedAsyncIteratorOptionsRefkey() {
|
|
17
|
+
return ay.refkey("BuildPagedAsyncIteratorOptions", "interface");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function PagedAsyncIterableIteratorInterfaceDeclaration() {
|
|
21
|
+
return (
|
|
22
|
+
<ay.Declaration
|
|
23
|
+
name="PagedAsyncIterableIterator"
|
|
24
|
+
refkey={getPagedAsyncIterableIteratorRefkey()}
|
|
25
|
+
>
|
|
26
|
+
{ay.code`
|
|
27
|
+
/**
|
|
28
|
+
* An interface that allows async iterable iteration both to completion and by page.
|
|
29
|
+
*/
|
|
30
|
+
export interface PagedAsyncIterableIterator<
|
|
31
|
+
TElement,
|
|
32
|
+
TPageResponse,
|
|
33
|
+
TPageSettings,
|
|
34
|
+
> {
|
|
35
|
+
/**
|
|
36
|
+
* The next method, part of the iteration protocol
|
|
37
|
+
*/
|
|
38
|
+
next(): Promise<IteratorResult<TElement>>;
|
|
39
|
+
/**
|
|
40
|
+
* The connection to the async iterator, part of the iteration protocol
|
|
41
|
+
*/
|
|
42
|
+
[Symbol.asyncIterator](): PagedAsyncIterableIterator<
|
|
43
|
+
TElement,
|
|
44
|
+
TPageResponse,
|
|
45
|
+
TPageSettings
|
|
46
|
+
>;
|
|
47
|
+
/**
|
|
48
|
+
* Return an AsyncIterableIterator that works a page at a time
|
|
49
|
+
*/
|
|
50
|
+
byPage: (
|
|
51
|
+
settings?: TPageSettings,
|
|
52
|
+
) => AsyncIterableIterator<TPageResponse>;
|
|
53
|
+
} `}
|
|
54
|
+
</ay.Declaration>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function PagedResultInterfaceDeclaration() {
|
|
59
|
+
return (
|
|
60
|
+
<ay.Declaration name="PagedResult" refkey={getPagedResultRefkey()}>
|
|
61
|
+
{ay.code`
|
|
62
|
+
/**
|
|
63
|
+
* An interface that describes how to communicate with the service.
|
|
64
|
+
*/
|
|
65
|
+
interface PagedResult<
|
|
66
|
+
TElement,
|
|
67
|
+
TPageResponse,
|
|
68
|
+
TPageSettings,
|
|
69
|
+
> {
|
|
70
|
+
/**
|
|
71
|
+
* Extract the paged elements from the response. Only support array of elements.
|
|
72
|
+
* @param response paged response
|
|
73
|
+
* @returns TElement[]
|
|
74
|
+
*/
|
|
75
|
+
getElements: (response: TPageResponse) => TElement[];
|
|
76
|
+
/**
|
|
77
|
+
* A method that returns a page of results.
|
|
78
|
+
*/
|
|
79
|
+
getPage: (
|
|
80
|
+
nextLinkOrContinuationToken?: string,
|
|
81
|
+
settings?: TPageSettings,
|
|
82
|
+
) => Promise<{ pagedResponse: TPageResponse; nextToken?: string } | undefined>;
|
|
83
|
+
/**
|
|
84
|
+
* a function to implement the \`byPage\` method on the paged async iterator.
|
|
85
|
+
*/
|
|
86
|
+
byPage: (
|
|
87
|
+
settings?: TPageSettings,
|
|
88
|
+
) => AsyncIterableIterator<TPageResponse>;
|
|
89
|
+
}`}
|
|
90
|
+
</ay.Declaration>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function BuildPagedAsyncIteratorOptionsInterfaceDeclaration() {
|
|
95
|
+
return (
|
|
96
|
+
<ay.Declaration
|
|
97
|
+
name="BuildPagedAsyncIteratorOptions"
|
|
98
|
+
refkey={getBuildPagedAsyncIteratorOptionsRefkey()}
|
|
99
|
+
>
|
|
100
|
+
{ay.code`
|
|
101
|
+
/**
|
|
102
|
+
* Options for the paging helper
|
|
103
|
+
*/
|
|
104
|
+
export interface BuildPagedAsyncIteratorOptions<
|
|
105
|
+
TElement,
|
|
106
|
+
TPageResponse,
|
|
107
|
+
TPageSettings,
|
|
108
|
+
> {
|
|
109
|
+
getElements: (response: TPageResponse) => TElement[];
|
|
110
|
+
getPagedResponse: (nextToken?: string, settings?: TPageSettings) => Promise<{ pagedResponse: TPageResponse; nextToken?: string } | undefined>;
|
|
111
|
+
}`}
|
|
112
|
+
</ay.Declaration>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function BuildPagedAsyncIteratorInterfaceDeclaration() {
|
|
117
|
+
return (
|
|
118
|
+
<ay.Declaration name="buildPagedAsyncIterator" refkey={getBuildPagedAsyncIteratorRefkey()}>
|
|
119
|
+
{ay.code`
|
|
120
|
+
/**
|
|
121
|
+
* Helper to paginate results in a generic way and return a PagedAsyncIterableIterator
|
|
122
|
+
*/
|
|
123
|
+
export function buildPagedAsyncIterator<
|
|
124
|
+
TElement,
|
|
125
|
+
TPageResponse,
|
|
126
|
+
TPageSettings
|
|
127
|
+
>(
|
|
128
|
+
options: BuildPagedAsyncIteratorOptions<TElement, TPageResponse, TPageSettings>,
|
|
129
|
+
): PagedAsyncIterableIterator<TElement, TPageResponse, TPageSettings> {
|
|
130
|
+
const pagedResult: ${getPagedResultRefkey()}<TElement, TPageResponse, TPageSettings> = {
|
|
131
|
+
getElements: options.getElements,
|
|
132
|
+
getPage: options.getPagedResponse,
|
|
133
|
+
byPage: (setting?: TPageSettings) => {
|
|
134
|
+
return getPageAsyncIterator(pagedResult, { setting });
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
const iter = getItemAsyncIterator<TElement, TPageResponse, TPageSettings>(pagedResult);
|
|
138
|
+
return {
|
|
139
|
+
next() {
|
|
140
|
+
return iter.next();
|
|
141
|
+
},
|
|
142
|
+
[Symbol.asyncIterator]() {
|
|
143
|
+
return this;
|
|
144
|
+
},
|
|
145
|
+
byPage: pagedResult.byPage,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function* getItemAsyncIterator<TElement, TPage, TPageSettings>(
|
|
150
|
+
pagedResult: ${getPagedResultRefkey()}<TElement, TPage, TPageSettings>,
|
|
151
|
+
): AsyncIterableIterator<TElement> {
|
|
152
|
+
const pages = getPageAsyncIterator(pagedResult);
|
|
153
|
+
for await (const page of pages) {
|
|
154
|
+
const results = pagedResult.getElements(page);
|
|
155
|
+
yield* results;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function* getPageAsyncIterator<TElement, TPageResponse, TPageSettings>(
|
|
160
|
+
pagedResult: ${getPagedResultRefkey()}<TElement, TPageResponse, TPageSettings>,
|
|
161
|
+
options: {
|
|
162
|
+
setting?: TPageSettings;
|
|
163
|
+
} = {},
|
|
164
|
+
): AsyncIterableIterator<TPageResponse> {
|
|
165
|
+
let response = await pagedResult.getPage(undefined, options.setting);
|
|
166
|
+
let results = response?.pagedResponse;
|
|
167
|
+
let nextToken = response?.nextToken;
|
|
168
|
+
if (!results) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
yield results;
|
|
172
|
+
while (nextToken) {
|
|
173
|
+
response = await pagedResult.getPage(nextToken, options.setting);
|
|
174
|
+
if (!response) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
results = response.pagedResponse;
|
|
178
|
+
nextToken = response.nextToken;
|
|
179
|
+
yield results;
|
|
180
|
+
}
|
|
181
|
+
}`}
|
|
182
|
+
</ay.Declaration>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function PagingHelpers() {
|
|
187
|
+
return (
|
|
188
|
+
<ts.SourceFile path="pagingHelpers.ts">
|
|
189
|
+
<PagedAsyncIterableIteratorInterfaceDeclaration />
|
|
190
|
+
<PagedResultInterfaceDeclaration />
|
|
191
|
+
<BuildPagedAsyncIteratorOptionsInterfaceDeclaration />
|
|
192
|
+
<BuildPagedAsyncIteratorInterfaceDeclaration />
|
|
193
|
+
</ts.SourceFile>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
@@ -47,7 +47,10 @@ export function RestError() {
|
|
|
47
47
|
<ay.List hardline>
|
|
48
48
|
<ts.ClassMethod
|
|
49
49
|
name="constructor"
|
|
50
|
-
parameters={
|
|
50
|
+
parameters={[
|
|
51
|
+
{ name: "message", type: "string" },
|
|
52
|
+
{ name: "response", type: httpRuntimeTemplateLib.HttpResponse },
|
|
53
|
+
]}
|
|
51
54
|
returnType={null}
|
|
52
55
|
refkey={constructorRefkey}
|
|
53
56
|
>
|
|
@@ -68,7 +71,7 @@ export function RestError() {
|
|
|
68
71
|
<ts.ClassMethod
|
|
69
72
|
static
|
|
70
73
|
name="fromHttpResponse"
|
|
71
|
-
parameters={{ response: httpRuntimeTemplateLib.HttpResponse }}
|
|
74
|
+
parameters={[{ name: "response", type: httpRuntimeTemplateLib.HttpResponse }]}
|
|
72
75
|
returnType={getRestErrorRefkey()}
|
|
73
76
|
refkey={fromHttpResponseRefkey}
|
|
74
77
|
>
|
|
@@ -85,7 +88,7 @@ export function RestError() {
|
|
|
85
88
|
<ts.FunctionDeclaration
|
|
86
89
|
export
|
|
87
90
|
name="createRestError"
|
|
88
|
-
parameters={{ response: httpRuntimeTemplateLib.HttpResponse }}
|
|
91
|
+
parameters={[{ name: "response", type: httpRuntimeTemplateLib.HttpResponse }]}
|
|
89
92
|
returnType={getRestErrorRefkey()}
|
|
90
93
|
refkey={getCreateRestErrorRefkey()}
|
|
91
94
|
>
|
|
@@ -66,9 +66,9 @@ export function JsonArrayTransformDeclaration(props: JsonArrayTransformDeclarati
|
|
|
66
66
|
const inputType = props.target === "transport" ? <>{itemType} | null</> : "any";
|
|
67
67
|
const inputRef = ay.refkey();
|
|
68
68
|
|
|
69
|
-
const parameters:
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
const parameters: ts.ParameterDescriptor[] = [
|
|
70
|
+
{ name: "items_", type: inputType, refkey: inputRef, optional: true },
|
|
71
|
+
];
|
|
72
72
|
|
|
73
73
|
const declarationRefkey = getJsonArrayTransformRefkey(props.type, props.target);
|
|
74
74
|
return (
|
|
@@ -35,5 +35,17 @@ export function JsonModelPropertyTransform(props: JsonModelPropertyTransformProp
|
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
if (props.target === "transport") {
|
|
39
|
+
return (
|
|
40
|
+
<ay.NamePolicyContext.Provider value={{ getName: (n) => n }}>
|
|
41
|
+
<ts.ObjectProperty name={targetName} value={propertyValue} />
|
|
42
|
+
</ay.NamePolicyContext.Provider>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<>
|
|
48
|
+
<ts.ObjectProperty name={JSON.stringify(targetName)} value={propertyValue} />
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
39
51
|
}
|
|
@@ -79,10 +79,10 @@ export function JsonModelTransformDeclaration(
|
|
|
79
79
|
const inputType = props.target === "transport" ? <>{ay.refkey(props.type)} | null</> : "any";
|
|
80
80
|
const inputRef = ay.refkey();
|
|
81
81
|
|
|
82
|
-
const parameters:
|
|
82
|
+
const parameters: ts.ParameterDescriptor[] = [
|
|
83
83
|
// Make the input optional to make the transform more robust and check against null and undefined
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
{ name: "input_", type: inputType, refkey: inputRef, optional: true },
|
|
85
|
+
];
|
|
86
86
|
|
|
87
87
|
const spread = $.model.getSpreadType(props.type);
|
|
88
88
|
const hasAdditionalProperties = spread && $.model.is(spread) && $.record.is(spread);
|
|
@@ -67,9 +67,9 @@ export function JsonRecordTransformDeclaration(props: JsonRecordTransformDeclara
|
|
|
67
67
|
const inputType = props.target === "transport" ? <>{itemType} | null</> : "any";
|
|
68
68
|
const inputRef = ay.refkey();
|
|
69
69
|
|
|
70
|
-
const parameters:
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const parameters: ts.ParameterDescriptor[] = [
|
|
71
|
+
{ name: "items_", type: inputType, refkey: inputRef, optional: true },
|
|
72
|
+
];
|
|
73
73
|
|
|
74
74
|
const declarationRefkey = getJsonRecordTransformRefkey(props.type, props.target);
|
|
75
75
|
return (
|
|
@@ -78,9 +78,9 @@ export function JsonTransformDiscriminatorDeclaration(
|
|
|
78
78
|
const inputType = props.target === "transport" ? typeRef : "any";
|
|
79
79
|
const inputRef = ay.refkey();
|
|
80
80
|
|
|
81
|
-
const parameters:
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const parameters: ts.ParameterDescriptor[] = [
|
|
82
|
+
{ name: "input_", type: inputType, refkey: inputRef, optional: true },
|
|
83
|
+
];
|
|
84
84
|
|
|
85
85
|
return (
|
|
86
86
|
<ts.FunctionDeclaration
|
|
@@ -58,9 +58,9 @@ export function JsonUnionTransformDeclaration(props: JsonUnionTransformDeclarati
|
|
|
58
58
|
const inputType = props.target === "transport" ? <>{typeRef} | null</> : "any";
|
|
59
59
|
const inputRef = ay.refkey();
|
|
60
60
|
|
|
61
|
-
const parameters:
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const parameters: ts.ParameterDescriptor[] = [
|
|
62
|
+
{ name: "input_", type: inputType, refkey: inputRef, optional: true },
|
|
63
|
+
];
|
|
64
64
|
|
|
65
65
|
const declarationRefkey = getJsonUnionTransformRefkey(props.type, props.target);
|
|
66
66
|
return (
|
|
@@ -35,6 +35,7 @@ export interface SingleBodyTransformDeclarationProps {
|
|
|
35
35
|
export function SingleBodyTransformDeclaration(props: SingleBodyTransformDeclarationProps) {
|
|
36
36
|
const inputRef = ay.refkey(props.payload, "property");
|
|
37
37
|
const payloadParameter: ts.ParameterDescriptor = {
|
|
38
|
+
name: "payload",
|
|
38
39
|
type: <ef.TypeExpression type={props.payload.type} />,
|
|
39
40
|
refkey: inputRef,
|
|
40
41
|
};
|
|
@@ -43,7 +44,7 @@ export function SingleBodyTransformDeclaration(props: SingleBodyTransformDeclara
|
|
|
43
44
|
<ts.FunctionDeclaration
|
|
44
45
|
export
|
|
45
46
|
name={props.name}
|
|
46
|
-
parameters={
|
|
47
|
+
parameters={[payloadParameter]}
|
|
47
48
|
refkey={props.refkey}
|
|
48
49
|
>
|
|
49
50
|
return <JsonTransform itemRef={inputRef} target="transport" type={props.payload.type} />
|
|
@@ -2,7 +2,7 @@ import * as ts from "@alloy-js/typescript";
|
|
|
2
2
|
import { Type } from "@typespec/compiler";
|
|
3
3
|
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
4
|
import { HasName, TransformNamePolicyContext } from "@typespec/emitter-framework";
|
|
5
|
-
import {
|
|
5
|
+
import { HttpOperation } from "@typespec/http";
|
|
6
6
|
import { reportDiagnostic } from "../../lib.js";
|
|
7
7
|
import { ContentTypeEncodingProvider } from "./content-type-encoding-provider.jsx";
|
|
8
8
|
import { JsonTransform } from "./json/json-transform.jsx";
|
|
@@ -10,11 +10,11 @@ import { MultipartTransform } from "./multipart/multipart-transform.jsx";
|
|
|
10
10
|
import { defaultTransportNameGetter } from "./transform-name-policy.js";
|
|
11
11
|
|
|
12
12
|
export interface OperationTransformToTransportExpression {
|
|
13
|
-
|
|
13
|
+
httpOperation: HttpOperation;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function OperationTransformExpression(props: OperationTransformToTransportExpression) {
|
|
17
|
-
const body = props.
|
|
17
|
+
const body = props.httpOperation.parameters.body;
|
|
18
18
|
|
|
19
19
|
if (!body) {
|
|
20
20
|
return;
|
package/src/emitter.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { Output } from "./components/output.jsx";
|
|
|
9
9
|
import { ModelSerializers } from "./components/serializers.js";
|
|
10
10
|
import { Interfaces } from "./components/static-helpers/interfaces.jsx";
|
|
11
11
|
import { MultipartHelpers } from "./components/static-helpers/multipart-helpers.jsx";
|
|
12
|
+
import { PagingHelpers } from "./components/static-helpers/paging-helper.jsx";
|
|
12
13
|
import { RestError } from "./components/static-helpers/rest-error.jsx";
|
|
13
14
|
import { JsClientEmitterOptions } from "./lib.js";
|
|
14
15
|
|
|
@@ -41,6 +42,7 @@ export async function $onEmit(context: EmitContext<JsClientEmitterOptions>) {
|
|
|
41
42
|
<OperationsDirectory />
|
|
42
43
|
</ay.SourceDirectory>
|
|
43
44
|
<ay.SourceDirectory path="helpers">
|
|
45
|
+
<PagingHelpers />
|
|
44
46
|
<Interfaces />
|
|
45
47
|
<MultipartHelpers />
|
|
46
48
|
<ts.SourceFile path="error.ts">
|
package/src/lib.ts
CHANGED
|
@@ -107,6 +107,12 @@ export const $lib = createTypeSpecLibrary({
|
|
|
107
107
|
default: "Unexpected non-scalar type when trying to extract Scalar data",
|
|
108
108
|
},
|
|
109
109
|
},
|
|
110
|
+
"client-not-found": {
|
|
111
|
+
severity: "error",
|
|
112
|
+
messages: {
|
|
113
|
+
default: "Client for operation not found",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
110
116
|
},
|
|
111
117
|
});
|
|
112
118
|
|
package/src/utils/parameters.tsx
CHANGED
|
@@ -8,32 +8,32 @@ import * as cl from "@typespec/http-client";
|
|
|
8
8
|
import { getClientContextOptionsRef } from "../components/client-context/client-context-options.jsx";
|
|
9
9
|
import { httpRuntimeTemplateLib } from "../components/external-packages/ts-http-runtime.js";
|
|
10
10
|
|
|
11
|
-
export function buildClientParameters(client: cl.Client):
|
|
11
|
+
export function buildClientParameters(client: cl.Client): ts.ParameterDescriptor[] {
|
|
12
12
|
const clientConstructor = $.client.getConstructor(client);
|
|
13
13
|
const parameters = $.operation.getClientSignature(client, clientConstructor);
|
|
14
|
-
const params = parameters.
|
|
15
|
-
(
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
18
|
-
return
|
|
14
|
+
const params = parameters.flatMap(
|
|
15
|
+
(param) => {
|
|
16
|
+
const descriptor = buildClientParameterDescriptor(param);
|
|
17
|
+
if (!descriptor) {
|
|
18
|
+
return [];
|
|
19
19
|
}
|
|
20
|
-
const [name, descriptor] = paramsDescriptor;
|
|
21
20
|
|
|
22
21
|
if (!descriptor.optional) {
|
|
23
|
-
|
|
22
|
+
return [descriptor];
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
return
|
|
25
|
+
return [];
|
|
27
26
|
},
|
|
28
27
|
{} as Record<string, ts.ParameterDescriptor>,
|
|
29
28
|
);
|
|
30
29
|
|
|
31
|
-
if (!params
|
|
32
|
-
params
|
|
30
|
+
if (!params.some((p) => p.name === "options")) {
|
|
31
|
+
params.push({
|
|
32
|
+
name: "options",
|
|
33
33
|
refkey: ay.refkey(),
|
|
34
34
|
optional: true,
|
|
35
35
|
type: getClientContextOptionsRef(client),
|
|
36
|
-
};
|
|
36
|
+
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
return params;
|
|
@@ -41,7 +41,7 @@ export function buildClientParameters(client: cl.Client): Record<string, ts.Para
|
|
|
41
41
|
|
|
42
42
|
function buildClientParameterDescriptor(
|
|
43
43
|
modelProperty: ModelProperty,
|
|
44
|
-
):
|
|
44
|
+
): ts.ParameterDescriptor | undefined {
|
|
45
45
|
const authSchemes = $.modelProperty.getCredentialAuth(modelProperty);
|
|
46
46
|
|
|
47
47
|
if (authSchemes) {
|
|
@@ -52,18 +52,16 @@ function buildClientParameterDescriptor(
|
|
|
52
52
|
const credentialType = Array.from(
|
|
53
53
|
new Set(authSchemes.filter((s) => s.type !== "noAuth").map((s) => getCredentialType(s))),
|
|
54
54
|
);
|
|
55
|
-
return
|
|
56
|
-
"credential",
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
];
|
|
55
|
+
return {
|
|
56
|
+
name: "credential",
|
|
57
|
+
refkey: ay.refkey(modelProperty),
|
|
58
|
+
optional: modelProperty.optional,
|
|
59
|
+
type: ay.mapJoin(
|
|
60
|
+
() => credentialType,
|
|
61
|
+
(t) => t,
|
|
62
|
+
{ joiner: " | " },
|
|
63
|
+
),
|
|
64
|
+
};
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
return buildParameterDescriptor(modelProperty);
|
|
@@ -1,24 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
Pet,
|
|
4
|
+
ServerDrivenPaginationClient,
|
|
5
|
+
} from "../../../generated/payload/pageable/src/index.js";
|
|
4
6
|
|
|
5
|
-
describe
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
describe("Payload.Pageable", () => {
|
|
8
|
+
describe("list", () => {
|
|
9
|
+
const client = new ServerDrivenPaginationClient({
|
|
10
|
+
allowInsecureConnection: true,
|
|
11
|
+
});
|
|
12
|
+
const pets = [
|
|
13
|
+
{ id: "1", name: "dog" },
|
|
14
|
+
{ id: "2", name: "cat" },
|
|
15
|
+
{ id: "3", name: "bird" },
|
|
16
|
+
{ id: "4", name: "fish" },
|
|
17
|
+
];
|
|
18
|
+
it("Payload Pageable ServerDriven Pagination link", async () => {
|
|
19
|
+
const iter = client.link();
|
|
20
|
+
const items: Array<Pet> = [];
|
|
21
|
+
for await (const user of iter) {
|
|
22
|
+
items.push(user);
|
|
23
|
+
}
|
|
24
|
+
expect(items.length).toEqual(4);
|
|
25
|
+
expect(items).toStrictEqual(pets);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("continuation token for requestHeaderResponseBody", async () => {
|
|
29
|
+
const iter = client.continuationTokenClient.requestHeaderResponseBody({
|
|
30
|
+
bar: "bar",
|
|
31
|
+
foo: "foo",
|
|
32
|
+
});
|
|
33
|
+
const items: Array<Pet> = [];
|
|
34
|
+
for await (const user of iter) {
|
|
35
|
+
items.push(user);
|
|
36
|
+
}
|
|
37
|
+
expect(items.length).toEqual(4);
|
|
38
|
+
expect(items).toStrictEqual(pets);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("continuation token for requestQueryResponseBody", async () => {
|
|
42
|
+
const iter = client.continuationTokenClient.requestQueryResponseBody({
|
|
43
|
+
bar: "bar",
|
|
44
|
+
foo: "foo",
|
|
45
|
+
});
|
|
46
|
+
const items: Array<Pet> = [];
|
|
47
|
+
for await (const user of iter) {
|
|
48
|
+
items.push(user);
|
|
49
|
+
}
|
|
50
|
+
expect(items.length).toEqual(4);
|
|
51
|
+
expect(items).toStrictEqual(pets);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("continuation token for requestHeaderResponseHeader", async () => {
|
|
55
|
+
const iter = client.continuationTokenClient.requestHeaderResponseHeader({
|
|
56
|
+
bar: "bar",
|
|
57
|
+
foo: "foo",
|
|
58
|
+
});
|
|
59
|
+
const items: Array<Pet> = [];
|
|
60
|
+
for await (const user of iter) {
|
|
61
|
+
items.push(user);
|
|
62
|
+
}
|
|
63
|
+
expect(items.length).toEqual(4);
|
|
64
|
+
expect(items).toStrictEqual(pets);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("continuation token for requestQueryResponseHeader", async () => {
|
|
68
|
+
const iter = client.continuationTokenClient.requestQueryResponseHeader({
|
|
69
|
+
bar: "bar",
|
|
70
|
+
foo: "foo",
|
|
71
|
+
});
|
|
72
|
+
const items: Array<Pet> = [];
|
|
73
|
+
for await (const user of iter) {
|
|
74
|
+
items.push(user);
|
|
75
|
+
}
|
|
76
|
+
expect(items.length).toEqual(4);
|
|
77
|
+
expect(items).toStrictEqual(pets);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
24
80
|
});
|
|
@@ -68,7 +68,7 @@ export async function defaultEncoding(
|
|
|
68
68
|
const path = parse("/default").expand({});
|
|
69
69
|
const httpRequestOptions = {
|
|
70
70
|
headers: {
|
|
71
|
-
...(options?.value && { value: dateRfc7231Serializer(options
|
|
71
|
+
...(options?.value && { value: dateRfc7231Serializer(options.value) }),
|
|
72
72
|
},
|
|
73
73
|
};
|
|
74
74
|
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
@@ -66,7 +66,7 @@ export async function defaultEncoding(
|
|
|
66
66
|
options?: DefaultEncodingOptions,
|
|
67
67
|
): Promise<void> {
|
|
68
68
|
const path = parse("/default{?value}").expand({
|
|
69
|
-
...(options?.value && { value: dateRfc3339Serializer(options
|
|
69
|
+
...(options?.value && { value: dateRfc3339Serializer(options.value) }),
|
|
70
70
|
});
|
|
71
71
|
const httpRequestOptions = {
|
|
72
72
|
headers: {},
|