@visulima/pail 4.0.0-alpha.20 → 4.0.0-alpha.22

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 (90) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE.md +841 -6
  3. package/README.md +53 -24
  4. package/dist/error.js +2 -2
  5. package/dist/index.browser.d.ts +16 -5
  6. package/dist/index.browser.js +19 -19
  7. package/dist/index.server.d.ts +30 -5
  8. package/dist/index.server.js +28 -27
  9. package/dist/middleware/elysia.d.ts +5 -4
  10. package/dist/middleware/elysia.js +1 -1
  11. package/dist/middleware/express.d.ts +5 -4
  12. package/dist/middleware/express.js +1 -1
  13. package/dist/middleware/fastify.d.ts +5 -4
  14. package/dist/middleware/fastify.js +1 -1
  15. package/dist/middleware/hono.d.ts +5 -4
  16. package/dist/middleware/hono.js +1 -1
  17. package/dist/middleware/next/handler.d.ts +5 -4
  18. package/dist/middleware/next/handler.js +1 -1
  19. package/dist/middleware/sveltekit.d.ts +5 -4
  20. package/dist/middleware/sveltekit.js +1 -1
  21. package/dist/object-tree.js +2 -2
  22. package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
  23. package/dist/packem_shared/AbstractJsonReporter-C6iu_u9-.js +1 -0
  24. package/dist/packem_shared/JsonReporter-BXktpC__.js +2 -0
  25. package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
  26. package/dist/packem_shared/PailError-CbU1Ogfa.js +5 -0
  27. package/dist/packem_shared/PrettyReporter-DNNseeLK.js +44 -0
  28. package/dist/packem_shared/PrettyReporter-DsHfKOU7.js +5 -0
  29. package/dist/packem_shared/{abstract-json-reporter.d-BAgznjyU.d.ts → abstract-json-reporter.d-wfESoEa-.d.ts} +3 -2
  30. package/dist/packem_shared/abstract-pretty-reporter-Bczvp2Zh.js +57 -0
  31. package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-f9no2VNI.js +25 -0
  32. package/dist/packem_shared/{create-middleware-logger.d-CR3o6VDh.d.ts → create-middleware-logger.d-B-JmQ1Sl.d.ts} +2 -2
  33. package/dist/packem_shared/headers-DH0H2s8W.js +1 -0
  34. package/dist/packem_shared/index-Q1764hvO.js +1 -0
  35. package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
  36. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  37. package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
  38. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  39. package/dist/packem_shared/{types.d-BeLumqgD.d.ts → types.d-bWnqHJKL.d.ts} +2 -37
  40. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  41. package/dist/packem_shared/{wide-event.d-gb2-ks5w.d.ts → wide-event.d-D3ATYpoK.d.ts} +17 -5
  42. package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
  43. package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
  44. package/dist/processor/caller/caller-processor.d.ts +2 -1
  45. package/dist/processor/caller/caller-processor.js +1 -1
  46. package/dist/processor/environment-processor.d.ts +2 -1
  47. package/dist/processor/environment-processor.js +1 -1
  48. package/dist/processor/message-formatter-processor.d.ts +9 -1
  49. package/dist/processor/message-formatter-processor.js +1 -1
  50. package/dist/processor/opentelemetry-processor.d.ts +2 -1
  51. package/dist/processor/opentelemetry-processor.js +1 -1
  52. package/dist/processor/redact-processor.d.ts +41 -2
  53. package/dist/processor/redact-processor.js +1 -1
  54. package/dist/processor/sampling-processor.d.ts +2 -1
  55. package/dist/processor/sampling-processor.js +1 -1
  56. package/dist/reporter/file/json-file-reporter.d.ts +21 -3
  57. package/dist/reporter/file/json-file-reporter.js +2 -2
  58. package/dist/reporter/http/abstract-http-reporter.d.ts +46 -3
  59. package/dist/reporter/http/abstract-http-reporter.js +2 -2
  60. package/dist/reporter/http/http-reporter.d.ts +4 -3
  61. package/dist/reporter/http/http-reporter.edge-light.d.ts +57 -1
  62. package/dist/reporter/http/http-reporter.edge-light.js +2 -2
  63. package/dist/reporter/http/http-reporter.js +1 -1
  64. package/dist/reporter/json/index.browser.d.ts +1 -1
  65. package/dist/reporter/json/index.browser.js +1 -1
  66. package/dist/reporter/json/index.d.ts +6 -4
  67. package/dist/reporter/json/index.js +1 -1
  68. package/dist/reporter/pretty/index.browser.js +1 -1
  69. package/dist/reporter/pretty/index.d.ts +125 -5
  70. package/dist/reporter/pretty/index.js +1 -1
  71. package/dist/reporter/simple/simple-reporter.server.d.ts +87 -5
  72. package/dist/reporter/simple/simple-reporter.server.js +8 -8
  73. package/dist/wide-event.d.ts +4 -3
  74. package/dist/wide-event.js +1 -1
  75. package/package.json +4 -4
  76. package/dist/packem_shared/AbstractJsonReporter-D_Pb6kpB.js +0 -1
  77. package/dist/packem_shared/AbstractJsonReporter-PVC4ONf2.js +0 -1
  78. package/dist/packem_shared/JsonReporter-BEEmb0W4.js +0 -2
  79. package/dist/packem_shared/JsonReporter-CE-lw7R0.js +0 -1
  80. package/dist/packem_shared/PrettyReporter-CDv9n1Fy.js +0 -5
  81. package/dist/packem_shared/PrettyReporter-CuFxJm_o.js +0 -44
  82. package/dist/packem_shared/abstract-pretty-reporter-BpyhtAoN.js +0 -33
  83. package/dist/packem_shared/createPailError-53jAfQ-T.js +0 -5
  84. package/dist/packem_shared/headers-S8WyX-2m.js +0 -1
  85. package/dist/packem_shared/index-Dwp5v97D.js +0 -1
  86. package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +0 -1
  87. package/dist/packem_shared/storage-DHM1EP2P.js +0 -1
  88. package/dist/packem_shared/useLogger-qyZrjy4D.js +0 -1
  89. package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +0 -1
  90. package/dist/packem_shared/write-stream-Dd4_PTcm.js +0 -1
package/README.md CHANGED
@@ -1041,30 +1041,59 @@ When a log entry exceeds `maxLogSize`, a `LogSizeError` is thrown. When a batch
1041
1041
 
1042
1042
  ### Configuration Options
1043
1043
 
1044
- | Option | Type | Default | Description |
1045
- | ------------------------ | ------------------------------------------ | -------------------- | --------------------------------------------- |
1046
- | `url` | `string` | **required** | HTTP endpoint URL |
1047
- | `method` | `string` | `"POST"` | HTTP method |
1048
- | `headers` | `Record<string, string> \| (() => ...)` | `{}` | Request headers (object or function) |
1049
- | `contentType` | `string` | `"application/json"` | Content type for single requests |
1050
- | `batchContentType` | `string` | `"application/json"` | Content type for batch requests |
1051
- | `enableBatchSend` | `boolean` | `true` | Enable automatic batching |
1052
- | `batchSize` | `number` | `100` | Number of logs to batch before sending |
1053
- | `batchSendTimeout` | `number` | `5000` | Timeout (ms) to send batch regardless of size |
1054
- | `batchMode` | `"delimiter" \| "array" \| "field"` | `"delimiter"` | Batch format mode |
1055
- | `batchSendDelimiter` | `string` | `"\n"` | Delimiter for batch entries |
1056
- | `batchFieldName` | `string` | `undefined` | Field name for "field" batch mode |
1057
- | `compression` | `boolean` | `false` | Enable gzip compression |
1058
- | `maxRetries` | `number` | `3` | Maximum retry attempts |
1059
- | `retryDelay` | `number` | `1000` | Base delay between retries (ms) |
1060
- | `respectRateLimit` | `boolean` | `true` | Wait on 429 rate limit responses |
1061
- | `maxLogSize` | `number` | `1048576` | Maximum size per log entry (bytes) |
1062
- | `maxPayloadSize` | `number` | `5242880` | Maximum size per payload (bytes) |
1063
- | `edgeCompat` | `boolean` | `false` | Enable Edge Runtime compatibility |
1064
- | `onError` | `(error: Error) => void` | `undefined` | Error callback |
1065
- | `onDebug` | `(entry: Record<string, unknown>) => void` | `undefined` | Debug callback for log entries |
1066
- | `onDebugRequestResponse` | `(reqRes: {...}) => void` | `undefined` | Debug callback for HTTP requests/responses |
1067
- | `payloadTemplate` | `(data: {...}) => string` | `undefined` | Custom payload formatter |
1044
+ | Option | Type | Default | Description |
1045
+ | ------------------------ | ------------------------------------------ | -------------------- | ---------------------------------------------- |
1046
+ | `url` | `string` | **required** | HTTP endpoint URL |
1047
+ | `method` | `string` | `"POST"` | HTTP method |
1048
+ | `headers` | `Record<string, string> \| (() => ...)` | `{}` | Request headers (object or function) |
1049
+ | `contentType` | `string` | `"application/json"` | Content type for single requests |
1050
+ | `batchContentType` | `string` | `"application/json"` | Content type for batch requests |
1051
+ | `enableBatchSend` | `boolean` | `true` | Enable automatic batching |
1052
+ | `batchSize` | `number` | `100` | Number of logs to batch before sending |
1053
+ | `batchSendTimeout` | `number` | `5000` | Timeout (ms) to send batch regardless of size |
1054
+ | `batchMode` | `"delimiter" \| "array" \| "field"` | `"delimiter"` | Batch format mode |
1055
+ | `batchSendDelimiter` | `string` | `"\n"` | Delimiter for batch entries |
1056
+ | `batchFieldName` | `string` | `undefined` | Field name for "field" batch mode |
1057
+ | `compression` | `boolean` | `false` | Enable gzip compression |
1058
+ | `maxRetries` | `number` | `3` | Maximum retry attempts |
1059
+ | `retryDelay` | `number` | `1000` | Base delay between retries (ms) |
1060
+ | `respectRateLimit` | `boolean` | `true` | Wait on 429 rate limit responses |
1061
+ | `maxLogSize` | `number` | `1048576` | Maximum size per log entry (bytes) |
1062
+ | `maxPayloadSize` | `number` | `5242880` | Maximum size per payload (bytes) |
1063
+ | `maxQueueSize` | `number` | `10000` | Max queued entries before drop-oldest kicks in |
1064
+ | `edgeCompat` | `boolean` | `false` | Enable Edge Runtime compatibility |
1065
+ | `onError` | `(error: Error) => void` | `undefined` | Error callback |
1066
+ | `onDrop` | `(droppedCount: number) => void` | `undefined` | Called when queued entries are dropped |
1067
+ | `onDebug` | `(entry: Record<string, unknown>) => void` | `undefined` | Debug callback for log entries |
1068
+ | `onDebugRequestResponse` | `(reqRes: {...}) => void` | `undefined` | Debug callback for HTTP requests/responses |
1069
+ | `payloadTemplate` | `(data: {...}) => string` | `undefined` | Custom payload formatter |
1070
+
1071
+ ### Flushing & Shutdown
1072
+
1073
+ `HttpReporter` batches entries (up to `batchSize`, or every `batchSendTimeout` ms). Before a
1074
+ short-lived or serverless process exits, call `flush()` (or `close()` / `dispose()`) so the
1075
+ tail of the batch is shipped rather than lost:
1076
+
1077
+ ```typescript
1078
+ const reporter = new HttpReporter({ url: "https://logs.example.com" });
1079
+
1080
+ // ... log ...
1081
+
1082
+ // Drain the queue before exit
1083
+ await reporter.flush();
1084
+ ```
1085
+
1086
+ If the endpoint is unavailable, the queue is capped at `maxQueueSize` entries using a
1087
+ drop-oldest policy, so a sustained outage cannot grow memory without bound. Provide `onDrop`
1088
+ to be notified when entries are dropped.
1089
+
1090
+ `JsonFileReporter` likewise exposes `close()` / `dispose()` to end its rotating-file stream:
1091
+
1092
+ ```typescript
1093
+ process.on("beforeExit", () => {
1094
+ fileReporter.close();
1095
+ });
1096
+ ```
1068
1097
 
1069
1098
  ## Wide Events
1070
1099
 
package/dist/error.js CHANGED
@@ -1,5 +1,5 @@
1
- var h=Object.defineProperty;var e=(i,s)=>h(i,"name",{value:s,configurable:!0});var r=Object.defineProperty,a=e((i,s)=>r(i,"name",{value:s,configurable:!0}),"e");class n extends Error{static{e(this,"n")}static{a(this,"PailError")}status;why;fix;link;constructor(s){const t=typeof s=="string"?{message:s}:s;super(t.message,t.cause===void 0?void 0:{cause:t.cause}),this.name="PailError",this.status=t.status??500,this.why=t.why,this.fix=t.fix,this.link=t.link}toJSON(){const s={message:this.message,name:this.name,status:this.status};return this.why&&(s.why=this.why),this.fix&&(s.fix=this.fix),this.link&&(s.link=this.link),this.stack&&(s.stack=this.stack),this.cause!==void 0&&(s.cause=this.cause instanceof Error?{message:this.cause.message,name:this.cause.name,stack:this.cause.stack}:this.cause),s}toString(){let s=`${this.name} [${String(this.status)}]: ${this.message}`;if(this.why&&(s+=`
1
+ class e extends Error{status;why;fix;link;constructor(s){const t=typeof s=="string"?{message:s}:s;super(t.message,t.cause===void 0?void 0:{cause:t.cause}),this.name="PailError",this.status=t.status??500,this.why=t.why,this.fix=t.fix,this.link=t.link}toJSON(){const s={message:this.message,name:this.name,status:this.status};return this.why&&(s.why=this.why),this.fix&&(s.fix=this.fix),this.link&&(s.link=this.link),this.stack&&(s.stack=this.stack),this.cause!==void 0&&(s.cause=this.cause instanceof Error?{message:this.cause.message,name:this.cause.name,stack:this.cause.stack}:this.cause),s}toString(){let s=`${this.name} [${String(this.status)}]: ${this.message}`;if(this.why&&(s+=`
2
2
  Why: ${this.why}`),this.fix&&(s+=`
3
3
  Fix: ${this.fix}`),this.link&&(s+=`
4
4
  Link: ${this.link}`),this.cause!==void 0){const t=this.cause instanceof Error?this.cause.message:String(this.cause);s+=`
5
- Cause: ${t}`}return s}}const u=a(i=>new n(i),"createPailError");export{n as PailError,u as createPailError};
5
+ Cause: ${t}`}return s}}const a=i=>new e(i);export{e as PailError,a as createPailError};
@@ -1,6 +1,6 @@
1
- import { stringify } from 'safe-stable-stringify';
1
+ import { s as stringify } from "./packem_shared/index.d-T71KjNAr.js";
2
2
  import { C as ConstructorOptions, M as Meta, D as DefaultLogTypes, L as LiteralUnion, a as LoggerTypesConfig, P as Processor, E as ExtendedRfc5424LogLevels, c as Reporter, d as LoggerFunction } from "./packem_shared/types.d-xxE3FOD3.js";
3
- export { type e as DefaultLoggerTypes, type f as LoggerConfiguration, type b as LoggerTypesAwareReporter, type g as StreamAwareReporter } from "./packem_shared/types.d-xxE3FOD3.js";
3
+ export type { e as DefaultLoggerTypes, f as LoggerConfiguration, b as LoggerTypesAwareReporter, g as StreamAwareReporter } from "./packem_shared/types.d-xxE3FOD3.js";
4
4
  import '@visulima/colorize';
5
5
  import '@visulima/interactive-manager';
6
6
  /**
@@ -28,9 +28,6 @@ import '@visulima/interactive-manager';
28
28
  */
29
29
  declare class PailBrowserImpl<T extends string = string, L extends string = string> {
30
30
  #private;
31
- protected timersMap: Map<string, number>;
32
- protected countMap: Map<string, number>;
33
- protected seqTimers: Set<string>;
34
31
  protected readonly lastLog: {
35
32
  count?: number;
36
33
  object?: Meta<L>;
@@ -119,6 +116,20 @@ declare class PailBrowserImpl<T extends string = string, L extends string = stri
119
116
  */
120
117
  wrapException(): void;
121
118
  /**
119
+ * Removes the global exception/rejection handlers installed by {@link wrapException}.
120
+ *
121
+ * Counterpart to `wrapException()` (mirrors `wrapConsole()`/`restoreConsole()`).
122
+ * Safe to call when no handlers are installed.
123
+ * @example
124
+ * ```typescript
125
+ * const logger = createPail();
126
+ * logger.wrapException();
127
+ * // ... later ...
128
+ * logger.restoreException(); // global handlers removed
129
+ * ```
130
+ */
131
+ restoreException(): void;
132
+ /**
122
133
  * Disables all logging output.
123
134
  *
124
135
  * When disabled, all log calls will be silently ignored and no output
@@ -1,19 +1,19 @@
1
- var ce=Object.defineProperty;var g=(o,e)=>ce(o,"name",{value:e,configurable:!0});import{L as ue,a as ge,E as fe}from"./packem_shared/constants-DKfCaSUR.js";import{t as pe}from"./packem_shared/write-console-log-based-on-level-DfD64owL.js";import{s as se,G as he}from"./packem_shared/index-Dwp5v97D.js";import de from"./packem_shared/JsonReporter-CE-lw7R0.js";import{PailError as Ue,createPailError as We}from"./packem_shared/createPailError-53jAfQ-T.js";var ye=Object.defineProperty,k=g((o,e)=>ye(o,"name",{value:e,configurable:!0}),"t$2");function le(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}g(le,"getDefaultExportFromCjs");k(le,"getDefaultExportFromCjs");function me(o){return o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}g(me,"getDefaultExportFromNamespaceIfPresent");k(me,"getDefaultExportFromNamespaceIfPresent");function be(o){return o&&Object.prototype.hasOwnProperty.call(o,"default")&&Object.keys(o).length===1?o.default:o}g(be,"getDefaultExportFromNamespaceIfNotNamed");k(be,"getDefaultExportFromNamespaceIfNotNamed");function ve(o){if(Object.prototype.hasOwnProperty.call(o,"__esModule"))return o;var e=o.default;if(typeof e=="function"){var s=k(g(function r(){var a=!1;try{a=this instanceof r}catch{}return a?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)},"a"),"a");s.prototype=e.prototype}else s={};return Object.defineProperty(s,"__esModule",{value:!0}),Object.keys(o).forEach(function(r){var a=Object.getOwnPropertyDescriptor(o,r);Object.defineProperty(s,r,a.get?a:{enumerable:!0,get:k(function(){return o[r]},"get")})}),s}g(ve,"getAugmentedNamespace");k(ve,"getAugmentedNamespace");var U={exports:{}},ie;function $e(){return ie||(ie=1,(function(o,e){var s=Object.defineProperty,r=g((i,n)=>s(i,"name",{value:n,configurable:!0}),"$");const{hasOwnProperty:a}=Object.prototype,v=Q();v.configure=Q,v.stringify=v,v.default=v,e.stringify=v,e.configure=Q,o.exports=v;const P=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;function u(i){return i.length<5e3&&!P.test(i)?`"${i}"`:JSON.stringify(i)}g(u,"strEscape"),r(u,"strEscape");function L(i,n){if(i.length>200||n)return i.sort(n);for(let h=1;h<i.length;h++){const A=i[h];let j=h;for(;j!==0&&i[j-1]>A;)i[j]=i[j-1],j--;i[j]=A}return i}g(L,"sort"),r(L,"sort");const N=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function _(i){return N.call(i)!==void 0&&i.length!==0}g(_,"isTypedArrayWithEntries"),r(_,"isTypedArrayWithEntries");function T(i,n,h){i.length<h&&(h=i.length);const A=n===","?"":" ";let j=`"0":${A}${i[0]}`;for(let q=1;q<h;q++)j+=`${n}"${q}":${A}${i[q]}`;return j}g(T,"stringifyTypedArray"),r(T,"stringifyTypedArray");function D(i){if(a.call(i,"circularValue")){const n=i.circularValue;if(typeof n=="string")return`"${n}"`;if(n==null)return n;if(n===Error||n===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}g(D,"getCircularValueOption"),r(D,"getCircularValueOption");function H(i){let n;if(a.call(i,"deterministic")&&(n=i.deterministic,typeof n!="boolean"&&typeof n!="function"))throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');return n===void 0?!0:n}g(H,"getDeterministicOption"),r(H,"getDeterministicOption");function Z(i,n){let h;if(a.call(i,n)&&(h=i[n],typeof h!="boolean"))throw new TypeError(`The "${n}" argument must be of type boolean`);return h===void 0?!0:h}g(Z,"getBooleanOption"),r(Z,"getBooleanOption");function W(i,n){let h;if(a.call(i,n)){if(h=i[n],typeof h!="number")throw new TypeError(`The "${n}" argument must be of type number`);if(!Number.isInteger(h))throw new TypeError(`The "${n}" argument must be an integer`);if(h<1)throw new RangeError(`The "${n}" argument must be >= 1`)}return h===void 0?1/0:h}g(W,"getPositiveIntegerOption"),r(W,"getPositiveIntegerOption");function J(i){return i===1?"1 item":`${i} items`}g(J,"getItemCount"),r(J,"getItemCount");function ee(i){const n=new Set;for(const h of i)(typeof h=="string"||typeof h=="number")&&n.add(String(h));return n}g(ee,"getUniqueReplacerSet"),r(ee,"getUniqueReplacerSet");function te(i){if(a.call(i,"strict")){const n=i.strict;if(typeof n!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(n)return h=>{let A=`Object can not safely be stringified. Received type ${typeof h}`;throw typeof h!="function"&&(A+=` (${h.toString()})`),new Error(A)}}}g(te,"getStrictOption"),r(te,"getStrictOption");function Q(i){i={...i};const n=te(i);n&&(i.bigint===void 0&&(i.bigint=!1),"circularValue"in i||(i.circularValue=Error));const h=D(i),A=Z(i,"bigint"),j=H(i),q=typeof j=="function"?j:void 0,C=W(i,"maximumDepth"),$=W(i,"maximumBreadth");function z(x,t,l,d,f,y){let c=t[x];switch(typeof c=="object"&&c!==null&&typeof c.toJSON=="function"&&(c=c.toJSON(x)),c=d.call(t,x,c),typeof c){case"string":return u(c);case"object":{if(c===null)return"null";if(l.indexOf(c)!==-1)return h;let p="",w=",";const O=y;if(Array.isArray(c)){if(c.length===0)return"[]";if(C<l.length+1)return'"[Array]"';l.push(c),f!==""&&(y+=f,p+=`
2
- ${y}`,w=`,
3
- ${y}`);const M=Math.min(c.length,$);let F=0;for(;F<M-1;F++){const Y=z(String(F),c,l,d,f,y);p+=Y!==void 0?Y:"null",p+=w}const I=z(String(F),c,l,d,f,y);if(p+=I!==void 0?I:"null",c.length-1>$){const Y=c.length-$-1;p+=`${w}"... ${J(Y)} not stringified"`}return f!==""&&(p+=`
4
- ${O}`),l.pop(),`[${p}]`}let b=Object.keys(c);const S=b.length;if(S===0)return"{}";if(C<l.length+1)return'"[Object]"';let m="",E="";f!==""&&(y+=f,w=`,
5
- ${y}`,m=" ");const R=Math.min(S,$);j&&!_(c)&&(b=L(b,q)),l.push(c);for(let M=0;M<R;M++){const F=b[M],I=z(F,c,l,d,f,y);I!==void 0&&(p+=`${E}${u(F)}:${m}${I}`,E=w)}if(S>$){const M=S-$;p+=`${E}"...":${m}"${J(M)} not stringified"`,E=w}return f!==""&&E.length>1&&(p=`
6
- ${y}${p}
7
- ${O}`),l.pop(),`{${p}}`}case"number":return isFinite(c)?String(c):n?n(c):"null";case"boolean":return c===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(c);default:return n?n(c):void 0}}g(z,"J"),r(z,"stringifyFnReplacer");function G(x,t,l,d,f,y){switch(typeof t=="object"&&t!==null&&typeof t.toJSON=="function"&&(t=t.toJSON(x)),typeof t){case"string":return u(t);case"object":{if(t===null)return"null";if(l.indexOf(t)!==-1)return h;const c=y;let p="",w=",";if(Array.isArray(t)){if(t.length===0)return"[]";if(C<l.length+1)return'"[Array]"';l.push(t),f!==""&&(y+=f,p+=`
8
- ${y}`,w=`,
9
- ${y}`);const S=Math.min(t.length,$);let m=0;for(;m<S-1;m++){const R=G(String(m),t[m],l,d,f,y);p+=R!==void 0?R:"null",p+=w}const E=G(String(m),t[m],l,d,f,y);if(p+=E!==void 0?E:"null",t.length-1>$){const R=t.length-$-1;p+=`${w}"... ${J(R)} not stringified"`}return f!==""&&(p+=`
10
- ${c}`),l.pop(),`[${p}]`}l.push(t);let O="";f!==""&&(y+=f,w=`,
11
- ${y}`,O=" ");let b="";for(const S of d){const m=G(S,t[S],l,d,f,y);m!==void 0&&(p+=`${b}${u(S)}:${O}${m}`,b=w)}return f!==""&&b.length>1&&(p=`
12
- ${y}${p}
13
- ${c}`),l.pop(),`{${p}}`}case"number":return isFinite(t)?String(t):n?n(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(t);default:return n?n(t):void 0}}g(G,"I"),r(G,"stringifyArrayReplacer");function V(x,t,l,d,f){switch(typeof t){case"string":return u(t);case"object":{if(t===null)return"null";if(typeof t.toJSON=="function"){if(t=t.toJSON(x),typeof t!="object")return V(x,t,l,d,f);if(t===null)return"null"}if(l.indexOf(t)!==-1)return h;const y=f;if(Array.isArray(t)){if(t.length===0)return"[]";if(C<l.length+1)return'"[Array]"';l.push(t),f+=d;let m=`
14
- ${f}`;const E=`,
15
- ${f}`,R=Math.min(t.length,$);let M=0;for(;M<R-1;M++){const I=V(String(M),t[M],l,d,f);m+=I!==void 0?I:"null",m+=E}const F=V(String(M),t[M],l,d,f);if(m+=F!==void 0?F:"null",t.length-1>$){const I=t.length-$-1;m+=`${E}"... ${J(I)} not stringified"`}return m+=`
16
- ${y}`,l.pop(),`[${m}]`}let c=Object.keys(t);const p=c.length;if(p===0)return"{}";if(C<l.length+1)return'"[Object]"';f+=d;const w=`,
17
- ${f}`;let O="",b="",S=Math.min(p,$);_(t)&&(O+=T(t,w,$),c=c.slice(t.length),S-=t.length,b=w),j&&(c=L(c,q)),l.push(t);for(let m=0;m<S;m++){const E=c[m],R=V(E,t[E],l,d,f);R!==void 0&&(O+=`${b}${u(E)}: ${R}`,b=w)}if(p>$){const m=p-$;O+=`${b}"...": "${J(m)} not stringified"`,b=w}return b!==""&&(O=`
18
- ${f}${O}
19
- ${y}`),l.pop(),`{${O}}`}case"number":return isFinite(t)?String(t):n?n(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(t);default:return n?n(t):void 0}}g(V,"V"),r(V,"stringifyIndent");function B(x,t,l){switch(typeof t){case"string":return u(t);case"object":{if(t===null)return"null";if(typeof t.toJSON=="function"){if(t=t.toJSON(x),typeof t!="object")return B(x,t,l);if(t===null)return"null"}if(l.indexOf(t)!==-1)return h;let d="";const f=t.length!==void 0;if(f&&Array.isArray(t)){if(t.length===0)return"[]";if(C<l.length+1)return'"[Array]"';l.push(t);const O=Math.min(t.length,$);let b=0;for(;b<O-1;b++){const m=B(String(b),t[b],l);d+=m!==void 0?m:"null",d+=","}const S=B(String(b),t[b],l);if(d+=S!==void 0?S:"null",t.length-1>$){const m=t.length-$-1;d+=`,"... ${J(m)} not stringified"`}return l.pop(),`[${d}]`}let y=Object.keys(t);const c=y.length;if(c===0)return"{}";if(C<l.length+1)return'"[Object]"';let p="",w=Math.min(c,$);f&&_(t)&&(d+=T(t,",",$),y=y.slice(t.length),w-=t.length,p=","),j&&(y=L(y,q)),l.push(t);for(let O=0;O<w;O++){const b=y[O],S=B(b,t[b],l);S!==void 0&&(d+=`${p}${u(b)}:${S}`,p=",")}if(c>$){const O=c-$;d+=`${p}"...":"${J(O)} not stringified"`}return l.pop(),`{${d}}`}case"number":return isFinite(t)?String(t):n?n(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(t);default:return n?n(t):void 0}}g(B,"N"),r(B,"stringifySimple");function re(x,t,l){if(arguments.length>1){let d="";if(typeof l=="number"?d=" ".repeat(Math.min(l,10)):typeof l=="string"&&(d=l.slice(0,10)),t!=null){if(typeof t=="function")return z("",{"":x},[],t,d,"");if(Array.isArray(t))return G("",x,[],ee(t),d,"")}if(d.length!==0)return V("",x,[],d,"")}return B("",x,[])}return g(re,"M"),r(re,"stringify"),re}g(Q,"configure"),r(Q,"configure")})(U,U.exports)),U.exports}g($e,"requireSafeStableStringify");var we=$e();const Oe=le(we),Se=Oe.configure;var Le=Object.defineProperty,Te=g((o,e)=>Le(o,"name",{value:e,configurable:!0}),"t$1");let xe=class{static{g(this,"a")}static{Te(this,"RawReporter")}log(e){const{context:s=[],message:r,type:a}=e;pe(a.level)(r,...s)}};var je=Object.defineProperty,Ee=g((o,e)=>je(o,"name",{value:e,configurable:!0}),"a");const oe=Ee(o=>o===void 0?[]:Array.isArray(o)?o:[o],"arrayify");var Me=Object.defineProperty,Ae=g((o,e)=>Me(o,"name",{value:e,configurable:!0}),"g");const ne=Ae((o,e)=>{const s={...o};return Object.keys(e).forEach(r=>{s[r]={...s[r],...e[r]}}),s},"mergeTypes");var Pe=Object.defineProperty,K=g((o,e)=>Pe(o,"name",{value:e,configurable:!0}),"d");const Ne=K(o=>{let e=!1;return function(...s){if(!e){e=!0;try{const r=o.apply(this,s);return e=!1,r}catch(r){throw e=!1,r}}}},"preventLoop");class X{static{g(this,"PailBrowserImpl")}static{K(this,"PailBrowserImpl")}timersMap;countMap;seqTimers;lastLog;logLevels;disabled;paused;messageQueue;scopeName;types;longestLabel;processors;generalLogLevel;reporters;throttle;throttleMin;stringify;groups;startTimerMessage;endTimerMessage;rawReporter;force={};constructor(e){this.throttle=e.throttle??1e3,this.throttleMin=e.throttleMin??5;const s=e.parentLongestLabel,r=e.parentTypes,a=e.parentStringify,v=e.parentLogLevels;this.stringify=a??Se({strict:!0}),this.startTimerMessage=e.messages?.timerStart??"Initialized timer...",this.endTimerMessage=e.messages?.timerEnd??"Timer run for:",r&&s?(this.types=r,this.longestLabel=s):(this.types=ne(ue,e.types??{}),this.longestLabel=se(this.types)),this.logLevels=v&&!e.logLevels?v:{...ge,...e.logLevels},this.generalLogLevel=this.#e(e.logLevel),this.reporters=new Set,this.processors=new Set,this.disabled=e.disabled??!1,this.paused=!1,this.messageQueue=[],this.scopeName=oe(e.scope).filter(Boolean),this.timersMap=new Map,this.countMap=new Map,this.groups=[],this.seqTimers=new Set,this.lastLog={},this.logger=Ne(this.logger.bind(this)),this.#t(),Array.isArray(e.reporters)&&this.registerReporters(e.reporters),this.rawReporter=this.extendReporter(e.rawReporter??new xe),Array.isArray(e.processors)&&this.registerProcessors(e.processors)}#t(){for(const e in this.types)this[e]=this.logger.bind(this,e,!1,!1);for(const e in this.types)this.force[e]=this.logger.bind(this,e,!1,!0);this.raw=this.raw.bind(this)}wrapConsole(){for(const e in this.types)console[`__${e}`]||(console[`__${e}`]=console[e]),console[e]=this[e]}restoreConsole(){for(const e in this.types)console[`__${e}`]&&(console[e]=console[`__${e}`],delete console[`__${e}`])}wrapException(){process.on("uncaughtException",e=>{this.error(e)}),process.on("unhandledRejection",e=>{this.error(e)})}disable(){this.disabled=!0}enable(){this.disabled=!1}isEnabled(){return!this.disabled}pause(){this.paused=!0}resume(){this.paused=!1;const e=this.messageQueue.splice(0);for(let s=0;s<e.length;s+=1){const{messageObject:r,raw:a,type:v}=e[s];this.logger(v,a,!1,...r)}}scope(...e){if(e.length===0)throw new Error("No scope name was defined.");return this.scopeName=e.flat(),this}unscope(){this.scopeName=[]}child(e){const s=e?.types!==void 0,r=s?ne(this.types,e.types):this.types,a=e?.reporters??[],v=a.length>0?[...this.reporters,...a]:[...this.reporters],P=e?.processors??[],u=P.length>0?[...this.processors,...P]:[...this.processors],L=e?.logLevels?{...this.logLevels,...e.logLevels}:this.logLevels;let N;if(e?.scope){const D=oe(e.scope).filter(Boolean);N=this.scopeName.length>0?[...this.scopeName,...D]:D}else N=this.scopeName.length>0?this.scopeName:[];const _=e?.messages?{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage,...e.messages}:{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage},T={disabled:e?.disabled??this.disabled,logLevel:e?.logLevel??this.generalLogLevel,logLevels:L,messages:_,processors:u,rawReporter:e?.rawReporter??this.rawReporter,reporters:v,scope:N,throttle:e?.throttle??this.throttle,throttleMin:e?.throttleMin??this.throttleMin};return s?(T.parentTypes=r,T.parentLongestLabel=se(r)):(T.parentTypes=this.types,T.parentLongestLabel=this.longestLabel),e?.logLevels||(T.parentLogLevels=this.logLevels),e?.messages||(T.parentMessages={timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage}),T.parentStringify=this.stringify,new X(T)}time(e="default"){this.seqTimers.has(e)?this.logger("warn",!1,!1,{message:`Timer '${e}' already exists`,prefix:e}):(this.seqTimers.add(e),this.timersMap.set(e,Date.now()),this.logger("start",!1,!1,{message:this.startTimerMessage,prefix:e}))}timeLog(e,...s){if(!e&&this.seqTimers.size>0&&(e=[...this.seqTimers].pop()),e&&this.timersMap.has(e)){const r=Date.now()-this.timersMap.get(e);this.logger("info",!1,!1,{context:s,message:r<1e3?`${String(r)} ms`:`${(r/1e3).toFixed(2)} s`,prefix:e})}else this.logger("warn",!1,!1,{context:s,message:"Timer not found",prefix:e})}timeEnd(e){if(!e&&this.seqTimers.size>0&&(e=[...this.seqTimers].pop()),e&&this.timersMap.has(e)){const s=Date.now()-this.timersMap.get(e);this.timersMap.delete(e),this.logger("stop",!1,!1,{message:`${this.endTimerMessage} ${s<1e3?`${String(s)} ms`:`${(s/1e3).toFixed(2)} s`}`,prefix:e})}else this.logger("warn",!1,!1,{message:"Timer not found",prefix:e})}group(e="console.group"){globalThis.window===void 0?this.groups.push(e):console.group(e)}groupEnd(){globalThis.window===void 0?this.groups.pop():console.groupEnd()}count(e="default"){const s=this.countMap.get(e)??0;this.countMap.set(e,s+1),this.logger("log",!1,!1,{message:`${e}: ${String(s+1)}`,prefix:e})}countReset(e="default"){this.countMap.has(e)?this.countMap.delete(e):this.logger("warn",!1,!1,{message:`Count for ${e} does not exist`,prefix:e})}clear(){console.clear()}raw(e,...s){this.disabled||this.logger("log",!0,!1,{context:s,message:e})}extendReporter(e){return typeof e.setLoggerTypes=="function"&&e.setLoggerTypes(this.types),typeof e.setStringify=="function"&&e.setStringify(this.stringify),e}registerReporters(e){for(let s=0;s<e.length;s+=1)this.reporters.add(this.extendReporter(e[s]))}registerProcessors(e){for(let s=0;s<e.length;s+=1){const r=e[s];typeof r.setStringify=="function"&&r.setStringify(this.stringify),this.processors.add(r)}}#r(e,s){if(s)this.rawReporter.log(Object.freeze(e));else for(const r of this.reporters)r.log(Object.freeze(e))}#e(e){return e&&this.logLevels[e]?e:"debug"}#s(e,s,...r){const a={badge:void 0,context:void 0,error:void 0,label:void 0,message:fe,prefix:void 0,repeated:void 0,scope:void 0,suffix:void 0};if(a.type={level:s.logLevel,name:e},a.groups=this.groups,a.scope=this.scopeName,a.date=new Date,r.length>0&&r[0]instanceof Error)a.error=r[0],r.length>1&&(a.context=r.slice(1));else if(r.length>0&&typeof r[0]=="object"&&r[0]!==null&&"message"in r[0]){const{context:v,message:P,prefix:u,suffix:L}=r[0];if(v&&(a.context=v),u&&(a.prefix=u),L&&(a.suffix=L),a.message=P,r.length>1){const N=r.slice(1);a.context?a.context=Array.isArray(a.context)?[...a.context,...N]:[a.context,...N]:a.context=N}}else r.length>1?(a.message=r[0],a.context=r.slice(1)):r.length===1?a.message=r[0]:a.message=void 0;return s.logLevel==="trace"&&(a.traceError=new Error("Trace")),s.badge&&(a.badge=s.badge),s.label&&(a.label=s.label),a}logger(e,s,r,...a){if(this.disabled)return;if(this.paused){this.messageQueue.push({messageObject:a,raw:s,type:e});return}const v=this.types[e],P=this.#e(v.logLevel);if(r||this.logLevels[P]>=this.logLevels[this.generalLogLevel]){let u=this.#s(e,v,...a);const L=K((_=!1)=>{const T=(this.lastLog.count??0)-this.throttleMin;if(this.lastLog.object&&T>0){const D={...this.lastLog.object};T>1&&(D.repeated=T),this.#r(D,s),this.lastLog.count=1}if(_){for(const D of this.processors)u={...D.process(u)};if(u.dropped===!0)return;this.lastLog.object=u;try{this.lastLog.signature=JSON.stringify([u.label,u.scope,u.type,u.message,u.prefix,u.suffix,u.context])}catch{this.lastLog.signature=void 0}this.#r(u,s)}},"resolveLog");clearTimeout(this.lastLog.timeout);const N=this.lastLog.time&&u.date?new Date(u.date).getTime()-this.lastLog.time.getTime():0;if(this.lastLog.time=new Date(u.date),N<this.throttle)try{const _=JSON.stringify([u.label,u.scope,u.type,u.message,u.prefix,u.suffix,u.context]);if(this.lastLog.object&&_===this.lastLog.signature&&(this.lastLog.count=(this.lastLog.count??0)+1,this.lastLog.count>this.throttleMin)){this.lastLog.timeout=setTimeout(L,this.throttle);return}}catch{}L(!0)}}}const Re=X;var _e=Object.defineProperty,ae=g((o,e)=>_e(o,"name",{value:e,configurable:!0}),"s");class De{static{g(this,"p")}static{ae(this,"MessageFormatterProcessor")}#t;#r;#e;constructor(e={}){this.#r=e.formatters}setStringify(e){this.#t=e}process(e){this.#e===void 0&&(this.#e=he({formatters:this.#r,stringify:ae(r=>this.#t?this.#t(r):JSON.stringify(r),"stringify")}));const s=this.#e;return e.message!==void 0&&(e.message=this.#s(s,e.message,e.context??[])),e}#s(e,s,r=[]){if(typeof s=="string")return e(s,r);if(typeof s=="object"&&s!==null){const a=s,v=Object.keys(a);for(let P=0;P<v.length;P+=1){const u=v[P],L=a[u];(typeof L=="string"||Array.isArray(L)||typeof L=="object")&&(a[u]=this.#s(e,L,r))}}return s}}var Fe=Object.defineProperty,Ie=g((o,e)=>Fe(o,"name",{value:e,configurable:!0}),"e");const Je=Ie(o=>new Re({processors:[new De],reporters:[new de],...o}),"createPail"),Ge=Je();export{Ue as PailError,Je as createPail,We as createPailError,Ge as pail};
1
+ import{a as se,E as re,L as ie}from"./packem_shared/constants-DKfCaSUR.js";import{t as oe}from"./packem_shared/write-console-log-based-on-level-BqjxV016.js";import{g as X,O as ne}from"./packem_shared/index-Q1764hvO.js";import le from"./packem_shared/JsonReporter-bmem9lcg.js";import{PailError as xe,createPailError as Te}from"./packem_shared/PailError-CbU1Ogfa.js";var Y={exports:{}},H;function ae(){return H||(H=1,(function(x,e){const{hasOwnProperty:s}=Object.prototype,r=U();r.configure=U,r.stringify=r,r.default=r,e.stringify=r,e.configure=U,x.exports=r;const a=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;function y(i){return i.length<5e3&&!a.test(i)?`"${i}"`:JSON.stringify(i)}function S(i,o){if(i.length>200||o)return i.sort(o);for(let h=1;h<i.length;h++){const N=i[h];let E=h;for(;E!==0&&i[E-1]>N;)i[E]=i[E-1],E--;i[E]=N}return i}const c=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function $(i){return c.call(i)!==void 0&&i.length!==0}function T(i,o,h){i.length<h&&(h=i.length);const N=o===","?"":" ";let E=`"0":${N}${i[0]}`;for(let D=1;D<h;D++)E+=`${o}"${D}":${N}${i[D]}`;return E}function k(i){if(s.call(i,"circularValue")){const o=i.circularValue;if(typeof o=="string")return`"${o}"`;if(o==null)return o;if(o===Error||o===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}function A(i){let o;if(s.call(i,"deterministic")&&(o=i.deterministic,typeof o!="boolean"&&typeof o!="function"))throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');return o===void 0?!0:o}function F(i,o){let h;if(s.call(i,o)&&(h=i[o],typeof h!="boolean"))throw new TypeError(`The "${o}" argument must be of type boolean`);return h===void 0?!0:h}function C(i,o){let h;if(s.call(i,o)){if(h=i[o],typeof h!="number")throw new TypeError(`The "${o}" argument must be of type number`);if(!Number.isInteger(h))throw new TypeError(`The "${o}" argument must be an integer`);if(h<1)throw new RangeError(`The "${o}" argument must be >= 1`)}return h===void 0?1/0:h}function R(i){return i===1?"1 item":`${i} items`}function I(i){const o=new Set;for(const h of i)(typeof h=="string"||typeof h=="number")&&o.add(String(h));return o}function ee(i){if(s.call(i,"strict")){const o=i.strict;if(typeof o!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(o)return h=>{let N=`Object can not safely be stringified. Received type ${typeof h}`;throw typeof h!="function"&&(N+=` (${h.toString()})`),new Error(N)}}}function U(i){i={...i};const o=ee(i);o&&(i.bigint===void 0&&(i.bigint=!1),"circularValue"in i||(i.circularValue=Error));const h=k(i),N=F(i,"bigint"),E=A(i),D=typeof E=="function"?E:void 0,V=C(i,"maximumDepth"),b=C(i,"maximumBreadth");function q(O,t,n,f,g,p){let l=t[O];switch(typeof l=="object"&&l!==null&&typeof l.toJSON=="function"&&(l=l.toJSON(O)),l=f.call(t,O,l),typeof l){case"string":return y(l);case"object":{if(l===null)return"null";if(n.indexOf(l)!==-1)return h;let u="",v=",";const w=p;if(Array.isArray(l)){if(l.length===0)return"[]";if(V<n.length+1)return'"[Array]"';n.push(l),g!==""&&(p+=g,u+=`
2
+ ${p}`,v=`,
3
+ ${p}`);const j=Math.min(l.length,b);let _=0;for(;_<j-1;_++){const G=q(String(_),l,n,f,g,p);u+=G!==void 0?G:"null",u+=v}const J=q(String(_),l,n,f,g,p);if(u+=J!==void 0?J:"null",l.length-1>b){const G=l.length-b-1;u+=`${v}"... ${R(G)} not stringified"`}return g!==""&&(u+=`
4
+ ${w}`),n.pop(),`[${u}]`}let m=Object.keys(l);const L=m.length;if(L===0)return"{}";if(V<n.length+1)return'"[Object]"';let d="",M="";g!==""&&(p+=g,v=`,
5
+ ${p}`,d=" ");const P=Math.min(L,b);E&&!$(l)&&(m=S(m,D)),n.push(l);for(let j=0;j<P;j++){const _=m[j],J=q(_,l,n,f,g,p);J!==void 0&&(u+=`${M}${y(_)}:${d}${J}`,M=v)}if(L>b){const j=L-b;u+=`${M}"...":${d}"${R(j)} not stringified"`,M=v}return g!==""&&M.length>1&&(u=`
6
+ ${p}${u}
7
+ ${w}`),n.pop(),`{${u}}`}case"number":return isFinite(l)?String(l):o?o(l):"null";case"boolean":return l===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(l);default:return o?o(l):void 0}}function Q(O,t,n,f,g,p){switch(typeof t=="object"&&t!==null&&typeof t.toJSON=="function"&&(t=t.toJSON(O)),typeof t){case"string":return y(t);case"object":{if(t===null)return"null";if(n.indexOf(t)!==-1)return h;const l=p;let u="",v=",";if(Array.isArray(t)){if(t.length===0)return"[]";if(V<n.length+1)return'"[Array]"';n.push(t),g!==""&&(p+=g,u+=`
8
+ ${p}`,v=`,
9
+ ${p}`);const L=Math.min(t.length,b);let d=0;for(;d<L-1;d++){const P=Q(String(d),t[d],n,f,g,p);u+=P!==void 0?P:"null",u+=v}const M=Q(String(d),t[d],n,f,g,p);if(u+=M!==void 0?M:"null",t.length-1>b){const P=t.length-b-1;u+=`${v}"... ${R(P)} not stringified"`}return g!==""&&(u+=`
10
+ ${l}`),n.pop(),`[${u}]`}n.push(t);let w="";g!==""&&(p+=g,v=`,
11
+ ${p}`,w=" ");let m="";for(const L of f){const d=Q(L,t[L],n,f,g,p);d!==void 0&&(u+=`${m}${y(L)}:${w}${d}`,m=v)}return g!==""&&m.length>1&&(u=`
12
+ ${p}${u}
13
+ ${l}`),n.pop(),`{${u}}`}case"number":return isFinite(t)?String(t):o?o(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(t);default:return o?o(t):void 0}}function z(O,t,n,f,g){switch(typeof t){case"string":return y(t);case"object":{if(t===null)return"null";if(typeof t.toJSON=="function"){if(t=t.toJSON(O),typeof t!="object")return z(O,t,n,f,g);if(t===null)return"null"}if(n.indexOf(t)!==-1)return h;const p=g;if(Array.isArray(t)){if(t.length===0)return"[]";if(V<n.length+1)return'"[Array]"';n.push(t),g+=f;let d=`
14
+ ${g}`;const M=`,
15
+ ${g}`,P=Math.min(t.length,b);let j=0;for(;j<P-1;j++){const J=z(String(j),t[j],n,f,g);d+=J!==void 0?J:"null",d+=M}const _=z(String(j),t[j],n,f,g);if(d+=_!==void 0?_:"null",t.length-1>b){const J=t.length-b-1;d+=`${M}"... ${R(J)} not stringified"`}return d+=`
16
+ ${p}`,n.pop(),`[${d}]`}let l=Object.keys(t);const u=l.length;if(u===0)return"{}";if(V<n.length+1)return'"[Object]"';g+=f;const v=`,
17
+ ${g}`;let w="",m="",L=Math.min(u,b);$(t)&&(w+=T(t,v,b),l=l.slice(t.length),L-=t.length,m=v),E&&(l=S(l,D)),n.push(t);for(let d=0;d<L;d++){const M=l[d],P=z(M,t[M],n,f,g);P!==void 0&&(w+=`${m}${y(M)}: ${P}`,m=v)}if(u>b){const d=u-b;w+=`${m}"...": "${R(d)} not stringified"`,m=v}return m!==""&&(w=`
18
+ ${g}${w}
19
+ ${p}`),n.pop(),`{${w}}`}case"number":return isFinite(t)?String(t):o?o(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(t);default:return o?o(t):void 0}}function B(O,t,n){switch(typeof t){case"string":return y(t);case"object":{if(t===null)return"null";if(typeof t.toJSON=="function"){if(t=t.toJSON(O),typeof t!="object")return B(O,t,n);if(t===null)return"null"}if(n.indexOf(t)!==-1)return h;let f="";const g=t.length!==void 0;if(g&&Array.isArray(t)){if(t.length===0)return"[]";if(V<n.length+1)return'"[Array]"';n.push(t);const w=Math.min(t.length,b);let m=0;for(;m<w-1;m++){const d=B(String(m),t[m],n);f+=d!==void 0?d:"null",f+=","}const L=B(String(m),t[m],n);if(f+=L!==void 0?L:"null",t.length-1>b){const d=t.length-b-1;f+=`,"... ${R(d)} not stringified"`}return n.pop(),`[${f}]`}let p=Object.keys(t);const l=p.length;if(l===0)return"{}";if(V<n.length+1)return'"[Object]"';let u="",v=Math.min(l,b);g&&$(t)&&(f+=T(t,",",b),p=p.slice(t.length),v-=t.length,u=","),E&&(p=S(p,D)),n.push(t);for(let w=0;w<v;w++){const m=p[w],L=B(m,t[m],n);L!==void 0&&(f+=`${u}${y(m)}:${L}`,u=",")}if(l>b){const w=l-b;f+=`${u}"...":"${R(w)} not stringified"`}return n.pop(),`{${f}}`}case"number":return isFinite(t)?String(t):o?o(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(t);default:return o?o(t):void 0}}function te(O,t,n){if(arguments.length>1){let f="";if(typeof n=="number"?f=" ".repeat(Math.min(n,10)):typeof n=="string"&&(f=n.slice(0,10)),t!=null){if(typeof t=="function")return q("",{"":O},[],t,f,"");if(Array.isArray(t))return Q("",O,[],I(t),f,"")}if(f.length!==0)return z("",O,[],f,"")}return B("",O,[])}return te}})(Y,Y.exports)),Y.exports}var ce=ae();class ge{#t=new Map;#e;constructor(e){this.#e=e}count(e="default"){const s=this.#t.get(e)??0;this.#t.set(e,s+1),this.#e("log",!1,!1,{message:`${e}: ${String(s+1)}`,prefix:e})}countReset(e="default"){this.#t.has(e)?this.#t.delete(e):this.#e("warn",!1,!1,{message:`Count for ${e} does not exist`,prefix:e})}}class ue{log(e){const{context:s=[],message:r,type:a}=e;oe(a.level)(r,...s)}}class he{#t=new Map;#e=new Set;#s;#i;#r;constructor(e,s,r){this.#r=e,this.#s=s,this.#i=r}time(e="default"){this.#e.has(e)?this.#r("warn",!1,!1,{message:`Timer '${e}' already exists`,prefix:e}):(this.#e.add(e),this.#t.set(e,Date.now()),this.#r("start",!1,!1,{message:this.#s,prefix:e}))}timeLog(e,...s){if(!e&&this.#e.size>0&&(e=[...this.#e].pop()),e&&this.#t.has(e)){const r=Date.now()-this.#t.get(e);this.#r("info",!1,!1,{context:s,message:r<1e3?`${String(r)} ms`:`${(r/1e3).toFixed(2)} s`,prefix:e})}else this.#r("warn",!1,!1,{context:s,message:"Timer not found",prefix:e})}timeEnd(e){if(!e&&this.#e.size>0&&(e=[...this.#e].pop()),e&&this.#t.has(e)){const s=Date.now()-this.#t.get(e);this.#t.delete(e),this.#r("stop",!1,!1,{message:`${this.#i} ${s<1e3?`${String(s)} ms`:`${(s/1e3).toFixed(2)} s`}`,prefix:e})}else this.#r("warn",!1,!1,{message:"Timer not found",prefix:e})}}const K=x=>x===void 0?[]:Array.isArray(x)?x:[x],Z=(x,e)=>{const s={...x};return Object.keys(e).forEach(r=>{s[r]={...s[r],...e[r]}}),s},fe=x=>{let e=!1;return function(...s){if(!e){e=!0;try{const r=x.apply(this,s);return e=!1,r}catch(r){throw e=!1,r}}}};class W{timerManager;counterManager;lastLog;logLevels;disabled;paused;messageQueue;scopeName;types;longestLabel;processors;generalLogLevel;reporters;throttle;throttleMin;stringify;groups;startTimerMessage;endTimerMessage;rawReporter;force={};#t=new Set;#e;#s;constructor(e){this.throttle=e.throttle??1e3,this.throttleMin=e.throttleMin??5;const s=e.parentLongestLabel,r=e.parentTypes,a=e.parentStringify,y=e.parentLogLevels;this.stringify=a??ce.configure({strict:!0}),this.startTimerMessage=e.messages?.timerStart??"Initialized timer...",this.endTimerMessage=e.messages?.timerEnd??"Timer run for:",r&&s?(this.types=r,this.longestLabel=s):(this.types=Z(ie,e.types??{}),this.longestLabel=X(this.types)),this.logLevels=y&&!e.logLevels?y:{...se,...e.logLevels},this.generalLogLevel=this.#o(e.logLevel),this.reporters=new Set,this.processors=new Set,this.disabled=e.disabled??!1,this.paused=!1,this.messageQueue=[],this.scopeName=K(e.scope).filter(Boolean),this.timerManager=new he((S,c,$,...T)=>{this.logger(S,c,$,...T)},this.startTimerMessage,this.endTimerMessage),this.counterManager=new ge((S,c,$,...T)=>{this.logger(S,c,$,...T)}),this.groups=[],this.lastLog={},this.logger=fe(this.logger.bind(this)),this.#i(),Array.isArray(e.reporters)&&this.registerReporters(e.reporters),this.rawReporter=this.extendReporter(e.rawReporter??new ue),Array.isArray(e.processors)&&this.registerProcessors(e.processors)}#i(){for(const e in this.types)this[e]=this.logger.bind(this,e,!1,!1);for(const e in this.types)this.force[e]=this.logger.bind(this,e,!1,!0);this.raw=this.raw.bind(this)}wrapConsole(){for(const e in this.types)console[`__${e}`]||(console[`__${e}`]=console[e]),console[e]=this[e]}restoreConsole(){for(const e in this.types)console[`__${e}`]&&(console[e]=console[`__${e}`],delete console[`__${e}`])}wrapException(){this.#e||this.#s||(this.#e=e=>{this.error(e)},this.#s=e=>{this.error(e)},process.on("uncaughtException",this.#e),process.on("unhandledRejection",this.#s))}restoreException(){this.#e&&(process.off("uncaughtException",this.#e),this.#e=void 0),this.#s&&(process.off("unhandledRejection",this.#s),this.#s=void 0)}disable(){this.disabled=!0}enable(){this.disabled=!1}isEnabled(){return!this.disabled}pause(){this.paused=!0}resume(){this.paused=!1;const e=this.messageQueue.splice(0);for(let s=0;s<e.length;s+=1){const{messageObject:r,raw:a,type:y}=e[s];this.logger(y,a,!1,...r)}}scope(...e){if(e.length===0)throw new Error("No scope name was defined.");return this.child({scope:e})}unscope(){this.scopeName=[]}child(e){const s=e?.types!==void 0,r=s?Z(this.types,e.types):this.types,a=e?.reporters??[],y=a.length>0?[...this.reporters,...a]:[...this.reporters],S=e?.processors??[],c=S.length>0?[...this.processors,...S]:[...this.processors],$=e?.logLevels?{...this.logLevels,...e.logLevels}:this.logLevels;let T;if(e?.scope){const F=K(e.scope).filter(Boolean);T=this.scopeName.length>0?[...this.scopeName,...F]:F}else T=this.scopeName.length>0?this.scopeName:[];const k=e?.messages?{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage,...e.messages}:{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage},A={disabled:e?.disabled??this.disabled,logLevel:e?.logLevel??this.generalLogLevel,logLevels:$,messages:k,processors:c,rawReporter:e?.rawReporter??this.rawReporter,reporters:y,scope:T,throttle:e?.throttle??this.throttle,throttleMin:e?.throttleMin??this.throttleMin};return s?(A.parentTypes=r,A.parentLongestLabel=X(r)):(A.parentTypes=this.types,A.parentLongestLabel=this.longestLabel),e?.logLevels||(A.parentLogLevels=this.logLevels),e?.messages||(A.parentMessages={timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage}),A.parentStringify=this.stringify,new W(A)}time(e="default"){this.timerManager.time(e)}timeLog(e,...s){this.timerManager.timeLog(e,...s)}timeEnd(e){this.timerManager.timeEnd(e)}group(e="console.group"){globalThis.window===void 0?this.groups.push(e):console.group(e)}groupEnd(){globalThis.window===void 0?this.groups.pop():console.groupEnd()}count(e="default"){this.counterManager.count(e)}countReset(e="default"){this.counterManager.countReset(e)}clear(){console.clear()}raw(e,...s){this.disabled||this.logger("log",!0,!1,{context:s,message:e})}extendReporter(e){return typeof e.setLoggerTypes=="function"&&e.setLoggerTypes(this.types),typeof e.setStringify=="function"&&e.setStringify(this.stringify),e}registerReporters(e){for(let s=0;s<e.length;s+=1)this.reporters.add(this.extendReporter(e[s]))}registerProcessors(e){for(let s=0;s<e.length;s+=1){const r=e[s];typeof r.setStringify=="function"&&r.setStringify(this.stringify),this.processors.add(r)}}#r(e,s){if(s)this.rawReporter.log(Object.freeze(e));else for(const r of this.reporters)r.log(Object.freeze(e))}#o(e){let s="debug";return e!==void 0&&Object.hasOwn(this.logLevels,e)?s=e:e!==void 0&&!this.#t.has(e)&&(this.#t.add(e),console.warn(`[pail] Unknown log level "${String(e)}". Valid levels: ${Object.keys(this.logLevels).join(", ")}. Falling back to "debug".`)),s}#n(e,s,...r){const a={badge:void 0,context:void 0,error:void 0,label:void 0,message:re,prefix:void 0,repeated:void 0,scope:void 0,suffix:void 0};if(a.type={level:s.logLevel,name:e},a.groups=this.groups,a.scope=this.scopeName,a.date=new Date,r.length>0&&r[0]instanceof Error)a.error=r[0],r.length>1&&(a.context=r.slice(1));else if(r.length>0&&typeof r[0]=="object"&&r[0]!==null&&"message"in r[0]){const{context:y,message:S,prefix:c,suffix:$}=r[0];if(y&&(a.context=y),c&&(a.prefix=c),$&&(a.suffix=$),a.message=S,r.length>1){const T=r.slice(1);a.context?a.context=Array.isArray(a.context)?[...a.context,...T]:[a.context,...T]:a.context=T}}else r.length>1?(a.message=r[0],a.context=r.slice(1)):r.length===1?a.message=r[0]:a.message=void 0;return s.logLevel==="trace"&&(a.traceError=new Error("Trace")),s.badge&&(a.badge=s.badge),s.label&&(a.label=s.label),a}logger(e,s,r,...a){if(this.disabled)return;if(this.paused){this.messageQueue.push({messageObject:a,raw:s,type:e});return}const y=this.types[e],S=this.#o(y.logLevel);if(r||this.logLevels[S]>=this.logLevels[this.generalLogLevel]){let c=this.#n(e,y,...a),$;try{$=JSON.stringify([c.label,c.scope,c.type,c.message,c.prefix,c.suffix,c.context])}catch{$=void 0}const T=this.processors.size>0,k=(C=!1)=>{const R=(this.lastLog.count??0)-this.throttleMin;if(this.lastLog.object&&R>0){const I={...this.lastLog.object};R>1&&(I.repeated=R),this.#r(I,s),this.lastLog.count=1}if(C){for(const I of this.processors)c=I.process(c);if(c.dropped===!0)return;if(this.lastLog.object=c,T)try{this.lastLog.signature=JSON.stringify([c.label,c.scope,c.type,c.message,c.prefix,c.suffix,c.context])}catch{this.lastLog.signature=void 0}else this.lastLog.signature=$;this.#r(c,s)}};clearTimeout(this.lastLog.timeout);const A=c.date instanceof Date?c.date:new Date(c.date),F=this.lastLog.time?A.getTime()-this.lastLog.time.getTime():0;if(this.lastLog.time=A,F<this.throttle)try{const C=$;if(this.lastLog.object&&C!==void 0&&C===this.lastLog.signature&&(this.lastLog.count=(this.lastLog.count??0)+1,this.lastLog.count>this.throttleMin)){this.lastLog.timeout=setTimeout(k,this.throttle);return}}catch{}k(!0)}}}const pe=W;class de{#t;#e;#s;constructor(e={}){this.#e=e.formatters}setStringify(e){this.#t=e}process(e){this.#s===void 0&&(this.#s=ne({formatters:this.#e}));const s=this.#s;return e.message!==void 0&&(e.message=this.#i(s,e.message,e.context??[])),e}#i(e,s,r=[]){if(typeof s=="string")return e(s,r);if(typeof s=="object"&&s!==null){const a=s,y=Object.keys(a);for(let S=0;S<y.length;S+=1){const c=y[S],$=a[c];(typeof $=="string"||Array.isArray($)||typeof $=="object")&&(a[c]=this.#i(e,$,r))}}return s}}const me=x=>new pe({processors:[new de],reporters:[new le],...x}),we=me();export{xe as PailError,me as createPail,Te as createPailError,we as pail};
@@ -1,9 +1,23 @@
1
1
  import { InteractiveManager } from '@visulima/interactive-manager';
2
- import { stringify } from 'safe-stable-stringify';
3
2
  import { LiteralUnion } from 'type-fest';
4
3
  import { M as Meta, D as DefaultLogTypes, L as LoggerTypesConfig, P as Processor, E as ExtendedRfc5424LogLevels, R as Reporter, a as LoggerFunction, C as ConstructorOptions, S as ServerConstructorOptions } from "./packem_shared/types.d-Cz9S7jZh.js";
5
- export { type b as DefaultLoggerTypes, type c as LoggerConfiguration, type d as LoggerTypesAwareReporter, type e as StreamAwareReporter } from "./packem_shared/types.d-Cz9S7jZh.js";
4
+ export type { b as DefaultLoggerTypes, c as LoggerConfiguration, d as LoggerTypesAwareReporter, e as StreamAwareReporter } from "./packem_shared/types.d-Cz9S7jZh.js";
6
5
  import '@visulima/colorize';
6
+ type Replacer = (number | string)[] | null | undefined | ((key: string, value: unknown) => string | number | boolean | null | object);
7
+ declare function stringify(value: undefined | symbol | ((...args: unknown[]) => unknown), replacer?: Replacer, space?: string | number): undefined;
8
+ declare function stringify(value: string | number | unknown[] | null | boolean | object, replacer?: Replacer, space?: string | number): string;
9
+ declare function stringify(value: unknown, replacer?: ((key: string, value: unknown) => unknown) | (number | string)[] | null | undefined, space?: string | number): string | undefined;
10
+ declare namespace stringify {
11
+ export function configure(options: StringifyOptions): typeof stringify;
12
+ }
13
+ interface StringifyOptions {
14
+ bigint?: boolean;
15
+ circularValue?: string | null | TypeErrorConstructor | ErrorConstructor;
16
+ deterministic?: boolean | ((a: string, b: string) => number);
17
+ maximumBreadth?: number;
18
+ maximumDepth?: number;
19
+ strict?: boolean;
20
+ }
7
21
  /**
8
22
  * Pail Browser Implementation.
9
23
  *
@@ -29,9 +43,6 @@ import '@visulima/colorize';
29
43
  */
30
44
  declare class PailBrowserImpl<T extends string = string, L extends string = string> {
31
45
  #private;
32
- protected timersMap: Map<string, number>;
33
- protected countMap: Map<string, number>;
34
- protected seqTimers: Set<string>;
35
46
  protected readonly lastLog: {
36
47
  count?: number;
37
48
  object?: Meta<L>;
@@ -120,6 +131,20 @@ declare class PailBrowserImpl<T extends string = string, L extends string = stri
120
131
  */
121
132
  wrapException(): void;
122
133
  /**
134
+ * Removes the global exception/rejection handlers installed by {@link wrapException}.
135
+ *
136
+ * Counterpart to `wrapException()` (mirrors `wrapConsole()`/`restoreConsole()`).
137
+ * Safe to call when no handlers are installed.
138
+ * @example
139
+ * ```typescript
140
+ * const logger = createPail();
141
+ * logger.wrapException();
142
+ * // ... later ...
143
+ * logger.restoreException(); // global handlers removed
144
+ * ```
145
+ */
146
+ restoreException(): void;
147
+ /**
123
148
  * Disables all logging output.
124
149
  *
125
150
  * When disabled, all log calls will be silently ignored and no output