@azure/eventgrid-namespaces 1.0.0-alpha.20240412.4
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/LICENSE +21 -0
- package/README.md +181 -0
- package/dist/index.js +600 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/EventGridClient.js +50 -0
- package/dist-esm/src/cadl-generated/EventGridClient.js.map +1 -0
- package/dist-esm/src/cadl-generated/api/EventGridContext.js +9 -0
- package/dist-esm/src/cadl-generated/api/EventGridContext.js.map +1 -0
- package/dist-esm/src/cadl-generated/api/index.js +5 -0
- package/dist-esm/src/cadl-generated/api/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/api/operations.js +197 -0
- package/dist-esm/src/cadl-generated/api/operations.js.map +1 -0
- package/dist-esm/src/cadl-generated/index.js +4 -0
- package/dist-esm/src/cadl-generated/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/logger.js +5 -0
- package/dist-esm/src/cadl-generated/logger.js.map +1 -0
- package/dist-esm/src/cadl-generated/models/index.js +4 -0
- package/dist-esm/src/cadl-generated/models/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/models/models.js +4 -0
- package/dist-esm/src/cadl-generated/models/models.js.map +1 -0
- package/dist-esm/src/cadl-generated/models/options.js +4 -0
- package/dist-esm/src/cadl-generated/models/options.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/clientDefinitions.js +4 -0
- package/dist-esm/src/cadl-generated/rest/clientDefinitions.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/eventGridClient.js +40 -0
- package/dist-esm/src/cadl-generated/rest/eventGridClient.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/index.js +12 -0
- package/dist-esm/src/cadl-generated/rest/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/isUnexpected.js +75 -0
- package/dist-esm/src/cadl-generated/rest/isUnexpected.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/models.js +4 -0
- package/dist-esm/src/cadl-generated/rest/models.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/outputModels.js +4 -0
- package/dist-esm/src/cadl-generated/rest/outputModels.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/parameters.js +4 -0
- package/dist-esm/src/cadl-generated/rest/parameters.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/responses.js +4 -0
- package/dist-esm/src/cadl-generated/rest/responses.js.map +1 -0
- package/dist-esm/src/constants.js +5 -0
- package/dist-esm/src/constants.js.map +1 -0
- package/dist-esm/src/eventGridNamespacesClient.js +147 -0
- package/dist-esm/src/eventGridNamespacesClient.js.map +1 -0
- package/dist-esm/src/eventGridNamespacesPublishBinaryMode.js +63 -0
- package/dist-esm/src/eventGridNamespacesPublishBinaryMode.js.map +1 -0
- package/dist-esm/src/index.js +5 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/models.js +14 -0
- package/dist-esm/src/models.js.map +1 -0
- package/package.json +120 -0
- package/types/eventgrid-namespaces.d.ts +275 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"clientDefinitions.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/clientDefinitions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PublishCloudEventParameters,\n PublishCloudEventsParameters,\n ReceiveCloudEventsParameters,\n AcknowledgeCloudEventsParameters,\n ReleaseCloudEventsParameters,\n RejectCloudEventsParameters,\n RenewCloudEventLocksParameters,\n} from \"./parameters\";\nimport {\n PublishCloudEvent200Response,\n PublishCloudEventDefaultResponse,\n PublishCloudEvents200Response,\n PublishCloudEventsDefaultResponse,\n ReceiveCloudEvents200Response,\n ReceiveCloudEventsDefaultResponse,\n AcknowledgeCloudEvents200Response,\n AcknowledgeCloudEventsDefaultResponse,\n ReleaseCloudEvents200Response,\n ReleaseCloudEventsDefaultResponse,\n RejectCloudEvents200Response,\n RejectCloudEventsDefaultResponse,\n RenewCloudEventLocks200Response,\n RenewCloudEventLocksDefaultResponse,\n} from \"./responses\";\nimport { Client, StreamableMethod } from \"@azure-rest/core-client\";\n\nexport interface PublishCloudEvent {\n /** Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. */\n post(\n options: PublishCloudEventParameters,\n ): StreamableMethod<PublishCloudEvent200Response | PublishCloudEventDefaultResponse>;\n /** Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. */\n post(\n options: PublishCloudEventsParameters,\n ): StreamableMethod<PublishCloudEvents200Response | PublishCloudEventsDefaultResponse>;\n}\n\nexport interface ReceiveCloudEvents {\n /** Receive Batch of Cloud Events from the Event Subscription. */\n post(\n options?: ReceiveCloudEventsParameters,\n ): StreamableMethod<ReceiveCloudEvents200Response | ReceiveCloudEventsDefaultResponse>;\n}\n\nexport interface AcknowledgeCloudEvents {\n /** Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully acknowledged lockTokens, along with other failed lockTokens with their corresponding error information. Successfully acknowledged events will no longer be available to any consumer. */\n post(\n options: AcknowledgeCloudEventsParameters,\n ): StreamableMethod<AcknowledgeCloudEvents200Response | AcknowledgeCloudEventsDefaultResponse>;\n}\n\nexport interface ReleaseCloudEvents {\n /** Release batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully released lockTokens, along with other failed lockTokens with their corresponding error information. */\n post(\n options: ReleaseCloudEventsParameters,\n ): StreamableMethod<ReleaseCloudEvents200Response | ReleaseCloudEventsDefaultResponse>;\n}\n\nexport interface RejectCloudEvents {\n /** Reject batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully rejected lockTokens, along with other failed lockTokens with their corresponding error information. */\n post(\n options: RejectCloudEventsParameters,\n ): StreamableMethod<RejectCloudEvents200Response | RejectCloudEventsDefaultResponse>;\n}\n\nexport interface RenewCloudEventLocks {\n /** Renew lock for batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully renewed lockTokens, along with other failed lockTokens with their corresponding error information. */\n post(\n options: RenewCloudEventLocksParameters,\n ): StreamableMethod<RenewCloudEventLocks200Response | RenewCloudEventLocksDefaultResponse>;\n}\n\nexport interface Routes {\n /** Resource for '/topics/\\{topicName\\}:publish' has methods for the following verbs: post */\n (path: \"/topics/{topicName}:publish\", topicName: string): PublishCloudEvent;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:receive' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive\",\n topicName: string,\n eventSubscriptionName: string,\n ): ReceiveCloudEvents;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:acknowledge' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge\",\n topicName: string,\n eventSubscriptionName: string,\n ): AcknowledgeCloudEvents;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:release' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release\",\n topicName: string,\n eventSubscriptionName: string,\n ): ReleaseCloudEvents;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:reject' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject\",\n topicName: string,\n eventSubscriptionName: string,\n ): RejectCloudEvents;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:renewLock' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:renewLock\",\n topicName: string,\n eventSubscriptionName: string,\n ): RenewCloudEventLocks;\n}\n\nexport type EventGridContext = Client & {\n path: Routes;\n};\n"]}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
import { getClient } from "@azure-rest/core-client";
|
4
|
+
import { logger } from "../logger";
|
5
|
+
import { isKeyCredential } from "@azure/core-auth";
|
6
|
+
/**
|
7
|
+
* Initialize a new instance of `EventGridContext`
|
8
|
+
* @param endpoint - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net
|
9
|
+
* @param credentials - uniquely identify client credential
|
10
|
+
* @param options - the parameter for all optional parameters
|
11
|
+
*/
|
12
|
+
export default function createClient(endpoint, credentials, options = {}) {
|
13
|
+
var _a, _b, _c, _d, _e, _f;
|
14
|
+
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}`;
|
15
|
+
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-10-01-preview";
|
16
|
+
const userAgentInfo = `azsdk-js-eventgrid-namespaces-rest/1.0.0-beta.1`;
|
17
|
+
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
18
|
+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
19
|
+
: `${userAgentInfo}`;
|
20
|
+
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
21
|
+
userAgentPrefix,
|
22
|
+
}, loggingOptions: {
|
23
|
+
logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info,
|
24
|
+
}, credentials: {
|
25
|
+
scopes: (_f = (_e = options.credentials) === null || _e === void 0 ? void 0 : _e.scopes) !== null && _f !== void 0 ? _f : ["https://eventgrid.azure.net/.default"],
|
26
|
+
apiKeyHeaderName: "Authorization",
|
27
|
+
} });
|
28
|
+
const client = getClient(baseUrl, credentials, options);
|
29
|
+
if (isKeyCredential(credentials)) {
|
30
|
+
client.pipeline.addPolicy({
|
31
|
+
name: "customKeyCredentialPolicy",
|
32
|
+
async sendRequest(request, next) {
|
33
|
+
request.headers.set("Authorization", "SharedAccessKey " + credentials.key);
|
34
|
+
return next(request);
|
35
|
+
},
|
36
|
+
});
|
37
|
+
}
|
38
|
+
return client;
|
39
|
+
}
|
40
|
+
//# sourceMappingURL=eventGridClient.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"eventGridClient.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/eventGridClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,SAAS,EAAiB,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAkC,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,QAAgB,EAChB,WAA4C,EAC5C,UAAyB,EAAE;;IAE3B,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,GAAG,QAAQ,EAAE,CAAC;IACjD,OAAO,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,oBAAoB,CAAC;IAChE,MAAM,aAAa,GAAG,iDAAiD,CAAC;IACxE,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;QAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,aAAa,EAAE;QAChE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC;IACzB,OAAO,mCACF,OAAO,KACV,gBAAgB,EAAE;YAChB,eAAe;SAChB,EACD,cAAc,EAAE;YACd,MAAM,EAAE,MAAA,MAAA,OAAO,CAAC,cAAc,0CAAE,MAAM,mCAAI,MAAM,CAAC,IAAI;SACtD,EACD,WAAW,EAAE;YACX,MAAM,EAAE,MAAA,MAAA,OAAO,CAAC,WAAW,0CAAE,MAAM,mCAAI,CAAC,sCAAsC,CAAC;YAC/E,gBAAgB,EAAE,eAAe;SAClC,GACF,CAAC;IAEF,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAqB,CAAC;IAE5E,IAAI,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC;QACjC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;YACxB,IAAI,EAAE,2BAA2B;YACjC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI;gBAC7B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,kBAAkB,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;gBAC3E,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getClient, ClientOptions } from \"@azure-rest/core-client\";\nimport { logger } from \"../logger\";\nimport { TokenCredential, KeyCredential, isKeyCredential } from \"@azure/core-auth\";\nimport { EventGridContext } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of `EventGridContext`\n * @param endpoint - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpoint: string,\n credentials: TokenCredential | KeyCredential,\n options: ClientOptions = {},\n): EventGridContext {\n const baseUrl = options.baseUrl ?? `${endpoint}`;\n options.apiVersion = options.apiVersion ?? \"2023-10-01-preview\";\n const userAgentInfo = `azsdk-js-eventgrid-namespaces-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n credentials: {\n scopes: options.credentials?.scopes ?? [\"https://eventgrid.azure.net/.default\"],\n apiKeyHeaderName: \"Authorization\",\n },\n };\n\n const client = getClient(baseUrl, credentials, options) as EventGridContext;\n\n if (isKeyCredential(credentials)) {\n client.pipeline.addPolicy({\n name: \"customKeyCredentialPolicy\",\n async sendRequest(request, next) {\n request.headers.set(\"Authorization\", \"SharedAccessKey \" + credentials.key);\n return next(request);\n },\n });\n }\n\n return client;\n}\n"]}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
import EventGridClient from "./eventGridClient";
|
4
|
+
export * from "./eventGridClient";
|
5
|
+
export * from "./parameters";
|
6
|
+
export * from "./responses";
|
7
|
+
export * from "./clientDefinitions";
|
8
|
+
export * from "./isUnexpected";
|
9
|
+
export * from "./models";
|
10
|
+
export * from "./outputModels";
|
11
|
+
export default EventGridClient;
|
12
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,eAAe,eAAe,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport EventGridClient from \"./eventGridClient\";\n\nexport * from \"./eventGridClient\";\nexport * from \"./parameters\";\nexport * from \"./responses\";\nexport * from \"./clientDefinitions\";\nexport * from \"./isUnexpected\";\nexport * from \"./models\";\nexport * from \"./outputModels\";\n\nexport default EventGridClient;\n"]}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
const responseMap = {
|
4
|
+
"POST /topics/{topicName}:publish": ["200"],
|
5
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive": ["200"],
|
6
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge": ["200"],
|
7
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release": ["200"],
|
8
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject": ["200"],
|
9
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:renewLock": ["200"],
|
10
|
+
};
|
11
|
+
export function isUnexpected(response) {
|
12
|
+
const lroOriginal = response.headers["x-ms-original-url"];
|
13
|
+
const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
|
14
|
+
const method = response.request.method;
|
15
|
+
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
16
|
+
if (!pathDetails) {
|
17
|
+
pathDetails = getParametrizedPathSuccess(method, url.pathname);
|
18
|
+
}
|
19
|
+
return !pathDetails.includes(response.status);
|
20
|
+
}
|
21
|
+
function getParametrizedPathSuccess(method, path) {
|
22
|
+
var _a, _b, _c, _d;
|
23
|
+
const pathParts = path.split("/");
|
24
|
+
// Traverse list to match the longest candidate
|
25
|
+
// matchedLen: the length of candidate path
|
26
|
+
// matchedValue: the matched status code array
|
27
|
+
let matchedLen = -1, matchedValue = [];
|
28
|
+
// Iterate the responseMap to find a match
|
29
|
+
for (const [key, value] of Object.entries(responseMap)) {
|
30
|
+
// Extracting the path from the map key which is in format
|
31
|
+
// GET /path/foo
|
32
|
+
if (!key.startsWith(method)) {
|
33
|
+
continue;
|
34
|
+
}
|
35
|
+
const candidatePath = getPathFromMapKey(key);
|
36
|
+
// Get each part of the url path
|
37
|
+
const candidateParts = candidatePath.split("/");
|
38
|
+
// track if we have found a match to return the values found.
|
39
|
+
let found = true;
|
40
|
+
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
41
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
|
42
|
+
const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
|
43
|
+
// If the current part of the candidate is a "template" part
|
44
|
+
// Try to use the suffix of pattern to match the path
|
45
|
+
// {guid} ==> $
|
46
|
+
// {guid}:export ==> :export$
|
47
|
+
const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
|
48
|
+
if (!isMatched) {
|
49
|
+
found = false;
|
50
|
+
break;
|
51
|
+
}
|
52
|
+
continue;
|
53
|
+
}
|
54
|
+
// If the candidate part is not a template and
|
55
|
+
// the parts don't match mark the candidate as not found
|
56
|
+
// to move on with the next candidate path.
|
57
|
+
if (candidateParts[i] !== pathParts[j]) {
|
58
|
+
found = false;
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
// We finished evaluating the current candidate parts
|
63
|
+
// Update the matched value if and only if we found the longer pattern
|
64
|
+
if (found && candidatePath.length > matchedLen) {
|
65
|
+
matchedLen = candidatePath.length;
|
66
|
+
matchedValue = value;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
return matchedValue;
|
70
|
+
}
|
71
|
+
function getPathFromMapKey(mapKey) {
|
72
|
+
const pathStart = mapKey.indexOf("/");
|
73
|
+
return mapKey.slice(pathStart);
|
74
|
+
}
|
75
|
+
//# sourceMappingURL=isUnexpected.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAkBlC,MAAM,WAAW,GAA6B;IAC5C,kCAAkC,EAAE,CAAC,KAAK,CAAC;IAC3C,6EAA6E,EAAE,CAAC,KAAK,CAAC;IACtF,iFAAiF,EAAE,CAAC,KAAK,CAAC;IAC1F,6EAA6E,EAAE,CAAC,KAAK,CAAC;IACtF,4EAA4E,EAAE,CAAC,KAAK,CAAC;IACrF,+EAA+E,EAAE,CAAC,KAAK,CAAC;CACzF,CAAC;AAuBF,MAAM,UAAU,YAAY,CAC1B,QAauC;IAQvC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;IACvC,IAAI,WAAW,GAAG,WAAW,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,WAAW,GAAG,0BAA0B,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,0BAA0B,CAAC,MAAc,EAAE,IAAY;;IAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,C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AAC,CAAC,0CAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAC1E,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CACnB,CAAC;gBAEF,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,KAAK,GAAG,KAAK,CAAC;oBACd,MAAM;gBACR,CAAC;gBACD,SAAS;YACX,CAAC;YAED,8CAA8C;YAC9C,wDAAwD;YACxD,2CAA2C;YAC3C,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvC,KAAK,GAAG,KAAK,CAAC;gBACd,MAAM;YACR,CAAC;QACH,CAAC;QAED,qDAAqD;QACrD,sEAAsE;QACtE,IAAI,KAAK,IAAI,aAAa,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;YAC/C,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC;YAClC,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PublishCloudEvent200Response,\n PublishCloudEvents200Response,\n PublishCloudEventDefaultResponse,\n ReceiveCloudEvents200Response,\n ReceiveCloudEventsDefaultResponse,\n AcknowledgeCloudEvents200Response,\n AcknowledgeCloudEventsDefaultResponse,\n ReleaseCloudEvents200Response,\n ReleaseCloudEventsDefaultResponse,\n RejectCloudEvents200Response,\n RejectCloudEventsDefaultResponse,\n RenewCloudEventLocks200Response,\n RenewCloudEventLocksDefaultResponse,\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"POST /topics/{topicName}:publish\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:renewLock\": [\"200\"],\n};\n\nexport function isUnexpected(\n response:\n | PublishCloudEvent200Response\n | PublishCloudEvents200Response\n | PublishCloudEventDefaultResponse,\n): response is PublishCloudEventDefaultResponse;\nexport function isUnexpected(\n response: ReceiveCloudEvents200Response | ReceiveCloudEventsDefaultResponse,\n): response is ReceiveCloudEventsDefaultResponse;\nexport function isUnexpected(\n response: AcknowledgeCloudEvents200Response | AcknowledgeCloudEventsDefaultResponse,\n): response is AcknowledgeCloudEventsDefaultResponse;\nexport function isUnexpected(\n response: ReleaseCloudEvents200Response | ReleaseCloudEventsDefaultResponse,\n): response is ReleaseCloudEventsDefaultResponse;\nexport function isUnexpected(\n response: RejectCloudEvents200Response | RejectCloudEventsDefaultResponse,\n): response is RejectCloudEventsDefaultResponse;\nexport function isUnexpected(\n response: RenewCloudEventLocks200Response | RenewCloudEventLocksDefaultResponse,\n): response is RenewCloudEventLocksDefaultResponse;\nexport function isUnexpected(\n response:\n | PublishCloudEvent200Response\n | PublishCloudEvents200Response\n | PublishCloudEventDefaultResponse\n | ReceiveCloudEvents200Response\n | ReceiveCloudEventsDefaultResponse\n | AcknowledgeCloudEvents200Response\n | AcknowledgeCloudEventsDefaultResponse\n | ReleaseCloudEvents200Response\n | ReleaseCloudEventsDefaultResponse\n | RejectCloudEvents200Response\n | RejectCloudEventsDefaultResponse\n | RenewCloudEventLocks200Response\n | RenewCloudEventLocksDefaultResponse,\n): response is\n | PublishCloudEventDefaultResponse\n | ReceiveCloudEventsDefaultResponse\n | AcknowledgeCloudEventsDefaultResponse\n | ReleaseCloudEventsDefaultResponse\n | RejectCloudEventsDefaultResponse\n | RenewCloudEventLocksDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\",\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/** Properties of an event published to an Azure Messaging EventGrid Namespace topic using the CloudEvent 1.0 Schema. */\nexport interface CloudEvent {\n /** An identifier for the event. The combination of id and source must be unique for each distinct event. */\n id: string;\n /** Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event. */\n source: string;\n /** Event data specific to the event type. */\n data?: unknown;\n /** Event data specific to the event type, encoded as a base64 string. */\n data_base64?: string;\n /** Type of event related to the originating occurrence. */\n type: string;\n /** The time (in UTC) the event was generated, in RFC3339 format. */\n time?: Date | string;\n /** The version of the CloudEvents specification which the event uses. */\n specversion: string;\n /** Identifies the schema that data adheres to. */\n dataschema?: string;\n /** Content type of data value. */\n datacontenttype?: string;\n /** This describes the subject of the event in the context of the event producer (identified by source). */\n subject?: string;\n}\n\n/** Array of lock tokens for the corresponding received Cloud Events to be acknowledged. */\nexport interface AcknowledgeOptions {\n /** Array of lock tokens. */\n lockTokens: string[];\n}\n\n/** Array of lock tokens for the corresponding received Cloud Events to be released. */\nexport interface ReleaseOptions {\n /** Array of lock tokens. */\n lockTokens: string[];\n}\n\n/** Array of lock tokens for the corresponding received Cloud Events to be rejected. */\nexport interface RejectOptions {\n /** Array of lock tokens. */\n lockTokens: string[];\n}\n\n/** Array of lock tokens for the corresponding received Cloud Events to be renewed. */\nexport interface RenewLockOptions {\n /** Array of lock tokens. */\n lockTokens: string[];\n}\n\n/** Alias for ReleaseDelay */\nexport type ReleaseDelay = number | 0 | 10 | 60 | 600 | 3600;\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"outputModels.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/outputModels.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { ErrorModel } from \"@azure-rest/core-client\";\n\n/** Properties of an event published to an Azure Messaging EventGrid Namespace topic using the CloudEvent 1.0 Schema. */\nexport interface CloudEventOutput {\n /** An identifier for the event. The combination of id and source must be unique for each distinct event. */\n id: string;\n /** Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event. */\n source: string;\n /** Event data specific to the event type. */\n data?: any;\n /** Event data specific to the event type, encoded as a base64 string. */\n data_base64?: string;\n /** Type of event related to the originating occurrence. */\n type: string;\n /** The time (in UTC) the event was generated, in RFC3339 format. */\n time?: string;\n /** The version of the CloudEvents specification which the event uses. */\n specversion: string;\n /** Identifies the schema that data adheres to. */\n dataschema?: string;\n /** Content type of data value. */\n datacontenttype?: string;\n /** This describes the subject of the event in the context of the event producer (identified by source). */\n subject?: string;\n}\n\n/** The result of the Publish operation. */\nexport interface PublishResultOutput {}\n\n/** Details of the Receive operation response. */\nexport interface ReceiveResultOutput {\n /** Array of receive responses, one per cloud event. */\n value: Array<ReceiveDetailsOutput>;\n}\n\n/** Receive operation details per Cloud Event. */\nexport interface ReceiveDetailsOutput {\n /** The Event Broker details. */\n brokerProperties: BrokerPropertiesOutput;\n /** Cloud Event details. */\n event: CloudEventOutput;\n}\n\n/** Properties of the Event Broker operation. */\nexport interface BrokerPropertiesOutput {\n /** The token of the lock on the event. */\n lockToken: string;\n /** The attempt count for delivering the event. */\n deliveryCount: number;\n}\n\n/** The result of the Acknowledge operation. */\nexport interface AcknowledgeResultOutput {\n /** Array of FailedLockToken for failed cloud events. Each FailedLockToken includes the lock token along with the related error information (namely, the error code and description). */\n failedLockTokens: Array<FailedLockTokenOutput>;\n /** Array of lock tokens for the successfully acknowledged cloud events. */\n succeededLockTokens: string[];\n}\n\n/** Failed LockToken information. */\nexport interface FailedLockTokenOutput {\n /** The lock token of an entry in the request. */\n lockToken: string;\n /** Error information of the failed operation result for the lock token in the request. */\n error: ErrorModel;\n}\n\n/** The result of the Release operation. */\nexport interface ReleaseResultOutput {\n /** Array of FailedLockToken for failed cloud events. Each FailedLockToken includes the lock token along with the related error information (namely, the error code and description). */\n failedLockTokens: Array<FailedLockTokenOutput>;\n /** Array of lock tokens for the successfully released cloud events. */\n succeededLockTokens: string[];\n}\n\n/** The result of the Reject operation. */\nexport interface RejectResultOutput {\n /** Array of FailedLockToken for failed cloud events. Each FailedLockToken includes the lock token along with the related error information (namely, the error code and description). */\n failedLockTokens: Array<FailedLockTokenOutput>;\n /** Array of lock tokens for the successfully rejected cloud events. */\n succeededLockTokens: string[];\n}\n\n/** The result of the RenewLock operation. */\nexport interface RenewCloudEventLocksResultOutput {\n /** Array of FailedLockToken for failed cloud events. Each FailedLockToken includes the lock token along with the related error information (namely, the error code and description). */\n failedLockTokens: Array<FailedLockTokenOutput>;\n /** Array of lock tokens for the successfully renewed locks. */\n succeededLockTokens: string[];\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/parameters.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RequestParameters } from \"@azure-rest/core-client\";\nimport {\n CloudEvent,\n AcknowledgeOptions,\n ReleaseDelay,\n ReleaseOptions,\n RejectOptions,\n RenewLockOptions,\n} from \"./models\";\n\nexport interface PublishCloudEventBodyParam {\n /** Single Cloud Event being published. */\n body: CloudEvent;\n}\n\nexport interface PublishCloudEventMediaTypesParam {\n /** content type */\n contentType: \"application/cloudevents+json; charset=utf-8\";\n}\n\nexport type PublishCloudEventParameters = PublishCloudEventMediaTypesParam &\n PublishCloudEventBodyParam &\n RequestParameters;\n\nexport interface PublishCloudEventsBodyParam {\n /** Array of Cloud Events being published. */\n body: Array<CloudEvent>;\n}\n\nexport interface PublishCloudEventsMediaTypesParam {\n /** content type */\n contentType: \"application/cloudevents-batch+json; charset=utf-8\";\n}\n\nexport type PublishCloudEventsParameters = PublishCloudEventsMediaTypesParam &\n PublishCloudEventsBodyParam &\n RequestParameters;\n\nexport interface ReceiveCloudEventsQueryParamProperties {\n /** Max Events count to be received. Minimum value is 1, while maximum value is 100 events. If not specified, the default value is 1. */\n maxEvents?: number;\n /** Max wait time value for receive operation in Seconds. It is the time in seconds that the server approximately waits for the availability of an event and responds to the request. If an event is available, the broker responds immediately to the client. Minimum value is 10 seconds, while maximum value is 120 seconds. If not specified, the default value is 60 seconds. */\n maxWaitTime?: number;\n}\n\nexport interface ReceiveCloudEventsQueryParam {\n queryParameters?: ReceiveCloudEventsQueryParamProperties;\n}\n\nexport type ReceiveCloudEventsParameters = ReceiveCloudEventsQueryParam & RequestParameters;\n\nexport interface AcknowledgeCloudEventsBodyParam {\n /** AcknowledgeOptions. */\n body: AcknowledgeOptions;\n}\n\nexport type AcknowledgeCloudEventsParameters = AcknowledgeCloudEventsBodyParam & RequestParameters;\n\nexport interface ReleaseCloudEventsBodyParam {\n /** ReleaseOptions */\n body: ReleaseOptions;\n}\n\nexport interface ReleaseCloudEventsQueryParamProperties {\n /** Release cloud events with the specified delay in seconds. */\n releaseDelayInSeconds?: ReleaseDelay;\n}\n\nexport interface ReleaseCloudEventsQueryParam {\n queryParameters?: ReleaseCloudEventsQueryParamProperties;\n}\n\nexport type ReleaseCloudEventsParameters = ReleaseCloudEventsQueryParam &\n ReleaseCloudEventsBodyParam &\n RequestParameters;\n\nexport interface RejectCloudEventsBodyParam {\n /** RejectOptions */\n body: RejectOptions;\n}\n\nexport type RejectCloudEventsParameters = RejectCloudEventsBodyParam & RequestParameters;\n\nexport interface RenewCloudEventLocksBodyParam {\n /** RenewLockOptions */\n body: RenewLockOptions;\n}\n\nexport type RenewCloudEventLocksParameters = RenewCloudEventLocksBodyParam & RequestParameters;\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/responses.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RawHttpHeaders } from \"@azure/core-rest-pipeline\";\nimport { HttpResponse, ErrorResponse } from \"@azure-rest/core-client\";\nimport {\n PublishResultOutput,\n ReceiveResultOutput,\n AcknowledgeResultOutput,\n ReleaseResultOutput,\n RejectResultOutput,\n RenewCloudEventLocksResultOutput,\n} from \"./outputModels\";\n\n/** The request has succeeded. */\nexport interface PublishCloudEvent200Response extends HttpResponse {\n status: \"200\";\n body: PublishResultOutput;\n}\n\nexport interface PublishCloudEventDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface PublishCloudEventDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & PublishCloudEventDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface PublishCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: PublishResultOutput;\n}\n\nexport interface PublishCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface PublishCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & PublishCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface ReceiveCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: ReceiveResultOutput;\n}\n\nexport interface ReceiveCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface ReceiveCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & ReceiveCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface AcknowledgeCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: AcknowledgeResultOutput;\n}\n\nexport interface AcknowledgeCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface AcknowledgeCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & AcknowledgeCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface ReleaseCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: ReleaseResultOutput;\n}\n\nexport interface ReleaseCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface ReleaseCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & ReleaseCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface RejectCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: RejectResultOutput;\n}\n\nexport interface RejectCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface RejectCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & RejectCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface RenewCloudEventLocks200Response extends HttpResponse {\n status: \"200\";\n body: RenewCloudEventLocksResultOutput;\n}\n\nexport interface RenewCloudEventLocksDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface RenewCloudEventLocksDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & RenewCloudEventLocksDefaultHeaders;\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAChD,MAAM,CAAC,MAAM,uBAAuB,GAAG,sCAAsC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const DEFAULT_API_VERSION = \"2018-01-01\";\nexport const DEFAULT_EVENTGRID_SCOPE = \"https://eventgrid.azure.net/.default\";\n"]}
|
@@ -0,0 +1,147 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
import { randomUUID } from "@azure/core-util";
|
4
|
+
import { EventGridClient as EventGridClientGenerated } from "./cadl-generated/EventGridClient";
|
5
|
+
import { cloudEventReservedPropertyNames } from "./models";
|
6
|
+
import { publishCloudEventInBinaryMode } from "./eventGridNamespacesPublishBinaryMode";
|
7
|
+
/**
|
8
|
+
* Event Grid Namespaces Client
|
9
|
+
*/
|
10
|
+
export class EventGridNamespacesClient {
|
11
|
+
/** Azure Messaging EventGrid Client */
|
12
|
+
constructor(endpoint, credential, options = {}) {
|
13
|
+
// credential.update(`SharedAccessKey ${credential.key}`);
|
14
|
+
this._client = new EventGridClientGenerated(endpoint, credential, options);
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
|
18
|
+
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
19
|
+
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
20
|
+
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
21
|
+
* internal server error.
|
22
|
+
*
|
23
|
+
* @param event - Event to publish
|
24
|
+
* @param topicName - Topic to publish the event
|
25
|
+
* @param options - Options to publish
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
async publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
|
29
|
+
const cloudEventWireModel = convertCloudEventToModelType(event);
|
30
|
+
if (!options.binaryMode) {
|
31
|
+
await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
await publishCloudEventInBinaryMode(this._client.getClient(), topicName, cloudEventWireModel, Object.assign({ contentType: options.contentType }, options));
|
35
|
+
}
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
|
39
|
+
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
40
|
+
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
41
|
+
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
42
|
+
* internal server error.
|
43
|
+
*
|
44
|
+
* @param events - Events to publish
|
45
|
+
* @param topicName - Topic to publish the event
|
46
|
+
* @param options - Options to publish
|
47
|
+
*
|
48
|
+
*/
|
49
|
+
async publishCloudEvents(events, topicName, options = { requestOptions: {} }) {
|
50
|
+
const eventsWireModel = [];
|
51
|
+
for (const individualevent of events) {
|
52
|
+
eventsWireModel.push(convertCloudEventToModelType(individualevent));
|
53
|
+
}
|
54
|
+
await this._client.publishCloudEvents(topicName, eventsWireModel, options);
|
55
|
+
}
|
56
|
+
/**
|
57
|
+
* Receive Batch of Cloud Events from the Event Subscription.
|
58
|
+
*
|
59
|
+
* @param topicName - Topic to receive
|
60
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
61
|
+
* @param options - Options to receive
|
62
|
+
*
|
63
|
+
*/
|
64
|
+
receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
65
|
+
return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
|
66
|
+
}
|
67
|
+
/**
|
68
|
+
* Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
|
69
|
+
* event is successfully acknowledged. The response body will include the set of successfully acknowledged
|
70
|
+
* lockTokens, along with other failed lockTokens with their corresponding error information. Successfully
|
71
|
+
* acknowledged events will no longer be available to any consumer.
|
72
|
+
*
|
73
|
+
* @param lockTokens - Lock Tokens
|
74
|
+
* @param topicName - Topic Name
|
75
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
76
|
+
* @param options - Options to Acknowledge
|
77
|
+
*
|
78
|
+
*/
|
79
|
+
acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
80
|
+
return this._client.acknowledgeCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
81
|
+
}
|
82
|
+
/**
|
83
|
+
* Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
|
84
|
+
* successfully released. The response body will include the set of successfully released lockTokens, along
|
85
|
+
* with other failed lockTokens with their corresponding error information.
|
86
|
+
*
|
87
|
+
* @param lockTokens - Lock Tokens
|
88
|
+
* @param topicName - Topic Name
|
89
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
90
|
+
* @param options - Options to release
|
91
|
+
*
|
92
|
+
*/
|
93
|
+
releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
94
|
+
return this._client.releaseCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
95
|
+
}
|
96
|
+
/**
|
97
|
+
* Reject batch of Cloud Events.
|
98
|
+
*
|
99
|
+
* @param lockTokens - Lock Tokens
|
100
|
+
* @param topicName - Topic Name
|
101
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
102
|
+
* @param options - Options to reject
|
103
|
+
*
|
104
|
+
*/
|
105
|
+
rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
106
|
+
return this._client.rejectCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
107
|
+
}
|
108
|
+
/**
|
109
|
+
* Renew lock for batch of Cloud Events.
|
110
|
+
*
|
111
|
+
* @param lockTokens - Lock Tokens
|
112
|
+
* @param topicName - Topic Name
|
113
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
114
|
+
* @param options - Options to renew
|
115
|
+
*/
|
116
|
+
renewCloudEventLocks(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
117
|
+
return this._client.renewCloudEventLocks(topicName, eventSubscriptionName, { lockTokens }, options);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
export function convertCloudEventToModelType(event) {
|
121
|
+
var _a, _b, _c, _d, _e;
|
122
|
+
if (event.extensionAttributes) {
|
123
|
+
for (const propName in event.extensionAttributes) {
|
124
|
+
// Per the cloud events spec: "CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z') or digits ('0' to '9') from the ASCII character set"
|
125
|
+
// they also can not match an existing defined property name.
|
126
|
+
if (!/^[a-z0-9]*$/.test(propName) ||
|
127
|
+
cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
|
128
|
+
throw new Error(`invalid extension attribute name: ${propName}`);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
const converted = Object.assign({ specversion: (_a = event.specversion) !== null && _a !== void 0 ? _a : "1.0", type: event.type, source: event.source, id: (_b = event.id) !== null && _b !== void 0 ? _b : randomUUID(), time: (_c = event.time) !== null && _c !== void 0 ? _c : new Date(), subject: event.subject, dataschema: event.dataschema }, ((_d = event.extensionAttributes) !== null && _d !== void 0 ? _d : []));
|
133
|
+
if (event.data instanceof Uint8Array) {
|
134
|
+
if (!event.datacontenttype) {
|
135
|
+
throw new Error("a data content type must be provided when sending an event with binary data");
|
136
|
+
}
|
137
|
+
converted.datacontenttype = event.datacontenttype;
|
138
|
+
converted.dataBase64 = event.data;
|
139
|
+
}
|
140
|
+
else {
|
141
|
+
converted.datacontenttype =
|
142
|
+
(_e = event.datacontenttype) !== null && _e !== void 0 ? _e : "application/cloudevents+json; charset=utf-8";
|
143
|
+
converted.data = event.data;
|
144
|
+
}
|
145
|
+
return converted;
|
146
|
+
}
|
147
|
+
//# sourceMappingURL=eventGridNamespacesClient.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"eventGridNamespacesClient.js","sourceRoot":"","sources":["../../src/eventGridNamespacesClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBl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AAS,CAAC,eAAe;YACvB,MAAA,KAAK,CAAC,eAAe,mCAAI,6CAA6C,CAAC;QACzE,SAAS,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureKeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport {\n ReceiveResult,\n AcknowledgeResult,\n ReleaseResult,\n RejectResult,\n PublishCloudEventsOptions,\n ReceiveCloudEventsOptions,\n AcknowledgeCloudEventsOptions,\n ReleaseCloudEventsOptions,\n RejectCloudEventsOptions,\n RenewCloudEventLocksOptions,\n RenewCloudEventLocksResult,\n CloudEvent as CloudEventWireModel,\n} from \"./cadl-generated/models\";\nimport { randomUUID } from \"@azure/core-util\";\nimport { EventGridClient as EventGridClientGenerated } from \"./cadl-generated/EventGridClient\";\nimport { EventGridClientOptions } from \"./cadl-generated/api\";\nimport { PublishCloudEventOptions, CloudEvent, cloudEventReservedPropertyNames } from \"./models\";\nimport { publishCloudEventInBinaryMode } from \"./eventGridNamespacesPublishBinaryMode\";\n\n/**\n * Event Grid Namespaces Client\n */\nexport class EventGridNamespacesClient {\n private _client: EventGridClientGenerated;\n\n /** Azure Messaging EventGrid Client */\n constructor(\n endpoint: string,\n credential: AzureKeyCredential | TokenCredential,\n options: EventGridClientOptions = {},\n ) {\n // credential.update(`SharedAccessKey ${credential.key}`);\n this._client = new EventGridClientGenerated(endpoint, credential, options);\n }\n\n /**\n * Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200\n * status code with an empty JSON object in response. Otherwise, the server can return various error codes.\n * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message\n * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for\n * internal server error.\n *\n * @param event - Event to publish\n * @param topicName - Topic to publish the event\n * @param options - Options to publish\n *\n */\n async publishCloudEvent<T>(\n event: CloudEvent<T>,\n topicName: string,\n options: PublishCloudEventOptions = { requestOptions: {} },\n ): Promise<void> {\n const cloudEventWireModel: CloudEventWireModel = convertCloudEventToModelType(event);\n\n if (!options.binaryMode) {\n await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);\n } else {\n await publishCloudEventInBinaryMode(\n this._client.getClient(),\n topicName,\n cloudEventWireModel,\n {\n contentType: options.contentType,\n ...options,\n },\n );\n }\n }\n\n /**\n * Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200\n * status code with an empty JSON object in response. Otherwise, the server can return various error codes.\n * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message\n * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for\n * internal server error.\n *\n * @param events - Events to publish\n * @param topicName - Topic to publish the event\n * @param options - Options to publish\n *\n */\n async publishCloudEvents<T>(\n events: CloudEvent<T>[],\n topicName: string,\n options: PublishCloudEventsOptions = { requestOptions: {} },\n ): Promise<void> {\n const eventsWireModel: Array<CloudEventWireModel> = [];\n for (const individualevent of events) {\n eventsWireModel.push(convertCloudEventToModelType(individualevent));\n }\n await this._client.publishCloudEvents(topicName, eventsWireModel, options);\n }\n\n /**\n * Receive Batch of Cloud Events from the Event Subscription.\n *\n * @param topicName - Topic to receive\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to receive\n *\n */\n receiveCloudEvents(\n topicName: string,\n eventSubscriptionName: string,\n options: ReceiveCloudEventsOptions = { requestOptions: {} },\n ): Promise<ReceiveResult> {\n return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);\n }\n\n /**\n * Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one\n * event is successfully acknowledged. The response body will include the set of successfully acknowledged\n * lockTokens, along with other failed lockTokens with their corresponding error information. Successfully\n * acknowledged events will no longer be available to any consumer.\n *\n * @param lockTokens - Lock Tokens\n * @param topicName - Topic Name\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to Acknowledge\n *\n */\n acknowledgeCloudEvents(\n lockTokens: string[],\n topicName: string,\n eventSubscriptionName: string,\n options: AcknowledgeCloudEventsOptions = { requestOptions: {} },\n ): Promise<AcknowledgeResult> {\n return this._client.acknowledgeCloudEvents(\n topicName,\n eventSubscriptionName,\n { lockTokens },\n options,\n );\n }\n\n /**\n * Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is\n * successfully released. The response body will include the set of successfully released lockTokens, along\n * with other failed lockTokens with their corresponding error information.\n *\n * @param lockTokens - Lock Tokens\n * @param topicName - Topic Name\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to release\n *\n */\n releaseCloudEvents(\n lockTokens: string[],\n topicName: string,\n eventSubscriptionName: string,\n options: ReleaseCloudEventsOptions = { requestOptions: {} },\n ): Promise<ReleaseResult> {\n return this._client.releaseCloudEvents(\n topicName,\n eventSubscriptionName,\n { lockTokens },\n options,\n );\n }\n\n /**\n * Reject batch of Cloud Events.\n *\n * @param lockTokens - Lock Tokens\n * @param topicName - Topic Name\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to reject\n *\n */\n rejectCloudEvents(\n lockTokens: string[],\n topicName: string,\n eventSubscriptionName: string,\n options: RejectCloudEventsOptions = { requestOptions: {} },\n ): Promise<RejectResult> {\n return this._client.rejectCloudEvents(\n topicName,\n eventSubscriptionName,\n { lockTokens },\n options,\n );\n }\n\n /**\n * Renew lock for batch of Cloud Events.\n *\n * @param lockTokens - Lock Tokens\n * @param topicName - Topic Name\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to renew\n */\n renewCloudEventLocks(\n lockTokens: string[],\n topicName: string,\n eventSubscriptionName: string,\n options: RenewCloudEventLocksOptions = { requestOptions: {} },\n ): Promise<RenewCloudEventLocksResult> {\n return this._client.renewCloudEventLocks(\n topicName,\n eventSubscriptionName,\n { lockTokens },\n options,\n );\n }\n}\n\nexport function convertCloudEventToModelType<T>(event: CloudEvent<T>): CloudEventWireModel {\n if (event.extensionAttributes) {\n for (const propName in event.extensionAttributes) {\n // Per the cloud events spec: \"CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z') or digits ('0' to '9') from the ASCII character set\"\n // they also can not match an existing defined property name.\n\n if (\n !/^[a-z0-9]*$/.test(propName) ||\n cloudEventReservedPropertyNames.indexOf(propName) !== -1\n ) {\n throw new Error(`invalid extension attribute name: ${propName}`);\n }\n }\n }\n\n const converted: CloudEventWireModel = {\n specversion: event.specversion ?? \"1.0\",\n type: event.type,\n source: event.source,\n id: event.id ?? randomUUID(),\n time: event.time ?? new Date(),\n subject: event.subject,\n dataschema: event.dataschema,\n ...(event.extensionAttributes ?? []),\n };\n\n if (event.data instanceof Uint8Array) {\n if (!event.datacontenttype) {\n throw new Error(\n \"a data content type must be provided when sending an event with binary data\",\n );\n }\n\n converted.datacontenttype = event.datacontenttype;\n converted.dataBase64 = event.data;\n } else {\n converted.datacontenttype =\n event.datacontenttype ?? \"application/cloudevents+json; charset=utf-8\";\n converted.data = event.data;\n }\n\n return converted;\n}\n"]}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
import { isUnexpected, } from "./cadl-generated/rest/index";
|
4
|
+
import { operationOptionsToRequestParameters } from "@azure-rest/core-client";
|
5
|
+
import { Buffer } from "buffer";
|
6
|
+
export async function publishCloudEventInBinaryMode(context, topicName, event, options = { requestOptions: {} }) {
|
7
|
+
const result = await _publishCloudEventSendBinaryMode(context, topicName, event, options);
|
8
|
+
return _publishCloudEventDeserialize(result);
|
9
|
+
}
|
10
|
+
export async function _publishCloudEventDeserialize(result) {
|
11
|
+
if (isUnexpected(result)) {
|
12
|
+
throw result.body;
|
13
|
+
}
|
14
|
+
return result.body;
|
15
|
+
}
|
16
|
+
export function _publishCloudEventSendBinaryMode(context, topicName, event, options = { requestOptions: {} }) {
|
17
|
+
var _a, _b;
|
18
|
+
const headers = {
|
19
|
+
"ce-id": event.id,
|
20
|
+
"ce-source": event.source,
|
21
|
+
"ce-type": event.type,
|
22
|
+
"ce-specversion": event.specversion,
|
23
|
+
};
|
24
|
+
if (event.time) {
|
25
|
+
headers["ce-time"] = event.time.toISOString();
|
26
|
+
}
|
27
|
+
if (event.dataschema) {
|
28
|
+
headers["ce-dataschema"] = event.dataschema;
|
29
|
+
}
|
30
|
+
if (event.datacontenttype) {
|
31
|
+
headers["ce-datacontenttype"] = event.datacontenttype;
|
32
|
+
}
|
33
|
+
if (event.subject) {
|
34
|
+
headers["ce-subject"] = event.subject;
|
35
|
+
}
|
36
|
+
let data;
|
37
|
+
if (event.data) {
|
38
|
+
// If data is already encoded
|
39
|
+
if (Buffer.isBuffer(event.data)) {
|
40
|
+
data = event.data;
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
throw new Error(`CloudEvent data must be binary when in binary mode.`);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
if (event.dataBase64) {
|
48
|
+
data = event.dataBase64;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
return context.path("/topics/{topicName}:publish", topicName).post(Object.assign(Object.assign({}, operationOptionsToRequestParameters(options)), { contentType: (_a = options.contentType) !== null && _a !== void 0 ? _a : "application/cloudevents+json; charset=utf-8", headers, body: {
|
52
|
+
id: event.id,
|
53
|
+
source: event.source,
|
54
|
+
data,
|
55
|
+
type: event.type,
|
56
|
+
time: (_b = event.time) === null || _b === void 0 ? void 0 : _b.toISOString(),
|
57
|
+
specversion: event.specversion,
|
58
|
+
dataschema: event.dataschema,
|
59
|
+
datacontenttype: event.datacontenttype,
|
60
|
+
subject: event.subject,
|
61
|
+
} }));
|
62
|
+
}
|
63
|
+
//# sourceMappingURL=eventGridNamespacesPublishBinaryMode.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"eventGridNamespacesPublishBinaryMode.js","sourceRoot":"","sources":["../../src/eventGridNamespacesPublishBinaryMode.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,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AC,GAAG,KAAK,CAAC,eAAe,CAAC;IACxD,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;IACxC,CAAC;IAED,IAAI,IAAS,CAAC;IACd,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,6BAA6B;QAC7B,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,SAAS,CAAC,CAAC,IAAI,iCAC7D,mCAAmC,CAAC,OAAO,CAAC,KAC/C,WAAW,EAAE,MAAC,OAAO,CAAC,WAAmB,mCAAI,6CAA6C,EAC1F,OAAO,EACP,IAAI,EAAE;YACJ,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,IAAI;YACJ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,MAAA,KAAK,CAAC,IAAI,0CAAE,WAAW,EAAE;YAC/B,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,IACD,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n isUnexpected,\n EventGridContext as Client,\n PublishCloudEvent200Response,\n PublishCloudEventDefaultResponse,\n} from \"./cadl-generated/rest/index\";\nimport { StreamableMethod, operationOptionsToRequestParameters } from \"@azure-rest/core-client\";\nimport { PublishCloudEventOptions } from \"./cadl-generated/models/options\";\nimport { RawHttpHeadersInput } from \"@azure/core-rest-pipeline\";\nimport { Buffer } from \"buffer\";\nimport { CloudEvent } from \"./cadl-generated\";\n\nexport async function publishCloudEventInBinaryMode(\n context: Client,\n topicName: string,\n event: CloudEvent,\n options: PublishCloudEventOptions = { requestOptions: {} },\n): Promise<Record<string, any>> {\n const result = await _publishCloudEventSendBinaryMode(context, topicName, event, options);\n return _publishCloudEventDeserialize(result);\n}\n\nexport async function _publishCloudEventDeserialize(\n result: PublishCloudEvent200Response | PublishCloudEventDefaultResponse,\n): Promise<Record<string, any>> {\n if (isUnexpected(result)) {\n throw result.body;\n }\n\n return result.body;\n}\n\nexport function _publishCloudEventSendBinaryMode(\n context: Client,\n topicName: string,\n event: CloudEvent,\n options: PublishCloudEventOptions = { requestOptions: {} },\n): StreamableMethod<PublishCloudEvent200Response | PublishCloudEventDefaultResponse> {\n const headers: RawHttpHeadersInput = {\n \"ce-id\": event.id,\n \"ce-source\": event.source,\n \"ce-type\": event.type,\n \"ce-specversion\": event.specversion,\n };\n\n if (event.time) {\n headers[\"ce-time\"] = event.time.toISOString();\n }\n\n if (event.dataschema) {\n headers[\"ce-dataschema\"] = event.dataschema;\n }\n\n if (event.datacontenttype) {\n headers[\"ce-datacontenttype\"] = event.datacontenttype;\n }\n\n if (event.subject) {\n headers[\"ce-subject\"] = event.subject;\n }\n\n let data: any;\n if (event.data) {\n // If data is already encoded\n if (Buffer.isBuffer(event.data)) {\n data = event.data;\n } else {\n throw new Error(`CloudEvent data must be binary when in binary mode.`);\n }\n } else {\n if (event.dataBase64) {\n data = event.dataBase64;\n }\n }\n\n return context.path(\"/topics/{topicName}:publish\", topicName).post({\n ...operationOptionsToRequestParameters(options),\n contentType: (options.contentType as any) ?? \"application/cloudevents+json; charset=utf-8\",\n headers,\n body: {\n id: event.id,\n source: event.source,\n data,\n type: event.type,\n time: event.time?.toISOString(),\n specversion: event.specversion,\n dataschema: event.dataschema,\n datacontenttype: event.datacontenttype,\n subject: event.subject,\n },\n });\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAoBtD,OAAO,EAAE,yBAAyB,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { AzureKeyCredential } from \"@azure/core-auth\";\n\nexport {\n ReceiveResult,\n ReceiveDetails,\n BrokerProperties,\n AcknowledgeResult,\n FailedLockToken,\n ReleaseResult,\n RejectResult,\n PublishCloudEventsOptions,\n ReceiveCloudEventsOptions,\n AcknowledgeCloudEventsOptions,\n ReleaseCloudEventsOptions,\n RejectCloudEventsOptions,\n ReleaseDelay,\n RenewCloudEventLocksOptions,\n RenewCloudEventLocksResult,\n} from \"./cadl-generated/models\";\n\nexport { EventGridNamespacesClient as EventGridClient } from \"./eventGridNamespacesClient\";\n\nexport { EventGridClientOptions } from \"./cadl-generated\";\n\nexport { PublishResultOutput } from \"./cadl-generated/rest\";\n\nexport { OperationOptions } from \"@azure-rest/core-client\";\n\nexport { CloudEvent, PublishCloudEventOptions } from \"./models\";\n"]}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
export const cloudEventReservedPropertyNames = [
|
4
|
+
"specversion",
|
5
|
+
"id",
|
6
|
+
"source",
|
7
|
+
"type",
|
8
|
+
"datacontenttype",
|
9
|
+
"dataschema",
|
10
|
+
"subject",
|
11
|
+
"time",
|
12
|
+
"data",
|
13
|
+
];
|
14
|
+
//# sourceMappingURL=models.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AA0DlC,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,aAAa;IACb,IAAI;IACJ,QAAQ;IACR,MAAM;IACN,iBAAiB;IACjB,YAAY;IACZ,SAAS;IACT,MAAM;IACN,MAAM;CACP,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { OperationOptions } from \"@azure-rest/core-client\";\n\nexport interface PublishCloudEventOptions extends OperationOptions {\n /** binary mode */\n binaryMode?: boolean;\n\n /** content type */\n contentType?: string;\n}\n\n/**\n * An event in the Cloud Event 1.0 schema.\n */\nexport interface CloudEvent<T> {\n /**\n * Type of event related to the originating occurrence.\n */\n type: string;\n /**\n * Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event.\n */\n source: string;\n /**\n * An identifier for the event. The combination of id and source must be unique for each distinct event.\n */\n id: string;\n /**\n * The time the event was generated.\n */\n time?: Date;\n /**\n * Identifies the schema that data adheres to.\n */\n dataschema?: string;\n /**\n * Content type of data value.\n */\n datacontenttype?: string;\n /**\n * Event data specific to the event type.\n */\n data?: T;\n /**\n * This describes the subject of the event in the context of the event producer (identified by source).\n */\n subject?: string;\n /**\n * Additional context attributes for the event. The Cloud Event specification refers to these as \"extension attributes\".\n */\n extensionAttributes?: Record<string, unknown>;\n /**\n * The version of the CloudEvents specification which the event uses.\n */\n specversion?: string | \"1.0\";\n}\n\nexport const cloudEventReservedPropertyNames = [\n \"specversion\",\n \"id\",\n \"source\",\n \"type\",\n \"datacontenttype\",\n \"dataschema\",\n \"subject\",\n \"time\",\n \"data\",\n];\n"]}
|