@trayio/commons 2.2.0 → 2.4.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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
1
2
|
import * as E from 'fp-ts/Either';
|
|
2
3
|
import * as t from 'io-ts';
|
|
3
4
|
import { Codec } from '../codec/Codec';
|
|
@@ -9,6 +10,7 @@ export type DynamicArray = Array<DynamicType>;
|
|
|
9
10
|
export interface DynamicTypeInterface {
|
|
10
11
|
readFromFile: (path: string) => E.Either<Error, DynamicType>;
|
|
11
12
|
writeToFile: (path: string, value: DynamicType) => E.Either<Error, undefined>;
|
|
13
|
+
writeToFileAsync: (path: string, value: DynamicType) => TE.TaskEither<Error, undefined>;
|
|
12
14
|
safeCast: <T>(dynamicType: DynamicType, codec: Codec<T>) => E.Either<Error, T>;
|
|
13
15
|
}
|
|
14
16
|
export declare const DynamicType: DynamicTypeInterface;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicType.d.ts","sourceRoot":"","sources":["../../src/dynamictype/DynamicType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DynamicType.d.ts","sourceRoot":"","sources":["../../src/dynamictype/DynamicType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGvC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,MAAM,MAAM,WAAW,GACpB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,aAAa,GACb,YAAY,CAAC;AAEhB,MAAM,MAAM,aAAa,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;CAAE,CAAC;AAEzD,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACpC,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC7D,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC9E,gBAAgB,EAAE,CACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,KACd,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACrC,QAAQ,EAAE,CAAC,CAAC,EACX,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KACX,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CACxB;AAED,eAAO,MAAM,WAAW,EAAE,oBAuBzB,CAAC;AACF,eAAO,MAAM,qBAAqB,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAWrD,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAG7D,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAG3D,CAAC"}
|
|
@@ -24,7 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.dynamicArrayTypeDescriptor = exports.dynamicObjectTypeDescriptor = exports.dynamicTypeDescriptor = exports.DynamicType = void 0;
|
|
27
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
27
28
|
const fs = __importStar(require("fs"));
|
|
29
|
+
const fse = __importStar(require("fs-extra"));
|
|
28
30
|
const E = __importStar(require("fp-ts/Either"));
|
|
29
31
|
const function_1 = require("fp-ts/function");
|
|
30
32
|
const t = __importStar(require("io-ts"));
|
|
@@ -32,6 +34,7 @@ const Try_1 = require("../try/Try");
|
|
|
32
34
|
exports.DynamicType = {
|
|
33
35
|
readFromFile: (path) => (0, Try_1.tryToEither)(() => JSON.parse(fs.readFileSync(path, 'utf8'))),
|
|
34
36
|
writeToFile: (path, value) => (0, function_1.pipe)((0, Try_1.tryToEither)(() => fs.writeFileSync(path, JSON.stringify(value))), E.map(() => undefined)),
|
|
37
|
+
writeToFileAsync: (path, value) => (0, function_1.pipe)(TE.tryCatch(() => fse.writeFile(path, JSON.stringify(value)), (err) => new Error(err.message)), TE.map(() => undefined)),
|
|
35
38
|
safeCast: (dynamicType, codec) => codec.decode(dynamicType),
|
|
36
39
|
};
|
|
37
40
|
exports.dynamicTypeDescriptor = t.recursion('DynamicType', () => t.union([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/commons",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Extensions to the standard/core libraries and basic features",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@types/formidable": "3.4.
|
|
17
|
+
"@types/formidable": "3.4.5",
|
|
18
18
|
"@types/node": "18.11.9",
|
|
19
19
|
"@types/uuid": "9.0.2",
|
|
20
20
|
"formidable": "^3.5.1",
|