Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DigiGov-OSS
AuditRecordDB
Commits
9af07bd6
Commit
9af07bd6
authored
Feb 17, 2022
by
Panagiotis Skarvelis
Browse files
refactor reset var names
parent
3e301872
Changes
18
Hide whitespace changes
Inline
Side-by-side
dist/cjs/engines/file/FileEngine.d.ts
View file @
9af07bd6
import
{
AuditRecord
,
AuditEngine
,
SE
Q
TYPES
}
from
'
../../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
PNRE
SE
T
TYPES
}
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 {SE
Q
TYPES} pn
seqtype
- protocol number sequence type
* @param {
PNRE
SE
T
TYPES} pn
reset
- protocol number sequence type
*/
export
declare
class
FileEngine
implements
AuditEngine
{
#
private
;
constructor
(
path
?:
string
,
pn
seqtype
?:
SE
Q
TYPES
);
constructor
(
path
?:
string
,
pn
reset
?:
PNRE
SE
T
TYPES
);
/**
* @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
?:
SE
Q
TYPES
,
path
?:
string
):
string
;
pn
(
reset
?:
PNRE
SE
T
TYPES
,
path
?:
string
):
string
;
}
export
default
FileEngine
;
dist/cjs/engines/file/FileEngine.js
View file @
9af07bd6
...
...
@@ -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_pn
seqtype
;
var
_FileEngine_path
,
_FileEngine_pn
reset
;
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 {SE
Q
TYPES} pn
seqtype
- protocol number sequence type
* @param {
PNRE
SE
T
TYPES} pn
reset
- protocol number sequence type
*/
class
FileEngine
{
constructor
(
path
,
pn
seqtype
)
{
constructor
(
path
,
pn
reset
)
{
_FileEngine_path
.
set
(
this
,
void
0
);
_FileEngine_pn
seqtype
.
set
(
this
,
void
0
);
_FileEngine_pn
reset
.
set
(
this
,
void
0
);
__classPrivateFieldSet
(
this
,
_FileEngine_path
,
path
?
path
:
"
/tmp
"
,
"
f
"
);
__classPrivateFieldSet
(
this
,
_FileEngine_pn
seqtype
,
pnseqtype
||
"
innumerable
"
,
"
f
"
);
__classPrivateFieldSet
(
this
,
_FileEngine_pn
reset
,
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_pn
seqtype
,
"
f
"
);
const
protocol_reset
=
reset
||
__classPrivateFieldGet
(
this
,
_FileEngine_pn
reset
,
"
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_pn
seqtype
=
new
WeakMap
();
_FileEngine_path
=
new
WeakMap
(),
_FileEngine_pn
reset
=
new
WeakMap
();
exports
.
default
=
FileEngine
;
dist/cjs/engines/file/protocol.d.ts
View file @
9af07bd6
import
{
SE
Q
TYPES
}
from
'
../../interfaces/index.js
'
;
import
{
PNRE
SE
T
TYPES
}
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
:
SE
Q
TYPES
)
=>
string
;
declare
const
protocol
:
(
protocol_path
:
string
,
pnreset
:
PNRE
SE
T
TYPES
)
=>
string
;
export
default
protocol
;
dist/cjs/engines/file/protocol.js
View file @
9af07bd6
...
...
@@ -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
;
};
...
...
dist/cjs/interfaces/index.d.ts
View file @
9af07bd6
...
...
@@ -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
SE
Q
TYPES
=
"
daily
"
|
"
monthly
"
|
"
yearly
"
|
"
innumerable
"
;
export
declare
type
PNRE
SE
T
TYPES
=
"
daily
"
|
"
monthly
"
|
"
yearly
"
|
"
innumerable
"
;
/**
* @description Schema to be used to store the audit records on real databases
*/
...
...
dist/cjs/lib/db.d.ts
View file @
9af07bd6
import
{
AuditRecord
,
AuditEngine
,
SE
Q
TYPES
}
from
'
../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
PNRE
SE
T
TYPES
}
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:SE
Q
TYPES
* @param type:
PNRE
SE
T
TYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
pn
(
type
?:
SE
Q
TYPES
,
path
?:
string
):
Promise
<
string
>
;
pn
(
reset
?:
PNRE
SE
T
TYPES
,
path
?:
string
):
Promise
<
string
>
;
}
export
default
db
;
dist/cjs/lib/db.js
View file @
9af07bd6
...
...
@@ -62,15 +62,15 @@ class db {
}
/**
* @description Generate a new protocol string
* @param type:SE
Q
TYPES
* @param type:
PNRE
SE
T
TYPES
* @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
);
});
}
}
...
...
dist/esm/engines/file/FileEngine.d.ts
View file @
9af07bd6
import
{
AuditRecord
,
AuditEngine
,
SE
Q
TYPES
}
from
'
../../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
PNRE
SE
T
TYPES
}
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 {SE
Q
TYPES} pn
seqtype
- protocol number sequence type
* @param {
PNRE
SE
T
TYPES} pn
reset
- protocol number sequence type
*/
export
declare
class
FileEngine
implements
AuditEngine
{
#
private
;
constructor
(
path
?:
string
,
pn
seqtype
?:
SE
Q
TYPES
);
constructor
(
path
?:
string
,
pn
reset
?:
PNRE
SE
T
TYPES
);
/**
* @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
?:
SE
Q
TYPES
,
path
?:
string
):
string
;
pn
(
reset
?:
PNRE
SE
T
TYPES
,
path
?:
string
):
string
;
}
export
default
FileEngine
;
dist/esm/engines/file/FileEngine.js
View file @
9af07bd6
...
...
@@ -8,14 +8,14 @@ import sequence from './sequence.js';
* @class FileEngine
* @implements AuditEngine
* @param {string} path - path to store the records
* @param {SE
Q
TYPES} pn
seqtype
- protocol number sequence type
* @param {
PNRE
SE
T
TYPES} pn
reset
- protocol number sequence type
*/
export
class
FileEngine
{
#
path
;
#
pn
seqtype
;
constructor
(
path
,
pn
seqtype
)
{
#
pn
reset
;
constructor
(
path
,
pn
reset
)
{
this
.
#
path
=
path
?
path
:
"
/tmp
"
;
this
.
#
pn
seqtype
=
pnseqtype
||
"
innumerable
"
;
this
.
#
pn
reset
=
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
.
#
pn
seqtype
;
const
protocol_reset
=
reset
||
this
.
#
pn
reset
;
try
{
return
protocol
(
protocol_save_path
,
sequence_type
);
return
protocol
(
protocol_save_path
,
protocol_reset
);
}
catch
(
error
)
{
throw
error
;
...
...
dist/esm/engines/file/protocol.d.ts
View file @
9af07bd6
import
{
SE
Q
TYPES
}
from
'
../../interfaces/index.js
'
;
import
{
PNRE
SE
T
TYPES
}
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
:
SE
Q
TYPES
)
=>
string
;
declare
const
protocol
:
(
protocol_path
:
string
,
pnreset
:
PNRE
SE
T
TYPES
)
=>
string
;
export
default
protocol
;
dist/esm/engines/file/protocol.js
View file @
9af07bd6
...
...
@@ -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
;
};
...
...
dist/esm/interfaces/index.d.ts
View file @
9af07bd6
...
...
@@ -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
SE
Q
TYPES
=
"
daily
"
|
"
monthly
"
|
"
yearly
"
|
"
innumerable
"
;
export
declare
type
PNRE
SE
T
TYPES
=
"
daily
"
|
"
monthly
"
|
"
yearly
"
|
"
innumerable
"
;
/**
* @description Schema to be used to store the audit records on real databases
*/
...
...
dist/esm/lib/db.d.ts
View file @
9af07bd6
import
{
AuditRecord
,
AuditEngine
,
SE
Q
TYPES
}
from
'
../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
PNRE
SE
T
TYPES
}
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:SE
Q
TYPES
* @param type:
PNRE
SE
T
TYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
pn
(
type
?:
SE
Q
TYPES
,
path
?:
string
):
Promise
<
string
>
;
pn
(
reset
?:
PNRE
SE
T
TYPES
,
path
?:
string
):
Promise
<
string
>
;
}
export
default
db
;
dist/esm/lib/db.js
View file @
9af07bd6
...
...
@@ -45,14 +45,14 @@ export class db {
}
/**
* @description Generate a new protocol string
* @param type:SE
Q
TYPES
* @param type:
PNRE
SE
T
TYPES
* @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
;
src/engines/file/FileEngine.ts
View file @
9af07bd6
//Use File System as DB storage
import
fs
from
'
fs
'
;
import
{
AuditRecord
,
AuditEngine
,
SE
Q
TYPES
}
from
'
../../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
PNRE
SE
T
TYPES
}
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 {SE
Q
TYPES} pn
seqtype
- protocol number sequence type
* @param {
PNRE
SE
T
TYPES} pn
reset
- protocol number sequence type
*/
export
class
FileEngine
implements
AuditEngine
{
#
path
:
string
#
pn
seqtype
:
SE
Q
TYPES
#
pn
reset
:
PNRE
SE
T
TYPES
constructor
(
path
?:
string
,
pn
seqtype
?:
SE
Q
TYPES
)
{
constructor
(
path
?:
string
,
pn
reset
?:
PNRE
SE
T
TYPES
)
{
this
.
#
path
=
path
?
path
:
"
/tmp
"
;
this
.
#
pn
seqtype
=
pnseqtype
||
"
innumerable
"
;
this
.
#
pn
reset
=
pnreset
||
"
innumerable
"
;
}
/**
...
...
@@ -78,11 +78,11 @@ export class FileEngine implements AuditEngine {
* @memberof FileEngine
* @method protocol
*/
pn
(
type
?:
SE
Q
TYPES
,
path
?:
string
):
string
{
pn
(
reset
?:
PNRE
SE
T
TYPES
,
path
?:
string
):
string
{
const
protocol_save_path
=
path
||
this
.
#
path
;
const
sequence_type
=
type
||
this
.
#
pn
seqtype
;
const
protocol_reset
=
reset
||
this
.
#
pn
reset
;
try
{
return
protocol
(
protocol_save_path
,
sequence_type
)
return
protocol
(
protocol_save_path
,
protocol_reset
)
}
catch
(
error
)
{
throw
error
;
}
...
...
src/engines/file/protocol.ts
View file @
9af07bd6
import
sequence
from
'
./sequence.js
'
;
import
{
SE
Q
TYPES
}
from
'
../../interfaces/index.js
'
;
import
{
PNRE
SE
T
TYPES
}
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
:
SE
Q
TYPES
)
=>
{
const
protocol
=
(
protocol_path
:
string
,
pnreset
:
PNRE
SE
T
TYPES
)
=>
{
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
;
}
...
...
src/interfaces/index.ts
View file @
9af07bd6
...
...
@@ -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
SE
Q
TYPES
=
"
daily
"
|
"
monthly
"
|
"
yearly
"
|
"
innumerable
"
;
export
type
PNRE
SE
T
TYPES
=
"
daily
"
|
"
monthly
"
|
"
yearly
"
|
"
innumerable
"
;
/**
* @description Schema to be used to store the audit records on real databases
...
...
src/lib/db.ts
View file @
9af07bd6
import
{
AuditRecord
,
AuditEngine
,
SE
Q
TYPES
}
from
'
../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
PNRE
SE
T
TYPES
}
from
'
../interfaces/index.js
'
;
/**
* @description AuditEngine implementation
...
...
@@ -49,14 +49,14 @@ export class db {
/**
* @description Generate a new protocol string
* @param type:SE
Q
TYPES
* @param type:
PNRE
SE
T
TYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
async
pn
(
type
?:
SE
Q
TYPES
,
path
?:
string
):
Promise
<
string
>
{
return
await
this
.
engine
.
pn
(
type
,
path
);
async
pn
(
reset
?:
PNRE
SE
T
TYPES
,
path
?:
string
):
Promise
<
string
>
{
return
await
this
.
engine
.
pn
(
reset
,
path
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment