@leyyo/common 1.0.1 → 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 +3 -4
- package/dist/assertion/common-assertion-impl.js +9 -8
- package/dist/assertion/index-types.d.ts +6 -22
- 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 -52
- 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.js +6 -6
- package/dist/is/index-types.d.ts +2 -3
- 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 -52
- 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 +3 -3
- package/dist/log/logger-impl.js +5 -5
- package/dist/{assertion → shared}/assert.js +1 -0
- package/dist/{aliases.d.ts → shared/index-aliases.d.ts} +1 -1
- 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 -3
- package/dist/storage/common-storage-impl.js +3 -3
- package/dist/storage/index-types.d.ts +3 -13
- package/dist/storage/index.d.ts +0 -1
- package/dist/storage/index.js +0 -1
- package/dist/to/common-to-impl.d.ts +3 -3
- package/dist/to/common-to-impl.js +11 -11
- package/dist/to/index-types.d.ts +1 -30
- 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 -73
- package/dist/callback/index.d.ts +0 -2
- package/dist/literals.d.ts +0 -106
- package/dist/literals.js +0 -81
- 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,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonAssertion, CommonAssertionSecure } from "./index-types";
|
|
2
2
|
import { Leyyo } from "../leyyo";
|
|
3
|
-
import { ToTypeOpt } from "../
|
|
4
|
-
import { Arr, Obj } from "../aliases";
|
|
3
|
+
import { Arr, AssertionCallback, AssertionOpt, Obj, ToTypeOpt } from "../shared";
|
|
5
4
|
/** @inheritDoc */
|
|
6
5
|
export declare class CommonAssertionImpl implements CommonAssertion, CommonAssertionSecure {
|
|
7
6
|
private is;
|
|
8
|
-
private
|
|
7
|
+
private fqn;
|
|
9
8
|
constructor();
|
|
10
9
|
/**
|
|
11
10
|
* Build error parameters as message and params
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonAssertionImpl = void 0;
|
|
4
|
-
const
|
|
4
|
+
const exception_1 = require("../exception");
|
|
5
|
+
// noinspection JSUnusedGlobalSymbols
|
|
5
6
|
/** @inheritDoc */
|
|
6
7
|
class CommonAssertionImpl {
|
|
7
8
|
// endregion properties
|
|
@@ -50,10 +51,10 @@ class CommonAssertionImpl {
|
|
|
50
51
|
switch (typeof value) {
|
|
51
52
|
case 'object':
|
|
52
53
|
if (set.has(value)) {
|
|
53
|
-
return `<circular>${this.
|
|
54
|
+
return `<circular>${this.fqn.name(value === null || value === void 0 ? void 0 : value.constructor)}`;
|
|
54
55
|
}
|
|
55
56
|
if (level >= 10) {
|
|
56
|
-
return `<max-depth>${this.
|
|
57
|
+
return `<max-depth>${this.fqn.name(value === null || value === void 0 ? void 0 : value.constructor)}`;
|
|
57
58
|
}
|
|
58
59
|
set.add(value);
|
|
59
60
|
if (Array.isArray(value)) {
|
|
@@ -75,7 +76,7 @@ class CommonAssertionImpl {
|
|
|
75
76
|
}
|
|
76
77
|
return obj;
|
|
77
78
|
case 'function':
|
|
78
|
-
return `<function>${this.
|
|
79
|
+
return `<function>${this.fqn.name(value)}`;
|
|
79
80
|
case 'symbol':
|
|
80
81
|
return `<symbol>${value.toString()}`;
|
|
81
82
|
}
|
|
@@ -89,17 +90,17 @@ class CommonAssertionImpl {
|
|
|
89
90
|
const type = typeof value;
|
|
90
91
|
switch (type) {
|
|
91
92
|
case "object":
|
|
92
|
-
params.type = `object(${this.
|
|
93
|
+
params.type = `object(${this.fqn.name(value.constructor)})`;
|
|
93
94
|
break;
|
|
94
95
|
case "function":
|
|
95
|
-
params.type = `function(${this.
|
|
96
|
+
params.type = `function(${this.fqn.name(value)})`;
|
|
96
97
|
break;
|
|
97
98
|
default:
|
|
98
99
|
params.type = type;
|
|
99
100
|
break;
|
|
100
101
|
}
|
|
101
102
|
def = def !== null && def !== void 0 ? def : 'Assertion error';
|
|
102
|
-
throw new
|
|
103
|
+
throw new exception_1.AssertionException(message !== null && message !== void 0 ? message : def, params);
|
|
103
104
|
}
|
|
104
105
|
/** @inheritDoc */
|
|
105
106
|
// noinspection JSUnusedLocalSymbols
|
|
@@ -237,7 +238,7 @@ class CommonAssertionImpl {
|
|
|
237
238
|
/** @inheritDoc */
|
|
238
239
|
$init(leyyo) {
|
|
239
240
|
this.is = leyyo.is;
|
|
240
|
-
this.
|
|
241
|
+
this.fqn = leyyo.fqn;
|
|
241
242
|
}
|
|
242
243
|
/** @inheritDoc */
|
|
243
244
|
get $secure() {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Arr,
|
|
2
|
-
import { ToTypeOpt } from "../to";
|
|
1
|
+
import { Arr, AssertionCallback, AssertionOpt, InitLike, ShiftMain, ShiftSecure, ToTypeOpt } from "../shared";
|
|
3
2
|
/**
|
|
4
|
-
* Basic
|
|
3
|
+
* Basic assertions to easy use
|
|
5
4
|
* */
|
|
6
5
|
export interface CommonAssertion extends ShiftSecure<CommonAssertionSecure> {
|
|
7
6
|
/**
|
|
@@ -465,22 +464,7 @@ export interface CommonAssertion extends ShiftSecure<CommonAssertionSecure> {
|
|
|
465
464
|
* */
|
|
466
465
|
boolean(value: any, opt?: AssertionOpt): void;
|
|
467
466
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
param?: string;
|
|
473
|
-
where?: string;
|
|
474
|
-
value?: any;
|
|
475
|
-
expected?: OneOrMore<string>;
|
|
476
|
-
current?: string;
|
|
477
|
-
type?: string;
|
|
478
|
-
[k: string]: any;
|
|
479
|
-
}
|
|
480
|
-
type AssertionReason = 'invalid.type' | 'not.found' | 'duplicated' | 'empty';
|
|
481
|
-
export type AssertionCallback = () => string | AssertionOpt;
|
|
482
|
-
export interface AssertionBuiltResult {
|
|
483
|
-
message?: string;
|
|
484
|
-
params: AssertionOpt;
|
|
485
|
-
}
|
|
486
|
-
export {};
|
|
467
|
+
/**
|
|
468
|
+
* Secure assertion methods
|
|
469
|
+
* */
|
|
470
|
+
export type CommonAssertionSecure = ShiftMain<CommonAssertion> & InitLike;
|
package/dist/assertion/index.js
CHANGED
|
@@ -16,4 +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-assertion-impl"), exports);
|
|
19
|
-
__exportStar(require("./assert"), exports);
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { CommonError, CommonErrorSecure
|
|
1
|
+
import { CommonError, CommonErrorSecure } from "./index-types";
|
|
2
2
|
import { Leyyo } from "../leyyo";
|
|
3
|
-
import { Dict } from "../
|
|
4
|
-
import {
|
|
3
|
+
import { Dict } from "../shared";
|
|
4
|
+
import { ExceptionLike } from "../exception";
|
|
5
5
|
export declare class CommonErrorImpl implements CommonError, CommonErrorSecure {
|
|
6
|
+
private hook;
|
|
6
7
|
get $back(): CommonError;
|
|
7
8
|
$init(leyyo: Leyyo): void;
|
|
8
9
|
get $secure(): CommonErrorSecure;
|
|
9
10
|
addOmit(clz: Function, ...properties: Array<string>): boolean;
|
|
10
11
|
addSign(err: Error, ...keys: Array<string>): boolean;
|
|
11
12
|
afterCreate(e: ExceptionLike): void;
|
|
13
|
+
register(cls: Function): void;
|
|
12
14
|
build(e: Error | string): ExceptionLike;
|
|
13
15
|
buildStack(e: Error): void;
|
|
14
|
-
copyStack(exception:
|
|
16
|
+
copyStack(exception: ExceptionLike, error: Error): void;
|
|
15
17
|
causedBy(e: Error | string): ExceptionLike;
|
|
16
18
|
getOmit(clz: Function): Array<string>;
|
|
17
19
|
getSign(err: Error): Array<string>;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonErrorImpl = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const shared_1 = require("../shared");
|
|
5
|
+
const exception_1 = require("../exception");
|
|
6
6
|
// noinspection JSUnusedLocalSymbols
|
|
7
7
|
class CommonErrorImpl {
|
|
8
8
|
get $back() {
|
|
9
9
|
return this;
|
|
10
10
|
}
|
|
11
11
|
$init(leyyo) {
|
|
12
|
+
this.hook = leyyo.hook;
|
|
12
13
|
const fields = ['build', 'afterCreate', 'causedBy', 'toObject', 'buildStack', 'copyStack',
|
|
13
14
|
'initSign', 'addSign', 'getSign', 'removeSign', 'hasSign',
|
|
14
15
|
'initOmit', 'addOmit', 'getOmit', 'inheritOmit'];
|
|
@@ -17,9 +18,9 @@ class CommonErrorImpl {
|
|
|
17
18
|
rec[field] = this[field];
|
|
18
19
|
});
|
|
19
20
|
// define itself temporarily for error operations
|
|
20
|
-
|
|
21
|
+
this.hook.defineProvider(shared_1.LY_ATTACHED_ERROR, CommonErrorImpl, rec);
|
|
21
22
|
// when new error provider is defined, replace all common methods
|
|
22
|
-
|
|
23
|
+
this.hook.whenProviderDefined(shared_1.LY_ATTACHED_ERROR, CommonErrorImpl, (ins) => {
|
|
23
24
|
fields.forEach(field => {
|
|
24
25
|
if (typeof ins[field] === 'function') {
|
|
25
26
|
this[field] = ins[field];
|
|
@@ -39,6 +40,9 @@ class CommonErrorImpl {
|
|
|
39
40
|
afterCreate(e) {
|
|
40
41
|
e.$secure.$setName(e.constructor.name);
|
|
41
42
|
}
|
|
43
|
+
register(cls) {
|
|
44
|
+
this.hook.queueForCallback(shared_1.LY_PENDING_ERROR_REGISTER, cls);
|
|
45
|
+
}
|
|
42
46
|
build(e) {
|
|
43
47
|
if (e instanceof exception_1.Exception) {
|
|
44
48
|
return e;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { CommonCallbackDefined } from "../callback";
|
|
1
|
+
import { Dict, InitLike, ShiftMain, ShiftSecure } from "../shared";
|
|
2
|
+
import { ExceptionLike } from "../exception";
|
|
4
3
|
export interface CommonError extends ShiftSecure<CommonErrorSecure> {
|
|
4
|
+
register(cls: Function): void;
|
|
5
5
|
build(e: Error | string): ExceptionLike;
|
|
6
6
|
afterCreate(e: ExceptionLike): void;
|
|
7
7
|
causedBy(e: Error | string): ExceptionLike;
|
|
@@ -12,57 +12,10 @@ export interface CommonError extends ShiftSecure<CommonErrorSecure> {
|
|
|
12
12
|
hasSign(err: Error, key: string): boolean;
|
|
13
13
|
toObject(e: Error, ...omittedFields: Array<string>): Dict;
|
|
14
14
|
buildStack(e: Error): void;
|
|
15
|
-
copyStack(exception:
|
|
15
|
+
copyStack(exception: ExceptionLike, error: Error): void;
|
|
16
16
|
initOmit(clz: Function): boolean;
|
|
17
17
|
addOmit(clz: Function, ...properties: Array<string>): boolean;
|
|
18
18
|
getOmit(clz: Function): Array<string>;
|
|
19
19
|
inheritOmit(clz: Function): Array<string>;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
22
|
-
build?(e: Error | string): ExceptionLike;
|
|
23
|
-
afterCreate?(e: ExceptionLike): void;
|
|
24
|
-
causedBy?(e: Error | string): ExceptionLike;
|
|
25
|
-
initSign?(err: Error): boolean;
|
|
26
|
-
addSign?(err: Error, ...keys: Array<string>): boolean;
|
|
27
|
-
getSign?(err: Error): Array<string>;
|
|
28
|
-
removeSign?(err: Error, ...keys: Array<string>): boolean;
|
|
29
|
-
hasSign?(err: Error, key: string): boolean;
|
|
30
|
-
toObject?(e: Error, ...omittedFields: Array<string>): Dict;
|
|
31
|
-
buildStack?(e: Error): void;
|
|
32
|
-
copyStack?(exception: Exception, error: Error): void;
|
|
33
|
-
initOmit?(clz: Function): boolean;
|
|
34
|
-
addOmit?(clz: Function, ...properties: Array<string>): boolean;
|
|
35
|
-
getOmit?(clz: Function): Array<string>;
|
|
36
|
-
inheritOmit?(clz: Function): Array<string>;
|
|
37
|
-
}
|
|
38
|
-
export interface CommonErrorSecure extends ShiftMain<CommonError>, InitLike {
|
|
39
|
-
}
|
|
40
|
-
export interface ExceptionStackLine {
|
|
41
|
-
file?: string;
|
|
42
|
-
method?: string;
|
|
43
|
-
line?: number;
|
|
44
|
-
column?: number;
|
|
45
|
-
}
|
|
46
|
-
export interface ExceptionParamsAppend extends Dict {
|
|
47
|
-
indicator?: string;
|
|
48
|
-
}
|
|
49
|
-
export interface ExceptionLike extends Error, ShiftSecure<ExceptionSecure> {
|
|
50
|
-
get params(): Dict;
|
|
51
|
-
causedBy(e: Error | string): this;
|
|
52
|
-
with(clazz: ClassLike): this;
|
|
53
|
-
with(instance: Abstract<any>): this;
|
|
54
|
-
with(name: string): this;
|
|
55
|
-
with(value: any): this;
|
|
56
|
-
appendParams(params: ExceptionParamsAppend, ignoreExisting?: boolean): this;
|
|
57
|
-
log(req?: unknown): this;
|
|
58
|
-
raise(throwable?: boolean, req?: unknown): this;
|
|
59
|
-
toObject(...omittedFields: Array<string>): Dict;
|
|
60
|
-
toJSON(): Dict;
|
|
61
|
-
}
|
|
62
|
-
export interface ExceptionSecure extends ShiftMain<ExceptionLike> {
|
|
63
|
-
$setName(name: string): this;
|
|
64
|
-
$hasSign(key: string): boolean;
|
|
65
|
-
$listSigns(): Array<string>;
|
|
66
|
-
$addSign(...keys: Array<string>): boolean;
|
|
67
|
-
$removeSign(...keys: Array<string>): boolean;
|
|
68
|
-
}
|
|
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;
|