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
455039ff
Commit
455039ff
authored
Feb 16, 2022
by
Panagiotis Skarvelis
Browse files
allow select for seq split
parent
72b10e36
Changes
23
Hide whitespace changes
Inline
Side-by-side
dist/cjs/engines/file/FileEngine.d.ts
View file @
455039ff
import
{
AuditRecord
,
AuditEngine
}
from
'
../../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
SEQTYPES
}
from
'
../../interfaces/index.js
'
;
/**
* @description AuditEngine implementation
* @note This class is used to implement the methods that must be implemented by the AuditEngine
...
...
@@ -35,11 +35,12 @@ export declare class FileEngine implements AuditEngine {
seq
(
path
?:
string
):
number
;
/**
* @description Generate a new protocol number
* @param path
* @param type: SEQTYPES
* @param path: string
* @returns string
* @memberof FileEngine
* @method protocol
*/
pn
(
path
?:
string
):
string
;
pn
(
type
?:
SEQTYPES
,
path
?:
string
):
string
;
}
export
default
FileEngine
;
dist/cjs/engines/file/FileEngine.js
View file @
455039ff
...
...
@@ -83,15 +83,17 @@ class FileEngine {
}
/**
* @description Generate a new protocol number
* @param path
* @param type: SEQTYPES
* @param path: string
* @returns string
* @memberof FileEngine
* @method protocol
*/
pn
(
path
)
{
pn
(
type
,
path
)
{
const
protocol_save_path
=
path
||
__classPrivateFieldGet
(
this
,
_FileEngine_path
,
"
f
"
);
const
sequence_type
=
type
||
"
innumerable
"
;
try
{
return
(
0
,
protocol_js_1
.
default
)(
protocol_save_path
);
return
(
0
,
protocol_js_1
.
default
)(
protocol_save_path
,
sequence_type
);
}
catch
(
error
)
{
throw
error
;
...
...
dist/cjs/engines/file/protocol.d.ts
View file @
455039ff
import
{
SEQTYPES
}
from
'
../../interfaces/index.js
'
;
/**
* Generate a new protocol number
* in the format sequence/date
...
...
@@ -5,5 +6,5 @@
* @param protocol_path
* @returns string
*/
declare
const
protocol
:
(
protocol_path
:
string
)
=>
string
;
declare
const
protocol
:
(
protocol_path
:
string
,
seqtype
:
SEQTYPES
)
=>
string
;
export
default
protocol
;
dist/cjs/engines/file/protocol.js
View file @
455039ff
...
...
@@ -11,11 +11,25 @@ const sequence_js_1 = __importDefault(require("./sequence.js"));
* @param protocol_path
* @returns string
*/
const
protocol
=
(
protocol_path
)
=>
{
const
protocol_date
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
];
const
path
=
`
${
protocol_path
}
/
${
protocol_date
}
.protocol.sequence`
;
const
protocol
=
(
protocol_path
,
seqtype
)
=>
{
let
protocol_split
=
"
aion
"
;
switch
(
seqtype
)
{
case
"
daily
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
];
break
;
case
"
monthly
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
].
split
(
'
-
'
)[
1
];
break
;
case
"
yearly
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
].
split
(
'
-
'
)[
0
];
break
;
case
"
innumerable
"
:
protocol_split
=
"
aion
"
;
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.
let
pn
=
protocol_sequence
+
"
/
"
+
protocol_
date
;
let
pn
=
protocol_sequence
+
"
/
"
+
protocol_
split
;
return
pn
;
};
exports
.
default
=
protocol
;
dist/cjs/index.js
View file @
455039ff
...
...
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
PostgreSqlEngine
=
exports
.
FileEngine
=
exports
.
generateAuditRecord
=
void
0
;
exports
.
FileEngine
=
exports
.
generateAuditRecord
=
void
0
;
const
db_js_1
=
__importDefault
(
require
(
"
./lib/db.js
"
));
const
index_js_1
=
require
(
"
./engines/index.js
"
);
/**
...
...
@@ -55,4 +55,3 @@ exports.generateAuditRecord = generateAuditRecord;
exports
.
default
=
exports
.
generateAuditRecord
;
var
index_js_2
=
require
(
"
./engines/index.js
"
);
Object
.
defineProperty
(
exports
,
"
FileEngine
"
,
{
enumerable
:
true
,
get
:
function
()
{
return
index_js_2
.
FileEngine
;
}
});
Object
.
defineProperty
(
exports
,
"
PostgreSqlEngine
"
,
{
enumerable
:
true
,
get
:
function
()
{
return
index_js_2
.
PostgreSqlEngine
;
}
});
dist/cjs/interfaces/index.d.ts
View file @
455039ff
...
...
@@ -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
:
(
path
?:
string
)
=>
string
|
Promise
<
string
>
;
pn
:
(
type
?:
"
daily
"
|
"
monthly
"
|
"
yearly
"
|
"
innumerable
"
,
path
?:
string
)
=>
string
|
Promise
<
string
>
;
}
/**
* @description FileSystem errors
...
...
@@ -28,6 +28,7 @@ export declare type FS_ERROR = {
code
:
string
;
message
:
string
;
};
export
declare
type
SEQTYPES
=
"
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 @
455039ff
import
{
AuditRecord
,
AuditEngine
}
from
'
../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
SEQTYPES
}
from
'
../interfaces/index.js
'
;
/**
* @description AuditEngine implementation
* @note This class uses AuditEngine implemetations, look at FileEngine.ts for an example
...
...
@@ -10,7 +10,7 @@ export declare class db {
constructor
(
engine
:
AuditEngine
);
/**
* @description Store a record in the database
* @param record
* @param record
:AuditRecord
* @returns Promise<AuditRecord>
* @memberof db
* @method put
...
...
@@ -18,7 +18,7 @@ export declare class db {
put
(
record
:
AuditRecord
):
Promise
<
AuditRecord
>
;
/**
* @description Get a record from the database
* @param auditTransactionId
* @param auditTransactionId
:string
* @returns Promise<AuditRecord>
* @memberof db
* @method get
...
...
@@ -26,7 +26,7 @@ export declare class db {
get
(
auditTransactionId
:
string
):
Promise
<
AuditRecord
>
;
/**
* @description Generate a new sequence number
* @param path
* @param path
:string
* @returns Promise<number>
* @memberof db
* @method seq
...
...
@@ -34,11 +34,12 @@ export declare class db {
seq
(
path
?:
string
):
Promise
<
number
>
;
/**
* @description Generate a new protocol string
* @param path
* @param type:SEQTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
pn
(
path
?:
string
):
Promise
<
string
>
;
pn
(
type
?:
SEQTYPES
,
path
?:
string
):
Promise
<
string
>
;
}
export
default
db
;
dist/cjs/lib/db.js
View file @
455039ff
...
...
@@ -22,7 +22,7 @@ class db {
}
/**
* @description Store a record in the database
* @param record
* @param record
:AuditRecord
* @returns Promise<AuditRecord>
* @memberof db
* @method put
...
...
@@ -36,7 +36,7 @@ class db {
}
/**
* @description Get a record from the database
* @param auditTransactionId
* @param auditTransactionId
:string
* @returns Promise<AuditRecord>
* @memberof db
* @method get
...
...
@@ -50,7 +50,7 @@ class db {
}
/**
* @description Generate a new sequence number
* @param path
* @param path
:string
* @returns Promise<number>
* @memberof db
* @method seq
...
...
@@ -62,14 +62,15 @@ class db {
}
/**
* @description Generate a new protocol string
* @param path
* @param type:SEQTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
pn
(
path
)
{
pn
(
type
,
path
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
return
yield
this
.
engine
.
pn
(
path
);
return
yield
this
.
engine
.
pn
(
type
,
path
);
});
}
}
...
...
dist/esm/engines/file/FileEngine.d.ts
View file @
455039ff
import
{
AuditRecord
,
AuditEngine
}
from
'
../../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
SEQTYPES
}
from
'
../../interfaces/index.js
'
;
/**
* @description AuditEngine implementation
* @note This class is used to implement the methods that must be implemented by the AuditEngine
...
...
@@ -35,11 +35,12 @@ export declare class FileEngine implements AuditEngine {
seq
(
path
?:
string
):
number
;
/**
* @description Generate a new protocol number
* @param path
* @param type: SEQTYPES
* @param path: string
* @returns string
* @memberof FileEngine
* @method protocol
*/
pn
(
path
?:
string
):
string
;
pn
(
type
?:
SEQTYPES
,
path
?:
string
):
string
;
}
export
default
FileEngine
;
dist/esm/engines/file/FileEngine.js
View file @
455039ff
...
...
@@ -65,15 +65,17 @@ export class FileEngine {
}
/**
* @description Generate a new protocol number
* @param path
* @param type: SEQTYPES
* @param path: string
* @returns string
* @memberof FileEngine
* @method protocol
*/
pn
(
path
)
{
pn
(
type
,
path
)
{
const
protocol_save_path
=
path
||
this
.
#
path
;
const
sequence_type
=
type
||
"
innumerable
"
;
try
{
return
protocol
(
protocol_save_path
);
return
protocol
(
protocol_save_path
,
sequence_type
);
}
catch
(
error
)
{
throw
error
;
...
...
dist/esm/engines/file/protocol.d.ts
View file @
455039ff
import
{
SEQTYPES
}
from
'
../../interfaces/index.js
'
;
/**
* Generate a new protocol number
* in the format sequence/date
...
...
@@ -5,5 +6,5 @@
* @param protocol_path
* @returns string
*/
declare
const
protocol
:
(
protocol_path
:
string
)
=>
string
;
declare
const
protocol
:
(
protocol_path
:
string
,
seqtype
:
SEQTYPES
)
=>
string
;
export
default
protocol
;
dist/esm/engines/file/protocol.js
View file @
455039ff
...
...
@@ -6,11 +6,25 @@ import sequence from './sequence.js';
* @param protocol_path
* @returns string
*/
const
protocol
=
(
protocol_path
)
=>
{
const
protocol_date
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
];
const
path
=
`
${
protocol_path
}
/
${
protocol_date
}
.protocol.sequence`
;
const
protocol
=
(
protocol_path
,
seqtype
)
=>
{
let
protocol_split
=
"
aion
"
;
switch
(
seqtype
)
{
case
"
daily
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
];
break
;
case
"
monthly
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
].
split
(
'
-
'
)[
1
];
break
;
case
"
yearly
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
].
split
(
'
-
'
)[
0
];
break
;
case
"
innumerable
"
:
protocol_split
=
"
aion
"
;
break
;
}
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_
date
;
let
pn
=
protocol_sequence
+
"
/
"
+
protocol_
split
;
return
pn
;
};
export
default
protocol
;
dist/esm/index.d.ts
View file @
455039ff
...
...
@@ -11,5 +11,5 @@ import { AuditRecord, AuditEngine } from './interfaces/index.js';
*/
export
declare
const
generateAuditRecord
:
(
auditInit
?:
AuditRecord
|
undefined
,
dbEngine
?:
AuditEngine
|
undefined
)
=>
Promise
<
AuditRecord
|
null
>
;
export
default
generateAuditRecord
;
export
{
FileEngine
,
PostgreSqlEngine
}
from
'
./engines/index.js
'
;
export
{
AuditRecord
,
AuditEngine
,
FS_ERROR
}
from
'
./interfaces/index.js
'
;
export
{
FileEngine
}
from
'
./engines/index.js
'
;
export
{
AuditRecord
,
AuditEngine
,
DatabaseSettings
,
FS_ERROR
}
from
'
./interfaces/index.js
'
;
dist/esm/index.js
View file @
455039ff
...
...
@@ -37,4 +37,4 @@ export const generateAuditRecord = async (auditInit, dbEngine) => {
}
};
export
default
generateAuditRecord
;
export
{
FileEngine
,
PostgreSqlEngine
}
from
'
./engines/index.js
'
;
export
{
FileEngine
}
from
'
./engines/index.js
'
;
dist/esm/interfaces/index.d.ts
View file @
455039ff
...
...
@@ -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
:
(
path
?:
string
)
=>
string
|
Promise
<
string
>
;
pn
:
(
type
?:
"
daily
"
|
"
monthly
"
|
"
yearly
"
|
"
innumerable
"
,
path
?:
string
)
=>
string
|
Promise
<
string
>
;
}
/**
* @description FileSystem errors
...
...
@@ -28,6 +28,7 @@ export declare type FS_ERROR = {
code
:
string
;
message
:
string
;
};
export
declare
type
SEQTYPES
=
"
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 @
455039ff
import
{
AuditRecord
,
AuditEngine
}
from
'
../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
SEQTYPES
}
from
'
../interfaces/index.js
'
;
/**
* @description AuditEngine implementation
* @note This class uses AuditEngine implemetations, look at FileEngine.ts for an example
...
...
@@ -10,7 +10,7 @@ export declare class db {
constructor
(
engine
:
AuditEngine
);
/**
* @description Store a record in the database
* @param record
* @param record
:AuditRecord
* @returns Promise<AuditRecord>
* @memberof db
* @method put
...
...
@@ -18,7 +18,7 @@ export declare class db {
put
(
record
:
AuditRecord
):
Promise
<
AuditRecord
>
;
/**
* @description Get a record from the database
* @param auditTransactionId
* @param auditTransactionId
:string
* @returns Promise<AuditRecord>
* @memberof db
* @method get
...
...
@@ -26,7 +26,7 @@ export declare class db {
get
(
auditTransactionId
:
string
):
Promise
<
AuditRecord
>
;
/**
* @description Generate a new sequence number
* @param path
* @param path
:string
* @returns Promise<number>
* @memberof db
* @method seq
...
...
@@ -34,11 +34,12 @@ export declare class db {
seq
(
path
?:
string
):
Promise
<
number
>
;
/**
* @description Generate a new protocol string
* @param path
* @param type:SEQTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
pn
(
path
?:
string
):
Promise
<
string
>
;
pn
(
type
?:
SEQTYPES
,
path
?:
string
):
Promise
<
string
>
;
}
export
default
db
;
dist/esm/lib/db.js
View file @
455039ff
...
...
@@ -11,7 +11,7 @@ export class db {
}
/**
* @description Store a record in the database
* @param record
* @param record
:AuditRecord
* @returns Promise<AuditRecord>
* @memberof db
* @method put
...
...
@@ -23,7 +23,7 @@ export class db {
}
/**
* @description Get a record from the database
* @param auditTransactionId
* @param auditTransactionId
:string
* @returns Promise<AuditRecord>
* @memberof db
* @method get
...
...
@@ -35,7 +35,7 @@ export class db {
}
/**
* @description Generate a new sequence number
* @param path
* @param path
:string
* @returns Promise<number>
* @memberof db
* @method seq
...
...
@@ -45,13 +45,14 @@ export class db {
}
/**
* @description Generate a new protocol string
* @param path
* @param type:SEQTYPES
* @param path:string
* @returns string
* @memberof db
* @method pn
*/
async
pn
(
path
)
{
return
await
this
.
engine
.
pn
(
path
);
async
pn
(
type
,
path
)
{
return
await
this
.
engine
.
pn
(
type
,
path
);
}
}
export
default
db
;
src/engines/file/FileEngine.ts
View file @
455039ff
//Use File System as DB storage
import
fs
from
'
fs
'
;
import
{
AuditRecord
,
AuditEngine
}
from
'
../../interfaces/index.js
'
;
import
{
AuditRecord
,
AuditEngine
,
SEQTYPES
}
from
'
../../interfaces/index.js
'
;
import
protocol
from
'
./protocol.js
'
;
import
sequence
from
'
./sequence.js
'
;
...
...
@@ -69,15 +69,17 @@ export class FileEngine implements AuditEngine {
/**
* @description Generate a new protocol number
* @param path
* @param type: SEQTYPES
* @param path: string
* @returns string
* @memberof FileEngine
* @method protocol
*/
pn
(
path
?:
string
):
string
{
pn
(
type
?:
SEQTYPES
,
path
?:
string
):
string
{
const
protocol_save_path
=
path
||
this
.
#
path
;
const
sequence_type
=
type
||
"
innumerable
"
;
try
{
return
protocol
(
protocol_save_path
)
return
protocol
(
protocol_save_path
,
sequence_type
)
}
catch
(
error
)
{
throw
error
;
}
...
...
src/engines/file/protocol.ts
View file @
455039ff
import
sequence
from
'
./sequence.js
'
;
import
{
SEQTYPES
}
from
'
../../interfaces/index.js
'
;
/**
* Generate a new protocol number
* in the format sequence/date
...
...
@@ -7,11 +7,25 @@ import sequence from './sequence.js';
* @param protocol_path
* @returns string
*/
const
protocol
=
(
protocol_path
:
string
)
=>
{
const
protocol_date
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
];
const
path
=
`
${
protocol_path
}
/
${
protocol_date
}
.protocol.sequence`
;
const
protocol
=
(
protocol_path
:
string
,
seqtype
:
SEQTYPES
)
=>
{
let
protocol_split
=
"
aion
"
;
switch
(
seqtype
){
case
"
daily
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
];
break
;
case
"
monthly
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
].
split
(
'
-
'
)[
1
];
break
;
case
"
yearly
"
:
protocol_split
=
new
Date
().
toISOString
().
split
(
'
T
'
)[
0
].
split
(
'
-
'
)[
0
];
break
;
case
"
innumerable
"
:
protocol_split
=
"
aion
"
;
break
;
}
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_
date
;
let
pn
=
protocol_sequence
+
"
/
"
+
protocol_
split
;
return
pn
;
}
...
...
src/engines/index.ts
View file @
455039ff
export
{
default
as
FileEngine
}
from
"
./file/FileEngine.js
"
;
// Language: typescript, note the extension, sould be .js! even if it is .ts for esm to work correctly
export
{
default
as
PostgreSqlEngine
}
from
"
./postgresql/PostgreSqlEngine.js
"
;
Prev
1
2
Next
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