@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,155 +0,0 @@
1
- import type { Refkey } from "@alloy-js/core";
2
- import { code, mapJoin, refkey } from "@alloy-js/core";
3
- import type * as ts from "@alloy-js/typescript";
4
- import type { ModelProperty, Value } from "@typespec/compiler";
5
- import { useTsp } from "@typespec/emitter-framework";
6
- import { buildParameterDescriptor } from "@typespec/emitter-framework/typescript";
7
- import type { HttpAuth, HttpProperty, OAuth2FlowType } from "@typespec/http";
8
- import type * as cl from "@typespec/http-client";
9
- import { getClientContextOptionsRef } from "../components/client-context/client-context-options.jsx";
10
- import { httpRuntimeTemplateLib } from "../components/external-packages/ts-http-runtime.js";
11
-
12
- export function buildClientParameters(
13
- client: cl.Client,
14
- suffixRefkey: Refkey,
15
- ): ts.ParameterDescriptor[] {
16
- const { $ } = useTsp();
17
- const clientConstructor = $.client.getConstructor(client);
18
- const parameters = $.operation.getClientSignature(client, clientConstructor);
19
- const params = parameters.flatMap(
20
- (param) => {
21
- const descriptor = buildClientParameterDescriptor(param, suffixRefkey);
22
- if (!descriptor) {
23
- return [];
24
- }
25
-
26
- if (!descriptor.optional) {
27
- return [descriptor];
28
- }
29
-
30
- return [];
31
- },
32
- {} as Record<string, ts.ParameterDescriptor>,
33
- );
34
-
35
- if (!params.some((p) => p.name === "options")) {
36
- params.push({
37
- name: "options",
38
- refkey: refkey("client-options", suffixRefkey),
39
- optional: true,
40
- type: getClientContextOptionsRef(client),
41
- });
42
- }
43
-
44
- return params;
45
- }
46
-
47
- function buildClientParameterDescriptor(
48
- modelProperty: ModelProperty,
49
- suffixRefkey: Refkey,
50
- ): ts.ParameterDescriptor | undefined {
51
- const { $ } = useTsp();
52
- const authSchemes = $.modelProperty.getCredentialAuth(modelProperty);
53
-
54
- if (authSchemes) {
55
- if (authSchemes.length === 1 && authSchemes[0].type === "noAuth") {
56
- return undefined;
57
- }
58
-
59
- const credentialType = Array.from(
60
- new Set(authSchemes.filter((s) => s.type !== "noAuth").map((s) => getCredentialType(s))),
61
- );
62
- return {
63
- name: "credential",
64
- refkey: refkey(modelProperty, suffixRefkey),
65
- optional: modelProperty.optional,
66
- type: mapJoin(
67
- () => credentialType,
68
- (t) => t,
69
- { joiner: " | " },
70
- ),
71
- };
72
- }
73
-
74
- return buildParameterDescriptor(modelProperty, suffixRefkey);
75
- }
76
-
77
- const oauth2FlowRefs: Record<OAuth2FlowType, Refkey> = {
78
- authorizationCode: httpRuntimeTemplateLib.AuthorizationCodeFlow,
79
- clientCredentials: httpRuntimeTemplateLib.ClientCredentialsFlow,
80
- password: httpRuntimeTemplateLib.PasswordFlow,
81
- implicit: httpRuntimeTemplateLib.ImplicitFlow,
82
- };
83
-
84
- function getCredentialType(scheme: HttpAuth) {
85
- switch (scheme.type) {
86
- case "apiKey":
87
- return httpRuntimeTemplateLib.ApiKeyCredential;
88
- case "http":
89
- if (scheme.scheme === "Basic") {
90
- return httpRuntimeTemplateLib.BasicCredential;
91
- } else {
92
- return httpRuntimeTemplateLib.BearerTokenCredential;
93
- }
94
- case "oauth2":
95
- const flowType = mapJoin(
96
- () => scheme.flows,
97
- (x) => oauth2FlowRefs[x.type],
98
- { joiner: " | " },
99
- );
100
- return code`${httpRuntimeTemplateLib.OAuth2TokenCredential}<${flowType}>`;
101
- default:
102
- return null;
103
- }
104
- }
105
-
106
- /**
107
- * Checks if a parameter has a default value. Only honors default values for content-type.
108
- * @param property Property to check
109
- * @returns whether the property has a default value
110
- */
111
- export function hasDefaultValue(property: HttpProperty): boolean {
112
- return getDefaultValue(property) !== undefined;
113
- }
114
-
115
- export function getDefaultValue(property: ModelProperty): string | number | boolean | undefined;
116
- export function getDefaultValue(property: HttpProperty): string | number | boolean | undefined;
117
- export function getDefaultValue(
118
- httpOrModelProperty: HttpProperty | ModelProperty,
119
- ): string | number | boolean | undefined {
120
- let property;
121
-
122
- if ("kind" in httpOrModelProperty && httpOrModelProperty.kind === "ModelProperty") {
123
- property = httpOrModelProperty;
124
- } else {
125
- property = httpOrModelProperty.property;
126
- }
127
-
128
- if (property.defaultValue) {
129
- if ("value" in property.defaultValue) {
130
- return getValue(property.defaultValue);
131
- }
132
- }
133
-
134
- if ("value" in property.type && property.type.value !== undefined) {
135
- return JSON.stringify(property.type.value);
136
- }
137
-
138
- return undefined;
139
- }
140
-
141
- function getValue(value: Value | undefined) {
142
- if (!value) {
143
- return undefined;
144
- }
145
- switch (value.valueKind) {
146
- case "StringValue":
147
- return `"${value.value}"`;
148
- case "NumericValue":
149
- return value.value.asNumber() ?? undefined;
150
- case "BooleanValue":
151
- return value.value;
152
- default:
153
- return undefined;
154
- }
155
- }
Binary file
Binary file
@@ -1,38 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ApiKeyClient } from "../../../generated/authentication/api-key/src/index.js";
3
-
4
- describe("Authentication.ApiKey", () => {
5
- const client = new ApiKeyClient(
6
- {
7
- key: "valid-key", // Set the default API key here
8
- },
9
- { allowInsecureConnection: true },
10
- );
11
-
12
- it("should authenticate with a valid API key", async () => {
13
- const response = await client.valid();
14
- expect(response).toBeUndefined(); // NoContentResponse is expected
15
- });
16
-
17
- it.skip("should return error for an invalid API key", async () => {
18
- const invalidClient = new ApiKeyClient(
19
- {
20
- key: "invalid-key",
21
- },
22
- { allowInsecureConnection: true },
23
- );
24
-
25
- try {
26
- await invalidClient.invalid();
27
- throw new Error("Expected an error for invalid API key");
28
- } catch (error: any) {
29
- expect(error.statusCode).toBe(403);
30
- expect(error.body).toEqual({
31
- error: {
32
- code: "InvalidApiKey",
33
- message: "API key is invalid",
34
- },
35
- });
36
- }
37
- });
38
- });
@@ -1,31 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { OAuth2Client } from "../../../generated/authentication/oauth2/src/index.js";
3
-
4
- describe("Authentication.OAuth2", () => {
5
- const client = new OAuth2Client(
6
- {
7
- getOAuth2Token: async () => "https://security.microsoft.com/.default",
8
- },
9
- { allowInsecureConnection: true },
10
- );
11
-
12
- it("should validate the client is authenticated", async () => {
13
- const response = await client.valid();
14
- expect(response).toBe(undefined); // No content response
15
- });
16
-
17
- it("should handle invalid authentication and return error", async () => {
18
- try {
19
- const client = new OAuth2Client(
20
- {
21
- getOAuth2Token: async () => "invalid",
22
- },
23
- { allowInsecureConnection: true },
24
- );
25
- await client.invalid();
26
- } catch (error: any) {
27
- expect(error.status).toBe("403");
28
- expect(error.body.error).toBe("invalid-grant");
29
- }
30
- });
31
- });
@@ -1,26 +0,0 @@
1
- import { describe, it } from "vitest";
2
- import { UnionClient } from "../../../generated/authentication/union/src/index.js";
3
-
4
- describe("Authentication.Union", () => {
5
- it("should authenticate using the valid API key", async () => {
6
- const client = new UnionClient(
7
- {
8
- key: "valid-key",
9
- },
10
- { allowInsecureConnection: true },
11
- );
12
- await client.validKey();
13
- // Assert successful request
14
- });
15
-
16
- it("should authenticate using the valid OAuth token", async () => {
17
- const client = new UnionClient(
18
- {
19
- getOAuth2Token: async () => "https://security.microsoft.com/.default",
20
- },
21
- { allowInsecureConnection: true },
22
- );
23
- await client.validToken();
24
- // Assert successful request
25
- });
26
- });
@@ -1,191 +0,0 @@
1
- import { readFile } from "fs/promises";
2
- import { dirname, resolve } from "path";
3
- import { fileURLToPath } from "url";
4
- import { describe, expect, it } from "vitest";
5
- import {
6
- HeaderClient,
7
- PropertyClient,
8
- QueryClient,
9
- RequestBodyClient,
10
- ResponseBodyClient,
11
- } from "../../../generated/encode/bytes/src/index.js";
12
-
13
- const __filename = fileURLToPath(import.meta.url);
14
- const __dirname = dirname(__filename);
15
-
16
- const pngImagePath = resolve(
17
- __dirname,
18
- "../../../../../node_modules/@typespec/http-specs/assets/image.png",
19
- );
20
- const pngBuffer = await readFile(pngImagePath);
21
- const pngContents = new Uint8Array(pngBuffer);
22
-
23
- const base64EncodeToUint8Array = (input: string): Uint8Array => {
24
- // Encode the string as Base64
25
- const base64String = btoa(input);
26
-
27
- // Decode Base64 into a binary string
28
- const binaryString = atob(base64String);
29
-
30
- // Convert the binary string to a Uint8Array
31
- const uint8Array = new Uint8Array(binaryString.length);
32
- for (let i = 0; i < binaryString.length; i++) {
33
- uint8Array[i] = binaryString.charCodeAt(i);
34
- }
35
-
36
- return uint8Array;
37
- };
38
-
39
- const encodedTestString = base64EncodeToUint8Array("test");
40
-
41
- const str = "test";
42
- const testUint8Array = new Uint8Array([...str].map((char) => char.charCodeAt(0)));
43
-
44
- describe("Encode.Bytes", () => {
45
- describe("QueryClient", () => {
46
- const client = new QueryClient({ allowInsecureConnection: true });
47
-
48
- it.skip("should test default encode (base64) for bytes query parameter", async () => {
49
- //
50
- await client.default_(testUint8Array);
51
- // Assert successful request
52
- });
53
-
54
- it("should test base64 encode for bytes query parameter", async () => {
55
- await client.base64(testUint8Array);
56
- // Assert successful request
57
- });
58
-
59
- it("should test base64url encode for bytes query parameter", async () => {
60
- await client.base64url(testUint8Array);
61
- // Assert successful request
62
- });
63
-
64
- it("should test base64url encode for bytes array query parameter", async () => {
65
- await client.base64urlArray([testUint8Array, testUint8Array]);
66
- // Assert successful request
67
- });
68
- });
69
-
70
- describe("PropertyClient", () => {
71
- const client = new PropertyClient({ allowInsecureConnection: true });
72
-
73
- it("should test default encode (base64) for bytes properties", async () => {
74
- const response = await client.default_({ value: encodedTestString });
75
- expect(response.value).toStrictEqual(encodedTestString);
76
- });
77
-
78
- it("should test base64 encode for bytes properties", async () => {
79
- const response = await client.base64({ value: testUint8Array });
80
- expect(response.value).toStrictEqual(encodedTestString);
81
- });
82
-
83
- it("should test base64url encode for bytes properties", async () => {
84
- const response = await client.base64url({ value: testUint8Array });
85
- expect(response.value).toStrictEqual(encodedTestString);
86
- });
87
-
88
- it("should test base64url encode for bytes array properties", async () => {
89
- const response = await client.base64urlArray({
90
- value: [testUint8Array, testUint8Array],
91
- });
92
- expect(response.value).toStrictEqual([testUint8Array, testUint8Array]);
93
- });
94
- });
95
-
96
- describe("HeaderClient", () => {
97
- const client = new HeaderClient({ allowInsecureConnection: true });
98
-
99
- it("should test default encode (base64) for bytes header", async () => {
100
- await client.default_(testUint8Array);
101
- // Assert successful request
102
- });
103
-
104
- it("should test base64 encode for bytes header", async () => {
105
- await client.base64(testUint8Array);
106
- // Assert successful request
107
- });
108
-
109
- it("should test base64url encode for bytes header", async () => {
110
- await client.base64url(testUint8Array);
111
- // Assert successful request
112
- });
113
-
114
- it("should test base64url encode for bytes array header", async () => {
115
- await client.base64urlArray([encodedTestString, encodedTestString]);
116
- // Assert successful request
117
- });
118
- });
119
-
120
- describe("RequestBodyClient", () => {
121
- const client = new RequestBodyClient({
122
- allowInsecureConnection: true,
123
- retryOptions: {
124
- maxRetries: 1,
125
- },
126
- });
127
-
128
- it.skip("should test default encode (base64) for bytes in JSON body", async () => {
129
- await client.default_(encodedTestString);
130
- // Assert successful request
131
- });
132
-
133
- it("should test application/octet-stream content type with bytes payload", async () => {
134
- const content = pngContents;
135
- await client.octetStream(content);
136
- // Assert successful request
137
- });
138
-
139
- it("should test custom content type (image/png) with bytes payload", async () => {
140
- const content = pngContents;
141
- await client.customContentType(content);
142
- // Assert successful request
143
- });
144
-
145
- it.skip("should test base64 encode for bytes body", async () => {
146
- await client.base64(testUint8Array);
147
- // Assert successful request
148
- });
149
-
150
- it.skip("should test base64url encode for bytes body", async () => {
151
- await client.base64url(testUint8Array);
152
- // Assert successful request
153
- });
154
- });
155
-
156
- describe("ResponseBodyClient", () => {
157
- const client = new ResponseBodyClient({
158
- allowInsecureConnection: true,
159
- retryOptions: {
160
- maxRetries: 1,
161
- },
162
- });
163
-
164
- it.skip("should test default encode (base64) for bytes in JSON body response", async () => {
165
- const response = await client.default_();
166
- expect(response).toStrictEqual(encodedTestString);
167
- });
168
-
169
- it.skip("should test application/octet-stream content type with bytes response", async () => {
170
- const response = await client.octetStream();
171
- const expectedContent = pngContents;
172
- expect(response).toStrictEqual(expectedContent);
173
- });
174
-
175
- it.skip("should test custom content type (image/png) with bytes response", async () => {
176
- const response = await client.customContentType();
177
- const expectedContent = pngContents;
178
- expect(response).toStrictEqual(expectedContent);
179
- });
180
-
181
- it("should test base64 encode for bytes response body", async () => {
182
- const response = await client.base64();
183
- expect(response).toStrictEqual(encodedTestString);
184
- });
185
-
186
- it("should test base64url encode for bytes response body", async () => {
187
- const response = await client.base64url();
188
- expect(response).toStrictEqual(encodedTestString);
189
- });
190
- });
191
- });
@@ -1,176 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- HeaderClient,
4
- PropertyClient,
5
- QueryClient,
6
- ResponseHeaderClient,
7
- } from "../../../generated/encode/datetime/src/index.js";
8
-
9
- describe("Encode.Datetime", () => {
10
- describe("QueryClient", () => {
11
- const client = new QueryClient({ allowInsecureConnection: true });
12
-
13
- it("should test default encode (rfc3339) for datetime query parameter", async () => {
14
- await client.default_(new Date("2022-08-26T18:38:00.000Z"));
15
- // Assert successful request
16
- });
17
-
18
- it("should test rfc3339 encode for datetime query parameter", async () => {
19
- await client.rfc3339(new Date("2022-08-26T18:38:00.000Z"));
20
- // Assert successful request
21
- });
22
-
23
- it("should test rfc7231 encode for datetime query parameter", async () => {
24
- await client.rfc7231(new Date("2022-08-26T14:38:00.000Z"));
25
- // Assert successful request
26
- });
27
-
28
- it("should test unixTimestamp encode for datetime query parameter", async () => {
29
- // For QueryClient, the correct unixTimestamp date is unchanged.
30
- await client.unixTimestamp(new Date("2023-06-12T10:47:44Z"));
31
- // Assert successful request.
32
- });
33
-
34
- it("should test unixTimestamp encode for datetime array query parameter", async () => {
35
- // For QueryClient, the array dates remain as before.
36
- const timestamps = [new Date("2023-06-12T10:47:44Z"), new Date("2023-06-14T09:17:36Z")];
37
- await client.unixTimestampArray(timestamps);
38
- // Assert successful request
39
- });
40
- });
41
-
42
- describe("PropertyClient", () => {
43
- const client = new PropertyClient({ allowInsecureConnection: true });
44
-
45
- it("should handle default encode (rfc3339) for datetime property", async () => {
46
- const requestBody = { value: new Date("2022-08-26T18:38:00.000Z") };
47
- const response = await client.default_(requestBody);
48
- expect(response).toEqual(requestBody);
49
- });
50
-
51
- it("should handle rfc3339 encode for datetime property", async () => {
52
- const requestBody = { value: new Date("2022-08-26T18:38:00.000Z") };
53
- const response = await client.rfc3339(requestBody);
54
- expect(response).toEqual(requestBody);
55
- });
56
-
57
- it("should handle rfc7231 encode for datetime property", async () => {
58
- // Use a fixed date string for clarity.
59
- const requestBody = { value: new Date("Fri, 26 Aug 2022 14:38:00 GMT") };
60
- const response = await client.rfc7231(requestBody);
61
- expect(response).toEqual(requestBody);
62
- });
63
-
64
- it.skip("should handle unixTimestamp encode for datetime property", async () => {
65
- // Correct property unixTimestamp date.
66
- const requestBody = { value: new Date("2023-06-12T06:41:04.000Z") };
67
- const response = await client.unixTimestamp(requestBody);
68
- expect(response).toEqual(requestBody);
69
- });
70
-
71
- it.skip("should handle unixTimestamp encode for datetime array property", async () => {
72
- // Correct property unixTimestamp-array dates.
73
- const requestBody = {
74
- value: [new Date("2023-06-12T06:41:04.000Z"), new Date("2023-06-14T11:57:36.000Z")],
75
- };
76
- const response = await client.unixTimestampArray(requestBody);
77
- expect(response).toEqual(requestBody);
78
- });
79
- });
80
-
81
- describe("HeaderClient", () => {
82
- const client = new HeaderClient({ allowInsecureConnection: true });
83
-
84
- it("should test default encode (rfc7231) for datetime header", async () => {
85
- await client.default_(new Date("2022-08-26T14:38:00.000Z"));
86
- // Assert successful request
87
- });
88
-
89
- it("should test rfc3339 encode for datetime header", async () => {
90
- await client.rfc3339(new Date("2022-08-26T18:38:00.000Z"));
91
- // Assert successful request
92
- });
93
-
94
- it("should test rfc7231 encode for datetime header", async () => {
95
- await client.rfc7231(new Date("2022-08-26T14:38:00.000Z"));
96
- // Assert successful request
97
- });
98
-
99
- it.skip("should test unixTimestamp encode for datetime header", async () => {
100
- // Correct should test default encode (base64) for bytes query parameterheader unixTimestamp date.
101
- await client.unixTimestamp(new Date("2023-06-12T06:41:04.000Z"));
102
- // Assert successful request
103
- });
104
-
105
- it.skip("should test unixTimestamp encode for datetime array header", async () => {
106
- // Correct header unixTimestamp-array dates.
107
- const timestamps = [
108
- new Date("2023-06-12T06:41:04.000Z"),
109
- new Date("2023-06-14T11:57:36.000Z"),
110
- ];
111
- await client.unixTimestampArray(timestamps);
112
- // Assert successful request
113
- });
114
- });
115
-
116
- describe("ResponseHeaderClient", () => {
117
- const client = new ResponseHeaderClient({
118
- allowInsecureConnection: true,
119
- retryOptions: {
120
- maxRetries: 1,
121
- },
122
- });
123
-
124
- it("should handle default encode (rfc7231) for datetime response header", async () => {
125
- let value;
126
- await client.default_({
127
- operationOptions: {
128
- onResponse: (r) => {
129
- value = new Date((r.headers as any)["value"]);
130
- },
131
- },
132
- });
133
- expect(value).toEqual(new Date("2022-08-26T14:38:00.000Z"));
134
- });
135
-
136
- it("should handle rfc3339 encode for datetime response header", async () => {
137
- let value;
138
-
139
- await client.rfc3339({
140
- operationOptions: {
141
- onResponse: (r) => {
142
- value = new Date((r.headers as any)["value"]);
143
- },
144
- },
145
- });
146
- expect(value).toEqual(new Date("2022-08-26T18:38:00.000Z"));
147
- });
148
-
149
- it("should handle rfc7231 encode for datetime response header", async () => {
150
- let value;
151
-
152
- await client.rfc3339({
153
- operationOptions: {
154
- onResponse: (r) => {
155
- value = new Date((r.headers as any)["value"]);
156
- },
157
- },
158
- });
159
- expect(value).toEqual(new Date("2022-08-26T18:38:00.000Z"));
160
- });
161
-
162
- it("should handle unixTimestamp encode for datetime response header", async () => {
163
- let value;
164
-
165
- // Correct response header unixTimestamp date.
166
- await client.rfc3339({
167
- operationOptions: {
168
- onResponse: (r) => {
169
- value = r.headers["value"];
170
- },
171
- },
172
- });
173
- expect(value).toEqual("2022-08-26T18:38:00.000Z");
174
- });
175
- });
176
- });