@microsoft/kiota-serialization-multipart
Version:
Implementation of Kiota Serialization interfaces for multipart form data
116 lines • 5.54 kB
JavaScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/* eslint-disable @typescript-eslint/no-unused-expressions */
import { MultipartBody } from "@microsoft/kiota-abstractions";
/** Serialization writer for multipart/form-data */
export class MultipartSerializationWriter {
constructor() {
this.writer = new ArrayBuffer(0);
this.writeStringValue = (key, value) => {
if (key) {
this.writeRawStringValue(key);
}
if (value) {
if (key) {
this.writeRawStringValue(": ");
}
this.writeRawStringValue(value);
}
};
this.writeRawStringValue = (value) => {
if (value) {
this.writeByteArrayValue(undefined, new TextEncoder().encode(value).buffer);
}
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.writeBooleanValue = (key, value) => {
throw new Error(`serialization of boolean values is not supported with multipart`);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.writeNumberValue = (key, value) => {
throw new Error(`serialization of number values is not supported with multipart`);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.writeGuidValue = (key, value) => {
throw new Error(`serialization of guid values is not supported with multipart`);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.writeDateValue = (key, value) => {
throw new Error(`serialization of date values is not supported with multipart`);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.writeDateOnlyValue = (key, value) => {
throw new Error(`serialization of date only values is not supported with multipart`);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.writeTimeOnlyValue = (key, value) => {
throw new Error(`serialization of time only values is not supported with multipart`);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.writeDurationValue = (key, value) => {
throw new Error(`serialization of duration values is not supported with multipart`);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.writeNullValue = (key) => {
throw new Error(`serialization of null values is not supported with multipart`);
};
this.writeCollectionOfPrimitiveValues = (_key, _values) => {
throw new Error(`serialization of collections is not supported with multipart`);
};
this.writeCollectionOfObjectValues = (_key, _values) => {
throw new Error(`serialization of collections is not supported with multipart`);
};
this.writeObjectValue = (key, value, serializerMethod) => {
if (!value) {
throw new Error(`value cannot be undefined`);
}
if (!(value instanceof MultipartBody)) {
throw new Error(`expected MultipartBody instance`);
}
if (!serializerMethod) {
throw new Error(`serializer method cannot be undefined`);
}
this.onBeforeObjectSerialization && this.onBeforeObjectSerialization(value);
this.onStartObjectSerialization && this.onStartObjectSerialization(value, this);
serializerMethod(this, value);
this.onAfterObjectSerialization && this.onAfterObjectSerialization(value);
};
this.writeEnumValue = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
key,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
...values) => {
throw new Error(`serialization of enum values is not supported with multipart`);
};
this.writeCollectionOfEnumValues = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
key,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
values) => {
throw new Error(`serialization of collection of enum values is not supported with multipart`);
};
this.getSerializedContent = () => {
return this.writer;
};
this.writeAdditionalData = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
additionalData) => {
throw new Error(`serialization of additional data is not supported with multipart`);
};
}
writeByteArrayValue(key, value) {
if (!value) {
throw new Error("value cannot be undefined");
}
const previousValue = this.writer;
this.writer = new ArrayBuffer(previousValue.byteLength + value.byteLength);
const pipe = new Uint8Array(this.writer);
pipe.set(new Uint8Array(previousValue), 0);
pipe.set(new Uint8Array(value), previousValue.byteLength);
}
}
//# sourceMappingURL=multipartSerializationWriter.js.map