@sprucelabs/spruce-file-utils 15.1.13 → 15.1.15

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.
@@ -1,7 +1,11 @@
1
1
  import { SpruceSchemas } from '@sprucelabs/mercury-types';
2
2
  import { SpruceUploaderImpl } from './uploading/SpruceUploader';
3
3
  export type Settings = SpruceSchemas.Files.v2022_05_13.Settings;
4
- export type UploadedFile = SpruceSchemas.Files.v2022_05_13.UploadedFile;
4
+ export interface UploadedFile {
5
+ id: string;
6
+ uri: string;
7
+ type: string;
8
+ }
5
9
  declare module '@sprucelabs/spruce-skill-utils/build/types/skill.types' {
6
10
  interface SkillContext {
7
11
  uploader: SpruceUploaderImpl;
@@ -5,10 +5,12 @@ export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingU
5
5
  static instance?: MockChunkingUploader;
6
6
  private lastUploadOptions?;
7
7
  private lastUploadResponse?;
8
+ private setNextUploadResponseOptions?;
8
9
  constructor();
9
10
  static assertWasCreated(): void;
10
11
  assertFileEqualsLastReturnedFromUpload(file: UploadedFile): void;
11
12
  assertUploadOptionsEqual(options: UploadOptions): void;
13
+ setNextUploadResponse(options: UploadedFile): void;
12
14
  upload(options: UploadOptions): Promise<{
13
15
  file: UploadedFile;
14
16
  }>;
@@ -27,15 +27,22 @@ export default class MockChunkingUploader extends AbstractEventEmitter {
27
27
  assertOptions(options, ['fileName', 'base64']);
28
28
  assert.isEqualDeep(options, this.lastUploadOptions, 'Upload options do not match the last upload options.');
29
29
  }
30
+ setNextUploadResponse(options) {
31
+ assertOptions(options, ['id', 'type', 'uri']);
32
+ this.setNextUploadResponseOptions = options;
33
+ }
30
34
  upload(options) {
31
35
  return __awaiter(this, void 0, void 0, function* () {
36
+ var _a;
32
37
  this.lastUploadOptions = options;
33
- this.lastUploadResponse = {
38
+ this.lastUploadResponse = (_a = this.setNextUploadResponseOptions) !== null && _a !== void 0 ? _a : {
34
39
  id: generateId(),
35
40
  type: generateId(),
36
41
  uri: generateId(),
37
42
  };
38
- return { file: this.lastUploadResponse };
43
+ return {
44
+ file: this.lastUploadResponse,
45
+ };
39
46
  });
40
47
  }
41
48
  }
@@ -1,7 +1,11 @@
1
1
  import { SpruceSchemas } from '@sprucelabs/mercury-types';
2
2
  import { SpruceUploaderImpl } from './uploading/SpruceUploader';
3
3
  export type Settings = SpruceSchemas.Files.v2022_05_13.Settings;
4
- export type UploadedFile = SpruceSchemas.Files.v2022_05_13.UploadedFile;
4
+ export interface UploadedFile {
5
+ id: string;
6
+ uri: string;
7
+ type: string;
8
+ }
5
9
  declare module '@sprucelabs/spruce-skill-utils/build/types/skill.types' {
6
10
  interface SkillContext {
7
11
  uploader: SpruceUploaderImpl;
@@ -5,10 +5,12 @@ export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingU
5
5
  static instance?: MockChunkingUploader;
6
6
  private lastUploadOptions?;
7
7
  private lastUploadResponse?;
8
+ private setNextUploadResponseOptions?;
8
9
  constructor();
9
10
  static assertWasCreated(): void;
10
11
  assertFileEqualsLastReturnedFromUpload(file: UploadedFile): void;
11
12
  assertUploadOptionsEqual(options: UploadOptions): void;
13
+ setNextUploadResponse(options: UploadedFile): void;
12
14
  upload(options: UploadOptions): Promise<{
13
15
  file: UploadedFile;
14
16
  }>;
@@ -20,14 +20,20 @@ class MockChunkingUploader extends mercury_event_emitter_1.AbstractEventEmitter
20
20
  (0, schema_1.assertOptions)(options, ['fileName', 'base64']);
21
21
  test_utils_1.assert.isEqualDeep(options, this.lastUploadOptions, 'Upload options do not match the last upload options.');
22
22
  }
23
+ setNextUploadResponse(options) {
24
+ (0, schema_1.assertOptions)(options, ['id', 'type', 'uri']);
25
+ this.setNextUploadResponseOptions = options;
26
+ }
23
27
  async upload(options) {
24
28
  this.lastUploadOptions = options;
25
- this.lastUploadResponse = {
29
+ this.lastUploadResponse = this.setNextUploadResponseOptions ?? {
26
30
  id: (0, test_utils_1.generateId)(),
27
31
  type: (0, test_utils_1.generateId)(),
28
32
  uri: (0, test_utils_1.generateId)(),
29
33
  };
30
- return { file: this.lastUploadResponse };
34
+ return {
35
+ file: this.lastUploadResponse,
36
+ };
31
37
  }
32
38
  }
33
39
  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.13",
4
+ "version": "15.1.15",
5
5
  "skill": {
6
6
  "namespace": "files"
7
7
  },
@@ -21,11 +21,6 @@
21
21
  "build/esm/files.types.d.ts",
22
22
  "build/files.types.js",
23
23
  "build/files.types.d.ts",
24
-
25
- "build/schemas/v2022_05_13/uploadedFile.builder.d.ts",
26
- "build/schemas/v2022_05_13/uploadedFile.builder.js",
27
- "build/esm/schemas/v2022_05_13/uploadedFile.builder.d.ts",
28
- "build/esm/schemas/v2022_05_13/uploadedFile.builder.js",
29
24
 
30
25
  "build/esm/index-module.js",
31
26
  "build/esm/index-module.d.ts",
@@ -45,7 +40,6 @@
45
40
  "build/uploading/MockChunkingUploader.d.ts",
46
41
  "build/uploading/MockChunkingUploader.js",
47
42
 
48
-
49
43
  "build/esm/errors/SpruceError.d.ts",
50
44
  "build/esm/errors/SpruceError.js",
51
45
  "build/errors/SpruceError.d.ts",
@@ -1,19 +0,0 @@
1
- declare const _default: {
2
- id: string;
3
- name: string;
4
- fields: {
5
- id: {
6
- type: "id";
7
- isRequired: true;
8
- };
9
- uri: {
10
- type: "text";
11
- isRequired: true;
12
- };
13
- type: {
14
- type: "text";
15
- isRequired: true;
16
- };
17
- };
18
- };
19
- export default _default;
@@ -1,19 +0,0 @@
1
- import { buildSchema } from '@sprucelabs/schema';
2
- export default buildSchema({
3
- id: 'uploadedFile',
4
- name: 'Uploaded file',
5
- fields: {
6
- id: {
7
- type: 'id',
8
- isRequired: true,
9
- },
10
- uri: {
11
- type: 'text',
12
- isRequired: true,
13
- },
14
- type: {
15
- type: 'text',
16
- isRequired: true,
17
- },
18
- },
19
- });
@@ -1,19 +0,0 @@
1
- declare const _default: {
2
- id: string;
3
- name: string;
4
- fields: {
5
- id: {
6
- type: "id";
7
- isRequired: true;
8
- };
9
- uri: {
10
- type: "text";
11
- isRequired: true;
12
- };
13
- type: {
14
- type: "text";
15
- isRequired: true;
16
- };
17
- };
18
- };
19
- export default _default;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const schema_1 = require("@sprucelabs/schema");
4
- exports.default = (0, schema_1.buildSchema)({
5
- id: 'uploadedFile',
6
- name: 'Uploaded file',
7
- fields: {
8
- id: {
9
- type: 'id',
10
- isRequired: true,
11
- },
12
- uri: {
13
- type: 'text',
14
- isRequired: true,
15
- },
16
- type: {
17
- type: 'text',
18
- isRequired: true,
19
- },
20
- },
21
- });