@azure/digital-twins-core
Version:
An isomorphic client library for Azure Digital Twins
260 lines • 9.31 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 ImportJobs operations. */
export class ImportJobsImpl {
/**
* Initialize a new instance of the class ImportJobs class.
* @param client Reference to the service client
*/
constructor(client) {
this.client = client;
}
/**
* Retrieves all import jobs.
* 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 import jobs.
* Status codes:
* * 200 OK
* @param options The options parameters.
*/
_list(options) {
return this.client.sendOperationRequest({ options }, listOperationSpec);
}
/**
* Creates an import job.
* Status codes:
* * 201 Created
* * 400 Bad Request
* * JobLimitReached - The maximum number of import jobs allowed has been reached.
* * ValidationFailed - The import job request is not valid.
* @param id The id for the import job. The id is unique within the service and case sensitive.
* @param importJob The import job being added.
* @param options The options parameters.
*/
add(id, importJob, options) {
return this.client.sendOperationRequest({ id, importJob, options }, addOperationSpec);
}
/**
* Retrieves an import job.
* Status codes:
* * 200 OK
* * 404 Not Found
* * ImportJobNotFound - The import job was not found.
* @param id The id for the import 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);
}
/**
* Deletes an import job. This is simply used to remove a job id, so it may be reused later. It can not
* be used to stop entities from being imported.
* Status codes:
* * 204 No Content
* * 400 Bad Request
* * ValidationFailed - The import job request is not valid.
* @param id The id for the import job. The id is unique within the service and case sensitive.
* @param options The options parameters.
*/
delete(id, options) {
return this.client.sendOperationRequest({ id, options }, deleteOperationSpec);
}
/**
* Cancels an import job that is currently running. Service will stop any import operations triggered
* by the current import job that are in progress, and go to a cancelled state. Please note that this
* will leave your instance in an unknown state as there won't be any rollback operation.
* Status codes:
* * 200 Request Accepted
* * 400 Bad Request
* * ValidationFailed - The import job request is not valid.
* @param id The id for the import job. The id is unique within the service and case sensitive.
* @param options The options parameters.
*/
cancel(id, options) {
return this.client.sendOperationRequest({ id, options }, cancelOperationSpec);
}
/**
* 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: "/jobs/imports",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ImportJobCollection,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.ImportJobsListExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host],
headerParameters: [Parameters.accept, Parameters.resultsPerPage],
serializer,
};
const addOperationSpec = {
path: "/jobs/imports/{id}",
httpMethod: "PUT",
responses: {
201: {
bodyMapper: Mappers.ImportJob,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.ImportJobsAddExceptionHeaders,
},
},
requestBody: Parameters.importJob,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.id],
headerParameters: [Parameters.contentType, Parameters.accept],
mediaType: "json",
serializer,
};
const getByIdOperationSpec = {
path: "/jobs/imports/{id}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ImportJob,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.ImportJobsGetByIdExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.id],
headerParameters: [Parameters.accept],
serializer,
};
const deleteOperationSpec = {
path: "/jobs/imports/{id}",
httpMethod: "DELETE",
responses: {
204: {},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.ImportJobsDeleteExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.id],
headerParameters: [Parameters.accept],
serializer,
};
const cancelOperationSpec = {
path: "/jobs/imports/{id}/cancel",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.ImportJob,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.ImportJobsCancelExceptionHeaders,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.id],
headerParameters: [Parameters.accept],
serializer,
};
const listNextOperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ImportJobCollection,
},
default: {
bodyMapper: Mappers.ErrorResponse,
headersMapper: Mappers.ImportJobsListNextExceptionHeaders,
},
},
urlParameters: [Parameters.$host, Parameters.nextLink],
headerParameters: [Parameters.accept, Parameters.resultsPerPage],
serializer,
};
//# sourceMappingURL=importJobs.js.map