@azure/digital-twins-core
Version:
An isomorphic client library for Azure Digital Twins
261 lines • 9.94 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";
import { createHttpPoller, } from "@azure/core-lro";
import { createLroSpec } from "../lroImpl.js";
/// <reference lib="esnext.asynciterable" />
/** Class containing DeleteJobs operations. */
export class DeleteJobsImpl {
/**
* Initialize a new instance of the class DeleteJobs class.
* @param client Reference to the service client
*/
constructor(client) {
this.client = client;
}
/**
* Retrieves all deletion jobs. This may be useful to find a delete job that was previously requested,
* or to view a history of delete jobs that have run or are currently running on the instance.
* 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; }
}
});
}
/**
* Initiates a job which deletes all models, twins, and relationships on the instance. Does not delete
* any other types of entities.
* Status codes:
* * 202 Created
* * 400 Bad Request
* * JobLimitReached - The maximum number of delete jobs allowed has been reached.
* * ValidationFailed - Operation-Id already exists.
* @param options The options parameters.
*/
async beginAdd(options) {
const directSendOperation = async (args, spec) => {
return this.client.sendOperationRequest(args, spec);
};
const sendOperationFn = async (args, spec) => {
var _a;
let currentRawResponse = undefined;
const providedCallback = (_a = args.options) === null || _a === void 0 ? void 0 : _a.onResponse;
const callback = (rawResponse, flatResponse) => {
currentRawResponse = rawResponse;
providedCallback === null || providedCallback === void 0 ? void 0 : providedCallback(rawResponse, flatResponse);
};
const updatedArgs = Object.assign(Object.assign({}, args), { options: Object.assign(Object.assign({}, args.options), { onResponse: callback }) });
const flatResponse = await directSendOperation(updatedArgs, spec);
return {
flatResponse,
rawResponse: {
statusCode: currentRawResponse.status,
body: currentRawResponse.parsedBody,
headers: currentRawResponse.headers.toJSON(),
},
};
};
const lro = createLroSpec({
sendOperationFn,
args: { options },
spec: addOperationSpec,
});
const poller = await createHttpPoller(lro, {
restoreFrom: options === null || options === void 0 ? void 0 : options.resumeFrom,
intervalInMs: options === null || options === void 0 ? void 0 : options.updateIntervalInMs,
});
await poller.poll();
return poller;
}
/**
* Initiates a job which deletes all models, twins, and relationships on the instance. Does not delete
* any other types of entities.
* Status codes:
* * 202 Created
* * 400 Bad Request
* * JobLimitReached - The maximum number of delete jobs allowed has been reached.
* * ValidationFailed - Operation-Id already exists.
* @param options The options parameters.
*/
async beginAddAndWait(options) {
const poller = await this.beginAdd(options);
return poller.pollUntilDone();
}
/**
* Retrieves all deletion jobs. This may be useful to find a delete job that was previously requested,
* or to view a history of delete jobs that have run or are currently running on the instance.
* Status codes:
* * 200 OK
* @param options The options parameters.
*/
_list(options) {
return this.client.sendOperationRequest({ options }, listOperationSpec);
}
/**
* Retrieves a delete job.
* Status codes:
* * 200 OK
* * 404 Not Found
* * DeleteJobNotFound - The delete job was not found.
* @param id The id for the delete job. The id is unique within the service and case sensitive.
* @param options The options parameters.
*/
getById(id, options) {
return this.client.sendOperationRequest({ id, options }, getByIdOperationSpec);
}
/**
* 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 addOperationSpec = {
path: "/jobs/deletions",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.DeleteJob,
headersMapper: Mappers.DeleteJobsAddHeaders,
},
201: {
bodyMapper: Mappers.DeleteJob,
headersMapper: Mappers.DeleteJobsAddHeaders,
},
202: {
bodyMapper: Mappers.DeleteJob,
headersMapper: Mappers.DeleteJobsAddHeaders,
},
204: {
bodyMapper: Mappers.DeleteJob,
headersMapper: Mappers.DeleteJobsAddHeaders,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.DeleteJobsAddExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion, Parameters.timeoutInMinutes],
urlParameters: [Parameters.$host],
headerParameters: [Parameters.accept, Parameters.operationId],
serializer,
};
const listOperationSpec = {
path: "/jobs/deletions",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.DeleteJobCollection,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.DeleteJobsListExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host],
headerParameters: [Parameters.accept, Parameters.resultsPerPage],
serializer,
};
const getByIdOperationSpec = {
path: "/jobs/deletions/{id}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.DeleteJob,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.DeleteJobsGetByIdExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.id],
headerParameters: [Parameters.accept],
serializer,
};
const listNextOperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.DeleteJobCollection,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.DeleteJobsListNextExceptionHeaders,
},
},
urlParameters: [Parameters.$host, Parameters.nextLink],
headerParameters: [Parameters.accept, Parameters.resultsPerPage],
serializer,
};
//# sourceMappingURL=deleteJobs.js.map