sqlite-actor 0.1.4 → 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 +17 -1
- package/dist/index.js +16 -4
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Currently, `sqlite-actor` bundles the following extensions directly into its WAS
|
|
|
19
19
|
*(Note: We plan to support more extensions in the future based on user requests. Please open a GitHub issue if you need another extension.)*
|
|
20
20
|
|
|
21
21
|
## Features
|
|
22
|
-
- **Zero-Config**: The WASM binary is
|
|
22
|
+
- **Zero-Config (Hybrid)**: The WASM binary is inlined as a base64 string for easy use in most environments. For security-restricted environments like Cloudflare Workers, we also export the `.wasm` file directly for ESM imports.
|
|
23
23
|
- **Synchronous API**: Designed for the single-threaded nature of Actors, the SDK is completely synchronous after the initial load.
|
|
24
24
|
- **VFS Bridge**: It uses a memory-first Virtual File System (VFS) to back the database to the actor's provided key-value storage.
|
|
25
25
|
|
|
@@ -51,6 +51,22 @@ export class MyVectorActor {
|
|
|
51
51
|
return new Response(JSON.stringify(results));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
### Cloudflare Workers / Durable Objects
|
|
55
|
+
|
|
56
|
+
Cloudflare Workers have a strict "No-Eval" policy that blocks instantiating WASM from a buffer. To use `sqlite-actor` in Workers, you must import the `.wasm` file as an ES module and pass it to `create()`:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
import { SqliteActor } from "sqlite-actor";
|
|
60
|
+
import wasmModule from "sqlite-actor/sqlite-actor.wasm";
|
|
61
|
+
|
|
62
|
+
export class MyVectorActor {
|
|
63
|
+
async fetch(request) {
|
|
64
|
+
// Pass the pre-compiled wasmModule to bypass "No-Eval" restrictions
|
|
65
|
+
const db = await SqliteActor.create(this.state.storage, { wasmModule });
|
|
66
|
+
|
|
67
|
+
// ... use the database
|
|
68
|
+
}
|
|
69
|
+
}
|
|
54
70
|
```
|
|
55
71
|
|
|
56
72
|
## Development setup (Building from Source)
|
package/dist/index.js
CHANGED
|
@@ -33,10 +33,18 @@ export class SqliteActor {
|
|
|
33
33
|
else if (options?.wasmBinary) {
|
|
34
34
|
config.wasmBinary = options.wasmBinary;
|
|
35
35
|
}
|
|
36
|
-
else {
|
|
36
|
+
else if (typeof SQLITE_ACTOR_WASM_BASE64 !== "undefined") {
|
|
37
37
|
config.wasmBinary = base64ToUint8Array(SQLITE_ACTOR_WASM_BASE64);
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
else {
|
|
40
|
+
throw new Error("No WASM source provided (wasmModule, wasmBinary, or inlined base64)");
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
this.wasm = await initSqlite3(config);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throw new Error(`Failed to initialize SQLite3 WASM: ${e.message}`);
|
|
47
|
+
}
|
|
40
48
|
// 2. Pre-load all pages into memory cache for synchronous VFS access
|
|
41
49
|
const metaMaxPageId = await this.kv.get("meta:maxPageId");
|
|
42
50
|
this.maxPageId = metaMaxPageId ? Number(new TextDecoder().decode(metaMaxPageId)) : -1;
|
|
@@ -201,6 +209,7 @@ export class SqliteActor {
|
|
|
201
209
|
}
|
|
202
210
|
}
|
|
203
211
|
function base64ToUint8Array(base64) {
|
|
212
|
+
// Browser / Cloudflare Workers
|
|
204
213
|
if (typeof atob !== "undefined") {
|
|
205
214
|
const binaryString = atob(base64);
|
|
206
215
|
const bytes = new Uint8Array(binaryString.length);
|
|
@@ -209,8 +218,11 @@ function base64ToUint8Array(base64) {
|
|
|
209
218
|
}
|
|
210
219
|
return bytes;
|
|
211
220
|
}
|
|
212
|
-
|
|
221
|
+
// Node.js
|
|
222
|
+
// @ts-ignore
|
|
223
|
+
if (typeof Buffer !== "undefined") {
|
|
213
224
|
// @ts-ignore
|
|
214
|
-
return
|
|
225
|
+
return Buffer.from(base64, "base64");
|
|
215
226
|
}
|
|
227
|
+
throw new Error("No base64 decoder found (atob or Buffer)");
|
|
216
228
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sqlite-actor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SQLite + sqlite-vec vector database for actor platforms",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./sqlite-actor.wasm": "./dist/sqlite-actor.wasm"
|
|
11
|
+
},
|
|
8
12
|
"files": [
|
|
9
13
|
"dist"
|
|
10
14
|
],
|