@leyyo/common 1.0.4 → 1.0.6
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.d.ts +54 -0
- package/dist/assertion/common-assertion.js +180 -0
- package/dist/assertion/common-assertion.js.map +1 -0
- package/dist/assertion/index-types.d.ts +154 -159
- package/dist/assertion/index-types.js +1 -0
- package/dist/assertion/index-types.js.map +1 -0
- package/dist/assertion/index.d.ts +0 -1
- package/dist/assertion/index.js +1 -1
- package/dist/assertion/index.js.map +1 -0
- package/dist/descriptor/common-descriptor.d.ts +19 -0
- package/dist/descriptor/common-descriptor.js +92 -0
- package/dist/descriptor/common-descriptor.js.map +1 -0
- package/dist/descriptor/index-types.d.ts +21 -0
- package/dist/{literal → descriptor}/index-types.js +1 -0
- package/dist/descriptor/index-types.js.map +1 -0
- package/dist/descriptor/index.d.ts +1 -0
- package/dist/{storage → descriptor}/index.js +1 -1
- package/dist/descriptor/index.js.map +1 -0
- package/dist/developer/common-developer.d.ts +29 -0
- package/dist/developer/common-developer.js +266 -0
- package/dist/developer/common-developer.js.map +1 -0
- package/dist/developer/index-types.d.ts +77 -0
- package/dist/{storage → developer}/index-types.js +1 -0
- package/dist/developer/index-types.js.map +1 -0
- package/dist/developer/index.d.ts +1 -0
- package/dist/developer/index.js +18 -0
- package/dist/developer/index.js.map +1 -0
- package/dist/error/{common-error-impl.d.ts → common-error.d.ts} +5 -5
- package/dist/error/common-error.js +104 -0
- package/dist/error/common-error.js.map +1 -0
- package/dist/error/index-types.d.ts +21 -2
- package/dist/error/index-types.js +1 -0
- package/dist/error/index-types.js.map +1 -0
- package/dist/error/index.d.ts +0 -1
- package/dist/error/index.js +1 -1
- package/dist/error/index.js.map +1 -0
- package/dist/exception/assertion-exception.d.ts +2 -2
- package/dist/exception/assertion-exception.js +3 -2
- package/dist/exception/assertion-exception.js.map +1 -0
- package/dist/exception/caused-exception.d.ts +2 -2
- package/dist/exception/caused-exception.js +3 -2
- package/dist/exception/caused-exception.js.map +1 -0
- package/dist/exception/developer-exception.d.ts +2 -2
- package/dist/exception/developer-exception.js +3 -2
- package/dist/exception/developer-exception.js.map +1 -0
- package/dist/exception/exception.d.ts +7 -5
- package/dist/exception/exception.js +14 -4
- package/dist/exception/exception.js.map +1 -0
- package/dist/exception/index-types.d.ts +1 -1
- package/dist/exception/index-types.js +1 -0
- package/dist/exception/index-types.js.map +1 -0
- package/dist/exception/index.d.ts +1 -0
- package/dist/exception/index.js +2 -0
- package/dist/exception/index.js.map +1 -0
- package/dist/exception/invalid-value-exception.d.ts +5 -0
- package/dist/exception/invalid-value-exception.js +12 -0
- package/dist/exception/invalid-value-exception.js.map +1 -0
- package/dist/exception/multiple-exception.js +1 -0
- package/dist/exception/multiple-exception.js.map +1 -0
- package/dist/fqn/common-fqn.d.ts +20 -0
- package/dist/fqn/common-fqn.js +116 -0
- package/dist/fqn/common-fqn.js.map +1 -0
- package/dist/fqn/index-types.d.ts +14 -5
- package/dist/fqn/index-types.js +1 -0
- package/dist/fqn/index-types.js.map +1 -0
- package/dist/fqn/index.d.ts +0 -1
- package/dist/fqn/index.js +1 -1
- package/dist/fqn/index.js.map +1 -0
- package/dist/hook/{common-hook-impl.d.ts → common-hook.d.ts} +12 -10
- package/dist/hook/{common-hook-impl.js → common-hook.js} +27 -21
- package/dist/hook/common-hook.js.map +1 -0
- package/dist/hook/index-types.d.ts +29 -14
- package/dist/hook/index-types.js +1 -0
- package/dist/hook/index-types.js.map +1 -0
- package/dist/hook/index.d.ts +0 -1
- package/dist/hook/index.js +1 -1
- package/dist/hook/index.js.map +1 -0
- package/dist/index.d.ts +27 -11
- package/dist/index.js +30 -20
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +4 -1
- package/dist/internal.js.map +1 -0
- package/dist/is/{common-is-impl.d.ts → common-is.d.ts} +19 -5
- package/dist/is/common-is.js +136 -0
- package/dist/is/common-is.js.map +1 -0
- package/dist/is/index-types.d.ts +48 -3
- package/dist/is/index-types.js +1 -0
- package/dist/is/index-types.js.map +1 -0
- package/dist/is/index.d.ts +0 -1
- package/dist/is/index.js +1 -1
- package/dist/is/index.js.map +1 -0
- package/dist/leyyo/index-types.d.ts +30 -17
- package/dist/leyyo/index-types.js +1 -0
- package/dist/leyyo/index-types.js.map +1 -0
- package/dist/leyyo/index.d.ts +1 -1
- package/dist/leyyo/index.js +2 -1
- package/dist/leyyo/index.js.map +1 -0
- package/dist/leyyo/leyyo-common-hook.d.ts +10 -0
- package/dist/leyyo/leyyo-common-hook.js +18 -0
- package/dist/leyyo/leyyo-common-hook.js.map +1 -0
- package/dist/leyyo/leyyo.d.ts +35 -0
- package/dist/leyyo/leyyo.js +77 -0
- package/dist/leyyo/leyyo.js.map +1 -0
- package/dist/log/common-log.d.ts +14 -0
- package/dist/log/common-log.js +92 -0
- package/dist/log/common-log.js.map +1 -0
- package/dist/log/index-types.d.ts +57 -3
- package/dist/log/index-types.js +1 -0
- package/dist/log/index-types.js.map +1 -0
- package/dist/log/index.d.ts +2 -2
- package/dist/log/index.js +3 -2
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger-instance.d.ts +31 -0
- package/dist/log/logger-instance.js +114 -0
- package/dist/log/logger-instance.js.map +1 -0
- package/dist/{literal → log}/severity.js +1 -0
- package/dist/log/severity.js.map +1 -0
- package/dist/repo/common-repo.d.ts +44 -0
- package/dist/repo/common-repo.js +180 -0
- package/dist/repo/common-repo.js.map +1 -0
- package/dist/repo/index-types.d.ts +104 -0
- package/dist/{shared/index-aliases.js → repo/index-types.js} +1 -2
- package/dist/repo/index-types.js.map +1 -0
- package/dist/repo/index.d.ts +2 -0
- package/dist/repo/index.js +19 -0
- package/dist/repo/index.js.map +1 -0
- package/dist/repo/repo-type.d.ts +8 -0
- package/dist/repo/repo-type.js +8 -0
- package/dist/repo/repo-type.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +5 -0
- package/dist/server.js.map +1 -0
- package/dist/shared/index-types.d.ts +162 -132
- package/dist/shared/index-types.js +2 -1
- package/dist/shared/index-types.js.map +1 -0
- package/dist/shared/index.d.ts +0 -4
- package/dist/shared/index.js +1 -4
- package/dist/shared/index.js.map +1 -0
- package/dist/system/common-system.d.ts +10 -0
- package/dist/system/common-system.js +65 -0
- package/dist/system/common-system.js.map +1 -0
- package/dist/{literal → system}/country-code.js +1 -0
- package/dist/system/country-code.js.map +1 -0
- package/dist/{literal → system}/environment.js +1 -0
- package/dist/system/environment.js.map +1 -0
- package/dist/{literal → system}/http-method.js +1 -0
- package/dist/system/http-method.js.map +1 -0
- package/dist/{literal → system}/http-place.js +1 -0
- package/dist/system/http-place.js.map +1 -0
- package/dist/system/index-types.d.ts +6 -0
- package/dist/system/index-types.js +3 -0
- package/dist/system/index-types.js.map +1 -0
- package/dist/{literal → system}/index.d.ts +1 -8
- package/dist/{literal → system}/index.js +2 -8
- package/dist/system/index.js.map +1 -0
- package/dist/{literal → system}/language-code.js +1 -0
- package/dist/system/language-code.js.map +1 -0
- package/dist/{literal → system}/locale-code.js +1 -0
- package/dist/system/locale-code.js.map +1 -0
- package/dist/{literal → system}/sys-class.js +1 -0
- package/dist/system/sys-class.js.map +1 -0
- package/dist/{literal → system}/sys-function.js +1 -0
- package/dist/system/sys-function.js.map +1 -0
- package/dist/to/common-to.d.ts +45 -0
- package/dist/to/common-to.js +868 -0
- package/dist/to/common-to.js.map +1 -0
- package/dist/to/index-types.d.ts +38 -18
- package/dist/to/index-types.js +1 -0
- package/dist/to/index-types.js.map +1 -0
- package/dist/to/index.d.ts +6 -1
- package/dist/to/index.js +7 -1
- package/dist/to/index.js.map +1 -0
- package/dist/{literal → to}/key-value.js +1 -0
- package/dist/to/key-value.js.map +1 -0
- package/dist/{shared → to}/list.d.ts +1 -0
- package/dist/{shared → to}/list.js +4 -0
- package/dist/to/list.js.map +1 -0
- package/dist/{literal → to}/primitive.js +1 -0
- package/dist/to/primitive.js.map +1 -0
- package/dist/{literal → to}/real-value.js +1 -0
- package/dist/to/real-value.js.map +1 -0
- package/dist/{literal → to}/weak-false.js +1 -0
- package/dist/to/weak-false.js.map +1 -0
- package/dist/{literal → to}/weak-true.js +1 -0
- package/dist/to/weak-true.js.map +1 -0
- package/dist/wrapper/common-wrapper.d.ts +26 -0
- package/dist/wrapper/common-wrapper.js +81 -0
- package/dist/wrapper/common-wrapper.js.map +1 -0
- package/dist/wrapper/index-types.d.ts +29 -0
- package/dist/wrapper/index-types.js +3 -0
- package/dist/wrapper/index-types.js.map +1 -0
- package/dist/wrapper/index.d.ts +2 -0
- package/dist/wrapper/index.js +19 -0
- package/dist/wrapper/index.js.map +1 -0
- package/dist/wrapper/wrap.d.ts +7 -0
- package/dist/wrapper/wrap.js +11 -0
- package/dist/wrapper/wrap.js.map +1 -0
- package/package.json +13 -15
- package/dist/assertion/common-assertion-impl.d.ts +0 -65
- package/dist/assertion/common-assertion-impl.js +0 -248
- package/dist/error/common-error-impl.js +0 -92
- package/dist/fqn/common-fqn-impl.d.ts +0 -18
- package/dist/fqn/common-fqn-impl.js +0 -121
- package/dist/is/common-is-impl.js +0 -91
- package/dist/leyyo/leyyo-impl.d.ts +0 -26
- package/dist/leyyo/leyyo-impl.js +0 -94
- package/dist/literal/index-types.d.ts +0 -6
- package/dist/literal/storage-type.d.ts +0 -8
- package/dist/literal/storage-type.js +0 -7
- package/dist/log/common-log-impl.d.ts +0 -14
- package/dist/log/common-log-impl.js +0 -59
- package/dist/log/logger-impl.d.ts +0 -23
- package/dist/log/logger-impl.js +0 -77
- package/dist/shared/assert.d.ts +0 -6
- package/dist/shared/assert.js +0 -14
- package/dist/shared/index-aliases.d.ts +0 -167
- package/dist/shared/index-constants.d.ts +0 -8
- package/dist/shared/index-constants.js +0 -11
- package/dist/storage/common-storage-impl.d.ts +0 -47
- package/dist/storage/common-storage-impl.js +0 -150
- package/dist/storage/index-types.d.ts +0 -87
- package/dist/storage/index.d.ts +0 -2
- package/dist/to/common-to-impl.d.ts +0 -38
- package/dist/to/common-to-impl.js +0 -553
- /package/dist/{literal → log}/severity.d.ts +0 -0
- /package/dist/{literal → system}/country-code.d.ts +0 -0
- /package/dist/{literal → system}/environment.d.ts +0 -0
- /package/dist/{literal → system}/http-method.d.ts +0 -0
- /package/dist/{literal → system}/http-place.d.ts +0 -0
- /package/dist/{literal → system}/language-code.d.ts +0 -0
- /package/dist/{literal → system}/locale-code.d.ts +0 -0
- /package/dist/{literal → system}/sys-class.d.ts +0 -0
- /package/dist/{literal → system}/sys-function.d.ts +0 -0
- /package/dist/{literal → to}/key-value.d.ts +0 -0
- /package/dist/{literal → to}/primitive.d.ts +0 -0
- /package/dist/{literal → to}/real-value.d.ts +0 -0
- /package/dist/{literal → to}/weak-false.d.ts +0 -0
- /package/dist/{literal → to}/weak-true.d.ts +0 -0
package/dist/storage/index.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { CommonTo, CommonToSecure } from "./index-types";
|
|
2
|
-
import { Dict, KeyValue, OneOrMore, ToTypeArrayOpt, ToTypeEnumOpt, ToTypeObjectOpt, ToTypeOpt } from "../shared";
|
|
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 fqn;
|
|
15
|
-
private assertion;
|
|
16
|
-
private _enumInMap;
|
|
17
|
-
private _enumInArray;
|
|
18
|
-
private _enumInAlteration;
|
|
19
|
-
runFn<T = unknown>(fn: Function, value: Function, opt?: ToTypeOpt): T;
|
|
20
|
-
runSave<T = unknown>(fn: Function, value: unknown, opt?: ToTypeOpt): T;
|
|
21
|
-
raiseInvalidValue<T = unknown>(value: unknown, expected: OneOrMore<string>, opt?: ToTypeOpt, params?: Dict): T;
|
|
22
|
-
any(value: unknown, opt?: ToTypeOpt): unknown;
|
|
23
|
-
array<T = unknown>(value: unknown, opt?: ToTypeArrayOpt): Array<T>;
|
|
24
|
-
boolean(value: unknown, opt?: ToTypeOpt): boolean;
|
|
25
|
-
clazz(value: unknown, opt?: ToTypeOpt): string;
|
|
26
|
-
date(value: unknown, opt?: ToTypeOpt): Date;
|
|
27
|
-
enumeration<T extends KeyValue = KeyValue>(value: unknown, opt?: ToTypeEnumOpt<T>): T;
|
|
28
|
-
float(value: unknown, opt?: ToTypeOpt): number | null;
|
|
29
|
-
func<T = Function>(value: unknown, opt?: ToTypeOpt): T | null;
|
|
30
|
-
integer(value: unknown, opt?: ToTypeOpt): number | null;
|
|
31
|
-
object<T = unknown>(value: unknown, opt?: ToTypeObjectOpt): Dict<T>;
|
|
32
|
-
dict<T = unknown>(value: unknown, opt?: ToTypeObjectOpt): Dict<T>;
|
|
33
|
-
string(value: unknown, opt?: ToTypeOpt): string;
|
|
34
|
-
text(value: unknown, opt?: ToTypeOpt): string;
|
|
35
|
-
$init(leyyo: Leyyo): void;
|
|
36
|
-
get $back(): CommonTo;
|
|
37
|
-
get $secure(): CommonToSecure;
|
|
38
|
-
}
|
|
@@ -1,553 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommonToImpl = void 0;
|
|
4
|
-
const literal_1 = require("../literal");
|
|
5
|
-
const exception_1 = require("../exception");
|
|
6
|
-
// noinspection JSUnusedGlobalSymbols
|
|
7
|
-
class CommonToImpl {
|
|
8
|
-
constructor() {
|
|
9
|
-
// region properties
|
|
10
|
-
this._EXPECTED_ANY = ['string', 'boolean', 'bigint', 'object', 'number', 'array'];
|
|
11
|
-
this._EXPECTED_ARRAY = ['array'];
|
|
12
|
-
this._EXPECTED_BOOL = ['boolean', 'string', 'number'];
|
|
13
|
-
this._EXPECTED_CLASS = ['string', 'function', 'object'];
|
|
14
|
-
this._EXPECTED_DATE = ['string', 'number', 'date', 'moment'];
|
|
15
|
-
this._EXPECTED_ENUM = ['string', 'number'];
|
|
16
|
-
this._EXPECTED_NUMBER = ['string', 'number', 'bigint'];
|
|
17
|
-
this._EXPECTED_STRING = ['boolean', 'string', 'number'];
|
|
18
|
-
// endregion secure
|
|
19
|
-
}
|
|
20
|
-
// endregion properties
|
|
21
|
-
// region private
|
|
22
|
-
_enumInMap(value, map) {
|
|
23
|
-
// regular, in values
|
|
24
|
-
if (Object.values(map).includes(value)) {
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
// ir-regular, in keys
|
|
28
|
-
if (Object.keys(map).includes(value)) {
|
|
29
|
-
return map[value];
|
|
30
|
-
}
|
|
31
|
-
if (typeof value === 'string') {
|
|
32
|
-
// regular, in lower-case
|
|
33
|
-
let str = value.toLowerCase();
|
|
34
|
-
let v = this._enumInMap(str, map);
|
|
35
|
-
if (v !== null) {
|
|
36
|
-
return v;
|
|
37
|
-
}
|
|
38
|
-
// regular, in upper-case
|
|
39
|
-
str = str.toUpperCase();
|
|
40
|
-
v = this._enumInMap(str, map);
|
|
41
|
-
if (v !== null) {
|
|
42
|
-
return v;
|
|
43
|
-
}
|
|
44
|
-
if (/^[0-9]+$/.test(value)) {
|
|
45
|
-
try {
|
|
46
|
-
return this._enumInMap(parseInt(value, 10), map);
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
_enumInArray(value, arr) {
|
|
56
|
-
// regular, in values
|
|
57
|
-
if (arr.includes(value)) {
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
if (typeof value === 'string') {
|
|
61
|
-
// regular, in lower-case
|
|
62
|
-
let str = value.toLowerCase();
|
|
63
|
-
let v = this._enumInArray(str, arr);
|
|
64
|
-
if (v !== null) {
|
|
65
|
-
return v;
|
|
66
|
-
}
|
|
67
|
-
// regular, in upper-case
|
|
68
|
-
str = str.toUpperCase();
|
|
69
|
-
v = this._enumInArray(str, arr);
|
|
70
|
-
if (v !== null) {
|
|
71
|
-
return v;
|
|
72
|
-
}
|
|
73
|
-
if (/^[0-9]+$/.test(value)) {
|
|
74
|
-
try {
|
|
75
|
-
return this._enumInArray(parseInt(value, 10), arr);
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
// noinspection JSMethodCanBeStatic
|
|
85
|
-
_enumInAlteration(value, alt) {
|
|
86
|
-
// ir-regular, in keys
|
|
87
|
-
if (Object.keys(alt).includes(value)) {
|
|
88
|
-
return alt[value];
|
|
89
|
-
}
|
|
90
|
-
if (typeof value === 'string') {
|
|
91
|
-
// regular, in lower-case
|
|
92
|
-
let str = value.toLowerCase();
|
|
93
|
-
let v = this._enumInAlteration(str, alt);
|
|
94
|
-
if (v !== null) {
|
|
95
|
-
return v;
|
|
96
|
-
}
|
|
97
|
-
// regular, in upper-case
|
|
98
|
-
str = str.toUpperCase();
|
|
99
|
-
v = this._enumInAlteration(str, alt);
|
|
100
|
-
if (v !== null) {
|
|
101
|
-
return v;
|
|
102
|
-
}
|
|
103
|
-
if (/^[0-9]+$/.test(value)) {
|
|
104
|
-
try {
|
|
105
|
-
return this._enumInAlteration(parseInt(value, 10), alt);
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
// endregion private
|
|
115
|
-
// region utility
|
|
116
|
-
runFn(fn, value, opt) {
|
|
117
|
-
try {
|
|
118
|
-
return fn(value());
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
if (!opt.silent) {
|
|
122
|
-
delete opt.silent;
|
|
123
|
-
let indicator;
|
|
124
|
-
if (opt.indicator !== undefined) {
|
|
125
|
-
indicator = opt.indicator;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
indicator = 'assertion.error';
|
|
129
|
-
}
|
|
130
|
-
this.assertion.raise(opt, value.name, indicator);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
runSave(fn, value, opt) {
|
|
136
|
-
try {
|
|
137
|
-
return fn(value);
|
|
138
|
-
}
|
|
139
|
-
catch (e) {
|
|
140
|
-
exception_1.Exception.cast(e).raise(!(opt === null || opt === void 0 ? void 0 : opt.silent));
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
raiseInvalidValue(value, expected, opt, params) {
|
|
145
|
-
let indicator;
|
|
146
|
-
if (opt.indicator !== undefined) {
|
|
147
|
-
indicator = opt.indicator;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
indicator = 'type.invalid-value';
|
|
151
|
-
}
|
|
152
|
-
opt = Object.assign(Object.assign(Object.assign({}, opt), params), { expected, value });
|
|
153
|
-
new exception_1.DeveloperException(indicator, opt)
|
|
154
|
-
.with(this)
|
|
155
|
-
.raise(!(opt === null || opt === void 0 ? void 0 : opt.silent));
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
// endregion utility
|
|
159
|
-
// region types
|
|
160
|
-
any(value, opt) {
|
|
161
|
-
if (this.is.empty(value)) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
switch (typeof value) {
|
|
165
|
-
case 'string':
|
|
166
|
-
case 'boolean':
|
|
167
|
-
case 'bigint':
|
|
168
|
-
case 'object':
|
|
169
|
-
return value;
|
|
170
|
-
case 'number':
|
|
171
|
-
return this.assertion.realNumber(value, opt);
|
|
172
|
-
case 'function':
|
|
173
|
-
return this.runFn(v => this.any(v, opt), value, opt);
|
|
174
|
-
}
|
|
175
|
-
return this.raiseInvalidValue(value, this._EXPECTED_ANY, opt);
|
|
176
|
-
}
|
|
177
|
-
array(value, opt) {
|
|
178
|
-
var _a, _b;
|
|
179
|
-
if (this.is.empty(value)) {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
switch (typeof value) {
|
|
183
|
-
case "string":
|
|
184
|
-
case "boolean":
|
|
185
|
-
case "number":
|
|
186
|
-
case "bigint":
|
|
187
|
-
return this.array([value], opt);
|
|
188
|
-
case 'object':
|
|
189
|
-
if (Array.isArray(value)) {
|
|
190
|
-
opt = opt !== null && opt !== void 0 ? opt : {};
|
|
191
|
-
const result = [];
|
|
192
|
-
const valueFn = (_b = (_a = opt === null || opt === void 0 ? void 0 : opt.children) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.fn;
|
|
193
|
-
if (typeof valueFn !== "function") {
|
|
194
|
-
result.push(...value);
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
const clonedOpt = Object.assign({}, opt);
|
|
198
|
-
value.forEach((v, index) => {
|
|
199
|
-
clonedOpt.param = opt.param ? `${opt.param}#${index}` : `#${index}`;
|
|
200
|
-
try {
|
|
201
|
-
result.push(valueFn(v, clonedOpt));
|
|
202
|
-
}
|
|
203
|
-
catch (e) {
|
|
204
|
-
exception_1.Exception.cast(e).raise(!opt.silent);
|
|
205
|
-
result.push(null);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return result;
|
|
210
|
-
}
|
|
211
|
-
return this.array([value], opt);
|
|
212
|
-
case 'function':
|
|
213
|
-
return this.runFn(v => this.array(v, opt), value, opt);
|
|
214
|
-
}
|
|
215
|
-
return this.raiseInvalidValue(value, this._EXPECTED_ARRAY, opt);
|
|
216
|
-
}
|
|
217
|
-
boolean(value, opt) {
|
|
218
|
-
if (this.is.empty(value)) {
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
switch (typeof value) {
|
|
222
|
-
case 'boolean':
|
|
223
|
-
return value;
|
|
224
|
-
case 'string':
|
|
225
|
-
value = value.trim().toLowerCase();
|
|
226
|
-
if (value === '') {
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
if (literal_1.WeakTrueItems.includes(value)) {
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
if (literal_1.WeakFalseItems.includes(value)) {
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
return this.raiseInvalidValue(value, this._EXPECTED_BOOL, opt);
|
|
236
|
-
case 'number':
|
|
237
|
-
return value > 0;
|
|
238
|
-
case 'object':
|
|
239
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
240
|
-
return this.boolean(value[0], opt);
|
|
241
|
-
}
|
|
242
|
-
break;
|
|
243
|
-
case 'function':
|
|
244
|
-
return this.runFn(v => this.boolean(v, opt), value, opt);
|
|
245
|
-
}
|
|
246
|
-
return this.raiseInvalidValue(value, this._EXPECTED_BOOL, opt);
|
|
247
|
-
}
|
|
248
|
-
clazz(value, opt) {
|
|
249
|
-
if (this.is.empty(value)) {
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
switch (typeof value) {
|
|
253
|
-
case 'string':
|
|
254
|
-
value = value.trim();
|
|
255
|
-
if (value === '') {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
return value;
|
|
259
|
-
case 'object':
|
|
260
|
-
case 'function':
|
|
261
|
-
return this.fqn.name(value);
|
|
262
|
-
}
|
|
263
|
-
return this.raiseInvalidValue(value, this._EXPECTED_CLASS, opt);
|
|
264
|
-
}
|
|
265
|
-
date(value, opt) {
|
|
266
|
-
if (this.is.empty(value)) {
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
switch (typeof value) {
|
|
270
|
-
case 'object':
|
|
271
|
-
if (value instanceof Date) {
|
|
272
|
-
return value;
|
|
273
|
-
}
|
|
274
|
-
else if (typeof value['toDate'] === 'function') {
|
|
275
|
-
return this.date(this.runSave(v => v.toDate(), value, opt), opt);
|
|
276
|
-
}
|
|
277
|
-
if (Array.isArray(value)) {
|
|
278
|
-
const arr = value;
|
|
279
|
-
if (arr.length === 1) {
|
|
280
|
-
return this.date(arr[0], opt);
|
|
281
|
-
}
|
|
282
|
-
if (arr.length > 1 && arr.length < 8) {
|
|
283
|
-
return this.date(this.runSave(v => new Date(v[0], v[1], v[2], v[3], v[4], v[5], v[6]), value, opt), opt);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
else if (value.id !== undefined) {
|
|
287
|
-
return this.date(value.id, opt);
|
|
288
|
-
}
|
|
289
|
-
break;
|
|
290
|
-
case 'string':
|
|
291
|
-
if (value.trim() === '') {
|
|
292
|
-
return null;
|
|
293
|
-
}
|
|
294
|
-
return this.date(this.runSave(v => new Date(v), value.trim(), opt), opt);
|
|
295
|
-
case 'bigint':
|
|
296
|
-
return this.date(this.runSave(v => new Date(Number(v)), value, opt), opt);
|
|
297
|
-
case 'number':
|
|
298
|
-
return this.date(this.runSave(v => new Date(v), value, opt), opt);
|
|
299
|
-
case 'function':
|
|
300
|
-
return this.runFn(v => this.date(v, opt), value, opt);
|
|
301
|
-
}
|
|
302
|
-
return this.raiseInvalidValue(value, this._EXPECTED_DATE, opt);
|
|
303
|
-
}
|
|
304
|
-
enumeration(value, opt) {
|
|
305
|
-
if (this.is.empty(value)) {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
opt = opt !== null && opt !== void 0 ? opt : {};
|
|
309
|
-
let mapType = null;
|
|
310
|
-
if (this.is.object(opt.map)) {
|
|
311
|
-
mapType = 'object';
|
|
312
|
-
}
|
|
313
|
-
else if (this.is.array(opt.map)) {
|
|
314
|
-
mapType = 'array';
|
|
315
|
-
}
|
|
316
|
-
if (!mapType) {
|
|
317
|
-
throw new exception_1.DeveloperException('type.invalid-enum-items', { map: opt.map });
|
|
318
|
-
}
|
|
319
|
-
let v;
|
|
320
|
-
switch (typeof value) {
|
|
321
|
-
case 'string':
|
|
322
|
-
value = value.trim();
|
|
323
|
-
if (value === '') {
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
if (mapType === 'object') {
|
|
327
|
-
v = this._enumInMap(value, opt.map);
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
v = this._enumInArray(value, opt.map);
|
|
331
|
-
}
|
|
332
|
-
if (v !== null) {
|
|
333
|
-
return v;
|
|
334
|
-
}
|
|
335
|
-
if (this.is.object(opt.alt)) {
|
|
336
|
-
v = this._enumInAlteration(value, opt.alt);
|
|
337
|
-
if (v !== null) {
|
|
338
|
-
return v;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return this.raiseInvalidValue(value, this._EXPECTED_ENUM, opt);
|
|
342
|
-
case 'number':
|
|
343
|
-
const num = this.assertion.realNumber(value, opt);
|
|
344
|
-
if (num === null) {
|
|
345
|
-
return null;
|
|
346
|
-
}
|
|
347
|
-
if (mapType === 'object') {
|
|
348
|
-
v = this._enumInMap(value, opt.map);
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
v = this._enumInArray(value, opt.map);
|
|
352
|
-
}
|
|
353
|
-
if (v !== null) {
|
|
354
|
-
return v;
|
|
355
|
-
}
|
|
356
|
-
if (this.is.object(opt.alt)) {
|
|
357
|
-
v = this._enumInAlteration(value, opt.alt);
|
|
358
|
-
if (v !== null) {
|
|
359
|
-
return v;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return this.raiseInvalidValue(value, this._EXPECTED_ENUM, opt);
|
|
363
|
-
case 'object':
|
|
364
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
365
|
-
return this.enumeration(value[0], opt);
|
|
366
|
-
}
|
|
367
|
-
return this.enumeration(value.id, opt);
|
|
368
|
-
case 'function':
|
|
369
|
-
return this.runFn(v => this.enumeration(v, opt), value, opt);
|
|
370
|
-
}
|
|
371
|
-
return this.raiseInvalidValue(value, this._EXPECTED_ENUM, opt);
|
|
372
|
-
}
|
|
373
|
-
float(value, opt) {
|
|
374
|
-
if (this.is.empty(value)) {
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
switch (typeof value) {
|
|
378
|
-
case 'string':
|
|
379
|
-
return this.float(this.runSave(parseFloat, value.trim(), opt), opt);
|
|
380
|
-
case 'number':
|
|
381
|
-
return this.assertion.realNumber(value, opt);
|
|
382
|
-
case 'bigint':
|
|
383
|
-
return this.float(this.runSave(Number, value, opt), opt);
|
|
384
|
-
case 'boolean':
|
|
385
|
-
return value ? 1 : 0;
|
|
386
|
-
case 'object':
|
|
387
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
388
|
-
return this.float(value[0], opt);
|
|
389
|
-
}
|
|
390
|
-
return this.float(value.id, opt);
|
|
391
|
-
case 'function':
|
|
392
|
-
return this.runFn(v => this.float(v, opt), value, opt);
|
|
393
|
-
}
|
|
394
|
-
return this.raiseInvalidValue(value, this._EXPECTED_NUMBER, opt);
|
|
395
|
-
}
|
|
396
|
-
func(value, opt) {
|
|
397
|
-
if (this.is.empty(value)) {
|
|
398
|
-
return null;
|
|
399
|
-
}
|
|
400
|
-
switch (typeof value) {
|
|
401
|
-
case "function":
|
|
402
|
-
return value;
|
|
403
|
-
case 'object':
|
|
404
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
405
|
-
return this.func(value[0], opt);
|
|
406
|
-
}
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
return this.raiseInvalidValue(value, ['function'], opt);
|
|
410
|
-
}
|
|
411
|
-
integer(value, opt) {
|
|
412
|
-
if (this.is.empty(value)) {
|
|
413
|
-
return null;
|
|
414
|
-
}
|
|
415
|
-
switch (typeof value) {
|
|
416
|
-
case 'string':
|
|
417
|
-
return this.integer(this.runSave(parseFloat, value.trim(), opt), opt);
|
|
418
|
-
case 'number':
|
|
419
|
-
let num = this.assertion.realNumber(value, opt);
|
|
420
|
-
if (num !== null && !Number.isSafeInteger(num)) {
|
|
421
|
-
num = Math.floor(num);
|
|
422
|
-
}
|
|
423
|
-
return num;
|
|
424
|
-
case 'bigint':
|
|
425
|
-
return this.integer(this.runSave(Number, value, opt), opt);
|
|
426
|
-
case 'boolean':
|
|
427
|
-
return value ? 1 : 0;
|
|
428
|
-
case 'object':
|
|
429
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
430
|
-
return this.integer(value[0], opt);
|
|
431
|
-
}
|
|
432
|
-
return this.integer(value.id, opt);
|
|
433
|
-
case 'function':
|
|
434
|
-
return this.runFn(v => this.integer(v, opt), value, opt);
|
|
435
|
-
}
|
|
436
|
-
return this.raiseInvalidValue(value, this._EXPECTED_NUMBER, opt);
|
|
437
|
-
}
|
|
438
|
-
object(value, opt) {
|
|
439
|
-
return this.dict(value, opt);
|
|
440
|
-
}
|
|
441
|
-
dict(value, opt) {
|
|
442
|
-
var _a, _b, _c, _d;
|
|
443
|
-
if (this.is.empty(value)) {
|
|
444
|
-
return null;
|
|
445
|
-
}
|
|
446
|
-
switch (typeof value) {
|
|
447
|
-
case 'object':
|
|
448
|
-
if (Array.isArray(value)) {
|
|
449
|
-
if (value.length === 1) {
|
|
450
|
-
return this.object(value[0], opt);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
opt = opt !== null && opt !== void 0 ? opt : {};
|
|
455
|
-
const keyOpt = Object.assign(Object.assign({}, ((_b = (_a = opt === null || opt === void 0 ? void 0 : opt.children) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : {})), opt);
|
|
456
|
-
if (typeof keyOpt.fn !== 'function') {
|
|
457
|
-
keyOpt.fn = (k, o) => {
|
|
458
|
-
if (!this.is.key(k)) {
|
|
459
|
-
this.raiseInvalidValue(k, ['string', 'number'], o, { key: k });
|
|
460
|
-
}
|
|
461
|
-
return k;
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
const valueOpt = Object.assign(Object.assign({}, ((_d = (_c = opt === null || opt === void 0 ? void 0 : opt.children) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : {})), opt);
|
|
465
|
-
if (typeof valueOpt.fn !== 'function') {
|
|
466
|
-
valueOpt.fn = (v) => {
|
|
467
|
-
return v;
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
const result = {};
|
|
471
|
-
for (const [k, v] of Object.entries(value)) {
|
|
472
|
-
keyOpt.param = opt.param ? `${opt.param}.${k}` : `${k}`;
|
|
473
|
-
valueOpt.param = opt.param ? `${opt.param}.${k}` : `${k}`;
|
|
474
|
-
try {
|
|
475
|
-
result[keyOpt.fn(k, keyOpt)] = valueOpt.fn(v, valueOpt);
|
|
476
|
-
}
|
|
477
|
-
catch (e) {
|
|
478
|
-
exception_1.Exception.cast(e).raise(!opt.silent);
|
|
479
|
-
result[k] = null;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return result;
|
|
483
|
-
}
|
|
484
|
-
break;
|
|
485
|
-
case 'function':
|
|
486
|
-
return this.runFn(v => this.object(v, opt), value, opt);
|
|
487
|
-
}
|
|
488
|
-
return this.raiseInvalidValue(value, ['object'], opt);
|
|
489
|
-
}
|
|
490
|
-
string(value, opt) {
|
|
491
|
-
if (this.is.empty(value)) {
|
|
492
|
-
return null;
|
|
493
|
-
}
|
|
494
|
-
switch (typeof value) {
|
|
495
|
-
case 'string':
|
|
496
|
-
return value;
|
|
497
|
-
case 'number':
|
|
498
|
-
const num = this.assertion.realNumber(value, opt);
|
|
499
|
-
return num !== null ? num.toString(10) : null;
|
|
500
|
-
case 'bigint':
|
|
501
|
-
return value.toString();
|
|
502
|
-
case 'boolean':
|
|
503
|
-
return value ? 'true' : 'false';
|
|
504
|
-
case 'object':
|
|
505
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
506
|
-
return this.string(value[0], opt);
|
|
507
|
-
}
|
|
508
|
-
return this.string(value.id, opt);
|
|
509
|
-
case 'function':
|
|
510
|
-
return this.runFn(v => this.string(v, opt), value, opt);
|
|
511
|
-
}
|
|
512
|
-
return this.raiseInvalidValue(value, this._EXPECTED_STRING, opt);
|
|
513
|
-
}
|
|
514
|
-
text(value, opt) {
|
|
515
|
-
if (this.is.empty(value)) {
|
|
516
|
-
return null;
|
|
517
|
-
}
|
|
518
|
-
switch (typeof value) {
|
|
519
|
-
case 'string':
|
|
520
|
-
const str = value.trim();
|
|
521
|
-
return str ? str : null;
|
|
522
|
-
case 'number':
|
|
523
|
-
const num = this.assertion.realNumber(value, opt);
|
|
524
|
-
return num !== null ? num.toString(10) : null;
|
|
525
|
-
case 'bigint':
|
|
526
|
-
return value.toString();
|
|
527
|
-
case 'boolean':
|
|
528
|
-
return value ? 'true' : 'false';
|
|
529
|
-
case 'object':
|
|
530
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
531
|
-
return this.text(value[0], opt);
|
|
532
|
-
}
|
|
533
|
-
return this.text(value.id, opt);
|
|
534
|
-
case 'function':
|
|
535
|
-
return this.runFn(v => this.text(v, opt), value, opt);
|
|
536
|
-
}
|
|
537
|
-
return this.raiseInvalidValue(value, this._EXPECTED_STRING, opt);
|
|
538
|
-
}
|
|
539
|
-
// endregion types
|
|
540
|
-
// region secure
|
|
541
|
-
$init(leyyo) {
|
|
542
|
-
this.is = leyyo.is;
|
|
543
|
-
this.fqn = leyyo.fqn;
|
|
544
|
-
this.assertion = leyyo.assertion;
|
|
545
|
-
}
|
|
546
|
-
get $back() {
|
|
547
|
-
return this;
|
|
548
|
-
}
|
|
549
|
-
get $secure() {
|
|
550
|
-
return this;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
exports.CommonToImpl = CommonToImpl;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|