@trayio/commons 4.47.0 → 4.48.0
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.
- package/dist/file/FakeFileStorage.d.ts.map +1 -1
- package/dist/file/FakeFileStorage.js +6 -3
- package/dist/file/File.d.ts +10 -8
- package/dist/file/File.d.ts.map +1 -1
- package/dist/file/File.js +23 -10
- package/dist/file/FileStorage.abstract.test.d.ts.map +1 -1
- package/dist/file/FileStorage.abstract.test.js +8 -5
- package/dist/file/NodeFsFileStorage.d.ts.map +1 -1
- package/dist/file/NodeFsFileStorage.integration.test.js +12 -6
- package/dist/file/NodeFsFileStorage.js +8 -2
- package/dist/http/Http.d.ts.map +1 -1
- package/dist/http/Http.js +4 -4
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
- package/dist/http/HttpClient.abstract.test.js +30 -17
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/FakeFileStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIvC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEtD,qBAAa,eAAgB,YAAW,WAAW;IAClD,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;IAMzB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAY7C,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAkBlD,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAYzD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAI1D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"FakeFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/FakeFileStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIvC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEtD,qBAAa,eAAgB,YAAW,WAAW;IAClD,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;IAMzB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAY7C,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAkBlD,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAYzD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAI1D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;CAmB7D"}
|
|
@@ -34,7 +34,7 @@ class FakeFileStorage {
|
|
|
34
34
|
this.files = new Map();
|
|
35
35
|
}
|
|
36
36
|
write(file) {
|
|
37
|
-
return (0, function_1.pipe)(TE.fromEither(E.tryCatch(() => this.files.set(file.key, file), (error) => new Error(error))), TE.map(() => file));
|
|
37
|
+
return (0, function_1.pipe)(TE.fromEither(E.tryCatch(() => this.files.set(file.reference.key, file), (error) => new Error(error))), TE.map(() => file));
|
|
38
38
|
}
|
|
39
39
|
read(fileName) {
|
|
40
40
|
return (0, function_1.pipe)(TE.fromEither(E.tryCatch(() => this.files.get(fileName), (error) => new Error(error))), TE.chain((file) => {
|
|
@@ -52,8 +52,11 @@ class FakeFileStorage {
|
|
|
52
52
|
}
|
|
53
53
|
createDirectory(key) {
|
|
54
54
|
return (0, function_1.pipe)(TE.fromEither(E.tryCatch(() => this.files.set(key, {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
reference: {
|
|
56
|
+
_tag: 'FileDescriptor',
|
|
57
|
+
key,
|
|
58
|
+
metadata: { name: key },
|
|
59
|
+
},
|
|
57
60
|
content: stream_1.Readable.from(''),
|
|
58
61
|
}), (error) => new Error(error))), TE.map(() => undefined));
|
|
59
62
|
}
|
package/dist/file/File.d.ts
CHANGED
|
@@ -5,24 +5,26 @@ import * as t from 'io-ts';
|
|
|
5
5
|
import { Option } from 'fp-ts/lib/Option';
|
|
6
6
|
import { DynamicObject } from '../dynamictype/DynamicType';
|
|
7
7
|
export type FileMetadata = {
|
|
8
|
+
name: string;
|
|
8
9
|
size?: number;
|
|
9
10
|
contentType?: string;
|
|
10
11
|
};
|
|
11
12
|
export declare const fileMetadataDescriptor: t.Type<FileMetadata, unknown>;
|
|
13
|
+
export declare const fileDescriptorDescriptor: t.Type<FileDescriptor, unknown>;
|
|
12
14
|
export type File = {
|
|
13
|
-
|
|
14
|
-
metadata: FileMetadata;
|
|
15
|
+
reference: FileDescriptor;
|
|
15
16
|
content: Readable;
|
|
16
17
|
};
|
|
17
|
-
export type
|
|
18
|
-
_tag: '
|
|
18
|
+
export type FileDescriptor = {
|
|
19
|
+
_tag: 'FileDescriptor';
|
|
19
20
|
key: string;
|
|
21
|
+
metadata: FileMetadata;
|
|
20
22
|
};
|
|
21
|
-
export interface
|
|
22
|
-
|
|
23
|
-
fromFile(file: File):
|
|
23
|
+
export interface FileDescriptorInterface {
|
|
24
|
+
isFileDescriptor(value: unknown): value is FileDescriptor;
|
|
25
|
+
fromFile(file: File): FileDescriptor;
|
|
24
26
|
}
|
|
25
|
-
export declare const
|
|
27
|
+
export declare const FileDescriptor: FileDescriptorInterface;
|
|
26
28
|
export type SharedUrl = {
|
|
27
29
|
url: string;
|
|
28
30
|
expires?: number;
|
package/dist/file/File.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../src/file/File.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AACF,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../src/file/File.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AACF,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAS9D,CAAC;AAEJ,eAAO,M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
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.FileDescriptor = exports.fileDescriptorDescriptor = exports.fileMetadataDescriptor = void 0;
|
|
27
27
|
const t = __importStar(require("io-ts"));
|
|
28
|
-
exports.fileMetadataDescriptor = t.
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
exports.fileMetadataDescriptor = t.intersection([
|
|
29
|
+
t.type({
|
|
30
|
+
name: t.string,
|
|
31
|
+
}),
|
|
32
|
+
t.partial({
|
|
33
|
+
size: t.number,
|
|
34
|
+
contentType: t.string,
|
|
35
|
+
}),
|
|
36
|
+
]);
|
|
37
|
+
exports.fileDescriptorDescriptor = t.type({
|
|
38
|
+
_tag: t.literal('FileDescriptor'),
|
|
39
|
+
key: t.string,
|
|
40
|
+
metadata: exports.fileMetadataDescriptor,
|
|
31
41
|
});
|
|
32
|
-
exports.
|
|
33
|
-
|
|
42
|
+
exports.FileDescriptor = {
|
|
43
|
+
isFileDescriptor(value) {
|
|
34
44
|
return (typeof value === 'object' &&
|
|
35
45
|
value !== null &&
|
|
36
46
|
'_tag' in value &&
|
|
37
|
-
value._tag === '
|
|
47
|
+
value._tag === 'FileDescriptor' &&
|
|
38
48
|
'key' in value &&
|
|
39
|
-
typeof value.key === 'string'
|
|
49
|
+
typeof value.key === 'string' &&
|
|
50
|
+
'metadata' in value &&
|
|
51
|
+
exports.fileMetadataDescriptor.is(value.metadata));
|
|
40
52
|
},
|
|
41
53
|
fromFile(file) {
|
|
42
54
|
return {
|
|
43
|
-
_tag: '
|
|
44
|
-
key: file.key,
|
|
55
|
+
_tag: 'FileDescriptor',
|
|
56
|
+
key: file.reference.key,
|
|
57
|
+
metadata: file.reference.metadata,
|
|
45
58
|
};
|
|
46
59
|
},
|
|
47
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileStorage.abstract.test.d.ts","sourceRoot":"","sources":["../../src/file/FileStorage.abstract.test.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAQ,MAAM,QAAQ,CAAC;AAE3C,eAAO,MAAM,eAAe,gBAAiB,WAAW,
|
|
1
|
+
{"version":3,"file":"FileStorage.abstract.test.d.ts","sourceRoot":"","sources":["../../src/file/FileStorage.abstract.test.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAQ,MAAM,QAAQ,CAAC;AAE3C,eAAO,MAAM,eAAe,gBAAiB,WAAW,SA6FvD,CAAC"}
|
|
@@ -44,13 +44,16 @@ const fileStorageTest = (fileStorage) => {
|
|
|
44
44
|
});
|
|
45
45
|
const fileName = `test-${(0, uuid_1.v4)()}.json`;
|
|
46
46
|
const file = {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
reference: {
|
|
48
|
+
_tag: 'FileDescriptor',
|
|
49
|
+
key: fileName,
|
|
50
|
+
metadata: { name: fileName },
|
|
51
|
+
},
|
|
49
52
|
content: readableStream,
|
|
50
53
|
};
|
|
51
54
|
const writtenFile = await fileStorage.write(file, O.none)();
|
|
52
55
|
expect(writtenFile).toEqual(E.right(file));
|
|
53
|
-
const sharedUrl = await fileStorage.getSharedUrl(file.key)();
|
|
56
|
+
const sharedUrl = await fileStorage.getSharedUrl(file.reference.key)();
|
|
54
57
|
expect(sharedUrl).toEqual(E.right(expect.objectContaining({
|
|
55
58
|
url: expect.any(String),
|
|
56
59
|
})));
|
|
@@ -59,7 +62,7 @@ const fileStorageTest = (fileStorage) => {
|
|
|
59
62
|
expect(sharedUrl.right.expires).toEqual(expect.any(Number));
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
|
-
const read = await fileStorage.read(file.key)();
|
|
65
|
+
const read = await fileStorage.read(file.reference.key)();
|
|
63
66
|
const readResponse = E.getOrElse(() => {
|
|
64
67
|
throw new Error('Expected right');
|
|
65
68
|
})(read);
|
|
@@ -77,7 +80,7 @@ const fileStorageTest = (fileStorage) => {
|
|
|
77
80
|
throw new Error('failed to deserialise stream contents');
|
|
78
81
|
}
|
|
79
82
|
expect(deserializedData.right).toStrictEqual(fileContent);
|
|
80
|
-
const deleted = await fileStorage.delete(file.key)();
|
|
83
|
+
const deleted = await fileStorage.delete(file.reference.key)();
|
|
81
84
|
expect(deleted).toEqual(E.right(undefined));
|
|
82
85
|
});
|
|
83
86
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeFsFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/NodeFsFileStorage.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,
|
|
1
|
+
{"version":3,"file":"NodeFsFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/NodeFsFileStorage.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EACN,IAAI,EACJ,WAAW,EAEX,SAAS,EAET,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,qBAAa,iBAAkB,YAAW,WAAW;IACxC,OAAO,CAAC,QAAQ;gBAAR,QAAQ,GAAE,MAAe;IAE7C,KAAK,CACJ,IAAI,EAAE,IAAI,EACV,YAAY,GAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAU,GAC5C,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAkB7B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAuB7C,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAW1D,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAYpD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAY7D,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;CAW1D"}
|
|
@@ -42,8 +42,11 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
42
42
|
});
|
|
43
43
|
const fileName = `test-${(0, uuid_1.v4)()}.txt`;
|
|
44
44
|
const file = {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
reference: {
|
|
46
|
+
_tag: 'FileDescriptor',
|
|
47
|
+
key: fileName,
|
|
48
|
+
metadata: { name: fileName },
|
|
49
|
+
},
|
|
47
50
|
content: readableStream,
|
|
48
51
|
};
|
|
49
52
|
const writtenFile = await fileStorage.write(file, O.none)();
|
|
@@ -56,14 +59,17 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
56
59
|
},
|
|
57
60
|
});
|
|
58
61
|
const appendFile = {
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
reference: {
|
|
63
|
+
_tag: 'FileDescriptor',
|
|
64
|
+
key: fileName,
|
|
65
|
+
metadata: { name: fileName },
|
|
66
|
+
},
|
|
61
67
|
content: appendReadableStream,
|
|
62
68
|
};
|
|
63
69
|
const appendedFile = await fileStorage.write(appendFile, O.some({ flag: 'a' }))();
|
|
64
70
|
expect(appendedFile).toEqual(E.right(appendFile));
|
|
65
71
|
// When reading the full contents.
|
|
66
|
-
const read = await fileStorage.read(file.key)();
|
|
72
|
+
const read = await fileStorage.read(file.reference.key)();
|
|
67
73
|
const readResponse = E.getOrElse(() => {
|
|
68
74
|
throw new Error('Expected right');
|
|
69
75
|
})(read);
|
|
@@ -77,7 +83,7 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
77
83
|
});
|
|
78
84
|
});
|
|
79
85
|
expect(Buffer.from(data).toString()).toStrictEqual(`${fileContent}${secondFileContent}`);
|
|
80
|
-
const deleted = await fileStorage.delete(file.key)();
|
|
86
|
+
const deleted = await fileStorage.delete(file.reference.key)();
|
|
81
87
|
expect(deleted).toEqual(E.right(undefined));
|
|
82
88
|
});
|
|
83
89
|
});
|
|
@@ -36,7 +36,7 @@ class NodeFsFileStorage {
|
|
|
36
36
|
this.basePath = basePath;
|
|
37
37
|
}
|
|
38
38
|
write(file, writeOptions = O.none) {
|
|
39
|
-
const filePath = `${this.basePath}/${file.key}`;
|
|
39
|
+
const filePath = `${this.basePath}/${file.reference.key}`;
|
|
40
40
|
const uploadOptions = O.toNullable(writeOptions);
|
|
41
41
|
const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.writeFile(filePath, file.content, uploadOptions?.flag ? { flag: uploadOptions.flag } : {}));
|
|
42
42
|
return (0, function_1.pipe)(result, TE.map(() => file));
|
|
@@ -48,9 +48,15 @@ class NodeFsFileStorage {
|
|
|
48
48
|
const stat = await fs.stat(filePath);
|
|
49
49
|
const stream = fileHandle.createReadStream();
|
|
50
50
|
const metadata = {
|
|
51
|
+
name: key,
|
|
51
52
|
size: stat.size,
|
|
52
53
|
};
|
|
53
|
-
|
|
54
|
+
const fileReference = {
|
|
55
|
+
_tag: 'FileDescriptor',
|
|
56
|
+
key,
|
|
57
|
+
metadata,
|
|
58
|
+
};
|
|
59
|
+
return { reference: fileReference, content: stream };
|
|
54
60
|
}, (reason) => new Error(String(reason)));
|
|
55
61
|
}
|
|
56
62
|
getSharedUrl(key) {
|
package/dist/http/Http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../src/http/Http.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,O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IAC3D,eAAe,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,aAAa,CAAC;CACzD;AAED,eAAO,MAAM,WAAW,EAAE,oBAyIzB,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACxD,mBAAmB,EACnB,eAAe,CAGf,CAAC;AAEF,eAAO,MAAM,eAAe,SACrB,eAAe,qCAEkC,CAAC"}
|
package/dist/http/Http.js
CHANGED
|
@@ -43,10 +43,10 @@ exports.MultipartHttpRequestBody = {
|
|
|
43
43
|
return TE.left(Error('Multipart body must be an object'));
|
|
44
44
|
}
|
|
45
45
|
const fields = {};
|
|
46
|
-
const
|
|
46
|
+
const fileDescriptors = [];
|
|
47
47
|
Object.entries(value).forEach(([key, val]) => {
|
|
48
|
-
if (File_1.
|
|
49
|
-
|
|
48
|
+
if (File_1.FileDescriptor.isFileDescriptor(val)) {
|
|
49
|
+
fileDescriptors.push(val);
|
|
50
50
|
}
|
|
51
51
|
else if (!_.isObject(val)) {
|
|
52
52
|
fields[key] = val;
|
|
@@ -55,7 +55,7 @@ exports.MultipartHttpRequestBody = {
|
|
|
55
55
|
return TE.left(Error(`Multipart body field '${key}' must be a string, number, boolean or file reference`));
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
|
-
return (0, function_1.pipe)(TE.sequenceArray(
|
|
58
|
+
return (0, function_1.pipe)(TE.sequenceArray(fileDescriptors.map((fileReference) => (0, function_1.pipe)(fileStorage.read(fileReference.key), TE.map((file) => ({ key: file.reference.key, file }))))), TE.map((files) => {
|
|
59
59
|
const filesRecord = {};
|
|
60
60
|
files.forEach(({ key, file }) => {
|
|
61
61
|
filesRecord[key] = file;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.abstract.test.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.abstract.test.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"HttpClient.abstract.test.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.abstract.test.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,QAogBpD"}
|
|
@@ -56,8 +56,7 @@ function httpClientTest(httpClient) {
|
|
|
56
56
|
const testMultiPartBodyTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
57
57
|
fields: t.record(t.string, t.string),
|
|
58
58
|
files: t.record(t.string, t.type({
|
|
59
|
-
|
|
60
|
-
metadata: File_1.fileMetadataDescriptor,
|
|
59
|
+
reference: File_1.fileDescriptorDescriptor,
|
|
61
60
|
content: t.any,
|
|
62
61
|
})),
|
|
63
62
|
}));
|
|
@@ -128,9 +127,13 @@ function httpClientTest(httpClient) {
|
|
|
128
127
|
return flattenedFiles;
|
|
129
128
|
};
|
|
130
129
|
const convertFormidableFileToTrayFile = (file) => ({
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
reference: {
|
|
131
|
+
_tag: 'FileDescriptor',
|
|
132
|
+
key: file.newFilename,
|
|
133
|
+
metadata: {
|
|
134
|
+
name: file.newFilename,
|
|
135
|
+
size: file.size,
|
|
136
|
+
},
|
|
134
137
|
},
|
|
135
138
|
content: stream_1.Readable.from(file.filepath),
|
|
136
139
|
});
|
|
@@ -229,13 +232,19 @@ function httpClientTest(httpClient) {
|
|
|
229
232
|
await fileStorage.delete('file1')();
|
|
230
233
|
await fileStorage.delete('file2')();
|
|
231
234
|
const file1 = await fileStorage.write({
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
reference: {
|
|
236
|
+
_tag: 'FileDescriptor',
|
|
237
|
+
key: 'file1',
|
|
238
|
+
metadata: { name: 'file1' },
|
|
239
|
+
},
|
|
234
240
|
content: stream_1.Readable.from('file 1 content'),
|
|
235
241
|
})();
|
|
236
242
|
const file2 = await fileStorage.write({
|
|
237
|
-
|
|
238
|
-
|
|
243
|
+
reference: {
|
|
244
|
+
_tag: 'FileDescriptor',
|
|
245
|
+
key: 'file2',
|
|
246
|
+
metadata: { name: 'file2' },
|
|
247
|
+
},
|
|
239
248
|
content: stream_1.Readable.from('file 2 content'),
|
|
240
249
|
})();
|
|
241
250
|
if (file1._tag === 'Left') {
|
|
@@ -251,13 +260,11 @@ function httpClientTest(httpClient) {
|
|
|
251
260
|
},
|
|
252
261
|
files: {
|
|
253
262
|
file1: {
|
|
254
|
-
|
|
255
|
-
metadata: {},
|
|
263
|
+
reference: file1.right.reference,
|
|
256
264
|
content: stream_1.Readable.from('Hello world'),
|
|
257
265
|
},
|
|
258
266
|
file2: {
|
|
259
|
-
|
|
260
|
-
metadata: {},
|
|
267
|
+
reference: file2.right.reference,
|
|
261
268
|
content: stream_1.Readable.from('Hello world'),
|
|
262
269
|
},
|
|
263
270
|
},
|
|
@@ -277,12 +284,18 @@ function httpClientTest(httpClient) {
|
|
|
277
284
|
fields: testInput.fields,
|
|
278
285
|
files: expect.objectContaining({
|
|
279
286
|
file1: expect.objectContaining({
|
|
280
|
-
|
|
281
|
-
|
|
287
|
+
reference: expect.objectContaining({
|
|
288
|
+
_tag: 'FileDescriptor',
|
|
289
|
+
key: expect.any(String),
|
|
290
|
+
metadata: expect.objectContaining({}),
|
|
291
|
+
}),
|
|
282
292
|
}),
|
|
283
293
|
file2: expect.objectContaining({
|
|
284
|
-
|
|
285
|
-
|
|
294
|
+
reference: expect.objectContaining({
|
|
295
|
+
_tag: 'FileDescriptor',
|
|
296
|
+
key: expect.any(String),
|
|
297
|
+
metadata: expect.objectContaining({}),
|
|
298
|
+
}),
|
|
286
299
|
}),
|
|
287
300
|
}),
|
|
288
301
|
})));
|