@sprucelabs/spruce-file-utils 15.1.4 → 15.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,3 +2,4 @@ export { default as FileUploaderImpl } from './uploading/FileUploader';
2
2
  export * from './uploading/FileUploader';
3
3
  export { default as ChunkingUploaderImpl } from './uploading/ChunkingUploader';
4
4
  export * from './uploading/ChunkingUploader';
5
+ export { default as MockChunkingUploader } from './uploading/MockChunkingUploader';
@@ -2,3 +2,4 @@ export { default as FileUploaderImpl } from './uploading/FileUploader.js';
2
2
  export * from './uploading/FileUploader.js';
3
3
  export { default as ChunkingUploaderImpl } from './uploading/ChunkingUploader.js';
4
4
  export * from './uploading/ChunkingUploader.js';
5
+ export { default as MockChunkingUploader } from './uploading/MockChunkingUploader.js';
@@ -30,7 +30,7 @@ export interface ChunkingUploader extends MercuryEventEmitter<ChunkingUploaderEv
30
30
  file: UploadedFile;
31
31
  }>;
32
32
  }
33
- declare const chunkingUploaderEventContract: {
33
+ export declare const chunkingUploaderEventContract: {
34
34
  eventSignatures: {
35
35
  'did-upload-chunk': {
36
36
  emitPayloadSchema: {
@@ -45,11 +45,10 @@ declare const chunkingUploaderEventContract: {
45
45
  };
46
46
  };
47
47
  };
48
- type ChunkingUploaderEventContract = typeof chunkingUploaderEventContract;
48
+ export type ChunkingUploaderEventContract = typeof chunkingUploaderEventContract;
49
49
  export interface UploadOptions {
50
50
  fileName: string;
51
51
  base64: string;
52
52
  locationId?: string;
53
53
  organizationId?: string;
54
54
  }
55
- export {};
@@ -145,7 +145,7 @@ class ChunkingUploaderImpl extends AbstractEventEmitter {
145
145
  ChunkingUploaderImpl.fetch = fetch;
146
146
  ChunkingUploaderImpl.chunkSizeKb = 1024;
147
147
  export default ChunkingUploaderImpl;
148
- const chunkingUploaderEventContract = buildEventContract({
148
+ export const chunkingUploaderEventContract = buildEventContract({
149
149
  eventSignatures: {
150
150
  'did-upload-chunk': {
151
151
  emitPayloadSchema: buildSchema({
@@ -2,3 +2,4 @@ export { default as FileUploaderImpl } from './uploading/FileUploader';
2
2
  export * from './uploading/FileUploader';
3
3
  export { default as ChunkingUploaderImpl } from './uploading/ChunkingUploader';
4
4
  export * from './uploading/ChunkingUploader';
5
+ export { default as MockChunkingUploader } from './uploading/MockChunkingUploader';
@@ -17,10 +17,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.ChunkingUploaderImpl = exports.FileUploaderImpl = void 0;
20
+ exports.MockChunkingUploader = exports.ChunkingUploaderImpl = exports.FileUploaderImpl = void 0;
21
21
  var FileUploader_1 = require("./uploading/FileUploader");
22
22
  Object.defineProperty(exports, "FileUploaderImpl", { enumerable: true, get: function () { return __importDefault(FileUploader_1).default; } });
23
23
  __exportStar(require("./uploading/FileUploader"), exports);
24
24
  var ChunkingUploader_1 = require("./uploading/ChunkingUploader");
25
25
  Object.defineProperty(exports, "ChunkingUploaderImpl", { enumerable: true, get: function () { return __importDefault(ChunkingUploader_1).default; } });
26
26
  __exportStar(require("./uploading/ChunkingUploader"), exports);
27
+ var MockChunkingUploader_1 = require("./uploading/MockChunkingUploader");
28
+ Object.defineProperty(exports, "MockChunkingUploader", { enumerable: true, get: function () { return __importDefault(MockChunkingUploader_1).default; } });
@@ -30,7 +30,7 @@ export interface ChunkingUploader extends MercuryEventEmitter<ChunkingUploaderEv
30
30
  file: UploadedFile;
31
31
  }>;
32
32
  }
33
- declare const chunkingUploaderEventContract: {
33
+ export declare const chunkingUploaderEventContract: {
34
34
  eventSignatures: {
35
35
  'did-upload-chunk': {
36
36
  emitPayloadSchema: {
@@ -45,11 +45,10 @@ declare const chunkingUploaderEventContract: {
45
45
  };
46
46
  };
47
47
  };
48
- type ChunkingUploaderEventContract = typeof chunkingUploaderEventContract;
48
+ export type ChunkingUploaderEventContract = typeof chunkingUploaderEventContract;
49
49
  export interface UploadOptions {
50
50
  fileName: string;
51
51
  base64: string;
52
52
  locationId?: string;
53
53
  organizationId?: string;
54
54
  }
55
- export {};
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.chunkingUploaderEventContract = void 0;
6
7
  const mercury_event_emitter_1 = require("@sprucelabs/mercury-event-emitter");
7
8
  const mercury_types_1 = require("@sprucelabs/mercury-types");
8
9
  const schema_1 = require("@sprucelabs/schema");
9
10
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
10
11
  class ChunkingUploaderImpl extends mercury_event_emitter_1.AbstractEventEmitter {
11
12
  constructor(connectToApi) {
12
- super(chunkingUploaderEventContract);
13
+ super(exports.chunkingUploaderEventContract);
13
14
  this.connectToApi = connectToApi;
14
15
  }
15
16
  static Uploader(connectToApi) {
@@ -131,7 +132,7 @@ class ChunkingUploaderImpl extends mercury_event_emitter_1.AbstractEventEmitter
131
132
  ChunkingUploaderImpl.fetch = fetch;
132
133
  ChunkingUploaderImpl.chunkSizeKb = 1024;
133
134
  exports.default = ChunkingUploaderImpl;
134
- const chunkingUploaderEventContract = (0, mercury_types_1.buildEventContract)({
135
+ exports.chunkingUploaderEventContract = (0, mercury_types_1.buildEventContract)({
135
136
  eventSignatures: {
136
137
  'did-upload-chunk': {
137
138
  emitPayloadSchema: (0, schema_1.buildSchema)({
@@ -0,0 +1,15 @@
1
+ import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
2
+ import { UploadedFile } from '../files.types';
3
+ import { ChunkingUploader, ChunkingUploaderEventContract, UploadOptions } from './ChunkingUploader';
4
+ export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingUploaderEventContract> implements ChunkingUploader {
5
+ static instance?: MockChunkingUploader;
6
+ private lastUploadOptions?;
7
+ private lastUploadResponse?;
8
+ constructor();
9
+ static assertWasCreated(): void;
10
+ assertFileEqualsLastReturnedFromUpload(file: UploadedFile): void;
11
+ assertUploadOptionsEqual(options: UploadOptions): void;
12
+ upload(options: UploadOptions): Promise<{
13
+ file: UploadedFile;
14
+ }>;
15
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mercury_event_emitter_1 = require("@sprucelabs/mercury-event-emitter");
4
+ const schema_1 = require("@sprucelabs/schema");
5
+ const test_utils_1 = require("@sprucelabs/test-utils");
6
+ const ChunkingUploader_1 = require("./ChunkingUploader");
7
+ class MockChunkingUploader extends mercury_event_emitter_1.AbstractEventEmitter {
8
+ constructor() {
9
+ super(ChunkingUploader_1.chunkingUploaderEventContract);
10
+ MockChunkingUploader.instance = this;
11
+ }
12
+ static assertWasCreated() {
13
+ test_utils_1.assert.isTruthy(MockChunkingUploader.instance, 'You need to intantiate ChunkingUploaderImpl.Uploader(this.connectApi).');
14
+ }
15
+ assertFileEqualsLastReturnedFromUpload(file) {
16
+ (0, schema_1.assertOptions)({ file }, ['file']);
17
+ test_utils_1.assert.isEqualDeep(file, this.lastUploadResponse, 'Files do not match');
18
+ }
19
+ assertUploadOptionsEqual(options) {
20
+ (0, schema_1.assertOptions)(options, ['fileName', 'base64']);
21
+ test_utils_1.assert.isEqualDeep(options, this.lastUploadOptions, 'Upload options do not match the last upload options.');
22
+ }
23
+ async upload(options) {
24
+ this.lastUploadOptions = options;
25
+ this.lastUploadResponse = {
26
+ id: (0, test_utils_1.generateId)(),
27
+ type: (0, test_utils_1.generateId)(),
28
+ uri: (0, test_utils_1.generateId)(),
29
+ };
30
+ return { file: this.lastUploadResponse };
31
+ }
32
+ }
33
+ exports.default = MockChunkingUploader;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-file-utils",
3
3
  "description": "Utils for working with files and Sprucebot.",
4
- "version": "15.1.4",
4
+ "version": "15.1.6",
5
5
  "skill": {
6
6
  "namespace": "files"
7
7
  },
@@ -29,6 +29,8 @@
29
29
  "build/esm/uploading/ChunkingUploader.js",
30
30
  "build/uploading/ChunkingUploader.d.ts",
31
31
  "build/uploading/ChunkingUploader.js",
32
+ "build/uploading/MockChunkingUploader.d.ts",
33
+ "build/uploading/MockChunkingUploader.js",
32
34
 
33
35
  "build/esm/uploading/LocalUploadStrategy.d.ts",
34
36
  "build/esm/uploading/LocalUploadStrategy.js",