Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add converter for uint8array map to string and serialization for models #1934

Merged
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/autorest.typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions packages/rlc-common/src/metadata/buildPackageFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"@azure-rest/core-client": "^1.1.2",
"@azure/core-auth": "^1.4.1",
"@azure/core-rest-pipeline": "^1.8.1",
"@azure/core-util": "^1.1.0",
"@azure/core-util": "^1.4.0",
"@azure/logger": "^1.0.3",
"tslib": "^2.4.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"@azure-rest/core-client": "^1.1.4",
"@azure/core-rest-pipeline": "^1.8.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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
StreamableMethod,
operationOptionsToRequestParameters,
} from "@azure-rest/core-client";
import { uint8ArrayToString, stringToUint8Array } from "@azure/core-util";
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
import {
PublishCloudEventOptions,
PublishCloudEventsOptions,
Expand All @@ -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"],
},
},
});
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"@azure-rest/core-client": "^1.1.2",
"@azure/core-auth": "^1.4.1",
"@azure/core-rest-pipeline": "^1.8.1",
"@azure/core-util": "^1.1.0",
"@azure/core-util": "^1.4.0",
"@azure/logger": "^1.0.3",
"tslib": "^2.4.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@microsoft/api-extractor": "^7.31.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
},
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"@azure-rest/core-client": "^1.1.2",
"@azure/core-auth": "^1.4.1",
"@azure/core-rest-pipeline": "^1.8.1",
"@azure/core-util": "^1.1.0",
"@azure/core-util": "^1.4.0",
"@azure/logger": "^1.0.3",
"tslib": "^2.4.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"@azure-rest/core-client": "^1.1.2",
"@azure/core-auth": "^1.4.1",
"@azure/core-rest-pipeline": "^1.8.1",
"@azure/core-util": "^1.1.0",
"@azure/core-util": "^1.4.0",
"@azure/logger": "^1.0.3",
"tslib": "^2.4.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"@azure-rest/core-client": "^1.1.4",
"@azure/core-rest-pipeline": "^1.8.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",
Expand Down
3 changes: 2 additions & 1 deletion packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"@azure/core-paging": "^1.5.0",
"@azure/core-lro": "^2.5.4",
"@azure/core-rest-pipeline": "^1.9.2",
"@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",
Expand Down
Loading
Loading