Commit e312d271 authored by Panagiotis Skarvelis's avatar Panagiotis Skarvelis
Browse files

add select of sequence types

parent d8ad1adb
......@@ -5,10 +5,11 @@ import { AuditRecord, AuditEngine, SEQTYPES } from '../../interfaces/index.js';
* @class FileEngine
* @implements AuditEngine
* @param {string} path - path to store the records
* @param {SEQTYPES} pnseqtype - protocol number sequence type
*/
export declare class FileEngine implements AuditEngine {
#private;
constructor(path: string);
constructor(path: string, pnseqtype?: SEQTYPES);
/**
* @description Store a record in the database
* @param {AuditRecord} record - record to be stored
......
......@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _FileEngine_path;
var _FileEngine_path, _FileEngine_pnseqtype;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileEngine = void 0;
//Use File System as DB storage
......@@ -26,11 +26,14 @@ const sequence_js_1 = __importDefault(require("./sequence.js"));
* @class FileEngine
* @implements AuditEngine
* @param {string} path - path to store the records
* @param {SEQTYPES} pnseqtype - protocol number sequence type
*/
class FileEngine {
constructor(path) {
constructor(path, pnseqtype) {
_FileEngine_path.set(this, void 0);
_FileEngine_pnseqtype.set(this, void 0);
__classPrivateFieldSet(this, _FileEngine_path, path, "f");
__classPrivateFieldSet(this, _FileEngine_pnseqtype, pnseqtype || "innumerable", "f");
}
/**
* @description Store a record in the database
......@@ -91,7 +94,7 @@ class FileEngine {
*/
pn(type, path) {
const protocol_save_path = path || __classPrivateFieldGet(this, _FileEngine_path, "f");
const sequence_type = type || "innumerable";
const sequence_type = type || __classPrivateFieldGet(this, _FileEngine_pnseqtype, "f");
try {
return (0, protocol_js_1.default)(protocol_save_path, sequence_type);
}
......@@ -101,5 +104,5 @@ class FileEngine {
}
}
exports.FileEngine = FileEngine;
_FileEngine_path = new WeakMap();
_FileEngine_path = new WeakMap(), _FileEngine_pnseqtype = new WeakMap();
exports.default = FileEngine;
......@@ -13,15 +13,16 @@ const sequence_js_1 = __importDefault(require("./sequence.js"));
*/
const protocol = (protocol_path, seqtype) => {
let protocol_split = "aion";
let protocol_date = new Date().toISOString().split('T')[0];
switch (seqtype) {
case "daily":
protocol_split = new Date().toISOString().split('T')[0];
protocol_split = protocol_date;
break;
case "monthly":
protocol_split = new Date().toISOString().split('T')[0].split('-')[1];
protocol_split = protocol_date.split('-')[0] + "-" + protocol_date.split('-')[1];
break;
case "yearly":
protocol_split = new Date().toISOString().split('T')[0].split('-')[0];
protocol_split = protocol_date.split('-')[0];
break;
case "innumerable":
protocol_split = "aion";
......@@ -29,7 +30,7 @@ const protocol = (protocol_path, seqtype) => {
}
const path = `${protocol_path}/${protocol_split}.protocol.sequence`;
const protocol_sequence = (0, sequence_js_1.default)(path, path); //Protocol starts from 1 each day.
let pn = protocol_sequence + "/" + protocol_split;
let pn = protocol_sequence + "/" + protocol_date;
return pn;
};
exports.default = protocol;
......@@ -5,10 +5,11 @@ import { AuditRecord, AuditEngine, SEQTYPES } from '../../interfaces/index.js';
* @class FileEngine
* @implements AuditEngine
* @param {string} path - path to store the records
* @param {SEQTYPES} pnseqtype - protocol number sequence type
*/
export declare class FileEngine implements AuditEngine {
#private;
constructor(path: string);
constructor(path: string, pnseqtype?: SEQTYPES);
/**
* @description Store a record in the database
* @param {AuditRecord} record - record to be stored
......
......@@ -8,11 +8,14 @@ import sequence from './sequence.js';
* @class FileEngine
* @implements AuditEngine
* @param {string} path - path to store the records
* @param {SEQTYPES} pnseqtype - protocol number sequence type
*/
export class FileEngine {
#path;
constructor(path) {
#pnseqtype;
constructor(path, pnseqtype) {
this.#path = path;
this.#pnseqtype = pnseqtype || "innumerable";
}
/**
* @description Store a record in the database
......@@ -73,7 +76,7 @@ export class FileEngine {
*/
pn(type, path) {
const protocol_save_path = path || this.#path;
const sequence_type = type || "innumerable";
const sequence_type = type || this.#pnseqtype;
try {
return protocol(protocol_save_path, sequence_type);
}
......
......@@ -8,15 +8,16 @@ import sequence from './sequence.js';
*/
const protocol = (protocol_path, seqtype) => {
let protocol_split = "aion";
let protocol_date = new Date().toISOString().split('T')[0];
switch (seqtype) {
case "daily":
protocol_split = new Date().toISOString().split('T')[0];
protocol_split = protocol_date;
break;
case "monthly":
protocol_split = new Date().toISOString().split('T')[0].split('-')[1];
protocol_split = protocol_date.split('-')[0] + "-" + protocol_date.split('-')[1];
break;
case "yearly":
protocol_split = new Date().toISOString().split('T')[0].split('-')[0];
protocol_split = protocol_date.split('-')[0];
break;
case "innumerable":
protocol_split = "aion";
......@@ -24,7 +25,7 @@ const protocol = (protocol_path, seqtype) => {
}
const path = `${protocol_path}/${protocol_split}.protocol.sequence`;
const protocol_sequence = sequence(path, path); //Protocol starts from 1 each day.
let pn = protocol_sequence + "/" + protocol_split;
let pn = protocol_sequence + "/" + protocol_date;
return pn;
};
export default protocol;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment