@iskra-bun/core 0.1.0 → 0.2.0

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/src/types.ts CHANGED
@@ -13,17 +13,42 @@ export interface Plugin {
13
13
  install(app: App): Promise<void> | void;
14
14
  }
15
15
 
16
- export interface Context<T = any> {
16
+ /** What an `app.on()` handler receives; `payload` is the emitted value. */
17
+ export interface Context<T = unknown> {
17
18
  app: App;
18
19
  logger: Logger;
19
20
  payload: T;
20
- reply(data: any): void;
21
+ /** Emits `<event>:reply` with `data`. */
22
+ reply(data: unknown): void;
21
23
  }
22
24
 
25
+ /**
26
+ * What each kit shares through `app.context`, by key, so `app.context.get('db')`
27
+ * is typed. Kits add their keys with declaration merging, and so can an app:
28
+ *
29
+ * ```ts
30
+ * declare module '@iskra-bun/core' {
31
+ * interface AppContextRegistry {
32
+ * bridge: DesktopBridge;
33
+ * }
34
+ * }
35
+ * ```
36
+ */
37
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- filled by declaration merging
38
+ export interface AppContextRegistry {}
39
+
40
+ /**
41
+ * The payload of each app event, by name, so `app.on('process:exit', ...)`
42
+ * and `app.emit(...)` are typed. Kits add their events with declaration
43
+ * merging, and so can an app (as with AppContextRegistry).
44
+ */
45
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- filled by declaration merging
46
+ export interface AppEvents {}
47
+
23
48
  export interface OtelConfig {
24
49
  /** Defaults to true when otel config is present */
25
50
  enabled?: boolean;
26
- /** OTLP endpoint URL. Defaults to http://localhost:4318 */
51
+ /** OTLP endpoint URL. Defaults to http://localhost:4318; use https:// for a collector on another host. */
27
52
  endpoint?: string;
28
53
  /** Overrides app name for the service.name resource attribute */
29
54
  serviceName?: string;
@@ -35,8 +60,14 @@ export interface OtelConfig {
35
60
  metricIntervalMs?: number;
36
61
  /** Additional resource attributes */
37
62
  resourceAttributes?: Record<string, string>;
38
- /** Auto-instrumentation overrides (passed to getNodeAutoInstrumentations) */
39
- instrumentations?: Record<string, { enabled?: boolean }>;
63
+ /**
64
+ * Options of each auto-instrumentation, by package name, passed to
65
+ * getNodeAutoInstrumentations(): `{ enabled: false }`, or its own options
66
+ * (`'@opentelemetry/instrumentation-http': { ignoreIncomingRequestHook,
67
+ * redactedQueryParams }`). The HTTP one redacts SECRET_QUERY_PARAMS in
68
+ * exported URLs unless `redactedQueryParams` says otherwise.
69
+ */
70
+ instrumentations?: Record<string, { enabled?: boolean; [option: string]: unknown }>;
40
71
  }
41
72
 
42
73
  export interface AppConfig {
@@ -46,6 +77,13 @@ export interface AppConfig {
46
77
  level?: string;
47
78
  };
48
79
  otel?: OtelConfig;
80
+ /**
81
+ * Signals that trigger a graceful `stop()` and exit. Default
82
+ * `['SIGTERM', 'SIGINT']` (none under NODE_ENV=test); `false` disables.
83
+ */
84
+ shutdownSignals?: string[] | false;
85
+ /** Max time for a signal-triggered stop before forcing exit(1). Default 10000. */
86
+ shutdownTimeoutMs?: number;
49
87
  processes?: Record<string, ProcessConfig>;
50
88
  socket?: {
51
89
  enabled: boolean;
@@ -53,15 +91,26 @@ export interface AppConfig {
53
91
  adapter?: 'bun' | 'socket.io';
54
92
  };
55
93
  kv?: {
56
- driver: 'memory' | 'redis' | 'libsql';
57
- connection?: any;
94
+ driver: 'memory' | 'redis';
95
+ /** Redis: a URL string, ioredis options, or ioredis options with `url`. */
96
+ connection?: string | Record<string, unknown>;
58
97
  };
59
98
  db?: {
60
99
  driver: 'postgres' | 'mysql' | 'sqlite' | 'libsql';
61
100
  url: string;
62
101
  authToken?: string;
63
102
  };
64
- [key: string]: any;
103
+ /** Sections of other kits or of the app; read them with their own type. */
104
+ [key: string]: unknown;
105
+ }
106
+
107
+ export interface RestartBackoffConfig {
108
+ /** Initial delay in ms before the first restart. Default: 1000 */
109
+ initialMs?: number;
110
+ /** Maximum delay cap in ms. Default: 30000 */
111
+ maxMs?: number;
112
+ /** Multiplier applied to the delay after each restart. Default: 2 */
113
+ factor?: number;
65
114
  }
66
115
 
67
116
  export interface ProcessConfig {
@@ -71,5 +120,20 @@ export interface ProcessConfig {
71
120
  restartOnCrash?: boolean;
72
121
  maxRestarts?: number;
73
122
  restartCooldown?: number;
123
+ /** Variables set for the child, over the ones it inherits (see `inheritEnv`). */
74
124
  env?: Record<string, string>;
125
+ /**
126
+ * Which of the app's environment variables the child inherits. Default
127
+ * `false`: a minimal set without secrets (PATH, HOME, locale, TZ, temp
128
+ * dir, NODE_ENV…). A list adds those names to it; `true` passes them all
129
+ * (DATABASE_URL, AUTH_SECRET, cloud keys…).
130
+ */
131
+ inheritEnv?: boolean | string[];
132
+ /**
133
+ * `stdio` mode: bytes `send()` lets wait for a child that is not reading
134
+ * its stdin; past this it refuses messages (returns false). Default 8 MiB.
135
+ */
136
+ maxPendingStdinBytes?: number;
137
+ /** Exponential backoff settings for restarts. Defaults to 1000 ms flat (no backoff). */
138
+ restartBackoff?: RestartBackoffConfig;
75
139
  }