@curium.rocks/json-chronicler
Advanced tools
Comparing version
import { LoggerFacade, IRotatingFileChronicler, IJsonSerializable, IClassifier } from '@curium.rocks/data-emitter-base'; | ||
import { BaseChronicler } from '@curium.rocks/data-emitter-base/build/src/chronicler'; | ||
export interface JsonChroniclerOptions extends IClassifier { | ||
@@ -32,3 +33,3 @@ logger?: LoggerFacade; | ||
*/ | ||
export declare class JsonChronicler implements IRotatingFileChronicler { | ||
export declare class JsonChronicler extends BaseChronicler implements IRotatingFileChronicler { | ||
static readonly TYPE: string; | ||
@@ -45,19 +46,4 @@ private firstWrite; | ||
private disposed; | ||
private _id; | ||
private _name; | ||
private _description; | ||
/** | ||
* | ||
*/ | ||
get id(): string; | ||
/** | ||
* | ||
*/ | ||
get description(): string; | ||
/** | ||
* | ||
*/ | ||
get name(): string; | ||
/** | ||
* | ||
* @param {JsonChroniclerOptions} options | ||
@@ -109,3 +95,3 @@ */ | ||
/** | ||
* | ||
* Compress a plain text log file | ||
* @param {string} logName | ||
@@ -117,2 +103,3 @@ * @return {Promise<void>} | ||
/** | ||
* Compress rotated logs | ||
* @return {Promise<void>} | ||
@@ -122,2 +109,3 @@ */ | ||
/** | ||
* Get the filename of the active log file | ||
* @return {string} | ||
@@ -127,5 +115,17 @@ */ | ||
/** | ||
* | ||
* Dipose of any resources managed by the chronicler that | ||
* aren't automatically cleaned up | ||
*/ | ||
dispose(): void; | ||
/** | ||
* The type of the chronicler | ||
* @return {string} | ||
*/ | ||
getType(): string; | ||
/** | ||
* Get the properties unique to this chronicler that are | ||
* needed to restore it's state | ||
* @return {unknown} | ||
*/ | ||
getChroniclerProperties(): unknown; | ||
} |
@@ -12,2 +12,3 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const chronicler_1 = require("@curium.rocks/data-emitter-base/build/src/chronicler"); | ||
/** | ||
@@ -51,3 +52,3 @@ * | ||
*/ | ||
class JsonChronicler { | ||
class JsonChronicler extends chronicler_1.BaseChronicler { | ||
/** | ||
@@ -58,2 +59,9 @@ * | ||
constructor(options) { | ||
super({ | ||
id: options.id, | ||
name: options.name, | ||
description: options.description, | ||
type: JsonChronicler.TYPE, | ||
chroniclerProperties: options | ||
}); | ||
this.firstWrite = true; | ||
@@ -71,20 +79,2 @@ this.disposed = false; | ||
/** | ||
* | ||
*/ | ||
get id() { | ||
return this._id; | ||
} | ||
/** | ||
* | ||
*/ | ||
get description() { | ||
return this._description; | ||
} | ||
/** | ||
* | ||
*/ | ||
get name() { | ||
return this._name; | ||
} | ||
/** | ||
* @return {string} filename for next archive | ||
@@ -198,3 +188,3 @@ * @private | ||
/** | ||
* | ||
* Compress a plain text log file | ||
* @param {string} logName | ||
@@ -206,6 +196,6 @@ * @return {Promise<void>} | ||
const gzip = zlib_1.default.createGzip(); | ||
const source = fs_1.createReadStream(path_1.default.join(this.logDirectory, logName)); | ||
const destination = fs_1.createWriteStream(path_1.default.join(this.logDirectory, `${logName}.gz`)); | ||
const source = (0, fs_1.createReadStream)(path_1.default.join(this.logDirectory, logName)); | ||
const destination = (0, fs_1.createWriteStream)(path_1.default.join(this.logDirectory, `${logName}.gz`)); | ||
try { | ||
await promises_2.pipeline(source, gzip, destination); | ||
await (0, promises_2.pipeline)(source, gzip, destination); | ||
await promises_1.default.unlink(path_1.default.join(this.logDirectory, logName)); | ||
@@ -220,2 +210,3 @@ } | ||
/** | ||
* Compress rotated logs | ||
* @return {Promise<void>} | ||
@@ -239,2 +230,3 @@ */ | ||
/** | ||
* Get the filename of the active log file | ||
* @return {string} | ||
@@ -246,3 +238,4 @@ */ | ||
/** | ||
* | ||
* Dipose of any resources managed by the chronicler that | ||
* aren't automatically cleaned up | ||
*/ | ||
@@ -257,2 +250,24 @@ dispose() { | ||
} | ||
/** | ||
* The type of the chronicler | ||
* @return {string} | ||
*/ | ||
getType() { | ||
return JsonChronicler.TYPE; | ||
} | ||
/** | ||
* Get the properties unique to this chronicler that are | ||
* needed to restore it's state | ||
* @return {unknown} | ||
*/ | ||
getChroniclerProperties() { | ||
return { | ||
logDirectory: this.logDirectory, | ||
logName: this.logName, | ||
rotationSettings: this.rotationSettings, | ||
id: this.id, | ||
name: this.name, | ||
description: this.description | ||
}; | ||
} | ||
} | ||
@@ -259,0 +274,0 @@ exports.JsonChronicler = JsonChronicler; |
@@ -23,3 +23,3 @@ "use strict"; | ||
return Promise.reject(new Error("Missing required rotationSettings property for JsonChronicler")); | ||
if (!(jsonChronicler_1.isRotationOptions(props.rotationSettings))) | ||
if (!((0, jsonChronicler_1.isRotationOptions)(props.rotationSettings))) | ||
return Promise.reject(new Error("rotationSettings does not conform to RotationOptions interface")); | ||
@@ -26,0 +26,0 @@ const options = { |
{ | ||
"name": "@curium.rocks/json-chronicler", | ||
"version": "0.1.1-5", | ||
"version": "0.1.1-6", | ||
"description": "Persists objects in JSON format to rolling archive files", | ||
@@ -42,2 +42,3 @@ "main": "build/src/index.js", | ||
"sonarqube-scanner": "^2.8.1", | ||
"source-map-support": "^0.5.19", | ||
"ts-node": "^10.1.0", | ||
@@ -44,0 +45,0 @@ "typedoc": "^0.21.4", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
32258
5.34%451
3.44%17
6.25%