@trayio/commons 4.73.0 → 4.75.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/NodeFsFileStorage.d.ts +1 -0
- package/dist/file/NodeFsFileStorage.d.ts.map +1 -1
- package/dist/file/NodeFsFileStorage.integration.test.js +32 -0
- package/dist/file/NodeFsFileStorage.js +9 -4
- package/dist/uuid/Uuid.d.ts +17 -0
- package/dist/uuid/Uuid.d.ts.map +1 -0
- package/dist/uuid/Uuid.js +43 -0
- package/dist/uuid/Uuid.unit.test.d.ts +2 -0
- package/dist/uuid/Uuid.unit.test.d.ts.map +1 -0
- package/dist/uuid/Uuid.unit.test.js +42 -0
- package/package.json +1 -1
|
@@ -13,5 +13,6 @@ export declare class NodeFsFileStorage implements FileStorage {
|
|
|
13
13
|
delete(key: string): TE.TaskEither<Error, undefined>;
|
|
14
14
|
createDirectory(key: string): TE.TaskEither<Error, undefined>;
|
|
15
15
|
readDirectory(key: string): TE.TaskEither<Error, Dirent[]>;
|
|
16
|
+
deleteDirectory(key: string): TE.TaskEither<Error, undefined>;
|
|
16
17
|
}
|
|
17
18
|
//# sourceMappingURL=NodeFsFileStorage.d.ts.map
|
|
@@ -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,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,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,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;IAY1D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;CAY7D"}
|
|
@@ -86,4 +86,36 @@ describe('NodeFsFileStorage Tests', () => {
|
|
|
86
86
|
const deleted = await fileStorage.delete(file.reference.key)();
|
|
87
87
|
expect(deleted).toEqual(E.right(undefined));
|
|
88
88
|
});
|
|
89
|
+
it('should create, read and remove a folder', async () => {
|
|
90
|
+
const fileContent = 'This is the initial text.';
|
|
91
|
+
const readableStream = new stream_1.Readable({
|
|
92
|
+
read() {
|
|
93
|
+
this.push(Buffer.from(fileContent));
|
|
94
|
+
this.push(null);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const folderName = `folder`;
|
|
98
|
+
const fileName = `test-${(0, uuid_1.v4)()}.txt`;
|
|
99
|
+
const createdFolderResult = await fileStorage.createDirectory(folderName)();
|
|
100
|
+
expect(createdFolderResult).toEqual(E.right(undefined));
|
|
101
|
+
const file = {
|
|
102
|
+
reference: {
|
|
103
|
+
_tag: 'FileDescriptor',
|
|
104
|
+
key: `${folderName}/${fileName}`,
|
|
105
|
+
metadata: { name: fileName },
|
|
106
|
+
},
|
|
107
|
+
content: readableStream,
|
|
108
|
+
};
|
|
109
|
+
const writtenFile = await fileStorage.write(file, O.none)();
|
|
110
|
+
expect(writtenFile).toEqual(E.right(file));
|
|
111
|
+
const readFolderResult = await fileStorage.readDirectory(folderName)();
|
|
112
|
+
const contents = E.getOrElse(() => {
|
|
113
|
+
throw new Error('Expected right');
|
|
114
|
+
})(readFolderResult);
|
|
115
|
+
expect(contents.length).toEqual(1);
|
|
116
|
+
const deleteFolderResult = await fileStorage.deleteDirectory(folderName)();
|
|
117
|
+
expect(deleteFolderResult).toEqual(E.right(undefined));
|
|
118
|
+
const readFolderResult2 = await fileStorage.readDirectory(folderName)();
|
|
119
|
+
expect(readFolderResult2).toEqual(E.left(new Error("Error: ENOENT: no such file or directory, scandir '/tmp/folder'")));
|
|
120
|
+
});
|
|
89
121
|
});
|
|
@@ -71,16 +71,21 @@ class NodeFsFileStorage {
|
|
|
71
71
|
return (0, function_1.pipe)(result, TE.map(() => undefined));
|
|
72
72
|
}
|
|
73
73
|
createDirectory(key) {
|
|
74
|
-
const
|
|
75
|
-
const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.mkdir(
|
|
74
|
+
const dirPath = `${this.basePath}/${key}`;
|
|
75
|
+
const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.mkdir(dirPath, { recursive: true }));
|
|
76
76
|
return (0, function_1.pipe)(result, TE.map(() => undefined));
|
|
77
77
|
}
|
|
78
78
|
readDirectory(key) {
|
|
79
|
-
const
|
|
79
|
+
const dirPath = `${this.basePath}/${key}`;
|
|
80
80
|
return TE.tryCatch(async () => {
|
|
81
|
-
const files = await fs.readdir(
|
|
81
|
+
const files = await fs.readdir(dirPath, { withFileTypes: true });
|
|
82
82
|
return files;
|
|
83
83
|
}, (reason) => new Error(String(reason)));
|
|
84
84
|
}
|
|
85
|
+
deleteDirectory(key) {
|
|
86
|
+
const dirPath = `${this.basePath}/${key}`;
|
|
87
|
+
const result = (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.rm(dirPath, { recursive: true, force: true }));
|
|
88
|
+
return (0, function_1.pipe)(result, TE.map(() => undefined));
|
|
89
|
+
}
|
|
85
90
|
}
|
|
86
91
|
exports.NodeFsFileStorage = NodeFsFileStorage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as t from 'io-ts';
|
|
2
|
+
import * as E from 'fp-ts/Either';
|
|
3
|
+
import { Codec } from '../codec/Codec';
|
|
4
|
+
declare const uuidTypeDescriptor: t.BrandC<t.StringC, UuidBrand>;
|
|
5
|
+
export type Uuid = t.TypeOf<typeof uuidTypeDescriptor>;
|
|
6
|
+
export interface UuidBrand {
|
|
7
|
+
readonly Uuid: unique symbol;
|
|
8
|
+
}
|
|
9
|
+
export interface UuidInterface {
|
|
10
|
+
typeDescriptor: t.BrandC<t.StringC, UuidBrand>;
|
|
11
|
+
typeCodec: Codec<Uuid>;
|
|
12
|
+
fromString: (value: string) => E.Either<Error, Uuid>;
|
|
13
|
+
decodeBinary: (value: Uuid) => ArrayBuffer;
|
|
14
|
+
}
|
|
15
|
+
export declare const Uuid: UuidInterface;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=Uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uuid.d.ts","sourceRoot":"","sources":["../../src/uuid/Uuid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAQvC,QAAA,MAAM,kBAAkB,gCAIvB,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAIvD,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,IAAI,EAAE,OAAO,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC7B,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC/C,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACvB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACrD,YAAY,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,WAAW,CAAC;CAC3C;AAED,eAAO,MAAM,IAAI,EAAE,aAalB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Uuid = void 0;
|
|
27
|
+
const t = __importStar(require("io-ts"));
|
|
28
|
+
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
29
|
+
const isUuid = (s) => {
|
|
30
|
+
const exp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
31
|
+
return exp.test(s);
|
|
32
|
+
};
|
|
33
|
+
const uuidTypeDescriptor = t.brand(t.string, (input) => isUuid(input), 'Uuid');
|
|
34
|
+
const uuidTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(uuidTypeDescriptor);
|
|
35
|
+
exports.Uuid = {
|
|
36
|
+
typeDescriptor: uuidTypeDescriptor,
|
|
37
|
+
typeCodec: uuidTypeCodec,
|
|
38
|
+
fromString: (value) => uuidTypeCodec.decode(value),
|
|
39
|
+
decodeBinary: (value) => {
|
|
40
|
+
const binary = Buffer.from(uuidTypeCodec.encode(value), 'utf-8');
|
|
41
|
+
return binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uuid.unit.test.d.ts","sourceRoot":"","sources":["../../src/uuid/Uuid.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
27
|
+
const Uuid_1 = require("./Uuid");
|
|
28
|
+
describe('Uuid', () => {
|
|
29
|
+
test('should create uuid type for valid string', () => {
|
|
30
|
+
const testValue = '3fa04423-4a2c-462f-8032-8cdd6f1cd5cd';
|
|
31
|
+
const uuidResult = Uuid_1.Uuid.fromString(testValue);
|
|
32
|
+
const uuid = E.getOrElse((error) => {
|
|
33
|
+
throw new Error('This is not a valid UUID');
|
|
34
|
+
})(uuidResult);
|
|
35
|
+
expect(uuid.toString()).toStrictEqual(testValue);
|
|
36
|
+
});
|
|
37
|
+
test('should fail when string is invalid', () => {
|
|
38
|
+
const testValue = 'some-invalid-uuid';
|
|
39
|
+
const uuidResult = Uuid_1.Uuid.fromString(testValue);
|
|
40
|
+
expect(E.isLeft(uuidResult)).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|