@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.
Files changed (187) hide show
  1. package/dist/consts/mime-type.const.d.ts +456 -0
  2. package/dist/consts/mime-type.const.js +456 -0
  3. package/dist/consts/unit.const.d.ts +22 -0
  4. package/dist/consts/unit.const.js +22 -0
  5. package/dist/functions/debounce.function.d.ts +1 -0
  6. package/dist/functions/debounce.function.js +12 -0
  7. package/dist/functions/is-node-environment.function.d.ts +1 -0
  8. package/dist/functions/is-node-environment.function.js +3 -0
  9. package/dist/functions/parse-path-selector.function.d.ts +2 -0
  10. package/dist/functions/parse-path-selector.function.js +17 -0
  11. package/dist/functions/parse-url.function.d.ts +12 -0
  12. package/dist/functions/parse-url.function.js +25 -0
  13. package/dist/index.d.ts +92 -0
  14. package/dist/index.js +93 -0
  15. package/dist/interfaces/group.interface.d.ts +4 -0
  16. package/dist/interfaces/group.interface.js +0 -0
  17. package/dist/interfaces/key-value.interface.d.ts +4 -0
  18. package/dist/interfaces/key-value.interface.js +0 -0
  19. package/dist/modules/api/socket.model.d.ts +26 -0
  20. package/dist/modules/api/socket.model.js +66 -0
  21. package/dist/modules/api/web-client.model.d.ts +16 -0
  22. package/dist/modules/api/web-client.model.js +34 -0
  23. package/dist/modules/array/array.util.d.ts +17 -0
  24. package/dist/modules/array/array.util.js +105 -0
  25. package/dist/modules/changes/changes.util.d.ts +45 -0
  26. package/dist/modules/changes/changes.util.js +330 -0
  27. package/dist/modules/color/color-data.interface.d.ts +10 -0
  28. package/dist/modules/color/color-data.interface.js +0 -0
  29. package/dist/modules/color/color-formats.const.d.ts +9 -0
  30. package/dist/modules/color/color-formats.const.js +8 -0
  31. package/dist/modules/color/color.type.d.ts +4 -0
  32. package/dist/modules/color/color.type.js +0 -0
  33. package/dist/modules/color/color.util.d.ts +41 -0
  34. package/dist/modules/color/color.util.js +327 -0
  35. package/dist/modules/color/colors.const.d.ts +151 -0
  36. package/dist/modules/color/colors.const.js +150 -0
  37. package/dist/modules/color/hsl.interface.d.ts +6 -0
  38. package/dist/modules/color/hsl.interface.js +0 -0
  39. package/dist/modules/color/hsv.interface.d.ts +6 -0
  40. package/dist/modules/color/hsv.interface.js +0 -0
  41. package/dist/modules/color/rgb.interface.d.ts +6 -0
  42. package/dist/modules/color/rgb.interface.js +0 -0
  43. package/dist/modules/compression/compression.util.d.ts +4 -0
  44. package/dist/modules/compression/compression.util.js +52 -0
  45. package/dist/modules/date/date.util.d.ts +37 -0
  46. package/dist/modules/date/date.util.js +84 -0
  47. package/dist/modules/enum/enum.util.d.ts +17 -0
  48. package/dist/modules/enum/enum.util.js +69 -0
  49. package/dist/modules/hash/hash.util.d.ts +3 -0
  50. package/dist/modules/hash/hash.util.js +9 -0
  51. package/dist/modules/id/id.util.d.ts +7 -0
  52. package/dist/modules/id/id.util.js +33 -0
  53. package/dist/modules/injector/decorators/inject-token.decorator.d.ts +14 -0
  54. package/dist/modules/injector/decorators/inject-token.decorator.js +12 -0
  55. package/dist/modules/injector/decorators/injectable.decorator.d.ts +9 -0
  56. package/dist/modules/injector/decorators/injectable.decorator.js +7 -0
  57. package/dist/modules/injector/injector.model.d.ts +25 -0
  58. package/dist/modules/injector/injector.model.js +152 -0
  59. package/dist/modules/injector/provider-scopes.enum.d.ts +5 -0
  60. package/dist/modules/injector/provider-scopes.enum.js +6 -0
  61. package/dist/modules/injector/provider.interface.d.ts +10 -0
  62. package/dist/modules/injector/provider.interface.js +0 -0
  63. package/dist/modules/json-filter/json-filter.function.d.ts +41 -0
  64. package/dist/modules/json-filter/json-filter.function.js +75 -0
  65. package/dist/modules/logging/console-logger.model.d.ts +36 -0
  66. package/dist/modules/logging/console-logger.model.js +44 -0
  67. package/dist/modules/logging/logger.model.d.ts +6 -0
  68. package/dist/modules/logging/logger.model.js +7 -0
  69. package/dist/modules/logging/task.d.ts +38 -0
  70. package/dist/modules/logging/task.js +133 -0
  71. package/dist/modules/math/line.d.ts +12 -0
  72. package/dist/modules/math/line.js +50 -0
  73. package/dist/modules/math/point.d.ts +34 -0
  74. package/dist/modules/math/point.js +71 -0
  75. package/dist/modules/math/polygon.d.ts +45 -0
  76. package/dist/modules/math/polygon.js +273 -0
  77. package/dist/modules/math/rect.d.ts +6 -0
  78. package/dist/modules/math/rect.js +0 -0
  79. package/dist/modules/math/size.d.ts +4 -0
  80. package/dist/modules/math/size.js +0 -0
  81. package/dist/modules/number/number.util.d.ts +9 -0
  82. package/dist/modules/number/number.util.js +27 -0
  83. package/dist/modules/object/object.util.d.ts +7 -0
  84. package/dist/modules/object/object.util.js +63 -0
  85. package/dist/modules/path/path.util.d.ts +11 -0
  86. package/dist/modules/path/path.util.js +59 -0
  87. package/dist/modules/random/random.util.d.ts +17 -0
  88. package/dist/modules/random/random.util.js +57 -0
  89. package/dist/modules/readable-stream/readable-stream.util.d.ts +3 -0
  90. package/dist/modules/readable-stream/readable-stream.util.js +26 -0
  91. package/dist/modules/reflection/interfaces/parameter.interface.d.ts +4 -0
  92. package/dist/modules/reflection/interfaces/parameter.interface.js +0 -0
  93. package/dist/modules/reflection/models/attribute.model.d.ts +12 -0
  94. package/dist/modules/reflection/models/attribute.model.js +17 -0
  95. package/dist/modules/reflection/models/class-attribute.model.d.ts +4 -0
  96. package/dist/modules/reflection/models/class-attribute.model.js +6 -0
  97. package/dist/modules/reflection/models/method-attribute.model.d.ts +5 -0
  98. package/dist/modules/reflection/models/method-attribute.model.js +8 -0
  99. package/dist/modules/reflection/models/parameter-attribute.model.d.ts +7 -0
  100. package/dist/modules/reflection/models/parameter-attribute.model.js +21 -0
  101. package/dist/modules/reflection/models/property-attribute.model.d.ts +5 -0
  102. package/dist/modules/reflection/models/property-attribute.model.js +8 -0
  103. package/dist/modules/reflection/models/property-proxy-attribute.model.d.ts +15 -0
  104. package/dist/modules/reflection/models/property-proxy-attribute.model.js +19 -0
  105. package/dist/modules/reflection/types/constructor.type.d.ts +2 -0
  106. package/dist/modules/reflection/types/constructor.type.js +0 -0
  107. package/dist/modules/reflection/types/instance.type.d.ts +7 -0
  108. package/dist/modules/reflection/types/instance.type.js +0 -0
  109. package/dist/modules/reflection/types/type.type.d.ts +2 -0
  110. package/dist/modules/reflection/types/type.type.js +0 -0
  111. package/dist/modules/reflection/utils/decorator.util.d.ts +70 -0
  112. package/dist/modules/reflection/utils/decorator.util.js +135 -0
  113. package/dist/modules/reflection/utils/reflection.util.d.ts +140 -0
  114. package/dist/modules/reflection/utils/reflection.util.js +311 -0
  115. package/dist/modules/router/router.util.d.ts +33 -0
  116. package/dist/modules/router/router.util.js +59 -0
  117. package/dist/modules/state/adaptors/array/array-adaptor.util.d.ts +25 -0
  118. package/dist/modules/state/adaptors/array/array-adaptor.util.js +97 -0
  119. package/dist/modules/state/adaptors/entity/entity-adaptor.util.d.ts +35 -0
  120. package/dist/modules/state/adaptors/entity/entity-adaptor.util.js +158 -0
  121. package/dist/modules/state/adaptors/entity/entity-map.type.d.ts +4 -0
  122. package/dist/modules/state/adaptors/entity/entity-map.type.js +0 -0
  123. package/dist/modules/state/adaptors/entity/entity.interface.d.ts +3 -0
  124. package/dist/modules/state/adaptors/entity/entity.interface.js +0 -0
  125. package/dist/modules/state/state.model.d.ts +46 -0
  126. package/dist/modules/state/state.model.js +129 -0
  127. package/dist/modules/state/update.type.d.ts +2 -0
  128. package/dist/modules/state/update.type.js +0 -0
  129. package/dist/modules/string/string.util.d.ts +11 -0
  130. package/dist/modules/string/string.util.js +42 -0
  131. package/dist/modules/subscribable/subscribable.model.d.ts +10 -0
  132. package/dist/modules/subscribable/subscribable.model.js +34 -0
  133. package/dist/modules/subscribable/subscription.interface.d.ts +3 -0
  134. package/dist/modules/subscribable/subscription.interface.js +0 -0
  135. package/dist/modules/tson/error.d.ts +8 -0
  136. package/dist/modules/tson/error.js +13 -0
  137. package/dist/modules/tson/schema.d.ts +10 -0
  138. package/dist/modules/tson/schema.js +0 -0
  139. package/dist/modules/tson/schemas/any.d.ts +14 -0
  140. package/dist/modules/tson/schemas/any.js +27 -0
  141. package/dist/modules/tson/schemas/array.d.ts +21 -0
  142. package/dist/modules/tson/schemas/array.js +80 -0
  143. package/dist/modules/tson/schemas/boolean.d.ts +14 -0
  144. package/dist/modules/tson/schemas/boolean.js +38 -0
  145. package/dist/modules/tson/schemas/enum.d.ts +15 -0
  146. package/dist/modules/tson/schemas/enum.js +43 -0
  147. package/dist/modules/tson/schemas/number.d.ts +20 -0
  148. package/dist/modules/tson/schemas/number.js +66 -0
  149. package/dist/modules/tson/schemas/object.d.ts +33 -0
  150. package/dist/modules/tson/schemas/object.js +88 -0
  151. package/dist/modules/tson/schemas/schema-base.d.ts +12 -0
  152. package/dist/modules/tson/schemas/schema-base.js +14 -0
  153. package/dist/modules/tson/schemas/string.d.ts +19 -0
  154. package/dist/modules/tson/schemas/string.js +60 -0
  155. package/dist/modules/tson/schemas/union.d.ts +16 -0
  156. package/dist/modules/tson/schemas/union.js +56 -0
  157. package/dist/modules/tson/tson.d.ts +41 -0
  158. package/dist/modules/tson/tson.js +138 -0
  159. package/dist/modules/tson/type.d.ts +53 -0
  160. package/dist/modules/tson/type.js +0 -0
  161. package/dist/modules/value/value.util.d.ts +18 -0
  162. package/dist/modules/value/value.util.js +180 -0
  163. package/dist/types/awaitable.type.d.ts +1 -0
  164. package/dist/types/awaitable.type.js +0 -0
  165. package/dist/types/camel-to-kebab.type.d.ts +1 -0
  166. package/dist/types/camel-to-kebab.type.js +0 -0
  167. package/dist/types/has-key.type.d.ts +3 -0
  168. package/dist/types/has-key.type.js +0 -0
  169. package/dist/types/is-union.type.d.ts +1 -0
  170. package/dist/types/is-union.type.js +0 -0
  171. package/dist/types/keys-of-type.type.d.ts +5 -0
  172. package/dist/types/keys-of-type.type.js +0 -0
  173. package/dist/types/keys-with-fix.type.d.ts +3 -0
  174. package/dist/types/keys-with-fix.type.js +0 -0
  175. package/dist/types/optional-keys.type.d.ts +6 -0
  176. package/dist/types/optional-keys.type.js +0 -0
  177. package/dist/types/partial.type.d.ts +6 -0
  178. package/dist/types/partial.type.js +0 -0
  179. package/dist/types/predicate.type.d.ts +1 -0
  180. package/dist/types/predicate.type.js +0 -0
  181. package/dist/types/recursive-readonly.type.d.ts +3 -0
  182. package/dist/types/recursive-readonly.type.js +0 -0
  183. package/dist/types/recursive-value.type.d.ts +3 -0
  184. package/dist/types/recursive-value.type.js +0 -0
  185. package/dist/types/selector.type.d.ts +1 -0
  186. package/dist/types/selector.type.js +0 -0
  187. package/package.json +1 -1
@@ -0,0 +1,52 @@
1
+ export class Compression {
2
+ static compressString(string) {
3
+ if (string.length === 0)
4
+ return '';
5
+ const dict = new Map();
6
+ let dictSize = 256;
7
+ let w = string[0];
8
+ const codes = [];
9
+ for (let i = 1; i < string.length; i++) {
10
+ const c = string[i];
11
+ const wc = w + c;
12
+ if (dict.has(wc)) {
13
+ w = wc;
14
+ }
15
+ else {
16
+ codes.push(w.length > 1 ? dict.get(w) : w.charCodeAt(0));
17
+ dict.set(wc, dictSize++);
18
+ w = c;
19
+ }
20
+ }
21
+ codes.push(w.length > 1 ? dict.get(w) : w.charCodeAt(0));
22
+ return codes.map((code) => String.fromCharCode(code)).join('');
23
+ }
24
+ static decompressString(string) {
25
+ if (string.length === 0)
26
+ return '';
27
+ const dict = new Map();
28
+ let dictSize = 256;
29
+ const symbols = [...string];
30
+ let w = symbols[0];
31
+ let result = w;
32
+ for (let i = 1; i < symbols.length; i++) {
33
+ const k = symbols[i].charCodeAt(0);
34
+ let entry;
35
+ if (k < 256) {
36
+ entry = symbols[i];
37
+ }
38
+ else if (dict.has(k)) {
39
+ entry = dict.get(k);
40
+ }
41
+ else if (k === dictSize) {
42
+ entry = w + w[0];
43
+ }
44
+ else {
45
+ throw new Error('Corrupt LZW stream: unknown code encountered.');
46
+ }
47
+ result += entry;
48
+ dict.set(dictSize++, w + entry[0]);
49
+ w = entry;
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,37 @@
1
+ export declare class $Date {
2
+ static addMilliseconds(date: Date, ms: number): Date;
3
+ static addSeconds(date: Date, seconds: number): Date;
4
+ static addMinutes(date: Date, minutes: number): Date;
5
+ static addHours(date: Date, hours: number): Date;
6
+ static addDays(date: Date, days: number): Date;
7
+ static addWeeks(date: Date, weeks: number): Date;
8
+ static addMonths(date: Date, months: number): Date;
9
+ static addYears(date: Date, years: number): Date;
10
+ /**
11
+ *
12
+ * @param date
13
+ * @param format
14
+ * @returns
15
+ * @example
16
+ * // 12 Jan 2025 11:50:15
17
+ * `YYYY` = 2025
18
+ * `YY` = 25
19
+ * `MM` = 01
20
+ * `DD` = 12
21
+ * `hh` = 11
22
+ * `mm` = 50
23
+ * `ss` = 15
24
+ */
25
+ static format(date: Date, format: string): string;
26
+ /**
27
+ *
28
+ * @param target
29
+ * @param compareTo
30
+ * @returns
31
+ * @example
32
+ * // 5 days ago
33
+ * // 1 minute from now
34
+ */
35
+ static toAgoString(target: Date, compareTo?: Date): string;
36
+ static isValid(date: unknown): date is Date;
37
+ }
@@ -0,0 +1,84 @@
1
+ export class $Date {
2
+ static addMilliseconds(date, ms) {
3
+ return new Date(date.getTime() + ms);
4
+ }
5
+ static addSeconds(date, seconds) {
6
+ return $Date.addMilliseconds(date, seconds * 1_000);
7
+ }
8
+ static addMinutes(date, minutes) {
9
+ return $Date.addMilliseconds(date, minutes * 60_000);
10
+ }
11
+ static addHours(date, hours) {
12
+ return $Date.addMilliseconds(date, hours * 3_600_000);
13
+ }
14
+ static addDays(date, days) {
15
+ return $Date.addMilliseconds(date, days * 86_400_000);
16
+ }
17
+ static addWeeks(date, weeks) {
18
+ return $Date.addDays(date, weeks * 7);
19
+ }
20
+ static addMonths(date, months) {
21
+ date = new Date(date.getTime());
22
+ date.setMonth(date.getMonth() + months);
23
+ return date;
24
+ }
25
+ static addYears(date, years) {
26
+ date = new Date(date.getTime());
27
+ date.setFullYear(date.getFullYear() + years);
28
+ return date;
29
+ }
30
+ /**
31
+ *
32
+ * @param date
33
+ * @param format
34
+ * @returns
35
+ * @example
36
+ * // 12 Jan 2025 11:50:15
37
+ * `YYYY` = 2025
38
+ * `YY` = 25
39
+ * `MM` = 01
40
+ * `DD` = 12
41
+ * `hh` = 11
42
+ * `mm` = 50
43
+ * `ss` = 15
44
+ */
45
+ static format(date, format) {
46
+ const year = String(date.getFullYear());
47
+ const month = String(date.getMonth() + 1).padStart(2, '0');
48
+ const day = String(date.getDate()).padStart(2, '0');
49
+ const hours = String(date.getHours()).padStart(2, '0');
50
+ const minutes = String(date.getMinutes()).padStart(2, '0');
51
+ const seconds = String(date.getSeconds()).padStart(2, '0');
52
+ return format.replace('YYYY', year).replace('YY', year.slice(-2)).replace('MM', month).replace('DD', day).replace('hh', hours).replace('mm', minutes).replace('ss', seconds);
53
+ }
54
+ /**
55
+ *
56
+ * @param target
57
+ * @param compareTo
58
+ * @returns
59
+ * @example
60
+ * // 5 days ago
61
+ * // 1 minute from now
62
+ */
63
+ static toAgoString(target, compareTo = new Date()) {
64
+ const msDiff = compareTo.getTime() - target.getTime();
65
+ const seconds = Math.floor(Math.abs(msDiff) / 1000);
66
+ const epochs = [
67
+ { name: 'year', seconds: 31_536_000 },
68
+ { name: 'month', seconds: 2_592_000 },
69
+ { name: 'week', seconds: 604_800 },
70
+ { name: 'day', seconds: 86_400 },
71
+ { name: 'hour', seconds: 3_600 },
72
+ { name: 'minute', seconds: 60 },
73
+ { name: 'second', seconds: 0 },
74
+ ];
75
+ const epoch = epochs.find((e) => e.seconds <= seconds);
76
+ const count = Math.floor(seconds / (epoch.seconds || 1));
77
+ const unit = count === 1 ? epoch.name : `${epoch.name}s`;
78
+ const when = msDiff > 0 ? 'ago' : 'from now';
79
+ return `${count} ${unit} ${when}`;
80
+ }
81
+ static isValid(date) {
82
+ return date instanceof Date && !Number.isNaN(date.getTime());
83
+ }
84
+ }
@@ -0,0 +1,17 @@
1
+ import type { KeyValue } from '../../interfaces/key-value.interface';
2
+ export declare class $Enum {
3
+ static getFlags(target: any, value: number): string[];
4
+ static addFlag(value: number, flag: number): number;
5
+ static removeFlag(value: number, flag: number): number;
6
+ static toggleFlag(value: number, flag: number): number;
7
+ static hasFlag(value: any, flag: number): boolean;
8
+ static switchFlags(value: any, ...cases: [...number[], (value: number) => void][]): void;
9
+ static isNumeric(target: any): boolean;
10
+ static isNonNumeric(target: any): boolean;
11
+ static isEnum(target: any): boolean;
12
+ static getItems<T extends string | number = string | number>(target: any): KeyValue<T>[];
13
+ static getValues(target: any): any[];
14
+ static getKeys(target: any): string[];
15
+ static getValueKey(target: any, value: number | string): string | number;
16
+ static getValue(target: any, name: string | number): number | string;
17
+ }
@@ -0,0 +1,69 @@
1
+ import { $Reflection } from '../reflection/utils/reflection.util';
2
+ export class $Enum {
3
+ static getFlags(target, value) {
4
+ return $Enum
5
+ .getItems(target)
6
+ .filter((item) => $Enum.hasFlag(value, item.value))
7
+ .map((item) => item.key);
8
+ }
9
+ static addFlag(value, flag) {
10
+ return value | flag;
11
+ }
12
+ static removeFlag(value, flag) {
13
+ return value & ~flag;
14
+ }
15
+ static toggleFlag(value, flag) {
16
+ return $Enum.hasFlag(value, flag) ? $Enum.removeFlag(value, flag) : $Enum.addFlag(value, flag);
17
+ }
18
+ static hasFlag(value, flag) {
19
+ return value != null && flag != null && ((value === 0 && value === flag) || (value & flag) === flag);
20
+ }
21
+ static switchFlags(value, ...cases) {
22
+ for (const statement of cases) {
23
+ for (let i = 0; i < statement.length - 1; i++) {
24
+ if ($Enum.hasFlag(value, Number(statement[i]))) {
25
+ statement[statement.length - 1](value);
26
+ break;
27
+ }
28
+ }
29
+ }
30
+ }
31
+ static isNumeric(target) {
32
+ return $Reflection.isObject(target) && Object.keys(target).every((key) => (Number.isFinite(Number(key)) || typeof target[key] === 'number') && String(target[key]) in target);
33
+ }
34
+ static isNonNumeric(target) {
35
+ return $Reflection.isObject(target) && Object.keys(target).every((key) => !Number.isFinite(Number(key)) && typeof target[key] === 'string');
36
+ }
37
+ static isEnum(target) {
38
+ return $Enum.isNumeric(target) || $Enum.isNonNumeric(target);
39
+ }
40
+ static getItems(target) {
41
+ const items = [];
42
+ if ($Enum.isNumeric(target)) {
43
+ for (const key in target) {
44
+ if (typeof target[key] === 'number') {
45
+ items.push({ key, value: target[key] });
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ for (const key in target) {
51
+ items.push({ key, value: target[key] });
52
+ }
53
+ }
54
+ return items;
55
+ }
56
+ static getValues(target) {
57
+ return $Enum.getItems(target).map((iItem) => iItem.value);
58
+ }
59
+ static getKeys(target) {
60
+ return $Enum.getItems(target).map((iItem) => iItem.key);
61
+ }
62
+ static getValueKey(target, value) {
63
+ const item = $Enum.getItems(target).find((iEntry) => iEntry.value === value);
64
+ return item ? item.key : typeof value === 'number' ? value : null;
65
+ }
66
+ static getValue(target, name) {
67
+ return target[name];
68
+ }
69
+ }
@@ -0,0 +1,3 @@
1
+ export declare class $Hash {
2
+ static generateSha256Base64(value: any): Promise<string>;
3
+ }
@@ -0,0 +1,9 @@
1
+ import { $Value } from '../value/value.util';
2
+ export class $Hash {
3
+ static async generateSha256Base64(value) {
4
+ const json = JSON.stringify($Value.orderProperties(value));
5
+ const buffer = new TextEncoder().encode(json);
6
+ const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
7
+ return btoa(String.fromCharCode(...new Uint8Array(hashBuffer))).slice(0, 12);
8
+ }
9
+ }
@@ -0,0 +1,7 @@
1
+ export declare class $Id {
2
+ static guid(): string;
3
+ static uuid(): string;
4
+ static getUuidTimestamp(uuid: string): number;
5
+ static uid(): string;
6
+ static getUidTimestamp(uid: string): number;
7
+ }
@@ -0,0 +1,33 @@
1
+ export class $Id {
2
+ static guid() {
3
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
4
+ const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
5
+ return v.toString(16);
6
+ });
7
+ }
8
+ static uuid() {
9
+ const timestamp = Date.now();
10
+ const bytes = new Uint8Array(16);
11
+ bytes[0] = (timestamp / 2 ** 40) & 0xff;
12
+ bytes[1] = (timestamp / 2 ** 32) & 0xff;
13
+ bytes[2] = (timestamp / 2 ** 24) & 0xff;
14
+ bytes[3] = (timestamp / 2 ** 16) & 0xff;
15
+ bytes[4] = (timestamp / 2 ** 8) & 0xff;
16
+ bytes[5] = timestamp & 0xff;
17
+ crypto.getRandomValues(bytes.subarray(6));
18
+ bytes[6] = (bytes[6] & 0x0f) | 0x70;
19
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
20
+ const hex = [...bytes].map(b => b.toString(16).padStart(2, '0')).join('');
21
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
22
+ }
23
+ static getUuidTimestamp(uuid) {
24
+ const hex = uuid.slice(0, 8) + uuid.slice(9, 13);
25
+ return parseInt(hex, 16);
26
+ }
27
+ static uid() {
28
+ return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;
29
+ }
30
+ static getUidTimestamp(uid) {
31
+ return parseInt(uid.slice(0, -3), 36);
32
+ }
33
+ }
@@ -0,0 +1,14 @@
1
+ import type { Type } from '../../reflection/types/type.type';
2
+ import { ConstructorParameterDecorator } from '../../reflection/utils/decorator.util';
3
+ export type InjectDecoratorData = {
4
+ type: Type;
5
+ optional?: boolean;
6
+ };
7
+ export declare class InjectDecorator extends ConstructorParameterDecorator<InjectDecoratorData> {
8
+ }
9
+ export declare function Inject(args: {
10
+ type: Type;
11
+ optional?: boolean;
12
+ index: number;
13
+ name: string;
14
+ }): (target: Type, _context: ClassDecoratorContext) => void;
@@ -0,0 +1,12 @@
1
+ import { $Decorator, ConstructorParameterDecorator } from '../../reflection/utils/decorator.util';
2
+ export class InjectDecorator extends ConstructorParameterDecorator {
3
+ }
4
+ export function Inject(args) {
5
+ return $Decorator.createClassDecorator((type) => {
6
+ const data = {
7
+ type: args.type,
8
+ optional: args.optional,
9
+ };
10
+ return new InjectDecorator(type, { index: args.index, name: args.name }, data);
11
+ });
12
+ }
@@ -0,0 +1,9 @@
1
+ import { ClassDecorator } from '../../reflection/utils/decorator.util';
2
+ import { ProviderScopes } from '../provider-scopes.enum';
3
+ export type InjectableDecoratorData = {
4
+ global?: boolean;
5
+ scope?: ProviderScopes;
6
+ };
7
+ export declare class InjectableDecorator extends ClassDecorator<InjectableDecoratorData> {
8
+ }
9
+ export declare function Injectable(data?: InjectableDecoratorData): (target: import("../../..").Type, _context: ClassDecoratorContext) => void;
@@ -0,0 +1,7 @@
1
+ import { $Decorator, ClassDecorator } from '../../reflection/utils/decorator.util';
2
+ import { ProviderScopes } from '../provider-scopes.enum';
3
+ export class InjectableDecorator extends ClassDecorator {
4
+ }
5
+ export function Injectable(data = { scope: ProviderScopes.Singleton }) {
6
+ return $Decorator.createClassDecorator((type) => new InjectableDecorator(type, data));
7
+ }
@@ -0,0 +1,25 @@
1
+ import type { Constructor } from '../reflection/types/constructor.type';
2
+ import { Instance } from '../reflection/types/instance.type';
3
+ import type { Type } from '../reflection/types/type.type';
4
+ import type { IProvider, Provider } from './provider.interface';
5
+ export declare class InjectorError extends Error {
6
+ }
7
+ export declare class Injector {
8
+ static providers: IProvider[];
9
+ providers: IProvider[];
10
+ parentInjector: Injector;
11
+ constructor(providers?: Provider[], parentInjector?: Injector);
12
+ static parseProvider(value: Provider): IProvider;
13
+ private getProvider;
14
+ private getGlobalProvider;
15
+ create<T = any>(type: Constructor<T>): T;
16
+ private createProviderInstance;
17
+ get<T = any>(type: Type<T>, optional?: boolean): T;
18
+ map<T extends Record<string, Type<T>>>(map: T): {
19
+ [key in keyof T]: Instance<T[key]>;
20
+ };
21
+ add(...providers: Provider[]): Injector;
22
+ addInstance(...instances: any[]): Injector;
23
+ addDefault(...providers: Provider[]): Injector;
24
+ scope(...instances: any[]): Injector;
25
+ }
@@ -0,0 +1,152 @@
1
+ import { $Decorator } from '../reflection/utils/decorator.util';
2
+ import { $Reflection } from '../reflection/utils/reflection.util';
3
+ import { InjectableDecorator } from './decorators/injectable.decorator';
4
+ import { ProviderScopes } from './provider-scopes.enum';
5
+ export class InjectorError extends Error {
6
+ }
7
+ export class Injector {
8
+ static providers = [];
9
+ providers = [];
10
+ parentInjector;
11
+ constructor(providers = [], parentInjector) {
12
+ this.providers = providers.map((provider) => Injector.parseProvider(provider));
13
+ this.parentInjector = parentInjector;
14
+ }
15
+ static parseProvider(value) {
16
+ if ($Reflection.isType(value)) {
17
+ const decorator = $Decorator.get({
18
+ target: value,
19
+ type: InjectableDecorator,
20
+ first: true,
21
+ });
22
+ return {
23
+ scope: decorator?.data.scope ?? ProviderScopes.Singleton,
24
+ type: value,
25
+ };
26
+ }
27
+ else {
28
+ const provider = value;
29
+ const decorator = $Decorator.get({
30
+ target: provider.type,
31
+ type: InjectableDecorator,
32
+ first: true,
33
+ });
34
+ provider.scope ??= decorator?.data.scope ?? ProviderScopes.Singleton;
35
+ return provider;
36
+ }
37
+ }
38
+ getProvider(type) {
39
+ for (const provider of this.providers) {
40
+ if ($Reflection.extends(provider.type, type)) {
41
+ return provider;
42
+ }
43
+ }
44
+ }
45
+ getGlobalProvider(type) {
46
+ const injectable = $Decorator.get({
47
+ target: type,
48
+ type: InjectableDecorator,
49
+ first: true,
50
+ });
51
+ if (injectable?.data.global) {
52
+ let provider = Injector.providers.find((provider) => $Reflection.extends(provider.type, type));
53
+ if (!provider) {
54
+ provider = Injector.parseProvider(type);
55
+ Injector.providers.push(provider);
56
+ }
57
+ return provider;
58
+ }
59
+ }
60
+ create(type) {
61
+ if ('inject' in type && typeof type.inject === 'object' && type.inject != null) {
62
+ const tokens = {};
63
+ for (const [key, value] of Object.entries(type.inject)) {
64
+ try {
65
+ tokens[key] = this.get(value);
66
+ }
67
+ catch (error) {
68
+ if (error instanceof InjectorError) {
69
+ throw new InjectorError(`Unable to create ${$Reflection.getTypeName(type)}, failed to resolve key (${key}). ${error.message}`);
70
+ }
71
+ throw error;
72
+ }
73
+ }
74
+ return new type(tokens);
75
+ }
76
+ return new type();
77
+ }
78
+ createProviderInstance(provider, scope = ProviderScopes.Singleton) {
79
+ if (provider.value == null || provider.scope === ProviderScopes.Transient || (scope === ProviderScopes.Transient && provider.scope !== ProviderScopes.Singleton) || (scope === ProviderScopes.Scoped && provider.scope !== ProviderScopes.Singleton)) {
80
+ if (provider.factory) {
81
+ return provider.factory(this);
82
+ }
83
+ else if ($Reflection.isType(provider.type)) {
84
+ return this.create(provider.type);
85
+ }
86
+ else {
87
+ throw new InjectorError(`Unable to create provider instance ${$Reflection.getTypeName(provider.type)}. Type is not constructable or factory is not provided`);
88
+ }
89
+ }
90
+ return provider.value;
91
+ }
92
+ get(type, optional) {
93
+ if (type === Injector) {
94
+ return this;
95
+ }
96
+ else if (type === Object) {
97
+ throw new InjectorError('Unable to resolve provider for anonymous type.');
98
+ }
99
+ else {
100
+ const provider = this.getProvider(type) ?? this.parentInjector?.getProvider(type) ?? this.getGlobalProvider(type);
101
+ if (provider) {
102
+ provider.value = this.createProviderInstance(provider);
103
+ return provider.value;
104
+ }
105
+ else if (!optional) {
106
+ throw new InjectorError(`No provider registered for type (${$Reflection.getTypeName(type)}).`);
107
+ }
108
+ }
109
+ }
110
+ map(map) {
111
+ return Object.keys(map).reduce((result, key) => ({ ...result, [key]: this.get(map[key]) }), {});
112
+ }
113
+ add(...providers) {
114
+ for (const provider of providers.map(Injector.parseProvider)) {
115
+ this.providers = [...this.providers.filter((_provider) => !$Reflection.extends(provider.type, _provider.type)), provider];
116
+ }
117
+ return this;
118
+ }
119
+ addInstance(...instances) {
120
+ for (const instance of instances) {
121
+ const type = $Reflection.getType(instance);
122
+ this.add({
123
+ scope: ProviderScopes.Singleton,
124
+ type,
125
+ value: instance,
126
+ });
127
+ }
128
+ return this;
129
+ }
130
+ addDefault(...providers) {
131
+ for (const provider of providers.map(Injector.parseProvider)) {
132
+ if (!this.getProvider(provider.type)) {
133
+ this.add(provider);
134
+ }
135
+ }
136
+ return this;
137
+ }
138
+ scope(...instances) {
139
+ const providers = [];
140
+ for (const provider of this.providers) {
141
+ if (provider.scope !== ProviderScopes.Singleton) {
142
+ providers.push({
143
+ ...provider,
144
+ value: this.createProviderInstance(provider, ProviderScopes.Scoped),
145
+ });
146
+ }
147
+ }
148
+ const scope = new Injector(providers, this.parentInjector ?? this);
149
+ scope.addInstance(...instances);
150
+ return scope;
151
+ }
152
+ }
@@ -0,0 +1,5 @@
1
+ export declare enum ProviderScopes {
2
+ Singleton = 0,
3
+ Scoped = 1,
4
+ Transient = 2
5
+ }
@@ -0,0 +1,6 @@
1
+ export var ProviderScopes;
2
+ (function (ProviderScopes) {
3
+ ProviderScopes[ProviderScopes["Singleton"] = 0] = "Singleton";
4
+ ProviderScopes[ProviderScopes["Scoped"] = 1] = "Scoped";
5
+ ProviderScopes[ProviderScopes["Transient"] = 2] = "Transient";
6
+ })(ProviderScopes || (ProviderScopes = {}));
@@ -0,0 +1,10 @@
1
+ import type { Type } from '../reflection/types/type.type';
2
+ import type { Injector } from './injector.model';
3
+ import type { ProviderScopes } from './provider-scopes.enum';
4
+ export interface IProvider<T = any> {
5
+ type: Type<T>;
6
+ scope: ProviderScopes;
7
+ value?: T;
8
+ factory?: (injector: Injector) => T;
9
+ }
10
+ export type Provider<T = any> = Type<T> | IProvider<T>;
File without changes
@@ -0,0 +1,41 @@
1
+ export type JsonFilter<T = any> = (value: T) => boolean;
2
+ export type JsonFilterOperator<TArg = any, TValue = any> = (arg: TArg, options: JsonFilterOptions) => JsonFilter<TValue>;
3
+ export type JsonFilterOperators = {
4
+ [operator: string]: JsonFilterOperator;
5
+ };
6
+ export declare const JsonFilters: {
7
+ query: <T = any, TT = any>(selector: (value: T) => TT, operator: JsonFilter<TT>) => (value: T) => boolean;
8
+ and: <T = any>(...operators: JsonFilter<T>[]) => (value: T) => boolean;
9
+ or: <T = any>(...operators: JsonFilter<T>[]) => (value: T) => boolean;
10
+ not: <T = any>(operator: JsonFilter<T>) => (value: T) => boolean;
11
+ equals: (arg: string | number | Date) => (value: any) => boolean;
12
+ length: (arg: number) => (value: any) => boolean;
13
+ contains: (arg: string | number) => (value: any) => boolean;
14
+ starts: (arg: string | number | Date) => (value: any) => boolean;
15
+ ends: (arg: string | number | Date) => (value: any) => boolean;
16
+ greater: (arg: number | Date) => (value: any) => boolean;
17
+ less: (arg: number | Date) => (value: any) => boolean;
18
+ };
19
+ export declare const JsonFilterOperators: JsonFilterOperators;
20
+ export type JsonFilterOptions = {
21
+ operatorPrefix: string;
22
+ operator: 'or' | 'and';
23
+ operators: {
24
+ [operator: string]: JsonFilterOperator;
25
+ };
26
+ };
27
+ export declare const DefaultJsonFilterOptions: JsonFilterOptions;
28
+ export type JsonFilterQuery = {
29
+ [property: string]: JsonFilterQuery;
30
+ } | {
31
+ $and?: JsonFilterQuery[];
32
+ $or?: JsonFilterQuery[];
33
+ $not?: JsonFilterQuery;
34
+ $equals?: string | number | Date;
35
+ $contains?: string | number;
36
+ $starts?: string | number | Date;
37
+ $ends?: string | number | Date;
38
+ $greater?: number | Date;
39
+ $less?: number | Date;
40
+ };
41
+ export declare function jsonFilter<TQuery = JsonFilterQuery>(query: TQuery, options?: Partial<JsonFilterOptions>): JsonFilter;