@typespec/http-client-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.testignore +2 -0
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/babel.config.js +4 -0
- package/dist/src/components/client-context/client-context-declaration.d.ts +8 -0
- package/dist/src/components/client-context/client-context-declaration.d.ts.map +1 -0
- package/dist/src/components/client-context/client-context-declaration.js +21 -0
- package/dist/src/components/client-context/client-context-declaration.js.map +1 -0
- package/dist/src/components/client-context/client-context-factory.d.ts +8 -0
- package/dist/src/components/client-context/client-context-factory.d.ts.map +1 -0
- package/dist/src/components/client-context/client-context-factory.js +154 -0
- package/dist/src/components/client-context/client-context-factory.js.map +1 -0
- package/dist/src/components/client-context/client-context-options.d.ts +8 -0
- package/dist/src/components/client-context/client-context-options.d.ts.map +1 -0
- package/dist/src/components/client-context/client-context-options.js +42 -0
- package/dist/src/components/client-context/client-context-options.js.map +1 -0
- package/dist/src/components/client-context/client-context.d.ts +8 -0
- package/dist/src/components/client-context/client-context.d.ts.map +1 -0
- package/dist/src/components/client-context/client-context.js +33 -0
- package/dist/src/components/client-context/client-context.js.map +1 -0
- package/dist/src/components/client-context/parametrized-endpoint.d.ts +9 -0
- package/dist/src/components/client-context/parametrized-endpoint.d.ts.map +1 -0
- package/dist/src/components/client-context/parametrized-endpoint.js +48 -0
- package/dist/src/components/client-context/parametrized-endpoint.js.map +1 -0
- package/dist/src/components/client-directory.d.ts +11 -0
- package/dist/src/components/client-directory.d.ts.map +1 -0
- package/dist/src/components/client-directory.js +39 -0
- package/dist/src/components/client-directory.js.map +1 -0
- package/dist/src/components/client-operation.d.ts +11 -0
- package/dist/src/components/client-operation.d.ts.map +1 -0
- package/dist/src/components/client-operation.js +74 -0
- package/dist/src/components/client-operation.js.map +1 -0
- package/dist/src/components/client.d.ts +15 -0
- package/dist/src/components/client.d.ts.map +1 -0
- package/dist/src/components/client.js +153 -0
- package/dist/src/components/client.js.map +1 -0
- package/dist/src/components/encoding-provider.d.ts +8 -0
- package/dist/src/components/encoding-provider.d.ts.map +1 -0
- package/dist/src/components/encoding-provider.js +17 -0
- package/dist/src/components/encoding-provider.js.map +1 -0
- package/dist/src/components/external-packages/ts-http-runtime.d.ts +13 -0
- package/dist/src/components/external-packages/ts-http-runtime.d.ts.map +1 -0
- package/dist/src/components/external-packages/ts-http-runtime.js +11 -0
- package/dist/src/components/external-packages/ts-http-runtime.js.map +1 -0
- package/dist/src/components/external-packages/uri-template.d.ts +4 -0
- package/dist/src/components/external-packages/uri-template.d.ts.map +1 -0
- package/dist/src/components/external-packages/uri-template.js +11 -0
- package/dist/src/components/external-packages/uri-template.js.map +1 -0
- package/dist/src/components/http-request-options.d.ts +25 -0
- package/dist/src/components/http-request-options.d.ts.map +1 -0
- package/dist/src/components/http-request-options.js +74 -0
- package/dist/src/components/http-request-options.js.map +1 -0
- package/dist/src/components/http-request-parameters-expression.d.ts +10 -0
- package/dist/src/components/http-request-parameters-expression.d.ts.map +1 -0
- package/dist/src/components/http-request-parameters-expression.js +62 -0
- package/dist/src/components/http-request-parameters-expression.js.map +1 -0
- package/dist/src/components/http-request.d.ts +16 -0
- package/dist/src/components/http-request.d.ts.map +1 -0
- package/dist/src/components/http-request.js +70 -0
- package/dist/src/components/http-request.js.map +1 -0
- package/dist/src/components/http-response.d.ts +14 -0
- package/dist/src/components/http-response.d.ts.map +1 -0
- package/dist/src/components/http-response.js +61 -0
- package/dist/src/components/http-response.js.map +1 -0
- package/dist/src/components/models.d.ts +5 -0
- package/dist/src/components/models.d.ts.map +1 -0
- package/dist/src/components/models.js +41 -0
- package/dist/src/components/models.js.map +1 -0
- package/dist/src/components/operation-options.d.ts +8 -0
- package/dist/src/components/operation-options.d.ts.map +1 -0
- package/dist/src/components/operation-options.js +41 -0
- package/dist/src/components/operation-options.js.map +1 -0
- package/dist/src/components/operation-parameters.d.ts +9 -0
- package/dist/src/components/operation-parameters.d.ts.map +1 -0
- package/dist/src/components/operation-parameters.js +33 -0
- package/dist/src/components/operation-parameters.js.map +1 -0
- package/dist/src/components/output.d.ts +6 -0
- package/dist/src/components/output.d.ts.map +1 -0
- package/dist/src/components/output.js +35 -0
- package/dist/src/components/output.js.map +1 -0
- package/dist/src/components/serializers.d.ts +5 -0
- package/dist/src/components/serializers.d.ts.map +1 -0
- package/dist/src/components/serializers.js +43 -0
- package/dist/src/components/serializers.js.map +1 -0
- package/dist/src/components/static-helpers/bytes-encoding.d.ts +6 -0
- package/dist/src/components/static-helpers/bytes-encoding.d.ts.map +1 -0
- package/dist/src/components/static-helpers/bytes-encoding.js +68 -0
- package/dist/src/components/static-helpers/bytes-encoding.js.map +1 -0
- package/dist/src/components/static-helpers/interfaces.d.ts +5 -0
- package/dist/src/components/static-helpers/interfaces.d.ts.map +1 -0
- package/dist/src/components/static-helpers/interfaces.js +41 -0
- package/dist/src/components/static-helpers/interfaces.js.map +1 -0
- package/dist/src/components/static-helpers/multipart-helpers.d.ts +8 -0
- package/dist/src/components/static-helpers/multipart-helpers.d.ts.map +1 -0
- package/dist/src/components/static-helpers/multipart-helpers.js +83 -0
- package/dist/src/components/static-helpers/multipart-helpers.js.map +1 -0
- package/dist/src/components/static-helpers/rest-error.d.ts +5 -0
- package/dist/src/components/static-helpers/rest-error.d.ts.map +1 -0
- package/dist/src/components/static-helpers/rest-error.js +127 -0
- package/dist/src/components/static-helpers/rest-error.js.map +1 -0
- package/dist/src/components/testing/client-options.d.ts +8 -0
- package/dist/src/components/testing/client-options.d.ts.map +1 -0
- package/dist/src/components/testing/client-options.js +27 -0
- package/dist/src/components/testing/client-options.js.map +1 -0
- package/dist/src/components/transforms/content-type-encoding-provider.d.ts +7 -0
- package/dist/src/components/transforms/content-type-encoding-provider.d.ts.map +1 -0
- package/dist/src/components/transforms/content-type-encoding-provider.js +25 -0
- package/dist/src/components/transforms/content-type-encoding-provider.js.map +1 -0
- package/dist/src/components/transforms/data-transform.d.ts +9 -0
- package/dist/src/components/transforms/data-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/data-transform.js +31 -0
- package/dist/src/components/transforms/data-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-array-transform.d.ts +15 -0
- package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-array-transform.js +71 -0
- package/dist/src/components/transforms/json/json-array-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts +9 -0
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js +35 -0
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-model-base-transform.d.ts +9 -0
- package/dist/src/components/transforms/json/json-model-base-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-model-base-transform.js +13 -0
- package/dist/src/components/transforms/json/json-model-base-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-model-property-transform.d.ts +9 -0
- package/dist/src/components/transforms/json/json-model-property-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-model-property-transform.js +44 -0
- package/dist/src/components/transforms/json/json-model-property-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-model-transform.d.ts +15 -0
- package/dist/src/components/transforms/json/json-model-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-model-transform.js +96 -0
- package/dist/src/components/transforms/json/json-model-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-record-transform.d.ts +15 -0
- package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-record-transform.js +71 -0
- package/dist/src/components/transforms/json/json-record-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts +16 -0
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-transform-discriminator.js +82 -0
- package/dist/src/components/transforms/json/json-transform-discriminator.js.map +1 -0
- package/dist/src/components/transforms/json/json-transform.d.ts +14 -0
- package/dist/src/components/transforms/json/json-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-transform.js +149 -0
- package/dist/src/components/transforms/json/json-transform.js.map +1 -0
- package/dist/src/components/transforms/json/union-transform.d.ts +15 -0
- package/dist/src/components/transforms/json/union-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/union-transform.js +67 -0
- package/dist/src/components/transforms/json/union-transform.js.map +1 -0
- package/dist/src/components/transforms/json/utils/transport-namer.d.ts +3 -0
- package/dist/src/components/transforms/json/utils/transport-namer.d.ts.map +1 -0
- package/dist/src/components/transforms/json/utils/transport-namer.js +13 -0
- package/dist/src/components/transforms/json/utils/transport-namer.js.map +1 -0
- package/dist/src/components/transforms/multipart/array-part-transform.d.ts +8 -0
- package/dist/src/components/transforms/multipart/array-part-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/array-part-transform.js +29 -0
- package/dist/src/components/transforms/multipart/array-part-transform.js.map +1 -0
- package/dist/src/components/transforms/multipart/file-part-transform.d.ts +8 -0
- package/dist/src/components/transforms/multipart/file-part-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/file-part-transform.js +40 -0
- package/dist/src/components/transforms/multipart/file-part-transform.js.map +1 -0
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts +7 -0
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/multipart-transform.js +26 -0
- package/dist/src/components/transforms/multipart/multipart-transform.js.map +1 -0
- package/dist/src/components/transforms/multipart/part-transform.d.ts +8 -0
- package/dist/src/components/transforms/multipart/part-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/part-transform.js +35 -0
- package/dist/src/components/transforms/multipart/part-transform.js.map +1 -0
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts +8 -0
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/simple-part-transform.js +48 -0
- package/dist/src/components/transforms/multipart/simple-part-transform.js.map +1 -0
- package/dist/src/components/transforms/operation-transform-declaration.d.ts +17 -0
- package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -0
- package/dist/src/components/transforms/operation-transform-declaration.js +74 -0
- package/dist/src/components/transforms/operation-transform-declaration.js.map +1 -0
- package/dist/src/components/transforms/operation-transform-expression.d.ts +6 -0
- package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -0
- package/dist/src/components/transforms/operation-transform-expression.js +60 -0
- package/dist/src/components/transforms/operation-transform-expression.js.map +1 -0
- package/dist/src/components/transforms/scalar-transform.d.ts +15 -0
- package/dist/src/components/transforms/scalar-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/scalar-transform.js +317 -0
- package/dist/src/components/transforms/scalar-transform.js.map +1 -0
- package/dist/src/components/transforms/transform-name-policy.d.ts +71 -0
- package/dist/src/components/transforms/transform-name-policy.d.ts.map +1 -0
- package/dist/src/components/transforms/transform-name-policy.js +111 -0
- package/dist/src/components/transforms/transform-name-policy.js.map +1 -0
- package/dist/src/components/utils/unpack-model-property.d.ts +8 -0
- package/dist/src/components/utils/unpack-model-property.d.ts.map +1 -0
- package/dist/src/components/utils/unpack-model-property.js +33 -0
- package/dist/src/components/utils/unpack-model-property.js.map +1 -0
- package/dist/src/components/utils/url-template.d.ts +7 -0
- package/dist/src/components/utils/url-template.d.ts.map +1 -0
- package/dist/src/components/utils/url-template.js +23 -0
- package/dist/src/components/utils/url-template.js.map +1 -0
- package/dist/src/context/encoding/encoding-context.d.ts +6 -0
- package/dist/src/context/encoding/encoding-context.d.ts.map +1 -0
- package/dist/src/context/encoding/encoding-context.js +20 -0
- package/dist/src/context/encoding/encoding-context.js.map +1 -0
- package/dist/src/context/encoding/types.d.ts +6 -0
- package/dist/src/context/encoding/types.d.ts.map +1 -0
- package/dist/src/context/encoding/types.js +1 -0
- package/dist/src/context/encoding/types.js.map +1 -0
- package/dist/src/emitter.d.ts +8 -0
- package/dist/src/emitter.d.ts.map +1 -0
- package/dist/src/emitter.js +68 -0
- package/dist/src/emitter.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +206 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +107 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +8 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/utils/client-discovery.d.ts +7 -0
- package/dist/src/utils/client-discovery.d.ts.map +1 -0
- package/dist/src/utils/client-discovery.js +26 -0
- package/dist/src/utils/client-discovery.js.map +1 -0
- package/dist/src/utils/multipart.d.ts +3 -0
- package/dist/src/utils/multipart.d.ts.map +1 -0
- package/dist/src/utils/multipart.js +26 -0
- package/dist/src/utils/multipart.js.map +1 -0
- package/dist/src/utils/operations.d.ts +3 -0
- package/dist/src/utils/operations.d.ts.map +1 -0
- package/dist/src/utils/operations.js +11 -0
- package/dist/src/utils/operations.js.map +1 -0
- package/dist/src/utils/parameters.d.ts +14 -0
- package/dist/src/utils/parameters.d.ts.map +1 -0
- package/dist/src/utils/parameters.js +98 -0
- package/dist/src/utils/parameters.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/eng/scripts/calculate-coverage.js +36 -0
- package/eng/scripts/emit-e2e.js +329 -0
- package/eng/scripts/run-e2e-tests.js +162 -0
- package/eng/scripts/tspconfig.yaml +6 -0
- package/eng/scripts/upload-spector-results.js +120 -0
- package/package.json +83 -0
- package/src/components/client-context/client-context-declaration.tsx +19 -0
- package/src/components/client-context/client-context-factory.tsx +142 -0
- package/src/components/client-context/client-context-options.tsx +28 -0
- package/src/components/client-context/client-context.tsx +21 -0
- package/src/components/client-context/parametrized-endpoint.tsx +39 -0
- package/src/components/client-directory.tsx +40 -0
- package/src/components/client-operation.tsx +52 -0
- package/src/components/client.tsx +137 -0
- package/src/components/encoding-provider.tsx +19 -0
- package/src/components/external-packages/ts-http-runtime.ts +22 -0
- package/src/components/external-packages/uri-template.ts +11 -0
- package/src/components/http-request-options.tsx +69 -0
- package/src/components/http-request-parameters-expression.tsx +69 -0
- package/src/components/http-request.tsx +58 -0
- package/src/components/http-response.tsx +68 -0
- package/src/components/models.tsx +29 -0
- package/src/components/operation-options.tsx +26 -0
- package/src/components/operation-parameters.tsx +43 -0
- package/src/components/output.tsx +26 -0
- package/src/components/serializers.tsx +47 -0
- package/src/components/static-helpers/bytes-encoding.tsx +41 -0
- package/src/components/static-helpers/interfaces.tsx +26 -0
- package/src/components/static-helpers/multipart-helpers.tsx +59 -0
- package/src/components/static-helpers/rest-error.tsx +61 -0
- package/src/components/testing/client-options.tsx +32 -0
- package/src/components/transforms/content-type-encoding-provider.tsx +28 -0
- package/src/components/transforms/data-transform.tsx +39 -0
- package/src/components/transforms/json/json-array-transform.tsx +83 -0
- package/src/components/transforms/json/json-model-additional-properties-transform.tsx +47 -0
- package/src/components/transforms/json/json-model-base-transform.tsx +19 -0
- package/src/components/transforms/json/json-model-property-transform.tsx +41 -0
- package/src/components/transforms/json/json-model-transform.tsx +87 -0
- package/src/components/transforms/json/json-record-transform.tsx +84 -0
- package/src/components/transforms/json/json-transform-discriminator.tsx +114 -0
- package/src/components/transforms/json/json-transform.tsx +113 -0
- package/src/components/transforms/json/union-transform.tsx +73 -0
- package/src/components/transforms/json/utils/transport-namer.ts +12 -0
- package/src/components/transforms/multipart/array-part-transform.tsx +40 -0
- package/src/components/transforms/multipart/file-part-transform.tsx +44 -0
- package/src/components/transforms/multipart/multipart-transform.tsx +32 -0
- package/src/components/transforms/multipart/part-transform.tsx +22 -0
- package/src/components/transforms/multipart/simple-part-transform.tsx +49 -0
- package/src/components/transforms/operation-transform-declaration.tsx +64 -0
- package/src/components/transforms/operation-transform-expression.tsx +54 -0
- package/src/components/transforms/scalar-transform.tsx +289 -0
- package/src/components/transforms/transform-name-policy.ts +133 -0
- package/src/components/utils/unpack-model-property.ts +31 -0
- package/src/components/utils/url-template.tsx +21 -0
- package/src/context/encoding/encoding-context.tsx +26 -0
- package/src/context/encoding/types.ts +6 -0
- package/src/emitter.tsx +53 -0
- package/src/index.ts +5 -0
- package/src/lib.ts +108 -0
- package/src/testing/index.ts +8 -0
- package/src/utils/client-discovery.ts +28 -0
- package/src/utils/multipart.ts +28 -0
- package/src/utils/operations.ts +14 -0
- package/src/utils/parameters.tsx +129 -0
- package/test/e2e/assets/image.jpg +0 -0
- package/test/e2e/assets/image.png +0 -0
- package/test/e2e/http/authentication/api-key/main.test.ts +38 -0
- package/test/e2e/http/authentication/oauth2/main.test.ts +41 -0
- package/test/e2e/http/authentication/union/main.test.ts +29 -0
- package/test/e2e/http/encode/bytes/main.test.ts +191 -0
- package/test/e2e/http/encode/datetime/main.test.ts +176 -0
- package/test/e2e/http/encode/duration/main.test.ts +126 -0
- package/test/e2e/http/encode/numeric/main.test.ts +26 -0
- package/test/e2e/http/parameters/basic/main.test.ts +35 -0
- package/test/e2e/http/parameters/body-optionality/main.test.ts +43 -0
- package/test/e2e/http/parameters/collection-format/main.test.ts +45 -0
- package/test/e2e/http/parameters/spread/main.test.ts +56 -0
- package/test/e2e/http/payload/content-negotiation/main.test.ts +40 -0
- package/test/e2e/http/payload/json-merge-patch/main.test.ts +122 -0
- package/test/e2e/http/payload/media-type/main.test.ts +28 -0
- package/test/e2e/http/payload/multipart/main.test.ts +164 -0
- package/test/e2e/http/payload/pageable/main.test.ts +24 -0
- package/test/e2e/http/payload/xml/main.test.ts +287 -0
- package/test/e2e/http/routes/main.test.ts +284 -0
- package/test/e2e/http/serialization/encoded-name/json/main.test.ts +20 -0
- package/test/e2e/http/server/endpoint/not-defined/main.test.ts +11 -0
- package/test/e2e/http/server/path/multiple/main.test.ts +22 -0
- package/test/e2e/http/server/path/single/main.test.ts +11 -0
- package/test/e2e/http/server/versions/not-versioned/main.test.ts +22 -0
- package/test/e2e/http/server/versions/versioned/main.test.ts +28 -0
- package/test/e2e/http/special-headers/conditional-request/main.test.ts +35 -0
- package/test/e2e/http/special-headers/repeatability/main.test.ts +18 -0
- package/test/e2e/http/special-words/main.test.ts +434 -0
- package/test/e2e/http/type/array/array.test.ts +256 -0
- package/test/e2e/http/type/dictionary/main.test.ts +229 -0
- package/test/e2e/http/type/enum/extensible/main.test.ts +34 -0
- package/test/e2e/http/type/enum/fixed/main.test.ts +29 -0
- package/test/e2e/http/type/model/empty/main.test.ts +21 -0
- package/test/e2e/http/type/model/inheritance/enum-discriminator/main.test.ts +51 -0
- package/test/e2e/http/type/model/inheritance/nested-discriminator/main.test.ts +168 -0
- package/test/e2e/http/type/model/inheritance/not-discriminated/main.test.ts +42 -0
- package/test/e2e/http/type/model/inheritance/recursive/main.test.ts +46 -0
- package/test/e2e/http/type/model/inheritance/single-discriminator/main.test.ts +101 -0
- package/test/e2e/http/type/model/visibility/main.test.ts +64 -0
- package/test/e2e/http/type/property/additional-properties/main.test.ts +185 -0
- package/test/e2e/http/type/property/additional-properties/spreads.test.ts +470 -0
- package/test/e2e/http/type/property/nullable/main.test.ts +275 -0
- package/test/e2e/http/type/property/optionality/main.test.ts +256 -0
- package/test/e2e/http/type/property/value-types/main.test.ts +193 -0
- package/test/e2e/http/type/scalar/main.test.ts +133 -0
- package/test/e2e/http/type/scalar/scalar.test.ts +95 -0
- package/test/e2e/http/type/union/main.test.ts +207 -0
- package/test/e2e/http/versioning/added/main.test.ts +61 -0
- package/test/e2e/http/versioning/madeOptional/main.test.ts +34 -0
- package/test/e2e/http/versioning/removed/main.test.ts +75 -0
- package/test/e2e/http/versioning/renamedFrom/main.test.ts +52 -0
- package/test/e2e/http/versioning/returnTypeChangedFrom/main.test.ts +22 -0
- package/test/e2e/http/versioning/typeChangedFrom/main.test.ts +31 -0
- package/test/scenarios/additional-properties/extends.md +71 -0
- package/test/scenarios/additional-properties/is.md +46 -0
- package/test/scenarios/additional-properties/spread.md +72 -0
- package/test/scenarios/auth/basic_auth.md +67 -0
- package/test/scenarios/auth/bearer.md +67 -0
- package/test/scenarios/auth/client_parameters.md +68 -0
- package/test/scenarios/auth/client_structure.md +38 -0
- package/test/scenarios/auth/key_credential.md +67 -0
- package/test/scenarios/auth/sub_client_override.md +114 -0
- package/test/scenarios/client/client_context.md +36 -0
- package/test/scenarios/client/dotted_namespace.md +30 -0
- package/test/scenarios/client/global_namespace.md +74 -0
- package/test/scenarios/client/multiple_top_level_clients.md +74 -0
- package/test/scenarios/client/nested_client.md +106 -0
- package/test/scenarios/client/wrapping_namespace.md +43 -0
- package/test/scenarios/encoding/bytes_body.md +48 -0
- package/test/scenarios/encoding/bytes_json_property.md +60 -0
- package/test/scenarios/encoding/bytes_nullable.md +153 -0
- package/test/scenarios/encoding/header_bytes.md +142 -0
- package/test/scenarios/encoding/header_date.md +236 -0
- package/test/scenarios/encoding/model_with_bytes_property.md +50 -0
- package/test/scenarios/encoding/query_bytes.md +46 -0
- package/test/scenarios/encoding/query_date.md +236 -0
- package/test/scenarios/http-operations/basic-request.md +162 -0
- package/test/scenarios/http-operations/basic-response.md +246 -0
- package/test/scenarios/http-operations/basic.md +134 -0
- package/test/scenarios/http-operations/constant-header.md +37 -0
- package/test/scenarios/http-operations/create-operation.md +62 -0
- package/test/scenarios/http-operations/on_response.md +56 -0
- package/test/scenarios/http-operations/optional-request-body.md +55 -0
- package/test/scenarios/http-operations/path-parameter-in-model.md +59 -0
- package/test/scenarios/http-operations/path-parameter.md +54 -0
- package/test/scenarios/http-operations/scalar-payload.md +63 -0
- package/test/scenarios/http-operations/with-parameters.md +85 -0
- package/test/scenarios/models/array-properties.md +47 -0
- package/test/scenarios/models/basic.md +118 -0
- package/test/scenarios/models/dictionary-properties.md +44 -0
- package/test/scenarios/models/inheritance_2_discriminators.md +370 -0
- package/test/scenarios/models/inheritance_discriminator.md +92 -0
- package/test/scenarios/models/inline-models.md +29 -0
- package/test/scenarios/models/model_additional_properties.md +79 -0
- package/test/scenarios/models/model_extends.md +101 -0
- package/test/scenarios/models/model_spread.md +65 -0
- package/test/scenarios/models/nested_property.md +45 -0
- package/test/scenarios/models/property_references_property.md +156 -0
- package/test/scenarios/multipart/anonymous_part.md +57 -0
- package/test/scenarios/multipart/file.md +166 -0
- package/test/scenarios/multipart/file_content_type.md +67 -0
- package/test/scenarios/multipart/simple_part.md +69 -0
- package/test/scenarios/operation-parameters/body_root_anonymous.md +92 -0
- package/test/scenarios/operation-parameters/constant_as_optional.md +59 -0
- package/test/scenarios/operation-parameters/default_value_as_optional.md +59 -0
- package/test/scenarios/operation-parameters/no_content_type.md +67 -0
- package/test/scenarios/operation-parameters/no_parameters.md +55 -0
- package/test/scenarios/operation-parameters/only_optional.md +67 -0
- package/test/scenarios/operation-parameters/only_required.md +63 -0
- package/test/scenarios/operation-parameters/reserved_names.md +65 -0
- package/test/scenarios/operation-parameters/spread_body.md +75 -0
- package/test/scenarios/operation-parameters/spread_with_nested.md +87 -0
- package/test/scenarios/operation-parameters/union_body.md +92 -0
- package/test/scenarios/operation-parameters/with_body_property.md +72 -0
- package/test/scenarios/operation-parameters/with_body_root.md +74 -0
- package/test/scenarios/serializers/arrays.md +199 -0
- package/test/scenarios/serializers/basic_model.md +115 -0
- package/test/scenarios/serializers/basic_model_wire_name.md +50 -0
- package/test/scenarios/serializers/discriminated_union.md +86 -0
- package/test/scenarios/serializers/discriminated_union_spread.md +119 -0
- package/test/scenarios/serializers/model_date_time.md +65 -0
- package/test/scenarios/serializers/multipart.md +66 -0
- package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +164 -0
- package/test/scenarios/serializers/record.md +101 -0
- package/test/scenarios/serializers/scalars.md +33 -0
- package/test/scenarios/serializers/spread.md +75 -0
- package/test/scenarios/serializers/string_union.md +61 -0
- package/test/scenarios/server/default_url.md +45 -0
- package/test/scenarios/server/multiple-parameters.md +57 -0
- package/test/scenarios/server/no-server.md +37 -0
- package/test/scenarios/server/parametrized-endpoint.md +53 -0
- package/test/scenarios.test.ts +18 -0
- package/test/test-host.ts +76 -0
- package/tsconfig.json +16 -0
- package/tsconfig.test.json +7 -0
- package/vitest.config.js +23 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Children, code, refkey, Refkey } from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { Reference } from "@alloy-js/typescript";
|
|
4
|
+
import { ClientOperation } from "@typespec/http-client";
|
|
5
|
+
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
6
|
+
import { uriTemplateLib } from "./external-packages/uri-template.js";
|
|
7
|
+
import { HttpRequestOptions } from "./http-request-options.js";
|
|
8
|
+
import { HttpRequestParametersExpression } from "./http-request-parameters-expression.js";
|
|
9
|
+
import { getOperationOptionsParameterRefkey } from "./operation-parameters.jsx";
|
|
10
|
+
|
|
11
|
+
export interface HttpRequestProps {
|
|
12
|
+
operation: ClientOperation;
|
|
13
|
+
responseRefkey?: Refkey;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function HttpRequest(props: HttpRequestProps) {
|
|
17
|
+
const operationUrlRefkey = refkey();
|
|
18
|
+
const requestOptionsRefkey = refkey();
|
|
19
|
+
const httpResponseRefkey = props.responseRefkey ?? refkey();
|
|
20
|
+
const verb = props.operation.httpOperation.verb;
|
|
21
|
+
return <>
|
|
22
|
+
<HttpRequest.Url operation={props.operation} refkey={operationUrlRefkey}/>
|
|
23
|
+
|
|
24
|
+
<HttpRequestOptions operation={props.operation} refkey={requestOptionsRefkey} />
|
|
25
|
+
|
|
26
|
+
<ts.VarDeclaration name="response" refkey={httpResponseRefkey}>
|
|
27
|
+
{code`
|
|
28
|
+
await client.pathUnchecked(${<Reference refkey={operationUrlRefkey}/>}).${verb}(${<Reference refkey={requestOptionsRefkey}/>})
|
|
29
|
+
|
|
30
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
31
|
+
options?.operationOptions?.onResponse(response);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
`}
|
|
35
|
+
|
|
36
|
+
</ts.VarDeclaration>
|
|
37
|
+
</>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface HttpUrlProps {
|
|
41
|
+
operation: ClientOperation;
|
|
42
|
+
refkey?: Refkey;
|
|
43
|
+
children?: Children;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
HttpRequest.Url = function HttpUrlDeclaration(props: HttpUrlProps) {
|
|
47
|
+
const httpOperation = props.operation.httpOperation;
|
|
48
|
+
const urlTemplate = httpOperation.uriTemplate;
|
|
49
|
+
const urlParameters = httpOperation.parameters.properties.filter(
|
|
50
|
+
(p) => p.kind === "path" || p.kind === "query",
|
|
51
|
+
);
|
|
52
|
+
const optionsParameter = getOperationOptionsParameterRefkey(props.operation.httpOperation);
|
|
53
|
+
return <EncodingProvider defaults={{bytes: "base64url"}}>
|
|
54
|
+
<ts.VarDeclaration name="path" refkey={props.refkey}>
|
|
55
|
+
{uriTemplateLib.parse}({JSON.stringify(urlTemplate)}).expand({<HttpRequestParametersExpression optionsParameter={optionsParameter!} parameters={urlParameters} />})
|
|
56
|
+
</ts.VarDeclaration>
|
|
57
|
+
</EncodingProvider>;
|
|
58
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Children, code, mapJoin, Refkey } from "@alloy-js/core";
|
|
2
|
+
import { isVoidType } from "@typespec/compiler";
|
|
3
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
|
+
import { ClientOperation } from "@typespec/http-client";
|
|
5
|
+
import { getCreateRestErrorRefkey } from "./static-helpers/rest-error.jsx";
|
|
6
|
+
import { ContentTypeEncodingProvider } from "./transforms/content-type-encoding-provider.jsx";
|
|
7
|
+
import { JsonTransform } from "./transforms/json/json-transform.jsx";
|
|
8
|
+
export interface HttpResponseProps {
|
|
9
|
+
operation: ClientOperation;
|
|
10
|
+
responseRefkey: Refkey;
|
|
11
|
+
children?: Children;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function HttpResponse(props: HttpResponseProps) {
|
|
15
|
+
return <>
|
|
16
|
+
<HttpResponses operation={props.operation} />
|
|
17
|
+
|
|
18
|
+
{code`throw ${getCreateRestErrorRefkey()}(response);`}
|
|
19
|
+
</>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface HttpResponsesProps {
|
|
23
|
+
operation: ClientOperation;
|
|
24
|
+
children?: Children;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function HttpResponses(props: HttpResponsesProps) {
|
|
28
|
+
// Handle response by status code and content type
|
|
29
|
+
const responses = $.httpOperation.flattenResponses(props.operation.httpOperation);
|
|
30
|
+
return mapJoin(
|
|
31
|
+
responses.filter((r) => !$.httpResponse.isErrorResponse(r)),
|
|
32
|
+
({ statusCode, contentType, responseContent, type }) => {
|
|
33
|
+
const body = responseContent.body;
|
|
34
|
+
|
|
35
|
+
let expression: Children = code`return;`;
|
|
36
|
+
|
|
37
|
+
const contentTypeCheck = body
|
|
38
|
+
? ` && response.headers["content-type"]?.includes("${contentType}")`
|
|
39
|
+
: " && !response.body";
|
|
40
|
+
|
|
41
|
+
if (body && (body.bodyKind === "single" || (type && !isVoidType(type)))) {
|
|
42
|
+
expression =
|
|
43
|
+
<ContentTypeEncodingProvider contentType={contentType}>
|
|
44
|
+
return <JsonTransform itemRef={"response.body"} target="application" type={body.type} />!;
|
|
45
|
+
</ContentTypeEncodingProvider>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if ($.httpResponse.statusCode.isSingle(statusCode)) {
|
|
49
|
+
return code`
|
|
50
|
+
if (+response.status === ${statusCode}${contentTypeCheck}) {
|
|
51
|
+
${expression}
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if ($.httpResponse.statusCode.isRange(statusCode)) {
|
|
57
|
+
return code`
|
|
58
|
+
if (+response.status >= ${statusCode.start} && +response.status <= ${statusCode.end} ${contentTypeCheck}) {
|
|
59
|
+
${expression}
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return null;
|
|
65
|
+
},
|
|
66
|
+
{ joiner: "\n\n" },
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { mapJoin, refkey } from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
|
+
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
|
+
import { useClientLibrary } from "@typespec/http-client";
|
|
6
|
+
import { getFileTypeReference } from "./static-helpers/multipart-helpers.jsx";
|
|
7
|
+
|
|
8
|
+
export interface ModelsProps {
|
|
9
|
+
path?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Models(props: ModelsProps) {
|
|
13
|
+
const clientLibrary = useClientLibrary();
|
|
14
|
+
const dataTypes = clientLibrary.dataTypes;
|
|
15
|
+
return <ts.SourceFile path={props.path ?? "models.ts"}>
|
|
16
|
+
{mapJoin(
|
|
17
|
+
dataTypes,
|
|
18
|
+
(type) => {
|
|
19
|
+
if($.model.is(type) && $.model.isHttpFile(type)) {
|
|
20
|
+
return <ts.TypeDeclaration name="File" export kind="type" refkey={refkey(type)}>
|
|
21
|
+
{getFileTypeReference()}
|
|
22
|
+
</ts.TypeDeclaration>
|
|
23
|
+
}
|
|
24
|
+
return $.array.is(type) || $.record.is(type) ? null : <ef.TypeDeclaration export type={type} />
|
|
25
|
+
},
|
|
26
|
+
{ joiner: "\n\n" }
|
|
27
|
+
)}
|
|
28
|
+
</ts.SourceFile>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import * as ef from "@typespec/emitter-framework/typescript";
|
|
4
|
+
import { HttpOperation } from "@typespec/http";
|
|
5
|
+
import { hasDefaultValue } from "../utils/parameters.jsx";
|
|
6
|
+
import { getOperationOptionsInterfaceRefkey } from "./static-helpers/interfaces.jsx";
|
|
7
|
+
export interface OperationOptionsProps {
|
|
8
|
+
operation: HttpOperation;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getOperationOptionsTypeRefkey(operation: HttpOperation) {
|
|
12
|
+
return ay.refkey(operation, "operation-options");
|
|
13
|
+
}
|
|
14
|
+
export function OperationOptionsDeclaration(props: OperationOptionsProps) {
|
|
15
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
16
|
+
const interfaceName = namePolicy.getName(props.operation.operation.name + "Options", "interface");
|
|
17
|
+
const optionalParameters = props.operation.parameters.properties.filter(
|
|
18
|
+
(p) => p.property.optional || hasDefaultValue(p),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return <ts.InterfaceDeclaration export name={interfaceName} extends={getOperationOptionsInterfaceRefkey()} refkey={getOperationOptionsTypeRefkey(props.operation)}>
|
|
22
|
+
{ay.mapJoin(optionalParameters, (parameter) => (
|
|
23
|
+
<ts.InterfaceMember name={parameter.property.name} optional type={<ef.TypeExpression type={parameter.property.type} />} />
|
|
24
|
+
))}
|
|
25
|
+
</ts.InterfaceDeclaration>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { useTransformNamePolicy } from "@typespec/emitter-framework";
|
|
4
|
+
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
|
+
import { HttpOperation } from "@typespec/http";
|
|
6
|
+
import { hasDefaultValue } from "../utils/parameters.jsx";
|
|
7
|
+
import { getOperationOptionsTypeRefkey } from "./operation-options.jsx";
|
|
8
|
+
|
|
9
|
+
export interface OperationParametersProps {
|
|
10
|
+
operation: HttpOperation;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getOperationOptionsParameterRefkey(operation: HttpOperation) {
|
|
14
|
+
return ay.refkey(operation, "operation-options-parameter");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getOperationParameters(
|
|
18
|
+
operation: HttpOperation,
|
|
19
|
+
): Record<string, ts.ParameterDescriptor | ay.Children> {
|
|
20
|
+
const transformNamer = useTransformNamePolicy();
|
|
21
|
+
const requiredParameters = operation.parameters.properties
|
|
22
|
+
.filter((p) => !p.property.optional && !hasDefaultValue(p))
|
|
23
|
+
.filter((p) => p.path.length === 1);
|
|
24
|
+
|
|
25
|
+
const parameters: Record<string, ts.ParameterDescriptor | ay.Children> = {};
|
|
26
|
+
|
|
27
|
+
for (const parameter of requiredParameters) {
|
|
28
|
+
const parameterDescriptor: ts.ParameterDescriptor = {
|
|
29
|
+
refkey: ay.refkey(parameter.property, "operation-parameter"),
|
|
30
|
+
type: <ef.TypeExpression type={parameter.property.type} />,
|
|
31
|
+
};
|
|
32
|
+
const name = transformNamer.getApplicationName(parameter.property);
|
|
33
|
+
parameters[name] = parameterDescriptor;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
parameters["options"] = {
|
|
37
|
+
refkey: getOperationOptionsParameterRefkey(operation),
|
|
38
|
+
type: getOperationOptionsTypeRefkey(operation),
|
|
39
|
+
optional: true,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return parameters;
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { TransformNamePolicyContext } from "@typespec/emitter-framework";
|
|
4
|
+
import { ClientLibrary } from "@typespec/http-client/components";
|
|
5
|
+
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
6
|
+
import { httpRuntimeTemplateLib } from "./external-packages/ts-http-runtime.js";
|
|
7
|
+
import { uriTemplateLib } from "./external-packages/uri-template.js";
|
|
8
|
+
import { createTransformNamePolicy } from "./transforms/transform-name-policy.js";
|
|
9
|
+
|
|
10
|
+
export interface OutputProps {
|
|
11
|
+
children?: ay.Children;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function Output(props: OutputProps) {
|
|
15
|
+
const tsNamePolicy = ts.createTSNamePolicy();
|
|
16
|
+
const defaultTransformNamePolicy = createTransformNamePolicy();
|
|
17
|
+
return <ay.Output namePolicy={tsNamePolicy} externals={[uriTemplateLib, httpRuntimeTemplateLib]}>
|
|
18
|
+
<ClientLibrary>
|
|
19
|
+
<TransformNamePolicyContext.Provider value={defaultTransformNamePolicy}>
|
|
20
|
+
<EncodingProvider>
|
|
21
|
+
{props.children}
|
|
22
|
+
</EncodingProvider>
|
|
23
|
+
</TransformNamePolicyContext.Provider>
|
|
24
|
+
</ClientLibrary>
|
|
25
|
+
</ay.Output>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as ts from "@alloy-js/typescript";
|
|
2
|
+
import {
|
|
3
|
+
DateDeserializer,
|
|
4
|
+
DateRfc3339Serializer,
|
|
5
|
+
DateRfc7231Deserializer,
|
|
6
|
+
DateRfc7231Serializer,
|
|
7
|
+
DateUnixTimestampDeserializer,
|
|
8
|
+
DateUnixTimestampSerializer,
|
|
9
|
+
} from "@typespec/emitter-framework/typescript";
|
|
10
|
+
import { useClientLibrary } from "@typespec/http-client";
|
|
11
|
+
import { flattenClients } from "../utils/client-discovery.js";
|
|
12
|
+
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
13
|
+
import { DecodeBase64, EncodeUint8Array } from "./static-helpers/bytes-encoding.jsx";
|
|
14
|
+
import { JsonTransformDeclaration } from "./transforms/json/json-transform.jsx";
|
|
15
|
+
import { TransformDeclaration } from "./transforms/operation-transform-declaration.jsx";
|
|
16
|
+
export interface ModelSerializersProps {
|
|
17
|
+
path?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function ModelSerializers(props: ModelSerializersProps) {
|
|
21
|
+
const clientLibrary = useClientLibrary();
|
|
22
|
+
const dataTypes = clientLibrary.dataTypes;
|
|
23
|
+
const flatClients = clientLibrary.topLevel.flatMap((c) => flattenClients(c));
|
|
24
|
+
const operations = flatClients.flatMap((c) => c.operations);
|
|
25
|
+
// Todo: Handle other kinds of serialization, for example XML. Might need to
|
|
26
|
+
// revisit the way we process these and might need to track the relationship
|
|
27
|
+
// between the data type and the operations that consume them.
|
|
28
|
+
return <ts.SourceFile path={props.path ?? "serializers.ts"}>
|
|
29
|
+
<DecodeBase64 />
|
|
30
|
+
<EncodeUint8Array />
|
|
31
|
+
<DateDeserializer />
|
|
32
|
+
<DateRfc7231Deserializer />
|
|
33
|
+
<DateRfc3339Serializer />
|
|
34
|
+
<DateRfc7231Serializer />
|
|
35
|
+
<DateUnixTimestampSerializer />
|
|
36
|
+
<DateUnixTimestampDeserializer />
|
|
37
|
+
{operations.map(o => <TransformDeclaration operation={o} />)}
|
|
38
|
+
{dataTypes
|
|
39
|
+
.filter((m) => m.kind === "Model" || m.kind === "Union")
|
|
40
|
+
.map((type) => (
|
|
41
|
+
<EncodingProvider defaults={{bytes: "base64"}}>
|
|
42
|
+
<JsonTransformDeclaration type={type} target="transport" />
|
|
43
|
+
<JsonTransformDeclaration type={type} target="application" />
|
|
44
|
+
</EncodingProvider>
|
|
45
|
+
))}
|
|
46
|
+
</ts.SourceFile>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
|
|
4
|
+
export function getEncodeUint8ArrayRef(): ay.Refkey {
|
|
5
|
+
return ay.refkey("encodeUint8Array");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function EncodeUint8Array(): ay.Children {
|
|
9
|
+
const valueRef = ay.refkey();
|
|
10
|
+
const encodingRef = ay.refkey();
|
|
11
|
+
const refkey = getEncodeUint8ArrayRef();
|
|
12
|
+
return <ts.FunctionDeclaration export refkey={refkey} name="encodeUint8Array" parameters={{value: {type: "Uint8Array | undefined | null", refkey: valueRef,}, encoding: {type: "BufferEncoding", refkey: encodingRef}}} returnType="string | undefined">
|
|
13
|
+
{ay.code`
|
|
14
|
+
if (!${valueRef}) {
|
|
15
|
+
return ${valueRef} as any;
|
|
16
|
+
}
|
|
17
|
+
return Buffer.from(${valueRef}).toString(${encodingRef});
|
|
18
|
+
`}
|
|
19
|
+
</ts.FunctionDeclaration>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getDecodeUint8ArrayRef(): ay.Refkey {
|
|
23
|
+
return ay.refkey("decodeUint8Array");
|
|
24
|
+
}
|
|
25
|
+
export function DecodeBase64(): ay.Children {
|
|
26
|
+
const refkey = getDecodeUint8ArrayRef();
|
|
27
|
+
const valueRef = ay.refkey();
|
|
28
|
+
return <ts.FunctionDeclaration export name="decodeBase64" parameters={{value: {type: "string", refkey: valueRef}}} returnType="Uint8Array | undefined" refkey={refkey}>
|
|
29
|
+
{ay.code`
|
|
30
|
+
if(!${valueRef}) {
|
|
31
|
+
return ${valueRef} as any;
|
|
32
|
+
}
|
|
33
|
+
// Normalize Base64URL to Base64
|
|
34
|
+
const base64 = ${valueRef}.replace(/-/g, '+').replace(/_/g, '/')
|
|
35
|
+
.padEnd(${valueRef}.length + (4 - (${valueRef}.length % 4)) % 4, '=');
|
|
36
|
+
|
|
37
|
+
return new Uint8Array(Buffer.from(base64, 'base64'));
|
|
38
|
+
`}
|
|
39
|
+
|
|
40
|
+
</ts.FunctionDeclaration>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { httpRuntimeTemplateLib } from "../external-packages/ts-http-runtime.js";
|
|
4
|
+
|
|
5
|
+
export function getOperationOptionsInterfaceRefkey() {
|
|
6
|
+
return ay.refkey("OperationOptions", "interface");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function OperationOptionsInterfaceDeclaration() {
|
|
10
|
+
const declarationRefkey = getOperationOptionsInterfaceRefkey();
|
|
11
|
+
const onResponseCallback = ay.code`(rawResponse: ${httpRuntimeTemplateLib.PathUncheckedResponse}) => void`;
|
|
12
|
+
|
|
13
|
+
const operationOptions =
|
|
14
|
+
<ts.InterfaceExpression>
|
|
15
|
+
<ts.InterfaceMember name="onResponse" optional type={onResponseCallback} />
|
|
16
|
+
</ts.InterfaceExpression>;
|
|
17
|
+
return <ts.InterfaceDeclaration export name="OperationOptions" refkey={declarationRefkey}>
|
|
18
|
+
<ts.InterfaceMember name="operationOptions" optional type={operationOptions}/>
|
|
19
|
+
</ts.InterfaceDeclaration>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Interfaces() {
|
|
23
|
+
return <ts.SourceFile path="interfaces.ts">
|
|
24
|
+
<OperationOptionsInterfaceDeclaration />
|
|
25
|
+
</ts.SourceFile>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
export interface MultipartHelpersProps {}
|
|
4
|
+
|
|
5
|
+
export function getFileContentsTypeReference() {
|
|
6
|
+
return ay.refkey("FileContents", "type", "static-helpers");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getCreateFilePartDescriptorReference() {
|
|
10
|
+
return ay.refkey("createFilePartDescriptor", "function", "static-helpers");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getFileTypeReference() {
|
|
14
|
+
return ay.refkey("File", "type", "static-helpers");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function MultipartHelpers(props: MultipartHelpersProps) {
|
|
18
|
+
return <ts.SourceFile path="multipart-helpers.ts">
|
|
19
|
+
<ts.InterfaceDeclaration name="File" export refkey={getFileTypeReference()}>
|
|
20
|
+
contents: {getFileContentsTypeReference()};
|
|
21
|
+
contentType?: string;
|
|
22
|
+
filename?: string;
|
|
23
|
+
</ts.InterfaceDeclaration>
|
|
24
|
+
<ts.TypeDeclaration name="FileContents" export kind="type" refkey={getFileContentsTypeReference()}>
|
|
25
|
+
{ay.mapJoin(["string", "NodeJS.ReadableStream", "ReadableStream<Uint8Array>", "Uint8Array", "Blob"], (t) => t, {joiner: " | "})}
|
|
26
|
+
</ts.TypeDeclaration>
|
|
27
|
+
<ts.FunctionDeclaration name="createFilePartDescriptor" parameters={getCreateFilePartParameters()} export returnType="any" refkey={getCreateFilePartDescriptorReference()}>
|
|
28
|
+
{ay.code`
|
|
29
|
+
if (fileInput.contents) {
|
|
30
|
+
return {
|
|
31
|
+
name: partName,
|
|
32
|
+
body: fileInput.contents,
|
|
33
|
+
contentType: fileInput.contentType ?? defaultContentType,
|
|
34
|
+
filename: fileInput.filename,
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
return {
|
|
38
|
+
name: partName,
|
|
39
|
+
body: fileInput,
|
|
40
|
+
contentType: defaultContentType,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
`}
|
|
44
|
+
</ts.FunctionDeclaration>
|
|
45
|
+
</ts.SourceFile>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getCreateFilePartParameters() {
|
|
49
|
+
return {
|
|
50
|
+
partName: "string",
|
|
51
|
+
fileInput: "any",
|
|
52
|
+
defaultContentType: {
|
|
53
|
+
optional: true,
|
|
54
|
+
key: "defaultContentType",
|
|
55
|
+
refkey: ay.refkey(),
|
|
56
|
+
type: "string",
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { httpRuntimeTemplateLib } from "../external-packages/ts-http-runtime.js";
|
|
4
|
+
|
|
5
|
+
export function getRestErrorRefkey() {
|
|
6
|
+
return ay.refkey("rest-error", "static-helpers", "class");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getCreateRestErrorRefkey() {
|
|
10
|
+
return ay.refkey("create-rest-error", "static-helpers", "function");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function RestError() {
|
|
14
|
+
const requestRefkey = ay.refkey("request", "rest-error-class-field");
|
|
15
|
+
const responseRefkey = ay.refkey("response", "rest-error-class-field");
|
|
16
|
+
const statusRefkey = ay.refkey("status", "rest-error-class-field");
|
|
17
|
+
const bodyRefkey = ay.refkey("body", "rest-error-class-field");
|
|
18
|
+
const headersRefkey = ay.refkey("headers", "rest-error-class-field");
|
|
19
|
+
const constructorRefkey = ay.refkey("constructor", "rest-error-class-method");
|
|
20
|
+
const fromHttpResponseRefkey = ay.refkey("from-http-response", "rest-error-class-method");
|
|
21
|
+
|
|
22
|
+
const restErrorClass =
|
|
23
|
+
<ts.ClassDeclaration export name="RestError" extends="Error" refkey={getRestErrorRefkey()}>
|
|
24
|
+
<ts.ClassField public name="request" type={httpRuntimeTemplateLib.PipelineRequest} refkey={requestRefkey} />
|
|
25
|
+
<ts.ClassField public name="response" type={httpRuntimeTemplateLib.HttpResponse} refkey={responseRefkey} />
|
|
26
|
+
<ts.ClassField public name="status" type="string" refkey={statusRefkey}/>
|
|
27
|
+
<ts.ClassField public name="body" type="any" refkey={bodyRefkey}/>
|
|
28
|
+
<ts.ClassField public name="headers" type={httpRuntimeTemplateLib.RawHttpHeaders} refkey={headersRefkey} />
|
|
29
|
+
|
|
30
|
+
<ts.ClassMethod name="constructor" parameters={{message: "string", response: httpRuntimeTemplateLib.HttpResponse}} returnType={null} refkey={constructorRefkey}>
|
|
31
|
+
{ay.code`
|
|
32
|
+
// Create an error message that includes relevant details.
|
|
33
|
+
super(\`$\{message\} - HTTP $\{response.status} received for $\{response.request.method} $\{response.request.url}\`);
|
|
34
|
+
this.name = 'RestError';
|
|
35
|
+
this.request = response.request;
|
|
36
|
+
this.response = response;
|
|
37
|
+
this.status = response.status;
|
|
38
|
+
this.headers = response.headers;
|
|
39
|
+
this.body = response.body;
|
|
40
|
+
|
|
41
|
+
// Set the prototype explicitly.
|
|
42
|
+
Object.setPrototypeOf(this, RestError.prototype);
|
|
43
|
+
`}
|
|
44
|
+
</ts.ClassMethod>
|
|
45
|
+
<ts.ClassMethod static name="fromHttpResponse" parameters={{response: httpRuntimeTemplateLib.HttpResponse}} returnType={getRestErrorRefkey()} refkey={fromHttpResponseRefkey}>
|
|
46
|
+
{ay.code`
|
|
47
|
+
const defaultMessage = \`Unexpected HTTP status code: $\{response.status}\`;
|
|
48
|
+
return new RestError(defaultMessage, response);
|
|
49
|
+
`}
|
|
50
|
+
</ts.ClassMethod>
|
|
51
|
+
</ts.ClassDeclaration>;
|
|
52
|
+
|
|
53
|
+
const createRestError =
|
|
54
|
+
<ts.FunctionDeclaration export name="createRestError" parameters={{response: httpRuntimeTemplateLib.HttpResponse}} returnType={getRestErrorRefkey()} refkey={getCreateRestErrorRefkey()}>
|
|
55
|
+
{ay.code`
|
|
56
|
+
return ${fromHttpResponseRefkey}(response);
|
|
57
|
+
`}
|
|
58
|
+
</ts.FunctionDeclaration>;
|
|
59
|
+
|
|
60
|
+
return [restErrorClass, "\n\n", createRestError];
|
|
61
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import { config } from "dotenv";
|
|
3
|
+
|
|
4
|
+
config();
|
|
5
|
+
|
|
6
|
+
export interface ClientTestOptions {}
|
|
7
|
+
|
|
8
|
+
export function ClientTestOptions(_props: ClientTestOptions) {
|
|
9
|
+
if (process.env.TYPESPEC_JS_EMITTER_TESTING !== "true") {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return ay.code`
|
|
14
|
+
allowInsecureConnection: true,
|
|
15
|
+
retryOptions: {
|
|
16
|
+
maxRetries: 1,
|
|
17
|
+
}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function addClientTestOptions(
|
|
21
|
+
options: ay.Children[],
|
|
22
|
+
settings: { location?: "front" | "back" } = { location: "front" },
|
|
23
|
+
) {
|
|
24
|
+
if (process.env.TYPESPEC_JS_EMITTER_TESTING === "true") {
|
|
25
|
+
const testOptions = <ClientTestOptions />;
|
|
26
|
+
if (settings.location === "front") {
|
|
27
|
+
options.unshift(testOptions);
|
|
28
|
+
} else {
|
|
29
|
+
options.push(testOptions);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
2
|
+
import { EncodingDefaults } from "../../context/encoding/types.js";
|
|
3
|
+
import { EncodingProvider } from "../encoding-provider.jsx";
|
|
4
|
+
|
|
5
|
+
export interface ContentTypeEncodingProviderProps {
|
|
6
|
+
contentType?: string;
|
|
7
|
+
children?: Children;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function ContentTypeEncodingProvider(props: ContentTypeEncodingProviderProps) {
|
|
11
|
+
const contentType = props.contentType ?? "application/json";
|
|
12
|
+
let defaults: EncodingDefaults = {
|
|
13
|
+
bytes: "none",
|
|
14
|
+
datetime: "rfc3339",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Follows the media type conventions from RFC 6838 section 4.2.8, which standardizes the +json suffix for JSON-structured syntaxes.
|
|
18
|
+
if (contentType?.includes("application/json") || contentType.trim()?.endsWith("+json")) {
|
|
19
|
+
defaults = {
|
|
20
|
+
bytes: "base64",
|
|
21
|
+
datetime: "rfc3339",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return <EncodingProvider defaults={defaults}>
|
|
26
|
+
{props.children}
|
|
27
|
+
</EncodingProvider>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
+
import { EncodeData, ModelProperty, Scalar } from "@typespec/compiler";
|
|
3
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
|
+
import { reportDiagnostic } from "../../lib.js";
|
|
5
|
+
import { unpackProperty } from "../utils/unpack-model-property.js";
|
|
6
|
+
import { getScalarTransformer } from "./scalar-transform.jsx";
|
|
7
|
+
|
|
8
|
+
export interface ScalarDataTransformProps {
|
|
9
|
+
itemRef: Refkey | Children;
|
|
10
|
+
type: Scalar | ModelProperty;
|
|
11
|
+
target: "transport" | "application";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function ScalarDataTransform(props: ScalarDataTransformProps) {
|
|
15
|
+
let scalar: Scalar;
|
|
16
|
+
let encoding: EncodeData | undefined;
|
|
17
|
+
if ($.modelProperty.is(props.type)) {
|
|
18
|
+
const valueType = unpackProperty(props.type);
|
|
19
|
+
if (!$.scalar.is(valueType)) {
|
|
20
|
+
reportDiagnostic($.program, {
|
|
21
|
+
code: "unexpected-non-scalar-type",
|
|
22
|
+
target: props.type,
|
|
23
|
+
});
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
scalar = valueType;
|
|
27
|
+
encoding = $.modelProperty.getEncoding(props.type);
|
|
28
|
+
} else {
|
|
29
|
+
scalar = props.type;
|
|
30
|
+
encoding = $.scalar.getEncoding(scalar);
|
|
31
|
+
}
|
|
32
|
+
// const encoding = $.scalar.getEncoding(scalar);
|
|
33
|
+
|
|
34
|
+
const { toApplication, toTransport } = getScalarTransformer(scalar);
|
|
35
|
+
|
|
36
|
+
return props.target === "transport"
|
|
37
|
+
? toTransport(props.itemRef, encoding)
|
|
38
|
+
: toApplication(props.itemRef, encoding);
|
|
39
|
+
}
|