@velajs/cloudflare 1.1.0 → 1.2.0
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.
|
@@ -1,14 +1,33 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
1
|
import { BindingRef } from "../binding-ref.js";
|
|
3
2
|
// Single factory for every Cloudflare binding module (KV, D1, R2, ...).
|
|
4
3
|
// Each binding module is just a bag of (token, service); this generates
|
|
5
4
|
// the canonical forRoot() shape for them.
|
|
5
|
+
//
|
|
6
|
+
// Identity model (post vela audit #2):
|
|
7
|
+
// - One real module class is declared per binding TYPE (KV, D1, R2, ...).
|
|
8
|
+
// Its `name` property is set so error messages and diagnostics carry
|
|
9
|
+
// the friendly name (e.g. `KVModule`).
|
|
10
|
+
// - Each `forRoot({ binding })` returns `{ module, key: binding, ... }`.
|
|
11
|
+
// Vela dedups by (module, key), so two `KVModule.forRoot({...})` calls
|
|
12
|
+
// with different bindings coexist as distinct module instances; two
|
|
13
|
+
// calls with the same binding dedup.
|
|
6
14
|
export function createBindingModule(opts) {
|
|
15
|
+
// Fresh module class per binding TYPE (one KVModule, one D1Module, ...).
|
|
16
|
+
// The computed-property-name idiom is the canonical JS way to give a
|
|
17
|
+
// class expression a dynamic `name`: NamedEvaluation reads the property
|
|
18
|
+
// key and stamps it on the class at creation, instead of patching the
|
|
19
|
+
// (configurable, non-writable) `name` slot via Object.defineProperty.
|
|
20
|
+
const className = `${opts.name}Module`;
|
|
21
|
+
const moduleClass = {
|
|
22
|
+
[className]: class {
|
|
23
|
+
}
|
|
24
|
+
}[className];
|
|
7
25
|
return {
|
|
8
26
|
forRoot ({ binding }) {
|
|
9
27
|
const ref = new BindingRef(binding);
|
|
10
28
|
return {
|
|
11
|
-
module:
|
|
29
|
+
module: moduleClass,
|
|
30
|
+
key: binding,
|
|
12
31
|
providers: [
|
|
13
32
|
{
|
|
14
33
|
provide: opts.bindingRefToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velajs/cloudflare",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Cloudflare Workers integration for Vela framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,13 +17,6 @@
|
|
|
17
17
|
"LICENSE",
|
|
18
18
|
"CHANGELOG.md"
|
|
19
19
|
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "rm -rf dist && swc src -d dist --strip-leading-paths && tsc --emitDeclarationOnly",
|
|
22
|
-
"test": "vitest run",
|
|
23
|
-
"typecheck": "tsc --noEmit",
|
|
24
|
-
"prepare": "swc src -d dist --strip-leading-paths && tsc --emitDeclarationOnly",
|
|
25
|
-
"prepublishOnly": "pnpm run typecheck && pnpm test"
|
|
26
|
-
},
|
|
27
20
|
"sideEffects": false,
|
|
28
21
|
"keywords": [
|
|
29
22
|
"vela",
|
|
@@ -52,24 +45,22 @@
|
|
|
52
45
|
},
|
|
53
46
|
"peerDependencies": {
|
|
54
47
|
"@cloudflare/workers-types": ">=4",
|
|
55
|
-
"@velajs/vela": ">=1.
|
|
48
|
+
"@velajs/vela": ">=1.5.0",
|
|
56
49
|
"hono": ">=4"
|
|
57
50
|
},
|
|
58
51
|
"devDependencies": {
|
|
59
52
|
"@cloudflare/workers-types": "^4",
|
|
60
53
|
"@swc/cli": "^0.8.0",
|
|
61
54
|
"@swc/core": "^1.15.11",
|
|
62
|
-
"@velajs/vela": "^1.
|
|
55
|
+
"@velajs/vela": "^1.5.0",
|
|
63
56
|
"hono": "^4",
|
|
64
57
|
"typescript": "^5",
|
|
65
58
|
"unplugin-swc": "^1.5.9",
|
|
66
59
|
"vitest": "^4.0.18"
|
|
67
60
|
},
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
"esbuild"
|
|
73
|
-
]
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "rm -rf dist && swc src -d dist --strip-leading-paths && tsc --emitDeclarationOnly",
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"typecheck": "tsc --noEmit"
|
|
74
65
|
}
|
|
75
|
-
}
|
|
66
|
+
}
|