@azure/digital-twins-core
Version:
An isomorphic client library for Azure Digital Twins
228 lines • 8.08 kB
JavaScript
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
import { setContinuationToken } from "../pagingHelper.js";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers.js";
import * as Parameters from "../models/parameters.js";
/// <reference lib="esnext.asynciterable" />
/** Class containing EventRoutes operations. */
export class EventRoutesImpl {
/**
* Initialize a new instance of the class EventRoutes class.
* @param client Reference to the service client
*/
constructor(client) {
this.client = client;
}
/**
* Retrieves all event routes.
* Status codes:
* * 200 OK
* @param options The options parameters.
*/
list(options) {
const iter = this.listPagingAll(options);
return {
next() {
return iter.next();
},
[Symbol.asyncIterator]() {
return this;
},
byPage: (settings) => {
if (settings === null || settings === void 0 ? void 0 : settings.maxPageSize) {
throw new Error("maxPageSize is not supported by this operation.");
}
return this.listPagingPage(options, settings);
},
};
}
listPagingPage(options, settings) {
return __asyncGenerator(this, arguments, function* listPagingPage_1() {
let result;
let continuationToken = settings === null || settings === void 0 ? void 0 : settings.continuationToken;
if (!continuationToken) {
result = yield __await(this._list(options));
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield yield __await(page);
}
while (continuationToken) {
result = yield __await(this._listNext(continuationToken, options));
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield yield __await(page);
}
});
}
listPagingAll(options) {
return __asyncGenerator(this, arguments, function* listPagingAll_1() {
var _a, e_1, _b, _c;
try {
for (var _d = true, _e = __asyncValues(this.listPagingPage(options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const page = _c;
yield __await(yield* __asyncDelegator(__asyncValues(page)));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
}
finally { if (e_1) throw e_1.error; }
}
});
}
/**
* Retrieves all event routes.
* Status codes:
* * 200 OK
* @param options The options parameters.
*/
_list(options) {
return this.client.sendOperationRequest({ options }, listOperationSpec);
}
/**
* Retrieves an event route.
* Status codes:
* * 200 OK
* * 404 Not Found
* * EventRouteNotFound - The event route was not found.
* @param id The id for an event route. The id is unique within event routes and case sensitive.
* @param options The options parameters.
*/
getById(id, options) {
return this.client.sendOperationRequest({ id, options }, getByIdOperationSpec);
}
/**
* Adds or replaces an event route.
* Status codes:
* * 204 No Content
* * 400 Bad Request
* * EventRouteEndpointInvalid - The endpoint provided does not exist or is not active.
* * EventRouteFilterInvalid - The event route filter is invalid.
* * EventRouteIdInvalid - The event route id is invalid.
* * LimitExceeded - The maximum number of event routes allowed has been reached.
* @param id The id for an event route. The id is unique within event routes and case sensitive.
* @param eventRoute The event route data
* @param options The options parameters.
*/
add(id, eventRoute, options) {
return this.client.sendOperationRequest({ id, eventRoute, options }, addOperationSpec);
}
/**
* Deletes an event route.
* Status codes:
* * 204 No Content
* * 404 Not Found
* * EventRouteNotFound - The event route was not found.
* @param id The id for an event route. The id is unique within event routes and case sensitive.
* @param options The options parameters.
*/
delete(id, options) {
return this.client.sendOperationRequest({ id, options }, deleteOperationSpec);
}
/**
* ListNext
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
_listNext(nextLink, options) {
return this.client.sendOperationRequest({ nextLink, options }, listNextOperationSpec);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listOperationSpec = {
path: "/eventroutes",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.EventRouteCollection,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.EventRoutesListExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host],
headerParameters: [Parameters.accept, Parameters.resultsPerPage],
serializer,
};
const getByIdOperationSpec = {
path: "/eventroutes/{id}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.EventRoute,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.EventRoutesGetByIdExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.id],
headerParameters: [Parameters.accept],
serializer,
};
const addOperationSpec = {
path: "/eventroutes/{id}",
httpMethod: "PUT",
responses: {
204: {},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.EventRoutesAddExceptionHeaders,
},
},
requestBody: Parameters.eventRoute,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.id],
headerParameters: [Parameters.contentType, Parameters.accept],
mediaType: "json",
serializer,
};
const deleteOperationSpec = {
path: "/eventroutes/{id}",
httpMethod: "DELETE",
responses: {
204: {},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.EventRoutesDeleteExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.id],
headerParameters: [Parameters.accept],
serializer,
};
const listNextOperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.EventRouteCollection,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.EventRoutesListNextExceptionHeaders,
},
},
urlParameters: [Parameters.$host, Parameters.nextLink],
headerParameters: [Parameters.accept, Parameters.resultsPerPage],
serializer,
};
//# sourceMappingURL=eventRoutes.js.map