@b9g/platform 0.1.11 → 0.1.13
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 +22 -38
- package/src/config.d.ts +15 -163
- package/src/config.js +18 -630
- package/src/globals.d.ts +119 -0
- package/src/index.d.ts +294 -25
- package/src/index.js +466 -126
- package/src/runtime.d.ts +423 -22
- package/src/runtime.js +693 -250
- package/src/shovel-config.d.ts +10 -0
- package/chunk-P57PW2II.js +0 -11
- 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/README.md
CHANGED
|
@@ -213,7 +213,7 @@ const platform = new CloudflarePlatform({
|
|
|
213
213
|
|
|
214
214
|
### Re-exports from @b9g/filesystem
|
|
215
215
|
|
|
216
|
-
- `
|
|
216
|
+
- `DirectoryStorage`, `Directory`, `DirectoryFactory`, `CustomDirectoryStorage`
|
|
217
217
|
|
|
218
218
|
### Re-exports from @b9g/cache
|
|
219
219
|
|
package/package.json
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/platform",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.13",
|
|
4
|
+
"description": "The portable meta-framework built on web standards.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"service-worker",
|
|
7
7
|
"universal",
|
|
8
8
|
"deployment",
|
|
9
9
|
"platform",
|
|
10
|
-
"registry",
|
|
11
10
|
"node",
|
|
12
11
|
"bun",
|
|
13
12
|
"cloudflare",
|
|
14
13
|
"workers",
|
|
14
|
+
"cache",
|
|
15
|
+
"framework",
|
|
16
|
+
"meta-framework",
|
|
17
|
+
"esbuild",
|
|
15
18
|
"shovel"
|
|
16
19
|
],
|
|
17
20
|
"dependencies": {
|
|
18
|
-
"@b9g/async-context": "^0.
|
|
19
|
-
"@b9g/cache": "^0.
|
|
21
|
+
"@b9g/async-context": "^0.2.0-beta.0",
|
|
22
|
+
"@b9g/cache": "^0.2.0-beta.0",
|
|
20
23
|
"@b9g/filesystem": "^0.1.7",
|
|
24
|
+
"@b9g/zen": "^0.1.6",
|
|
21
25
|
"@logtape/logtape": "^1.2.0"
|
|
22
26
|
},
|
|
23
27
|
"devDependencies": {
|
|
24
|
-
"@b9g/libuild": "^0.1.
|
|
25
|
-
"
|
|
28
|
+
"@b9g/libuild": "^0.1.20",
|
|
29
|
+
"@b9g/node-webworker": "^0.2.0-beta.1",
|
|
30
|
+
"@b9g/platform-bun": "^0.1.10",
|
|
31
|
+
"@b9g/platform-node": "^0.1.12"
|
|
26
32
|
},
|
|
27
33
|
"peerDependencies": {
|
|
28
34
|
"@logtape/file": "^1.0.0",
|
|
@@ -57,14 +63,6 @@
|
|
|
57
63
|
"import": "./src/index.js"
|
|
58
64
|
},
|
|
59
65
|
"./package.json": "./package.json",
|
|
60
|
-
"./worker-pool": {
|
|
61
|
-
"types": "./src/worker-pool.d.ts",
|
|
62
|
-
"import": "./src/worker-pool.js"
|
|
63
|
-
},
|
|
64
|
-
"./worker-pool.js": {
|
|
65
|
-
"types": "./src/worker-pool.d.ts",
|
|
66
|
-
"import": "./src/worker-pool.js"
|
|
67
|
-
},
|
|
68
66
|
"./runtime": {
|
|
69
67
|
"types": "./src/runtime.d.ts",
|
|
70
68
|
"import": "./src/runtime.js"
|
|
@@ -73,22 +71,6 @@
|
|
|
73
71
|
"types": "./src/runtime.d.ts",
|
|
74
72
|
"import": "./src/runtime.js"
|
|
75
73
|
},
|
|
76
|
-
"./config": {
|
|
77
|
-
"types": "./src/config.d.ts",
|
|
78
|
-
"import": "./src/config.js"
|
|
79
|
-
},
|
|
80
|
-
"./config.js": {
|
|
81
|
-
"types": "./src/config.d.ts",
|
|
82
|
-
"import": "./src/config.js"
|
|
83
|
-
},
|
|
84
|
-
"./cookie-store": {
|
|
85
|
-
"types": "./src/cookie-store.d.ts",
|
|
86
|
-
"import": "./src/cookie-store.js"
|
|
87
|
-
},
|
|
88
|
-
"./cookie-store.js": {
|
|
89
|
-
"types": "./src/cookie-store.d.ts",
|
|
90
|
-
"import": "./src/cookie-store.js"
|
|
91
|
-
},
|
|
92
74
|
"./index": {
|
|
93
75
|
"types": "./src/index.d.ts",
|
|
94
76
|
"import": "./src/index.js"
|
|
@@ -97,13 +79,15 @@
|
|
|
97
79
|
"types": "./src/index.d.ts",
|
|
98
80
|
"import": "./src/index.js"
|
|
99
81
|
},
|
|
100
|
-
"./
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
"./globals.d.ts": "./src/globals.d.ts",
|
|
83
|
+
"./shovel-config.d.ts": "./src/shovel-config.d.ts",
|
|
84
|
+
"./config": {
|
|
85
|
+
"types": "./src/config.d.ts",
|
|
86
|
+
"import": "./src/config.js"
|
|
103
87
|
},
|
|
104
|
-
"./
|
|
105
|
-
"types": "./src/
|
|
106
|
-
"import": "./src/
|
|
88
|
+
"./config.js": {
|
|
89
|
+
"types": "./src/config.d.ts",
|
|
90
|
+
"import": "./src/config.js"
|
|
107
91
|
}
|
|
108
92
|
}
|
|
109
93
|
}
|
package/src/config.d.ts
CHANGED
|
@@ -1,172 +1,24 @@
|
|
|
1
|
+
/// <reference path="./globals.d.ts" />
|
|
2
|
+
/// <reference path="./shovel-config.d.ts" />
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
4
|
+
* Config Validation Utilities
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
* - ALL_CAPS = env var reference (e.g., NODE_ENV, PORT)
|
|
6
|
-
* - Everything else = string literal (kebab-case, URLs, camelCase, PascalCase)
|
|
7
|
-
* - Quoted strings = explicit strings (escape hatch)
|
|
8
|
-
* - JavaScript keywords: true, false, null, undefined
|
|
9
|
-
* - Operators: ||, &&, ===, !==, ==, !=, ? :, !
|
|
10
|
-
* - No eval - uses recursive descent parser
|
|
11
|
-
*
|
|
12
|
-
* Examples:
|
|
13
|
-
* "PORT || 3000"
|
|
14
|
-
* "NODE_ENV === production ? redis : memory"
|
|
15
|
-
* "REDIS_URL || redis://localhost:6379"
|
|
16
|
-
* "S3_BUCKET || my-bucket-name"
|
|
17
|
-
* "BASE_PATH || ./uploads"
|
|
18
|
-
*/
|
|
19
|
-
import { Cache } from "@b9g/cache";
|
|
20
|
-
/**
|
|
21
|
-
* Parse a configuration expression with the DSL
|
|
22
|
-
*/
|
|
23
|
-
export declare function parseConfigExpr(expr: string, env?: Record<string, string | undefined>, options?: {
|
|
24
|
-
strict?: boolean;
|
|
25
|
-
}): any;
|
|
26
|
-
/**
|
|
27
|
-
* Process a config value (handles nested objects/arrays)
|
|
28
|
-
*/
|
|
29
|
-
export declare function processConfigValue(value: any, env?: Record<string, string | undefined>, options?: {
|
|
30
|
-
strict?: boolean;
|
|
31
|
-
}): any;
|
|
32
|
-
/**
|
|
33
|
-
* Match a name against config patterns
|
|
34
|
-
*
|
|
35
|
-
* Priority:
|
|
36
|
-
* 1. Exact match: "sessions" matches "sessions"
|
|
37
|
-
* 2. Prefix patterns: "api-*" matches "api-v1", "api-v2" (longest first)
|
|
38
|
-
* 3. Catch-all: "*" matches everything
|
|
39
|
-
*
|
|
40
|
-
* Examples:
|
|
41
|
-
* matchPattern("sessions", {"sessions": {...}, "*": {...}}) → sessions config
|
|
42
|
-
* matchPattern("api-v1", {"api-*": {...}, "*": {...}}) → api-* config
|
|
43
|
-
* matchPattern("random", {"*": {...}}) → * config
|
|
44
|
-
*/
|
|
45
|
-
export declare function matchPattern<T>(name: string, config: Record<string, T>): T | undefined;
|
|
46
|
-
export interface CacheConfig {
|
|
47
|
-
provider?: string | number;
|
|
48
|
-
url?: string | number;
|
|
49
|
-
maxEntries?: string | number;
|
|
50
|
-
TTL?: string | number;
|
|
51
|
-
}
|
|
52
|
-
export interface BucketConfig {
|
|
53
|
-
provider?: string | number;
|
|
54
|
-
path?: string | number;
|
|
55
|
-
bucket?: string | number;
|
|
56
|
-
region?: string | number;
|
|
57
|
-
endpoint?: string | number;
|
|
58
|
-
}
|
|
59
|
-
/** Log level for filtering */
|
|
60
|
-
export type LogLevel = "debug" | "info" | "warning" | "error";
|
|
61
|
-
/** Sink configuration */
|
|
62
|
-
export interface SinkConfig {
|
|
63
|
-
provider: string;
|
|
64
|
-
/** Provider-specific options (path, maxSize, etc.) */
|
|
65
|
-
[key: string]: any;
|
|
66
|
-
}
|
|
67
|
-
/** Per-category logging configuration */
|
|
68
|
-
export interface CategoryLoggingConfig {
|
|
69
|
-
level?: LogLevel;
|
|
70
|
-
sinks?: SinkConfig[];
|
|
71
|
-
}
|
|
72
|
-
export interface LoggingConfig {
|
|
73
|
-
/** Default log level. Defaults to "info" */
|
|
74
|
-
level?: LogLevel;
|
|
75
|
-
/** Default sinks. Defaults to console */
|
|
76
|
-
sinks?: SinkConfig[];
|
|
77
|
-
/** Per-category config (inherits from top-level, can override level and/or sinks) */
|
|
78
|
-
categories?: Record<string, CategoryLoggingConfig>;
|
|
79
|
-
}
|
|
80
|
-
export interface ShovelConfig {
|
|
81
|
-
platform?: string;
|
|
82
|
-
port?: number | string;
|
|
83
|
-
host?: string;
|
|
84
|
-
workers?: number | string;
|
|
85
|
-
logging?: LoggingConfig;
|
|
86
|
-
caches?: Record<string, CacheConfig>;
|
|
87
|
-
buckets?: Record<string, BucketConfig>;
|
|
88
|
-
}
|
|
89
|
-
/** Processed logging config with all defaults applied */
|
|
90
|
-
export interface ProcessedLoggingConfig {
|
|
91
|
-
level: LogLevel;
|
|
92
|
-
sinks: SinkConfig[];
|
|
93
|
-
categories: Record<string, CategoryLoggingConfig>;
|
|
94
|
-
}
|
|
95
|
-
export interface ProcessedShovelConfig {
|
|
96
|
-
platform?: string;
|
|
97
|
-
port: number;
|
|
98
|
-
host: string;
|
|
99
|
-
workers: number;
|
|
100
|
-
logging: ProcessedLoggingConfig;
|
|
101
|
-
caches: Record<string, CacheConfig>;
|
|
102
|
-
buckets: Record<string, BucketConfig>;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Load Shovel configuration from shovel.json or package.json
|
|
106
|
-
* Priority: shovel.json > package.json "shovel" field > defaults
|
|
107
|
-
* @param cwd - Current working directory (must be provided by runtime adapter)
|
|
6
|
+
* Helpers for validating config objects at runtime.
|
|
108
7
|
*/
|
|
109
|
-
export declare function loadConfig(cwd: string): ProcessedShovelConfig;
|
|
110
8
|
/**
|
|
111
|
-
*
|
|
112
|
-
* Call this in both main thread and workers.
|
|
113
|
-
*
|
|
114
|
-
* @param loggingConfig - The logging configuration from ProcessedShovelConfig.logging
|
|
115
|
-
* @param options - Additional options
|
|
116
|
-
* @param options.reset - Whether to reset existing LogTape config (default: true)
|
|
117
|
-
* @param options.cwd - Working directory for resolving relative paths
|
|
118
|
-
*/
|
|
119
|
-
export declare function configureLogging(loggingConfig: ProcessedLoggingConfig, options?: {
|
|
120
|
-
reset?: boolean;
|
|
121
|
-
cwd?: string;
|
|
122
|
-
}): Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Get cache config for a specific cache name (with pattern matching)
|
|
9
|
+
* Error thrown when config validation fails
|
|
125
10
|
*/
|
|
126
|
-
export declare
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
export declare function getBucketConfig(config: ProcessedShovelConfig, name: string): BucketConfig;
|
|
131
|
-
export interface BucketFactoryOptions {
|
|
132
|
-
/** Base directory for path resolution (entrypoint directory) - REQUIRED */
|
|
133
|
-
baseDir: string;
|
|
134
|
-
/** Shovel configuration for overrides */
|
|
135
|
-
config?: ProcessedShovelConfig;
|
|
11
|
+
export declare class ConfigValidationError extends Error {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly issue: "undefined" | "NaN";
|
|
14
|
+
constructor(path: string, issue: "undefined" | "NaN");
|
|
136
15
|
}
|
|
137
16
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* Provider resolution:
|
|
142
|
-
* 1. "node" -> built-in NodeBucket (default)
|
|
143
|
-
* 2. "memory" -> built-in MemoryBucket
|
|
144
|
-
* 3. "s3" -> @b9g/filesystem-s3 (blessed module)
|
|
145
|
-
* 4. Any other string -> treated as a module name (e.g., "my-custom-bucket")
|
|
146
|
-
*
|
|
147
|
-
* Custom bucket modules must export a class that:
|
|
148
|
-
* - Implements FileSystemDirectoryHandle
|
|
149
|
-
* - Has constructor(name: string, options?: object)
|
|
150
|
-
*/
|
|
151
|
-
export declare function createBucketFactory(options: BucketFactoryOptions): (name: string) => Promise<FileSystemDirectoryHandle>;
|
|
152
|
-
export interface CacheFactoryOptions {
|
|
153
|
-
/** Shovel configuration for cache settings */
|
|
154
|
-
config?: ProcessedShovelConfig;
|
|
155
|
-
/** Default provider when not specified in config. Defaults to "memory". */
|
|
156
|
-
defaultProvider?: string;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Creates a cache factory function for CustomCacheStorage.
|
|
160
|
-
* Lazily imports cache implementations.
|
|
161
|
-
*
|
|
162
|
-
* Provider resolution:
|
|
163
|
-
* 1. "memory" -> built-in MemoryCache
|
|
164
|
-
* 2. "redis" -> @b9g/cache-redis (blessed module)
|
|
165
|
-
* 3. "cloudflare" -> native Cloudflare caches.open(name)
|
|
166
|
-
* 4. Any other string -> treated as a module name (e.g., "my-custom-cache")
|
|
17
|
+
* Validate that a config object has no undefined or NaN values.
|
|
18
|
+
* Call this at runtime to fail fast on missing env vars.
|
|
167
19
|
*
|
|
168
|
-
*
|
|
169
|
-
* -
|
|
170
|
-
*
|
|
20
|
+
* @param config - The config object to validate
|
|
21
|
+
* @param path - Current path for error messages (used in recursion)
|
|
22
|
+
* @throws ConfigValidationError if any value is undefined or NaN
|
|
171
23
|
*/
|
|
172
|
-
export declare function
|
|
24
|
+
export declare function validateConfig(config: Record<string, unknown>, path?: string): void;
|