UNPKG

@itwin/core-common

Version:

iTwin.js components common to frontend and backend

52 lines 2.04 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module RpcInterface */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RpcMultipart = void 0; const core_bentley_1 = require("@itwin/core-bentley"); const IModelError_1 = require("../../IModelError"); /** Support for transporting RPC values using the HTTP multipart content type. * @internal */ class RpcMultipart { /** Creates a multipart form object for an RPC value. */ static createForm(value) { const form = new FormData(); RpcMultipart.writeValueToForm(form, value); return form; } /** Creates a multipart stream for an RPC value. */ static createStream(value) { return this.platform.createStream(value); } /** Obtains the RPC value from a multipart HTTP request. */ static async parseRequest(req) { return this.platform.parseRequest(req); } /** @internal */ static writeValueToForm(form, value) { form.append("objects", value.objects); for (let i = 0; i !== value.data.length; ++i) { this.platform.appendToForm(i, form, value); } } /** @internal */ static platform = { createStream(_value) { throw new IModelError_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Not bound."); }, async parseRequest(_req) { throw new IModelError_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Not bound."); }, appendToForm(i, form, value) { form.append(`data-${i}`, new Blob([value.data[i]], { type: "application/octet-stream" })); }, }; } exports.RpcMultipart = RpcMultipart; //# sourceMappingURL=RpcMultipart.js.map