@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Mustafa Yelmer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Leyyo Common
|
|
2
|
+
Common library for Leyyo framework
|
|
3
|
+
|
|
4
|
+
## Import
|
|
5
|
+
- `npm i @leyyo/common`
|
|
6
|
+
|
|
7
|
+
## Standards
|
|
8
|
+
- Language: `TS`
|
|
9
|
+
- Eslint: `Yes`
|
|
10
|
+
- Static Code Analysis: `Yes` *IntelliJ Code Inspections*
|
|
11
|
+
- DDD - Document Driven: `Yes`
|
|
12
|
+
- DDD - Domain Driven: `Yes`
|
|
13
|
+
- EDD - Exception Driven: `Yes`
|
|
14
|
+
- TDD - Test Driven: `Yes`
|
|
15
|
+
- LDD - Log Driven: `Yes`
|
|
16
|
+
- 12FA - 12 Factor-App: `50%` *Partially*
|
|
17
|
+
|
|
18
|
+
## Dependencies
|
|
19
|
+
### NO
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
### Prepared by
|
|
23
|
+
- Mustafa Yelmer
|
|
24
|
+
- mustafayelmer(at)gmail.com
|
|
25
|
+
- `2025-01-10`
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { LanguageCode, LocaleCode } from "./literals";
|
|
2
|
+
export type BasicType = 'undefined' | 'string' | 'object' | 'number' | 'boolean' | 'function' | 'symbol' | 'bigint';
|
|
3
|
+
export type Dict<T = any> = Record<KeyValue, T>;
|
|
4
|
+
export type Arr<T = any> = Array<T>;
|
|
5
|
+
export type KeyValue = string | number;
|
|
6
|
+
export type Id = string | number;
|
|
7
|
+
export type Unknown = unknown;
|
|
8
|
+
export type Integer = number;
|
|
9
|
+
export type Float = number;
|
|
10
|
+
export type Boolean = boolean;
|
|
11
|
+
export type Enum = string;
|
|
12
|
+
export type Alpha = string;
|
|
13
|
+
export type String = string;
|
|
14
|
+
export type Digit = string;
|
|
15
|
+
export type Title = string;
|
|
16
|
+
export type Description = string;
|
|
17
|
+
export type RichText = string;
|
|
18
|
+
export type Uuid = string;
|
|
19
|
+
export type Host = string;
|
|
20
|
+
export type Url = string;
|
|
21
|
+
export type Email = string;
|
|
22
|
+
export type Folder = string;
|
|
23
|
+
export type Timestamp = number;
|
|
24
|
+
export type IsoDatetime = string;
|
|
25
|
+
export type IsoDate = string;
|
|
26
|
+
export type IsoTime = string;
|
|
27
|
+
interface _Func {
|
|
28
|
+
readonly name?: string;
|
|
29
|
+
readonly length?: number;
|
|
30
|
+
bind(thisArg: any, ...args: Array<any>): any;
|
|
31
|
+
apply(thisArg: any, args: Array<any>): any;
|
|
32
|
+
call(thisArg: any, ...args: Array<any>): any;
|
|
33
|
+
}
|
|
34
|
+
export interface Fnc<R = any> extends _Func {
|
|
35
|
+
(...args: Array<any>): R;
|
|
36
|
+
}
|
|
37
|
+
export interface AsyncFnc<R = any> extends _Func {
|
|
38
|
+
(...args: Array<any>): Promise<R>;
|
|
39
|
+
}
|
|
40
|
+
export type Func<R = any> = Function | Fnc<R>;
|
|
41
|
+
export type Async<R = any> = Function | AsyncFnc<R>;
|
|
42
|
+
export interface ClassLike<T = {}> extends _Func {
|
|
43
|
+
new (...args: Array<any>): T;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Serialized version of another type
|
|
47
|
+
*/
|
|
48
|
+
export type Serialized<T> = {
|
|
49
|
+
[P in keyof T]: T[P];
|
|
50
|
+
};
|
|
51
|
+
export type ClassOrName = ClassLike | string;
|
|
52
|
+
export type FuncOrName = Function | string;
|
|
53
|
+
/**
|
|
54
|
+
* Referenced from Object
|
|
55
|
+
* */
|
|
56
|
+
export type Obj = Object & {};
|
|
57
|
+
export interface Abstract<T> extends Function {
|
|
58
|
+
prototype: T;
|
|
59
|
+
}
|
|
60
|
+
export interface Entity<I extends Id = Uuid> {
|
|
61
|
+
id?: I;
|
|
62
|
+
}
|
|
63
|
+
export interface Pair<I extends Id = Uuid> extends Entity<I> {
|
|
64
|
+
name?: string;
|
|
65
|
+
}
|
|
66
|
+
export type TypeOfMethod<T, M extends keyof T> = T[M] extends Function ? T[M] : never;
|
|
67
|
+
export type KeyOf<T> = keyof T;
|
|
68
|
+
export type Keys<T> = Array<keyof T>;
|
|
69
|
+
export type ValueOf<T> = T[KeyOf<T>];
|
|
70
|
+
export type Values<T> = Array<T[KeyOf<T>]>;
|
|
71
|
+
export type MaximumOneOf<T, K extends keyof T = keyof T> = K extends keyof T ? {
|
|
72
|
+
[P in K]: T[K];
|
|
73
|
+
} & Partial<Record<Exclude<keyof T, K>, never>> : never;
|
|
74
|
+
export type OneOf<Obj> = ValueOf<OneOfByKey<Obj>>;
|
|
75
|
+
export type Xor<A, B> = XorIn<A & {
|
|
76
|
+
[K in keyof B]?: undefined;
|
|
77
|
+
}> | XorIn<B & {
|
|
78
|
+
[K in keyof A]?: undefined;
|
|
79
|
+
}>;
|
|
80
|
+
export type Mutable<A> = {
|
|
81
|
+
-readonly [K in keyof A]: A[K];
|
|
82
|
+
};
|
|
83
|
+
export type OneOrMore<T> = T | Array<T>;
|
|
84
|
+
export type SameType<A, T> = {
|
|
85
|
+
[K in keyof A]: T;
|
|
86
|
+
};
|
|
87
|
+
type OneOnly<T, K extends keyof T> = Omit<T, Exclude<keyof T, K>> | Pick<T, K>;
|
|
88
|
+
type OneOfByKey<T> = {
|
|
89
|
+
[key in keyof T]: OneOnly<T, key>;
|
|
90
|
+
};
|
|
91
|
+
type XorIn<T> = {
|
|
92
|
+
[K in keyof T]: T[K];
|
|
93
|
+
} & unknown;
|
|
94
|
+
export interface ShiftSecure<S extends ShiftMain<any>> {
|
|
95
|
+
get $secure(): S;
|
|
96
|
+
}
|
|
97
|
+
export interface ShiftFlat<D> {
|
|
98
|
+
get $flat(): D;
|
|
99
|
+
}
|
|
100
|
+
export interface ShiftMain<M extends ShiftSecure<any>> {
|
|
101
|
+
get $back(): M;
|
|
102
|
+
}
|
|
103
|
+
export interface InitLike {
|
|
104
|
+
$init(...args: Arr): void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* JSON Object
|
|
108
|
+
*/
|
|
109
|
+
export type JsonObject = {
|
|
110
|
+
[K in string]?: JsonValue;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* JSON Array
|
|
114
|
+
*/
|
|
115
|
+
export type JsonArray = Array<JsonValue>;
|
|
116
|
+
/**
|
|
117
|
+
* JSON Primitives
|
|
118
|
+
*/
|
|
119
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
120
|
+
/**
|
|
121
|
+
* JSON Values
|
|
122
|
+
*/
|
|
123
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
124
|
+
/**
|
|
125
|
+
* Primitive language key
|
|
126
|
+
*
|
|
127
|
+
* It can be language (xx), local (xx-xx) or string (not preferred)
|
|
128
|
+
* */
|
|
129
|
+
export type I18nKey = LanguageCode | LocaleCode | string;
|
|
130
|
+
/**
|
|
131
|
+
* Language map
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* const name = {en: "Apple", tr: "Elma"};
|
|
135
|
+
*
|
|
136
|
+
* */
|
|
137
|
+
export type I18nRaw<V = unknown> = Dict<V>;
|
|
138
|
+
export type I18nAny<V = unknown> = I18nRaw<V> | V;
|
|
139
|
+
export {};
|
package/dist/aliases.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AssertionOpt } from "./index-types";
|
|
2
|
+
import { Leyyo } from "../leyyo";
|
|
3
|
+
export declare function assert(flag: boolean, message?: string): void;
|
|
4
|
+
export declare function assert(flag: boolean, opt?: AssertionOpt): void;
|
|
5
|
+
export declare function assert(flag: boolean, fn?: Function): void;
|
|
6
|
+
export declare function $$setLeyyo(leyyo: Leyyo): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assert = assert;
|
|
4
|
+
exports.$$setLeyyo = $$setLeyyo;
|
|
5
|
+
let assertion;
|
|
6
|
+
function assert(flag, v2) {
|
|
7
|
+
if (!flag) {
|
|
8
|
+
assertion.raise(v2);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function $$setLeyyo(leyyo) {
|
|
12
|
+
assertion = leyyo.assertion;
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AssertionCallback, AssertionOpt, CommonAssertion, CommonAssertionSecure } from "./index-types";
|
|
2
|
+
import { Leyyo } from "../leyyo";
|
|
3
|
+
import { TypeOpt } from "../to";
|
|
4
|
+
import { Arr, Obj } from "../aliases";
|
|
5
|
+
export declare class CommonAssertionImpl implements CommonAssertion, CommonAssertionSecure {
|
|
6
|
+
private is;
|
|
7
|
+
private callback;
|
|
8
|
+
constructor();
|
|
9
|
+
private buildMessage;
|
|
10
|
+
_secureJson(value: unknown, level: number, set: WeakSet<Obj>): unknown;
|
|
11
|
+
raise(opt: string | AssertionOpt | AssertionCallback, value?: any, indicator?: string, def?: string): void;
|
|
12
|
+
emptyFn(...params: Arr): void;
|
|
13
|
+
secureJson<E = unknown>(value: unknown): E;
|
|
14
|
+
realNumber(value: number, opt?: TypeOpt): number;
|
|
15
|
+
array(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
16
|
+
boolean(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
17
|
+
clazz(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
18
|
+
date(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
19
|
+
func(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
20
|
+
integer(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
21
|
+
key(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
22
|
+
notEmpty(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
23
|
+
number(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
24
|
+
object(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
25
|
+
positiveInteger(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
26
|
+
positiveNumber(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
27
|
+
primitive(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
28
|
+
string(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
29
|
+
text(value: unknown, opt?: string | AssertionOpt | AssertionCallback): string;
|
|
30
|
+
value(value: unknown, opt?: string | AssertionOpt | AssertionCallback): void;
|
|
31
|
+
get $back(): CommonAssertion;
|
|
32
|
+
$init(leyyo: Leyyo): void;
|
|
33
|
+
get $secure(): CommonAssertionSecure;
|
|
34
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonAssertionImpl = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
class CommonAssertionImpl {
|
|
6
|
+
// endregion properties
|
|
7
|
+
constructor() {
|
|
8
|
+
}
|
|
9
|
+
// region internal
|
|
10
|
+
buildMessage(v2, indicator) {
|
|
11
|
+
if (typeof v2 === 'string') {
|
|
12
|
+
return { message: v2, params: { indicator } };
|
|
13
|
+
}
|
|
14
|
+
if (v2 && typeof v2 === 'object' && !Array.isArray(v2)) {
|
|
15
|
+
const params = v2;
|
|
16
|
+
if (params.indicator !== undefined) {
|
|
17
|
+
params.indicator2 = params.indicator;
|
|
18
|
+
params.indicator = indicator;
|
|
19
|
+
}
|
|
20
|
+
return { params };
|
|
21
|
+
}
|
|
22
|
+
if (typeof v2 === 'function') {
|
|
23
|
+
try {
|
|
24
|
+
return this.buildMessage(v2(), indicator);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
return { params: { indicator, callbackError: e.message } };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (v2 === null || v2 === undefined) {
|
|
31
|
+
return { params: { indicator } };
|
|
32
|
+
}
|
|
33
|
+
const json = this.secureJson(v2);
|
|
34
|
+
if (json && typeof json === 'object' && !Array.isArray(json)) {
|
|
35
|
+
return { params: Object.assign(Object.assign({}, json), { indicator }) };
|
|
36
|
+
}
|
|
37
|
+
return { params: { json, indicator } };
|
|
38
|
+
}
|
|
39
|
+
_secureJson(value, level, set) {
|
|
40
|
+
if ([null, undefined].includes(value)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
switch (typeof value) {
|
|
44
|
+
case 'object':
|
|
45
|
+
if (set.has(value)) {
|
|
46
|
+
return `<circular>${this.callback.fqnName(value === null || value === void 0 ? void 0 : value.constructor)}`;
|
|
47
|
+
}
|
|
48
|
+
if (level >= 10) {
|
|
49
|
+
return `<max-depth>${this.callback.fqnName(value === null || value === void 0 ? void 0 : value.constructor)}`;
|
|
50
|
+
}
|
|
51
|
+
set.add(value);
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return value.map(item => this._secureJson(item, level + 1, set));
|
|
54
|
+
}
|
|
55
|
+
const obj = {};
|
|
56
|
+
if (value instanceof Map) {
|
|
57
|
+
for (const [k, v] of value.entries()) {
|
|
58
|
+
obj[k] = JSON.parse(JSON.stringify(this._secureJson(v, level + 1, set)));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (value instanceof Set) {
|
|
62
|
+
return Array.from(value).map(item => this._secureJson(item, level + 1, set));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
for (const [k, v] of Object.entries(value)) {
|
|
66
|
+
obj[k] = JSON.parse(JSON.stringify(this._secureJson(v, level + 1, set)));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return obj;
|
|
70
|
+
case 'function':
|
|
71
|
+
return `<function>${this.callback.fqnName(value)}`;
|
|
72
|
+
case 'symbol':
|
|
73
|
+
return `<symbol>${value.toString()}`;
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
// endregion internal
|
|
78
|
+
// region raise
|
|
79
|
+
raise(opt, value, indicator, def) {
|
|
80
|
+
const { message, params } = this.buildMessage(opt, indicator);
|
|
81
|
+
const type = typeof value;
|
|
82
|
+
switch (type) {
|
|
83
|
+
case "object":
|
|
84
|
+
params.type = `object(${this.callback.fqnName(value.constructor)})`;
|
|
85
|
+
break;
|
|
86
|
+
case "function":
|
|
87
|
+
params.type = `function(${this.callback.fqnName(value)})`;
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
params.type = type;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
def = def !== null && def !== void 0 ? def : 'Assertion error';
|
|
94
|
+
throw new error_1.AssertionException(message !== null && message !== void 0 ? message : def, params);
|
|
95
|
+
}
|
|
96
|
+
// noinspection JSUnusedLocalSymbols
|
|
97
|
+
emptyFn(...params) { }
|
|
98
|
+
secureJson(value) {
|
|
99
|
+
return this._secureJson(value, 0, new WeakSet());
|
|
100
|
+
}
|
|
101
|
+
realNumber(value, opt) {
|
|
102
|
+
if (isNaN(value) || !isFinite(value)) {
|
|
103
|
+
if (!opt) {
|
|
104
|
+
opt = {};
|
|
105
|
+
}
|
|
106
|
+
if (!opt.silent) {
|
|
107
|
+
delete opt.silent;
|
|
108
|
+
this.raise(opt, value, 'not.real.number', 'Not real number');
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
// endregion raise
|
|
115
|
+
// region types
|
|
116
|
+
array(value, opt) {
|
|
117
|
+
if (!this.is.array(value)) {
|
|
118
|
+
this.raise(opt, value, 'invalid.array.value', 'Invalid array value');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
boolean(value, opt) {
|
|
122
|
+
if (!this.is.boolean(value)) {
|
|
123
|
+
this.raise(opt, value, 'invalid.boolean.value', 'Invalid boolean value');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
clazz(value, opt) {
|
|
127
|
+
if (!this.is.clazz(value)) {
|
|
128
|
+
this.raise(opt, value, 'invalid.class.value', 'Invalid class value');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
date(value, opt) {
|
|
132
|
+
if (!(value instanceof Date)) {
|
|
133
|
+
this.raise(opt, value, 'invalid.date.value', 'Invalid date value');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
func(value, opt) {
|
|
137
|
+
if (!this.is.func(value)) {
|
|
138
|
+
this.raise(opt, value, 'invalid.function.value', 'Invalid function value');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
integer(value, opt) {
|
|
142
|
+
if (!this.is.integer(value)) {
|
|
143
|
+
this.raise(opt, value, 'invalid.integer.value', 'Invalid integer value');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
key(value, opt) {
|
|
147
|
+
if (!this.is.key(value)) {
|
|
148
|
+
this.raise(opt, value, 'invalid.key.value', 'Invalid key value');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
notEmpty(value, opt) {
|
|
152
|
+
if (this.is.empty(value)) {
|
|
153
|
+
this.raise(opt, value, 'empty.value', 'Empty value');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
number(value, opt) {
|
|
157
|
+
if (!this.is.number(value)) {
|
|
158
|
+
this.raise(opt, value, 'invalid.number.value', 'Invalid number value');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
object(value, opt) {
|
|
162
|
+
if (!this.is.object(value)) {
|
|
163
|
+
this.raise(opt, value, 'invalid.object.value', 'Invalid object value');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
positiveInteger(value, opt) {
|
|
167
|
+
if (!this.is.integer(value) || (value <= 0)) {
|
|
168
|
+
this.raise(opt, value, 'invalid.positive.integer.value', 'Invalid positive integer value');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
positiveNumber(value, opt) {
|
|
172
|
+
if (!this.is.number(value) || (value <= 0)) {
|
|
173
|
+
this.raise(opt, value, 'invalid.positive.number.value', 'Invalid positive number value');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
primitive(value, opt) {
|
|
177
|
+
if (!this.is.primitive(value)) {
|
|
178
|
+
this.raise(opt, value, 'invalid.primitive.value', 'Invalid primitive value');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
string(value, opt) {
|
|
182
|
+
if (!this.is.string(value)) {
|
|
183
|
+
this.raise(opt, value, 'invalid.string.value', 'Invalid string value');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
text(value, opt) {
|
|
187
|
+
if (!this.is.text(value)) {
|
|
188
|
+
this.raise(opt, value, 'invalid.text.value', 'Invalid text value');
|
|
189
|
+
}
|
|
190
|
+
return value.trim();
|
|
191
|
+
}
|
|
192
|
+
value(value, opt) {
|
|
193
|
+
if (!this.is.text(value)) {
|
|
194
|
+
this.raise(opt, value, 'invalid.value.value', 'Invalid regular value');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// endregion types
|
|
198
|
+
// region secure
|
|
199
|
+
get $back() {
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
$init(leyyo) {
|
|
203
|
+
this.is = leyyo.is;
|
|
204
|
+
this.callback = leyyo.callback;
|
|
205
|
+
}
|
|
206
|
+
get $secure() {
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.CommonAssertionImpl = CommonAssertionImpl;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Leyyo } from "../leyyo";
|
|
2
|
+
import { Arr, OneOrMore, ShiftMain, ShiftSecure } from "../aliases";
|
|
3
|
+
import { TypeOpt } from "../to";
|
|
4
|
+
export interface CommonAssertion extends ShiftSecure<CommonAssertionSecure> {
|
|
5
|
+
raise(opt: string, value?: any, indicator?: string, def?: string): void;
|
|
6
|
+
raise(opt: AssertionCallback, value?: any, indicator?: string, def?: string): void;
|
|
7
|
+
raise(opt: AssertionOpt, value?: any, indicator?: string, def?: string): void;
|
|
8
|
+
emptyFn(...params: Arr): void;
|
|
9
|
+
secureJson<E = unknown>(value: unknown): E;
|
|
10
|
+
realNumber(value: number, opt?: TypeOpt): number;
|
|
11
|
+
notEmpty(value: unknown, message?: string): void;
|
|
12
|
+
notEmpty(value: unknown, fn?: AssertionCallback): void;
|
|
13
|
+
notEmpty(value: unknown, opt?: AssertionOpt): void;
|
|
14
|
+
primitive(value: unknown, message?: string): void;
|
|
15
|
+
primitive(value: unknown, fn?: AssertionCallback): void;
|
|
16
|
+
primitive(value: unknown, opt?: AssertionOpt): void;
|
|
17
|
+
value(value: unknown, message?: string): void;
|
|
18
|
+
value(value: unknown, fn?: AssertionCallback): void;
|
|
19
|
+
value(value: unknown, opt?: AssertionOpt): void;
|
|
20
|
+
key(value: unknown, message?: string): void;
|
|
21
|
+
key(value: unknown, fn?: AssertionCallback): void;
|
|
22
|
+
key(value: unknown, opt?: AssertionOpt): void;
|
|
23
|
+
object(value: unknown, message?: string): void;
|
|
24
|
+
object(value: unknown, fn?: AssertionCallback): void;
|
|
25
|
+
object(value: unknown, opt?: AssertionOpt): void;
|
|
26
|
+
array(value: unknown, message?: string): void;
|
|
27
|
+
array(value: unknown, fn?: AssertionCallback): void;
|
|
28
|
+
array(value: unknown, opt?: AssertionOpt): void;
|
|
29
|
+
func(value: unknown, message?: string): void;
|
|
30
|
+
func(value: unknown, fn?: AssertionCallback): void;
|
|
31
|
+
func(value: unknown, opt?: AssertionOpt): void;
|
|
32
|
+
number(value: unknown, message?: string): void;
|
|
33
|
+
number(value: unknown, fn?: AssertionCallback): void;
|
|
34
|
+
number(value: unknown, opt?: AssertionOpt): void;
|
|
35
|
+
positiveNumber(value: unknown, message?: string): void;
|
|
36
|
+
positiveNumber(value: unknown, fn?: AssertionCallback): void;
|
|
37
|
+
positiveNumber(value: unknown, opt?: AssertionOpt): void;
|
|
38
|
+
integer(value: unknown, message?: string): void;
|
|
39
|
+
integer(value: unknown, fn?: AssertionCallback): void;
|
|
40
|
+
integer(value: unknown, opt?: AssertionOpt): void;
|
|
41
|
+
positiveInteger(value: unknown, message?: string): void;
|
|
42
|
+
positiveInteger(value: unknown, fn?: AssertionCallback): void;
|
|
43
|
+
positiveInteger(value: unknown, opt?: AssertionOpt): void;
|
|
44
|
+
string(value: unknown, message?: string): void;
|
|
45
|
+
string(value: unknown, fn?: AssertionCallback): void;
|
|
46
|
+
string(value: unknown, opt?: AssertionOpt): void;
|
|
47
|
+
text(value: unknown, message?: string): string;
|
|
48
|
+
text(value: unknown, fn?: AssertionCallback): string;
|
|
49
|
+
text(value: unknown, opt?: AssertionOpt): string;
|
|
50
|
+
clazz(value: unknown, message?: string): void;
|
|
51
|
+
clazz(value: unknown, fn?: AssertionCallback): void;
|
|
52
|
+
clazz(value: unknown, opt?: AssertionOpt): void;
|
|
53
|
+
date(value: unknown, message?: string): void;
|
|
54
|
+
date(value: unknown, fn?: AssertionCallback): void;
|
|
55
|
+
date(value: unknown, opt?: AssertionOpt): void;
|
|
56
|
+
boolean(value: unknown, message?: string): void;
|
|
57
|
+
boolean(value: unknown, fn?: AssertionCallback): void;
|
|
58
|
+
boolean(value: unknown, opt?: AssertionOpt): void;
|
|
59
|
+
}
|
|
60
|
+
export interface CommonAssertionSecure extends ShiftMain<CommonAssertion> {
|
|
61
|
+
$init(leyyo: Leyyo): void;
|
|
62
|
+
}
|
|
63
|
+
export interface AssertionOpt {
|
|
64
|
+
indicator?: AssertionReason | string;
|
|
65
|
+
param?: string;
|
|
66
|
+
where?: string;
|
|
67
|
+
value?: any;
|
|
68
|
+
expected?: OneOrMore<string>;
|
|
69
|
+
current?: string;
|
|
70
|
+
type?: string;
|
|
71
|
+
[k: string]: any;
|
|
72
|
+
}
|
|
73
|
+
type AssertionReason = 'invalid.type' | 'not.found' | 'duplicated' | 'empty';
|
|
74
|
+
export type AssertionCallback = () => string | AssertionOpt;
|
|
75
|
+
export interface AssertionBuiltResult {
|
|
76
|
+
message?: string;
|
|
77
|
+
params: AssertionOpt;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
@@ -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("./common-assertion-impl"), exports);
|
|
19
|
+
__exportStar(require("./assert"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Arr } from "../aliases";
|
|
2
|
+
import { CallbackWhenDefinedLambda, CommonCallback, CommonCallbackDefined, CommonCallbackSecure } from "./index-types";
|
|
3
|
+
import { Leyyo } from "../leyyo";
|
|
4
|
+
export declare class CommonCallbackImpl implements CommonCallback, CommonCallbackSecure {
|
|
5
|
+
private _waitingForCallbacks;
|
|
6
|
+
private _attachedCallbacks;
|
|
7
|
+
private _waitingForProviders;
|
|
8
|
+
private _definedProviders;
|
|
9
|
+
fqnName(value: any): string;
|
|
10
|
+
/**
|
|
11
|
+
* Default constructor
|
|
12
|
+
*
|
|
13
|
+
* Responsibilities
|
|
14
|
+
* - Create repositories => ie: callbacks
|
|
15
|
+
* - Trigger clear pending operation
|
|
16
|
+
* */
|
|
17
|
+
constructor();
|
|
18
|
+
$init(leyyo: Leyyo): void;
|
|
19
|
+
/**
|
|
20
|
+
* Clear jobs in the queue which named as pending
|
|
21
|
+
*
|
|
22
|
+
* Because the expected callback may not be defined
|
|
23
|
+
* */
|
|
24
|
+
private _clearPending;
|
|
25
|
+
get $secure(): CommonCallbackSecure;
|
|
26
|
+
attachCallback(name: string, fn: Function): void;
|
|
27
|
+
queueForCallback(name: string, ...args: Arr): boolean;
|
|
28
|
+
get $back(): CommonCallback;
|
|
29
|
+
whenProviderDefined<T extends CommonCallbackDefined = CommonCallbackDefined>(name: string, consumer: Function, callback: CallbackWhenDefinedLambda<T>): void;
|
|
30
|
+
defineProvider<T extends CommonCallbackDefined = CommonCallbackDefined>(name: string, producer: Function, instance: T): void;
|
|
31
|
+
}
|