@typespec/http-client-js 0.16.2-dev.1 → 0.16.2

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 (225) hide show
  1. package/dist/tsconfig.tsbuildinfo +1 -1
  2. package/package.json +24 -20
  3. package/.github/copilot-instructions.md +0 -180
  4. package/.testignore +0 -19
  5. package/.turbo/turbo-build.log +0 -3
  6. package/CHANGELOG.md +0 -159
  7. package/eng/scripts/calculate-coverage.ts +0 -33
  8. package/eng/scripts/emit-e2e.ts +0 -317
  9. package/eng/scripts/run-e2e-tests.ts +0 -166
  10. package/eng/scripts/tspconfig.yaml +0 -6
  11. package/eng/scripts/upload-spector-results.ts +0 -139
  12. package/src/components/client-context/client-context-declaration.tsx +0 -26
  13. package/src/components/client-context/client-context-factory.tsx +0 -218
  14. package/src/components/client-context/client-context-options.tsx +0 -36
  15. package/src/components/client-context/client-context.tsx +0 -23
  16. package/src/components/client-context/parametrized-endpoint.tsx +0 -51
  17. package/src/components/client-directory.tsx +0 -51
  18. package/src/components/client-operation.tsx +0 -102
  19. package/src/components/client.tsx +0 -177
  20. package/src/components/encoding-provider.tsx +0 -17
  21. package/src/components/external-packages/ts-http-runtime.ts +0 -28
  22. package/src/components/external-packages/uri-template.ts +0 -11
  23. package/src/components/http-request-options.tsx +0 -88
  24. package/src/components/http-request-parameters-expression.tsx +0 -191
  25. package/src/components/http-request.tsx +0 -80
  26. package/src/components/http-response.tsx +0 -74
  27. package/src/components/index.ts +0 -12
  28. package/src/components/models.tsx +0 -26
  29. package/src/components/operation-handlers/index.tsx +0 -2
  30. package/src/components/operation-handlers/operation-pipeline.tsx +0 -33
  31. package/src/components/operation-handlers/paging/page-item.tsx +0 -14
  32. package/src/components/operation-handlers/paging/page-response.tsx +0 -57
  33. package/src/components/operation-handlers/paging/page-settings.tsx +0 -53
  34. package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +0 -200
  35. package/src/components/operation-handlers/paging/request-send.tsx +0 -85
  36. package/src/components/operation-handlers/paging/response-deserialize.tsx +0 -60
  37. package/src/components/operation-handlers/paging/util.ts +0 -70
  38. package/src/components/operation-handlers/types.tsx +0 -18
  39. package/src/components/operation-options.tsx +0 -42
  40. package/src/components/operation-parameters.tsx +0 -44
  41. package/src/components/output.tsx +0 -32
  42. package/src/components/serializers.tsx +0 -74
  43. package/src/components/static-helpers/bytes-encoding.tsx +0 -61
  44. package/src/components/static-helpers/interfaces.tsx +0 -31
  45. package/src/components/static-helpers/multipart-helpers.tsx +0 -80
  46. package/src/components/static-helpers/paging-helper.tsx +0 -202
  47. package/src/components/static-helpers/rest-error.tsx +0 -102
  48. package/src/components/testing/client-options.tsx +0 -30
  49. package/src/components/transforms/content-type-encoding-provider.tsx +0 -26
  50. package/src/components/transforms/data-transform.tsx +0 -40
  51. package/src/components/transforms/json/json-array-transform.tsx +0 -87
  52. package/src/components/transforms/json/json-model-additional-properties-transform.tsx +0 -54
  53. package/src/components/transforms/json/json-model-base-transform.tsx +0 -24
  54. package/src/components/transforms/json/json-model-property-transform.tsx +0 -53
  55. package/src/components/transforms/json/json-model-transform.tsx +0 -115
  56. package/src/components/transforms/json/json-record-transform.tsx +0 -88
  57. package/src/components/transforms/json/json-transform-discriminator.tsx +0 -111
  58. package/src/components/transforms/json/json-transform.tsx +0 -120
  59. package/src/components/transforms/json/union-transform.tsx +0 -87
  60. package/src/components/transforms/json/utils/transport-namer.ts +0 -12
  61. package/src/components/transforms/multipart/array-part-transform.tsx +0 -44
  62. package/src/components/transforms/multipart/file-part-transform.tsx +0 -45
  63. package/src/components/transforms/multipart/multipart-transform.tsx +0 -30
  64. package/src/components/transforms/multipart/part-transform.tsx +0 -22
  65. package/src/components/transforms/multipart/simple-part-transform.tsx +0 -42
  66. package/src/components/transforms/operation-transform-declaration.tsx +0 -83
  67. package/src/components/transforms/operation-transform-expression.tsx +0 -62
  68. package/src/components/transforms/scalar-transform.tsx +0 -301
  69. package/src/components/transforms/transform-name-policy.ts +0 -134
  70. package/src/components/utils/unpack-model-property.ts +0 -44
  71. package/src/components/utils/url-template.tsx +0 -25
  72. package/src/context/encoding/encoding-context.tsx +0 -28
  73. package/src/context/encoding/types.ts +0 -6
  74. package/src/emitter.tsx +0 -85
  75. package/src/index.ts +0 -5
  76. package/src/lib.ts +0 -120
  77. package/src/testing/index.ts +0 -11
  78. package/src/utils/client-discovery.ts +0 -28
  79. package/src/utils/multipart.ts +0 -29
  80. package/src/utils/operations.ts +0 -112
  81. package/src/utils/parameters.tsx +0 -155
  82. package/test/e2e/assets/image.jpg +0 -0
  83. package/test/e2e/assets/image.png +0 -0
  84. package/test/e2e/http/authentication/api-key/main.test.ts +0 -38
  85. package/test/e2e/http/authentication/oauth2/main.test.ts +0 -31
  86. package/test/e2e/http/authentication/union/main.test.ts +0 -26
  87. package/test/e2e/http/encode/bytes/main.test.ts +0 -191
  88. package/test/e2e/http/encode/datetime/main.test.ts +0 -176
  89. package/test/e2e/http/encode/duration/main.test.ts +0 -126
  90. package/test/e2e/http/encode/numeric/main.test.ts +0 -26
  91. package/test/e2e/http/parameters/basic/main.test.ts +0 -35
  92. package/test/e2e/http/parameters/body-optionality/main.test.ts +0 -43
  93. package/test/e2e/http/parameters/collection-format/main.test.ts +0 -40
  94. package/test/e2e/http/parameters/spread/main.test.ts +0 -56
  95. package/test/e2e/http/payload/content-negotiation/main.test.ts +0 -40
  96. package/test/e2e/http/payload/json-merge-patch/main.test.ts +0 -122
  97. package/test/e2e/http/payload/media-type/main.test.ts +0 -28
  98. package/test/e2e/http/payload/multipart/main.test.ts +0 -200
  99. package/test/e2e/http/payload/pageable/main.test.ts +0 -78
  100. package/test/e2e/http/payload/xml/main.test.ts +0 -287
  101. package/test/e2e/http/routes/main.test.ts +0 -284
  102. package/test/e2e/http/serialization/encoded-name/json/main.test.ts +0 -20
  103. package/test/e2e/http/server/endpoint/not-defined/main.test.ts +0 -11
  104. package/test/e2e/http/server/path/multiple/main.test.ts +0 -22
  105. package/test/e2e/http/server/path/single/main.test.ts +0 -11
  106. package/test/e2e/http/server/versions/not-versioned/main.test.ts +0 -22
  107. package/test/e2e/http/server/versions/versioned/main.test.ts +0 -28
  108. package/test/e2e/http/special-headers/conditional-request/main.test.ts +0 -35
  109. package/test/e2e/http/special-headers/repeatability/main.test.ts +0 -18
  110. package/test/e2e/http/special-words/main.test.ts +0 -434
  111. package/test/e2e/http/type/array/array.test.ts +0 -256
  112. package/test/e2e/http/type/dictionary/main.test.ts +0 -229
  113. package/test/e2e/http/type/enum/extensible/main.test.ts +0 -34
  114. package/test/e2e/http/type/enum/fixed/main.test.ts +0 -29
  115. package/test/e2e/http/type/model/empty/main.test.ts +0 -21
  116. package/test/e2e/http/type/model/inheritance/enum-discriminator/main.test.ts +0 -51
  117. package/test/e2e/http/type/model/inheritance/nested-discriminator/main.test.ts +0 -168
  118. package/test/e2e/http/type/model/inheritance/not-discriminated/main.test.ts +0 -42
  119. package/test/e2e/http/type/model/inheritance/recursive/main.test.ts +0 -46
  120. package/test/e2e/http/type/model/inheritance/single-discriminator/main.test.ts +0 -99
  121. package/test/e2e/http/type/model/visibility/main.test.ts +0 -64
  122. package/test/e2e/http/type/property/additional-properties/main.test.ts +0 -185
  123. package/test/e2e/http/type/property/additional-properties/spreads.test.ts +0 -448
  124. package/test/e2e/http/type/property/nullable/main.test.ts +0 -275
  125. package/test/e2e/http/type/property/optionality/main.test.ts +0 -256
  126. package/test/e2e/http/type/property/value-types/main.test.ts +0 -193
  127. package/test/e2e/http/type/scalar/main.test.ts +0 -133
  128. package/test/e2e/http/type/scalar/scalar.test.ts +0 -95
  129. package/test/e2e/http/type/union/main.test.ts +0 -207
  130. package/test/e2e/http/versioning/added/main.test.ts +0 -60
  131. package/test/e2e/http/versioning/madeOptional/main.test.ts +0 -34
  132. package/test/e2e/http/versioning/removed/main.test.ts +0 -75
  133. package/test/e2e/http/versioning/renamedFrom/main.test.ts +0 -52
  134. package/test/e2e/http/versioning/returnTypeChangedFrom/main.test.ts +0 -22
  135. package/test/e2e/http/versioning/typeChangedFrom/main.test.ts +0 -31
  136. package/test/scenarios/additional-properties/extends.md +0 -67
  137. package/test/scenarios/additional-properties/is.md +0 -42
  138. package/test/scenarios/additional-properties/spread.md +0 -68
  139. package/test/scenarios/auth/basic_auth.md +0 -68
  140. package/test/scenarios/auth/bearer.md +0 -68
  141. package/test/scenarios/auth/client_parameters.md +0 -78
  142. package/test/scenarios/auth/client_structure.md +0 -36
  143. package/test/scenarios/auth/key_credential.md +0 -69
  144. package/test/scenarios/auth/oauth2.md +0 -90
  145. package/test/scenarios/auth/sub_client_override.md +0 -114
  146. package/test/scenarios/client/client_context.md +0 -34
  147. package/test/scenarios/client/dotted_namespace.md +0 -27
  148. package/test/scenarios/client/global_namespace.md +0 -69
  149. package/test/scenarios/client/multiple_top_level_clients.md +0 -72
  150. package/test/scenarios/client/nested_client.md +0 -102
  151. package/test/scenarios/client/wrapping_namespace.md +0 -41
  152. package/test/scenarios/encoding/bytes_body.md +0 -44
  153. package/test/scenarios/encoding/bytes_json_property.md +0 -55
  154. package/test/scenarios/encoding/bytes_nullable.md +0 -139
  155. package/test/scenarios/encoding/header_bytes.md +0 -130
  156. package/test/scenarios/encoding/header_date.md +0 -216
  157. package/test/scenarios/encoding/model_with_bytes_property.md +0 -45
  158. package/test/scenarios/encoding/query_bytes.md +0 -42
  159. package/test/scenarios/encoding/query_date.md +0 -216
  160. package/test/scenarios/http-operations/basic-request.md +0 -144
  161. package/test/scenarios/http-operations/basic-response.md +0 -219
  162. package/test/scenarios/http-operations/basic.md +0 -128
  163. package/test/scenarios/http-operations/constant-header.md +0 -33
  164. package/test/scenarios/http-operations/create-operation.md +0 -58
  165. package/test/scenarios/http-operations/on_response.md +0 -52
  166. package/test/scenarios/http-operations/optional-request-body.md +0 -50
  167. package/test/scenarios/http-operations/paging.md +0 -242
  168. package/test/scenarios/http-operations/path-parameter-in-model.md +0 -53
  169. package/test/scenarios/http-operations/path-parameter.md +0 -48
  170. package/test/scenarios/http-operations/query-parameter.md +0 -41
  171. package/test/scenarios/http-operations/scalar-payload.md +0 -57
  172. package/test/scenarios/http-operations/with-parameters.md +0 -78
  173. package/test/scenarios/models/array-properties.md +0 -47
  174. package/test/scenarios/models/basic.md +0 -118
  175. package/test/scenarios/models/dictionary-properties.md +0 -44
  176. package/test/scenarios/models/inheritance_2_discriminators.md +0 -346
  177. package/test/scenarios/models/inheritance_discriminator.md +0 -88
  178. package/test/scenarios/models/inline-models.md +0 -29
  179. package/test/scenarios/models/model_additional_properties.md +0 -75
  180. package/test/scenarios/models/model_extends.md +0 -97
  181. package/test/scenarios/models/model_spread.md +0 -63
  182. package/test/scenarios/models/nested_property.md +0 -41
  183. package/test/scenarios/models/property_references_property.md +0 -150
  184. package/test/scenarios/multipart/anonymous_part.md +0 -53
  185. package/test/scenarios/multipart/file.md +0 -154
  186. package/test/scenarios/multipart/file_content_type.md +0 -92
  187. package/test/scenarios/multipart/non-string-float.md +0 -55
  188. package/test/scenarios/multipart/simple_part.md +0 -65
  189. package/test/scenarios/operation-parameters/body_root_anonymous.md +0 -87
  190. package/test/scenarios/operation-parameters/constant_as_optional.md +0 -54
  191. package/test/scenarios/operation-parameters/default_value_as_optional.md +0 -54
  192. package/test/scenarios/operation-parameters/no_content_type.md +0 -62
  193. package/test/scenarios/operation-parameters/no_parameters.md +0 -50
  194. package/test/scenarios/operation-parameters/only_optional.md +0 -62
  195. package/test/scenarios/operation-parameters/only_required.md +0 -58
  196. package/test/scenarios/operation-parameters/reserved_names.md +0 -60
  197. package/test/scenarios/operation-parameters/spread_body.md +0 -70
  198. package/test/scenarios/operation-parameters/spread_with_nested.md +0 -82
  199. package/test/scenarios/operation-parameters/union_body.md +0 -86
  200. package/test/scenarios/operation-parameters/with_body_property.md +0 -67
  201. package/test/scenarios/operation-parameters/with_body_root.md +0 -69
  202. package/test/scenarios/serializers/arrays.md +0 -191
  203. package/test/scenarios/serializers/basic_model.md +0 -111
  204. package/test/scenarios/serializers/basic_model_wire_name.md +0 -48
  205. package/test/scenarios/serializers/discriminated_union.md +0 -86
  206. package/test/scenarios/serializers/discriminated_union_spread.md +0 -115
  207. package/test/scenarios/serializers/file.md +0 -67
  208. package/test/scenarios/serializers/model_date_time.md +0 -65
  209. package/test/scenarios/serializers/multipart.md +0 -62
  210. package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +0 -157
  211. package/test/scenarios/serializers/property_references_property.md +0 -72
  212. package/test/scenarios/serializers/record.md +0 -97
  213. package/test/scenarios/serializers/scalars.md +0 -34
  214. package/test/scenarios/serializers/spread.md +0 -69
  215. package/test/scenarios/serializers/string_union.md +0 -55
  216. package/test/scenarios/server/default_url.md +0 -45
  217. package/test/scenarios/server/multiple-parameters.md +0 -55
  218. package/test/scenarios/server/no-server.md +0 -37
  219. package/test/scenarios/server/parametrized-endpoint.md +0 -51
  220. package/test/scenarios.test.ts +0 -24
  221. package/test/test-host.ts +0 -22
  222. package/tsconfig.json +0 -16
  223. package/tsconfig.test.json +0 -9
  224. package/vitest.config.e2e.ts +0 -16
  225. package/vitest.config.ts +0 -15
@@ -1,69 +0,0 @@
1
- # Handles a simple bearer authentication scheme
2
-
3
- This test validates that the emitter can handle a key auth scheme correctly with a header location
4
-
5
- ## Typespec
6
-
7
- The spec contains a simple service with a ApiKey authentication scheme
8
-
9
- ```tsp
10
- @service(#{ title: "Test Service" })
11
- @useAuth(ApiKeyAuth<ApiKeyLocation.header, "X-API-KEY">)
12
- namespace Test;
13
-
14
- @route("/valid")
15
- @get
16
- op valid(): NoContentResponse;
17
- ```
18
-
19
- ## TypeScript
20
-
21
- ### Client
22
-
23
- The client signature should include a positional parameter for credential of type KeyCredential.
24
-
25
- ```ts src/testClient.ts class TestClient
26
- export class TestClient {
27
- #context: TestClientContext;
28
- constructor(endpoint: string, credential: ApiKeyCredential, options?: TestClientOptions) {
29
- this.#context = createTestClientContext(endpoint, credential, options);
30
- }
31
- async valid(options?: ValidOptions) {
32
- return valid(this.#context, options);
33
- }
34
- }
35
- ```
36
-
37
- ### ClientContext
38
-
39
- The client context should setup the pipeline to use the credential in the header with the name provided in the Scheme configuration. In this case "X-API-KEY"
40
-
41
- ```ts src/api/testClientContext.ts function createTestClientContext
42
- export function createTestClientContext(
43
- endpoint: string,
44
- credential: ApiKeyCredential,
45
- options?: TestClientOptions,
46
- ): TestClientContext {
47
- const params: Record<string, any> = {
48
- endpoint: endpoint,
49
- };
50
- const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
51
- key in params
52
- ? String(params[key])
53
- : (() => {
54
- throw new Error(`Missing parameter: ${key}`);
55
- })(),
56
- );
57
- return getClient(resolvedEndpoint, {
58
- ...options,
59
- credential,
60
- authSchemes: [
61
- {
62
- kind: "apiKey",
63
- apiKeyLocation: "header",
64
- name: "X-API-KEY",
65
- },
66
- ],
67
- });
68
- }
69
- ```
@@ -1,90 +0,0 @@
1
- # Handles oauth2 authentication scheme
2
-
3
- This test validates that the emitter can handle a basic authentication scheme correctly, including the client signature and its initialization
4
-
5
- ## Typespec
6
-
7
- The spec contains a simple service with a Bearer authentication scheme
8
-
9
- ```tsp
10
- @service(#{ title: "Test Service" })
11
- @useAuth(
12
- OAuth2Auth<
13
- [
14
- {
15
- type: OAuth2FlowType.clientCredentials,
16
- tokenUrl: "https://api.example.com/oauth2/authorize",
17
- refreshUrl: "https://api.example.com/oauth2/refresh",
18
- }
19
- ],
20
- ["read"]
21
- >
22
- )
23
- namespace Test;
24
-
25
- @route("/valid")
26
- @get
27
- op valid(): NoContentResponse;
28
- ```
29
-
30
- ## TypeScript
31
-
32
- ### Client
33
-
34
- The client signature should include a positional parameter for credential of type KeyCredential. A basic auth token is a key credential that gets put into the Authorization header
35
-
36
- ```ts src/testClient.ts class TestClient
37
- export class TestClient {
38
- #context: TestClientContext;
39
- constructor(
40
- endpoint: string,
41
- credential: OAuth2TokenCredential<ClientCredentialsFlow>,
42
- options?: TestClientOptions,
43
- ) {
44
- this.#context = createTestClientContext(endpoint, credential, options);
45
- }
46
- async valid(options?: ValidOptions) {
47
- return valid(this.#context, options);
48
- }
49
- }
50
- ```
51
-
52
- ### ClientContext
53
-
54
- The client context should setup the pipeline to use the credential in the Authorization header.
55
-
56
- ```ts src/api/testClientContext.ts function createTestClientContext
57
- export function createTestClientContext(
58
- endpoint: string,
59
- credential: OAuth2TokenCredential<ClientCredentialsFlow>,
60
- options?: TestClientOptions,
61
- ): TestClientContext {
62
- const params: Record<string, any> = {
63
- endpoint: endpoint,
64
- };
65
- const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
66
- key in params
67
- ? String(params[key])
68
- : (() => {
69
- throw new Error(`Missing parameter: ${key}`);
70
- })(),
71
- );
72
- return getClient(resolvedEndpoint, {
73
- ...options,
74
- credential,
75
- authSchemes: [
76
- {
77
- kind: "oauth2",
78
- flows: [
79
- {
80
- kind: "clientCredentials",
81
- tokenUrl: "https://api.example.com/oauth2/authorize",
82
- refreshUrl: "https://api.example.com/oauth2/refresh",
83
- scopes: ["read"],
84
- },
85
- ],
86
- },
87
- ],
88
- });
89
- }
90
- ```
@@ -1,114 +0,0 @@
1
- # A sub client can override the partent credential scheme
2
-
3
- The sub client sets NoAuth to override the auth scheme of the parent
4
-
5
- ## Typespec
6
-
7
- The spec contains a client with BasicAuth and a sub client with no auth
8
-
9
- ```tsp
10
- @service(#{ title: "Test Service" })
11
- @useAuth(BasicAuth)
12
- namespace Test;
13
-
14
- @route("/")
15
- @get
16
- op valid(): NoContentResponse;
17
-
18
- @useAuth(NoAuth)
19
- @route("/sub")
20
- namespace Sub {
21
- @get
22
- op put(): NoContentResponse;
23
- }
24
- ```
25
-
26
- ## TypeScript
27
-
28
- ### Client
29
-
30
- The client signature should include a positional parameter for credential of type KeyCredential. A basic auth token is a key credential that gets put into the Authorization header/
31
-
32
- The subclient is not a child of the TestClient because they have different parameter.
33
-
34
- ```ts src/testClient.ts class TestClient
35
- export class TestClient {
36
- #context: TestClientContext;
37
- constructor(endpoint: string, credential: BasicCredential, options?: TestClientOptions) {
38
- this.#context = createTestClientContext(endpoint, credential, options);
39
- }
40
- async valid(options?: ValidOptions) {
41
- return valid(this.#context, options);
42
- }
43
- }
44
- ```
45
-
46
- The sub client shouldn't take a credential
47
-
48
- ```ts src/testClient.ts class SubClient
49
- export class SubClient {
50
- #context: SubClientContext;
51
- constructor(endpoint: string, options?: SubClientOptions) {
52
- this.#context = createSubClientContext(endpoint, options);
53
- }
54
- async put(options?: PutOptions) {
55
- return put(this.#context, options);
56
- }
57
- }
58
- ```
59
-
60
- ### ClientContext
61
-
62
- The client context should setup the pipeline to use the credential in the Authorization header.
63
-
64
- ```ts src/api/testClientContext.ts function createTestClientContext
65
- export function createTestClientContext(
66
- endpoint: string,
67
- credential: BasicCredential,
68
- options?: TestClientOptions,
69
- ): TestClientContext {
70
- const params: Record<string, any> = {
71
- endpoint: endpoint,
72
- };
73
- const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
74
- key in params
75
- ? String(params[key])
76
- : (() => {
77
- throw new Error(`Missing parameter: ${key}`);
78
- })(),
79
- );
80
- return getClient(resolvedEndpoint, {
81
- ...options,
82
- credential,
83
- authSchemes: [
84
- {
85
- kind: "http",
86
- scheme: "basic",
87
- },
88
- ],
89
- });
90
- }
91
- ```
92
-
93
- The suv client context should setup the pipeline to use the credential in the Authorization header.
94
-
95
- ```ts src/api/subClient/subClientContext.ts function createSubClientContext
96
- export function createSubClientContext(
97
- endpoint: string,
98
- options?: SubClientOptions,
99
- ): SubClientContext {
100
- const params: Record<string, any> = {
101
- endpoint: endpoint,
102
- };
103
- const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
104
- key in params
105
- ? String(params[key])
106
- : (() => {
107
- throw new Error(`Missing parameter: ${key}`);
108
- })(),
109
- );
110
- return getClient(resolvedEndpoint, {
111
- ...options,
112
- });
113
- }
114
- ```
@@ -1,34 +0,0 @@
1
- # Should generate a client context factory for a simple client
2
-
3
- ## TypeSpec
4
-
5
- ```tsp
6
- @service(#{ title: "Widget Service" })
7
- namespace DemoService;
8
- op foo(): void;
9
- ```
10
-
11
- ## TypeScript
12
-
13
- Should generate a factory function named after the namespace `createDemoServiceContext`. Since there is no url defined the factory takes an endpoint parameter
14
-
15
- ```ts src/api/demoServiceClientContext.ts function createDemoServiceClientContext
16
- export function createDemoServiceClientContext(
17
- endpoint: string,
18
- options?: DemoServiceClientOptions,
19
- ): DemoServiceClientContext {
20
- const params: Record<string, any> = {
21
- endpoint: endpoint,
22
- };
23
- const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
24
- key in params
25
- ? String(params[key])
26
- : (() => {
27
- throw new Error(`Missing parameter: ${key}`);
28
- })(),
29
- );
30
- return getClient(resolvedEndpoint, {
31
- ...options,
32
- });
33
- }
34
- ```
@@ -1,27 +0,0 @@
1
- # Handles dotted namespaces when only the last has content
2
-
3
- ## Spec
4
-
5
- A dotted namespace where only the last part has content. The leading namespaces have no operations and a single sub namespace
6
-
7
- ```tsp
8
- @service(#{ title: "TestService" })
9
- namespace Foo.Bar.Baz;
10
- @get op get(): string[];
11
- ```
12
-
13
- ## Expectations
14
-
15
- The client should match the last namespace.
16
-
17
- ```ts src/bazClient.ts class BazClient
18
- export class BazClient {
19
- #context: BazClientContext;
20
- constructor(endpoint: string, options?: BazClientOptions) {
21
- this.#context = createBazClientContext(endpoint, options);
22
- }
23
- async get(options?: GetOptions) {
24
- return get(this.#context, options);
25
- }
26
- }
27
- ```
@@ -1,69 +0,0 @@
1
- # Client from the global namespace
2
-
3
- This tests that the emitter can handle a spec that has no top-level namespace defined
4
-
5
- ## TypeSpec
6
-
7
- ```tsp
8
- op foo(): void;
9
- ```
10
-
11
- ## TypeScript
12
-
13
- It should generate an interface and factory for the client context.
14
-
15
- ```ts src/api/clientContext.ts interface ClientContext
16
- export interface ClientContext extends Client {}
17
- ```
18
-
19
- ```ts src/api/clientContext.ts function createClientContext
20
- export function createClientContext(endpoint: string, options?: ClientOptions): ClientContext {
21
- const params: Record<string, any> = {
22
- endpoint: endpoint,
23
- };
24
- const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
25
- key in params
26
- ? String(params[key])
27
- : (() => {
28
- throw new Error(`Missing parameter: ${key}`);
29
- })(),
30
- );
31
- return getClient(resolvedEndpoint, {
32
- ...options,
33
- });
34
- }
35
- ```
36
-
37
- It should generate a client for the Global Namespace with a single operation `foo` matching the spec and no sub-clients.
38
-
39
- ```ts src/client.ts class Client
40
- export class Client {
41
- #context: ClientContext;
42
- constructor(endpoint: string, options?: ClientOptions) {
43
- this.#context = createClientContext(endpoint, options);
44
- }
45
- async foo(options?: FooOptions) {
46
- return foo(this.#context, options);
47
- }
48
- }
49
- ```
50
-
51
- It should generate an operation for foo
52
-
53
- ```ts src/api/clientOperations.ts function foo
54
- export async function foo(client: ClientContext, options?: FooOptions): Promise<void> {
55
- const path = parse("/").expand({});
56
- const httpRequestOptions = {
57
- headers: {},
58
- };
59
- const response = await client.pathUnchecked(path).get(httpRequestOptions);
60
-
61
- if (typeof options?.operationOptions?.onResponse === "function") {
62
- options?.operationOptions?.onResponse(response);
63
- }
64
- if (+response.status === 204 && !response.body) {
65
- return;
66
- }
67
- throw createRestError(response);
68
- }
69
- ```
@@ -1,72 +0,0 @@
1
- # Emits multiple top level clients
2
-
3
- Verifies that the emitter can handle correctly when there are 2 root namespaces, translating these into 2 separate clients
4
-
5
- ## TypeSpec
6
-
7
- ```tsp
8
- namespace Foo {
9
- model FooItem {
10
- name: string;
11
- }
12
-
13
- op get(): FooItem;
14
- }
15
-
16
- namespace Bar {
17
- model BarItem {
18
- title: string;
19
- }
20
-
21
- op get(): BarItem;
22
- @post op create(foo: BarItem): void;
23
- }
24
- ```
25
-
26
- ## TypeScript
27
-
28
- It should generate a client for Foo with a single operation as defined in the spec
29
-
30
- ```ts src/fooClient.ts
31
- import {
32
- createFooClientContext,
33
- type FooClientContext,
34
- type FooClientOptions,
35
- } from "./api/fooClientContext.js";
36
- import { get, type GetOptions } from "./api/fooClientOperations.js";
37
-
38
- export class FooClient {
39
- #context: FooClientContext;
40
- constructor(endpoint: string, options?: FooClientOptions) {
41
- this.#context = createFooClientContext(endpoint, options);
42
- }
43
- async get(options?: GetOptions) {
44
- return get(this.#context, options);
45
- }
46
- }
47
- ```
48
-
49
- It should generate a client for Bar with `create` and `get` operations as defined in the spec
50
-
51
- ```ts src/barClient.ts
52
- import {
53
- type BarClientContext,
54
- type BarClientOptions,
55
- createBarClientContext,
56
- } from "./api/barClientContext.js";
57
- import { create, type CreateOptions, get, type GetOptions } from "./api/barClientOperations.js";
58
- import type { BarItem } from "./models/models.js";
59
-
60
- export class BarClient {
61
- #context: BarClientContext;
62
- constructor(endpoint: string, options?: BarClientOptions) {
63
- this.#context = createBarClientContext(endpoint, options);
64
- }
65
- async get(options?: GetOptions) {
66
- return get(this.#context, options);
67
- }
68
- async create(foo: BarItem, options?: CreateOptions) {
69
- return create(this.#context, foo, options);
70
- }
71
- }
72
- ```
@@ -1,102 +0,0 @@
1
- # Should generate a client structure that has a root client with a nested client
2
-
3
- This specs nests namespace > namespace > interface
4
-
5
- ## TypeSpec
6
-
7
- ```tsp
8
- @service(#{ title: "Widget Service" })
9
- namespace DemoService;
10
-
11
- model Widget {
12
- @visibility(Lifecycle.Read, Lifecycle.Update)
13
- @path
14
- id: string;
15
-
16
- weight: int32;
17
- color: "red" | "blue";
18
- }
19
-
20
- @error
21
- model Error {
22
- code: int32;
23
- message: string;
24
- }
25
-
26
- @route("/widgets")
27
- @tag("Widgets")
28
- interface Widgets {
29
- @get list(): Widget[] | Error;
30
- @get read(@path id: string): Widget | Error;
31
- @post create(...Widget): Widget | Error;
32
- @patch update(...Widget): Widget | Error;
33
- @delete delete(@path id: string): void | Error;
34
- @route("{id}/analyze") @post analyze(@path id: string): string | Error;
35
- }
36
- ```
37
-
38
- ## TypeScript
39
-
40
- ### Client
41
-
42
- It generates a class called TestClient with a single operation
43
-
44
- ```ts src/demoServiceClient.ts
45
- import {
46
- createDemoServiceClientContext,
47
- type DemoServiceClientContext,
48
- type DemoServiceClientOptions,
49
- } from "./api/demoServiceClientContext.js";
50
- import {
51
- createWidgetsClientContext,
52
- type WidgetsClientContext,
53
- type WidgetsClientOptions,
54
- } from "./api/widgetsClient/widgetsClientContext.js";
55
- import {
56
- analyze,
57
- type AnalyzeOptions,
58
- create,
59
- type CreateOptions,
60
- delete_,
61
- type DeleteOptions,
62
- list,
63
- type ListOptions,
64
- read,
65
- type ReadOptions,
66
- update,
67
- type UpdateOptions,
68
- } from "./api/widgetsClient/widgetsClientOperations.js";
69
-
70
- export class DemoServiceClient {
71
- #context: DemoServiceClientContext;
72
- widgetsClient: WidgetsClient;
73
- constructor(endpoint: string, options?: DemoServiceClientOptions) {
74
- this.#context = createDemoServiceClientContext(endpoint, options);
75
- this.widgetsClient = new WidgetsClient(endpoint, options);
76
- }
77
- }
78
- export class WidgetsClient {
79
- #context: WidgetsClientContext;
80
- constructor(endpoint: string, options?: WidgetsClientOptions) {
81
- this.#context = createWidgetsClientContext(endpoint, options);
82
- }
83
- async list(options?: ListOptions) {
84
- return list(this.#context, options);
85
- }
86
- async read(id: string, options?: ReadOptions) {
87
- return read(this.#context, id, options);
88
- }
89
- async create(weight: number, color: "red" | "blue", options?: CreateOptions) {
90
- return create(this.#context, weight, color, options);
91
- }
92
- async update(id: string, weight: number, color: "red" | "blue", options?: UpdateOptions) {
93
- return update(this.#context, id, weight, color, options);
94
- }
95
- async delete_(id: string, options?: DeleteOptions) {
96
- return delete_(this.#context, id, options);
97
- }
98
- async analyze(id: string, options?: AnalyzeOptions) {
99
- return analyze(this.#context, id, options);
100
- }
101
- }
102
- ```
@@ -1,41 +0,0 @@
1
- # Handles a structure where there is a namespace with sub namespaces only
2
-
3
- This scenario has a structure where the root namespace has no operations but has 2 sub namespaces.
4
-
5
- In this scenario the emitter is expected to resolve the root namespace as a client
6
-
7
- ## Spec
8
-
9
- A dotted namespace where only the last part has stuff
10
-
11
- ```tsp
12
- @service(#{ title: "TestService" })
13
- namespace Foo;
14
-
15
- @route("/bar")
16
- namespace Bar {
17
- @get op getBar(): string[];
18
- }
19
-
20
- @route("/baz")
21
- namespace Baz {
22
- @get op getBaz(): string[];
23
- }
24
- ```
25
-
26
- ## Expectations
27
-
28
- The root client should be FooClient and should have 2 sub clients as members for bor and baz
29
-
30
- ```ts src/fooClient.ts class FooClient
31
- export class FooClient {
32
- #context: FooClientContext;
33
- barClient: BarClient;
34
- bazClient: BazClient;
35
- constructor(endpoint: string, options?: FooClientOptions) {
36
- this.#context = createFooClientContext(endpoint, options);
37
- this.barClient = new BarClient(endpoint, options);
38
- this.bazClient = new BazClient(endpoint, options);
39
- }
40
- }
41
- ```
@@ -1,44 +0,0 @@
1
- # Should not encode a bytes data when the body is bytes
2
-
3
- ## TypeSpec
4
-
5
- ```tsp
6
- @service
7
- namespace Test;
8
-
9
- @route("/default")
10
- op foo(@header contentType: "application/octet-stream", @body value: bytes): {
11
- @header contentType: "application/octet-stream";
12
- @body value: bytes;
13
- };
14
- ```
15
-
16
- ## TypeScript
17
-
18
- ```ts src/api/testClientOperations.ts function foo
19
- export async function foo(
20
- client: TestClientContext,
21
- value: Uint8Array,
22
- options?: FooOptions,
23
- ): Promise<Uint8Array> {
24
- const path = parse("/default").expand({});
25
- const httpRequestOptions = {
26
- headers: {
27
- "content-type": options?.contentType ?? "application/octet-stream",
28
- },
29
- body: value,
30
- };
31
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
32
-
33
- if (typeof options?.operationOptions?.onResponse === "function") {
34
- options?.operationOptions?.onResponse(response);
35
- }
36
- if (
37
- +response.status === 200 &&
38
- response.headers["content-type"]?.includes("application/octet-stream")
39
- ) {
40
- return response.body!;
41
- }
42
- throw createRestError(response);
43
- }
44
- ```