UNPKG

@azure/digital-twins-core

Version:
297 lines 11 kB
/* * 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 DigitalTwinModels operations. */ export class DigitalTwinModelsImpl { /** * Initialize a new instance of the class DigitalTwinModels class. * @param client Reference to the service client */ constructor(client) { this.client = client; } /** * Retrieves model metadata and, optionally, model definitions. * Status codes: * * 200 OK * * 400 Bad Request * * InvalidArgument - The model id is invalid. * * LimitExceeded - The maximum number of model ids allowed in 'dependenciesFor' has been reached. * * 404 Not Found * * ModelNotFound - The model was not found. * @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; } } }); } /** * Uploads one or more models. When any error occurs, no models are uploaded. * Status codes: * * 201 Created * * 400 Bad Request * * DTDLParserError - The models provided are not valid DTDL. * * InvalidArgument - The model id is invalid. * * LimitExceeded - The maximum number of model ids allowed in 'dependenciesFor' has been reached. * * ModelVersionNotSupported - The version of DTDL used is not supported. * * 409 Conflict * * ModelAlreadyExists - The model provided already exists. * @param models An array of models to add. * @param options The options parameters. */ add(models, options) { return this.client.sendOperationRequest({ models, options }, addOperationSpec); } /** * Retrieves model metadata and, optionally, model definitions. * Status codes: * * 200 OK * * 400 Bad Request * * InvalidArgument - The model id is invalid. * * LimitExceeded - The maximum number of model ids allowed in 'dependenciesFor' has been reached. * * 404 Not Found * * ModelNotFound - The model was not found. * @param options The options parameters. */ _list(options) { return this.client.sendOperationRequest({ options }, listOperationSpec); } /** * Retrieves model metadata and optionally the model definition. * Status codes: * * 200 OK * * 400 Bad Request * * InvalidArgument - The model id is invalid. * * MissingArgument - The model id was not provided. * * 404 Not Found * * ModelNotFound - The model was not found. * @param id The id for the model. The id is globally unique and case sensitive. * @param options The options parameters. */ getById(id, options) { return this.client.sendOperationRequest({ id, options }, getByIdOperationSpec); } /** * Updates the metadata for a model. * Status codes: * * 204 No Content * * 400 Bad Request * * InvalidArgument - The model id is invalid. * * JsonPatchInvalid - The JSON Patch provided is invalid. * * MissingArgument - The model id was not provided. * * 404 Not Found * * ModelNotFound - The model was not found. * * 409 Conflict * * ModelReferencesNotDecommissioned - The model refers to models that are not decommissioned. * @param id The id for the model. The id is globally unique and case sensitive. * @param updateModel An update specification described by JSON Patch. Only the decommissioned property * can be replaced. * @param options The options parameters. */ update(id, updateModel, options) { return this.client.sendOperationRequest({ id, updateModel, options }, updateOperationSpec); } /** * Deletes a model. A model can only be deleted if no other models reference it. * Status codes: * * 204 No Content * * 400 Bad Request * * InvalidArgument - The model id is invalid. * * MissingArgument - The model id was not provided. * * 404 Not Found * * ModelNotFound - The model was not found. * * 409 Conflict * * ModelReferencesNotDeleted - The model refers to models that are not deleted. * @param id The id for the model. The id is globally unique 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 addOperationSpec = { path: "/models", httpMethod: "POST", responses: { 201: { bodyMapper: { type: { name: "Sequence", element: { type: { name: "Composite", className: "DigitalTwinsModelData" }, }, }, }, }, default: { bodyMapper: Mappers.ErrorResponse, headersMapper: Mappers.DigitalTwinModelsAddExceptionHeaders, }, }, requestBody: Parameters.models, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.$host], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer, }; const listOperationSpec = { path: "/models", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.PagedDigitalTwinsModelDataCollection, }, default: { bodyMapper: Mappers.ErrorResponse, headersMapper: Mappers.DigitalTwinModelsListExceptionHeaders, }, }, queryParameters: [ Parameters.apiVersion, Parameters.dependenciesFor, Parameters.includeModelDefinition, ], urlParameters: [Parameters.$host], headerParameters: [Parameters.accept, Parameters.resultsPerPage], serializer, }; const getByIdOperationSpec = { path: "/models/{id}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DigitalTwinsModelData, }, default: { bodyMapper: Mappers.ErrorResponse, headersMapper: Mappers.DigitalTwinModelsGetByIdExceptionHeaders, }, }, queryParameters: [Parameters.apiVersion, Parameters.includeModelDefinition], urlParameters: [Parameters.$host, Parameters.id], headerParameters: [Parameters.accept], serializer, }; const updateOperationSpec = { path: "/models/{id}", httpMethod: "PATCH", responses: { 204: {}, default: { bodyMapper: Mappers.ErrorResponse, headersMapper: Mappers.DigitalTwinModelsUpdateExceptionHeaders, }, }, requestBody: Parameters.updateModel, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.$host, Parameters.id], headerParameters: [Parameters.accept, Parameters.contentType1], mediaType: "json", serializer, }; const deleteOperationSpec = { path: "/models/{id}", httpMethod: "DELETE", responses: { 204: {}, default: { bodyMapper: Mappers.ErrorResponse, headersMapper: Mappers.DigitalTwinModelsDeleteExceptionHeaders, }, }, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.$host, Parameters.id], headerParameters: [Parameters.accept], serializer, }; const listNextOperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.PagedDigitalTwinsModelDataCollection, }, default: { bodyMapper: Mappers.ErrorResponse, headersMapper: Mappers.DigitalTwinModelsListNextExceptionHeaders, }, }, urlParameters: [Parameters.$host, Parameters.nextLink], headerParameters: [Parameters.accept, Parameters.resultsPerPage], serializer, }; //# sourceMappingURL=digitalTwinModels.js.map