@b9g/platform 0.1.16 → 0.1.17
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 +5 -5
- package/src/runtime.d.ts +4 -1
- package/src/runtime.js +17 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/platform",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "The portable meta-framework built on web standards.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"service-worker",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@b9g/async-context": "^0.2.1",
|
|
27
|
-
"@b9g/cache": "^0.2.
|
|
28
|
-
"@b9g/filesystem": "^0.1.
|
|
27
|
+
"@b9g/cache": "^0.2.2",
|
|
28
|
+
"@b9g/filesystem": "^0.1.10",
|
|
29
29
|
"@logtape/logtape": "^1.2.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@b9g/libuild": "^0.1.20",
|
|
33
33
|
"@b9g/node-webworker": "^0.2.1",
|
|
34
|
-
"@b9g/platform-bun": "^0.1.
|
|
35
|
-
"@b9g/platform-node": "^0.1.
|
|
34
|
+
"@b9g/platform-bun": "^0.1.15",
|
|
35
|
+
"@b9g/platform-node": "^0.1.17"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@b9g/zen": "^0.1.6"
|
package/src/runtime.d.ts
CHANGED
|
@@ -780,6 +780,9 @@ export interface WorkerErrorMessage {
|
|
|
780
780
|
export interface InitWorkerRuntimeOptions {
|
|
781
781
|
/** Shovel configuration (from shovel:config) */
|
|
782
782
|
config: ShovelConfig;
|
|
783
|
+
/** Whether to use PostMessageCache for cache operations (default: true).
|
|
784
|
+
* Set to false when the worker handles requests directly (no message loop). */
|
|
785
|
+
usePostMessage?: boolean;
|
|
783
786
|
}
|
|
784
787
|
/**
|
|
785
788
|
* Result from initializing the worker runtime
|
|
@@ -859,7 +862,7 @@ export interface LoggerConfig {
|
|
|
859
862
|
export interface LoggingConfig {
|
|
860
863
|
/** Named sinks. "console" is always available implicitly. */
|
|
861
864
|
sinks?: Record<string, SinkConfig>;
|
|
862
|
-
/** Logger configurations. Shovel provides defaults for ["shovel", ...] categories. */
|
|
865
|
+
/** Logger configurations. Shovel provides defaults for ["shovel", ...] and ["app", ...] categories. */
|
|
863
866
|
loggers?: LoggerConfig[];
|
|
864
867
|
}
|
|
865
868
|
/** Processed logging config with all defaults applied */
|
package/src/runtime.js
CHANGED
|
@@ -1219,12 +1219,24 @@ var ServiceWorkerGlobals = class {
|
|
|
1219
1219
|
}
|
|
1220
1220
|
}
|
|
1221
1221
|
};
|
|
1222
|
+
function matchPattern(name, patterns) {
|
|
1223
|
+
if (patterns[name])
|
|
1224
|
+
return patterns[name];
|
|
1225
|
+
for (const [pattern, value] of Object.entries(patterns)) {
|
|
1226
|
+
if (pattern.includes("*")) {
|
|
1227
|
+
const regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
|
|
1228
|
+
if (regex.test(name))
|
|
1229
|
+
return value;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
return void 0;
|
|
1233
|
+
}
|
|
1222
1234
|
function isClass(fn) {
|
|
1223
1235
|
return typeof fn === "function" && fn.prototype !== void 0;
|
|
1224
1236
|
}
|
|
1225
1237
|
function createDirectoryFactory(configs) {
|
|
1226
1238
|
return async (name) => {
|
|
1227
|
-
const config = configs
|
|
1239
|
+
const config = matchPattern(name, configs);
|
|
1228
1240
|
if (!config) {
|
|
1229
1241
|
throw new Error(
|
|
1230
1242
|
`Directory "${name}" is not configured. Available directories: ${Object.keys(configs).join(", ") || "(none)"}`
|
|
@@ -1249,7 +1261,7 @@ function createCacheFactory(options) {
|
|
|
1249
1261
|
if (usePostMessage) {
|
|
1250
1262
|
return new PostMessageCache(name);
|
|
1251
1263
|
}
|
|
1252
|
-
const config = configs
|
|
1264
|
+
const config = matchPattern(name, configs);
|
|
1253
1265
|
if (!config) {
|
|
1254
1266
|
throw new Error(
|
|
1255
1267
|
`Cache "${name}" is not configured. Available caches: ${Object.keys(configs).join(", ") || "(none)"}`
|
|
@@ -1269,7 +1281,7 @@ function createCacheFactory(options) {
|
|
|
1269
1281
|
};
|
|
1270
1282
|
}
|
|
1271
1283
|
async function initWorkerRuntime(options) {
|
|
1272
|
-
const { config } = options;
|
|
1284
|
+
const { config, usePostMessage = true } = options;
|
|
1273
1285
|
const runtimeLogger = getLogger(["shovel", "platform"]);
|
|
1274
1286
|
if (config?.logging) {
|
|
1275
1287
|
await configureLogging(config.logging);
|
|
@@ -1278,7 +1290,7 @@ async function initWorkerRuntime(options) {
|
|
|
1278
1290
|
const caches = new CustomCacheStorage(
|
|
1279
1291
|
createCacheFactory({
|
|
1280
1292
|
configs: config?.caches ?? {},
|
|
1281
|
-
usePostMessage
|
|
1293
|
+
usePostMessage
|
|
1282
1294
|
})
|
|
1283
1295
|
);
|
|
1284
1296
|
const directories = new CustomDirectoryStorage(
|
|
@@ -1402,6 +1414,7 @@ function startWorkerMessageLoop(options) {
|
|
|
1402
1414
|
}
|
|
1403
1415
|
var SHOVEL_DEFAULT_LOGGERS = [
|
|
1404
1416
|
{ category: ["shovel"], level: "info", sinks: ["console"] },
|
|
1417
|
+
{ category: ["app"], level: "info", sinks: ["console"] },
|
|
1405
1418
|
{ category: ["logtape", "meta"], level: "warning", sinks: ["console"] }
|
|
1406
1419
|
];
|
|
1407
1420
|
async function createSink(config) {
|