@b9g/platform 0.1.9 → 0.1.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/platform",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "ServiceWorker-first universal deployment platform. Write ServiceWorker apps once, deploy anywhere (Node/Bun/Cloudflare). Registry-based multi-app orchestration.",
5
5
  "keywords": [
6
6
  "serviceworker",
package/src/config.d.ts CHANGED
@@ -56,10 +56,19 @@ export interface BucketConfig {
56
56
  region?: string | number;
57
57
  endpoint?: string | number;
58
58
  }
59
+ /** Log level for filtering */
60
+ export type LogLevel = "debug" | "info" | "warning" | "error";
61
+ export interface LoggingConfig {
62
+ /** Default log level. Defaults to "error" */
63
+ level?: LogLevel;
64
+ /** Per-category log levels (overrides default) */
65
+ categories?: Record<string, LogLevel>;
66
+ }
59
67
  export interface ShovelConfig {
60
68
  port?: number | string;
61
69
  host?: string;
62
70
  workers?: number | string;
71
+ logging?: LoggingConfig;
63
72
  caches?: Record<string, CacheConfig>;
64
73
  buckets?: Record<string, BucketConfig>;
65
74
  }
@@ -67,6 +76,7 @@ export interface ProcessedShovelConfig {
67
76
  port: number;
68
77
  host: string;
69
78
  workers: number;
79
+ logging: Required<LoggingConfig>;
70
80
  caches: Record<string, CacheConfig>;
71
81
  buckets: Record<string, BucketConfig>;
72
82
  }
@@ -76,6 +86,17 @@ export interface ProcessedShovelConfig {
76
86
  * @param cwd - Current working directory (must be provided by runtime adapter)
77
87
  */
78
88
  export declare function loadConfig(cwd: string): ProcessedShovelConfig;
89
+ /**
90
+ * Configure LogTape logging based on Shovel config.
91
+ * Call this in both main thread and workers.
92
+ *
93
+ * @param loggingConfig - The logging configuration from ProcessedShovelConfig.logging
94
+ * @param options - Additional options
95
+ * @param options.reset - Whether to reset existing LogTape config (default: true)
96
+ */
97
+ export declare function configureLogging(loggingConfig: Required<LoggingConfig>, options?: {
98
+ reset?: boolean;
99
+ }): Promise<void>;
79
100
  /**
80
101
  * Get cache config for a specific cache name (with pattern matching)
81
102
  */
package/src/config.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { readFileSync } from "fs";
4
4
  import { resolve } from "path";
5
5
  import { Cache } from "@b9g/cache";
6
+ import { configure, getConsoleSink } from "@logtape/logtape";
6
7
  function getEnv() {
7
8
  if (typeof import.meta !== "undefined" && import.meta.env) {
8
9
  return import.meta.env;
@@ -395,11 +396,52 @@ function loadConfig(cwd) {
395
396
  port: typeof processed.port === "number" ? processed.port : 3e3,
396
397
  host: processed.host || "localhost",
397
398
  workers: typeof processed.workers === "number" ? processed.workers : 1,
399
+ logging: {
400
+ level: processed.logging?.level || "error",
401
+ categories: processed.logging?.categories || {}
402
+ },
398
403
  caches: processed.caches || {},
399
404
  buckets: processed.buckets || {}
400
405
  };
401
406
  return config;
402
407
  }
408
+ var SHOVEL_CATEGORIES = [
409
+ "cli",
410
+ "watcher",
411
+ "worker",
412
+ "single-threaded",
413
+ "assets",
414
+ "platform-node",
415
+ "platform-bun",
416
+ "platform-cloudflare",
417
+ "cache",
418
+ "cache-redis",
419
+ "router"
420
+ ];
421
+ async function configureLogging(loggingConfig, options = {}) {
422
+ const { level, categories } = loggingConfig;
423
+ const reset = options.reset !== false;
424
+ const loggers = SHOVEL_CATEGORIES.map((category) => {
425
+ const categoryLevel = categories[category] || level;
426
+ return {
427
+ category: [category],
428
+ level: categoryLevel,
429
+ sinks: ["console"]
430
+ };
431
+ });
432
+ loggers.push({
433
+ category: ["logtape", "meta"],
434
+ level: "warning",
435
+ sinks: []
436
+ });
437
+ await configure({
438
+ reset,
439
+ sinks: {
440
+ console: getConsoleSink()
441
+ },
442
+ loggers
443
+ });
444
+ }
403
445
  function getCacheConfig(config, name) {
404
446
  return matchPattern(name, config.caches) || {};
405
447
  }
@@ -506,6 +548,7 @@ For redis: npm install @b9g/cache-redis`
506
548
  };
507
549
  }
508
550
  export {
551
+ configureLogging,
509
552
  createBucketFactory,
510
553
  createCacheFactory,
511
554
  getBucketConfig,
package/src/index.d.ts CHANGED
@@ -192,4 +192,4 @@ export { SingleThreadedRuntime, type SingleThreadedRuntimeOptions, } from "./sin
192
192
  export { ShovelServiceWorkerRegistration, ShovelGlobalScope, FetchEvent, InstallEvent, ActivateEvent, ExtendableEvent, } from "./runtime.js";
193
193
  export { RequestCookieStore, type CookieListItem, type CookieInit, type CookieStoreGetOptions, type CookieStoreDeleteOptions, type CookieSameSite, type CookieList, parseCookieHeader, serializeCookie, parseSetCookieHeader, } from "./cookie-store.js";
194
194
  export { CustomBucketStorage } from "@b9g/filesystem";
195
- export { loadConfig, getCacheConfig, getBucketConfig, parseConfigExpr, processConfigValue, matchPattern, createBucketFactory, createCacheFactory, type ShovelConfig, type CacheConfig, type BucketConfig, type BucketFactoryOptions, type CacheFactoryOptions, type ProcessedShovelConfig, } from "./config.js";
195
+ export { loadConfig, configureLogging, getCacheConfig, getBucketConfig, parseConfigExpr, processConfigValue, matchPattern, createBucketFactory, createCacheFactory, type ShovelConfig, type CacheConfig, type BucketConfig, type LoggingConfig, type LogLevel, type BucketFactoryOptions, type CacheFactoryOptions, type ProcessedShovelConfig, } from "./config.js";
package/src/index.js CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  import { CustomBucketStorage } from "@b9g/filesystem";
28
28
  import {
29
29
  loadConfig,
30
+ configureLogging,
30
31
  getCacheConfig,
31
32
  getBucketConfig,
32
33
  parseConfigExpr,
@@ -237,6 +238,7 @@ export {
237
238
  ShovelGlobalScope,
238
239
  ShovelServiceWorkerRegistration,
239
240
  SingleThreadedRuntime,
241
+ configureLogging,
240
242
  createBucketFactory,
241
243
  createCacheFactory,
242
244
  createPlatform,
package/src/runtime.js CHANGED
@@ -6,6 +6,7 @@ import { CustomBucketStorage } from "@b9g/filesystem";
6
6
  import { CustomCacheStorage } from "@b9g/cache";
7
7
  import { createBucketFactory, createCacheFactory } from "./config.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
+ import { configureLogging } from "./config.js";
9
10
  if (import.meta.env && !import.meta.env.MODE && import.meta.env.NODE_ENV) {
10
11
  import.meta.env.MODE = import.meta.env.NODE_ENV;
11
12
  }
@@ -899,6 +900,9 @@ var workerId = Math.random().toString(36).substring(2, 8);
899
900
  var sendMessage;
900
901
  async function initializeRuntime(config, baseDir) {
901
902
  try {
903
+ if (config?.logging) {
904
+ await configureLogging(config.logging);
905
+ }
902
906
  logger.info(`[Worker-${workerId}] Initializing runtime with config`, {
903
907
  config,
904
908
  baseDir
@@ -5,6 +5,7 @@ import { ShovelGlobalScope, ShovelServiceWorkerRegistration } from "./runtime.js
5
5
  import { CustomBucketStorage } from "@b9g/filesystem";
6
6
  import { CustomCacheStorage } from "@b9g/cache";
7
7
  import {
8
+ configureLogging,
8
9
  createBucketFactory,
9
10
  createCacheFactory
10
11
  } from "./config.js";
@@ -34,6 +35,9 @@ var SingleThreadedRuntime = class {
34
35
  * Initialize the runtime (install scope as globalThis.self)
35
36
  */
36
37
  async init() {
38
+ if (this.#config?.logging) {
39
+ await configureLogging(this.#config.logging);
40
+ }
37
41
  this.#scope.install();
38
42
  logger.info("SingleThreadedRuntime initialized - scope installed");
39
43
  }