@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,200 +0,0 @@
1
- import type { Children } from "@alloy-js/core";
2
- import { code, List, refkey } from "@alloy-js/core";
3
- import * as ts from "@alloy-js/typescript";
4
- import { useTsp } from "@typespec/emitter-framework";
5
- import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
6
- import type { HttpOperation } from "@typespec/http";
7
- import * as cl from "@typespec/http-client";
8
- import { reportDiagnostic } from "../../../lib.js";
9
- import { getClientcontextDeclarationRef } from "../../client-context/client-context-declaration.jsx";
10
- import { OperationOptionsDeclaration } from "../../operation-options.jsx";
11
- import { getOperationParameters } from "../../operation-parameters.jsx";
12
- import {
13
- getBuildPagedAsyncIteratorRefkey,
14
- getPagedAsyncIterableIteratorRefkey,
15
- } from "../../static-helpers/paging-helper.jsx";
16
- import { getPageItemTypeName } from "../paging/page-item.jsx";
17
- import { getPageResponseTypeRefkey, PageResponseDeclaration } from "../paging/page-response.jsx";
18
- import {
19
- getPageSettingProperties,
20
- getPageSettingsTypeRefkey,
21
- PageSettingsDeclaration,
22
- } from "../paging/page-settings.jsx";
23
- import { HttpRequestSend } from "../paging/request-send.jsx";
24
- import {
25
- getHttpRequestDeserializeRefkey,
26
- HttpResponseDeserialize,
27
- } from "../paging/response-deserialize.jsx";
28
- import type { PagingDetail } from "../paging/util.js";
29
- import { extractPagingDetail } from "../paging/util.js";
30
- import type { OperationHandler } from "../types.js";
31
-
32
- export const PaginatedOperationHandler: OperationHandler = {
33
- canHandle(httpOperation: HttpOperation): boolean {
34
- const { $ } = useTsp();
35
- const pagingMetadata = $.operation.getPagingMetadata(httpOperation.operation);
36
- return pagingMetadata !== undefined;
37
- },
38
- handle(httpOperation: HttpOperation): Children {
39
- const { $ } = useTsp();
40
- const clientLibrary = cl.useClientLibrary();
41
- const client = clientLibrary.getClientForOperation(httpOperation);
42
-
43
- if (!client) {
44
- reportDiagnostic($.program, {
45
- code: "client-not-found",
46
- target: httpOperation.operation,
47
- });
48
- return;
49
- }
50
- const pagingOperation = $.operation.getPagingMetadata(httpOperation.operation)!;
51
- const responseRefkey = refkey(httpOperation, "http-response");
52
- const operationRefkey = refkey(httpOperation.operation);
53
- const returnType = code`${getPagedAsyncIterableIteratorRefkey()}<${getPageItemTypeName(pagingOperation)},${getPageResponseTypeRefkey(httpOperation)},${getPageSettingsTypeRefkey(httpOperation)}>`;
54
- const clientContextInterfaceRef = getClientcontextDeclarationRef(client);
55
- const optionsRefkey = refkey();
56
- const signatureParams: ts.ParameterDescriptor[] = [
57
- {
58
- name: "client",
59
- type: clientContextInterfaceRef,
60
- refkey: refkey(client, "paging-operation-client-param"),
61
- },
62
- ...getOperationParameters(httpOperation, optionsRefkey),
63
- ];
64
- const pagingDetail = extractPagingDetail(httpOperation, pagingOperation);
65
- // Exclude from operation options and include them into PageSettings
66
- const excludes = getPageSettingProperties(pagingOperation).map((p) => p.property);
67
- return (
68
- <List>
69
- <OperationOptionsDeclaration operation={httpOperation} excludes={excludes} />
70
- <PageSettingsDeclaration operation={httpOperation} pagingOperation={pagingOperation} />
71
- <PageResponseDeclaration operation={httpOperation} pagingOperation={pagingOperation} />
72
- <HttpRequestSend httpOperation={httpOperation} responseRefkey={responseRefkey} />
73
- <HttpResponseDeserialize httpOperation={httpOperation} responseRefkey={responseRefkey} />
74
- <FunctionDeclaration
75
- export
76
- name={httpOperation.operation.name}
77
- returnType={returnType}
78
- refkey={operationRefkey}
79
- parametersMode="replace"
80
- parameters={signatureParams}
81
- >
82
- <List>
83
- <GetElements httpOperation={httpOperation} pageDetail={pagingDetail} />
84
- <GetPagedResponse
85
- httpOperation={httpOperation}
86
- pageDetail={pagingDetail}
87
- operationParams={signatureParams}
88
- />
89
- <>
90
- {code`
91
- return ${getBuildPagedAsyncIteratorRefkey}<${getPageItemTypeName(pagingOperation)}, ${getPageResponseTypeRefkey(httpOperation)}, ${getPageSettingsTypeRefkey(httpOperation)}>({${getElementsRefkey(httpOperation)}, ${getPagedResponseFunctionRefkey(httpOperation)}: ${getPagedResponseFunctionRefkey(httpOperation)} as any});`}
92
- </>
93
- </List>
94
- </FunctionDeclaration>
95
- </List>
96
- );
97
- },
98
- };
99
-
100
- interface GetPagedResponseProps {
101
- httpOperation: HttpOperation;
102
- pageDetail: PagingDetail;
103
- operationParams: ts.ParameterDescriptor[];
104
- }
105
- function getPagedResponseFunctionRefkey(httpOperation: HttpOperation) {
106
- return refkey(httpOperation, "get-paged-response");
107
- }
108
-
109
- function GetPagedResponse(props: GetPagedResponseProps) {
110
- const pagingDetail = props.pageDetail;
111
- const httpOperation = props.httpOperation;
112
- const params: ts.ParameterDescriptor[] = [
113
- { name: "nextToken", type: "string", optional: true, refkey: refkey() },
114
- {
115
- name: "settings",
116
- type: getPageSettingsTypeRefkey(httpOperation),
117
- optional: true,
118
- refkey: refkey(),
119
- },
120
- ];
121
- // TODO: template can't resolve the ref key so fallback to useTSNamePolicy
122
- const namePolicy = ts.useTSNamePolicy();
123
- const functionName = namePolicy.getName(httpOperation.operation.name + "Send", "function");
124
- const sendParamStr = props.operationParams
125
- .map((param) => param.name)
126
- .slice(0, -1)
127
- .join(", ");
128
- return (
129
- <FunctionDeclaration
130
- name="getPagedResponse"
131
- async
132
- refkey={getPagedResponseFunctionRefkey(httpOperation)}
133
- parameters={params}
134
- >
135
- {code`
136
- ${
137
- props.pageDetail.pattern === "nextLink"
138
- ? `
139
- let response: PathUncheckedResponse;
140
- if (nextToken) {
141
- response = await client.pathUnchecked(nextToken).get();
142
- } else {
143
- const combinedOptions = { ...options, ...settings };
144
- response = await ${functionName}(${sendParamStr}, combinedOptions);
145
- } `
146
- : `
147
- const combinedOptions = {...options, ...settings};
148
- ${
149
- pagingDetail.input?.nextToken
150
- ? `
151
- if (nextToken) {
152
- combinedOptions.${pagingDetail.input?.nextToken} = nextToken;
153
- }`
154
- : ``
155
- }
156
- const response = await ${functionName}(${sendParamStr}, combinedOptions);
157
- `
158
- }
159
- return {
160
- pagedResponse: await ${getHttpRequestDeserializeRefkey(httpOperation)}(response, options),
161
- nextToken: ${
162
- pagingDetail.output.nextToken
163
- ? `response.${pagingDetail.output.nextToken.position}["${pagingDetail.output.nextToken.name}"]`
164
- : `undefined`
165
- },
166
- };
167
- `}
168
- </FunctionDeclaration>
169
- );
170
- }
171
-
172
- interface GetElementsProps {
173
- httpOperation: HttpOperation;
174
- pageDetail: PagingDetail;
175
- }
176
- function getElementsRefkey(httpOperation: HttpOperation) {
177
- return refkey(httpOperation, "get-elements");
178
- }
179
- function GetElements(props: GetElementsProps) {
180
- const pagingDetail = props.pageDetail;
181
- const httpOperation = props.httpOperation;
182
- const params = [
183
- {
184
- name: "response",
185
- type: getPageResponseTypeRefkey(httpOperation),
186
- refkey: refkey(),
187
- },
188
- ];
189
- return (
190
- <FunctionDeclaration
191
- name="getElements"
192
- refkey={getElementsRefkey(httpOperation)}
193
- parameters={params}
194
- >
195
- {code`
196
- return response.${pagingDetail.output.items};
197
- `}
198
- </FunctionDeclaration>
199
- );
200
- }
@@ -1,85 +0,0 @@
1
- import type { Refkey } from "@alloy-js/core";
2
- import { List, StatementList, code, refkey } from "@alloy-js/core";
3
- import * as ts from "@alloy-js/typescript";
4
- import { Reference } from "@alloy-js/typescript";
5
- import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
6
- import type { HttpOperation } from "@typespec/http";
7
- import * as cl from "@typespec/http-client";
8
- import { getClientcontextDeclarationRef } from "../../client-context/client-context-declaration.jsx";
9
- import { HttpRequestOptions } from "../../http-request-options.jsx";
10
- import { HttpRequest } from "../../http-request.jsx";
11
- import { getOperationParameters } from "../../operation-parameters.jsx";
12
-
13
- export interface HttpRequestSendProps {
14
- httpOperation: HttpOperation;
15
- responseRefkey?: Refkey;
16
- }
17
-
18
- export function getHttpRequestSendRefkey(httpOperation: HttpOperation) {
19
- return refkey(httpOperation, "http-request-send");
20
- }
21
-
22
- function getPagingOperationOptionsParameterRefkey(httpOperation: HttpOperation): Refkey {
23
- return refkey(httpOperation, "paging-operation-options-parameter");
24
- }
25
-
26
- export function getHttpRequestSendParams(httpOperation: HttpOperation) {
27
- const optionsRefkey = getPagingOperationOptionsParameterRefkey(httpOperation);
28
- const clientLibrary = cl.useClientLibrary();
29
- const client = clientLibrary.getClientForOperation(httpOperation);
30
- const clientContextInterfaceRef = getClientcontextDeclarationRef(client!);
31
- const signatureParams: ts.ParameterDescriptor[] = [
32
- {
33
- name: "client",
34
- type: clientContextInterfaceRef,
35
- refkey: refkey(client, "send-client-param"),
36
- },
37
- ...getOperationParameters(httpOperation, optionsRefkey),
38
- ];
39
- const parameters: ts.ParameterDescriptor[] = [...signatureParams];
40
- // re-correct the `options` parameter to Record<string, any> to accept both paging and non-paging options
41
- parameters[parameters.length - 1] = {
42
- name: "options",
43
- type: "Record<string, any>",
44
- refkey: optionsRefkey,
45
- optional: true,
46
- };
47
- return parameters;
48
- }
49
-
50
- export function HttpRequestSend(props: HttpRequestSendProps) {
51
- const httpOperation = props.httpOperation;
52
- const optionsRefkey = getPagingOperationOptionsParameterRefkey(httpOperation);
53
- const operationUrlRefkey = refkey();
54
- const requestOptionsVarRefkey = refkey();
55
- const verb = props.httpOperation.verb;
56
- const namePolicy = ts.useTSNamePolicy();
57
- const functionName = namePolicy.getName(httpOperation.operation.name + "Send", "function");
58
- const parameters = getHttpRequestSendParams(httpOperation);
59
- return (
60
- <FunctionDeclaration
61
- name={functionName}
62
- async
63
- refkey={getHttpRequestSendRefkey(httpOperation)}
64
- parametersMode="replace"
65
- parameters={parameters}
66
- >
67
- <List>
68
- <StatementList>
69
- <HttpRequest.Url
70
- httpOperation={props.httpOperation}
71
- pathVarRefkey={operationUrlRefkey}
72
- requestOptionsParamRefkey={optionsRefkey}
73
- />
74
-
75
- <HttpRequestOptions
76
- httpOperation={props.httpOperation}
77
- requestOptionsVarRefkey={requestOptionsVarRefkey}
78
- requestOptionsParamRefkey={optionsRefkey}
79
- />
80
- {code`return await client.pathUnchecked(${(<Reference refkey={operationUrlRefkey} />)}).${verb}(${(<Reference refkey={requestOptionsVarRefkey} />)});`}
81
- </StatementList>
82
- </List>
83
- </FunctionDeclaration>
84
- );
85
- }
@@ -1,60 +0,0 @@
1
- import type { Children, Refkey } from "@alloy-js/core";
2
- import { code, List, refkey } from "@alloy-js/core";
3
- import * as ts from "@alloy-js/typescript";
4
- import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
5
- import type { HttpOperation } from "@typespec/http";
6
- import { httpRuntimeTemplateLib } from "../../external-packages/ts-http-runtime.js";
7
- import type { HttpResponseProps } from "../../http-response.jsx";
8
- import { HttpResponses } from "../../http-response.jsx";
9
- import { getOperationOptionsTypeRefkey } from "../../operation-options.jsx";
10
- import { getCreateRestErrorRefkey } from "../../static-helpers/rest-error.jsx";
11
-
12
- export function getHttpRequestDeserializeRefkey(httpOperation: HttpOperation) {
13
- return refkey(httpOperation, "http-request-deserialize");
14
- }
15
-
16
- export interface HttpResponseDeserializeProps {
17
- httpOperation: HttpOperation;
18
- responseRefkey: Refkey;
19
- children?: Children;
20
- }
21
-
22
- export function getPagingDeserializationOptionsParamRef(httpOperation: HttpOperation): Refkey {
23
- return refkey(httpOperation, "paging-deserialization-options-parameter");
24
- }
25
-
26
- export function HttpResponseDeserialize(props: HttpResponseProps) {
27
- const httpOperation = props.httpOperation;
28
- const httpRequestOptionsRefkey = getPagingDeserializationOptionsParamRef(httpOperation);
29
- const namePolicy = ts.useTSNamePolicy();
30
- const functionName = namePolicy.getName(httpOperation.operation.name + "Deserialize", "function");
31
- const params = [
32
- {
33
- name: "response",
34
- type: httpRuntimeTemplateLib.PathUncheckedResponse,
35
- },
36
- {
37
- name: "options",
38
- refkey: httpRequestOptionsRefkey,
39
- type: getOperationOptionsTypeRefkey(httpOperation),
40
- optional: true,
41
- },
42
- ];
43
- return (
44
- <FunctionDeclaration
45
- name={functionName}
46
- refkey={getHttpRequestDeserializeRefkey(httpOperation)}
47
- parametersMode="replace"
48
- parameters={params}
49
- >
50
- {code`
51
- if (typeof options?.operationOptions?.onResponse === "function") {
52
- options?.operationOptions?.onResponse(response);
53
- }`}
54
- <List hardline>
55
- <HttpResponses httpOperation={props.httpOperation} />
56
- {code`throw ${getCreateRestErrorRefkey()}(response);`}
57
- </List>
58
- </FunctionDeclaration>
59
- );
60
- }
@@ -1,70 +0,0 @@
1
- import type { ModelProperty, PagingOperation } from "@typespec/compiler";
2
- import type { HttpOperation } from "@typespec/http";
3
-
4
- export interface PagingDetail {
5
- // Only support the nextLink or continuationToken
6
- pattern: "nextLink" | "continuationToken";
7
- input?: {
8
- nextToken: string;
9
- };
10
- output: {
11
- items: string;
12
- nextToken?: {
13
- name: string;
14
- position: "headers" | "body";
15
- };
16
- };
17
- }
18
-
19
- export function extractPagingDetail(
20
- httpOperation: HttpOperation,
21
- pagingOperation: PagingOperation,
22
- ): PagingDetail {
23
- const ret: PagingDetail = {
24
- pattern: "nextLink",
25
- output: {
26
- items: pagingOperation.output.pageItems.property.name,
27
- },
28
- };
29
- const returnedNextToken =
30
- pagingOperation.output.nextLink?.property ?? pagingOperation.output.continuationToken?.property;
31
- const isHeaderToken = getResponseHeader(httpOperation, returnedNextToken);
32
- const returnedTokenPosition = isHeaderToken ? "headers" : "body";
33
- const returnedTokenName = isHeaderToken ? isHeaderToken : returnedNextToken?.name;
34
- if (returnedNextToken && returnedTokenName) {
35
- ret.output.nextToken = {
36
- name: returnedTokenName,
37
- position: returnedTokenPosition,
38
- };
39
- }
40
- if (pagingOperation.output.continuationToken) {
41
- ret.pattern = "continuationToken";
42
- if (pagingOperation.input.continuationToken) {
43
- ret.input = {
44
- nextToken: pagingOperation.input.continuationToken?.property.name,
45
- };
46
- }
47
- return ret;
48
- }
49
- return ret;
50
- }
51
-
52
- function getResponseHeader(httpOperation: HttpOperation, prop?: ModelProperty): string | undefined {
53
- if (!prop) {
54
- return undefined;
55
- }
56
- const headers = httpOperation.responses
57
- .flatMap((resp) => resp.responses)
58
- .map((resp) => resp.headers);
59
- for (const header of headers) {
60
- if (!header) {
61
- continue;
62
- }
63
- for (const key in header) {
64
- if (header[key] === prop) {
65
- return key;
66
- }
67
- }
68
- }
69
- return undefined;
70
- }
@@ -1,18 +0,0 @@
1
- import { type Children } from "@alloy-js/core";
2
- import type { HttpOperation } from "@typespec/http";
3
-
4
- export interface OperationHandler {
5
- /**
6
- * Check if this handler can handle the given operation
7
- */
8
- canHandle(operation: HttpOperation): boolean;
9
-
10
- /**
11
- * Render the operation using this handler
12
- */
13
- handle(operation: HttpOperation): Children;
14
- }
15
-
16
- export interface OperationHandlerPipeline {
17
- handlers: OperationHandler[];
18
- }
@@ -1,42 +0,0 @@
1
- import { For, refkey } from "@alloy-js/core";
2
- import * as ts from "@alloy-js/typescript";
3
- import type { ModelProperty } from "@typespec/compiler";
4
- import * as ef from "@typespec/emitter-framework/typescript";
5
- import type { HttpOperation } from "@typespec/http";
6
- import { hasDefaultValue } from "../utils/parameters.jsx";
7
- import { getOperationOptionsInterfaceRefkey } from "./static-helpers/interfaces.jsx";
8
- export interface OperationOptionsProps {
9
- operation: HttpOperation;
10
- excludes?: ModelProperty[];
11
- }
12
-
13
- export function getOperationOptionsTypeRefkey(operation: HttpOperation) {
14
- return refkey(operation, "operation-options");
15
- }
16
- export function OperationOptionsDeclaration(props: OperationOptionsProps) {
17
- const namePolicy = ts.useTSNamePolicy();
18
- const excludes = (props.excludes ?? []).map((p) => p.name);
19
- const interfaceName = namePolicy.getName(props.operation.operation.name + "Options", "interface");
20
- const optionalParameters = props.operation.parameters.properties
21
- .filter((p) => !excludes.includes(p.property.name))
22
- .filter((p) => p.property.optional || hasDefaultValue(p));
23
-
24
- return (
25
- <ef.InterfaceDeclaration
26
- export
27
- name={interfaceName}
28
- extends={getOperationOptionsInterfaceRefkey()}
29
- refkey={getOperationOptionsTypeRefkey(props.operation)}
30
- >
31
- <For each={optionalParameters} line>
32
- {(parameter) => (
33
- <ts.InterfaceMember
34
- name={parameter.property.name}
35
- optional
36
- type={<ef.TypeExpression type={parameter.property.type} />}
37
- />
38
- )}
39
- </For>
40
- </ef.InterfaceDeclaration>
41
- );
42
- }
@@ -1,44 +0,0 @@
1
- import type { Refkey } from "@alloy-js/core";
2
- import { refkey } from "@alloy-js/core";
3
- import type * as ts from "@alloy-js/typescript";
4
- import { useTransformNamePolicy } from "@typespec/emitter-framework";
5
- import * as ef from "@typespec/emitter-framework/typescript";
6
- import type { HttpOperation } from "@typespec/http";
7
- import { hasDefaultValue } from "../utils/parameters.jsx";
8
- import { getOperationOptionsTypeRefkey } from "./operation-options.jsx";
9
-
10
- export interface OperationParametersProps {
11
- operation: HttpOperation;
12
- }
13
-
14
- export function getOperationParameters(
15
- operation: HttpOperation,
16
- optionsRefkey: Refkey,
17
- ): ts.ParameterDescriptor[] {
18
- const transformNamer = useTransformNamePolicy();
19
- const requiredParameters = operation.parameters.properties
20
- .filter((p) => !p.property.optional && !hasDefaultValue(p))
21
- .filter((p) => p.path.length === 1);
22
-
23
- const parameters: ts.ParameterDescriptor[] = [];
24
-
25
- for (const parameter of requiredParameters) {
26
- const name = transformNamer.getApplicationName(parameter.property);
27
- const parameterDescriptor: ts.ParameterDescriptor = {
28
- name,
29
- refkey: refkey(),
30
- type: <ef.TypeExpression type={parameter.property.type} />,
31
- };
32
-
33
- parameters.push(parameterDescriptor);
34
- }
35
-
36
- parameters.push({
37
- name: "options",
38
- refkey: optionsRefkey,
39
- type: getOperationOptionsTypeRefkey(operation),
40
- optional: true,
41
- });
42
-
43
- return parameters;
44
- }
@@ -1,32 +0,0 @@
1
- import type { Children } from "@alloy-js/core/jsx-runtime";
2
- import * as ts from "@alloy-js/typescript";
3
- import type { Program } from "@typespec/compiler";
4
- import { Output as EFOutput, TransformNamePolicyContext } from "@typespec/emitter-framework";
5
- import { ClientLibrary } from "@typespec/http-client/components";
6
- import { EncodingProvider } from "./encoding-provider.jsx";
7
- import { httpRuntimeTemplateLib } from "./external-packages/ts-http-runtime.js";
8
- import { uriTemplateLib } from "./external-packages/uri-template.js";
9
- import { createTransformNamePolicy } from "./transforms/transform-name-policy.js";
10
-
11
- export interface OutputProps {
12
- children?: Children;
13
- program: Program;
14
- }
15
-
16
- export function Output(props: OutputProps) {
17
- const tsNamePolicy = ts.createTSNamePolicy();
18
- const defaultTransformNamePolicy = createTransformNamePolicy();
19
- return (
20
- <EFOutput
21
- namePolicy={tsNamePolicy}
22
- externals={[uriTemplateLib, httpRuntimeTemplateLib]}
23
- program={props.program}
24
- >
25
- <ClientLibrary program={props.program}>
26
- <TransformNamePolicyContext.Provider value={defaultTransformNamePolicy}>
27
- <EncodingProvider>{props.children}</EncodingProvider>
28
- </TransformNamePolicyContext.Provider>
29
- </ClientLibrary>
30
- </EFOutput>
31
- );
32
- }
@@ -1,74 +0,0 @@
1
- import * as ts from "@alloy-js/typescript";
2
- import type { Type } from "@typespec/compiler";
3
- import { type Typekit } from "@typespec/compiler/typekit";
4
- import { useTsp } from "@typespec/emitter-framework";
5
- import {
6
- DateDeserializer,
7
- DateRfc3339Serializer,
8
- DateRfc7231Deserializer,
9
- DateRfc7231Serializer,
10
- DateUnixTimestampDeserializer,
11
- DateUnixTimestampSerializer,
12
- } from "@typespec/emitter-framework/typescript";
13
- import { useClientLibrary } from "@typespec/http-client";
14
- import { flattenClients } from "../utils/client-discovery.js";
15
- import { EncodingProvider } from "./encoding-provider.jsx";
16
- import { DecodeBase64, EncodeUint8Array } from "./static-helpers/bytes-encoding.jsx";
17
- import { JsonTransformDeclaration } from "./transforms/json/json-transform.jsx";
18
- import { TransformDeclaration } from "./transforms/operation-transform-declaration.jsx";
19
- export interface ModelSerializersProps {
20
- path?: string;
21
- }
22
-
23
- export function ModelSerializers(props: ModelSerializersProps) {
24
- const { $ } = useTsp();
25
- const clientLibrary = useClientLibrary();
26
- const dataTypes = clientLibrary.dataTypes;
27
- const flatClients = clientLibrary.topLevel.flatMap((c) => flattenClients(c));
28
- const operations = flatClients.flatMap((c) => c.operations);
29
- // Todo: Handle other kinds of serialization, for example XML. Might need to
30
- // revisit the way we process these and might need to track the relationship
31
- // between the data type and the operations that consume them.
32
- return (
33
- <ts.SourceFile path={props.path ?? "serializers.ts"}>
34
- <DecodeBase64 />
35
- <EncodeUint8Array />
36
- <DateDeserializer />
37
- <DateRfc7231Deserializer />
38
- <DateRfc3339Serializer />
39
- <DateRfc7231Serializer />
40
- <DateUnixTimestampSerializer />
41
- <DateUnixTimestampDeserializer />
42
- {operations.map((o) => (
43
- <TransformDeclaration operation={o} />
44
- ))}
45
- {dataTypes
46
- .filter((m) => m.kind === "Model" || m.kind === "Union")
47
- .map((type) => {
48
- let bytesDefaultEncoding: "base64" | "none" = "base64";
49
- if (isOrExtendsFile($, type)) {
50
- bytesDefaultEncoding = "none";
51
- }
52
-
53
- return (
54
- <EncodingProvider defaults={{ bytes: bytesDefaultEncoding }}>
55
- <JsonTransformDeclaration type={type} target="transport" />
56
- <JsonTransformDeclaration type={type} target="application" />
57
- </EncodingProvider>
58
- );
59
- })}
60
- </ts.SourceFile>
61
- );
62
- }
63
-
64
- function isOrExtendsFile($: Typekit, type: Type): boolean {
65
- if (!$.model.is(type)) {
66
- return false;
67
- }
68
-
69
- if ($.model.isHttpFile(type)) {
70
- return true;
71
- }
72
-
73
- return type.baseModel ? isOrExtendsFile($, type.baseModel) : false;
74
- }