@delali/narsil 0.1.9 → 0.1.10

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.
@@ -1,4 +1,4 @@
1
- import { getNestedValue, getLanguage, extractVectorFieldsFromSchema, createDirectExecutor, createPartitionRouter, createPartitionManager, createVectorIndex, validateSchema, deserializePayloadV2, tokenize, fanOutQuery, validateRequiredFields, validateVectorPromotion, createPartitionIndex, flattenSchema, fnv1a, detectRuntime, kWayMerge } from './chunk-VWF7RKSF.mjs';
1
+ import { getNestedValue, getLanguage, extractVectorFieldsFromSchema, createDirectExecutor, createPartitionRouter, createPartitionManager, createVectorIndex, validateSchema, deserializePayloadV2, tokenize, fanOutQuery, validateRequiredFields, validateVectorPromotion, createPartitionIndex, flattenSchema, fnv1a, detectRuntime, isNodeMainThread, spawnNodeWorker, kWayMerge } from './chunk-Q4OVNESD.mjs';
2
2
  import { crc32, crc32Init, crc32Update, crc32Final } from './chunk-KMMJMDUA.mjs';
3
3
  import { ErrorCodes, NarsilError } from './chunk-ALB35PRQ.mjs';
4
4
  import { generateId, createRequestId, isValidWorkerResponse } from './chunk-HRABJLPB.mjs';
@@ -287,7 +287,7 @@ function createExecutionPromoter(config) {
287
287
  return { check, markPromoted, isPromoted };
288
288
  }
289
289
 
290
- // src/persistence/durability/durable-filesystem.ts
290
+ // src/persistence/durability/node-fs.ts
291
291
  var cachedFs = null;
292
292
  var cachedPath = null;
293
293
  async function getFs() {
@@ -302,6 +302,8 @@ async function getPath() {
302
302
  }
303
303
  return cachedPath;
304
304
  }
305
+
306
+ // src/persistence/durability/durable-filesystem.ts
305
307
  function validateRelativeKey(key) {
306
308
  if (key.length === 0) {
307
309
  throw new NarsilError(ErrorCodes.PERSISTENCE_SAVE_FAILED, "Invalid key: empty");
@@ -569,12 +571,7 @@ var mainThreadResolved = false;
569
571
  var onMainThread = true;
570
572
  async function isOnMainThread() {
571
573
  if (!mainThreadResolved) {
572
- try {
573
- const workerThreads = await import('worker_threads');
574
- onMainThread = workerThreads.isMainThread;
575
- } catch {
576
- onMainThread = true;
577
- }
574
+ onMainThread = await isNodeMainThread();
578
575
  mainThreadResolved = true;
579
576
  }
580
577
  return onMainThread;
@@ -589,8 +586,7 @@ function resolveWorkerEntryPoint() {
589
586
  }
590
587
  async function spawnWorker() {
591
588
  try {
592
- const workerThreads = await import('worker_threads');
593
- return new workerThreads.Worker(new URL(resolveWorkerEntryPoint()));
589
+ return await spawnNodeWorker(new URL(resolveWorkerEntryPoint()));
594
590
  } catch {
595
591
  return null;
596
592
  }
@@ -1269,8 +1265,10 @@ function resolveWorkerEntryPoint2() {
1269
1265
  }
1270
1266
  async function spawnWorker2() {
1271
1267
  try {
1272
- const workerThreads = await import('worker_threads');
1273
- const worker = new workerThreads.Worker(new URL(resolveWorkerEntryPoint2()));
1268
+ const worker = await spawnNodeWorker(new URL(resolveWorkerEntryPoint2()));
1269
+ if (worker === null) {
1270
+ return null;
1271
+ }
1274
1272
  if (typeof worker.unref === "function") {
1275
1273
  worker.unref();
1276
1274
  }
@@ -4424,6 +4424,24 @@ function deserializeScalarQuantizer(data, dimensions, ordinalSource) {
4424
4424
  return quantizer;
4425
4425
  }
4426
4426
 
4427
+ // src/workers/node-worker.ts
4428
+ async function spawnNodeWorker(entryPoint) {
4429
+ try {
4430
+ const workerThreads = await import('worker_threads');
4431
+ return new workerThreads.Worker(entryPoint);
4432
+ } catch {
4433
+ return null;
4434
+ }
4435
+ }
4436
+ async function isNodeMainThread() {
4437
+ try {
4438
+ const workerThreads = await import('worker_threads');
4439
+ return workerThreads.isMainThread;
4440
+ } catch {
4441
+ return true;
4442
+ }
4443
+ }
4444
+
4427
4445
  // src/runtime/detect.ts
4428
4446
  function detectRuntimeName() {
4429
4447
  if ("Bun" in globalThis) {
@@ -4473,9 +4491,7 @@ async function spawnWorker() {
4473
4491
  const entryPoint = resolveWorkerEntryPoint();
4474
4492
  if (runtime.supportsWorkerThreads) {
4475
4493
  try {
4476
- const workerThreads = await import('worker_threads');
4477
- const instance = new workerThreads.Worker(new URL(entryPoint));
4478
- return instance;
4494
+ return await spawnNodeWorker(new URL(entryPoint));
4479
4495
  } catch {
4480
4496
  return null;
4481
4497
  }
@@ -5325,4 +5341,4 @@ function createDirectExecutor() {
5325
5341
  };
5326
5342
  }
5327
5343
 
5328
- export { MAX_NESTING_DEPTH, clearNormalizationCache, configureNormalizationCache, createDirectExecutor, createPartitionIndex, createPartitionManager, createPartitionRouter, createVectorIndex, deserializePayloadV2, detectRuntime, extractVectorFieldsFromSchema, fanOutQuery, flattenSchema, fnv1a, getLanguage, getNestedValue, getNormalizationCacheSize, kWayMerge, mergePartitionStats, registerLanguage, resetNormalizationCache, tokenize, validateRequiredFields, validateSchema, validateVectorPromotion };
5344
+ export { MAX_NESTING_DEPTH, clearNormalizationCache, configureNormalizationCache, createDirectExecutor, createPartitionIndex, createPartitionManager, createPartitionRouter, createVectorIndex, deserializePayloadV2, detectRuntime, extractVectorFieldsFromSchema, fanOutQuery, flattenSchema, fnv1a, getLanguage, getNestedValue, getNormalizationCacheSize, isNodeMainThread, kWayMerge, mergePartitionStats, registerLanguage, resetNormalizationCache, spawnNodeWorker, tokenize, validateRequiredFields, validateSchema, validateVectorPromotion };
@@ -1,4 +1,4 @@
1
- export { createDirectExecutor } from './chunk-VWF7RKSF.mjs';
1
+ export { createDirectExecutor } from './chunk-Q4OVNESD.mjs';
2
2
  import './chunk-S7RJJMHI.mjs';
3
3
  import './chunk-TW6BXTOL.mjs';
4
4
  import './chunk-ALB35PRQ.mjs';
@@ -1,7 +1,7 @@
1
1
  export { createInMemoryCoordinator } from './chunk-RQLXC2YS.mjs';
2
2
  import './chunk-WISGW24C.mjs';
3
- import { ReplicationMessageTypes, ClusterMessageTypes, DEFAULT_TRANSPORT_CONFIG, TransportError, TransportErrorCodes, MAX_MESSAGE_SIZE_BYTES, createEngineCore, createNarsilFromCore, QueryMessageTypes, applyIndexEntry, applyDeleteEntry, validateEntryPayload, createAckMessage, validateReplicationEntry, MAX_PARTITION_COUNT, MAX_INDEX_NAME_LENGTH, validateIndexName, computeEntryChecksum, createInsyncConfirmMessage, createEntryMessage, getIndexMetadata, validateAckPayload, createInsyncRemoveMessage, validateInsyncConfirmPayload, putIndexMetadata, createForwardMessage } from './chunk-SVDEEMO6.mjs';
4
- import { deserializePayloadV2, createPartitionIndex, getLanguage, fnv1a, mergePartitionStats, MAX_NESTING_DEPTH } from './chunk-VWF7RKSF.mjs';
3
+ import { ReplicationMessageTypes, ClusterMessageTypes, DEFAULT_TRANSPORT_CONFIG, TransportError, TransportErrorCodes, MAX_MESSAGE_SIZE_BYTES, createEngineCore, createNarsilFromCore, QueryMessageTypes, applyIndexEntry, applyDeleteEntry, validateEntryPayload, createAckMessage, validateReplicationEntry, MAX_PARTITION_COUNT, MAX_INDEX_NAME_LENGTH, validateIndexName, computeEntryChecksum, createInsyncConfirmMessage, createEntryMessage, getIndexMetadata, validateAckPayload, createInsyncRemoveMessage, validateInsyncConfirmPayload, putIndexMetadata, createForwardMessage } from './chunk-CU6BVZEU.mjs';
4
+ import { deserializePayloadV2, createPartitionIndex, getLanguage, fnv1a, mergePartitionStats, MAX_NESTING_DEPTH } from './chunk-Q4OVNESD.mjs';
5
5
  import './chunk-S7RJJMHI.mjs';
6
6
  import { crc32 } from './chunk-KMMJMDUA.mjs';
7
7
  import './chunk-TW6BXTOL.mjs';
@@ -6176,6 +6176,14 @@ function createHNSWIndex(dimension, store, config, quantizer) {
6176
6176
  };
6177
6177
  }
6178
6178
 
6179
+ // src/workers/node-worker.browser.ts
6180
+ async function spawnNodeWorker(_entryPoint) {
6181
+ return null;
6182
+ }
6183
+ async function isNodeMainThread() {
6184
+ return true;
6185
+ }
6186
+
6179
6187
  // src/runtime/detect.ts
6180
6188
  function detectRuntimeName() {
6181
6189
  if ("Bun" in globalThis) {
@@ -6225,9 +6233,7 @@ async function spawnWorker() {
6225
6233
  const entryPoint = resolveWorkerEntryPoint();
6226
6234
  if (runtime.supportsWorkerThreads) {
6227
6235
  try {
6228
- const workerThreads = await import('worker_threads');
6229
- const instance = new workerThreads.Worker(new URL(entryPoint));
6230
- return instance;
6236
+ return await spawnNodeWorker(new URL(entryPoint));
6231
6237
  } catch {
6232
6238
  return null;
6233
6239
  }
@@ -7115,21 +7121,21 @@ function createExecutionPromoter(config) {
7115
7121
  return { check, markPromoted, isPromoted };
7116
7122
  }
7117
7123
 
7118
- // src/persistence/durability/durable-filesystem.ts
7119
- var cachedFs = null;
7120
- var cachedPath = null;
7124
+ // src/persistence/durability/node-fs.browser.ts
7125
+ function filesystemUnavailable() {
7126
+ throw new NarsilError(
7127
+ ErrorCodes.CONFIG_INVALID,
7128
+ "Filesystem durability requires a Node.js runtime; use the memory or IndexedDB persistence adapters in the browser"
7129
+ );
7130
+ }
7121
7131
  async function getFs() {
7122
- if (cachedFs === null) {
7123
- cachedFs = await import('fs/promises');
7124
- }
7125
- return cachedFs;
7132
+ return filesystemUnavailable();
7126
7133
  }
7127
7134
  async function getPath() {
7128
- if (cachedPath === null) {
7129
- cachedPath = await import('path');
7130
- }
7131
- return cachedPath;
7135
+ return filesystemUnavailable();
7132
7136
  }
7137
+
7138
+ // src/persistence/durability/durable-filesystem.ts
7133
7139
  function validateRelativeKey(key) {
7134
7140
  if (key.length === 0) {
7135
7141
  throw new NarsilError(ErrorCodes.PERSISTENCE_SAVE_FAILED, "Invalid key: empty");
@@ -7442,12 +7448,7 @@ var mainThreadResolved = false;
7442
7448
  var onMainThread = true;
7443
7449
  async function isOnMainThread() {
7444
7450
  if (!mainThreadResolved) {
7445
- try {
7446
- const workerThreads = await import('worker_threads');
7447
- onMainThread = workerThreads.isMainThread;
7448
- } catch {
7449
- onMainThread = true;
7450
- }
7451
+ onMainThread = await isNodeMainThread();
7451
7452
  mainThreadResolved = true;
7452
7453
  }
7453
7454
  return onMainThread;
@@ -7462,8 +7463,7 @@ function resolveWorkerEntryPoint2() {
7462
7463
  }
7463
7464
  async function spawnWorker2() {
7464
7465
  try {
7465
- const workerThreads = await import('worker_threads');
7466
- return new workerThreads.Worker(new URL(resolveWorkerEntryPoint2()));
7466
+ return await spawnNodeWorker(new URL(resolveWorkerEntryPoint2()));
7467
7467
  } catch {
7468
7468
  return null;
7469
7469
  }
@@ -8142,8 +8142,10 @@ function resolveWorkerEntryPoint3() {
8142
8142
  }
8143
8143
  async function spawnWorker3() {
8144
8144
  try {
8145
- const workerThreads = await import('worker_threads');
8146
- const worker = new workerThreads.Worker(new URL(resolveWorkerEntryPoint3()));
8145
+ const worker = await spawnNodeWorker(new URL(resolveWorkerEntryPoint3()));
8146
+ if (worker === null) {
8147
+ return null;
8148
+ }
8147
8149
  if (typeof worker.unref === "function") {
8148
8150
  worker.unref();
8149
8151
  }
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { VERSION, createNarsil } from './chunk-SVDEEMO6.mjs';
2
- export { clearNormalizationCache, configureNormalizationCache, getLanguage, getNormalizationCacheSize, registerLanguage, resetNormalizationCache } from './chunk-VWF7RKSF.mjs';
1
+ export { VERSION, createNarsil } from './chunk-CU6BVZEU.mjs';
2
+ export { clearNormalizationCache, configureNormalizationCache, getLanguage, getNormalizationCacheSize, registerLanguage, resetNormalizationCache } from './chunk-Q4OVNESD.mjs';
3
3
  export { isSimdAvailable } from './chunk-S7RJJMHI.mjs';
4
4
  import './chunk-KMMJMDUA.mjs';
5
5
  import './chunk-TW6BXTOL.mjs';
@@ -1,5 +1,5 @@
1
- import { createDurableDirectory, writeSegmentedCheckpoint } from '../../chunk-SVDEEMO6.mjs';
2
- import '../../chunk-VWF7RKSF.mjs';
1
+ import { createDurableDirectory, writeSegmentedCheckpoint } from '../../chunk-CU6BVZEU.mjs';
2
+ import '../../chunk-Q4OVNESD.mjs';
3
3
  import '../../chunk-S7RJJMHI.mjs';
4
4
  import '../../chunk-KMMJMDUA.mjs';
5
5
  import '../../chunk-TW6BXTOL.mjs';
@@ -15,7 +15,7 @@ async function setup() {
15
15
  } catch {
16
16
  parentPort = null;
17
17
  }
18
- const { createDirectExecutor } = await import('../direct-executor-KC5O5D2R.mjs');
18
+ const { createDirectExecutor } = await import('../direct-executor-6FOKJKLD.mjs');
19
19
  const executor = createDirectExecutor();
20
20
  function buildErrorResponse(requestId, code, message) {
21
21
  return { type: "error", requestId, code, message };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delali/narsil",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "description": "A distributed full-text search engine with cross-language portable binary format.",
6
6
  "author": "Delali (https://sondelali.com)",
@@ -22,6 +22,14 @@
22
22
  "#platform/vector-promoter": {
23
23
  "browser": "./src/vector/promoter.browser.ts",
24
24
  "default": "./src/vector/promoter.ts"
25
+ },
26
+ "#platform/durable-fs": {
27
+ "browser": "./src/persistence/durability/node-fs.browser.ts",
28
+ "default": "./src/persistence/durability/node-fs.ts"
29
+ },
30
+ "#platform/node-worker": {
31
+ "browser": "./src/workers/node-worker.browser.ts",
32
+ "default": "./src/workers/node-worker.ts"
25
33
  }
26
34
  },
27
35
  "sideEffects": false,
@@ -133,7 +141,7 @@
133
141
  }
134
142
  },
135
143
  "scripts": {
136
- "build": "tsup",
144
+ "build": "tsup && node scripts/check-browser-bundle.mjs",
137
145
  "test": "vitest run --exclude='**/vector/recall.test.ts'",
138
146
  "test:etcd": "vitest run src/__tests__/distribution/coordinator/etcd-integration/*.test.ts",
139
147
  "test:watch": "vitest",