diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 77c0608095..c5c8718b49 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -23,7 +23,7 @@ importers: '@azure/core-paging': ^1.5.0 '@azure/core-rest-pipeline': ^1.12.0 '@azure/core-tracing': ^1.0.0 - '@azure/core-util': ^1.0.0-beta.1 + '@azure/core-util': ^1.4.0 '@azure/core-xml': ^1.0.0-beta.1 '@azure/logger': ^1.0.0 '@microsoft.azure/autorest.testserver': ^3.3.34 @@ -110,7 +110,7 @@ importers: '@types/fs-extra': 9.0.13 '@types/js-yaml': 3.12.1 '@types/mocha': 5.2.7 - '@types/node': 18.17.2 + '@types/node': 18.17.3 '@types/prettier': 1.19.1 '@types/sinon': 10.0.16 '@types/xmlbuilder': 0.0.34 @@ -167,12 +167,12 @@ importers: devDependencies: '@types/fs-extra': 8.1.2 '@types/lodash': 4.14.196 - '@types/node': 18.17.2 + '@types/node': 18.17.3 eslint: 8.46.0 fs-extra: 10.1.0 prettier: 2.7.1 rimraf: 3.0.2 - ts-node: 10.9.1_wi7sq6ly3n6iu4nn6oglpcixxq + ts-node: 10.9.1_nxr4dymg3vz2ku26eufzpgsdza typescript: 5.0.4 ../../packages/typespec-test: @@ -208,7 +208,7 @@ importers: prettier: 2.7.1 devDependencies: '@types/mocha': 5.2.7 - '@types/node': 18.17.2 + '@types/node': 18.17.3 ts-node: 8.10.2_typescript@5.0.4 typescript: 5.0.4 @@ -225,6 +225,7 @@ importers: '@azure/core-lro': ^2.5.4 '@azure/core-paging': ^1.5.0 '@azure/core-rest-pipeline': ^1.12.0 + '@azure/core-util': ^1.4.0 '@azure/logger': ^1.0.4 '@types/chai': ^4.3.1 '@types/fs-extra': ^9.0.13 @@ -271,11 +272,12 @@ importers: '@azure/core-lro': 2.5.4 '@azure/core-paging': 1.5.0 '@azure/core-rest-pipeline': 1.12.0 + '@azure/core-util': 1.4.0 '@azure/logger': 1.0.4 '@types/chai': 4.3.5 '@types/fs-extra': 9.0.13 '@types/mocha': 9.1.1 - '@types/node': 18.17.2 + '@types/node': 18.17.3 '@types/prettier': 2.7.3 '@typescript-eslint/eslint-plugin': 5.62.0_btmaeoyl2rpnnxkii57gvvnqrq '@typescript-eslint/parser': 5.62.0_qjkw45b3tljvcusgfgkwdbduhu @@ -286,7 +288,7 @@ importers: mkdirp: 2.1.6 mocha: 9.2.2 rimraf: 3.0.2 - ts-node: 10.9.1_wi7sq6ly3n6iu4nn6oglpcixxq + ts-node: 10.9.1_nxr4dymg3vz2ku26eufzpgsdza typescript: 5.0.4 packages: @@ -361,7 +363,7 @@ packages: dependencies: '@azure/identity': 3.2.4 '@azure/storage-blob': 12.15.0 - '@types/node': 18.17.2 + '@types/node': 18.17.3 transitivePeerDependencies: - encoding - supports-color @@ -686,9 +688,9 @@ packages: '@azure/core-tracing': 1.0.1 '@azure/core-util': 1.4.0 '@azure/logger': 1.0.4 - '@azure/msal-browser': 2.38.0 - '@azure/msal-common': 13.2.0 - '@azure/msal-node': 1.18.0 + '@azure/msal-browser': 2.38.1 + '@azure/msal-common': 13.2.1 + '@azure/msal-node': 1.18.1 events: 3.3.0 jws: 4.0.0 open: 8.4.2 @@ -705,23 +707,23 @@ packages: dependencies: tslib: 2.6.1 - /@azure/msal-browser/2.38.0: - resolution: {integrity: sha512-gxBh83IumHgEP9uMCm9pJLKLRwICMQTxG9TX3AytdNt3oLUI3tytm/szYD5u5zKJgSkhHvwFSM+NPnM04hYw3w==} + /@azure/msal-browser/2.38.1: + resolution: {integrity: sha512-NROo7mLpw7aWtj8tWy9ZPz3WWiudwVAOIDZ1K3PPrjDAA4kFYayWlbZiJl1T1sD5Oqwa6FOtwzFSvuUj1CWp6Q==} engines: {node: '>=0.8.0'} dependencies: - '@azure/msal-common': 13.2.0 + '@azure/msal-common': 13.2.1 dev: true - /@azure/msal-common/13.2.0: - resolution: {integrity: sha512-rnstQ7Zgn3fSTKNQO+/YNV34/QXJs0vni7IA0/3QB1EEyrJg14xyRmTqlw9ta+pdSuT5OJwUP8kI3D/rBwUIBw==} + /@azure/msal-common/13.2.1: + resolution: {integrity: sha512-9CtyVdDtAOw+raemKg8gdBuE7gleObgSb7p4bzMIlUt8eM69/Gaow7uqr1gK3jLYINSrss32OZW8mBbdgVLiHg==} engines: {node: '>=0.8.0'} dev: true - /@azure/msal-node/1.18.0: - resolution: {integrity: sha512-N6GX1Twxw524e7gaJvj7hKtrPRmZl9qGY7U4pmUdx4XzoWYRFfYk4H1ZjVhQ7pwb5Ks88NNhbXVCagsuYPTEFg==} + /@azure/msal-node/1.18.1: + resolution: {integrity: sha512-B4kUOWJoN4vD8b3pGJ9Q9mIZhaDb8EnQM1aN0x1otlQgTfzDvEk6rWc6fy8uGdtXqcNddBtiXdc4oRiItroVkA==} engines: {node: 10 || 12 || 14 || 16 || 18} dependencies: - '@azure/msal-common': 13.2.0 + '@azure/msal-common': 13.2.1 jsonwebtoken: 9.0.1 uuid: 8.3.2 dev: true @@ -742,18 +744,19 @@ packages: - encoding dev: true - /@babel/code-frame/7.22.5: - resolution: {integrity: sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ==} + /@babel/code-frame/7.22.10: + resolution: {integrity: sha512-/KKIMG4UEL35WmI9OlvMhurwtytjvXoFcGNrOvyG9zIzA8YmPjVtIZUf7b05+TPO7G7/GEmLHDaoCgACHl9hhA==} engines: {node: '>=6.9.0'} dependencies: - '@babel/highlight': 7.22.5 + '@babel/highlight': 7.22.10 + chalk: 2.4.2 /@babel/helper-validator-identifier/7.22.5: resolution: {integrity: sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==} engines: {node: '>=6.9.0'} - /@babel/highlight/7.22.5: - resolution: {integrity: sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==} + /@babel/highlight/7.22.10: + resolution: {integrity: sha512-78aUtVcT7MUscr0K5mIEnkwxPE0MaxkR5RxRwuHaQ+JuU5AmTPhY+do2mdzVTnIJJpyBglql2pehuBIWHug+WQ==} engines: {node: '>=6.9.0'} dependencies: '@babel/helper-validator-identifier': 7.22.5 @@ -848,12 +851,7 @@ packages: dependencies: '@jridgewell/set-array': 1.1.2 '@jridgewell/sourcemap-codec': 1.4.15 - '@jridgewell/trace-mapping': 0.3.18 - dev: true - - /@jridgewell/resolve-uri/3.1.0: - resolution: {integrity: sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==} - engines: {node: '>=6.0.0'} + '@jridgewell/trace-mapping': 0.3.19 dev: true /@jridgewell/resolve-uri/3.1.1: @@ -870,22 +868,18 @@ packages: resolution: {integrity: sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==} dependencies: '@jridgewell/gen-mapping': 0.3.3 - '@jridgewell/trace-mapping': 0.3.18 - dev: true - - /@jridgewell/sourcemap-codec/1.4.14: - resolution: {integrity: sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==} + '@jridgewell/trace-mapping': 0.3.19 dev: true /@jridgewell/sourcemap-codec/1.4.15: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} dev: true - /@jridgewell/trace-mapping/0.3.18: - resolution: {integrity: sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA==} + /@jridgewell/trace-mapping/0.3.19: + resolution: {integrity: sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==} dependencies: - '@jridgewell/resolve-uri': 3.1.0 - '@jridgewell/sourcemap-codec': 1.4.14 + '@jridgewell/resolve-uri': 3.1.1 + '@jridgewell/sourcemap-codec': 1.4.15 dev: true /@jridgewell/trace-mapping/0.3.9: @@ -1057,18 +1051,18 @@ packages: /@types/cors/2.8.13: resolution: {integrity: sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 dev: true /@types/eslint-scope/3.7.4: resolution: {integrity: sha512-9K4zoImiZc3HlIp6AVUDE4CWYx22a+lhSZMYNpbjW04+YF0KWj4pJXnEMjdnFTiQibFFmElcsasJXDbdI/EPhA==} dependencies: - '@types/eslint': 8.44.1 + '@types/eslint': 8.44.2 '@types/estree': 1.0.1 dev: true - /@types/eslint/8.44.1: - resolution: {integrity: sha512-XpNDc4Z5Tb4x+SW1MriMVeIsMoONHCkWFMkR/aPJbzEsxqHy+4Glu/BqTdPrApfDeMaXbtNh6bseNgl5KaWrSg==} + /@types/eslint/8.44.2: + resolution: {integrity: sha512-sdPRb9K6iL5XZOmBubg8yiFp5yS/JdUDQsq5e6h95km91MCYMuvp7mh1fjPEYUhvHepKpZOjnEaMBR4PxjWDzg==} dependencies: '@types/estree': 1.0.1 '@types/json-schema': 7.0.12 @@ -1081,13 +1075,13 @@ packages: /@types/fs-extra/8.1.2: resolution: {integrity: sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 dev: true /@types/fs-extra/9.0.13: resolution: {integrity: sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 dev: true /@types/js-yaml/3.12.1: @@ -1116,11 +1110,11 @@ packages: /@types/node-fetch/2.6.4: resolution: {integrity: sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg==} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 form-data: 3.0.1 - /@types/node/18.17.2: - resolution: {integrity: sha512-wBo3KqP/PBqje5TI9UTiuL3yWfP6sdPtjtygSOqcYZWT232dfDeDOnkDps5wqZBP9NgGgYrNejinl0faAuE+HQ==} + /@types/node/18.17.3: + resolution: {integrity: sha512-2x8HWtFk0S99zqVQABU9wTpr8wPoaDHZUcAkoTKH+nL7kPv3WUI9cRi/Kk5Mz4xdqXSqTkKP7IWNoQQYCnDsTA==} /@types/prettier/1.19.1: resolution: {integrity: sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ==} @@ -1151,13 +1145,13 @@ packages: /@types/tunnel/0.0.1: resolution: {integrity: sha512-AOqu6bQu5MSWwYvehMXLukFHnupHrpZ8nvgae5Ggie9UwzDR1CCwoXgSSWNZJuyOlCdfdsWMA5F2LlmvyoTv8A==} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 dev: false /@types/tunnel/0.0.3: resolution: {integrity: sha512-sOUTGn6h1SfQ+gbgqC364jLFBw2lnFqkgF3q0WovEHRLMrVD1sd5aufqi/aJObLekJO+Aq5z646U4Oxy6shXMA==} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 dev: true /@types/xmlbuilder/0.0.34: @@ -1178,7 +1172,7 @@ packages: resolution: {integrity: sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==} requiresBuild: true dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 dev: true optional: true @@ -1317,7 +1311,7 @@ packages: engines: {node: '>=16.0.0'} hasBin: true dependencies: - '@babel/code-frame': 7.22.5 + '@babel/code-frame': 7.22.10 ajv: 8.12.0 change-case: 4.1.2 globby: 13.1.4 @@ -1847,7 +1841,7 @@ packages: hasBin: true dependencies: caniuse-lite: 1.0.30001519 - electron-to-chromium: 1.4.484 + electron-to-chromium: 1.4.487 node-releases: 2.0.13 update-browserslist-db: 1.0.11_browserslist@4.21.10 dev: true @@ -2387,8 +2381,8 @@ packages: resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==} dev: true - /electron-to-chromium/1.4.484: - resolution: {integrity: sha512-nO3ZEomTK2PO/3TUXgEx0A97xZTpKVf4p427lABHuCpT1IQ2N+njVh29DkQkCk6Q4m2wjU+faK4xAcfFndwjvw==} + /electron-to-chromium/1.4.487: + resolution: {integrity: sha512-XbCRs/34l31np/p33m+5tdBrdXu9jJkZxSbNxj5I0H1KtV2ZMSB+i/HYqDiRzHaFx2T5EdytjoBRe8QRJE2vQg==} dev: true /emoji-regex/8.0.0: @@ -2425,7 +2419,7 @@ packages: dependencies: '@types/cookie': 0.4.1 '@types/cors': 2.8.13 - '@types/node': 18.17.2 + '@types/node': 18.17.3 accepts: 1.3.8 base64id: 2.0.0 cookie: 0.4.2 @@ -3446,8 +3440,8 @@ packages: engines: {node: '>= 0.4'} dev: true - /is-core-module/2.12.1: - resolution: {integrity: sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==} + /is-core-module/2.13.0: + resolution: {integrity: sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==} dependencies: has: 1.0.3 dev: true @@ -3636,7 +3630,7 @@ packages: resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==} engines: {node: '>= 10.13.0'} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 merge-stream: 2.0.0 supports-color: 8.1.1 dev: true @@ -4208,7 +4202,7 @@ packages: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} dependencies: hosted-git-info: 2.8.9 - resolve: 1.22.2 + resolve: 1.22.4 semver: 5.7.2 validate-npm-package-license: 3.0.4 dev: true @@ -4667,7 +4661,7 @@ packages: resolution: {integrity: sha512-/njmZ8s1wVeR6pjTZ+0nCnv8SpZNRMT2D1RLOJQESlYFDBvwpTA4KWJpZ+sBJ4+vhjILRcK7JIFdGCdxEAAitg==} engines: {node: '>= 0.10'} dependencies: - resolve: 1.22.2 + resolve: 1.22.4 dev: true /regexp.prototype.flags/1.5.0: @@ -4757,11 +4751,11 @@ packages: engines: {node: '>=8'} dev: true - /resolve/1.22.2: - resolution: {integrity: sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==} + /resolve/1.22.4: + resolution: {integrity: sha512-PXNdCiPqDqeUou+w1C2eTQbNfxKSuMxqTCuvlmmMsk1NWHL5fRrhY6Pl0qEYYc6+QqGClco1Qj8XnjPego4wfg==} hasBin: true dependencies: - is-core-module: 2.12.1 + is-core-module: 2.13.0 path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 dev: true @@ -5269,7 +5263,7 @@ packages: uglify-js: optional: true dependencies: - '@jridgewell/trace-mapping': 0.3.18 + '@jridgewell/trace-mapping': 0.3.19 jest-worker: 27.5.1 schema-utils: 3.3.0 serialize-javascript: 6.0.1 @@ -5351,7 +5345,7 @@ packages: code-block-writer: 11.0.3 dev: false - /ts-node/10.9.1_wi7sq6ly3n6iu4nn6oglpcixxq: + /ts-node/10.9.1_nxr4dymg3vz2ku26eufzpgsdza: resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -5370,7 +5364,7 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 - '@types/node': 18.17.2 + '@types/node': 18.17.3 acorn: 8.10.0 acorn-walk: 8.2.0 arg: 4.1.3 diff --git a/packages/autorest.typescript/package.json b/packages/autorest.typescript/package.json index 1577957aa0..9252e0f757 100644 --- a/packages/autorest.typescript/package.json +++ b/packages/autorest.typescript/package.json @@ -79,7 +79,7 @@ "devDependencies": { "@azure-tools/test-recorder": "^3.0.0", "@azure/abort-controller": "^1.0.1", - "@azure/core-util": "^1.0.0-beta.1", + "@azure/core-util": "^1.4.0", "@azure/core-xml": "^1.0.0-beta.1", "@microsoft.azure/autorest.testserver": "^3.3.34", "@types/chai": "^4.2.8", diff --git a/packages/rlc-common/src/metadata/buildPackageFile.ts b/packages/rlc-common/src/metadata/buildPackageFile.ts index 9919fbd84d..d35fc02308 100644 --- a/packages/rlc-common/src/metadata/buildPackageFile.ts +++ b/packages/rlc-common/src/metadata/buildPackageFile.ts @@ -164,6 +164,9 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) { ...(hasLRO && { "@azure/core-lro": "^2.5.4", "@azure/abort-controller": "^1.0.0" + }), + ...(model.options.isModularLibrary && { + "@azure/core-util": "^1.4.0" }) }, devDependencies: { diff --git a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/package-files/package.json b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/package-files/package.json index 6948c195da..9ea8d0e70e 100644 --- a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/package-files/package.json +++ b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/package-files/package.json @@ -126,7 +126,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" } diff --git a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/package.json b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/package.json index cd50faae68..7961474f22 100644 --- a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/package.json @@ -55,7 +55,8 @@ "@azure-rest/core-client": "^1.1.4", "@azure/core-rest-pipeline": "^1.12.0", "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "tslib": "^2.2.0", + "@azure/core-util": "^1.4.0" }, "devDependencies": { "@microsoft/api-extractor": "^7.31.1", diff --git a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/api/operations.ts b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/api/operations.ts index a893700226..4cbeee4732 100644 --- a/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/api/operations.ts +++ b/packages/typespec-test/test/eventgrid_modular/generated/typespec-ts/src/api/operations.ts @@ -28,6 +28,7 @@ import { StreamableMethod, operationOptionsToRequestParameters, } from "@azure-rest/core-client"; +import { uint8ArrayToString, stringToUint8Array } from "@azure/core-util"; import { PublishCloudEventOptions, PublishCloudEventsOptions, @@ -52,7 +53,24 @@ export function _publishCloudEventSend( contentType: (options.contentType as any) ?? "application/cloudevents+json; charset=utf-8", - body: { event: event }, + body: { + event: { + id: event["id"], + source: event["source"], + data: event["data"], + data_base64: + event["dataBase64"] !== undefined + ? uint8ArrayToString(event["dataBase64"], "base64") + : undefined, + type: event["type"], + time: + event["time"] !== undefined ? new Date(event["time"]) : undefined, + specversion: event["specversion"], + dataschema: event["dataschema"], + datacontenttype: event["datacontenttype"], + subject: event["subject"], + }, + }, }); } @@ -90,15 +108,29 @@ export function _publishCloudEventsSend( ): StreamableMethod< PublishCloudEvents200Response | PublishCloudEventsDefaultResponse > { - return context - .path("/topics/{topicName}:publish", topicName) - .post({ - ...operationOptionsToRequestParameters(options), - contentType: - (options.contentType as any) ?? - "application/cloudevents-batch+json; charset=utf-8", - body: events, - }); + return context.path("/topics/{topicName}:publish", topicName).post({ + ...operationOptionsToRequestParameters(options), + contentType: + (options.contentType as any) ?? + "application/cloudevents-batch+json; charset=utf-8", + body: (events ?? []).map((p) => { + return { + id: p["id"], + source: p["source"], + data: p["data"], + data_base64: + p["dataBase64"] !== undefined + ? uint8ArrayToString(p["dataBase64"], "base64") + : undefined, + type: p["type"], + time: p["time"] !== undefined ? new Date(p["time"]) : undefined, + specversion: p["specversion"], + dataschema: p["dataschema"], + datacontenttype: p["datacontenttype"], + subject: p["subject"], + }; + }), + }); } export async function _publishCloudEventsDeserialize( @@ -167,9 +199,13 @@ export async function _receiveCloudEventsDeserialize( id: p.event["id"], source: p.event["source"], data: p.event["data"], - dataBase64: Buffer.from(p.event["data_base64"] ?? ""), + dataBase64: + typeof p.event["data_base64"] === "string" + ? stringToUint8Array(p.event["data_base64"], "base64") + : p.event["data_base64"], type: p.event["type"], - time: new Date(p.event["time"] ?? ""), + time: + p.event["time"] !== undefined ? new Date(p.event["time"]) : undefined, specversion: p.event["specversion"], dataschema: p.event["dataschema"], datacontenttype: p.event["datacontenttype"], diff --git a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/package-files/package.json b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/package-files/package.json index f91aa9ac82..b0f01b31ea 100644 --- a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/package-files/package.json +++ b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/package-files/package.json @@ -142,7 +142,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" } diff --git a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/package.json b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/package.json index 96758f13bd..28c4226c04 100644 --- a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/package.json @@ -58,7 +58,8 @@ "tslib": "^2.2.0", "@azure/core-paging": "^1.5.0", "@azure/core-lro": "^2.5.4", - "@azure/abort-controller": "^1.0.0" + "@azure/abort-controller": "^1.0.0", + "@azure/core-util": "^1.4.0" }, "devDependencies": { "@microsoft/api-extractor": "^7.31.1", diff --git a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/loadTestAdministration/api/operations.ts b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/loadTestAdministration/api/operations.ts index 291c32e69f..521b928756 100644 --- a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/loadTestAdministration/api/operations.ts +++ b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/loadTestAdministration/api/operations.ts @@ -76,11 +76,42 @@ export function _createOrUpdateTestSend( contentType: (options.contentType as any) ?? "application/merge-patch+json", body: { - passFailCriteria: options?.passFailCriteria, + passFailCriteria: { + passFailMetrics: options?.passFailCriteria?.["passFailMetrics"], + }, secrets: options?.secrets, - certificate: options?.certificate, + certificate: { + value: options?.certificate?.["value"], + type: options?.certificate?.["type"], + name: options?.certificate?.["name"], + }, environmentVariables: options?.environmentVariables, - loadTestConfiguration: options?.loadTestConfiguration, + loadTestConfiguration: { + engineInstances: options?.loadTestConfiguration?.["engineInstances"], + splitAllCSVs: options?.loadTestConfiguration?.["splitAllCSVs"], + quickStartTest: options?.loadTestConfiguration?.["quickStartTest"], + optionalLoadTestConfig: !options?.loadTestConfiguration + ?.optionalLoadTestConfig + ? undefined + : { + endpointUrl: + options?.loadTestConfiguration?.optionalLoadTestConfig?.[ + "endpointUrl" + ], + virtualUsers: + options?.loadTestConfiguration?.optionalLoadTestConfig?.[ + "virtualUsers" + ], + rampUpTime: + options?.loadTestConfiguration?.optionalLoadTestConfig?.[ + "rampUpTime" + ], + duration: + options?.loadTestConfiguration?.optionalLoadTestConfig?.[ + "duration" + ], + }, + }, description: options?.description, displayName: options?.displayName, subnetId: options?.subnetId, diff --git a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/loadTestRun/api/operations.ts b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/loadTestRun/api/operations.ts index 610e744233..ca9151a566 100644 --- a/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/loadTestRun/api/operations.ts +++ b/packages/typespec-test/test/loadtesting_modular/generated/typespec-ts/src/loadTestRun/api/operations.ts @@ -88,11 +88,42 @@ export function _testRunSend( (options.contentType as any) ?? "application/merge-patch+json", queryParameters: { oldTestRunId: options?.oldTestRunId }, body: { - passFailCriteria: options?.passFailCriteria, + passFailCriteria: { + passFailMetrics: options?.passFailCriteria?.["passFailMetrics"], + }, secrets: options?.secrets, - certificate: options?.certificate, + certificate: { + value: options?.certificate?.["value"], + type: options?.certificate?.["type"], + name: options?.certificate?.["name"], + }, environmentVariables: options?.environmentVariables, - loadTestConfiguration: options?.loadTestConfiguration, + loadTestConfiguration: { + engineInstances: options?.loadTestConfiguration?.["engineInstances"], + splitAllCSVs: options?.loadTestConfiguration?.["splitAllCSVs"], + quickStartTest: options?.loadTestConfiguration?.["quickStartTest"], + optionalLoadTestConfig: !options?.loadTestConfiguration + ?.optionalLoadTestConfig + ? undefined + : { + endpointUrl: + options?.loadTestConfiguration?.optionalLoadTestConfig?.[ + "endpointUrl" + ], + virtualUsers: + options?.loadTestConfiguration?.optionalLoadTestConfig?.[ + "virtualUsers" + ], + rampUpTime: + options?.loadTestConfiguration?.optionalLoadTestConfig?.[ + "rampUpTime" + ], + duration: + options?.loadTestConfiguration?.optionalLoadTestConfig?.[ + "duration" + ], + }, + }, displayName: options?.displayName, testId: options?.testId, description: options?.description, diff --git a/packages/typespec-test/test/openai_modular/generated/typespec-ts/package-files/package.json b/packages/typespec-test/test/openai_modular/generated/typespec-ts/package-files/package.json index bb71052ada..d20d7f79da 100644 --- a/packages/typespec-test/test/openai_modular/generated/typespec-ts/package-files/package.json +++ b/packages/typespec-test/test/openai_modular/generated/typespec-ts/package-files/package.json @@ -126,7 +126,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" } diff --git a/packages/typespec-test/test/openai_modular/generated/typespec-ts/package.json b/packages/typespec-test/test/openai_modular/generated/typespec-ts/package.json index f698700689..5c034694d2 100644 --- a/packages/typespec-test/test/openai_modular/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/openai_modular/generated/typespec-ts/package.json @@ -57,7 +57,8 @@ "@azure/logger": "^1.0.0", "tslib": "^2.2.0", "@azure/core-lro": "^2.5.4", - "@azure/abort-controller": "^1.0.0" + "@azure/abort-controller": "^1.0.0", + "@azure/core-util": "^1.4.0" }, "devDependencies": { "@microsoft/api-extractor": "^7.31.1", diff --git a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/package-files/package.json b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/package-files/package.json index 05f9946086..546a74ac38 100644 --- a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/package-files/package.json +++ b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/package-files/package.json @@ -126,7 +126,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" } diff --git a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/package.json b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/package.json index 8f05bcbab1..95d447453f 100644 --- a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/package.json @@ -55,7 +55,8 @@ "@azure-rest/core-client": "^1.1.4", "@azure/core-rest-pipeline": "^1.12.0", "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "tslib": "^2.2.0", + "@azure/core-util": "^1.4.0" }, "devDependencies": { "@microsoft/api-extractor": "^7.31.1", diff --git a/packages/typespec-ts/package.json b/packages/typespec-ts/package.json index fb5720e360..9c2bca16d2 100644 --- a/packages/typespec-ts/package.json +++ b/packages/typespec-ts/package.json @@ -60,7 +60,8 @@ "@azure/core-paging": "^1.5.0", "@azure/core-lro": "^2.5.4", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/logger": "^1.0.4" + "@azure/logger": "^1.0.4", + "@azure/core-util": "^1.4.0" }, "peerDependencies": { "@azure-tools/typespec-azure-core": ">=0.32.0 <1.0.0", diff --git a/packages/typespec-ts/src/modular/buildCodeModel.ts b/packages/typespec-ts/src/modular/buildCodeModel.ts index d51673f9c1..c9e7ace45e 100644 --- a/packages/typespec-ts/src/modular/buildCodeModel.ts +++ b/packages/typespec-ts/src/modular/buildCodeModel.ts @@ -37,6 +37,7 @@ import { IntrinsicType, getProjectedName, isNullType, + getEncode, isTemplateDeclarationOrInstance } from "@typespec/compiler"; import { @@ -996,11 +997,12 @@ function emitCredentialUnion(cred_types: CredentialTypeUnion) { } function emitStdScalar( + program: Program, scalar: Scalar & { name: IntrinsicScalarName } ): Record { switch (scalar.name) { case "bytes": - return { type: "byte-array", format: "byte" }; + return { type: "byte-array", format: getEncode(program, scalar) }; case "int8": case "int16": case "int32": @@ -1095,7 +1097,7 @@ function applyIntrinsicDecorators( function emitScalar(program: Program, scalar: Scalar): Record { let result: Record = {}; if (program.checker.isStdType(scalar)) { - result = emitStdScalar(scalar); + result = emitStdScalar(program, scalar); } else if (scalar.baseScalar) { result = emitScalar(program, scalar.baseScalar); } diff --git a/packages/typespec-ts/src/modular/buildOperations.ts b/packages/typespec-ts/src/modular/buildOperations.ts index 3e58c5ea48..e3628b360e 100644 --- a/packages/typespec-ts/src/modular/buildOperations.ts +++ b/packages/typespec-ts/src/modular/buildOperations.ts @@ -26,6 +26,7 @@ export function buildOperationFiles( needUnexpectedHelper: boolean = true ) { for (const operationGroup of client.operationGroups) { + const importSet: Map> = new Map>(); const fileName = operationGroup.className ? `${normalizeName(operationGroup.className, NameType.File)}` : // When the program has no operation groups defined all operations are put @@ -73,11 +74,16 @@ export function buildOperationFiles( } operationGroup.operations.forEach((o) => { const operationDeclaration = getOperationFunction(o, clientType); - const sendOperationDeclaration = getSendPrivateFunction(o, clientType); + const sendOperationDeclaration = getSendPrivateFunction( + o, + clientType, + importSet + ); const deserializeOperationDeclaration = getDeserializePrivateFunction( o, isRLCMultiEndpoint(dpgContext), - needUnexpectedHelper + needUnexpectedHelper, + importSet ); operationGroupFile.addFunctions([ sendOperationDeclaration, @@ -95,7 +101,16 @@ export function buildOperationFiles( ] } ]); - + if (importSet.size > 0) { + for (const [moduleName, imports] of importSet.entries()) { + operationGroupFile.addImportDeclarations([ + { + moduleSpecifier: moduleName, + namedImports: [...imports.values()] + } + ]); + } + } operationGroupFile.fixMissingImports(); // have to fixUnusedIdentifiers after everything get generated. operationGroupFile.fixUnusedIdentifiers(); diff --git a/packages/typespec-ts/src/modular/buildProjectFiles.ts b/packages/typespec-ts/src/modular/buildProjectFiles.ts index ebaab04197..43c863fa60 100644 --- a/packages/typespec-ts/src/modular/buildProjectFiles.ts +++ b/packages/typespec-ts/src/modular/buildProjectFiles.ts @@ -172,7 +172,7 @@ export function emitPackage( "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", tslib: "^2.4.0" } diff --git a/packages/typespec-ts/src/modular/helpers/operationHelpers.ts b/packages/typespec-ts/src/modular/helpers/operationHelpers.ts index 254d025c4a..321e7200d5 100644 --- a/packages/typespec-ts/src/modular/helpers/operationHelpers.ts +++ b/packages/typespec-ts/src/modular/helpers/operationHelpers.ts @@ -44,7 +44,8 @@ function getRLCResponseType(rlcResponse?: OperationResponse) { export function getSendPrivateFunction( operation: Operation, - clientType: string + clientType: string, + importSet: Map> ): OptionalKind { const parameters = getOperationSignatureParameters(operation, clientType); const { name } = getOperationName(operation); @@ -65,7 +66,8 @@ export function getSendPrivateFunction( `return context.path("${operationPath}", ${getPathParameters( operation )}).${operationMethod}({...operationOptionsToRequestParameters(options), ${getRequestParameters( - operation + operation, + importSet )}});` ); @@ -78,7 +80,8 @@ export function getSendPrivateFunction( export function getDeserializePrivateFunction( operation: Operation, needSubClient: boolean, - needUnexpectedHelper: boolean + needUnexpectedHelper: boolean, + importSet: Map> ): OptionalKind { const { name } = getOperationName(operation); @@ -126,12 +129,20 @@ export function getDeserializePrivateFunction( statements.push(`return result.body`); } else if (response?.type?.elementType) { statements.push( - `return ${deserializeResponseValue(response.type, "result.body")}` + `return ${deserializeResponseValue( + response.type, + "result.body", + importSet + )}` ); } else if (response?.type?.properties) { statements.push( `return {`, - getResponseMapping(response.type.properties ?? []).join(","), + getResponseMapping( + response.type.properties ?? [], + "result.body", + importSet + ).join(","), `}` ); } else if (returnType.type === "void") { @@ -258,7 +269,10 @@ export function getOperationOptionsName(operation: Operation) { * RLC internally. This will translate High Level parameters into the RLC ones. * Figuring out what goes in headers, body, path and qsp. */ -function getRequestParameters(operation: Operation): string { +function getRequestParameters( + operation: Operation, + importSet: Map> +): string { if (!operation.parameters) { return ""; } @@ -280,7 +294,9 @@ function getRequestParameters(operation: Operation): string { for (const param of operationParameters) { if (param.location === "header" || param.location === "query") { - parametersImplementation[param.location].push(getParameterMap(param)); + parametersImplementation[param.location].push( + getParameterMap(param, importSet) + ); } } @@ -302,30 +318,60 @@ function getRequestParameters(operation: Operation): string { )}},`; } - paramStr = `${paramStr}${buildBodyParameter(operation.bodyParameter)}`; + paramStr = `${paramStr}${buildBodyParameter( + operation.bodyParameter, + importSet + )}`; return paramStr; } -function buildBodyParameter(bodyParameter: BodyParameter | undefined) { +function buildBodyParameter( + bodyParameter: BodyParameter | undefined, + importSet: Map> +) { if (!bodyParameter) { return ""; } if (bodyParameter.type.type === "model") { const bodyParts: string[] = []; + let hasSerializeBody = false; for (const param of bodyParameter?.type.properties?.filter( (p) => !p.readonly ) ?? []) { - bodyParts.push(getParameterMap(param)); + if (param.type.type === "model" && isRequired(param)) { + hasSerializeBody = true; + bodyParts.push( + ...getRequestModelMapping(param.type, param.clientName, importSet) + ); + } else { + bodyParts.push(getParameterMap(param, importSet)); + } } if (bodyParameter && bodyParameter.type.properties) { - return `\nbody: {${bodyParts.join(",\n")}},`; + if (hasSerializeBody) { + return `\nbody: {"${bodyParameter.restApiName}": {${bodyParts.join( + ",\n" + )}}},`; + } else { + return `\nbody: {${bodyParts.join(",\n")}},`; + } } } if (bodyParameter.type.type === "list") { + if (bodyParameter.type.elementType?.type === "model") { + const bodyParts = getRequestModelMapping( + bodyParameter.type.elementType, + "p", + importSet + ); + return `\nbody: (${bodyParameter.clientName} ?? []).map((p) => { return { + ${bodyParts.join(", ")} + };}),`; + } return `\nbody: ${bodyParameter.clientName},`; } @@ -339,21 +385,24 @@ function buildBodyParameter(bodyParameter: BodyParameter | undefined) { /** * This function helps with renames, translating client names to rest api names */ -function getParameterMap(param: Parameter | Property) { +function getParameterMap( + param: Parameter | Property, + importSet: Map> +): string { if (isConstant(param)) { return getConstantValue(param); } if (isOptionalWithouDefault(param)) { - return getOptionalWithoutDefault(param); + return getOptionalWithoutDefault(param, importSet); } if (isOptionalWithDefault(param)) { - return getOptionalWithDefault(param); + return getOptionalWithDefault(param, importSet); } if (isRequired(param)) { - return getRequired(param); + return getRequired(param, importSet); } throw new Error(`Parameter ${param.clientName} is not supported`); @@ -391,7 +440,14 @@ function isRequired(param: Parameter | Property): param is RequiredType { return !param.optional; } -function getRequired(param: RequiredType) { +function getRequired(param: RequiredType, importSet: Map>) { + if (param.type.type === "model") { + return `"${param.restApiName}": ${getRequestModelMapping( + param.type, + param.clientName, + importSet + ).join(",")}`; + } return `"${param.restApiName}": ${param.clientName}`; } @@ -426,7 +482,17 @@ function isOptionalWithouDefault( ): param is OptionalWithoutDefaultType { return Boolean(param.optional && !param.clientDefaultValue); } -function getOptionalWithoutDefault(param: OptionalWithoutDefaultType) { +function getOptionalWithoutDefault( + param: OptionalWithoutDefaultType, + importSet: Map> +) { + if (param.type.type === "model") { + return `"${param.restApiName}": {${getRequestModelMapping( + param.type, + "options?." + param.clientName + "?", + importSet + ).join(", ")}}`; + } return `"${param.restApiName}": options?.${param.clientName}`; } @@ -439,7 +505,17 @@ function isOptionalWithDefault( return Boolean(param.clientDefaultValue); } -function getOptionalWithDefault(param: OptionalWithDefaultType) { +function getOptionalWithDefault( + param: OptionalWithDefaultType, + importSet: Map> +) { + if (param.type.type === "model") { + return `"${param.restApiName}": {${getRequestModelMapping( + param.type, + "options?." + param.clientName, + importSet + ).join(", ")}} ?? ${getQuotedValue(param)}`; + } return `"${param.restApiName}": options.${ param.clientName } ?? ${getQuotedValue(param)}`; @@ -503,13 +579,78 @@ function getNullableCheck(name: string, type: Type) { return `${name} === null ? null :`; } + +/** + * + * This function helps translating an HLC request to RLC request, + * extracting properties from body and headers and building the RLC response object + */ +function getRequestModelMapping( + modelPropertyType: Type, + propertyPath: string = "body", + importSet: Map> +) { + if (!modelPropertyType.properties || !modelPropertyType.properties) { + return []; + } + const props: string[] = []; + const properties: Property[] = modelPropertyType.properties; + for (const property of properties) { + if (property.readonly) { + continue; + } + const propertyFullName = `${propertyPath}.${property.restApiName}`; + if (property.type.type === "model") { + let definition; + if (property.type.isCoreErrorType) { + definition = `"${property.restApiName}": ${getNullableCheck( + propertyFullName, + property.type + )} ${ + !property.optional ? "" : `!${propertyFullName} ? undefined :` + } ${propertyFullName}`; + } else { + definition = `"${property.restApiName}": ${getNullableCheck( + propertyFullName, + property.type + )} ${ + !property.optional ? "" : `!${propertyFullName} ? undefined :` + } {${getRequestModelMapping( + property.type, + `${propertyPath}.${property.restApiName}${ + property.optional ? "?" : "" + }`, + importSet + )}}`; + } + + props.push(definition); + } else { + const dot = propertyPath.endsWith("?") ? "." : ""; + const restValue = `${ + propertyPath ? `${propertyPath}${dot}` : `${dot}` + }["${property.clientName}"]`; + props.push( + `"${property.restApiName}": ${serializeRequestValue( + property.type, + restValue, + importSet + )}` + ); + } + } + + return props; +} + /** * This function helps translating an RLC response to an HLC response, * extracting properties from body and headers and building the HLC response object */ function getResponseMapping( properties: Property[], - propertyPath: string = "result.body" + propertyPath: string = "result.body", + importSet: Map> ) { const props: string[] = []; for (const property of properties) { @@ -534,7 +675,8 @@ function getResponseMapping( property.type.properties ?? [], `${propertyPath}.${property.restApiName}${ property.optional ? "?" : "" - }` + }`, + importSet )}}`; } @@ -547,7 +689,8 @@ function getResponseMapping( props.push( `"${property.clientName}": ${deserializeResponseValue( property.type, - restValue + restValue, + importSet )}` ); } @@ -561,29 +704,94 @@ function getResponseMapping( * We need to drill down into Array elements to make sure that the element type is * deserialized correctly */ -function deserializeResponseValue(type: Type, restValue: string): string { +function deserializeResponseValue( + type: Type, + restValue: string, + importSet: Map> +): string { + const coreUtilSet = importSet.get("@azure/core-util"); switch (type.type) { case "datetime": - return `new Date(${restValue} ?? "")`; - case "byte-array": - return `Buffer.from(${restValue} ?? "")`; + return `${restValue} !== undefined? new Date(${restValue}): undefined`; case "list": if (type.elementType?.type === "model") { return `(${restValue} ?? []).map(p => ({${getResponseMapping( type.elementType?.properties ?? [], - "p" + "p", + importSet )}}))`; } else if ( type.elementType?.properties?.some((p) => needsDeserialize(p.type)) ) { return `(${restValue} ?? []).map(p => ${deserializeResponseValue( type.elementType!, - "p" + "p", + importSet )})`; } else { return restValue; } + case "byte-array": + if (!coreUtilSet) { + importSet.set( + "@azure/core-util", + new Set().add("stringToUint8Array") + ); + } else { + coreUtilSet.add("stringToUint8Array"); + } + return `typeof ${restValue} === 'string' + ? stringToUint8Array(${restValue}, "${type.format ?? "base64"}") + : ${restValue}`; + default: + return restValue; + } +} +/** + * This function helps converting strings into JS complex types recursively. + * We need to drill down into Array elements to make sure that the element type is + * deserialized correctly + */ +function serializeRequestValue( + type: Type, + restValue: string, + importSet: Map> = new Map>() +): string { + const coreUtilSet = importSet.get("@azure/core-util"); + switch (type.type) { + case "datetime": + return `${restValue} !== undefined ? new Date(${restValue}): undefined`; + case "list": + if (type.elementType?.type === "model") { + return `(${restValue} ?? []).map(p => ({${getResponseMapping( + type.elementType?.properties ?? [], + "p", + importSet + )}}))`; + } else if ( + type.elementType?.properties?.some((p) => needsDeserialize(p.type)) + ) { + return `(${restValue} ?? []).map(p => ${deserializeResponseValue( + type.elementType!, + "p", + importSet + )})`; + } else { + return restValue; + } + case "byte-array": + if (!coreUtilSet) { + importSet.set( + "@azure/core-util", + new Set().add("uint8ArrayToString") + ); + } else { + coreUtilSet.add("uint8ArrayToString"); + } + return `${restValue} !== undefined ? uint8ArrayToString(${restValue}, "${ + type.format ?? "base64" + }"): undefined`; default: return restValue; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/package-files/package.json b/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/package-files/package.json index 16a9812258..ae8a4071dc 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/package-files/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/package-files/package.json @@ -128,7 +128,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" } diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/package.json b/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/package.json index 6ce299940c..95704ea4e9 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/default/package.json @@ -55,7 +55,8 @@ "@azure-rest/core-client": "^1.1.4", "@azure/core-rest-pipeline": "^1.12.0", "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "tslib": "^2.2.0", + "@azure/core-util": "^1.4.0" }, "devDependencies": { "@microsoft/api-extractor": "^7.31.1", diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/package-files/package.json b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/package-files/package.json index c3c21c4ac9..7718fc3c47 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/package-files/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/package-files/package.json @@ -144,7 +144,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" } diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/package.json b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/package.json index 07374517c8..986779e349 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/multi-client/package.json @@ -55,7 +55,8 @@ "@azure-rest/core-client": "^1.1.4", "@azure/core-rest-pipeline": "^1.12.0", "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "tslib": "^2.2.0", + "@azure/core-util": "^1.4.0" }, "devDependencies": { "@microsoft/api-extractor": "^7.31.1", diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/package-files/package.json b/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/package-files/package.json index 5bb07132d8..60df4f97b0 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/package-files/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/package-files/package.json @@ -128,7 +128,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" } diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/package.json b/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/package.json index b90e106d11..4501cda901 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/renamed-operation/package.json @@ -55,7 +55,8 @@ "@azure-rest/core-client": "^1.1.4", "@azure/core-rest-pipeline": "^1.12.0", "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "tslib": "^2.2.0", + "@azure/core-util": "^1.4.0" }, "devDependencies": { "@microsoft/api-extractor": "^7.31.1", diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/package-files/package.json b/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/package-files/package.json index c254f2f4fd..0bd758d1c2 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/package-files/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/package-files/package.json @@ -128,7 +128,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" } diff --git a/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/package.json b/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/package.json index 8e75e10f77..af243afbff 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/client/structure/two-operation-group/package.json @@ -55,7 +55,8 @@ "@azure-rest/core-client": "^1.1.4", "@azure/core-rest-pipeline": "^1.12.0", "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "tslib": "^2.2.0", + "@azure/core-util": "^1.4.0" }, "devDependencies": { "@microsoft/api-extractor": "^7.31.1", diff --git a/packages/typespec-ts/test/modularIntegration/generated/models/usage/generated/package-files/package.json b/packages/typespec-ts/test/modularIntegration/generated/models/usage/generated/package-files/package.json index ef7f36b41e..06d40054b9 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/models/usage/generated/package-files/package.json +++ b/packages/typespec-ts/test/modularIntegration/generated/models/usage/generated/package-files/package.json @@ -126,7 +126,7 @@ "@azure-rest/core-client": "^1.1.2", "@azure/core-auth": "^1.4.1", "@azure/core-rest-pipeline": "^1.12.0", - "@azure/core-util": "^1.1.0", + "@azure/core-util": "^1.4.0", "@azure/logger": "^1.0.3", "tslib": "^2.4.0" }