elysia-wide-event 0.1.1 → 0.1.3

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 CHANGED
@@ -14,6 +14,7 @@ Inspired by [Logging Sucks](https://loggingsucks.com/) - the wide event pattern
14
14
 
15
15
  ## Features
16
16
 
17
+ - **Server Start Log**: Log custom data on server startup with `start` option
17
18
  - **Context Accumulation**: Collect data throughout request lifecycle via `wideEvent.set()`
18
19
  - **Flexible Output**: Pretty colored output or JSON - you choose
19
20
  - **Request ID**: Auto-generates or extracts from `x-request-id` header
@@ -55,14 +56,16 @@ wideEvent({
55
56
  generateRequestId: () => crypto.randomUUID(),
56
57
  requestIdHeader: "x-request-id",
57
58
  json: false,
59
+ start: { env: "production", version: "1.0.0" },
58
60
  });
59
61
  ```
60
62
 
61
- | Option | Type | Default | Description |
62
- | ------------------- | -------------- | ------------------- | --------------------------------------- |
63
- | `generateRequestId` | `() => string` | `crypto.randomUUID` | Custom request ID generator |
64
- | `requestIdHeader` | `string` | `"x-request-id"` | Header for incoming request ID |
65
- | `json` | `boolean` | `false` | Output as JSON instead of pretty format |
63
+ | Option | Type | Default | Description |
64
+ | ------------------- | -------------- | ------------------- | ----------------------------------------------------- |
65
+ | `generateRequestId` | `() => string` | `crypto.randomUUID` | Custom request ID generator |
66
+ | `requestIdHeader` | `string` | `"x-request-id"` | Header for incoming request ID |
67
+ | `json` | `boolean` | `false` | Output as JSON instead of pretty format |
68
+ | `start` | `LogData` | `undefined` | Custom data to log on server startup (URL auto-added) |
66
69
 
67
70
  ## API
68
71
 
@@ -74,12 +77,13 @@ Add context to the current request log.
74
77
  wideEvent.set("auth", { userId: "123", role: "admin" });
75
78
  ```
76
79
 
77
- ### `wideEvent.error({ type, message })`
80
+ ### `wideEvent.error(data)`
78
81
 
79
- Log error details.
82
+ Log error details. Accepts any object.
80
83
 
81
84
  ```typescript
82
85
  wideEvent.error({ type: "ValidationError", message: "Invalid email" });
86
+ wideEvent.error({ code: "E001", reason: "timeout" });
83
87
  ```
84
88
 
85
89
  ## Requirements
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Elysia } from "elysia";
2
2
  import type { WideEventOptions, FlushableLogger } from "./types";
3
- export type { LogData, ErrorData, WideEventLogger, WideEventOptions, } from "./types";
3
+ export type { LogData, WideEventLogger, WideEventOptions } from "./types";
4
4
  export declare const wideEvent: (options?: WideEventOptions) => Elysia<"", {
5
5
  decorator: {};
6
6
  store: {};
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGjE,YAAY,EACV,OAAO,EACP,SAAS,EACT,eAAe,EACf,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,SAAS,GAAI,UAAS,gBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCvD,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGjE,YAAY,EAAE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE1E,eAAO,MAAM,SAAS,GAAI,UAAS,gBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCvD,CAAC;AAEF,eAAe,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -58,8 +58,7 @@ ${colors.dim}[${this.headerTime}]${colors.reset} ` + `${colors.yellow}${this.met
58
58
  console.log(` ${colors.blue}${key}:${colors.reset} ${formatData(data)}`);
59
59
  }
60
60
  if (this.errorData) {
61
- const errorMsg = this.errorData.message ? `${this.errorData.type}: ${this.errorData.message}` : this.errorData.type;
62
- console.log(` ${colors.red}\u2717${colors.reset} ${errorMsg}`);
61
+ console.log(` ${colors.red}error:${colors.reset} ${formatData(this.errorData)}`);
63
62
  }
64
63
  }
65
64
  flushJson(status, durationMs) {
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAIP,eAAe,EAChB,MAAM,SAAS,CAAC;AAkFjB,iBAAS,YAAY,CACnB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACf,eAAe,CAEjB;AAED,iBAAS,cAAc,CACrB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,OAAO,GACf,IAAI,CAqBN;AAED,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAGP,eAAe,EAChB,MAAM,SAAS,CAAC;AA+EjB,iBAAS,YAAY,CACnB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACf,eAAe,CAEjB;AAED,iBAAS,cAAc,CACrB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,OAAO,GACf,IAAI,CAqBN;AAED,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,15 +1,9 @@
1
1
  export interface LogData {
2
2
  [key: string]: unknown;
3
3
  }
4
- export interface ErrorData {
5
- type: string;
6
- code?: string;
7
- message?: string;
8
- [key: string]: unknown;
9
- }
10
4
  export interface WideEventLogger {
11
5
  set: (key: string, data: LogData) => void;
12
- error: (error: ErrorData) => void;
6
+ error: (error: LogData) => void;
13
7
  }
14
8
  export interface WideEventOptions {
15
9
  /**
@@ -63,7 +57,7 @@ export interface WideEventRecord {
63
57
  path: string;
64
58
  status?: number;
65
59
  duration_ms?: number;
66
- error?: ErrorData;
60
+ error?: LogData;
67
61
  [key: string]: unknown;
68
62
  }
69
63
  export type FlushableLogger = WideEventLogger & {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1C,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,MAAM,MAAM,CAAC;IAEjC;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,M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EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elysia-wide-event",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Wide event logging plugin for Elysia - structured logging with request context",
5
5
  "author": "Jay Choi",
6
6
  "license": "MIT",