@vorplex/core 0.0.8 → 0.0.11
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/consts/mime-type.const.d.ts +456 -0
- package/dist/consts/mime-type.const.js +456 -0
- package/dist/consts/unit.const.d.ts +22 -0
- package/dist/consts/unit.const.js +22 -0
- package/dist/functions/debounce.function.d.ts +1 -0
- package/dist/functions/debounce.function.js +12 -0
- package/dist/functions/is-node-environment.function.d.ts +1 -0
- package/dist/functions/is-node-environment.function.js +3 -0
- package/dist/functions/parse-path-selector.function.d.ts +2 -0
- package/dist/functions/parse-path-selector.function.js +17 -0
- package/dist/functions/parse-url.function.d.ts +12 -0
- package/dist/functions/parse-url.function.js +25 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +93 -0
- package/dist/interfaces/group.interface.d.ts +4 -0
- package/dist/interfaces/group.interface.js +0 -0
- package/dist/interfaces/key-value.interface.d.ts +4 -0
- package/dist/interfaces/key-value.interface.js +0 -0
- package/dist/modules/api/socket.model.d.ts +26 -0
- package/dist/modules/api/socket.model.js +66 -0
- package/dist/modules/api/web-client.model.d.ts +16 -0
- package/dist/modules/api/web-client.model.js +34 -0
- package/dist/modules/array/array.util.d.ts +17 -0
- package/dist/modules/array/array.util.js +105 -0
- package/dist/modules/changes/changes.util.d.ts +45 -0
- package/dist/modules/changes/changes.util.js +330 -0
- package/dist/modules/color/color-data.interface.d.ts +10 -0
- package/dist/modules/color/color-data.interface.js +0 -0
- package/dist/modules/color/color-formats.const.d.ts +9 -0
- package/dist/modules/color/color-formats.const.js +8 -0
- package/dist/modules/color/color.type.d.ts +4 -0
- package/dist/modules/color/color.type.js +0 -0
- package/dist/modules/color/color.util.d.ts +41 -0
- package/dist/modules/color/color.util.js +327 -0
- package/dist/modules/color/colors.const.d.ts +151 -0
- package/dist/modules/color/colors.const.js +150 -0
- package/dist/modules/color/hsl.interface.d.ts +6 -0
- package/dist/modules/color/hsl.interface.js +0 -0
- package/dist/modules/color/hsv.interface.d.ts +6 -0
- package/dist/modules/color/hsv.interface.js +0 -0
- package/dist/modules/color/rgb.interface.d.ts +6 -0
- package/dist/modules/color/rgb.interface.js +0 -0
- package/dist/modules/compression/compression.util.d.ts +4 -0
- package/dist/modules/compression/compression.util.js +52 -0
- package/dist/modules/date/date.util.d.ts +37 -0
- package/dist/modules/date/date.util.js +84 -0
- package/dist/modules/enum/enum.util.d.ts +17 -0
- package/dist/modules/enum/enum.util.js +69 -0
- package/dist/modules/hash/hash.util.d.ts +3 -0
- package/dist/modules/hash/hash.util.js +9 -0
- package/dist/modules/id/id.util.d.ts +7 -0
- package/dist/modules/id/id.util.js +33 -0
- package/dist/modules/injector/decorators/inject-token.decorator.d.ts +14 -0
- package/dist/modules/injector/decorators/inject-token.decorator.js +12 -0
- package/dist/modules/injector/decorators/injectable.decorator.d.ts +9 -0
- package/dist/modules/injector/decorators/injectable.decorator.js +7 -0
- package/dist/modules/injector/injector.model.d.ts +25 -0
- package/dist/modules/injector/injector.model.js +152 -0
- package/dist/modules/injector/provider-scopes.enum.d.ts +5 -0
- package/dist/modules/injector/provider-scopes.enum.js +6 -0
- package/dist/modules/injector/provider.interface.d.ts +10 -0
- package/dist/modules/injector/provider.interface.js +0 -0
- package/dist/modules/json-filter/json-filter.function.d.ts +41 -0
- package/dist/modules/json-filter/json-filter.function.js +75 -0
- package/dist/modules/logging/console-logger.model.d.ts +36 -0
- package/dist/modules/logging/console-logger.model.js +44 -0
- package/dist/modules/logging/logger.model.d.ts +6 -0
- package/dist/modules/logging/logger.model.js +7 -0
- package/dist/modules/logging/task.d.ts +38 -0
- package/dist/modules/logging/task.js +133 -0
- package/dist/modules/math/line.d.ts +12 -0
- package/dist/modules/math/line.js +50 -0
- package/dist/modules/math/point.d.ts +34 -0
- package/dist/modules/math/point.js +71 -0
- package/dist/modules/math/polygon.d.ts +45 -0
- package/dist/modules/math/polygon.js +273 -0
- package/dist/modules/math/rect.d.ts +6 -0
- package/dist/modules/math/rect.js +0 -0
- package/dist/modules/math/size.d.ts +4 -0
- package/dist/modules/math/size.js +0 -0
- package/dist/modules/number/number.util.d.ts +9 -0
- package/dist/modules/number/number.util.js +27 -0
- package/dist/modules/object/object.util.d.ts +7 -0
- package/dist/modules/object/object.util.js +63 -0
- package/dist/modules/path/path.util.d.ts +11 -0
- package/dist/modules/path/path.util.js +59 -0
- package/dist/modules/random/random.util.d.ts +17 -0
- package/dist/modules/random/random.util.js +57 -0
- package/dist/modules/readable-stream/readable-stream.util.d.ts +3 -0
- package/dist/modules/readable-stream/readable-stream.util.js +26 -0
- package/dist/modules/reflection/interfaces/parameter.interface.d.ts +4 -0
- package/dist/modules/reflection/interfaces/parameter.interface.js +0 -0
- package/dist/modules/reflection/models/attribute.model.d.ts +12 -0
- package/dist/modules/reflection/models/attribute.model.js +17 -0
- package/dist/modules/reflection/models/class-attribute.model.d.ts +4 -0
- package/dist/modules/reflection/models/class-attribute.model.js +6 -0
- package/dist/modules/reflection/models/method-attribute.model.d.ts +5 -0
- package/dist/modules/reflection/models/method-attribute.model.js +8 -0
- package/dist/modules/reflection/models/parameter-attribute.model.d.ts +7 -0
- package/dist/modules/reflection/models/parameter-attribute.model.js +21 -0
- package/dist/modules/reflection/models/property-attribute.model.d.ts +5 -0
- package/dist/modules/reflection/models/property-attribute.model.js +8 -0
- package/dist/modules/reflection/models/property-proxy-attribute.model.d.ts +15 -0
- package/dist/modules/reflection/models/property-proxy-attribute.model.js +19 -0
- package/dist/modules/reflection/types/constructor.type.d.ts +2 -0
- package/dist/modules/reflection/types/constructor.type.js +0 -0
- package/dist/modules/reflection/types/instance.type.d.ts +7 -0
- package/dist/modules/reflection/types/instance.type.js +0 -0
- package/dist/modules/reflection/types/type.type.d.ts +2 -0
- package/dist/modules/reflection/types/type.type.js +0 -0
- package/dist/modules/reflection/utils/decorator.util.d.ts +70 -0
- package/dist/modules/reflection/utils/decorator.util.js +135 -0
- package/dist/modules/reflection/utils/reflection.util.d.ts +140 -0
- package/dist/modules/reflection/utils/reflection.util.js +311 -0
- package/dist/modules/router/router.util.d.ts +33 -0
- package/dist/modules/router/router.util.js +59 -0
- package/dist/modules/state/adaptors/array/array-adaptor.util.d.ts +25 -0
- package/dist/modules/state/adaptors/array/array-adaptor.util.js +97 -0
- package/dist/modules/state/adaptors/entity/entity-adaptor.util.d.ts +35 -0
- package/dist/modules/state/adaptors/entity/entity-adaptor.util.js +158 -0
- package/dist/modules/state/adaptors/entity/entity-map.type.d.ts +4 -0
- package/dist/modules/state/adaptors/entity/entity-map.type.js +0 -0
- package/dist/modules/state/adaptors/entity/entity.interface.d.ts +3 -0
- package/dist/modules/state/adaptors/entity/entity.interface.js +0 -0
- package/dist/modules/state/state.model.d.ts +46 -0
- package/dist/modules/state/state.model.js +129 -0
- package/dist/modules/state/update.type.d.ts +2 -0
- package/dist/modules/state/update.type.js +0 -0
- package/dist/modules/string/string.util.d.ts +11 -0
- package/dist/modules/string/string.util.js +42 -0
- package/dist/modules/subscribable/subscribable.model.d.ts +10 -0
- package/dist/modules/subscribable/subscribable.model.js +34 -0
- package/dist/modules/subscribable/subscription.interface.d.ts +3 -0
- package/dist/modules/subscribable/subscription.interface.js +0 -0
- package/dist/modules/tson/error.d.ts +8 -0
- package/dist/modules/tson/error.js +13 -0
- package/dist/modules/tson/schema.d.ts +10 -0
- package/dist/modules/tson/schema.js +0 -0
- package/dist/modules/tson/schemas/any.d.ts +14 -0
- package/dist/modules/tson/schemas/any.js +27 -0
- package/dist/modules/tson/schemas/array.d.ts +21 -0
- package/dist/modules/tson/schemas/array.js +80 -0
- package/dist/modules/tson/schemas/boolean.d.ts +14 -0
- package/dist/modules/tson/schemas/boolean.js +38 -0
- package/dist/modules/tson/schemas/enum.d.ts +15 -0
- package/dist/modules/tson/schemas/enum.js +43 -0
- package/dist/modules/tson/schemas/number.d.ts +20 -0
- package/dist/modules/tson/schemas/number.js +66 -0
- package/dist/modules/tson/schemas/object.d.ts +33 -0
- package/dist/modules/tson/schemas/object.js +88 -0
- package/dist/modules/tson/schemas/schema-base.d.ts +12 -0
- package/dist/modules/tson/schemas/schema-base.js +14 -0
- package/dist/modules/tson/schemas/string.d.ts +19 -0
- package/dist/modules/tson/schemas/string.js +60 -0
- package/dist/modules/tson/schemas/union.d.ts +16 -0
- package/dist/modules/tson/schemas/union.js +56 -0
- package/dist/modules/tson/tson.d.ts +41 -0
- package/dist/modules/tson/tson.js +138 -0
- package/dist/modules/tson/type.d.ts +53 -0
- package/dist/modules/tson/type.js +0 -0
- package/dist/modules/value/value.util.d.ts +18 -0
- package/dist/modules/value/value.util.js +180 -0
- package/dist/types/awaitable.type.d.ts +1 -0
- package/dist/types/awaitable.type.js +0 -0
- package/dist/types/camel-to-kebab.type.d.ts +1 -0
- package/dist/types/camel-to-kebab.type.js +0 -0
- package/dist/types/has-key.type.d.ts +3 -0
- package/dist/types/has-key.type.js +0 -0
- package/dist/types/is-union.type.d.ts +1 -0
- package/dist/types/is-union.type.js +0 -0
- package/dist/types/keys-of-type.type.d.ts +5 -0
- package/dist/types/keys-of-type.type.js +0 -0
- package/dist/types/keys-with-fix.type.d.ts +3 -0
- package/dist/types/keys-with-fix.type.js +0 -0
- package/dist/types/optional-keys.type.d.ts +6 -0
- package/dist/types/optional-keys.type.js +0 -0
- package/dist/types/partial.type.d.ts +6 -0
- package/dist/types/partial.type.js +0 -0
- package/dist/types/predicate.type.d.ts +1 -0
- package/dist/types/predicate.type.js +0 -0
- package/dist/types/recursive-readonly.type.d.ts +3 -0
- package/dist/types/recursive-readonly.type.js +0 -0
- package/dist/types/recursive-value.type.d.ts +3 -0
- package/dist/types/recursive-value.type.js +0 -0
- package/dist/types/selector.type.d.ts +1 -0
- package/dist/types/selector.type.js +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
export class $Reflection {
|
|
2
|
+
constructor() { }
|
|
3
|
+
/**
|
|
4
|
+
* Returns the names of the parameters of the given function
|
|
5
|
+
*
|
|
6
|
+
* @static
|
|
7
|
+
* @template T
|
|
8
|
+
* @param func The function definition
|
|
9
|
+
* @param [name=''] The name of the function
|
|
10
|
+
* @return {*} The names of the parameters
|
|
11
|
+
*/
|
|
12
|
+
static getParameterNames(func, name = '') {
|
|
13
|
+
const data = func.toString();
|
|
14
|
+
const paramRegex = new RegExp(`(?:${name}|${func.name})\\(([^)]*)\\)`);
|
|
15
|
+
const match = data.match(paramRegex);
|
|
16
|
+
if (!match)
|
|
17
|
+
return [];
|
|
18
|
+
const paramsString = match[1].replace(/\/\*.*?\*\//g, '');
|
|
19
|
+
const params = paramsString
|
|
20
|
+
.split(',')
|
|
21
|
+
.map((param) => param
|
|
22
|
+
.trim()
|
|
23
|
+
.replace(/^\.\.\./, '')
|
|
24
|
+
.split('=')[0]
|
|
25
|
+
.trim()
|
|
26
|
+
.split(':')[0]
|
|
27
|
+
.replace(/@.*\(/, '')
|
|
28
|
+
.trim())
|
|
29
|
+
.filter(Boolean);
|
|
30
|
+
return params;
|
|
31
|
+
}
|
|
32
|
+
static combineClasses(...classes) {
|
|
33
|
+
class DynamicClass {
|
|
34
|
+
}
|
|
35
|
+
for (const class$ of classes) {
|
|
36
|
+
const keys = Object.getOwnPropertyNames(class$.prototype);
|
|
37
|
+
for (const key of keys) {
|
|
38
|
+
if (key !== 'constructor') {
|
|
39
|
+
const descriptor = Object.getOwnPropertyDescriptor(class$.prototype, key);
|
|
40
|
+
Object.defineProperty(DynamicClass.prototype, key, descriptor);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return DynamicClass;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns true if the `target` contains a property called `name`.
|
|
48
|
+
* @param target The object containing the property.
|
|
49
|
+
* @param name The name of the property to check.
|
|
50
|
+
*/
|
|
51
|
+
static hasProperty(target, name) {
|
|
52
|
+
return target && $Reflection.isObject(target) && name in target;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the type associate with the `prototype`.
|
|
56
|
+
* @param prototype The prototype which type to return.
|
|
57
|
+
*/
|
|
58
|
+
static getProtoType(prototype) {
|
|
59
|
+
return $Reflection.getType(Object.setPrototypeOf({}, prototype));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Defines a property on `target` called `name` with the given `get` and `set`.
|
|
63
|
+
*
|
|
64
|
+
* @param target The object or type to define the property on.
|
|
65
|
+
* @param name The name of the property.
|
|
66
|
+
* @param get The getter of the property.
|
|
67
|
+
* @param set The setter of the property.
|
|
68
|
+
*/
|
|
69
|
+
static defineProperty(target, name, get, set) {
|
|
70
|
+
target = $Reflection.isType(target) ? target.prototype : target;
|
|
71
|
+
Object.defineProperty(target, name, {
|
|
72
|
+
configurable: true,
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: get,
|
|
75
|
+
set: set,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns the type of the `value`.
|
|
80
|
+
* @param value The value which type to return.
|
|
81
|
+
*/
|
|
82
|
+
static getType(value) {
|
|
83
|
+
return value?.__proto__?.constructor ?? value;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns true if `value` is of a primitive type.
|
|
87
|
+
* Primitive types are `undefined`, `null`, `String`, `Number`, `Boolean`.
|
|
88
|
+
* @param value The value to check for primitive type.
|
|
89
|
+
*/
|
|
90
|
+
static isPrimitive(value) {
|
|
91
|
+
return [undefined, null, String, Number, Boolean].includes($Reflection.getType(value));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns true if `value` is of type function, lambda or class.
|
|
95
|
+
* @param value The value to check.
|
|
96
|
+
*/
|
|
97
|
+
static isFunction(value) {
|
|
98
|
+
return $Reflection.getType(value) === Function && (!value.prototype || !`${$Reflection.getProtoType(value.prototype)}`.startsWith('class'));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns true if `value` is a type or function.
|
|
102
|
+
* @param value The value to check.
|
|
103
|
+
*/
|
|
104
|
+
static isType(value) {
|
|
105
|
+
return $Reflection.getType(value) === Function && !!value.prototype && $Reflection.getType(value.prototype) !== Function;
|
|
106
|
+
}
|
|
107
|
+
static isValidDate(value) {
|
|
108
|
+
return new Date(value).toString() !== 'Invalid Date';
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns true if `value` is of type `Object`.
|
|
112
|
+
* @param value The value to check.
|
|
113
|
+
*/
|
|
114
|
+
static isObject(value) {
|
|
115
|
+
return value != null && !$Reflection.isArray(value) && typeof value === 'object' && !(value instanceof Date);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Returns true if `value` is of type `Symbol`.
|
|
119
|
+
* @param value The value to check.
|
|
120
|
+
*/
|
|
121
|
+
static isSymbol(value) {
|
|
122
|
+
return typeof value === 'symbol';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns true if `value` is a reference type.
|
|
126
|
+
* Reference types are `Object`, `Function`, `Array`, `Symbol`, `Date`.
|
|
127
|
+
* @param value The value to check for reference type.
|
|
128
|
+
*/
|
|
129
|
+
static isReference(value) {
|
|
130
|
+
return value && ['object', 'function', 'symbol'].includes(typeof value);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns true if `type` is a value type.
|
|
134
|
+
* Value types are `undefined`, `null`, `String`, `Number`, `Boolean`.
|
|
135
|
+
* @param type The type to check for value type.
|
|
136
|
+
*/
|
|
137
|
+
static isValueType(type) {
|
|
138
|
+
return type == null || !![String, Boolean, Number].find((_type) => _type === type);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns true if `type` is a reference type.
|
|
142
|
+
* Reference types are `Object`, `Function`, `Array`, `Symbol`, `Date`.
|
|
143
|
+
* @param value The type to check for reference type.
|
|
144
|
+
*/
|
|
145
|
+
static isReferenceType(type) {
|
|
146
|
+
return !$Reflection.isValueType(type);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Returns all the properties of `object`.
|
|
150
|
+
* @param object The object which properties to return.
|
|
151
|
+
*/
|
|
152
|
+
static getProperties(object) {
|
|
153
|
+
return Object.keys(object).filter((key) => !$Reflection.isFunction(object[key]));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Returns the default value for `type`.
|
|
157
|
+
* @param type The type which default value to return.
|
|
158
|
+
* @example
|
|
159
|
+
* String: ''
|
|
160
|
+
* Number: 0
|
|
161
|
+
* Boolean: false
|
|
162
|
+
* Date: 0
|
|
163
|
+
* Array: []
|
|
164
|
+
* ...: null
|
|
165
|
+
*/
|
|
166
|
+
static getDefault(type) {
|
|
167
|
+
switch (type) {
|
|
168
|
+
case String:
|
|
169
|
+
return '';
|
|
170
|
+
case Number:
|
|
171
|
+
return 0;
|
|
172
|
+
case Boolean:
|
|
173
|
+
return false;
|
|
174
|
+
case Date:
|
|
175
|
+
return 0;
|
|
176
|
+
case Array:
|
|
177
|
+
return [];
|
|
178
|
+
default:
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Sets the type of `value` to `type`.
|
|
184
|
+
* @param value The value which type to set.
|
|
185
|
+
* @param type The type to apply to the value.
|
|
186
|
+
*/
|
|
187
|
+
static setType(value, type) {
|
|
188
|
+
if (value == null || type == null) {
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
else if (type === Number) {
|
|
192
|
+
return Number(value);
|
|
193
|
+
}
|
|
194
|
+
else if (type === Boolean) {
|
|
195
|
+
return Boolean(value);
|
|
196
|
+
}
|
|
197
|
+
else if (type === String) {
|
|
198
|
+
return String(value);
|
|
199
|
+
}
|
|
200
|
+
else if (type === Date) {
|
|
201
|
+
return new Date(value);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return Object.setPrototypeOf(value, type.prototype);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Returns true if `value` is of type `Array`.
|
|
209
|
+
* @param value The value to check.
|
|
210
|
+
* @param type The type of array to check for.
|
|
211
|
+
*/
|
|
212
|
+
static isArray(value, type) {
|
|
213
|
+
if (Array.isArray(value)) {
|
|
214
|
+
if (type) {
|
|
215
|
+
if ($Reflection.isValueType(type)) {
|
|
216
|
+
return value.every((item) => $Reflection.getType(item) === type);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return value.every((item) => item instanceof type);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Returns true if `type` extends `base`.
|
|
228
|
+
* @param type The type to check.
|
|
229
|
+
* @param base The base of `type` to check.
|
|
230
|
+
*/
|
|
231
|
+
static extends(type, base) {
|
|
232
|
+
return type === base || $Reflection.getTypeBases(type).includes(base);
|
|
233
|
+
}
|
|
234
|
+
static instanceOf(value, type) {
|
|
235
|
+
return value instanceof type || $Reflection.extends($Reflection.getType(value), type);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Returns all the base types of `type`.
|
|
239
|
+
* @param type The type which base types to return.
|
|
240
|
+
*/
|
|
241
|
+
static getTypeBases(type) {
|
|
242
|
+
const types = [];
|
|
243
|
+
let base = $Reflection.getTypeBase(type);
|
|
244
|
+
while (base) {
|
|
245
|
+
types.push(base);
|
|
246
|
+
base = $Reflection.getTypeBase(base);
|
|
247
|
+
}
|
|
248
|
+
if ($Reflection.isReferenceType(type)) {
|
|
249
|
+
types.push(Object);
|
|
250
|
+
}
|
|
251
|
+
return types;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns the base type of `value`.
|
|
255
|
+
* @param value The value which base type to return.
|
|
256
|
+
*/
|
|
257
|
+
static getBaseType(value) {
|
|
258
|
+
const type = $Reflection.getType(value);
|
|
259
|
+
if (type) {
|
|
260
|
+
return $Reflection.getTypeBase(type);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Returns the base type of `type`.
|
|
265
|
+
* @param type The type which base type to return.
|
|
266
|
+
*/
|
|
267
|
+
static getTypeBase(type) {
|
|
268
|
+
if (type != null) {
|
|
269
|
+
const base = Object.getPrototypeOf(type);
|
|
270
|
+
return base !== Object.getPrototypeOf(Function) ? base : null;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
static getTypeName(value) {
|
|
274
|
+
return $Reflection.isType(value) ? value.name : $Reflection.isSymbol(value) ? String(value) : String($Reflection.getType(value)?.name ?? value);
|
|
275
|
+
}
|
|
276
|
+
static getSimpleTypeName(value) {
|
|
277
|
+
if (value == null)
|
|
278
|
+
return 'null';
|
|
279
|
+
if (typeof value === 'string')
|
|
280
|
+
return 'string';
|
|
281
|
+
if (typeof value === 'number')
|
|
282
|
+
return 'number';
|
|
283
|
+
if (typeof value === 'boolean')
|
|
284
|
+
return 'boolean';
|
|
285
|
+
if (typeof value === 'symbol')
|
|
286
|
+
return 'symbol';
|
|
287
|
+
if (typeof value === 'bigint')
|
|
288
|
+
return 'bigint';
|
|
289
|
+
if (value instanceof Date)
|
|
290
|
+
return 'date';
|
|
291
|
+
if ($Reflection.isType(value))
|
|
292
|
+
return 'type';
|
|
293
|
+
if ($Reflection.isFunction(value))
|
|
294
|
+
return 'function';
|
|
295
|
+
if (Array.isArray(value))
|
|
296
|
+
return 'array';
|
|
297
|
+
if ($Reflection.isObject(value))
|
|
298
|
+
return 'object';
|
|
299
|
+
}
|
|
300
|
+
static parsePrimitiveValue(value) {
|
|
301
|
+
if (/^\d+$/.test(value))
|
|
302
|
+
return parseInt(value, 10);
|
|
303
|
+
if (/^\d+\.\d+$/.test(value))
|
|
304
|
+
return parseFloat(value);
|
|
305
|
+
if (value.toLowerCase() === 'true')
|
|
306
|
+
return true;
|
|
307
|
+
if (value.toLowerCase() === 'false')
|
|
308
|
+
return false;
|
|
309
|
+
return value;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
type RouteParamObject<P extends string> = P extends `...${infer Name}?` ? {
|
|
2
|
+
[K in Name]?: string;
|
|
3
|
+
} : P extends `...${infer Name}` ? {
|
|
4
|
+
[K in Name]: string;
|
|
5
|
+
} : P extends `${infer Name}?` ? {
|
|
6
|
+
[K in Name]?: string;
|
|
7
|
+
} : {
|
|
8
|
+
[K in P]: string;
|
|
9
|
+
};
|
|
10
|
+
export type ExtractRouteParams<T extends string> = T extends `${string}{${infer P}}${infer Rest}` ? RouteParamObject<P> & ExtractRouteParams<Rest> : {};
|
|
11
|
+
export interface RouteParameter {
|
|
12
|
+
name: string;
|
|
13
|
+
optional: boolean;
|
|
14
|
+
rest: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class $Router {
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param route
|
|
20
|
+
* `/api/users/get/{name}/{surname?}`
|
|
21
|
+
*
|
|
22
|
+
* `/api/users/?`
|
|
23
|
+
*
|
|
24
|
+
* `/api/users/get/{...rest}`
|
|
25
|
+
* @param url
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
static match(route: string, url: string): Record<string, string>;
|
|
29
|
+
static getParameters(route: string): RouteParameter[];
|
|
30
|
+
static getRouteRegex(route: string): RegExp;
|
|
31
|
+
static getQueryParameters(url: string): Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export class $Router {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param route
|
|
5
|
+
* `/api/users/get/{name}/{surname?}`
|
|
6
|
+
*
|
|
7
|
+
* `/api/users/?`
|
|
8
|
+
*
|
|
9
|
+
* `/api/users/get/{...rest}`
|
|
10
|
+
* @param url
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
static match(route, url) {
|
|
14
|
+
const regex = $Router.getRouteRegex(route);
|
|
15
|
+
const result = regex.exec(url.trim().split(/[?#]/, 1)[0]);
|
|
16
|
+
if (!result)
|
|
17
|
+
return null;
|
|
18
|
+
return result.groups ?? {};
|
|
19
|
+
}
|
|
20
|
+
static getParameters(route) {
|
|
21
|
+
const pattern = [
|
|
22
|
+
// check if the parameter starts with ...
|
|
23
|
+
'(?<rest>[.]{3})?',
|
|
24
|
+
// extract the name from the parameter
|
|
25
|
+
'(?<name>[^?}]*)',
|
|
26
|
+
// check if the parameter ends with a ?
|
|
27
|
+
'(?<optional>[?])?',
|
|
28
|
+
];
|
|
29
|
+
const regex = new RegExp(`({${pattern.join('')}})`, 'gmi');
|
|
30
|
+
let match;
|
|
31
|
+
const variables = [];
|
|
32
|
+
while ((match = regex.exec(route))) {
|
|
33
|
+
variables.push({
|
|
34
|
+
name: match.groups['name'],
|
|
35
|
+
rest: match.groups['rest'] === '...',
|
|
36
|
+
optional: match.groups['optional'] === '?',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return variables;
|
|
40
|
+
}
|
|
41
|
+
static getRouteRegex(route) {
|
|
42
|
+
const variables = $Router.getParameters(route);
|
|
43
|
+
for (const variable of variables) {
|
|
44
|
+
if (variable.rest) {
|
|
45
|
+
route = route.replace(`{...${variable.name}}`, `(?<${variable.name}>(?:.*))`);
|
|
46
|
+
}
|
|
47
|
+
else if (variable.optional) {
|
|
48
|
+
route = route.replace(`{${variable.name}?}`, `(?<${variable.name}>(?:[^/]+)?)`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
route = route.replace(`{${variable.name}}`, `(?<${variable.name}>(?:[^/]+))`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return new RegExp(`^${route}$`, 'gmi');
|
|
55
|
+
}
|
|
56
|
+
static getQueryParameters(url) {
|
|
57
|
+
return Object.fromEntries(new URL(url, 'http://domain').searchParams);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { KeysOfType } from '../../../../types/keys-of-type.type';
|
|
2
|
+
import type { Predicate } from '../../../../types/predicate.type';
|
|
3
|
+
import type { Selector } from '../../../../types/selector.type';
|
|
4
|
+
import type { Update, UpdateFunc } from '../../update.type';
|
|
5
|
+
export declare class ArrayAdaptor<TState, TItem, TString extends keyof KeysOfType<TState, TItem[]>> {
|
|
6
|
+
private key;
|
|
7
|
+
constructor(key: TString);
|
|
8
|
+
static updateWhere<T>(array: T[], query?: Predicate<T>, ...updates: Update<T>[]): T[];
|
|
9
|
+
static updateAtIndex<T>(array: T[], index: number, ...updates: Update<T>[]): T[];
|
|
10
|
+
static updateAll<T>(array: T[], ...updates: Update<T>[]): T[];
|
|
11
|
+
static upsert<T>(array: T[], ...items: T[]): T[];
|
|
12
|
+
static upsertBy<T>(array: T[], selector: Selector<T>, ...items: T[]): T[];
|
|
13
|
+
updateWhere(query?: Predicate<TItem>, ...updates: Update<TItem>[]): Update<TState>;
|
|
14
|
+
set(items: TItem[]): UpdateFunc<TState>;
|
|
15
|
+
updateAll(...updates: Update<TItem>[]): Update<TState>;
|
|
16
|
+
add(...items: TItem[]): Update<TState>;
|
|
17
|
+
insert(index: number, ...items: TItem[]): Update<TState>;
|
|
18
|
+
upsert(...items: TItem[]): Update<TState>;
|
|
19
|
+
toggle(item: TItem): Update<TState>;
|
|
20
|
+
remove(...items: TItem[]): Update<TState>;
|
|
21
|
+
removeWhere(query: Predicate<TItem>): Update<TState>;
|
|
22
|
+
removeAt(...indexes: number[]): Update<TState>;
|
|
23
|
+
move(item: TItem, index: number): Update<TState>;
|
|
24
|
+
moveAt(fromIndex: number, toIndex: number): Update<TState>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { $Array } from '../../../array/array.util';
|
|
2
|
+
import { State } from '../../state.model';
|
|
3
|
+
export class ArrayAdaptor {
|
|
4
|
+
key;
|
|
5
|
+
constructor(key) {
|
|
6
|
+
this.key = key;
|
|
7
|
+
}
|
|
8
|
+
static updateWhere(array, query, ...updates) {
|
|
9
|
+
array = [...array];
|
|
10
|
+
for (const [index, item] of array.entries()) {
|
|
11
|
+
if (!query || query(item)) {
|
|
12
|
+
array[index] = State.update(item, ...updates);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return array;
|
|
16
|
+
}
|
|
17
|
+
static updateAtIndex(array, index, ...updates) {
|
|
18
|
+
array = [...array];
|
|
19
|
+
array[index] = State.update(array[index], ...updates);
|
|
20
|
+
return array;
|
|
21
|
+
}
|
|
22
|
+
static updateAll(array, ...updates) {
|
|
23
|
+
return ArrayAdaptor.updateWhere(array, null, ...updates);
|
|
24
|
+
}
|
|
25
|
+
static upsert(array, ...items) {
|
|
26
|
+
return ArrayAdaptor.upsertBy(array, (item) => item, ...items);
|
|
27
|
+
}
|
|
28
|
+
static upsertBy(array, selector, ...items) {
|
|
29
|
+
array = [...array];
|
|
30
|
+
for (const item of items) {
|
|
31
|
+
const index = array.findIndex((existing) => selector(existing) === selector(item));
|
|
32
|
+
if (index > -1)
|
|
33
|
+
array[index] = item;
|
|
34
|
+
else
|
|
35
|
+
array.push(item);
|
|
36
|
+
}
|
|
37
|
+
return array;
|
|
38
|
+
}
|
|
39
|
+
updateWhere(query, ...updates) {
|
|
40
|
+
return (state) => ({
|
|
41
|
+
[this.key]: ArrayAdaptor.updateWhere(state[this.key], query, ...updates),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
set(items) {
|
|
45
|
+
return (state) => ({
|
|
46
|
+
[this.key]: items,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
updateAll(...updates) {
|
|
50
|
+
return this.updateWhere(null, ...updates);
|
|
51
|
+
}
|
|
52
|
+
add(...items) {
|
|
53
|
+
return (state) => ({
|
|
54
|
+
[this.key]: state[this.key].concat(...items),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
insert(index, ...items) {
|
|
58
|
+
return (state) => ({
|
|
59
|
+
[this.key]: $Array.insert(state[this.key], index, ...items),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
upsert(...items) {
|
|
63
|
+
return (state) => ({
|
|
64
|
+
[this.key]: $Array.upsert(state[this.key], ...items),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
toggle(item) {
|
|
68
|
+
return (state) => ({
|
|
69
|
+
[this.key]: $Array.toggle(state[this.key], item),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
remove(...items) {
|
|
73
|
+
return (state) => ({
|
|
74
|
+
[this.key]: $Array.remove(state[this.key], ...items),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
removeWhere(query) {
|
|
78
|
+
return (state) => ({
|
|
79
|
+
[this.key]: $Array.removeWhere(state[this.key], query),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
removeAt(...indexes) {
|
|
83
|
+
return (state) => ({
|
|
84
|
+
[this.key]: $Array.removeAt(state[this.key], ...indexes),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
move(item, index) {
|
|
88
|
+
return (state) => ({
|
|
89
|
+
[this.key]: $Array.move(state[this.key], item, index),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
moveAt(fromIndex, toIndex) {
|
|
93
|
+
return (state) => ({
|
|
94
|
+
[this.key]: $Array.moveAt(state[this.key], fromIndex, toIndex),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { KeysOfType } from '../../../../types/keys-of-type.type';
|
|
2
|
+
import type { Predicate } from '../../../../types/predicate.type';
|
|
3
|
+
import type { Update } from '../../update.type';
|
|
4
|
+
import type { EntityMap } from './entity-map.type';
|
|
5
|
+
import type { IEntity } from './entity.interface';
|
|
6
|
+
export declare class MapAdaptor {
|
|
7
|
+
private constructor();
|
|
8
|
+
static delete<T extends Record<string, any>>(records: T, ...keys: (keyof T)[]): T;
|
|
9
|
+
static set<T extends Record<string, any>>(records: T, items: Partial<T>): T;
|
|
10
|
+
static map<T extends Record<string, any>, TT>(records: T, map: (record: T[keyof T]) => [string, TT]): Record<string, TT>;
|
|
11
|
+
static fromArray<T, TT>(records: T[], map: (record: T) => [string, TT]): Record<string, TT>;
|
|
12
|
+
}
|
|
13
|
+
export declare class EntityAdaptor<TState, TEntity extends IEntity, TKey extends keyof KeysOfType<TState, EntityMap<TEntity>>> {
|
|
14
|
+
private key;
|
|
15
|
+
constructor(key: TKey);
|
|
16
|
+
static create<T extends IEntity>(items: EntityMap<T>, ...entities: T[]): EntityMap<T>;
|
|
17
|
+
create(...entities: TEntity[]): Update<TState>;
|
|
18
|
+
static updateAll<T extends IEntity>(items: EntityMap<T>, ...updates: Update<T>[]): EntityMap<T>;
|
|
19
|
+
updateAll(...updates: Update<TEntity>[]): Update<TState>;
|
|
20
|
+
static updateById<T extends IEntity>(items: EntityMap<T>, id: string, ...updates: Update<T>[]): EntityMap<T>;
|
|
21
|
+
updateById(id: string, ...updates: Update<TEntity>[]): Update<TState>;
|
|
22
|
+
static updateByIds<T extends IEntity>(items: EntityMap<T>, ids: string[], ...updates: Update<T>[]): EntityMap<T>;
|
|
23
|
+
updateByIds(ids: string[], ...updates: Update<TEntity>[]): Update<TState>;
|
|
24
|
+
static updateWhere<T extends IEntity>(items: EntityMap<T>, predicate: Predicate<T>, ...updates: Update<T>[]): EntityMap<T>;
|
|
25
|
+
updateWhere(predicate: Predicate<TEntity>, ...updates: Update<TEntity>[]): Update<TState>;
|
|
26
|
+
static upsert<T extends IEntity>(items: EntityMap<T>, ...entities: T[]): EntityMap<T>;
|
|
27
|
+
static upsertBy<T extends IEntity>(items: EntityMap<T>, predicate: (existing: T, entity: T) => boolean, ...entities: T[]): EntityMap<T>;
|
|
28
|
+
upsertBy(predicate: (existing: TEntity, entity: TEntity) => boolean, ...entities: TEntity[]): Update<TState>;
|
|
29
|
+
upsert(...entities: TEntity[]): Update<TState>;
|
|
30
|
+
static delete<T extends IEntity>(items: EntityMap<T>, ...ids: string[]): EntityMap<T>;
|
|
31
|
+
delete(...ids: string[]): Update<TState>;
|
|
32
|
+
static deleteWhere<T extends IEntity>(items: EntityMap<T>, predicate: Predicate<T>): EntityMap<T>;
|
|
33
|
+
deleteWhere(predicate: Predicate<TEntity>): Update<TState>;
|
|
34
|
+
static fromArray<T extends IEntity>(entities: T[]): EntityMap<T>;
|
|
35
|
+
}
|