From 0fa7cd2a39d2121162d0f8c0a18f09a0be2967a4 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Wed, 16 Oct 2024 19:03:04 +0300 Subject: [PATCH] fix code format --- .../src/multipartSerializationWriter.ts | 251 ++++++++---------- 1 file changed, 109 insertions(+), 142 deletions(-) diff --git a/packages/serialization/multipart/src/multipartSerializationWriter.ts b/packages/serialization/multipart/src/multipartSerializationWriter.ts index 5d32900c9..50b72f727 100644 --- a/packages/serialization/multipart/src/multipartSerializationWriter.ts +++ b/packages/serialization/multipart/src/multipartSerializationWriter.ts @@ -11,148 +11,115 @@ import type { Guid } from "guid-typescript"; /** Serialization writer for multipart/form-data */ export class MultipartSerializationWriter implements SerializationWriter { - public writeByteArrayValue( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - key?: string | undefined, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - value?: ArrayBuffer | undefined, - ): void { - 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); - } - private writer: ArrayBuffer = new ArrayBuffer(0); - public onBeforeObjectSerialization: ((value: Parsable) => void) | undefined; - public onAfterObjectSerialization: ((value: Parsable) => void) | undefined; - public onStartObjectSerialization: - | ((value: Parsable, writer: SerializationWriter) => void) - | undefined; - public writeStringValue = (key?: string, value?: string): void => { - if (key) { - this.writeRawStringValue(key); - } - if (value) { - if (key) { - this.writeRawStringValue(": "); - } - this.writeRawStringValue(value); - } - }; - private writeRawStringValue = (value?: string): void => { - if (value) { - this.writeByteArrayValue( - undefined, - new TextEncoder().encode(value).buffer, - ); - } - }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public writeBooleanValue = (key?: string, value?: boolean): void => { - throw new Error( - `serialization of boolean values is not supported with multipart`, - ); - }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public writeNumberValue = (key?: string, value?: number): void => { - throw new Error( - `serialization of number values is not supported with multipart`, - ); - }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public writeGuidValue = (key?: string, value?: Guid): void => { - throw new Error( - `serialization of guid values is not supported with multipart`, - ); - }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public writeDateValue = (key?: string, value?: Date): void => { - throw new Error( - `serialization of date values is not supported with multipart`, - ); - }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public writeDateOnlyValue = (key?: string, value?: DateOnly): void => { - throw new Error( - `serialization of date only values is not supported with multipart`, - ); - }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public writeTimeOnlyValue = (key?: string, value?: TimeOnly): void => { - throw new Error( - `serialization of time only values is not supported with multipart`, - ); - }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public writeDurationValue = (key?: string, value?: Duration): void => { - throw new Error( - `serialization of duration values is not supported with multipart`, - ); - }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public writeNullValue = (key?: string): void => { - throw new Error( - `serialization of null values is not supported with multipart`, - ); - }; - public writeCollectionOfPrimitiveValues = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _key?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _values?: T[], - ): void => { - throw new Error( - `serialization of collections is not supported with multipart`, - ); - }; - public writeCollectionOfObjectValues = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _key?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _values?: T[], - ): void => { - throw new Error( - `serialization of collections is not supported with multipart`, - ); - }; - public writeObjectValue = ( - key: string | undefined, - value: T | undefined, - serializerMethod: ModelSerializerFunction, - ): void => { - 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); - }; - public writeEnumValue = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - key?: string | undefined, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - ...values: (T | undefined)[] - ): void => { - throw new Error( - `serialization of enum values is not supported with multipart`, - ); - }; - public getSerializedContent = (): ArrayBuffer => { - return this.writer; - }; - + public writeByteArrayValue( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + key?: string | undefined, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + value?: ArrayBuffer | undefined, + ): void { + 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); + } + private writer: ArrayBuffer = new ArrayBuffer(0); + public onBeforeObjectSerialization: ((value: Parsable) => void) | undefined; + public onAfterObjectSerialization: ((value: Parsable) => void) | undefined; + public onStartObjectSerialization: ((value: Parsable, writer: SerializationWriter) => void) | undefined; + public writeStringValue = (key?: string, value?: string): void => { + if (key) { + this.writeRawStringValue(key); + } + if (value) { + if (key) { + this.writeRawStringValue(": "); + } + this.writeRawStringValue(value); + } + }; + private writeRawStringValue = (value?: string): void => { + if (value) { + this.writeByteArrayValue(undefined, new TextEncoder().encode(value).buffer); + } + }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeBooleanValue = (key?: string, value?: boolean): void => { + throw new Error(`serialization of boolean values is not supported with multipart`); + }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeNumberValue = (key?: string, value?: number): void => { + throw new Error(`serialization of number values is not supported with multipart`); + }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeGuidValue = (key?: string, value?: Guid): void => { + throw new Error(`serialization of guid values is not supported with multipart`); + }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeDateValue = (key?: string, value?: Date): void => { + throw new Error(`serialization of date values is not supported with multipart`); + }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeDateOnlyValue = (key?: string, value?: DateOnly): void => { + throw new Error(`serialization of date only values is not supported with multipart`); + }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeTimeOnlyValue = (key?: string, value?: TimeOnly): void => { + throw new Error(`serialization of time only values is not supported with multipart`); + }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeDurationValue = (key?: string, value?: Duration): void => { + throw new Error(`serialization of duration values is not supported with multipart`); + }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeNullValue = (key?: string): void => { + throw new Error(`serialization of null values is not supported with multipart`); + }; + public writeCollectionOfPrimitiveValues = ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + _key?: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + _values?: T[], + ): void => { + throw new Error(`serialization of collections is not supported with multipart`); + }; + public writeCollectionOfObjectValues = ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + _key?: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + _values?: T[], + ): void => { + throw new Error(`serialization of collections is not supported with multipart`); + }; + public writeObjectValue = (key: string | undefined, value: T | undefined, serializerMethod: ModelSerializerFunction): void => { + 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); + }; + public writeEnumValue = ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + key?: string | undefined, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + ...values: (T | undefined)[] + ): void => { + throw new Error(`serialization of enum values is not supported with multipart`); + }; + public getSerializedContent = (): ArrayBuffer => { + return this.writer; + }; public writeAdditionalData = ( // eslint-disable-next-line @typescript-eslint/no-unused-vars