lemon-core 5.0.0 → 5.0.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.
@@ -9,6 +9,7 @@
9
9
  *
10
10
  * @author Steve Jung <steve@lemoncloud.io>
11
11
  * @date 2026-10-27 v5 B2-c (D40)
12
+ * @date 2026-10-28 v5 B7: `PerfTrace` for the per-request `PERF` lines.
12
13
  *
13
14
  * @copyright (C) 2026 LemonCloud Co Ltd. - All Rights Reserved.
14
15
  */
@@ -33,3 +34,31 @@ export declare const measure: <T>(log: PerfLogger, ns: string, label: string, fn
33
34
  * - a rejection is passed through, and no line is printed.
34
35
  */
35
36
  export declare const measureAsync: <T>(log: PerfLogger, ns: string, label: string, fn: () => Promise<T>) => Promise<T>;
37
+ /** a value of `PerfTrace.line()`: `undefined`, `null` and `''` drop the key. */
38
+ export type PerfValue = string | number | boolean | null | undefined;
39
+ /**
40
+ * class: `PerfTrace`
41
+ * - step marks of one request (v5 B7): each `mark(name)` keeps the ms since the previous mark (or the start).
42
+ * - holds numbers only; the caller prints the line with its own logger.
43
+ */
44
+ export declare class PerfTrace {
45
+ private readonly t0;
46
+ private cursor;
47
+ private readonly $marks;
48
+ constructor();
49
+ /**
50
+ * keep the ms since the previous mark (or t0) as `name`, then move the cursor.
51
+ * @returns the ms of this mark.
52
+ */
53
+ mark(name: string): number;
54
+ /** the ms since t0. */
55
+ elapsed(): number;
56
+ /** a copy of the marks. */
57
+ marks(): Record<string, number>;
58
+ /**
59
+ * build the `key=value` tail in the given key order.
60
+ * - `undefined`, `null` and `''` drop the key; a boolean is `1`/`0`; a number (ms) has one decimal.
61
+ * - pass a number that is not ms (ex: an HTTP status) as a string.
62
+ */
63
+ line(extra: Record<string, PerfValue>): string;
64
+ }
package/dist/lib/perf.js CHANGED
@@ -10,11 +10,12 @@
10
10
  *
11
11
  * @author Steve Jung <steve@lemoncloud.io>
12
12
  * @date 2026-10-27 v5 B2-c (D40)
13
+ * @date 2026-10-28 v5 B7: `PerfTrace` for the per-request `PERF` lines.
13
14
  *
14
15
  * @copyright (C) 2026 LemonCloud Co Ltd. - All Rights Reserved.
15
16
  */
16
17
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.measureAsync = exports.measure = exports.nowMs = void 0;
18
+ exports.PerfTrace = exports.measureAsync = exports.measure = exports.nowMs = void 0;
18
19
  /**
19
20
  * current monotonic time in ms (from `process.hrtime.bigint()`).
20
21
  */
@@ -49,4 +50,63 @@ const measureAsync = async (log, ns, label, fn) => {
49
50
  return res;
50
51
  };
51
52
  exports.measureAsync = measureAsync;
53
+ /**
54
+ * class: `PerfTrace`
55
+ * - step marks of one request (v5 B7): each `mark(name)` keeps the ms since the previous mark (or the start).
56
+ * - holds numbers only; the caller prints the line with its own logger.
57
+ */
58
+ class PerfTrace {
59
+ //* start time (t0), and the cursor of the last mark.
60
+ t0;
61
+ cursor;
62
+ //* marks by name (the insertion order is kept).
63
+ $marks = {};
64
+ //* start the trace now.
65
+ constructor() {
66
+ this.t0 = (0, exports.nowMs)();
67
+ this.cursor = this.t0;
68
+ }
69
+ /**
70
+ * keep the ms since the previous mark (or t0) as `name`, then move the cursor.
71
+ * @returns the ms of this mark.
72
+ */
73
+ mark(name) {
74
+ const now = (0, exports.nowMs)();
75
+ const ms = now - this.cursor;
76
+ this.$marks[name] = ms;
77
+ this.cursor = now;
78
+ return ms;
79
+ }
80
+ /** the ms since t0. */
81
+ elapsed() {
82
+ return (0, exports.nowMs)() - this.t0;
83
+ }
84
+ /** a copy of the marks. */
85
+ marks() {
86
+ return { ...this.$marks };
87
+ }
88
+ /**
89
+ * build the `key=value` tail in the given key order.
90
+ * - `undefined`, `null` and `''` drop the key; a boolean is `1`/`0`; a number (ms) has one decimal.
91
+ * - pass a number that is not ms (ex: an HTTP status) as a string.
92
+ */
93
+ line(extra) {
94
+ //* format one value (or `null` to drop the key).
95
+ const asText = (v) => {
96
+ if (v === undefined || v === null || v === '')
97
+ return null;
98
+ if (typeof v === 'boolean')
99
+ return v ? '1' : '0';
100
+ if (typeof v === 'number')
101
+ return v.toFixed(1);
102
+ return `${v}`;
103
+ };
104
+ return Object.entries(extra || {})
105
+ .map(([k, v]) => [k, asText(v)])
106
+ .filter(([, v]) => v !== null)
107
+ .map(([k, v]) => `${k}=${v}`)
108
+ .join(' ');
109
+ }
110
+ }
111
+ exports.PerfTrace = PerfTrace;
52
112
  //# sourceMappingURL=perf.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"perf.js","sourceRoot":"","sources":["../../src/lib/perf.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAKH;;GAEG;AACI,MAAM,KAAK,GAAG,GAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,CAAC;AAA5D,QAAA,KAAK,SAAuD;AAEzE,0CAA0C;AAC1C,MAAM,IAAI,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,GAAG,CAAC,IAAA,aAAK,GAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AAEvE;;;;;;;;GAQG;AACI,MAAM,OAAO,GAAG,CAAI,GAAe,EAAE,EAAU,EAAE,KAAa,EAAE,EAAW,EAAK,EAAE;IACrF,MAAM,EAAE,GAAG,IAAA,aAAK,GAAE,CAAC;IACnB,MAAM,GAAG,GAAG,EAAE,EAAE,CAAC;IACjB,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC;AACf,CAAC,CAAC;AALW,QAAA,OAAO,WAKlB;AAEF;;;GAGG;AACI,MAAM,YAAY,GAAG,KAAK,EAAK,GAAe,EAAE,EAAU,EAAE,KAAa,EAAE,EAAoB,EAAc,EAAE;IAClH,MAAM,EAAE,GAAG,IAAA,aAAK,GAAE,CAAC;IACnB,MAAM,GAAG,GAAG,MAAM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AO,GAAG,CAAC,EAAE,CAAC;QAClB,CAAC,CAAC;QACF,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;aAC7B,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;aAC7B,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;aAC5B,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACJ;AAtDD,8BAsDC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lemon-core",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Lemon Serverless Micro-Service Platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",