@delali/narsil 0.4.5-next.309 → 0.4.6-next.332

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 (80) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/{chunk-263ERYKA.mjs → chunk-DJDBJB2U.mjs} +1 -1
  3. package/dist/browser/{storage-leaf-42IZEOJJ.mjs → storage-leaf-72PEG6IP.mjs} +20 -12
  4. package/dist/{chunk-7SMVY4AX.mjs → chunk-3GWUUKDJ.mjs} +11 -11
  5. package/dist/{chunk-3PO2MOFY.mjs → chunk-57MN2UAL.mjs} +1 -1
  6. package/dist/{chunk-H7IIA2KL.mjs → chunk-7DW2ITZ3.mjs} +1 -1
  7. package/dist/{chunk-GDCTK5LU.mjs → chunk-AQI4DIFA.mjs} +2 -2
  8. package/dist/{chunk-7HVZVD2N.mjs → chunk-AWMO3NKJ.mjs} +1 -1
  9. package/dist/{chunk-XX4SKT54.mjs → chunk-BOTZ2GSW.mjs} +9 -9
  10. package/dist/{chunk-BVLR6S5J.mjs → chunk-CN42TL6V.mjs} +5 -5
  11. package/dist/{chunk-VV6P6LKJ.mjs → chunk-CZHAPGVH.mjs} +2 -2
  12. package/dist/{chunk-C3OQQ3M6.mjs → chunk-DVFCDOXW.mjs} +1 -1
  13. package/dist/{chunk-CPAE2QJP.mjs → chunk-EDZJNZKV.mjs} +1 -1
  14. package/dist/{chunk-REM3KDXN.mjs → chunk-FWZ5OK5G.mjs} +4 -4
  15. package/dist/{chunk-PBUME456.mjs → chunk-G6P6YTTW.mjs} +1 -1
  16. package/dist/{chunk-RXQZ53NV.mjs → chunk-GTB2S2VX.mjs} +1 -1
  17. package/dist/{chunk-KGLBLKYF.mjs → chunk-HWIIMLLR.mjs} +64 -49
  18. package/dist/{chunk-UDDZVZTV.mjs → chunk-JASE2FE6.mjs} +2 -2
  19. package/dist/{chunk-ICOCO7R4.mjs → chunk-JXRMHWQU.mjs} +1 -1
  20. package/dist/{chunk-AAH5CD3M.mjs → chunk-MUBQER6D.mjs} +1 -1
  21. package/dist/{chunk-ZGGZXRGM.mjs → chunk-NNRDQYBD.mjs} +8 -8
  22. package/dist/{chunk-DEYEVTFV.mjs → chunk-ONDHZ4WW.mjs} +2 -2
  23. package/dist/{chunk-FAK7Y3OX.mjs → chunk-PM2UOKYB.mjs} +3 -3
  24. package/dist/{chunk-3Q6CDT32.mjs → chunk-RBHEMWN6.mjs} +2 -2
  25. package/dist/{chunk-CP4ZQR2X.mjs → chunk-UAITBI74.mjs} +2 -2
  26. package/dist/{chunk-UQFWTROO.mjs → chunk-VIHHCXBO.mjs} +3 -3
  27. package/dist/{chunk-GLPBA2YZ.mjs → chunk-WCGFMFWK.mjs} +2 -2
  28. package/dist/{chunk-6RNOECOF.mjs → chunk-WRDGPEN6.mjs} +2 -2
  29. package/dist/{direct-executor-TWLEPVQO.mjs → direct-executor-3C5WFR33.mjs} +1 -1
  30. package/dist/distribution/coordinator/etcd.mjs +5 -1
  31. package/dist/distribution/transport/tcp.mjs +23 -18
  32. package/dist/distribution.mjs +391 -305
  33. package/dist/index.browser.mjs +1 -1
  34. package/dist/index.mjs +1 -1
  35. package/dist/index.react-native.mjs +1 -1
  36. package/dist/{long-query-thread-HK5FP64H.mjs → long-query-thread-C62WK6NI.mjs} +10 -10
  37. package/dist/{optional-writes-DPWRGFKK.mjs → optional-writes-AGDEVXC4.mjs} +3 -3
  38. package/dist/{paged-partition-archive-NITVFYOC.mjs → paged-partition-archive-EABR3N3F.mjs} +9 -9
  39. package/dist/partial-words.browser.mjs +1 -1
  40. package/dist/partial-words.mjs +1 -1
  41. package/dist/persistence/durability/checkpoint-worker.mjs +7 -7
  42. package/dist/{query-actions-AA5LE2WV.mjs → query-actions-QH5UQRCY.mjs} +1 -1
  43. package/dist/query-suggestions/merge-worker.mjs +4 -4
  44. package/dist/query-suggestions.browser.mjs +1 -1
  45. package/dist/query-suggestions.mjs +2 -2
  46. package/dist/react-native/chunks/{chunk-HGZNA5A6.mjs → chunk-ALSPAMEE.mjs} +1 -1
  47. package/dist/react-native/chunks/{chunk-OVYLUGEW.mjs → chunk-BGRX5SPG.mjs} +1 -1
  48. package/dist/react-native/chunks/{chunk-ZZQ2RIYZ.mjs → chunk-GPMPHDDO.mjs} +2 -2
  49. package/dist/react-native/chunks/{chunk-3BEUTRYM.mjs → chunk-NUOJ2EAK.mjs} +1 -1
  50. package/dist/react-native/chunks/{chunk-574N6ERF.mjs → chunk-PTCHRZCP.mjs} +1 -1
  51. package/dist/react-native/chunks/{chunk-6KVWTGEJ.mjs → chunk-V2H7EDTM.mjs} +8 -8
  52. package/dist/react-native/chunks/{optional-writes-UYVKLJU6.mjs → optional-writes-F4FJKEZ4.mjs} +2 -2
  53. package/dist/react-native/chunks/{restore-queue-AZIZ5ABX.mjs → restore-queue-MLFBOOZP.mjs} +4 -4
  54. package/dist/react-native/chunks/{segment-codec-leaf-TYO4LKQ6.mjs → segment-codec-leaf-Z3OS3B2K.mjs} +2 -2
  55. package/dist/react-native/chunks/{segment-merge-leaf-KM52IXXQ.mjs → segment-merge-leaf-TNHU77VW.mjs} +3 -3
  56. package/dist/react-native/chunks/{storage-leaf-HKJBZXIP.mjs → storage-leaf-NF733K7B.mjs} +25 -17
  57. package/dist/react-native/chunks/{store-leaf-LS5LT25L.mjs → store-leaf-UDKCNQB7.mjs} +3 -3
  58. package/dist/react-native/chunks/{suggestions-leaf-IJ3Z4EH3.mjs → suggestions-leaf-M6ITOPNM.mjs} +3 -3
  59. package/dist/react-native/chunks/{worker-copies-VNXZRBVW.mjs → worker-copies-GG7CKUBI.mjs} +2 -2
  60. package/dist/react-native/partial-words.mjs +1 -1
  61. package/dist/react-native/query-suggestions.mjs +1 -1
  62. package/dist/react-native/sync.mjs +1 -1
  63. package/dist/react-native/synonyms.mjs +1 -1
  64. package/dist/{rerank-X4HOST2N.mjs → rerank-LCMA5PZG.mjs} +1 -1
  65. package/dist/{restore-queue-CI72WRAF.mjs → restore-queue-NSA3RWF6.mjs} +4 -4
  66. package/dist/{segment-codec-leaf-7R5H2IYU.mjs → segment-codec-leaf-DQKKIN4F.mjs} +2 -2
  67. package/dist/{segment-merge-leaf-IWL4VH7C.mjs → segment-merge-leaf-67Z6OMRF.mjs} +2 -2
  68. package/dist/server.mjs +16 -16
  69. package/dist/{storage-leaf-6YCHFH2O.mjs → storage-leaf-FUH75D3X.mjs} +18 -18
  70. package/dist/{store-leaf-V5N2REHF.mjs → store-leaf-CKZFFFTX.mjs} +3 -3
  71. package/dist/{suggestions-leaf-XFJ4L37A.mjs → suggestions-leaf-NOSJIRSD.mjs} +5 -5
  72. package/dist/sync/filesystem.mjs +4 -4
  73. package/dist/sync.browser.mjs +1 -1
  74. package/dist/sync.mjs +1 -1
  75. package/dist/synonyms.browser.mjs +1 -1
  76. package/dist/synonyms.mjs +1 -1
  77. package/dist/{thread-UQAIJ5CS.mjs → thread-T5F3HSMC.mjs} +9 -9
  78. package/dist/{worker-copies-44MSY3IU.mjs → worker-copies-TPEHVXPI.mjs} +4 -4
  79. package/dist/workers/entry.mjs +7 -7
  80. package/package.json +5 -5
@@ -1,38 +1,38 @@
1
- import { routableAllocation, resolvePartitionId, resolveNodeTargets, resolvePrimaryAssignment, requireAssignedPrimary, assertSufficientActiveReplicas, getInSyncReplicaTargets } from './chunk-DEYEVTFV.mjs';
2
- import { emptySerializablePartition } from './chunk-H7IIA2KL.mjs';
3
- import { applyStoredIndexBm25 } from './chunk-C3OQQ3M6.mjs';
4
- import { keyBytesOf, querySuggestionsOf, createQuerySuggestionsRuntime, publicBuildOf, buildRecordToWire, buildRecordFromWire, SUGGESTIONS_SCHEMA } from './chunk-REM3KDXN.mjs';
5
- import { stampAnalysisGeneration, holdsNamedSettings, dropHeldAnalysisChange, releaseHeldAnalysisChange, heldAnalysisIsBuilt, buildHeldAnalysisChange, archiveStream, buildArchiveFromMemory, indexMetadataOf, applyIndexEntry, applyDeleteEntry, documentExportStream, followSourceChanges, requireChangesSetting, resolveAnalysisTarget, requireConfigurationWithinSizeLimit, memoryCheckpointStore, createByteReader, writeArchiveFile, namedSettingsOf, createDetachedIndex, loadPartitionSegments, changesStatusOf, holdsSettings, configOfNamedSettings, closePartitionWriter, requireRestoreMemory, archiveFootprint, storedBytesOfSegments, validateReplicationEntry, readSegmentManifest, replaySyncedWal, nestedSchemaOf } from './chunk-XX4SKT54.mjs';
6
- import { readVectorFile } from './chunk-UQFWTROO.mjs';
1
+ import { routableAllocation, resolvePartitionId, resolveNodeTargets, resolvePrimaryAssignment, requireAssignedPrimary, assertSufficientActiveReplicas, getInSyncReplicaTargets } from './chunk-ONDHZ4WW.mjs';
2
+ import { emptySerializablePartition } from './chunk-7DW2ITZ3.mjs';
3
+ import { applyStoredIndexBm25 } from './chunk-DVFCDOXW.mjs';
4
+ import { keyBytesOf, querySuggestionsOf, createQuerySuggestionsRuntime, publicBuildOf, buildRecordToWire, buildRecordFromWire, SUGGESTIONS_SCHEMA } from './chunk-FWZ5OK5G.mjs';
5
+ import { stampAnalysisGeneration, holdsNamedSettings, dropHeldAnalysisChange, releaseHeldAnalysisChange, heldAnalysisIsBuilt, buildHeldAnalysisChange, archiveStream, buildArchiveFromMemory, indexMetadataOf, applyIndexEntry, applyDeleteEntry, documentExportStream, followSourceChanges, requireChangesSetting, resolveAnalysisTarget, requireConfigurationWithinSizeLimit, memoryCheckpointStore, createByteReader, writeArchiveFile, namedSettingsOf, createDetachedIndex, loadPartitionSegments, changesStatusOf, holdsSettings, configOfNamedSettings, closePartitionWriter, requireRestoreMemory, archiveFootprint, storedBytesOfSegments, validateReplicationEntry, readSegmentManifest, replaySyncedWal, nestedSchemaOf } from './chunk-BOTZ2GSW.mjs';
6
+ import { readVectorFile } from './chunk-VIHHCXBO.mjs';
7
7
  import { addBackgroundAdmission, workWaitingForMemory, resolveHybridFusion, fuseRankings } from './chunk-GXED6R3Q.mjs';
8
8
  import { UNADDRESSABLE_TARGET_DETAIL, MAX_MESSAGE_SIZE_BYTES } from './chunk-HZ3OAUTL.mjs';
9
- import { bindEngineWriteBlock, bindIndexReads, syncServingSourceOf, bindSyncServing, changesServingSourceOf, bindChangesServing, validateBackupConfig, BACKUP_SWEEP_INTERVAL_MS, bindWriteBlockLookup, backupKeys, validateBackupName, CHANGES_BACKUP_TAKER, BACKUP_MANIFEST_READS_AT_ONCE, storedFilesOf, decodeBackupManifest, BACKUP_JOBS_KEY, BACKUP_DELETES_AT_ONCE, BACKUP_PROGRESS_REPORT_INTERVAL_MS, BACKUP_PARTITION_RESULT_RETENTION_MS, BACKUP_JOB_POLL_INTERVAL_MS, BACKUP_FILES_AT_ONCE, isCount, storeWithoutSaveIfAbsent, CLUSTER_UUID_KEY, isSha256Hex, BACKUP_PUBLISH_RETRY_MS, isBackupTaker, readRestorePlacement, SYNC_BACKUP_TAKER, BACKUP_JOB_CAS_ATTEMPTS, BACKUP_JOB_CAS_RETRY_MS, MAX_CLUSTER_UUID_BYTES, MAX_FINISHED_BACKUP_JOBS, BACKUP_FILE_CHUNK_BYTES, encodeBackupManifest, SYNC_BACKUPS_KEPT, BACKUP_PARTITIONS_AT_ONCE, BACKUP_PARTITION_POLL_INTERVAL_MS, BACKUP_PRIMARY_WAIT_MS, readBackupPartition, readStoredFile } from './chunk-7SMVY4AX.mjs';
10
- import { DEFAULT_NODE_LIFECYCLE_CONFIG, DEFAULT_CONTROLLER_CONFIG, indexMetadataSnapshotOf, getIndexMetadata, getClusterIndexConfig, withPartitionCount, readIndexMetadataSnapshot, validateIndexName, indexConfigKey, metadataWithSync, suggestionStateOfSettings, indexConfigFromSettings, metadataWithBm25, readIndexState, storeSynonymSet, deleteSynonymSet, indexSettingsOf, putIndexMetadata, isValidInteger, isRecord, HIDDEN_GENERATION_PREFIX, isRecord2, decodeIndexSettings, metadataWithSynonymSet, RESHARD_RECORD_CAS_ATTEMPTS, indexUuidOfStoredMetadata, storedSynonymSetOf, RESHARD_FORWARD_BATCH_DOCUMENTS, RESHARD_RETRY_DELAY_MS, TEARDOWN_CAS_ATTEMPTS, RESHARD_RECORD_CHECK_INTERVAL_MS, RESHARD_POLL_INTERVAL_MS, ALLOCATION_RETRY_DELAY_MS, TEARDOWN_RETRY_ROUNDS, ANALYSIS_CHANGE_RETRY_MS, putIndexReplicationFactor, ALLOCATION_CAS_ATTEMPTS, TEARDOWN_RETRY_DELAY_MS, RESHARD_CONTROLLER_POLL_INTERVAL_MS, MAX_RESHARD_CUTOVER_ATTEMPTS, ANALYSIS_CHANGE_POLL_INTERVAL_MS, RECOVERY_CAS_ATTEMPTS, ESTIMATED_PARTITION_BYTES, REBALANCE_THRESHOLD, putGenerationMetadata, RESHARD_CUTOVER_LAG_ENTRIES, ANALYSIS_REBUILD_RESEND_MS, RESHARD_CUTOVER_TIMEOUT_MS, PARTITION_STORES_TIMEOUT_MS, SYNC_EPOCH_CAS_ATTEMPTS, syncSettingsOfSnapshot, epochFeaturesOn, LEADERSHIP_IMBALANCE_THRESHOLD, BOOTSTRAP_CAS_ATTEMPTS, metadataWithSuggestionState, UNFED_REPLICA_CHECK_INTERVAL_MS, UNFED_REPLICA_RESYNC_MS } from './chunk-VV6P6LKJ.mjs';
9
+ import { bindEngineWriteBlock, bindIndexReads, syncServingSourceOf, bindSyncServing, changesServingSourceOf, bindChangesServing, validateBackupConfig, BACKUP_SWEEP_INTERVAL_MS, bindWriteBlockLookup, backupKeys, validateBackupName, CHANGES_BACKUP_TAKER, BACKUP_MANIFEST_READS_AT_ONCE, storedFilesOf, decodeBackupManifest, BACKUP_JOBS_KEY, BACKUP_DELETES_AT_ONCE, BACKUP_PROGRESS_REPORT_INTERVAL_MS, BACKUP_PARTITION_RESULT_RETENTION_MS, BACKUP_JOB_POLL_INTERVAL_MS, BACKUP_FILES_AT_ONCE, isCount, storeWithoutSaveIfAbsent, CLUSTER_UUID_KEY, isSha256Hex, BACKUP_PUBLISH_RETRY_MS, isBackupTaker, readRestorePlacement, SYNC_BACKUP_TAKER, BACKUP_JOB_CAS_ATTEMPTS, BACKUP_JOB_CAS_RETRY_MS, MAX_CLUSTER_UUID_BYTES, MAX_FINISHED_BACKUP_JOBS, BACKUP_FILE_CHUNK_BYTES, encodeBackupManifest, SYNC_BACKUPS_KEPT, BACKUP_PARTITIONS_AT_ONCE, BACKUP_PARTITION_POLL_INTERVAL_MS, BACKUP_PRIMARY_WAIT_MS, readBackupPartition, readStoredFile } from './chunk-3GWUUKDJ.mjs';
10
+ import { DEFAULT_NODE_LIFECYCLE_CONFIG, DEFAULT_CONTROLLER_CONFIG, indexMetadataSnapshotOf, getIndexMetadata, getClusterIndexConfig, withPartitionCount, readIndexMetadataSnapshot, validateIndexName, indexConfigKey, metadataWithSync, suggestionStateOfSettings, indexConfigFromSettings, metadataWithBm25, readIndexState, storeSynonymSet, deleteSynonymSet, indexSettingsOf, putIndexMetadata, isValidInteger, isRecord, HIDDEN_GENERATION_PREFIX, isRecord2, decodeIndexSettings, metadataWithSynonymSet, RESHARD_RECORD_CAS_ATTEMPTS, indexUuidOfStoredMetadata, storedSynonymSetOf, RESHARD_FORWARD_BATCH_DOCUMENTS, RESHARD_RETRY_DELAY_MS, TEARDOWN_CAS_ATTEMPTS, RESHARD_RECORD_CHECK_INTERVAL_MS, RESHARD_POLL_INTERVAL_MS, ALLOCATION_RETRY_DELAY_MS, TEARDOWN_RETRY_ROUNDS, ANALYSIS_CHANGE_RETRY_MS, putIndexReplicationFactor, ALLOCATION_CAS_ATTEMPTS, TEARDOWN_RETRY_DELAY_MS, RESHARD_CONTROLLER_POLL_INTERVAL_MS, MAX_RESHARD_CUTOVER_ATTEMPTS, ANALYSIS_CHANGE_POLL_INTERVAL_MS, RECOVERY_CAS_ATTEMPTS, ESTIMATED_PARTITION_BYTES, REBALANCE_THRESHOLD, putGenerationMetadata, RESHARD_CUTOVER_LAG_ENTRIES, ANALYSIS_REBUILD_RESEND_MS, RESHARD_CUTOVER_TIMEOUT_MS, PARTITION_STORES_TIMEOUT_MS, SYNC_EPOCH_CAS_ATTEMPTS, syncSettingsOfSnapshot, epochFeaturesOn, LEADERSHIP_IMBALANCE_THRESHOLD, BOOTSTRAP_CAS_ATTEMPTS, metadataWithSuggestionState, UNFED_REPLICA_CHECK_INTERVAL_MS, UNFED_REPLICA_RESYNC_MS } from './chunk-CZHAPGVH.mjs';
11
11
  import './chunk-4H4RG2FR.mjs';
12
- import { MAX_WAIT_FOR_ACTIVE_REPLICAS, MIN_CONTROLLER_LEASE_TTL_MS, MAX_NODE_LEFT_DELAY_MS, DEFAULT_MAX_PER_SOURCE_SNAPSHOTS, DEFAULT_MAX_STREAMS_PER_INDEX, DEFAULT_CAPACITY, CATCH_UP_TICK_MS, MEMORY_SAMPLE_INTERVAL_MS, createWritePressure, WRITE_MEMORY_SAMPLE_MAX_AGE_MS, DEFAULT_IN_FLIGHT_WRITE_FRACTION, MAX_SETTINGS_REPLACEMENT_ATTEMPTS, SETTINGS_CONTENTION_REASON, MAX_DROP_ACKNOWLEDGE_WAIT_MS, DEFAULT_PARTITION_COUNT, DEFAULT_REPLICATION_FACTOR, DEFAULT_CREATE_INDEX_WAIT_MS, DEFAULT_BOOTSTRAP_SYNC_DEADLINE_MS, DROP_ACKNOWLEDGE_POLL_INTERVAL_MS, COORDINATOR_REQUEST_BUCKET_BOUNDS_SECONDS, COPY_FAILURE_ATTEMPTS, SEARCH_CONTEXT_REAPER_INTERVAL_MS, DECOMMISSION_RECHECK_INTERVAL_MS, refuseEncodeWithoutRoom, answerRefusalOf, withAdmittedWrite, estimateForwardedBytes, PARTITION_BYTES_INDEX_OVERHEAD_BYTES, MAX_SOURCE_ID_LENGTH, ADMISSION_TIMEOUT_MS, PARTITION_BYTES_ENTRY_BYTES, PARTITION_BYTES_REPORT_BUDGET_BYTES, CATCH_UP_FEED_WINDOW_MS, MAX_CATCH_UP_IN_FLIGHT_BYTES, SYNCED_POSITION_REPORT_TIMEOUT_MS, SNAPSHOT_CHUNK_YIELD_INTERVAL_MS, ANSWER_DECODE_HEAP_BYTES_PER_PAYLOAD_BYTE, ADMISSION_RETRIES_AFTER_IN_SYNC_CHANGE, REGISTRATION_LEASE_DRIFT_SHARE, REGISTRATION_LEASE_CONFIRM_TIMEOUT_MS, WRITE_APPLY_YIELD_INTERVAL_MS, ROLLBACK_RETRY_INITIAL_DELAY_MS, ROLLBACK_RETRY_DELAY_CAP_MS, OUT_OF_STEP_REMOVAL_RETRY_INITIAL_DELAY_MS, OUT_OF_STEP_REMOVAL_RETRY_DELAY_CAP_MS, FETCH_GROUP_DOCUMENT_IDS, COPY_FAILURE_RETRY_DELAY_MS, SEARCH_CONTEXT_ENTRY_HEAP_BYTES, CLEAR_PAGE_SIZE, estimateDocumentsBytes, estimateDocumentBytes, PRIMARY_CHANGE_RETRY_WINDOW_MS, PRIMARY_CHANGE_POLL_INTERVAL_MS, PARTITION_WRITE_CONCURRENCY, FORWARD_RETRY_INITIAL_DELAY_MS, FORWARD_RETRY_DELAY_CAP_MS } from './chunk-AAH5CD3M.mjs';
13
- export { DEFAULT_CAPACITY, DEFAULT_PARTITION_COUNT, DEFAULT_REPLICATION_FACTOR } from './chunk-AAH5CD3M.mjs';
14
- import { encodeIndexConfiguration, MAX_SNAPSHOT_ANALYSIS_ATTEMPTS, decodeIndexConfiguration, requireSyncSetting, requireNoQuerySuggestions, validChangeFilter, createDocumentTest, INDEX_CONFIGURATION_ENVELOPE_VERSION, changesNotEnabled } from './chunk-GDCTK5LU.mjs';
12
+ import { MAX_WAIT_FOR_ACTIVE_REPLICAS, MIN_CONTROLLER_LEASE_TTL_MS, MAX_NODE_LEFT_DELAY_MS, DEFAULT_MAX_PER_SOURCE_SNAPSHOTS, DEFAULT_MAX_STREAMS_PER_INDEX, DEFAULT_CAPACITY, CATCH_UP_TICK_MS, MEMORY_SAMPLE_INTERVAL_MS, createWritePressure, WRITE_MEMORY_SAMPLE_MAX_AGE_MS, DEFAULT_IN_FLIGHT_WRITE_FRACTION, MAX_SETTINGS_REPLACEMENT_ATTEMPTS, SETTINGS_CONTENTION_REASON, MAX_DROP_ACKNOWLEDGE_WAIT_MS, DEFAULT_PARTITION_COUNT, DEFAULT_REPLICATION_FACTOR, DEFAULT_CREATE_INDEX_WAIT_MS, DEFAULT_BOOTSTRAP_SYNC_DEADLINE_MS, DROP_ACKNOWLEDGE_POLL_INTERVAL_MS, COORDINATOR_REQUEST_BUCKET_BOUNDS_SECONDS, COPY_FAILURE_ATTEMPTS, SEARCH_CONTEXT_REAPER_INTERVAL_MS, DECOMMISSION_RECHECK_INTERVAL_MS, refuseEncodeWithoutRoom, answerRefusalOf, withAdmittedWrite, estimateForwardedBytes, PARTITION_BYTES_INDEX_OVERHEAD_BYTES, MAX_SOURCE_ID_LENGTH, ADMISSION_TIMEOUT_MS, PARTITION_BYTES_ENTRY_BYTES, PARTITION_BYTES_REPORT_BUDGET_BYTES, CATCH_UP_FEED_WINDOW_MS, MAX_CATCH_UP_IN_FLIGHT_BYTES, SYNCED_POSITION_REPORT_TIMEOUT_MS, SNAPSHOT_CHUNK_YIELD_INTERVAL_MS, ANSWER_DECODE_HEAP_BYTES_PER_PAYLOAD_BYTE, ADMISSION_RETRIES_AFTER_IN_SYNC_CHANGE, REGISTRATION_LEASE_DRIFT_SHARE, REGISTRATION_LEASE_CONFIRM_TIMEOUT_MS, WRITE_APPLY_YIELD_INTERVAL_MS, ROLLBACK_RETRY_INITIAL_DELAY_MS, ROLLBACK_RETRY_DELAY_CAP_MS, OUT_OF_STEP_REMOVAL_RETRY_INITIAL_DELAY_MS, OUT_OF_STEP_REMOVAL_RETRY_DELAY_CAP_MS, FETCH_GROUP_DOCUMENT_IDS, COPY_FAILURE_RETRY_DELAY_MS, SEARCH_CONTEXT_ENTRY_HEAP_BYTES, CLEAR_PAGE_SIZE, estimateDocumentsBytes, estimateDocumentBytes, PRIMARY_CHANGE_RETRY_WINDOW_MS, PRIMARY_CHANGE_POLL_INTERVAL_MS, PARTITION_WRITE_CONCURRENCY, FORWARD_RETRY_INITIAL_DELAY_MS, FORWARD_RETRY_DELAY_CAP_MS } from './chunk-MUBQER6D.mjs';
13
+ export { DEFAULT_CAPACITY, DEFAULT_PARTITION_COUNT, DEFAULT_REPLICATION_FACTOR } from './chunk-MUBQER6D.mjs';
14
+ import { encodeIndexConfiguration, MAX_SNAPSHOT_ANALYSIS_ATTEMPTS, decodeIndexConfiguration, requireSyncSetting, requireNoQuerySuggestions, validChangeFilter, createDocumentTest, INDEX_CONFIGURATION_ENVELOPE_VERSION, changesNotEnabled } from './chunk-AQI4DIFA.mjs';
15
15
  import { restoredConfigFields, restoredEmbedding } from './chunk-M2Z5WVWW.mjs';
16
- import { readSnapshotArchive, archiveLayout, openManifestPayload, sourceIndexNameOf, listedKeysOf, decodeManifestPayload, estimatedArchiveBytes } from './chunk-3Q6CDT32.mjs';
16
+ import { readSnapshotArchive, archiveLayout, openManifestPayload, sourceIndexNameOf, listedKeysOf, decodeManifestPayload, estimatedArchiveBytes } from './chunk-RBHEMWN6.mjs';
17
17
  import { CONTROLLER_LEASE_KEY } from './chunk-44W3CBNG.mjs';
18
18
  import './chunk-T4HMSZCX.mjs';
19
- import { createForwardBatchResultMessage, validateEntryBatchPayload, createAckMessage, validateEntryPayload, validateForwardBatchPayload, DEFAULT_LOG_RETENTION_BYTES, buildEntry, optionalIndexUuid, entryByteEstimate, computeEntryChecksum, createPrimaryResignMessage, validateInsyncConfirmPayload, createInsyncRemoveMessage, SNAPSHOT_CHUNK_SIZE, createEntryBatchMessage, createInsyncConfirmMessage, createEntryMessage, validateAckPayload, createInsyncAddMessage, checkpointLastSeqNo, checkpointPrimaryTerm, INSYNC_CAS_ATTEMPTS, createForwardBatchMessage, validateForwardBatchResultPayload, createForwardMessage } from './chunk-KGLBLKYF.mjs';
20
- import { directoryCheckpointStore, readListedFile, encodeSegmentManifest } from './chunk-UDDZVZTV.mjs';
19
+ import { createForwardBatchResultMessage, validateEntryBatchPayload, createAckMessage, validateEntryPayload, validateForwardBatchPayload, DEFAULT_LOG_RETENTION_BYTES, buildEntry, invalidReplicationPayload, optionalIndexUuid, validateForwardOperation, entryByteEstimate, computeEntryChecksum, createPrimaryResignMessage, validateInsyncConfirmPayload, createInsyncRemoveMessage, SNAPSHOT_CHUNK_SIZE, createEntryBatchMessage, createEntryMessage, validateAckPayload, createInsyncAddMessage, createInsyncConfirmMessage, checkpointLastSeqNo, checkpointPrimaryTerm, INSYNC_CAS_ATTEMPTS, createForwardBatchMessage, validateForwardBatchResultPayload, createForwardMessage } from './chunk-HWIIMLLR.mjs';
20
+ import { directoryCheckpointStore, readListedFile, encodeSegmentManifest } from './chunk-JASE2FE6.mjs';
21
21
  import { TransportErrorCodes, ClusterMessageTypes, ReplicationMessageTypes, SuggestionMessageTypes, SyncMessageTypes, QueryMessageTypes, TransportError, DEFAULT_TRANSPORT_CONFIG } from './chunk-5FLRXF73.mjs';
22
22
  import { MAX_PARTITION_COUNT, MAX_REPLICATION_FACTOR, WIRE_BATCH_BUDGET } from './chunk-JDDXV6UF.mjs';
23
- import { manifestFileRefs, segmentKey, SEGMENT_MANIFEST_VERSION, vectorFileKey } from './chunk-CPAE2QJP.mjs';
23
+ import { manifestFileRefs, segmentKey, SEGMENT_MANIFEST_VERSION, vectorFileKey } from './chunk-EDZJNZKV.mjs';
24
24
  import './chunk-S5QMWECL.mjs';
25
25
  import './chunk-LNGE7SLY.mjs';
26
26
  import './chunk-5SHWA6PE.mjs';
27
- import './chunk-7HVZVD2N.mjs';
28
- import { deserializePartition } from './chunk-3PO2MOFY.mjs';
27
+ import './chunk-AWMO3NKJ.mjs';
28
+ import { deserializePartition } from './chunk-57MN2UAL.mjs';
29
29
  import { decodeVectorFilePayload, bytesToVectors, isDead, MIN_EF_SEARCH, MAX_EF_SEARCH, MIN_OVERSAMPLE } from './chunk-R724DJSG.mjs';
30
- import './chunk-6RNOECOF.mjs';
31
- import { RestoredHistory } from './chunk-GLPBA2YZ.mjs';
30
+ import './chunk-WRDGPEN6.mjs';
31
+ import { RestoredHistory } from './chunk-WCGFMFWK.mjs';
32
32
  import { oneSyncChangeAtATime } from './chunk-V6EUBAIT.mjs';
33
- import { historyFilesOf, removeHistoryFolder, QUERY_HISTORY_FOLDER, RESTORE_STAGING_INFIX, openChecksummedEnvelope, historyFolderOf, listHistoryFolder, historyFileOf, COUNTS_STREAM_CHUNK_BYTES, BUILD_WRITE_BATCH, restoreStagingPrefix, crc32Init, crc32Final, crc32Update, MAX_COUNTS_STREAM_KEY_BYTES, MAX_HISTORY_FILE_BYTES, packChecksummedEnvelope, storedStateOf } from './chunk-RXQZ53NV.mjs';
33
+ import { historyFilesOf, removeHistoryFolder, QUERY_HISTORY_FOLDER, RESTORE_STAGING_INFIX, openChecksummedEnvelope, historyFolderOf, listHistoryFolder, historyFileOf, COUNTS_STREAM_CHUNK_BYTES, BUILD_WRITE_BATCH, restoreStagingPrefix, crc32Init, crc32Final, crc32Update, MAX_COUNTS_STREAM_KEY_BYTES, MAX_HISTORY_FILE_BYTES, packChecksummedEnvelope, storedStateOf } from './chunk-GTB2S2VX.mjs';
34
34
  import { boundQuerySuggestionsOf, bindQuerySuggestions } from './chunk-S2POFTLN.mjs';
35
- import { oversampledShardSize, runtimeHost, bindRerankWindowSource, rerankWindowCapOf, validateMemoryFractions, requireKnownConfig, importOptionalReads, resolveRunnableConfig, createEngineCore, startEngineCore, createNarsilFromCore, runEngineQueryStats, runEngineListDocuments, runEngineSuggest, runEnginePreflight, runEngineQuery, emitEngineEvent, synonymModule, createEngineIndex, generateId, documentChurnOf, isCompositePartition, getLanguage, resolveIndexAnalysis, memoryFractionsOf, createMemoryMonitor, readMemoryFigures, FULL_MEMORY_COLLECTION_INTERVAL_MS, validateBM25Params, storedBM25Params, requireSurfaceFormsForPartialFields, bm25SetsValue, prepareConfiguredSynonyms, storedArrayPositionGap, updateDocumentVectors, arrayPositionsAreStale, fnv1a, readRecentMemoryFigures, normalizeSort, sortModesOf, resolveProjection, noteDocumentChurn, MAP_TABLE_MIN_CAPACITY, MAP_TABLE_SHRINK_DIVISOR, requireLoadedOptionalReads, applyProjection, FILTER_EXPRESSION_KEYS, filterTestCount, setNestedValue, validateBM25Shape, CASE_FOLD_EXPANSION_FACTOR, PATTERN_RUN_HEAP_BYTES, ENUM_VALUE_HEAP_BYTES, DOCUMENT_VALUE_HEAP_BYTES, DOCUMENT_HEAP_BYTES_PER_ESTIMATED_BYTE, DOCUMENT_PROPERTY_HEAP_BYTES, VECTOR_DOCUMENT_HEAP_BYTES, VECTOR_COMPONENT_HEAP_BYTES, hasLanguage, FIELD_FILTER_OPERATORS, yieldToEventLoop, NORMALIZATION_EXPANSION_FACTOR, TERM_UNIT_HEAP_BYTES, customTokensOf, visitTokens, getVectorFieldPaths, resolvePartitionInsertOptions, clampRowCount, now, sortSignatureOf, listBindingOf, requireMatchingCursor, decodePageCursor, encodePageCursor, DISTINCT_TERM_HEAP_BYTES, PARTIAL_SPELLING_HEAP_BYTES, clampLimit, requireWithinResultWindow, providedDocId, MAP_TABLE_HEADER_BYTES, MAP_TABLE_SLOT_BYTES, holdsQuotedText, queryBindingOf, engineCoreOf, sortSignatureEntry, fnv1aUint32s, loadRerankRuntime, mergePartitionStats, mergeEntries, regionsOverlap, compareScores } from './chunk-ZGGZXRGM.mjs';
35
+ import { oversampledShardSize, runtimeHost, bindRerankWindowSource, rerankWindowCapOf, validateMemoryFractions, requireKnownConfig, importOptionalReads, resolveRunnableConfig, createEngineCore, startEngineCore, createNarsilFromCore, runEngineQueryStats, runEngineListDocuments, runEngineSuggest, runEnginePreflight, runEngineQuery, emitEngineEvent, synonymModule, createEngineIndex, generateId, documentChurnOf, isCompositePartition, getLanguage, resolveIndexAnalysis, memoryFractionsOf, createMemoryMonitor, readMemoryFigures, FULL_MEMORY_COLLECTION_INTERVAL_MS, validateBM25Params, storedBM25Params, requireSurfaceFormsForPartialFields, bm25SetsValue, prepareConfiguredSynonyms, storedArrayPositionGap, updateDocumentVectors, arrayPositionsAreStale, fnv1a, readRecentMemoryFigures, resolveProjection, normalizeSort, sortModesOf, noteDocumentChurn, MAP_TABLE_MIN_CAPACITY, MAP_TABLE_SHRINK_DIVISOR, applyProjection, requireLoadedOptionalReads, FILTER_EXPRESSION_KEYS, filterTestCount, setNestedValue, CASE_FOLD_EXPANSION_FACTOR, PATTERN_RUN_HEAP_BYTES, ENUM_VALUE_HEAP_BYTES, validateBM25Shape, DOCUMENT_VALUE_HEAP_BYTES, DOCUMENT_HEAP_BYTES_PER_ESTIMATED_BYTE, DOCUMENT_PROPERTY_HEAP_BYTES, VECTOR_DOCUMENT_HEAP_BYTES, VECTOR_COMPONENT_HEAP_BYTES, hasLanguage, FIELD_FILTER_OPERATORS, yieldToEventLoop, NORMALIZATION_EXPANSION_FACTOR, TERM_UNIT_HEAP_BYTES, customTokensOf, visitTokens, getVectorFieldPaths, resolvePartitionInsertOptions, clampRowCount, now, sortSignatureOf, listBindingOf, requireMatchingCursor, decodePageCursor, encodePageCursor, DISTINCT_TERM_HEAP_BYTES, PARTIAL_SPELLING_HEAP_BYTES, clampLimit, requireWithinResultWindow, providedDocId, MAP_TABLE_HEADER_BYTES, MAP_TABLE_SLOT_BYTES, holdsQuotedText, queryBindingOf, engineCoreOf, sortSignatureEntry, fnv1aUint32s, loadRerankRuntime, mergePartitionStats, mergeEntries, regionsOverlap, compareScores } from './chunk-NNRDQYBD.mjs';
36
36
  import { encodeDocument, encodeDocumentReply } from './chunk-2CKDCC65.mjs';
37
37
  import { collectYoungGenerationBeforeRefusal, collectGarbageBeforeRefusal, onRefusalAfterCollection, reservedHeapBytes, reserveHeapBytes } from './chunk-BRTABNC7.mjs';
38
38
  import { decode } from './chunk-Y7GXGJFZ.mjs';
@@ -116,6 +116,19 @@ function encodeRebalanceRefusal(error) {
116
116
  return encode({ error: true, code, message: text2 });
117
117
  }
118
118
  }
119
+
120
+ // src/distribution/request-decode.ts
121
+ function decodeRequestPayload(payload, messageType) {
122
+ try {
123
+ return decode(payload);
124
+ } catch (error) {
125
+ throw new NarsilError(
126
+ TransportErrorCodes.DECODE_FAILED,
127
+ `The payload of a ${messageType} request is not valid MessagePack`,
128
+ { messageType, cause: error instanceof Error ? error.message : String(error) }
129
+ );
130
+ }
131
+ }
119
132
  var PHASES = /* @__PURE__ */ new Set(["copying", "cutover", "aborting"]);
120
133
  var ABSENT = new Uint8Array(0);
121
134
  function rebalanceRecordKey(indexName) {
@@ -322,6 +335,9 @@ function malformed2() {
322
335
  { key: BACKUP_JOBS_KEY }
323
336
  );
324
337
  }
338
+ function nilAsAbsent(value) {
339
+ return value === null ? void 0 : value;
340
+ }
325
341
  function isOptionalString(value) {
326
342
  return value === void 0 || typeof value === "string";
327
343
  }
@@ -331,21 +347,26 @@ function decodeJobError(value) {
331
347
  return { code: value.code, message: value.message };
332
348
  }
333
349
  function decodeJob(value) {
334
- if (!isRecord(value) || typeof value.kind !== "string" || !KINDS.has(value.kind) || typeof value.backupName !== "string" || !isOptionalString(value.indexName) || !isOptionalString(value.generation) || !isOptionalString(value.nameIndexUuid) || typeof value.status !== "string" || !STATUSES.has(value.status) || !isCount(value.partitionsDone) || !isCount(value.partitionsTotal) || !isCount(value.startedAt) || !(value.finishedAt === void 0 || isCount(value.finishedAt))) {
350
+ if (!isRecord(value)) malformed2();
351
+ const indexName = nilAsAbsent(value.indexName);
352
+ const generation = nilAsAbsent(value.generation);
353
+ const nameIndexUuid = nilAsAbsent(value.nameIndexUuid);
354
+ const finishedAt = nilAsAbsent(value.finishedAt);
355
+ if (typeof value.kind !== "string" || !KINDS.has(value.kind) || typeof value.backupName !== "string" || !isOptionalString(indexName) || !isOptionalString(generation) || !isOptionalString(nameIndexUuid) || typeof value.status !== "string" || !STATUSES.has(value.status) || !isCount(value.partitionsDone) || !isCount(value.partitionsTotal) || !isCount(value.startedAt) || !(finishedAt === void 0 || isCount(finishedAt))) {
335
356
  malformed2();
336
357
  }
337
- const error = decodeJobError(value.error);
358
+ const error = decodeJobError(nilAsAbsent(value.error));
338
359
  return {
339
360
  kind: value.kind,
340
361
  backupName: value.backupName,
341
- ...value.indexName === void 0 ? {} : { indexName: value.indexName },
342
- ...value.generation === void 0 ? {} : { generation: value.generation },
343
- ...value.nameIndexUuid === void 0 ? {} : { nameIndexUuid: value.nameIndexUuid },
362
+ ...indexName === void 0 ? {} : { indexName },
363
+ ...generation === void 0 ? {} : { generation },
364
+ ...nameIndexUuid === void 0 ? {} : { nameIndexUuid },
344
365
  status: value.status,
345
366
  partitionsDone: value.partitionsDone,
346
367
  partitionsTotal: value.partitionsTotal,
347
368
  startedAt: value.startedAt,
348
- ...value.finishedAt === void 0 ? {} : { finishedAt: value.finishedAt },
369
+ ...finishedAt === void 0 ? {} : { finishedAt },
349
370
  ...error === void 0 ? {} : { error }
350
371
  };
351
372
  }
@@ -927,6 +948,66 @@ async function admitDeletion(coordinator, store, backupName) {
927
948
  await claimBackupStore(store, await clusterUuidOf(coordinator));
928
949
  }
929
950
 
951
+ // src/distribution/backups/config-agreement.ts
952
+ function isNil(value) {
953
+ return value === null || value === void 0;
954
+ }
955
+ function sameBytes(left, right) {
956
+ if (left.byteLength !== right.byteLength) return false;
957
+ for (let at = 0; at < left.byteLength; at++) {
958
+ if (left[at] !== right[at]) return false;
959
+ }
960
+ return true;
961
+ }
962
+ function pushMembers(pending, left, right) {
963
+ for (const key of Object.keys(left)) pending.push([left[key], right[key]]);
964
+ for (const key of Object.keys(right)) {
965
+ if (!Object.hasOwn(left, key)) pending.push([void 0, right[key]]);
966
+ }
967
+ }
968
+ function sameDecodedValue(left, right) {
969
+ const pending = [[left, right]];
970
+ for (let pair = pending.pop(); pair !== void 0; pair = pending.pop()) {
971
+ const [a, b] = pair;
972
+ if (a === b || isNil(a) && isNil(b)) continue;
973
+ if (typeof a === "number" && typeof b === "number" && Number.isNaN(a) && Number.isNaN(b)) continue;
974
+ if (a instanceof Uint8Array || b instanceof Uint8Array) {
975
+ if (a instanceof Uint8Array && b instanceof Uint8Array && sameBytes(a, b)) continue;
976
+ return false;
977
+ }
978
+ if (Array.isArray(a) || Array.isArray(b)) {
979
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
980
+ for (let at = 0; at < a.length; at++) pending.push([a[at], b[at]]);
981
+ continue;
982
+ }
983
+ if (!isRecord(a) || !isRecord(b)) return false;
984
+ pushMembers(pending, a, b);
985
+ }
986
+ return true;
987
+ }
988
+ function settingsChanged(indexName) {
989
+ return new NarsilError(
990
+ ErrorCodes.ANALYSIS_CHANGE_NOT_READY,
991
+ `The settings of index '${indexName}' changed while its partitions were backed up, so the backup stores no manifest`,
992
+ { indexName }
993
+ );
994
+ }
995
+ async function agreedConfigOf(store, results, indexName, backupName) {
996
+ const [first] = results;
997
+ if (first === void 0) throw settingsChanged(indexName);
998
+ const distinct = /* @__PURE__ */ new Map();
999
+ for (const result of results) {
1000
+ if (result.config.sha256 !== first.config.sha256) distinct.set(result.config.sha256, result.config);
1001
+ }
1002
+ if (distinct.size === 0) return first.config;
1003
+ const decodedFirst = await decodeIndexConfiguration(await loadCheckedBytes(store, first.config, backupName));
1004
+ for (const config of distinct.values()) {
1005
+ const decoded = await decodeIndexConfiguration(await loadCheckedBytes(store, config, backupName));
1006
+ if (!sameDecodedValue(decodedFirst, decoded)) throw settingsChanged(indexName);
1007
+ }
1008
+ return first.config;
1009
+ }
1010
+
930
1011
  // src/distribution/cluster/node-targets.ts
931
1012
  function targetsOfRegisteredNode(nodeId, address) {
932
1013
  return address.length === 0 || address === nodeId ? [nodeId] : [address, nodeId];
@@ -953,9 +1034,7 @@ var MAX_PINNED_ENTRIES = 1e3;
953
1034
  var MAX_PINNED_POSITION = RESULT_WINDOW;
954
1035
  var MAX_OVERSAMPLE = 100;
955
1036
  var MAX_GROUP_FIELDS = 64;
956
- var MAX_HIGHLIGHT_TAG_LENGTH = 256;
957
- var MAX_HIGHLIGHT_SNIPPET_LENGTH = 65536;
958
- var MAX_LIST_CURSOR_LENGTH = 4096;
1037
+ var MAX_LIST_CURSOR_LENGTH = 40960;
959
1038
  var MAX_SUGGEST_WIRE_LIMIT = 1e3;
960
1039
  var MAX_COUNT_VALUE = Number.MAX_SAFE_INTEGER;
961
1040
  var MAX_LANGUAGE_NAME_LENGTH = 64;
@@ -987,6 +1066,14 @@ function isInteger(value) {
987
1066
  function isFiniteNumber(value) {
988
1067
  return typeof value === "number" && Number.isFinite(value);
989
1068
  }
1069
+ function restoreMissingAsNil(record, members) {
1070
+ for (const member of members) {
1071
+ if (!Object.hasOwn(record, member)) record[member] = null;
1072
+ }
1073
+ }
1074
+ function dropNilMember(record, member) {
1075
+ if (record[member] === null) delete record[member];
1076
+ }
990
1077
  function validateStringField(value, fieldLabel, maxLength, errorCode) {
991
1078
  if (typeof value !== "string") {
992
1079
  throwInvalid(errorCode, `Invalid payload: "${fieldLabel}" must be a string`);
@@ -1109,32 +1196,6 @@ function validateDocumentId(value, fieldLabel) {
1109
1196
  validateStringField(value.docId, `${fieldLabel}.docId`, MAX_DOC_ID_LENGTH, CONFIG_INVALID);
1110
1197
  validatePartitionId(value.partitionId, `${fieldLabel}.partitionId`, CONFIG_INVALID);
1111
1198
  }
1112
- function validateHighlightConfig(value) {
1113
- if (!isRecord3(value)) {
1114
- throwInvalid(CONFIG_INVALID, 'Invalid FetchPayload: "highlight" must be an object or null');
1115
- }
1116
- if (value.fields !== null) {
1117
- validateStringArray(value.fields, "highlight.fields", MAX_FIELDS_LIST, 255, SEARCH_INVALID_FIELD);
1118
- }
1119
- if (typeof value.before !== "string" || value.before.length > MAX_HIGHLIGHT_TAG_LENGTH) {
1120
- throwInvalid(
1121
- CONFIG_INVALID,
1122
- `Invalid FetchPayload: "highlight.before" must be a string of at most ${MAX_HIGHLIGHT_TAG_LENGTH} characters`
1123
- );
1124
- }
1125
- if (typeof value.after !== "string" || value.after.length > MAX_HIGHLIGHT_TAG_LENGTH) {
1126
- throwInvalid(
1127
- CONFIG_INVALID,
1128
- `Invalid FetchPayload: "highlight.after" must be a string of at most ${MAX_HIGHLIGHT_TAG_LENGTH} characters`
1129
- );
1130
- }
1131
- if (typeof value.maxSnippetLength !== "number" || !Number.isFinite(value.maxSnippetLength) || !Number.isInteger(value.maxSnippetLength) || value.maxSnippetLength <= 0 || value.maxSnippetLength > MAX_HIGHLIGHT_SNIPPET_LENGTH) {
1132
- throwInvalid(
1133
- CONFIG_INVALID,
1134
- `Invalid FetchPayload: "highlight.maxSnippetLength" must be a positive integer at most ${MAX_HIGHLIGHT_SNIPPET_LENGTH}`
1135
- );
1136
- }
1137
- }
1138
1199
  function validateFetchPayload(decoded) {
1139
1200
  if (!isRecord3(decoded)) {
1140
1201
  throwInvalid(CONFIG_INVALID, "Invalid FetchPayload: expected an object");
@@ -1153,12 +1214,11 @@ function validateFetchPayload(decoded) {
1153
1214
  for (let i = 0; i < decoded.documentIds.length; i++) {
1154
1215
  validateDocumentId(decoded.documentIds[i], `documentIds[${i}]`);
1155
1216
  }
1217
+ decoded.fields ??= null;
1218
+ decoded.highlight = null;
1156
1219
  if (decoded.fields !== null) {
1157
1220
  validateStringArray(decoded.fields, "fields", MAX_FIELDS_LIST, 255, SEARCH_INVALID_FIELD);
1158
1221
  }
1159
- if (decoded.highlight !== null) {
1160
- validateHighlightConfig(decoded.highlight);
1161
- }
1162
1222
  if (decoded.contextId !== null && decoded.contextId !== void 0) {
1163
1223
  validateStringField(decoded.contextId, "contextId", MAX_SEARCH_CONTEXT_ID_LENGTH, CONFIG_INVALID);
1164
1224
  }
@@ -1183,9 +1243,7 @@ function validateFetchResultPayload(decoded) {
1183
1243
  if (!isRecord3(doc.document)) {
1184
1244
  throwInvalid(CONFIG_INVALID, `Invalid FetchResultPayload: "documents[${i}].document" must be an object`);
1185
1245
  }
1186
- if (doc.highlights !== null && !isRecord3(doc.highlights)) {
1187
- throwInvalid(CONFIG_INVALID, `Invalid FetchResultPayload: "documents[${i}].highlights" must be an object or null`);
1188
- }
1246
+ doc.highlights = null;
1189
1247
  }
1190
1248
  return decoded;
1191
1249
  }
@@ -1515,11 +1573,16 @@ var ALLOWED_MODES = ["fulltext", "vector", "hybrid"];
1515
1573
  var ALLOWED_FACET_ORDERS = ["asc", "desc"];
1516
1574
  var ALLOWED_METRICS = ["cosine", "dotProduct", "euclidean"];
1517
1575
  var ALLOWED_HYBRID_STRATEGIES = ["rrf", "linear"];
1576
+ var HYBRID_OPTIONAL_MEMBERS = ["strategy", "k", "alpha", "depth"];
1577
+ var GROUP_OPTIONAL_MEMBERS = ["limit"];
1578
+ var FACET_OPTIONAL_MEMBERS = ["sort", "ranges"];
1579
+ var BM25_MEMBERS = ["k1", "b", "fields"];
1580
+ var BM25_FIELD_MEMBERS = ["k1", "b"];
1518
1581
  function validateHybridParams(value) {
1519
1582
  if (!isRecord3(value)) {
1520
1583
  throwInvalid(CONFIG_INVALID, 'Invalid SearchPayload: "params.hybrid" must be an object');
1521
1584
  }
1522
- if (!Object.hasOwn(value, "depth")) value.depth = null;
1585
+ restoreMissingAsNil(value, HYBRID_OPTIONAL_MEMBERS);
1523
1586
  if (value.strategy !== null && !ALLOWED_HYBRID_STRATEGIES.includes(value.strategy)) {
1524
1587
  throwInvalid(
1525
1588
  SEARCH_INVALID_MODE,
@@ -1549,6 +1612,7 @@ function validateGroupParams(value) {
1549
1612
  if (!isRecord3(value)) {
1550
1613
  throwInvalid(CONFIG_INVALID, 'Invalid SearchPayload: "params.group" must be an object');
1551
1614
  }
1615
+ restoreMissingAsNil(value, GROUP_OPTIONAL_MEMBERS);
1552
1616
  const fields = validateStringArray(
1553
1617
  value.fields,
1554
1618
  "params.group.fields",
@@ -1609,6 +1673,7 @@ function validateFacetParams(value) {
1609
1673
  if (!isRecord3(entry)) {
1610
1674
  throwInvalid(CONFIG_INVALID, `Invalid SearchPayload: "params.facets[${i}]" must be an object`);
1611
1675
  }
1676
+ restoreMissingAsNil(entry, FACET_OPTIONAL_MEMBERS);
1612
1677
  validateFieldName(entry.field, `params.facets[${i}].field`, SEARCH_INVALID_FIELD);
1613
1678
  if (entry.sort !== null && !ALLOWED_FACET_ORDERS.includes(entry.sort)) {
1614
1679
  throwInvalid(
@@ -1621,6 +1686,31 @@ function validateFacetParams(value) {
1621
1686
  }
1622
1687
  }
1623
1688
  }
1689
+ function presentMembers(value, members) {
1690
+ const kept = {};
1691
+ for (const member of members) {
1692
+ const memberValue = value[member];
1693
+ if (memberValue !== void 0 && memberValue !== null) kept[member] = memberValue;
1694
+ }
1695
+ return kept;
1696
+ }
1697
+ function validateWireBm25Param(params, member, ranges) {
1698
+ const value = params[member];
1699
+ if (value === void 0 || value === null) return;
1700
+ if (isRecord3(value)) {
1701
+ const kept = presentMembers(value, BM25_MEMBERS);
1702
+ if (isRecord3(kept.fields)) {
1703
+ kept.fields = Object.fromEntries(
1704
+ Object.entries(kept.fields).map(([name, pair]) => [
1705
+ name,
1706
+ isRecord3(pair) ? presentMembers(pair, BM25_FIELD_MEMBERS) : pair
1707
+ ])
1708
+ );
1709
+ }
1710
+ params[member] = kept;
1711
+ }
1712
+ validateBM25Shape(params[member], ranges);
1713
+ }
1624
1714
  function validateTermMatchParam(value) {
1625
1715
  if (value === "all" || value === "any") {
1626
1716
  return;
@@ -1723,6 +1813,16 @@ function validateOversampleParam(value) {
1723
1813
  var MAX_FACET_SHARD_SIZE = oversampledShardSize(MAX_FACET_SIZE);
1724
1814
  var ALLOWED_SCORING = ["local", "dfs", "broadcast"];
1725
1815
  var ALLOWED_SORT_DIRECTIONS = ["asc", "desc"];
1816
+ var VECTOR_OPTIONAL_MEMBERS = [
1817
+ "value",
1818
+ "text",
1819
+ "similarity",
1820
+ "metric",
1821
+ "efSearch",
1822
+ "oversample",
1823
+ "rescoreWindow"
1824
+ ];
1825
+ var SEARCH_OPTIONAL_MEMBERS = ["globalStats", "facetShardSize"];
1726
1826
  function validateIndexNameField2(value, fieldLabel) {
1727
1827
  if (typeof value !== "string") {
1728
1828
  throwInvalid(CONFIG_INVALID, `Invalid SearchPayload: "${fieldLabel}" must be a string`);
@@ -1734,7 +1834,7 @@ function validateVectorParams(value) {
1734
1834
  if (!isRecord3(value)) {
1735
1835
  throwInvalid(CONFIG_INVALID, 'Invalid SearchPayload: "params.vector" must be an object');
1736
1836
  }
1737
- if (!Object.hasOwn(value, "rescoreWindow")) value.rescoreWindow = null;
1837
+ restoreMissingAsNil(value, VECTOR_OPTIONAL_MEMBERS);
1738
1838
  validateFieldName(value.field, "params.vector.field", SEARCH_INVALID_FIELD);
1739
1839
  if (value.value !== null) {
1740
1840
  if (!Array.isArray(value.value)) {
@@ -1808,6 +1908,7 @@ function validateSortParams(value) {
1808
1908
  throwInvalid(CONFIG_INVALID, `Invalid SearchPayload: "params.sort[${i}]" must be an object`);
1809
1909
  }
1810
1910
  validateFieldName(entry.field, `params.sort[${i}].field`, SEARCH_INVALID_FIELD);
1911
+ dropNilMember(entry, "mode");
1811
1912
  if (!ALLOWED_SORT_DIRECTIONS.includes(entry.direction)) {
1812
1913
  throwInvalid(
1813
1914
  SEARCH_INVALID_MODE,
@@ -1911,8 +2012,8 @@ function validateParams(params) {
1911
2012
  if (params.boost !== null) {
1912
2013
  validateBoostParams(params.boost);
1913
2014
  }
1914
- if (params.bm25 !== void 0 && params.bm25 !== null) validateBM25Shape(params.bm25, "settable");
1915
- if (params.indexBm25 !== void 0 && params.indexBm25 !== null) validateBM25Shape(params.indexBm25, "stored");
2015
+ validateWireBm25Param(params, "bm25", "settable");
2016
+ validateWireBm25Param(params, "indexBm25", "stored");
1916
2017
  validateAnalysisGeneration(params.analysisGeneration, "SearchPayload");
1917
2018
  if (params.tolerance !== null) {
1918
2019
  if (!isInteger(params.tolerance) || params.tolerance < 0 || params.tolerance > MAX_TOLERANCE) {
@@ -1980,6 +2081,7 @@ function validateSearchPayload(decoded) {
1980
2081
  throwInvalid(CONFIG_INVALID, 'Invalid SearchPayload: "params" must be an object');
1981
2082
  }
1982
2083
  validateParams(decoded.params);
2084
+ restoreMissingAsNil(decoded, SEARCH_OPTIONAL_MEMBERS);
1983
2085
  if (decoded.globalStats !== null) {
1984
2086
  validateGlobalStatsShape(decoded.globalStats);
1985
2087
  }
@@ -2020,6 +2122,7 @@ function validateCountPayload(decoded) {
2020
2122
  return decoded;
2021
2123
  }
2022
2124
  var STORED_SIZE_FIELDS = ["savedBytes", "vectorSavedBytes", "logBytes"];
2125
+ var LIST_OPTIONAL_MEMBERS = ["cursor", "filters", "sort", "fields"];
2023
2126
  function validateCountResultPayload(decoded) {
2024
2127
  if (!isRecord3(decoded)) {
2025
2128
  throwInvalid(CONFIG_INVALID, "Invalid CountResultPayload: expected an object");
@@ -2041,6 +2144,7 @@ function validateCountResultPayload(decoded) {
2041
2144
  CONFIG_INVALID
2042
2145
  );
2043
2146
  for (const figure2 of STORED_SIZE_FIELDS) {
2147
+ dropNilMember(entry, figure2);
2044
2148
  if (entry[figure2] === void 0) continue;
2045
2149
  validateNonNegativeInteger(entry[figure2], `partitions[${i}].${figure2}`, MAX_COUNT_VALUE, CONFIG_INVALID);
2046
2150
  }
@@ -2064,6 +2168,7 @@ function validateListSort(value) {
2064
2168
  throwInvalid(CONFIG_INVALID, `Invalid ListPayload: "sort[${i}]" must be an object`);
2065
2169
  }
2066
2170
  validateFieldName(entry.field, `sort[${i}].field`, SEARCH_INVALID_FIELD);
2171
+ dropNilMember(entry, "mode");
2067
2172
  if (entry.direction !== "asc" && entry.direction !== "desc") {
2068
2173
  throwInvalid(SEARCH_INVALID_MODE, `Invalid ListPayload: "sort[${i}].direction" must be "asc" or "desc"`);
2069
2174
  }
@@ -2081,6 +2186,7 @@ function validateListPayload(decoded) {
2081
2186
  }
2082
2187
  validateIndexNameField3(decoded, "ListPayload");
2083
2188
  validatePartitionIdsArray(decoded.partitionIds, "partitionIds", CONFIG_INVALID);
2189
+ restoreMissingAsNil(decoded, LIST_OPTIONAL_MEMBERS);
2084
2190
  if (decoded.cursor !== null) {
2085
2191
  validateStringField(decoded.cursor, "cursor", MAX_LIST_CURSOR_LENGTH, CONFIG_INVALID);
2086
2192
  }
@@ -2139,6 +2245,7 @@ function validateListResultPayload(decoded) {
2139
2245
  if (!isRecord3(entry.document)) {
2140
2246
  throwInvalid(CONFIG_INVALID, `Invalid ListResultPayload: "entries[${i}].document" must be an object`);
2141
2247
  }
2248
+ entry.sortValues ??= null;
2142
2249
  if (entry.sortValues !== null) {
2143
2250
  validateSortValues(entry.sortValues, `entries[${i}].sortValues`);
2144
2251
  }
@@ -3890,7 +3997,8 @@ function validatePartitionStoresResultPayload(decoded) {
3890
3997
  if (typeof decoded.indexName !== "string" || decoded.indexName.length === 0) {
3891
3998
  return null;
3892
3999
  }
3893
- if (decoded.indexUuid !== null && typeof decoded.indexUuid !== "string") {
4000
+ const indexUuid = decoded.indexUuid ?? null;
4001
+ if (indexUuid !== null && typeof indexUuid !== "string") {
3894
4002
  return null;
3895
4003
  }
3896
4004
  if (!Array.isArray(decoded.partitionIds)) {
@@ -3903,7 +4011,7 @@ function validatePartitionStoresResultPayload(decoded) {
3903
4011
  }
3904
4012
  partitionIds.push(partitionId);
3905
4013
  }
3906
- return { indexName: decoded.indexName, indexUuid: decoded.indexUuid, partitionIds };
4014
+ return { indexName: decoded.indexName, indexUuid, partitionIds };
3907
4015
  }
3908
4016
  function createPartitionStoresMessage(payload, sourceNodeId, requestId) {
3909
4017
  return {
@@ -5203,6 +5311,24 @@ async function compensateRemove(scope, documentId, previousDocument, originalErr
5203
5311
  }
5204
5312
  }
5205
5313
 
5314
+ // src/distribution/cluster-node/write-routing/forwarded-document.ts
5315
+ function decodeForwardedDocument(bytes, documentId) {
5316
+ let decoded;
5317
+ try {
5318
+ decoded = decode(bytes);
5319
+ } catch (err) {
5320
+ throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Forwarded document could not be decoded: ${String(err)}`, {
5321
+ documentId
5322
+ });
5323
+ }
5324
+ if (!isRecord(decoded)) {
5325
+ throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "A forwarded document must be a MessagePack map", {
5326
+ documentId
5327
+ });
5328
+ }
5329
+ return decoded;
5330
+ }
5331
+
5206
5332
  // src/distribution/cluster-node/reshard/state.ts
5207
5333
  function createReshardState() {
5208
5334
  return {
@@ -5326,13 +5452,13 @@ function isRecord5(value) {
5326
5452
  function requireCount(record, field, payloadName) {
5327
5453
  const value = record[field];
5328
5454
  if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
5329
- throw new Error(`Invalid ${payloadName}: "${field}" must be a non-negative integer`);
5455
+ throw invalidReplicationPayload(`Invalid ${payloadName}: "${field}" must be a non-negative integer`);
5330
5456
  }
5331
5457
  return value;
5332
5458
  }
5333
5459
  function requireIndexName(record, payloadName) {
5334
5460
  if (typeof record.indexName !== "string" || record.indexName.length === 0) {
5335
- throw new Error(`Invalid ${payloadName}: "indexName" must be a non-empty string`);
5461
+ throw invalidReplicationPayload(`Invalid ${payloadName}: "indexName" must be a non-empty string`);
5336
5462
  }
5337
5463
  return record.indexName;
5338
5464
  }
@@ -5353,9 +5479,9 @@ function createTermStartAckMessage(payload, sourceId, requestId) {
5353
5479
  };
5354
5480
  }
5355
5481
  function validateTermStartPayload(payload) {
5356
- const decoded = decode(payload);
5482
+ const decoded = decodeRequestPayload(payload, ReplicationMessageTypes.TERM_START);
5357
5483
  if (!isRecord5(decoded)) {
5358
- throw new Error("Invalid TermStartPayload: expected an object");
5484
+ throw invalidReplicationPayload("Invalid TermStartPayload: expected an object");
5359
5485
  }
5360
5486
  const validated = {
5361
5487
  indexName: requireIndexName(decoded, "TermStartPayload"),
@@ -6378,9 +6504,9 @@ async function applyAdmittedForwardedWrite(payload, deps) {
6378
6504
  }
6379
6505
  if (payload.operation === "insert") {
6380
6506
  if (payload.document === null) {
6381
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Invalid ForwardPayload: insert requires a document");
6507
+ throw new NarsilError(ErrorCodes.REPLICATION_ENTRY_INVALID, "Invalid ForwardPayload: insert requires a document");
6382
6508
  }
6383
- const document = decode(payload.document);
6509
+ const document = decodeForwardedDocument(payload.document, payload.documentId);
6384
6510
  return applyPrimaryInsert(
6385
6511
  payload.indexName,
6386
6512
  document,
@@ -6421,11 +6547,11 @@ async function applyAdmittedForwardedWrite(payload, deps) {
6421
6547
  }
6422
6548
  async function resolveForwardedUpdateDocument(indexName, documentId, document, updateFields, deps) {
6423
6549
  if (document !== null) {
6424
- return decode(document);
6550
+ return decodeForwardedDocument(document, documentId);
6425
6551
  }
6426
6552
  if (updateFields === null) {
6427
6553
  throw new NarsilError(
6428
- ErrorCodes.CONFIG_INVALID,
6554
+ ErrorCodes.REPLICATION_ENTRY_INVALID,
6429
6555
  "Invalid ForwardPayload: update requires a document or updateFields"
6430
6556
  );
6431
6557
  }
@@ -6979,21 +7105,17 @@ function decodeOperationDocument(wire, results, index) {
6979
7105
  if (wire.document === null) {
6980
7106
  results[index] = failureResult(
6981
7107
  wire.documentId,
6982
- new NarsilError(ErrorCodes.CONFIG_INVALID, "A forwarded insert requires a document", {
7108
+ new NarsilError(ErrorCodes.REPLICATION_ENTRY_INVALID, "A forwarded insert requires a document", {
6983
7109
  documentId: wire.documentId
6984
7110
  })
6985
7111
  );
6986
7112
  return null;
6987
7113
  }
6988
7114
  try {
6989
- return decode(wire.document);
7115
+ return decodeForwardedDocument(wire.document, wire.documentId);
6990
7116
  } catch (err) {
6991
- results[index] = failureResult(
6992
- wire.documentId,
6993
- new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Forwarded document could not be decoded: ${String(err)}`, {
6994
- documentId: wire.documentId
6995
- })
6996
- );
7117
+ const error = err instanceof NarsilError ? err : new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, String(err));
7118
+ results[index] = failureResult(wire.documentId, error);
6997
7119
  return null;
6998
7120
  }
6999
7121
  }
@@ -7489,17 +7611,6 @@ function readPartitionResult(value, backupName, partitionId, partitionCount) {
7489
7611
  throw unreadableResult(backupName, partitionId);
7490
7612
  }
7491
7613
  }
7492
- function sameConfigOf(results, indexName) {
7493
- const [first] = results;
7494
- if (first === void 0 || results.some((result) => result.config.sha256 !== first.config.sha256)) {
7495
- throw new NarsilError(
7496
- ErrorCodes.ANALYSIS_CHANGE_NOT_READY,
7497
- `The settings of index '${indexName}' changed while its partitions were backed up, so the backup stores no manifest`,
7498
- { indexName }
7499
- );
7500
- }
7501
- return first.config;
7502
- }
7503
7614
  async function backUpEveryPartition(context, generation, partitionCount) {
7504
7615
  const { jobId, job } = context;
7505
7616
  const results = new Array(partitionCount);
@@ -7540,7 +7651,7 @@ async function runBackupCreation(context, request) {
7540
7651
  const partitions = results.map((result) => result.partition);
7541
7652
  const config = await configWithSuggestionState(
7542
7653
  context,
7543
- sameConfigOf(results, indexName),
7654
+ await agreedConfigOf(store, results, indexName, job.backupName),
7544
7655
  suggestionStateOfSettings(named)
7545
7656
  );
7546
7657
  const queryHistory = request.queryHistory ? await backUpQueryHistory(context, indexName) : void 0;
@@ -7852,12 +7963,7 @@ function malformed3(kind, reason) {
7852
7963
  });
7853
7964
  }
7854
7965
  function decodeRequest(kind, message) {
7855
- let decoded;
7856
- try {
7857
- decoded = decode(message.payload);
7858
- } catch (_) {
7859
- throw malformed3(kind, "the payload is not MessagePack");
7860
- }
7966
+ const decoded = decodeRequestPayload(message.payload, message.type);
7861
7967
  if (!isRecord(decoded)) throw malformed3(kind, "expected an object");
7862
7968
  return decoded;
7863
7969
  }
@@ -7913,14 +8019,14 @@ async function startJob(deps, store, job, run, afterJob) {
7913
8019
  return { jobId, ended };
7914
8020
  }
7915
8021
  function takenByOf(request) {
7916
- if (request.takenBy === void 0) return void 0;
8022
+ if (request.takenBy === void 0 || request.takenBy === null) return void 0;
7917
8023
  if (!isBackupTaker(request.takenBy)) {
7918
8024
  throw malformed3("backup", `"takenBy" must be "${SYNC_BACKUP_TAKER}" or "${CHANGES_BACKUP_TAKER}"`);
7919
8025
  }
7920
8026
  return request.takenBy;
7921
8027
  }
7922
8028
  function queryHistoryOf(request) {
7923
- if (request.queryHistory === void 0) return false;
8029
+ if (request.queryHistory === void 0 || request.queryHistory === null) return false;
7924
8030
  if (typeof request.queryHistory !== "boolean") throw malformed3("backup", '"queryHistory" must be a boolean');
7925
8031
  return request.queryHistory;
7926
8032
  }
@@ -8297,12 +8403,7 @@ function invalid(what) {
8297
8403
  return new NarsilError(ErrorCodes.CONFIG_INVALID, `Invalid backup partition message: ${what}`);
8298
8404
  }
8299
8405
  function readPayload(message) {
8300
- let decoded;
8301
- try {
8302
- decoded = decode(message.payload);
8303
- } catch (_) {
8304
- decoded = null;
8305
- }
8406
+ const decoded = decodeRequestPayload(message.payload, message.type);
8306
8407
  if (!isRecord(decoded)) throw invalid("expected an object");
8307
8408
  const { jobId, indexName, partitionId } = decoded;
8308
8409
  if (typeof jobId !== "string" || jobId.length === 0) throw invalid('"jobId" must be a non-empty string');
@@ -11033,6 +11134,27 @@ function scheduleStandbyRetry(state, retryMs, onRetry) {
11033
11134
  onRetry();
11034
11135
  }, retryMs);
11035
11136
  }
11137
+ function readPingTimestamp(payload) {
11138
+ const decoded = decodeRequestPayload(payload, ClusterMessageTypes.PING);
11139
+ if (!isRecord(decoded) || !isValidInteger(decoded.timestamp) || decoded.timestamp < 0) {
11140
+ throw new NarsilError(
11141
+ ErrorCodes.CONFIG_INVALID,
11142
+ "Invalid PingPayload: it needs a timestamp that is a non-negative integer"
11143
+ );
11144
+ }
11145
+ return decoded.timestamp;
11146
+ }
11147
+ function pongReply(message) {
11148
+ try {
11149
+ const pong = { timestamp: readPingTimestamp(message.payload), respondedAt: Date.now() };
11150
+ return { type: ClusterMessageTypes.PONG, payload: encode(pong) };
11151
+ } catch (error) {
11152
+ return { type: `${message.type}.error`, payload: encodeErrorReplyFrom(error, ErrorCodes.CONFIG_INVALID) };
11153
+ }
11154
+ }
11155
+ function answerPing(message, respond, nodeId) {
11156
+ return respond({ ...pongReply(message), sourceId: nodeId, requestId: message.requestId });
11157
+ }
11036
11158
 
11037
11159
  // src/distribution/cluster/allocator/deciders/balance.ts
11038
11160
  var balanceDecider = {
@@ -12868,34 +12990,32 @@ async function sendRejection(respond, controllerNodeId, requestId, indexName, pa
12868
12990
  };
12869
12991
  await respond(response);
12870
12992
  }
12871
- async function rejectBootstrapComplete(message, respond, controllerNodeId) {
12872
- let decoded;
12993
+ async function readBootstrapCompleteOrRefuse(message, respond, controllerNodeId) {
12873
12994
  try {
12874
- decoded = decode(message.payload);
12875
- } catch (_) {
12876
- await sendRejection(respond, controllerNodeId, message.requestId, "", -1);
12877
- return;
12878
- }
12879
- const payload = validateBootstrapCompletePayload(decoded);
12880
- if (payload === null) {
12881
- await sendRejection(respond, controllerNodeId, message.requestId, "", -1);
12882
- return;
12995
+ const payload = validateBootstrapCompletePayload(decodeRequestPayload(message.payload, message.type));
12996
+ if (payload !== null) return payload;
12997
+ throw new NarsilError(
12998
+ ErrorCodes.CONFIG_INVALID,
12999
+ "Invalid BootstrapCompletePayload: it needs an indexName, a partitionId, a nodeId, and a primaryTerm"
13000
+ );
13001
+ } catch (error) {
13002
+ await respond({
13003
+ type: `${message.type}.error`,
13004
+ sourceId: controllerNodeId,
13005
+ requestId: message.requestId,
13006
+ payload: encodeRebalanceRefusal(error)
13007
+ });
13008
+ return null;
12883
13009
  }
13010
+ }
13011
+ async function rejectBootstrapComplete(message, respond, controllerNodeId) {
13012
+ const payload = await readBootstrapCompleteOrRefuse(message, respond, controllerNodeId);
13013
+ if (payload === null) return;
12884
13014
  await sendRejection(respond, controllerNodeId, message.requestId, payload.indexName, payload.partitionId);
12885
13015
  }
12886
13016
  async function handleBootstrapCompleteMessage(message, respond, coordinator, controllerNodeId) {
12887
- let decoded;
12888
- try {
12889
- decoded = decode(message.payload);
12890
- } catch (_) {
12891
- await sendRejection(respond, controllerNodeId, message.requestId, "", -1);
12892
- return;
12893
- }
12894
- const payload = validateBootstrapCompletePayload(decoded);
12895
- if (payload === null) {
12896
- await sendRejection(respond, controllerNodeId, message.requestId, "", -1);
12897
- return;
12898
- }
13017
+ const payload = await readBootstrapCompleteOrRefuse(message, respond, controllerNodeId);
13018
+ if (payload === null) return;
12899
13019
  if (message.sourceId !== payload.nodeId) {
12900
13020
  await sendRejection(respond, controllerNodeId, message.requestId, payload.indexName, payload.partitionId);
12901
13021
  return;
@@ -12959,7 +13079,6 @@ async function processBootstrapComplete(payload, coordinator, controllerNodeId)
12959
13079
  }
12960
13080
 
12961
13081
  // src/distribution/cluster/controller/event-loop/insync-messages.ts
12962
- var UNKNOWN_PARTITION_ID = -1;
12963
13082
  function validateInsyncRemovePayload(decoded) {
12964
13083
  if (!isRecord(decoded)) {
12965
13084
  return null;
@@ -13008,22 +13127,25 @@ function validateInsyncAddPayload(decoded) {
13008
13127
  replicaStartedAt: decoded.replicaStartedAt
13009
13128
  };
13010
13129
  }
13011
- function decodeMessage(message) {
13130
+ function readRequestOrRefuse(message, respond, nodeId, validate, payloadName) {
13012
13131
  try {
13013
- return decode(message.payload);
13014
- } catch (_) {
13132
+ const payload = validate(decodeRequestPayload(message.payload, message.type));
13133
+ if (payload !== null) return payload;
13134
+ throw new NarsilError(
13135
+ ErrorCodes.CONFIG_INVALID,
13136
+ `Invalid ${payloadName}: a member is missing or holds a value of the wrong type`
13137
+ );
13138
+ } catch (error) {
13139
+ respond({
13140
+ type: `${message.type}.error`,
13141
+ sourceId: nodeId,
13142
+ requestId: message.requestId,
13143
+ payload: encodeRebalanceRefusal(error)
13144
+ }).catch(() => {
13145
+ });
13015
13146
  return null;
13016
13147
  }
13017
13148
  }
13018
- function describeRequest(decoded) {
13019
- if (!isRecord(decoded)) {
13020
- return { indexName: "", partitionId: UNKNOWN_PARTITION_ID };
13021
- }
13022
- return {
13023
- indexName: typeof decoded.indexName === "string" ? decoded.indexName : "",
13024
- partitionId: isValidInteger(decoded.partitionId) ? decoded.partitionId : UNKNOWN_PARTITION_ID
13025
- };
13026
- }
13027
13149
  async function assertSenderLeadsPartition(coordinator, indexName, partitionId, sourceId) {
13028
13150
  const table = await coordinator.getAllocation(indexName);
13029
13151
  const assignment = table?.assignments.get(partitionId);
@@ -13055,12 +13177,8 @@ async function respondRefusal(respond, request, nodeId, requestId) {
13055
13177
  }
13056
13178
  }
13057
13179
  function handleInsyncRemoveMessage(state, message, respond, coordinator, nodeId, isActive) {
13058
- const decoded = decodeMessage(message);
13059
- const payload = validateInsyncRemovePayload(decoded);
13060
- if (payload === null) {
13061
- void respondRefusal(respond, describeRequest(decoded), nodeId, message.requestId);
13062
- return;
13063
- }
13180
+ const payload = readRequestOrRefuse(message, respond, nodeId, validateInsyncRemovePayload, "InsyncRemovePayload");
13181
+ if (payload === null) return;
13064
13182
  enqueue(state, async () => {
13065
13183
  const mayRemove = await assertSenderMayRemove(coordinator, payload, message.sourceId);
13066
13184
  if (!mayRemove || !isActive()) {
@@ -13072,12 +13190,8 @@ function handleInsyncRemoveMessage(state, message, respond, coordinator, nodeId,
13072
13190
  });
13073
13191
  }
13074
13192
  function handleInsyncAddMessage(state, message, respond, coordinator, nodeId, isActive, onError) {
13075
- const decoded = decodeMessage(message);
13076
- const payload = validateInsyncAddPayload(decoded);
13077
- if (payload === null) {
13078
- void respondRefusal(respond, describeRequest(decoded), nodeId, message.requestId);
13079
- return;
13080
- }
13193
+ const payload = readRequestOrRefuse(message, respond, nodeId, validateInsyncAddPayload, "InsyncAddPayload");
13194
+ if (payload === null) return;
13081
13195
  enqueue(state, async () => {
13082
13196
  const leadsPartition = await assertSenderLeadsPartition(
13083
13197
  coordinator,
@@ -13146,12 +13260,8 @@ async function resign(payload, sourceId, coordinator, controllerNodeId) {
13146
13260
  return false;
13147
13261
  }
13148
13262
  function handlePrimaryResignMessage(state, message, respond, coordinator, nodeId, isActive, onError) {
13149
- const decoded = decodeMessage(message);
13150
- const payload = validatePrimaryResignPayload(decoded);
13151
- if (payload === null) {
13152
- void respondRefusal(respond, describeRequest(decoded), nodeId, message.requestId);
13153
- return;
13154
- }
13263
+ const payload = readRequestOrRefuse(message, respond, nodeId, validatePrimaryResignPayload, "PrimaryResignPayload");
13264
+ if (payload === null) return;
13155
13265
  enqueue(state, async () => {
13156
13266
  const accepted = isActive() && await resign(payload, message.sourceId, coordinator, nodeId);
13157
13267
  const confirm = { indexName: payload.indexName, partitionId: payload.partitionId, accepted };
@@ -13576,12 +13686,7 @@ function startRebalanceDriver(ctx, indexName, jobId) {
13576
13686
 
13577
13687
  // src/distribution/cluster/controller/event-loop/rebalance/request.ts
13578
13688
  function readPayload2(message) {
13579
- let decoded;
13580
- try {
13581
- decoded = decode(message.payload);
13582
- } catch (_) {
13583
- decoded = null;
13584
- }
13689
+ const decoded = decodeRequestPayload(message.payload, message.type);
13585
13690
  if (!isRecord(decoded) || typeof decoded.indexName !== "string" || decoded.indexName.length === 0) {
13586
13691
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "A partition count change must name an index", {});
13587
13692
  }
@@ -13697,12 +13802,7 @@ function encodeRefusal(error) {
13697
13802
  }
13698
13803
  }
13699
13804
  function readPayload3(message) {
13700
- let decoded;
13701
- try {
13702
- decoded = decode(message.payload);
13703
- } catch (_) {
13704
- decoded = null;
13705
- }
13805
+ const decoded = decodeRequestPayload(message.payload, message.type);
13706
13806
  if (!isRecord(decoded) || typeof decoded.indexName !== "string") {
13707
13807
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "A replication factor request must name an index", {});
13708
13808
  }
@@ -13780,6 +13880,11 @@ async function startEventLoop(state, coordinator, transport, nodeId, isActive, o
13780
13880
  }
13781
13881
  });
13782
13882
  state.unwatchTransport = await transport.listen((message, respond) => {
13883
+ if (message.type === ClusterMessageTypes.PING) {
13884
+ answerPing(message, respond, nodeId).catch(() => {
13885
+ });
13886
+ return;
13887
+ }
13783
13888
  if (message.type === ClusterMessageTypes.REPLICATION_FACTOR) {
13784
13889
  handleReplicationFactorMessage(state, message, respond, coordinator, nodeId, isActive, onError);
13785
13890
  return;
@@ -14629,7 +14734,7 @@ async function answerSyncRead(deps, request) {
14629
14734
  return { frames: read.frames, head, highestSeqNo, oldestSeqNo, bytesBehind };
14630
14735
  }
14631
14736
  async function handleSyncRead(message, respond, deps) {
14632
- const request = validateSyncReadRequest(decode(message.payload));
14737
+ const request = validateSyncReadRequest(decodeRequestPayload(message.payload, message.type));
14633
14738
  if (request === null) {
14634
14739
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "A sync.read request is malformed", {
14635
14740
  sourceNodeId: message.sourceId
@@ -16054,7 +16159,7 @@ async function openOnce(core, indexName, partitionId) {
16054
16159
  if (directory === void 0) throw durabilityRequired(indexName, partitionId);
16055
16160
  if ((checkpoint.manifest.analysisGeneration ?? 0) !== entry.analysisGeneration) return null;
16056
16161
  const config = await encodeIndexConfiguration(entry);
16057
- const { openPagedPartitionArchive } = await import('./paged-partition-archive-NITVFYOC.mjs');
16162
+ const { openPagedPartitionArchive } = await import('./paged-partition-archive-EABR3N3F.mjs');
16058
16163
  const archive = await openPagedPartitionArchive(checkpoint, directory, indexName, partitionId, manager);
16059
16164
  handedOver = true;
16060
16165
  try {
@@ -16769,7 +16874,7 @@ async function archiveReplicationPartition(core, indexName, partitionId, lastSeq
16769
16874
  );
16770
16875
  }
16771
16876
  try {
16772
- const { openPagedPartitionArchive } = await import('./paged-partition-archive-NITVFYOC.mjs');
16877
+ const { openPagedPartitionArchive } = await import('./paged-partition-archive-EABR3N3F.mjs');
16773
16878
  const archive = await openPagedPartitionArchive(checkpoint2, directory, indexName, partitionId, manager);
16774
16879
  return {
16775
16880
  stream: archiveStream({ ...archive, config, sourceIndexName: indexName }),
@@ -16984,7 +17089,7 @@ async function restoreReplicationPartition(core, engine, indexName, partitionId,
16984
17089
  if (directory !== null) {
16985
17090
  const durable = core.durability?.manager;
16986
17091
  await (durable?.checkpointFromMemory?.(indexName) ?? durable?.checkpoint(indexName));
16987
- const { removeReceivedFilesNothingReads } = await import('./paged-partition-archive-NITVFYOC.mjs');
17092
+ const { removeReceivedFilesNothingReads } = await import('./paged-partition-archive-EABR3N3F.mjs');
16988
17093
  await removeReceivedFilesNothingReads(
16989
17094
  directory,
16990
17095
  core.requireManager(indexName),
@@ -20556,6 +20661,44 @@ function readSortValues(document, fields, modes) {
20556
20661
  return fields.map((field, index) => reduceSortValue(readSortField(document, field), modes[index] ?? "min"));
20557
20662
  }
20558
20663
 
20664
+ // src/distribution/cluster-node/reads/local-list-page.ts
20665
+ function toWireSortValue(value) {
20666
+ if (typeof value === "string") return value;
20667
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
20668
+ if (typeof value === "boolean") return value;
20669
+ return null;
20670
+ }
20671
+ function fieldsToList(fields, sortFieldNames) {
20672
+ if (fields === null || fields.length === 0 || sortFieldNames === null) return fields;
20673
+ const listed = new Set(fields);
20674
+ for (const sortField of sortFieldNames) listed.add(sortField);
20675
+ return listed.size === fields.length ? fields : Array.from(listed);
20676
+ }
20677
+ async function listLocalPage(engine, payload) {
20678
+ const normalizedSort = payload.sort === null ? null : normalizeSort(payload.sort);
20679
+ const sortFieldNames = normalizedSort === null ? null : normalizedSort.map((entry) => entry.field);
20680
+ const sortModes = normalizedSort === null ? [] : sortModesOf(normalizedSort);
20681
+ const listedFields = fieldsToList(payload.fields, sortFieldNames);
20682
+ const answerProjection = listedFields === payload.fields || payload.fields === null ? null : resolveProjection({ include: payload.fields });
20683
+ const listParams = {
20684
+ cursor: payload.cursor ?? void 0,
20685
+ limit: payload.limit,
20686
+ filters: payload.filters ?? void 0,
20687
+ sort: payload.sort ?? void 0,
20688
+ document: listedFields === null ? void 0 : { include: listedFields }
20689
+ };
20690
+ const result = await engine.listPartitions(payload.indexName, listParams, payload.partitionIds);
20691
+ const entries = result.documents.map((listed) => {
20692
+ const stored = listed.document;
20693
+ return {
20694
+ docId: listed.id,
20695
+ document: answerProjection === null || stored === void 0 ? stored : applyProjection(stored, answerProjection),
20696
+ sortValues: sortFieldNames === null ? null : readSortValues(stored, sortFieldNames, sortModes).map(toWireSortValue)
20697
+ };
20698
+ });
20699
+ return { entries, total: result.total, hasMore: result.cursor !== null };
20700
+ }
20701
+
20559
20702
  // src/distribution/cluster-node/reads/list.ts
20560
20703
  function clampListLimit(limit) {
20561
20704
  const clamped = Math.max(1, clampLimit(limit));
@@ -20575,28 +20718,6 @@ function wireFieldsFor(projection, sortFieldNames) {
20575
20718
  }
20576
20719
  return Array.from(fields);
20577
20720
  }
20578
- function toWireSortValue(value) {
20579
- if (typeof value === "string") return value;
20580
- if (typeof value === "number") return Number.isFinite(value) ? value : null;
20581
- if (typeof value === "boolean") return value;
20582
- return null;
20583
- }
20584
- async function gatherLocalPage(deps, indexName, payload, partitionIds, sortFieldNames, sortModes) {
20585
- const listParams = {
20586
- cursor: payload.cursor ?? void 0,
20587
- limit: payload.limit,
20588
- filters: payload.filters ?? void 0,
20589
- sort: payload.sort ?? void 0,
20590
- document: payload.fields === null ? void 0 : { include: payload.fields }
20591
- };
20592
- const result = await deps.engine.listPartitions(indexName, listParams, partitionIds);
20593
- const entries = result.documents.map((listed) => ({
20594
- docId: listed.id,
20595
- document: listed.document,
20596
- sortValues: sortFieldNames === null ? null : readSortValues(listed.document, sortFieldNames, sortModes).map(toWireSortValue)
20597
- }));
20598
- return { entries, total: result.total, hasMore: result.cursor !== null };
20599
- }
20600
20721
  async function listCluster(deps, indexName, params) {
20601
20722
  const allocation = await routableAllocation(deps.config.coordinator, indexName);
20602
20723
  if (allocation === null) {
@@ -20625,14 +20746,7 @@ async function listCluster(deps, indexName, params) {
20625
20746
  };
20626
20747
  const gathered = await gatherFromEveryPartition(allocation, indexName, (group) => {
20627
20748
  if (group.nodeId === deps.nodeId) {
20628
- return gatherLocalPage(
20629
- deps,
20630
- indexName,
20631
- { ...payload, partitionIds: group.partitionIds },
20632
- group.partitionIds,
20633
- sortFieldNames,
20634
- sortModesOf(normalizedSort)
20635
- );
20749
+ return listLocalPage(deps.engine, { ...payload, partitionIds: group.partitionIds });
20636
20750
  }
20637
20751
  const message = createListMessage({ ...payload, partitionIds: group.partitionIds }, deps.nodeId);
20638
20752
  return sendReadRequest(deps, group.nodeId, message, indexName, validateListResultPayload, true);
@@ -20840,7 +20954,7 @@ async function queryCluster(deps, indexName, params, settingName) {
20840
20954
  (reader) => searchCluster(deps, indexName, settingName, params, allocation, reader, false)
20841
20955
  );
20842
20956
  }
20843
- const { rerankClusterQuery } = await import('./rerank-X4HOST2N.mjs');
20957
+ const { rerankClusterQuery } = await import('./rerank-LCMA5PZG.mjs');
20844
20958
  return withRankedReader(
20845
20959
  deps,
20846
20960
  indexName,
@@ -21044,14 +21158,20 @@ function describeLocalCopy(deps, indexName) {
21044
21158
  return { indexName, indexUuid, partitionIds };
21045
21159
  }
21046
21160
  async function handlePartitionStores(message, respond, deps) {
21047
- const payload = validatePartitionStoresPayload(decode(message.payload));
21048
- const result = payload === null ? { indexName: "", indexUuid: null, partitionIds: [] } : describeLocalCopy(deps, payload.indexName);
21161
+ const payload = validatePartitionStoresPayload(decodeRequestPayload(message.payload, message.type));
21162
+ if (payload === null) {
21163
+ throw new NarsilError(
21164
+ ErrorCodes.CONFIG_INVALID,
21165
+ "Invalid PartitionStoresPayload: it needs an indexName that is a non-empty string"
21166
+ );
21167
+ }
21168
+ const result = describeLocalCopy(deps, payload.indexName);
21049
21169
  await respond(createPartitionStoresResultMessage(result, deps.nodeId, message.requestId));
21050
21170
  }
21051
21171
 
21052
21172
  // src/distribution/cluster-node/rebuild-analysis.ts
21053
21173
  function validateRebuildPayload(decoded) {
21054
- if (!isRecord(decoded) || typeof decoded.indexName !== "string" || decoded.indexName.length === 0 || typeof decoded.indexUuid !== "string" || decoded.indexUuid.length === 0 || decoded.generation !== void 0 && (!Number.isSafeInteger(decoded.generation) || Number(decoded.generation) < 1)) {
21174
+ if (!isRecord(decoded) || typeof decoded.indexName !== "string" || decoded.indexName.length === 0 || typeof decoded.indexUuid !== "string" || decoded.indexUuid.length === 0 || decoded.generation !== void 0 && decoded.generation !== null && (!Number.isSafeInteger(decoded.generation) || Number(decoded.generation) < 1)) {
21055
21175
  throw new NarsilError(
21056
21176
  ErrorCodes.CONFIG_INVALID,
21057
21177
  "Invalid RebuildAnalysisPayload: it needs an indexName, an indexUuid, and a generation of 1 or more where it carries one"
@@ -21111,7 +21231,7 @@ async function rebuildLocalCopies(engine, payload) {
21111
21231
  return { indexName, rebuiltPartitions: heldPartitionIdsOf(engine, indexName) };
21112
21232
  }
21113
21233
  async function handleRebuildAnalysis(message, respond, deps) {
21114
- const payload = validateRebuildPayload(decode(message.payload));
21234
+ const payload = validateRebuildPayload(decodeRequestPayload(message.payload, message.type));
21115
21235
  const result = payload.generation === void 0 ? await rebuildLocalCopies(deps.engine, payload) : await buildHeldCopies(deps.engine, deps.coordinator, payload, payload.generation);
21116
21236
  await respond({
21117
21237
  type: ClusterMessageTypes.REBUILD_ANALYSIS,
@@ -22471,12 +22591,7 @@ function invalid2(what) {
22471
22591
  return new NarsilError(ErrorCodes.CONFIG_INVALID, `Invalid partition copy message: ${what}`);
22472
22592
  }
22473
22593
  function decodedRecord(message) {
22474
- let decoded;
22475
- try {
22476
- decoded = decode(message.payload);
22477
- } catch (_) {
22478
- decoded = null;
22479
- }
22594
+ const decoded = decodeRequestPayload(message.payload, message.type);
22480
22595
  if (!isRecord(decoded)) throw invalid2("expected an object");
22481
22596
  return decoded;
22482
22597
  }
@@ -22575,14 +22690,20 @@ async function handleReshardPurge(message, respond, deps) {
22575
22690
 
22576
22691
  // src/distribution/cluster-node/message-handler/index-settings.ts
22577
22692
  async function handleIndexSettings(message, respond, deps) {
22578
- const payload = validateIndexSettingsPayload(decode(message.payload));
22579
- const applied = payload !== null && await applyStoredSynonyms(deps.engine, deps.coordinator, payload.indexName, payload.indexUuid);
22580
- const indexName = payload?.indexName ?? "";
22581
- await respond(createIndexSettingsResultMessage({ indexName, applied }, deps.nodeId, message.requestId));
22693
+ const payload = validateIndexSettingsPayload(decodeRequestPayload(message.payload, message.type));
22694
+ if (payload === null) {
22695
+ throw new NarsilError(
22696
+ ErrorCodes.CONFIG_INVALID,
22697
+ "Invalid IndexSettingsPayload: it needs an indexName and an indexUuid that are non-empty strings"
22698
+ );
22699
+ }
22700
+ const applied = await applyStoredSynonyms(deps.engine, deps.coordinator, payload.indexName, payload.indexUuid);
22701
+ await respond(
22702
+ createIndexSettingsResultMessage({ indexName: payload.indexName, applied }, deps.nodeId, message.requestId)
22703
+ );
22582
22704
  }
22583
22705
  async function handleSearch(message, respond, deps) {
22584
- const decoded = decode(message.payload);
22585
- const payload = validateSearchPayload(decoded);
22706
+ const payload = validateSearchPayload(decodeRequestPayload(message.payload, message.type));
22586
22707
  const queryParams = wireParamsToLocal(payload.params, payload.facetShardSize);
22587
22708
  if (queryParams.group?.limit !== void 0) {
22588
22709
  queryParams.group = { ...queryParams.group, limit: oversampledShardSize(queryParams.group.limit) };
@@ -22662,8 +22783,7 @@ async function convertLocalGroupsToWire(groups, sortFields, sortModes, deps, ind
22662
22783
  return wireGroups;
22663
22784
  }
22664
22785
  async function handleFetch(message, respond, deps) {
22665
- const decoded = decode(message.payload);
22666
- const payload = validateFetchPayload(decoded);
22786
+ const payload = validateFetchPayload(decodeRequestPayload(message.payload, message.type));
22667
22787
  const projection = resolveProjection(payload.fields === null ? void 0 : { include: payload.fields });
22668
22788
  const contextId = payload.contextId ?? null;
22669
22789
  const documents = contextId === null ? await readCurrentDocuments(deps, payload.indexName, payload.documentIds, projection) : readContextDocuments(deps, contextId, payload.documentIds, payload.releaseContext !== false, projection);
@@ -22721,8 +22841,7 @@ function openSearchContext(deps, coordinatorNodeId, keepAliveMs, snapshots) {
22721
22841
  return deps.searchContexts.open(coordinatorNodeId, keepAliveOf(keepAliveMs), snapshots);
22722
22842
  }
22723
22843
  async function handleStats(message, respond, deps) {
22724
- const decoded = decode(message.payload);
22725
- const payload = validateStatsPayload(decoded);
22844
+ const payload = validateStatsPayload(decodeRequestPayload(message.payload, message.type));
22726
22845
  const resultPayload = await deps.analysisView.answerAt(
22727
22846
  payload.indexName,
22728
22847
  payload.analysisGeneration ?? 0,
@@ -22767,39 +22886,18 @@ function convertLocalFacetsToWire2(facets) {
22767
22886
 
22768
22887
  // src/distribution/cluster-node/message-handler/read-handlers.ts
22769
22888
  async function handleCount(message, respond, deps) {
22770
- const payload = validateCountPayload(decode(message.payload));
22889
+ const payload = validateCountPayload(decodeRequestPayload(message.payload, message.type));
22771
22890
  const answer2 = await localCountAnswer(deps.engine, payload.indexName, payload.partitionIds);
22772
22891
  await respond(createCountResultMessage(answer2, deps.nodeId, message.requestId));
22773
22892
  }
22774
22893
  async function handleList(message, respond, deps) {
22775
- const payload = validateListPayload(decode(message.payload));
22776
- const listParams = {
22777
- cursor: payload.cursor ?? void 0,
22778
- limit: payload.limit,
22779
- filters: payload.filters ?? void 0,
22780
- sort: payload.sort ?? void 0,
22781
- document: payload.fields === null ? void 0 : { include: payload.fields }
22782
- };
22783
- const result = await deps.engine.listPartitions(payload.indexName, listParams, payload.partitionIds);
22784
- const normalizedSort = payload.sort === null ? null : normalizeSort(payload.sort);
22785
- const sortFields = normalizedSort === null ? null : normalizedSort.map((entry) => entry.field);
22786
- const sortModes = normalizedSort === null ? [] : sortModesOf(normalizedSort);
22787
- const entries = result.documents.map((listed) => ({
22788
- docId: listed.id,
22789
- document: listed.document,
22790
- sortValues: sortFields === null ? null : readSortValues(listed.document, sortFields, sortModes).map(toWireSortValue3)
22791
- }));
22792
- refuseEncodeWithoutRoom(entries.map((entry) => entry.document));
22793
- await respond(
22794
- createListResultMessage(
22795
- { entries, total: result.total, hasMore: result.cursor !== null },
22796
- deps.nodeId,
22797
- message.requestId
22798
- )
22799
- );
22894
+ const payload = validateListPayload(decodeRequestPayload(message.payload, message.type));
22895
+ const page = await listLocalPage(deps.engine, payload);
22896
+ refuseEncodeWithoutRoom(page.entries.map((entry) => entry.document));
22897
+ await respond(createListResultMessage(page, deps.nodeId, message.requestId));
22800
22898
  }
22801
22899
  async function handleSuggest(message, respond, deps) {
22802
- const payload = validateSuggestPayload(decode(message.payload));
22900
+ const payload = validateSuggestPayload(decodeRequestPayload(message.payload, message.type));
22803
22901
  const result = await deps.analysisView.answerAt(
22804
22902
  payload.indexName,
22805
22903
  payload.analysisGeneration ?? 0,
@@ -22818,7 +22916,7 @@ async function handleSuggest(message, respond, deps) {
22818
22916
  );
22819
22917
  }
22820
22918
  async function handlePreflight(message, respond, deps) {
22821
- const payload = validatePreflightPayload(decode(message.payload));
22919
+ const payload = validatePreflightPayload(decodeRequestPayload(message.payload, message.type));
22822
22920
  const params = wireParamsToLocal(payload.params);
22823
22921
  const result = await deps.analysisView.answerAt(
22824
22922
  payload.indexName,
@@ -22838,12 +22936,6 @@ async function handlePreflight(message, respond, deps) {
22838
22936
  )
22839
22937
  );
22840
22938
  }
22841
- function toWireSortValue3(value) {
22842
- if (typeof value === "string") return value;
22843
- if (typeof value === "number") return Number.isFinite(value) ? value : null;
22844
- if (typeof value === "boolean") return value;
22845
- return null;
22846
- }
22847
22939
 
22848
22940
  // src/distribution/replication/sync-primary.ts
22849
22941
  function decideSyncTier(log, replicaLastSeqNo, replicaLastPrimaryTerm) {
@@ -23390,17 +23482,26 @@ function currentSyncSessionOf(request, sourceNodeId, assignment, deps) {
23390
23482
  );
23391
23483
  }
23392
23484
  async function sendSyncEntriesResponse(message, respond, deps, entries, syncSession) {
23393
- const payload = {
23394
- entries,
23395
- isLast: true,
23396
- syncSession
23397
- };
23398
- await respond({
23399
- type: ReplicationMessageTypes.SYNC_ENTRIES,
23400
- sourceId: deps.nodeId,
23401
- requestId: message.requestId,
23402
- payload: encode(payload)
23485
+ const batches = chunkByBudget(entries, {
23486
+ ...WIRE_BATCH_BUDGET,
23487
+ payloadBytesOf: (entry) => (entry.document?.byteLength ?? 0) + (entry.previousDocument?.byteLength ?? 0)
23403
23488
  });
23489
+ if (batches.length === 0) {
23490
+ batches.push([]);
23491
+ }
23492
+ for (let index = 0; index < batches.length; index++) {
23493
+ const payload = {
23494
+ entries: batches[index],
23495
+ isLast: index === batches.length - 1,
23496
+ syncSession
23497
+ };
23498
+ await respond({
23499
+ type: ReplicationMessageTypes.SYNC_ENTRIES,
23500
+ sourceId: deps.nodeId,
23501
+ requestId: message.requestId,
23502
+ payload: encode(payload)
23503
+ });
23504
+ }
23404
23505
  }
23405
23506
 
23406
23507
  // src/distribution/cluster-node/message-handler/entry-authority.ts
@@ -23467,8 +23568,7 @@ async function resolveValidatedAssignment(entry, sourceNodeId, deps) {
23467
23568
  return live;
23468
23569
  }
23469
23570
  async function handleForward(message, respond, deps) {
23470
- const decoded = decode(message.payload);
23471
- const payload = validateForwardPayload(decoded);
23571
+ const payload = validateForwardPayload(decodeRequestPayload(message.payload, message.type));
23472
23572
  const heldIndexUuid = deps.engine.indexUuidOf(payload.indexName);
23473
23573
  if (typeof heldIndexUuid === "string" && holdsAnotherIndex(heldIndexUuid, payload.indexUuid)) {
23474
23574
  throw anotherIndexAsPrimary(payload.indexName, deps.nodeId, heldIndexUuid);
@@ -23482,7 +23582,7 @@ async function handleForward(message, respond, deps) {
23482
23582
  });
23483
23583
  }
23484
23584
  async function handleForwardBatch(message, respond, deps) {
23485
- const payload = validateForwardBatchPayload(decode(message.payload));
23585
+ const payload = validateForwardBatchPayload(decodeRequestPayload(message.payload, message.type));
23486
23586
  const heldIndexUuid = deps.engine.indexUuidOf(payload.indexName);
23487
23587
  if (typeof heldIndexUuid === "string" && holdsAnotherIndex(heldIndexUuid, payload.indexUuid)) {
23488
23588
  const refusal2 = anotherIndexAsPrimary(payload.indexName, deps.nodeId, heldIndexUuid);
@@ -23500,14 +23600,14 @@ async function handleForwardBatch(message, respond, deps) {
23500
23600
  await respond(createForwardBatchResultMessage({ results }, deps.nodeId, message.requestId));
23501
23601
  }
23502
23602
  async function handleReplicationEntry(message, respond, deps) {
23503
- const payload = validateEntryPayload(decode(message.payload));
23603
+ const payload = validateEntryPayload(decodeRequestPayload(message.payload, message.type));
23504
23604
  const { entry } = payload;
23505
23605
  refuseAnotherIndex(entry.indexName, payload.indexUuid, deps);
23506
23606
  await applyEntriesFromPrimary([entry], message.sourceId, deps, payload.previousPrimaryTerm);
23507
23607
  await respond(createAckMessage(entry.seqNo, entry.partitionId, entry.indexName, deps.nodeId, message.requestId));
23508
23608
  }
23509
23609
  async function handleReplicationEntryBatch(message, respond, deps) {
23510
- const payload = validateEntryBatchPayload(decode(message.payload));
23610
+ const payload = validateEntryBatchPayload(decodeRequestPayload(message.payload, message.type));
23511
23611
  const lastEntry = payload.entries[payload.entries.length - 1];
23512
23612
  refuseAnotherIndex(lastEntry.indexName, payload.indexUuid, deps);
23513
23613
  await applyEntriesFromPrimary(payload.entries, message.sourceId, deps, payload.previousPrimaryTerm);
@@ -23648,26 +23748,14 @@ async function applyRun2(run, log, deps) {
23648
23748
  if (applied < run.length) throw error;
23649
23749
  }
23650
23750
  function validateForwardPayload(decoded) {
23651
- if (decoded === null || typeof decoded !== "object" || Array.isArray(decoded)) {
23652
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Invalid ForwardPayload: expected an object");
23653
- }
23654
- const record = decoded;
23655
- if (typeof record.indexName !== "string" || record.indexName.length === 0) {
23656
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'Invalid ForwardPayload: "indexName" must be a non-empty string');
23657
- }
23658
- if (typeof record.documentId !== "string" || record.documentId.length === 0) {
23659
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'Invalid ForwardPayload: "documentId" must be a non-empty string');
23660
- }
23661
- if (record.operation !== "insert" && record.operation !== "remove" && record.operation !== "update") {
23662
- throw new NarsilError(
23663
- ErrorCodes.CONFIG_INVALID,
23664
- 'Invalid ForwardPayload: "operation" must be "insert", "remove", or "update"'
23665
- );
23751
+ if (!isRecord(decoded)) {
23752
+ throw invalidReplicationPayload("Invalid ForwardPayload: expected an object");
23666
23753
  }
23667
- const indexUuid = record.indexUuid;
23668
- if (indexUuid !== void 0 && indexUuid !== null && (typeof indexUuid !== "string" || indexUuid.length === 0)) {
23669
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'Invalid ForwardPayload: "indexUuid" must be a non-empty string');
23754
+ if (typeof decoded.indexName !== "string" || decoded.indexName.length === 0) {
23755
+ throw invalidReplicationPayload('Invalid ForwardPayload: "indexName" must be a non-empty string');
23670
23756
  }
23757
+ validateForwardOperation(decoded, "ForwardPayload");
23758
+ optionalIndexUuid(decoded.indexUuid, "ForwardPayload");
23671
23759
  return decoded;
23672
23760
  }
23673
23761
 
@@ -23770,6 +23858,9 @@ function createDataNodeHandler(deps) {
23770
23858
  case SuggestionMessageTypes.COUNTS:
23771
23859
  await deps.answerQueryCounts?.(message, respond);
23772
23860
  return;
23861
+ case ClusterMessageTypes.PING:
23862
+ await answerPing(message, respond, deps.nodeId);
23863
+ return;
23773
23864
  default:
23774
23865
  return;
23775
23866
  }
@@ -23807,7 +23898,7 @@ function refuseMessage(nodeId, message, respond, code, text2) {
23807
23898
  });
23808
23899
  }
23809
23900
  function createNotReadyHandler(nodeId) {
23810
- return (message, respond) => refuseMessage(
23901
+ return (message, respond) => message.type === ClusterMessageTypes.PING ? answerPing(message, respond, nodeId) : refuseMessage(
23811
23902
  nodeId,
23812
23903
  message,
23813
23904
  respond,
@@ -24239,12 +24330,7 @@ function createClusterHost(deps) {
24239
24330
  };
24240
24331
  }
24241
24332
  function indexNameOf2(message) {
24242
- let decoded;
24243
- try {
24244
- decoded = decode(message.payload);
24245
- } catch {
24246
- decoded = null;
24247
- }
24333
+ const decoded = decodeRequestPayload(message.payload, message.type);
24248
24334
  if (!isRecord(decoded) || typeof decoded.indexName !== "string") {
24249
24335
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, `A ${message.type} request needs "indexName" as a string`);
24250
24336
  }