@delali/narsil 0.1.1 → 0.1.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 +39 -0
- package/dist/adapters/filesystem.mjs +1 -1
- package/dist/adapters/indexeddb.mjs +1 -1
- package/dist/{chunk-JKIBUPAY.mjs → chunk-7GKPWGCN.mjs} +2 -1
- package/dist/chunk-GVN2W4VA.mjs +570 -0
- package/dist/chunk-HRABJLPB.mjs +64 -0
- package/dist/{chunk-5HXMVMSM.mjs → chunk-LIRVYUQ5.mjs} +1174 -181
- package/dist/direct-executor-DFRFDLFP.mjs +4 -0
- package/dist/index.d.ts +46 -3
- package/dist/index.mjs +1367 -415
- package/dist/vector/hnsw-build-worker.d.ts +37 -0
- package/dist/vector/hnsw-build-worker.mjs +81 -0
- package/dist/workers/entry.mjs +3 -32
- package/package.json +17 -11
- package/dist/chunk-N37VMC62.mjs +0 -18
- package/dist/direct-executor-MQD7JRD4.mjs +0 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/core/id-generator.ts
|
|
2
|
+
function generateId() {
|
|
3
|
+
const bytes = new Uint8Array(16);
|
|
4
|
+
crypto.getRandomValues(bytes);
|
|
5
|
+
const now = Date.now();
|
|
6
|
+
bytes[0] = Math.floor(now / 2 ** 40);
|
|
7
|
+
bytes[1] = Math.floor(now / 2 ** 32) % 256;
|
|
8
|
+
bytes[2] = Math.floor(now / 2 ** 24) % 256;
|
|
9
|
+
bytes[3] = Math.floor(now / 2 ** 16) % 256;
|
|
10
|
+
bytes[4] = Math.floor(now / 2 ** 8) % 256;
|
|
11
|
+
bytes[5] = now % 256;
|
|
12
|
+
bytes[6] = bytes[6] & 15 | 112;
|
|
13
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
14
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
15
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/workers/protocol.ts
|
|
19
|
+
var KNOWN_ACTION_TYPES = [
|
|
20
|
+
"insert",
|
|
21
|
+
"remove",
|
|
22
|
+
"update",
|
|
23
|
+
"query",
|
|
24
|
+
"preflight",
|
|
25
|
+
"get",
|
|
26
|
+
"has",
|
|
27
|
+
"count",
|
|
28
|
+
"createIndex",
|
|
29
|
+
"dropIndex",
|
|
30
|
+
"getStats",
|
|
31
|
+
"clear",
|
|
32
|
+
"serialize",
|
|
33
|
+
"deserialize",
|
|
34
|
+
"memoryReport",
|
|
35
|
+
"shutdown"
|
|
36
|
+
];
|
|
37
|
+
function createRequestId() {
|
|
38
|
+
return generateId();
|
|
39
|
+
}
|
|
40
|
+
function isValidWorkerAction(msg) {
|
|
41
|
+
if (msg === null || msg === void 0 || typeof msg !== "object") {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const candidate = msg;
|
|
45
|
+
if (typeof candidate.type !== "string" || typeof candidate.requestId !== "string") {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return KNOWN_ACTION_TYPES.includes(candidate.type);
|
|
49
|
+
}
|
|
50
|
+
function isValidWorkerResponse(msg) {
|
|
51
|
+
if (msg === null || msg === void 0 || typeof msg !== "object") {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const candidate = msg;
|
|
55
|
+
if (typeof candidate.requestId !== "string") {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (candidate.type !== "success" && candidate.type !== "error") {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { createRequestId, generateId, isValidWorkerAction, isValidWorkerResponse };
|