@typespec/http-client-js 0.7.0-dev.1 → 0.7.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/dist/src/components/client-context/client-context-declaration.d.ts +2 -3
- package/dist/src/components/client-context/client-context-declaration.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-declaration.js +2 -2
- package/dist/src/components/client-context/client-context-factory.d.ts +3 -3
- package/dist/src/components/client-context/client-context-factory.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-factory.js +10 -10
- package/dist/src/components/client-context/client-context-options.d.ts +3 -3
- package/dist/src/components/client-context/client-context-options.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-options.js +3 -3
- package/dist/src/components/client-context/client-context.d.ts +3 -3
- package/dist/src/components/client-context/client-context.d.ts.map +1 -1
- package/dist/src/components/client-context/parametrized-endpoint.d.ts +3 -3
- package/dist/src/components/client-context/parametrized-endpoint.d.ts.map +1 -1
- package/dist/src/components/client-context/parametrized-endpoint.js +5 -5
- package/dist/src/components/client-directory.d.ts +4 -4
- package/dist/src/components/client-directory.d.ts.map +1 -1
- package/dist/src/components/client-directory.js +5 -5
- package/dist/src/components/client-operation.d.ts +4 -4
- package/dist/src/components/client-operation.d.ts.map +1 -1
- package/dist/src/components/client-operation.js +6 -6
- package/dist/src/components/client.d.ts +5 -5
- package/dist/src/components/client.d.ts.map +1 -1
- package/dist/src/components/client.js +14 -14
- package/dist/src/components/encoding-provider.d.ts +1 -1
- package/dist/src/components/encoding-provider.d.ts.map +1 -1
- package/dist/src/components/http-request-parameters-expression.d.ts +4 -4
- package/dist/src/components/http-request-parameters-expression.d.ts.map +1 -1
- package/dist/src/components/http-request-parameters-expression.js +10 -10
- package/dist/src/components/models.d.ts +1 -2
- package/dist/src/components/models.d.ts.map +1 -1
- package/dist/src/components/models.js +2 -3
- package/dist/src/components/operation-handlers/operation-pipeline.d.ts +1 -2
- package/dist/src/components/operation-handlers/operation-pipeline.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/operation-pipeline.js +2 -2
- package/dist/src/components/operation-handlers/paging/page-response.d.ts +2 -3
- package/dist/src/components/operation-handlers/paging/page-response.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/paging/page-response.js +3 -3
- package/dist/src/components/operation-handlers/paging/page-settings.d.ts +2 -3
- package/dist/src/components/operation-handlers/paging/page-settings.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/paging/page-settings.js +3 -3
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.js +16 -16
- package/dist/src/components/operation-handlers/paging/request-send.d.ts +2 -3
- package/dist/src/components/operation-handlers/paging/request-send.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/paging/request-send.js +1 -2
- package/dist/src/components/operation-handlers/types.d.ts +1 -1
- package/dist/src/components/operation-handlers/types.d.ts.map +1 -1
- package/dist/src/components/operation-options.d.ts +2 -3
- package/dist/src/components/operation-options.d.ts.map +1 -1
- package/dist/src/components/operation-options.js +3 -3
- package/dist/src/components/operation-parameters.d.ts +2 -2
- package/dist/src/components/operation-parameters.d.ts.map +1 -1
- package/dist/src/components/operation-parameters.js +2 -2
- package/dist/src/components/output.d.ts +3 -3
- package/dist/src/components/output.d.ts.map +1 -1
- package/dist/src/components/static-helpers/bytes-encoding.d.ts +6 -5
- package/dist/src/components/static-helpers/bytes-encoding.d.ts.map +1 -1
- package/dist/src/components/static-helpers/bytes-encoding.js +15 -19
- package/dist/src/components/static-helpers/interfaces.d.ts +3 -4
- package/dist/src/components/static-helpers/interfaces.d.ts.map +1 -1
- package/dist/src/components/static-helpers/interfaces.js +3 -3
- package/dist/src/components/static-helpers/multipart-helpers.d.ts +4 -5
- package/dist/src/components/static-helpers/multipart-helpers.d.ts.map +1 -1
- package/dist/src/components/static-helpers/multipart-helpers.js +8 -10
- package/dist/src/components/static-helpers/paging-helper.d.ts +3 -4
- package/dist/src/components/static-helpers/paging-helper.d.ts.map +1 -1
- package/dist/src/components/static-helpers/paging-helper.js +17 -23
- package/dist/src/components/static-helpers/rest-error.d.ts +3 -4
- package/dist/src/components/static-helpers/rest-error.d.ts.map +1 -1
- package/dist/src/components/static-helpers/rest-error.js +19 -25
- package/dist/src/components/testing/client-options.d.ts +3 -3
- package/dist/src/components/testing/client-options.d.ts.map +1 -1
- package/dist/src/components/testing/client-options.js +2 -2
- package/dist/src/components/transforms/content-type-encoding-provider.d.ts +1 -1
- package/dist/src/components/transforms/content-type-encoding-provider.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-array-transform.d.ts +6 -6
- package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-array-transform.js +5 -5
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts +4 -4
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js +4 -4
- package/dist/src/components/transforms/json/json-model-base-transform.d.ts +4 -4
- package/dist/src/components/transforms/json/json-model-base-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-property-transform.d.ts +3 -3
- 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 +3 -3
- package/dist/src/components/transforms/json/json-model-transform.d.ts +6 -6
- package/dist/src/components/transforms/json/json-model-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-transform.js +8 -8
- package/dist/src/components/transforms/json/json-record-transform.d.ts +6 -6
- package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-record-transform.js +5 -5
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts +5 -5
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-transform-discriminator.js +13 -13
- package/dist/src/components/transforms/json/json-transform.d.ts +6 -5
- package/dist/src/components/transforms/json/json-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-transform.js +2 -2
- package/dist/src/components/transforms/json/union-transform.d.ts +6 -6
- package/dist/src/components/transforms/json/union-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/union-transform.js +6 -6
- package/dist/src/components/transforms/json/utils/transport-namer.d.ts +1 -1
- package/dist/src/components/transforms/json/utils/transport-namer.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/array-part-transform.d.ts +3 -3
- package/dist/src/components/transforms/multipart/array-part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/array-part-transform.js +5 -5
- package/dist/src/components/transforms/multipart/file-part-transform.d.ts +3 -3
- package/dist/src/components/transforms/multipart/file-part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/file-part-transform.js +2 -2
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts +1 -2
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/multipart-transform.js +2 -2
- package/dist/src/components/transforms/multipart/part-transform.d.ts +3 -3
- package/dist/src/components/transforms/multipart/part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts +3 -3
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/simple-part-transform.js +5 -5
- package/dist/src/components/transforms/operation-transform-declaration.d.ts +6 -6
- package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.js +3 -3
- package/dist/src/components/transforms/transform-name-policy.d.ts +1 -1
- package/dist/src/components/transforms/transform-name-policy.d.ts.map +1 -1
- package/dist/src/emitter.js +6 -6
- package/dist/src/utils/multipart.d.ts +1 -1
- package/dist/src/utils/multipart.d.ts.map +1 -1
- package/dist/src/utils/parameters.d.ts +2 -2
- package/dist/src/utils/parameters.d.ts.map +1 -1
- package/dist/src/utils/parameters.js +6 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/client-context/client-context-declaration.tsx +2 -2
- package/src/components/client-context/client-context-factory.tsx +19 -19
- package/src/components/client-context/client-context-options.tsx +5 -5
- package/src/components/client-context/client-context.tsx +2 -2
- package/src/components/client-context/parametrized-endpoint.tsx +8 -8
- package/src/components/client-directory.tsx +10 -10
- package/src/components/client-operation.tsx +11 -11
- package/src/components/client.tsx +21 -21
- package/src/components/encoding-provider.tsx +1 -1
- package/src/components/http-request-parameters-expression.tsx +19 -19
- package/src/components/models.tsx +2 -3
- package/src/components/operation-handlers/operation-pipeline.tsx +2 -2
- package/src/components/operation-handlers/paging/page-response.tsx +4 -4
- package/src/components/operation-handlers/paging/page-settings.tsx +4 -4
- package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +18 -19
- package/src/components/operation-handlers/paging/request-send.tsx +1 -2
- package/src/components/operation-handlers/types.tsx +1 -1
- package/src/components/operation-options.tsx +4 -4
- package/src/components/operation-parameters.tsx +3 -3
- package/src/components/output.tsx +2 -2
- package/src/components/serializers.tsx +1 -1
- package/src/components/static-helpers/bytes-encoding.tsx +17 -16
- package/src/components/static-helpers/interfaces.tsx +3 -3
- package/src/components/static-helpers/multipart-helpers.tsx +7 -7
- package/src/components/static-helpers/paging-helper.tsx +17 -20
- package/src/components/static-helpers/rest-error.tsx +17 -17
- package/src/components/testing/client-options.tsx +3 -3
- package/src/components/transforms/content-type-encoding-provider.tsx +1 -1
- package/src/components/transforms/json/json-array-transform.tsx +8 -8
- package/src/components/transforms/json/json-model-additional-properties-transform.tsx +6 -6
- package/src/components/transforms/json/json-model-base-transform.tsx +3 -3
- package/src/components/transforms/json/json-model-property-transform.tsx +6 -6
- package/src/components/transforms/json/json-model-transform.tsx +12 -14
- package/src/components/transforms/json/json-record-transform.tsx +8 -8
- package/src/components/transforms/json/json-transform-discriminator.tsx +12 -12
- package/src/components/transforms/json/json-transform.tsx +6 -5
- package/src/components/transforms/json/union-transform.tsx +8 -8
- package/src/components/transforms/json/utils/transport-namer.ts +1 -1
- package/src/components/transforms/multipart/array-part-transform.tsx +6 -5
- package/src/components/transforms/multipart/file-part-transform.tsx +5 -5
- package/src/components/transforms/multipart/multipart-transform.tsx +3 -3
- package/src/components/transforms/multipart/part-transform.tsx +2 -2
- package/src/components/transforms/multipart/simple-part-transform.tsx +8 -8
- package/src/components/transforms/operation-transform-declaration.tsx +7 -6
- package/src/components/transforms/operation-transform-expression.tsx +1 -1
- package/src/components/transforms/transform-name-policy.ts +1 -1
- package/src/emitter.tsx +11 -11
- package/src/utils/multipart.ts +1 -1
- package/src/utils/parameters.tsx +9 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-js",
|
|
3
|
-
"version": "0.7.0-dev.
|
|
3
|
+
"version": "0.7.0-dev.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://typespec.io",
|
|
6
6
|
"readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"@typespec/rest": "^0.71.0 || >=0.72.0-dev <0.72.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@alloy-js/core": "^0.
|
|
39
|
-
"@alloy-js/typescript": "^0.
|
|
38
|
+
"@alloy-js/core": "^0.18.0",
|
|
39
|
+
"@alloy-js/typescript": "^0.18.0",
|
|
40
40
|
"@typespec/emitter-framework": "^0.8.0 || >=0.9.0-dev <0.9.0",
|
|
41
41
|
"@typespec/http-client": "^0.7.0 || >=0.8.0-dev <0.8.0",
|
|
42
42
|
"prettier": "~3.5.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@alloy-js/cli": "^0.
|
|
45
|
+
"@alloy-js/cli": "^0.18.0",
|
|
46
46
|
"@alloy-js/rollup-plugin": "^0.1.0",
|
|
47
47
|
"@types/yargs": "~17.0.33",
|
|
48
48
|
"@typespec/http": "^1.1.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import * as cl from "@typespec/http-client";
|
|
4
4
|
import { httpRuntimeTemplateLib } from "../external-packages/ts-http-runtime.js";
|
|
@@ -8,7 +8,7 @@ export interface ClientContextDeclarationProps {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function getClientcontextDeclarationRef(client: cl.Client) {
|
|
11
|
-
return
|
|
11
|
+
return refkey(client, "declaration");
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function ClientContextDeclaration(props: ClientContextDeclarationProps) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Children, For, List, refkey, Refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
|
|
@@ -16,7 +16,7 @@ export interface ClientContextFactoryProps {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function getClientContextFactoryRef(client: cl.Client) {
|
|
19
|
-
return
|
|
19
|
+
return refkey(client, "contextFactory");
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps) {
|
|
@@ -27,9 +27,9 @@ export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps
|
|
|
27
27
|
const factoryFunctionName = namePolicy.getName(`create_${props.client.name}Context`, "function");
|
|
28
28
|
|
|
29
29
|
const clientConstructor = $.client.getConstructor(props.client);
|
|
30
|
-
const parameters = buildClientParameters(props.client,
|
|
30
|
+
const parameters = buildClientParameters(props.client, refkey());
|
|
31
31
|
const urlTemplate = $.client.getUrlTemplate(props.client);
|
|
32
|
-
const endpointRef =
|
|
32
|
+
const endpointRef = refkey();
|
|
33
33
|
const resolvedEndpoint = (
|
|
34
34
|
<ParametrizedEndpoint
|
|
35
35
|
refkey={endpointRef}
|
|
@@ -70,7 +70,7 @@ export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps
|
|
|
70
70
|
|
|
71
71
|
interface ClientFactoryArgumentsProps {
|
|
72
72
|
client: cl.Client;
|
|
73
|
-
endpointRef:
|
|
73
|
+
endpointRef: Refkey;
|
|
74
74
|
credentialsRef?: string;
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -105,10 +105,10 @@ function AuthScheme(props: AuthSchemeProps) {
|
|
|
105
105
|
case "http":
|
|
106
106
|
return (
|
|
107
107
|
<ts.ObjectExpression>
|
|
108
|
-
<
|
|
108
|
+
<List comma>
|
|
109
109
|
<ts.ObjectProperty name="kind" jsValue="http" />
|
|
110
110
|
<ts.ObjectProperty name="scheme" jsValue={props.scheme.scheme.toLowerCase()} />
|
|
111
|
-
</
|
|
111
|
+
</List>
|
|
112
112
|
</ts.ObjectExpression>
|
|
113
113
|
);
|
|
114
114
|
case "apiKey":
|
|
@@ -121,26 +121,26 @@ function AuthScheme(props: AuthSchemeProps) {
|
|
|
121
121
|
|
|
122
122
|
return (
|
|
123
123
|
<ts.ObjectExpression>
|
|
124
|
-
<
|
|
124
|
+
<List comma>
|
|
125
125
|
<ts.ObjectProperty name="kind" jsValue="apiKey" />
|
|
126
126
|
<ts.ObjectProperty name="apiKeyLocation" jsValue={props.scheme.in} />
|
|
127
127
|
<ts.ObjectProperty name="name" jsValue={props.scheme.name} />
|
|
128
|
-
</
|
|
128
|
+
</List>
|
|
129
129
|
</ts.ObjectExpression>
|
|
130
130
|
);
|
|
131
131
|
case "oauth2":
|
|
132
132
|
return (
|
|
133
133
|
<ts.ObjectExpression>
|
|
134
|
-
<
|
|
134
|
+
<List comma>
|
|
135
135
|
<ts.ObjectProperty name="kind" jsValue="oauth2" />
|
|
136
136
|
<ts.ObjectProperty name="flows">
|
|
137
137
|
[
|
|
138
|
-
<
|
|
138
|
+
<For each={props.scheme.flows} comma line>
|
|
139
139
|
{(flow) => <OAuth2Flow flow={flow} />}
|
|
140
|
-
</
|
|
140
|
+
</For>
|
|
141
141
|
]
|
|
142
142
|
</ts.ObjectProperty>
|
|
143
|
-
</
|
|
143
|
+
</List>
|
|
144
144
|
</ts.ObjectExpression>
|
|
145
145
|
);
|
|
146
146
|
default:
|
|
@@ -181,20 +181,20 @@ function AuthSchemeOptions(props: AuthSchemeOptionsProps) {
|
|
|
181
181
|
return (
|
|
182
182
|
<ts.ObjectProperty name="authSchemes">
|
|
183
183
|
[
|
|
184
|
-
<
|
|
184
|
+
<For each={supportedSchemes} comma line>
|
|
185
185
|
{(scheme) => <AuthScheme scheme={scheme} client={props.client} />}
|
|
186
|
-
</
|
|
186
|
+
</For>
|
|
187
187
|
]
|
|
188
188
|
</ts.ObjectProperty>
|
|
189
189
|
);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
interface ClientOptionsExpressionProps {
|
|
193
|
-
children?:
|
|
193
|
+
children?: Children;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
function ClientOptionsExpression(props: ClientOptionsExpressionProps) {
|
|
197
|
-
const options:
|
|
197
|
+
const options: Children = ["...options"];
|
|
198
198
|
|
|
199
199
|
// Conditionally add test options
|
|
200
200
|
// based on the environment variable TYPESPEC_JS_EMITTER_TESTING
|
|
@@ -208,9 +208,9 @@ function ClientOptionsExpression(props: ClientOptionsExpressionProps) {
|
|
|
208
208
|
|
|
209
209
|
return (
|
|
210
210
|
<ts.ObjectExpression>
|
|
211
|
-
<
|
|
211
|
+
<For each={options} joiner="," line>
|
|
212
212
|
{(child) => child}
|
|
213
|
-
</
|
|
213
|
+
</For>
|
|
214
214
|
</ts.ObjectExpression>
|
|
215
215
|
);
|
|
216
216
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Children, For, refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import * as cl from "@typespec/http-client";
|
|
4
4
|
import { httpRuntimeTemplateLib } from "../external-packages/ts-http-runtime.js";
|
|
@@ -8,7 +8,7 @@ export interface ClientContextOptionsDeclarationProps {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function getClientContextOptionsRef(client: cl.Client) {
|
|
11
|
-
return
|
|
11
|
+
return refkey(client, "options");
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function ClientContextOptionsDeclaration(props: ClientContextOptionsDeclarationProps) {
|
|
@@ -17,7 +17,7 @@ export function ClientContextOptionsDeclaration(props: ClientContextOptionsDecla
|
|
|
17
17
|
const name = namePolicy.getName(`${props.client.name}Options`, "interface");
|
|
18
18
|
|
|
19
19
|
// TODO: Here we will calculate and include all the options that the client can accept
|
|
20
|
-
const clientOptions: Map<string,
|
|
20
|
+
const clientOptions: Map<string, Children> = new Map();
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
23
|
<ts.InterfaceDeclaration
|
|
@@ -26,9 +26,9 @@ export function ClientContextOptionsDeclaration(props: ClientContextOptionsDecla
|
|
|
26
26
|
refkey={ref}
|
|
27
27
|
extends={<ts.Reference refkey={httpRuntimeTemplateLib.ClientOptions} />}
|
|
28
28
|
>
|
|
29
|
-
<
|
|
29
|
+
<For each={Array.from(clientOptions.entries())} semicolon line>
|
|
30
30
|
{([key, value]) => <ts.InterfaceMember optional name={key} type={value} />}
|
|
31
|
-
</
|
|
31
|
+
</For>
|
|
32
32
|
<ts.InterfaceMember optional name="endpoint" type="string" />;
|
|
33
33
|
</ts.InterfaceDeclaration>
|
|
34
34
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import * as cl from "@typespec/http-client";
|
|
4
4
|
import { ClientContextDeclaration } from "./client-context-declaration.jsx";
|
|
@@ -7,7 +7,7 @@ import { ClientContextOptionsDeclaration } from "./client-context-options.jsx";
|
|
|
7
7
|
|
|
8
8
|
export interface ClientContextProps {
|
|
9
9
|
client: cl.Client;
|
|
10
|
-
children?:
|
|
10
|
+
children?: Children;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function ClientContext(props: ClientContextProps) {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { code, For, Refkey, refkey, StatementList } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { ModelProperty } from "@typespec/compiler";
|
|
4
4
|
import { useTransformNamePolicy } from "@typespec/emitter-framework";
|
|
5
5
|
import { getDefaultValue } from "../../utils/parameters.jsx";
|
|
6
6
|
|
|
7
7
|
export interface ParametrizedEndpointProps {
|
|
8
|
-
refkey:
|
|
8
|
+
refkey: Refkey;
|
|
9
9
|
template: string;
|
|
10
10
|
params: ModelProperty[];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function ParametrizedEndpoint(props: ParametrizedEndpointProps) {
|
|
14
14
|
const propNamer = useTransformNamePolicy();
|
|
15
|
-
const paramsRef =
|
|
15
|
+
const paramsRef = refkey();
|
|
16
16
|
const params = (
|
|
17
17
|
<ts.VarDeclaration name="params" type={"Record<string, any>"} refkey={paramsRef}>
|
|
18
18
|
<ts.ObjectExpression>
|
|
19
|
-
<
|
|
19
|
+
<For each={props.params} joiner="," line>
|
|
20
20
|
{(p) => {
|
|
21
21
|
const applicationName = propNamer.getApplicationName(p);
|
|
22
22
|
const transportName = propNamer.getTransportName(p);
|
|
@@ -26,14 +26,14 @@ export function ParametrizedEndpoint(props: ParametrizedEndpointProps) {
|
|
|
26
26
|
: applicationName;
|
|
27
27
|
return <ts.ObjectProperty name={transportName} value={itemRef} />;
|
|
28
28
|
}}
|
|
29
|
-
</
|
|
29
|
+
</For>
|
|
30
30
|
</ts.ObjectExpression>
|
|
31
31
|
</ts.VarDeclaration>
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
const resolvedEndpoint = (
|
|
35
35
|
<ts.VarDeclaration name="resolvedEndpoint" refkey={props.refkey}>
|
|
36
|
-
{
|
|
36
|
+
{code`
|
|
37
37
|
"${props.template}".replace(/{([^}]+)}/g, (_, key) =>
|
|
38
38
|
key in ${paramsRef} ? String(params[key]) : (() => { throw new Error(\`Missing parameter: $\{key}\`); })()
|
|
39
39
|
);
|
|
@@ -42,9 +42,9 @@ export function ParametrizedEndpoint(props: ParametrizedEndpointProps) {
|
|
|
42
42
|
);
|
|
43
43
|
|
|
44
44
|
return (
|
|
45
|
-
<
|
|
45
|
+
<StatementList>
|
|
46
46
|
{params}
|
|
47
47
|
{resolvedEndpoint}
|
|
48
|
-
</
|
|
48
|
+
</StatementList>
|
|
49
49
|
);
|
|
50
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Children, For, SourceDirectory, StatementList } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import * as cl from "@typespec/http-client";
|
|
4
4
|
import { useClientLibrary } from "@typespec/http-client";
|
|
@@ -6,22 +6,22 @@ import { ClientContext } from "./client-context/client-context.jsx";
|
|
|
6
6
|
import { ClientOperations } from "./client-operation.jsx";
|
|
7
7
|
|
|
8
8
|
export interface OperationsDirectoryProps {
|
|
9
|
-
children?:
|
|
9
|
+
children?: Children;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function OperationsDirectory(props: OperationsDirectoryProps) {
|
|
13
13
|
const { topLevel: clients } = useClientLibrary();
|
|
14
14
|
// If it is the root client, we don't need to create a directory
|
|
15
15
|
return (
|
|
16
|
-
<
|
|
16
|
+
<For each={clients} joiner="," line>
|
|
17
17
|
{(client) => (
|
|
18
|
-
<
|
|
18
|
+
<StatementList>
|
|
19
19
|
<ClientOperations client={client} />
|
|
20
20
|
<ClientContext client={client} />
|
|
21
21
|
<SubClients client={client} />
|
|
22
|
-
</
|
|
22
|
+
</StatementList>
|
|
23
23
|
)}
|
|
24
|
-
</
|
|
24
|
+
</For>
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -33,18 +33,18 @@ export function SubClients(props: SubClientsProps) {
|
|
|
33
33
|
const subClients = props.client.subClients;
|
|
34
34
|
|
|
35
35
|
return (
|
|
36
|
-
<
|
|
36
|
+
<For each={subClients}>
|
|
37
37
|
{(subClient) => {
|
|
38
38
|
const namePolicy = ts.useTSNamePolicy();
|
|
39
39
|
const subClientName = namePolicy.getName(subClient.name, "variable");
|
|
40
40
|
return (
|
|
41
|
-
<
|
|
41
|
+
<SourceDirectory path={subClientName}>
|
|
42
42
|
<ClientOperations client={subClient} />
|
|
43
43
|
<ClientContext client={subClient} />
|
|
44
44
|
<SubClients client={subClient} />
|
|
45
|
-
</
|
|
45
|
+
</SourceDirectory>
|
|
46
46
|
);
|
|
47
47
|
}}
|
|
48
|
-
</
|
|
48
|
+
</For>
|
|
49
49
|
);
|
|
50
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { For, List, Refkey, refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { FunctionDeclaration, TypeExpression } from "@typespec/emitter-framework/typescript";
|
|
@@ -28,26 +28,26 @@ export function ClientOperations(props: ClientOperationsProps) {
|
|
|
28
28
|
|
|
29
29
|
return (
|
|
30
30
|
<ts.SourceFile path={`${fileName}.ts`}>
|
|
31
|
-
<
|
|
31
|
+
<For each={clientOperations}>
|
|
32
32
|
{(operation) => (
|
|
33
33
|
<OperationPipeline
|
|
34
34
|
httpOperation={operation.httpOperation}
|
|
35
35
|
pipeline={{ handlers: [PaginatedOperationHandler] }}
|
|
36
36
|
/>
|
|
37
37
|
)}
|
|
38
|
-
</
|
|
38
|
+
</For>
|
|
39
39
|
</ts.SourceFile>
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export interface ClientOperationProps {
|
|
44
44
|
httpOperation: HttpOperation;
|
|
45
|
-
refkey:
|
|
45
|
+
refkey: Refkey;
|
|
46
46
|
internal?: boolean;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
function getClientOperationOptionsParamRef(httpOperation: HttpOperation):
|
|
50
|
-
return
|
|
49
|
+
function getClientOperationOptionsParamRef(httpOperation: HttpOperation): Refkey {
|
|
50
|
+
return refkey(httpOperation, "client-operation-options-parameter");
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export function ClientOperation(props: ClientOperationProps) {
|
|
@@ -65,7 +65,7 @@ export function ClientOperation(props: ClientOperationProps) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const returnType = $.httpOperation.getReturnType(props.httpOperation);
|
|
68
|
-
const responseRefkey =
|
|
68
|
+
const responseRefkey = refkey(props.httpOperation, "http-response");
|
|
69
69
|
const clientContextInterfaceRef = getClientcontextDeclarationRef(client);
|
|
70
70
|
const signatureParams: ts.ParameterDescriptor[] = [
|
|
71
71
|
{
|
|
@@ -75,7 +75,7 @@ export function ClientOperation(props: ClientOperationProps) {
|
|
|
75
75
|
...getOperationParameters(props.httpOperation, optionsRefkey),
|
|
76
76
|
];
|
|
77
77
|
return (
|
|
78
|
-
<
|
|
78
|
+
<List hardline>
|
|
79
79
|
<OperationOptionsDeclaration operation={props.httpOperation} />
|
|
80
80
|
<FunctionDeclaration
|
|
81
81
|
export={!props.internal}
|
|
@@ -86,16 +86,16 @@ export function ClientOperation(props: ClientOperationProps) {
|
|
|
86
86
|
parameters={signatureParams}
|
|
87
87
|
refkey={props.refkey}
|
|
88
88
|
>
|
|
89
|
-
<
|
|
89
|
+
<List hardline>
|
|
90
90
|
<HttpRequest
|
|
91
91
|
httpOperation={props.httpOperation}
|
|
92
92
|
responseRefkey={responseRefkey}
|
|
93
93
|
operationOptionsParamRefkey={optionsRefkey}
|
|
94
94
|
/>
|
|
95
95
|
<HttpResponse httpOperation={props.httpOperation} responseRefkey={responseRefkey} />
|
|
96
|
-
</
|
|
96
|
+
</List>
|
|
97
97
|
</FunctionDeclaration>
|
|
98
98
|
;
|
|
99
|
-
</
|
|
99
|
+
</List>
|
|
100
100
|
);
|
|
101
101
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { For, List, Refkey, refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { ClassMethod } from "@typespec/emitter-framework/typescript";
|
|
@@ -18,19 +18,19 @@ export function Client(props: ClientProps) {
|
|
|
18
18
|
const { topLevel } = useClientLibrary();
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
|
-
<
|
|
21
|
+
<For each={topLevel} hardline>
|
|
22
22
|
{(client) => {
|
|
23
23
|
const fileName = namePolicy.getName($.client.getName(client), "variable");
|
|
24
24
|
const flatClients = flattenClients(client);
|
|
25
25
|
return (
|
|
26
26
|
<ts.SourceFile path={`${fileName}.ts`}>
|
|
27
|
-
<
|
|
27
|
+
<For each={flatClients} hardline>
|
|
28
28
|
{(client) => <ClientClass client={client} />}
|
|
29
|
-
</
|
|
29
|
+
</For>
|
|
30
30
|
</ts.SourceFile>
|
|
31
31
|
);
|
|
32
32
|
}}
|
|
33
|
-
</
|
|
33
|
+
</For>
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -39,11 +39,11 @@ export interface ClientClassProps {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function getClientClassRef(client: cl.Client) {
|
|
42
|
-
return
|
|
42
|
+
return refkey(client.type, "client-class");
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function getClientContextFieldRef(client: cl.Client) {
|
|
46
|
-
return
|
|
46
|
+
return refkey(client.type, "client-context");
|
|
47
47
|
}
|
|
48
48
|
export function ClientClass(props: ClientClassProps) {
|
|
49
49
|
const { $ } = useTsp();
|
|
@@ -56,20 +56,20 @@ export function ClientClass(props: ClientClassProps) {
|
|
|
56
56
|
const operations = props.client.operations;
|
|
57
57
|
return (
|
|
58
58
|
<ts.ClassDeclaration export name={clientName} refkey={clientClassRef}>
|
|
59
|
-
<
|
|
59
|
+
<List hardline>
|
|
60
60
|
<ts.ClassField
|
|
61
61
|
name="context"
|
|
62
62
|
jsPrivate
|
|
63
63
|
refkey={contextMemberRef}
|
|
64
64
|
type={contextDeclarationRef}
|
|
65
65
|
/>
|
|
66
|
-
<
|
|
66
|
+
<For each={subClients} hardline semicolon>
|
|
67
67
|
{(subClient) => <SubClientClassField client={subClient} />}
|
|
68
|
-
</
|
|
68
|
+
</For>
|
|
69
69
|
<ClientConstructor client={props.client} />
|
|
70
|
-
<
|
|
70
|
+
<For each={operations} hardline semicolon>
|
|
71
71
|
{(op) => {
|
|
72
|
-
const parameters = getOperationParameters(op.httpOperation,
|
|
72
|
+
const parameters = getOperationParameters(op.httpOperation, refkey());
|
|
73
73
|
const args = parameters.flatMap((p) => p.refkey);
|
|
74
74
|
const isPaging = Boolean($.operation.getPagingMetadata(op.httpOperation.operation));
|
|
75
75
|
|
|
@@ -83,15 +83,15 @@ export function ClientClass(props: ClientClassProps) {
|
|
|
83
83
|
>
|
|
84
84
|
return{" "}
|
|
85
85
|
<ts.FunctionCallExpression
|
|
86
|
-
target={
|
|
86
|
+
target={refkey(op.httpOperation.operation)}
|
|
87
87
|
args={[contextMemberRef, ...args]}
|
|
88
88
|
/>
|
|
89
89
|
;
|
|
90
90
|
</ClassMethod>
|
|
91
91
|
);
|
|
92
92
|
}}
|
|
93
|
-
</
|
|
94
|
-
</
|
|
93
|
+
</For>
|
|
94
|
+
</List>
|
|
95
95
|
</ts.ClassDeclaration>
|
|
96
96
|
);
|
|
97
97
|
}
|
|
@@ -101,7 +101,7 @@ interface SubClientClassFieldProps {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
function getSubClientClassFieldRef(client: cl.Client) {
|
|
104
|
-
return
|
|
104
|
+
return refkey(client.type, "client-field");
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
function SubClientClassField(props: SubClientClassFieldProps) {
|
|
@@ -131,14 +131,14 @@ function ClientConstructor(props: ClientConstructorProps) {
|
|
|
131
131
|
);
|
|
132
132
|
const clientContextFieldRef = getClientContextFieldRef(props.client);
|
|
133
133
|
const clientContextFactoryRef = getClientContextFactoryRef(props.client);
|
|
134
|
-
const constructorParameters = buildClientParameters(props.client,
|
|
134
|
+
const constructorParameters = buildClientParameters(props.client, refkey());
|
|
135
135
|
const args = Object.values(constructorParameters).map((p) => p.refkey);
|
|
136
136
|
|
|
137
137
|
return (
|
|
138
138
|
<ts.ClassMethod name="constructor" parameters={constructorParameters}>
|
|
139
139
|
{clientContextFieldRef} ={" "}
|
|
140
140
|
<ts.FunctionCallExpression target={clientContextFactoryRef} args={args} />;<br />
|
|
141
|
-
<
|
|
141
|
+
<For each={subClients} joiner=";" hardline>
|
|
142
142
|
{(subClient) => {
|
|
143
143
|
const subClientFieldRef = getSubClientClassFieldRef(subClient);
|
|
144
144
|
const subClientArgs = calculateSubClientArgs(subClient, constructorParameters);
|
|
@@ -148,13 +148,13 @@ function ClientConstructor(props: ClientConstructorProps) {
|
|
|
148
148
|
</>
|
|
149
149
|
);
|
|
150
150
|
}}
|
|
151
|
-
</
|
|
151
|
+
</For>
|
|
152
152
|
</ts.ClassMethod>
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
function calculateSubClientArgs(subClient: cl.Client, parentParams: ts.ParameterDescriptor[]) {
|
|
157
|
-
const subClientParams = buildClientParameters(subClient,
|
|
157
|
+
const subClientParams = buildClientParameters(subClient, refkey()).map((p) => p.name);
|
|
158
158
|
return parentParams
|
|
159
159
|
.filter(({ name }) => subClientParams.includes(name))
|
|
160
160
|
.flatMap((p) => (p.refkey ? p.refkey : []));
|
|
@@ -162,7 +162,7 @@ function calculateSubClientArgs(subClient: cl.Client, parentParams: ts.Parameter
|
|
|
162
162
|
|
|
163
163
|
export interface NewClientExpressionProps {
|
|
164
164
|
client: cl.Client;
|
|
165
|
-
args:
|
|
165
|
+
args: Refkey[];
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
function NewClientExpression(props: NewClientExpressionProps) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core";
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
2
|
import { EncodingContext } from "../context/encoding/encoding-context.jsx";
|
|
3
3
|
import { EncodingDefaults } from "../context/encoding/types.js";
|
|
4
4
|
export interface EncodingProviderProps {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Children, code, For, List, NamePolicyContext, useNamePolicy } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { useTransformNamePolicy } from "@typespec/emitter-framework";
|
|
4
4
|
import { HttpOperation, HttpProperty } from "@typespec/http";
|
|
@@ -6,13 +6,13 @@ import { getDefaultValue, hasDefaultValue } from "../utils/parameters.jsx";
|
|
|
6
6
|
import { JsonTransform } from "./transforms/json/json-transform.jsx";
|
|
7
7
|
export interface HttpRequestParametersExpressionProps {
|
|
8
8
|
httpOperation: HttpOperation;
|
|
9
|
-
optionsParameter:
|
|
9
|
+
optionsParameter: Children;
|
|
10
10
|
parameters?: HttpProperty[];
|
|
11
|
-
children?:
|
|
11
|
+
children?: Children;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function HttpRequestParametersExpression(props: HttpRequestParametersExpressionProps) {
|
|
15
|
-
const parameters:
|
|
15
|
+
const parameters: Children[] = [];
|
|
16
16
|
const transformNamer = useTransformNamePolicy();
|
|
17
17
|
|
|
18
18
|
if (props.children || (Array.isArray(props.children) && props.children.length)) {
|
|
@@ -27,7 +27,7 @@ export function HttpRequestParametersExpression(props: HttpRequestParametersExpr
|
|
|
27
27
|
|
|
28
28
|
const optionsParamRef = props.optionsParameter ?? "options";
|
|
29
29
|
const members = (
|
|
30
|
-
<
|
|
30
|
+
<For each={props.parameters} line comma>
|
|
31
31
|
{(httpProperty) => {
|
|
32
32
|
const defaultValue = getDefaultValue(httpProperty);
|
|
33
33
|
const propertyExpression = buildMemberChainExpression(
|
|
@@ -45,14 +45,14 @@ export function HttpRequestParametersExpression(props: HttpRequestParametersExpr
|
|
|
45
45
|
</>
|
|
46
46
|
);
|
|
47
47
|
return (
|
|
48
|
-
<
|
|
48
|
+
<NamePolicyContext.Provider value={{ getName: (n) => n }}>
|
|
49
49
|
<ts.ObjectProperty name={transportParamName} value={paramValue} />
|
|
50
|
-
</
|
|
50
|
+
</NamePolicyContext.Provider>
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (propertyExpression.isNullish) {
|
|
55
|
-
return
|
|
55
|
+
return code`
|
|
56
56
|
...(${propertyExpression.fullExpression} && {${(<JsonTransform itemRef={propertyExpression.leadingExpression} type={httpProperty.property} target="transport" />)}})
|
|
57
57
|
`;
|
|
58
58
|
} else {
|
|
@@ -65,7 +65,7 @@ export function HttpRequestParametersExpression(props: HttpRequestParametersExpr
|
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
}}
|
|
68
|
-
</
|
|
68
|
+
</For>
|
|
69
69
|
);
|
|
70
70
|
|
|
71
71
|
parameters.push(members);
|
|
@@ -76,8 +76,8 @@ export function HttpRequestParametersExpression(props: HttpRequestParametersExpr
|
|
|
76
76
|
interface MemberChainExpression {
|
|
77
77
|
propertyName: string;
|
|
78
78
|
isNullish: boolean;
|
|
79
|
-
fullExpression:
|
|
80
|
-
leadingExpression?:
|
|
79
|
+
fullExpression: Children;
|
|
80
|
+
leadingExpression?: Children;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
@@ -101,11 +101,11 @@ interface MemberChainExpression {
|
|
|
101
101
|
function buildMemberChainExpression(
|
|
102
102
|
httpOperation: HttpOperation,
|
|
103
103
|
httpProperty: HttpProperty,
|
|
104
|
-
optionsParamRef?:
|
|
104
|
+
optionsParamRef?: Children,
|
|
105
105
|
): MemberChainExpression {
|
|
106
|
-
const segments:
|
|
106
|
+
const segments: Children[] = [];
|
|
107
107
|
let isNullish = httpProperty.property.optional === true;
|
|
108
|
-
const namePolicy =
|
|
108
|
+
const namePolicy = useNamePolicy();
|
|
109
109
|
const propertyApplicationName = namePolicy.getName(httpProperty.property.name, "property");
|
|
110
110
|
|
|
111
111
|
// If the property is at the top level, return early
|
|
@@ -114,8 +114,8 @@ function buildMemberChainExpression(
|
|
|
114
114
|
return {
|
|
115
115
|
propertyName: propertyApplicationName,
|
|
116
116
|
isNullish,
|
|
117
|
-
fullExpression:
|
|
118
|
-
leadingExpression:
|
|
117
|
+
fullExpression: code`${optionsParamRef}?.${propertyApplicationName}`,
|
|
118
|
+
leadingExpression: code`${optionsParamRef}`,
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
return {
|
|
@@ -146,7 +146,7 @@ function buildMemberChainExpression(
|
|
|
146
146
|
|
|
147
147
|
// Use direct property access if possible.
|
|
148
148
|
if (isValidIdentifier(parentName)) {
|
|
149
|
-
segments.unshift(
|
|
149
|
+
segments.unshift(code`${parentName}`);
|
|
150
150
|
} else {
|
|
151
151
|
// For non-valid identifiers, use bracket notation.
|
|
152
152
|
segments.unshift(`[${JSON.stringify(parentName)}]`);
|
|
@@ -158,11 +158,11 @@ function buildMemberChainExpression(
|
|
|
158
158
|
|
|
159
159
|
const fullExpression = (
|
|
160
160
|
<>
|
|
161
|
-
<
|
|
161
|
+
<List children={segments} />
|
|
162
162
|
{propertyApplicationName}
|
|
163
163
|
</>
|
|
164
164
|
);
|
|
165
|
-
const leadingExpression = <
|
|
165
|
+
const leadingExpression = <List children={segments.slice(0, -1)} />;
|
|
166
166
|
|
|
167
167
|
return {
|
|
168
168
|
propertyName: propertyApplicationName,
|