@leyyo/common 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/aliases.d.ts +139 -0
- package/dist/aliases.js +4 -0
- package/dist/assertion/assert.d.ts +6 -0
- package/dist/assertion/assert.js +13 -0
- package/dist/assertion/common-assertion-impl.d.ts +34 -0
- package/dist/assertion/common-assertion-impl.js +210 -0
- package/dist/assertion/index-types.d.ts +79 -0
- package/dist/assertion/index-types.js +2 -0
- package/dist/assertion/index.d.ts +3 -0
- package/dist/assertion/index.js +19 -0
- package/dist/callback/common-callback-impl.d.ts +31 -0
- package/dist/callback/common-callback-impl.js +134 -0
- package/dist/callback/index-types.d.ts +75 -0
- package/dist/callback/index-types.js +2 -0
- package/dist/callback/index.d.ts +2 -0
- package/dist/callback/index.js +18 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +10 -0
- package/dist/error/assertion-exception.d.ts +5 -0
- package/dist/error/assertion-exception.js +11 -0
- package/dist/error/caused-exception.d.ts +5 -0
- package/dist/error/caused-exception.js +12 -0
- package/dist/error/common-error-impl.d.ts +24 -0
- package/dist/error/common-error-impl.js +88 -0
- package/dist/error/developer-exception.d.ts +5 -0
- package/dist/error/developer-exception.js +11 -0
- package/dist/error/exception.d.ts +33 -0
- package/dist/error/exception.js +124 -0
- package/dist/error/index-types.d.ts +70 -0
- package/dist/error/index-types.js +2 -0
- package/dist/error/index.d.ts +7 -0
- package/dist/error/index.js +23 -0
- package/dist/error/multiple-exception.d.ts +8 -0
- package/dist/error/multiple-exception.js +33 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +26 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +4 -0
- package/dist/is/common-is-impl.d.ts +22 -0
- package/dist/is/common-is-impl.js +66 -0
- package/dist/is/index-types.d.ts +22 -0
- package/dist/is/index-types.js +2 -0
- package/dist/is/index.d.ts +2 -0
- package/dist/is/index.js +18 -0
- package/dist/leyyo/index-types.d.ts +16 -0
- package/dist/leyyo/index-types.js +2 -0
- package/dist/leyyo/index.d.ts +2 -0
- package/dist/leyyo/index.js +18 -0
- package/dist/leyyo/leyyo-impl.d.ts +24 -0
- package/dist/leyyo/leyyo-impl.js +71 -0
- package/dist/literals.d.ts +98 -0
- package/dist/literals.js +77 -0
- package/dist/log/common-log-impl.d.ts +13 -0
- package/dist/log/common-log-impl.js +59 -0
- package/dist/log/index-types.d.ts +58 -0
- package/dist/log/index-types.js +3 -0
- package/dist/log/index.d.ts +3 -0
- package/dist/log/index.js +19 -0
- package/dist/log/logger-impl.d.ts +23 -0
- package/dist/log/logger-impl.js +73 -0
- package/dist/storage/common-storage-impl.d.ts +46 -0
- package/dist/storage/common-storage-impl.js +150 -0
- package/dist/storage/index-types.d.ts +102 -0
- package/dist/storage/index-types.js +2 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.js +19 -0
- package/dist/storage/list.d.ts +9 -0
- package/dist/storage/list.js +16 -0
- package/dist/to/common-to-impl.d.ts +38 -0
- package/dist/to/common-to-impl.js +553 -0
- package/dist/to/index-types.d.ts +50 -0
- package/dist/to/index-types.js +2 -0
- package/dist/to/index.d.ts +2 -0
- package/dist/to/index.js +18 -0
- package/package.json +53 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonLogImpl = void 0;
|
|
4
|
+
const logger_impl_1 = require("./logger-impl");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
// noinspection JSUnusedLocalSymbols
|
|
7
|
+
class CommonLogImpl {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.create.bind(this);
|
|
10
|
+
this.apply.bind(this);
|
|
11
|
+
this.check.bind(this);
|
|
12
|
+
this.print.bind(this);
|
|
13
|
+
}
|
|
14
|
+
get $secure() {
|
|
15
|
+
throw this;
|
|
16
|
+
}
|
|
17
|
+
$init(leyyo) {
|
|
18
|
+
this.callback = leyyo.callback;
|
|
19
|
+
const fields = ['create', 'apply', 'check', 'print'];
|
|
20
|
+
const rec = { proper: false };
|
|
21
|
+
fields.forEach(field => {
|
|
22
|
+
rec[field] = this[field];
|
|
23
|
+
});
|
|
24
|
+
// define itself temporarily for log operations
|
|
25
|
+
this.callback.defineProvider(constants_1.LY_ATTACHED_LOG, CommonLogImpl, rec);
|
|
26
|
+
// when new log provider is defined, replace all common methods
|
|
27
|
+
this.callback.whenProviderDefined(constants_1.LY_ATTACHED_LOG, CommonLogImpl, (ins) => {
|
|
28
|
+
fields.forEach(field => {
|
|
29
|
+
if (typeof ins[field] === 'function') {
|
|
30
|
+
this[field] = ins[field];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
create(clazz) {
|
|
36
|
+
const ins = new logger_impl_1.LoggerImpl(clazz);
|
|
37
|
+
this.callback.queueForCallback(constants_1.LY_PENDING_LOG_REGISTER, ins, clazz);
|
|
38
|
+
return ins;
|
|
39
|
+
}
|
|
40
|
+
apply(line) {
|
|
41
|
+
if ((global === null || global === void 0 ? void 0 : global.leyyo_is_testing) || !line) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const lineEnhanced = line;
|
|
45
|
+
lineEnhanced.time = new Date();
|
|
46
|
+
this.check(lineEnhanced);
|
|
47
|
+
this.print(lineEnhanced);
|
|
48
|
+
}
|
|
49
|
+
check(line) {
|
|
50
|
+
// nothing
|
|
51
|
+
}
|
|
52
|
+
print(line) {
|
|
53
|
+
console[line.severity](`[${line.time}] ${line.severity} ${line.holder} ${line.message}`, line.params);
|
|
54
|
+
}
|
|
55
|
+
get $back() {
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.CommonLogImpl = CommonLogImpl;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Leyyo } from "../leyyo";
|
|
2
|
+
import { Severity } from "../literals";
|
|
3
|
+
import { Dict, ShiftMain, ShiftSecure } from "../aliases";
|
|
4
|
+
import { CommonCallbackDefined } from "../callback";
|
|
5
|
+
export interface CommonLog extends ShiftSecure<CommonLogSecure>, LogConsumer {
|
|
6
|
+
create(clazz: Object | Function | string): Logger;
|
|
7
|
+
}
|
|
8
|
+
export interface CommonLogCb extends CommonCallbackDefined {
|
|
9
|
+
create?(clazz: Object | Function | string): Logger;
|
|
10
|
+
apply?(line: LogLine): void;
|
|
11
|
+
check?<T>(line: LogLineEnhanced<T>): void;
|
|
12
|
+
print<T>(line: LogLineEnhanced<T>): void;
|
|
13
|
+
}
|
|
14
|
+
export interface CommonLogSecure extends ShiftMain<CommonLog> {
|
|
15
|
+
$init(leyyo: Leyyo): void;
|
|
16
|
+
}
|
|
17
|
+
export interface LogConsumer {
|
|
18
|
+
apply(line: LogLine): void;
|
|
19
|
+
}
|
|
20
|
+
export interface LogLine {
|
|
21
|
+
severity: Severity;
|
|
22
|
+
message: string | Error;
|
|
23
|
+
holder?: string;
|
|
24
|
+
params?: Dict;
|
|
25
|
+
}
|
|
26
|
+
export interface LogLineEnhanced<L = Dict> extends LogLine {
|
|
27
|
+
time?: Date;
|
|
28
|
+
locals?: L;
|
|
29
|
+
}
|
|
30
|
+
export interface Logger extends ShiftSecure<LoggerSecure> {
|
|
31
|
+
error(message: string, params?: any): void;
|
|
32
|
+
error(error: Error, params?: any): void;
|
|
33
|
+
error(whatever: any, params?: any): void;
|
|
34
|
+
warn(message: string, params?: any): void;
|
|
35
|
+
warn(error: Error, params?: any): void;
|
|
36
|
+
warn(whatever: any, params?: any): void;
|
|
37
|
+
info(message: string, params?: any): void;
|
|
38
|
+
info(error: Error, params?: any): void;
|
|
39
|
+
info(whatever: any, params?: any): void;
|
|
40
|
+
log(message: string, params?: any): void;
|
|
41
|
+
log(error: Error, params?: any): void;
|
|
42
|
+
log(whatever: any, params?: any): void;
|
|
43
|
+
trace(message: string, params?: any): void;
|
|
44
|
+
trace(error: Error, params?: any): void;
|
|
45
|
+
trace(whatever: any, params?: any): void;
|
|
46
|
+
debug(message: string, params?: any): void;
|
|
47
|
+
debug(error: Error, params?: any): void;
|
|
48
|
+
debug(whatever: any, params?: any): void;
|
|
49
|
+
}
|
|
50
|
+
export type LogMethod = 'error' | 'warn' | 'info' | 'log' | 'trace' | 'debug';
|
|
51
|
+
export interface LoggerSecure extends ShiftMain<Logger> {
|
|
52
|
+
get $clazz(): Function;
|
|
53
|
+
get $name(): string;
|
|
54
|
+
$assert(error: Error, indicator: string, params?: unknown): void;
|
|
55
|
+
$setName(name: string): void;
|
|
56
|
+
$setMethod(method: LogMethod, lambda?: LoggerLambda): void;
|
|
57
|
+
}
|
|
58
|
+
export type LoggerLambda = (whatever: any, params?: any) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./index-types"), exports);
|
|
18
|
+
__exportStar(require("./logger-impl"), exports);
|
|
19
|
+
__exportStar(require("./common-log-impl"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Logger, LoggerLambda, LoggerSecure, LogMethod } from "./index-types";
|
|
2
|
+
import { Leyyo } from "../leyyo";
|
|
3
|
+
export declare class LoggerImpl implements Logger, LoggerSecure {
|
|
4
|
+
private readonly _clazz;
|
|
5
|
+
private _name;
|
|
6
|
+
private static _callback;
|
|
7
|
+
private static _log;
|
|
8
|
+
constructor(value: Object | Function | string);
|
|
9
|
+
debug(message: any, params?: any): void;
|
|
10
|
+
error(message: any, params?: any): void;
|
|
11
|
+
info(message: any, params?: any): void;
|
|
12
|
+
log(message: any, params?: any): void;
|
|
13
|
+
trace(message: any, params?: any): void;
|
|
14
|
+
warn(message: any, params?: any): void;
|
|
15
|
+
get $back(): Logger;
|
|
16
|
+
get $secure(): LoggerSecure;
|
|
17
|
+
get $clazz(): Function;
|
|
18
|
+
get $name(): string;
|
|
19
|
+
static $setLeyyo(leyyo: Leyyo): void;
|
|
20
|
+
$setName(name: string): void;
|
|
21
|
+
$setMethod(method: LogMethod, lambda?: LoggerLambda): void;
|
|
22
|
+
$assert(error: Error, indicator: string, params?: unknown): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerImpl = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
// noinspection JSUnusedLocalSymbols
|
|
6
|
+
class LoggerImpl {
|
|
7
|
+
constructor(value) {
|
|
8
|
+
switch (typeof value) {
|
|
9
|
+
case "function":
|
|
10
|
+
this._clazz = value;
|
|
11
|
+
this._name = LoggerImpl._callback.fqnName(value);
|
|
12
|
+
break;
|
|
13
|
+
case "object":
|
|
14
|
+
this._clazz = value.constructor;
|
|
15
|
+
this._name = LoggerImpl._callback.fqnName(value);
|
|
16
|
+
break;
|
|
17
|
+
case "string":
|
|
18
|
+
this._name = value;
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
throw new error_1.DeveloperException('invalid.logger.name', { type: typeof value });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
debug(message, params) {
|
|
25
|
+
LoggerImpl._log.apply({ severity: 'debug', message: message, holder: this._name, params: params });
|
|
26
|
+
}
|
|
27
|
+
error(message, params) {
|
|
28
|
+
LoggerImpl._log.apply({ severity: 'error', message: message, holder: this._name, params: params });
|
|
29
|
+
}
|
|
30
|
+
info(message, params) {
|
|
31
|
+
LoggerImpl._log.apply({ severity: 'info', message: message, holder: this._name, params: params });
|
|
32
|
+
}
|
|
33
|
+
log(message, params) {
|
|
34
|
+
LoggerImpl._log.apply({ severity: 'log', message: message, holder: this._name, params: params });
|
|
35
|
+
}
|
|
36
|
+
trace(message, params) {
|
|
37
|
+
LoggerImpl._log.apply({ severity: 'trace', message: message, holder: this._name, params: params });
|
|
38
|
+
}
|
|
39
|
+
warn(message, params) {
|
|
40
|
+
LoggerImpl._log.apply({ severity: 'warn', message: message, holder: this._name, params: params });
|
|
41
|
+
}
|
|
42
|
+
// region secure
|
|
43
|
+
get $back() {
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
get $secure() {
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
get $clazz() {
|
|
50
|
+
return this._clazz;
|
|
51
|
+
}
|
|
52
|
+
get $name() {
|
|
53
|
+
return this._name;
|
|
54
|
+
}
|
|
55
|
+
static $setLeyyo(leyyo) {
|
|
56
|
+
this._callback = leyyo.callback;
|
|
57
|
+
this._log = leyyo.log;
|
|
58
|
+
}
|
|
59
|
+
$setName(name) {
|
|
60
|
+
this._name = name;
|
|
61
|
+
}
|
|
62
|
+
$setMethod(method, lambda) {
|
|
63
|
+
if (typeof lambda === 'function') {
|
|
64
|
+
this[method] = lambda;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this[method] = () => { };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
$assert(error, indicator, params) {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.LoggerImpl = LoggerImpl;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { List } from "./list";
|
|
2
|
+
import { CommonStorage, CommonStorageSecure, StorageDetail, StorageItem, StorageType } from "./index-types";
|
|
3
|
+
import { Leyyo } from "../leyyo";
|
|
4
|
+
/** @inheritDoc */
|
|
5
|
+
export declare class CommonStorageImpl implements CommonStorage, CommonStorageSecure {
|
|
6
|
+
private readonly _lists;
|
|
7
|
+
private readonly _arrays;
|
|
8
|
+
private readonly _maps;
|
|
9
|
+
private readonly _sets;
|
|
10
|
+
/**
|
|
11
|
+
* Default constructor
|
|
12
|
+
*
|
|
13
|
+
* Responsibilities
|
|
14
|
+
* - Create repositories => ie: lists, arrays, maps, sets
|
|
15
|
+
* */
|
|
16
|
+
constructor();
|
|
17
|
+
$init(leyyo: Leyyo): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get sizes of each repository by given type and name (optional)
|
|
20
|
+
*
|
|
21
|
+
* @param {StorageType} type
|
|
22
|
+
* @param {string?} name
|
|
23
|
+
* @return {StorageItem}
|
|
24
|
+
* */
|
|
25
|
+
protected detailItem(type: StorageType, name?: string): StorageItem;
|
|
26
|
+
/** @inheritDoc */
|
|
27
|
+
newList<V>(name: string): List<V>;
|
|
28
|
+
/** @inheritDoc */
|
|
29
|
+
getList<V>(name: string): List<V>;
|
|
30
|
+
/** @inheritDoc */
|
|
31
|
+
newArray<V>(name: string): Array<V>;
|
|
32
|
+
/** @inheritDoc */
|
|
33
|
+
getArray<V>(name: string): Array<V>;
|
|
34
|
+
/** @inheritDoc */
|
|
35
|
+
newMap<V>(name: string): Map<string, V>;
|
|
36
|
+
/** @inheritDoc */
|
|
37
|
+
getMap<V>(name: string): Map<string, V>;
|
|
38
|
+
/** @inheritDoc */
|
|
39
|
+
newSet<V>(name: string): Set<V>;
|
|
40
|
+
/** @inheritDoc */
|
|
41
|
+
getSet<V>(name: string): Set<V>;
|
|
42
|
+
/** @inheritDoc */
|
|
43
|
+
details(type?: StorageType, name?: string): StorageDetail;
|
|
44
|
+
get $back(): CommonStorage;
|
|
45
|
+
get $secure(): CommonStorageSecure;
|
|
46
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonStorageImpl = void 0;
|
|
4
|
+
const list_1 = require("./list");
|
|
5
|
+
// noinspection JSUnusedLocalSymbols
|
|
6
|
+
/** @inheritDoc */
|
|
7
|
+
class CommonStorageImpl {
|
|
8
|
+
/**
|
|
9
|
+
* Default constructor
|
|
10
|
+
*
|
|
11
|
+
* Responsibilities
|
|
12
|
+
* - Create repositories => ie: lists, arrays, maps, sets
|
|
13
|
+
* */
|
|
14
|
+
constructor() {
|
|
15
|
+
this._lists = new Map();
|
|
16
|
+
this._arrays = new Map();
|
|
17
|
+
this._maps = new Map();
|
|
18
|
+
this._sets = new Map();
|
|
19
|
+
}
|
|
20
|
+
$init(leyyo) {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get sizes of each repository by given type and name (optional)
|
|
24
|
+
*
|
|
25
|
+
* @param {StorageType} type
|
|
26
|
+
* @param {string?} name
|
|
27
|
+
* @return {StorageItem}
|
|
28
|
+
* */
|
|
29
|
+
detailItem(type, name) {
|
|
30
|
+
const result = {};
|
|
31
|
+
switch (type) {
|
|
32
|
+
case "array":
|
|
33
|
+
if (name) {
|
|
34
|
+
if (this._arrays.has(name)) {
|
|
35
|
+
return { [name]: this._arrays.get(name).length };
|
|
36
|
+
}
|
|
37
|
+
return { [name]: -1 };
|
|
38
|
+
}
|
|
39
|
+
for (const [key, list] of this._arrays.entries()) {
|
|
40
|
+
result[key] = list.length;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
case "list":
|
|
44
|
+
if (name) {
|
|
45
|
+
if (this._lists.has(name)) {
|
|
46
|
+
return { [name]: this._lists.get(name).length };
|
|
47
|
+
}
|
|
48
|
+
return { [name]: -1 };
|
|
49
|
+
}
|
|
50
|
+
for (const [key, list] of this._lists.entries()) {
|
|
51
|
+
result[key] = list.length;
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
case "map":
|
|
55
|
+
if (name) {
|
|
56
|
+
if (this._maps.has(name)) {
|
|
57
|
+
return { [name]: this._maps.get(name).size };
|
|
58
|
+
}
|
|
59
|
+
return { [name]: -1 };
|
|
60
|
+
}
|
|
61
|
+
for (const [key, map] of this._maps.entries()) {
|
|
62
|
+
result[key] = map.size;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
case "set":
|
|
66
|
+
if (name) {
|
|
67
|
+
if (this._sets.has(name)) {
|
|
68
|
+
return { [name]: this._sets.get(name).size };
|
|
69
|
+
}
|
|
70
|
+
return { [name]: -1 };
|
|
71
|
+
}
|
|
72
|
+
for (const [key, set] of this._sets.entries()) {
|
|
73
|
+
result[key] = set.size;
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
default:
|
|
77
|
+
return { [name]: -1 };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// region list
|
|
81
|
+
/** @inheritDoc */
|
|
82
|
+
newList(name) {
|
|
83
|
+
const list = new list_1.List();
|
|
84
|
+
this._lists.set(name, list);
|
|
85
|
+
return list;
|
|
86
|
+
}
|
|
87
|
+
/** @inheritDoc */
|
|
88
|
+
getList(name) {
|
|
89
|
+
return this._lists.get(name);
|
|
90
|
+
}
|
|
91
|
+
// endregion list
|
|
92
|
+
// region array
|
|
93
|
+
/** @inheritDoc */
|
|
94
|
+
newArray(name) {
|
|
95
|
+
const arr = [];
|
|
96
|
+
this._arrays.set(name, arr);
|
|
97
|
+
return arr;
|
|
98
|
+
}
|
|
99
|
+
/** @inheritDoc */
|
|
100
|
+
getArray(name) {
|
|
101
|
+
return this._arrays.get(name);
|
|
102
|
+
}
|
|
103
|
+
// endregion array
|
|
104
|
+
// region map
|
|
105
|
+
/** @inheritDoc */
|
|
106
|
+
newMap(name) {
|
|
107
|
+
const map = new Map;
|
|
108
|
+
this._maps.set(name, map);
|
|
109
|
+
return map;
|
|
110
|
+
}
|
|
111
|
+
/** @inheritDoc */
|
|
112
|
+
getMap(name) {
|
|
113
|
+
return this._maps.get(name);
|
|
114
|
+
}
|
|
115
|
+
// endregion map
|
|
116
|
+
// region set
|
|
117
|
+
/** @inheritDoc */
|
|
118
|
+
newSet(name) {
|
|
119
|
+
const set = new Set;
|
|
120
|
+
this._sets.set(name, set);
|
|
121
|
+
return set;
|
|
122
|
+
}
|
|
123
|
+
/** @inheritDoc */
|
|
124
|
+
getSet(name) {
|
|
125
|
+
return this._sets.get(name);
|
|
126
|
+
}
|
|
127
|
+
// endregion set
|
|
128
|
+
/** @inheritDoc */
|
|
129
|
+
details(type, name) {
|
|
130
|
+
const result = {};
|
|
131
|
+
if (type) {
|
|
132
|
+
result[type] = this.detailItem(type, name);
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
result['array'] = this.detailItem('array', name);
|
|
137
|
+
result['list'] = this.detailItem('list', name);
|
|
138
|
+
result['map'] = this.detailItem('map', name);
|
|
139
|
+
result['set'] = this.detailItem('set', name);
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
get $back() {
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
get $secure() {
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.CommonStorageImpl = CommonStorageImpl;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { List } from "./list";
|
|
2
|
+
import { Dict, ShiftMain, ShiftSecure } from "../aliases";
|
|
3
|
+
import { Leyyo } from "../leyyo";
|
|
4
|
+
/**
|
|
5
|
+
* Storage factory
|
|
6
|
+
*
|
|
7
|
+
* Purpose, unify all iteration based data in some place to track memory usage in your applications
|
|
8
|
+
* */
|
|
9
|
+
export interface CommonStorage extends ShiftSecure<CommonStorageSecure> {
|
|
10
|
+
/**
|
|
11
|
+
* Creates new array
|
|
12
|
+
*
|
|
13
|
+
* @param {string} name
|
|
14
|
+
* @return {Array<any>}
|
|
15
|
+
* */
|
|
16
|
+
newArray<V>(name: string): Array<V>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns an array by given name
|
|
19
|
+
*
|
|
20
|
+
* @param {string} name
|
|
21
|
+
* @return {Array<any>}
|
|
22
|
+
*
|
|
23
|
+
* Note:
|
|
24
|
+
* If the array does not exist than it returns null
|
|
25
|
+
* */
|
|
26
|
+
getArray<V>(name: string): Array<V>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates new list
|
|
29
|
+
*
|
|
30
|
+
* @param {string} name
|
|
31
|
+
* @return {List<any>}
|
|
32
|
+
* */
|
|
33
|
+
newList<V>(name: string): List<V>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns a list by given name
|
|
36
|
+
*
|
|
37
|
+
* @param {string} name
|
|
38
|
+
* @return {List<any>}
|
|
39
|
+
*
|
|
40
|
+
* Note:
|
|
41
|
+
* If the list does not exist than it returns null
|
|
42
|
+
* */
|
|
43
|
+
getList<V>(name: string): List<V>;
|
|
44
|
+
/**
|
|
45
|
+
* Creates new map
|
|
46
|
+
*
|
|
47
|
+
* @param {string} name
|
|
48
|
+
* @return {Map<string, any>}
|
|
49
|
+
* */
|
|
50
|
+
newMap<V>(name: string): Map<string, V>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns a map by given name
|
|
53
|
+
*
|
|
54
|
+
* @param {string} name
|
|
55
|
+
* @return {Map<string, any>}
|
|
56
|
+
*
|
|
57
|
+
* Note:
|
|
58
|
+
* If the map does not exist than it returns null
|
|
59
|
+
* */
|
|
60
|
+
getMap<V>(name: string): Map<string, V>;
|
|
61
|
+
/**
|
|
62
|
+
* Creates new set
|
|
63
|
+
*
|
|
64
|
+
* @param {string} name
|
|
65
|
+
* @return {Set<any>}
|
|
66
|
+
* */
|
|
67
|
+
newSet<V>(name: string): Set<V>;
|
|
68
|
+
/**
|
|
69
|
+
* Returns a set by given name
|
|
70
|
+
*
|
|
71
|
+
* @param {string} name
|
|
72
|
+
* @return {Set<any>}
|
|
73
|
+
*
|
|
74
|
+
* Note:
|
|
75
|
+
* If the set does not exist than it returns null
|
|
76
|
+
* */
|
|
77
|
+
getSet<V>(name: string): Set<V>;
|
|
78
|
+
/**
|
|
79
|
+
* Exports sizes of repositories by given type and name
|
|
80
|
+
*
|
|
81
|
+
*
|
|
82
|
+
* @param {StorageType?} type
|
|
83
|
+
* @param {string?} name
|
|
84
|
+
* @return {StorageDetail}
|
|
85
|
+
* */
|
|
86
|
+
details(type?: StorageType, name?: string): StorageDetail;
|
|
87
|
+
}
|
|
88
|
+
export interface CommonStorageSecure extends ShiftMain<CommonStorage> {
|
|
89
|
+
$init(leyyo: Leyyo): void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Storage type literal, as an enum
|
|
93
|
+
* */
|
|
94
|
+
export type StorageType = 'array' | 'list' | 'map' | 'set';
|
|
95
|
+
/**
|
|
96
|
+
* Storage size dictionary which in corresponding type
|
|
97
|
+
* */
|
|
98
|
+
export type StorageItem = Dict<number>;
|
|
99
|
+
/**
|
|
100
|
+
* Storage export dictionary which includes items
|
|
101
|
+
* */
|
|
102
|
+
export type StorageDetail = Record<StorageType, StorageItem>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./index-types"), exports);
|
|
18
|
+
__exportStar(require("./list"), exports);
|
|
19
|
+
__exportStar(require("./common-storage-impl"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.List = void 0;
|
|
4
|
+
// noinspection JSUnusedGlobalSymbols
|
|
5
|
+
/**
|
|
6
|
+
* Extended array class, ie: Clearable arrays
|
|
7
|
+
* */
|
|
8
|
+
class List extends Array {
|
|
9
|
+
/**
|
|
10
|
+
* Clears array items, to align all iteration repositories, like Set, Map etc
|
|
11
|
+
* */
|
|
12
|
+
clear() {
|
|
13
|
+
this.splice(0, this.length);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.List = List;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CommonTo, CommonToSecure, TypeArrayOpt, TypeEnumOpt, TypeObjectOpt, TypeOpt } from "./index-types";
|
|
2
|
+
import { Dict, KeyValue, OneOrMore } from "../aliases";
|
|
3
|
+
import { Leyyo } from "../leyyo";
|
|
4
|
+
export declare class CommonToImpl implements CommonTo, CommonToSecure {
|
|
5
|
+
private readonly _EXPECTED_ANY;
|
|
6
|
+
private readonly _EXPECTED_ARRAY;
|
|
7
|
+
private readonly _EXPECTED_BOOL;
|
|
8
|
+
private readonly _EXPECTED_CLASS;
|
|
9
|
+
private readonly _EXPECTED_DATE;
|
|
10
|
+
private readonly _EXPECTED_ENUM;
|
|
11
|
+
private readonly _EXPECTED_NUMBER;
|
|
12
|
+
private readonly _EXPECTED_STRING;
|
|
13
|
+
private is;
|
|
14
|
+
private callback;
|
|
15
|
+
private assertion;
|
|
16
|
+
private _enumInMap;
|
|
17
|
+
private _enumInArray;
|
|
18
|
+
private _enumInAlteration;
|
|
19
|
+
runFn<T = unknown>(fn: Function, value: Function, opt?: TypeOpt): T;
|
|
20
|
+
runSave<T = unknown>(fn: Function, value: unknown, opt?: TypeOpt): T;
|
|
21
|
+
raiseInvalidValue<T = unknown>(value: unknown, expected: OneOrMore<string>, opt?: TypeOpt, params?: Dict): T;
|
|
22
|
+
any(value: unknown, opt?: TypeOpt): unknown;
|
|
23
|
+
array<T = unknown>(value: unknown, opt?: TypeArrayOpt): Array<T>;
|
|
24
|
+
boolean(value: unknown, opt?: TypeOpt): boolean;
|
|
25
|
+
clazz(value: unknown, opt?: TypeOpt): string;
|
|
26
|
+
date(value: unknown, opt?: TypeOpt): Date;
|
|
27
|
+
enumeration<T extends KeyValue = KeyValue>(value: unknown, opt?: TypeEnumOpt<T>): T;
|
|
28
|
+
float(value: unknown, opt?: TypeOpt): number | null;
|
|
29
|
+
func<T = Function>(value: unknown, opt?: TypeOpt): T | null;
|
|
30
|
+
integer(value: unknown, opt?: TypeOpt): number | null;
|
|
31
|
+
object<T = unknown>(value: unknown, opt?: TypeObjectOpt): Dict<T>;
|
|
32
|
+
dict<T = unknown>(value: unknown, opt?: TypeObjectOpt): Dict<T>;
|
|
33
|
+
string(value: unknown, opt?: TypeOpt): string;
|
|
34
|
+
text(value: unknown, opt?: TypeOpt): string;
|
|
35
|
+
$init(leyyo: Leyyo): void;
|
|
36
|
+
get $back(): CommonTo;
|
|
37
|
+
get $secure(): CommonToSecure;
|
|
38
|
+
}
|