Commit 9af07bd6 authored by Panagiotis Skarvelis's avatar Panagiotis Skarvelis
Browse files

refactor reset var names

parent 3e301872
import { AuditRecord, AuditEngine, SEQTYPES } from '../../interfaces/index.js';
import { AuditRecord, AuditEngine, PNRESETTYPES } from '../../interfaces/index.js';
/**
* @description AuditEngine implementation
* @note This class is used to implement the methods that must be implemented by the AuditEngine
* @class FileEngine
* @implements AuditEngine
* @param {string} path - path to store the records
* @param {SEQTYPES} pnseqtype - protocol number sequence type
* @param {PNRESETTYPES} pnreset - protocol number sequence type
*/
export declare class FileEngine implements AuditEngine {
#private;
constructor(path?: string, pnseqtype?: SEQTYPES);
constructor(path?: string, pnreset?: PNRESETTYPES);
/**
* @description Store a record in the database
* @param {AuditRecord} record - record to be stored
......@@ -42,6 +42,6 @@ export declare class FileEngine implements AuditEngine {
* @memberof FileEngine
* @method protocol
*/
pn(type?: SEQTYPES, path?: string): string;
pn(reset?: PNRESETTYPES, path?: string): string;
}
export default FileEngine;
......@@ -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, _FileEngine_pnseqtype;
var _FileEngine_path, _FileEngine_pnreset;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileEngine = void 0;
//Use File System as DB storage
......@@ -26,14 +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
* @param {PNRESETTYPES} pnreset - protocol number sequence type
*/
class FileEngine {
constructor(path, pnseqtype) {
constructor(path, pnreset) {
_FileEngine_path.set(this, void 0);
_FileEngine_pnseqtype.set(this, void 0);
_FileEngine_pnreset.set(this, void 0);
__classPrivateFieldSet(this, _FileEngine_path, path ? path : "/tmp", "f");
__classPrivateFieldSet(this, _FileEngine_pnseqtype, pnseqtype || "innumerable", "f");
__classPrivateFieldSet(this, _FileEngine_pnreset, pnreset || "innumerable", "f");
}
/**
* @description Store a record in the database
......@@ -92,11 +92,11 @@ class FileEngine {
* @memberof FileEngine
* @method protocol
*/
pn(type, path) {
pn(reset, path) {
const protocol_save_path = path || __classPrivateFieldGet(this, _FileEngine_path, "f");
const sequence_type = type || __classPrivateFieldGet(this, _FileEngine_pnseqtype, "f");
const protocol_reset = reset || __classPrivateFieldGet(this, _FileEngine_pnreset, "f");
try {
return (0, protocol_js_1.default)(protocol_save_path, sequence_type);
return (0, protocol_js_1.default)(protocol_save_path, protocol_reset);
}
catch (error) {
throw error;
......@@ -104,5 +104,5 @@ class FileEngine {
}
}
exports.FileEngine = FileEngine;
_FileEngine_path = new WeakMap(), _FileEngine_pnseqtype = new WeakMap();
_FileEngine_path = new WeakMap(), _FileEngine_pnreset = new WeakMap();
exports.default = FileEngine;
import { SEQTYPES } from '../../interfaces/index.js';
import { PNRESETTYPES } from '../../interfaces/index.js';
/**
* Generate a new protocol number
* in the format sequence/date
......@@ -6,5 +6,5 @@ import { SEQTYPES } from '../../interfaces/index.js';
* @param protocol_path
* @returns string
*/
declare const protocol: (protocol_path: string, seqtype: SEQTYPES) => string;
declare const protocol: (protocol_path: string, pnreset: PNRESETTYPES) => string;
export default protocol;
......@@ -11,10 +11,10 @@ const sequence_js_1 = __importDefault(require("./sequence.js"));
* @param protocol_path
* @returns string
*/
const protocol = (protocol_path, seqtype) => {
const protocol = (protocol_path, pnreset) => {
let protocol_split = "aion";
let protocol_date = new Date().toISOString().split('T')[0];
switch (seqtype) {
switch (pnreset) {
case "daily":
protocol_split = protocol_date;
break;
......@@ -29,7 +29,7 @@ const protocol = (protocol_path, seqtype) => {
break;
}
const path = `${protocol_path}/${protocol_split}.protocol.sequence`;
const protocol_sequence = (0, sequence_js_1.default)(path, path); //Protocol starts from 1 each day.
const protocol_sequence = (0, sequence_js_1.default)(path, path); //Protocol starts from 1 depent on pnreset.
let pn = protocol_sequence + "/" + protocol_date;
return pn;
};
......
......@@ -19,7 +19,7 @@ export interface AuditEngine {
put: (record: AuditRecord) => AuditRecord | Promise<AuditRecord>;
get: (auditTransactionId: string) => AuditRecord | Promise<AuditRecord>;
seq: (path?: string) => number | Promise<number>;
pn: (type?: "daily" | "monthly" | "yearly" | "innumerable", path?: string) => string | Promise<string>;
pn: (reset?: "daily" | "monthly" | "yearly" | "innumerable", path?: string) => string | Promise<string>;
}
/**
* @description FileSystem errors
......@@ -28,7 +28,7 @@ export declare type FS_ERROR = {
code: string;
message: string;
};
export declare type SEQTYPES = "daily" | "monthly" | "yearly" | "innumerable";
export declare type PNRESETTYPES = "daily" | "monthly" | "yearly" | "innumerable";
/**
* @description Schema to be used to store the audit records on real databases
*/
......
import { AuditRecord, AuditEngine, SEQTYPES } from '../interfaces/index.js';
import { AuditRecord, AuditEngine, PNRESETTYPES } from '../interfaces/index.js';
/**
* @description AuditEngine implementation
* @note This class uses AuditEngine implemetations, look at FileEngine.ts for an example
......@@ -34,12 +34,12 @@ export declare class db {
seq(path?: string): Promise<number>;
/**
* @description Generate a new protocol string
* @param type:SEQTYPES
* @param type:PNRESETTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
pn(type?: SEQTYPES, path?: string): Promise<string>;
pn(reset?: PNRESETTYPES, path?: string): Promise<string>;
}
export default db;
......@@ -62,15 +62,15 @@ class db {
}
/**
* @description Generate a new protocol string
* @param type:SEQTYPES
* @param type:PNRESETTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
pn(type, path) {
pn(reset, path) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.engine.pn(type, path);
return yield this.engine.pn(reset, path);
});
}
}
......
import { AuditRecord, AuditEngine, SEQTYPES } from '../../interfaces/index.js';
import { AuditRecord, AuditEngine, PNRESETTYPES } from '../../interfaces/index.js';
/**
* @description AuditEngine implementation
* @note This class is used to implement the methods that must be implemented by the AuditEngine
* @class FileEngine
* @implements AuditEngine
* @param {string} path - path to store the records
* @param {SEQTYPES} pnseqtype - protocol number sequence type
* @param {PNRESETTYPES} pnreset - protocol number sequence type
*/
export declare class FileEngine implements AuditEngine {
#private;
constructor(path?: string, pnseqtype?: SEQTYPES);
constructor(path?: string, pnreset?: PNRESETTYPES);
/**
* @description Store a record in the database
* @param {AuditRecord} record - record to be stored
......@@ -42,6 +42,6 @@ export declare class FileEngine implements AuditEngine {
* @memberof FileEngine
* @method protocol
*/
pn(type?: SEQTYPES, path?: string): string;
pn(reset?: PNRESETTYPES, path?: string): string;
}
export default FileEngine;
......@@ -8,14 +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
* @param {PNRESETTYPES} pnreset - protocol number sequence type
*/
export class FileEngine {
#path;
#pnseqtype;
constructor(path, pnseqtype) {
#pnreset;
constructor(path, pnreset) {
this.#path = path ? path : "/tmp";
this.#pnseqtype = pnseqtype || "innumerable";
this.#pnreset = pnreset || "innumerable";
}
/**
* @description Store a record in the database
......@@ -74,11 +74,11 @@ export class FileEngine {
* @memberof FileEngine
* @method protocol
*/
pn(type, path) {
pn(reset, path) {
const protocol_save_path = path || this.#path;
const sequence_type = type || this.#pnseqtype;
const protocol_reset = reset || this.#pnreset;
try {
return protocol(protocol_save_path, sequence_type);
return protocol(protocol_save_path, protocol_reset);
}
catch (error) {
throw error;
......
import { SEQTYPES } from '../../interfaces/index.js';
import { PNRESETTYPES } from '../../interfaces/index.js';
/**
* Generate a new protocol number
* in the format sequence/date
......@@ -6,5 +6,5 @@ import { SEQTYPES } from '../../interfaces/index.js';
* @param protocol_path
* @returns string
*/
declare const protocol: (protocol_path: string, seqtype: SEQTYPES) => string;
declare const protocol: (protocol_path: string, pnreset: PNRESETTYPES) => string;
export default protocol;
......@@ -6,10 +6,10 @@ import sequence from './sequence.js';
* @param protocol_path
* @returns string
*/
const protocol = (protocol_path, seqtype) => {
const protocol = (protocol_path, pnreset) => {
let protocol_split = "aion";
let protocol_date = new Date().toISOString().split('T')[0];
switch (seqtype) {
switch (pnreset) {
case "daily":
protocol_split = protocol_date;
break;
......@@ -24,7 +24,7 @@ const protocol = (protocol_path, seqtype) => {
break;
}
const path = `${protocol_path}/${protocol_split}.protocol.sequence`;
const protocol_sequence = sequence(path, path); //Protocol starts from 1 each day.
const protocol_sequence = sequence(path, path); //Protocol starts from 1 depent on pnreset.
let pn = protocol_sequence + "/" + protocol_date;
return pn;
};
......
......@@ -19,7 +19,7 @@ export interface AuditEngine {
put: (record: AuditRecord) => AuditRecord | Promise<AuditRecord>;
get: (auditTransactionId: string) => AuditRecord | Promise<AuditRecord>;
seq: (path?: string) => number | Promise<number>;
pn: (type?: "daily" | "monthly" | "yearly" | "innumerable", path?: string) => string | Promise<string>;
pn: (reset?: "daily" | "monthly" | "yearly" | "innumerable", path?: string) => string | Promise<string>;
}
/**
* @description FileSystem errors
......@@ -28,7 +28,7 @@ export declare type FS_ERROR = {
code: string;
message: string;
};
export declare type SEQTYPES = "daily" | "monthly" | "yearly" | "innumerable";
export declare type PNRESETTYPES = "daily" | "monthly" | "yearly" | "innumerable";
/**
* @description Schema to be used to store the audit records on real databases
*/
......
import { AuditRecord, AuditEngine, SEQTYPES } from '../interfaces/index.js';
import { AuditRecord, AuditEngine, PNRESETTYPES } from '../interfaces/index.js';
/**
* @description AuditEngine implementation
* @note This class uses AuditEngine implemetations, look at FileEngine.ts for an example
......@@ -34,12 +34,12 @@ export declare class db {
seq(path?: string): Promise<number>;
/**
* @description Generate a new protocol string
* @param type:SEQTYPES
* @param type:PNRESETTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
pn(type?: SEQTYPES, path?: string): Promise<string>;
pn(reset?: PNRESETTYPES, path?: string): Promise<string>;
}
export default db;
......@@ -45,14 +45,14 @@ export class db {
}
/**
* @description Generate a new protocol string
* @param type:SEQTYPES
* @param type:PNRESETTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
async pn(type, path) {
return await this.engine.pn(type, path);
async pn(reset, path) {
return await this.engine.pn(reset, path);
}
}
export default db;
//Use File System as DB storage
import fs from 'fs';
import { AuditRecord, AuditEngine, SEQTYPES } from '../../interfaces/index.js';
import { AuditRecord, AuditEngine, PNRESETTYPES } from '../../interfaces/index.js';
import protocol from './protocol.js';
import sequence from './sequence.js';
......@@ -10,15 +10,15 @@ import sequence from './sequence.js';
* @class FileEngine
* @implements AuditEngine
* @param {string} path - path to store the records
* @param {SEQTYPES} pnseqtype - protocol number sequence type
* @param {PNRESETTYPES} pnreset - protocol number sequence type
*/
export class FileEngine implements AuditEngine {
#path: string
#pnseqtype:SEQTYPES
#pnreset:PNRESETTYPES
constructor(path?: string, pnseqtype?: SEQTYPES) {
constructor(path?: string, pnreset?: PNRESETTYPES) {
this.#path = path?path:"/tmp";
this.#pnseqtype = pnseqtype || "innumerable";
this.#pnreset = pnreset || "innumerable";
}
/**
......@@ -78,11 +78,11 @@ export class FileEngine implements AuditEngine {
* @memberof FileEngine
* @method protocol
*/
pn(type?:SEQTYPES, path?: string): string {
pn(reset?:PNRESETTYPES, path?: string): string {
const protocol_save_path = path || this.#path;
const sequence_type = type || this.#pnseqtype;
const protocol_reset = reset || this.#pnreset;
try {
return protocol(protocol_save_path,sequence_type)
return protocol(protocol_save_path,protocol_reset)
} catch (error) {
throw error;
}
......
import sequence from './sequence.js';
import { SEQTYPES } from '../../interfaces/index.js';
import { PNRESETTYPES } from '../../interfaces/index.js';
/**
* Generate a new protocol number
* in the format sequence/date
......@@ -7,10 +7,10 @@ import { SEQTYPES } from '../../interfaces/index.js';
* @param protocol_path
* @returns string
*/
const protocol = (protocol_path: string,seqtype:SEQTYPES) => {
const protocol = (protocol_path: string,pnreset:PNRESETTYPES) => {
let protocol_split = "aion";
let protocol_date = new Date().toISOString().split('T')[0];
switch(seqtype){
switch(pnreset){
case "daily":
protocol_split = protocol_date;
break;
......@@ -25,7 +25,7 @@ const protocol = (protocol_path: string,seqtype:SEQTYPES) => {
break;
}
const path = `${protocol_path}/${protocol_split}.protocol.sequence`;
const protocol_sequence = sequence(path, path);//Protocol starts from 1 each day.
const protocol_sequence = sequence(path, path);//Protocol starts from 1 depent on pnreset.
let pn = protocol_sequence + "/" + protocol_date;
return pn;
}
......
......@@ -20,7 +20,7 @@ export interface AuditEngine {
put: (record: AuditRecord) => AuditRecord | Promise<AuditRecord>;
get: (auditTransactionId: string) => AuditRecord | Promise<AuditRecord>;
seq: (path?: string) => number | Promise<number>; //Generate a new sequence number
pn: (type?:"daily"|"monthly"|"yearly"|"innumerable",path?: string) => string | Promise<string>; //Generate a new protocol string
pn: (reset?:"daily"|"monthly"|"yearly"|"innumerable",path?: string) => string | Promise<string>; //Generate a new protocol string
}
/**
......@@ -31,7 +31,7 @@ export type FS_ERROR = {
message: string
}
export type SEQTYPES = "daily"|"monthly"|"yearly"|"innumerable";
export type PNRESETTYPES = "daily"|"monthly"|"yearly"|"innumerable";
/**
* @description Schema to be used to store the audit records on real databases
......
import { AuditRecord, AuditEngine, SEQTYPES } from '../interfaces/index.js';
import { AuditRecord, AuditEngine, PNRESETTYPES } from '../interfaces/index.js';
/**
* @description AuditEngine implementation
......@@ -49,14 +49,14 @@ export class db {
/**
* @description Generate a new protocol string
* @param type:SEQTYPES
* @param type:PNRESETTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
async pn(type?: SEQTYPES, path?: string): Promise<string> {
return await this.engine.pn(type, path);
async pn(reset?: PNRESETTYPES, path?: string): Promise<string> {
return await this.engine.pn(reset, path);
}
}
......
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