@warlock.js/core 4.0.159 → 4.0.162

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 (29) hide show
  1. package/esm/application/application-config-types.d.ts +27 -0
  2. package/esm/application/application-config-types.d.ts.map +1 -0
  3. package/esm/application/application.d.ts +68 -0
  4. package/esm/application/application.d.ts.map +1 -0
  5. package/esm/application/application.js +94 -0
  6. package/esm/application/application.js.map +1 -0
  7. package/esm/application/index.d.ts +3 -0
  8. package/esm/application/index.d.ts.map +1 -0
  9. package/esm/benchmark/benchmark-snapshots.d.ts +47 -0
  10. package/esm/benchmark/benchmark-snapshots.d.ts.map +1 -0
  11. package/esm/benchmark/benchmark-snapshots.js +77 -0
  12. package/esm/benchmark/benchmark-snapshots.js.map +1 -0
  13. package/esm/benchmark/benchmark.d.ts +25 -0
  14. package/esm/benchmark/benchmark.d.ts.map +1 -0
  15. package/esm/benchmark/benchmark.example.d.ts +2 -0
  16. package/esm/benchmark/benchmark.example.d.ts.map +1 -0
  17. package/esm/benchmark/benchmark.js +120 -0
  18. package/esm/benchmark/benchmark.js.map +1 -0
  19. package/esm/benchmark/channels/console.channel.d.ts +14 -0
  20. package/esm/benchmark/channels/console.channel.d.ts.map +1 -0
  21. package/esm/benchmark/channels/console.channel.js +29 -0
  22. package/esm/benchmark/channels/console.channel.js.map +1 -0
  23. package/esm/benchmark/channels/index.d.ts +3 -0
  24. package/esm/benchmark/channels/index.d.ts.map +1 -0
  25. package/esm/benchmark/channels/noop.channel.d.ts +5 -0
  26. package/esm/benchmark/channels/noop.channel.d.ts.map +1 -0
  27. package/esm/benchmark/channels/noop.channel.js +3 -0
  28. package/esm/benchmark/channels/noop.channel.js.map +1 -0
  29. package/package.json +7 -7
@@ -0,0 +1,27 @@
1
+ export type AppConfigurations = {
2
+ /**
3
+ * App name
4
+ */
5
+ appName?: string;
6
+ /**
7
+ * Default locale code
8
+ *
9
+ * @default en
10
+ */
11
+ localeCode?: string;
12
+ /**
13
+ * Application base URL
14
+ *
15
+ * @default localhost:
16
+ */
17
+ baseUrl?: string;
18
+ /**
19
+ * Application timezone
20
+ */
21
+ timezone?: string;
22
+ /**
23
+ * Locale Codes list
24
+ */
25
+ localeCodes?: string[];
26
+ };
27
+ //# sourceMappingURL=application-config-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-config-types.d.ts","sourceRoot":"","sources":["../../src/application/application-config-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { type Environment } from "../utils/environment";
2
+ export declare class Application {
3
+ /**
4
+ * Project start time regarding the process start time
5
+ */
6
+ static readonly startedAt: Date;
7
+ /**
8
+ * Runtime strategy
9
+ */
10
+ static runtimeStrategy: "production" | "development";
11
+ /**
12
+ * Get framework version
13
+ */
14
+ static get version(): string;
15
+ /**
16
+ * Set the runtime strategy
17
+ */
18
+ static setRuntimeStrategy(strategy: "production" | "development"): void;
19
+ /**
20
+ * Get project uptime in milliseconds
21
+ */
22
+ static get uptime(): number;
23
+ /**
24
+ * Get the current environment
25
+ */
26
+ static get environment(): Environment;
27
+ /**
28
+ * Set the current environment
29
+ */
30
+ static setEnvironment(env: Environment): void;
31
+ /**
32
+ * Check if the application is running in production environment
33
+ */
34
+ static get isProduction(): boolean;
35
+ /**
36
+ * Check if the application is running in development environment
37
+ */
38
+ static get isDevelopment(): boolean;
39
+ /**
40
+ * Check if the application is running in test environment
41
+ */
42
+ static get isTest(): boolean;
43
+ /**
44
+ * Get the root path
45
+ */
46
+ static get rootPath(): string;
47
+ /**
48
+ * Get the src path
49
+ */
50
+ static get srcPath(): string;
51
+ /**
52
+ * Get the app path
53
+ */
54
+ static get appPath(): string;
55
+ /**
56
+ * Get the storage path
57
+ */
58
+ static get storagePath(): string;
59
+ /**
60
+ * Get the uploads path
61
+ */
62
+ static get uploadsPath(): string;
63
+ /**
64
+ * Get the public path
65
+ */
66
+ static get publicPath(): string;
67
+ }
68
+ //# sourceMappingURL=application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../src/application/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIrF,qBAAa,WAAW;IACtB;;OAEG;IACH,gBAAuB,SAAS,OAAkD;IAElF;;OAEG;IACH,OAAc,eAAe,EAAE,YAAY,GAAG,aAAa,CAAC;IAE5D;;OAEG;IACH,WAAkB,OAAO,WAExB;IAED;;OAEG;WACW,kBAAkB,CAAC,QAAQ,EAAE,YAAY,GAAG,aAAa;IAIvE;;OAEG;IACH,WAAkB,MAAM,IAAI,MAAM,CAEjC;IAED;;OAEG;IACH,WAAkB,WAAW,IAAI,WAAW,CAE3C;IAED;;OAEG;WACW,cAAc,CAAC,GAAG,EAAE,WAAW;IAI7C;;OAEG;IACH,WAAkB,YAAY,IAAI,OAAO,CAExC;IAED;;OAEG;IACH,WAAkB,aAAa,IAAI,OAAO,CAEzC;IAED;;OAEG;IACH,WAAkB,MAAM,IAAI,OAAO,CAElC;IAED;;OAEG;IACH,WAAkB,QAAQ,IAAI,MAAM,CAEnC;IAED;;OAEG;IACH,WAAkB,OAAO,IAAI,MAAM,CAElC;IAED;;OAEG;IACH,WAAkB,OAAO,IAAI,MAAM,CAElC;IAED;;OAEG;IACH,WAAkB,WAAW,IAAI,MAAM,CAEtC;IAED;;OAEG;IACH,WAAkB,WAAW,IAAI,MAAM,CAEtC;IAED;;OAEG;IACH,WAAkB,UAAU,IAAI,MAAM,CAErC;CACF"}
@@ -0,0 +1,94 @@
1
+ import {environment,setEnvironment}from'../utils/environment.js';import {getFrameworkVersion}from'../utils/framework-vesion.js';import {rootPath,srcPath,appPath,storagePath,uploadsPath,publicPath}from'../utils/paths.js';class Application {
2
+ /**
3
+ * Project start time regarding the process start time
4
+ */
5
+ static startedAt = new Date(Date.now() - process.uptime() * 1000);
6
+ /**
7
+ * Runtime strategy
8
+ */
9
+ static runtimeStrategy;
10
+ /**
11
+ * Get framework version
12
+ */
13
+ static get version() {
14
+ return getFrameworkVersion();
15
+ }
16
+ /**
17
+ * Set the runtime strategy
18
+ */
19
+ static setRuntimeStrategy(strategy) {
20
+ this.runtimeStrategy = strategy;
21
+ }
22
+ /**
23
+ * Get project uptime in milliseconds
24
+ */
25
+ static get uptime() {
26
+ return process.uptime() * 1000;
27
+ }
28
+ /**
29
+ * Get the current environment
30
+ */
31
+ static get environment() {
32
+ return environment();
33
+ }
34
+ /**
35
+ * Set the current environment
36
+ */
37
+ static setEnvironment(env) {
38
+ setEnvironment(env);
39
+ }
40
+ /**
41
+ * Check if the application is running in production environment
42
+ */
43
+ static get isProduction() {
44
+ return this.environment === "production";
45
+ }
46
+ /**
47
+ * Check if the application is running in development environment
48
+ */
49
+ static get isDevelopment() {
50
+ return this.environment === "development";
51
+ }
52
+ /**
53
+ * Check if the application is running in test environment
54
+ */
55
+ static get isTest() {
56
+ return this.environment === "test";
57
+ }
58
+ /**
59
+ * Get the root path
60
+ */
61
+ static get rootPath() {
62
+ return rootPath();
63
+ }
64
+ /**
65
+ * Get the src path
66
+ */
67
+ static get srcPath() {
68
+ return srcPath();
69
+ }
70
+ /**
71
+ * Get the app path
72
+ */
73
+ static get appPath() {
74
+ return appPath();
75
+ }
76
+ /**
77
+ * Get the storage path
78
+ */
79
+ static get storagePath() {
80
+ return storagePath();
81
+ }
82
+ /**
83
+ * Get the uploads path
84
+ */
85
+ static get uploadsPath() {
86
+ return uploadsPath();
87
+ }
88
+ /**
89
+ * Get the public path
90
+ */
91
+ static get publicPath() {
92
+ return publicPath();
93
+ }
94
+ }export{Application};//# sourceMappingURL=application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.js","sources":["../../src/application/application.ts"],"sourcesContent":[null],"names":[],"mappings":"kOAIa,WAAW,CAAA;AACtB;;AAEG;AACI,IAAA,OAAgB,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;AAElF;;AAEG;IACI,OAAO,eAAe,CAA+B;AAE5D;;AAEG;AACI,IAAA,WAAW,OAAO,GAAA;QACvB,OAAO,mBAAmB,EAAE,CAAC;KAC9B;AAED;;AAEG;IACI,OAAO,kBAAkB,CAAC,QAAsC,EAAA;AACrE,QAAA,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;KACjC;AAED;;AAEG;AACI,IAAA,WAAW,MAAM,GAAA;AACtB,QAAA,OAAO,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;KAChC;AAED;;AAEG;AACI,IAAA,WAAW,WAAW,GAAA;QAC3B,OAAO,WAAW,EAAE,CAAC;KACtB;AAED;;AAEG;IACI,OAAO,cAAc,CAAC,GAAgB,EAAA;QAC3C,cAAc,CAAC,GAAG,CAAC,CAAC;KACrB;AAED;;AAEG;AACI,IAAA,WAAW,YAAY,GAAA;AAC5B,QAAA,OAAO,IAAI,CAAC,WAAW,KAAK,YAAY,CAAC;KAC1C;AAED;;AAEG;AACI,IAAA,WAAW,aAAa,GAAA;AAC7B,QAAA,OAAO,IAAI,CAAC,WAAW,KAAK,aAAa,CAAC;KAC3C;AAED;;AAEG;AACI,IAAA,WAAW,MAAM,GAAA;AACtB,QAAA,OAAO,IAAI,CAAC,WAAW,KAAK,MAAM,CAAC;KACpC;AAED;;AAEG;AACI,IAAA,WAAW,QAAQ,GAAA;QACxB,OAAO,QAAQ,EAAE,CAAC;KACnB;AAED;;AAEG;AACI,IAAA,WAAW,OAAO,GAAA;QACvB,OAAO,OAAO,EAAE,CAAC;KAClB;AAED;;AAEG;AACI,IAAA,WAAW,OAAO,GAAA;QACvB,OAAO,OAAO,EAAE,CAAC;KAClB;AAED;;AAEG;AACI,IAAA,WAAW,WAAW,GAAA;QAC3B,OAAO,WAAW,EAAE,CAAC;KACtB;AAED;;AAEG;AACI,IAAA,WAAW,WAAW,GAAA;QAC3B,OAAO,WAAW,EAAE,CAAC;KACtB;AAED;;AAEG;AACI,IAAA,WAAW,UAAU,GAAA;QAC1B,OAAO,UAAU,EAAE,CAAC;KACrB;"}
@@ -0,0 +1,3 @@
1
+ export * from "./application";
2
+ export * from "./application-config-types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/application/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { BenchmarkErrorResult, BenchmarkSnapshotsOptions, BenchmarkSuccessResult } from "./types";
2
+ export declare class BenchmarkSnapshots {
3
+ private readonly maxSnapshots;
4
+ private readonly capture;
5
+ private readonly snapshots;
6
+ constructor(options?: BenchmarkSnapshotsOptions);
7
+ /**
8
+ * Record a raw result. Called automatically by measure() when a snapshotContainer is set.
9
+ * Respects the `capture` setting — ignores results that don't match.
10
+ *
11
+ * @param result - The success or error result to record.
12
+ *
13
+ * @example
14
+ * snapshots.record(result);
15
+ */
16
+ record(result: BenchmarkSuccessResult<unknown> | BenchmarkErrorResult): void;
17
+ /**
18
+ * Get all snapshots for one operation name.
19
+ *
20
+ * @param name - The operation name.
21
+ * @returns Array of snapshots for the operation.
22
+ *
23
+ * @example
24
+ * snapshots.getSnapshots("db-query");
25
+ */
26
+ getSnapshots(name: string): (BenchmarkSuccessResult<unknown> | BenchmarkErrorResult)[];
27
+ /**
28
+ * Get all snapshots for all tracked operations.
29
+ *
30
+ * @returns A mapping of operation names to their snapshots array.
31
+ *
32
+ * @example
33
+ * snapshots.allSnapshots();
34
+ */
35
+ allSnapshots(): Record<string, (BenchmarkSuccessResult<unknown> | BenchmarkErrorResult)[]>;
36
+ /**
37
+ * Clear snapshots for one or all operations.
38
+ *
39
+ * @param name - Optional operation name. If omitted, clears all snapshots.
40
+ *
41
+ * @example
42
+ * snapshots.reset("db-query");
43
+ * snapshots.reset();
44
+ */
45
+ reset(name?: string): void;
46
+ }
47
+ //# sourceMappingURL=benchmark-snapshots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"benchmark-snapshots.d.ts","sourceRoot":"","sources":["../../src/benchmark/benchmark-snapshots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAGtB;gBAEe,OAAO,CAAC,EAAE,yBAAyB;IAKtD;;;;;;;;OAQG;IACI,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,OAAO,CAAC,GAAG,oBAAoB,GAAG,IAAI;IAkBnF;;;;;;;;OAQG;IACI,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,sBAAsB,CAAC,OAAO,CAAC,GAAG,oBAAoB,CAAC,EAAE;IAI7F;;;;;;;OAOG;IACI,YAAY,IAAI,MAAM,CAC3B,MAAM,EACN,CAAC,sBAAsB,CAAC,OAAO,CAAC,GAAG,oBAAoB,CAAC,EAAE,CAC3D;IAUD;;;;;;;;OAQG;IACI,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;CAOlC"}
@@ -0,0 +1,77 @@
1
+ class BenchmarkSnapshots {
2
+ maxSnapshots;
3
+ capture;
4
+ snapshots = new Map();
5
+ constructor(options) {
6
+ this.maxSnapshots = options?.maxSnapshots ?? 100;
7
+ this.capture = options?.capture ?? "error";
8
+ }
9
+ /**
10
+ * Record a raw result. Called automatically by measure() when a snapshotContainer is set.
11
+ * Respects the `capture` setting — ignores results that don't match.
12
+ *
13
+ * @param result - The success or error result to record.
14
+ *
15
+ * @example
16
+ * snapshots.record(result);
17
+ */
18
+ record(result) {
19
+ if (this.capture === "error" && result.success)
20
+ return;
21
+ if (this.capture === "value" && !result.success)
22
+ return;
23
+ let list = this.snapshots.get(result.name);
24
+ if (!list) {
25
+ list = [];
26
+ this.snapshots.set(result.name, list);
27
+ }
28
+ if (list.length >= this.maxSnapshots && this.maxSnapshots > 0) {
29
+ list.shift(); // Evict oldest
30
+ }
31
+ list.push(result);
32
+ }
33
+ /**
34
+ * Get all snapshots for one operation name.
35
+ *
36
+ * @param name - The operation name.
37
+ * @returns Array of snapshots for the operation.
38
+ *
39
+ * @example
40
+ * snapshots.getSnapshots("db-query");
41
+ */
42
+ getSnapshots(name) {
43
+ return this.snapshots.get(name) ?? [];
44
+ }
45
+ /**
46
+ * Get all snapshots for all tracked operations.
47
+ *
48
+ * @returns A mapping of operation names to their snapshots array.
49
+ *
50
+ * @example
51
+ * snapshots.allSnapshots();
52
+ */
53
+ allSnapshots() {
54
+ const all = {};
55
+ for (const [name, list] of this.snapshots.entries()) {
56
+ all[name] = [...list];
57
+ }
58
+ return all;
59
+ }
60
+ /**
61
+ * Clear snapshots for one or all operations.
62
+ *
63
+ * @param name - Optional operation name. If omitted, clears all snapshots.
64
+ *
65
+ * @example
66
+ * snapshots.reset("db-query");
67
+ * snapshots.reset();
68
+ */
69
+ reset(name) {
70
+ if (name) {
71
+ this.snapshots.delete(name);
72
+ }
73
+ else {
74
+ this.snapshots.clear();
75
+ }
76
+ }
77
+ }export{BenchmarkSnapshots};//# sourceMappingURL=benchmark-snapshots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ben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IjB,MAAM,GAAG,GAA+E,EAAE,CAAC;AAE3F,QAAA,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE;YACnD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACvB,SAAA;AAED,QAAA,OAAO,GAAG,CAAC;KACZ;AAED;;;;;;;;AAQG;AACI,IAAA,KAAK,CAAC,IAAa,EAAA;AACxB,QAAA,IAAI,IAAI,EAAE;AACR,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC7B,SAAA;AAAM,aAAA;AACL,YAAA,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;AACxB,SAAA;KACF;AACF"}
@@ -0,0 +1,25 @@
1
+ import type { BenchmarkErrorResult, BenchmarkOptions, BenchmarkSuccessResult } from "./types";
2
+ /**
3
+ * Measure the execution time of a function and classify its performance.
4
+ *
5
+ * When `enabled` is false, fn() is still called but no timing runs and no hooks fire.
6
+ * A zeroed SuccessResult is returned to keep the return type stable for all callers.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const result = await measure("db-query", () => db.query("SELECT 1"), {
11
+ * latencyRange: { excellent: 100, poor: 500 },
12
+ * onComplete: (r) => metrics.record(r.latency),
13
+ * onError: (r) => logger.error("query failed", r.error),
14
+ * onFinish: (r) => logger.info(`${r.name} took ${r.latency}ms`),
15
+ * });
16
+ *
17
+ * if (isSuccessResult(result)) {
18
+ * console.log(result.value);
19
+ * } else {
20
+ * console.error(result.error);
21
+ * }
22
+ * ```
23
+ */
24
+ export declare function measure<T>(name: string, fn: () => T | Promise<T>, options?: BenchmarkOptions<T>): Promise<BenchmarkSuccessResult<T> | BenchmarkErrorResult>;
25
+ //# sourceMappingURL=benchmark.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"benchmark.d.ts","sourceRoot":"","sources":["../../src/benchmark/benchmark.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAmBjB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAkG3D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=benchmark.example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"benchmark.example.d.ts","sourceRoot":"","sources":["../../src/benchmark/benchmark.example.ts"],"names":[],"mappings":""}
@@ -0,0 +1,120 @@
1
+ import {config}from'../config/config-getter.js';import'../config/config-handlers.js';/**
2
+ * Classifies latency into "excellent", "good", or "poor" based on thresholds.
3
+ *
4
+ * @example
5
+ * latencyState(80, { excellent: 100, poor: 500 }) // "excellent"
6
+ * latencyState(300, { excellent: 100, poor: 500 }) // "good"
7
+ * latencyState(600, { excellent: 100, poor: 500 }) // "poor"
8
+ */
9
+ function latencyState(latency, range) {
10
+ if (latency <= range.excellent)
11
+ return "excellent";
12
+ if (latency >= range.poor)
13
+ return "poor";
14
+ return "good";
15
+ }
16
+ /**
17
+ * Measure the execution time of a function and classify its performance.
18
+ *
19
+ * When `enabled` is false, fn() is still called but no timing runs and no hooks fire.
20
+ * A zeroed SuccessResult is returned to keep the return type stable for all callers.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const result = await measure("db-query", () => db.query("SELECT 1"), {
25
+ * latencyRange: { excellent: 100, poor: 500 },
26
+ * onComplete: (r) => metrics.record(r.latency),
27
+ * onError: (r) => logger.error("query failed", r.error),
28
+ * onFinish: (r) => logger.info(`${r.name} took ${r.latency}ms`),
29
+ * });
30
+ *
31
+ * if (isSuccessResult(result)) {
32
+ * console.log(result.value);
33
+ * } else {
34
+ * console.error(result.error);
35
+ * }
36
+ * ```
37
+ */
38
+ async function measure(name, fn, options) {
39
+ // Fast path: disabled — call fn() and return a zeroed success wrapper.
40
+ // No timing, no hooks. Re-throws if fn() throws.
41
+ if (options?.enabled === false) {
42
+ const value = await fn();
43
+ return {
44
+ name,
45
+ success: true,
46
+ value,
47
+ latency: 0,
48
+ state: "excellent",
49
+ tags: options.tags,
50
+ startedAt: new Date(),
51
+ endedAt: new Date(),
52
+ };
53
+ }
54
+ // Resolve latency range from inline options or global config
55
+ const benchmarkConfig = config.get("benchmark");
56
+ const latencyRange = options?.latencyRange ?? benchmarkConfig?.latencyRange;
57
+ const startedAt = new Date();
58
+ const startTime = performance.now();
59
+ const profiler = options?.profiler ?? benchmarkConfig?.profiler;
60
+ const snapshotContainer = options?.snapshotContainer ?? benchmarkConfig?.snapshotContainer;
61
+ try {
62
+ const value = await fn();
63
+ const endTime = performance.now();
64
+ const latency = Math.round(endTime - startTime);
65
+ const state = latencyRange ? latencyState(latency, latencyRange) : "good";
66
+ const result = {
67
+ name,
68
+ success: true,
69
+ value,
70
+ latency,
71
+ state,
72
+ tags: options?.tags,
73
+ startedAt,
74
+ endedAt: new Date(),
75
+ };
76
+ if (profiler) {
77
+ profiler.record(result);
78
+ }
79
+ if (snapshotContainer) {
80
+ snapshotContainer.record(result);
81
+ }
82
+ options?.onComplete?.(result);
83
+ options?.onFinish?.(result);
84
+ return result;
85
+ }
86
+ catch (thrown) {
87
+ // Decide whether to benchmark this error or just re-throw immediately
88
+ const shouldBenchmark = options?.shouldBenchmarkError
89
+ ? options.shouldBenchmarkError(thrown)
90
+ : true;
91
+ if (!shouldBenchmark) {
92
+ throw thrown;
93
+ }
94
+ // Capture timing even on failure — a 30s timeout is very different from a 2ms crash
95
+ const endTime = performance.now();
96
+ const latency = Math.round(endTime - startTime);
97
+ const state = latencyRange ? latencyState(latency, latencyRange) : "poor";
98
+ // Normalize thrown value to something consistent
99
+ const error = thrown instanceof Error ? thrown : new Error(String(thrown));
100
+ const result = {
101
+ name,
102
+ success: false,
103
+ error,
104
+ latency,
105
+ state,
106
+ tags: options?.tags,
107
+ startedAt,
108
+ endedAt: new Date(),
109
+ };
110
+ if (profiler) {
111
+ profiler.record(result);
112
+ }
113
+ if (snapshotContainer) {
114
+ snapshotContainer.record(result);
115
+ }
116
+ options?.onError?.(result);
117
+ options?.onFinish?.(result);
118
+ return result;
119
+ }
120
+ }export{measure};//# sourceMappingURL=benchmark.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"benchmark.js","sources":["../../src/benchmark/benchmark.ts"],"sourcesContent":[null],"names":[],"mappings":"qFAQA;;;;;;;AAOG;AACH,SAAS,YAAY,CACnB,OAAe,EACf,KAA0C,EAAA;AAE1C,IAAA,IAAI,OAAO,IAAI,KAAK,CAAC,SAAS;AAAE,QAAA,OAAO,WAAW,CAAC;AACnD,IAAA,IAAI,OAAO,IAAI,KAAK,CAAC,IAAI;AAAE,QAAA,OAAO,MAAM,CAAC;AACzC,IAAA,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;AAqBG;AACI,eAAe,OAAO,CAC3B,IAAY,EACZ,EAAwB,EACxB,OAA6B,EAAA;;;AAI7B,IAAA,IAAI,OAAO,EAAE,OAAO,KAAK,KAAK,EAAE;AAC9B,QAAA,MAAM,KAAK,GAAG,MAAM,EAAE,EAAE,CAAC;QACzB,OAAO;YACL,IAAI;AACJ,YAAA,OAAO,EAAE,IAAI;YACb,KAAK;AACL,YAAA,OAAO,EAAE,CAAC;AACV,YAAA,KAAK,EAAE,WAAW;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO,EAAE,IAAI,IAAI,EAAE;SACpB,CAAC;AACH,KAAA;;IAGD,MAAM,eAAe,GAAG,MAAM,CAA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
+ * Pretty-prints a stats table per operation on onFlush().
5
+ *
6
+ * @param stats - Aggregated stats for all tracked operations.
7
+ *
8
+ * @example
9
+ * const channel = new ConsoleChannel();
10
+ * channel.onFlush({ "db-query": { p50: 10, count: 100, ... } });
11
+ */
12
+ onFlush(stats: Record<string, BenchmarkStats>): void;
13
+ }
14
+ //# sourceMappingURL=console.channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.channel.d.ts","sourceRoot":"","sources":["../../../src/benchmark/channels/console.channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEjE,qBAAa,cAAe,YAAW,gBAAgB;IACrD;;;;;;;;OAQG;IACI,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI;CAoB5D"}
@@ -0,0 +1,29 @@
1
+ class ConsoleChannel {
2
+ /**
3
+ * Pretty-prints a stats table per operation on onFlush().
4
+ *
5
+ * @param stats - Aggregated stats for all tracked operations.
6
+ *
7
+ * @example
8
+ * const channel = new ConsoleChannel();
9
+ * channel.onFlush({ "db-query": { p50: 10, count: 100, ... } });
10
+ */
11
+ onFlush(stats) {
12
+ const tableData = {};
13
+ for (const [name, operationStats] of Object.entries(stats)) {
14
+ tableData[name] = {
15
+ "p50 (ms)": operationStats.p50,
16
+ "p90 (ms)": operationStats.p90,
17
+ "p95 (ms)": operationStats.p95,
18
+ "p99 (ms)": operationStats.p99,
19
+ "Avg (ms)": operationStats.avg,
20
+ "Min (ms)": operationStats.min,
21
+ "Max (ms)": operationStats.max,
22
+ "Error Rate": `${(operationStats.errorRate * 100).toFixed(2)}%`,
23
+ Errors: operationStats.errors,
24
+ Count: operationStats.count,
25
+ };
26
+ }
27
+ console.table(tableData);
28
+ }
29
+ }export{ConsoleChannel};//# sourceMappingURL=console.channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.channel.js","sources":["../../../src/benchmark/channels/console.channel.ts"],"sourcesContent":[null],"names":[],"mappings":"MAEa,cAAc,CAAA;AACzB;;;;;;;;AAQG;AACI,IAAA,OAAO,CAAC,KAAqC,EAAA;QAClD,MAAM,SAAS,GAAwB,EAAE,CAAC;AAE1C,QAAA,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC1D,SAAS,CAAC,IAAI,CAAC,GAAG;gBAChB,UAAU,EAAE,cAAc,CAAC,GAAG;gBAC9B,UAAU,EAAE,cAAc,CAAC,GAAG;gBAC9B,UAAU,EAAE,cAAc,CAAC,GAAG;gBAC9B,UAAU,EAAE,cAAc,CAAC,GAAG;gBAC9B,UAAU,EAAE,cAAc,CAAC,GAAG;gBAC9B,UAAU,EAAE,cAAc,CAAC,GAAG;gBAC9B,UAAU,EAAE,cAAc,CAAC,GAAG;AAC9B,gBAAA,YAAY,EAAE,CAAA,EAAG,CAAC,cAAc,CAAC,SAAS,GAAG,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAG,CAAA,CAAA;gBAC/D,MAAM,EAAE,cAAc,CAAC,MAAM;gBAC7B,KAAK,EAAE,cAAc,CAAC,KAAK;aAC5B,CAAC;AACH,SAAA;AAED,QAAA,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;KAC1B;AACF"}
@@ -0,0 +1,3 @@
1
+ export { ConsoleChannel } from "./console.channel";
2
+ export { NoopChannel } from "./noop.channel";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/benchmark/channels/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { BenchmarkChannel } from "../types";
2
+ export declare class NoopChannel implements BenchmarkChannel {
3
+ onFlush(): void;
4
+ }
5
+ //# sourceMappingURL=noop.channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop.channel.d.ts","sourceRoot":"","sources":["../../../src/benchmark/channels/noop.channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,qBAAa,WAAY,YAAW,gBAAgB;IAC3C,OAAO,IAAI,IAAI;CACvB"}
@@ -0,0 +1,3 @@
1
+ class NoopChannel {
2
+ onFlush() { }
3
+ }export{NoopChannel};//# sourceMappingURL=noop.channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop.channel.js","sources":["../../../src/benchmark/channels/noop.channel.ts"],"sourcesContent":[null],"names":[],"mappings":"MAEa,WAAW,CAAA;AACf,IAAA,OAAO,MAAW;AAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warlock.js/core",
3
- "version": "4.0.159",
3
+ "version": "4.0.162",
4
4
  "description": "A robust nodejs framework for building blazing fast applications",
5
5
  "main": "./esm/index.js",
6
6
  "bin": {
@@ -31,12 +31,12 @@
31
31
  "pluralize-esm": "^9.0.5",
32
32
  "@mongez/supportive-is": "^2.0.4",
33
33
  "@mongez/time-wizard": "^1.0.6",
34
- "@warlock.js/auth": "4.0.158",
35
- "@warlock.js/cache": "4.0.158",
36
- "@warlock.js/cascade": "4.0.158",
37
- "@warlock.js/context": "4.0.158",
38
- "@warlock.js/logger": "4.0.158",
39
- "@warlock.js/seal": "4.0.158",
34
+ "@warlock.js/auth": "4.0.162",
35
+ "@warlock.js/cache": "4.0.162",
36
+ "@warlock.js/cascade": "4.0.162",
37
+ "@warlock.js/context": "4.0.162",
38
+ "@warlock.js/logger": "4.0.162",
39
+ "@warlock.js/seal": "4.0.162",
40
40
  "axios": "^1.14.0",
41
41
  "chokidar": "^5.0.0",
42
42
  "dayjs": "^1.11.19",