@leyyo/common 1.0.0 → 1.0.2
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/dist/assertion/common-assertion-impl.d.ts +38 -7
- package/dist/assertion/common-assertion-impl.js +64 -26
- package/dist/assertion/index-types.d.ts +466 -75
- package/dist/assertion/index.d.ts +0 -1
- package/dist/assertion/index.js +0 -1
- package/dist/error/common-error-impl.d.ts +6 -4
- package/dist/error/common-error-impl.js +8 -4
- package/dist/error/index-types.d.ts +5 -54
- package/dist/error/index.d.ts +0 -5
- package/dist/error/index.js +0 -5
- package/dist/{error → exception}/assertion-exception.d.ts +1 -1
- package/dist/{error → exception}/caused-exception.d.ts +1 -1
- package/dist/{error → exception}/developer-exception.d.ts +1 -1
- package/dist/{error → exception}/exception.d.ts +4 -3
- package/dist/{error → exception}/exception.js +4 -4
- package/dist/exception/index-types.d.ts +30 -0
- package/dist/exception/index.d.ts +6 -0
- package/dist/exception/index.js +22 -0
- package/dist/fqn/common-fqn-impl.d.ts +11 -0
- package/dist/fqn/common-fqn-impl.js +47 -0
- package/dist/fqn/index-types.d.ts +6 -0
- package/dist/fqn/index-types.js +2 -0
- package/dist/fqn/index.d.ts +2 -0
- package/dist/{callback → fqn}/index.js +1 -1
- package/dist/hook/common-hook-impl.d.ts +30 -0
- package/dist/hook/common-hook-impl.js +111 -0
- package/dist/hook/index-types.d.ts +56 -0
- package/dist/hook/index-types.js +2 -0
- package/dist/hook/index.d.ts +2 -0
- package/dist/hook/index.js +18 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +19 -6
- package/dist/is/common-is-impl.d.ts +36 -15
- package/dist/is/common-is-impl.js +35 -10
- package/dist/is/index-types.d.ts +142 -20
- package/dist/leyyo/index-types.d.ts +4 -2
- package/dist/leyyo/leyyo-impl.d.ts +4 -2
- package/dist/leyyo/leyyo-impl.js +37 -29
- package/dist/literal/country-code.d.ts +8 -0
- package/dist/literal/country-code.js +17 -0
- package/dist/literal/environment.d.ts +8 -0
- package/dist/literal/environment.js +7 -0
- package/dist/literal/http-method.d.ts +8 -0
- package/dist/literal/http-method.js +7 -0
- package/dist/literal/http-place.d.ts +8 -0
- package/dist/literal/http-place.js +7 -0
- package/dist/literal/index-types.d.ts +6 -0
- package/dist/literal/index-types.js +2 -0
- package/dist/literal/index.d.ts +14 -0
- package/dist/literal/index.js +30 -0
- package/dist/literal/key-value.d.ts +4 -0
- package/dist/literal/key-value.js +7 -0
- package/dist/literal/language-code.d.ts +8 -0
- package/dist/literal/language-code.js +12 -0
- package/dist/literal/locale-code.d.ts +10 -0
- package/dist/literal/locale-code.js +17 -0
- package/dist/literal/primitive.d.ts +8 -0
- package/dist/literal/primitive.js +7 -0
- package/dist/literal/real-value.d.ts +8 -0
- package/dist/literal/real-value.js +7 -0
- package/dist/literal/severity.d.ts +8 -0
- package/dist/literal/severity.js +7 -0
- package/dist/literal/storage-type.d.ts +8 -0
- package/dist/literal/storage-type.js +7 -0
- package/dist/literal/weak-false.d.ts +8 -0
- package/dist/literal/weak-false.js +7 -0
- package/dist/literal/weak-true.d.ts +8 -0
- package/dist/literal/weak-true.js +7 -0
- package/dist/log/common-log-impl.d.ts +3 -2
- package/dist/log/common-log-impl.js +6 -6
- package/dist/log/index-types.d.ts +2 -55
- package/dist/log/index-types.js +0 -1
- package/dist/log/index.d.ts +1 -1
- package/dist/log/index.js +1 -1
- package/dist/log/logger-impl.d.ts +4 -3
- package/dist/log/logger-impl.js +7 -6
- package/dist/{assertion → shared}/assert.js +1 -0
- package/dist/{aliases.d.ts → shared/index-aliases.d.ts} +32 -4
- package/dist/shared/index-types.d.ts +141 -0
- package/dist/shared/index-types.js +3 -0
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.js +21 -0
- package/dist/storage/common-storage-impl.d.ts +3 -2
- package/dist/storage/common-storage-impl.js +3 -3
- package/dist/storage/index-types.d.ts +3 -18
- package/dist/storage/index.d.ts +0 -1
- package/dist/storage/index.js +0 -1
- package/dist/to/common-to-impl.d.ts +19 -19
- package/dist/to/common-to-impl.js +11 -11
- package/dist/to/index-types.d.ts +18 -48
- package/package.json +1 -1
- package/dist/callback/common-callback-impl.d.ts +0 -31
- package/dist/callback/common-callback-impl.js +0 -134
- package/dist/callback/index-types.d.ts +0 -75
- package/dist/callback/index.d.ts +0 -2
- package/dist/literals.d.ts +0 -98
- package/dist/literals.js +0 -77
- package/dist/{error → exception}/assertion-exception.js +0 -0
- package/dist/{error → exception}/caused-exception.js +0 -0
- package/dist/{error → exception}/developer-exception.js +0 -0
- package/dist/{callback → exception}/index-types.js +0 -0
- package/dist/{error → exception}/multiple-exception.d.ts +1 -1
- package/dist/{error → exception}/multiple-exception.js +0 -0
- package/dist/{assertion → shared}/assert.d.ts +1 -1
- /package/dist/{aliases.js → shared/index-aliases.js} +0 -0
- /package/dist/{constants.d.ts → shared/index-constants.d.ts} +0 -0
- /package/dist/{constants.js → shared/index-constants.js} +0 -0
- /package/dist/{storage → shared}/list.d.ts +0 -0
- /package/dist/{storage → shared}/list.js +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Exception } from "./exception";
|
|
4
|
-
import { CommonCallbackDefined } from "../callback";
|
|
1
|
+
import { Dict, InitLike, ShiftMain, ShiftSecure } from "../shared";
|
|
2
|
+
import { ExceptionLike } from "../exception";
|
|
5
3
|
export interface CommonError extends ShiftSecure<CommonErrorSecure> {
|
|
4
|
+
register(cls: Function): void;
|
|
6
5
|
build(e: Error | string): ExceptionLike;
|
|
7
6
|
afterCreate(e: ExceptionLike): void;
|
|
8
7
|
causedBy(e: Error | string): ExceptionLike;
|
|
@@ -13,58 +12,10 @@ export interface CommonError extends ShiftSecure<CommonErrorSecure> {
|
|
|
13
12
|
hasSign(err: Error, key: string): boolean;
|
|
14
13
|
toObject(e: Error, ...omittedFields: Array<string>): Dict;
|
|
15
14
|
buildStack(e: Error): void;
|
|
16
|
-
copyStack(exception:
|
|
15
|
+
copyStack(exception: ExceptionLike, error: Error): void;
|
|
17
16
|
initOmit(clz: Function): boolean;
|
|
18
17
|
addOmit(clz: Function, ...properties: Array<string>): boolean;
|
|
19
18
|
getOmit(clz: Function): Array<string>;
|
|
20
19
|
inheritOmit(clz: Function): Array<string>;
|
|
21
20
|
}
|
|
22
|
-
export
|
|
23
|
-
build?(e: Error | string): ExceptionLike;
|
|
24
|
-
afterCreate?(e: ExceptionLike): void;
|
|
25
|
-
causedBy?(e: Error | string): ExceptionLike;
|
|
26
|
-
initSign?(err: Error): boolean;
|
|
27
|
-
addSign?(err: Error, ...keys: Array<string>): boolean;
|
|
28
|
-
getSign?(err: Error): Array<string>;
|
|
29
|
-
removeSign?(err: Error, ...keys: Array<string>): boolean;
|
|
30
|
-
hasSign?(err: Error, key: string): boolean;
|
|
31
|
-
toObject?(e: Error, ...omittedFields: Array<string>): Dict;
|
|
32
|
-
buildStack?(e: Error): void;
|
|
33
|
-
copyStack?(exception: Exception, error: Error): void;
|
|
34
|
-
initOmit?(clz: Function): boolean;
|
|
35
|
-
addOmit?(clz: Function, ...properties: Array<string>): boolean;
|
|
36
|
-
getOmit?(clz: Function): Array<string>;
|
|
37
|
-
inheritOmit?(clz: Function): Array<string>;
|
|
38
|
-
}
|
|
39
|
-
export interface CommonErrorSecure extends ShiftMain<CommonError> {
|
|
40
|
-
$init(leyyo: Leyyo): void;
|
|
41
|
-
}
|
|
42
|
-
export interface ExceptionStackLine {
|
|
43
|
-
file?: string;
|
|
44
|
-
method?: string;
|
|
45
|
-
line?: number;
|
|
46
|
-
column?: number;
|
|
47
|
-
}
|
|
48
|
-
export interface ExceptionParamsAppend extends Dict {
|
|
49
|
-
indicator?: string;
|
|
50
|
-
}
|
|
51
|
-
export interface ExceptionLike extends Error, ShiftSecure<ExceptionSecure> {
|
|
52
|
-
get params(): Dict;
|
|
53
|
-
causedBy(e: Error | string): this;
|
|
54
|
-
with(clazz: ClassLike): this;
|
|
55
|
-
with(instance: Abstract<any>): this;
|
|
56
|
-
with(name: string): this;
|
|
57
|
-
with(value: any): this;
|
|
58
|
-
appendParams(params: ExceptionParamsAppend, ignoreExisting?: boolean): this;
|
|
59
|
-
log(req?: unknown): this;
|
|
60
|
-
raise(throwable?: boolean, req?: unknown): this;
|
|
61
|
-
toObject(...omittedFields: Array<string>): Dict;
|
|
62
|
-
toJSON(): Dict;
|
|
63
|
-
}
|
|
64
|
-
export interface ExceptionSecure extends ShiftMain<ExceptionLike> {
|
|
65
|
-
$setName(name: string): this;
|
|
66
|
-
$hasSign(key: string): boolean;
|
|
67
|
-
$listSigns(): Array<string>;
|
|
68
|
-
$addSign(...keys: Array<string>): boolean;
|
|
69
|
-
$removeSign(...keys: Array<string>): boolean;
|
|
70
|
-
}
|
|
21
|
+
export type CommonErrorSecure = ShiftMain<CommonError> & InitLike;
|
package/dist/error/index.d.ts
CHANGED
package/dist/error/index.js
CHANGED
|
@@ -16,8 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./index-types"), exports);
|
|
18
18
|
__exportStar(require("./common-error-impl"), exports);
|
|
19
|
-
__exportStar(require("./exception"), exports);
|
|
20
|
-
__exportStar(require("./caused-exception"), exports);
|
|
21
|
-
__exportStar(require("./developer-exception"), exports);
|
|
22
|
-
__exportStar(require("./assertion-exception"), exports);
|
|
23
|
-
__exportStar(require("./multiple-exception"), exports);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { CommonError
|
|
2
|
-
import { Abstract, ClassLike, ClassOrName, Dict } from "../
|
|
1
|
+
import { CommonError } from "../error";
|
|
2
|
+
import { Abstract, ClassLike, ClassOrName, Dict } from "../shared";
|
|
3
3
|
import { Leyyo } from "../leyyo";
|
|
4
|
+
import { ExceptionLike, ExceptionParamsAppend, ExceptionSecure, ExceptionStackLine } from "./index-types";
|
|
4
5
|
export declare class Exception extends Error implements ExceptionLike, ExceptionSecure {
|
|
5
|
-
private static
|
|
6
|
+
private static _fqn;
|
|
6
7
|
private static _error;
|
|
7
8
|
private static _log;
|
|
8
9
|
private static _assertion;
|
|
@@ -7,7 +7,7 @@ class Exception extends Error {
|
|
|
7
7
|
message += ` => ${JSON.stringify(Exception._assertion.secureJson(params))}`;
|
|
8
8
|
}
|
|
9
9
|
super(message);
|
|
10
|
-
this.name = Exception.
|
|
10
|
+
this.name = Exception._fqn.name(this);
|
|
11
11
|
this._params = params !== null && params !== void 0 ? params : {};
|
|
12
12
|
this._parsed = [];
|
|
13
13
|
Exception._error.afterCreate(this);
|
|
@@ -27,7 +27,7 @@ class Exception extends Error {
|
|
|
27
27
|
return this;
|
|
28
28
|
}
|
|
29
29
|
with(value) {
|
|
30
|
-
this._holder = Exception.
|
|
30
|
+
this._holder = Exception._fqn.name(value);
|
|
31
31
|
return this;
|
|
32
32
|
}
|
|
33
33
|
appendParams(params, ignoreExisting) {
|
|
@@ -98,8 +98,8 @@ class Exception extends Error {
|
|
|
98
98
|
return Exception._error.removeSign(this, ...keys);
|
|
99
99
|
}
|
|
100
100
|
static $setLeyyo(leyyo) {
|
|
101
|
-
if (!this.
|
|
102
|
-
this.
|
|
101
|
+
if (!this._fqn) {
|
|
102
|
+
this._fqn = leyyo.fqn;
|
|
103
103
|
}
|
|
104
104
|
if (!this._error) {
|
|
105
105
|
this._error = leyyo.error;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Abstract, ClassLike, Dict, ShiftMain, ShiftSecure } from "../shared";
|
|
2
|
+
export interface ExceptionStackLine {
|
|
3
|
+
file?: string;
|
|
4
|
+
method?: string;
|
|
5
|
+
line?: number;
|
|
6
|
+
column?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ExceptionParamsAppend extends Dict {
|
|
9
|
+
indicator?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ExceptionLike extends Error, ShiftSecure<ExceptionSecure> {
|
|
12
|
+
get params(): Dict;
|
|
13
|
+
causedBy(e: Error | string): this;
|
|
14
|
+
with(clazz: ClassLike): this;
|
|
15
|
+
with(instance: Abstract<any>): this;
|
|
16
|
+
with(name: string): this;
|
|
17
|
+
with(value: any): this;
|
|
18
|
+
appendParams(params: ExceptionParamsAppend, ignoreExisting?: boolean): this;
|
|
19
|
+
log(req?: unknown): this;
|
|
20
|
+
raise(throwable?: boolean, req?: unknown): this;
|
|
21
|
+
toObject(...omittedFields: Array<string>): Dict;
|
|
22
|
+
toJSON(): Dict;
|
|
23
|
+
}
|
|
24
|
+
export interface ExceptionSecure extends ShiftMain<ExceptionLike> {
|
|
25
|
+
$setName(name: string): this;
|
|
26
|
+
$hasSign(key: string): boolean;
|
|
27
|
+
$listSigns(): Array<string>;
|
|
28
|
+
$addSign(...keys: Array<string>): boolean;
|
|
29
|
+
$removeSign(...keys: Array<string>): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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("./exception"), exports);
|
|
19
|
+
__exportStar(require("./caused-exception"), exports);
|
|
20
|
+
__exportStar(require("./developer-exception"), exports);
|
|
21
|
+
__exportStar(require("./assertion-exception"), exports);
|
|
22
|
+
__exportStar(require("./multiple-exception"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommonFqn, CommonFqnSecure } from "./index-types";
|
|
2
|
+
import { Leyyo } from "../leyyo";
|
|
3
|
+
import { FqnStereoType } from "../shared";
|
|
4
|
+
export declare class CommonFqnImpl implements CommonFqn, CommonFqnSecure {
|
|
5
|
+
private hook;
|
|
6
|
+
get $back(): CommonFqn;
|
|
7
|
+
$init(leyyo: Leyyo): void;
|
|
8
|
+
get $secure(): CommonFqnSecure;
|
|
9
|
+
name(value: any): string;
|
|
10
|
+
register(value: any, type: FqnStereoType, pckName: string): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonFqnImpl = void 0;
|
|
4
|
+
const shared_1 = require("../shared");
|
|
5
|
+
// noinspection JSUnusedLocalSymbols
|
|
6
|
+
class CommonFqnImpl {
|
|
7
|
+
get $back() {
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
$init(leyyo) {
|
|
11
|
+
this.hook = leyyo.hook;
|
|
12
|
+
const fields = ['name', 'register'];
|
|
13
|
+
const rec = { proper: false };
|
|
14
|
+
fields.forEach(field => {
|
|
15
|
+
rec[field] = this[field];
|
|
16
|
+
});
|
|
17
|
+
// define itself temporarily for fqn operations
|
|
18
|
+
leyyo.hook.defineProvider(shared_1.LY_ATTACHED_FQN, CommonFqnImpl, rec);
|
|
19
|
+
// when new fqn provider is defined, replace all common methods
|
|
20
|
+
leyyo.hook.whenProviderDefined(shared_1.LY_ATTACHED_FQN, CommonFqnImpl, (ins) => {
|
|
21
|
+
fields.forEach(field => {
|
|
22
|
+
if (typeof ins[field] === 'function') {
|
|
23
|
+
this[field] = ins[field];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
get $secure() {
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
name(value) {
|
|
32
|
+
switch (typeof value) {
|
|
33
|
+
case "function":
|
|
34
|
+
return value.name;
|
|
35
|
+
case "object":
|
|
36
|
+
return value.constructor.name;
|
|
37
|
+
case "string":
|
|
38
|
+
return value;
|
|
39
|
+
default:
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
register(value, type, pckName) {
|
|
44
|
+
this.hook.queueForCallback(shared_1.LY_PENDING_FQN_REGISTER, value, type, pckName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.CommonFqnImpl = CommonFqnImpl;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FqnStereoType, InitLike, ShiftMain, ShiftSecure } from "../shared";
|
|
2
|
+
export interface CommonFqn extends ShiftSecure<CommonFqnSecure> {
|
|
3
|
+
name(value: any): string;
|
|
4
|
+
register(value: any, type: FqnStereoType, pckName: string): void;
|
|
5
|
+
}
|
|
6
|
+
export type CommonFqnSecure = ShiftMain<CommonFqn> & InitLike;
|
|
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./index-types"), exports);
|
|
18
|
-
__exportStar(require("./common-
|
|
18
|
+
__exportStar(require("./common-fqn-impl"), exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Arr, HookDefinedProvider, HookDefinedProviderLambda } from "../shared";
|
|
2
|
+
import { Leyyo } from "../leyyo";
|
|
3
|
+
import { CommonHook, CommonHookSecure } from "./index-types";
|
|
4
|
+
export declare class CommonHookImpl implements CommonHook, CommonHookSecure {
|
|
5
|
+
private _waitingForCallbacks;
|
|
6
|
+
private _attachedCallbacks;
|
|
7
|
+
private _waitingForProviders;
|
|
8
|
+
private _definedProviders;
|
|
9
|
+
/**
|
|
10
|
+
* Default constructor
|
|
11
|
+
*
|
|
12
|
+
* Responsibilities
|
|
13
|
+
* - Create repositories => ie: callbacks
|
|
14
|
+
* - Trigger clear pending operation
|
|
15
|
+
* */
|
|
16
|
+
constructor();
|
|
17
|
+
$init(leyyo: Leyyo): void;
|
|
18
|
+
/**
|
|
19
|
+
* Clear jobs in the queue which channel as pending
|
|
20
|
+
*
|
|
21
|
+
* Because the expected callback may not be defined
|
|
22
|
+
* */
|
|
23
|
+
private _clearPending;
|
|
24
|
+
get $secure(): CommonHookSecure;
|
|
25
|
+
attachCallback(channel: string, fn: Function): void;
|
|
26
|
+
queueForCallback(channel: string, ...args: Arr): boolean;
|
|
27
|
+
get $back(): CommonHook;
|
|
28
|
+
whenProviderDefined<T extends HookDefinedProvider = HookDefinedProvider>(channel: string, consumer: Function, callback: HookDefinedProviderLambda<T>): void;
|
|
29
|
+
defineProvider<T extends HookDefinedProvider = HookDefinedProvider>(channel: string, producer: Function, instance: T): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonHookImpl = void 0;
|
|
4
|
+
const internal_1 = require("../internal");
|
|
5
|
+
const exception_1 = require("../exception");
|
|
6
|
+
// noinspection JSUnusedGlobalSymbols
|
|
7
|
+
class CommonHookImpl {
|
|
8
|
+
/**
|
|
9
|
+
* Default constructor
|
|
10
|
+
*
|
|
11
|
+
* Responsibilities
|
|
12
|
+
* - Create repositories => ie: callbacks
|
|
13
|
+
* - Trigger clear pending operation
|
|
14
|
+
* */
|
|
15
|
+
constructor() {
|
|
16
|
+
// clear after 1 minute
|
|
17
|
+
setTimeout(() => this._clearPending(), 60000);
|
|
18
|
+
}
|
|
19
|
+
$init(leyyo) {
|
|
20
|
+
this._waitingForCallbacks = leyyo.storage.newMap(`${internal_1.FQN_PCK}/waitingForCallbacks`);
|
|
21
|
+
this._attachedCallbacks = leyyo.storage.newMap(`${internal_1.FQN_PCK}/attachedCallbacks`);
|
|
22
|
+
this._waitingForProviders = leyyo.storage.newMap(`${internal_1.FQN_PCK}/waitingForProviders`);
|
|
23
|
+
this._definedProviders = leyyo.storage.newMap(`${internal_1.FQN_PCK}/definedProviders`);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Clear jobs in the queue which channel as pending
|
|
27
|
+
*
|
|
28
|
+
* Because the expected callback may not be defined
|
|
29
|
+
* */
|
|
30
|
+
_clearPending() {
|
|
31
|
+
for (const [channel,] of this._waitingForCallbacks.entries()) {
|
|
32
|
+
const rec = this._attachedCallbacks.get(channel);
|
|
33
|
+
if (rec && !rec.initialization) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
this._waitingForCallbacks.delete(channel);
|
|
37
|
+
console.log(`hook.cleared.pending => {channel: ${channel}}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
get $secure() {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
attachCallback(channel, fn) {
|
|
44
|
+
if (!channel || typeof channel !== 'string') {
|
|
45
|
+
throw new Error(`hook.invalid.channel => {type: ${typeof channel}}`);
|
|
46
|
+
}
|
|
47
|
+
// callback attached
|
|
48
|
+
this._attachedCallbacks.set(channel, { fn });
|
|
49
|
+
// check waiting records, to be called
|
|
50
|
+
if (this._waitingForCallbacks.has(channel)) {
|
|
51
|
+
this._waitingForCallbacks.get(channel).forEach(item => {
|
|
52
|
+
fn(...item);
|
|
53
|
+
});
|
|
54
|
+
this._waitingForCallbacks.delete(channel);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
queueForCallback(channel, ...args) {
|
|
58
|
+
if (!channel || typeof channel !== 'string') {
|
|
59
|
+
throw new Error(`hook.invalid.channel => {type: ${typeof channel}}`);
|
|
60
|
+
}
|
|
61
|
+
// callback already exists
|
|
62
|
+
if (this._attachedCallbacks.has(channel)) {
|
|
63
|
+
const rec = this._attachedCallbacks.get(channel);
|
|
64
|
+
rec.fn(...args);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
// callback does not exist yet, so wait to be attached
|
|
68
|
+
if (this._waitingForCallbacks.has(channel)) {
|
|
69
|
+
this._waitingForCallbacks.get(channel).push(args);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this._waitingForCallbacks.set(channel, [args]);
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
get $back() {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
whenProviderDefined(channel, consumer, callback) {
|
|
80
|
+
if (!channel || typeof channel !== 'string') {
|
|
81
|
+
throw new exception_1.DeveloperException(`hook.invalid.channel`, { type: typeof channel });
|
|
82
|
+
}
|
|
83
|
+
if (!this._waitingForProviders.has(channel)) {
|
|
84
|
+
this._waitingForProviders.set(channel, []);
|
|
85
|
+
}
|
|
86
|
+
if (this._definedProviders.has(channel)) {
|
|
87
|
+
const ins = this._definedProviders.get(channel);
|
|
88
|
+
if (ins.producer !== consumer) {
|
|
89
|
+
callback(ins);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this._waitingForProviders.get(channel).push({ consumer, callback });
|
|
93
|
+
}
|
|
94
|
+
defineProvider(channel, producer, instance) {
|
|
95
|
+
if (!channel || typeof channel !== 'string') {
|
|
96
|
+
throw new exception_1.DeveloperException(`hook.invalid.channel`, { type: typeof channel });
|
|
97
|
+
}
|
|
98
|
+
const ins = Object.assign(Object.assign({}, instance), { producer });
|
|
99
|
+
this._definedProviders.set(channel, ins);
|
|
100
|
+
if (instance.proper) {
|
|
101
|
+
if (this._waitingForProviders.has(channel)) {
|
|
102
|
+
this._waitingForProviders.get(channel).forEach(item => {
|
|
103
|
+
if (item.consumer !== producer) {
|
|
104
|
+
item.callback(instance);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.CommonHookImpl = CommonHookImpl;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Arr, HookDefinedProvider, HookDefinedProviderLambda, InitLike, ShiftMain, ShiftSecure } from "../shared";
|
|
2
|
+
/**
|
|
3
|
+
* Hook interface, it collects all jobs and fire them when callback is defined
|
|
4
|
+
* */
|
|
5
|
+
export interface CommonHook extends ShiftSecure<CommonHookSecure> {
|
|
6
|
+
/**
|
|
7
|
+
* Attach a callback
|
|
8
|
+
*
|
|
9
|
+
* @param {string} channel
|
|
10
|
+
* @param {Function} fn
|
|
11
|
+
*
|
|
12
|
+
* Notes:
|
|
13
|
+
* - channel should be regular string
|
|
14
|
+
* - After attached, it should call all waiting calls in the queue
|
|
15
|
+
* */
|
|
16
|
+
attachCallback(channel: string, fn: Function): void;
|
|
17
|
+
/**
|
|
18
|
+
* Add a call into queue, which to be executed by appropriate callback
|
|
19
|
+
*
|
|
20
|
+
* @param {string} channel
|
|
21
|
+
* @param {Array<any>} args
|
|
22
|
+
* @returns {boolean} - channel exists?
|
|
23
|
+
*
|
|
24
|
+
* Notes:
|
|
25
|
+
* - channel should be regular string
|
|
26
|
+
* */
|
|
27
|
+
queueForCallback(channel: string, ...args: Arr): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Informs when callback is changed
|
|
30
|
+
*
|
|
31
|
+
* @param {string} channel
|
|
32
|
+
* @param {Function} consumer
|
|
33
|
+
* @param {HookDefinedProviderLambda} callback
|
|
34
|
+
*
|
|
35
|
+
* Notes:
|
|
36
|
+
* - channel should be regular string
|
|
37
|
+
* - callback should be regular function
|
|
38
|
+
* - channel should not be already defined
|
|
39
|
+
* */
|
|
40
|
+
whenProviderDefined<T extends HookDefinedProvider = HookDefinedProvider>(channel: string, consumer: Function, callback: HookDefinedProviderLambda<T>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Defines a provider to replace temporary providers
|
|
43
|
+
*
|
|
44
|
+
* @param {string} channel
|
|
45
|
+
* @param {Function} producer
|
|
46
|
+
* @param {Object} instance
|
|
47
|
+
*
|
|
48
|
+
* Notes:
|
|
49
|
+
* - channel should be regular string
|
|
50
|
+
* */
|
|
51
|
+
defineProvider<T extends HookDefinedProvider = HookDefinedProvider>(channel: string, producer: Function, instance: T): void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Secure hook interface
|
|
55
|
+
* */
|
|
56
|
+
export type CommonHookSecure = ShiftMain<CommonHook> & InitLike;
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./common-hook-impl"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
export * from './exception';
|
|
2
|
+
export * from './literal';
|
|
3
|
+
export * from './shared';
|
|
1
4
|
import { leyyo } from "./leyyo";
|
|
2
|
-
export * from './aliases';
|
|
3
|
-
export * from './constants';
|
|
4
|
-
export * from './literals';
|
|
5
5
|
declare const is: import("./is").CommonIs;
|
|
6
|
-
declare const
|
|
7
|
-
|
|
6
|
+
declare const hook: import("./hook").CommonHook;
|
|
7
|
+
declare const assertion: import("./assertion").CommonAssertion;
|
|
8
|
+
declare const storage: import("./storage").CommonStorage;
|
|
9
|
+
declare const to: import("./to").CommonTo;
|
|
10
|
+
declare const commonFqn: import("./fqn").CommonFqn;
|
|
11
|
+
declare const commonLog: import("./log").CommonLog;
|
|
12
|
+
declare const commonError: import("./error").CommonError;
|
|
13
|
+
export { leyyo, is, hook, assertion, storage, to, commonFqn, commonLog, commonError };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
4
|
if (k2 === undefined) k2 = k;
|
|
4
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -14,13 +15,25 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
16
|
};
|
|
16
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
+
exports.commonError = exports.commonLog = exports.commonFqn = exports.to = exports.storage = exports.assertion = exports.hook = exports.is = exports.leyyo = void 0;
|
|
19
|
+
__exportStar(require("./exception"), exports);
|
|
20
|
+
__exportStar(require("./literal"), exports);
|
|
21
|
+
__exportStar(require("./shared"), exports);
|
|
18
22
|
const leyyo_1 = require("./leyyo");
|
|
19
23
|
Object.defineProperty(exports, "leyyo", { enumerable: true, get: function () { return leyyo_1.leyyo; } });
|
|
20
|
-
__exportStar(require("./aliases"), exports);
|
|
21
|
-
__exportStar(require("./constants"), exports);
|
|
22
|
-
__exportStar(require("./literals"), exports);
|
|
23
24
|
const is = leyyo_1.leyyo.is;
|
|
24
25
|
exports.is = is;
|
|
25
|
-
const
|
|
26
|
-
exports.
|
|
26
|
+
const hook = leyyo_1.leyyo.hook;
|
|
27
|
+
exports.hook = hook;
|
|
28
|
+
const assertion = leyyo_1.leyyo.assertion;
|
|
29
|
+
exports.assertion = assertion;
|
|
30
|
+
const storage = leyyo_1.leyyo.storage;
|
|
31
|
+
exports.storage = storage;
|
|
32
|
+
const to = leyyo_1.leyyo.to;
|
|
33
|
+
exports.to = to;
|
|
34
|
+
const commonFqn = leyyo_1.leyyo.fqn;
|
|
35
|
+
exports.commonFqn = commonFqn;
|
|
36
|
+
const commonLog = leyyo_1.leyyo.log;
|
|
37
|
+
exports.commonLog = commonLog;
|
|
38
|
+
const commonError = leyyo_1.leyyo.error;
|
|
39
|
+
exports.commonError = commonError;
|
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
import { CommonIs, CommonIsSecure } from "./index-types";
|
|
2
2
|
import { Leyyo } from "../leyyo";
|
|
3
|
+
/** @inheritDoc */
|
|
3
4
|
export declare class CommonIsImpl implements CommonIs, CommonIsSecure {
|
|
5
|
+
/** @inheritDoc */
|
|
6
|
+
empty(value: any): boolean;
|
|
7
|
+
/** @inheritDoc */
|
|
8
|
+
primitive(value: any): boolean;
|
|
9
|
+
/** @inheritDoc */
|
|
10
|
+
realValue(value: any): boolean;
|
|
11
|
+
/** @inheritDoc */
|
|
12
|
+
key(value: any): boolean;
|
|
13
|
+
/** @inheritDoc */
|
|
14
|
+
object(value: any): boolean;
|
|
15
|
+
/** @inheritDoc */
|
|
16
|
+
array(value: any): boolean;
|
|
17
|
+
/** @inheritDoc */
|
|
18
|
+
func(value: any): boolean;
|
|
19
|
+
/** @inheritDoc */
|
|
20
|
+
number(value: any): boolean;
|
|
21
|
+
/** @inheritDoc */
|
|
22
|
+
integer(value: any): boolean;
|
|
23
|
+
/** @inheritDoc */
|
|
24
|
+
safeInteger(value: any): boolean;
|
|
25
|
+
/** @inheritDoc */
|
|
26
|
+
string(value: any): boolean;
|
|
27
|
+
/** @inheritDoc */
|
|
28
|
+
text(value: any): boolean;
|
|
29
|
+
/** @inheritDoc */
|
|
30
|
+
clazz(value: any): boolean;
|
|
31
|
+
/** @inheritDoc */
|
|
32
|
+
boolean(value: any): boolean;
|
|
33
|
+
/** @inheritDoc */
|
|
34
|
+
true(value: any): boolean;
|
|
35
|
+
/** @inheritDoc */
|
|
36
|
+
false(value: any): boolean;
|
|
37
|
+
/** @inheritDoc */
|
|
4
38
|
$init(leyyo: Leyyo): void;
|
|
5
|
-
|
|
6
|
-
primitive(value: unknown): boolean;
|
|
7
|
-
value(value: unknown): boolean;
|
|
8
|
-
key(value: unknown): boolean;
|
|
9
|
-
object(value: unknown): boolean;
|
|
10
|
-
array(value: unknown): boolean;
|
|
11
|
-
func(value: unknown): boolean;
|
|
12
|
-
number(value: unknown): boolean;
|
|
13
|
-
integer(value: unknown): boolean;
|
|
14
|
-
string(value: unknown): boolean;
|
|
15
|
-
text(value: unknown): boolean;
|
|
16
|
-
clazz(value: unknown): boolean;
|
|
17
|
-
boolean(value: unknown): boolean;
|
|
18
|
-
true(value: unknown): boolean;
|
|
19
|
-
false(value: unknown): boolean;
|
|
39
|
+
/** @inheritDoc */
|
|
20
40
|
get $back(): CommonIs;
|
|
41
|
+
/** @inheritDoc */
|
|
21
42
|
get $secure(): CommonIsSecure;
|
|
22
43
|
}
|