@delali/narsil 0.2.2 → 0.2.3-next.32

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.
Files changed (66) hide show
  1. package/README.md +12 -9
  2. package/dist/adapters/filesystem.d.ts +1 -1
  3. package/dist/adapters/filesystem.mjs +1 -1
  4. package/dist/adapters/indexeddb.d.ts +1 -1
  5. package/dist/adapters/indexeddb.mjs +1 -1
  6. package/dist/adapters/memory.d.ts +1 -1
  7. package/dist/{adapters-CVqI5NBt.d.ts → adapters-79OIa4xm.d.ts} +1 -1
  8. package/dist/brute-force-DbHYCTc3.d.ts +8 -0
  9. package/dist/chunk-BFIH7OV5.mjs +185 -0
  10. package/dist/chunk-C6VVLMRX.mjs +63 -0
  11. package/dist/{chunk-UNJZ7ZDB.mjs → chunk-EMI63EXP.mjs} +33 -2
  12. package/dist/chunk-MFFAJ2NR.mjs +135 -0
  13. package/dist/chunk-OBXS7OZM.mjs +376 -0
  14. package/dist/{chunk-ASI6AOW2.mjs → chunk-RO4EFWE6.mjs} +7833 -3524
  15. package/dist/{chunk-WLR5BFL3.mjs → chunk-TEAJO7CU.mjs} +3067 -2087
  16. package/dist/{chunk-S7RJJMHI.mjs → chunk-WDL632CN.mjs} +699 -222
  17. package/dist/{chunk-BKAI2WXI.mjs → chunk-WTONLDU3.mjs} +5 -0
  18. package/dist/client-DQHB_swQ.d.ts +793 -0
  19. package/dist/client.d.ts +6 -0
  20. package/dist/client.mjs +843 -0
  21. package/dist/{config-DXypXAfN.d.ts → config-ChZ7lfqc.d.ts} +3 -3
  22. package/dist/direct-executor-YARCDMJF.mjs +8 -0
  23. package/dist/distribution/coordinator/etcd.d.ts +3 -3
  24. package/dist/distribution/coordinator/etcd.mjs +471 -2
  25. package/dist/distribution/coordinator/in-memory.d.ts +3 -3
  26. package/dist/distribution/coordinator/in-memory.mjs +286 -1
  27. package/dist/distribution/transport/grpc.d.ts +45 -0
  28. package/dist/distribution/transport/grpc.mjs +586 -0
  29. package/dist/distribution/transport/in-memory.d.ts +118 -0
  30. package/dist/distribution/transport/in-memory.mjs +214 -0
  31. package/dist/distribution/transport/tcp.d.ts +27 -0
  32. package/dist/distribution/transport/tcp.mjs +595 -0
  33. package/dist/distribution.d.ts +241 -192
  34. package/dist/distribution.mjs +6620 -4795
  35. package/dist/embeddings/openai.d.ts +1 -1
  36. package/dist/embeddings/openai.mjs +1 -1
  37. package/dist/{engine-CO9Wnfie.d.ts → engine-DScGlT2Z.d.ts} +30 -3
  38. package/dist/index.browser.mjs +10035 -3914
  39. package/dist/index.d.ts +8 -8
  40. package/dist/index.mjs +8 -5
  41. package/dist/invalidation/broadcast-channel.d.ts +1 -1
  42. package/dist/invalidation/filesystem.d.ts +1 -1
  43. package/dist/invalidation/filesystem.mjs +3 -1
  44. package/dist/invalidation/noop.d.ts +1 -1
  45. package/dist/options-BORJg5XB.d.ts +234 -0
  46. package/dist/persistence/durability/checkpoint-worker.d.ts +4 -2
  47. package/dist/persistence/durability/checkpoint-worker.mjs +8 -5
  48. package/dist/react.d.ts +340 -0
  49. package/dist/react.mjs +687 -0
  50. package/dist/{schema-CE6S_aAr.d.ts → schema-emTQfEiX.d.ts} +21 -7
  51. package/dist/{search-DLBtiPdQ.d.ts → search-CQ-9bKxo.d.ts} +226 -14
  52. package/dist/server.d.ts +42 -356
  53. package/dist/server.mjs +493 -106
  54. package/dist/tasks-CnMLpfk-.d.ts +274 -0
  55. package/dist/types-BQDlIvfS.d.ts +34 -0
  56. package/dist/{types-BV3nAKTL.d.ts → types-Bfhhnh3G.d.ts} +23 -1
  57. package/dist/types-D5OwhtsQ.d.ts +97 -0
  58. package/dist/vector/hnsw-build-worker.d.ts +2 -7
  59. package/dist/vector/hnsw-build-worker.mjs +2 -1
  60. package/dist/vector/search-worker.d.ts +373 -0
  61. package/dist/vector/search-worker.mjs +279 -0
  62. package/dist/workers/entry.mjs +43 -25
  63. package/package.json +42 -2
  64. package/dist/chunk-FKK76OR7.mjs +0 -456
  65. package/dist/chunk-RQLXC2YS.mjs +0 -269
  66. package/dist/direct-executor-3W4QRA4E.mjs +0 -5
@@ -1,269 +0,0 @@
1
- // src/distribution/coordinator/in-memory.ts
2
- var NODE_HEARTBEAT_PREFIX = "_narsil/node/";
3
- function bytesEqual(a, b) {
4
- if (a.byteLength !== b.byteLength) {
5
- return false;
6
- }
7
- for (let i = 0; i < a.byteLength; i++) {
8
- if (a[i] !== b[i]) {
9
- return false;
10
- }
11
- }
12
- return true;
13
- }
14
- function createInMemoryCoordinator() {
15
- const nodes = /* @__PURE__ */ new Map();
16
- const allocations = /* @__PURE__ */ new Map();
17
- const partitionStates = /* @__PURE__ */ new Map();
18
- const leases = /* @__PURE__ */ new Map();
19
- const schemas = /* @__PURE__ */ new Map();
20
- const kvStore = /* @__PURE__ */ new Map();
21
- const nodeWatchers = /* @__PURE__ */ new Set();
22
- const allocationWatchers = /* @__PURE__ */ new Set();
23
- const schemaWatchers = /* @__PURE__ */ new Set();
24
- let isShutdown = false;
25
- function assertNotShutdown() {
26
- if (isShutdown) {
27
- throw new Error("Coordinator has been shut down");
28
- }
29
- }
30
- function emitNodeEvent(event) {
31
- for (const handler of nodeWatchers) {
32
- try {
33
- handler(event);
34
- } catch (_) {
35
- }
36
- }
37
- }
38
- function emitAllocationEvent(event) {
39
- for (const handler of allocationWatchers) {
40
- try {
41
- handler(event);
42
- } catch (_) {
43
- }
44
- }
45
- }
46
- function emitSchemaEvent(event) {
47
- for (const handler of schemaWatchers) {
48
- try {
49
- handler(event);
50
- } catch (_) {
51
- }
52
- }
53
- }
54
- function clearLeaseEntry(key) {
55
- const entry = leases.get(key);
56
- if (entry !== void 0) {
57
- clearTimeout(entry.timer);
58
- leases.delete(key);
59
- }
60
- }
61
- function createLeaseTimer(key, ttlMs) {
62
- return setTimeout(() => {
63
- leases.delete(key);
64
- if (key.startsWith(NODE_HEARTBEAT_PREFIX)) {
65
- const expiredNodeId = key.slice(NODE_HEARTBEAT_PREFIX.length);
66
- nodes.delete(expiredNodeId);
67
- emitNodeEvent({ type: "node_left", nodeId: expiredNodeId, registration: null });
68
- }
69
- }, ttlMs);
70
- }
71
- function isLeaseValid(key) {
72
- const entry = leases.get(key);
73
- if (entry === void 0) {
74
- return false;
75
- }
76
- return entry.expiresAt > Date.now();
77
- }
78
- const coordinator = {
79
- async registerNode(registration) {
80
- assertNotShutdown();
81
- nodes.set(registration.nodeId, registration);
82
- const heartbeatKey = `${NODE_HEARTBEAT_PREFIX}${registration.nodeId}`;
83
- const defaultTtlMs = 3e4;
84
- clearLeaseEntry(heartbeatKey);
85
- const timer = createLeaseTimer(heartbeatKey, defaultTtlMs);
86
- leases.set(heartbeatKey, {
87
- nodeId: registration.nodeId,
88
- expiresAt: Date.now() + defaultTtlMs,
89
- timer
90
- });
91
- emitNodeEvent({ type: "node_joined", nodeId: registration.nodeId, registration });
92
- },
93
- async deregisterNode(nodeId) {
94
- assertNotShutdown();
95
- const existed = nodes.delete(nodeId);
96
- const heartbeatKey = `${NODE_HEARTBEAT_PREFIX}${nodeId}`;
97
- clearLeaseEntry(heartbeatKey);
98
- if (existed) {
99
- emitNodeEvent({ type: "node_left", nodeId, registration: null });
100
- }
101
- },
102
- async listNodes() {
103
- assertNotShutdown();
104
- return Array.from(nodes.values());
105
- },
106
- async watchNodes(handler) {
107
- assertNotShutdown();
108
- nodeWatchers.add(handler);
109
- return () => {
110
- nodeWatchers.delete(handler);
111
- };
112
- },
113
- async getAllocation(indexName) {
114
- assertNotShutdown();
115
- return allocations.get(indexName) ?? null;
116
- },
117
- async putAllocation(indexName, table, expectedVersion) {
118
- assertNotShutdown();
119
- if (expectedVersion !== void 0) {
120
- const current = allocations.get(indexName);
121
- if (expectedVersion === null) {
122
- if (current !== void 0) {
123
- return false;
124
- }
125
- } else {
126
- if (current === void 0 || current.version !== expectedVersion) {
127
- return false;
128
- }
129
- }
130
- }
131
- allocations.set(indexName, table);
132
- emitAllocationEvent({ indexName, table });
133
- return true;
134
- },
135
- async watchAllocation(handler) {
136
- assertNotShutdown();
137
- allocationWatchers.add(handler);
138
- return () => {
139
- allocationWatchers.delete(handler);
140
- };
141
- },
142
- async getPartitionState(indexName, partitionId) {
143
- assertNotShutdown();
144
- const indexStates = partitionStates.get(indexName);
145
- if (indexStates === void 0) {
146
- return "UNASSIGNED";
147
- }
148
- return indexStates.get(partitionId) ?? "UNASSIGNED";
149
- },
150
- async putPartitionState(indexName, partitionId, state) {
151
- assertNotShutdown();
152
- let indexStates = partitionStates.get(indexName);
153
- if (indexStates === void 0) {
154
- indexStates = /* @__PURE__ */ new Map();
155
- partitionStates.set(indexName, indexStates);
156
- }
157
- indexStates.set(partitionId, state);
158
- },
159
- async acquireLease(key, nodeId, ttlMs) {
160
- assertNotShutdown();
161
- if (isLeaseValid(key)) {
162
- const entry = leases.get(key);
163
- if (entry !== void 0 && entry.nodeId !== nodeId) {
164
- return false;
165
- }
166
- if (entry !== void 0 && entry.nodeId === nodeId) {
167
- clearTimeout(entry.timer);
168
- const timer2 = createLeaseTimer(key, ttlMs);
169
- entry.expiresAt = Date.now() + ttlMs;
170
- entry.timer = timer2;
171
- return true;
172
- }
173
- }
174
- clearLeaseEntry(key);
175
- const timer = createLeaseTimer(key, ttlMs);
176
- leases.set(key, { nodeId, expiresAt: Date.now() + ttlMs, timer });
177
- return true;
178
- },
179
- async renewLease(key, nodeId, ttlMs) {
180
- assertNotShutdown();
181
- const entry = leases.get(key);
182
- if (entry === void 0 || entry.nodeId !== nodeId) {
183
- return false;
184
- }
185
- if (!isLeaseValid(key)) {
186
- leases.delete(key);
187
- return false;
188
- }
189
- clearTimeout(entry.timer);
190
- entry.timer = createLeaseTimer(key, ttlMs);
191
- entry.expiresAt = Date.now() + ttlMs;
192
- return true;
193
- },
194
- async releaseLease(key) {
195
- assertNotShutdown();
196
- clearLeaseEntry(key);
197
- },
198
- async get(key) {
199
- assertNotShutdown();
200
- const value = kvStore.get(key);
201
- return value !== void 0 ? new Uint8Array(value) : null;
202
- },
203
- async compareAndSet(key, expected, value) {
204
- assertNotShutdown();
205
- const current = kvStore.get(key);
206
- if (expected === null) {
207
- if (current !== void 0) {
208
- return false;
209
- }
210
- kvStore.set(key, new Uint8Array(value));
211
- return true;
212
- }
213
- if (current === void 0) {
214
- return false;
215
- }
216
- if (!bytesEqual(current, expected)) {
217
- return false;
218
- }
219
- kvStore.set(key, new Uint8Array(value));
220
- return true;
221
- },
222
- async getSchema(indexName) {
223
- assertNotShutdown();
224
- return schemas.get(indexName) ?? null;
225
- },
226
- async putSchema(indexName, schema) {
227
- assertNotShutdown();
228
- schemas.set(indexName, schema);
229
- emitSchemaEvent({ type: "schema_created", indexName, schema });
230
- },
231
- async watchSchemas(handler) {
232
- assertNotShutdown();
233
- schemaWatchers.add(handler);
234
- return () => {
235
- schemaWatchers.delete(handler);
236
- };
237
- },
238
- async getLeaseHolder(key) {
239
- assertNotShutdown();
240
- if (!isLeaseValid(key)) {
241
- clearLeaseEntry(key);
242
- return null;
243
- }
244
- const entry = leases.get(key);
245
- return entry?.nodeId ?? null;
246
- },
247
- async shutdown() {
248
- if (isShutdown) {
249
- return;
250
- }
251
- isShutdown = true;
252
- for (const entry of leases.values()) {
253
- clearTimeout(entry.timer);
254
- }
255
- leases.clear();
256
- nodes.clear();
257
- allocations.clear();
258
- partitionStates.clear();
259
- schemas.clear();
260
- kvStore.clear();
261
- nodeWatchers.clear();
262
- allocationWatchers.clear();
263
- schemaWatchers.clear();
264
- }
265
- };
266
- return coordinator;
267
- }
268
-
269
- export { createInMemoryCoordinator };
@@ -1,5 +0,0 @@
1
- export { createDirectExecutor } from './chunk-ASI6AOW2.mjs';
2
- import './chunk-TGP5M5R7.mjs';
3
- import './chunk-S7RJJMHI.mjs';
4
- import './chunk-U2BKYEC7.mjs';
5
- import './chunk-UNJZ7ZDB.mjs';