@vielzeug/toolkit 1.0.14 → 1.1.3
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/README.md +546 -0
- package/dist/async/attempt.cjs.map +1 -0
- package/dist/async/attempt.js.map +1 -0
- package/dist/async/defer.cjs +2 -0
- package/dist/async/defer.cjs.map +1 -0
- package/dist/async/defer.js +10 -0
- package/dist/async/defer.js.map +1 -0
- package/dist/async/delay.cjs.map +1 -0
- package/dist/async/delay.js.map +1 -0
- package/dist/async/parallel.cjs.map +1 -0
- package/dist/async/parallel.js.map +1 -0
- package/dist/async/pool.cjs +2 -0
- package/dist/async/pool.cjs.map +1 -0
- package/dist/async/pool.js +22 -0
- package/dist/async/pool.js.map +1 -0
- package/dist/async/predict.cjs.map +1 -0
- package/dist/async/predict.js.map +1 -0
- package/dist/async/queue.cjs +2 -0
- package/dist/async/queue.cjs.map +1 -0
- package/dist/async/queue.js +57 -0
- package/dist/async/queue.js.map +1 -0
- package/dist/async/race.cjs +2 -0
- package/dist/async/race.cjs.map +1 -0
- package/dist/async/race.js +8 -0
- package/dist/async/race.js.map +1 -0
- package/dist/async/retry.cjs.map +1 -0
- package/dist/{function → async}/retry.js +4 -4
- package/dist/async/retry.js.map +1 -0
- package/dist/async/sleep.cjs +2 -0
- package/dist/async/sleep.cjs.map +1 -0
- package/dist/{function → async}/sleep.js +1 -1
- package/dist/async/sleep.js.map +1 -0
- package/dist/async/waitFor.cjs +2 -0
- package/dist/async/waitFor.cjs.map +1 -0
- package/dist/async/waitFor.js +37 -0
- package/dist/async/waitFor.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +175 -0
- package/dist/index.js +242 -230
- package/dist/index.js.map +1 -1
- package/dist/logit/dist/logit.cjs +1 -1
- package/dist/logit/dist/logit.cjs.map +1 -1
- package/dist/logit/dist/logit.js +147 -64
- package/dist/logit/dist/logit.js.map +1 -1
- package/dist/object/cache.cjs +2 -0
- package/dist/object/cache.cjs.map +1 -0
- package/dist/object/cache.js +63 -0
- package/dist/object/cache.js.map +1 -0
- package/package.json +1 -1
- package/dist/function/attempt.cjs.map +0 -1
- package/dist/function/attempt.js.map +0 -1
- package/dist/function/delay.cjs.map +0 -1
- package/dist/function/delay.js.map +0 -1
- package/dist/function/parallel.cjs.map +0 -1
- package/dist/function/parallel.js.map +0 -1
- package/dist/function/predict.cjs.map +0 -1
- package/dist/function/predict.js.map +0 -1
- package/dist/function/retry.cjs.map +0 -1
- package/dist/function/retry.js.map +0 -1
- package/dist/function/sleep.cjs +0 -2
- package/dist/function/sleep.cjs.map +0 -1
- package/dist/function/sleep.js.map +0 -1
- /package/dist/{function → async}/attempt.cjs +0 -0
- /package/dist/{function → async}/attempt.js +0 -0
- /package/dist/{function → async}/delay.cjs +0 -0
- /package/dist/{function → async}/delay.js +0 -0
- /package/dist/{function → async}/parallel.cjs +0 -0
- /package/dist/{function → async}/parallel.js +0 -0
- /package/dist/{function → async}/predict.cjs +0 -0
- /package/dist/{function → async}/predict.js +0 -0
- /package/dist/{function → async}/retry.cjs +0 -0
package/dist/logit/dist/logit.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const
|
|
1
|
+
const $ = {}, h = {
|
|
2
2
|
debug: "log",
|
|
3
3
|
success: "log"
|
|
4
|
-
},
|
|
4
|
+
}, w = () => typeof window < "u" && $?.NODE_ENV ? !1 : typeof process < "u" && process.env?.NODE_ENV ? process.env.NODE_ENV === "production" : !1, d = w(), x = typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches, b = {
|
|
5
5
|
debug: { bg: "#616161", border: "#424242", color: "#fff", icon: "☕", symbol: "🅳" },
|
|
6
6
|
error: { bg: "#d32f2f", border: "#c62828", color: "#fff", icon: "✘", symbol: "🅴" },
|
|
7
7
|
group: { bg: "#546e7a", border: "#455a64", color: "#fff", icon: "⚭", symbol: "🅶" },
|
|
8
8
|
info: { bg: "#1976d2", border: "#1565c0", color: "#fff", icon: "ℹ", symbol: "🅸" },
|
|
9
|
-
ns:
|
|
9
|
+
ns: x ? { bg: "#fafafa", border: "#c7c7c7", color: "#000" } : { bg: "#424242", border: "#212121", color: "#fff" },
|
|
10
10
|
success: { bg: "#689f38", border: "#558b2f", color: "#fff", icon: "✔", symbol: "🆂" },
|
|
11
11
|
time: { bg: "#0097a7", border: "#00838f", color: "#fff", icon: "⏲", symbol: "🆃" },
|
|
12
12
|
trace: { bg: "#d81b60", border: "#c2185b", color: "#fff", icon: "⛢", symbol: "🆃" },
|
|
13
13
|
warn: { bg: "#ffb300", border: "#ffa000", color: "#fff", icon: "⚠", symbol: "🆆" }
|
|
14
|
-
},
|
|
14
|
+
}, m = {
|
|
15
15
|
debug: 0,
|
|
16
16
|
trace: 1,
|
|
17
17
|
time: 2,
|
|
@@ -21,76 +21,91 @@ const w = {}, v = {
|
|
|
21
21
|
warn: 6,
|
|
22
22
|
error: 7,
|
|
23
23
|
off: 8
|
|
24
|
-
},
|
|
24
|
+
}, o = {
|
|
25
25
|
environment: !0,
|
|
26
26
|
logLevel: "debug",
|
|
27
27
|
namespace: "",
|
|
28
28
|
remote: { handler: void 0, logLevel: "off" },
|
|
29
29
|
timestamp: !0,
|
|
30
30
|
variant: "symbol"
|
|
31
|
-
}, i = (e) =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
}, i = (e) => m[o.logLevel] <= m[e], p = () => (/* @__PURE__ */ new Date()).toISOString().slice(11, 23), g = () => d ? "🄿" : "🄳", y = (e, r) => {
|
|
32
|
+
o.remote.handler && m[o.remote.logLevel] <= m[e] && Promise.resolve().then(() => {
|
|
33
|
+
o.remote.handler?.(e, {
|
|
34
|
+
args: r,
|
|
35
|
+
environment: d ? "production" : "development",
|
|
36
|
+
namespace: o.namespace || void 0,
|
|
37
|
+
timestamp: o.timestamp ? p() : void 0
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}, f = (e) => h[e] || e, L = "border: 1px solid", E = "border-radius: 4px", u = "border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter; padding: 0 4px;", l = (e, r = "") => {
|
|
41
|
+
const { bg: t, color: s, border: n } = b[e], a = `${L} ${n}; ${E}`;
|
|
42
|
+
switch (o.variant) {
|
|
36
43
|
case "symbol":
|
|
37
|
-
return
|
|
44
|
+
return `color: ${t}; ${a}; padding: 1px 1px 0${r}`;
|
|
38
45
|
case "icon":
|
|
39
|
-
return
|
|
46
|
+
return `color: ${t}; ${a}; padding: 0 3px${r}`;
|
|
40
47
|
default:
|
|
41
|
-
return `background: ${t}; color: ${
|
|
48
|
+
return `background: ${t}; color: ${s}; ${a}; font-weight: bold; padding: 0 3px${r}`;
|
|
42
49
|
}
|
|
43
|
-
},
|
|
44
|
-
const
|
|
45
|
-
return t === "text" || !
|
|
50
|
+
}, v = (e) => {
|
|
51
|
+
const r = b[e], { variant: t } = o;
|
|
52
|
+
return t === "text" || !r || !r[t] ? e.toUpperCase() : r[t];
|
|
46
53
|
};
|
|
47
54
|
function D(e) {
|
|
48
|
-
const { namespace:
|
|
49
|
-
let n = `%c${
|
|
50
|
-
const
|
|
51
|
-
return
|
|
55
|
+
const { namespace: r, timestamp: t, environment: s } = o;
|
|
56
|
+
let n = `%c${v(e)}%c`;
|
|
57
|
+
const a = [l(e), ""];
|
|
58
|
+
return r && (n += ` %c${r}%c`, a.push(l("ns", `; ${u}`), "")), s && (n += ` %c${g()}%c`, a.push("color: darkgray", "")), t && (n += ` %c${p()}%c`, a.push("color: gray", "")), { format: n, parts: a };
|
|
52
59
|
}
|
|
53
|
-
const
|
|
60
|
+
const c = (e, ...r) => {
|
|
54
61
|
if (typeof window > "u") {
|
|
55
|
-
const
|
|
56
|
-
|
|
62
|
+
const a = console[f(e)];
|
|
63
|
+
a(`${v(e)} | ${g()} |`, ...r);
|
|
57
64
|
return;
|
|
58
65
|
}
|
|
59
66
|
if (!i(e)) return;
|
|
60
|
-
const { format: t, parts:
|
|
61
|
-
n(t, ...
|
|
62
|
-
},
|
|
63
|
-
const
|
|
64
|
-
return
|
|
65
|
-
},
|
|
67
|
+
const { format: t, parts: s } = D(e), n = console[f(e)];
|
|
68
|
+
n(t, ...s, ...r), y(e, r);
|
|
69
|
+
}, N = (e) => {
|
|
70
|
+
const r = Math.floor(Date.now() - e);
|
|
71
|
+
return r ? `${r}ms` : "";
|
|
72
|
+
}, O = {
|
|
66
73
|
/**
|
|
67
74
|
* Asserts a condition and logs an error if it's false.
|
|
68
75
|
*/
|
|
69
|
-
assert: (e,
|
|
70
|
-
debug: (...e) =>
|
|
71
|
-
error: (...e) =>
|
|
76
|
+
assert: (e, r, t) => console.assert(e, r, t),
|
|
77
|
+
debug: (...e) => c("debug", ...e),
|
|
78
|
+
error: (...e) => c("error", ...e),
|
|
79
|
+
/**
|
|
80
|
+
* Gets whether the environment indicator is shown.
|
|
81
|
+
*/
|
|
82
|
+
getEnvironment: () => o.environment,
|
|
72
83
|
/**
|
|
73
84
|
* Gets the current log level.
|
|
74
85
|
*/
|
|
75
|
-
getLevel: () =>
|
|
86
|
+
getLevel: () => o.logLevel,
|
|
76
87
|
/**
|
|
77
88
|
* Gets the current namespace prefix.
|
|
78
89
|
*/
|
|
79
|
-
getPrefix: () =>
|
|
90
|
+
getPrefix: () => o.namespace,
|
|
80
91
|
/**
|
|
81
92
|
* Gets whether timestamps are shown.
|
|
82
93
|
*/
|
|
83
|
-
getTimestamp: () =>
|
|
94
|
+
getTimestamp: () => o.timestamp,
|
|
95
|
+
/**
|
|
96
|
+
* Gets the current display variant.
|
|
97
|
+
*/
|
|
98
|
+
getVariant: () => o.variant,
|
|
84
99
|
/**
|
|
85
100
|
* Creates a collapsed group in the console.
|
|
86
101
|
*/
|
|
87
|
-
groupCollapsed: (e,
|
|
102
|
+
groupCollapsed: (e, r = "GROUP", t = Date.now()) => {
|
|
88
103
|
if (!i("success")) return;
|
|
89
|
-
const
|
|
104
|
+
const s = N(t), n = g(), a = o.timestamp ? p() : "";
|
|
90
105
|
console.groupCollapsed(
|
|
91
|
-
`%c${
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
`%c${r}%c${o.namespace}%c${n}%c${a}%c${s}%c${e}`,
|
|
107
|
+
l("group", "; margin-right: 6px; padding: 1px 3px 0"),
|
|
108
|
+
l("ns", `; ${u}; margin-right: 6px`),
|
|
94
109
|
"color: darkgray; margin-right: 6px",
|
|
95
110
|
"color: gray; font-weight: lighter; margin-right: 6px",
|
|
96
111
|
"color: gray; font-weight: lighter; margin-right: 6px",
|
|
@@ -103,56 +118,92 @@ const a = (e, ...o) => {
|
|
|
103
118
|
groupEnd: () => {
|
|
104
119
|
i("success") && console.groupEnd();
|
|
105
120
|
},
|
|
106
|
-
info: (...e) =>
|
|
121
|
+
info: (...e) => c("info", ...e),
|
|
107
122
|
/**
|
|
108
|
-
*
|
|
123
|
+
* Creates a scoped logger with a namespaced prefix.
|
|
124
|
+
* Does not mutate global state - returns an isolated logger instance.
|
|
125
|
+
*
|
|
126
|
+
* @param namespace - The namespace to prepend to all log messages
|
|
127
|
+
* @returns A scoped logger with all logging methods
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const apiLogger = Logit.scope('api');
|
|
132
|
+
* apiLogger.info('Request received'); // [API] Request received
|
|
133
|
+
*
|
|
134
|
+
* const dbLogger = Logit.scope('database');
|
|
135
|
+
* dbLogger.error('Connection failed'); // [DATABASE] Connection failed
|
|
136
|
+
* ```
|
|
109
137
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
scope: (e) => {
|
|
139
|
+
const r = o.namespace, t = r ? `${r}.${e}` : e;
|
|
140
|
+
return {
|
|
141
|
+
debug: (...s) => {
|
|
142
|
+
const n = o.namespace;
|
|
143
|
+
o.namespace = t, c("debug", ...s), o.namespace = n;
|
|
144
|
+
},
|
|
145
|
+
error: (...s) => {
|
|
146
|
+
const n = o.namespace;
|
|
147
|
+
o.namespace = t, c("error", ...s), o.namespace = n;
|
|
148
|
+
},
|
|
149
|
+
info: (...s) => {
|
|
150
|
+
const n = o.namespace;
|
|
151
|
+
o.namespace = t, c("info", ...s), o.namespace = n;
|
|
152
|
+
},
|
|
153
|
+
success: (...s) => {
|
|
154
|
+
const n = o.namespace;
|
|
155
|
+
o.namespace = t, c("success", ...s), o.namespace = n;
|
|
156
|
+
},
|
|
157
|
+
trace: (...s) => {
|
|
158
|
+
const n = o.namespace;
|
|
159
|
+
o.namespace = t, c("trace", ...s), o.namespace = n;
|
|
160
|
+
},
|
|
161
|
+
warn: (...s) => {
|
|
162
|
+
const n = o.namespace;
|
|
163
|
+
o.namespace = t, c("warn", ...s), o.namespace = n;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
112
166
|
},
|
|
113
167
|
/**
|
|
114
168
|
* Sets the minimum log level to display.
|
|
115
169
|
*/
|
|
116
170
|
setLogLevel: (e) => {
|
|
117
|
-
|
|
171
|
+
o.logLevel = e;
|
|
118
172
|
},
|
|
119
173
|
/**
|
|
120
174
|
* Sets the namespace prefix for all logs.
|
|
121
175
|
*/
|
|
122
176
|
setPrefix: (e) => {
|
|
123
|
-
|
|
177
|
+
o.namespace = e;
|
|
124
178
|
},
|
|
125
179
|
/**
|
|
126
180
|
* Configures remote logging options.
|
|
127
181
|
*/
|
|
128
182
|
setRemote: (e) => {
|
|
129
|
-
|
|
183
|
+
o.remote = e;
|
|
130
184
|
},
|
|
131
185
|
/**
|
|
132
186
|
* Sets the log level for remote logging.
|
|
133
187
|
*/
|
|
134
188
|
setRemoteLogLevel: (e) => {
|
|
135
|
-
|
|
136
|
-
},
|
|
137
|
-
/**
|
|
138
|
-
* Sets the display variant (text, icon, or symbol).
|
|
139
|
-
*/
|
|
140
|
-
setVariant: (e) => {
|
|
141
|
-
r.variant = e;
|
|
189
|
+
o.remote.logLevel = e;
|
|
142
190
|
},
|
|
143
191
|
/**
|
|
144
|
-
*
|
|
192
|
+
* Configures Logit with custom options.
|
|
193
|
+
*
|
|
194
|
+
* Note: The remote option will be merged with existing remote config,
|
|
195
|
+
* not replaced entirely. To clear a remote handler, set remote.handler to undefined.
|
|
145
196
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
197
|
+
setup: (e) => {
|
|
198
|
+
e.remote && (o.remote = { ...o.remote, ...e.remote }, delete e.remote), Object.assign(o, e);
|
|
148
199
|
},
|
|
149
200
|
/**
|
|
150
|
-
*
|
|
201
|
+
* Sets the display variant (text, icon, or symbol).
|
|
151
202
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
203
|
+
setVariant: (e) => {
|
|
204
|
+
o.variant = e;
|
|
154
205
|
},
|
|
155
|
-
success: (...e) =>
|
|
206
|
+
success: (...e) => c("success", ...e),
|
|
156
207
|
/**
|
|
157
208
|
* Displays data in a table format.
|
|
158
209
|
*/
|
|
@@ -171,10 +222,42 @@ const a = (e, ...o) => {
|
|
|
171
222
|
timeEnd: (e) => {
|
|
172
223
|
i("time") && console.timeEnd(e);
|
|
173
224
|
},
|
|
174
|
-
|
|
175
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Toggles or sets the environment indicator visibility.
|
|
227
|
+
* When called without arguments, toggles the current state.
|
|
228
|
+
*
|
|
229
|
+
* @param value - Optional boolean to explicitly set the state
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* Logit.toggleEnvironment(); // Toggles current state
|
|
234
|
+
* Logit.toggleEnvironment(true); // Shows environment indicator
|
|
235
|
+
* Logit.toggleEnvironment(false); // Hides environment indicator
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
toggleEnvironment: (e) => {
|
|
239
|
+
o.environment = e ?? !o.environment;
|
|
240
|
+
},
|
|
241
|
+
/**
|
|
242
|
+
* Toggles or sets timestamp visibility in logs.
|
|
243
|
+
* When called without arguments, toggles the current state.
|
|
244
|
+
*
|
|
245
|
+
* @param value - Optional boolean to explicitly set the state
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* Logit.toggleTimestamp(); // Toggles current state
|
|
250
|
+
* Logit.toggleTimestamp(true); // Shows timestamps
|
|
251
|
+
* Logit.toggleTimestamp(false); // Hides timestamps
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
toggleTimestamp: (e) => {
|
|
255
|
+
o.timestamp = e ?? !o.timestamp;
|
|
256
|
+
},
|
|
257
|
+
trace: (...e) => c("trace", ...e),
|
|
258
|
+
warn: (...e) => c("warn", ...e)
|
|
176
259
|
};
|
|
177
260
|
export {
|
|
178
|
-
|
|
261
|
+
O as Logit
|
|
179
262
|
};
|
|
180
263
|
//# sourceMappingURL=logit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logit.js","sources":["../../../../logit/dist/logit.js"],"sourcesContent":["const $ = {};\nconst v = {\n debug: \"log\",\n success: \"log\"\n}, w = () => typeof window < \"u\" && $?.NODE_ENV ? !1 : typeof process < \"u\" && process.env?.NODE_ENV ? process.env.NODE_ENV === \"production\" : !1, _ = w(), L = typeof window < \"u\" && window.matchMedia?.(\"(prefers-color-scheme: dark)\").matches, b = {\n debug: { bg: \"#616161\", border: \"#424242\", color: \"#fff\", icon: \"☕\", symbol: \"🅳\" },\n error: { bg: \"#d32f2f\", border: \"#c62828\", color: \"#fff\", icon: \"✘\", symbol: \"🅴\" },\n group: { bg: \"#546e7a\", border: \"#455a64\", color: \"#fff\", icon: \"⚭\", symbol: \"🅶\" },\n info: { bg: \"#1976d2\", border: \"#1565c0\", color: \"#fff\", icon: \"ℹ\", symbol: \"🅸\" },\n ns: L ? { bg: \"#fafafa\", border: \"#c7c7c7\", color: \"#000\" } : { bg: \"#424242\", border: \"#212121\", color: \"#fff\" },\n success: { bg: \"#689f38\", border: \"#558b2f\", color: \"#fff\", icon: \"✔\", symbol: \"🆂\" },\n time: { bg: \"#0097a7\", border: \"#00838f\", color: \"#fff\", icon: \"⏲\", symbol: \"🆃\" },\n trace: { bg: \"#d81b60\", border: \"#c2185b\", color: \"#fff\", icon: \"⛢\", symbol: \"🆃\" },\n warn: { bg: \"#ffb300\", border: \"#ffa000\", color: \"#fff\", icon: \"⚠\", symbol: \"🆆\" }\n}, l = {\n debug: 0,\n trace: 1,\n time: 2,\n table: 3,\n info: 4,\n success: 5,\n warn: 6,\n error: 7,\n off: 8\n}, r = {\n environment: !0,\n logLevel: \"debug\",\n namespace: \"\",\n remote: { handler: void 0, logLevel: \"off\" },\n timestamp: !0,\n variant: \"symbol\"\n}, a = (e) => l[r.logLevel] <= l[e], u = () => (/* @__PURE__ */ new Date()).toISOString().slice(11, 23), d = () => _ ? \"🄿\" : \"🄳\", x = (e, o) => {\n r.remote.handler && l[r.remote.logLevel] <= l[e] && r.remote.handler(e, ...o);\n}, g = (e) => v[e] || e, m = \"border: 1px solid\", p = \"border-radius: 4px\", h = \"border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter\", f = (e, o = \"\") => {\n const { bg: t, color: c, border: n } = b[e], s = `color: ${t}; ${m} ${n}; ${p}`;\n switch (r.variant) {\n case \"symbol\":\n return `${s}; padding: 1px 1px 0${o}`;\n case \"icon\":\n return `${s}; padding: 0 3px${o}`;\n default:\n return `background: ${t}; color: ${c}; ${m} ${n}; ${p}; font-weight: bold; padding: 0 3px${o}`;\n }\n}, E = (e) => {\n const o = b[e], { variant: t } = r;\n return t === \"text\" || !o[t] ? e.toUpperCase() : o[t];\n};\nfunction D(e) {\n const { namespace: o, timestamp: t, environment: c } = r;\n let n = `%c${E(e)}%c`;\n const s = [f(e), \"\"];\n return o && (n += ` %c${o}%c`, s.push(f(\"ns\", `; ${h}`), \"\")), c && (n += ` %c${d()}%c`, s.push(\"color: darkgray\", \"\")), t && (n += ` %c${u()}%c`, s.push(\"color: gray\", \"\")), { format: n, parts: s };\n}\nconst i = (e, ...o) => {\n if (typeof window > \"u\") {\n const s = console[g(e)];\n s(`${E(e)} | ${d()} |`, ...o);\n return;\n }\n if (!a(e)) return;\n const { format: t, parts: c } = D(e), n = console[g(e)];\n n(t, ...c, ...o), x(e, o);\n}, O = (e) => {\n const o = Math.floor(Date.now() - e);\n return o ? `${o}ms` : \"\";\n}, y = {\n /**\n * Asserts a condition and logs an error if it's false.\n */\n assert: (e, o, t) => console.assert(e, o, t),\n debug: (...e) => i(\"debug\", ...e),\n error: (...e) => i(\"error\", ...e),\n /**\n * Gets the current log level.\n */\n getLevel: () => r.logLevel,\n /**\n * Gets the current namespace prefix.\n */\n getPrefix: () => r.namespace,\n /**\n * Gets whether timestamps are shown.\n */\n getTimestamp: () => r.timestamp,\n /**\n * Creates a collapsed group in the console.\n */\n groupCollapsed: (e, o = \"GROUP\", t = Date.now()) => {\n if (!a(\"success\")) return;\n const c = O(t), n = d(), s = r.timestamp ? u() : \"\";\n console.groupCollapsed(\n `%c${o}%c${r.namespace}%c${n}%c${s}%c${c}%c${e}`,\n f(\"group\", \"; margin-right: 6px; padding: 1px 3px 0\"),\n f(\"ns\", `; ${h}; margin-right: 6px`),\n \"color: darkgray; margin-right: 6px\",\n \"color: gray; font-weight: lighter; margin-right: 6px\",\n \"color: gray; font-weight: lighter; margin-right: 6px\",\n \"color: inherit; font-weight: lighter\"\n );\n },\n /**\n * Ends the current console group.\n */\n groupEnd: () => {\n a(\"success\") && console.groupEnd();\n },\n info: (...e) => i(\"info\", ...e),\n /**\n * Initializes Logit with custom options.\n */\n initialise: (e) => {\n Object.assign(r, e);\n },\n /**\n * Sets the minimum log level to display.\n */\n setLogLevel: (e) => {\n r.logLevel = e;\n },\n /**\n * Sets the namespace prefix for all logs.\n */\n setPrefix: (e) => {\n r.namespace = e;\n },\n /**\n * Configures remote logging options.\n */\n setRemote: (e) => {\n r.remote = e;\n },\n /**\n * Sets the log level for remote logging.\n */\n setRemoteLogLevel: (e) => {\n r.remote.logLevel = e;\n },\n /**\n * Sets the display variant (text, icon, or symbol).\n */\n setVariant: (e) => {\n r.variant = e;\n },\n /**\n * Shows or hides the environment indicator.\n */\n showEnvironment: (e) => {\n r.environment = e;\n },\n /**\n * Shows or hides timestamps in logs.\n */\n showTimestamp: (e) => {\n r.timestamp = e;\n },\n success: (...e) => i(\"success\", ...e),\n /**\n * Displays data in a table format.\n */\n table: (...e) => {\n a(\"table\") && console.table(...e);\n },\n /**\n * Starts a timer with the given label.\n */\n time: (e) => {\n a(\"time\") && console.time(e);\n },\n /**\n * Ends a timer with the given label.\n */\n timeEnd: (e) => {\n a(\"time\") && console.timeEnd(e);\n },\n trace: (...e) => i(\"trace\", ...e),\n warn: (...e) => i(\"warn\", ...e)\n};\nexport {\n y as Logit\n};\n//# sourceMappingURL=logit.js.map\n"],"names":["$","w","_","a","d","x","g","m","h","E","i","y"],"mappings":"AAAA,MAAMA,IAAI,CAAA,GACJ,IAAI;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AACX,GAAGC,IAAI,MAAM,OAAO,SAAS,OAAOD,GAAG,WAAW,KAAK,OAAO,UAAU,OAAO,QAAQ,KAAK,WAAW,QAAQ,IAAI,aAAa,eAAe,IAAIE,IAAID,EAAC,GAAI,IAAI,OAAO,SAAS,OAAO,OAAO,aAAa,8BAA8B,EAAE,SAAS,IAAI;AAAA,EACtP,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAI;AAAA,EACjF,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAI;AAAA,EACjF,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAI;AAAA,EACjF,MAAM,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAI;AAAA,EAChF,IAAI,IAAI,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,OAAM,IAAK,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,OAAM;AAAA,EAC/G,SAAS,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,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AAE,WAAW;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAIA,WAAW,CAAC,MAAM;AAChB,MAAE,YAAY;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAIA,WAAW,CAAC,MAAM;AAChB,MAAE,SAAS;AAAA,EACb;AAAA;AAAA;AAAA;AAAA,EAIA,mBAAmB,CAAC,MAAM;AACxB,MAAE,OAAO,WAAW;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAIA,YAAY,CAAC,MAAM;AACjB,MAAE,UAAU;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAIA,iBAAiB,CAAC,MAAM;AACtB,MAAE,cAAc;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAIA,eAAe,CAAC,MAAM;AACpB,MAAE,YAAY;AAAA,EAChB;AAAA,EACA,SAAS,IAAI,MAAMA,EAAE,WAAW,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA,EAIpC,OAAO,IAAI,MAAM;AACf,IAAAP,EAAE,OAAO,KAAK,QAAQ,MAAM,GAAG,CAAC;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAIA,MAAM,CAAC,MAAM;AACX,IAAAA,EAAE,MAAM,KAAK,QAAQ,KAAK,CAAC;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAIA,SAAS,CAAC,MAAM;AACd,IAAAA,EAAE,MAAM,KAAK,QAAQ,QAAQ,CAAC;AAAA,EAChC;AAAA,EACA,OAAO,IAAI,MAAMO,EAAE,SAAS,GAAG,CAAC;AAAA,EAChC,MAAM,IAAI,MAAMA,EAAE,QAAQ,GAAG,CAAC;AAChC;"}
|
|
1
|
+
{"version":3,"file":"logit.js","sources":["../../../../logit/dist/logit.js"],"sourcesContent":["const h = {};\nconst E = {\n debug: \"log\",\n success: \"log\"\n}, $ = () => typeof window < \"u\" && h?.NODE_ENV ? !1 : typeof process < \"u\" && process.env?.NODE_ENV ? process.env.NODE_ENV === \"production\" : !1, g = $(), w = typeof window < \"u\" && window.matchMedia?.(\"(prefers-color-scheme: dark)\").matches, u = {\n debug: { bg: \"#616161\", border: \"#424242\", color: \"#fff\", icon: \"☕\", symbol: \"🅳\" },\n error: { bg: \"#d32f2f\", border: \"#c62828\", color: \"#fff\", icon: \"✘\", symbol: \"🅴\" },\n group: { bg: \"#546e7a\", border: \"#455a64\", color: \"#fff\", icon: \"⚭\", symbol: \"🅶\" },\n info: { bg: \"#1976d2\", border: \"#1565c0\", color: \"#fff\", icon: \"ℹ\", symbol: \"🅸\" },\n ns: w ? { bg: \"#fafafa\", border: \"#c7c7c7\", color: \"#000\" } : { bg: \"#424242\", border: \"#212121\", color: \"#fff\" },\n success: { bg: \"#689f38\", border: \"#558b2f\", color: \"#fff\", icon: \"✔\", symbol: \"🆂\" },\n time: { bg: \"#0097a7\", border: \"#00838f\", color: \"#fff\", icon: \"⏲\", symbol: \"🆃\" },\n trace: { bg: \"#d81b60\", border: \"#c2185b\", color: \"#fff\", icon: \"⛢\", symbol: \"🆃\" },\n warn: { bg: \"#ffb300\", border: \"#ffa000\", color: \"#fff\", icon: \"⚠\", symbol: \"🆆\" }\n}, m = {\n debug: 0,\n trace: 1,\n time: 2,\n table: 3,\n info: 4,\n success: 5,\n warn: 6,\n error: 7,\n off: 8\n}, o = {\n environment: !0,\n logLevel: \"debug\",\n namespace: \"\",\n remote: { handler: void 0, logLevel: \"off\" },\n timestamp: !0,\n variant: \"symbol\"\n}, i = (e) => m[o.logLevel] <= m[e], p = () => (/* @__PURE__ */ new Date()).toISOString().slice(11, 23), d = () => g ? \"🄿\" : \"🄳\", _ = (e, n) => {\n o.remote.handler && m[o.remote.logLevel] <= m[e] && Promise.resolve().then(() => {\n o.remote.handler?.(e, {\n args: n,\n environment: g ? \"production\" : \"development\",\n namespace: o.namespace || void 0,\n timestamp: o.timestamp ? p() : void 0\n });\n });\n}, f = (e) => E[e] || e, L = \"border: 1px solid\", x = \"border-radius: 4px\", b = \"border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter; padding: 0 4px;\", l = (e, n = \"\") => {\n const { bg: r, color: s, border: t } = u[e], c = `${L} ${t}; ${x}`;\n switch (o.variant) {\n case \"symbol\":\n return `color: ${r}; ${c}; padding: 1px 1px 0${n}`;\n case \"icon\":\n return `color: ${r}; ${c}; padding: 0 3px${n}`;\n default:\n return `background: ${r}; color: ${s}; ${c}; font-weight: bold; padding: 0 3px${n}`;\n }\n}, v = (e) => {\n const n = u[e], { variant: r } = o;\n return r === \"text\" || !n || !n[r] ? e.toUpperCase() : n[r];\n};\nfunction D(e) {\n const { namespace: n, timestamp: r, environment: s } = o;\n let t = `%c${v(e)}%c`;\n const c = [l(e), \"\"];\n return n && (t += ` %c${n}%c`, c.push(l(\"ns\", `; ${b}`), \"\")), s && (t += ` %c${d()}%c`, c.push(\"color: darkgray\", \"\")), r && (t += ` %c${p()}%c`, c.push(\"color: gray\", \"\")), { format: t, parts: c };\n}\nconst a = (e, ...n) => {\n if (typeof window > \"u\") {\n const c = console[f(e)];\n c(`${v(e)} | ${d()} |`, ...n);\n return;\n }\n if (!i(e)) return;\n const { format: r, parts: s } = D(e), t = console[f(e)];\n t(r, ...s, ...n), _(e, n);\n}, N = (e) => {\n const n = Math.floor(Date.now() - e);\n return n ? `${n}ms` : \"\";\n}, O = {\n /**\n * Asserts a condition and logs an error if it's false.\n */\n assert: (e, n, r) => console.assert(e, n, r),\n debug: (...e) => a(\"debug\", ...e),\n error: (...e) => a(\"error\", ...e),\n /**\n * Gets whether the environment indicator is shown.\n */\n getEnvironment: () => o.environment,\n /**\n * Gets the current log level.\n */\n getLevel: () => o.logLevel,\n /**\n * Gets the current namespace prefix.\n */\n getPrefix: () => o.namespace,\n /**\n * Gets whether timestamps are shown.\n */\n getTimestamp: () => o.timestamp,\n /**\n * Gets the current display variant.\n */\n getVariant: () => o.variant,\n /**\n * Creates a collapsed group in the console.\n */\n groupCollapsed: (e, n = \"GROUP\", r = Date.now()) => {\n if (!i(\"success\")) return;\n const s = N(r), t = d(), c = o.timestamp ? p() : \"\";\n console.groupCollapsed(\n `%c${n}%c${o.namespace}%c${t}%c${c}%c${s}%c${e}`,\n l(\"group\", \"; margin-right: 6px; padding: 1px 3px 0\"),\n l(\"ns\", `; ${b}; margin-right: 6px`),\n \"color: darkgray; margin-right: 6px\",\n \"color: gray; font-weight: lighter; margin-right: 6px\",\n \"color: gray; font-weight: lighter; margin-right: 6px\",\n \"color: inherit; font-weight: lighter\"\n );\n },\n /**\n * Ends the current console group.\n */\n groupEnd: () => {\n i(\"success\") && console.groupEnd();\n },\n info: (...e) => a(\"info\", ...e),\n /**\n * Creates a scoped logger with a namespaced prefix.\n * Does not mutate global state - returns an isolated logger instance.\n *\n * @param namespace - The namespace to prepend to all log messages\n * @returns A scoped logger with all logging methods\n *\n * @example\n * ```ts\n * const apiLogger = Logit.scope('api');\n * apiLogger.info('Request received'); // [API] Request received\n *\n * const dbLogger = Logit.scope('database');\n * dbLogger.error('Connection failed'); // [DATABASE] Connection failed\n * ```\n */\n scope: (e) => {\n const n = o.namespace, r = n ? `${n}.${e}` : e;\n return {\n debug: (...s) => {\n const t = o.namespace;\n o.namespace = r, a(\"debug\", ...s), o.namespace = t;\n },\n error: (...s) => {\n const t = o.namespace;\n o.namespace = r, a(\"error\", ...s), o.namespace = t;\n },\n info: (...s) => {\n const t = o.namespace;\n o.namespace = r, a(\"info\", ...s), o.namespace = t;\n },\n success: (...s) => {\n const t = o.namespace;\n o.namespace = r, a(\"success\", ...s), o.namespace = t;\n },\n trace: (...s) => {\n const t = o.namespace;\n o.namespace = r, a(\"trace\", ...s), o.namespace = t;\n },\n warn: (...s) => {\n const t = o.namespace;\n o.namespace = r, a(\"warn\", ...s), o.namespace = t;\n }\n };\n },\n /**\n * Sets the minimum log level to display.\n */\n setLogLevel: (e) => {\n o.logLevel = e;\n },\n /**\n * Sets the namespace prefix for all logs.\n */\n setPrefix: (e) => {\n o.namespace = e;\n },\n /**\n * Configures remote logging options.\n */\n setRemote: (e) => {\n o.remote = e;\n },\n /**\n * Sets the log level for remote logging.\n */\n setRemoteLogLevel: (e) => {\n o.remote.logLevel = e;\n },\n /**\n * Configures Logit with custom options.\n *\n * Note: The remote option will be merged with existing remote config,\n * not replaced entirely. To clear a remote handler, set remote.handler to undefined.\n */\n setup: (e) => {\n e.remote && (o.remote = { ...o.remote, ...e.remote }, delete e.remote), Object.assign(o, e);\n },\n /**\n * Sets the display variant (text, icon, or symbol).\n */\n setVariant: (e) => {\n o.variant = e;\n },\n success: (...e) => a(\"success\", ...e),\n /**\n * Displays data in a table format.\n */\n table: (...e) => {\n i(\"table\") && console.table(...e);\n },\n /**\n * Starts a timer with the given label.\n */\n time: (e) => {\n i(\"time\") && console.time(e);\n },\n /**\n * Ends a timer with the given label.\n */\n timeEnd: (e) => {\n i(\"time\") && console.timeEnd(e);\n },\n /**\n * Toggles or sets the environment indicator visibility.\n * When called without arguments, toggles the current state.\n *\n * @param value - Optional boolean to explicitly set the state\n *\n * @example\n * ```ts\n * Logit.toggleEnvironment(); // Toggles current state\n * Logit.toggleEnvironment(true); // Shows environment indicator\n * Logit.toggleEnvironment(false); // Hides environment indicator\n * ```\n */\n toggleEnvironment: (e) => {\n o.environment = e ?? !o.environment;\n },\n /**\n * Toggles or sets timestamp visibility in logs.\n * When called without arguments, toggles the current state.\n *\n * @param value - Optional boolean to explicitly set the state\n *\n * @example\n * ```ts\n * Logit.toggleTimestamp(); // Toggles current state\n * Logit.toggleTimestamp(true); // Shows timestamps\n * Logit.toggleTimestamp(false); // Hides timestamps\n * ```\n */\n toggleTimestamp: (e) => {\n o.timestamp = e ?? !o.timestamp;\n },\n trace: (...e) => a(\"trace\", ...e),\n warn: (...e) => a(\"warn\", ...e)\n};\nexport {\n O as Logit\n};\n//# sourceMappingURL=logit.js.map\n"],"names":["h","E","$","g","w","u","d","_","n","x","b","r","t","c","a"],"mappings":"AAAA,MAAMA,IAAI,CAAA,GACJC,IAAI;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AACX,GAAGC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O,OAAO,GAAG,CAAC;AAAA,EAC5F;AAAA;AAAA;AAAA;AAAA,EAIA,YAAY,CAAC,MAAM;AACjB,MAAE,UAAU;AAAA,EACd;AAAA,EACA,SAAS,IAAI,MAAME,EAAE,WAAW,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA,EAIpC,OAAO,IAAI,MAAM;AACf,MAAE,OAAO,KAAK,QAAQ,MAAM,GAAG,CAAC;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAIA,MAAM,CAAC,MAAM;AACX,MAAE,MAAM,KAAK,QAAQ,KAAK,CAAC;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAIA,SAAS,CAAC,MAAM;AACd,MAAE,MAAM,KAAK,QAAQ,QAAQ,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,mBAAmB,CAAC,MAAM;AACxB,MAAE,cAAc,KAAK,CAAC,EAAE;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,iBAAiB,CAAC,MAAM;AACtB,MAAE,YAAY,KAAK,CAAC,EAAE;AAAA,EACxB;AAAA,EACA,OAAO,IAAI,MAAMA,EAAE,SAAS,GAAG,CAAC;AAAA,EAChC,MAAM,IAAI,MAAMA,EAAE,QAAQ,GAAG,CAAC;AAChC;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function T(){const r=new Map,o=new Map,n=new Map,c=e=>JSON.stringify(e);function i(e){return r.get(c(e))}function u(e,t){r.set(c(e),t)}function l(e){const t=c(e);return a(t),n.delete(t),r.delete(t)}function f(){o.forEach(e=>{clearTimeout(e)}),r.clear(),o.clear(),n.clear()}function d(){return r.size}function g(e,t){const s=c(e);a(s),o.set(s,setTimeout(()=>{r.delete(s),o.delete(s),n.delete(s)},t))}function h(e,t){n.set(c(e),{lastUsedAt:Date.now(),...t})}function m(e){return n.get(c(e))}function M(e){return n.get(e)}function y(){return Array.from(n.keys())}function a(e){const t=o.get(e);t&&(clearTimeout(t),o.delete(e))}return{clear:f,delete:l,get:i,getMeta:m,getMetaByHash:M,hash:c,listMetaHashes:y,scheduleGc:g,set:u,setMeta:h,size:d}}exports.cache=T;
|
|
2
|
+
//# sourceMappingURL=cache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.cjs","sources":["../../src/object/cache.ts"],"sourcesContent":["/**\n * Creates a generic key-value cache with automatic garbage collection and observer support.\n *\n * @example\n * ```ts\n * const myCache = cache<string>();\n * myCache.set(['user', 1], 'John Doe');\n * const value = myCache.get(['user', 1]); // 'John Doe'\n * myCache.scheduleGc(['user', 1], 5000); // Auto-delete after 5s\n * ```\n *\n * @template T - The type of values stored in the cache.\n *\n * @returns A cache instance with get, set, delete, clear, and GC methods.\n */\nexport function cache<T>() {\n const store = new Map<string, T>();\n const gcTimers = new Map<string, ReturnType<typeof setTimeout>>();\n const metadata = new Map<string, { lastUsedAt: number }>();\n\n const hash = (key: readonly unknown[]) => JSON.stringify(key);\n\n function get(key: readonly unknown[]): T | undefined {\n return store.get(hash(key));\n }\n\n function set(key: readonly unknown[], value: T): void {\n store.set(hash(key), value);\n }\n\n function del(key: readonly unknown[]): boolean {\n const h = hash(key);\n clearGc(h);\n metadata.delete(h);\n return store.delete(h);\n }\n\n function clear(): void {\n gcTimers.forEach((timer) => {\n clearTimeout(timer);\n });\n store.clear();\n gcTimers.clear();\n metadata.clear();\n }\n\n function size(): number {\n return store.size;\n }\n\n function scheduleGc(key: readonly unknown[], delayMs: number): void {\n const h = hash(key);\n clearGc(h);\n gcTimers.set(\n h,\n setTimeout(() => {\n store.delete(h);\n gcTimers.delete(h);\n metadata.delete(h);\n }, delayMs),\n );\n }\n\n function setMeta(key: readonly unknown[], meta: Record<string, unknown>): void {\n metadata.set(hash(key), { lastUsedAt: Date.now(), ...meta });\n }\n\n function getMeta(key: readonly unknown[]): Record<string, unknown> | undefined {\n return metadata.get(hash(key));\n }\n\n function getMetaByHash(keyHash: string): Record<string, unknown> | undefined {\n return metadata.get(keyHash);\n }\n\n function listMetaHashes(): string[] {\n return Array.from(metadata.keys());\n }\n\n function clearGc(keyHash: string): void {\n const timer = gcTimers.get(keyHash);\n if (timer) {\n clearTimeout(timer);\n gcTimers.delete(keyHash);\n }\n }\n\n return {\n clear,\n delete: del,\n get,\n getMeta,\n getMetaByHash,\n hash,\n listMetaHashes,\n scheduleGc,\n set,\n setMeta,\n size,\n };\n}\n"],"names":["cache","store","gcTimers","metadata","hash","key","get","set","value","del","h","clearGc","clear","timer","size","scheduleGc","delayMs","setMeta","meta","getMeta","getMetaByHash","keyHash","listMetaHashes"],"mappings":"gFAeO,SAASA,GAAW,CACzB,MAAMC,MAAY,IACZC,MAAe,IACfC,MAAe,IAEfC,EAAQC,GAA4B,KAAK,UAAUA,CAAG,EAE5D,SAASC,EAAID,EAAwC,CACnD,OAAOJ,EAAM,IAAIG,EAAKC,CAAG,CAAC,CAC5B,CAEA,SAASE,EAAIF,EAAyBG,EAAgB,CACpDP,EAAM,IAAIG,EAAKC,CAAG,EAAGG,CAAK,CAC5B,CAEA,SAASC,EAAIJ,EAAkC,CAC7C,MAAMK,EAAIN,EAAKC,CAAG,EAClB,OAAAM,EAAQD,CAAC,EACTP,EAAS,OAAOO,CAAC,EACVT,EAAM,OAAOS,CAAC,CACvB,CAEA,SAASE,GAAc,CACrBV,EAAS,QAASW,GAAU,CAC1B,aAAaA,CAAK,CACpB,CAAC,EACDZ,EAAM,MAAA,EACNC,EAAS,MAAA,EACTC,EAAS,MAAA,CACX,CAEA,SAASW,GAAe,CACtB,OAAOb,EAAM,IACf,CAEA,SAASc,EAAWV,EAAyBW,EAAuB,CAClE,MAAMN,EAAIN,EAAKC,CAAG,EAClBM,EAAQD,CAAC,EACTR,EAAS,IACPQ,EACA,WAAW,IAAM,CACfT,EAAM,OAAOS,CAAC,EACdR,EAAS,OAAOQ,CAAC,EACjBP,EAAS,OAAOO,CAAC,CACnB,EAAGM,CAAO,CAAA,CAEd,CAEA,SAASC,EAAQZ,EAAyBa,EAAqC,CAC7Ef,EAAS,IAAIC,EAAKC,CAAG,EAAG,CAAE,WAAY,KAAK,IAAA,EAAO,GAAGa,EAAM,CAC7D,CAEA,SAASC,EAAQd,EAA8D,CAC7E,OAAOF,EAAS,IAAIC,EAAKC,CAAG,CAAC,CAC/B,CAEA,SAASe,EAAcC,EAAsD,CAC3E,OAAOlB,EAAS,IAAIkB,CAAO,CAC7B,CAEA,SAASC,GAA2B,CAClC,OAAO,MAAM,KAAKnB,EAAS,KAAA,CAAM,CACnC,CAEA,SAASQ,EAAQU,EAAuB,CACtC,MAAMR,EAAQX,EAAS,IAAImB,CAAO,EAC9BR,IACF,aAAaA,CAAK,EAClBX,EAAS,OAAOmB,CAAO,EAE3B,CAEA,MAAO,CACL,MAAAT,EACA,OAAQH,EACR,IAAAH,EACA,QAAAa,EACA,cAAAC,EACA,KAAAhB,EACA,eAAAkB,EACA,WAAAP,EACA,IAAAR,EACA,QAAAU,EACA,KAAAH,CAAA,CAEJ"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function w() {
|
|
2
|
+
const r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), c = (e) => JSON.stringify(e);
|
|
3
|
+
function i(e) {
|
|
4
|
+
return r.get(c(e));
|
|
5
|
+
}
|
|
6
|
+
function u(e, t) {
|
|
7
|
+
r.set(c(e), t);
|
|
8
|
+
}
|
|
9
|
+
function l(e) {
|
|
10
|
+
const t = c(e);
|
|
11
|
+
return a(t), n.delete(t), r.delete(t);
|
|
12
|
+
}
|
|
13
|
+
function f() {
|
|
14
|
+
o.forEach((e) => {
|
|
15
|
+
clearTimeout(e);
|
|
16
|
+
}), r.clear(), o.clear(), n.clear();
|
|
17
|
+
}
|
|
18
|
+
function d() {
|
|
19
|
+
return r.size;
|
|
20
|
+
}
|
|
21
|
+
function g(e, t) {
|
|
22
|
+
const s = c(e);
|
|
23
|
+
a(s), o.set(
|
|
24
|
+
s,
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
r.delete(s), o.delete(s), n.delete(s);
|
|
27
|
+
}, t)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function h(e, t) {
|
|
31
|
+
n.set(c(e), { lastUsedAt: Date.now(), ...t });
|
|
32
|
+
}
|
|
33
|
+
function m(e) {
|
|
34
|
+
return n.get(c(e));
|
|
35
|
+
}
|
|
36
|
+
function M(e) {
|
|
37
|
+
return n.get(e);
|
|
38
|
+
}
|
|
39
|
+
function p() {
|
|
40
|
+
return Array.from(n.keys());
|
|
41
|
+
}
|
|
42
|
+
function a(e) {
|
|
43
|
+
const t = o.get(e);
|
|
44
|
+
t && (clearTimeout(t), o.delete(e));
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
clear: f,
|
|
48
|
+
delete: l,
|
|
49
|
+
get: i,
|
|
50
|
+
getMeta: m,
|
|
51
|
+
getMetaByHash: M,
|
|
52
|
+
hash: c,
|
|
53
|
+
listMetaHashes: p,
|
|
54
|
+
scheduleGc: g,
|
|
55
|
+
set: u,
|
|
56
|
+
setMeta: h,
|
|
57
|
+
size: d
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
w as cache
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sources":["../../src/object/cache.ts"],"sourcesContent":["/**\n * Creates a generic key-value cache with automatic garbage collection and observer support.\n *\n * @example\n * ```ts\n * const myCache = cache<string>();\n * myCache.set(['user', 1], 'John Doe');\n * const value = myCache.get(['user', 1]); // 'John Doe'\n * myCache.scheduleGc(['user', 1], 5000); // Auto-delete after 5s\n * ```\n *\n * @template T - The type of values stored in the cache.\n *\n * @returns A cache instance with get, set, delete, clear, and GC methods.\n */\nexport function cache<T>() {\n const store = new Map<string, T>();\n const gcTimers = new Map<string, ReturnType<typeof setTimeout>>();\n const metadata = new Map<string, { lastUsedAt: number }>();\n\n const hash = (key: readonly unknown[]) => JSON.stringify(key);\n\n function get(key: readonly unknown[]): T | undefined {\n return store.get(hash(key));\n }\n\n function set(key: readonly unknown[], value: T): void {\n store.set(hash(key), value);\n }\n\n function del(key: readonly unknown[]): boolean {\n const h = hash(key);\n clearGc(h);\n metadata.delete(h);\n return store.delete(h);\n }\n\n function clear(): void {\n gcTimers.forEach((timer) => {\n clearTimeout(timer);\n });\n store.clear();\n gcTimers.clear();\n metadata.clear();\n }\n\n function size(): number {\n return store.size;\n }\n\n function scheduleGc(key: readonly unknown[], delayMs: number): void {\n const h = hash(key);\n clearGc(h);\n gcTimers.set(\n h,\n setTimeout(() => {\n store.delete(h);\n gcTimers.delete(h);\n metadata.delete(h);\n }, delayMs),\n );\n }\n\n function setMeta(key: readonly unknown[], meta: Record<string, unknown>): void {\n metadata.set(hash(key), { lastUsedAt: Date.now(), ...meta });\n }\n\n function getMeta(key: readonly unknown[]): Record<string, unknown> | undefined {\n return metadata.get(hash(key));\n }\n\n function getMetaByHash(keyHash: string): Record<string, unknown> | undefined {\n return metadata.get(keyHash);\n }\n\n function listMetaHashes(): string[] {\n return Array.from(metadata.keys());\n }\n\n function clearGc(keyHash: string): void {\n const timer = gcTimers.get(keyHash);\n if (timer) {\n clearTimeout(timer);\n gcTimers.delete(keyHash);\n }\n }\n\n return {\n clear,\n delete: del,\n get,\n getMeta,\n getMetaByHash,\n hash,\n listMetaHashes,\n scheduleGc,\n set,\n setMeta,\n size,\n };\n}\n"],"names":["cache","store","gcTimers","metadata","hash","key","get","set","value","del","h","clearGc","clear","timer","size","scheduleGc","delayMs","setMeta","meta","getMeta","getMetaByHash","keyHash","listMetaHashes"],"mappings":"AAeO,SAASA,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AAAA,EAC7B;AAEA,WAASC,IAA2B;AAClC,WAAO,MAAM,KAAKnB,EAAS,KAAA,CAAM;AAAA,EACnC;AAEA,WAASQ,EAAQU,GAAuB;AACtC,UAAMR,IAAQX,EAAS,IAAImB,CAAO;AAClC,IAAIR,MACF,aAAaA,CAAK,GAClBX,EAAS,OAAOmB,CAAO;AAAA,EAE3B;AAEA,SAAO;AAAA,IACL,OAAAT;AAAA,IACA,QAAQH;AAAA,IACR,KAAAH;AAAA,IACA,SAAAa;AAAA,IACA,eAAAC;AAAA,IACA,MAAAhB;AAAA,IACA,gBAAAkB;AAAA,IACA,YAAAP;AAAA,IACA,KAAAR;AAAA,IACA,SAAAU;AAAA,IACA,MAAAH;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attempt.cjs","sources":["../../src/function/attempt.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport type { Fn } from '../types';\nimport { predict } from './predict';\nimport { retry } from './retry';\n\ntype AttemptOptions = {\n identifier?: string;\n retries?: number;\n silent?: boolean;\n timeout?: number;\n};\n\n/**\n * Attempts to execute a function with advanced error handling and retry logic.\n *\n * @example\n * ```ts\n * const unreliableFunction = async () => {\n * if (Math.random() < 0.7) throw new Error ('Random failure');\n * return 'Success!';\n * };\n *\n * await attempt(\n * unreliableFunction,\n * { retries: 3, silent: false, timeout: 5000 }); // Success! (or undefined if all attempts failed)\n * ```\n *\n * @param fn - The function to be executed.\n * @param [options] - Configuration options for the attempt.\n * @param [options.identifier] - Custom identifier for logging purposes.\n * @param [options.retries=0] - Number of retry attempts if the function fails.\n * @param [options.silent=false] - If true, suppresses error logging.\n * @param [options.timeout=7000] - Timeout in milliseconds for function execution.\n *\n * @returns The result of the function or undefined if it failed.\n */\nexport async function attempt<T extends Fn, R = Awaited<ReturnType<T>>>(\n fn: T,\n { silent = false, retries = 0, timeout = 7000, identifier = fn.name || 'anonymous function' }: AttemptOptions = {},\n): Promise<R | undefined> {\n try {\n return await retry(() => predict<R>(() => fn(), { timeout }), { times: retries + 1 });\n } catch (err) {\n if (!silent) {\n Logit.error(`attempt(${identifier}) -> all attempts failed`, { cause: err });\n }\n return undefined;\n }\n}\n"],"names":["attempt","fn","silent","retries","timeout","identifier","retry","predict","err","Logit"],"mappings":"+KAoCA,eAAsBA,EACpBC,EACA,CAAE,OAAAC,EAAS,GAAO,QAAAC,EAAU,EAAG,QAAAC,EAAU,IAAM,WAAAC,EAAaJ,EAAG,MAAQ,oBAAA,EAAyC,CAAA,EACxF,CACxB,GAAI,CACF,OAAO,MAAMK,EAAAA,MAAM,IAAMC,EAAAA,QAAW,IAAMN,EAAA,EAAM,CAAE,QAAAG,CAAA,CAAS,EAAG,CAAE,MAAOD,EAAU,EAAG,CACtF,OAASK,EAAK,CACPN,GACHO,QAAM,MAAM,WAAWJ,CAAU,2BAA4B,CAAE,MAAOG,EAAK,EAE7E,MACF,CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attempt.js","sources":["../../src/function/attempt.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport type { Fn } from '../types';\nimport { predict } from './predict';\nimport { retry } from './retry';\n\ntype AttemptOptions = {\n identifier?: string;\n retries?: number;\n silent?: boolean;\n timeout?: number;\n};\n\n/**\n * Attempts to execute a function with advanced error handling and retry logic.\n *\n * @example\n * ```ts\n * const unreliableFunction = async () => {\n * if (Math.random() < 0.7) throw new Error ('Random failure');\n * return 'Success!';\n * };\n *\n * await attempt(\n * unreliableFunction,\n * { retries: 3, silent: false, timeout: 5000 }); // Success! (or undefined if all attempts failed)\n * ```\n *\n * @param fn - The function to be executed.\n * @param [options] - Configuration options for the attempt.\n * @param [options.identifier] - Custom identifier for logging purposes.\n * @param [options.retries=0] - Number of retry attempts if the function fails.\n * @param [options.silent=false] - If true, suppresses error logging.\n * @param [options.timeout=7000] - Timeout in milliseconds for function execution.\n *\n * @returns The result of the function or undefined if it failed.\n */\nexport async function attempt<T extends Fn, R = Awaited<ReturnType<T>>>(\n fn: T,\n { silent = false, retries = 0, timeout = 7000, identifier = fn.name || 'anonymous function' }: AttemptOptions = {},\n): Promise<R | undefined> {\n try {\n return await retry(() => predict<R>(() => fn(), { timeout }), { times: retries + 1 });\n } catch (err) {\n if (!silent) {\n Logit.error(`attempt(${identifier}) -> all attempts failed`, { cause: err });\n }\n return undefined;\n }\n}\n"],"names":["attempt","fn","silent","retries","timeout","identifier","retry","predict","err","Logit"],"mappings":";;;AAoCA,eAAsBA,EACpBC,GACA,EAAE,QAAAC,IAAS,IAAO,SAAAC,IAAU,GAAG,SAAAC,IAAU,KAAM,YAAAC,IAAaJ,EAAG,QAAQ,qBAAA,IAAyC,CAAA,GACxF;AACxB,MAAI;AACF,WAAO,MAAMK,EAAM,MAAMC,EAAW,MAAMN,EAAA,GAAM,EAAE,SAAAG,EAAA,CAAS,GAAG,EAAE,OAAOD,IAAU,GAAG;AAAA,EACtF,SAASK,GAAK;AACZ,IAAKN,KACHO,EAAM,MAAM,WAAWJ,CAAU,4BAA4B,EAAE,OAAOG,GAAK;AAE7E;AAAA,EACF;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delay.cjs","sources":["../../src/function/delay.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { sleep } from './sleep';\n\n/**\n * Delays the execution of a function by a specified amount of time.\n *\n * @example\n * ```ts\n * const log = () => console.log('Hello, world!');\n *\n * delay(log, 1000); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param fn - The function to be delayed.\n * @param delay - The amount of time to delay the function execution, in milliseconds. Default is 700.\n *\n * @returns A Promise that resolves with the result of the function execution.\n */\nexport async function delay<T extends Fn>(fn: T, delay = 700) {\n await sleep(delay);\n\n return fn();\n}\n"],"names":["delay","fn","sleep"],"mappings":"+GAkBA,eAAsBA,EAAoBC,EAAOD,EAAQ,IAAK,CAC5D,aAAME,EAAAA,MAAMF,CAAK,EAEVC,EAAA,CACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delay.js","sources":["../../src/function/delay.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { sleep } from './sleep';\n\n/**\n * Delays the execution of a function by a specified amount of time.\n *\n * @example\n * ```ts\n * const log = () => console.log('Hello, world!');\n *\n * delay(log, 1000); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param fn - The function to be delayed.\n * @param delay - The amount of time to delay the function execution, in milliseconds. Default is 700.\n *\n * @returns A Promise that resolves with the result of the function execution.\n */\nexport async function delay<T extends Fn>(fn: T, delay = 700) {\n await sleep(delay);\n\n return fn();\n}\n"],"names":["delay","fn","sleep"],"mappings":";AAkBA,eAAsBA,EAAoBC,GAAOD,IAAQ,KAAK;AAC5D,eAAME,EAAMF,CAAK,GAEVC,EAAA;AACT;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.cjs","sources":["../../src/function/parallel.ts"],"sourcesContent":["/**\n * Processes an array with an async callback with controlled parallelism.\n * Similar to Promise.all, but limits how many items are processed concurrently.\n * Returns an ordered array of results.\n *\n * @example\n * ```ts\n * // Process 3 items at a time\n * const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {\n * await delay(100);\n * return n * 2;\n * });\n * // [2, 4, 6, 8, 10]\n *\n * // With abort signal\n * const controller = new AbortController();\n * const results = await parallel(2, items, async (item) => {\n * return processItem(item);\n * }, controller.signal);\n * ```\n *\n * @param limit - Maximum number of concurrent operations (must be >= 1)\n * @param array - Array of items to process\n * @param callback - Async function to process each item\n * @param signal - Optional AbortSignal to cancel processing\n * @returns Promise resolving to an ordered array of results\n * @throws {Error} If limit is less than 1\n * @throws {DOMException} If aborted via signal\n */\nexport async function parallel<T, R>(\n limit: number,\n array: T[],\n callback: (item: T, index: number, array: T[]) => Promise<R>,\n signal?: AbortSignal,\n): Promise<R[]> {\n if (limit < 1) {\n throw new Error('Limit must be at least 1');\n }\n\n if (signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n const results: R[] = new Array(array.length);\n let currentIndex = 0;\n let hasError = false;\n let error: unknown;\n\n // Check for abort\n const checkAbort = () => {\n if (signal?.aborted) {\n hasError = true;\n error = new DOMException('Aborted', 'AbortError');\n return true;\n }\n return false;\n };\n\n // Worker function that processes items from the queue\n const worker = async (): Promise<void> => {\n while (currentIndex < array.length && !hasError) {\n if (checkAbort()) {\n break;\n }\n\n const index = currentIndex++;\n\n try {\n results[index] = await callback(array[index], index, array);\n } catch (err) {\n hasError = true;\n error = err;\n break;\n }\n }\n };\n\n // Create workers up to the limit\n const workers: Promise<void>[] = [];\n const workerCount = Math.min(limit, array.length);\n\n for (let i = 0; i < workerCount; i++) {\n workers.push(worker());\n }\n\n // Wait for all workers to complete\n await Promise.all(workers);\n\n // If there was an error, throw it\n if (hasError) {\n throw error;\n }\n\n return results;\n}\n"],"names":["parallel","limit","array","callback","signal","results","currentIndex","hasError","error","checkAbort","worker","index","err","workers","workerCount","i"],"mappings":"gFA6BA,eAAsBA,EACpBC,EACAC,EACAC,EACAC,EACc,CACd,GAAIH,EAAQ,EACV,MAAM,IAAI,MAAM,0BAA0B,EAG5C,GAAIG,GAAQ,QACV,MAAM,IAAI,aAAa,UAAW,YAAY,EAGhD,MAAMC,EAAe,IAAI,MAAMH,EAAM,MAAM,EAC3C,IAAII,EAAe,EACfC,EAAW,GACXC,EAGJ,MAAMC,EAAa,IACbL,GAAQ,SACVG,EAAW,GACXC,EAAQ,IAAI,aAAa,UAAW,YAAY,EACzC,IAEF,GAIHE,EAAS,SAA2B,CACxC,KAAOJ,EAAeJ,EAAM,QAAU,CAACK,GACjC,CAAAE,KAD2C,CAK/C,MAAME,EAAQL,IAEd,GAAI,CACFD,EAAQM,CAAK,EAAI,MAAMR,EAASD,EAAMS,CAAK,EAAGA,EAAOT,CAAK,CAC5D,OAASU,EAAK,CACZL,EAAW,GACXC,EAAQI,EACR,KACF,CACF,CACF,EAGMC,EAA2B,CAAA,EAC3BC,EAAc,KAAK,IAAIb,EAAOC,EAAM,MAAM,EAEhD,QAASa,EAAI,EAAGA,EAAID,EAAaC,IAC/BF,EAAQ,KAAKH,GAAQ,EAOvB,GAHA,MAAM,QAAQ,IAAIG,CAAO,EAGrBN,EACF,MAAMC,EAGR,OAAOH,CACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.js","sources":["../../src/function/parallel.ts"],"sourcesContent":["/**\n * Processes an array with an async callback with controlled parallelism.\n * Similar to Promise.all, but limits how many items are processed concurrently.\n * Returns an ordered array of results.\n *\n * @example\n * ```ts\n * // Process 3 items at a time\n * const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {\n * await delay(100);\n * return n * 2;\n * });\n * // [2, 4, 6, 8, 10]\n *\n * // With abort signal\n * const controller = new AbortController();\n * const results = await parallel(2, items, async (item) => {\n * return processItem(item);\n * }, controller.signal);\n * ```\n *\n * @param limit - Maximum number of concurrent operations (must be >= 1)\n * @param array - Array of items to process\n * @param callback - Async function to process each item\n * @param signal - Optional AbortSignal to cancel processing\n * @returns Promise resolving to an ordered array of results\n * @throws {Error} If limit is less than 1\n * @throws {DOMException} If aborted via signal\n */\nexport async function parallel<T, R>(\n limit: number,\n array: T[],\n callback: (item: T, index: number, array: T[]) => Promise<R>,\n signal?: AbortSignal,\n): Promise<R[]> {\n if (limit < 1) {\n throw new Error('Limit must be at least 1');\n }\n\n if (signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n const results: R[] = new Array(array.length);\n let currentIndex = 0;\n let hasError = false;\n let error: unknown;\n\n // Check for abort\n const checkAbort = () => {\n if (signal?.aborted) {\n hasError = true;\n error = new DOMException('Aborted', 'AbortError');\n return true;\n }\n return false;\n };\n\n // Worker function that processes items from the queue\n const worker = async (): Promise<void> => {\n while (currentIndex < array.length && !hasError) {\n if (checkAbort()) {\n break;\n }\n\n const index = currentIndex++;\n\n try {\n results[index] = await callback(array[index], index, array);\n } catch (err) {\n hasError = true;\n error = err;\n break;\n }\n }\n };\n\n // Create workers up to the limit\n const workers: Promise<void>[] = [];\n const workerCount = Math.min(limit, array.length);\n\n for (let i = 0; i < workerCount; i++) {\n workers.push(worker());\n }\n\n // Wait for all workers to complete\n await Promise.all(workers);\n\n // If there was an error, throw it\n if (hasError) {\n throw error;\n }\n\n return results;\n}\n"],"names":["parallel","limit","array","callback","signal","results","currentIndex","hasError","error","checkAbort","worker","index","err","workers","workerCount","i"],"mappings":"AA6BA,eAAsBA,EACpBC,GACAC,GACAC,GACAC,GACc;AACd,MAAIH,IAAQ;AACV,UAAM,IAAI,MAAM,0BAA0B;AAG5C,MAAIG,GAAQ;AACV,UAAM,IAAI,aAAa,WAAW,YAAY;AAGhD,QAAMC,IAAe,IAAI,MAAMH,EAAM,MAAM;AAC3C,MAAII,IAAe,GACfC,IAAW,IACXC;AAGJ,QAAMC,IAAa,MACbL,GAAQ,WACVG,IAAW,IACXC,IAAQ,IAAI,aAAa,WAAW,YAAY,GACzC,MAEF,IAIHE,IAAS,YAA2B;AACxC,WAAOJ,IAAeJ,EAAM,UAAU,CAACK,KACjC,CAAAE,OAD2C;AAK/C,YAAME,IAAQL;AAEd,UAAI;AACF,QAAAD,EAAQM,CAAK,IAAI,MAAMR,EAASD,EAAMS,CAAK,GAAGA,GAAOT,CAAK;AAAA,MAC5D,SAASU,GAAK;AACZ,QAAAL,IAAW,IACXC,IAAQI;AACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAGMC,IAA2B,CAAA,GAC3BC,IAAc,KAAK,IAAIb,GAAOC,EAAM,MAAM;AAEhD,WAASa,IAAI,GAAGA,IAAID,GAAaC;AAC/B,IAAAF,EAAQ,KAAKH,GAAQ;AAOvB,MAHA,MAAM,QAAQ,IAAIG,CAAO,GAGrBN;AACF,UAAMC;AAGR,SAAOH;AACT;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"predict.cjs","sources":["../../src/function/predict.ts"],"sourcesContent":["/**\n * Creates a Promise that can be aborted using an AbortController.\n *\n * @example\n * ```ts\n * const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));\n * const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));\n *\n * predict(slowFn); // rejects after 7 seconds\n * predict(fastFn); // resolves with 'fast' after 5 seconds\n * ```\n *\n * @param fn - The function to execute, which receives an AbortSignal.\n * @param options - The options for the abortable function.\n * @param [options.signal] - The AbortSignal to use for aborting the Promise.\n * @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.\n *\n * @returns - A Promise that resolves with the result of the callback or rejects if aborted.\n */\nexport function predict<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n options: { signal?: AbortSignal; timeout?: number } = {},\n): Promise<T> {\n const { signal, timeout = 7000 } = options;\n const abortSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout);\n\n return Promise.race([\n fn(abortSignal),\n new Promise<never>((_, reject) => {\n abortSignal.addEventListener('abort', () => reject(new Error('Operation aborted')), { once: true });\n }),\n ]);\n}\n"],"names":["predict","fn","options","signal","timeout","abortSignal","_","reject"],"mappings":"gFAmBO,SAASA,EACdC,EACAC,EAAsD,GAC1C,CACZ,KAAM,CAAE,OAAAC,EAAQ,QAAAC,EAAU,GAAA,EAASF,EAC7BG,EAAcF,EAAS,YAAY,IAAI,CAAC,YAAY,QAAQC,CAAO,EAAGD,CAAM,CAAC,EAAI,YAAY,QAAQC,CAAO,EAElH,OAAO,QAAQ,KAAK,CAClBH,EAAGI,CAAW,EACd,IAAI,QAAe,CAACC,EAAGC,IAAW,CAChCF,EAAY,iBAAiB,QAAS,IAAME,EAAO,IAAI,MAAM,mBAAmB,CAAC,EAAG,CAAE,KAAM,EAAA,CAAM,CACpG,CAAC,CAAA,CACF,CACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"predict.js","sources":["../../src/function/predict.ts"],"sourcesContent":["/**\n * Creates a Promise that can be aborted using an AbortController.\n *\n * @example\n * ```ts\n * const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));\n * const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));\n *\n * predict(slowFn); // rejects after 7 seconds\n * predict(fastFn); // resolves with 'fast' after 5 seconds\n * ```\n *\n * @param fn - The function to execute, which receives an AbortSignal.\n * @param options - The options for the abortable function.\n * @param [options.signal] - The AbortSignal to use for aborting the Promise.\n * @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.\n *\n * @returns - A Promise that resolves with the result of the callback or rejects if aborted.\n */\nexport function predict<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n options: { signal?: AbortSignal; timeout?: number } = {},\n): Promise<T> {\n const { signal, timeout = 7000 } = options;\n const abortSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout);\n\n return Promise.race([\n fn(abortSignal),\n new Promise<never>((_, reject) => {\n abortSignal.addEventListener('abort', () => reject(new Error('Operation aborted')), { once: true });\n }),\n ]);\n}\n"],"names":["predict","fn","options","signal","timeout","abortSignal","_","reject"],"mappings":"AAmBO,SAASA,EACdC,GACAC,IAAsD,IAC1C;AACZ,QAAM,EAAE,QAAAC,GAAQ,SAAAC,IAAU,IAAA,IAASF,GAC7BG,IAAcF,IAAS,YAAY,IAAI,CAAC,YAAY,QAAQC,CAAO,GAAGD,CAAM,CAAC,IAAI,YAAY,QAAQC,CAAO;AAElH,SAAO,QAAQ,KAAK;AAAA,IAClBH,EAAGI,CAAW;AAAA,IACd,IAAI,QAAe,CAACC,GAAGC,MAAW;AAChC,MAAAF,EAAY,iBAAiB,SAAS,MAAME,EAAO,IAAI,MAAM,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAA,CAAM;AAAA,IACpG,CAAC;AAAA,EAAA,CACF;AACH;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retry.cjs","sources":["../../src/function/retry.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { sleep } from './sleep';\n\n/**\n * Retries an asynchronous function a specified number of times with delay and optional exponential backoff.\n *\n * @example\n * ```ts\n * retry(() => fetchData(), { times: 3, delay: 1000, backoff: 2, signal: abortSignal })\n * .then(result => console.log(result))\n * .catch(error => console.error(error));\n * ```\n *\n * @param fn - The asynchronous function to retry.\n * @param options - (optional) Options for retrying the function.\n * @param [options.times=3] - The number of retry attempts.\n * @param [options.delay=250] - The delay in milliseconds between retries.\n * @param [options.backoff=1] - Exponential backoff factor (default: 1 → no backoff).\n * @param [options.signal] - `AbortSignal` to allow canceling retries.\n *\n * @returns The result of the asynchronous function.\n */\nexport async function retry<T>(\n fn: () => Promise<T>,\n {\n times = 3,\n delay = 250,\n backoff = 1,\n signal,\n }: {\n times?: number;\n delay?: number;\n backoff?: number | ((attempt: number, delay: number) => number);\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n let currentDelay = delay;\n\n for (let attempt = 1; attempt <= times; attempt++) {\n if (signal?.aborted) {\n Logit.warn(`retry() -> Aborted after ${attempt - 1} attempts`);\n throw new Error('Retry aborted');\n }\n\n try {\n return await fn();\n } catch (err) {\n if (attempt === times) throw err;\n\n Logit.warn(`retry() -> ${err}, attempt ${attempt}/${times}, retrying in ${currentDelay}ms`);\n if (currentDelay > 0) await sleep(currentDelay);\n\n currentDelay = typeof backoff === 'function' ? backoff(attempt, currentDelay) : currentDelay * backoff;\n }\n }\n\n throw new Error('Retry failed unexpectedly');\n}\n"],"names":["retry","fn","times","delay","backoff","signal","currentDelay","attempt","Logit","err","sleep"],"mappings":"oJAsBA,eAAsBA,EACpBC,EACA,CACE,MAAAC,EAAQ,EACR,MAAAC,EAAQ,IACR,QAAAC,EAAU,EACV,OAAAC,CACF,EAKI,GACQ,CACZ,IAAIC,EAAeH,EAEnB,QAASI,EAAU,EAAGA,GAAWL,EAAOK,IAAW,CACjD,GAAIF,GAAQ,QACVG,MAAAA,EAAAA,MAAM,KAAK,4BAA4BD,EAAU,CAAC,WAAW,EACvD,IAAI,MAAM,eAAe,EAGjC,GAAI,CACF,OAAO,MAAMN,EAAA,CACf,OAASQ,EAAK,CACZ,GAAIF,IAAYL,EAAO,MAAMO,EAE7BD,EAAAA,MAAM,KAAK,cAAcC,CAAG,aAAaF,CAAO,IAAIL,CAAK,iBAAiBI,CAAY,IAAI,EACtFA,EAAe,GAAG,MAAMI,EAAAA,MAAMJ,CAAY,EAE9CA,EAAe,OAAOF,GAAY,WAAaA,EAAQG,EAASD,CAAY,EAAIA,EAAeF,CACjG,CACF,CAEA,MAAM,IAAI,MAAM,2BAA2B,CAC7C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sources":["../../src/function/retry.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { sleep } from './sleep';\n\n/**\n * Retries an asynchronous function a specified number of times with delay and optional exponential backoff.\n *\n * @example\n * ```ts\n * retry(() => fetchData(), { times: 3, delay: 1000, backoff: 2, signal: abortSignal })\n * .then(result => console.log(result))\n * .catch(error => console.error(error));\n * ```\n *\n * @param fn - The asynchronous function to retry.\n * @param options - (optional) Options for retrying the function.\n * @param [options.times=3] - The number of retry attempts.\n * @param [options.delay=250] - The delay in milliseconds between retries.\n * @param [options.backoff=1] - Exponential backoff factor (default: 1 → no backoff).\n * @param [options.signal] - `AbortSignal` to allow canceling retries.\n *\n * @returns The result of the asynchronous function.\n */\nexport async function retry<T>(\n fn: () => Promise<T>,\n {\n times = 3,\n delay = 250,\n backoff = 1,\n signal,\n }: {\n times?: number;\n delay?: number;\n backoff?: number | ((attempt: number, delay: number) => number);\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n let currentDelay = delay;\n\n for (let attempt = 1; attempt <= times; attempt++) {\n if (signal?.aborted) {\n Logit.warn(`retry() -> Aborted after ${attempt - 1} attempts`);\n throw new Error('Retry aborted');\n }\n\n try {\n return await fn();\n } catch (err) {\n if (attempt === times) throw err;\n\n Logit.warn(`retry() -> ${err}, attempt ${attempt}/${times}, retrying in ${currentDelay}ms`);\n if (currentDelay > 0) await sleep(currentDelay);\n\n currentDelay = typeof backoff === 'function' ? backoff(attempt, currentDelay) : currentDelay * backoff;\n }\n }\n\n throw new Error('Retry failed unexpectedly');\n}\n"],"names":["retry","fn","times","delay","backoff","signal","currentDelay","attempt","Logit","err","sleep"],"mappings":";;AAsBA,eAAsBA,EACpBC,GACA;AAAA,EACE,OAAAC,IAAQ;AAAA,EACR,OAAAC,IAAQ;AAAA,EACR,SAAAC,IAAU;AAAA,EACV,QAAAC;AACF,IAKI,IACQ;AACZ,MAAIC,IAAeH;AAEnB,WAASI,IAAU,GAAGA,KAAWL,GAAOK,KAAW;AACjD,QAAIF,GAAQ;AACVG,YAAAA,EAAM,KAAK,4BAA4BD,IAAU,CAAC,WAAW,GACvD,IAAI,MAAM,eAAe;AAGjC,QAAI;AACF,aAAO,MAAMN,EAAA;AAAA,IACf,SAASQ,GAAK;AACZ,UAAIF,MAAYL,EAAO,OAAMO;AAE7BD,MAAAA,EAAM,KAAK,cAAcC,CAAG,aAAaF,CAAO,IAAIL,CAAK,iBAAiBI,CAAY,IAAI,GACtFA,IAAe,KAAG,MAAMI,EAAMJ,CAAY,GAE9CA,IAAe,OAAOF,KAAY,aAAaA,EAAQG,GAASD,CAAY,IAAIA,IAAeF;AAAA,IACjG;AAAA,EACF;AAEA,QAAM,IAAI,MAAM,2BAA2B;AAC7C;"}
|
package/dist/function/sleep.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./assert.cjs");async function s(e){return n.assert(typeof e=="number"&&e>=0&&Number.isFinite(e),"Timeout must be a non-negative finite number",{args:{timeout:e},type:TypeError}),new Promise(r=>setTimeout(r,e))}exports.sleep=s;
|
|
2
|
-
//# sourceMappingURL=sleep.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.cjs","sources":["../../src/function/sleep.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Creates a Promise that resolves after a specified amount of time.\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n *\n * @returns A Promise that resolves after the specified time.\n *\n * @throws {TypeError} If timeout is not a non-negative number.\n */\nexport async function sleep(timeout: number): Promise<void> {\n assert(\n typeof timeout === 'number' && timeout >= 0 && Number.isFinite(timeout),\n 'Timeout must be a non-negative finite number',\n { args: { timeout }, type: TypeError },\n );\n return new Promise((resolve) => setTimeout(resolve, timeout));\n}\n"],"names":["sleep","timeout","assert","resolve"],"mappings":"gHAgBA,eAAsBA,EAAMC,EAAgC,CAC1DC,OAAAA,EAAAA,OACE,OAAOD,GAAY,UAAYA,GAAW,GAAK,OAAO,SAASA,CAAO,EACtE,+CACA,CAAE,KAAM,CAAE,QAAAA,CAAA,EAAW,KAAM,SAAA,CAAU,EAEhC,IAAI,QAASE,GAAY,WAAWA,EAASF,CAAO,CAAC,CAC9D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.js","sources":["../../src/function/sleep.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Creates a Promise that resolves after a specified amount of time.\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n *\n * @returns A Promise that resolves after the specified time.\n *\n * @throws {TypeError} If timeout is not a non-negative number.\n */\nexport async function sleep(timeout: number): Promise<void> {\n assert(\n typeof timeout === 'number' && timeout >= 0 && Number.isFinite(timeout),\n 'Timeout must be a non-negative finite number',\n { args: { timeout }, type: TypeError },\n );\n return new Promise((resolve) => setTimeout(resolve, timeout));\n}\n"],"names":["sleep","timeout","assert","resolve"],"mappings":";AAgBA,eAAsBA,EAAMC,GAAgC;AAC1D,SAAAC;AAAA,IACE,OAAOD,KAAY,YAAYA,KAAW,KAAK,OAAO,SAASA,CAAO;AAAA,IACtE;AAAA,IACA,EAAE,MAAM,EAAE,SAAAA,EAAA,GAAW,MAAM,UAAA;AAAA,EAAU,GAEhC,IAAI,QAAQ,CAACE,MAAY,WAAWA,GAASF,CAAO,CAAC;AAC9D;"}
|
|
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
|