desktopr 1.3.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-sdk/_companion_context.js +10 -5
- package/dist-sdk/_helpers.js +1 -1
- package/dist-sdk/desktopr/_helpers.js +1 -1
- package/dist-sdk/desktopr/_types.d.ts +2 -2
- package/dist-sdk/modules/rs/app/_types.d.ts +1 -1
- package/dist-sdk/modules/rs/badge/_types.d.ts +1 -1
- package/dist-sdk/modules/rs/contextMenu/_helpers.js +1 -1
- package/dist-sdk/modules/rs/diagnostics/_helpers.js +1 -1
- package/dist-sdk/modules/rs/diagnostics/_types.d.ts +1 -1
- package/dist-sdk/modules/rs/files/_types.d.ts +1 -1
- package/dist-sdk/modules/rs/fs/_main.js +44 -1
- package/dist-sdk/modules/rs/fs/_types.d.ts +7 -1
- package/dist-sdk/modules/rs/menu/_helpers.js +1 -1
- package/dist-sdk/modules/rs/network/_types.d.ts +1 -1
- package/dist-sdk/modules/rs/plugins/_helpers.d.ts +1 -0
- package/dist-sdk/modules/rs/plugins/_helpers.js +9 -0
- package/dist-sdk/modules/rs/plugins/_main.d.ts +5 -0
- package/dist-sdk/modules/rs/plugins/_main.js +15 -0
- package/dist-sdk/modules/rs/plugins/_types.d.ts +38 -0
- package/dist-sdk/modules/rs/plugins/_types.js +2 -0
- package/dist-sdk/modules/rs/window/_helpers.js +1 -1
- package/dist-sdk/modules/rs/worker/_main.d.ts +1 -1
- package/dist-sdk/modules/rs/worker/_types.d.ts +1 -1
- package/dist-sdk/utils/crypto/_crypto.d.ts +31 -0
- package/dist-sdk/utils/crypto/_crypto.js +116 -0
- package/dist-sdk/utils/crypto/index.d.ts +1 -0
- package/dist-sdk/utils/crypto/index.js +17 -0
- package/dist-sdk/utils/index.d.ts +2 -0
- package/dist-sdk/utils/index.js +18 -0
- package/dist-sdk/utils/shared/_types.d.ts +64 -0
- package/dist-sdk/utils/shared/_types.js +2 -0
- package/dist-sdk/utils/utils/_browserStorage.d.ts +22 -0
- package/dist-sdk/utils/utils/_browserStorage.js +149 -0
- package/dist-sdk/utils/utils/_integerUtils.d.ts +50 -0
- package/dist-sdk/utils/utils/_integerUtils.js +74 -0
- package/dist-sdk/utils/utils/_jitter.d.ts +4 -0
- package/dist-sdk/utils/utils/_jitter.js +25 -0
- package/dist-sdk/utils/utils/_json.d.ts +63 -0
- package/dist-sdk/utils/utils/_json.js +510 -0
- package/dist-sdk/utils/utils/_logger.d.ts +16 -0
- package/dist-sdk/utils/utils/_logger.js +43 -0
- package/dist-sdk/utils/utils/_pageStore.d.ts +37 -0
- package/dist-sdk/utils/utils/_pageStore.js +61 -0
- package/dist-sdk/utils/utils/_regexPatterns.d.ts +113 -0
- package/dist-sdk/utils/utils/_regexPatterns.js +150 -0
- package/dist-sdk/utils/utils/_typesValidation.d.ts +50 -0
- package/dist-sdk/utils/utils/_typesValidation.js +125 -0
- package/dist-sdk/utils/utils/_utils.d.ts +201 -0
- package/dist-sdk/utils/utils/_utils.js +1200 -0
- package/dist-sdk/utils/utils/index.d.ts +9 -0
- package/dist-sdk/utils/utils/index.js +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export type ColorInfo = {
|
|
2
|
+
HEX: string;
|
|
3
|
+
RGB: {
|
|
4
|
+
R: number;
|
|
5
|
+
G: number;
|
|
6
|
+
B: number;
|
|
7
|
+
};
|
|
8
|
+
TAILWIND_CLASS: string;
|
|
9
|
+
};
|
|
10
|
+
export type AppRoute = {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
};
|
|
15
|
+
export type VoidFunction = () => void;
|
|
16
|
+
export type AuthMode = "signin" | "signup" | "forgot_password" | null | undefined;
|
|
17
|
+
export type PasswordStrength = {
|
|
18
|
+
text: 'very weak';
|
|
19
|
+
score: 0;
|
|
20
|
+
} | {
|
|
21
|
+
text: 'weak';
|
|
22
|
+
score: 1;
|
|
23
|
+
} | {
|
|
24
|
+
text: 'medium';
|
|
25
|
+
score: 2;
|
|
26
|
+
} | {
|
|
27
|
+
text: 'strong';
|
|
28
|
+
score: 3;
|
|
29
|
+
} | {
|
|
30
|
+
text: 'very strong';
|
|
31
|
+
score: 4;
|
|
32
|
+
};
|
|
33
|
+
export type TailwindWidth = '3xs' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | '7xl';
|
|
34
|
+
export type TableData = {
|
|
35
|
+
id?: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
columns: string[];
|
|
38
|
+
rows: (string | number | boolean | null)[][];
|
|
39
|
+
enableHorizontalHeader?: boolean;
|
|
40
|
+
};
|
|
41
|
+
export type CheckboxSetOption = {
|
|
42
|
+
value: string | number;
|
|
43
|
+
label: string;
|
|
44
|
+
id?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
};
|
|
47
|
+
export type DropdownOption = {
|
|
48
|
+
label: string;
|
|
49
|
+
value: string | number;
|
|
50
|
+
id: string;
|
|
51
|
+
flag?: string;
|
|
52
|
+
};
|
|
53
|
+
export type ComboboxOption = DropdownOption & {
|
|
54
|
+
description?: string;
|
|
55
|
+
};
|
|
56
|
+
export type AnyObject = Record<string, any>;
|
|
57
|
+
export type HexColor = `#${string}`;
|
|
58
|
+
export type RgbColor = `rgb(${number}, ${number}, ${number})`;
|
|
59
|
+
export type RgbaColor = `rgba(${number}, ${number}, ${number}, ${number})`;
|
|
60
|
+
export type HslColor = `hsl(${number}, ${number}%, ${number}%)`;
|
|
61
|
+
export type HslaColor = `hsla(${number}, ${number}%, ${number}%, ${number})`;
|
|
62
|
+
export type ColorString = HexColor | RgbColor | RgbaColor | HslColor | HslaColor;
|
|
63
|
+
export type CssNamedColor = 'aliceblue' | 'antiquewhite' | 'aqua' | 'aquamarine' | 'azure' | 'beige' | 'bisque' | 'black' | 'blanchedalmond' | 'blue' | 'blueviolet' | 'brown' | 'burlywood' | 'cadetblue' | 'chartreuse' | 'chocolate' | 'coral' | 'cornflowerblue' | 'cornsilk' | 'crimson' | 'cyan' | 'darkblue' | 'darkcyan' | 'darkgoldenrod' | 'darkgray' | 'darkgreen' | 'darkgrey' | 'darkkhaki' | 'darkmagenta' | 'darkolivegreen' | 'darkorange' | 'darkorchid' | 'darkred' | 'darksalmon' | 'darkseagreen' | 'darkslateblue' | 'darkslategray' | 'darkslategrey' | 'darkturquoise' | 'darkviolet' | 'deeppink' | 'deepskyblue' | 'dimgray' | 'dimgrey' | 'dodgerblue' | 'firebrick' | 'floralwhite' | 'forestgreen' | 'fuchsia' | 'gainsboro' | 'ghostwhite' | 'gold' | 'goldenrod' | 'gray' | 'green' | 'greenyellow' | 'grey' | 'honeydew' | 'hotpink' | 'indianred' | 'indigo' | 'ivory' | 'khaki' | 'lavender' | 'lavenderblush' | 'lawngreen' | 'lemonchiffon' | 'lightblue' | 'lightcoral' | 'lightcyan' | 'lightgoldenrodyellow' | 'lightgray' | 'lightgreen' | 'lightgrey' | 'lightpink' | 'lightsalmon' | 'lightseagreen' | 'lightskyblue' | 'lightslategray' | 'lightslategrey' | 'lightsteelblue' | 'lightyellow' | 'lime' | 'limegreen' | 'linen' | 'magenta' | 'maroon' | 'mediumaquamarine' | 'mediumblue' | 'mediumorchid' | 'mediumpurple' | 'mediumseagreen' | 'mediumslateblue' | 'mediumspringgreen' | 'mediumturquoise' | 'mediumvioletred' | 'midnightblue' | 'mintcream' | 'mistyrose' | 'moccasin' | 'navajowhite' | 'navy' | 'oldlace' | 'olive' | 'olivedrab' | 'orange' | 'orangered' | 'orchid' | 'palegoldenrod' | 'palegreen' | 'paleturquoise' | 'palevioletred' | 'papayawhip' | 'peachpuff' | 'peru' | 'pink' | 'plum' | 'powderblue' | 'purple' | 'rebeccapurple' | 'red' | 'rosybrown' | 'royalblue' | 'saddlebrown' | 'salmon' | 'sandybrown' | 'seagreen' | 'seashell' | 'sienna' | 'silver' | 'skyblue' | 'slateblue' | 'slategray' | 'slategrey' | 'snow' | 'springgreen' | 'steelblue' | 'tan' | 'teal' | 'thistle' | 'tomato' | 'turquoise' | 'violet' | 'wheat' | 'white' | 'whitesmoke' | 'yellow' | 'yellowgreen';
|
|
64
|
+
export type StringLiteralJoin<T extends string[], Sep extends string = ''> = T extends [infer F extends string, ...infer R extends string[]] ? R['length'] extends 0 ? F : `${F}${Sep}${StringLiteralJoin<R, Sep>}` : '';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type BrowserStorageType = "local" | "session";
|
|
2
|
+
interface _BrowserStorageAPI {
|
|
3
|
+
getItem(key: string): unknown | null;
|
|
4
|
+
getNamespaceItems(): {
|
|
5
|
+
key: string;
|
|
6
|
+
value: unknown;
|
|
7
|
+
}[];
|
|
8
|
+
getItemsByKeys(keys: string[]): {
|
|
9
|
+
key: string;
|
|
10
|
+
value: unknown;
|
|
11
|
+
}[];
|
|
12
|
+
setItem(key: string, value: unknown, options?: {
|
|
13
|
+
expiresIn?: number;
|
|
14
|
+
}): void;
|
|
15
|
+
removeItem(key: string): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
clearExpired(): void;
|
|
18
|
+
length(): number;
|
|
19
|
+
keysList(): string[];
|
|
20
|
+
}
|
|
21
|
+
export declare function browserStorage(type: BrowserStorageType, namespace?: string): _BrowserStorageAPI;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.browserStorage = browserStorage;
|
|
4
|
+
const _logger_1 = require("./_logger");
|
|
5
|
+
const _isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
6
|
+
function browserStorage(type, namespace) {
|
|
7
|
+
const _storage = _isBrowser
|
|
8
|
+
? type === "local"
|
|
9
|
+
? localStorage
|
|
10
|
+
: sessionStorage
|
|
11
|
+
: undefined;
|
|
12
|
+
const _prefix = namespace ? `${namespace}:` : "";
|
|
13
|
+
function _fullKey(key) {
|
|
14
|
+
return `${_prefix}${key}`;
|
|
15
|
+
}
|
|
16
|
+
function getItem(key) {
|
|
17
|
+
if (!_isBrowser)
|
|
18
|
+
return null;
|
|
19
|
+
const raw = _storage?.getItem(_fullKey(key));
|
|
20
|
+
if (!raw)
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(raw);
|
|
24
|
+
if (parsed.expiresAt && Date.now() > parsed.expiresAt) {
|
|
25
|
+
_storage?.removeItem(_fullKey(key));
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return parsed.value;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function getNamespaceItems() {
|
|
35
|
+
if (!_isBrowser)
|
|
36
|
+
return [];
|
|
37
|
+
const items = [];
|
|
38
|
+
for (let i = 0; i < (_storage?.length ?? 0); i++) {
|
|
39
|
+
const fullKey = _storage?.key(i);
|
|
40
|
+
if (!fullKey || (_prefix && !fullKey.startsWith(_prefix)))
|
|
41
|
+
continue;
|
|
42
|
+
const key = fullKey.slice(_prefix.length); // rimuove il namespace
|
|
43
|
+
const raw = _storage?.getItem(fullKey);
|
|
44
|
+
if (!raw)
|
|
45
|
+
continue;
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(raw);
|
|
48
|
+
if (parsed.expiresAt && Date.now() > parsed.expiresAt)
|
|
49
|
+
continue;
|
|
50
|
+
items.push({ key, value: parsed.value });
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// ignora valori corrotti
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return items;
|
|
57
|
+
}
|
|
58
|
+
function getItemsByKeys(keys) {
|
|
59
|
+
if (!_isBrowser)
|
|
60
|
+
return [];
|
|
61
|
+
const items = [];
|
|
62
|
+
for (const key of keys) {
|
|
63
|
+
const fullKey = _fullKey(key);
|
|
64
|
+
const raw = _storage?.getItem(fullKey);
|
|
65
|
+
if (!raw)
|
|
66
|
+
continue;
|
|
67
|
+
try {
|
|
68
|
+
const parsed = JSON.parse(raw);
|
|
69
|
+
if (parsed.expiresAt && Date.now() > parsed.expiresAt)
|
|
70
|
+
continue;
|
|
71
|
+
items.push({ key, value: parsed.value });
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// ignora valori corrotti
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return items;
|
|
78
|
+
}
|
|
79
|
+
function setItem(key, value, options) {
|
|
80
|
+
if (!_isBrowser)
|
|
81
|
+
return;
|
|
82
|
+
const expiresAt = options?.expiresIn
|
|
83
|
+
? Date.now() + options.expiresIn * 1000
|
|
84
|
+
: undefined;
|
|
85
|
+
const payload = { value, expiresAt };
|
|
86
|
+
try {
|
|
87
|
+
_storage?.setItem(_fullKey(key), JSON.stringify(payload));
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
_logger_1.logger.warn(`[browserStorage] Failed to set key "${key}"`, err);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function removeItem(key) {
|
|
94
|
+
if (!_isBrowser)
|
|
95
|
+
return;
|
|
96
|
+
_storage?.removeItem(_fullKey(key));
|
|
97
|
+
}
|
|
98
|
+
function clear() {
|
|
99
|
+
if (!_isBrowser)
|
|
100
|
+
return;
|
|
101
|
+
keysList().forEach((key) => _storage?.removeItem(key));
|
|
102
|
+
}
|
|
103
|
+
function clearExpired() {
|
|
104
|
+
if (!_isBrowser)
|
|
105
|
+
return;
|
|
106
|
+
keysList().forEach((key) => {
|
|
107
|
+
const raw = _storage?.getItem(key);
|
|
108
|
+
if (!raw)
|
|
109
|
+
return;
|
|
110
|
+
try {
|
|
111
|
+
const parsed = JSON.parse(raw);
|
|
112
|
+
if (parsed.expiresAt && Date.now() > parsed.expiresAt) {
|
|
113
|
+
_storage?.removeItem(key);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// ignore
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function length() {
|
|
122
|
+
if (!_isBrowser)
|
|
123
|
+
return 0;
|
|
124
|
+
return keysList().length;
|
|
125
|
+
}
|
|
126
|
+
function keysList() {
|
|
127
|
+
if (!_isBrowser)
|
|
128
|
+
return [];
|
|
129
|
+
const keys = [];
|
|
130
|
+
for (let i = 0; i < (_storage?.length ?? 0); i++) {
|
|
131
|
+
const key = _storage?.key(i);
|
|
132
|
+
if (key && (!_prefix || key.startsWith(_prefix))) {
|
|
133
|
+
keys.push(key);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return keys;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
getItem,
|
|
140
|
+
getNamespaceItems,
|
|
141
|
+
getItemsByKeys,
|
|
142
|
+
setItem,
|
|
143
|
+
removeItem,
|
|
144
|
+
clear,
|
|
145
|
+
clearExpired,
|
|
146
|
+
length,
|
|
147
|
+
keysList,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type Brand<Base, Tag extends string> = Base & {
|
|
2
|
+
readonly __brand: Tag;
|
|
3
|
+
};
|
|
4
|
+
export type U8 = Brand<number, "u8">;
|
|
5
|
+
export type U16 = Brand<number, "u16">;
|
|
6
|
+
export type U32 = Brand<number, "u32">;
|
|
7
|
+
export type U64 = Brand<number, "u64">;
|
|
8
|
+
export type I8 = Brand<number, "i8">;
|
|
9
|
+
export type I16 = Brand<number, "i16">;
|
|
10
|
+
export type I32 = Brand<number, "i32">;
|
|
11
|
+
export type I64 = Brand<number, "i64">;
|
|
12
|
+
export type F32 = Brand<number, "f32">;
|
|
13
|
+
export type F64 = Brand<number, "f64">;
|
|
14
|
+
export type NumberPredicate = (v: unknown) => v is number;
|
|
15
|
+
export interface NumPredicates {
|
|
16
|
+
isU8: NumberPredicate;
|
|
17
|
+
isU16: NumberPredicate;
|
|
18
|
+
isU32: NumberPredicate;
|
|
19
|
+
isU64: NumberPredicate;
|
|
20
|
+
isI8: NumberPredicate;
|
|
21
|
+
isI16: NumberPredicate;
|
|
22
|
+
isI32: NumberPredicate;
|
|
23
|
+
isI64: NumberPredicate;
|
|
24
|
+
isF32: NumberPredicate;
|
|
25
|
+
isF64: NumberPredicate;
|
|
26
|
+
}
|
|
27
|
+
export interface Refinement<TBrand extends string> {
|
|
28
|
+
/** Type guard verso il tipo brandizzato */
|
|
29
|
+
is(v: unknown): v is Brand<number, TBrand>;
|
|
30
|
+
/** Costruttore che valida e lancia su input invalido */
|
|
31
|
+
as(v: unknown): Brand<number, TBrand>;
|
|
32
|
+
/** Costruttore “safe” che restituisce null se non valido */
|
|
33
|
+
try(v: unknown): Brand<number, TBrand> | null;
|
|
34
|
+
/** Parser da stringa (usa Number), valida e lancia su input invalido */
|
|
35
|
+
parse(s: string): Brand<number, TBrand>;
|
|
36
|
+
}
|
|
37
|
+
export interface NumAPI extends NumPredicates {
|
|
38
|
+
U8: Refinement<"u8">;
|
|
39
|
+
U16: Refinement<"u16">;
|
|
40
|
+
U32: Refinement<"u32">;
|
|
41
|
+
U64: Refinement<"u64">;
|
|
42
|
+
I8: Refinement<"i8">;
|
|
43
|
+
I16: Refinement<"i16">;
|
|
44
|
+
I32: Refinement<"i32">;
|
|
45
|
+
I64: Refinement<"i64">;
|
|
46
|
+
F32: Refinement<"f32">;
|
|
47
|
+
F64: Refinement<"f64">;
|
|
48
|
+
}
|
|
49
|
+
export declare const Pred: Readonly<NumPredicates>;
|
|
50
|
+
export declare const Num: NumAPI;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// numberUtils.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Num = exports.Pred = void 0;
|
|
5
|
+
// ---------- Runtime helpers ----------
|
|
6
|
+
function isIntegerInRange(v, min, max) {
|
|
7
|
+
return typeof v === "number" && Number.isInteger(v) && v >= min && v <= max;
|
|
8
|
+
}
|
|
9
|
+
function isF32Runtime(v) {
|
|
10
|
+
return typeof v === "number" && Math.fround(v) === v;
|
|
11
|
+
}
|
|
12
|
+
// Predicati tipizzati e riusabili
|
|
13
|
+
exports.Pred = {
|
|
14
|
+
// Unsigned
|
|
15
|
+
isU8: (v) => isIntegerInRange(v, 0, 0xFF),
|
|
16
|
+
isU16: (v) => isIntegerInRange(v, 0, 0xFFFF),
|
|
17
|
+
isU32: (v) => isIntegerInRange(v, 0, 0xFFFFFFFF),
|
|
18
|
+
isU64: (v) => isIntegerInRange(v, 0, Number.MAX_SAFE_INTEGER),
|
|
19
|
+
// Signed
|
|
20
|
+
isI8: (v) => isIntegerInRange(v, -0x80, 0x7F),
|
|
21
|
+
isI16: (v) => isIntegerInRange(v, -0x8000, 0x7FFF),
|
|
22
|
+
isI32: (v) => isIntegerInRange(v, -0x80000000, 0x7FFFFFFF),
|
|
23
|
+
isI64: (v) => typeof v === "number" &&
|
|
24
|
+
Number.isInteger(v) &&
|
|
25
|
+
v >= Number.MIN_SAFE_INTEGER &&
|
|
26
|
+
v <= Number.MAX_SAFE_INTEGER,
|
|
27
|
+
// Floats
|
|
28
|
+
isF32: (v) => isF32Runtime(v),
|
|
29
|
+
isF64: (v) => typeof v === "number",
|
|
30
|
+
};
|
|
31
|
+
// Factory per i refinements
|
|
32
|
+
function makeRefinement(tag, isFn) {
|
|
33
|
+
return {
|
|
34
|
+
is: (v) => isFn(v),
|
|
35
|
+
as: (v) => {
|
|
36
|
+
if (!isFn(v))
|
|
37
|
+
throw new TypeError(`Expected ${tag}, got ${String(v)}`);
|
|
38
|
+
return v;
|
|
39
|
+
},
|
|
40
|
+
try: (v) => (isFn(v) ? v : null),
|
|
41
|
+
parse: (s) => {
|
|
42
|
+
const n = Number(s);
|
|
43
|
+
if (!Number.isFinite(n) || !isFn(n)) {
|
|
44
|
+
throw new TypeError(`Invalid ${tag} from "${s}"`);
|
|
45
|
+
}
|
|
46
|
+
return n;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Implementazione + tipizzazione esplicita
|
|
51
|
+
exports.Num = {
|
|
52
|
+
// Predicates (stile number.is...)
|
|
53
|
+
isU8: exports.Pred.isU8,
|
|
54
|
+
isU16: exports.Pred.isU16,
|
|
55
|
+
isU32: exports.Pred.isU32,
|
|
56
|
+
isU64: exports.Pred.isU64,
|
|
57
|
+
isI8: exports.Pred.isI8,
|
|
58
|
+
isI16: exports.Pred.isI16,
|
|
59
|
+
isI32: exports.Pred.isI32,
|
|
60
|
+
isI64: exports.Pred.isI64,
|
|
61
|
+
isF32: exports.Pred.isF32,
|
|
62
|
+
isF64: exports.Pred.isF64,
|
|
63
|
+
// Branded constructors / refiners
|
|
64
|
+
U8: makeRefinement("u8", exports.Pred.isU8),
|
|
65
|
+
U16: makeRefinement("u16", exports.Pred.isU16),
|
|
66
|
+
U32: makeRefinement("u32", exports.Pred.isU32),
|
|
67
|
+
U64: makeRefinement("u64", exports.Pred.isU64),
|
|
68
|
+
I8: makeRefinement("i8", exports.Pred.isI8),
|
|
69
|
+
I16: makeRefinement("i16", exports.Pred.isI16),
|
|
70
|
+
I32: makeRefinement("i32", exports.Pred.isI32),
|
|
71
|
+
I64: makeRefinement("i64", exports.Pred.isI64),
|
|
72
|
+
F32: makeRefinement("f32", exports.Pred.isF32),
|
|
73
|
+
F64: makeRefinement("f64", exports.Pred.isF64),
|
|
74
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const backoffNoJitter: (attempt: number, baseMin?: number, capMin?: number) => number;
|
|
2
|
+
export declare const addJitter: (minutes: number, ratio?: number) => number;
|
|
3
|
+
export declare const fullJitter: (attempt: number, baseMin?: number, capMin?: number) => number;
|
|
4
|
+
export declare const decorrelatedJitter: (prevMin: number, baseMin?: number, capMin?: number) => number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorrelatedJitter = exports.fullJitter = exports.addJitter = exports.backoffNoJitter = void 0;
|
|
4
|
+
// backoff "pulito" (senza jitter): base * 2^(n-1), con cap
|
|
5
|
+
const backoffNoJitter = (attempt, baseMin = 15, capMin = 240) => Math.min(capMin, baseMin * Math.pow(2, Math.max(0, attempt - 1)));
|
|
6
|
+
exports.backoffNoJitter = backoffNoJitter;
|
|
7
|
+
// ±10% attorno al valore (equal jitter semplice)
|
|
8
|
+
const addJitter = (minutes, ratio = 0.10) => {
|
|
9
|
+
const min = minutes * (1 - ratio);
|
|
10
|
+
const max = minutes * (1 + ratio);
|
|
11
|
+
return Math.round(min + Math.random() * (max - min));
|
|
12
|
+
};
|
|
13
|
+
exports.addJitter = addJitter;
|
|
14
|
+
// Full jitter: scegli un valore casuale tra 0 e il backoff calcolato
|
|
15
|
+
const fullJitter = (attempt, baseMin = 15, capMin = 240) => {
|
|
16
|
+
const d = (0, exports.backoffNoJitter)(attempt, baseMin, capMin);
|
|
17
|
+
return Math.round(Math.random() * d);
|
|
18
|
+
};
|
|
19
|
+
exports.fullJitter = fullJitter;
|
|
20
|
+
// Decorrelated jitter (richiede il delay precedente)
|
|
21
|
+
const decorrelatedJitter = (prevMin, baseMin = 15, capMin = 240) => {
|
|
22
|
+
const next = Math.min(capMin, Math.max(baseMin, Math.random() * (prevMin * 3)));
|
|
23
|
+
return Math.round(next);
|
|
24
|
+
};
|
|
25
|
+
exports.decorrelatedJitter = decorrelatedJitter;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AnySchema } from "ajv";
|
|
2
|
+
/**
|
|
3
|
+
* Public interface for the jsonTools utility.
|
|
4
|
+
* Import this if you want to type variables or parameters that expose
|
|
5
|
+
* the same API surface as `jsonTools`.
|
|
6
|
+
*/
|
|
7
|
+
export interface JsonTools {
|
|
8
|
+
/**
|
|
9
|
+
* Validate a JSON string against an optional schema.
|
|
10
|
+
* - If `schema` is omitted: only checks JSON validity and returns the parsed value.
|
|
11
|
+
* - If `schema` is provided: validates using Ajv (draft-07 friendly).
|
|
12
|
+
*/
|
|
13
|
+
validate<T = unknown>(jsonStr: string, schema?: AnySchema | string): {
|
|
14
|
+
ok: true;
|
|
15
|
+
data: T;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
errors: string[];
|
|
19
|
+
};
|
|
20
|
+
/** Safely parse a JSON string without throwing. */
|
|
21
|
+
parse<T = unknown>(jsonStr: string): {
|
|
22
|
+
ok: true;
|
|
23
|
+
data: T;
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
/** Safely stringify any value to JSON (handles circular refs and never throws). */
|
|
29
|
+
stringify(value: any, space?: number): string;
|
|
30
|
+
/** Pretty-print a JSON string with a given indentation (returns original if invalid). */
|
|
31
|
+
pretty(jsonStr: string, indent?: number): string;
|
|
32
|
+
/** Minify a JSON string by removing whitespace (returns original if invalid). */
|
|
33
|
+
compact(jsonStr: string): string;
|
|
34
|
+
/** Deep structural equality for JSON-compatible values (key-order insensitive for objects). */
|
|
35
|
+
isEqual(a: unknown, b: unknown): boolean;
|
|
36
|
+
/** Safely access nested properties via dot-path (supports numeric indices). */
|
|
37
|
+
get<T = unknown>(obj: any, path: string): T | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Non-mutating deep merge of two objects (arrays are overwritten).
|
|
40
|
+
* Returns a new object typed as the intersection T & U.
|
|
41
|
+
*/
|
|
42
|
+
merge<T extends object, U extends object>(target: T, source: U): T & U;
|
|
43
|
+
/**
|
|
44
|
+
* Compute a flat diff map of paths to old/new values.
|
|
45
|
+
* Paths use dot notation; "(root)" indicates the root value.
|
|
46
|
+
*/
|
|
47
|
+
diff(a: unknown, b: unknown): Record<string, {
|
|
48
|
+
oldValue: any;
|
|
49
|
+
newValue: any;
|
|
50
|
+
}>;
|
|
51
|
+
/** Summarize a JSON Schema for quick inspection (types, enums, properties). */
|
|
52
|
+
schemaSummary(schema: AnySchema): string;
|
|
53
|
+
/** Infer a minimal JSON Schema from an example value. */
|
|
54
|
+
inferSchema(example: unknown): AnySchema;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A small toolkit for working with JSON strings.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* - The only exported API is this default object `jsonTools`.
|
|
61
|
+
* - All functions are documented with JSDoc so tooltips are shown in IDEs.
|
|
62
|
+
*/
|
|
63
|
+
export declare const jsonTools: JsonTools;
|