@typespec/http-client-js 0.1.0 → 0.2.0-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +193 -0
- package/README.md +31 -15
- package/dist/src/components/client-context/client-context-declaration.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-declaration.js.map +1 -1
- package/dist/src/components/client-context/client-context-factory.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-factory.js +7 -4
- package/dist/src/components/client-context/client-context-factory.js.map +1 -1
- package/dist/src/components/client-context/client-context-options.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-options.js +13 -9
- package/dist/src/components/client-context/client-context-options.js.map +1 -1
- package/dist/src/components/client-context/client-context.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context.js +7 -12
- package/dist/src/components/client-context/client-context.js.map +1 -1
- package/dist/src/components/client-context/parametrized-endpoint.d.ts +1 -1
- package/dist/src/components/client-context/parametrized-endpoint.d.ts.map +1 -1
- package/dist/src/components/client-context/parametrized-endpoint.js +22 -13
- package/dist/src/components/client-context/parametrized-endpoint.js.map +1 -1
- package/dist/src/components/client-directory.d.ts +2 -2
- package/dist/src/components/client-directory.d.ts.map +1 -1
- package/dist/src/components/client-directory.js +33 -21
- package/dist/src/components/client-directory.js.map +1 -1
- package/dist/src/components/client-operation.d.ts.map +1 -1
- package/dist/src/components/client-operation.js +6 -6
- package/dist/src/components/client-operation.js.map +1 -1
- package/dist/src/components/client.d.ts +1 -1
- package/dist/src/components/client.d.ts.map +1 -1
- package/dist/src/components/client.js +83 -64
- package/dist/src/components/client.js.map +1 -1
- package/dist/src/components/encoding-provider.d.ts.map +1 -1
- package/dist/src/components/encoding-provider.js +0 -1
- package/dist/src/components/encoding-provider.js.map +1 -1
- package/dist/src/components/http-request-options.d.ts.map +1 -1
- package/dist/src/components/http-request-options.js +3 -3
- package/dist/src/components/http-request-options.js.map +1 -1
- package/dist/src/components/http-request-parameters-expression.d.ts +1 -2
- package/dist/src/components/http-request-parameters-expression.d.ts.map +1 -1
- package/dist/src/components/http-request-parameters-expression.js +37 -33
- package/dist/src/components/http-request-parameters-expression.js.map +1 -1
- package/dist/src/components/http-request.d.ts.map +1 -1
- package/dist/src/components/http-request.js +24 -20
- package/dist/src/components/http-request.js.map +1 -1
- package/dist/src/components/http-response.d.ts +1 -1
- package/dist/src/components/http-response.d.ts.map +1 -1
- package/dist/src/components/http-response.js +36 -33
- package/dist/src/components/http-response.js.map +1 -1
- package/dist/src/components/models.d.ts.map +1 -1
- package/dist/src/components/models.js +21 -18
- package/dist/src/components/models.js.map +1 -1
- package/dist/src/components/operation-options.d.ts.map +1 -1
- package/dist/src/components/operation-options.js +17 -14
- package/dist/src/components/operation-options.js.map +1 -1
- package/dist/src/components/output.d.ts.map +1 -1
- package/dist/src/components/output.js +2 -1
- package/dist/src/components/output.js.map +1 -1
- package/dist/src/components/serializers.d.ts.map +1 -1
- package/dist/src/components/serializers.js +21 -14
- package/dist/src/components/serializers.js.map +1 -1
- package/dist/src/components/static-helpers/bytes-encoding.d.ts.map +1 -1
- package/dist/src/components/static-helpers/bytes-encoding.js +2 -2
- package/dist/src/components/static-helpers/bytes-encoding.js.map +1 -1
- package/dist/src/components/static-helpers/interfaces.d.ts.map +1 -1
- package/dist/src/components/static-helpers/interfaces.js.map +1 -1
- package/dist/src/components/static-helpers/multipart-helpers.d.ts.map +1 -1
- package/dist/src/components/static-helpers/multipart-helpers.js +4 -4
- package/dist/src/components/static-helpers/multipart-helpers.js.map +1 -1
- package/dist/src/components/static-helpers/rest-error.d.ts.map +1 -1
- package/dist/src/components/static-helpers/rest-error.js +66 -57
- package/dist/src/components/static-helpers/rest-error.js.map +1 -1
- package/dist/src/components/testing/client-options.d.ts.map +1 -1
- package/dist/src/components/testing/client-options.js +0 -2
- package/dist/src/components/testing/client-options.js.map +1 -1
- package/dist/src/components/transforms/content-type-encoding-provider.d.ts.map +1 -1
- package/dist/src/components/transforms/content-type-encoding-provider.js +0 -1
- package/dist/src/components/transforms/content-type-encoding-provider.js.map +1 -1
- package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-array-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js +4 -4
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-base-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-base-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-property-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-property-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-transform.js +20 -17
- package/dist/src/components/transforms/json/json-model-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-record-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-transform-discriminator.js +5 -10
- package/dist/src/components/transforms/json/json-transform-discriminator.js.map +1 -1
- package/dist/src/components/transforms/json/json-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-transform.js.map +1 -1
- package/dist/src/components/transforms/json/union-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/union-transform.js +2 -2
- package/dist/src/components/transforms/json/union-transform.js.map +1 -1
- package/dist/src/components/transforms/multipart/array-part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/array-part-transform.js.map +1 -1
- package/dist/src/components/transforms/multipart/file-part-transform.js +1 -1
- package/dist/src/components/transforms/multipart/file-part-transform.js.map +1 -1
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/multipart-transform.js +9 -6
- package/dist/src/components/transforms/multipart/multipart-transform.js.map +1 -1
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/simple-part-transform.js +23 -13
- package/dist/src/components/transforms/multipart/simple-part-transform.js.map +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.js +2 -2
- package/dist/src/components/transforms/operation-transform-declaration.js.map +1 -1
- package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-expression.js.map +1 -1
- package/dist/src/components/utils/unpack-model-property.d.ts.map +1 -1
- package/dist/src/components/utils/unpack-model-property.js +11 -2
- package/dist/src/components/utils/unpack-model-property.js.map +1 -1
- package/dist/src/components/utils/url-template.d.ts.map +1 -1
- package/dist/src/components/utils/url-template.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +6 -6
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +2 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/utils/operations.d.ts +13 -1
- package/dist/src/utils/operations.d.ts.map +1 -1
- package/dist/src/utils/operations.js +71 -0
- package/dist/src/utils/operations.js.map +1 -1
- package/dist/src/utils/parameters.d.ts.map +1 -1
- package/dist/src/utils/parameters.js +1 -1
- package/dist/src/utils/parameters.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/emit-e2e.js +1 -1
- package/package.json +14 -13
- package/src/components/client-context/client-context-declaration.tsx +8 -1
- package/src/components/client-context/client-context-factory.tsx +50 -30
- package/src/components/client-context/client-context-options.tsx +13 -6
- package/src/components/client-context/client-context.tsx +5 -3
- package/src/components/client-context/parametrized-endpoint.tsx +26 -15
- package/src/components/client-directory.tsx +26 -16
- package/src/components/client-operation.tsx +24 -12
- package/src/components/client.tsx +77 -39
- package/src/components/encoding-provider.tsx +1 -3
- package/src/components/http-request-options.tsx +24 -14
- package/src/components/http-request-parameters-expression.tsx +34 -37
- package/src/components/http-request.tsx +26 -16
- package/src/components/http-response.tsx +31 -26
- package/src/components/models.tsx +18 -14
- package/src/components/operation-options.tsx +18 -5
- package/src/components/output.tsx +10 -9
- package/src/components/serializers.tsx +21 -9
- package/src/components/static-helpers/bytes-encoding.tsx +26 -8
- package/src/components/static-helpers/interfaces.tsx +14 -9
- package/src/components/static-helpers/multipart-helpers.tsx +34 -13
- package/src/components/static-helpers/rest-error.tsx +56 -18
- package/src/components/testing/client-options.tsx +0 -3
- package/src/components/transforms/content-type-encoding-provider.tsx +1 -3
- package/src/components/transforms/json/json-array-transform.tsx +6 -4
- package/src/components/transforms/json/json-model-additional-properties-transform.tsx +18 -13
- package/src/components/transforms/json/json-model-base-transform.tsx +6 -1
- package/src/components/transforms/json/json-model-property-transform.tsx +7 -9
- package/src/components/transforms/json/json-model-transform.tsx +44 -16
- package/src/components/transforms/json/json-record-transform.tsx +5 -3
- package/src/components/transforms/json/json-transform-discriminator.tsx +17 -30
- package/src/components/transforms/json/json-transform.tsx +5 -3
- package/src/components/transforms/json/union-transform.tsx +20 -8
- package/src/components/transforms/multipart/array-part-transform.tsx +6 -3
- package/src/components/transforms/multipart/file-part-transform.tsx +1 -1
- package/src/components/transforms/multipart/multipart-transform.tsx +4 -6
- package/src/components/transforms/multipart/part-transform.tsx +1 -1
- package/src/components/transforms/multipart/simple-part-transform.tsx +16 -13
- package/src/components/transforms/operation-transform-declaration.tsx +24 -7
- package/src/components/transforms/operation-transform-expression.tsx +12 -5
- package/src/components/utils/unpack-model-property.ts +13 -2
- package/src/components/utils/url-template.tsx +10 -6
- package/src/emitter.tsx +4 -3
- package/src/lib.ts +6 -1
- package/src/utils/operations.ts +96 -1
- package/src/utils/parameters.tsx +5 -1
- package/test/e2e/http/payload/multipart/main.test.ts +20 -24
- package/test/e2e/http/type/property/additional-properties/spreads.test.ts +4 -1
- package/test/scenarios/additional-properties/extends.md +0 -4
- package/test/scenarios/additional-properties/is.md +0 -4
- package/test/scenarios/additional-properties/spread.md +0 -4
- package/test/scenarios/auth/basic_auth.md +0 -1
- package/test/scenarios/auth/bearer.md +0 -1
- package/test/scenarios/auth/client_parameters.md +0 -1
- package/test/scenarios/auth/key_credential.md +0 -1
- package/test/scenarios/auth/sub_client_override.md +0 -2
- package/test/scenarios/client/dotted_namespace.md +0 -1
- package/test/scenarios/client/global_namespace.md +0 -5
- package/test/scenarios/client/multiple_top_level_clients.md +0 -2
- package/test/scenarios/client/nested_client.md +0 -2
- package/test/scenarios/encoding/bytes_body.md +0 -4
- package/test/scenarios/encoding/bytes_json_property.md +0 -5
- package/test/scenarios/encoding/bytes_nullable.md +0 -14
- package/test/scenarios/encoding/header_bytes.md +0 -12
- package/test/scenarios/encoding/header_date.md +0 -20
- package/test/scenarios/encoding/model_with_bytes_property.md +0 -5
- package/test/scenarios/encoding/query_bytes.md +0 -4
- package/test/scenarios/encoding/query_date.md +0 -20
- package/test/scenarios/http-operations/basic-request.md +0 -12
- package/test/scenarios/http-operations/basic-response.md +0 -19
- package/test/scenarios/http-operations/basic.md +0 -6
- package/test/scenarios/http-operations/constant-header.md +0 -4
- package/test/scenarios/http-operations/create-operation.md +0 -4
- package/test/scenarios/http-operations/on_response.md +0 -4
- package/test/scenarios/http-operations/optional-request-body.md +0 -5
- package/test/scenarios/http-operations/path-parameter-in-model.md +0 -4
- package/test/scenarios/http-operations/path-parameter.md +0 -4
- package/test/scenarios/http-operations/scalar-payload.md +0 -4
- package/test/scenarios/http-operations/with-parameters.md +0 -5
- package/test/scenarios/models/inheritance_2_discriminators.md +0 -24
- package/test/scenarios/models/inheritance_discriminator.md +0 -4
- package/test/scenarios/models/inline-models.md +1 -4
- package/test/scenarios/models/model_additional_properties.md +0 -4
- package/test/scenarios/models/model_extends.md +0 -4
- package/test/scenarios/models/model_spread.md +0 -2
- package/test/scenarios/models/nested_property.md +0 -4
- package/test/scenarios/models/property_references_property.md +0 -6
- package/test/scenarios/multipart/anonymous_part.md +2 -11
- package/test/scenarios/multipart/file.md +0 -12
- package/test/scenarios/multipart/file_content_type.md +15 -5
- package/test/scenarios/multipart/non-string-float.md +50 -0
- package/test/scenarios/multipart/simple_part.md +0 -4
- package/test/scenarios/operation-parameters/body_root_anonymous.md +2 -17
- package/test/scenarios/operation-parameters/constant_as_optional.md +0 -5
- package/test/scenarios/operation-parameters/default_value_as_optional.md +0 -5
- package/test/scenarios/operation-parameters/no_content_type.md +0 -5
- package/test/scenarios/operation-parameters/no_parameters.md +0 -5
- package/test/scenarios/operation-parameters/only_optional.md +0 -5
- package/test/scenarios/operation-parameters/only_required.md +0 -5
- package/test/scenarios/operation-parameters/reserved_names.md +0 -5
- package/test/scenarios/operation-parameters/spread_body.md +0 -5
- package/test/scenarios/operation-parameters/spread_with_nested.md +0 -5
- package/test/scenarios/operation-parameters/union_body.md +0 -6
- package/test/scenarios/operation-parameters/with_body_property.md +0 -5
- package/test/scenarios/operation-parameters/with_body_root.md +0 -5
- package/test/scenarios/serializers/arrays.md +0 -8
- package/test/scenarios/serializers/basic_model.md +0 -4
- package/test/scenarios/serializers/basic_model_wire_name.md +0 -2
- package/test/scenarios/serializers/discriminated_union.md +1 -1
- package/test/scenarios/serializers/discriminated_union_spread.md +1 -5
- package/test/scenarios/serializers/multipart.md +0 -4
- package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +0 -5
- package/test/scenarios/serializers/property_references_property.md +72 -0
- package/test/scenarios/serializers/record.md +0 -4
- package/test/scenarios/serializers/scalars.md +0 -5
- package/test/scenarios/serializers/spread.md +0 -4
- package/test/scenarios/serializers/string_union.md +0 -4
package/eng/scripts/emit-e2e.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-dev.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -24,29 +24,30 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"description": "TypeSpec library for emitting Http Client libraries for JavaScript/TypeScript",
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@typespec/compiler": "
|
|
28
|
-
"@typespec/emitter-framework": "
|
|
29
|
-
"@typespec/http": "
|
|
30
|
-
"@typespec/http-client": "
|
|
31
|
-
"@typespec/rest": "
|
|
27
|
+
"@typespec/compiler": "^0.66.0 || >=0.67.0-dev <0.67.0",
|
|
28
|
+
"@typespec/emitter-framework": "^0.2.0 || >=0.3.0-dev <0.3.0",
|
|
29
|
+
"@typespec/http": "^0.66.0 || >=0.67.0-dev <0.67.0",
|
|
30
|
+
"@typespec/http-client": "^0.2.0 || >=0.3.0-dev <0.3.0",
|
|
31
|
+
"@typespec/rest": "^0.66.0 || >=0.67.0-dev <0.67.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@alloy-js/core": "^0.
|
|
35
|
-
"@alloy-js/typescript": "^0.
|
|
34
|
+
"@alloy-js/core": "^0.6.0",
|
|
35
|
+
"@alloy-js/typescript": "^0.6.0",
|
|
36
36
|
"prettier": "~3.5.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@alloy-js/babel-preset": "^0.
|
|
39
|
+
"@alloy-js/babel-preset": "^0.2.0",
|
|
40
40
|
"@babel/cli": "^7.24.8",
|
|
41
41
|
"@babel/core": "^7.26.9",
|
|
42
42
|
"@rollup/plugin-babel": "^6.0.4",
|
|
43
43
|
"@types/yargs": "~17.0.33",
|
|
44
|
-
"@typespec/http-specs": "0.1.0-alpha.
|
|
44
|
+
"@typespec/http-specs": "^0.1.0-alpha.12 || >=0.1.0-alpha.13-dev <0.1.0-alpha.13",
|
|
45
|
+
"@typespec/spector": "^0.1.0-alpha.8 || >=0.1.0-alpha.9-dev <0.1.0-alpha.9",
|
|
45
46
|
"@typespec/ts-http-runtime": "0.1.0",
|
|
47
|
+
"@typespec/versioning": "^0.66.0 || >=0.67.0-dev <0.67.0",
|
|
46
48
|
"@vitest/ui": "^3.0.7",
|
|
47
49
|
"picocolors": "~1.1.1",
|
|
48
50
|
"concurrently": "^9.1.2",
|
|
49
|
-
"dotenv": "^16.4.7",
|
|
50
51
|
"execa": "^9.5.2",
|
|
51
52
|
"fs-extra": "^11.2.0",
|
|
52
53
|
"globby": "~14.1.0",
|
|
@@ -58,8 +59,7 @@
|
|
|
58
59
|
"vitest": "^3.0.7",
|
|
59
60
|
"yargs": "~17.7.2",
|
|
60
61
|
"change-case": "~5.4.4",
|
|
61
|
-
"@typespec/
|
|
62
|
-
"@typespec/versioning": "~0.66.0"
|
|
62
|
+
"@typespec/tspd": "^0.46.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build-src": "babel src -d dist/src --extensions .ts,.tsx",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"stop:server": "npx tsp-spector server stop",
|
|
79
79
|
"test:e2e": "npm run emit:e2e && node eng/scripts/run-e2e-tests.js",
|
|
80
80
|
"run:e2e": "node eng/scripts/run-e2e-tests.js",
|
|
81
|
+
"regen-docs": "tspd doc . --enable-experimental --output-dir ../../website/src/content/docs/docs/emitters/clients/http-client-js/reference --skip-js",
|
|
81
82
|
"emit:e2e": "node eng/scripts/emit-e2e.js"
|
|
82
83
|
}
|
|
83
84
|
}
|
|
@@ -15,5 +15,12 @@ export function ClientContextDeclaration(props: ClientContextDeclarationProps) {
|
|
|
15
15
|
const ref = getClientcontextDeclarationRef(props.client);
|
|
16
16
|
const namePolicy = ts.useTSNamePolicy();
|
|
17
17
|
const name = namePolicy.getName(`${props.client.name}Context`, "class");
|
|
18
|
-
return
|
|
18
|
+
return (
|
|
19
|
+
<ts.InterfaceDeclaration
|
|
20
|
+
export
|
|
21
|
+
name={name}
|
|
22
|
+
refkey={ref}
|
|
23
|
+
extends={httpRuntimeTemplateLib.Client}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
19
26
|
}
|
|
@@ -28,8 +28,13 @@ export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps
|
|
|
28
28
|
const parameters = buildClientParameters(props.client);
|
|
29
29
|
const urlTemplate = $.client.getUrlTemplate(props.client);
|
|
30
30
|
const endpointRef = ay.refkey();
|
|
31
|
-
const resolvedEndpoint =
|
|
32
|
-
<ParametrizedEndpoint
|
|
31
|
+
const resolvedEndpoint = (
|
|
32
|
+
<ParametrizedEndpoint
|
|
33
|
+
refkey={endpointRef}
|
|
34
|
+
template={urlTemplate.url}
|
|
35
|
+
params={urlTemplate.parameters}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
33
38
|
|
|
34
39
|
let credentialsRef: string | undefined;
|
|
35
40
|
if (clientConstructor.parameters.properties.has("credential")) {
|
|
@@ -37,21 +42,28 @@ export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
// Filter out optional parameters, they will be passed as options
|
|
40
|
-
const args =
|
|
41
|
-
<ClientFactoryArguments
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
const args = (
|
|
46
|
+
<ClientFactoryArguments
|
|
47
|
+
client={props.client}
|
|
48
|
+
endpointRef={endpointRef}
|
|
49
|
+
credentialsRef={credentialsRef}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<FunctionDeclaration
|
|
55
|
+
export
|
|
56
|
+
name={factoryFunctionName}
|
|
57
|
+
type={clientConstructor}
|
|
58
|
+
returnType={contextDeclarationRef}
|
|
59
|
+
refkey={ref}
|
|
60
|
+
parametersMode="replace"
|
|
61
|
+
parameters={parameters}
|
|
62
|
+
>
|
|
63
|
+
{resolvedEndpoint}
|
|
64
|
+
return <ts.FunctionCallExpression target={httpRuntimeTemplateLib.getClient} args={[args]} />
|
|
65
|
+
</FunctionDeclaration>
|
|
66
|
+
);
|
|
55
67
|
}
|
|
56
68
|
|
|
57
69
|
interface ClientFactoryArgumentsProps {
|
|
@@ -98,22 +110,26 @@ function CredentialOptions(props: CredentialOptionsProps) {
|
|
|
98
110
|
switch (scheme.type) {
|
|
99
111
|
case "http":
|
|
100
112
|
// Todo: handle scopes?
|
|
101
|
-
return
|
|
102
|
-
<ts.
|
|
103
|
-
<ts.
|
|
104
|
-
|
|
105
|
-
|
|
113
|
+
return (
|
|
114
|
+
<ts.ObjectProperty name="credentials">
|
|
115
|
+
<ts.ObjectExpression>
|
|
116
|
+
<ts.ObjectProperty name="apiKeyHeaderName" jsValue={"Authorization"} />
|
|
117
|
+
</ts.ObjectExpression>
|
|
118
|
+
</ts.ObjectProperty>
|
|
119
|
+
);
|
|
106
120
|
case "apiKey":
|
|
107
121
|
if (scheme.in !== "header") {
|
|
108
122
|
reportDiagnostic($.program, { code: "non-model-parts", target: props.client.service });
|
|
109
123
|
return null;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
|
-
return
|
|
113
|
-
<ts.
|
|
114
|
-
<ts.
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
return (
|
|
127
|
+
<ts.ObjectProperty name="credentials">
|
|
128
|
+
<ts.ObjectExpression>
|
|
129
|
+
<ts.ObjectProperty name="apiKeyHeaderName" jsValue={scheme.name} />
|
|
130
|
+
</ts.ObjectExpression>
|
|
131
|
+
</ts.ObjectProperty>
|
|
132
|
+
);
|
|
117
133
|
default:
|
|
118
134
|
return null;
|
|
119
135
|
}
|
|
@@ -136,7 +152,11 @@ function ClientOptionsExpression(props: ClientOptionsExpressionProps) {
|
|
|
136
152
|
options.push(...children);
|
|
137
153
|
}
|
|
138
154
|
|
|
139
|
-
return
|
|
140
|
-
|
|
141
|
-
|
|
155
|
+
return (
|
|
156
|
+
<ts.ObjectExpression>
|
|
157
|
+
<ay.For each={options} joiner="," line>
|
|
158
|
+
{(child) => child}
|
|
159
|
+
</ay.For>
|
|
160
|
+
</ts.ObjectExpression>
|
|
161
|
+
);
|
|
142
162
|
}
|
|
@@ -19,10 +19,17 @@ export function ClientContextOptionsDeclaration(props: ClientContextOptionsDecla
|
|
|
19
19
|
// TODO: Here we will calculate and include all the options that the client can accept
|
|
20
20
|
const clientOptions: Map<string, ay.Children> = new Map();
|
|
21
21
|
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
return (
|
|
23
|
+
<ts.InterfaceDeclaration
|
|
24
|
+
export
|
|
25
|
+
name={name}
|
|
26
|
+
refkey={ref}
|
|
27
|
+
extends={<ts.Reference refkey={httpRuntimeTemplateLib.ClientOptions} />}
|
|
28
|
+
>
|
|
29
|
+
<ay.For each={Array.from(clientOptions.entries())} semicolon line>
|
|
30
|
+
{([key, value]) => <ts.InterfaceMember optional name={key} type={value} />}
|
|
31
|
+
</ay.For>
|
|
32
|
+
<ts.InterfaceMember optional name="endpoint" type="string" />;
|
|
33
|
+
</ts.InterfaceDeclaration>
|
|
34
|
+
);
|
|
28
35
|
}
|
|
@@ -13,9 +13,11 @@ export interface ClientContextProps {
|
|
|
13
13
|
export function ClientContext(props: ClientContextProps) {
|
|
14
14
|
const namePolicy = ts.useTSNamePolicy();
|
|
15
15
|
const fileName = namePolicy.getName(props.client.name + "Context", "variable");
|
|
16
|
-
return
|
|
17
|
-
|
|
16
|
+
return (
|
|
17
|
+
<ts.SourceFile path={`${fileName}.ts`}>
|
|
18
|
+
<ClientContextDeclaration client={props.client} />
|
|
18
19
|
<ClientContextOptionsDeclaration client={props.client} />
|
|
19
20
|
<ClientContextFactoryDeclaration client={props.client} />
|
|
20
|
-
|
|
21
|
+
</ts.SourceFile>
|
|
22
|
+
);
|
|
21
23
|
}
|
|
@@ -13,27 +13,38 @@ export interface ParametrizedEndpointProps {
|
|
|
13
13
|
export function ParametrizedEndpoint(props: ParametrizedEndpointProps) {
|
|
14
14
|
const propNamer = useTransformNamePolicy();
|
|
15
15
|
const paramsRef = ay.refkey();
|
|
16
|
-
const params =
|
|
16
|
+
const params = (
|
|
17
17
|
<ts.VarDeclaration name="params" type={"Record<string, any>"} refkey={paramsRef}>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
<ts.ObjectExpression>
|
|
19
|
+
<ay.For each={props.params} joiner="," line>
|
|
20
|
+
{(p) => {
|
|
21
|
+
const applicationName = propNamer.getApplicationName(p);
|
|
22
|
+
const transportName = propNamer.getTransportName(p);
|
|
23
|
+
const defaultValue = p.defaultValue ? ` ?? ${getDefaultValue(p)}` : "";
|
|
24
|
+
const itemRef = p.optional
|
|
25
|
+
? `options?.${applicationName}${defaultValue}`
|
|
26
|
+
: applicationName;
|
|
27
|
+
return <ts.ObjectProperty name={transportName} value={itemRef} />;
|
|
28
|
+
}}
|
|
29
|
+
</ay.For>
|
|
30
|
+
</ts.ObjectExpression>
|
|
31
|
+
</ts.VarDeclaration>
|
|
32
|
+
);
|
|
28
33
|
|
|
29
|
-
const resolvedEndpoint =
|
|
34
|
+
const resolvedEndpoint = (
|
|
30
35
|
<ts.VarDeclaration name="resolvedEndpoint" refkey={props.refkey}>
|
|
31
|
-
|
|
36
|
+
{ay.code`
|
|
32
37
|
"${props.template}".replace(/{([^}]+)}/g, (_, key) =>
|
|
33
38
|
key in ${paramsRef} ? String(params[key]) : (() => { throw new Error(\`Missing parameter: $\{key}\`); })()
|
|
34
39
|
);
|
|
35
40
|
`}
|
|
36
|
-
|
|
41
|
+
</ts.VarDeclaration>
|
|
42
|
+
);
|
|
37
43
|
|
|
38
|
-
return
|
|
44
|
+
return (
|
|
45
|
+
<ay.StatementList>
|
|
46
|
+
{params}
|
|
47
|
+
{resolvedEndpoint}
|
|
48
|
+
</ay.StatementList>
|
|
49
|
+
);
|
|
39
50
|
}
|
|
@@ -12,13 +12,17 @@ export interface OperationsDirectoryProps {
|
|
|
12
12
|
export function OperationsDirectory(props: OperationsDirectoryProps) {
|
|
13
13
|
const { topLevel: clients } = useClientLibrary();
|
|
14
14
|
// If it is the root client, we don't need to create a directory
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
return (
|
|
16
|
+
<ay.For each={clients} joiner="," line>
|
|
17
|
+
{(client) => (
|
|
18
|
+
<ay.StatementList>
|
|
19
|
+
<ClientOperations client={client} />
|
|
20
|
+
<ClientContext client={client} />
|
|
21
|
+
<SubClients client={client} />
|
|
22
|
+
</ay.StatementList>
|
|
23
|
+
)}
|
|
24
|
+
</ay.For>
|
|
25
|
+
);
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
export interface SubClientsProps {
|
|
@@ -28,13 +32,19 @@ export interface SubClientsProps {
|
|
|
28
32
|
export function SubClients(props: SubClientsProps) {
|
|
29
33
|
const subClients = props.client.subClients;
|
|
30
34
|
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
return (
|
|
36
|
+
<ay.For each={subClients}>
|
|
37
|
+
{(subClient) => {
|
|
38
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
39
|
+
const subClientName = namePolicy.getName(subClient.name, "variable");
|
|
40
|
+
return (
|
|
41
|
+
<ay.SourceDirectory path={subClientName}>
|
|
42
|
+
<ClientOperations client={subClient} />
|
|
43
|
+
<ClientContext client={subClient} />
|
|
44
|
+
<SubClients client={subClient} />
|
|
45
|
+
</ay.SourceDirectory>
|
|
46
|
+
);
|
|
47
|
+
}}
|
|
48
|
+
</ay.For>
|
|
49
|
+
);
|
|
40
50
|
}
|
|
@@ -22,11 +22,13 @@ export function ClientOperations(props: ClientOperationsProps) {
|
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</
|
|
25
|
+
return (
|
|
26
|
+
<ts.SourceFile path={`${fileName}.ts`}>
|
|
27
|
+
<ay.For each={clientOperations}>
|
|
28
|
+
{(operation) => <ClientOperation clientOperation={operation} />}
|
|
29
|
+
</ay.For>
|
|
30
|
+
</ts.SourceFile>
|
|
31
|
+
);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export interface ClientOperationProps {
|
|
@@ -42,11 +44,21 @@ export function ClientOperation(props: ClientOperationProps) {
|
|
|
42
44
|
client: { type: clientContextInterfaceRef, refkey: ay.refkey(client, "client") },
|
|
43
45
|
...getOperationParameters(props.clientOperation.httpOperation),
|
|
44
46
|
};
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
<OperationOptionsDeclaration operation={props.clientOperation.httpOperation} />
|
|
50
|
+
<FunctionDeclaration
|
|
51
|
+
export
|
|
52
|
+
async
|
|
53
|
+
type={props.clientOperation.httpOperation.operation}
|
|
54
|
+
returnType={<TypeExpression type={returnType} />}
|
|
55
|
+
parametersMode="replace"
|
|
56
|
+
parameters={signatureParams}
|
|
57
|
+
>
|
|
58
|
+
<HttpRequest operation={props.clientOperation} responseRefkey={responseRefkey} />
|
|
59
|
+
<HttpResponse operation={props.clientOperation} responseRefkey={responseRefkey} />
|
|
60
|
+
</FunctionDeclaration>
|
|
61
|
+
;
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
52
64
|
}
|
|
@@ -17,16 +17,20 @@ export function Client(props: ClientProps) {
|
|
|
17
17
|
const namePolicy = ts.useTSNamePolicy();
|
|
18
18
|
const { topLevel } = useClientLibrary();
|
|
19
19
|
|
|
20
|
-
return
|
|
21
|
-
topLevel
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
return (
|
|
21
|
+
<ay.For each={topLevel} hardline>
|
|
22
|
+
{(client) => {
|
|
23
|
+
const fileName = namePolicy.getName($.client.getName(client), "variable");
|
|
24
|
+
const flatClients = flattenClients(client);
|
|
25
|
+
return (
|
|
26
|
+
<ts.SourceFile path={`${fileName}.ts`}>
|
|
27
|
+
<ay.For each={flatClients} hardline>
|
|
28
|
+
{(client) => <ClientClass client={client} />}
|
|
29
|
+
</ay.For>
|
|
30
|
+
</ts.SourceFile>
|
|
31
|
+
);
|
|
32
|
+
}}
|
|
33
|
+
</ay.For>
|
|
30
34
|
);
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -49,21 +53,45 @@ export function ClientClass(props: ClientClassProps) {
|
|
|
49
53
|
const clientClassRef = getClientClassRef(props.client);
|
|
50
54
|
const subClients = props.client.subClients;
|
|
51
55
|
const operations = props.client.operations;
|
|
52
|
-
return
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
return (
|
|
57
|
+
<ClassDeclaration export name={clientName} refkey={clientClassRef}>
|
|
58
|
+
<ay.StatementList>
|
|
59
|
+
<ts.ClassField
|
|
60
|
+
name="context"
|
|
61
|
+
jsPrivate
|
|
62
|
+
refkey={contextMemberRef}
|
|
63
|
+
type={contextDeclarationRef}
|
|
64
|
+
/>
|
|
65
|
+
<ay.For each={subClients} hardline joiner=";">
|
|
66
|
+
{(subClient) => <SubClientClassField client={subClient} />}
|
|
67
|
+
</ay.For>
|
|
68
|
+
<ClientConstructor client={props.client} />;<br />
|
|
69
|
+
<ay.For each={operations} hardline joiner=";">
|
|
70
|
+
{(op) => {
|
|
71
|
+
const parameters = getOperationParameters(op.httpOperation);
|
|
72
|
+
const args = Object.keys(parameters).map((p) => p);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<ClassMethod
|
|
76
|
+
async
|
|
77
|
+
type={op.httpOperation.operation}
|
|
78
|
+
parameters={parameters}
|
|
79
|
+
returnType={null}
|
|
80
|
+
parametersMode="replace"
|
|
81
|
+
>
|
|
82
|
+
return{" "}
|
|
83
|
+
<ts.FunctionCallExpression
|
|
84
|
+
target={ay.refkey(op.httpOperation.operation)}
|
|
85
|
+
args={[contextMemberRef, ...args]}
|
|
86
|
+
/>
|
|
87
|
+
;
|
|
88
|
+
</ClassMethod>
|
|
89
|
+
);
|
|
90
|
+
}}
|
|
91
|
+
</ay.For>
|
|
92
|
+
</ay.StatementList>
|
|
93
|
+
</ClassDeclaration>
|
|
94
|
+
);
|
|
67
95
|
}
|
|
68
96
|
|
|
69
97
|
interface SubClientClassFieldProps {
|
|
@@ -95,22 +123,30 @@ interface ClientConstructorProps {
|
|
|
95
123
|
|
|
96
124
|
function ClientConstructor(props: ClientConstructorProps) {
|
|
97
125
|
const subClients = props.client.subClients.filter((sc) =>
|
|
98
|
-
$.client.haveSameConstructor(sc, props.client)
|
|
126
|
+
$.client.haveSameConstructor(sc, props.client),
|
|
127
|
+
);
|
|
99
128
|
const clientContextFieldRef = getClientContextFieldRef(props.client);
|
|
100
129
|
const clientContextFactoryRef = getClientContextFactoryRef(props.client);
|
|
101
130
|
const constructorParameters = buildClientParameters(props.client);
|
|
102
131
|
const args = Object.values(constructorParameters).map((p) => p.refkey);
|
|
103
132
|
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
133
|
+
return (
|
|
134
|
+
<ts.ClassMethod name="constructor" parameters={constructorParameters}>
|
|
135
|
+
{clientContextFieldRef} ={" "}
|
|
136
|
+
<ts.FunctionCallExpression target={clientContextFactoryRef} args={args} />;<br />
|
|
137
|
+
<ay.For each={subClients} joiner=";" hardline>
|
|
138
|
+
{(subClient) => {
|
|
139
|
+
const subClientFieldRef = getSubClientClassFieldRef(subClient);
|
|
140
|
+
const subClientArgs = calculateSubClientArgs(subClient, constructorParameters);
|
|
141
|
+
return (
|
|
142
|
+
<>
|
|
143
|
+
{subClientFieldRef} = <NewClientExpression client={subClient} args={subClientArgs} />;
|
|
144
|
+
</>
|
|
145
|
+
);
|
|
146
|
+
}}
|
|
147
|
+
</ay.For>
|
|
148
|
+
</ts.ClassMethod>
|
|
149
|
+
);
|
|
114
150
|
}
|
|
115
151
|
|
|
116
152
|
function calculateSubClientArgs(
|
|
@@ -131,7 +167,9 @@ export interface NewClientExpressionProps {
|
|
|
131
167
|
function NewClientExpression(props: NewClientExpressionProps) {
|
|
132
168
|
const clientConstructorRef = getClientClassRef(props.client);
|
|
133
169
|
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
new <ts.FunctionCallExpression target={clientConstructorRef} args={props.args} />
|
|
173
|
+
</>
|
|
174
|
+
);
|
|
137
175
|
}
|
|
@@ -13,7 +13,5 @@ export function EncodingProvider(props: EncodingProviderProps) {
|
|
|
13
13
|
...props.defaults,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
return <EncodingContext.Provider value={defaults}>
|
|
17
|
-
{props.children}
|
|
18
|
-
</EncodingContext.Provider>;
|
|
16
|
+
return <EncodingContext.Provider value={defaults}>{props.children}</EncodingContext.Provider>;
|
|
19
17
|
}
|
|
@@ -13,12 +13,14 @@ export interface HttpRequestOptionsProps {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function HttpRequestOptions(props: HttpRequestOptionsProps) {
|
|
16
|
-
return
|
|
17
|
-
<ts.
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
return (
|
|
17
|
+
<ts.VarDeclaration name="httpRequestOptions" refkey={props.refkey}>
|
|
18
|
+
<ts.ObjectExpression>
|
|
19
|
+
<HttpRequestOptions.Headers operation={props.operation} />
|
|
20
|
+
<HttpRequestOptions.Body operation={props.operation} />
|
|
21
|
+
</ts.ObjectExpression>
|
|
22
|
+
</ts.VarDeclaration>
|
|
23
|
+
);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export interface HttpRequestOptionsHeadersProps {
|
|
@@ -36,9 +38,13 @@ HttpRequestOptions.Headers = function HttpRequestOptionsHeaders(
|
|
|
36
38
|
);
|
|
37
39
|
|
|
38
40
|
const optionsParam = getOperationOptionsParameterRefkey(props.operation.httpOperation);
|
|
39
|
-
return
|
|
41
|
+
return (
|
|
42
|
+
<EncodingProvider defaults={{ bytes: "base64", datetime: "rfc7231" }}>
|
|
43
|
+
<ts.ObjectProperty name="headers">
|
|
40
44
|
<HttpRequestParametersExpression parameters={headers} optionsParameter={optionsParam} />,
|
|
41
|
-
|
|
45
|
+
</ts.ObjectProperty>
|
|
46
|
+
</EncodingProvider>
|
|
47
|
+
);
|
|
42
48
|
};
|
|
43
49
|
|
|
44
50
|
export interface HttpRequestOptionsBodyProps {
|
|
@@ -55,13 +61,17 @@ HttpRequestOptions.Body = function HttpRequestOptionsBody(props: HttpRequestOpti
|
|
|
55
61
|
return <></>;
|
|
56
62
|
}
|
|
57
63
|
// The transformer to apply to the body.
|
|
58
|
-
const bodyTransform =
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
const bodyTransform = (
|
|
65
|
+
<>
|
|
66
|
+
<OperationTransformExpression operation={props.operation} />
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
61
69
|
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
<ts.ObjectProperty name="body" value={bodyTransform} />,
|
|
73
|
+
</>
|
|
74
|
+
);
|
|
65
75
|
};
|
|
66
76
|
|
|
67
77
|
export function JSONSerializer(props: { children?: Children }) {
|