@adhd/apigen-plugin-logger 0.1.0 → 0.1.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.
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # @adhd/apigen-plugin-logger
2
+
3
+ apigen **Layer plugin** — wraps dispatch with structured request/timing logging. Activate with
4
+ `--use` on any target.
5
+
6
+ Part of [apigen](../../README.md). Driven via [`@adhd/apigen-cli`](../../cli).
7
+
8
+ ```bash
9
+ npx @adhd/apigen-cli run --source ./api.ts --type mcp --use @adhd/apigen-plugin-logger
10
+ ```
11
+
12
+ ```ts
13
+ import { loggerPlugin, makeLoggerPlugin, type LoggerOptions } from '@adhd/apigen-plugin-logger';
14
+ ```
package/index.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function G(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var C={exports:{}};function K(e){try{return JSON.stringify(e)}catch{return'"[Circular]"'}}var Y=J;function J(e,t,r){var s=r&&r.stringify||K,i=1;if(typeof e=="object"&&e!==null){var l=t.length+i;if(l===1)return e;var f=new Array(l);f[0]=s(e);for(var c=1;c<l;c++)f[c]=s(t[c]);return f.join(" ")}if(typeof e!="string")return e;var d=t.length;if(d===0)return e;for(var n="",a=1-i,o=-1,b=e&&e.length||0,u=0;u<b;){if(e.charCodeAt(u)===37&&u+1<b){switch(o=o>-1?o:0,e.charCodeAt(u+1)){case 100:case 102:if(a>=d||t[a]==null)break;o<u&&(n+=e.slice(o,u)),n+=Number(t[a]),o=u+2,u++;break;case 105:if(a>=d||t[a]==null)break;o<u&&(n+=e.slice(o,u)),n+=Math.floor(Number(t[a])),o=u+2,u++;break;case 79:case 111:case 106:if(a>=d||t[a]===void 0)break;o<u&&(n+=e.slice(o,u));var j=typeof t[a];if(j==="string"){n+="'"+t[a]+"'",o=u+2,u++;break}if(j==="function"){n+=t[a].name||"<anonymous>",o=u+2,u++;break}n+=s(t[a]),o=u+2,u++;break;case 115:if(a>=d)break;o<u&&(n+=e.slice(o,u)),n+=String(t[a]),o=u+2,u++;break;case 37:o<u&&(n+=e.slice(o,u)),n+="%",o=u+2,u++,a--;break}++a}++u}return o===-1?e:(o<b&&(n+=e.slice(o)),n)}const B=Y;C.exports=g;const L=ue().console||{},U={mapHttpRequest:S,mapHttpResponse:S,wrapRequestSerializer:F,wrapResponseSerializer:F,wrapErrorSerializer:F,req:S,res:S,err:R,errWithCause:R};function v(e,t){return e==="silent"?1/0:t.levels.values[e]}const A=Symbol("pino.logFuncs"),P=Symbol("pino.hierarchy"),Q={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function I(e,t){const r={logger:t,parent:e[P]};t[P]=r}function X(e,t,r){const s={};t.forEach(i=>{s[i]=r[i]?r[i]:L[i]||L[Q[i]||"log"]||w}),e[A]=s}function Z(e,t){return Array.isArray(e)?e.filter(function(s){return s!=="!stdSerializers.err"}):e===!0?Object.keys(t):!1}function g(e){e=e||{},e.browser=e.browser||{};const t=e.browser.transmit;if(t&&typeof t.send!="function")throw Error("pino: transmit option must have a send function");const r=e.browser.write||L;e.browser.write&&(e.browser.asObject=!0);const s=e.serializers||{},i=Z(e.browser.serialize,s);let l=e.browser.serialize;Array.isArray(e.browser.serialize)&&e.browser.serialize.indexOf("!stdSerializers.err")>-1&&(l=!1);const f=Object.keys(e.customLevels||{}),c=["error","fatal","warn","info","debug","trace"].concat(f);typeof r=="function"&&c.forEach(function(h){r[h]=r}),(e.enabled===!1||e.browser.disabled)&&(e.level="silent");const d=e.level||"info",n=Object.create(r);n.log||(n.log=w),X(n,c,r),I({},n),Object.defineProperty(n,"levelVal",{get:o}),Object.defineProperty(n,"level",{get:b,set:u});const a={transmit:t,serialize:i,asObject:e.browser.asObject,asObjectBindingsOnly:e.browser.asObjectBindingsOnly,formatters:e.browser.formatters,reportCaller:e.browser.reportCaller,levels:c,timestamp:ae(e),messageKey:e.messageKey||"msg",onChild:e.onChild||w};n.levels=ee(e),n.level=d,n.isLevelEnabled=function(h){return this.levels.values[h]?this.levels.values[h]>=this.levels.values[this.level]:!1},n.setMaxListeners=n.getMaxListeners=n.emit=n.addListener=n.on=n.prependListener=n.once=n.prependOnceListener=n.removeListener=n.removeAllListeners=n.listeners=n.listenerCount=n.eventNames=n.write=n.flush=w,n.serializers=s,n._serialize=i,n._stdErrSerialize=l,n.child=function(...h){return j.call(this,a,...h)},t&&(n._logEvent=x());function o(){return v(this.level,this)}function b(){return this._level}function u(h){if(h!=="silent"&&!this.levels.values[h])throw Error("unknown level "+h);this._level=h,y(this,a,n,"error"),y(this,a,n,"fatal"),y(this,a,n,"warn"),y(this,a,n,"info"),y(this,a,n,"debug"),y(this,a,n,"trace"),f.forEach(m=>{y(this,a,n,m)})}function j(h,m,_){if(!m)throw new Error("missing bindings for child Pino");_=_||{},i&&m.serializers&&(_.serializers=m.serializers);const V=_.serializers;if(i&&V){var z=Object.assign({},s,V),M=e.browser.serialize===!0?Object.keys(z):i;delete m.serializers,D([m],M,z,this._stdErrSerialize)}function $(E){this._childLevel=(E._childLevel|0)+1,this.bindings=m,z&&(this.serializers=z,this._serialize=M),t&&(this._logEvent=x([].concat(E._logEvent.bindings,m)))}$.prototype=this;const k=new $(this);return I(this,k),k.child=function(...E){return j.call(this,h,...E)},k.level=_.level||this.level,h.onChild(k),k}return n}function ee(e){const t=e.customLevels||{},r=Object.assign({},g.levels.values,t),s=Object.assign({},g.levels.labels,te(t));return{values:r,labels:s}}function te(e){const t={};return Object.keys(e).forEach(function(r){t[e[r]]=r}),t}g.levels={values:{fatal:60,error:50,warn:40,info:30,debug:20,trace:10},labels:{10:"trace",20:"debug",30:"info",40:"warn",50:"error",60:"fatal"}};g.stdSerializers=U;g.stdTimeFunctions=Object.assign({},{nullTime:q,epochTime:H,unixTime:le,isoTime:ce});function ne(e){const t=[];e.bindings&&t.push(e.bindings);let r=e[P];for(;r.parent;)r=r.parent,r.logger.bindings&&t.push(r.logger.bindings);return t.reverse()}function y(e,t,r,s){if(Object.defineProperty(e,s,{value:v(e.level,r)>v(s,r)?w:r[A][s],writable:!0,enumerable:!0,configurable:!0}),e[s]===w){if(!t.transmit)return;const l=t.transmit.level||e.level,f=v(l,r);if(v(s,r)<f)return}e[s]=ie(e,t,r,s);const i=ne(e);i.length!==0&&(e[s]=re(i,e[s]))}function re(e,t){return function(){return t.apply(this,[...e,...arguments])}}function ie(e,t,r,s){return function(i){return function(){const f=t.timestamp(),c=new Array(arguments.length),d=Object.getPrototypeOf&&Object.getPrototypeOf(this)===L?L:this;for(var n=0;n<c.length;n++)c[n]=arguments[n];var a=!1;if(t.serialize&&(D(c,this._serialize,this.serializers,this._stdErrSerialize),a=!0),t.asObject||t.formatters){const o=se(this,s,c,f,t);if(t.reportCaller&&o&&o.length>0&&o[0]&&typeof o[0]=="object")try{const b=N();b&&(o[0].caller=b)}catch{}i.call(d,...o)}else{if(t.reportCaller)try{const o=N();o&&c.push(o)}catch{}i.apply(d,c)}if(t.transmit){const o=t.transmit.level||e._level,b=v(o,r),u=v(s,r);if(u<b)return;oe(this,{ts:f,methodLevel:s,methodValue:u,transmitLevel:o,transmitValue:r.levels.values[t.transmit.level||e._level],send:t.transmit.send,val:v(e._level,r)},c,a)}}}(e[A][s])}function se(e,t,r,s,i){const{level:l,log:f=o=>o}=i.formatters||{},c=r.slice();let d=c[0];const n={};let a=(e._childLevel|0)+1;if(a<1&&(a=1),s&&(n.time=s),l){const o=l(t,e.levels.values[t]);Object.assign(n,o)}else n.level=e.levels.values[t];if(i.asObjectBindingsOnly){if(d!==null&&typeof d=="object")for(;a--&&typeof c[0]=="object";)Object.assign(n,c.shift());return[f(n),...c]}else{if(d!==null&&typeof d=="object"){for(;a--&&typeof c[0]=="object";)Object.assign(n,c.shift());d=c.length?B(c.shift(),c):void 0}else typeof d=="string"&&(d=B(c.shift(),c));return d!==void 0&&(n[i.messageKey]=d),[f(n)]}}function D(e,t,r,s){for(const i in e)if(s&&e[i]instanceof Error)e[i]=g.stdSerializers.err(e[i]);else if(typeof e[i]=="object"&&!Array.isArray(e[i])&&t)for(const l in e[i])t.indexOf(l)>-1&&l in r&&(e[i][l]=r[l](e[i][l]))}function oe(e,t,r,s=!1){const i=t.send,l=t.ts,f=t.methodLevel,c=t.methodValue,d=t.val,n=e._logEvent.bindings;s||D(r,e._serialize||Object.keys(e.serializers),e.serializers,e._stdErrSerialize===void 0?!0:e._stdErrSerialize),e._logEvent.ts=l,e._logEvent.messages=r.filter(function(a){return n.indexOf(a)===-1}),e._logEvent.level.label=f,e._logEvent.level.value=c,i(f,e._logEvent,d),e._logEvent=x(n)}function x(e){return{ts:0,messages:[],bindings:e||[],level:{label:"",value:0}}}function R(e){const t={type:e.constructor.name,msg:e.message,stack:e.stack};for(const r in e)t[r]===void 0&&(t[r]=e[r]);return t}function ae(e){return typeof e.timestamp=="function"?e.timestamp:e.timestamp===!1?q:H}function S(){return{}}function F(e){return e}function w(){}function q(){return!1}function H(){return Date.now()}function le(){return Math.round(Date.now()/1e3)}function ce(){return new Date(Date.now()).toISOString()}function ue(){function e(t){return typeof t<"u"&&t}try{return typeof globalThis<"u"||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch{return e(self)||e(window)||e(this)||{}}}C.exports.default=g;C.exports.pino=g;function N(){const e=new Error().stack;if(!e)return null;const t=e.split(`
2
- `);for(let r=1;r<t.length;r++){const s=t[r].trim();if(/(^at\s+)?(createWrap|LOG|set\s*\(|asObject|Object\.apply|Function\.apply)/.test(s)||s.indexOf("browser.js")!==-1||s.indexOf("node:internal")!==-1||s.indexOf("node_modules")!==-1)continue;let i=s.match(/\((.*?):(\d+):(\d+)\)/);if(i||(i=s.match(/at\s+(.*?):(\d+):(\d+)/)),i){const l=i[1],f=i[2],c=i[3];return l+":"+f+":"+c}}return null}var fe=C.exports;const p=G(fe);class O{constructor(t){this._inner=t}info(t,r){this._inner.info(t,r)}error(t,r){this._inner.error(t,r)}debug(t,r){this._inner.debug(t,r)}warn(t,r){this._inner.warn(t,r)}get pino(){return this._inner}}function de(e,t){const r=e.ctx.get(O);if(r!==void 0)return r;const s=new O(t.pino.child({op:e.operation.id}));return e.ctx.set(O,s),s}function he(e){const t=e.level??"info",r=typeof e.destination=="string"&&e.destination.length>0,s=!r&&!!process.stderr.isTTY,i=e.format??(s?"pretty":"json");let l;if(i==="pretty")l=p({level:t,transport:{target:"pino-pretty",options:{colorize:!r,translateTime:"SYS:HH:MM:ss.l",ignore:"pid,hostname",...r?{destination:e.destination,mkdir:!0}:{destination:2}}}});else{const f=r?p.destination({dest:e.destination,mkdir:!0,sync:!0}):p.destination(2);l=p({level:t},f)}return new O(l)}const be=new O(p({level:"info"},p.destination(2)));function W(e){return function(r,s){const i=de(r,e),l=r.operation.id,f=Date.now();i.info({op:l},`→ ${l}`);const c=s();function d(n){return n!==null&&typeof n=="object"&&Symbol.asyncIterator in n}return d(c)?async function*(){let a=0;try{for await(const o of c)a++,i.debug({op:l,chunk:a},`chunk ${a}`),yield o;i.info({op:l,ms:Date.now()-f,chunks:a},`← ${l} ok`)}catch(o){throw i.error({op:l,ms:Date.now()-f,err:o},`✗ ${l} stream error`),o}}():c.then(n=>(i.info({op:l,ms:Date.now()-f},`← ${l} ok`),n),n=>{throw i.error({op:l,ms:Date.now()-f,err:n},`✗ ${l} error`),n})}}const T={id:"logger",description:"Layer plugin: wraps every operation with entry/exit/error logging (SPEC §7.2a / §8.1). Seeds Logger into call.ctx for downstream consumers.",optionsSchema:{type:"object",properties:{level:{type:"string",description:"pino log level (trace|debug|info|warn|error|fatal). Default: info.",default:"info"},format:{type:"string",enum:["json","pretty"],description:"Log output format. Default: pretty on a TTY stderr, json otherwise."},destination:{type:"string",description:"File path to write logs to. Default: stderr (fd 2). Never stdout."}}},capabilities:{target:{name:"logger",generate(e,t){return[]}},layer:{layer:W(be)}}};function me(e={}){const t=he(e);return{...T,capabilities:{...T.capabilities,layer:{layer:W(t)}}}}exports.Logger=O;exports.default=T;exports.loggerPlugin=T;exports.makeLoggerPlugin=me;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("pino");class g{constructor(e){this._inner=e}info(e,t){this._inner.info(e,t)}error(e,t){this._inner.error(e,t)}debug(e,t){this._inner.debug(e,t)}warn(e,t){this._inner.warn(e,t)}get pino(){return this._inner}}function m(r,e){const t=r.ctx.get(g);if(t!==void 0)return t;const s=new g(e.pino.child({op:r.operation.id}));return r.ctx.set(g,s),s}function h(r){const e=r.level??"info",t=typeof r.destination=="string"&&r.destination.length>0,s=!t&&!!process.stderr.isTTY,i=r.format??(s?"pretty":"json");let n;if(i==="pretty")n=l({level:e,transport:{target:"pino-pretty",options:{colorize:!t,translateTime:"SYS:HH:MM:ss.l",ignore:"pid,hostname",...t?{destination:r.destination,mkdir:!0}:{destination:2}}}});else{const a=t?l.destination({dest:r.destination,mkdir:!0,sync:!0}):l.destination(2);n=l({level:e},a)}return new g(n)}const w=new g(l({level:"info"},l.destination(2)));function f(r){return function(t,s){const i=m(t,r),n=t.operation.id,a=Date.now();i.info({op:n},`→ ${n}`);const p=s();function y(o){return o!==null&&typeof o=="object"&&Symbol.asyncIterator in o}return y(p)?async function*(){let c=0;try{for await(const u of p)c++,i.debug({op:n,chunk:c},`chunk ${c}`),yield u;i.info({op:n,ms:Date.now()-a,chunks:c},`← ${n} ok`)}catch(u){throw i.error({op:n,ms:Date.now()-a,err:u},`✗ ${n} stream error`),u}}():p.then(o=>(i.info({op:n,ms:Date.now()-a},`← ${n} ok`),o),o=>{throw i.error({op:n,ms:Date.now()-a,err:o},`✗ ${n} error`),o})}}const d={id:"logger",description:"Layer plugin: wraps every operation with entry/exit/error logging (SPEC §7.2a / §8.1). Seeds Logger into call.ctx for downstream consumers.",language:"ts",optionsSchema:{type:"object",properties:{level:{type:"string",description:"pino log level (trace|debug|info|warn|error|fatal). Default: info.",default:"info"},format:{type:"string",enum:["json","pretty"],description:"Log output format. Default: pretty on a TTY stderr, json otherwise."},destination:{type:"string",description:"File path to write logs to. Default: stderr (fd 2). Never stdout."}}},capabilities:{target:{name:"logger",generate(r,e){return[]}},layer:{layer:f(w)}}};function b(r={}){const e=h(r);return{...d,capabilities:{...d.capabilities,layer:{layer:f(e)}}}}exports.Logger=g;exports.default=d;exports.loggerPlugin=d;exports.makeLoggerPlugin=b;
package/index.mjs CHANGED
@@ -1,506 +1,88 @@
1
- function G(e) {
2
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
3
- }
4
- var T = { exports: {} };
5
- function K(e) {
6
- try {
7
- return JSON.stringify(e);
8
- } catch {
9
- return '"[Circular]"';
10
- }
11
- }
12
- var Y = J;
13
- function J(e, t, r) {
14
- var s = r && r.stringify || K, i = 1;
15
- if (typeof e == "object" && e !== null) {
16
- var l = t.length + i;
17
- if (l === 1)
18
- return e;
19
- var f = new Array(l);
20
- f[0] = s(e);
21
- for (var c = 1; c < l; c++)
22
- f[c] = s(t[c]);
23
- return f.join(" ");
24
- }
25
- if (typeof e != "string")
26
- return e;
27
- var d = t.length;
28
- if (d === 0)
29
- return e;
30
- for (var n = "", a = 1 - i, o = -1, b = e && e.length || 0, u = 0; u < b; ) {
31
- if (e.charCodeAt(u) === 37 && u + 1 < b) {
32
- switch (o = o > -1 ? o : 0, e.charCodeAt(u + 1)) {
33
- case 100:
34
- case 102:
35
- if (a >= d || t[a] == null)
36
- break;
37
- o < u && (n += e.slice(o, u)), n += Number(t[a]), o = u + 2, u++;
38
- break;
39
- case 105:
40
- if (a >= d || t[a] == null)
41
- break;
42
- o < u && (n += e.slice(o, u)), n += Math.floor(Number(t[a])), o = u + 2, u++;
43
- break;
44
- case 79:
45
- case 111:
46
- case 106:
47
- if (a >= d || t[a] === void 0)
48
- break;
49
- o < u && (n += e.slice(o, u));
50
- var O = typeof t[a];
51
- if (O === "string") {
52
- n += "'" + t[a] + "'", o = u + 2, u++;
53
- break;
54
- }
55
- if (O === "function") {
56
- n += t[a].name || "<anonymous>", o = u + 2, u++;
57
- break;
58
- }
59
- n += s(t[a]), o = u + 2, u++;
60
- break;
61
- case 115:
62
- if (a >= d)
63
- break;
64
- o < u && (n += e.slice(o, u)), n += String(t[a]), o = u + 2, u++;
65
- break;
66
- case 37:
67
- o < u && (n += e.slice(o, u)), n += "%", o = u + 2, u++, a--;
68
- break;
69
- }
70
- ++a;
71
- }
72
- ++u;
73
- }
74
- return o === -1 ? e : (o < b && (n += e.slice(o)), n);
75
- }
76
- const $ = Y;
77
- T.exports = v;
78
- const L = ue().console || {}, U = {
79
- mapHttpRequest: S,
80
- mapHttpResponse: S,
81
- wrapRequestSerializer: C,
82
- wrapResponseSerializer: C,
83
- wrapErrorSerializer: C,
84
- req: S,
85
- res: S,
86
- err: I,
87
- errWithCause: I
88
- };
89
- function g(e, t) {
90
- return e === "silent" ? 1 / 0 : t.levels.values[e];
91
- }
92
- const A = Symbol("pino.logFuncs"), F = Symbol("pino.hierarchy"), Q = {
93
- error: "log",
94
- fatal: "error",
95
- warn: "error",
96
- info: "log",
97
- debug: "log",
98
- trace: "log"
99
- };
100
- function B(e, t) {
101
- const r = {
102
- logger: t,
103
- parent: e[F]
104
- };
105
- t[F] = r;
106
- }
107
- function X(e, t, r) {
108
- const s = {};
109
- t.forEach((i) => {
110
- s[i] = r[i] ? r[i] : L[i] || L[Q[i] || "log"] || w;
111
- }), e[A] = s;
112
- }
113
- function Z(e, t) {
114
- return Array.isArray(e) ? e.filter(function(s) {
115
- return s !== "!stdSerializers.err";
116
- }) : e === !0 ? Object.keys(t) : !1;
117
- }
118
- function v(e) {
119
- e = e || {}, e.browser = e.browser || {};
120
- const t = e.browser.transmit;
121
- if (t && typeof t.send != "function")
122
- throw Error("pino: transmit option must have a send function");
123
- const r = e.browser.write || L;
124
- e.browser.write && (e.browser.asObject = !0);
125
- const s = e.serializers || {}, i = Z(e.browser.serialize, s);
126
- let l = e.browser.serialize;
127
- Array.isArray(e.browser.serialize) && e.browser.serialize.indexOf("!stdSerializers.err") > -1 && (l = !1);
128
- const f = Object.keys(e.customLevels || {}), c = ["error", "fatal", "warn", "info", "debug", "trace"].concat(f);
129
- typeof r == "function" && c.forEach(function(h) {
130
- r[h] = r;
131
- }), (e.enabled === !1 || e.browser.disabled) && (e.level = "silent");
132
- const d = e.level || "info", n = Object.create(r);
133
- n.log || (n.log = w), X(n, c, r), B({}, n), Object.defineProperty(n, "levelVal", {
134
- get: o
135
- }), Object.defineProperty(n, "level", {
136
- get: b,
137
- set: u
138
- });
139
- const a = {
140
- transmit: t,
141
- serialize: i,
142
- asObject: e.browser.asObject,
143
- asObjectBindingsOnly: e.browser.asObjectBindingsOnly,
144
- formatters: e.browser.formatters,
145
- reportCaller: e.browser.reportCaller,
146
- levels: c,
147
- timestamp: ae(e),
148
- messageKey: e.messageKey || "msg",
149
- onChild: e.onChild || w
150
- };
151
- n.levels = ee(e), n.level = d, n.isLevelEnabled = function(h) {
152
- return this.levels.values[h] ? this.levels.values[h] >= this.levels.values[this.level] : !1;
153
- }, n.setMaxListeners = n.getMaxListeners = n.emit = n.addListener = n.on = n.prependListener = n.once = n.prependOnceListener = n.removeListener = n.removeAllListeners = n.listeners = n.listenerCount = n.eventNames = n.write = n.flush = w, n.serializers = s, n._serialize = i, n._stdErrSerialize = l, n.child = function(...h) {
154
- return O.call(this, a, ...h);
155
- }, t && (n._logEvent = x());
156
- function o() {
157
- return g(this.level, this);
158
- }
159
- function b() {
160
- return this._level;
161
- }
162
- function u(h) {
163
- if (h !== "silent" && !this.levels.values[h])
164
- throw Error("unknown level " + h);
165
- this._level = h, y(this, a, n, "error"), y(this, a, n, "fatal"), y(this, a, n, "warn"), y(this, a, n, "info"), y(this, a, n, "debug"), y(this, a, n, "trace"), f.forEach((m) => {
166
- y(this, a, n, m);
167
- });
168
- }
169
- function O(h, m, j) {
170
- if (!m)
171
- throw new Error("missing bindings for child Pino");
172
- j = j || {}, i && m.serializers && (j.serializers = m.serializers);
173
- const P = j.serializers;
174
- if (i && P) {
175
- var z = Object.assign({}, s, P), V = e.browser.serialize === !0 ? Object.keys(z) : i;
176
- delete m.serializers, D([m], V, z, this._stdErrSerialize);
177
- }
178
- function M(E) {
179
- this._childLevel = (E._childLevel | 0) + 1, this.bindings = m, z && (this.serializers = z, this._serialize = V), t && (this._logEvent = x(
180
- [].concat(E._logEvent.bindings, m)
181
- ));
182
- }
183
- M.prototype = this;
184
- const _ = new M(this);
185
- return B(this, _), _.child = function(...E) {
186
- return O.call(this, h, ...E);
187
- }, _.level = j.level || this.level, h.onChild(_), _;
188
- }
189
- return n;
190
- }
191
- function ee(e) {
192
- const t = e.customLevels || {}, r = Object.assign({}, v.levels.values, t), s = Object.assign({}, v.levels.labels, te(t));
193
- return {
194
- values: r,
195
- labels: s
196
- };
197
- }
198
- function te(e) {
199
- const t = {};
200
- return Object.keys(e).forEach(function(r) {
201
- t[e[r]] = r;
202
- }), t;
203
- }
204
- v.levels = {
205
- values: {
206
- fatal: 60,
207
- error: 50,
208
- warn: 40,
209
- info: 30,
210
- debug: 20,
211
- trace: 10
212
- },
213
- labels: {
214
- 10: "trace",
215
- 20: "debug",
216
- 30: "info",
217
- 40: "warn",
218
- 50: "error",
219
- 60: "fatal"
220
- }
221
- };
222
- v.stdSerializers = U;
223
- v.stdTimeFunctions = Object.assign({}, { nullTime: q, epochTime: H, unixTime: le, isoTime: ce });
224
- function ne(e) {
225
- const t = [];
226
- e.bindings && t.push(e.bindings);
227
- let r = e[F];
228
- for (; r.parent; )
229
- r = r.parent, r.logger.bindings && t.push(r.logger.bindings);
230
- return t.reverse();
231
- }
232
- function y(e, t, r, s) {
233
- if (Object.defineProperty(e, s, {
234
- value: g(e.level, r) > g(s, r) ? w : r[A][s],
235
- writable: !0,
236
- enumerable: !0,
237
- configurable: !0
238
- }), e[s] === w) {
239
- if (!t.transmit)
240
- return;
241
- const l = t.transmit.level || e.level, f = g(l, r);
242
- if (g(s, r) < f)
243
- return;
244
- }
245
- e[s] = ie(e, t, r, s);
246
- const i = ne(e);
247
- i.length !== 0 && (e[s] = re(i, e[s]));
248
- }
249
- function re(e, t) {
250
- return function() {
251
- return t.apply(this, [...e, ...arguments]);
252
- };
253
- }
254
- function ie(e, t, r, s) {
255
- return /* @__PURE__ */ function(i) {
256
- return function() {
257
- const f = t.timestamp(), c = new Array(arguments.length), d = Object.getPrototypeOf && Object.getPrototypeOf(this) === L ? L : this;
258
- for (var n = 0; n < c.length; n++)
259
- c[n] = arguments[n];
260
- var a = !1;
261
- if (t.serialize && (D(c, this._serialize, this.serializers, this._stdErrSerialize), a = !0), t.asObject || t.formatters) {
262
- const o = se(this, s, c, f, t);
263
- if (t.reportCaller && o && o.length > 0 && o[0] && typeof o[0] == "object")
264
- try {
265
- const b = R();
266
- b && (o[0].caller = b);
267
- } catch {
268
- }
269
- i.call(d, ...o);
270
- } else {
271
- if (t.reportCaller)
272
- try {
273
- const o = R();
274
- o && c.push(o);
275
- } catch {
276
- }
277
- i.apply(d, c);
278
- }
279
- if (t.transmit) {
280
- const o = t.transmit.level || e._level, b = g(o, r), u = g(s, r);
281
- if (u < b)
282
- return;
283
- oe(this, {
284
- ts: f,
285
- methodLevel: s,
286
- methodValue: u,
287
- transmitLevel: o,
288
- transmitValue: r.levels.values[t.transmit.level || e._level],
289
- send: t.transmit.send,
290
- val: g(e._level, r)
291
- }, c, a);
292
- }
293
- };
294
- }(e[A][s]);
295
- }
296
- function se(e, t, r, s, i) {
297
- const {
298
- level: l,
299
- log: f = (o) => o
300
- } = i.formatters || {}, c = r.slice();
301
- let d = c[0];
302
- const n = {};
303
- let a = (e._childLevel | 0) + 1;
304
- if (a < 1 && (a = 1), s && (n.time = s), l) {
305
- const o = l(t, e.levels.values[t]);
306
- Object.assign(n, o);
307
- } else
308
- n.level = e.levels.values[t];
309
- if (i.asObjectBindingsOnly) {
310
- if (d !== null && typeof d == "object")
311
- for (; a-- && typeof c[0] == "object"; )
312
- Object.assign(n, c.shift());
313
- return [f(n), ...c];
314
- } else {
315
- if (d !== null && typeof d == "object") {
316
- for (; a-- && typeof c[0] == "object"; )
317
- Object.assign(n, c.shift());
318
- d = c.length ? $(c.shift(), c) : void 0;
319
- } else
320
- typeof d == "string" && (d = $(c.shift(), c));
321
- return d !== void 0 && (n[i.messageKey] = d), [f(n)];
322
- }
323
- }
324
- function D(e, t, r, s) {
325
- for (const i in e)
326
- if (s && e[i] instanceof Error)
327
- e[i] = v.stdSerializers.err(e[i]);
328
- else if (typeof e[i] == "object" && !Array.isArray(e[i]) && t)
329
- for (const l in e[i])
330
- t.indexOf(l) > -1 && l in r && (e[i][l] = r[l](e[i][l]));
331
- }
332
- function oe(e, t, r, s = !1) {
333
- const i = t.send, l = t.ts, f = t.methodLevel, c = t.methodValue, d = t.val, n = e._logEvent.bindings;
334
- s || D(
335
- r,
336
- e._serialize || Object.keys(e.serializers),
337
- e.serializers,
338
- e._stdErrSerialize === void 0 ? !0 : e._stdErrSerialize
339
- ), e._logEvent.ts = l, e._logEvent.messages = r.filter(function(a) {
340
- return n.indexOf(a) === -1;
341
- }), e._logEvent.level.label = f, e._logEvent.level.value = c, i(f, e._logEvent, d), e._logEvent = x(n);
342
- }
343
- function x(e) {
344
- return {
345
- ts: 0,
346
- messages: [],
347
- bindings: e || [],
348
- level: { label: "", value: 0 }
349
- };
350
- }
351
- function I(e) {
352
- const t = {
353
- type: e.constructor.name,
354
- msg: e.message,
355
- stack: e.stack
356
- };
357
- for (const r in e)
358
- t[r] === void 0 && (t[r] = e[r]);
359
- return t;
360
- }
361
- function ae(e) {
362
- return typeof e.timestamp == "function" ? e.timestamp : e.timestamp === !1 ? q : H;
363
- }
364
- function S() {
365
- return {};
366
- }
367
- function C(e) {
368
- return e;
369
- }
370
- function w() {
371
- }
372
- function q() {
373
- return !1;
374
- }
375
- function H() {
376
- return Date.now();
377
- }
378
- function le() {
379
- return Math.round(Date.now() / 1e3);
380
- }
381
- function ce() {
382
- return new Date(Date.now()).toISOString();
383
- }
384
- function ue() {
385
- function e(t) {
386
- return typeof t < "u" && t;
387
- }
388
- try {
389
- return typeof globalThis < "u" || Object.defineProperty(Object.prototype, "globalThis", {
390
- get: function() {
391
- return delete Object.prototype.globalThis, this.globalThis = this;
392
- },
393
- configurable: !0
394
- }), globalThis;
395
- } catch {
396
- return e(self) || e(window) || e(this) || {};
397
- }
398
- }
399
- T.exports.default = v;
400
- T.exports.pino = v;
401
- function R() {
402
- const e = new Error().stack;
403
- if (!e)
404
- return null;
405
- const t = e.split(`
406
- `);
407
- for (let r = 1; r < t.length; r++) {
408
- const s = t[r].trim();
409
- if (/(^at\s+)?(createWrap|LOG|set\s*\(|asObject|Object\.apply|Function\.apply)/.test(s) || s.indexOf("browser.js") !== -1 || s.indexOf("node:internal") !== -1 || s.indexOf("node_modules") !== -1)
410
- continue;
411
- let i = s.match(/\((.*?):(\d+):(\d+)\)/);
412
- if (i || (i = s.match(/at\s+(.*?):(\d+):(\d+)/)), i) {
413
- const l = i[1], f = i[2], c = i[3];
414
- return l + ":" + f + ":" + c;
415
- }
416
- }
417
- return null;
418
- }
419
- var fe = T.exports;
420
- const p = /* @__PURE__ */ G(fe);
421
- class k {
1
+ import c from "pino";
2
+ class l {
422
3
  constructor(t) {
423
4
  this._inner = t;
424
5
  }
425
- info(t, r) {
426
- this._inner.info(t, r);
6
+ info(t, e) {
7
+ this._inner.info(t, e);
427
8
  }
428
- error(t, r) {
429
- this._inner.error(t, r);
9
+ error(t, e) {
10
+ this._inner.error(t, e);
430
11
  }
431
- debug(t, r) {
432
- this._inner.debug(t, r);
12
+ debug(t, e) {
13
+ this._inner.debug(t, e);
433
14
  }
434
- warn(t, r) {
435
- this._inner.warn(t, r);
15
+ warn(t, e) {
16
+ this._inner.warn(t, e);
436
17
  }
437
18
  /** Access the underlying pino logger for advanced usage. */
438
19
  get pino() {
439
20
  return this._inner;
440
21
  }
441
22
  }
442
- function de(e, t) {
443
- const r = e.ctx.get(k);
444
- if (r !== void 0)
445
- return r;
446
- const s = new k(t.pino.child({ op: e.operation.id }));
447
- return e.ctx.set(k, s), s;
23
+ function m(n, t) {
24
+ const e = n.ctx.get(l);
25
+ if (e !== void 0)
26
+ return e;
27
+ const s = new l(t.pino.child({ op: n.operation.id }));
28
+ return n.ctx.set(l, s), s;
448
29
  }
449
- function he(e) {
450
- const t = e.level ?? "info", r = typeof e.destination == "string" && e.destination.length > 0, s = !r && !!process.stderr.isTTY, i = e.format ?? (s ? "pretty" : "json");
451
- let l;
30
+ function h(n) {
31
+ const t = n.level ?? "info", e = typeof n.destination == "string" && n.destination.length > 0, s = !e && !!process.stderr.isTTY, i = n.format ?? (s ? "pretty" : "json");
32
+ let r;
452
33
  if (i === "pretty")
453
- l = p({
34
+ r = c({
454
35
  level: t,
455
36
  transport: {
456
37
  target: "pino-pretty",
457
38
  options: {
458
- colorize: !r,
39
+ colorize: !e,
459
40
  translateTime: "SYS:HH:MM:ss.l",
460
41
  ignore: "pid,hostname",
461
- ...r ? { destination: e.destination, mkdir: !0 } : { destination: 2 }
42
+ ...e ? { destination: n.destination, mkdir: !0 } : { destination: 2 }
462
43
  }
463
44
  }
464
45
  });
465
46
  else {
466
- const f = r ? p.destination({
467
- dest: e.destination,
47
+ const a = e ? c.destination({
48
+ dest: n.destination,
468
49
  mkdir: !0,
469
50
  sync: !0
470
- }) : p.destination(2);
471
- l = p({ level: t }, f);
472
- }
473
- return new k(l);
474
- }
475
- const be = new k(p({ level: "info" }, p.destination(2)));
476
- function W(e) {
477
- return function(r, s) {
478
- const i = de(r, e), l = r.operation.id, f = Date.now();
479
- i.info({ op: l }, `→ ${l}`);
480
- const c = s();
481
- function d(n) {
482
- return n !== null && typeof n == "object" && Symbol.asyncIterator in n;
51
+ }) : c.destination(2);
52
+ r = c({ level: t }, a);
53
+ }
54
+ return new l(r);
55
+ }
56
+ const w = new l(c({ level: "info" }, c.destination(2)));
57
+ function f(n) {
58
+ return function(e, s) {
59
+ const i = m(e, n), r = e.operation.id, a = Date.now();
60
+ i.info({ op: r }, `→ ${r}`);
61
+ const d = s();
62
+ function y(o) {
63
+ return o !== null && typeof o == "object" && Symbol.asyncIterator in o;
483
64
  }
484
- return d(c) ? async function* () {
485
- let a = 0;
65
+ return y(d) ? async function* () {
66
+ let g = 0;
486
67
  try {
487
- for await (const o of c)
488
- a++, i.debug({ op: l, chunk: a }, `chunk ${a}`), yield o;
489
- i.info({ op: l, ms: Date.now() - f, chunks: a }, `← ${l} ok`);
490
- } catch (o) {
491
- throw i.error({ op: l, ms: Date.now() - f, err: o }, `✗ ${l} stream error`), o;
68
+ for await (const u of d)
69
+ g++, i.debug({ op: r, chunk: g }, `chunk ${g}`), yield u;
70
+ i.info({ op: r, ms: Date.now() - a, chunks: g }, `← ${r} ok`);
71
+ } catch (u) {
72
+ throw i.error({ op: r, ms: Date.now() - a, err: u }, `✗ ${r} stream error`), u;
492
73
  }
493
- }() : c.then(
494
- (n) => (i.info({ op: l, ms: Date.now() - f }, `← ${l} ok`), n),
495
- (n) => {
496
- throw i.error({ op: l, ms: Date.now() - f, err: n }, `✗ ${l} error`), n;
74
+ }() : d.then(
75
+ (o) => (i.info({ op: r, ms: Date.now() - a }, `← ${r} ok`), o),
76
+ (o) => {
77
+ throw i.error({ op: r, ms: Date.now() - a, err: o }, `✗ ${r} error`), o;
497
78
  }
498
79
  );
499
80
  };
500
81
  }
501
- const N = {
82
+ const p = {
502
83
  id: "logger",
503
84
  description: "Layer plugin: wraps every operation with entry/exit/error logging (SPEC §7.2a / §8.1). Seeds Logger into call.ctx for downstream consumers.",
85
+ language: "ts",
504
86
  optionsSchema: {
505
87
  type: "object",
506
88
  properties: {
@@ -528,7 +110,7 @@ const N = {
528
110
  // ------------------------------------------------------------------
529
111
  target: {
530
112
  name: "logger",
531
- generate(e, t) {
113
+ generate(n, t) {
532
114
  return [];
533
115
  }
534
116
  },
@@ -542,25 +124,25 @@ const N = {
542
124
  // option control should construct a plugin instance via `makeLoggerPlugin`.
543
125
  // ------------------------------------------------------------------
544
126
  layer: {
545
- layer: W(be)
127
+ layer: f(w)
546
128
  }
547
129
  }
548
130
  };
549
- function me(e = {}) {
550
- const t = he(e);
131
+ function k(n = {}) {
132
+ const t = h(n);
551
133
  return {
552
- ...N,
134
+ ...p,
553
135
  capabilities: {
554
- ...N.capabilities,
136
+ ...p.capabilities,
555
137
  layer: {
556
- layer: W(t)
138
+ layer: f(t)
557
139
  }
558
140
  }
559
141
  };
560
142
  }
561
143
  export {
562
- k as Logger,
563
- N as default,
564
- N as loggerPlugin,
565
- me as makeLoggerPlugin
144
+ l as Logger,
145
+ p as default,
146
+ p as loggerPlugin,
147
+ k as makeLoggerPlugin
566
148
  };
package/lib/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin } from '@adhd/apigen-core';
1
+ import { Plugin } from '@adhd/apigen-core-client';
2
2
  import { Logger as PinoLogger } from 'pino';
3
3
 
4
4
  export interface LoggerOptions {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@adhd/apigen-plugin-logger",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "main": "./index.js",
5
5
  "dependencies": {
6
- "@adhd/apigen-core": "^0.1.0",
7
- "pino": "10.3.1"
6
+ "pino": "10.3.1",
7
+ "@adhd/apigen-core-client": "^0.1.0"
8
8
  },
9
9
  "publishConfig": {
10
10
  "access": "public"