@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,40 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { HttpOperationPart } from "@typespec/http";
|
|
4
|
+
import { HttpPartTransform } from "./part-transform.jsx";
|
|
5
|
+
|
|
6
|
+
export interface ArrayPartTransformProps {
|
|
7
|
+
part: HttpOperationPart;
|
|
8
|
+
itemRef: ay.Children;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function ArrayPartTransform(props: ArrayPartTransformProps) {
|
|
12
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
13
|
+
const applicationName = namePolicy.getName(props.part.name!, "variable");
|
|
14
|
+
const partElementName = applicationName;
|
|
15
|
+
const mapCallbackSignature = <>({partElementName}: any)</>;
|
|
16
|
+
const partItemRef = getPartRef(props.itemRef, applicationName);
|
|
17
|
+
const inputExpression = props.part.optional ? (
|
|
18
|
+
<>...({partItemRef} ?? [])</>
|
|
19
|
+
) : (
|
|
20
|
+
<>...{partItemRef}</>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const partElement: HttpOperationPart = {
|
|
24
|
+
...props.part,
|
|
25
|
+
multi: false,
|
|
26
|
+
name: partElementName,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return <>
|
|
30
|
+
{inputExpression}.map({mapCallbackSignature} {ay.code`=> (${<HttpPartTransform itemRef={null} part={partElement} />})`} )
|
|
31
|
+
</>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getPartRef(itemRef: ay.Children, partName: string) {
|
|
35
|
+
if (itemRef === null) {
|
|
36
|
+
return partName;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return ay.code`${itemRef}.${partName}`;
|
|
40
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { HttpOperationPart } from "@typespec/http";
|
|
4
|
+
import { getCreateFilePartDescriptorReference } from "../../static-helpers/multipart-helpers.jsx";
|
|
5
|
+
|
|
6
|
+
export interface FilePartTransformProps {
|
|
7
|
+
part: HttpOperationPart;
|
|
8
|
+
itemRef: ay.Children;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function FilePartTransform(props: FilePartTransformProps) {
|
|
12
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
13
|
+
const defaultContentType = getContentType(props.part);
|
|
14
|
+
const applicationName = namePolicy.getName(props.part.name!, "variable");
|
|
15
|
+
const itemRef = getPartRef(props.itemRef, applicationName);
|
|
16
|
+
const args: ay.Children = [JSON.stringify(props.part.name), itemRef];
|
|
17
|
+
if (defaultContentType) {
|
|
18
|
+
args.push(ts.ValueExpression({ jsValue: defaultContentType }));
|
|
19
|
+
}
|
|
20
|
+
return <ts.FunctionCallExpression refkey={getCreateFilePartDescriptorReference()} args={args} />;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getContentType(part: HttpOperationPart) {
|
|
24
|
+
const contentTypes = part.body.contentTypes;
|
|
25
|
+
if (contentTypes.length !== 1) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const contentType = contentTypes[0];
|
|
30
|
+
|
|
31
|
+
if (!contentType || contentType === "*/*") {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return contentType;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getPartRef(itemRef: ay.Children, partName: string) {
|
|
39
|
+
if (itemRef === null) {
|
|
40
|
+
return partName;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return ay.code`${itemRef}.${partName}`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
3
|
+
import { useTransformNamePolicy } from "@typespec/emitter-framework";
|
|
4
|
+
import { HttpOperationMultipartBody } from "@typespec/http";
|
|
5
|
+
import { reportDiagnostic } from "../../../lib.js";
|
|
6
|
+
import { HttpPartTransform } from "./part-transform.jsx";
|
|
7
|
+
|
|
8
|
+
export interface MultipartTransformProps {
|
|
9
|
+
body: HttpOperationMultipartBody;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function MultipartTransform(props: MultipartTransformProps) {
|
|
13
|
+
const transportNamer = useTransformNamePolicy();
|
|
14
|
+
const httpParts = props.body.parts;
|
|
15
|
+
|
|
16
|
+
if (httpParts.length === 0) {
|
|
17
|
+
reportDiagnostic($.program, { code: "missing-http-parts", target: props.body.property });
|
|
18
|
+
return <>[]</>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const itemRef = transportNamer.getApplicationName(props.body.property);
|
|
22
|
+
|
|
23
|
+
const partTransform = ay.mapJoin(
|
|
24
|
+
httpParts,
|
|
25
|
+
(part) => <HttpPartTransform part={part} itemRef={itemRef}/>,
|
|
26
|
+
{
|
|
27
|
+
joiner: ",\n",
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return <>[{partTransform}]</>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import { HttpOperationPart } from "@typespec/http";
|
|
3
|
+
import { ArrayPartTransform } from "./array-part-transform.jsx";
|
|
4
|
+
import { FilePartTransform } from "./file-part-transform.jsx";
|
|
5
|
+
import { SimplePartTransform } from "./simple-part-transform.jsx";
|
|
6
|
+
|
|
7
|
+
export interface HttpPartTransformProps {
|
|
8
|
+
part: HttpOperationPart;
|
|
9
|
+
itemRef: ay.Children;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function HttpPartTransform(props: HttpPartTransformProps) {
|
|
13
|
+
if (props.part.multi) {
|
|
14
|
+
return <ArrayPartTransform part={props.part} itemRef={props.itemRef}/>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (props.part.filename) {
|
|
18
|
+
return <FilePartTransform part={props.part} itemRef={props.itemRef} />;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return <SimplePartTransform part={props.part} itemRef={props.itemRef} />;
|
|
22
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
|
+
import { HttpOperationPart } from "@typespec/http";
|
|
5
|
+
import { reportDiagnostic } from "../../../lib.js";
|
|
6
|
+
import { JsonTransform } from "../json/json-transform.jsx";
|
|
7
|
+
|
|
8
|
+
export interface SimplePartTransformProps {
|
|
9
|
+
part: HttpOperationPart;
|
|
10
|
+
itemRef: ay.Children;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function SimplePartTransform(props: SimplePartTransformProps) {
|
|
14
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
15
|
+
const applicationName = namePolicy.getName(props.part.name!, "variable");
|
|
16
|
+
const partName = ts.ValueExpression({ jsValue: props.part.name });
|
|
17
|
+
const partContentType = props.part.body.contentTypes[0] ?? "application/json";
|
|
18
|
+
const partRef = getPartRef(props.itemRef, applicationName);
|
|
19
|
+
|
|
20
|
+
if (!partContentType.startsWith("application/json")) {
|
|
21
|
+
reportDiagnostic($.program, {
|
|
22
|
+
code: "unsupported-content-type",
|
|
23
|
+
target: props.part.body.type,
|
|
24
|
+
message: `Unsupported content type: ${partContentType}`,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return <ts.ObjectExpression>
|
|
29
|
+
<ts.ObjectProperty name="name" jsValue={partName} />,
|
|
30
|
+
<ts.ObjectProperty
|
|
31
|
+
name="body"
|
|
32
|
+
value={
|
|
33
|
+
<JsonTransform
|
|
34
|
+
itemRef={partRef}
|
|
35
|
+
target="transport"
|
|
36
|
+
type={props.part.body.type}
|
|
37
|
+
/>
|
|
38
|
+
}
|
|
39
|
+
/>,
|
|
40
|
+
</ts.ObjectExpression>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getPartRef(itemRef: ay.Children, partName: string) {
|
|
44
|
+
if (itemRef === null) {
|
|
45
|
+
return partName;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return ay.code`${itemRef}.${partName}`;
|
|
49
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { HttpOperationBody } from "@typespec/http";
|
|
5
|
+
import { ClientOperation } from "@typespec/http-client";
|
|
6
|
+
import { JsonTransform } from "./json/json-transform.jsx";
|
|
7
|
+
export interface TransformDeclarationProps {
|
|
8
|
+
operation: ClientOperation;
|
|
9
|
+
refkey?: ay.Refkey;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getTransformDeclarationRef(operaion: ClientOperation) {
|
|
13
|
+
if (operaion.httpOperation.parameters.body?.bodyKind === "single") {
|
|
14
|
+
return ef.getTypeTransformerRefkey(operaion.httpOperation.parameters.body.type, "transport");
|
|
15
|
+
}
|
|
16
|
+
return ay.refkey(operaion, "transform");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function TransformDeclaration(props: TransformDeclarationProps) {
|
|
20
|
+
const refkey = props.refkey ?? getTransformDeclarationRef(props.operation);
|
|
21
|
+
return <>
|
|
22
|
+
<TransformToTransportDeclaration operation={props.operation} refkey={refkey} />
|
|
23
|
+
</>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SingleBodyTransformDeclarationProps {
|
|
27
|
+
name: string;
|
|
28
|
+
operation: ClientOperation;
|
|
29
|
+
payload: HttpOperationBody;
|
|
30
|
+
refkey: ay.Refkey;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function SingleBodyTransformDeclaration(props: SingleBodyTransformDeclarationProps) {
|
|
34
|
+
const inputRef = ay.refkey(props.payload, "property");
|
|
35
|
+
const payloadParameter: ts.ParameterDescriptor = {
|
|
36
|
+
type: <ef.TypeExpression type={props.payload.type} />,
|
|
37
|
+
refkey: inputRef,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return <ts.FunctionDeclaration export name={props.name} parameters={{payload: payloadParameter}} refkey={props.refkey}>
|
|
41
|
+
return <JsonTransform itemRef={inputRef} target="transport" type={props.payload.type} />!;
|
|
42
|
+
</ts.FunctionDeclaration>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface TransformToTransportDeclarationProps {
|
|
46
|
+
operation: ClientOperation;
|
|
47
|
+
refkey: ay.Refkey;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function TransformToTransportDeclaration(props: TransformToTransportDeclarationProps) {
|
|
51
|
+
const requestPayload = props.operation.httpOperation.parameters.body;
|
|
52
|
+
if (!requestPayload || !requestPayload.property) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
57
|
+
const name = namePolicy.getName(`${props.operation.name}_payload_to_transport`, "function");
|
|
58
|
+
|
|
59
|
+
if (requestPayload.bodyKind === "multipart") {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return <SingleBodyTransformDeclaration operation={props.operation} payload={requestPayload} refkey={props.refkey} name={name} />;
|
|
64
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as ts from "@alloy-js/typescript";
|
|
2
|
+
import { Type } from "@typespec/compiler";
|
|
3
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
|
+
import { HasName, TransformNamePolicyContext } from "@typespec/emitter-framework";
|
|
5
|
+
import { ClientOperation } from "@typespec/http-client";
|
|
6
|
+
import { reportDiagnostic } from "../../lib.js";
|
|
7
|
+
import { ContentTypeEncodingProvider } from "./content-type-encoding-provider.jsx";
|
|
8
|
+
import { JsonTransform } from "./json/json-transform.jsx";
|
|
9
|
+
import { MultipartTransform } from "./multipart/multipart-transform.jsx";
|
|
10
|
+
import { defaultTransportNameGetter } from "./transform-name-policy.js";
|
|
11
|
+
|
|
12
|
+
export interface OperationTransformToTransportExpression {
|
|
13
|
+
operation: ClientOperation;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function OperationTransformExpression(props: OperationTransformToTransportExpression) {
|
|
17
|
+
const body = props.operation.httpOperation.parameters.body;
|
|
18
|
+
|
|
19
|
+
if (!body) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const itemRef = body.property ? payloadApplicationNameGetter(body.property) : null;
|
|
24
|
+
|
|
25
|
+
if (body.bodyKind === "multipart") {
|
|
26
|
+
return <MultipartTransform body={body} />;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// TODO: Handle content types other than application/json and multipart
|
|
30
|
+
// And multiple content types
|
|
31
|
+
const contentType = body.contentTypes[0];
|
|
32
|
+
const payloadType = body.type;
|
|
33
|
+
return <ContentTypeEncodingProvider contentType={contentType}>
|
|
34
|
+
<TransformNamePolicyContext.Provider value={{ getTransportName: defaultTransportNameGetter, getApplicationName: payloadApplicationNameGetter }}>
|
|
35
|
+
<JsonTransform itemRef={itemRef} target="transport" type={payloadType} />
|
|
36
|
+
</TransformNamePolicyContext.Provider>
|
|
37
|
+
</ContentTypeEncodingProvider>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function payloadApplicationNameGetter(type: HasName<Type>) {
|
|
41
|
+
if (typeof type.name !== "string") {
|
|
42
|
+
reportDiagnostic($.program, { code: "symbol-name-not-supported", target: type });
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const namePolicy = ts.useTSNamePolicy();
|
|
47
|
+
let name = namePolicy.getName(type.name, "object-member-data");
|
|
48
|
+
|
|
49
|
+
if ($.modelProperty.is(type) && type.optional) {
|
|
50
|
+
name = `options?.${name}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return name;
|
|
54
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { Children, code, Refkey } from "@alloy-js/core";
|
|
2
|
+
import { BytesKnownEncoding, EncodeData, NoTarget, Scalar } from "@typespec/compiler";
|
|
3
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
|
+
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
|
+
import { useDefaultEncoding } from "../../context/encoding/encoding-context.jsx";
|
|
6
|
+
import { reportDiagnostic } from "../../lib.js";
|
|
7
|
+
import {
|
|
8
|
+
getDecodeUint8ArrayRef,
|
|
9
|
+
getEncodeUint8ArrayRef,
|
|
10
|
+
} from "../static-helpers/bytes-encoding.jsx";
|
|
11
|
+
|
|
12
|
+
// Define the transformer function type.
|
|
13
|
+
export type TransformerFn = (itemRef: Refkey | Children, encoding?: EncodeData) => Children;
|
|
14
|
+
|
|
15
|
+
// Define a pair that holds both directions.
|
|
16
|
+
export interface TransformerPair {
|
|
17
|
+
toTransport: TransformerFn;
|
|
18
|
+
toApplication: TransformerFn;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the transformer pair for the given scalar type.
|
|
23
|
+
*
|
|
24
|
+
* @param type - The scalar type to look up.
|
|
25
|
+
* @returns The transformer pair from scalarTransformerMap for the given type.
|
|
26
|
+
*/
|
|
27
|
+
export function getScalarTransformer(type: Scalar): TransformerPair {
|
|
28
|
+
return scalarTransformerMap[getScalarTransformKey(type)];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function defineScalarTransformerMap<T extends Record<string, TransformerPair>>(map: T): T {
|
|
32
|
+
return map;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A paired transformer map for scalar types.
|
|
37
|
+
*
|
|
38
|
+
* Each scalar type is associated with a pair of functions: one for transforming the value for transport
|
|
39
|
+
* (serialization) and one for transforming the value for application (deserialization).
|
|
40
|
+
*/
|
|
41
|
+
const scalarTransformerMap = defineScalarTransformerMap({
|
|
42
|
+
boolean: {
|
|
43
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
44
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
bytes: {
|
|
48
|
+
toTransport: (itemRef, encoding) => {
|
|
49
|
+
const bytesEncoding: BytesKnownEncoding | undefined =
|
|
50
|
+
(encoding?.encoding as BytesKnownEncoding) ??
|
|
51
|
+
(useDefaultEncoding("bytes") as BytesKnownEncoding);
|
|
52
|
+
switch (bytesEncoding) {
|
|
53
|
+
case "base64":
|
|
54
|
+
case "base64url":
|
|
55
|
+
const bytesEncodeRef = getEncodeUint8ArrayRef();
|
|
56
|
+
return code`${bytesEncodeRef}(${itemRef}, "${bytesEncoding}")!`;
|
|
57
|
+
default:
|
|
58
|
+
reportDiagnostic($.program, {
|
|
59
|
+
code: "unknown-encoding",
|
|
60
|
+
target: encoding?.type ?? NoTarget,
|
|
61
|
+
});
|
|
62
|
+
return passthroughTransformer(itemRef);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
toApplication: (itemRef, encoding) => {
|
|
66
|
+
const bytesEncoding: BytesKnownEncoding | undefined =
|
|
67
|
+
(encoding?.encoding as BytesKnownEncoding) ??
|
|
68
|
+
(useDefaultEncoding("bytes") as BytesKnownEncoding);
|
|
69
|
+
|
|
70
|
+
switch (bytesEncoding) {
|
|
71
|
+
case "base64":
|
|
72
|
+
case "base64url":
|
|
73
|
+
const bytesDecodeRef = getDecodeUint8ArrayRef();
|
|
74
|
+
return code`${bytesDecodeRef}(${itemRef})!`;
|
|
75
|
+
default:
|
|
76
|
+
reportDiagnostic($.program, {
|
|
77
|
+
code: "unknown-encoding",
|
|
78
|
+
target: encoding?.type ?? NoTarget,
|
|
79
|
+
});
|
|
80
|
+
return passthroughTransformer(itemRef);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
// For numerics that have no transformation, both directions simply passthrough.
|
|
86
|
+
decimal: {
|
|
87
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
88
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
89
|
+
},
|
|
90
|
+
decimal128: {
|
|
91
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
92
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
93
|
+
},
|
|
94
|
+
float: {
|
|
95
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
96
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
97
|
+
},
|
|
98
|
+
float32: {
|
|
99
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
100
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
101
|
+
},
|
|
102
|
+
float64: {
|
|
103
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
104
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
105
|
+
},
|
|
106
|
+
int16: {
|
|
107
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
108
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
109
|
+
},
|
|
110
|
+
int32: {
|
|
111
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
112
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
113
|
+
},
|
|
114
|
+
int64: {
|
|
115
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
116
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
117
|
+
},
|
|
118
|
+
int8: {
|
|
119
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
120
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
121
|
+
},
|
|
122
|
+
integer: {
|
|
123
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
124
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
125
|
+
},
|
|
126
|
+
numeric: {
|
|
127
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
128
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
129
|
+
},
|
|
130
|
+
safeint: {
|
|
131
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
132
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
133
|
+
},
|
|
134
|
+
uint16: {
|
|
135
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
136
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
137
|
+
},
|
|
138
|
+
uint32: {
|
|
139
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
140
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
141
|
+
},
|
|
142
|
+
uint64: {
|
|
143
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
144
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
145
|
+
},
|
|
146
|
+
uint8: {
|
|
147
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
148
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
// Duration: We don't apply any transformation so just passthrough.
|
|
152
|
+
duration: {
|
|
153
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
154
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
// Date/Time scalars: using a serializer on transport and a deserializer on application.
|
|
158
|
+
offsetDateTime: {
|
|
159
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
160
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
161
|
+
},
|
|
162
|
+
plainDate: {
|
|
163
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
164
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
165
|
+
},
|
|
166
|
+
plainTime: {
|
|
167
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
168
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
169
|
+
},
|
|
170
|
+
utcDateTime: {
|
|
171
|
+
toTransport: (itemRef, encoding) => {
|
|
172
|
+
const dateEncoding = encoding?.encoding ?? useDefaultEncoding("datetime");
|
|
173
|
+
let encodingFnRef: Refkey = ef.DateRfc3339SerializerRefkey;
|
|
174
|
+
switch (dateEncoding) {
|
|
175
|
+
case "unixTimestamp":
|
|
176
|
+
encodingFnRef = ef.DateUnixTimestampSerializerRefkey;
|
|
177
|
+
break;
|
|
178
|
+
case "rfc7231":
|
|
179
|
+
encodingFnRef = ef.DateRfc7231SerializerRefkey;
|
|
180
|
+
break;
|
|
181
|
+
case "rfc3339":
|
|
182
|
+
// already defaulted above.
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
reportDiagnostic($.program, {
|
|
186
|
+
code: "unknown-encoding",
|
|
187
|
+
target: encoding?.type ?? NoTarget,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return code`${encodingFnRef}(${itemRef})`;
|
|
191
|
+
},
|
|
192
|
+
toApplication: (itemRef, encoding) => {
|
|
193
|
+
const dateEncoding = encoding?.encoding ?? useDefaultEncoding("datetime");
|
|
194
|
+
let decodingFnRef: Refkey = ef.DateDeserializerRefkey;
|
|
195
|
+
switch (dateEncoding) {
|
|
196
|
+
case "unixTimestamp":
|
|
197
|
+
decodingFnRef = ef.DateUnixTimestampDeserializerRefkey;
|
|
198
|
+
break;
|
|
199
|
+
case "rfc7231":
|
|
200
|
+
decodingFnRef = ef.DateRfc7231DeserializerRefkey;
|
|
201
|
+
break;
|
|
202
|
+
case "rfc3339":
|
|
203
|
+
// default already
|
|
204
|
+
break;
|
|
205
|
+
default:
|
|
206
|
+
reportDiagnostic($.program, {
|
|
207
|
+
code: "unknown-encoding",
|
|
208
|
+
target: encoding?.type ?? NoTarget,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return code`${decodingFnRef}(${itemRef})!`;
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
unixTimestamp32: {
|
|
216
|
+
toTransport: (itemRef) => {
|
|
217
|
+
return code`${ef.DateUnixTimestampSerializerRefkey}(${itemRef})`;
|
|
218
|
+
},
|
|
219
|
+
toApplication: (itemRef) => {
|
|
220
|
+
return code`${ef.DateUnixTimestampDeserializerRefkey}(${itemRef})`;
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
// For URL and string, no transformation is needed.
|
|
225
|
+
url: {
|
|
226
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
227
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
228
|
+
},
|
|
229
|
+
string: {
|
|
230
|
+
toTransport: (itemRef) => passthroughTransformer(itemRef),
|
|
231
|
+
toApplication: (itemRef) => passthroughTransformer(itemRef),
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Tests for determining the scalar transformation key.
|
|
237
|
+
*/
|
|
238
|
+
type ScalarTest = (type: Scalar) => boolean;
|
|
239
|
+
|
|
240
|
+
const scalarTests: { key: keyof typeof scalarTransformerMap; test: ScalarTest }[] = [
|
|
241
|
+
{ key: "boolean", test: (t) => $.scalar.isBoolean(t) || $.scalar.extendsBoolean(t) },
|
|
242
|
+
{ key: "bytes", test: (t) => $.scalar.isBytes(t) || $.scalar.extendsBytes(t) },
|
|
243
|
+
{ key: "decimal", test: (t) => $.scalar.isDecimal(t) || $.scalar.extendsDecimal(t) },
|
|
244
|
+
{ key: "decimal128", test: (t) => $.scalar.isDecimal128(t) || $.scalar.extendsDecimal128(t) },
|
|
245
|
+
{ key: "duration", test: (t) => $.scalar.isDuration(t) || $.scalar.extendsDuration(t) },
|
|
246
|
+
{ key: "float", test: (t) => $.scalar.isFloat(t) || $.scalar.extendsFloat(t) },
|
|
247
|
+
{ key: "float32", test: (t) => $.scalar.isFloat32(t) || $.scalar.extendsFloat32(t) },
|
|
248
|
+
{ key: "float64", test: (t) => $.scalar.isFloat64(t) || $.scalar.extendsFloat64(t) },
|
|
249
|
+
{ key: "int16", test: (t) => $.scalar.isInt16(t) || $.scalar.extendsInt16(t) },
|
|
250
|
+
{ key: "int32", test: (t) => $.scalar.isInt32(t) || $.scalar.extendsInt32(t) },
|
|
251
|
+
{ key: "int64", test: (t) => $.scalar.isInt64(t) || $.scalar.extendsInt64(t) },
|
|
252
|
+
{ key: "int8", test: (t) => $.scalar.isInt8(t) || $.scalar.extendsInt8(t) },
|
|
253
|
+
{ key: "integer", test: (t) => $.scalar.isInteger(t) || $.scalar.extendsInteger(t) },
|
|
254
|
+
{ key: "numeric", test: (t) => $.scalar.isNumeric(t) || $.scalar.extendsNumeric(t) },
|
|
255
|
+
{
|
|
256
|
+
key: "offsetDateTime",
|
|
257
|
+
test: (t) => $.scalar.isOffsetDateTime(t) || $.scalar.extendsOffsetDateTime(t),
|
|
258
|
+
},
|
|
259
|
+
{ key: "plainDate", test: (t) => $.scalar.isPlainDate(t) || $.scalar.extendsPlainDate(t) },
|
|
260
|
+
{ key: "plainTime", test: (t) => $.scalar.isPlainTime(t) || $.scalar.extendsPlainTime(t) },
|
|
261
|
+
{ key: "safeint", test: (t) => $.scalar.isSafeint(t) || $.scalar.extendsSafeint(t) },
|
|
262
|
+
{ key: "string", test: (t) => $.scalar.isString(t) || $.scalar.extendsString(t) },
|
|
263
|
+
{ key: "uint16", test: (t) => $.scalar.isUint16(t) || $.scalar.extendsUint16(t) },
|
|
264
|
+
{ key: "uint32", test: (t) => $.scalar.isUint32(t) || $.scalar.extendsUint32(t) },
|
|
265
|
+
{ key: "uint64", test: (t) => $.scalar.isUint64(t) || $.scalar.extendsUint64(t) },
|
|
266
|
+
{ key: "uint8", test: (t) => $.scalar.isUint8(t) || $.scalar.extendsUint8(t) },
|
|
267
|
+
{ key: "url", test: (t) => $.scalar.isUrl(t) || $.scalar.extendsUrl(t) },
|
|
268
|
+
{ key: "utcDateTime", test: (t) => $.scalar.isUtcDateTime(t) || $.scalar.extendsUtcDateTime(t) },
|
|
269
|
+
];
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Determines the key to use in the scalarTransformerMap for the given scalar type.
|
|
273
|
+
*
|
|
274
|
+
* @param type - The scalar type to check.
|
|
275
|
+
* @returns The corresponding key from the scalarTransformerMap.
|
|
276
|
+
* @throws Error if the scalar type is unknown.
|
|
277
|
+
*/
|
|
278
|
+
function getScalarTransformKey(type: Scalar): keyof typeof scalarTransformerMap {
|
|
279
|
+
for (const { key, test } of scalarTests) {
|
|
280
|
+
if (test(type)) {
|
|
281
|
+
return key;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
throw new Error(`Unknown scalar type: ${type}`);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function passthroughTransformer(itemRef: Refkey | Children) {
|
|
288
|
+
return itemRef;
|
|
289
|
+
}
|