@typespec/http-client-js 0.2.0-dev.9 → 0.3.0-dev.0

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.
Files changed (30) hide show
  1. package/.github/copilot-instructions.md +193 -0
  2. package/CHANGELOG.md +21 -0
  3. package/dist/src/components/output.d.ts.map +1 -1
  4. package/dist/src/components/output.js +0 -2
  5. package/dist/src/components/output.js.map +1 -1
  6. package/dist/tsconfig.tsbuildinfo +1 -1
  7. package/package.json +12 -9
  8. package/src/components/output.tsx +1 -2
  9. package/test/e2e/http/type/property/additional-properties/spreads.test.ts +0 -27
  10. package/test/scenarios/auth/basic_auth.md +1 -3
  11. package/test/scenarios/auth/bearer.md +1 -3
  12. package/test/scenarios/auth/client_parameters.md +1 -3
  13. package/test/scenarios/auth/client_structure.md +1 -3
  14. package/test/scenarios/auth/key_credential.md +1 -3
  15. package/test/scenarios/auth/sub_client_override.md +1 -3
  16. package/test/scenarios/client/client_context.md +1 -3
  17. package/test/scenarios/client/dotted_namespace.md +1 -3
  18. package/test/scenarios/client/nested_client.md +1 -3
  19. package/test/scenarios/client/wrapping_namespace.md +1 -3
  20. package/test/scenarios/http-operations/basic-request.md +3 -9
  21. package/test/scenarios/http-operations/basic-response.md +4 -12
  22. package/test/scenarios/http-operations/path-parameter-in-model.md +1 -3
  23. package/test/scenarios/http-operations/path-parameter.md +1 -3
  24. package/test/scenarios/http-operations/scalar-payload.md +1 -3
  25. package/test/scenarios/http-operations/with-parameters.md +1 -3
  26. package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +1 -3
  27. package/test/scenarios/serializers/spread.md +1 -3
  28. package/test/scenarios/serializers/string_union.md +1 -3
  29. package/test/scenarios/server/multiple-parameters.md +1 -3
  30. package/test/scenarios/server/parametrized-endpoint.md +1 -3
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@typespec/http-client-js",
3
- "version": "0.2.0-dev.9",
3
+ "version": "0.3.0-dev.0",
4
4
  "type": "module",
5
+ "homepage": "https://typespec.io",
6
+ "readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
5
7
  "exports": {
6
8
  ".": {
7
9
  "types": "./dist/src/index.d.ts",
@@ -24,27 +26,28 @@
24
26
  "license": "MIT",
25
27
  "description": "TypeSpec library for emitting Http Client libraries for JavaScript/TypeScript",
26
28
  "peerDependencies": {
27
- "@typespec/compiler": "^0.66.0 || >=0.67.0-dev <0.67.0",
28
- "@typespec/emitter-framework": "^0.2.0 || >=0.3.0-dev <0.3.0",
29
- "@typespec/http": "^0.66.0 || >=0.67.0-dev <0.67.0",
30
- "@typespec/http-client": "^0.2.0 || >=0.3.0-dev <0.3.0",
31
- "@typespec/rest": "^0.66.0 || >=0.67.0-dev <0.67.0"
29
+ "@typespec/compiler": "^0.67.0 || >=0.68.0-dev <0.68.0",
30
+ "@typespec/http": "^0.67.0 || >=0.68.0-dev <0.68.0",
31
+ "@typespec/rest": "^0.67.0 || >=0.68.0-dev <0.68.0"
32
32
  },
33
33
  "dependencies": {
34
+ "@typespec/emitter-framework": "^0.3.0 || >=0.4.0-dev <0.4.0",
35
+ "@typespec/http-client": "^0.3.0 || >=0.4.0-dev <0.4.0",
34
36
  "@alloy-js/core": "^0.6.0",
35
37
  "@alloy-js/typescript": "^0.6.0",
36
38
  "prettier": "~3.5.3"
37
39
  },
38
40
  "devDependencies": {
41
+ "@typespec/http": "^0.67.0 || >=0.68.0-dev <0.68.0",
39
42
  "@alloy-js/babel-preset": "^0.2.0",
40
43
  "@babel/cli": "^7.24.8",
41
44
  "@babel/core": "^7.26.9",
42
45
  "@rollup/plugin-babel": "^6.0.4",
43
46
  "@types/yargs": "~17.0.33",
44
- "@typespec/http-specs": "^0.1.0-alpha.12 || >=0.1.0-alpha.13-dev <0.1.0-alpha.13",
45
- "@typespec/spector": "^0.1.0-alpha.8 || >=0.1.0-alpha.9-dev <0.1.0-alpha.9",
47
+ "@typespec/http-specs": "^0.1.0-alpha.13 || >=0.1.0-alpha.14-dev <0.1.0-alpha.14",
48
+ "@typespec/spector": "^0.1.0-alpha.9 || >=0.1.0-alpha.10-dev <0.1.0-alpha.10",
46
49
  "@typespec/ts-http-runtime": "0.1.0",
47
- "@typespec/versioning": "^0.66.0 || >=0.67.0-dev <0.67.0",
50
+ "@typespec/versioning": "^0.67.0 || >=0.68.0-dev <0.68.0",
48
51
  "@vitest/ui": "^3.0.7",
49
52
  "picocolors": "~1.1.1",
50
53
  "concurrently": "^9.1.2",
@@ -2,7 +2,6 @@ import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
  import { TransformNamePolicyContext } from "@typespec/emitter-framework";
4
4
  import { ClientLibrary } from "@typespec/http-client/components";
5
- import { httpParamsMutator } from "../utils/operations.js";
6
5
  import { EncodingProvider } from "./encoding-provider.jsx";
7
6
  import { httpRuntimeTemplateLib } from "./external-packages/ts-http-runtime.js";
8
7
  import { uriTemplateLib } from "./external-packages/uri-template.js";
@@ -17,7 +16,7 @@ export function Output(props: OutputProps) {
17
16
  const defaultTransformNamePolicy = createTransformNamePolicy();
18
17
  return (
19
18
  <ay.Output namePolicy={tsNamePolicy} externals={[uriTemplateLib, httpRuntimeTemplateLib]}>
20
- <ClientLibrary operationMutators={[httpParamsMutator]}>
19
+ <ClientLibrary>
21
20
  <TransformNamePolicyContext.Provider value={defaultTransformNamePolicy}>
22
21
  <EncodingProvider>{props.children}</EncodingProvider>
23
22
  </TransformNamePolicyContext.Provider>
@@ -20,8 +20,6 @@ import {
20
20
  SpreadFloatClient,
21
21
  SpreadModelArrayClient,
22
22
  SpreadModelClient,
23
- SpreadRecordDiscriminatedUnionClient,
24
- SpreadRecordForDiscriminatedUnion,
25
23
  SpreadRecordForNonDiscriminatedUnion,
26
24
  SpreadRecordForNonDiscriminatedUnion2,
27
25
  SpreadRecordForNonDiscriminatedUnion3,
@@ -377,31 +375,6 @@ describe("Missing AdditionalProperties Endpoints", () => {
377
375
  });
378
376
  });
379
377
 
380
- /**
381
- * Deprecated @discriminator in unions
382
- */
383
- describe.skip("SpreadRecordDiscriminatedUnion", () => {
384
- const client = new SpreadRecordDiscriminatedUnionClient(clientOptions);
385
- const expected: SpreadRecordForDiscriminatedUnion = {
386
- name: "abc",
387
- additionalProperties: {
388
- prop1: { kind: "kind0", fooProp: "abc" },
389
- prop2: {
390
- kind: "kind1",
391
- start: new Date("2021-01-01T00:00:00Z"),
392
- end: new Date("2021-01-02T00:00:00Z"),
393
- },
394
- },
395
- };
396
- it("GET returns the expected response", async () => {
397
- const response = await client.get();
398
- expect(response).toEqual(expected);
399
- });
400
- it("PUT accepts the expected input", async () => {
401
- await client.put(expected);
402
- });
403
- });
404
-
405
378
  describe("SpreadRecordNonDiscriminatedUnion", () => {
406
379
  const client = new SpreadRecordNonDiscriminatedUnionClient(clientOptions);
407
380
  const expected: SpreadRecordForNonDiscriminatedUnion = {
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a basic authentication scheme co
7
7
  The spec contains a simple service with a Bearer authentication scheme
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(BasicAuth)
14
12
  namespace Test;
15
13
 
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a simple bearer authentication s
7
7
  The spec contains a simple service with a Bearer authentication scheme
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(BearerAuth)
14
12
  namespace Test;
15
13
 
@@ -7,9 +7,7 @@ This test validates that the emitter can generate the correct client signature w
7
7
  The spec contains 2 Schemas Bearer and ApiKey
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(BearerAuth | ApiKeyAuth<ApiKeyLocation.header, "X-API-KEY">)
14
12
  namespace Test;
15
13
 
@@ -3,9 +3,7 @@
3
3
  ## TypeSpec
4
4
 
5
5
  ```tsp
6
- @service({
7
- title: "My API",
8
- })
6
+ @service(#{ title: "My API" })
9
7
  @useAuth(BearerAuth)
10
8
  namespace MyApi;
11
9
 
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a key auth scheme correctly with
7
7
  The spec contains a simple service with a ApiKey authentication scheme
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(ApiKeyAuth<ApiKeyLocation.header, "X-API-KEY">)
14
12
  namespace Test;
15
13
 
@@ -7,9 +7,7 @@ The sub client sets NoAuth to override the auth scheme of the parent
7
7
  The spec contains a client with BasicAuth and a sub client with no auth
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(BasicAuth)
14
12
  namespace Test;
15
13
 
@@ -3,9 +3,7 @@
3
3
  ## TypeSpec
4
4
 
5
5
  ```tsp
6
- @service({
7
- title: "Widget Service",
8
- })
6
+ @service(#{ title: "Widget Service" })
9
7
  namespace DemoService;
10
8
  op foo(): void;
11
9
  ```
@@ -5,9 +5,7 @@
5
5
  A dotted namespace where only the last part has content. The leading namespaces have no operations and a single sub namespace
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "TestService",
10
- })
8
+ @service(#{ title: "TestService" })
11
9
  namespace Foo.Bar.Baz;
12
10
  @get op get(): string[];
13
11
  ```
@@ -5,9 +5,7 @@ This specs nests namespace > namespace > interface
5
5
  ## TypeSpec
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "Widget Service",
10
- })
8
+ @service(#{ title: "Widget Service" })
11
9
  namespace DemoService;
12
10
 
13
11
  model Widget {
@@ -9,9 +9,7 @@ In this scenario the emitter is expected to resolve the root namespace as a clie
9
9
  A dotted namespace where only the last part has stuff
10
10
 
11
11
  ```tsp
12
- @service({
13
- title: "TestService",
14
- })
12
+ @service(#{ title: "TestService" })
15
13
  namespace Foo;
16
14
 
17
15
  @route("/bar")
@@ -5,9 +5,7 @@ This test verifies that a basic `GET` request with no headers, body, or paramete
5
5
  ## TypeSpec
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "Widget Service",
10
- })
8
+ @service(#{ title: "Widget Service" })
11
9
  namespace DemoService;
12
10
 
13
11
  @route("/widgets")
@@ -46,9 +44,7 @@ This test verifies that a `POST` request with headers, a body, and query paramet
46
44
  ## TypeSpec
47
45
 
48
46
  ```tsp
49
- @service({
50
- title: "Widget Service",
51
- })
47
+ @service(#{ title: "Widget Service" })
52
48
  namespace DemoService;
53
49
 
54
50
  @test
@@ -110,9 +106,7 @@ This test verifies that a `GET` request with a scalar body is correctly handled.
110
106
  ## TypeSpec
111
107
 
112
108
  ```tsp
113
- @service({
114
- title: "Widget Service",
115
- })
109
+ @service(#{ title: "Widget Service" })
116
110
  namespace DemoService;
117
111
 
118
112
  @route("/widgets")
@@ -5,9 +5,7 @@ This test verifies that a response with status `204` and no body is correctly ha
5
5
  ## **TypeSpec**
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "Widget Service",
10
- })
8
+ @service(#{ title: "Widget Service" })
11
9
  namespace DemoService;
12
10
 
13
11
  @route("/widgets")
@@ -48,9 +46,7 @@ This test verifies that a response with a body containing a `Widget` model is co
48
46
  ## **TypeSpec**
49
47
 
50
48
  ```tsp
51
- @service({
52
- title: "Widget Service",
53
- })
49
+ @service(#{ title: "Widget Service" })
54
50
  namespace DemoService;
55
51
 
56
52
  @test
@@ -115,9 +111,7 @@ This test verifies that a response with multiple status codes (`200` and `204`)
115
111
  ## **TypeSpec**
116
112
 
117
113
  ```tsp
118
- @service({
119
- title: "Widget Service",
120
- })
114
+ @service(#{ title: "Widget Service" })
121
115
  namespace DemoService;
122
116
 
123
117
  @test
@@ -172,9 +166,7 @@ This test verifies that a response with multiple content types is correctly hand
172
166
  ## **TypeSpec**
173
167
 
174
168
  ```tsp
175
- @service({
176
- title: "Widget Service",
177
- })
169
+ @service(#{ title: "Widget Service" })
178
170
  namespace DemoService;
179
171
 
180
172
  model Widget {
@@ -7,9 +7,7 @@ A request that sends a request with a path parameter as a property of the input
7
7
  The path parameter is a property of a spread model input in the operation signature
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Widget Service",
12
- })
10
+ @service(#{ title: "Widget Service" })
13
11
  namespace DemoService;
14
12
 
15
13
  model ReadParams {
@@ -7,9 +7,7 @@ A request that sends a request with a path parameter directly on the operation s
7
7
  The path parameter is a positional parameter in the operation signature
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Widget Service",
12
- })
10
+ @service(#{ title: "Widget Service" })
13
11
  namespace DemoService;
14
12
 
15
13
  @route("/widgets")
@@ -7,9 +7,7 @@ A request that sends a body payload of scalar type
7
7
  The body is modeled as an explicit body property of type int32
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Widget Service",
12
- })
10
+ @service(#{ title: "Widget Service" })
13
11
  namespace DemoService;
14
12
 
15
13
  @route("/widgets")
@@ -5,9 +5,7 @@ A typical request with path, query header and body parameters. The body is model
5
5
  ## TypeSpec
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "Widget Service",
10
- })
8
+ @service(#{ title: "Widget Service" })
11
9
  namespace DemoService;
12
10
 
13
11
  @test
@@ -5,9 +5,7 @@
5
5
  The following TypeSpec block defines a service and several data models that serve as the foundation for our serializer tests. It starts with a base model, Bird, which uses a discriminator (kind) to support polymorphic behavior. Several derived models—SeaGull, Sparrow, Goose, and Eagle—are declared, each with a specific kind value to enable precise runtime type dispatching. Notably, the Eagle model includes additional complex properties (an array, a record, and a singular instance of Bird) to thoroughly test serialization of nested and compound types. This specification also exposes an HTTP GET endpoint returning a polymorphic Bird instance, ensuring that the generated TypeScript serializers handle these scenarios correctly.
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "Test Service",
10
- })
8
+ @service(#{ title: "Test Service" })
11
9
  namespace Test;
12
10
 
13
11
  @doc("This is base model for polymorphic single level inheritance with a discriminator.")
@@ -3,9 +3,7 @@
3
3
  ## Typespec
4
4
 
5
5
  ```tsp
6
- @service({
7
- title: "Test Service",
8
- })
6
+ @service(#{ title: "Test Service" })
9
7
  namespace Test;
10
8
  alias MultipleRequestParameters = {
11
9
  @path
@@ -3,9 +3,7 @@
3
3
  ## Typespec
4
4
 
5
5
  ```tsp
6
- @service({
7
- title: "Test Service",
8
- })
6
+ @service(#{ title: "Test Service" })
9
7
  namespace Test;
10
8
  union ServerExtensibleEnum {
11
9
  string,
@@ -5,9 +5,7 @@
5
5
  This spec defines a server that has a host template and and endpoint to fill it out.
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "Parametrized Endpoint",
10
- })
8
+ @service(#{ title: "Parametrized Endpoint" })
11
9
  @server(
12
10
  "{endpoint}/server/path/multiple/{apiVersion}",
13
11
  "Test server with path parameters.",
@@ -5,9 +5,7 @@
5
5
  This spec defines a server that has a host template and and endpoint to fill it out.
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "Parametrized Endpoint",
10
- })
8
+ @service(#{ title: "Parametrized Endpoint" })
11
9
  @server(
12
10
  "{foo}/server/path/multiple",
13
11
  "Test server with path parameters.",