@b9g/platform 0.1.12 → 0.1.14-beta.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/runtime.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference path="./globals.d.ts" />
2
+ /// <reference path="./shovel-config.d.ts" />
1
3
  /**
2
4
  * ServiceWorker Runtime - Complete ServiceWorker API Implementation
3
5
  *
@@ -9,6 +11,8 @@
9
11
  *
10
12
  * Based on: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API#interfaces
11
13
  */
14
+ import { CustomDirectoryStorage } from "@b9g/filesystem";
15
+ import { CustomCacheStorage, Cache } from "@b9g/cache";
12
16
  declare global {
13
17
  interface CookieListItem {
14
18
  domain?: string;
@@ -69,37 +73,137 @@ import type { DirectoryStorage } from "@b9g/filesystem";
69
73
  import { type Logger } from "@logtape/logtape";
70
74
  /**
71
75
  * Logger storage interface for accessing loggers by category path.
72
- * Unlike CacheStorage/DirectoryStorage which use a registry pattern,
73
- * LoggerStorage uses variadic categories since logging backends are
74
- * always LogTape and per-category config is in shovel.config.json.
76
+ * Uses array signature (matching LogTape) to allow future options parameter.
75
77
  */
76
78
  export interface LoggerStorage {
77
79
  /**
78
- * Open a logger by category path - returns LogTape's Logger directly
79
- * @example loggers.open("app") → getLogger(["app"])
80
- * @example loggers.open("app", "db") getLogger(["app", "db"])
80
+ * Get a logger by category path (sync)
81
+ * @example const logger = self.loggers.get(["app"])
82
+ * @example const logger = self.loggers.get(["app", "db"])
81
83
  */
82
- open(...categories: string[]): Logger;
84
+ get(categories: string[]): Logger;
83
85
  }
84
86
  /**
85
- * Factory function type for creating loggers
87
+ * Factory function type for creating loggers (sync).
86
88
  */
87
- export type LoggerFactory = (...categories: string[]) => Logger;
89
+ export type LoggerFactory = (categories: string[]) => Logger;
88
90
  /**
89
91
  * Custom logger storage implementation that wraps a factory function
90
92
  */
91
93
  export declare class CustomLoggerStorage implements LoggerStorage {
92
94
  #private;
93
95
  constructor(factory: LoggerFactory);
94
- open(...categories: string[]): Logger;
96
+ get(categories: string[]): Logger;
95
97
  }
98
+ import { Database } from "@b9g/zen";
99
+ /**
100
+ * Database configuration from shovel.json.
101
+ * Uses the unified impl pattern like directories and caches.
102
+ */
103
+ export interface DatabaseConfig {
104
+ /** Reified implementation (driver class from build-time code generation) */
105
+ impl?: new (url: string, options?: any) => any;
106
+ /** Database connection URL */
107
+ url?: string;
108
+ /** Additional driver-specific options */
109
+ [key: string]: unknown;
110
+ }
111
+ /**
112
+ * Upgrade event passed to onUpgrade callback during database.open().
113
+ */
114
+ export interface DatabaseUpgradeEvent {
115
+ /** The database being upgraded */
116
+ db: Database;
117
+ /** Previous database version (0 if new) */
118
+ oldVersion: number;
119
+ /** Target version being opened */
120
+ newVersion: number;
121
+ /** Register a promise that must complete before open() resolves */
122
+ waitUntil(promise: Promise<unknown>): void;
123
+ }
124
+ /**
125
+ * DatabaseStorage interface - provides access to named database instances.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // In activate handler - open database with migrations
130
+ * self.addEventListener("activate", (event) => {
131
+ * event.waitUntil(
132
+ * self.databases.open("main", 2, (e) => {
133
+ * e.waitUntil(runMigrations(e));
134
+ * })
135
+ * );
136
+ * });
137
+ *
138
+ * // In fetch handler - get the opened database (sync)
139
+ * self.addEventListener("fetch", (event) => {
140
+ * const db = self.databases.get("main");
141
+ * const users = await db.all(User)`WHERE active = ${true}`;
142
+ * });
143
+ * ```
144
+ */
145
+ export interface DatabaseStorage {
146
+ /**
147
+ * Open a database at a specific version.
148
+ * Imports the driver, creates the Database, runs migrations if needed.
149
+ * Caches the opened instance for later get() calls.
150
+ */
151
+ open(name: string, version: number, onUpgrade?: (event: DatabaseUpgradeEvent) => void): Promise<Database>;
152
+ /**
153
+ * Get an already-opened database.
154
+ * Throws if the database hasn't been opened yet.
155
+ * This is synchronous for fast access in request handlers.
156
+ */
157
+ get(name: string): Database;
158
+ /** Close a specific database */
159
+ close(name: string): Promise<void>;
160
+ /** Close all databases */
161
+ closeAll(): Promise<void>;
162
+ }
163
+ /**
164
+ * Factory function type for creating database drivers.
165
+ * Returns the Database instance and a close function.
166
+ */
167
+ export type DatabaseFactory = (name: string) => Promise<{
168
+ db: Database;
169
+ close: () => Promise<void>;
170
+ }>;
171
+ /**
172
+ * CustomDatabaseStorage implements DatabaseStorage.
173
+ */
174
+ export declare class CustomDatabaseStorage implements DatabaseStorage {
175
+ #private;
176
+ constructor(factory: DatabaseFactory);
177
+ open(name: string, version: number, onUpgrade?: (event: DatabaseUpgradeEvent) => void): Promise<Database>;
178
+ get(name: string): Database;
179
+ close(name: string): Promise<void>;
180
+ closeAll(): Promise<void>;
181
+ }
182
+ /**
183
+ * Create a DatabaseFactory from declarative config.
184
+ *
185
+ * This dynamically imports the driver module at runtime, following
186
+ * the same pattern as createDirectoryFactory and createCacheFactory.
187
+ *
188
+ * @param configs - The databases config from shovel.json
189
+ * @returns An async factory function that creates databases by name
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * // In platform adapter:
194
+ * const factory = createDatabaseFactory(config.databases);
195
+ * return new CustomDatabaseStorage(factory);
196
+ * ```
197
+ */
198
+ export declare function createDatabaseFactory(configs: Record<string, DatabaseConfig>): DatabaseFactory;
96
199
  /** Symbol for ending dispatch phase (internal use only) */
97
200
  declare const kEndDispatchPhase: unique symbol;
98
201
  /** Symbol for checking if extensions are allowed (internal use only) */
99
202
  declare const kCanExtend: unique symbol;
100
203
  /**
101
- * ExtendableEvent base class following ServiceWorker spec
102
- * Standard constructor: new ExtendableEvent(type) or new ExtendableEvent(type, options)
204
+ * Shovel's ExtendableEvent implementation following ServiceWorker spec.
205
+ *
206
+ * Standard constructor: new ShovelExtendableEvent(type) or new ShovelExtendableEvent(type, options)
103
207
  *
104
208
  * Per spec, waitUntil() can be called:
105
209
  * 1. Synchronously during event dispatch, OR
@@ -107,7 +211,7 @@ declare const kCanExtend: unique symbol;
107
211
  *
108
212
  * See: https://github.com/w3c/ServiceWorker/issues/771
109
213
  */
110
- export declare class ExtendableEvent extends Event {
214
+ export declare class ShovelExtendableEvent extends Event implements ExtendableEvent {
111
215
  #private;
112
216
  constructor(type: string, eventInitDict?: EventInit);
113
217
  waitUntil(promise: Promise<any>): void;
@@ -118,27 +222,48 @@ export declare class ExtendableEvent extends Event {
118
222
  [kCanExtend](): boolean;
119
223
  }
120
224
  /**
121
- * ServiceWorker-style fetch event
225
+ * Options for ShovelFetchEvent constructor (non-standard Shovel extension)
122
226
  */
123
- export declare class FetchEvent extends ExtendableEvent {
227
+ export interface ShovelFetchEventInit extends EventInit {
228
+ /**
229
+ * Platform-provided callback for extending request lifetime.
230
+ * Called automatically when waitUntil() is invoked.
231
+ * (e.g., Cloudflare's ctx.waitUntil)
232
+ */
233
+ platformWaitUntil?: (promise: Promise<unknown>) => void;
234
+ }
235
+ /**
236
+ * Shovel's FetchEvent implementation.
237
+ *
238
+ * Platforms can subclass this to add platform-specific properties (e.g., env bindings).
239
+ * The platformWaitUntil hook allows platforms to extend request lifetime properly.
240
+ */
241
+ export declare class ShovelFetchEvent extends ShovelExtendableEvent implements FetchEvent {
124
242
  #private;
125
243
  readonly request: Request;
126
244
  readonly cookieStore: RequestCookieStore;
127
- constructor(request: Request, eventInitDict?: EventInit);
245
+ readonly clientId: string;
246
+ readonly handled: Promise<undefined>;
247
+ readonly preloadResponse: Promise<any>;
248
+ readonly resultingClientId: string;
249
+ constructor(request: Request, options?: ShovelFetchEventInit);
250
+ waitUntil(promise: Promise<any>): void;
128
251
  respondWith(response: Response | Promise<Response>): void;
129
252
  getResponse(): Promise<Response> | null;
130
253
  hasResponded(): boolean;
254
+ /** The URL of the request (convenience property) */
255
+ get url(): string;
131
256
  }
132
257
  /**
133
- * ServiceWorker-style install event
258
+ * Shovel's InstallEvent implementation
134
259
  */
135
- export declare class InstallEvent extends ExtendableEvent {
260
+ export declare class ShovelInstallEvent extends ShovelExtendableEvent {
136
261
  constructor(eventInitDict?: EventInit);
137
262
  }
138
263
  /**
139
- * ServiceWorker-style activate event
264
+ * Shovel's ActivateEvent implementation
140
265
  */
141
- export declare class ActivateEvent extends ExtendableEvent {
266
+ export declare class ShovelActivateEvent extends ShovelExtendableEvent {
142
267
  constructor(eventInitDict?: EventInit);
143
268
  }
144
269
  /**
@@ -194,7 +319,7 @@ export interface ExtendableMessageEventInit extends EventInit {
194
319
  source?: Client | ServiceWorker | MessagePort | null;
195
320
  ports?: MessagePort[];
196
321
  }
197
- export declare class ExtendableMessageEvent extends ExtendableEvent {
322
+ export declare class ExtendableMessageEvent extends ShovelExtendableEvent {
198
323
  readonly data: any;
199
324
  readonly origin: string;
200
325
  readonly lastEventId: string;
@@ -229,6 +354,14 @@ export declare class ShovelNavigationPreloadManager implements NavigationPreload
229
354
  }>;
230
355
  setHeaderValue(_value: string): Promise<void>;
231
356
  }
357
+ /** @internal Symbol for accessing the internal ServiceWorker instance */
358
+ export declare const kServiceWorker: unique symbol;
359
+ /** @internal Symbol for dispatching the install lifecycle event */
360
+ export declare const kDispatchInstall: unique symbol;
361
+ /** @internal Symbol for dispatching the activate lifecycle event */
362
+ export declare const kDispatchActivate: unique symbol;
363
+ /** @internal Symbol for handling fetch requests */
364
+ declare const kHandleRequest: unique symbol;
232
365
  /**
233
366
  * ShovelServiceWorkerRegistration - Internal implementation of ServiceWorkerRegistration
234
367
  * This is also the Shovel ServiceWorker runtime - they are unified into one class
@@ -238,7 +371,7 @@ export declare class ShovelServiceWorkerRegistration extends EventTarget impleme
238
371
  readonly scope: string;
239
372
  readonly updateViaCache: "imports" | "all" | "none";
240
373
  readonly navigationPreload: NavigationPreloadManager;
241
- _serviceWorker: ShovelServiceWorker;
374
+ [kServiceWorker]: ShovelServiceWorker;
242
375
  readonly cookies: any;
243
376
  readonly pushManager: any;
244
377
  onupdatefound: ((ev: Event) => any) | null;
@@ -252,22 +385,71 @@ export declare class ShovelServiceWorkerRegistration extends EventTarget impleme
252
385
  unregister(): Promise<boolean>;
253
386
  update(): Promise<ServiceWorkerRegistration>;
254
387
  /**
255
- * Install the ServiceWorker (Shovel extension)
388
+ * Dispatch the install lifecycle event
389
+ * @internal Use runLifecycle() instead of calling this directly
256
390
  */
257
- install(): Promise<void>;
391
+ [kDispatchInstall](): Promise<void>;
258
392
  /**
259
- * Activate the ServiceWorker (Shovel extension)
393
+ * Dispatch the activate lifecycle event
394
+ * @internal Use runLifecycle() instead of calling this directly
260
395
  */
261
- activate(): Promise<void>;
396
+ [kDispatchActivate](): Promise<void>;
262
397
  /**
263
- * Handle a fetch request (Shovel extension)
398
+ * Handle a fetch request
399
+ * @internal Use the kHandleRequest symbol to access this method
400
+ *
401
+ * Platforms create a ShovelFetchEvent (or subclass) with platform-specific
402
+ * properties and hooks, then pass it to this method for dispatching.
403
+ *
404
+ * @param event - The fetch event to handle (created by platform adapter)
264
405
  */
265
- handleRequest(request: Request): Promise<Response>;
406
+ [kHandleRequest](event: ShovelFetchEvent): Promise<Response>;
266
407
  /**
267
408
  * Check if ready to handle requests (Shovel extension)
268
409
  */
269
410
  get ready(): boolean;
270
411
  }
412
+ /**
413
+ * Run ServiceWorker lifecycle events on a registration.
414
+ *
415
+ * This is the proper way to trigger lifecycle events in Shovel's server-side runtime.
416
+ * Unlike browsers where lifecycle is automatic, server-side code must explicitly
417
+ * trigger these events after registering event handlers.
418
+ *
419
+ * @param registration - The ServiceWorkerRegistration to run lifecycle on
420
+ * @param stage - Which lifecycle stage to run:
421
+ * - "install": Run only the install event
422
+ * - "activate": Run install then activate (default)
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * const {registration} = await initWorkerRuntime({config});
427
+ * await import("./server.js"); // Register event handlers
428
+ * await runLifecycle(registration); // Runs install + activate
429
+ * ```
430
+ */
431
+ export declare function runLifecycle(registration: ShovelServiceWorkerRegistration, stage?: "install" | "activate"): Promise<void>;
432
+ /**
433
+ * Dispatch a fetch request to a ServiceWorker registration.
434
+ *
435
+ * This is the proper way to dispatch requests in Shovel's server-side runtime.
436
+ * Platforms should use this function rather than accessing internal methods directly.
437
+ *
438
+ * @param registration - The ServiceWorkerRegistration to dispatch to
439
+ * @param requestOrEvent - The Request to dispatch, or a pre-constructed ShovelFetchEvent
440
+ * @returns The Response from the ServiceWorker
441
+ *
442
+ * @example
443
+ * ```typescript
444
+ * // Simple usage with a Request
445
+ * const response = await dispatchRequest(registration, request);
446
+ *
447
+ * // Platform-specific usage with a custom FetchEvent subclass
448
+ * const event = new CloudflareFetchEvent(request, {env, platformWaitUntil});
449
+ * const response = await dispatchRequest(registration, event);
450
+ * ```
451
+ */
452
+ export declare function dispatchRequest(registration: ShovelServiceWorkerRegistration, requestOrEvent: Request | ShovelFetchEvent): Promise<Response>;
271
453
  /**
272
454
  * ShovelServiceWorkerContainer - Internal implementation of ServiceWorkerContainer
273
455
  * This is the registry that manages multiple ServiceWorkerRegistrations by scope
@@ -301,10 +483,6 @@ export declare class ShovelServiceWorkerContainer extends EventTarget implements
301
483
  * Unregister a ServiceWorker registration
302
484
  */
303
485
  unregister(scope: string): Promise<boolean>;
304
- /**
305
- * Route a request to the appropriate registration based on scope matching
306
- */
307
- handleRequest(request: Request): Promise<Response | null>;
308
486
  /**
309
487
  * Install and activate all registrations
310
488
  */
@@ -351,7 +529,7 @@ export interface NotificationEventInit extends EventInit {
351
529
  notification: Notification;
352
530
  reply?: string | null;
353
531
  }
354
- export declare class NotificationEvent extends ExtendableEvent {
532
+ export declare class NotificationEvent extends ShovelExtendableEvent {
355
533
  readonly action: string;
356
534
  readonly notification: Notification;
357
535
  readonly reply: string | null;
@@ -363,7 +541,7 @@ export declare class NotificationEvent extends ExtendableEvent {
363
541
  export interface PushEventInit extends EventInit {
364
542
  data?: PushMessageData | null;
365
543
  }
366
- export declare class PushEvent extends ExtendableEvent {
544
+ export declare class PushEvent extends ShovelExtendableEvent {
367
545
  readonly data: PushMessageData | null;
368
546
  constructor(type: string, eventInitDict?: PushEventInit);
369
547
  }
@@ -387,7 +565,7 @@ export interface SyncEventInit extends EventInit {
387
565
  tag: string;
388
566
  lastChance?: boolean;
389
567
  }
390
- export declare class SyncEvent extends ExtendableEvent {
568
+ export declare class SyncEvent extends ShovelExtendableEvent {
391
569
  readonly tag: string;
392
570
  readonly lastChance: boolean;
393
571
  constructor(type: string, eventInitDict: SyncEventInit);
@@ -418,6 +596,8 @@ export interface ServiceWorkerGlobalsOptions {
418
596
  registration: ServiceWorkerRegistration;
419
597
  /** Directory storage (file system access) - REQUIRED */
420
598
  directories: DirectoryStorage;
599
+ /** Database storage - OPTIONAL */
600
+ databases?: DatabaseStorage;
421
601
  /** Logger storage (logging access) - REQUIRED */
422
602
  loggers: LoggerStorage;
423
603
  /** Cache storage (required by ServiceWorkerGlobalScope) - REQUIRED */
@@ -452,6 +632,7 @@ export declare class ServiceWorkerGlobals implements ServiceWorkerGlobalScope {
452
632
  readonly registration: ServiceWorkerRegistration;
453
633
  readonly caches: CacheStorage;
454
634
  readonly directories: DirectoryStorage;
635
+ readonly databases?: DatabaseStorage;
455
636
  readonly loggers: LoggerStorage;
456
637
  readonly clients: Clients;
457
638
  get cookieStore(): any;
@@ -518,44 +699,20 @@ export declare class ServiceWorkerGlobals implements ServiceWorkerGlobalScope {
518
699
  */
519
700
  restore(): void;
520
701
  }
521
- /** Log level for filtering */
522
- export type LogLevel = "debug" | "info" | "warning" | "error";
523
- /** Sink configuration */
524
- export interface SinkConfig {
525
- provider: string;
526
- /** Pre-imported factory function (from build-time code generation) */
527
- factory?: (options: Record<string, unknown>) => unknown;
528
- /** Provider-specific options (path, maxSize, etc.) */
529
- [key: string]: any;
530
- }
531
- /** Per-category logging configuration */
532
- export interface CategoryLoggingConfig {
533
- level?: LogLevel;
534
- sinks?: SinkConfig[];
535
- }
536
- export interface LoggingConfig {
537
- /** Default log level. Defaults to "info" */
538
- level?: LogLevel;
539
- /** Default sinks. Defaults to console */
540
- sinks?: SinkConfig[];
541
- /** Per-category config (inherits from top-level, can override level and/or sinks) */
542
- categories?: Record<string, CategoryLoggingConfig>;
543
- }
544
- /** Processed logging config with all defaults applied */
545
- export interface ProcessedLoggingConfig {
546
- level: LogLevel;
547
- sinks: SinkConfig[];
548
- categories: Record<string, CategoryLoggingConfig>;
549
- }
550
702
  /** Cache provider configuration */
551
703
  export interface CacheConfig {
552
- provider?: string;
704
+ /** Reified implementation (class or factory from build-time code generation) */
705
+ impl?: (new (name: string, options?: any) => Cache) | ((name: string, options?: any) => Cache);
706
+ /** Additional options passed to the constructor */
553
707
  [key: string]: unknown;
554
708
  }
555
709
  /** Directory (filesystem) provider configuration */
556
710
  export interface DirectoryConfig {
557
- provider?: string;
711
+ /** Reified implementation (class or factory from build-time code generation) */
712
+ impl?: (new (name: string, options?: any) => FileSystemDirectoryHandle) | ((name: string, options?: any) => FileSystemDirectoryHandle);
713
+ /** Custom path for filesystem directories */
558
714
  path?: string;
715
+ /** Additional options passed to the constructor */
559
716
  [key: string]: unknown;
560
717
  }
561
718
  /** Shovel application configuration (from shovel.json) */
@@ -567,16 +724,159 @@ export interface ShovelConfig {
567
724
  logging?: LoggingConfig;
568
725
  caches?: Record<string, CacheConfig>;
569
726
  directories?: Record<string, DirectoryConfig>;
727
+ databases?: Record<string, DatabaseConfig>;
728
+ }
729
+ /**
730
+ * Creates a directory factory function for CustomDirectoryStorage.
731
+ *
732
+ * Configs must have impl pre-imported (from generated config module).
733
+ * Paths are expected to be already resolved at build time by the path syntax parser.
734
+ * Runtime paths (like [tmpdir]) are evaluated as expressions in the generated config.
735
+ */
736
+ export declare function createDirectoryFactory(configs: Record<string, DirectoryConfig>): (name: string) => Promise<FileSystemDirectoryHandle>;
737
+ export interface CacheFactoryOptions {
738
+ /** Cache configurations with pre-imported CacheClass (from generated config module) */
739
+ configs: Record<string, CacheConfig>;
740
+ /** If true, use PostMessageCache (for workers communicating with main thread) */
741
+ usePostMessage?: boolean;
742
+ }
743
+ /**
744
+ * Creates a cache factory function for CustomCacheStorage.
745
+ * Configs must have impl pre-imported (from generated config module).
746
+ */
747
+ export declare function createCacheFactory(options: CacheFactoryOptions): (name: string) => Promise<Cache>;
748
+ /**
749
+ * Worker message types for the message loop
750
+ */
751
+ export interface WorkerRequestMessage {
752
+ type: "request";
753
+ request: {
754
+ url: string;
755
+ method: string;
756
+ headers: Record<string, string>;
757
+ body?: ArrayBuffer | null;
758
+ };
759
+ requestID: number;
760
+ }
761
+ export interface WorkerResponseMessage {
762
+ type: "response";
763
+ response: {
764
+ status: number;
765
+ statusText: string;
766
+ headers: Record<string, string>;
767
+ body: ArrayBuffer;
768
+ };
769
+ requestID: number;
770
+ }
771
+ export interface WorkerErrorMessage {
772
+ type: "error";
773
+ error: string;
774
+ stack?: string;
775
+ requestID?: number;
776
+ }
777
+ /**
778
+ * Options for initializing the worker runtime
779
+ */
780
+ export interface InitWorkerRuntimeOptions {
781
+ /** Shovel configuration (from shovel:config) */
782
+ config: ShovelConfig;
783
+ }
784
+ /**
785
+ * Result from initializing the worker runtime
786
+ */
787
+ export interface InitWorkerRuntimeResult {
788
+ /** The ServiceWorker registration instance */
789
+ registration: ShovelServiceWorkerRegistration;
790
+ /** The installed ServiceWorkerGlobals scope */
791
+ scope: ServiceWorkerGlobals;
792
+ /** Cache storage instance */
793
+ caches: CustomCacheStorage;
794
+ /** Directory storage instance */
795
+ directories: CustomDirectoryStorage;
796
+ /** Database storage instance (if configured) */
797
+ databases?: CustomDatabaseStorage;
798
+ /** Logger storage instance */
799
+ loggers: CustomLoggerStorage;
800
+ }
801
+ /**
802
+ * Initialize the worker runtime environment.
803
+ * Sets up ServiceWorkerGlobals, caches, directories, and logging.
804
+ *
805
+ * This should be called at the top of a worker entry point before importing user code.
806
+ *
807
+ * @example
808
+ * ```typescript
809
+ * import {config} from "shovel:config";
810
+ * import {initWorkerRuntime, runLifecycle, startWorkerMessageLoop} from "@b9g/platform/runtime";
811
+ *
812
+ * const {registration} = await initWorkerRuntime({config});
813
+ *
814
+ * // Import user code (registers event handlers)
815
+ * await import("./server.js");
816
+ *
817
+ * // Run lifecycle and start message loop
818
+ * await runLifecycle(registration);
819
+ * startWorkerMessageLoop(registration);
820
+ * ```
821
+ */
822
+ export declare function initWorkerRuntime(options: InitWorkerRuntimeOptions): Promise<InitWorkerRuntimeResult>;
823
+ /**
824
+ * Options for the worker message loop
825
+ */
826
+ export interface WorkerMessageLoopOptions {
827
+ registration: ShovelServiceWorkerRegistration;
828
+ databases?: CustomDatabaseStorage;
829
+ caches?: CacheStorage;
830
+ }
831
+ /**
832
+ * Start the worker message loop for handling requests.
833
+ * This function sets up message handling for request/response communication
834
+ * with the main thread via postMessage.
835
+ *
836
+ * @param options - The registration and resources to manage
837
+ */
838
+ export declare function startWorkerMessageLoop(options: ShovelServiceWorkerRegistration | WorkerMessageLoopOptions): void;
839
+ /** Log level for filtering */
840
+ export type LogLevel = "debug" | "info" | "warning" | "error";
841
+ /** Sink configuration */
842
+ export interface SinkConfig {
843
+ /** Reified implementation (factory function from build-time code generation) */
844
+ impl?: (...args: any[]) => unknown;
845
+ /** Additional options passed to the factory (path, maxSize, etc.) */
846
+ [key: string]: unknown;
847
+ }
848
+ /** Logger configuration - matches LogTape's logger config structure */
849
+ export interface LoggerConfig {
850
+ /** Category as string or array for hierarchy. e.g. "myapp" or ["myapp", "db"] */
851
+ category: string | string[];
852
+ /** Log level for this category. Inherits from parent if not specified. */
853
+ level?: LogLevel;
854
+ /** Sink names to add. Inherits from parent by default. */
855
+ sinks?: string[];
856
+ /** Set to "override" to replace parent sinks instead of inherit */
857
+ parentSinks?: "override";
858
+ }
859
+ export interface LoggingConfig {
860
+ /** Named sinks. "console" is always available implicitly. */
861
+ sinks?: Record<string, SinkConfig>;
862
+ /** Logger configurations. Shovel provides defaults for ["shovel", ...] categories. */
863
+ loggers?: LoggerConfig[];
864
+ }
865
+ /** Processed logging config with all defaults applied */
866
+ export interface ProcessedLoggingConfig {
867
+ sinks: Record<string, SinkConfig>;
868
+ loggers: LoggerConfig[];
570
869
  }
571
870
  /**
572
871
  * Configure LogTape logging based on Shovel config.
573
872
  * Call this in both main thread and workers.
574
873
  *
575
- * @param loggingConfig - The logging configuration (sinks defaults to console)
576
- * @param options - Additional options
577
- * @param options.reset - Whether to reset existing LogTape config (default: true)
874
+ * Uses LogTape-aligned config structure:
875
+ * - Named sinks (console is implicit)
876
+ * - Loggers array with category hierarchy support
877
+ * - Shovel provides default loggers for ["shovel", ...] categories
878
+ *
879
+ * @param loggingConfig - The logging configuration
578
880
  */
579
- export declare function configureLogging(loggingConfig: LoggingConfig, options?: {
580
- reset?: boolean;
581
- }): Promise<void>;
881
+ export declare function configureLogging(loggingConfig: LoggingConfig): Promise<void>;
582
882
  export {};