@typespec/http-client-js 0.4.0-dev.7 → 0.4.0-dev.8
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-factory.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-factory.js +10 -1
- package/dist/src/components/client-operation.d.ts.map +1 -1
- package/dist/src/components/client-operation.js +4 -1
- package/dist/src/components/client.d.ts.map +1 -1
- package/dist/src/components/client.js +13 -1
- package/dist/src/components/http-response.d.ts.map +1 -1
- package/dist/src/components/http-response.js +4 -1
- package/dist/src/components/models.d.ts.map +1 -1
- package/dist/src/components/models.js +4 -1
- package/dist/src/components/operation-handlers/paging/page-item.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/paging/page-item.js +4 -1
- 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 +7 -1
- package/dist/src/components/output.d.ts +2 -0
- package/dist/src/components/output.d.ts.map +1 -1
- package/dist/src/components/output.js +6 -5
- package/dist/src/components/serializers.d.ts.map +1 -1
- package/dist/src/components/serializers.js +7 -4
- package/dist/src/components/transforms/data-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/data-transform.js +4 -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 +7 -1
- 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 -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 +4 -1
- package/dist/src/components/transforms/json/json-model-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-transform.js +7 -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 +7 -1
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-transform-discriminator.js +7 -1
- package/dist/src/components/transforms/json/json-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-transform.js +10 -1
- package/dist/src/components/transforms/json/union-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/union-transform.js +4 -1
- package/dist/src/components/transforms/json/utils/transport-namer.d.ts +2 -1
- package/dist/src/components/transforms/json/utils/transport-namer.d.ts.map +1 -1
- package/dist/src/components/transforms/json/utils/transport-namer.js +1 -2
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/multipart-transform.js +4 -2
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/simple-part-transform.js +4 -1
- package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-expression.js +4 -2
- package/dist/src/components/transforms/scalar-transform.js +95 -78
- package/dist/src/components/transforms/transform-name-policy.d.ts.map +1 -1
- package/dist/src/components/transforms/transform-name-policy.js +6 -1
- package/dist/src/components/utils/unpack-model-property.d.ts.map +1 -1
- package/dist/src/components/utils/unpack-model-property.js +4 -1
- package/dist/src/context/encoding/encoding-context.d.ts.map +1 -1
- package/dist/src/context/encoding/encoding-context.js +4 -1
- package/dist/src/emitter.js +4 -1
- package/dist/src/utils/multipart.d.ts.map +1 -1
- package/dist/src/utils/multipart.js +4 -1
- package/dist/src/utils/operations.d.ts +3 -2
- package/dist/src/utils/operations.d.ts.map +1 -1
- package/dist/src/utils/operations.js +12 -13
- package/dist/src/utils/parameters.d.ts.map +1 -1
- package/dist/src/utils/parameters.js +7 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/client-context/client-context-factory.tsx +4 -1
- package/src/components/client-operation.tsx +2 -1
- package/src/components/client.tsx +5 -1
- package/src/components/http-response.tsx +2 -1
- package/src/components/models.tsx +2 -1
- package/src/components/operation-handlers/paging/page-item.tsx +2 -1
- package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +3 -1
- package/src/components/output.tsx +10 -5
- package/src/components/serializers.tsx +6 -4
- package/src/components/transforms/data-transform.tsx +2 -1
- package/src/components/transforms/json/json-array-transform.tsx +3 -1
- package/src/components/transforms/json/json-model-additional-properties-transform.tsx +2 -1
- package/src/components/transforms/json/json-model-property-transform.tsx +2 -1
- package/src/components/transforms/json/json-model-transform.tsx +3 -1
- package/src/components/transforms/json/json-record-transform.tsx +3 -1
- package/src/components/transforms/json/json-transform-discriminator.tsx +3 -1
- package/src/components/transforms/json/json-transform.tsx +4 -1
- package/src/components/transforms/json/union-transform.tsx +2 -1
- package/src/components/transforms/json/utils/transport-namer.ts +2 -2
- package/src/components/transforms/multipart/multipart-transform.tsx +2 -2
- package/src/components/transforms/multipart/simple-part-transform.tsx +2 -1
- package/src/components/transforms/operation-transform-expression.tsx +2 -2
- package/src/components/transforms/scalar-transform.tsx +42 -32
- package/src/components/transforms/transform-name-policy.ts +2 -1
- package/src/components/utils/unpack-model-property.ts +2 -1
- package/src/context/encoding/encoding-context.tsx +2 -1
- package/src/emitter.tsx +2 -2
- package/src/utils/multipart.ts +2 -1
- package/src/utils/operations.ts +13 -11
- package/src/utils/parameters.tsx +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
|
|
5
5
|
import { HttpAuth, type OAuth2Flow } from "@typespec/http";
|
|
6
6
|
import * as cl from "@typespec/http-client";
|
|
@@ -20,6 +20,7 @@ export function getClientContextFactoryRef(client: cl.Client) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps) {
|
|
23
|
+
const { $ } = useTsp();
|
|
23
24
|
const ref = getClientContextFactoryRef(props.client);
|
|
24
25
|
const contextDeclarationRef = getClientcontextDeclarationRef(props.client);
|
|
25
26
|
const namePolicy = ts.useTSNamePolicy();
|
|
@@ -99,6 +100,7 @@ interface AuthSchemeProps {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function AuthScheme(props: AuthSchemeProps) {
|
|
103
|
+
const { $ } = useTsp();
|
|
102
104
|
switch (props.scheme.type) {
|
|
103
105
|
case "http":
|
|
104
106
|
return (
|
|
@@ -161,6 +163,7 @@ function OAuth2Flow(props: OAuth2FlowProps) {
|
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
function AuthSchemeOptions(props: AuthSchemeOptionsProps) {
|
|
166
|
+
const { $ } = useTsp();
|
|
164
167
|
const clientCredential = $.client.getAuth(props.client);
|
|
165
168
|
|
|
166
169
|
if (clientCredential.schemes.length === 0) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { FunctionDeclaration, TypeExpression } from "@typespec/emitter-framework/typescript";
|
|
5
5
|
import { HttpOperation } from "@typespec/http";
|
|
6
6
|
import * as cl from "@typespec/http-client";
|
|
@@ -47,6 +47,7 @@ export interface ClientOperationProps {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export function ClientOperation(props: ClientOperationProps) {
|
|
50
|
+
const { $ } = useTsp();
|
|
50
51
|
const clientLibrary = cl.useClientLibrary();
|
|
51
52
|
const client = clientLibrary.getClientForOperation(props.httpOperation);
|
|
52
53
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { ClassMethod } from "@typespec/emitter-framework/typescript";
|
|
5
5
|
import * as cl from "@typespec/http-client";
|
|
6
6
|
import { useClientLibrary } from "@typespec/http-client";
|
|
@@ -13,6 +13,7 @@ import { getOperationParameters } from "./operation-parameters.jsx";
|
|
|
13
13
|
export interface ClientProps {}
|
|
14
14
|
|
|
15
15
|
export function Client(props: ClientProps) {
|
|
16
|
+
const { $ } = useTsp();
|
|
16
17
|
const namePolicy = ts.useTSNamePolicy();
|
|
17
18
|
const { topLevel } = useClientLibrary();
|
|
18
19
|
|
|
@@ -45,6 +46,7 @@ function getClientContextFieldRef(client: cl.Client) {
|
|
|
45
46
|
return ay.refkey(client.type, "client-context");
|
|
46
47
|
}
|
|
47
48
|
export function ClientClass(props: ClientClassProps) {
|
|
49
|
+
const { $ } = useTsp();
|
|
48
50
|
const namePolicy = ts.useTSNamePolicy();
|
|
49
51
|
const clientName = namePolicy.getName($.client.getName(props.client), "class");
|
|
50
52
|
const contextMemberRef = getClientContextFieldRef(props.client);
|
|
@@ -103,6 +105,7 @@ function getSubClientClassFieldRef(client: cl.Client) {
|
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
function SubClientClassField(props: SubClientClassFieldProps) {
|
|
108
|
+
const { $ } = useTsp();
|
|
106
109
|
const parent = props.client.parent;
|
|
107
110
|
// If sub client has different parameters than client, don't add it as a subclass field
|
|
108
111
|
// Todo: We need to detect the extra parameters and make this field a factory for the subclient
|
|
@@ -122,6 +125,7 @@ interface ClientConstructorProps {
|
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
function ClientConstructor(props: ClientConstructorProps) {
|
|
128
|
+
const { $ } = useTsp();
|
|
125
129
|
const subClients = props.client.subClients.filter((sc) =>
|
|
126
130
|
$.client.haveSameConstructor(sc, props.client),
|
|
127
131
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Children, code, For, List, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { isVoidType } from "@typespec/compiler";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
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";
|
|
@@ -26,6 +26,7 @@ export interface HttpResponsesProps {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function HttpResponses(props: HttpResponsesProps) {
|
|
29
|
+
const { $ } = useTsp();
|
|
29
30
|
// Handle response by status code and content type
|
|
30
31
|
const responses = $.httpOperation.flattenResponses(props.httpOperation);
|
|
31
32
|
return (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { For, refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
5
|
import { useClientLibrary } from "@typespec/http-client";
|
|
6
6
|
import { getFileTypeReference } from "./static-helpers/multipart-helpers.jsx";
|
|
@@ -10,6 +10,7 @@ export interface ModelsProps {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function Models(props: ModelsProps) {
|
|
13
|
+
const { $ } = useTsp();
|
|
13
14
|
const clientLibrary = useClientLibrary();
|
|
14
15
|
const dataTypes = clientLibrary.dataTypes;
|
|
15
16
|
return (
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { PagingOperation } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
2
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
3
3
|
import { TypeExpression } from "@typespec/emitter-framework/typescript";
|
|
4
4
|
|
|
5
5
|
export function getPageItemTypeName(pagingOperation: PagingOperation) {
|
|
6
|
+
const { $ } = useTsp();
|
|
6
7
|
const type = pagingOperation.output.pageItems.property.type;
|
|
7
8
|
// only accept array type
|
|
8
9
|
if (type.kind === "Model" && $.array.is(type)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import { Children } from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
5
5
|
import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
|
|
6
6
|
import { HttpOperation } from "@typespec/http";
|
|
7
7
|
import * as cl from "@typespec/http-client";
|
|
@@ -30,10 +30,12 @@ import { OperationHandler } from "../types.js";
|
|
|
30
30
|
|
|
31
31
|
export const PaginatedOperationHandler: OperationHandler = {
|
|
32
32
|
canHandle(httpOperation: HttpOperation): boolean {
|
|
33
|
+
const { $ } = useTsp();
|
|
33
34
|
const pagingMetadata = $.operation.getPagingMetadata(httpOperation.operation);
|
|
34
35
|
return pagingMetadata !== undefined;
|
|
35
36
|
},
|
|
36
37
|
handle(httpOperation: HttpOperation): Children {
|
|
38
|
+
const { $ } = useTsp();
|
|
37
39
|
const clientLibrary = cl.useClientLibrary();
|
|
38
40
|
const client = clientLibrary.getClientForOperation(httpOperation);
|
|
39
41
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import {
|
|
4
|
-
import { TransformNamePolicyContext } from "@typespec/emitter-framework";
|
|
3
|
+
import { Program } from "@typespec/compiler";
|
|
4
|
+
import { Output as EFOutput, TransformNamePolicyContext } from "@typespec/emitter-framework";
|
|
5
5
|
import { ClientLibrary } from "@typespec/http-client/components";
|
|
6
6
|
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
7
7
|
import { httpRuntimeTemplateLib } from "./external-packages/ts-http-runtime.js";
|
|
@@ -10,18 +10,23 @@ import { createTransformNamePolicy } from "./transforms/transform-name-policy.js
|
|
|
10
10
|
|
|
11
11
|
export interface OutputProps {
|
|
12
12
|
children?: ay.Children;
|
|
13
|
+
program: Program;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export function Output(props: OutputProps) {
|
|
16
17
|
const tsNamePolicy = ts.createTSNamePolicy();
|
|
17
18
|
const defaultTransformNamePolicy = createTransformNamePolicy();
|
|
18
19
|
return (
|
|
19
|
-
<
|
|
20
|
-
|
|
20
|
+
<EFOutput
|
|
21
|
+
namePolicy={tsNamePolicy}
|
|
22
|
+
externals={[uriTemplateLib, httpRuntimeTemplateLib]}
|
|
23
|
+
program={props.program}
|
|
24
|
+
>
|
|
25
|
+
<ClientLibrary program={props.program}>
|
|
21
26
|
<TransformNamePolicyContext.Provider value={defaultTransformNamePolicy}>
|
|
22
27
|
<EncodingProvider>{props.children}</EncodingProvider>
|
|
23
28
|
</TransformNamePolicyContext.Provider>
|
|
24
29
|
</ClientLibrary>
|
|
25
|
-
</
|
|
30
|
+
</EFOutput>
|
|
26
31
|
);
|
|
27
32
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as ts from "@alloy-js/typescript";
|
|
2
2
|
import { Type } from "@typespec/compiler";
|
|
3
|
-
import {
|
|
3
|
+
import type { Typekit } from "@typespec/compiler/experimental/typekit";
|
|
4
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
5
|
import {
|
|
5
6
|
DateDeserializer,
|
|
6
7
|
DateRfc3339Serializer,
|
|
@@ -20,6 +21,7 @@ export interface ModelSerializersProps {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export function ModelSerializers(props: ModelSerializersProps) {
|
|
24
|
+
const { $ } = useTsp();
|
|
23
25
|
const clientLibrary = useClientLibrary();
|
|
24
26
|
const dataTypes = clientLibrary.dataTypes;
|
|
25
27
|
const flatClients = clientLibrary.topLevel.flatMap((c) => flattenClients(c));
|
|
@@ -44,7 +46,7 @@ export function ModelSerializers(props: ModelSerializersProps) {
|
|
|
44
46
|
.filter((m) => m.kind === "Model" || m.kind === "Union")
|
|
45
47
|
.map((type) => {
|
|
46
48
|
let bytesDefaultEncoding: "base64" | "none" = "base64";
|
|
47
|
-
if (isOrExtendsFile(type)) {
|
|
49
|
+
if (isOrExtendsFile($, type)) {
|
|
48
50
|
bytesDefaultEncoding = "none";
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -59,7 +61,7 @@ export function ModelSerializers(props: ModelSerializersProps) {
|
|
|
59
61
|
);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
function isOrExtendsFile(type: Type): boolean {
|
|
64
|
+
function isOrExtendsFile($: Typekit, type: Type): boolean {
|
|
63
65
|
if (!$.model.is(type)) {
|
|
64
66
|
return false;
|
|
65
67
|
}
|
|
@@ -68,5 +70,5 @@ function isOrExtendsFile(type: Type): boolean {
|
|
|
68
70
|
return true;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
return type.baseModel ? isOrExtendsFile(type.baseModel) : false;
|
|
73
|
+
return type.baseModel ? isOrExtendsFile($, type.baseModel) : false;
|
|
72
74
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { EncodeData, ModelProperty, Scalar } from "@typespec/compiler";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { reportDiagnostic } from "../../lib.js";
|
|
5
5
|
import { unpackProperty } from "../utils/unpack-model-property.js";
|
|
6
6
|
import { getScalarTransformer } from "./scalar-transform.jsx";
|
|
@@ -12,6 +12,7 @@ export interface ScalarDataTransformProps {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function ScalarDataTransform(props: ScalarDataTransformProps) {
|
|
15
|
+
const { $ } = useTsp();
|
|
15
16
|
let scalar: Scalar;
|
|
16
17
|
let encoding: EncodeData | undefined;
|
|
17
18
|
if ($.modelProperty.is(props.type)) {
|
|
@@ -3,7 +3,7 @@ import * as ts from "@alloy-js/typescript";
|
|
|
3
3
|
import * as ef from "@typespec/emitter-framework/typescript";
|
|
4
4
|
|
|
5
5
|
import { Model } from "@typespec/compiler";
|
|
6
|
-
import {
|
|
6
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
7
7
|
import { JsonTransform } from "./json-transform.jsx";
|
|
8
8
|
|
|
9
9
|
export interface JsonArrayTransformProps {
|
|
@@ -13,6 +13,7 @@ export interface JsonArrayTransformProps {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function JsonArrayTransform(props: JsonArrayTransformProps) {
|
|
16
|
+
const { $ } = useTsp();
|
|
16
17
|
if (!$.array.is(props.type)) {
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
@@ -47,6 +48,7 @@ export interface JsonArrayTransformDeclarationProps {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export function JsonArrayTransformDeclaration(props: JsonArrayTransformDeclarationProps) {
|
|
51
|
+
const { $ } = useTsp();
|
|
50
52
|
if (!$.array.is(props.type)) {
|
|
51
53
|
return null;
|
|
52
54
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { Model } from "@typespec/compiler";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
5
5
|
import { getJsonRecordTransformRefkey } from "./json-record-transform.jsx";
|
|
6
6
|
|
|
7
7
|
export interface JsonAdditionalPropertiesTransformProps {
|
|
@@ -11,6 +11,7 @@ export interface JsonAdditionalPropertiesTransformProps {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function JsonAdditionalPropertiesTransform(props: JsonAdditionalPropertiesTransformProps) {
|
|
14
|
+
const { $ } = useTsp();
|
|
14
15
|
const additionalProperties = $.model.getAdditionalPropertiesRecord(props.type);
|
|
15
16
|
|
|
16
17
|
if (!additionalProperties) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { ModelProperty } from "@typespec/compiler";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
5
5
|
import { unpackProperty } from "../../utils/unpack-model-property.js";
|
|
6
6
|
import { ScalarDataTransform } from "../data-transform.jsx";
|
|
7
7
|
import { useTransformNamePolicy } from "../transform-name-policy.js";
|
|
@@ -14,6 +14,7 @@ export interface JsonModelPropertyTransformProps {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function JsonModelPropertyTransform(props: JsonModelPropertyTransformProps) {
|
|
17
|
+
const { $ } = useTsp();
|
|
17
18
|
const transformNamer = useTransformNamePolicy();
|
|
18
19
|
const propertyValueType = unpackProperty(props.type);
|
|
19
20
|
|
|
@@ -2,7 +2,7 @@ import * as ay from "@alloy-js/core";
|
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
|
|
4
4
|
import { Model } from "@typespec/compiler";
|
|
5
|
-
import {
|
|
5
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
6
6
|
import { JsonAdditionalPropertiesTransform } from "./json-model-additional-properties-transform.jsx";
|
|
7
7
|
import { JsonModelPropertyTransform } from "./json-model-property-transform.jsx";
|
|
8
8
|
import { JsonRecordTransformDeclaration } from "./json-record-transform.jsx";
|
|
@@ -18,6 +18,7 @@ export interface JsonModelTransformProps {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function JsonModelTransform(props: JsonModelTransformProps) {
|
|
21
|
+
const { $ } = useTsp();
|
|
21
22
|
// Need to skip never properties
|
|
22
23
|
const properties = Array.from(
|
|
23
24
|
$.model.getProperties(props.type, { includeExtended: true }).values(),
|
|
@@ -69,6 +70,7 @@ export interface JsonModelTransformDeclarationProps {
|
|
|
69
70
|
export function JsonModelTransformDeclaration(
|
|
70
71
|
props: JsonModelTransformDeclarationProps,
|
|
71
72
|
): ay.Children {
|
|
73
|
+
const { $ } = useTsp();
|
|
72
74
|
const namePolicy = ts.useTSNamePolicy();
|
|
73
75
|
const transformName = namePolicy.getName(
|
|
74
76
|
`json_${props.type.name}_to_${props.target}_transform`,
|
|
@@ -2,7 +2,7 @@ import * as ay from "@alloy-js/core";
|
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
|
|
4
4
|
import { Model } from "@typespec/compiler";
|
|
5
|
-
import {
|
|
5
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
6
6
|
import { JsonTransform } from "./json-transform.jsx";
|
|
7
7
|
|
|
8
8
|
export interface JsonRecordTransformProps {
|
|
@@ -12,6 +12,7 @@ export interface JsonRecordTransformProps {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function JsonRecordTransform(props: JsonRecordTransformProps) {
|
|
15
|
+
const { $ } = useTsp();
|
|
15
16
|
if (!$.record.is(props.type)) {
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
@@ -48,6 +49,7 @@ export interface JsonRecordTransformDeclarationProps {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
export function JsonRecordTransformDeclaration(props: JsonRecordTransformDeclarationProps) {
|
|
52
|
+
const { $ } = useTsp();
|
|
51
53
|
if (!$.record.is(props.type)) {
|
|
52
54
|
return null;
|
|
53
55
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { Discriminator, Model, Union } from "@typespec/compiler";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
5
5
|
import { JsonTransform } from "./json-transform.jsx";
|
|
6
6
|
|
|
7
7
|
export interface JsonTransformDiscriminatorProps {
|
|
@@ -12,6 +12,7 @@ export interface JsonTransformDiscriminatorProps {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function JsonTransformDiscriminator(props: JsonTransformDiscriminatorProps) {
|
|
15
|
+
const { $ } = useTsp();
|
|
15
16
|
const discriminatedUnion = $.model.is(props.type)
|
|
16
17
|
? $.model.getDiscriminatedUnion(props.type)
|
|
17
18
|
: $.union.getDiscriminatedUnion(props.type);
|
|
@@ -62,6 +63,7 @@ export interface JsonTransformDiscriminatorDeclarationProps {
|
|
|
62
63
|
export function JsonTransformDiscriminatorDeclaration(
|
|
63
64
|
props: JsonTransformDiscriminatorDeclarationProps,
|
|
64
65
|
) {
|
|
66
|
+
const { $ } = useTsp();
|
|
65
67
|
const discriminator = $.type.getDiscriminator(props.type);
|
|
66
68
|
if (!discriminator) {
|
|
67
69
|
return null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import { Type } from "@typespec/compiler";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { ScalarDataTransform } from "../data-transform.jsx";
|
|
5
5
|
import {
|
|
6
6
|
getJsonArrayTransformRefkey,
|
|
@@ -31,6 +31,7 @@ export interface JsonTransformProps {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function JsonTransform(props: JsonTransformProps) {
|
|
34
|
+
const { $ } = useTsp();
|
|
34
35
|
const type = $.httpPart.unpack(props.type) ?? props.type;
|
|
35
36
|
const declaredTransform = getTransformReference(type, props.target);
|
|
36
37
|
|
|
@@ -71,6 +72,7 @@ export interface JsonTransformDeclarationProps {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
export function JsonTransformDeclaration(props: JsonTransformDeclarationProps) {
|
|
75
|
+
const { $ } = useTsp();
|
|
74
76
|
if (!$.model.is(props.type) && !$.union.is(props.type)) {
|
|
75
77
|
return null;
|
|
76
78
|
}
|
|
@@ -96,6 +98,7 @@ function getTransformReference(
|
|
|
96
98
|
type: Type,
|
|
97
99
|
target: "transport" | "application",
|
|
98
100
|
): ay.Refkey | undefined {
|
|
101
|
+
const { $ } = useTsp();
|
|
99
102
|
if (type.kind === "Model" && Boolean(type.name)) {
|
|
100
103
|
if ($.array.is(type)) {
|
|
101
104
|
return getJsonArrayTransformRefkey(type, target);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { Union } from "@typespec/compiler";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
5
5
|
import {
|
|
6
6
|
getJsonTransformDiscriminatorRefkey,
|
|
7
7
|
JsonTransformDiscriminatorDeclaration,
|
|
@@ -15,6 +15,7 @@ export interface JsonUnionTransformProps {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function JsonUnionTransform(props: JsonUnionTransformProps) {
|
|
18
|
+
const { $ } = useTsp();
|
|
18
19
|
const discriminator = $.type.getDiscriminator(props.type);
|
|
19
20
|
if (discriminator) {
|
|
20
21
|
// return <JsonTransformDiscriminator {...props} discriminator={discriminator}/>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Type } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
2
|
+
import type { Typekit } from "@typespec/compiler/experimental/typekit";
|
|
3
3
|
import { reportDiagnostic } from "../../../../lib.js";
|
|
4
4
|
|
|
5
|
-
export function getJsonTransportName(type: Type) {
|
|
5
|
+
export function getJsonTransportName($: Typekit, type: Type) {
|
|
6
6
|
if (!("name" in type)) {
|
|
7
7
|
reportDiagnostic($.program, { code: "no-name-type", target: type });
|
|
8
8
|
return "";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
|
-
import {
|
|
3
|
-
import { useTransformNamePolicy } from "@typespec/emitter-framework";
|
|
2
|
+
import { useTransformNamePolicy, useTsp } from "@typespec/emitter-framework";
|
|
4
3
|
import { HttpOperationMultipartBody } from "@typespec/http";
|
|
5
4
|
import { reportDiagnostic } from "../../../lib.js";
|
|
6
5
|
import { HttpPartTransform } from "./part-transform.jsx";
|
|
@@ -10,6 +9,7 @@ export interface MultipartTransformProps {
|
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export function MultipartTransform(props: MultipartTransformProps) {
|
|
12
|
+
const { $ } = useTsp();
|
|
13
13
|
const transportNamer = useTransformNamePolicy();
|
|
14
14
|
const httpParts = props.body.parts;
|
|
15
15
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { HttpOperationPart } from "@typespec/http";
|
|
5
5
|
import { reportDiagnostic } from "../../../lib.js";
|
|
6
6
|
import { JsonTransform } from "../json/json-transform.jsx";
|
|
@@ -11,6 +11,7 @@ export interface SimplePartTransformProps {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function SimplePartTransform(props: SimplePartTransformProps) {
|
|
14
|
+
const { $ } = useTsp();
|
|
14
15
|
const namePolicy = ts.useTSNamePolicy();
|
|
15
16
|
const applicationName = namePolicy.getName(props.part.name!, "variable");
|
|
16
17
|
const partName = ts.ValueExpression({ jsValue: props.part.name });
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as ts from "@alloy-js/typescript";
|
|
2
2
|
import { Type } from "@typespec/compiler";
|
|
3
|
-
import {
|
|
4
|
-
import { HasName, TransformNamePolicyContext } from "@typespec/emitter-framework";
|
|
3
|
+
import { HasName, TransformNamePolicyContext, useTsp } from "@typespec/emitter-framework";
|
|
5
4
|
import { HttpOperation } from "@typespec/http";
|
|
6
5
|
import { reportDiagnostic } from "../../lib.js";
|
|
7
6
|
import { ContentTypeEncodingProvider } from "./content-type-encoding-provider.jsx";
|
|
@@ -45,6 +44,7 @@ export function OperationTransformExpression(props: OperationTransformToTranspor
|
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
function payloadApplicationNameGetter(type: HasName<Type>) {
|
|
47
|
+
const { $ } = useTsp();
|
|
48
48
|
if (typeof type.name !== "string") {
|
|
49
49
|
reportDiagnostic($.program, { code: "symbol-name-not-supported", target: type });
|
|
50
50
|
return "";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Children, code, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { BytesKnownEncoding, EncodeData, NoTarget, Scalar } from "@typespec/compiler";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
5
|
import { useDefaultEncoding } from "../../context/encoding/encoding-context.jsx";
|
|
6
6
|
import { reportDiagnostic } from "../../lib.js";
|
|
@@ -46,6 +46,7 @@ const scalarTransformerMap = defineScalarTransformerMap({
|
|
|
46
46
|
|
|
47
47
|
bytes: {
|
|
48
48
|
toTransport: (itemRef, encoding) => {
|
|
49
|
+
const { $ } = useTsp();
|
|
49
50
|
const bytesEncoding: BytesKnownEncoding | undefined =
|
|
50
51
|
(encoding?.encoding as BytesKnownEncoding) ??
|
|
51
52
|
(useDefaultEncoding("bytes") as BytesKnownEncoding);
|
|
@@ -63,6 +64,7 @@ const scalarTransformerMap = defineScalarTransformerMap({
|
|
|
63
64
|
}
|
|
64
65
|
},
|
|
65
66
|
toApplication: (itemRef, encoding) => {
|
|
67
|
+
const { $ } = useTsp();
|
|
66
68
|
const bytesEncoding: BytesKnownEncoding | undefined =
|
|
67
69
|
(encoding?.encoding as BytesKnownEncoding) ??
|
|
68
70
|
(useDefaultEncoding("bytes") as BytesKnownEncoding);
|
|
@@ -169,6 +171,7 @@ const scalarTransformerMap = defineScalarTransformerMap({
|
|
|
169
171
|
},
|
|
170
172
|
utcDateTime: {
|
|
171
173
|
toTransport: (itemRef, encoding) => {
|
|
174
|
+
const { $ } = useTsp();
|
|
172
175
|
const dateEncoding = encoding?.encoding ?? useDefaultEncoding("datetime");
|
|
173
176
|
let encodingFnRef: Refkey = ef.DateRfc3339SerializerRefkey;
|
|
174
177
|
switch (dateEncoding) {
|
|
@@ -190,6 +193,7 @@ const scalarTransformerMap = defineScalarTransformerMap({
|
|
|
190
193
|
return code`${encodingFnRef}(${itemRef})`;
|
|
191
194
|
},
|
|
192
195
|
toApplication: (itemRef, encoding) => {
|
|
196
|
+
const { $ } = useTsp();
|
|
193
197
|
const dateEncoding = encoding?.encoding ?? useDefaultEncoding("datetime");
|
|
194
198
|
let decodingFnRef: Refkey = ef.DateDeserializerRefkey;
|
|
195
199
|
switch (dateEncoding) {
|
|
@@ -237,36 +241,42 @@ const scalarTransformerMap = defineScalarTransformerMap({
|
|
|
237
241
|
*/
|
|
238
242
|
type ScalarTest = (type: Scalar) => boolean;
|
|
239
243
|
|
|
240
|
-
|
|
241
|
-
{
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
key: "
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
244
|
+
function getScalarTests(): { key: keyof typeof scalarTransformerMap; test: ScalarTest }[] {
|
|
245
|
+
const { $ } = useTsp();
|
|
246
|
+
return [
|
|
247
|
+
{ key: "boolean", test: (t) => $.scalar.isBoolean(t) || $.scalar.extendsBoolean(t) },
|
|
248
|
+
{ key: "bytes", test: (t) => $.scalar.isBytes(t) || $.scalar.extendsBytes(t) },
|
|
249
|
+
{ key: "decimal", test: (t) => $.scalar.isDecimal(t) || $.scalar.extendsDecimal(t) },
|
|
250
|
+
{ key: "decimal128", test: (t) => $.scalar.isDecimal128(t) || $.scalar.extendsDecimal128(t) },
|
|
251
|
+
{ key: "duration", test: (t) => $.scalar.isDuration(t) || $.scalar.extendsDuration(t) },
|
|
252
|
+
{ key: "float", test: (t) => $.scalar.isFloat(t) || $.scalar.extendsFloat(t) },
|
|
253
|
+
{ key: "float32", test: (t) => $.scalar.isFloat32(t) || $.scalar.extendsFloat32(t) },
|
|
254
|
+
{ key: "float64", test: (t) => $.scalar.isFloat64(t) || $.scalar.extendsFloat64(t) },
|
|
255
|
+
{ key: "int16", test: (t) => $.scalar.isInt16(t) || $.scalar.extendsInt16(t) },
|
|
256
|
+
{ key: "int32", test: (t) => $.scalar.isInt32(t) || $.scalar.extendsInt32(t) },
|
|
257
|
+
{ key: "int64", test: (t) => $.scalar.isInt64(t) || $.scalar.extendsInt64(t) },
|
|
258
|
+
{ key: "int8", test: (t) => $.scalar.isInt8(t) || $.scalar.extendsInt8(t) },
|
|
259
|
+
{ key: "integer", test: (t) => $.scalar.isInteger(t) || $.scalar.extendsInteger(t) },
|
|
260
|
+
{ key: "numeric", test: (t) => $.scalar.isNumeric(t) || $.scalar.extendsNumeric(t) },
|
|
261
|
+
{
|
|
262
|
+
key: "offsetDateTime",
|
|
263
|
+
test: (t) => $.scalar.isOffsetDateTime(t) || $.scalar.extendsOffsetDateTime(t),
|
|
264
|
+
},
|
|
265
|
+
{ key: "plainDate", test: (t) => $.scalar.isPlainDate(t) || $.scalar.extendsPlainDate(t) },
|
|
266
|
+
{ key: "plainTime", test: (t) => $.scalar.isPlainTime(t) || $.scalar.extendsPlainTime(t) },
|
|
267
|
+
{ key: "safeint", test: (t) => $.scalar.isSafeint(t) || $.scalar.extendsSafeint(t) },
|
|
268
|
+
{ key: "string", test: (t) => $.scalar.isString(t) || $.scalar.extendsString(t) },
|
|
269
|
+
{ key: "uint16", test: (t) => $.scalar.isUint16(t) || $.scalar.extendsUint16(t) },
|
|
270
|
+
{ key: "uint32", test: (t) => $.scalar.isUint32(t) || $.scalar.extendsUint32(t) },
|
|
271
|
+
{ key: "uint64", test: (t) => $.scalar.isUint64(t) || $.scalar.extendsUint64(t) },
|
|
272
|
+
{ key: "uint8", test: (t) => $.scalar.isUint8(t) || $.scalar.extendsUint8(t) },
|
|
273
|
+
{ key: "url", test: (t) => $.scalar.isUrl(t) || $.scalar.extendsUrl(t) },
|
|
274
|
+
{
|
|
275
|
+
key: "utcDateTime",
|
|
276
|
+
test: (t) => $.scalar.isUtcDateTime(t) || $.scalar.extendsUtcDateTime(t),
|
|
277
|
+
},
|
|
278
|
+
];
|
|
279
|
+
}
|
|
270
280
|
|
|
271
281
|
/**
|
|
272
282
|
* Determines the key to use in the scalarTransformerMap for the given scalar type.
|
|
@@ -276,7 +286,7 @@ const scalarTests: { key: keyof typeof scalarTransformerMap; test: ScalarTest }[
|
|
|
276
286
|
* @throws Error if the scalar type is unknown.
|
|
277
287
|
*/
|
|
278
288
|
function getScalarTransformKey(type: Scalar): keyof typeof scalarTransformerMap {
|
|
279
|
-
for (const { key, test } of
|
|
289
|
+
for (const { key, test } of getScalarTests()) {
|
|
280
290
|
if (test(type)) {
|
|
281
291
|
return key;
|
|
282
292
|
}
|