@typespec/http-client-js 0.4.0-dev.2 → 0.4.0-dev.4
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/.testignore +5 -0
- package/CHANGELOG.md +0 -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 +64 -32
- 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 +2 -1
- package/dist/src/components/client.js.map +1 -1
- package/dist/src/components/http-request-options.d.ts +4 -4
- package/dist/src/components/http-request-options.d.ts.map +1 -1
- package/dist/src/components/http-request-options.js +10 -11
- package/dist/src/components/http-request-options.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 -31
- 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/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/serializers.d.ts.map +1 -1
- package/dist/src/components/serializers.js +10 -1
- package/dist/src/components/serializers.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/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/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/client-operation.tsx +37 -13
- package/src/components/client.tsx +2 -1
- package/src/components/http-request-options.tsx +11 -12
- package/src/components/http-request.tsx +22 -21
- 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/output.tsx +2 -1
- package/src/components/serializers.tsx +14 -1
- package/src/components/static-helpers/paging-helper.tsx +195 -0
- package/src/components/transforms/operation-transform-expression.tsx +3 -3
- package/src/emitter.tsx +2 -0
- package/src/lib.ts +6 -0
- package/test/e2e/http/parameters/collection-format/main.test.ts +0 -5
- package/test/e2e/http/payload/multipart/main.test.ts +1 -1
- package/test/e2e/http/payload/pageable/main.test.ts +78 -22
- package/test/scenarios/http-operations/paging.md +244 -0
- package/test/scenarios/multipart/file_content_type.md +15 -0
- package/test/scenarios/serializers/file.md +67 -0
- package/tsconfig.test.json +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-js",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.4",
|
|
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",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@alloy-js/core": "^0.10.0",
|
|
35
35
|
"@alloy-js/typescript": "^0.10.0",
|
|
36
|
-
"@typespec/emitter-framework": "^0.
|
|
36
|
+
"@typespec/emitter-framework": "^0.5.0 || >=0.6.0-dev <0.6.0",
|
|
37
37
|
"@typespec/http-client": "^0.4.0 || >=0.5.0-dev <0.5.0",
|
|
38
38
|
"prettier": "~3.5.3"
|
|
39
39
|
},
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"test:ui": "vitest --ui",
|
|
78
78
|
"test:watch": "vitest -w",
|
|
79
79
|
"test:ci": "vitest run --coverage --reporter=junit --reporter=default",
|
|
80
|
-
"test:e2e": "pnpm emit:e2e && node eng/scripts/run-e2e-tests.js",
|
|
80
|
+
"test:e2e": "pnpm emit:e2e && pnpm build:test && node eng/scripts/run-e2e-tests.js",
|
|
81
81
|
"format": "prettier . --write",
|
|
82
82
|
"build:test": "tsc -p tsconfig.test.json",
|
|
83
83
|
"start:server": "npx tsp-spector server start node_modules/@typespec/http-specs/specs --coverageFile ./temp/tsp-spector-coverage-javascript-standard.json --debug",
|
|
@@ -2,10 +2,14 @@ import * as ay from "@alloy-js/core";
|
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
4
|
import { FunctionDeclaration, TypeExpression } from "@typespec/emitter-framework/typescript";
|
|
5
|
+
import { HttpOperation } from "@typespec/http";
|
|
5
6
|
import * as cl from "@typespec/http-client";
|
|
7
|
+
import { reportDiagnostic } from "../lib.js";
|
|
6
8
|
import { getClientcontextDeclarationRef } from "./client-context/client-context-declaration.jsx";
|
|
7
9
|
import { HttpRequest } from "./http-request.jsx";
|
|
8
10
|
import { HttpResponse } from "./http-response.jsx";
|
|
11
|
+
import { OperationPipeline } from "./operation-handlers/operation-pipeline.jsx";
|
|
12
|
+
import { PaginatedOperationHandler } from "./operation-handlers/paging/paginated-operation-handler.jsx";
|
|
9
13
|
import { OperationOptionsDeclaration } from "./operation-options.jsx";
|
|
10
14
|
import { getOperationParameters } from "./operation-parameters.jsx";
|
|
11
15
|
|
|
@@ -25,40 +29,60 @@ export function ClientOperations(props: ClientOperationsProps) {
|
|
|
25
29
|
return (
|
|
26
30
|
<ts.SourceFile path={`${fileName}.ts`}>
|
|
27
31
|
<ay.For each={clientOperations}>
|
|
28
|
-
{(operation) =>
|
|
32
|
+
{(operation) => (
|
|
33
|
+
<OperationPipeline
|
|
34
|
+
httpOperation={operation.httpOperation}
|
|
35
|
+
pipeline={{ handlers: [PaginatedOperationHandler] }}
|
|
36
|
+
/>
|
|
37
|
+
)}
|
|
29
38
|
</ay.For>
|
|
30
39
|
</ts.SourceFile>
|
|
31
40
|
);
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
export interface ClientOperationProps {
|
|
35
|
-
|
|
44
|
+
httpOperation: HttpOperation;
|
|
45
|
+
refkey: ay.Refkey;
|
|
46
|
+
internal?: boolean;
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
export function ClientOperation(props: ClientOperationProps) {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
50
|
+
const clientLibrary = cl.useClientLibrary();
|
|
51
|
+
const client = clientLibrary.getClientForOperation(props.httpOperation);
|
|
52
|
+
|
|
53
|
+
if (!client) {
|
|
54
|
+
reportDiagnostic($.program, {
|
|
55
|
+
code: "client-not-found",
|
|
56
|
+
target: props.httpOperation.operation,
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const returnType = $.httpOperation.getReturnType(props.httpOperation);
|
|
62
|
+
const responseRefkey = ay.refkey(props.httpOperation, "http-response");
|
|
42
63
|
const clientContextInterfaceRef = getClientcontextDeclarationRef(client);
|
|
43
64
|
const signatureParams: ts.ParameterDescriptor[] = [
|
|
44
65
|
{ name: "client", type: clientContextInterfaceRef, refkey: ay.refkey(client, "client") },
|
|
45
|
-
...getOperationParameters(props.
|
|
66
|
+
...getOperationParameters(props.httpOperation),
|
|
46
67
|
];
|
|
47
68
|
return (
|
|
48
|
-
|
|
49
|
-
<OperationOptionsDeclaration operation={props.
|
|
69
|
+
<ay.List hardline>
|
|
70
|
+
<OperationOptionsDeclaration operation={props.httpOperation} />
|
|
50
71
|
<FunctionDeclaration
|
|
51
|
-
export
|
|
72
|
+
export={!props.internal}
|
|
52
73
|
async
|
|
53
|
-
type={props.
|
|
74
|
+
type={props.httpOperation.operation}
|
|
54
75
|
returnType={<TypeExpression type={returnType} />}
|
|
55
76
|
parametersMode="replace"
|
|
56
77
|
parameters={signatureParams}
|
|
78
|
+
refkey={props.refkey}
|
|
57
79
|
>
|
|
58
|
-
<
|
|
59
|
-
|
|
80
|
+
<ay.List hardline>
|
|
81
|
+
<HttpRequest httpOperation={props.httpOperation} responseRefkey={responseRefkey} />
|
|
82
|
+
<HttpResponse httpOperation={props.httpOperation} responseRefkey={responseRefkey} />
|
|
83
|
+
</ay.List>
|
|
60
84
|
</FunctionDeclaration>
|
|
61
85
|
;
|
|
62
|
-
|
|
86
|
+
</ay.List>
|
|
63
87
|
);
|
|
64
88
|
}
|
|
@@ -69,10 +69,11 @@ export function ClientClass(props: ClientClassProps) {
|
|
|
69
69
|
{(op) => {
|
|
70
70
|
const parameters = getOperationParameters(op.httpOperation);
|
|
71
71
|
const args = parameters.flatMap((p) => p.refkey);
|
|
72
|
+
const isPaging = Boolean($.operation.getPagingMetadata(op.httpOperation.operation));
|
|
72
73
|
|
|
73
74
|
return (
|
|
74
75
|
<ClassMethod
|
|
75
|
-
async
|
|
76
|
+
async={!isPaging}
|
|
76
77
|
type={op.httpOperation.operation}
|
|
77
78
|
parameters={parameters}
|
|
78
79
|
returnType={null}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Children, code, Refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import {
|
|
3
|
+
import { HttpOperation } from "@typespec/http";
|
|
4
4
|
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
5
5
|
import { HttpRequestParametersExpression } from "./http-request-parameters-expression.jsx";
|
|
6
6
|
import { getOperationOptionsParameterRefkey } from "./operation-parameters.jsx";
|
|
7
7
|
import { OperationTransformExpression } from "./transforms/operation-transform-expression.jsx";
|
|
8
8
|
|
|
9
9
|
export interface HttpRequestOptionsProps {
|
|
10
|
-
|
|
10
|
+
httpOperation: HttpOperation;
|
|
11
11
|
refkey?: Refkey;
|
|
12
12
|
children?: Children;
|
|
13
13
|
}
|
|
@@ -16,15 +16,15 @@ export function HttpRequestOptions(props: HttpRequestOptionsProps) {
|
|
|
16
16
|
return (
|
|
17
17
|
<ts.VarDeclaration name="httpRequestOptions" refkey={props.refkey}>
|
|
18
18
|
<ts.ObjectExpression>
|
|
19
|
-
<HttpRequestOptions.Headers
|
|
20
|
-
<HttpRequestOptions.Body
|
|
19
|
+
<HttpRequestOptions.Headers httpOperation={props.httpOperation} />
|
|
20
|
+
<HttpRequestOptions.Body httpOperation={props.httpOperation} />
|
|
21
21
|
</ts.ObjectExpression>
|
|
22
22
|
</ts.VarDeclaration>
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export interface HttpRequestOptionsHeadersProps {
|
|
27
|
-
|
|
27
|
+
httpOperation: HttpOperation;
|
|
28
28
|
children?: Children;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -32,12 +32,12 @@ HttpRequestOptions.Headers = function HttpRequestOptionsHeaders(
|
|
|
32
32
|
props: HttpRequestOptionsHeadersProps,
|
|
33
33
|
) {
|
|
34
34
|
// Extract the header request parameters from the operation
|
|
35
|
-
const httpOperation = props.
|
|
36
|
-
const headers = httpOperation.parameters.properties.filter(
|
|
35
|
+
const httpOperation = props.httpOperation;
|
|
36
|
+
const headers = props.httpOperation.parameters.properties.filter(
|
|
37
37
|
(p) => p.kind === "header" || p.kind === "contentType",
|
|
38
38
|
);
|
|
39
39
|
|
|
40
|
-
const optionsParam = getOperationOptionsParameterRefkey(props.
|
|
40
|
+
const optionsParam = getOperationOptionsParameterRefkey(props.httpOperation);
|
|
41
41
|
return (
|
|
42
42
|
<EncodingProvider defaults={{ bytes: "base64", datetime: "rfc7231" }}>
|
|
43
43
|
<ts.ObjectProperty name="headers">
|
|
@@ -53,14 +53,13 @@ HttpRequestOptions.Headers = function HttpRequestOptionsHeaders(
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
export interface HttpRequestOptionsBodyProps {
|
|
56
|
-
|
|
56
|
+
httpOperation: HttpOperation;
|
|
57
57
|
itemName?: string;
|
|
58
58
|
children?: Children;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
HttpRequestOptions.Body = function HttpRequestOptionsBody(props: HttpRequestOptionsBodyProps) {
|
|
62
|
-
const
|
|
63
|
-
const body = httpOperation.parameters.body;
|
|
62
|
+
const body = props.httpOperation.parameters.body;
|
|
64
63
|
|
|
65
64
|
if (!body) {
|
|
66
65
|
return <></>;
|
|
@@ -68,7 +67,7 @@ HttpRequestOptions.Body = function HttpRequestOptionsBody(props: HttpRequestOpti
|
|
|
68
67
|
// The transformer to apply to the body.
|
|
69
68
|
const bodyTransform = (
|
|
70
69
|
<>
|
|
71
|
-
<OperationTransformExpression
|
|
70
|
+
<OperationTransformExpression httpOperation={props.httpOperation} />
|
|
72
71
|
</>
|
|
73
72
|
);
|
|
74
73
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Children, code, refkey, Refkey, StatementList } from "@alloy-js/core";
|
|
1
|
+
import { Children, code, List, refkey, Refkey, StatementList } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { Reference } from "@alloy-js/typescript";
|
|
4
|
-
import {
|
|
4
|
+
import { HttpOperation } from "@typespec/http";
|
|
5
5
|
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
6
6
|
import { uriTemplateLib } from "./external-packages/uri-template.js";
|
|
7
7
|
import { HttpRequestOptions } from "./http-request-options.js";
|
|
@@ -9,7 +9,7 @@ import { HttpRequestParametersExpression } from "./http-request-parameters-expre
|
|
|
9
9
|
import { getOperationOptionsParameterRefkey } from "./operation-parameters.jsx";
|
|
10
10
|
|
|
11
11
|
export interface HttpRequestProps {
|
|
12
|
-
|
|
12
|
+
httpOperation: HttpOperation;
|
|
13
13
|
responseRefkey?: Refkey;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -17,47 +17,48 @@ export function HttpRequest(props: HttpRequestProps) {
|
|
|
17
17
|
const operationUrlRefkey = refkey();
|
|
18
18
|
const requestOptionsRefkey = refkey();
|
|
19
19
|
const httpResponseRefkey = props.responseRefkey ?? refkey();
|
|
20
|
-
const verb = props.
|
|
20
|
+
const verb = props.httpOperation.verb;
|
|
21
21
|
return (
|
|
22
|
-
<
|
|
23
|
-
<
|
|
22
|
+
<List>
|
|
23
|
+
<StatementList>
|
|
24
|
+
<HttpRequest.Url httpOperation={props.httpOperation} refkey={operationUrlRefkey} />
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
<HttpRequestOptions httpOperation={props.httpOperation} refkey={requestOptionsRefkey} />
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
<ts.VarDeclaration name="response" refkey={httpResponseRefkey}>
|
|
29
|
+
{code`
|
|
29
30
|
await client.pathUnchecked(${(<Reference refkey={operationUrlRefkey} />)}).${verb}(${(<Reference refkey={requestOptionsRefkey} />)})
|
|
30
|
-
|
|
31
|
+
`}
|
|
32
|
+
</ts.VarDeclaration>
|
|
33
|
+
<hbr />
|
|
34
|
+
</StatementList>
|
|
35
|
+
{code`
|
|
31
36
|
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
32
37
|
options?.operationOptions?.onResponse(response);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
`}
|
|
36
|
-
</ts.VarDeclaration>
|
|
37
|
-
</StatementList>
|
|
38
|
+
}`}
|
|
39
|
+
</List>
|
|
38
40
|
);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export interface HttpUrlProps {
|
|
42
|
-
|
|
44
|
+
httpOperation: HttpOperation;
|
|
43
45
|
refkey?: Refkey;
|
|
44
46
|
children?: Children;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
HttpRequest.Url = function HttpUrlDeclaration(props: HttpUrlProps) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const urlParameters = httpOperation.parameters.properties.filter(
|
|
50
|
+
const urlTemplate = props.httpOperation.uriTemplate;
|
|
51
|
+
const urlParameters = props.httpOperation.parameters.properties.filter(
|
|
51
52
|
(p) => p.kind === "path" || p.kind === "query",
|
|
52
53
|
);
|
|
53
|
-
const optionsParameter = getOperationOptionsParameterRefkey(props.
|
|
54
|
+
const optionsParameter = getOperationOptionsParameterRefkey(props.httpOperation);
|
|
54
55
|
return (
|
|
55
56
|
<EncodingProvider defaults={{ bytes: "base64url" }}>
|
|
56
57
|
<ts.VarDeclaration name="path" refkey={props.refkey}>
|
|
57
58
|
{uriTemplateLib.parse}({JSON.stringify(urlTemplate)}).expand(
|
|
58
59
|
{
|
|
59
60
|
<HttpRequestParametersExpression
|
|
60
|
-
httpOperation={httpOperation}
|
|
61
|
+
httpOperation={props.httpOperation}
|
|
61
62
|
optionsParameter={optionsParameter!}
|
|
62
63
|
parameters={urlParameters}
|
|
63
64
|
/>
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { Children, code, For, Refkey } from "@alloy-js/core";
|
|
1
|
+
import { Children, code, For, List, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { isVoidType } from "@typespec/compiler";
|
|
3
3
|
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
|
-
import {
|
|
4
|
+
import { HttpOperation } from "@typespec/http";
|
|
5
5
|
import { getCreateRestErrorRefkey } from "./static-helpers/rest-error.jsx";
|
|
6
6
|
import { ContentTypeEncodingProvider } from "./transforms/content-type-encoding-provider.jsx";
|
|
7
7
|
import { JsonTransform } from "./transforms/json/json-transform.jsx";
|
|
8
8
|
export interface HttpResponseProps {
|
|
9
|
-
|
|
9
|
+
httpOperation: HttpOperation;
|
|
10
10
|
responseRefkey: Refkey;
|
|
11
11
|
children?: Children;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function HttpResponse(props: HttpResponseProps) {
|
|
15
15
|
return (
|
|
16
|
-
|
|
17
|
-
<HttpResponses
|
|
18
|
-
|
|
16
|
+
<List hardline>
|
|
17
|
+
<HttpResponses httpOperation={props.httpOperation} />
|
|
19
18
|
{code`throw ${getCreateRestErrorRefkey()}(response);`}
|
|
20
|
-
|
|
19
|
+
</List>
|
|
21
20
|
);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export interface HttpResponsesProps {
|
|
25
|
-
|
|
24
|
+
httpOperation: HttpOperation;
|
|
26
25
|
children?: Children;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
export function HttpResponses(props: HttpResponsesProps) {
|
|
30
29
|
// Handle response by status code and content type
|
|
31
|
-
const responses = $.httpOperation.flattenResponses(props.
|
|
30
|
+
const responses = $.httpOperation.flattenResponses(props.httpOperation);
|
|
32
31
|
return (
|
|
33
32
|
<For each={responses.filter((r) => !$.httpResponse.isErrorResponse(r))}>
|
|
34
33
|
{({ statusCode, contentType, responseContent, type }) => {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import { HttpOperation } from "@typespec/http";
|
|
3
|
+
import { ClientOperation as DefaultOperationComponent } from "../client-operation.jsx";
|
|
4
|
+
import { OperationHandlerPipeline } from "./types.jsx";
|
|
5
|
+
|
|
6
|
+
export interface OperationPipelineProps {
|
|
7
|
+
httpOperation: HttpOperation;
|
|
8
|
+
pipeline: OperationHandlerPipeline;
|
|
9
|
+
internal?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Component that manages the operation handler pipeline.
|
|
14
|
+
* It will try each handler in order until it finds one that can handle the operation.
|
|
15
|
+
* If no handler is found, it will use the default ClientOperation component.
|
|
16
|
+
*/
|
|
17
|
+
export function OperationPipeline({ httpOperation, pipeline, internal }: OperationPipelineProps) {
|
|
18
|
+
for (const handler of pipeline.handlers) {
|
|
19
|
+
if (handler.canHandle(httpOperation)) {
|
|
20
|
+
return handler.handle(httpOperation);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Default to standard client operation if no handler matched
|
|
25
|
+
const defaultOperationRefkey = ay.refkey(httpOperation.operation);
|
|
26
|
+
return (
|
|
27
|
+
<DefaultOperationComponent
|
|
28
|
+
httpOperation={httpOperation}
|
|
29
|
+
internal={internal}
|
|
30
|
+
refkey={defaultOperationRefkey}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PagingOperation } from "@typespec/compiler";
|
|
2
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
3
|
+
import { TypeExpression } from "@typespec/emitter-framework/typescript";
|
|
4
|
+
|
|
5
|
+
export function getPageItemTypeName(pagingOperation: PagingOperation) {
|
|
6
|
+
const type = pagingOperation.output.pageItems.property.type;
|
|
7
|
+
// only accept array type
|
|
8
|
+
if (type.kind === "Model" && $.array.is(type)) {
|
|
9
|
+
return <TypeExpression type={$.array.getElementType(type)} />;
|
|
10
|
+
}
|
|
11
|
+
// not supported and throw exceptions
|
|
12
|
+
throw new Error("Not supported");
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { PagingOperation, PagingProperty } from "@typespec/compiler";
|
|
4
|
+
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
|
+
import { HttpOperation } from "@typespec/http";
|
|
6
|
+
export interface PageResponseProps {
|
|
7
|
+
operation: HttpOperation;
|
|
8
|
+
pagingOperation: PagingOperation;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getPageResponseTypeRefkey(operation: HttpOperation) {
|
|
12
|
+
return ay.refkey(operation, "page-response");
|
|
13
|
+
}
|
|
14
|
+
export function PageResponseDeclaration(props: PageResponseProps) {
|
|
15
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
16
|
+
const interfaceName = namePolicy.getName(
|
|
17
|
+
props.operation.operation.name + "PageResponse",
|
|
18
|
+
"interface",
|
|
19
|
+
);
|
|
20
|
+
const definedResponses = props.pagingOperation.output;
|
|
21
|
+
// Only accept these respose items
|
|
22
|
+
const acceptedColumns = [
|
|
23
|
+
"continuationToken",
|
|
24
|
+
"pageItems",
|
|
25
|
+
"nextLink",
|
|
26
|
+
"prevLink",
|
|
27
|
+
"firstLink",
|
|
28
|
+
"lastLink",
|
|
29
|
+
];
|
|
30
|
+
const responseProperties: PagingProperty[] = [];
|
|
31
|
+
for (const key in definedResponses) {
|
|
32
|
+
const property = definedResponses[key as keyof typeof definedResponses];
|
|
33
|
+
if (acceptedColumns.includes(key) && !!property) {
|
|
34
|
+
responseProperties.push(property);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ts.InterfaceDeclaration
|
|
40
|
+
export
|
|
41
|
+
name={interfaceName}
|
|
42
|
+
refkey={getPageResponseTypeRefkey(props.operation)}
|
|
43
|
+
>
|
|
44
|
+
<ay.For each={responseProperties} line>
|
|
45
|
+
{(parameter) => (
|
|
46
|
+
<ts.InterfaceMember
|
|
47
|
+
name={parameter.property.name}
|
|
48
|
+
optional={parameter.property.optional}
|
|
49
|
+
type={<ef.TypeExpression type={parameter.property.type} />}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
</ay.For>
|
|
53
|
+
</ts.InterfaceDeclaration>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { PagingOperation, PagingProperty } from "@typespec/compiler";
|
|
4
|
+
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
|
+
import { HttpOperation } from "@typespec/http";
|
|
6
|
+
export interface PageSettingsProps {
|
|
7
|
+
operation: HttpOperation;
|
|
8
|
+
pagingOperation: PagingOperation;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getPageSettingsTypeRefkey(operation: HttpOperation) {
|
|
12
|
+
return ay.refkey(operation, "page-settings");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getPageSettingProperties(pagingOperation: PagingOperation) {
|
|
16
|
+
const definedSettings = pagingOperation.input;
|
|
17
|
+
// Only accept these page settings
|
|
18
|
+
const acceptedSettings = ["continuationToken", "offset", "pageSize", "pageIndex"];
|
|
19
|
+
const settingProperties: PagingProperty[] = [];
|
|
20
|
+
for (const key in definedSettings) {
|
|
21
|
+
const property = definedSettings[key as keyof typeof definedSettings];
|
|
22
|
+
if (acceptedSettings.includes(key) && !!property) {
|
|
23
|
+
settingProperties.push(property);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return settingProperties;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function PageSettingsDeclaration(props: PageSettingsProps) {
|
|
30
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
31
|
+
const interfaceName = namePolicy.getName(
|
|
32
|
+
props.operation.operation.name + "PageSettings",
|
|
33
|
+
"interface",
|
|
34
|
+
);
|
|
35
|
+
const settingProperties = getPageSettingProperties(props.pagingOperation);
|
|
36
|
+
return (
|
|
37
|
+
<ts.InterfaceDeclaration
|
|
38
|
+
export
|
|
39
|
+
name={interfaceName}
|
|
40
|
+
refkey={getPageSettingsTypeRefkey(props.operation)}
|
|
41
|
+
>
|
|
42
|
+
<ay.For each={settingProperties} line>
|
|
43
|
+
{(parameter) => (
|
|
44
|
+
<ts.InterfaceMember
|
|
45
|
+
name={parameter.property.name}
|
|
46
|
+
optional
|
|
47
|
+
type={<ef.TypeExpression type={parameter.property.type} />}
|
|
48
|
+
/>
|
|
49
|
+
)}
|
|
50
|
+
</ay.For>
|
|
51
|
+
</ts.InterfaceDeclaration>
|
|
52
|
+
);
|
|
53
|
+
}
|