semola 0.6.0 → 0.6.2

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 (51) hide show
  1. package/README.md +19 -5
  2. package/dist/index-DISN0WKZ.d.mts +78 -0
  3. package/dist/lib/api/index.cjs +1 -537
  4. package/dist/lib/api/index.d.cts +1 -271
  5. package/dist/lib/api/index.d.mts +100 -164
  6. package/dist/lib/api/index.mjs +1 -535
  7. package/dist/lib/cache/index.cjs +1 -99
  8. package/dist/lib/cache/index.d.cts +1 -27
  9. package/dist/lib/cache/index.mjs +1 -98
  10. package/dist/lib/cli/index.cjs +3 -0
  11. package/dist/lib/cli/index.d.cts +1 -0
  12. package/dist/lib/cli/index.d.mts +90 -0
  13. package/dist/lib/cli/index.mjs +3 -0
  14. package/dist/lib/cron/index.cjs +1 -735
  15. package/dist/lib/cron/index.d.cts +1 -146
  16. package/dist/lib/cron/index.d.mts +99 -36
  17. package/dist/lib/cron/index.mjs +1 -726
  18. package/dist/lib/errors/index.cjs +1 -30
  19. package/dist/lib/errors/index.d.cts +1 -13
  20. package/dist/lib/errors/index.mjs +1 -26
  21. package/dist/lib/i18n/index.cjs +1 -42
  22. package/dist/lib/i18n/index.d.cts +1 -28
  23. package/dist/lib/i18n/index.d.mts +2 -2
  24. package/dist/lib/i18n/index.mjs +1 -41
  25. package/dist/lib/logging/index.cjs +1 -388
  26. package/dist/lib/logging/index.d.cts +1 -108
  27. package/dist/lib/logging/index.mjs +1 -374
  28. package/dist/lib/orm/index.cjs +1 -1642
  29. package/dist/lib/orm/index.d.cts +1 -402
  30. package/dist/lib/orm/index.d.mts +27 -25
  31. package/dist/lib/orm/index.mjs +1 -1630
  32. package/dist/lib/policy/index.cjs +1 -285
  33. package/dist/lib/policy/index.d.cts +1 -77
  34. package/dist/lib/policy/index.d.mts +1 -1
  35. package/dist/lib/policy/index.mjs +1 -265
  36. package/dist/lib/prompts/index.cjs +6 -769
  37. package/dist/lib/prompts/index.d.cts +1 -75
  38. package/dist/lib/prompts/index.mjs +6 -762
  39. package/dist/lib/pubsub/index.cjs +1 -141
  40. package/dist/lib/pubsub/index.d.cts +1 -26
  41. package/dist/lib/pubsub/index.mjs +1 -140
  42. package/dist/lib/queue/index.cjs +1 -212
  43. package/dist/lib/queue/index.d.cts +1 -81
  44. package/dist/lib/queue/index.mjs +1 -209
  45. package/dist/lib/workflow/index.cjs +1 -537
  46. package/dist/lib/workflow/index.d.cts +1 -150
  47. package/dist/lib/workflow/index.d.mts +0 -1
  48. package/dist/lib/workflow/index.mjs +1 -527
  49. package/dist/rolldown-runtime-CMqjfN_6.cjs +1 -0
  50. package/package.json +17 -5
  51. package/dist/chunk-CKQMccvm.cjs +0 -28
@@ -1,108 +1 @@
1
- //#region src/lib/logging/core/types.d.ts
2
- declare const LogLevel: {
3
- readonly debug: 10;
4
- readonly info: 20;
5
- readonly warning: 30;
6
- readonly error: 40;
7
- readonly critical: 50;
8
- };
9
- type LogLevelType = keyof typeof LogLevel;
10
- type LogMessageType = string | object | number | boolean;
11
- type LogDataType = {
12
- prefix: string;
13
- level: LogLevelType;
14
- msg: LogMessageType;
15
- row?: string;
16
- column?: string;
17
- fileName?: string;
18
- method?: string;
19
- };
20
- //#endregion
21
- //#region src/lib/logging/formatter/types.d.ts
22
- type DateFmtFnType = () => string;
23
- //#endregion
24
- //#region src/lib/logging/formatter/index.d.ts
25
- declare abstract class Formatter {
26
- protected dateFmt: DateFmtFnType;
27
- constructor(dateFmt: DateFmtFnType);
28
- abstract format(logData: LogDataType): string;
29
- abstract formatError(logData: LogDataType, error: Error): string;
30
- }
31
- declare class BaseFormatter extends Formatter {
32
- constructor(dateFmt?: DateFmtFnType);
33
- format(logData: LogDataType): string;
34
- formatError(logData: LogDataType, error: Error): string;
35
- }
36
- declare class JSONFormatter extends Formatter {
37
- constructor(dateFmt?: DateFmtFnType);
38
- format(logData: LogDataType): string;
39
- formatError(logData: LogDataType, error: Error): string;
40
- }
41
- declare function isoDateTimeFormat(): string;
42
- declare function isoDateFormat(): string;
43
- declare function dmyFormat(): string;
44
- declare function mdyFormat(): string;
45
- //#endregion
46
- //#region src/lib/logging/provider/types.d.ts
47
- type ProviderOptions = {
48
- level?: LogLevelType;
49
- formatter?: Formatter;
50
- };
51
- interface SizeBasedPolicyType {
52
- type: "size";
53
- maxSize?: number;
54
- }
55
- interface TimeBasedPolicyType {
56
- type: "time";
57
- instant: "hour" | "day" | "week" | "month";
58
- duration: number;
59
- }
60
- type FileProviderOptions = ProviderOptions & {
61
- policy?: SizeBasedPolicyType | TimeBasedPolicyType;
62
- };
63
- //#endregion
64
- //#region src/lib/logging/provider/index.d.ts
65
- declare abstract class LoggerProvider {
66
- protected options: ProviderOptions;
67
- constructor(options?: ProviderOptions);
68
- abstract execute(data: LogDataType): void;
69
- getLogLevel(): number;
70
- }
71
- declare class FileProvider extends LoggerProvider {
72
- private readonly filePath;
73
- private counter;
74
- private file;
75
- private policy?;
76
- constructor(file: string, options?: FileProviderOptions);
77
- execute(data: LogDataType): void;
78
- private canRollFile;
79
- private getFileSize;
80
- private isJSONFile;
81
- private createNewFileName;
82
- }
83
- declare class ConsoleProvider extends LoggerProvider {
84
- execute(data: LogDataType): void;
85
- }
86
- //#endregion
87
- //#region src/lib/logging/core/index.d.ts
88
- declare abstract class AbstractLogger {
89
- protected providers: LoggerProvider[];
90
- protected prefix: string;
91
- constructor(prefix: string, providers: [LoggerProvider, ...LoggerProvider[]]);
92
- abstract debug(msg: LogMessageType): void;
93
- abstract info(msg: LogMessageType): void;
94
- abstract warning(msg: LogMessageType): void;
95
- abstract error(msg: LogMessageType): void;
96
- abstract critical(msg: LogMessageType): void;
97
- protected createLogData(level: LogLevelType, msg: LogMessageType, prefix: string): LogDataType;
98
- }
99
- declare class Logger extends AbstractLogger {
100
- debug(msg: LogMessageType): void;
101
- info(msg: LogMessageType): void;
102
- warning(msg: LogMessageType): void;
103
- error(msg: LogMessageType): void;
104
- critical(msg: LogMessageType): void;
105
- private run;
106
- }
107
- //#endregion
108
- export { AbstractLogger, BaseFormatter, ConsoleProvider, type DateFmtFnType, FileProvider, type FileProviderOptions, Formatter, JSONFormatter, type LogDataType, LogLevel, type LogLevelType, type LogMessageType, Logger, LoggerProvider, type ProviderOptions, type SizeBasedPolicyType, type TimeBasedPolicyType, dmyFormat, isoDateFormat, isoDateTimeFormat, mdyFormat };
1
+ export type * from './index.d.mts'
@@ -1,374 +1 @@
1
- import { mightThrowSync } from "../errors/index.mjs";
2
- import { basename, dirname, extname, join } from "node:path";
3
- import { appendFileSync, existsSync, mkdirSync, statSync } from "node:fs";
4
- //#region src/lib/logging/formatter/index.ts
5
- var Formatter = class {
6
- dateFmt;
7
- constructor(dateFmt) {
8
- this.dateFmt = dateFmt;
9
- }
10
- };
11
- var BaseFormatter = class extends Formatter {
12
- constructor(dateFmt = isoDateTimeFormat) {
13
- super(dateFmt);
14
- }
15
- format(logData) {
16
- let { prefix, level, msg, fileName, row, column, method } = logData;
17
- const timestamp = this.dateFmt();
18
- const levelType = level.toUpperCase();
19
- if (typeof msg === "object") msg = JSON.stringify(msg);
20
- const fileData = `${prefix}/${fileName}:${row}:${column}`;
21
- let header = `[${levelType}]`;
22
- if (method) header = `${header}\t[${method}]\t[${fileData}]`;
23
- else header = `${header}\t[${fileData}]`;
24
- return `${timestamp} ${header} : ${msg}`;
25
- }
26
- formatError(logData, error) {
27
- const { prefix, fileName, row, column, method } = logData;
28
- const timestamp = this.dateFmt();
29
- const fileData = `${prefix}/${fileName}:${row}:${column}`;
30
- let errorMsg = `Error name="${error.name}" Error message="${error.message}"`;
31
- let header = "[ERROR]";
32
- if (method) header = `${header}\t[${method}]\t[${fileData}]`;
33
- else header = `${header}\t[${fileData}]`;
34
- if (error.cause) errorMsg = `${errorMsg}\n\tError cause="${error.cause}"`;
35
- if (error.stack) errorMsg = `${errorMsg}\n\tStack trace="${error.stack}"`;
36
- return `${timestamp} ${header} : ${errorMsg}`;
37
- }
38
- };
39
- var JSONFormatter = class extends Formatter {
40
- constructor(dateFmt = isoDateTimeFormat) {
41
- super(dateFmt);
42
- }
43
- format(logData) {
44
- const { prefix, level, msg, fileName, row, column, method } = logData;
45
- const timestamp = this.dateFmt();
46
- const levelType = level.toUpperCase();
47
- let position = {};
48
- if (method) position = { method };
49
- position = {
50
- ...position,
51
- fileName,
52
- row,
53
- column
54
- };
55
- return JSON.stringify({
56
- timestamp,
57
- level: levelType,
58
- prefix,
59
- position,
60
- msg
61
- });
62
- }
63
- formatError(logData, error) {
64
- const { prefix, fileName, row, column, method } = logData;
65
- const timestamp = this.dateFmt();
66
- let errorMsg = {
67
- errorName: error.name,
68
- errorMessage: error.message
69
- };
70
- let position = {};
71
- if (method) position = { method };
72
- position = {
73
- ...position,
74
- fileName,
75
- row,
76
- column
77
- };
78
- if (error.cause) errorMsg = {
79
- ...errorMsg,
80
- errorCause: error.cause
81
- };
82
- if (error.stack) errorMsg = {
83
- ...errorMsg,
84
- stackTrace: error.stack
85
- };
86
- return JSON.stringify({
87
- timestamp,
88
- level: "ERROR",
89
- prefix,
90
- position,
91
- msg: errorMsg
92
- });
93
- }
94
- };
95
- function isoDateTimeFormat() {
96
- return (/* @__PURE__ */ new Date()).toISOString();
97
- }
98
- function isoDateFormat() {
99
- const date = isoDateTimeFormat().split("T")[0];
100
- if (!date) return "";
101
- return date;
102
- }
103
- function dmyFormat() {
104
- const isoDate = isoDateFormat();
105
- if (!isoDate) return "";
106
- const info = isoDate.split("-");
107
- return `${info[2]}-${info[1]}-${info[0]}`;
108
- }
109
- function mdyFormat() {
110
- const isoDate = isoDateFormat();
111
- if (!isoDate) return "";
112
- const info = isoDate.split("-");
113
- return `${info[1]}-${info[2]}-${info[0]}`;
114
- }
115
- //#endregion
116
- //#region src/lib/logging/core/index.ts
117
- const PROVIDER_OPTION_DEFAULT = {
118
- formatter: new BaseFormatter(),
119
- level: "debug"
120
- };
121
- const STACK_FRAME_IDX = 1;
122
- var StackData = class {
123
- stack = [];
124
- constructor(fn) {
125
- const oldStackTrace = Error.prepareStackTrace;
126
- const [stackTraceError] = mightThrowSync(() => {
127
- Error.prepareStackTrace = (_, stack) => {
128
- return stack.map((callSite) => {
129
- return {
130
- fileName: callSite.getFileName(),
131
- column: callSite.getColumnNumber(),
132
- row: callSite.getLineNumber(),
133
- functionCall: callSite.getFunctionName()
134
- };
135
- });
136
- };
137
- Error.captureStackTrace(this, fn);
138
- this.stack;
139
- });
140
- Error.prepareStackTrace = oldStackTrace;
141
- if (stackTraceError) this.stack = [];
142
- }
143
- retrieveFrame() {
144
- if (this.stack.length === 0) return void 0;
145
- return this.stack[STACK_FRAME_IDX];
146
- }
147
- };
148
- var AbstractLogger = class {
149
- providers;
150
- prefix;
151
- constructor(prefix, providers) {
152
- this.prefix = prefix;
153
- this.providers = providers;
154
- }
155
- createLogData(level, msg, prefix) {
156
- const logCall = new StackData(this.createLogData).retrieveFrame();
157
- let logData = {
158
- level,
159
- msg,
160
- prefix
161
- };
162
- if (!logCall) return logData;
163
- const { column, fileName, functionCall, row } = logCall;
164
- if (fileName) logData = {
165
- ...logData,
166
- fileName: basename(fileName)
167
- };
168
- if (column) logData = {
169
- ...logData,
170
- column: String(column)
171
- };
172
- if (row) logData = {
173
- ...logData,
174
- row: String(row)
175
- };
176
- if (functionCall) logData = {
177
- ...logData,
178
- method: functionCall
179
- };
180
- return logData;
181
- }
182
- };
183
- var Logger = class extends AbstractLogger {
184
- debug(msg) {
185
- const data = this.createLogData("debug", msg, this.prefix);
186
- this.run(data);
187
- }
188
- info(msg) {
189
- const data = this.createLogData("info", msg, this.prefix);
190
- this.run(data);
191
- }
192
- warning(msg) {
193
- const data = this.createLogData("warning", msg, this.prefix);
194
- this.run(data);
195
- }
196
- error(msg) {
197
- const data = this.createLogData("error", msg, this.prefix);
198
- this.run(data);
199
- }
200
- critical(msg) {
201
- const data = this.createLogData("critical", msg, this.prefix);
202
- this.run(data);
203
- }
204
- run(data) {
205
- for (let i = 0; i < this.providers.length; i++) this.providers[i]?.execute(data);
206
- }
207
- };
208
- //#endregion
209
- //#region src/lib/logging/core/types.ts
210
- const LogLevel = {
211
- debug: 10,
212
- info: 20,
213
- warning: 30,
214
- error: 40,
215
- critical: 50
216
- };
217
- //#endregion
218
- //#region src/lib/logging/provider/index.ts
219
- const DEFAULT_MAX_SIZE = 4 * 1024;
220
- const DurationUnit = {
221
- hour: 1e3 * 60 * 60,
222
- day: 1e3 * 60 * 60 * 24,
223
- week: 1e3 * 60 * 60 * 24 * 7,
224
- month: 1e3 * 60 * 60 * 24 * 7 * 4.345
225
- };
226
- var LoggerProvider = class {
227
- options;
228
- constructor(options = PROVIDER_OPTION_DEFAULT) {
229
- this.options = {
230
- ...PROVIDER_OPTION_DEFAULT,
231
- ...options
232
- };
233
- }
234
- getLogLevel() {
235
- if (!this.options.level) return LogLevel.debug;
236
- return LogLevel[this.options.level];
237
- }
238
- };
239
- const FILE_PROVIDER_OPTION_DEFAULT = {
240
- ...PROVIDER_OPTION_DEFAULT,
241
- policy: { type: "size" }
242
- };
243
- var FileProvider = class extends LoggerProvider {
244
- filePath;
245
- counter;
246
- file;
247
- policy;
248
- constructor(file, options = FILE_PROVIDER_OPTION_DEFAULT) {
249
- super({
250
- formatter: options.formatter ?? PROVIDER_OPTION_DEFAULT.formatter,
251
- level: options.level ?? PROVIDER_OPTION_DEFAULT.level
252
- });
253
- this.policy = options.policy ?? FILE_PROVIDER_OPTION_DEFAULT.policy;
254
- this.filePath = file;
255
- this.counter = 0;
256
- this.file = this.createNewFileName();
257
- }
258
- execute(data) {
259
- if (this.getLogLevel() > LogLevel[data.level]) return;
260
- const [error, formattedMessage] = mightThrowSync(() => {
261
- if (this.isJSONFile()) return JSON.stringify({
262
- timestamp: isoDateTimeFormat(),
263
- level: data.level,
264
- message: data.msg
265
- });
266
- const { formatter } = this.options;
267
- return formatter?.format(data) ?? "";
268
- });
269
- const [fsError] = mightThrowSync(() => {
270
- if (error && error instanceof Error) {
271
- const { formatter } = this.options;
272
- const errorMsg = formatter?.formatError(data, error);
273
- appendFileSync(this.file, `${errorMsg}\n`);
274
- }
275
- if (this.canRollFile()) {
276
- this.counter += 1;
277
- this.file = this.createNewFileName();
278
- }
279
- if (error || !formattedMessage) return;
280
- appendFileSync(this.file, `${formattedMessage}\n`);
281
- });
282
- if (fsError && fsError instanceof Error) throw fsError;
283
- }
284
- canRollFile() {
285
- if (!this.policy) return false;
286
- switch (this.policy.type) {
287
- case "size":
288
- if (this.policy.maxSize) return this.getFileSize() >= this.policy.maxSize;
289
- return this.getFileSize() >= DEFAULT_MAX_SIZE;
290
- case "time": {
291
- if (!existsSync(this.file)) return false;
292
- const { duration, instant } = this.policy;
293
- const { birthtime } = statSync(this.file);
294
- const creationTimeMs = birthtime.getTime();
295
- const currenTimeMs = Date.now();
296
- const diffMs = currenTimeMs - creationTimeMs;
297
- switch (instant) {
298
- case "hour": return Math.floor(diffMs / DurationUnit.hour) >= duration;
299
- case "day": return Math.floor(diffMs / DurationUnit.day) >= duration;
300
- case "week": return Math.floor(diffMs / DurationUnit.week) >= duration;
301
- case "month": {
302
- const currentDate = new Date(currenTimeMs);
303
- const monthsDiff = (currentDate.getFullYear() - birthtime.getFullYear()) * 12 + (currentDate.getMonth() - birthtime.getMonth());
304
- return (currentDate.getDate() >= birthtime.getDate() ? monthsDiff : monthsDiff - 1) >= duration;
305
- }
306
- }
307
- }
308
- }
309
- }
310
- getFileSize() {
311
- if (!existsSync(this.file)) return 0;
312
- const [statError, size] = mightThrowSync(() => {
313
- const { size } = statSync(this.file);
314
- return size;
315
- });
316
- if (statError && statError instanceof Error) return 0;
317
- if (!size) return 0;
318
- return size;
319
- }
320
- isJSONFile() {
321
- return extname(this.filePath) === ".json";
322
- }
323
- createNewFileName() {
324
- const fileName = basename(this.filePath);
325
- const directory = dirname(this.filePath);
326
- if (!existsSync(directory)) mkdirSync(directory, { recursive: true });
327
- const fileInfo = fileName.split(".");
328
- const extension = fileInfo.pop();
329
- return join(directory, [
330
- ...fileInfo,
331
- this.counter,
332
- extension
333
- ].join("."));
334
- }
335
- };
336
- var ConsoleProvider = class extends LoggerProvider {
337
- execute(data) {
338
- const level = this.getLogLevel();
339
- const userLevel = LogLevel[data.level];
340
- if (level > userLevel) return;
341
- const [error, formattedMessage] = mightThrowSync(() => {
342
- const { formatter } = this.options;
343
- return formatter?.format(data) ?? "";
344
- });
345
- if (error && error instanceof Error) {
346
- const { formatter } = this.options;
347
- console.error(formatter?.formatError(data, error));
348
- return;
349
- }
350
- if (!formattedMessage) return;
351
- switch (userLevel) {
352
- case LogLevel.debug:
353
- console.debug(formattedMessage);
354
- break;
355
- case LogLevel.info:
356
- console.info(formattedMessage);
357
- break;
358
- case LogLevel.warning:
359
- console.warn(formattedMessage);
360
- break;
361
- case LogLevel.error:
362
- console.error(formattedMessage);
363
- break;
364
- case LogLevel.critical:
365
- console.error(formattedMessage);
366
- break;
367
- default:
368
- console.debug(formattedMessage);
369
- break;
370
- }
371
- }
372
- };
373
- //#endregion
374
- export { AbstractLogger, BaseFormatter, ConsoleProvider, FileProvider, Formatter, JSONFormatter, LogLevel, Logger, LoggerProvider, dmyFormat, isoDateFormat, isoDateTimeFormat, mdyFormat };
1
+ import{mightThrowSync as e}from"../errors/index.mjs";import{basename as t,dirname as n,extname as r,join as i}from"node:path";import{appendFileSync as a,existsSync as o,mkdirSync as s,statSync as c}from"node:fs";var l=class{dateFmt;constructor(e){this.dateFmt=e}},u=class extends l{constructor(e=f){super(e)}format(e){let{prefix:t,level:n,msg:r,fileName:i,row:a,column:o,method:s}=e,c=this.dateFmt(),l=n.toUpperCase();typeof r==`object`&&(r=JSON.stringify(r));let u=`${t}/${i}:${a}:${o}`,d=`[${l}]`;return d=s?`${d}\t[${s}]\t[${u}]`:`${d}\t[${u}]`,`${c} ${d} : ${r}`}formatError(e,t){let{prefix:n,fileName:r,row:i,column:a,method:o}=e,s=this.dateFmt(),c=`${n}/${r}:${i}:${a}`,l=`Error name="${t.name}" Error message="${t.message}"`,u=`[ERROR]`;return u=o?`${u}\t[${o}]\t[${c}]`:`${u}\t[${c}]`,t.cause&&(l=`${l}\n\tError cause="${t.cause}"`),t.stack&&(l=`${l}\n\tStack trace="${t.stack}"`),`${s} ${u} : ${l}`}},d=class extends l{constructor(e=f){super(e)}format(e){let{prefix:t,level:n,msg:r,fileName:i,row:a,column:o,method:s}=e,c=this.dateFmt(),l=n.toUpperCase(),u={};return s&&(u={method:s}),u={...u,fileName:i,row:a,column:o},JSON.stringify({timestamp:c,level:l,prefix:t,position:u,msg:r})}formatError(e,t){let{prefix:n,fileName:r,row:i,column:a,method:o}=e,s=this.dateFmt(),c={errorName:t.name,errorMessage:t.message},l={};return o&&(l={method:o}),l={...l,fileName:r,row:i,column:a},t.cause&&(c={...c,errorCause:t.cause}),t.stack&&(c={...c,stackTrace:t.stack}),JSON.stringify({timestamp:s,level:`ERROR`,prefix:n,position:l,msg:c})}};function f(){return new Date().toISOString()}function p(){return f().split(`T`)[0]||``}function m(){let e=p();if(!e)return``;let t=e.split(`-`);return`${t[2]}-${t[1]}-${t[0]}`}function h(){let e=p();if(!e)return``;let t=e.split(`-`);return`${t[1]}-${t[2]}-${t[0]}`}const g={formatter:new u,level:`debug`};var _=class{stack=[];constructor(t){let n=Error.prepareStackTrace,[r]=e(()=>{Error.prepareStackTrace=(e,t)=>t.map(e=>({fileName:e.getFileName(),column:e.getColumnNumber(),row:e.getLineNumber(),functionCall:e.getFunctionName()})),Error.captureStackTrace(this,t),this.stack});Error.prepareStackTrace=n,r&&(this.stack=[])}retrieveFrame(){if(this.stack.length!==0)return this.stack[1]}},v=class{providers;prefix;constructor(e,t){this.prefix=e,this.providers=t}createLogData(e,n,r){let i=new _(this.createLogData).retrieveFrame(),a={level:e,msg:n,prefix:r};if(!i)return a;let{column:o,fileName:s,functionCall:c,row:l}=i;return s&&(a={...a,fileName:t(s)}),o&&(a={...a,column:String(o)}),l&&(a={...a,row:String(l)}),c&&(a={...a,method:c}),a}},y=class extends v{debug(e){let t=this.createLogData(`debug`,e,this.prefix);this.run(t)}info(e){let t=this.createLogData(`info`,e,this.prefix);this.run(t)}warning(e){let t=this.createLogData(`warning`,e,this.prefix);this.run(t)}error(e){let t=this.createLogData(`error`,e,this.prefix);this.run(t)}critical(e){let t=this.createLogData(`critical`,e,this.prefix);this.run(t)}run(e){for(let t=0;t<this.providers.length;t++)this.providers[t]?.execute(e)}};const b={debug:10,info:20,warning:30,error:40,critical:50},x={hour:1e3*60*60,day:1e3*60*60*24,week:1e3*60*60*24*7,month:1e3*60*60*24*7*4.345};var S=class{options;constructor(e=g){this.options={...g,...e}}getLogLevel(){return this.options.level?b[this.options.level]:b.debug}};const C={...g,policy:{type:`size`}};var w=class extends S{filePath;counter;file;policy;constructor(e,t=C){super({formatter:t.formatter??g.formatter,level:t.level??g.level}),this.policy=t.policy??C.policy,this.filePath=e,this.counter=0,this.file=this.createNewFileName()}execute(t){if(this.getLogLevel()>b[t.level])return;let[n,r]=e(()=>{if(this.isJSONFile())return JSON.stringify({timestamp:f(),level:t.level,message:t.msg});let{formatter:e}=this.options;return e?.format(t)??``}),[i]=e(()=>{if(n&&n instanceof Error){let{formatter:e}=this.options,r=e?.formatError(t,n);a(this.file,`${r}\n`)}this.canRollFile()&&(this.counter+=1,this.file=this.createNewFileName()),!(n||!r)&&a(this.file,`${r}\n`)});if(i&&i instanceof Error)throw i}canRollFile(){if(!this.policy)return!1;switch(this.policy.type){case`size`:return this.policy.maxSize?this.getFileSize()>=this.policy.maxSize:this.getFileSize()>=4096;case`time`:{if(!o(this.file))return!1;let{duration:e,instant:t}=this.policy,{birthtime:n}=c(this.file),r=n.getTime(),i=Date.now(),a=i-r;switch(t){case`hour`:return Math.floor(a/x.hour)>=e;case`day`:return Math.floor(a/x.day)>=e;case`week`:return Math.floor(a/x.week)>=e;case`month`:{let t=new Date(i),r=(t.getFullYear()-n.getFullYear())*12+(t.getMonth()-n.getMonth());return(t.getDate()>=n.getDate()?r:r-1)>=e}}}}}getFileSize(){if(!o(this.file))return 0;let[t,n]=e(()=>{let{size:e}=c(this.file);return e});return t&&t instanceof Error||!n?0:n}isJSONFile(){return r(this.filePath)===`.json`}createNewFileName(){let e=t(this.filePath),r=n(this.filePath);o(r)||s(r,{recursive:!0});let a=e.split(`.`),c=a.pop();return i(r,[...a,this.counter,c].join(`.`))}},T=class extends S{execute(t){let n=this.getLogLevel(),r=b[t.level];if(n>r)return;let[i,a]=e(()=>{let{formatter:e}=this.options;return e?.format(t)??``});if(i&&i instanceof Error){let{formatter:e}=this.options;console.error(e?.formatError(t,i));return}if(a)switch(r){case b.debug:console.debug(a);break;case b.info:console.info(a);break;case b.warning:console.warn(a);break;case b.error:console.error(a);break;case b.critical:console.error(a);break;default:console.debug(a);break}}};export{v as AbstractLogger,u as BaseFormatter,T as ConsoleProvider,w as FileProvider,l as Formatter,d as JSONFormatter,b as LogLevel,y as Logger,S as LoggerProvider,m as dmyFormat,p as isoDateFormat,f as isoDateTimeFormat,h as mdyFormat};