@moltendb-web/core 0.1.0-beta.1 → 0.1.0-beta.2

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 CHANGED
@@ -50,7 +50,30 @@ npm install @moltendb-web/core
50
50
  # Install the chainable query builder
51
51
  npm install @moltendb-web/query
52
52
  ```
53
+ 📦 **Bundler Setup**
53
54
 
55
+ MoltenDB handles its own Web Workers and WASM loading automatically. However, depending on your build tool, you may need a tiny config tweak to ensure it serves the static files correctly.
56
+
57
+ **For Vite:**
58
+ Exclude the core package from pre-bundling in your vite.config.js:
59
+
60
+ ```js
61
+ // vite.config.js`
62
+ export default defineConfig({
63
+ optimizeDeps: { exclude: ['@moltendb-web/core'] }
64
+ });
65
+ ```
66
+
67
+ **For Webpack 5 (Next.js, Create React App):**
68
+ Ensure Webpack treats the `.wasm` binary as a static resource in `webpack.config.js`:
69
+
70
+ ```js
71
+ module.exports = {
72
+ module: {
73
+ rules: [{ test: /\.wasm$/, type: 'asset/resource' }]
74
+ }
75
+ };
76
+ ```
54
77
  ---
55
78
 
56
79
  # Quick Start
@@ -62,12 +85,11 @@ TypeScript
62
85
  import { MoltenDB } from '@moltendb-web/core';
63
86
  import { MoltenDBClient, WorkerTransport } from '@moltendb-web/query';
64
87
 
65
- const workerUrl = new URL('@moltendb-web/core/worker', import.meta.url).href;
66
- const db = new MoltenDB('moltendb_demo', { syncEnabled: false, workerUrl });
88
+ const db = new MoltenDB('moltendb_demo');
67
89
  await db.init();
68
90
 
69
91
  // Connect the query builder to the WASM worker
70
- const client = new MoltenDBClient(new WorkerTransport(db.worker));
92
+ const client = new MoltenDBClient(db);
71
93
 
72
94
  // 2. Insert and Query
73
95
 
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ export type SyncCallback = (update: {
18
18
  }) => void;
19
19
  export declare class MoltenDB {
20
20
  readonly dbName: string;
21
- readonly workerUrl: string | URL;
21
+ readonly workerUrl?: string | URL;
22
22
  worker: Worker | null;
23
23
  private messageId;
24
24
  private pendingRequests;
package/dist/index.js CHANGED
@@ -20,8 +20,7 @@ export class MoltenDB {
20
20
  onEvent;
21
21
  constructor(dbName = 'moltendb', options = {}) {
22
22
  this.dbName = dbName;
23
- // Zero-config default worker resolution
24
- this.workerUrl = options.workerUrl ?? new URL('./moltendb-worker.js', import.meta.url).href;
23
+ this.workerUrl = options.workerUrl;
25
24
  this.syncEnabled = options.syncEnabled ?? false;
26
25
  this.serverUrl = options.serverUrl ?? 'wss://localhost:3000/ws';
27
26
  this.syncIntervalMs = options.syncIntervalMs ?? 5000;
@@ -57,7 +56,13 @@ export class MoltenDB {
57
56
  this.isLeader = true;
58
57
  if (this.worker)
59
58
  this.worker.terminate(); // Clean slate if promoted
60
- this.worker = new Worker(this.workerUrl, { type: 'module', name: `moltendb-${this.dbName}-leader` });
59
+ // We must inline `new URL` directly inside `new Worker` so bundlers catch it!
60
+ if (this.workerUrl) {
61
+ this.worker = new Worker(this.workerUrl, { type: 'module', name: `moltendb-${this.dbName}-leader` });
62
+ }
63
+ else {
64
+ this.worker = new Worker(new URL('./moltendb-worker.js', import.meta.url), { type: 'module', name: `moltendb-${this.dbName}-leader` });
65
+ }
61
66
  // Handle messages strictly from our local Worker
62
67
  this.worker.onmessage = (e) => {
63
68
  const data = e.data;
@@ -83,7 +88,7 @@ export class MoltenDB {
83
88
  await new Promise((resolve, reject) => {
84
89
  const id = this.messageId++;
85
90
  this.pendingRequests.set(id, { resolve, reject });
86
- this.worker.postMessage({ id, action: 'init', dbName: this.dbName, workerUrl: this.workerUrl });
91
+ this.worker.postMessage({ id, action: 'init', dbName: this.dbName });
87
92
  });
88
93
  // Listen to the BroadcastChannel for queries coming from Follower tabs
89
94
  this.bc.onmessage = async (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moltendb-web/core",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.2",
4
4
  "description": "MoltenDB WASM runtime — the database engine, Web Worker, and main-thread client in one package.",
5
5
  "type": "module",
6
6
  "author": "Maximilian Both <maximilian.both27@outlook.com>",
@@ -31,7 +31,7 @@
31
31
  "typecheck": "tsc --noEmit"
32
32
  },
33
33
  "devDependencies": {
34
- "typescript": "^6.0.1-rc"
34
+ "typescript": "^6.0.2"
35
35
  },
36
36
  "keywords": [
37
37
  "database",