backlib 0.3.3 → 0.4.0-SNAPSHOT.1
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/README.md +1 -1
- package/dist/decorator-leaf-tracer.js +6 -7
- package/dist/decorator-leaf-tracer.js.map +1 -0
- package/dist/fs.js +14 -21
- package/dist/fs.js.map +1 -0
- package/dist/index.js +5 -16
- package/dist/index.js.map +1 -0
- package/dist/log.js +20 -51
- package/dist/log.js.map +1 -0
- package/dist/utils.js +2 -5
- package/dist/utils.js.map +1 -0
- package/package.json +8 -7
- package/src/fs.ts +1 -1
- package/src/index.ts +4 -4
- package/src/log.ts +7 -8
- package/dist/decorator-leaf-tracer.d.ts +0 -13
- package/dist/fs.d.ts +0 -12
- package/dist/index.d.ts +0 -4
- package/dist/log.d.ts +0 -53
- package/dist/utils.d.ts +0 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Minimalist utilities for backend services.
|
|
|
8
8
|
- **Web Async** Web request utilities based on [koajs](https://koajs.com/) over express as it is a modern rewrite of more or less the same API with backed in support for Promise/async/await (simplify many of the usecases)
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
> NOTE:
|
|
11
|
+
> NOTE: Version `0.4.0` and above uses ESM module (i.e., `type: module`) only.
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
## Log
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.newLeafTracer = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Tracker to determine if a decorator is on the leaf"est" method of the class hierarchy.
|
|
6
3
|
*/
|
|
7
|
-
function newLeafTracer() {
|
|
4
|
+
export function newLeafTracer() {
|
|
8
5
|
return new LeafTracer();
|
|
9
6
|
}
|
|
10
|
-
exports.newLeafTracer = newLeafTracer;
|
|
11
7
|
/**
|
|
12
8
|
* Ter
|
|
13
9
|
*/
|
|
14
10
|
class LeafTracer {
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
constructor() {
|
|
12
|
+
// object class, by TopTarget
|
|
13
|
+
this.dic = new Map();
|
|
14
|
+
}
|
|
17
15
|
/** Returns true if this method is the leaf most method annotatio traced by this tracer */
|
|
18
16
|
trace(objectClass, targetClass, propertyKey) {
|
|
19
17
|
let topTargetClassByProperty = this.dic.get(objectClass);
|
|
@@ -41,3 +39,4 @@ class LeafTracer {
|
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
}
|
|
42
|
+
//# sourceMappingURL=decorator-leaf-tracer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-leaf-tracer.js","sourceRoot":"","sources":["../src/decorator-leaf-tracer.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,UAAU,aAAa;IAC5B,OAAO,IAAI,UAAU,EAAE,CAAC;AACzB,CAAC;AAID;;GAEG;AACH,MAAM,UAAU;IAAhB;QAEC,6BAA6B;QACrB,QAAG,GAA6C,IAAI,GAAG,EAAE,CAAC;IAgCnE,CAAC;IA9BA,0FAA0F;IAC1F,KAAK,CAAC,WAAqB,EAAE,WAAqB,EAAE,WAAmB;QAEtE,IAAI,wBAAwB,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAEzD,6FAA6F;QAC7F,oCAAoC;QACpC,IAAI,CAAC,wBAAwB,EAAE;YAC9B,wBAAwB,GAAG,IAAI,GAAG,EAAoB,CAAC;YACvD,wBAAwB,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;YAEvD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAC;YACpD,OAAO,IAAI,CAAC;SACZ;QACD,+BAA+B;aAC1B;YACJ,IAAI,cAAc,GAAG,wBAAwB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YAE/D,8DAA8D;YAC9D,6CAA6C;YAC7C,IAAI,CAAC,cAAc,EAAE;gBACpB,wBAAwB,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;gBACvD,OAAO,IAAI,CAAC;aACZ;YACD,6EAA6E;iBACxE;gBACJ,OAAO,CAAC,cAAc,KAAK,WAAW,CAAC,CAAC;aACxC;SACD;IACF,CAAC;CACD"}
|
package/dist/fs.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.saferRemove = exports.glob = void 0;
|
|
7
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
|
-
const fs_extra_1 = require("fs-extra");
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const utils_min_1 = require("utils-min");
|
|
1
|
+
import FastGlob from 'fast-glob';
|
|
2
|
+
import { join as pathJoin, resolve as pathResolve } from 'path';
|
|
3
|
+
import { asArray } from 'utils-min';
|
|
4
|
+
const { pathExists, remove } = (await import('fs-extra')).default;
|
|
11
5
|
/**
|
|
12
6
|
* Simplified and sorted glob function (using fast-glob) for one or more pattern from current directory or a optional cwd one.
|
|
13
7
|
*
|
|
@@ -16,37 +10,35 @@ const utils_min_1 = require("utils-min");
|
|
|
16
10
|
*
|
|
17
11
|
* @returns always sorted result return Promise<string[]>
|
|
18
12
|
*/
|
|
19
|
-
async function glob(pattern, cwdOrFastGlobOptions) {
|
|
13
|
+
export async function glob(pattern, cwdOrFastGlobOptions) {
|
|
20
14
|
let opts = undefined;
|
|
21
15
|
if (cwdOrFastGlobOptions != null) {
|
|
22
16
|
opts = (typeof cwdOrFastGlobOptions === 'string') ? { cwd: cwdOrFastGlobOptions } : cwdOrFastGlobOptions;
|
|
23
17
|
}
|
|
24
|
-
const result = await
|
|
18
|
+
const result = await FastGlob(pattern, opts);
|
|
25
19
|
const cwd = (opts) ? opts.cwd : undefined;
|
|
26
20
|
const list = result.map(path => {
|
|
27
|
-
return (cwd) ?
|
|
21
|
+
return (cwd) ? pathJoin(cwd, path) : path;
|
|
28
22
|
});
|
|
29
23
|
return list.sort(globCompare);
|
|
30
24
|
}
|
|
31
|
-
exports.glob = glob;
|
|
32
25
|
/** Remove one or more files. Resolved the number of names removed */
|
|
33
|
-
async function saferRemove(names, cwd) {
|
|
34
|
-
const baseDir = (cwd) ?
|
|
26
|
+
export async function saferRemove(names, cwd) {
|
|
27
|
+
const baseDir = (cwd) ? pathResolve(cwd) : pathResolve('./');
|
|
35
28
|
let removedNames = [];
|
|
36
|
-
for (const name of
|
|
37
|
-
const fullPath =
|
|
29
|
+
for (const name of asArray(names)) {
|
|
30
|
+
const fullPath = pathJoin(baseDir, name);
|
|
38
31
|
if (!fullPath.startsWith(baseDir)) {
|
|
39
32
|
throw new Error(`Path to be removed does not look safe (nothing done): ${fullPath}\n\tCause: Does not belong to ${baseDir}`);
|
|
40
33
|
}
|
|
41
|
-
const exists = await
|
|
34
|
+
const exists = await pathExists(fullPath);
|
|
42
35
|
if (exists) {
|
|
43
|
-
await
|
|
36
|
+
await remove(fullPath);
|
|
44
37
|
removedNames.push(name);
|
|
45
38
|
}
|
|
46
39
|
}
|
|
47
40
|
return removedNames;
|
|
48
41
|
}
|
|
49
|
-
exports.saferRemove = saferRemove;
|
|
50
42
|
//#region ---------- Utils ----------
|
|
51
43
|
function globCompare(a, b) {
|
|
52
44
|
const aPathIdxs = pathIndexes(a);
|
|
@@ -75,3 +67,4 @@ function pathIndexes(fullPath) {
|
|
|
75
67
|
// return (names instanceof Array) ? names : [names];
|
|
76
68
|
// }
|
|
77
69
|
//#endregion ---------- /Utils ----------
|
|
70
|
+
//# sourceMappingURL=fs.js.map
|
package/dist/fs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,QAAqB,MAAM,WAAW,CAAC;AAC9C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CAAC;KACtD;IAED,oCAAoC;IACpC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAGzB,CAAC;AAED,SAAS,WAAW,CAAC,QAAgB;IACpC,MAAM,IAAI,GAAa,EAAE,CAAC;IAE1B,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3B,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YACxB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACb;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED,+CAA+C;AAC/C,sDAAsD;AACtD,IAAI;AACJ,yCAAyC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./decorator-leaf-tracer"), exports);
|
|
14
|
-
__exportStar(require("./fs"), exports);
|
|
15
|
-
__exportStar(require("./log"), exports);
|
|
16
|
-
__exportStar(require("./utils"), exports);
|
|
1
|
+
export * from './decorator-leaf-tracer.js';
|
|
2
|
+
export * from './fs.js';
|
|
3
|
+
export * from './log.js';
|
|
4
|
+
export * from './utils.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
package/dist/log.js
CHANGED
|
@@ -1,35 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.FileLogWriter = exports.BaseLog = void 0;
|
|
23
|
-
const fs = __importStar(require("fs-extra"));
|
|
24
|
-
const Path = __importStar(require("path"));
|
|
25
|
-
const utils_min_1 = require("utils-min");
|
|
26
|
-
const fs_1 = require("./fs");
|
|
1
|
+
import * as Path from 'path';
|
|
2
|
+
import { isString } from 'utils-min';
|
|
3
|
+
import { glob, saferRemove } from './fs.js';
|
|
4
|
+
const { pathExists, mkdirs, appendFile, rename } = (await import('fs-extra')).default;
|
|
27
5
|
/**
|
|
28
6
|
* Base Log class that handle the base log management logic.
|
|
29
7
|
*/
|
|
30
|
-
class BaseLog {
|
|
31
|
-
logWriters = [];
|
|
8
|
+
export class BaseLog {
|
|
32
9
|
constructor(opts) {
|
|
10
|
+
this.logWriters = [];
|
|
33
11
|
this.logWriters = [...opts.writers];
|
|
34
12
|
}
|
|
35
13
|
async log(rec) {
|
|
@@ -47,21 +25,12 @@ class BaseLog {
|
|
|
47
25
|
}
|
|
48
26
|
}
|
|
49
27
|
}
|
|
50
|
-
|
|
51
|
-
class FileLogWriter {
|
|
52
|
-
name;
|
|
53
|
-
dir;
|
|
54
|
-
maxCount;
|
|
55
|
-
maxTime;
|
|
56
|
-
fileProcessor;
|
|
57
|
-
recordSerializer;
|
|
58
|
-
_init = false;
|
|
59
|
-
_rev = 0;
|
|
60
|
-
count = 0;
|
|
61
|
-
nextUpload = null; // null means nothing scheduled
|
|
62
|
-
lastUpload;
|
|
63
|
-
file;
|
|
28
|
+
export class FileLogWriter {
|
|
64
29
|
constructor(opts) {
|
|
30
|
+
this._init = false;
|
|
31
|
+
this._rev = 0;
|
|
32
|
+
this.count = 0;
|
|
33
|
+
this.nextUpload = null; // null means nothing scheduled
|
|
65
34
|
this.name = opts.name;
|
|
66
35
|
this.maxCount = opts.maxCount;
|
|
67
36
|
this.maxTime = opts.maxTime;
|
|
@@ -71,10 +40,10 @@ class FileLogWriter {
|
|
|
71
40
|
}
|
|
72
41
|
async init() {
|
|
73
42
|
if (!this._init) {
|
|
74
|
-
await
|
|
43
|
+
await mkdirs(this.dir);
|
|
75
44
|
// delete the logs dir if exit
|
|
76
|
-
const oldLogFiles = await
|
|
77
|
-
await
|
|
45
|
+
const oldLogFiles = await glob(this.dir + `${this.name}*.log`);
|
|
46
|
+
await saferRemove(oldLogFiles);
|
|
78
47
|
console.log('Deleted old log files', oldLogFiles);
|
|
79
48
|
this.rev();
|
|
80
49
|
this._init = true;
|
|
@@ -96,7 +65,7 @@ class FileLogWriter {
|
|
|
96
65
|
// NOTE: In fact, this whole file write and upload, should be part of a FileLogWriter, and we just treat it as above (perhaps in the BigQueryLogWriter extends FileLogWriter)
|
|
97
66
|
const str = this.recordSerializer(rec);
|
|
98
67
|
if (str != null) {
|
|
99
|
-
await
|
|
68
|
+
await appendFile(this.file, str);
|
|
100
69
|
}
|
|
101
70
|
// add count
|
|
102
71
|
this.count = this.count + 1;
|
|
@@ -122,12 +91,12 @@ class FileLogWriter {
|
|
|
122
91
|
// we rev just before to make sure other logs will happen on new files
|
|
123
92
|
this.rev();
|
|
124
93
|
try {
|
|
125
|
-
const exists = await
|
|
94
|
+
const exists = await pathExists(file);
|
|
126
95
|
if (exists) {
|
|
127
96
|
if (this.fileProcessor) {
|
|
128
97
|
await this.fileProcessor(file);
|
|
129
98
|
}
|
|
130
|
-
await
|
|
99
|
+
await saferRemove(file);
|
|
131
100
|
}
|
|
132
101
|
else {
|
|
133
102
|
console.log(`CODE ERROR - can't upload to big query ${file} does not exists`);
|
|
@@ -135,16 +104,16 @@ class FileLogWriter {
|
|
|
135
104
|
}
|
|
136
105
|
catch (ex) {
|
|
137
106
|
console.log(`ERROR - logger.processLogFile - cannot upload to big query ${file}, ${ex.message}`);
|
|
138
|
-
await
|
|
107
|
+
await rename(file, file + '.error');
|
|
139
108
|
}
|
|
140
109
|
this.count = 0;
|
|
141
110
|
this.lastUpload = Date.now();
|
|
142
111
|
this.nextUpload = null;
|
|
143
112
|
}
|
|
144
113
|
}
|
|
145
|
-
exports.FileLogWriter = FileLogWriter;
|
|
146
114
|
/** default serializer */
|
|
147
115
|
function defaultSerializer(rec) {
|
|
148
|
-
return
|
|
116
|
+
return isString(rec) ? rec : JSON.stringify(rec);
|
|
149
117
|
}
|
|
150
118
|
//#endregion ---------- /FileLogWriter ----------
|
|
119
|
+
//# sourceMappingURL=log.js.map
|
package/dist/log.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,O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CAAC,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAC,CAAC;SACpC;QAED,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACxB,CAAC;CAED;AAED,yBAAyB;AAEzB,SAAS,iBAAiB,CAAI,GAAM;IACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,kDAAkD"}
|
package/dist/utils.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prompt = void 0;
|
|
4
1
|
/** Promise a message and return the trimmed entered value */
|
|
5
|
-
async function prompt(message) {
|
|
2
|
+
export async function prompt(message) {
|
|
6
3
|
process.stdout.write(`\n${message}: `);
|
|
7
4
|
return new Promise(function (resolve, reject) {
|
|
8
5
|
process.stdin.resume();
|
|
@@ -13,4 +10,4 @@ async function prompt(message) {
|
|
|
13
10
|
});
|
|
14
11
|
});
|
|
15
12
|
}
|
|
16
|
-
|
|
13
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,6DAA6D;AAC7D,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAe;IAC3C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC;IACvC,OAAO,IAAI,OAAO,CAAC,UAAU,OAAO,EAAE,MAAM;QAC3C,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACvB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,IAAI;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backlib",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.4.0-SNAPSHOT.1",
|
|
4
5
|
"description": "Minimalist library for backend services",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"typings": "dist/index.d.ts",
|
|
@@ -19,17 +20,17 @@
|
|
|
19
20
|
"author": "jeremy.chone@gmail.com",
|
|
20
21
|
"license": "MIT",
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"fast-glob": "^3.2.
|
|
23
|
+
"fast-glob": "^3.2.11",
|
|
23
24
|
"fs-extra": "^10.0.0",
|
|
24
|
-
"utils-min": "^0.
|
|
25
|
+
"utils-min": "^0.2.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@types/fs-extra": "^9.0.
|
|
28
|
-
"@types/mocha": "^9.
|
|
29
|
-
"mocha": "^9.
|
|
28
|
+
"@types/fs-extra": "^9.0.13",
|
|
29
|
+
"@types/mocha": "^9.1.0",
|
|
30
|
+
"mocha": "^9.1.4",
|
|
30
31
|
"rimraf": "^3.0.2",
|
|
31
32
|
"ts-node-dev": "^1.1.8",
|
|
32
|
-
"typescript": "^4.
|
|
33
|
+
"typescript": "^4.5.4"
|
|
33
34
|
},
|
|
34
35
|
"files": [
|
|
35
36
|
"src/",
|
package/src/fs.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import FastGlob, { Options } from 'fast-glob';
|
|
2
|
-
import { pathExists, remove } from 'fs-extra';
|
|
3
2
|
import { join as pathJoin, resolve as pathResolve } from 'path';
|
|
4
3
|
import { asArray } from 'utils-min';
|
|
4
|
+
const { pathExists, remove } = (await import('fs-extra')).default;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Simplified and sorted glob function (using fast-glob) for one or more pattern from current directory or a optional cwd one.
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './decorator-leaf-tracer';
|
|
2
|
-
export * from './fs';
|
|
3
|
-
export * from './log';
|
|
4
|
-
export * from './utils';
|
|
1
|
+
export * from './decorator-leaf-tracer.js';
|
|
2
|
+
export * from './fs.js';
|
|
3
|
+
export * from './log.js';
|
|
4
|
+
export * from './utils.js';
|
|
5
5
|
|
package/src/log.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as fs from 'fs-extra';
|
|
2
1
|
import * as Path from 'path';
|
|
3
2
|
import { isString } from 'utils-min';
|
|
4
|
-
import { glob, saferRemove } from './fs';
|
|
3
|
+
import { glob, saferRemove } from './fs.js';
|
|
4
|
+
const { pathExists, mkdirs, appendFile, rename } = (await import('fs-extra')).default;
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
//#region ---------- BaseLog ----------
|
|
@@ -99,7 +99,7 @@ export class FileLogWriter<R> implements LogWriter<R> {
|
|
|
99
99
|
|
|
100
100
|
private async init() {
|
|
101
101
|
if (!this._init) {
|
|
102
|
-
await
|
|
102
|
+
await mkdirs(this.dir);
|
|
103
103
|
|
|
104
104
|
// delete the logs dir if exit
|
|
105
105
|
const oldLogFiles = await glob(this.dir + `${this.name}*.log`);
|
|
@@ -133,7 +133,7 @@ export class FileLogWriter<R> implements LogWriter<R> {
|
|
|
133
133
|
// NOTE: In fact, this whole file write and upload, should be part of a FileLogWriter, and we just treat it as above (perhaps in the BigQueryLogWriter extends FileLogWriter)
|
|
134
134
|
const str = this.recordSerializer(rec);
|
|
135
135
|
if (str != null) {
|
|
136
|
-
await
|
|
136
|
+
await appendFile(this.file!, str);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// add count
|
|
@@ -166,7 +166,7 @@ export class FileLogWriter<R> implements LogWriter<R> {
|
|
|
166
166
|
this.rev();
|
|
167
167
|
|
|
168
168
|
try {
|
|
169
|
-
const exists = await
|
|
169
|
+
const exists = await pathExists(file);
|
|
170
170
|
if (exists) {
|
|
171
171
|
if (this.fileProcessor) {
|
|
172
172
|
await this.fileProcessor(file);
|
|
@@ -176,9 +176,9 @@ export class FileLogWriter<R> implements LogWriter<R> {
|
|
|
176
176
|
console.log(`CODE ERROR - can't upload to big query ${file} does not exists`);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
} catch (ex) {
|
|
179
|
+
} catch (ex: any) {
|
|
180
180
|
console.log(`ERROR - logger.processLogFile - cannot upload to big query ${file}, ${ex.message}`);
|
|
181
|
-
await
|
|
181
|
+
await rename(file, file + '.error');
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
this.count = 0;
|
|
@@ -196,4 +196,3 @@ function defaultSerializer<R>(rec: R): string {
|
|
|
196
196
|
|
|
197
197
|
//#endregion ---------- /FileLogWriter ----------
|
|
198
198
|
|
|
199
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tracker to determine if a decorator is on the leaf"est" method of the class hierarchy.
|
|
3
|
-
*/
|
|
4
|
-
export declare function newLeafTracer(): LeafTracer;
|
|
5
|
-
/**
|
|
6
|
-
* Ter
|
|
7
|
-
*/
|
|
8
|
-
declare class LeafTracer {
|
|
9
|
-
private dic;
|
|
10
|
-
/** Returns true if this method is the leaf most method annotatio traced by this tracer */
|
|
11
|
-
trace(objectClass: Function, targetClass: Function, propertyKey: string): boolean;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
package/dist/fs.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Options } from 'fast-glob';
|
|
2
|
-
/**
|
|
3
|
-
* Simplified and sorted glob function (using fast-glob) for one or more pattern from current directory or a optional cwd one.
|
|
4
|
-
*
|
|
5
|
-
* Note 1: The result will be sorted by natural directory/subdir/filename order (as a would a recursive walk)
|
|
6
|
-
* Note 2: When `cwd` in options, it is added to the file path i.e. `pathJoin(cwd, path)`
|
|
7
|
-
*
|
|
8
|
-
* @returns always sorted result return Promise<string[]>
|
|
9
|
-
*/
|
|
10
|
-
export declare function glob(pattern: string | string[], cwdOrFastGlobOptions?: string | Options): Promise<string[]>;
|
|
11
|
-
/** Remove one or more files. Resolved the number of names removed */
|
|
12
|
-
export declare function saferRemove(names: string | string[], cwd?: string): Promise<string[]>;
|
package/dist/index.d.ts
DELETED
package/dist/log.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
interface LogOptions<R> {
|
|
2
|
-
writers: LogWriter<R>[];
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Base Log class that handle the base log management logic.
|
|
6
|
-
*/
|
|
7
|
-
export declare class BaseLog<R> {
|
|
8
|
-
private logWriters;
|
|
9
|
-
constructor(opts: LogOptions<R>);
|
|
10
|
-
log(rec: R): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export interface LogWriter<R> {
|
|
13
|
-
readonly name: string;
|
|
14
|
-
writeRec?(rec: R): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
/** processing file, if return true, then file will be assumed to be full processed, and will be deleted */
|
|
17
|
-
export declare type FileProcessor = (file: string) => Promise<boolean>;
|
|
18
|
-
/** Record serializer to string, which will be appended to the file. If null, record will be skipped */
|
|
19
|
-
export declare type RecordSerializer<R> = (rec: R) => string | null;
|
|
20
|
-
interface FileLogWriterOptions<R> {
|
|
21
|
-
/** name of the logWriter, will be used as prefix */
|
|
22
|
-
name: string;
|
|
23
|
-
/** Local directory in which the logs files will be saved */
|
|
24
|
-
dir: string;
|
|
25
|
-
/** maxCount of record before file is uploaded to destination */
|
|
26
|
-
maxCount: number;
|
|
27
|
-
/** max time (in ms) before file is uploaded to destination (which ever comes first with maxCount) */
|
|
28
|
-
maxTime: number;
|
|
29
|
-
fileProcessor?: FileProcessor;
|
|
30
|
-
recordSerializer?: RecordSerializer<R>;
|
|
31
|
-
}
|
|
32
|
-
export declare class FileLogWriter<R> implements LogWriter<R> {
|
|
33
|
-
readonly name: string;
|
|
34
|
-
private dir;
|
|
35
|
-
private maxCount;
|
|
36
|
-
private maxTime;
|
|
37
|
-
private fileProcessor?;
|
|
38
|
-
private recordSerializer;
|
|
39
|
-
private _init;
|
|
40
|
-
private _rev;
|
|
41
|
-
private count;
|
|
42
|
-
private nextUpload;
|
|
43
|
-
private lastUpload?;
|
|
44
|
-
private file?;
|
|
45
|
-
constructor(opts: FileLogWriterOptions<R>);
|
|
46
|
-
private init;
|
|
47
|
-
/** Update the revision file */
|
|
48
|
-
private rev;
|
|
49
|
-
/** IMPLEMENTATION of the FileWriter interface */
|
|
50
|
-
writeRec(rec: R): Promise<void>;
|
|
51
|
-
private endFile;
|
|
52
|
-
}
|
|
53
|
-
export {};
|
package/dist/utils.d.ts
DELETED