taladb 0.2.11 → 0.3.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.
- package/dist/index.js +7 -64
- package/dist/index.mjs +7 -64
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ var WorkerProxy = class {
|
|
|
57
57
|
else p.reject(new Error(error));
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
this.port.start();
|
|
60
|
+
this.port.start?.();
|
|
61
61
|
}
|
|
62
62
|
send(op, args = {}) {
|
|
63
63
|
return new Promise((resolve, reject) => {
|
|
@@ -67,70 +67,10 @@ var WorkerProxy = class {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
async function createInMemoryBrowserDB(_dbName) {
|
|
71
|
-
const wasmUrl = new URL("@taladb/web/pkg/taladb_web.js", import_meta.url);
|
|
72
|
-
const wasm = await import(
|
|
73
|
-
/* @vite-ignore */
|
|
74
|
-
wasmUrl.href
|
|
75
|
-
);
|
|
76
|
-
await wasm.default();
|
|
77
|
-
const db = wasm.TalaDBWasm.openInMemory();
|
|
78
|
-
function wrapCollection(name) {
|
|
79
|
-
const col = db.collection(name);
|
|
80
|
-
return {
|
|
81
|
-
insert: async (doc) => col.insert(doc),
|
|
82
|
-
insertMany: async (docs) => col.insertMany(docs),
|
|
83
|
-
find: async (filter) => col.find(filter ?? null),
|
|
84
|
-
findOne: async (filter) => col.findOne(filter) ?? null,
|
|
85
|
-
updateOne: async (filter, update) => col.updateOne(filter, update),
|
|
86
|
-
updateMany: async (filter, update) => col.updateMany(filter, update),
|
|
87
|
-
deleteOne: async (filter) => col.deleteOne(filter),
|
|
88
|
-
deleteMany: async (filter) => col.deleteMany(filter),
|
|
89
|
-
count: async (filter) => col.count(filter ?? null),
|
|
90
|
-
createIndex: async (field) => col.createIndex(field),
|
|
91
|
-
dropIndex: async (field) => col.dropIndex(field),
|
|
92
|
-
createVectorIndex: async (field, options) => col.createVectorIndex(field, options.dimensions, options.metric ?? null),
|
|
93
|
-
dropVectorIndex: async (field) => col.dropVectorIndex(field),
|
|
94
|
-
findNearest: async (field, vector, topK, filter) => {
|
|
95
|
-
const raw = await col.findNearest(field, vector, topK, filter ?? null);
|
|
96
|
-
return raw;
|
|
97
|
-
},
|
|
98
|
-
subscribe: (filter, callback) => {
|
|
99
|
-
let active = true;
|
|
100
|
-
let lastJson = "";
|
|
101
|
-
const poll = async () => {
|
|
102
|
-
if (!active) return;
|
|
103
|
-
try {
|
|
104
|
-
const docs = await col.find(filter ?? null);
|
|
105
|
-
const json = JSON.stringify(docs);
|
|
106
|
-
if (json !== lastJson) {
|
|
107
|
-
lastJson = json;
|
|
108
|
-
callback(docs);
|
|
109
|
-
}
|
|
110
|
-
} catch {
|
|
111
|
-
}
|
|
112
|
-
if (active) setTimeout(poll, 300);
|
|
113
|
-
};
|
|
114
|
-
poll();
|
|
115
|
-
return () => {
|
|
116
|
-
active = false;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
collection: (name) => wrapCollection(name),
|
|
123
|
-
close: async () => {
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
70
|
async function createBrowserDB(dbName) {
|
|
128
|
-
if (typeof SharedWorker === "undefined") {
|
|
129
|
-
return createInMemoryBrowserDB(dbName);
|
|
130
|
-
}
|
|
131
71
|
const workerUrl = new URL("@taladb/web/worker/taladb.worker.js", import_meta.url);
|
|
132
|
-
const worker = new
|
|
133
|
-
const proxy = new WorkerProxy(worker
|
|
72
|
+
const worker = new Worker(workerUrl, { type: "module", name: "taladb" });
|
|
73
|
+
const proxy = new WorkerProxy(worker);
|
|
134
74
|
await proxy.send("init", { dbName });
|
|
135
75
|
function wrapCollection(name) {
|
|
136
76
|
const s = JSON.stringify;
|
|
@@ -219,7 +159,10 @@ async function createBrowserDB(dbName) {
|
|
|
219
159
|
}
|
|
220
160
|
return {
|
|
221
161
|
collection: (name) => wrapCollection(name),
|
|
222
|
-
close: () =>
|
|
162
|
+
close: async () => {
|
|
163
|
+
await proxy.send("close");
|
|
164
|
+
worker.terminate();
|
|
165
|
+
}
|
|
223
166
|
};
|
|
224
167
|
}
|
|
225
168
|
async function createNodeDB(dbName) {
|
package/dist/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ var WorkerProxy = class {
|
|
|
22
22
|
else p.reject(new Error(error));
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
this.port.start();
|
|
25
|
+
this.port.start?.();
|
|
26
26
|
}
|
|
27
27
|
send(op, args = {}) {
|
|
28
28
|
return new Promise((resolve, reject) => {
|
|
@@ -32,70 +32,10 @@ var WorkerProxy = class {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
async function createInMemoryBrowserDB(_dbName) {
|
|
36
|
-
const wasmUrl = new URL("@taladb/web/pkg/taladb_web.js", import.meta.url);
|
|
37
|
-
const wasm = await import(
|
|
38
|
-
/* @vite-ignore */
|
|
39
|
-
wasmUrl.href
|
|
40
|
-
);
|
|
41
|
-
await wasm.default();
|
|
42
|
-
const db = wasm.TalaDBWasm.openInMemory();
|
|
43
|
-
function wrapCollection(name) {
|
|
44
|
-
const col = db.collection(name);
|
|
45
|
-
return {
|
|
46
|
-
insert: async (doc) => col.insert(doc),
|
|
47
|
-
insertMany: async (docs) => col.insertMany(docs),
|
|
48
|
-
find: async (filter) => col.find(filter ?? null),
|
|
49
|
-
findOne: async (filter) => col.findOne(filter) ?? null,
|
|
50
|
-
updateOne: async (filter, update) => col.updateOne(filter, update),
|
|
51
|
-
updateMany: async (filter, update) => col.updateMany(filter, update),
|
|
52
|
-
deleteOne: async (filter) => col.deleteOne(filter),
|
|
53
|
-
deleteMany: async (filter) => col.deleteMany(filter),
|
|
54
|
-
count: async (filter) => col.count(filter ?? null),
|
|
55
|
-
createIndex: async (field) => col.createIndex(field),
|
|
56
|
-
dropIndex: async (field) => col.dropIndex(field),
|
|
57
|
-
createVectorIndex: async (field, options) => col.createVectorIndex(field, options.dimensions, options.metric ?? null),
|
|
58
|
-
dropVectorIndex: async (field) => col.dropVectorIndex(field),
|
|
59
|
-
findNearest: async (field, vector, topK, filter) => {
|
|
60
|
-
const raw = await col.findNearest(field, vector, topK, filter ?? null);
|
|
61
|
-
return raw;
|
|
62
|
-
},
|
|
63
|
-
subscribe: (filter, callback) => {
|
|
64
|
-
let active = true;
|
|
65
|
-
let lastJson = "";
|
|
66
|
-
const poll = async () => {
|
|
67
|
-
if (!active) return;
|
|
68
|
-
try {
|
|
69
|
-
const docs = await col.find(filter ?? null);
|
|
70
|
-
const json = JSON.stringify(docs);
|
|
71
|
-
if (json !== lastJson) {
|
|
72
|
-
lastJson = json;
|
|
73
|
-
callback(docs);
|
|
74
|
-
}
|
|
75
|
-
} catch {
|
|
76
|
-
}
|
|
77
|
-
if (active) setTimeout(poll, 300);
|
|
78
|
-
};
|
|
79
|
-
poll();
|
|
80
|
-
return () => {
|
|
81
|
-
active = false;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
collection: (name) => wrapCollection(name),
|
|
88
|
-
close: async () => {
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
35
|
async function createBrowserDB(dbName) {
|
|
93
|
-
if (typeof SharedWorker === "undefined") {
|
|
94
|
-
return createInMemoryBrowserDB(dbName);
|
|
95
|
-
}
|
|
96
36
|
const workerUrl = new URL("@taladb/web/worker/taladb.worker.js", import.meta.url);
|
|
97
|
-
const worker = new
|
|
98
|
-
const proxy = new WorkerProxy(worker
|
|
37
|
+
const worker = new Worker(workerUrl, { type: "module", name: "taladb" });
|
|
38
|
+
const proxy = new WorkerProxy(worker);
|
|
99
39
|
await proxy.send("init", { dbName });
|
|
100
40
|
function wrapCollection(name) {
|
|
101
41
|
const s = JSON.stringify;
|
|
@@ -184,7 +124,10 @@ async function createBrowserDB(dbName) {
|
|
|
184
124
|
}
|
|
185
125
|
return {
|
|
186
126
|
collection: (name) => wrapCollection(name),
|
|
187
|
-
close: () =>
|
|
127
|
+
close: async () => {
|
|
128
|
+
await proxy.send("close");
|
|
129
|
+
worker.terminate();
|
|
130
|
+
}
|
|
188
131
|
};
|
|
189
132
|
}
|
|
190
133
|
async function createNodeDB(dbName) {
|