@b9g/platform 0.1.15 → 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/README.md +1 -1
- package/package.json +12 -7
- package/src/runtime.d.ts +4 -1
- package/src/runtime.js +35 -16
package/README.md
CHANGED
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",
|
|
@@ -17,17 +17,22 @@
|
|
|
17
17
|
"esbuild",
|
|
18
18
|
"shovel"
|
|
19
19
|
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/bikeshaving/shovel.git",
|
|
23
|
+
"directory": "packages/platform"
|
|
24
|
+
},
|
|
20
25
|
"dependencies": {
|
|
21
|
-
"@b9g/async-context": "^0.2.
|
|
22
|
-
"@b9g/cache": "^0.2.
|
|
23
|
-
"@b9g/filesystem": "^0.1.
|
|
26
|
+
"@b9g/async-context": "^0.2.1",
|
|
27
|
+
"@b9g/cache": "^0.2.2",
|
|
28
|
+
"@b9g/filesystem": "^0.1.10",
|
|
24
29
|
"@logtape/logtape": "^1.2.0"
|
|
25
30
|
},
|
|
26
31
|
"devDependencies": {
|
|
27
32
|
"@b9g/libuild": "^0.1.20",
|
|
28
|
-
"@b9g/node-webworker": "^0.2.
|
|
29
|
-
"@b9g/platform-bun": "^0.1.
|
|
30
|
-
"@b9g/platform-node": "^0.1.
|
|
33
|
+
"@b9g/node-webworker": "^0.2.1",
|
|
34
|
+
"@b9g/platform-bun": "^0.1.15",
|
|
35
|
+
"@b9g/platform-node": "^0.1.17"
|
|
31
36
|
},
|
|
32
37
|
"peerDependencies": {
|
|
33
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
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
} from "@logtape/logtape";
|
|
11
11
|
function parseCookieHeader(cookieHeader) {
|
|
12
12
|
const cookies = /* @__PURE__ */ new Map();
|
|
13
|
-
if (!cookieHeader)
|
|
13
|
+
if (!cookieHeader)
|
|
14
|
+
return cookies;
|
|
14
15
|
const pairs = cookieHeader.split(/;\s*/);
|
|
15
16
|
for (const pair of pairs) {
|
|
16
17
|
const [name, ...valueParts] = pair.split("=");
|
|
@@ -115,7 +116,8 @@ var RequestCookieStore = class extends EventTarget {
|
|
|
115
116
|
}
|
|
116
117
|
if (this.#changes.has(name)) {
|
|
117
118
|
const change = this.#changes.get(name);
|
|
118
|
-
if (change === null || change === void 0)
|
|
119
|
+
if (change === null || change === void 0)
|
|
120
|
+
return null;
|
|
119
121
|
return {
|
|
120
122
|
name: change.name,
|
|
121
123
|
value: change.value,
|
|
@@ -136,7 +138,8 @@ var RequestCookieStore = class extends EventTarget {
|
|
|
136
138
|
...this.#changes.keys()
|
|
137
139
|
]);
|
|
138
140
|
for (const cookieName of allNames) {
|
|
139
|
-
if (name && cookieName !== name)
|
|
141
|
+
if (name && cookieName !== name)
|
|
142
|
+
continue;
|
|
140
143
|
if (this.#changes.has(cookieName) && this.#changes.get(cookieName) === null) {
|
|
141
144
|
continue;
|
|
142
145
|
}
|
|
@@ -375,8 +378,8 @@ function promiseWithTimeout(promise, timeoutMs, errorMessage) {
|
|
|
375
378
|
)
|
|
376
379
|
]);
|
|
377
380
|
}
|
|
378
|
-
var kEndDispatchPhase =
|
|
379
|
-
var kCanExtend =
|
|
381
|
+
var kEndDispatchPhase = Symbol.for("shovel.endDispatchPhase");
|
|
382
|
+
var kCanExtend = Symbol.for("shovel.canExtend");
|
|
380
383
|
var ShovelExtendableEvent = class extends Event {
|
|
381
384
|
#promises;
|
|
382
385
|
#dispatchPhase;
|
|
@@ -576,10 +579,10 @@ var ShovelNavigationPreloadManager = class {
|
|
|
576
579
|
async setHeaderValue(_value) {
|
|
577
580
|
}
|
|
578
581
|
};
|
|
579
|
-
var kServiceWorker =
|
|
580
|
-
var kDispatchInstall =
|
|
581
|
-
var kDispatchActivate =
|
|
582
|
-
var kHandleRequest =
|
|
582
|
+
var kServiceWorker = Symbol("serviceWorker");
|
|
583
|
+
var kDispatchInstall = Symbol("dispatchInstall");
|
|
584
|
+
var kDispatchActivate = Symbol("dispatchActivate");
|
|
585
|
+
var kHandleRequest = Symbol("handleRequest");
|
|
583
586
|
var ShovelServiceWorkerRegistration = class extends EventTarget {
|
|
584
587
|
scope;
|
|
585
588
|
updateViaCache;
|
|
@@ -631,7 +634,8 @@ var ShovelServiceWorkerRegistration = class extends EventTarget {
|
|
|
631
634
|
* @internal Use runLifecycle() instead of calling this directly
|
|
632
635
|
*/
|
|
633
636
|
async [kDispatchInstall]() {
|
|
634
|
-
if (this[kServiceWorker].state !== "parsed")
|
|
637
|
+
if (this[kServiceWorker].state !== "parsed")
|
|
638
|
+
return;
|
|
635
639
|
this[kServiceWorker]._setState("installing");
|
|
636
640
|
return new Promise((resolve, reject) => {
|
|
637
641
|
const event = new ShovelInstallEvent();
|
|
@@ -1130,7 +1134,8 @@ var ServiceWorkerGlobals = class {
|
|
|
1130
1134
|
* other events (like "message" for worker threads) go to native handler
|
|
1131
1135
|
*/
|
|
1132
1136
|
addEventListener(type, listener, options) {
|
|
1133
|
-
if (!listener)
|
|
1137
|
+
if (!listener)
|
|
1138
|
+
return;
|
|
1134
1139
|
if (isServiceWorkerEvent(type)) {
|
|
1135
1140
|
this.registration.addEventListener(type, listener, options);
|
|
1136
1141
|
} else {
|
|
@@ -1141,7 +1146,8 @@ var ServiceWorkerGlobals = class {
|
|
|
1141
1146
|
}
|
|
1142
1147
|
}
|
|
1143
1148
|
removeEventListener(type, listener, options) {
|
|
1144
|
-
if (!listener)
|
|
1149
|
+
if (!listener)
|
|
1150
|
+
return;
|
|
1145
1151
|
if (isServiceWorkerEvent(type)) {
|
|
1146
1152
|
this.registration.removeEventListener(type, listener, options);
|
|
1147
1153
|
} else {
|
|
@@ -1213,12 +1219,24 @@ var ServiceWorkerGlobals = class {
|
|
|
1213
1219
|
}
|
|
1214
1220
|
}
|
|
1215
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
|
+
}
|
|
1216
1234
|
function isClass(fn) {
|
|
1217
1235
|
return typeof fn === "function" && fn.prototype !== void 0;
|
|
1218
1236
|
}
|
|
1219
1237
|
function createDirectoryFactory(configs) {
|
|
1220
1238
|
return async (name) => {
|
|
1221
|
-
const config = configs
|
|
1239
|
+
const config = matchPattern(name, configs);
|
|
1222
1240
|
if (!config) {
|
|
1223
1241
|
throw new Error(
|
|
1224
1242
|
`Directory "${name}" is not configured. Available directories: ${Object.keys(configs).join(", ") || "(none)"}`
|
|
@@ -1243,7 +1261,7 @@ function createCacheFactory(options) {
|
|
|
1243
1261
|
if (usePostMessage) {
|
|
1244
1262
|
return new PostMessageCache(name);
|
|
1245
1263
|
}
|
|
1246
|
-
const config = configs
|
|
1264
|
+
const config = matchPattern(name, configs);
|
|
1247
1265
|
if (!config) {
|
|
1248
1266
|
throw new Error(
|
|
1249
1267
|
`Cache "${name}" is not configured. Available caches: ${Object.keys(configs).join(", ") || "(none)"}`
|
|
@@ -1263,7 +1281,7 @@ function createCacheFactory(options) {
|
|
|
1263
1281
|
};
|
|
1264
1282
|
}
|
|
1265
1283
|
async function initWorkerRuntime(options) {
|
|
1266
|
-
const { config } = options;
|
|
1284
|
+
const { config, usePostMessage = true } = options;
|
|
1267
1285
|
const runtimeLogger = getLogger(["shovel", "platform"]);
|
|
1268
1286
|
if (config?.logging) {
|
|
1269
1287
|
await configureLogging(config.logging);
|
|
@@ -1272,7 +1290,7 @@ async function initWorkerRuntime(options) {
|
|
|
1272
1290
|
const caches = new CustomCacheStorage(
|
|
1273
1291
|
createCacheFactory({
|
|
1274
1292
|
configs: config?.caches ?? {},
|
|
1275
|
-
usePostMessage
|
|
1293
|
+
usePostMessage
|
|
1276
1294
|
})
|
|
1277
1295
|
);
|
|
1278
1296
|
const directories = new CustomDirectoryStorage(
|
|
@@ -1396,6 +1414,7 @@ function startWorkerMessageLoop(options) {
|
|
|
1396
1414
|
}
|
|
1397
1415
|
var SHOVEL_DEFAULT_LOGGERS = [
|
|
1398
1416
|
{ category: ["shovel"], level: "info", sinks: ["console"] },
|
|
1417
|
+
{ category: ["app"], level: "info", sinks: ["console"] },
|
|
1399
1418
|
{ category: ["logtape", "meta"], level: "warning", sinks: ["console"] }
|
|
1400
1419
|
];
|
|
1401
1420
|
async function createSink(config) {
|