@delali/narsil 0.3.1-next.156 → 0.3.1-next.157

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 (168) hide show
  1. package/dist/{analysis-change-5BQOQ4BF.mjs → analysis-change-CKEMM2MC.mjs} +9 -9
  2. package/dist/{react-native/chunks/analysis-change-entry-SCVWK6OU.mjs → analysis-change-entry-SEDMJ6MW.mjs} +1 -1
  3. package/dist/browser/{analysis-change-435CUEPZ.mjs → analysis-change-ZKGJFENM.mjs} +38 -29
  4. package/dist/{analysis-change-entry-TXX6JSMX.mjs → browser/analysis-change-entry-5BFUVMHJ.mjs} +1 -1
  5. package/dist/browser/{chunk-BHFQATSC.mjs → chunk-25MTVDYD.mjs} +1 -1
  6. package/dist/browser/{chunk-IZXVW2ZJ.mjs → chunk-3NLMB5CC.mjs} +2 -2
  7. package/dist/browser/{chunk-23XRXIBW.mjs → chunk-5YWB3E2W.mjs} +8 -1
  8. package/dist/browser/chunk-AI5UI46D.mjs +12 -0
  9. package/dist/browser/{chunk-2CFI5VVV.mjs → chunk-BLT4RHCJ.mjs} +2 -2
  10. package/dist/browser/{chunk-4NGKC4H4.mjs → chunk-C26SPCGQ.mjs} +7 -6
  11. package/dist/browser/{chunk-6LWDPLTB.mjs → chunk-C4FJ3WDY.mjs} +1 -1
  12. package/dist/browser/{chunk-MGI4BCXC.mjs → chunk-CXNTHHA7.mjs} +2 -2
  13. package/dist/browser/{chunk-STOWQFT3.mjs → chunk-DUH6QUVU.mjs} +547 -2
  14. package/dist/browser/chunk-EKMGCRSR.mjs +61 -0
  15. package/dist/browser/{chunk-SSTPBZZX.mjs → chunk-GFAZPSWK.mjs} +5 -5
  16. package/dist/browser/{chunk-3SSRJMFN.mjs → chunk-HUCSHDTB.mjs} +1 -1
  17. package/dist/browser/{chunk-K4Q6KX3R.mjs → chunk-K3IPRX6D.mjs} +48 -17
  18. package/dist/browser/{chunk-MOG4OVDK.mjs → chunk-MY2XKH22.mjs} +1 -12
  19. package/dist/browser/{chunk-3V7DNNZL.mjs → chunk-N23GL72Q.mjs} +178 -801
  20. package/dist/browser/{chunk-NQAME3RK.mjs → chunk-UATIJ4KU.mjs} +2 -2
  21. package/dist/browser/{chunk-2TI4SSUP.mjs → chunk-UKOWD2K5.mjs} +3 -3
  22. package/dist/browser/{chunk-7U3WVJUP.mjs → chunk-UTMHUHUV.mjs} +2 -2
  23. package/dist/browser/{chunk-EA63E3D2.mjs → chunk-V43N6TZO.mjs} +5 -5
  24. package/dist/browser/{chunk-CRE3G7F3.mjs → chunk-VY5KW3HN.mjs} +3 -3
  25. package/dist/browser/{chunk-WI4MR75E.mjs → chunk-X7TXYUKO.mjs} +1 -1
  26. package/dist/browser/{chunk-KZWSX6BH.mjs → chunk-Y6IBAUNO.mjs} +2 -86
  27. package/dist/browser/{cold-module-2EHCIV4K.mjs → cold-module-YNUUDNOM.mjs} +12 -10
  28. package/dist/browser/{durability-wiring-A7BVG2DW.mjs → durability-wiring-GVZEE46O.mjs} +64 -21
  29. package/dist/browser/{engine-hooks-E4UD67JD.mjs → engine-hooks-HBVS6YM4.mjs} +5 -4
  30. package/dist/browser/{geo-index-HHWGMNIS.mjs → geo-index-OTV7VPIR.mjs} +2 -1
  31. package/dist/browser/{import-DXYB6756.mjs → import-5ESVMFDJ.mjs} +6 -5
  32. package/dist/browser/{module-NIYMEA5R.mjs → module-NDSQLPMQ.mjs} +11 -9
  33. package/dist/{release-BH3DKW3T.mjs → browser/release-HYXPVJVS.mjs} +0 -1
  34. package/dist/browser/{restore-hooks-YPN4ZFCY.mjs → restore-hooks-IE3GGYHG.mjs} +8 -7
  35. package/dist/browser/{restore-queue-G3RQGL3Y.mjs → restore-queue-LQBBTODR.mjs} +3 -3
  36. package/dist/browser/{retention-ZWVMNC3Q.mjs → retention-TY3L3BFN.mjs} +7 -6
  37. package/dist/browser/{snapshot-VEQNIE6C.mjs → snapshot-5FHPPCNZ.mjs} +16 -14
  38. package/dist/browser/{start-BM442C6R.mjs → start-2UZTOBG5.mjs} +8 -7
  39. package/dist/browser/{write-2EVMZWDE.mjs → write-ULXAN5B4.mjs} +10 -8
  40. package/dist/{capabilities-Da4ywVVl.d.ts → capabilities-D3AoBJoF.d.ts} +2 -2
  41. package/dist/{chunk-K5QFDYST.mjs → chunk-24FNVRKB.mjs} +1 -1
  42. package/dist/{chunk-DP5C7YFQ.mjs → chunk-2ROUFMQX.mjs} +2 -2
  43. package/dist/{chunk-PWC4VB3Q.mjs → chunk-4B7JIGQD.mjs} +2 -2
  44. package/dist/{chunk-FAKFUDZZ.mjs → chunk-4LMSZAK6.mjs} +14 -3
  45. package/dist/{chunk-6I6AYAXS.mjs → chunk-4ZTHGTVX.mjs} +2 -2
  46. package/dist/{chunk-QOW2JPUI.mjs → chunk-BNL5OPRV.mjs} +6 -6
  47. package/dist/{chunk-3HYC4JRF.mjs → chunk-C7XQYG6U.mjs} +2 -2
  48. package/dist/{chunk-WX4LAO6M.mjs → chunk-CQZXZ75V.mjs} +3 -97
  49. package/dist/{chunk-4KKXNJM6.mjs → chunk-CWS55TEX.mjs} +2 -2
  50. package/dist/{chunk-2UV4QBHW.mjs → chunk-EYD7K3H6.mjs} +5 -5
  51. package/dist/{chunk-EFBDHH5P.mjs → chunk-FEZVDOWX.mjs} +160 -245
  52. package/dist/{chunk-XAXKV65G.mjs → chunk-FUD5XSZ5.mjs} +1 -1
  53. package/dist/{chunk-JDJBQLRO.mjs → chunk-GPWMUPCA.mjs} +10 -10
  54. package/dist/{chunk-25KDNIZZ.mjs → chunk-IIRIG7H5.mjs} +1 -1
  55. package/dist/{chunk-TZTRKM33.mjs → chunk-JSV6OQ4C.mjs} +1 -1
  56. package/dist/{chunk-NF4DT3IH.mjs → chunk-JTYPJF3T.mjs} +8 -1
  57. package/dist/chunk-KCQYFO4K.mjs +62 -0
  58. package/dist/{chunk-CSLGFPFQ.mjs → chunk-LDNCLRZU.mjs} +1 -1
  59. package/dist/{chunk-MQOJIO5B.mjs → chunk-MW6BR4QP.mjs} +2 -2
  60. package/dist/{react-native/chunks/chunk-MUWD2H2S.mjs → chunk-MWD5VPN7.mjs} +2 -2
  61. package/dist/{chunk-XXHN7J46.mjs → chunk-ODYKO5TO.mjs} +1 -1
  62. package/dist/{chunk-RDXO6JST.mjs → chunk-OG7UGJ6F.mjs} +2 -2
  63. package/dist/{chunk-FYOVBEMM.mjs → chunk-OQLD2BSW.mjs} +2 -2
  64. package/dist/{chunk-I53G4JAU.mjs → chunk-OYABFKTW.mjs} +2 -2
  65. package/dist/{chunk-TZ3355VS.mjs → chunk-P5LANSH6.mjs} +1 -1
  66. package/dist/{chunk-P5ZI2P2W.mjs → chunk-PIH5SJ4N.mjs} +3 -3
  67. package/dist/{chunk-HFPMMRQT.mjs → chunk-PSZI4O24.mjs} +51 -4
  68. package/dist/{chunk-L6V6BST3.mjs → chunk-PV2CG7EJ.mjs} +3 -552
  69. package/dist/{chunk-SA5LOGO3.mjs → chunk-PWGYQXML.mjs} +1 -1
  70. package/dist/{chunk-BWZ3P4MU.mjs → chunk-QLDABJZM.mjs} +3 -3
  71. package/dist/{chunk-JWRUUCWD.mjs → chunk-RCX4WNLC.mjs} +2 -2
  72. package/dist/{chunk-DWEPMFJE.mjs → chunk-RIHIVFIQ.mjs} +5 -5
  73. package/dist/{chunk-FNGAM5B7.mjs → chunk-RWURUDSP.mjs} +8 -8
  74. package/dist/{chunk-I2KPOLOZ.mjs → chunk-SMOOSIAW.mjs} +3 -3
  75. package/dist/{chunk-TGS5UXBE.mjs → chunk-SOI6LTHM.mjs} +3 -3
  76. package/dist/{chunk-YTWZVGCB.mjs → chunk-UD5HIS4U.mjs} +1 -1
  77. package/dist/{chunk-46KY2PJD.mjs → chunk-UJDJB3NE.mjs} +37 -29
  78. package/dist/{chunk-Z2KAFCRT.mjs → chunk-VSLSGASN.mjs} +2 -2
  79. package/dist/{chunk-VTTRFF2C.mjs → chunk-VZ2ONHEE.mjs} +9 -5
  80. package/dist/chunk-W5EB5XKI.mjs +741 -0
  81. package/dist/{chunk-7LXHHCXZ.mjs → chunk-W7OSSKH5.mjs} +46 -16
  82. package/dist/{chunk-ZKP7G7TV.mjs → chunk-XXJZMTZT.mjs} +1 -1
  83. package/dist/{chunk-FRBFVQFN.mjs → chunk-ZPZ3YGXV.mjs} +4 -4
  84. package/dist/{client-DRv7UVeY.d.ts → client-kqSMevVi.d.ts} +15 -3
  85. package/dist/client.d.ts +6 -6
  86. package/dist/client.mjs +4 -0
  87. package/dist/{cold-module-6MO2XJF2.mjs → cold-module-VOJXMNZB.mjs} +13 -12
  88. package/dist/{config-DMwffLKn.d.ts → config-B4v_Htpu.d.ts} +1 -1
  89. package/dist/{config-CoSig5Ox.d.ts → config-CTP01fns.d.ts} +1 -1
  90. package/dist/{direct-executor-FTMYY3TI.mjs → direct-executor-V5DRIECI.mjs} +5 -5
  91. package/dist/distribution.d.ts +4 -4
  92. package/dist/distribution.mjs +72 -64
  93. package/dist/{durability-wiring-VIF5MOSY.mjs → durability-wiring-3TD62MBI.mjs} +38 -30
  94. package/dist/{engine-CFxPYqEk.d.ts → engine-CkPn2PWE.d.ts} +1 -1
  95. package/dist/{engine-hooks-EGUGNZYE.mjs → engine-hooks-HA3SBOBR.mjs} +8 -8
  96. package/dist/{import-XKDPJQDP.mjs → import-GPKLTSKA.mjs} +8 -8
  97. package/dist/index.browser.mjs +4 -3
  98. package/dist/index.d.ts +4 -4
  99. package/dist/index.mjs +7 -7
  100. package/dist/index.react-native.mjs +3 -3
  101. package/dist/{long-query-thread-YA4IAYSY.mjs → long-query-thread-QDFQSJD6.mjs} +13 -13
  102. package/dist/{module-FQ4JWNQJ.mjs → module-JYHFTVPS.mjs} +12 -11
  103. package/dist/{paged-partition-archive-PXW5XAYU.mjs → paged-partition-archive-RLRGOXDX.mjs} +14 -14
  104. package/dist/partial-words.mjs +3 -3
  105. package/dist/persistence/durability/checkpoint-worker.mjs +13 -12
  106. package/dist/query-suggestions/merge-worker.mjs +9 -9
  107. package/dist/query-suggestions.browser.mjs +9 -8
  108. package/dist/query-suggestions.d.ts +1 -1
  109. package/dist/query-suggestions.mjs +17 -17
  110. package/dist/react-native/chunks/{analysis-change-LT5QBQ3H.mjs → analysis-change-QUVDNABS.mjs} +37 -29
  111. package/dist/{browser/analysis-change-entry-HZXKPPGV.mjs → react-native/chunks/analysis-change-entry-OC4XASBF.mjs} +1 -1
  112. package/dist/react-native/chunks/{chunk-KV46CT4D.mjs → chunk-4AV5PPH6.mjs} +2 -2
  113. package/dist/react-native/chunks/{chunk-GXX3DQXP.mjs → chunk-4COWCEY7.mjs} +188 -163
  114. package/dist/react-native/chunks/{chunk-G43IPIDG.mjs → chunk-4NWR3NGS.mjs} +2 -2
  115. package/dist/react-native/chunks/{chunk-3JWDECAZ.mjs → chunk-5MSX5FRT.mjs} +5 -5
  116. package/dist/react-native/chunks/{chunk-6WA3C3DV.mjs → chunk-6OFDUYVX.mjs} +8 -1
  117. package/dist/react-native/chunks/{chunk-NB3LP33V.mjs → chunk-6ZELFCK5.mjs} +2 -2
  118. package/dist/react-native/chunks/{chunk-4JYO3JD2.mjs → chunk-BITYFZSZ.mjs} +2 -2
  119. package/dist/react-native/chunks/{chunk-ZXZFN7FI.mjs → chunk-DMIFXZ3Q.mjs} +1 -1
  120. package/dist/{chunk-KF4EXSM4.mjs → react-native/chunks/chunk-IAENKE2D.mjs} +2 -2
  121. package/dist/react-native/chunks/{chunk-ZLWVW734.mjs → chunk-KSBYEMCB.mjs} +1 -1
  122. package/dist/react-native/chunks/chunk-KU646XXT.mjs +164 -0
  123. package/dist/react-native/chunks/{chunk-MIP4SOR6.mjs → chunk-OCSLSH27.mjs} +164 -244
  124. package/dist/react-native/chunks/chunk-OXM66LO6.mjs +62 -0
  125. package/dist/react-native/chunks/{chunk-VWUDIOT6.mjs → chunk-TORU2OHQ.mjs} +1 -1
  126. package/dist/react-native/chunks/{chunk-PDRWWPKV.mjs → chunk-WVWJNUMN.mjs} +48 -18
  127. package/dist/react-native/chunks/{chunk-UQ4OAXKU.mjs → chunk-WW2X2AEI.mjs} +4 -4
  128. package/dist/react-native/chunks/{chunk-QUKQNI3H.mjs → chunk-ZNZ6CPAZ.mjs} +2 -87
  129. package/dist/react-native/chunks/{chunk-TP6KCKER.mjs → chunk-ZVQMBF2H.mjs} +2 -2
  130. package/dist/react-native/chunks/{chunk-POPDAGH6.mjs → chunk-ZWAIN4GG.mjs} +6 -6
  131. package/dist/react-native/chunks/{cold-module-KVZYUGRY.mjs → cold-module-N6KFNNZA.mjs} +9 -8
  132. package/dist/react-native/chunks/{durability-wiring-34OYO32E.mjs → durability-wiring-RN64S2TL.mjs} +63 -21
  133. package/dist/react-native/chunks/{engine-hooks-M7JV46NH.mjs → engine-hooks-CWA5CKCA.mjs} +4 -4
  134. package/dist/react-native/chunks/{import-H6AQREWI.mjs → import-5UAWBRJP.mjs} +4 -4
  135. package/dist/react-native/chunks/{module-LBZPGOWH.mjs → module-6RP4ZCBW.mjs} +8 -7
  136. package/dist/react-native/chunks/{release-D7ZTIANM.mjs → release-2SIHZWDO.mjs} +0 -1
  137. package/dist/react-native/chunks/{restore-hooks-IBGIY3DR.mjs → restore-hooks-ENFMDTWC.mjs} +7 -7
  138. package/dist/react-native/chunks/{restore-queue-ZZX54AH7.mjs → restore-queue-4R6AASE5.mjs} +3 -3
  139. package/dist/react-native/chunks/{retention-EW4TTDFB.mjs → retention-5GTFT3GR.mjs} +6 -6
  140. package/dist/react-native/chunks/{snapshot-REYVIN3X.mjs → snapshot-5LGPQXFS.mjs} +15 -14
  141. package/dist/react-native/chunks/{start-BQK6KN3R.mjs → start-ZQJVZ5DN.mjs} +7 -7
  142. package/dist/react-native/chunks/{write-FQAYCZF5.mjs → write-6BRYIIZ7.mjs} +7 -6
  143. package/dist/react-native/partial-words.mjs +2 -2
  144. package/dist/react-native/query-suggestions.mjs +8 -8
  145. package/dist/react-native/sync.mjs +44 -10
  146. package/dist/react.d.ts +7 -7
  147. package/dist/{browser/release-76MXRPGV.mjs → release-SMR4WJD4.mjs} +0 -1
  148. package/dist/{restore-hooks-CDERDEF4.mjs → restore-hooks-HXLIEB4A.mjs} +12 -12
  149. package/dist/{restore-queue-7NNSTROA.mjs → restore-queue-LZH7LMLR.mjs} +3 -3
  150. package/dist/{retention-QSVBBNRM.mjs → retention-3K7ARGAG.mjs} +12 -12
  151. package/dist/server.d.ts +10 -8
  152. package/dist/server.mjs +37 -29
  153. package/dist/{snapshot-RH4NSKIZ.mjs → snapshot-O7ICP7NJ.mjs} +24 -23
  154. package/dist/{start-MCKCOGIW.mjs → start-S4PFP6RS.mjs} +14 -14
  155. package/dist/sync/filesystem.d.ts +2 -2
  156. package/dist/sync/indexeddb.d.ts +2 -2
  157. package/dist/sync.browser.mjs +44 -10
  158. package/dist/sync.d.ts +3 -3
  159. package/dist/sync.mjs +44 -10
  160. package/dist/{tasks-qrJojgST.d.ts → tasks-CoNjxbop.d.ts} +2 -2
  161. package/dist/{thread-O4SBJJJS.mjs → thread-YLJ3ZPQ3.mjs} +12 -12
  162. package/dist/{types-BZCGjfLn.d.ts → types-DPMjfOr_.d.ts} +1 -1
  163. package/dist/workers/entry.mjs +5 -5
  164. package/dist/{write-3FK7NG3Y.mjs → write-2OBJGLFS.mjs} +11 -10
  165. package/openapi.json +71 -0
  166. package/package.json +7 -7
  167. package/dist/chunk-BU4SAIC4.mjs +0 -196
  168. package/dist/react-native/chunks/chunk-DNXOMPAQ.mjs +0 -191
@@ -1,4 +1,5 @@
1
- import { compareCodePoints } from './chunk-NXQG7DRA.mjs';
1
+ import { MAX_LATITUDE_DEGREES, MAX_LONGITUDE_DEGREES } from './chunk-AI5UI46D.mjs';
2
+ import { compareCodePoints, EARLIER_RELEASE_MIN_M, MIN_M, MAX_M, holdsUnpairedSurrogate, exceedsCodePoints } from './chunk-NXQG7DRA.mjs';
2
3
  import { MAX_DOCUMENT_ENCODING_DEPTH, MAX_FILE_BYTES, DOCUMENT_ENCODER_RETAINED_BUFFER_BYTES, CHECKSUM_YIELD_CHUNK_BYTES } from './chunk-GPPOG6PT.mjs';
3
4
  import { NarsilError, ErrorCodes } from './chunk-SRMZXJSL.mjs';
4
5
  import { Encoder, decode } from '@msgpack/msgpack';
@@ -1513,6 +1514,377 @@ function getLanguage(name) {
1513
1514
  function hasLanguage(name) {
1514
1515
  return languages.has(name);
1515
1516
  }
1517
+
1518
+ // src/geo/coordinates.ts
1519
+ function isLatitude(value) {
1520
+ return value >= -MAX_LATITUDE_DEGREES && value <= MAX_LATITUDE_DEGREES;
1521
+ }
1522
+ function isLongitude(value) {
1523
+ return value >= -MAX_LONGITUDE_DEGREES && value <= MAX_LONGITUDE_DEGREES;
1524
+ }
1525
+
1526
+ // src/schema/validator/field-values.ts
1527
+ function validateGeopoint(path, value) {
1528
+ if (!isPlainObject(value)) {
1529
+ throw new NarsilError(
1530
+ ErrorCodes.SCHEMA_INVALID_GEOPOINT,
1531
+ `Field "${path}" expected a geopoint object with lat and lon`,
1532
+ {
1533
+ field: path,
1534
+ received: Array.isArray(value) ? "array" : typeof value
1535
+ }
1536
+ );
1537
+ }
1538
+ if (typeof value.lat !== "number" || typeof value.lon !== "number" || Number.isNaN(value.lat) || Number.isNaN(value.lon)) {
1539
+ throw new NarsilError(ErrorCodes.SCHEMA_INVALID_GEOPOINT, `Field "${path}" geopoint requires numeric lat and lon`, {
1540
+ field: path,
1541
+ lat: Number.isNaN(value.lat) ? "NaN" : typeof value.lat,
1542
+ lon: Number.isNaN(value.lon) ? "NaN" : typeof value.lon
1543
+ });
1544
+ }
1545
+ if (!isLatitude(value.lat)) {
1546
+ throw new NarsilError(
1547
+ ErrorCodes.SCHEMA_INVALID_GEOPOINT,
1548
+ `Field "${path}" geopoint lat must be between -90 and 90`,
1549
+ {
1550
+ field: path,
1551
+ lat: value.lat
1552
+ }
1553
+ );
1554
+ }
1555
+ if (!isLongitude(value.lon)) {
1556
+ throw new NarsilError(
1557
+ ErrorCodes.SCHEMA_INVALID_GEOPOINT,
1558
+ `Field "${path}" geopoint lon must be between -180 and 180`,
1559
+ {
1560
+ field: path,
1561
+ lon: value.lon
1562
+ }
1563
+ );
1564
+ }
1565
+ }
1566
+ function validateVector(path, value, expectedDimension) {
1567
+ const isArray = Array.isArray(value);
1568
+ const isFloat32 = value instanceof Float32Array;
1569
+ if (!isArray && !isFloat32) {
1570
+ throw new NarsilError(
1571
+ ErrorCodes.DOC_VALIDATION_FAILED,
1572
+ `Field "${path}" expected a vector (Array or Float32Array)`,
1573
+ { field: path, received: typeof value }
1574
+ );
1575
+ }
1576
+ const arr = value;
1577
+ if (arr.length !== expectedDimension) {
1578
+ throw new NarsilError(
1579
+ ErrorCodes.DOC_VALIDATION_FAILED,
1580
+ `Field "${path}" expected vector of dimension ${expectedDimension}, got ${arr.length}`,
1581
+ { field: path, expected: expectedDimension, received: arr.length }
1582
+ );
1583
+ }
1584
+ for (let i = 0; i < arr.length; i++) {
1585
+ if (typeof arr[i] !== "number" || !Number.isFinite(arr[i])) {
1586
+ throw new NarsilError(
1587
+ ErrorCodes.DOC_VALIDATION_FAILED,
1588
+ `Field "${path}" vector element at index ${i} is not a valid number`,
1589
+ { field: path, index: i, value: arr[i] }
1590
+ );
1591
+ }
1592
+ }
1593
+ }
1594
+ function validateTypedArray(path, value, elementType) {
1595
+ if (!Array.isArray(value)) {
1596
+ throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected an array`, {
1597
+ field: path,
1598
+ received: typeof value
1599
+ });
1600
+ }
1601
+ for (let i = 0; i < value.length; i++) {
1602
+ const el = value[i];
1603
+ if (typeof el !== elementType) {
1604
+ throw new NarsilError(
1605
+ ErrorCodes.DOC_VALIDATION_FAILED,
1606
+ `Field "${path}" array element at index ${i} expected ${elementType}, got ${typeof el}`,
1607
+ { field: path, index: i, expected: elementType, received: typeof el }
1608
+ );
1609
+ }
1610
+ if (elementType === "number" && !Number.isFinite(el)) {
1611
+ throw new NarsilError(
1612
+ ErrorCodes.DOC_VALIDATION_FAILED,
1613
+ `Field "${path}" array element at index ${i} is ${String(el)}, while a number field holds finite numbers alone`,
1614
+ { field: path, index: i }
1615
+ );
1616
+ }
1617
+ }
1618
+ }
1619
+ function validatePatternValue(path, value, patternValueLimit, index) {
1620
+ if (!exceedsCodePoints(value, patternValueLimit)) return;
1621
+ const subject = index === void 0 ? `The value of field "${path}"` : `Element ${index} of field "${path}"`;
1622
+ throw new NarsilError(
1623
+ ErrorCodes.DOC_VALIDATION_FAILED,
1624
+ `${subject} is longer than ${patternValueLimit} code points, which is the pattern value limit of this index`,
1625
+ { field: path, limit: patternValueLimit, ...index === void 0 ? {} : { index } }
1626
+ );
1627
+ }
1628
+ function validateFieldValue(path, value, type, patternValueLimit) {
1629
+ switch (type.base) {
1630
+ case "string":
1631
+ case "verbatim":
1632
+ if (typeof value !== "string") {
1633
+ throw new NarsilError(
1634
+ ErrorCodes.DOC_VALIDATION_FAILED,
1635
+ `Field "${path}" expected string, got ${typeof value}`,
1636
+ {
1637
+ field: path,
1638
+ expected: "string",
1639
+ received: typeof value
1640
+ }
1641
+ );
1642
+ }
1643
+ if (type.pattern) validatePatternValue(path, value, patternValueLimit);
1644
+ return;
1645
+ case "number":
1646
+ if (typeof value !== "number" || !Number.isFinite(value)) {
1647
+ throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected a finite number`, {
1648
+ field: path,
1649
+ expected: "number",
1650
+ received: typeof value === "number" ? String(value) : typeof value
1651
+ });
1652
+ }
1653
+ return;
1654
+ case "boolean":
1655
+ if (typeof value !== "boolean") {
1656
+ throw new NarsilError(
1657
+ ErrorCodes.DOC_VALIDATION_FAILED,
1658
+ `Field "${path}" expected boolean, got ${typeof value}`,
1659
+ {
1660
+ field: path,
1661
+ expected: "boolean",
1662
+ received: typeof value
1663
+ }
1664
+ );
1665
+ }
1666
+ return;
1667
+ case "enum":
1668
+ if (typeof value !== "string") {
1669
+ throw new NarsilError(
1670
+ ErrorCodes.DOC_VALIDATION_FAILED,
1671
+ `Field "${path}" expected enum (string), got ${typeof value}`,
1672
+ {
1673
+ field: path,
1674
+ expected: "enum",
1675
+ received: typeof value
1676
+ }
1677
+ );
1678
+ }
1679
+ return;
1680
+ case "geopoint":
1681
+ validateGeopoint(path, value);
1682
+ return;
1683
+ case "string[]":
1684
+ case "verbatim[]":
1685
+ validateTypedArray(path, value, "string");
1686
+ if (type.pattern) {
1687
+ const elements = value;
1688
+ for (let i = 0; i < elements.length; i++) validatePatternValue(path, elements[i], patternValueLimit, i);
1689
+ }
1690
+ return;
1691
+ case "number[]":
1692
+ validateTypedArray(path, value, "number");
1693
+ return;
1694
+ case "boolean[]":
1695
+ validateTypedArray(path, value, "boolean");
1696
+ return;
1697
+ case "enum[]":
1698
+ validateTypedArray(path, value, "string");
1699
+ return;
1700
+ case "vector":
1701
+ validateVector(path, value, type.dimension);
1702
+ return;
1703
+ }
1704
+ }
1705
+
1706
+ // src/schema/validator/storable.ts
1707
+ var RESERVED_OBJECT_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
1708
+ var UNPAIRED_SURROGATE_REASON = "holds an unpaired surrogate, the half of a character such as an emoji whose other half is missing, so the engine cannot store it as UTF-8";
1709
+ function reject(path, reason) {
1710
+ throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path === "" ? "(document)" : path}" ${reason}`, {
1711
+ field: path
1712
+ });
1713
+ }
1714
+ function isPlainObject2(value) {
1715
+ const proto = Object.getPrototypeOf(value);
1716
+ return proto === Object.prototype || proto === null;
1717
+ }
1718
+ function walkStorable(value, path, depth, ancestors, skip) {
1719
+ if (value === null || value === void 0) return;
1720
+ const kind = typeof value;
1721
+ if (kind === "string") {
1722
+ if (holdsUnpairedSurrogate(value)) reject(path, UNPAIRED_SURROGATE_REASON);
1723
+ return;
1724
+ }
1725
+ if (kind === "boolean" || kind === "number") return;
1726
+ if (kind === "bigint" || kind === "symbol" || kind === "function") {
1727
+ reject(path, `holds a ${kind}, which cannot be stored or recovered`);
1728
+ }
1729
+ const container = value;
1730
+ if (container instanceof Date) {
1731
+ if (Number.isNaN(container.getTime())) reject(path, "holds an invalid date, which the engine cannot store");
1732
+ return;
1733
+ }
1734
+ if (container instanceof Uint8Array) return;
1735
+ const isArray = Array.isArray(container);
1736
+ if (!isArray && !isPlainObject2(container)) {
1737
+ reject(
1738
+ path,
1739
+ "holds a value that does not survive storage; use plain objects, arrays, strings, numbers, booleans, dates, or Uint8Array bytes"
1740
+ );
1741
+ }
1742
+ if (depth >= MAX_DOCUMENT_NESTING_DEPTH) {
1743
+ reject(path, `nests deeper than ${MAX_DOCUMENT_NESTING_DEPTH} levels`);
1744
+ }
1745
+ if (ancestors.has(container)) {
1746
+ reject(path, "refers back to one of its own ancestors");
1747
+ }
1748
+ ancestors.add(container);
1749
+ if (isArray) {
1750
+ const items = container;
1751
+ for (let i = 0; i < items.length; i++) {
1752
+ walkStorable(items[i], `${path}[${i}]`, depth + 1, ancestors, skip);
1753
+ }
1754
+ } else {
1755
+ const record = container;
1756
+ for (const key of Object.keys(record)) {
1757
+ const keyPath = path === "" ? key : `${path}.${key}`;
1758
+ if (RESERVED_OBJECT_KEYS.has(key)) {
1759
+ reject(keyPath, "uses a reserved object key");
1760
+ }
1761
+ if (holdsUnpairedSurrogate(key)) reject(keyPath, `has a name that ${UNPAIRED_SURROGATE_REASON}`);
1762
+ if (skip.has(keyPath)) continue;
1763
+ walkStorable(record[key], keyPath, depth + 1, ancestors, skip);
1764
+ }
1765
+ }
1766
+ ancestors.delete(container);
1767
+ }
1768
+ function assertStorableDocument(document, skipFieldPaths) {
1769
+ walkStorable(document, "", 0, /* @__PURE__ */ new Set(), skipFieldPaths ?? /* @__PURE__ */ new Set());
1770
+ }
1771
+
1772
+ // src/schema/validator/document.ts
1773
+ var vectorPathCache = /* @__PURE__ */ new WeakMap();
1774
+ function vectorFieldPaths(schema) {
1775
+ let paths = vectorPathCache.get(schema);
1776
+ if (paths !== void 0) return paths;
1777
+ paths = /* @__PURE__ */ new Set();
1778
+ const collect = (level, prefix) => {
1779
+ for (const [field, type] of Object.entries(level)) {
1780
+ const path = prefix === "" ? field : `${prefix}.${field}`;
1781
+ if (typeof type === "string" && VECTOR_PATTERN.test(type)) {
1782
+ paths?.add(path);
1783
+ } else if (isPlainObject(type)) {
1784
+ collect(type, path);
1785
+ }
1786
+ }
1787
+ };
1788
+ collect(schema, "");
1789
+ vectorPathCache.set(schema, paths);
1790
+ return paths;
1791
+ }
1792
+ var parsedLevelCache = /* @__PURE__ */ new WeakMap();
1793
+ function parsedLevel(schema, prefix) {
1794
+ let entries = parsedLevelCache.get(schema);
1795
+ if (entries !== void 0) return entries;
1796
+ entries = Object.entries(schema).map(([field, type]) => {
1797
+ if (isPlainObject(type)) return { field, nested: type, type: null };
1798
+ const path = prefix ? `${prefix}.${field}` : field;
1799
+ return { field, nested: null, type: parseFieldType(type, path) };
1800
+ });
1801
+ parsedLevelCache.set(schema, entries);
1802
+ return entries;
1803
+ }
1804
+ function validateDocumentFields(doc, schema, prefix, patternValueLimit) {
1805
+ for (const { field, nested, type } of parsedLevel(schema, prefix)) {
1806
+ const value = doc[field];
1807
+ if (value === void 0 || value === null) continue;
1808
+ const path = prefix ? `${prefix}.${field}` : field;
1809
+ if (nested !== null) {
1810
+ if (!isPlainObject(value)) {
1811
+ throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected an object`, {
1812
+ field: path,
1813
+ received: Array.isArray(value) ? "array" : typeof value
1814
+ });
1815
+ }
1816
+ validateDocumentFields(value, nested, path, patternValueLimit);
1817
+ continue;
1818
+ }
1819
+ if (type !== null) validateFieldValue(path, value, type, patternValueLimit);
1820
+ }
1821
+ }
1822
+ function validateDocument(document, schema, patternValueLimit = DEFAULT_PATTERN_VALUE_LIMIT) {
1823
+ if (!isPlainObject(document)) {
1824
+ throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "Document must be a plain object", {
1825
+ received: typeof document
1826
+ });
1827
+ }
1828
+ requireIdFieldKey(document);
1829
+ assertStorableDocument(document, vectorFieldPaths(schema));
1830
+ validateDocumentFields(document, schema, "", patternValueLimit);
1831
+ }
1832
+ function requireIdFieldKey(document) {
1833
+ if (!Object.hasOwn(document, "id")) return;
1834
+ const id = document.id;
1835
+ if (typeof id === "string" && id.length > 0) return;
1836
+ throw new NarsilError(
1837
+ ErrorCodes.DOC_VALIDATION_FAILED,
1838
+ `Field "id" holds ${typeof id === "string" ? "an empty string" : id === null ? "null" : `a ${typeof id}`}, while the engine stores a document under its id field, so that field must hold a non-empty string`,
1839
+ { field: "id", received: id === null ? "null" : typeof id }
1840
+ );
1841
+ }
1842
+ function collectExtraFields(doc, schema, prefix, extras) {
1843
+ for (const key of Object.keys(doc)) {
1844
+ if (key === "id") continue;
1845
+ const path = prefix ? `${prefix}.${key}` : key;
1846
+ if (!Object.hasOwn(schema, key)) {
1847
+ extras.push(path);
1848
+ continue;
1849
+ }
1850
+ const schemaType = schema[key];
1851
+ if (isPlainObject(schemaType) && isPlainObject(doc[key])) {
1852
+ collectExtraFields(doc[key], schemaType, path, extras);
1853
+ }
1854
+ }
1855
+ }
1856
+ function validateDocumentStrict(document, schema) {
1857
+ const extras = [];
1858
+ collectExtraFields(document, schema, "", extras);
1859
+ if (extras.length > 0) {
1860
+ throw new NarsilError(
1861
+ ErrorCodes.DOC_VALIDATION_FAILED,
1862
+ `Document contains fields not defined in schema: ${extras.join(", ")}`,
1863
+ { extraFields: extras }
1864
+ );
1865
+ }
1866
+ }
1867
+ function resolveNestedValue(document, path) {
1868
+ if (!path.includes(".")) return document[path];
1869
+ const segments = path.split(".");
1870
+ let current = document;
1871
+ for (const segment of segments) {
1872
+ if (current === null || current === void 0 || typeof current !== "object") return void 0;
1873
+ current = current[segment];
1874
+ }
1875
+ return current;
1876
+ }
1877
+ function validateRequiredFields(document, required) {
1878
+ if (required.length === 0) return;
1879
+ for (const field of required) {
1880
+ const value = resolveNestedValue(document, field);
1881
+ if (value === void 0 || value === null) {
1882
+ throw new NarsilError(ErrorCodes.DOC_MISSING_REQUIRED_FIELD, `Document is missing required field "${field}"`, {
1883
+ field
1884
+ });
1885
+ }
1886
+ }
1887
+ }
1516
1888
  var INTEGER_ENCODING = { maxDepth: MAX_DOCUMENT_ENCODING_DEPTH };
1517
1889
  var FLOAT_ENCODING = { maxDepth: MAX_DOCUMENT_ENCODING_DEPTH, forceIntegerToFloat: true };
1518
1890
  var integerEncoder = new Encoder(INTEGER_ENCODING);
@@ -1546,6 +1918,117 @@ function encodeDocument(document) {
1546
1918
  }
1547
1919
  }
1548
1920
 
1921
+ // src/schema/validator/document-size.ts
1922
+ var LARGEST_HEADER_BYTES = 5;
1923
+ var LARGEST_NUMBER_BYTES = 9;
1924
+ var LARGEST_TIMESTAMP_BYTES = 15;
1925
+ var LARGEST_UTF8_BYTES_PER_UNIT = 3;
1926
+ function upperBoundBytes(value, budget, depth) {
1927
+ if (value === null || value === void 0 || typeof value === "boolean") return 1;
1928
+ if (typeof value === "number") return LARGEST_NUMBER_BYTES;
1929
+ if (typeof value === "string") return LARGEST_HEADER_BYTES + value.length * LARGEST_UTF8_BYTES_PER_UNIT;
1930
+ if (value instanceof Date) return LARGEST_TIMESTAMP_BYTES;
1931
+ if (ArrayBuffer.isView(value)) return LARGEST_HEADER_BYTES + value.byteLength;
1932
+ if (typeof value !== "object" || depth > MAX_DOCUMENT_NESTING_DEPTH) return LARGEST_NUMBER_BYTES;
1933
+ let total = LARGEST_HEADER_BYTES;
1934
+ if (Array.isArray(value)) {
1935
+ for (const item of value) {
1936
+ total += upperBoundBytes(item, budget - total, depth + 1);
1937
+ if (total > budget) return total;
1938
+ }
1939
+ return total;
1940
+ }
1941
+ const record = value;
1942
+ for (const key of Object.keys(record)) {
1943
+ total += LARGEST_HEADER_BYTES + key.length * LARGEST_UTF8_BYTES_PER_UNIT;
1944
+ total += upperBoundBytes(record[key], budget - total, depth + 1);
1945
+ if (total > budget) return total;
1946
+ }
1947
+ return total;
1948
+ }
1949
+ function messagePackUpperBoundBytes(value) {
1950
+ return upperBoundBytes(value, Number.POSITIVE_INFINITY, 0);
1951
+ }
1952
+ function encodedBytesOf(document) {
1953
+ try {
1954
+ return encodeDocument(document).byteLength;
1955
+ } catch {
1956
+ return null;
1957
+ }
1958
+ }
1959
+ function requireDocumentWithinSizeLimit(document) {
1960
+ if (upperBoundBytes(document, MAX_DOCUMENT_BYTES, 0) <= MAX_DOCUMENT_BYTES) return;
1961
+ const encodedBytes = encodedBytesOf(document);
1962
+ if (encodedBytes === null || encodedBytes <= MAX_DOCUMENT_BYTES) return;
1963
+ throw new NarsilError(
1964
+ ErrorCodes.DOC_VALIDATION_FAILED,
1965
+ `The document takes ${encodedBytes} bytes as MessagePack, vector values included, but a document may take at most ${MAX_DOCUMENT_BYTES}`,
1966
+ { bytes: encodedBytes, maximum: MAX_DOCUMENT_BYTES }
1967
+ );
1968
+ }
1969
+
1970
+ // src/schema/validator/vector-promotion.ts
1971
+ var QUANTIZATION_MODES = /* @__PURE__ */ new Set(["osq8", "osq4", "osq2", "osq1", "none"]);
1972
+ var STORAGE_MODES = /* @__PURE__ */ new Set(["memory", "disk"]);
1973
+ function fail(message, details) {
1974
+ throw new NarsilError(ErrorCodes.CONFIG_INVALID, message, details);
1975
+ }
1976
+ function isPositiveInteger(value) {
1977
+ return Number.isInteger(value) && value >= 1;
1978
+ }
1979
+ function isQuantizationMode(value) {
1980
+ return typeof value === "string" && QUANTIZATION_MODES.has(value);
1981
+ }
1982
+ function isStorageMode(value) {
1983
+ return typeof value === "string" && STORAGE_MODES.has(value);
1984
+ }
1985
+ function validateVectorStorage(config, filesystemDurability) {
1986
+ if (config?.storage === "disk" && !filesystemDurability) {
1987
+ fail("vectorPromotion.storage 'disk' needs filesystem durability, because a checkpoint file holds the vectors", {
1988
+ storage: config.storage
1989
+ });
1990
+ }
1991
+ }
1992
+ function validateTextStorage(textStorage, filesystemDurability) {
1993
+ if (textStorage === void 0 || textStorage === "memory" || textStorage === "disk" && filesystemDurability) return;
1994
+ fail("textStorage must be 'memory', or 'disk' with filesystem durability", { textStorage });
1995
+ }
1996
+ function raiseEarlierReleaseGraphSetting(config) {
1997
+ if (typeof config !== "object" || config === null) return config;
1998
+ const hnsw = config.hnswConfig;
1999
+ if (typeof hnsw !== "object" || hnsw === null) return config;
2000
+ if (hnsw.m !== EARLIER_RELEASE_MIN_M) return config;
2001
+ return { ...config, hnswConfig: { ...hnsw, m: MIN_M } };
2002
+ }
2003
+ function validateVectorPromotion(config) {
2004
+ if (config === void 0) return;
2005
+ if (config.threshold !== void 0 && !isPositiveInteger(config.threshold)) {
2006
+ fail("vectorPromotion.threshold must be a positive integer", { threshold: config.threshold });
2007
+ }
2008
+ const quantization = config.quantization;
2009
+ if (quantization !== void 0 && !isQuantizationMode(quantization)) {
2010
+ fail("vectorPromotion.quantization must be 'osq8', 'osq4', 'osq2', 'osq1', or 'none'", { quantization });
2011
+ }
2012
+ const storage = config.storage;
2013
+ if (storage !== void 0 && !isStorageMode(storage)) {
2014
+ fail("vectorPromotion.storage must be 'memory' or 'disk'", { storage });
2015
+ }
2016
+ const hnsw = config.hnswConfig;
2017
+ if (hnsw === void 0) return;
2018
+ if (hnsw.m !== void 0 && (!Number.isInteger(hnsw.m) || hnsw.m < MIN_M || hnsw.m > MAX_M)) {
2019
+ fail(`vectorPromotion.hnswConfig.m must be a whole number from ${MIN_M} to ${MAX_M}`, { m: hnsw.m });
2020
+ }
2021
+ if (hnsw.efConstruction !== void 0 && !isPositiveInteger(hnsw.efConstruction)) {
2022
+ fail("vectorPromotion.hnswConfig.efConstruction must be a positive integer", {
2023
+ efConstruction: hnsw.efConstruction
2024
+ });
2025
+ }
2026
+ const metric = hnsw.metric;
2027
+ if (metric !== void 0 && metric !== "cosine" && metric !== "dotProduct" && metric !== "euclidean") {
2028
+ fail("vectorPromotion.hnswConfig.metric must be 'cosine', 'dotProduct', or 'euclidean'", { metric });
2029
+ }
2030
+ }
2031
+
1549
2032
  // src/serialization/header.ts
1550
2033
  var MAGIC_BYTES = new Uint8Array([78, 82, 83, 76]);
1551
2034
  var HEADER_SIZE = 32;
@@ -1826,4 +2309,66 @@ function readHeapStatistics() {
1826
2309
  return null;
1827
2310
  }
1828
2311
 
1829
- export { DEFAULT_PATTERN_VALUE_LIMIT, HEADER_SIZE, INDEX_CONFIGURATION_ENVELOPE_VERSION, MAX_DOCUMENT_BYTES, MAX_DOCUMENT_NESTING_DEPTH, MAX_NESTING_DEPTH, MAX_PATTERN_VALUE_LIMIT, MIN_PATTERN_VALUE_LIMIT, PROTOTYPE_POLLUTION_KEYS, VECTOR_PATTERN, checksumOfChunks, crc32, crc32Final, crc32Init, crc32Update, decodeIndexConfiguration, encodeDocument, extractVectorFieldsFromSchema, flattenSchema, getLanguage, getStopWords, getTokenizer, hasLanguage, hasNrslMagic, hasStopWords, hasTokenizer, isGeopointOrVectorType, isListBase, isPlainObject, isSingleStringFieldType, isStringValuedBase, isWordIndexedBase, isWordIndexedFieldType, openChecksummedEnvelope, packEnvelopeWithEngineVersion, parseFieldType, parsedTypeOf, partialFieldsOf, payloadByteLength, readHeader, readHeapStatistics, registerLanguage, registerStopWords, registerTokenizer, requireConfigurationShape, requireCreatableSchema, requireValidFieldTypes, requireWithinFileLimit, resolveIndexAnalysis, schemaFieldsOf, validateSchema, withSortableOption, writeHeader };
2312
+ // src/core/partition/utils.ts
2313
+ function getOrCreateFieldNameIndex(table, fieldName) {
2314
+ const existing = table.indexMap.get(fieldName);
2315
+ if (existing !== void 0) return existing;
2316
+ const idx = table.names.length;
2317
+ table.names.push(fieldName);
2318
+ table.indexMap.set(fieldName, idx);
2319
+ return idx;
2320
+ }
2321
+ var VECTOR_PATTERN2 = /^vector\[(\d+)]$/;
2322
+ function getNestedValue(obj, path) {
2323
+ const parts = path.split(".");
2324
+ let current = obj;
2325
+ for (let i = 0; i < parts.length; i++) {
2326
+ if (current === null || current === void 0 || typeof current !== "object") return void 0;
2327
+ if (!Object.hasOwn(current, parts[i])) return void 0;
2328
+ current = current[parts[i]];
2329
+ }
2330
+ return current;
2331
+ }
2332
+ function stringArraysEqual(a, b) {
2333
+ if (a === b) return true;
2334
+ if (!a || !b) return false;
2335
+ if (a.length !== b.length) return false;
2336
+ for (let i = 0; i < a.length; i++) {
2337
+ if (a[i] !== b[i]) return false;
2338
+ }
2339
+ return true;
2340
+ }
2341
+ function textFieldsChanged(oldDoc, newDoc, fields) {
2342
+ for (const { path, base } of fields) {
2343
+ if (!isWordIndexedBase(base)) continue;
2344
+ const oldVal = getNestedValue(oldDoc, path);
2345
+ const newVal = getNestedValue(newDoc, path);
2346
+ if (base === "string") {
2347
+ if (oldVal !== newVal) return true;
2348
+ } else {
2349
+ if (!stringArraysEqual(oldVal, newVal)) return true;
2350
+ }
2351
+ }
2352
+ return false;
2353
+ }
2354
+ function parseVectorDimension(fieldType) {
2355
+ const match = VECTOR_PATTERN2.exec(fieldType);
2356
+ return match ? Number.parseInt(match[1], 10) : null;
2357
+ }
2358
+ function tokenizeOptions(options) {
2359
+ return {
2360
+ stem: true,
2361
+ removeStopWords: true,
2362
+ collectSurfaces: options?.collectSurfaces === true,
2363
+ stopWordOverride: options?.stopWordOverride,
2364
+ customTokenizer: options?.customTokenizer
2365
+ };
2366
+ }
2367
+ function getFlatSchema(state, schema) {
2368
+ if (state.lastSchemaRef === schema && state.flatSchemaCache) return state.flatSchemaCache;
2369
+ state.flatSchemaCache = flattenSchema(schema);
2370
+ state.lastSchemaRef = schema;
2371
+ return state.flatSchemaCache;
2372
+ }
2373
+
2374
+ export { HEADER_SIZE, INDEX_CONFIGURATION_ENVELOPE_VERSION, MAX_DOCUMENT_NESTING_DEPTH, MAX_NESTING_DEPTH, MAX_PATTERN_VALUE_LIMIT, MIN_PATTERN_VALUE_LIMIT, PROTOTYPE_POLLUTION_KEYS, VECTOR_PATTERN, checksumOfChunks, crc32, crc32Final, crc32Init, crc32Update, decodeIndexConfiguration, encodeDocument, extractVectorFieldsFromSchema, flattenSchema, getFlatSchema, getLanguage, getNestedValue, getOrCreateFieldNameIndex, getStopWords, getTokenizer, hasLanguage, hasNrslMagic, hasStopWords, hasTokenizer, isGeopointOrVectorType, isLatitude, isListBase, isLongitude, isPlainObject, isQuantizationMode, isSingleStringFieldType, isStorageMode, isStringValuedBase, isWordIndexedBase, isWordIndexedFieldType, messagePackUpperBoundBytes, openChecksummedEnvelope, packEnvelopeWithEngineVersion, parseVectorDimension, parsedTypeOf, partialFieldsOf, payloadByteLength, raiseEarlierReleaseGraphSetting, readHeader, readHeapStatistics, registerLanguage, registerStopWords, registerTokenizer, requireConfigurationShape, requireCreatableSchema, requireDocumentWithinSizeLimit, requireValidFieldTypes, requireWithinFileLimit, resolveIndexAnalysis, schemaFieldsOf, textFieldsChanged, tokenizeOptions, validateDocument, validateDocumentStrict, validateRequiredFields, validateSchema, validateTextStorage, validateVectorPromotion, validateVectorStorage, withSortableOption, writeHeader };
@@ -0,0 +1,61 @@
1
+ import { flattenSchema, VECTOR_PATTERN, getNestedValue } from './chunk-DUH6QUVU.mjs';
2
+
3
+ // src/serialization/vector-field-bytes.ts
4
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
5
+ var FLOAT32_BYTES = 4;
6
+ function vectorFieldPathsOfSchema(schema) {
7
+ const paths = /* @__PURE__ */ new Set();
8
+ for (const [fieldPath, fieldType] of Object.entries(flattenSchema(schema))) {
9
+ if (typeof fieldType === "string" && VECTOR_PATTERN.test(fieldType)) paths.add(fieldPath);
10
+ }
11
+ return paths;
12
+ }
13
+ function setNestedValue(obj, path, value) {
14
+ if (!path.includes(".")) {
15
+ if (FORBIDDEN_KEYS.has(path)) {
16
+ return;
17
+ }
18
+ obj[path] = value;
19
+ return;
20
+ }
21
+ const segments = path.split(".");
22
+ let current = obj;
23
+ for (let i = 0; i < segments.length - 1; i += 1) {
24
+ const segment = segments[i];
25
+ if (segment === void 0 || FORBIDDEN_KEYS.has(segment)) {
26
+ return;
27
+ }
28
+ let next = current[segment];
29
+ if (next === null || next === void 0 || typeof next !== "object") {
30
+ next = {};
31
+ current[segment] = next;
32
+ }
33
+ current = next;
34
+ }
35
+ const finalSegment = segments.at(-1);
36
+ if (finalSegment === void 0 || FORBIDDEN_KEYS.has(finalSegment)) {
37
+ return;
38
+ }
39
+ current[finalSegment] = value;
40
+ }
41
+ function restoreVectorFields(document, vectorFieldPaths) {
42
+ for (const fieldPath of vectorFieldPaths) {
43
+ const value = getNestedValue(document, fieldPath);
44
+ if (value instanceof Uint8Array && !(value instanceof Float32Array)) {
45
+ if (value.byteLength % FLOAT32_BYTES !== 0) {
46
+ throw new Error(
47
+ `Vector field "${fieldPath}" has invalid byte length ${value.byteLength} (must be divisible by 4)`
48
+ );
49
+ }
50
+ const elementCount = value.byteLength / FLOAT32_BYTES;
51
+ const float32 = new Float32Array(elementCount);
52
+ const dataView = new DataView(value.buffer, value.byteOffset, value.byteLength);
53
+ for (let i = 0; i < elementCount; i += 1) {
54
+ float32[i] = dataView.getFloat32(i * FLOAT32_BYTES, true);
55
+ }
56
+ setNestedValue(document, fieldPath, float32);
57
+ }
58
+ }
59
+ }
60
+
61
+ export { restoreVectorFields, setNestedValue, vectorFieldPathsOfSchema };
@@ -1,15 +1,15 @@
1
1
  import { SHA256_BLOCK_BYTES, sha256, SHA256_INITIAL_STATE, compressSha256Block, paddedSha256Message, sha256Digest } from './chunk-M3MQE2X7.mjs';
2
- import { dayOf, DayStore, RestoredHistory, openCountsFile, sameBytes } from './chunk-CRE3G7F3.mjs';
3
- import { resolveSetting, isPerson, isGroup, acceptedPhrase, parseSchedule, nextMatchAfter, latestMatchAtOrBefore } from './chunk-BHFQATSC.mjs';
4
- import { installSuggestionHooks } from './chunk-MGI4BCXC.mjs';
2
+ import { dayOf, DayStore, RestoredHistory, openCountsFile, sameBytes } from './chunk-VY5KW3HN.mjs';
3
+ import { resolveSetting, isPerson, isGroup, acceptedPhrase, parseSchedule, nextMatchAfter, latestMatchAtOrBefore } from './chunk-25MTVDYD.mjs';
4
+ import { installSuggestionHooks } from './chunk-CXNTHHA7.mjs';
5
5
  import { listHistoryFolder, historyFileOf, removeHistoryFolder, historyFilesOf, buildRecordKey, removeRestoreLeftovers } from './chunk-OEDCEZXJ.mjs';
6
6
  import { attachedRuntimeOf, attachRuntime } from './chunk-ATEBYXP6.mjs';
7
7
  import { oneSyncChangeAtATime } from './chunk-5W3MMTLG.mjs';
8
8
  import { SUGGESTIONS_INDEX_INFIX, BUILD_WRITE_BATCH, DAY_MS, MS_PER_SECOND, MIN_KEY_BYTES, SCRAMBLED_ID_BYTES, KEY_FINGERPRINT_LABEL, KEY_FINGERPRINT_BYTES, HISTORY_SWEEP_INTERVAL_MS, SCHEDULE_OFF, MAX_TIMER_DELAY_MS, BUILD_LIST_PAGE } from './chunk-7IGKGWSQ.mjs';
9
9
  import './chunk-HOZW3PKP.mjs';
10
- import { emitEngineEvent, emitWriteEventAfter, createEngineIndex, packEnvelopeWithChecksum } from './chunk-3V7DNNZL.mjs';
10
+ import { emitEngineEvent, emitWriteEventAfter, createEngineIndex, packEnvelopeWithChecksum } from './chunk-N23GL72Q.mjs';
11
11
  import { withOpenIndex } from './chunk-ML7THVLJ.mjs';
12
- import { crc32, openChecksummedEnvelope } from './chunk-STOWQFT3.mjs';
12
+ import { crc32, openChecksummedEnvelope } from './chunk-DUH6QUVU.mjs';
13
13
  import { compareCodePoints } from './chunk-NXQG7DRA.mjs';
14
14
  import { NarsilError, ErrorCodes } from './chunk-SRMZXJSL.mjs';
15
15
  import { encode, decode } from '@msgpack/msgpack';
@@ -1,4 +1,4 @@
1
- import { invalidSetting, acceptedPhrase, validateSetting, validateSource, settingToWire, settingFromWire, isNormalPhrase } from './chunk-BHFQATSC.mjs';
1
+ import { invalidSetting, acceptedPhrase, validateSetting, validateSource, settingToWire, settingFromWire, isNormalPhrase } from './chunk-25MTVDYD.mjs';
2
2
  import { MAX_BANNED_PHRASE_CODE_POINTS, MAX_BANNED_PHRASES, MAX_BAN_LIST_BYTES } from './chunk-7IGKGWSQ.mjs';
3
3
  import { encode } from '@msgpack/msgpack';
4
4