@b9g/platform 0.1.3 → 0.1.5
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 +94 -28
- package/package.json +45 -87
- package/src/config.d.ts +105 -0
- package/src/config.js +463 -0
- package/src/cookie-store.d.ts +80 -0
- package/src/cookie-store.js +231 -0
- package/src/index.d.ts +189 -9
- package/src/index.js +242 -49
- package/src/runtime.d.ts +426 -0
- package/src/runtime.js +997 -0
- package/src/single-threaded.d.ts +57 -0
- package/src/single-threaded.js +107 -0
- package/src/worker-pool.d.ts +22 -32
- package/src/worker-pool.js +214 -100
- package/src/adapter-registry.d.ts +0 -53
- package/src/adapter-registry.js +0 -71
- package/src/base-platform.d.ts +0 -49
- package/src/base-platform.js +0 -114
- package/src/detection.d.ts +0 -36
- package/src/detection.js +0 -126
- package/src/directory-storage.d.ts +0 -41
- package/src/directory-storage.js +0 -53
- package/src/filesystem.d.ts +0 -16
- package/src/filesystem.js +0 -20
- package/src/registry.d.ts +0 -31
- package/src/registry.js +0 -74
- package/src/service-worker.d.ts +0 -175
- package/src/service-worker.js +0 -245
- package/src/types.d.ts +0 -246
- package/src/types.js +0 -36
- package/src/utils.d.ts +0 -33
- package/src/utils.js +0 -139
- package/src/worker-web.js +0 -119
package/src/base-platform.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/// <reference types="./base-platform.d.ts" />
|
|
2
|
-
// src/base-platform.ts
|
|
3
|
-
import { loadCacheAdapter, loadFilesystemAdapter } from "./adapter-registry.js";
|
|
4
|
-
var BasePlatform = class {
|
|
5
|
-
config;
|
|
6
|
-
constructor(config = {}) {
|
|
7
|
-
this.config = config;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Create cache storage with dynamic adapter loading
|
|
11
|
-
* Uses platform defaults when specific cache types aren't configured
|
|
12
|
-
*/
|
|
13
|
-
async createCaches(config) {
|
|
14
|
-
const mergedConfig = this.mergeCacheConfig(config);
|
|
15
|
-
return this.buildCacheStorage(mergedConfig);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Get platform-specific default cache configuration
|
|
19
|
-
* Subclasses override this to provide optimal defaults for their runtime
|
|
20
|
-
*/
|
|
21
|
-
getDefaultCacheConfig() {
|
|
22
|
-
return {
|
|
23
|
-
pages: { type: "memory" },
|
|
24
|
-
api: { type: "memory" },
|
|
25
|
-
static: { type: "memory" }
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Merge user config with platform defaults
|
|
30
|
-
*/
|
|
31
|
-
mergeCacheConfig(userConfig) {
|
|
32
|
-
const defaults = this.getDefaultCacheConfig();
|
|
33
|
-
const platformConfig = this.config.caches || {};
|
|
34
|
-
return {
|
|
35
|
-
...defaults,
|
|
36
|
-
...platformConfig,
|
|
37
|
-
...userConfig
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Build CacheStorage instance with dynamic adapter loading
|
|
42
|
-
*/
|
|
43
|
-
async buildCacheStorage(config) {
|
|
44
|
-
const caches = /* @__PURE__ */ new Map();
|
|
45
|
-
for (const [name, cacheConfig] of Object.entries(config)) {
|
|
46
|
-
if (cacheConfig && typeof cacheConfig === "object" && "type" in cacheConfig) {
|
|
47
|
-
const cache = await this.loadCacheInstance(cacheConfig);
|
|
48
|
-
caches.set(name, cache);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
async open(name) {
|
|
53
|
-
const cache = caches.get(name);
|
|
54
|
-
if (!cache) {
|
|
55
|
-
throw new Error(`Cache '${name}' not configured`);
|
|
56
|
-
}
|
|
57
|
-
return cache;
|
|
58
|
-
},
|
|
59
|
-
async delete(name) {
|
|
60
|
-
const deleted = caches.delete(name);
|
|
61
|
-
return deleted;
|
|
62
|
-
},
|
|
63
|
-
async has(name) {
|
|
64
|
-
return caches.has(name);
|
|
65
|
-
},
|
|
66
|
-
async keys() {
|
|
67
|
-
return Array.from(caches.keys());
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Load a single cache instance using dynamic import
|
|
73
|
-
*/
|
|
74
|
-
async loadCacheInstance(config) {
|
|
75
|
-
if (!config.type) {
|
|
76
|
-
throw new Error("Cache configuration must specify a type");
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
return await loadCacheAdapter(config.type, config);
|
|
80
|
-
} catch (error) {
|
|
81
|
-
if (error instanceof Error) {
|
|
82
|
-
throw new Error(`Failed to load cache adapter: ${error.message}`);
|
|
83
|
-
}
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Load filesystem adapter using dynamic import
|
|
89
|
-
*/
|
|
90
|
-
async loadFilesystemAdapter(config) {
|
|
91
|
-
const fsConfig = config || this.config.filesystem || this.getDefaultFilesystemConfig();
|
|
92
|
-
if (!fsConfig.type) {
|
|
93
|
-
throw new Error("Filesystem configuration must specify a type");
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
return await loadFilesystemAdapter(fsConfig.type, fsConfig);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
if (error instanceof Error) {
|
|
99
|
-
throw new Error(`Failed to load filesystem adapter: ${error.message}`);
|
|
100
|
-
}
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Get platform-specific default filesystem configuration
|
|
106
|
-
* Subclasses override this to provide optimal defaults for their runtime
|
|
107
|
-
*/
|
|
108
|
-
getDefaultFilesystemConfig() {
|
|
109
|
-
return { type: "memory" };
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
export {
|
|
113
|
-
BasePlatform
|
|
114
|
-
};
|
package/src/detection.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Platform detection utilities
|
|
3
|
-
* Centralized logic for detecting JavaScript runtime and deployment platforms
|
|
4
|
-
*/
|
|
5
|
-
import type { PlatformDetection } from "./types.js";
|
|
6
|
-
/**
|
|
7
|
-
* Detect the current JavaScript runtime
|
|
8
|
-
*/
|
|
9
|
-
export declare function detectRuntime(): "bun" | "deno" | "node";
|
|
10
|
-
/**
|
|
11
|
-
* Detect platform for development (uses current runtime)
|
|
12
|
-
*/
|
|
13
|
-
export declare function detectDevelopmentPlatform(): string;
|
|
14
|
-
/**
|
|
15
|
-
* Comprehensive platform detection with confidence scoring
|
|
16
|
-
*/
|
|
17
|
-
export declare function detectPlatforms(): PlatformDetection[];
|
|
18
|
-
/**
|
|
19
|
-
* Get the best platform detection
|
|
20
|
-
*/
|
|
21
|
-
export declare function getBestPlatformDetection(): PlatformDetection;
|
|
22
|
-
/**
|
|
23
|
-
* Resolve platform name from options or auto-detect
|
|
24
|
-
*/
|
|
25
|
-
export declare function resolvePlatform(options: {
|
|
26
|
-
platform?: string;
|
|
27
|
-
target?: string;
|
|
28
|
-
}): string;
|
|
29
|
-
/**
|
|
30
|
-
* Create platform instance based on name
|
|
31
|
-
*/
|
|
32
|
-
export declare function createPlatform(platformName: string, options?: any): Promise<any>;
|
|
33
|
-
/**
|
|
34
|
-
* Display platform information (for CLI info command)
|
|
35
|
-
*/
|
|
36
|
-
export declare function displayPlatformInfo(platformName: string): void;
|
package/src/detection.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/// <reference types="./detection.d.ts" />
|
|
2
|
-
// src/detection.ts
|
|
3
|
-
function detectRuntime() {
|
|
4
|
-
if (typeof Bun !== "undefined" || process.versions?.bun) {
|
|
5
|
-
return "bun";
|
|
6
|
-
}
|
|
7
|
-
if (typeof Deno !== "undefined") {
|
|
8
|
-
return "deno";
|
|
9
|
-
}
|
|
10
|
-
return "node";
|
|
11
|
-
}
|
|
12
|
-
function detectDevelopmentPlatform() {
|
|
13
|
-
const runtime = detectRuntime();
|
|
14
|
-
switch (runtime) {
|
|
15
|
-
case "bun":
|
|
16
|
-
return "bun";
|
|
17
|
-
case "deno":
|
|
18
|
-
return "node";
|
|
19
|
-
case "node":
|
|
20
|
-
default:
|
|
21
|
-
return "node";
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function detectPlatforms() {
|
|
25
|
-
const detections = [];
|
|
26
|
-
if (typeof Bun !== "undefined") {
|
|
27
|
-
detections.push({
|
|
28
|
-
platform: "bun",
|
|
29
|
-
confidence: 0.9,
|
|
30
|
-
reasons: ["Bun global detected"]
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
if (typeof EdgeRuntime !== "undefined") {
|
|
34
|
-
detections.push({
|
|
35
|
-
platform: "vercel",
|
|
36
|
-
confidence: 0.9,
|
|
37
|
-
reasons: ["Vercel EdgeRuntime detected"]
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (typeof Deno !== "undefined") {
|
|
41
|
-
detections.push({
|
|
42
|
-
platform: "deno",
|
|
43
|
-
confidence: 0.9,
|
|
44
|
-
reasons: ["Deno global detected"]
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
if (typeof caches !== "undefined" && typeof Response !== "undefined" && typeof crypto !== "undefined") {
|
|
48
|
-
if (typeof addEventListener !== "undefined" && typeof fetch !== "undefined") {
|
|
49
|
-
detections.push({
|
|
50
|
-
platform: "cloudflare-workers",
|
|
51
|
-
confidence: 0.8,
|
|
52
|
-
reasons: ["Worker-like environment detected", "Web APIs available"]
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
57
|
-
detections.push({
|
|
58
|
-
platform: "node",
|
|
59
|
-
confidence: 0.7,
|
|
60
|
-
reasons: ["Node.js process detected"]
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (detections.length === 0) {
|
|
64
|
-
detections.push({
|
|
65
|
-
platform: "unknown",
|
|
66
|
-
confidence: 0,
|
|
67
|
-
reasons: ["No platform detected"]
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
return detections.sort((a, b) => b.confidence - a.confidence);
|
|
71
|
-
}
|
|
72
|
-
function getBestPlatformDetection() {
|
|
73
|
-
const detections = detectPlatforms();
|
|
74
|
-
return detections[0];
|
|
75
|
-
}
|
|
76
|
-
function resolvePlatform(options) {
|
|
77
|
-
if (options.platform) {
|
|
78
|
-
return options.platform;
|
|
79
|
-
}
|
|
80
|
-
if (options.target) {
|
|
81
|
-
return options.target;
|
|
82
|
-
}
|
|
83
|
-
return detectDevelopmentPlatform();
|
|
84
|
-
}
|
|
85
|
-
async function createPlatform(platformName, options = {}) {
|
|
86
|
-
switch (platformName) {
|
|
87
|
-
case "node": {
|
|
88
|
-
const modulePath = import.meta.resolve("@b9g/platform-node");
|
|
89
|
-
const { createNodePlatform } = await import(modulePath);
|
|
90
|
-
return createNodePlatform(options);
|
|
91
|
-
}
|
|
92
|
-
case "bun": {
|
|
93
|
-
const modulePath = import.meta.resolve("@b9g/platform-bun");
|
|
94
|
-
const { createBunPlatform } = await import(modulePath);
|
|
95
|
-
return createBunPlatform(options);
|
|
96
|
-
}
|
|
97
|
-
case "cloudflare":
|
|
98
|
-
case "cloudflare-workers":
|
|
99
|
-
case "cf": {
|
|
100
|
-
const modulePath = import.meta.resolve("@b9g/platform-cloudflare");
|
|
101
|
-
const { createCloudflarePlatform } = await import(modulePath);
|
|
102
|
-
return createCloudflarePlatform(options);
|
|
103
|
-
}
|
|
104
|
-
default:
|
|
105
|
-
throw new Error(
|
|
106
|
-
`Unknown platform: ${platformName}. Available platforms: node, bun, cloudflare`
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function displayPlatformInfo(platformName) {
|
|
111
|
-
const runtime = detectRuntime();
|
|
112
|
-
const detection = getBestPlatformDetection();
|
|
113
|
-
console.info(`\u{1F680} Platform: ${platformName}`);
|
|
114
|
-
console.info(`\u2699\uFE0F Runtime: ${runtime}`);
|
|
115
|
-
console.info(`\u{1F50D} Auto-detected: ${detection.platform} (confidence: ${detection.confidence})`);
|
|
116
|
-
console.info(`\u{1F4A1} Reasons: ${detection.reasons.join(", ")}`);
|
|
117
|
-
}
|
|
118
|
-
export {
|
|
119
|
-
createPlatform,
|
|
120
|
-
detectDevelopmentPlatform,
|
|
121
|
-
detectPlatforms,
|
|
122
|
-
detectRuntime,
|
|
123
|
-
displayPlatformInfo,
|
|
124
|
-
getBestPlatformDetection,
|
|
125
|
-
resolvePlatform
|
|
126
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bucket Storage implementation for ServiceWorker self.buckets API
|
|
3
|
-
*
|
|
4
|
-
* This implements the proposed web standard interface that parallels CacheStorage
|
|
5
|
-
* for structured filesystem access in ServiceWorkers.
|
|
6
|
-
*/
|
|
7
|
-
import type { BucketStorage as BucketStorageInterface } from "./service-worker.js";
|
|
8
|
-
/**
|
|
9
|
-
* Platform-agnostic bucket storage implementation
|
|
10
|
-
* Uses bucket pattern where each bucket name maps to a separate filesystem root
|
|
11
|
-
*/
|
|
12
|
-
export declare class PlatformBucketStorage implements BucketStorageInterface {
|
|
13
|
-
private buckets;
|
|
14
|
-
constructor(rootPath?: string);
|
|
15
|
-
/**
|
|
16
|
-
* Open a named bucket - creates if it doesn't exist
|
|
17
|
-
* Well-known names: 'assets', 'static', 'uploads', 'temp'
|
|
18
|
-
* Special values: '', '/', '.' return the root bucket
|
|
19
|
-
*/
|
|
20
|
-
open(name: string): Promise<FileSystemDirectoryHandle>;
|
|
21
|
-
/**
|
|
22
|
-
* Check if a named bucket exists
|
|
23
|
-
*/
|
|
24
|
-
has(name: string): Promise<boolean>;
|
|
25
|
-
/**
|
|
26
|
-
* Delete a named bucket and all its contents
|
|
27
|
-
*/
|
|
28
|
-
delete(name: string): Promise<boolean>;
|
|
29
|
-
/**
|
|
30
|
-
* List all available bucket names
|
|
31
|
-
*/
|
|
32
|
-
keys(): Promise<string[]>;
|
|
33
|
-
/**
|
|
34
|
-
* Alias for open() - for compatibility with File System Access API naming
|
|
35
|
-
*/
|
|
36
|
-
getDirectoryHandle(name: string): Promise<FileSystemDirectoryHandle>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Create a BucketStorage instance from a root path
|
|
40
|
-
*/
|
|
41
|
-
export declare function createBucketStorage(rootPath?: string): BucketStorageInterface;
|
package/src/directory-storage.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/// <reference types="./directory-storage.d.ts" />
|
|
2
|
-
// src/directory-storage.ts
|
|
3
|
-
import { BucketStorage, LocalBucket } from "@b9g/filesystem";
|
|
4
|
-
var PlatformBucketStorage = class {
|
|
5
|
-
buckets;
|
|
6
|
-
constructor(rootPath = "./dist") {
|
|
7
|
-
this.buckets = new BucketStorage((name) => {
|
|
8
|
-
if (name === "" || name === "/" || name === ".") {
|
|
9
|
-
return new LocalBucket(rootPath);
|
|
10
|
-
}
|
|
11
|
-
return new LocalBucket(`${rootPath}/${name}`);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Open a named bucket - creates if it doesn't exist
|
|
16
|
-
* Well-known names: 'assets', 'static', 'uploads', 'temp'
|
|
17
|
-
* Special values: '', '/', '.' return the root bucket
|
|
18
|
-
*/
|
|
19
|
-
async open(name) {
|
|
20
|
-
return await this.buckets.open(name);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Check if a named bucket exists
|
|
24
|
-
*/
|
|
25
|
-
async has(name) {
|
|
26
|
-
return await this.buckets.has(name);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Delete a named bucket and all its contents
|
|
30
|
-
*/
|
|
31
|
-
async delete(name) {
|
|
32
|
-
return await this.buckets.delete(name);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* List all available bucket names
|
|
36
|
-
*/
|
|
37
|
-
async keys() {
|
|
38
|
-
return await this.buckets.keys();
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Alias for open() - for compatibility with File System Access API naming
|
|
42
|
-
*/
|
|
43
|
-
async getDirectoryHandle(name) {
|
|
44
|
-
return await this.open(name);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function createBucketStorage(rootPath = "./dist") {
|
|
48
|
-
return new PlatformBucketStorage(rootPath);
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
PlatformBucketStorage,
|
|
52
|
-
createBucketStorage
|
|
53
|
-
};
|
package/src/filesystem.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File System Access API implementation
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Get the file system directory handle for the specified name
|
|
6
|
-
* Auto-registers Node.js platform if no platform is detected
|
|
7
|
-
*/
|
|
8
|
-
export declare function getDirectoryHandle(name: string): Promise<FileSystemDirectoryHandle>;
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated Use getDirectoryHandle() instead
|
|
11
|
-
*/
|
|
12
|
-
export declare function getBucket(name?: string): Promise<FileSystemDirectoryHandle>;
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Use getDirectoryHandle() instead
|
|
15
|
-
*/
|
|
16
|
-
export declare function getFileSystemRoot(name?: string): Promise<FileSystemDirectoryHandle>;
|
package/src/filesystem.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="./filesystem.d.ts" />
|
|
2
|
-
// src/filesystem.ts
|
|
3
|
-
import { getPlatformAsync } from "./registry.js";
|
|
4
|
-
async function getDirectoryHandle(name) {
|
|
5
|
-
const platform = await getPlatformAsync();
|
|
6
|
-
return await platform.getDirectoryHandle(name);
|
|
7
|
-
}
|
|
8
|
-
async function getBucket(name) {
|
|
9
|
-
const platform = await getPlatformAsync();
|
|
10
|
-
return await platform.getDirectoryHandle(name || "");
|
|
11
|
-
}
|
|
12
|
-
async function getFileSystemRoot(name) {
|
|
13
|
-
const platform = await getPlatformAsync();
|
|
14
|
-
return await platform.getDirectoryHandle(name || "");
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
getBucket,
|
|
18
|
-
getDirectoryHandle,
|
|
19
|
-
getFileSystemRoot
|
|
20
|
-
};
|
package/src/registry.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Platform registry for auto-detection and management
|
|
3
|
-
*/
|
|
4
|
-
import type { Platform, PlatformDetection, PlatformRegistry } from "./types.js";
|
|
5
|
-
/**
|
|
6
|
-
* Global platform registry
|
|
7
|
-
*/
|
|
8
|
-
declare class DefaultPlatformRegistry implements PlatformRegistry {
|
|
9
|
-
private platforms;
|
|
10
|
-
register(name: string, platform: Platform): void;
|
|
11
|
-
get(name: string): Platform | undefined;
|
|
12
|
-
detect(): PlatformDetection;
|
|
13
|
-
list(): string[];
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Global platform registry instance
|
|
17
|
-
*/
|
|
18
|
-
export declare const platformRegistry: DefaultPlatformRegistry;
|
|
19
|
-
/**
|
|
20
|
-
* Auto-detect and return the appropriate platform
|
|
21
|
-
*/
|
|
22
|
-
export declare function detectPlatform(): Platform | null;
|
|
23
|
-
/**
|
|
24
|
-
* Get platform by name with error handling
|
|
25
|
-
*/
|
|
26
|
-
export declare function getPlatform(name?: string): Platform;
|
|
27
|
-
/**
|
|
28
|
-
* Get platform with async auto-registration fallback
|
|
29
|
-
*/
|
|
30
|
-
export declare function getPlatformAsync(name?: string): Promise<Platform>;
|
|
31
|
-
export {};
|
package/src/registry.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/// <reference types="./registry.d.ts" />
|
|
2
|
-
// src/registry.ts
|
|
3
|
-
import { getBestPlatformDetection } from "./detection.js";
|
|
4
|
-
var DefaultPlatformRegistry = class {
|
|
5
|
-
platforms = /* @__PURE__ */ new Map();
|
|
6
|
-
register(name, platform) {
|
|
7
|
-
this.platforms.set(name, platform);
|
|
8
|
-
}
|
|
9
|
-
get(name) {
|
|
10
|
-
return this.platforms.get(name);
|
|
11
|
-
}
|
|
12
|
-
detect() {
|
|
13
|
-
return getBestPlatformDetection();
|
|
14
|
-
}
|
|
15
|
-
list() {
|
|
16
|
-
return Array.from(this.platforms.keys());
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var platformRegistry = new DefaultPlatformRegistry();
|
|
20
|
-
function detectPlatform() {
|
|
21
|
-
const detection = platformRegistry.detect();
|
|
22
|
-
if (detection.confidence > 0.5) {
|
|
23
|
-
const platform = platformRegistry.get(detection.platform);
|
|
24
|
-
if (platform) {
|
|
25
|
-
return platform;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
function getPlatform(name) {
|
|
31
|
-
if (name) {
|
|
32
|
-
const platform = platformRegistry.get(name);
|
|
33
|
-
if (!platform) {
|
|
34
|
-
const available = platformRegistry.list();
|
|
35
|
-
throw new Error(
|
|
36
|
-
`Platform '${name}' not found. Available platforms: ${available.join(", ")}`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return platform;
|
|
40
|
-
}
|
|
41
|
-
const detected = detectPlatform();
|
|
42
|
-
if (!detected) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
"No platform could be auto-detected. Please register a platform manually or specify a platform name."
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
return detected;
|
|
48
|
-
}
|
|
49
|
-
async function getPlatformAsync(name) {
|
|
50
|
-
if (name) {
|
|
51
|
-
const platform = platformRegistry.get(name);
|
|
52
|
-
if (!platform) {
|
|
53
|
-
const available = platformRegistry.list();
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Platform '${name}' not found. Available platforms: ${available.join(", ")}`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return platform;
|
|
59
|
-
}
|
|
60
|
-
const detected = detectPlatform();
|
|
61
|
-
if (!detected) {
|
|
62
|
-
const { createNodePlatform } = await import("@b9g/platform-node");
|
|
63
|
-
const nodePlatform = createNodePlatform();
|
|
64
|
-
platformRegistry.register("node", nodePlatform);
|
|
65
|
-
return nodePlatform;
|
|
66
|
-
}
|
|
67
|
-
return detected;
|
|
68
|
-
}
|
|
69
|
-
export {
|
|
70
|
-
detectPlatform,
|
|
71
|
-
getPlatform,
|
|
72
|
-
getPlatformAsync,
|
|
73
|
-
platformRegistry
|
|
74
|
-
};
|
package/src/service-worker.d.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ServiceWorker runtime environment for Shovel entrypoints
|
|
3
|
-
*
|
|
4
|
-
* Provides ServiceWorker APIs (self, addEventListener, etc.) in any JavaScript runtime
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* ExtendableEvent base class following ServiceWorker spec
|
|
8
|
-
*/
|
|
9
|
-
export declare class ExtendableEvent extends Event {
|
|
10
|
-
private promises;
|
|
11
|
-
private pendingPromises;
|
|
12
|
-
constructor(type: string, pendingPromises: Set<Promise<any>>);
|
|
13
|
-
waitUntil(promise: Promise<any>): void;
|
|
14
|
-
getPromises(): Promise<any>[];
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* ServiceWorker-style fetch event
|
|
18
|
-
*/
|
|
19
|
-
export declare class FetchEvent extends ExtendableEvent {
|
|
20
|
-
readonly request: Request;
|
|
21
|
-
private responsePromise;
|
|
22
|
-
private responded;
|
|
23
|
-
constructor(request: Request, pendingPromises: Set<Promise<any>>);
|
|
24
|
-
respondWith(response: Response | Promise<Response>): void;
|
|
25
|
-
getResponse(): Promise<Response> | null;
|
|
26
|
-
hasResponded(): boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* ServiceWorker-style install event
|
|
30
|
-
*/
|
|
31
|
-
export declare class InstallEvent extends ExtendableEvent {
|
|
32
|
-
constructor(pendingPromises: Set<Promise<any>>);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* ServiceWorker-style activate event
|
|
36
|
-
*/
|
|
37
|
-
export declare class ActivateEvent extends ExtendableEvent {
|
|
38
|
-
constructor(pendingPromises: Set<Promise<any>>);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Legacy interfaces for backward compatibility
|
|
42
|
-
*/
|
|
43
|
-
export interface ShovelFetchEvent extends Event {
|
|
44
|
-
readonly type: "fetch";
|
|
45
|
-
readonly request: Request;
|
|
46
|
-
respondWith(response: Response | Promise<Response>): void;
|
|
47
|
-
waitUntil(promise: Promise<any>): void;
|
|
48
|
-
}
|
|
49
|
-
export interface ShovelInstallEvent extends Event {
|
|
50
|
-
readonly type: "install";
|
|
51
|
-
waitUntil(promise: Promise<any>): void;
|
|
52
|
-
}
|
|
53
|
-
export interface ShovelActivateEvent extends Event {
|
|
54
|
-
readonly type: "activate";
|
|
55
|
-
waitUntil(promise: Promise<any>): void;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* ServiceWorker runtime that can be embedded in any platform
|
|
59
|
-
*/
|
|
60
|
-
export declare class ServiceWorkerRuntime extends EventTarget {
|
|
61
|
-
private pendingPromises;
|
|
62
|
-
private isInstalled;
|
|
63
|
-
private isActivated;
|
|
64
|
-
private eventListeners;
|
|
65
|
-
constructor();
|
|
66
|
-
addEventListener(type: string, listener: Function): void;
|
|
67
|
-
removeEventListener(type: string, listener: Function): void;
|
|
68
|
-
/**
|
|
69
|
-
* Create a fetch event and dispatch it
|
|
70
|
-
*/
|
|
71
|
-
handleRequest(request: Request): Promise<Response>;
|
|
72
|
-
/**
|
|
73
|
-
* Install the ServiceWorker
|
|
74
|
-
*/
|
|
75
|
-
install(): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Activate the ServiceWorker
|
|
78
|
-
*/
|
|
79
|
-
activate(): Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
* Check if ready to handle requests
|
|
82
|
-
*/
|
|
83
|
-
get ready(): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Wait for all pending promises to resolve
|
|
86
|
-
*/
|
|
87
|
-
waitForPending(): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* Reset the ServiceWorker state (for hot reloading)
|
|
90
|
-
*/
|
|
91
|
-
reset(): void;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Bucket storage interface - parallels CacheStorage for filesystem access
|
|
95
|
-
* This could become a future web standard
|
|
96
|
-
*/
|
|
97
|
-
export interface BucketStorage {
|
|
98
|
-
/**
|
|
99
|
-
* Open a named bucket - returns FileSystemDirectoryHandle (root of that bucket)
|
|
100
|
-
* Well-known names: 'assets', 'static', 'uploads', 'temp'
|
|
101
|
-
*/
|
|
102
|
-
open(name: string): Promise<FileSystemDirectoryHandle>;
|
|
103
|
-
/**
|
|
104
|
-
* Alias for open() - for compatibility with File System Access API naming
|
|
105
|
-
*/
|
|
106
|
-
getDirectoryHandle(name: string): Promise<FileSystemDirectoryHandle>;
|
|
107
|
-
/**
|
|
108
|
-
* Check if a named bucket exists
|
|
109
|
-
*/
|
|
110
|
-
has(name: string): Promise<boolean>;
|
|
111
|
-
/**
|
|
112
|
-
* Delete a named bucket and all its contents
|
|
113
|
-
*/
|
|
114
|
-
delete(name: string): Promise<boolean>;
|
|
115
|
-
/**
|
|
116
|
-
* List all available bucket names
|
|
117
|
-
*/
|
|
118
|
-
keys(): Promise<string[]>;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Create ServiceWorker globals for a module context
|
|
122
|
-
*/
|
|
123
|
-
export declare function createServiceWorkerGlobals(runtime: ServiceWorkerRuntime, options?: {
|
|
124
|
-
caches?: any;
|
|
125
|
-
buckets?: BucketStorage;
|
|
126
|
-
isDevelopment?: boolean;
|
|
127
|
-
hotReload?: () => Promise<void>;
|
|
128
|
-
}): {
|
|
129
|
-
console: Console;
|
|
130
|
-
setTimeout: typeof setTimeout;
|
|
131
|
-
clearTimeout: typeof clearTimeout;
|
|
132
|
-
setInterval: typeof setInterval;
|
|
133
|
-
clearInterval: typeof clearInterval;
|
|
134
|
-
fetch: typeof fetch;
|
|
135
|
-
Request: {
|
|
136
|
-
new (input: RequestInfo | URL, init?: RequestInit): Request;
|
|
137
|
-
prototype: Request;
|
|
138
|
-
};
|
|
139
|
-
Response: {
|
|
140
|
-
new (body?: BodyInit | null, init?: ResponseInit): Response;
|
|
141
|
-
prototype: Response;
|
|
142
|
-
error(): Response;
|
|
143
|
-
json(data: any, init?: ResponseInit): Response;
|
|
144
|
-
redirect(url: string | URL, status?: number): Response;
|
|
145
|
-
};
|
|
146
|
-
Headers: {
|
|
147
|
-
new (init?: HeadersInit): Headers;
|
|
148
|
-
prototype: Headers;
|
|
149
|
-
};
|
|
150
|
-
URL: {
|
|
151
|
-
new (url: string | URL, base?: string | URL): URL;
|
|
152
|
-
prototype: URL;
|
|
153
|
-
canParse(url: string | URL, base?: string | URL): boolean;
|
|
154
|
-
createObjectURL(obj: Blob | MediaSource): string;
|
|
155
|
-
parse(url: string | URL, base?: string | URL): URL | null;
|
|
156
|
-
revokeObjectURL(url: string): void;
|
|
157
|
-
};
|
|
158
|
-
URLSearchParams: {
|
|
159
|
-
new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
|
|
160
|
-
prototype: URLSearchParams;
|
|
161
|
-
};
|
|
162
|
-
caches: any;
|
|
163
|
-
buckets: BucketStorage;
|
|
164
|
-
self: ServiceWorkerRuntime;
|
|
165
|
-
addEventListener: any;
|
|
166
|
-
removeEventListener: any;
|
|
167
|
-
dispatchEvent: any;
|
|
168
|
-
skipWaiting: () => Promise<void>;
|
|
169
|
-
clients: {
|
|
170
|
-
claim(): Promise<void>;
|
|
171
|
-
get(id: string): Promise<any>;
|
|
172
|
-
matchAll(options?: any): Promise<any[]>;
|
|
173
|
-
openWindow(url: string | URL): Promise<any>;
|
|
174
|
-
};
|
|
175
|
-
};
|