@b9g/platform 0.1.11 → 0.1.12
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 +1 -1
- package/package.json +7 -31
- package/src/index.d.ts +216 -11
- package/src/index.js +488 -103
- package/src/runtime.d.ts +155 -7
- package/src/runtime.js +393 -245
- package/src/shovel-config.d.ts +10 -0
- package/src/worker.d.ts +39 -0
- package/src/worker.js +285 -0
- package/src/config.d.ts +0 -172
- package/src/config.js +0 -641
- package/src/cookie-store.d.ts +0 -80
- package/src/cookie-store.js +0 -233
- package/src/single-threaded.d.ts +0 -59
- package/src/single-threaded.js +0 -114
- package/src/worker-pool.d.ts +0 -93
- package/src/worker-pool.js +0 -390
package/src/runtime.d.ts
CHANGED
|
@@ -2,14 +2,97 @@
|
|
|
2
2
|
* ServiceWorker Runtime - Complete ServiceWorker API Implementation
|
|
3
3
|
*
|
|
4
4
|
* This module provides the complete ServiceWorker runtime environment for Shovel:
|
|
5
|
+
* - Cookie Store API (RequestCookieStore for per-request cookie management)
|
|
5
6
|
* - Base Event Classes (ExtendableEvent, FetchEvent, InstallEvent, ActivateEvent)
|
|
6
7
|
* - ServiceWorker API Type Shims (Client, Clients, ServiceWorkerRegistration, etc.)
|
|
7
8
|
* - ServiceWorkerGlobals (installs ServiceWorker globals onto any JavaScript runtime)
|
|
8
9
|
*
|
|
9
10
|
* Based on: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API#interfaces
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
declare global {
|
|
13
|
+
interface CookieListItem {
|
|
14
|
+
domain?: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
expires?: number;
|
|
17
|
+
secure?: boolean;
|
|
18
|
+
sameSite?: CookieSameSite;
|
|
19
|
+
partitioned?: boolean;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export type CookieSameSite = globalThis.CookieSameSite;
|
|
23
|
+
export type CookieInit = globalThis.CookieInit;
|
|
24
|
+
export type CookieStoreGetOptions = globalThis.CookieStoreGetOptions;
|
|
25
|
+
export type CookieStoreDeleteOptions = globalThis.CookieStoreDeleteOptions;
|
|
26
|
+
export type CookieListItem = globalThis.CookieListItem;
|
|
27
|
+
export type CookieList = CookieListItem[];
|
|
28
|
+
/**
|
|
29
|
+
* Parse Cookie header value into key-value pairs
|
|
30
|
+
* Cookie: name=value; name2=value2
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseCookieHeader(cookieHeader: string): Map<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* Serialize cookie into Set-Cookie header value
|
|
35
|
+
*/
|
|
36
|
+
export declare function serializeCookie(cookie: CookieInit): string;
|
|
37
|
+
/**
|
|
38
|
+
* Parse Set-Cookie header into CookieListItem
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseSetCookieHeader(setCookieHeader: string): CookieListItem;
|
|
41
|
+
/**
|
|
42
|
+
* RequestCookieStore - Cookie Store implementation for ServiceWorker contexts
|
|
43
|
+
*
|
|
44
|
+
* This implementation:
|
|
45
|
+
* - Reads cookies from the incoming Request's Cookie header
|
|
46
|
+
* - Tracks changes (set/delete operations)
|
|
47
|
+
* - Exports changes as Set-Cookie headers for the Response
|
|
48
|
+
*
|
|
49
|
+
* It follows the Cookie Store API spec but is designed for server-side
|
|
50
|
+
* request handling rather than browser contexts.
|
|
51
|
+
*/
|
|
52
|
+
export declare class RequestCookieStore extends EventTarget {
|
|
53
|
+
#private;
|
|
54
|
+
onchange: ((this: RequestCookieStore, ev: Event) => any) | null;
|
|
55
|
+
constructor(request?: Request);
|
|
56
|
+
get(nameOrOptions: string | CookieStoreGetOptions): Promise<CookieListItem | null>;
|
|
57
|
+
getAll(nameOrOptions?: string | CookieStoreGetOptions): Promise<CookieList>;
|
|
58
|
+
set(nameOrOptions: string | CookieInit, value?: string): Promise<void>;
|
|
59
|
+
delete(nameOrOptions: string | CookieStoreDeleteOptions): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Get Set-Cookie headers for all changes
|
|
62
|
+
* This should be called when constructing the Response
|
|
63
|
+
*/
|
|
64
|
+
getSetCookieHeaders(): string[];
|
|
65
|
+
hasChanges(): boolean;
|
|
66
|
+
clearChanges(): void;
|
|
67
|
+
}
|
|
68
|
+
import type { DirectoryStorage } from "@b9g/filesystem";
|
|
69
|
+
import { type Logger } from "@logtape/logtape";
|
|
70
|
+
/**
|
|
71
|
+
* 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.
|
|
75
|
+
*/
|
|
76
|
+
export interface LoggerStorage {
|
|
77
|
+
/**
|
|
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"])
|
|
81
|
+
*/
|
|
82
|
+
open(...categories: string[]): Logger;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Factory function type for creating loggers
|
|
86
|
+
*/
|
|
87
|
+
export type LoggerFactory = (...categories: string[]) => Logger;
|
|
88
|
+
/**
|
|
89
|
+
* Custom logger storage implementation that wraps a factory function
|
|
90
|
+
*/
|
|
91
|
+
export declare class CustomLoggerStorage implements LoggerStorage {
|
|
92
|
+
#private;
|
|
93
|
+
constructor(factory: LoggerFactory);
|
|
94
|
+
open(...categories: string[]): Logger;
|
|
95
|
+
}
|
|
13
96
|
/** Symbol for ending dispatch phase (internal use only) */
|
|
14
97
|
declare const kEndDispatchPhase: unique symbol;
|
|
15
98
|
/** Symbol for checking if extensions are allowed (internal use only) */
|
|
@@ -333,8 +416,10 @@ interface NotificationOptions {
|
|
|
333
416
|
export interface ServiceWorkerGlobalsOptions {
|
|
334
417
|
/** ServiceWorker registration instance */
|
|
335
418
|
registration: ServiceWorkerRegistration;
|
|
336
|
-
/**
|
|
337
|
-
|
|
419
|
+
/** Directory storage (file system access) - REQUIRED */
|
|
420
|
+
directories: DirectoryStorage;
|
|
421
|
+
/** Logger storage (logging access) - REQUIRED */
|
|
422
|
+
loggers: LoggerStorage;
|
|
338
423
|
/** Cache storage (required by ServiceWorkerGlobalScope) - REQUIRED */
|
|
339
424
|
caches: CacheStorage;
|
|
340
425
|
/** Development mode flag */
|
|
@@ -355,7 +440,7 @@ export declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
|
|
|
355
440
|
/**
|
|
356
441
|
* ServiceWorkerGlobals - Installs ServiceWorker globals onto globalThis
|
|
357
442
|
*
|
|
358
|
-
* This class holds ServiceWorker API implementations (caches,
|
|
443
|
+
* This class holds ServiceWorker API implementations (caches, directories, clients, etc.)
|
|
359
444
|
* and patches them onto globalThis via install(). It maintains the browser invariant
|
|
360
445
|
* that self === globalThis while providing ServiceWorker APIs.
|
|
361
446
|
*
|
|
@@ -366,7 +451,8 @@ export declare class ServiceWorkerGlobals implements ServiceWorkerGlobalScope {
|
|
|
366
451
|
readonly self: any;
|
|
367
452
|
readonly registration: ServiceWorkerRegistration;
|
|
368
453
|
readonly caches: CacheStorage;
|
|
369
|
-
readonly
|
|
454
|
+
readonly directories: DirectoryStorage;
|
|
455
|
+
readonly loggers: LoggerStorage;
|
|
370
456
|
readonly clients: Clients;
|
|
371
457
|
get cookieStore(): any;
|
|
372
458
|
readonly serviceWorker: any;
|
|
@@ -415,7 +501,8 @@ export declare class ServiceWorkerGlobals implements ServiceWorkerGlobalScope {
|
|
|
415
501
|
*/
|
|
416
502
|
skipWaiting(): Promise<void>;
|
|
417
503
|
/**
|
|
418
|
-
* Event target delegation to registration
|
|
504
|
+
* Event target delegation - ServiceWorker events go to registration,
|
|
505
|
+
* other events (like "message" for worker threads) go to native handler
|
|
419
506
|
*/
|
|
420
507
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
|
|
421
508
|
removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
|
|
@@ -431,4 +518,65 @@ export declare class ServiceWorkerGlobals implements ServiceWorkerGlobalScope {
|
|
|
431
518
|
*/
|
|
432
519
|
restore(): void;
|
|
433
520
|
}
|
|
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
|
+
/** Cache provider configuration */
|
|
551
|
+
export interface CacheConfig {
|
|
552
|
+
provider?: string;
|
|
553
|
+
[key: string]: unknown;
|
|
554
|
+
}
|
|
555
|
+
/** Directory (filesystem) provider configuration */
|
|
556
|
+
export interface DirectoryConfig {
|
|
557
|
+
provider?: string;
|
|
558
|
+
path?: string;
|
|
559
|
+
[key: string]: unknown;
|
|
560
|
+
}
|
|
561
|
+
/** Shovel application configuration (from shovel.json) */
|
|
562
|
+
export interface ShovelConfig {
|
|
563
|
+
port?: number;
|
|
564
|
+
host?: string;
|
|
565
|
+
workers?: number;
|
|
566
|
+
platform?: string;
|
|
567
|
+
logging?: LoggingConfig;
|
|
568
|
+
caches?: Record<string, CacheConfig>;
|
|
569
|
+
directories?: Record<string, DirectoryConfig>;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Configure LogTape logging based on Shovel config.
|
|
573
|
+
* Call this in both main thread and workers.
|
|
574
|
+
*
|
|
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)
|
|
578
|
+
*/
|
|
579
|
+
export declare function configureLogging(loggingConfig: LoggingConfig, options?: {
|
|
580
|
+
reset?: boolean;
|
|
581
|
+
}): Promise<void>;
|
|
434
582
|
export {};
|