@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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as ts from "@alloy-js/typescript";
|
|
2
2
|
import { Type } from "@typespec/compiler";
|
|
3
|
-
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
3
|
import * as ef from "@typespec/emitter-framework";
|
|
5
4
|
import { kebabCase } from "change-case";
|
|
6
5
|
import { reportDiagnostic } from "../../lib.js";
|
|
@@ -88,6 +87,7 @@ export function createTransformNamePolicy(namers: TransformNamers = {}): ef.Tran
|
|
|
88
87
|
* @returns The transformed application name as a string.
|
|
89
88
|
*/
|
|
90
89
|
export function defaultApplicationNameGetter(type: WithName): string {
|
|
90
|
+
const { $ } = ef.useTsp();
|
|
91
91
|
if (!hasStringName(type)) {
|
|
92
92
|
reportDiagnostic($.program, { code: "symbol-name-not-supported", target: type });
|
|
93
93
|
return "";
|
|
@@ -110,6 +110,7 @@ export function defaultTransportNameGetter(
|
|
|
110
110
|
type: WithName,
|
|
111
111
|
encoding: string = "application/json",
|
|
112
112
|
): string {
|
|
113
|
+
const { $ } = ef.useTsp();
|
|
113
114
|
if (!hasStringName(type)) {
|
|
114
115
|
reportDiagnostic($.program, { code: "symbol-name-not-supported", target: type });
|
|
115
116
|
return "";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNullType, ModelProperty, Type } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
2
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Sometimes a model property type would be another ModelProperty in this case we need to keep unpacking until we find a non Model Property
|
|
@@ -7,6 +7,7 @@ import { $ } from "@typespec/compiler/experimental/typekit";
|
|
|
7
7
|
* This also handles an HttpPart which needs to be unpacked as well.
|
|
8
8
|
*/
|
|
9
9
|
export function unpackProperty(modelProperty: ModelProperty): Type {
|
|
10
|
+
const { $ } = useTsp();
|
|
10
11
|
const type = $.httpPart.unpack(modelProperty.type) ?? modelProperty.type;
|
|
11
12
|
if ($.modelProperty.is(type)) {
|
|
12
13
|
return unpackProperty(type);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentContext, createNamedContext, useContext } from "@alloy-js/core";
|
|
2
2
|
import { NoTarget } from "@typespec/compiler";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
4
4
|
import { reportDiagnostic } from "../../lib.js";
|
|
5
5
|
import { EncodingDefaults } from "./types.js";
|
|
6
6
|
|
|
@@ -9,6 +9,7 @@ export const EncodingContext: ComponentContext<EncodingDefaults> =
|
|
|
9
9
|
|
|
10
10
|
export function useEncoding() {
|
|
11
11
|
const context = useContext(EncodingContext);
|
|
12
|
+
const { $ } = useTsp();
|
|
12
13
|
|
|
13
14
|
if (!context) {
|
|
14
15
|
reportDiagnostic($.program, {
|
package/src/emitter.tsx
CHANGED
|
@@ -20,7 +20,7 @@ import { JsClientEmitterOptions } from "./lib.js";
|
|
|
20
20
|
export async function $onEmit(context: EmitContext<JsClientEmitterOptions>) {
|
|
21
21
|
const packageName = context.options["package-name"] ?? "test-package";
|
|
22
22
|
const output = (
|
|
23
|
-
<Output>
|
|
23
|
+
<Output program={context.program}>
|
|
24
24
|
<ts.PackageDirectory
|
|
25
25
|
name={packageName}
|
|
26
26
|
version="1.0.0"
|
|
@@ -54,5 +54,5 @@ export async function $onEmit(context: EmitContext<JsClientEmitterOptions>) {
|
|
|
54
54
|
</Output>
|
|
55
55
|
);
|
|
56
56
|
|
|
57
|
-
await writeOutput(output, context.emitterOutputDir);
|
|
57
|
+
await writeOutput(context.program, output, context.emitterOutputDir);
|
|
58
58
|
}
|
package/src/utils/multipart.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Type } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
2
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
3
3
|
import { reportDiagnostic } from "../lib.js";
|
|
4
4
|
|
|
5
5
|
export function isMultipart(type: Type): boolean {
|
|
6
|
+
const { $ } = useTsp();
|
|
6
7
|
const body = type;
|
|
7
8
|
|
|
8
9
|
if (!$.model.is(body)) {
|
package/src/utils/operations.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { Model, ModelProperty, Operation, Union } from "@typespec/compiler";
|
|
2
2
|
import {
|
|
3
|
+
unsafe_$ as $,
|
|
3
4
|
unsafe_mutateSubgraph as mutateSubgraph,
|
|
4
5
|
unsafe_Mutator as Mutator,
|
|
5
6
|
unsafe_MutatorFlow as MutatorFlow,
|
|
6
7
|
unsafe_MutatorRecord,
|
|
7
8
|
} from "@typespec/compiler/experimental";
|
|
8
|
-
import {
|
|
9
|
+
import type { Typekit } from "@typespec/compiler/experimental/typekit";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Prepares operation for client representation. This includes adding an options bag for optional parameters.
|
|
12
13
|
* @param operation operation to be prepared
|
|
13
14
|
* @returns the prepared operation
|
|
14
15
|
*/
|
|
15
|
-
export function prepareOperation(operation: Operation): Operation {
|
|
16
|
+
export function prepareOperation($: Typekit, operation: Operation): Operation {
|
|
16
17
|
return mutateSubgraph($.program, [httpParamsMutator], operation).type as Operation;
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -23,9 +24,9 @@ const anonymousMutatorRecord: unsafe_MutatorRecord<Model | Union> = {
|
|
|
23
24
|
filter(t) {
|
|
24
25
|
return MutatorFlow.MutateAndRecur;
|
|
25
26
|
},
|
|
26
|
-
mutate(t, clone) {
|
|
27
|
+
mutate(t, clone, _program, realm) {
|
|
27
28
|
if (!clone.name) {
|
|
28
|
-
clone.name =
|
|
29
|
+
clone.name = $(realm).type.getPlausibleName(clone);
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
};
|
|
@@ -46,10 +47,11 @@ export const httpParamsMutator: Mutator = {
|
|
|
46
47
|
return MutatorFlow.DoNotRecur;
|
|
47
48
|
},
|
|
48
49
|
mutate(o, clone, _program, realm) {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
50
|
+
const tk = $(realm);
|
|
51
|
+
const httpOperation = tk.httpOperation.get(o);
|
|
52
|
+
const returnType = tk.httpOperation.getReturnType(httpOperation);
|
|
51
53
|
clone.returnType = returnType;
|
|
52
|
-
const params =
|
|
54
|
+
const params = tk.httpRequest.getParameters(httpOperation, [
|
|
53
55
|
"query",
|
|
54
56
|
"header",
|
|
55
57
|
"path",
|
|
@@ -73,18 +75,18 @@ export const httpParamsMutator: Mutator = {
|
|
|
73
75
|
{} as Record<string, ModelProperty>,
|
|
74
76
|
);
|
|
75
77
|
|
|
76
|
-
const optionsBag =
|
|
78
|
+
const optionsBag = tk.model.create({
|
|
77
79
|
properties: optionals,
|
|
78
80
|
});
|
|
79
81
|
|
|
80
|
-
const optionsProp =
|
|
82
|
+
const optionsProp = tk.modelProperty.create({
|
|
81
83
|
name: "options",
|
|
82
84
|
type: optionsBag,
|
|
83
85
|
optional: true,
|
|
84
86
|
});
|
|
85
87
|
|
|
86
88
|
for (const [key, prop] of clone.parameters.properties) {
|
|
87
|
-
if (prop.optional || isConstantHeader(prop)) {
|
|
89
|
+
if (prop.optional || isConstantHeader(tk, prop)) {
|
|
88
90
|
clone.parameters.properties.delete(key);
|
|
89
91
|
}
|
|
90
92
|
}
|
|
@@ -96,7 +98,7 @@ export const httpParamsMutator: Mutator = {
|
|
|
96
98
|
},
|
|
97
99
|
};
|
|
98
100
|
|
|
99
|
-
export function isConstantHeader(modelProperty: ModelProperty) {
|
|
101
|
+
export function isConstantHeader($: Typekit, modelProperty: ModelProperty) {
|
|
100
102
|
if (!$.modelProperty.isHttpHeader(modelProperty)) {
|
|
101
103
|
return false;
|
|
102
104
|
}
|
package/src/utils/parameters.tsx
CHANGED
|
@@ -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, Value } from "@typespec/compiler";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "@typespec/emitter-framework";
|
|
5
5
|
import { buildParameterDescriptor } from "@typespec/emitter-framework/typescript";
|
|
6
6
|
import { HttpAuth, HttpProperty, OAuth2FlowType } from "@typespec/http";
|
|
7
7
|
import * as cl from "@typespec/http-client";
|
|
@@ -9,6 +9,7 @@ import { getClientContextOptionsRef } from "../components/client-context/client-
|
|
|
9
9
|
import { httpRuntimeTemplateLib } from "../components/external-packages/ts-http-runtime.js";
|
|
10
10
|
|
|
11
11
|
export function buildClientParameters(client: cl.Client): ts.ParameterDescriptor[] {
|
|
12
|
+
const { $ } = useTsp();
|
|
12
13
|
const clientConstructor = $.client.getConstructor(client);
|
|
13
14
|
const parameters = $.operation.getClientSignature(client, clientConstructor);
|
|
14
15
|
const params = parameters.flatMap(
|
|
@@ -42,6 +43,7 @@ export function buildClientParameters(client: cl.Client): ts.ParameterDescriptor
|
|
|
42
43
|
function buildClientParameterDescriptor(
|
|
43
44
|
modelProperty: ModelProperty,
|
|
44
45
|
): ts.ParameterDescriptor | undefined {
|
|
46
|
+
const { $ } = useTsp();
|
|
45
47
|
const authSchemes = $.modelProperty.getCredentialAuth(modelProperty);
|
|
46
48
|
|
|
47
49
|
if (authSchemes) {
|