All files / src/lib remote.ts

100% Statements 67/67
100% Branches 16/16
100% Functions 13/13
100% Lines 67/67

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85    1x     1x 6x   1x 1x 1x 1x 1x 1x 1x   1x 1x 2x 2x 2x 2x 2x 1x 1x   1x 1x 1x 1x 1x   1x 1x 2x 2x 2x 1x 1x   1x 1x 1x 1x   1x 1x 2x 2x 1x 1x   1x 6x 6x 1x   1x   1x 4x 4x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x   1x 3x 3x 1x  
import { BlobFileSource, RemoteFileSource } from './types/args';
import { RemoteFileBuilderType, RemoteFileArrayBuilderType } from './types/builder';
import { buildFile, remoteFileSourceConverter } from './types/helper';
 
/* Remote Class */
export class RemoteFileArrayBuilder implements RemoteFileArrayBuilderType {
  private files: File[] = [];
 
  addBlob(blob: BlobFileSource): this {
    const object = new File([blob.blob], blob.name, {
      type: blob.mimeType,
    });
    this.files.push(object);
    return this;
  }
 
  addBlobs(blobs: BlobFileSource[]): this {
    for (const blob of blobs) {
      const object = new File([blob.blob], blob.name, {
        type: blob.mimeType,
      });
      this.files.push(object);
    }
    return this;
  }
 
  async addFile(file: RemoteFileSource): Promise<this> {
    const object = await remoteFileSourceConverter(file);
    this.files.push(object);
    return this;
  }
 
  async addFiles(files: RemoteFileSource[]): Promise<this> {
    for (const file of files) {
      const object = await remoteFileSourceConverter(file);
      this.files.push(object);
    }
    return this;
  }
 
  addFileObject(file: File): this {
    this.files.push(file);
    return this;
  }
 
  addFileObjects(files: Iterable<File>): this {
    for (const file of files) {
      this.files.push(file);
    }
    return this;
  }
 
  build(): File[] {
    return this.files;
  }
}
 
export class RemoteFileBuilder implements RemoteFileBuilderType {
  private file: File | undefined;
  constructor() {
    this.file = undefined;
  }
 
  addBlob(blob: BlobFileSource): this {
    this.file = new File([blob.blob], blob.name, {
      type: blob.mimeType,
    });
    return this;
  }
 
  async addFile(file: RemoteFileSource): Promise<this> {
    this.file = await remoteFileSourceConverter(file);
    return this;
  }
 
  addFileObject(file: File): this {
    this.file = file;
    return this;
  }
 
  build(): File {
    return buildFile(this.file);
  }
}