@delali/narsil 0.3.1-next.130 → 0.3.1-next.131

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.
@@ -298,6 +298,7 @@ var DEFAULT_MAX_RESTORE_BYTES = 64 * 1024 * BYTES_PER_MB;
298
298
  var SPOOL_PAUSE_ABOVE_BYTES = 8 * BYTES_PER_MB;
299
299
  var SNAPSHOT_ARCHIVE_CONTENT_TYPE = "application/x-tar";
300
300
  var DOCUMENT_EXPORT_CONTENT_TYPE = "application/x-ndjson";
301
+ var PROMETHEUS_TEXT_CONTENT_TYPE = "text/plain; version=0.0.4; charset=utf-8";
301
302
  var RELAY_STREAM_CHUNKS_IN_FLIGHT = 4;
302
303
  var DEFAULT_MAX_LINE_BYTES = 4 * BYTES_PER_MB;
303
304
  var DEFAULT_IMPORT_BATCH_SIZE = 1e3;
@@ -1105,7 +1106,8 @@ function createDocumentReadHandlers(deps) {
1105
1106
  const found = await engine.getMultiple(ctx.params[0], body.docIds);
1106
1107
  const documents = {};
1107
1108
  for (const [id, doc] of found) documents[id] = doc;
1108
- await respondAnswer(ctx, { documents }, "documents", `a multi-get on index '${ctx.params[0]}'`);
1109
+ const answer = { documents };
1110
+ await respondAnswer(ctx, answer, "documents", `a multi-get on index '${ctx.params[0]}'`);
1109
1111
  } catch (err) {
1110
1112
  respondError(ctx, err);
1111
1113
  }
@@ -1268,9 +1270,15 @@ function spoolBody(res, maxBytes, abort, admitted2) {
1268
1270
  paused: true,
1269
1271
  done: false
1270
1272
  };
1273
+ const resumeReading = () => {
1274
+ if (!state.paused || abort.aborted) return;
1275
+ state.paused = false;
1276
+ res.resume();
1277
+ };
1271
1278
  const fail = (error, answer) => {
1272
1279
  if (state.done) return;
1273
1280
  state.done = true;
1281
+ resumeReading();
1274
1282
  if (answer && !abort.aborted) {
1275
1283
  sendError(res, 500, ServerErrorCodes.INTERNAL_ERROR, "The server could not store the request body");
1276
1284
  }
@@ -1288,10 +1296,7 @@ function spoolBody(res, maxBytes, abort, admitted2) {
1288
1296
  if (!await admitted2) throw new NotAdmittedError("the request was not admitted");
1289
1297
  state.directory = await mkdtemp(path.join(tmpdir(), "narsil-spool-"));
1290
1298
  state.handle = await open(path.join(state.directory, "body"), "w");
1291
- if (!abort.aborted && !state.done && state.queued <= SPOOL_PAUSE_ABOVE_BYTES) {
1292
- state.paused = false;
1293
- res.resume();
1294
- }
1299
+ if (!state.done && state.queued <= SPOOL_PAUSE_ABOVE_BYTES) resumeReading();
1295
1300
  })();
1296
1301
  state.chain.catch(failFromChain);
1297
1302
  abort.onAbort(() => fail(new Error("aborted"), false));
@@ -1299,6 +1304,7 @@ function spoolBody(res, maxBytes, abort, admitted2) {
1299
1304
  if (state.done || abort.aborted) return;
1300
1305
  state.total += chunk.byteLength;
1301
1306
  if (maxBytes > 0 && state.total > maxBytes) {
1307
+ resumeReading();
1302
1308
  sendError(res, 413, ServerErrorCodes.PAYLOAD_TOO_LARGE, "Request body exceeds the configured size limit");
1303
1309
  fail(new Error("payload too large"), false);
1304
1310
  return;
@@ -1313,10 +1319,7 @@ function spoolBody(res, maxBytes, abort, admitted2) {
1313
1319
  if (state.handle === null) throw new Error("the spool file is not open");
1314
1320
  await state.handle.write(copy);
1315
1321
  state.queued -= copy.byteLength;
1316
- if (state.paused && state.queued <= SPOOL_PAUSE_ABOVE_BYTES && !abort.aborted && !state.done) {
1317
- state.paused = false;
1318
- res.resume();
1319
- }
1322
+ if (!state.done && state.queued <= SPOOL_PAUSE_ABOVE_BYTES) resumeReading();
1320
1323
  });
1321
1324
  state.chain.catch(failFromChain);
1322
1325
  if (!isLast) return;
@@ -1542,6 +1545,608 @@ function createRouteRunner(deps) {
1542
1545
  };
1543
1546
  }
1544
1547
 
1548
+ // src/server/routes/documents.ts
1549
+ function documentRoutes(shared) {
1550
+ const { named, document, writeBody, readBody: readBody2, batchBody, importBody, documentWriteBody } = shared;
1551
+ return [
1552
+ {
1553
+ method: "post",
1554
+ path: "/indexes/:name/documents",
1555
+ handler: "insert",
1556
+ options: writeBody,
1557
+ operationId: "insert",
1558
+ summary: "Insert one document",
1559
+ tags: ["Documents"],
1560
+ request: "InsertBody",
1561
+ responses: { 201: "DocumentIdResponse" }
1562
+ },
1563
+ {
1564
+ method: "post",
1565
+ path: "/indexes/:name/documents/_batch",
1566
+ handler: "batch",
1567
+ options: batchBody,
1568
+ operationId: "writeBatch",
1569
+ summary: "Insert, update, or remove many documents, with a result for each",
1570
+ tags: ["Documents"],
1571
+ request: "BatchBody",
1572
+ responses: { 200: "BatchResponse" }
1573
+ },
1574
+ {
1575
+ method: "post",
1576
+ path: "/indexes/:name/documents/_list",
1577
+ handler: "list",
1578
+ options: readBody2,
1579
+ operationId: "listDocuments",
1580
+ summary: "Read one page of stored documents",
1581
+ tags: ["Documents"],
1582
+ request: "ListParams",
1583
+ responses: { 200: "ListResult" },
1584
+ repeatable: true
1585
+ },
1586
+ {
1587
+ method: "post",
1588
+ path: "/indexes/:name/documents/_multi-get",
1589
+ handler: "multiGet",
1590
+ options: readBody2,
1591
+ operationId: "getMultiple",
1592
+ summary: "Fetch many documents by id",
1593
+ tags: ["Documents"],
1594
+ request: "MultiGetBody",
1595
+ responses: { 200: "MultiGetResponse" },
1596
+ repeatable: true
1597
+ },
1598
+ {
1599
+ method: "post",
1600
+ path: "/indexes/:name/documents/_import",
1601
+ handler: "importNdjson",
1602
+ options: importBody,
1603
+ operationId: "importNdjson",
1604
+ summary: "Load newline-delimited documents, inside the request or as a task",
1605
+ tags: ["Documents"],
1606
+ request: { contentType: DOCUMENT_EXPORT_CONTENT_TYPE },
1607
+ query: "ImportDocumentsQuery",
1608
+ responses: { 200: "ImportResult", 202: "TaskRecord" }
1609
+ },
1610
+ {
1611
+ method: "post",
1612
+ path: "/indexes/:name/_wait-for-writes",
1613
+ handler: "waitForWrites",
1614
+ options: named,
1615
+ operationId: "waitForWrites",
1616
+ summary: "Wait until every worker copy has applied the writes that returned before this request",
1617
+ tags: ["Documents"],
1618
+ request: null,
1619
+ responses: { 200: "OkResponse" }
1620
+ },
1621
+ {
1622
+ method: "get",
1623
+ path: "/indexes/:name/documents/:id",
1624
+ handler: "get",
1625
+ options: document,
1626
+ operationId: "get",
1627
+ summary: "Read one document",
1628
+ tags: ["Documents"],
1629
+ request: null,
1630
+ responses: { 200: "DocumentResponse" }
1631
+ },
1632
+ {
1633
+ method: "get",
1634
+ path: "/indexes/:name/documents/:id/_exists",
1635
+ handler: "exists",
1636
+ options: document,
1637
+ operationId: "has",
1638
+ summary: "Report whether an index holds a document with the id",
1639
+ tags: ["Documents"],
1640
+ request: null,
1641
+ responses: { 200: "DocumentExistsResponse" }
1642
+ },
1643
+ {
1644
+ method: "put",
1645
+ path: "/indexes/:name/documents/:id",
1646
+ handler: "put",
1647
+ options: documentWriteBody,
1648
+ operationId: "put",
1649
+ summary: "Write one document under the id, whether or not the id exists",
1650
+ tags: ["Documents"],
1651
+ request: "DocumentBody",
1652
+ responses: { 200: "DocumentPutResponse", 201: "DocumentPutResponse" }
1653
+ },
1654
+ {
1655
+ method: "patch",
1656
+ path: "/indexes/:name/documents/:id",
1657
+ handler: "patch",
1658
+ options: documentWriteBody,
1659
+ operationId: "update",
1660
+ summary: "Update one existing document",
1661
+ tags: ["Documents"],
1662
+ request: "DocumentBody",
1663
+ responses: { 200: "DocumentIdResponse" }
1664
+ },
1665
+ {
1666
+ method: "del",
1667
+ path: "/indexes/:name/documents/:id",
1668
+ handler: "remove",
1669
+ options: document,
1670
+ operationId: "remove",
1671
+ summary: "Remove one document",
1672
+ tags: ["Documents"],
1673
+ request: null,
1674
+ query: "RemoveDocumentQuery",
1675
+ responses: { 200: "DocumentRemovedResponse" }
1676
+ }
1677
+ ];
1678
+ }
1679
+ function searchRoutes(shared) {
1680
+ const { readBody: readBody2 } = shared;
1681
+ return [
1682
+ {
1683
+ method: "post",
1684
+ path: "/indexes/:name/search",
1685
+ handler: "search",
1686
+ options: readBody2,
1687
+ operationId: "query",
1688
+ summary: "Search an index",
1689
+ tags: ["Search"],
1690
+ request: "HttpQueryParams",
1691
+ responses: { 200: "HttpQueryResult" },
1692
+ repeatable: true
1693
+ },
1694
+ {
1695
+ method: "post",
1696
+ path: "/indexes/:name/search/preflight",
1697
+ handler: "preflight",
1698
+ options: readBody2,
1699
+ operationId: "preflight",
1700
+ summary: "Count the documents that a search matches, with no hits",
1701
+ tags: ["Search"],
1702
+ request: "HttpQueryParams",
1703
+ responses: { 200: "PreflightResult" },
1704
+ repeatable: true
1705
+ },
1706
+ {
1707
+ method: "post",
1708
+ path: "/indexes/:name/suggest",
1709
+ handler: "suggest",
1710
+ options: readBody2,
1711
+ operationId: "suggest",
1712
+ summary: "Complete a prefix from the terms of an index",
1713
+ tags: ["Search"],
1714
+ request: "SuggestParams",
1715
+ responses: { 200: "SuggestResult" },
1716
+ repeatable: true
1717
+ }
1718
+ ];
1719
+ }
1720
+
1721
+ // src/server/routes/indexes.ts
1722
+ function indexRoutes(shared) {
1723
+ const { bare, named, namedBody, newIndexBody } = shared;
1724
+ return [
1725
+ {
1726
+ method: "post",
1727
+ path: "/indexes",
1728
+ handler: "createIndex",
1729
+ options: newIndexBody,
1730
+ operationId: "createIndex",
1731
+ summary: "Create an index",
1732
+ tags: ["Indexes"],
1733
+ request: "HttpCreateIndexBody",
1734
+ responses: { 201: "IndexCreatedResponse" }
1735
+ },
1736
+ {
1737
+ method: "get",
1738
+ path: "/indexes",
1739
+ handler: "listIndexes",
1740
+ options: bare,
1741
+ operationId: "listIndexes",
1742
+ summary: "List every index",
1743
+ tags: ["Indexes"],
1744
+ request: null,
1745
+ responses: { 200: "IndexListResponse" }
1746
+ },
1747
+ {
1748
+ method: "del",
1749
+ path: "/indexes/:name",
1750
+ handler: "dropIndex",
1751
+ options: named,
1752
+ operationId: "dropIndex",
1753
+ summary: "Drop an index",
1754
+ tags: ["Indexes"],
1755
+ request: null,
1756
+ responses: { 200: "IndexDroppedResponse" }
1757
+ },
1758
+ {
1759
+ method: "get",
1760
+ path: "/indexes/:name/stats",
1761
+ handler: "indexStats",
1762
+ options: named,
1763
+ operationId: "getStats",
1764
+ summary: "Report the statistics of an index",
1765
+ tags: ["Indexes"],
1766
+ request: null,
1767
+ responses: { 200: "IndexStats" }
1768
+ },
1769
+ {
1770
+ method: "get",
1771
+ path: "/indexes/:name/partitions",
1772
+ handler: "indexPartitions",
1773
+ options: named,
1774
+ operationId: "getPartitionStats",
1775
+ summary: "Report the statistics of each partition of an index",
1776
+ tags: ["Indexes"],
1777
+ request: null,
1778
+ responses: { 200: "IndexPartitionsResponse" }
1779
+ },
1780
+ {
1781
+ method: "get",
1782
+ path: "/indexes/:name/cluster",
1783
+ handler: "clusterAllocation",
1784
+ options: named,
1785
+ operationId: "getIndexAllocation",
1786
+ summary: "Report how the cluster has placed the partitions of an index",
1787
+ tags: ["Cluster"],
1788
+ request: null,
1789
+ responses: { 200: "ClusterAllocationResponse" }
1790
+ },
1791
+ {
1792
+ method: "put",
1793
+ path: "/indexes/:name/replication-factor",
1794
+ handler: "clusterReplicationFactor",
1795
+ options: namedBody,
1796
+ operationId: "setReplicationFactor",
1797
+ summary: "Change how many replicas each partition of an index keeps",
1798
+ tags: ["Cluster"],
1799
+ request: "ReplicationFactorBody",
1800
+ responses: { 200: "ReplicationFactorResponse" }
1801
+ },
1802
+ {
1803
+ method: "post",
1804
+ path: "/indexes/:name/_clear",
1805
+ handler: "clearIndex",
1806
+ options: named,
1807
+ operationId: "clear",
1808
+ summary: "Remove every document and keep the index",
1809
+ tags: ["Indexes"],
1810
+ request: null,
1811
+ responses: { 200: "IndexClearedResponse" }
1812
+ },
1813
+ {
1814
+ method: "post",
1815
+ path: "/indexes/:name/_open",
1816
+ handler: "openIndex",
1817
+ options: named,
1818
+ operationId: "open",
1819
+ summary: "Load an index into memory",
1820
+ tags: ["Indexes"],
1821
+ request: null,
1822
+ responses: { 200: "IndexStateResponse" }
1823
+ },
1824
+ {
1825
+ method: "post",
1826
+ path: "/indexes/:name/_close",
1827
+ handler: "closeIndex",
1828
+ options: named,
1829
+ operationId: "close",
1830
+ summary: "Release the memory of an index",
1831
+ tags: ["Indexes"],
1832
+ request: null,
1833
+ responses: { 200: "IndexStateResponse" }
1834
+ },
1835
+ {
1836
+ method: "get",
1837
+ path: "/indexes/:name/count",
1838
+ handler: "count",
1839
+ options: named,
1840
+ operationId: "countDocuments",
1841
+ summary: "Count the documents in an index",
1842
+ tags: ["Indexes"],
1843
+ request: null,
1844
+ responses: { 200: "DocumentCountResponse" }
1845
+ }
1846
+ ];
1847
+ }
1848
+
1849
+ // src/server/routes/info.ts
1850
+ function infoRoutes(shared) {
1851
+ const { probe, bare, named } = shared;
1852
+ return [
1853
+ {
1854
+ method: "get",
1855
+ path: "/livez",
1856
+ handler: "livez",
1857
+ options: probe,
1858
+ operationId: "isAlive",
1859
+ summary: "Report that the process can serve HTTP",
1860
+ tags: ["Server"],
1861
+ request: null,
1862
+ responses: { 200: "LivenessResponse" }
1863
+ },
1864
+ {
1865
+ method: "get",
1866
+ path: "/readyz",
1867
+ handler: "readyz",
1868
+ options: probe,
1869
+ operationId: "isReady",
1870
+ summary: "Report whether the server can take requests",
1871
+ tags: ["Server"],
1872
+ request: null,
1873
+ responses: { 200: "ReadinessResponse", 503: "ReadinessResponse" }
1874
+ },
1875
+ {
1876
+ method: "get",
1877
+ path: "/health",
1878
+ handler: "readyz",
1879
+ options: probe,
1880
+ operationId: "health",
1881
+ summary: "Report whether the server can take requests, as /readyz does",
1882
+ tags: ["Server"],
1883
+ request: null,
1884
+ responses: { 200: "ReadinessResponse", 503: "ReadinessResponse" }
1885
+ },
1886
+ {
1887
+ method: "get",
1888
+ path: "/version",
1889
+ handler: "version",
1890
+ options: probe,
1891
+ operationId: "version",
1892
+ summary: "Report the build identity of the server",
1893
+ tags: ["Server"],
1894
+ request: null,
1895
+ responses: { 200: "VersionResponse" }
1896
+ },
1897
+ {
1898
+ method: "get",
1899
+ path: "/capabilities",
1900
+ handler: "capabilities",
1901
+ options: probe,
1902
+ operationId: "capabilities",
1903
+ summary: "List the optional routes and modes that this server serves",
1904
+ tags: ["Server"],
1905
+ request: null,
1906
+ responses: { 200: "CapabilitiesResponse" }
1907
+ },
1908
+ {
1909
+ method: "get",
1910
+ path: "/cluster",
1911
+ handler: "clusterTopology",
1912
+ options: bare,
1913
+ operationId: "getClusterTopology",
1914
+ summary: "Report the nodes of the cluster and the controller",
1915
+ tags: ["Cluster"],
1916
+ request: null,
1917
+ responses: { 200: "ClusterTopologyResponse" }
1918
+ },
1919
+ {
1920
+ method: "get",
1921
+ path: "/cluster/health",
1922
+ handler: "clusterHealth",
1923
+ options: bare,
1924
+ operationId: "getClusterHealth",
1925
+ summary: "Report a green, yellow, or red status for the cluster and each index",
1926
+ tags: ["Cluster"],
1927
+ request: null,
1928
+ responses: { 200: "ClusterHealth" }
1929
+ },
1930
+ {
1931
+ method: "get",
1932
+ path: "/metrics",
1933
+ handler: "metrics",
1934
+ options: bare,
1935
+ operationId: "getMetrics",
1936
+ summary: "Report the replication and coordinator figures in the Prometheus text format",
1937
+ tags: ["Cluster"],
1938
+ request: null,
1939
+ responses: { 200: { contentType: PROMETHEUS_TEXT_CONTENT_TYPE } }
1940
+ },
1941
+ {
1942
+ method: "get",
1943
+ path: "/stats/memory",
1944
+ handler: "memory",
1945
+ options: bare,
1946
+ operationId: "getMemoryStats",
1947
+ summary: "Report the memory that the engine and the server use",
1948
+ tags: ["Server"],
1949
+ request: null,
1950
+ responses: { 200: "MemoryStatsResponse" }
1951
+ },
1952
+ {
1953
+ method: "get",
1954
+ path: "/tasks",
1955
+ handler: "listTasks",
1956
+ options: bare,
1957
+ operationId: "listTasks",
1958
+ summary: "List task records, newest first",
1959
+ tags: ["Tasks"],
1960
+ request: null,
1961
+ query: "TaskListQuery",
1962
+ responses: { 200: "TaskListPage" }
1963
+ },
1964
+ {
1965
+ method: "get",
1966
+ path: "/tasks/:id",
1967
+ handler: "getTask",
1968
+ options: named,
1969
+ operationId: "getTask",
1970
+ summary: "Read one task record",
1971
+ tags: ["Tasks"],
1972
+ request: null,
1973
+ responses: { 200: "TaskRecord" }
1974
+ },
1975
+ {
1976
+ method: "post",
1977
+ path: "/tasks/:id/_cancel",
1978
+ handler: "cancelTask",
1979
+ options: named,
1980
+ operationId: "cancelTask",
1981
+ summary: "Ask a running task to stop",
1982
+ tags: ["Tasks"],
1983
+ request: null,
1984
+ responses: { 202: "TaskRecord" }
1985
+ }
1986
+ ];
1987
+ }
1988
+
1989
+ // src/server/routes/maintenance.ts
1990
+ function maintenanceRoutes(shared) {
1991
+ const { named, namedBody, spooledBody } = shared;
1992
+ return [
1993
+ {
1994
+ method: "post",
1995
+ path: "/indexes/:name/_checkpoint",
1996
+ handler: "checkpoint",
1997
+ options: named,
1998
+ operationId: "checkpoint",
1999
+ summary: "Force a checkpoint of an index",
2000
+ tags: ["Maintenance"],
2001
+ request: null,
2002
+ responses: { 200: "OkResponse" }
2003
+ },
2004
+ {
2005
+ method: "post",
2006
+ path: "/indexes/:name/_rebuild-analysis",
2007
+ handler: "rebuildAnalysis",
2008
+ options: named,
2009
+ operationId: "rebuildAnalysis",
2010
+ summary: "Reanalyse every document of an index, as a task",
2011
+ tags: ["Maintenance"],
2012
+ request: null,
2013
+ responses: { 202: "TaskRecord" }
2014
+ },
2015
+ {
2016
+ method: "get",
2017
+ path: "/indexes/:name/snapshot",
2018
+ handler: "snapshot",
2019
+ options: named,
2020
+ operationId: "snapshot",
2021
+ summary: "Stream a snapshot archive of an index",
2022
+ tags: ["Maintenance"],
2023
+ request: null,
2024
+ responses: { 200: { contentType: SNAPSHOT_ARCHIVE_CONTENT_TYPE } }
2025
+ },
2026
+ {
2027
+ method: "get",
2028
+ path: "/indexes/:name/vector-maintenance",
2029
+ handler: "vectorMaintenance",
2030
+ options: named,
2031
+ operationId: "vectorMaintenanceStatus",
2032
+ summary: "Report the state of each vector field of an index",
2033
+ tags: ["Maintenance"],
2034
+ request: null,
2035
+ responses: { 200: "VectorMaintenanceResponse" }
2036
+ },
2037
+ {
2038
+ method: "post",
2039
+ path: "/indexes/:name/vectors/_compact",
2040
+ handler: "compact",
2041
+ options: namedBody,
2042
+ operationId: "compactVectors",
2043
+ summary: "Compact the vector fields of an index",
2044
+ tags: ["Maintenance"],
2045
+ request: { optional: "VectorFieldBody" },
2046
+ responses: { 200: "OkResponse" }
2047
+ },
2048
+ {
2049
+ method: "post",
2050
+ path: "/indexes/:name/vectors/_optimize",
2051
+ handler: "optimize",
2052
+ options: namedBody,
2053
+ operationId: "optimizeVectors",
2054
+ summary: "Rebuild the vector graphs of an index, as a task",
2055
+ tags: ["Maintenance"],
2056
+ request: { optional: "VectorFieldBody" },
2057
+ responses: { 202: "TaskRecord" }
2058
+ },
2059
+ {
2060
+ method: "post",
2061
+ path: "/indexes/:name/_rebalance",
2062
+ handler: "rebalance",
2063
+ options: namedBody,
2064
+ operationId: "rebalance",
2065
+ summary: "Move an index to another partition count, as a task",
2066
+ tags: ["Maintenance"],
2067
+ request: "RebalanceBody",
2068
+ responses: { 202: "TaskRecord" }
2069
+ },
2070
+ {
2071
+ method: "post",
2072
+ path: "/indexes/:name/partition-config",
2073
+ handler: "partitionConfig",
2074
+ options: namedBody,
2075
+ operationId: "updatePartitionConfig",
2076
+ summary: "Change the partition settings of an index",
2077
+ tags: ["Maintenance"],
2078
+ request: { optional: "PartitionConfig" },
2079
+ responses: { 200: "OkResponse" }
2080
+ },
2081
+ {
2082
+ method: "get",
2083
+ path: "/indexes/:name/synonyms",
2084
+ handler: "readSynonyms",
2085
+ options: named,
2086
+ operationId: "getSynonyms",
2087
+ summary: "Read the synonym set of an index",
2088
+ tags: ["Maintenance"],
2089
+ request: null,
2090
+ responses: { 200: "SynonymSetBody" }
2091
+ },
2092
+ {
2093
+ method: "post",
2094
+ path: "/indexes/:name/synonyms",
2095
+ handler: "replaceSynonyms",
2096
+ options: namedBody,
2097
+ operationId: "updateSynonyms",
2098
+ summary: "Replace the synonym set of an index",
2099
+ tags: ["Maintenance"],
2100
+ request: "SynonymSetBody",
2101
+ responses: { 200: "OkResponse" }
2102
+ },
2103
+ {
2104
+ method: "post",
2105
+ path: "/indexes/:name/bm25",
2106
+ handler: "updateBm25",
2107
+ options: namedBody,
2108
+ operationId: "updateBM25",
2109
+ summary: "Replace the BM25 setting of an index",
2110
+ tags: ["Maintenance"],
2111
+ request: "BM25Params",
2112
+ responses: { 200: "OkResponse" }
2113
+ },
2114
+ {
2115
+ method: "post",
2116
+ path: "/indexes/:name/restore",
2117
+ handler: "restore",
2118
+ options: spooledBody,
2119
+ operationId: "restore",
2120
+ summary: "Restore an index from a snapshot archive, as a task",
2121
+ tags: ["Maintenance"],
2122
+ request: { contentType: SNAPSHOT_ARCHIVE_CONTENT_TYPE },
2123
+ responses: { 202: "TaskRecord" }
2124
+ },
2125
+ {
2126
+ method: "get",
2127
+ path: "/indexes/:name/export",
2128
+ handler: "exportDocuments",
2129
+ options: named,
2130
+ operationId: "exportDocuments",
2131
+ summary: "Stream a document export of an index",
2132
+ tags: ["Maintenance"],
2133
+ request: null,
2134
+ responses: { 200: { contentType: DOCUMENT_EXPORT_CONTENT_TYPE } }
2135
+ },
2136
+ {
2137
+ method: "post",
2138
+ path: "/indexes/:name/import",
2139
+ handler: "importExport",
2140
+ options: spooledBody,
2141
+ operationId: "importDocumentExport",
2142
+ summary: "Import a document export, as a task",
2143
+ tags: ["Maintenance"],
2144
+ request: { contentType: DOCUMENT_EXPORT_CONTENT_TYPE },
2145
+ responses: { 202: "TaskRecord" }
2146
+ }
2147
+ ];
2148
+ }
2149
+
1545
2150
  // src/server/batch-scan.ts
1546
2151
  var QUOTE2 = 34;
1547
2152
  var BACKSLASH2 = 92;
@@ -1632,99 +2237,42 @@ function batchBodyKindOf(prefix) {
1632
2237
  return prefix.length > BATCH_KIND_SCAN_BYTES ? "read" : null;
1633
2238
  }
1634
2239
 
1635
- // src/server/routes.ts
2240
+ // src/server/routes/options.ts
1636
2241
  var writeBodyKind = () => "write";
1637
2242
  var readBodyKind = () => "read";
1638
- function serverRoutes(limits) {
1639
- const { maxBodyBytes, maxImportBytes } = limits;
1640
- const probe = { maxBytes: 0, skipHooks: true };
1641
- const bare = { maxBytes: 0 };
1642
- const named = { paramCount: 1, maxBytes: 0 };
2243
+ function sharedRouteOptions(limits) {
2244
+ const { maxBodyBytes, maxImportBytes, maxRestoreBytes } = limits;
1643
2245
  const namedBody = { paramCount: 1, needsBody: true, maxBytes: maxBodyBytes };
1644
- const document = { paramCount: 2, maxBytes: 0 };
1645
2246
  const documentBody = { paramCount: 2, needsBody: true, maxBytes: maxBodyBytes };
1646
- const writeBody = { ...namedBody, bodyKind: writeBodyKind };
1647
- const readBody2 = { ...namedBody, bodyKind: readBodyKind };
1648
- const documentWriteBody = { ...documentBody, bodyKind: writeBodyKind };
2247
+ return {
2248
+ probe: { maxBytes: 0, skipHooks: true },
2249
+ bare: { maxBytes: 0 },
2250
+ named: { paramCount: 1, maxBytes: 0 },
2251
+ namedBody,
2252
+ document: { paramCount: 2, maxBytes: 0 },
2253
+ writeBody: { ...namedBody, bodyKind: writeBodyKind },
2254
+ readBody: { ...namedBody, bodyKind: readBodyKind },
2255
+ batchBody: { ...namedBody, bodyKind: batchBodyKindOf },
2256
+ documentWriteBody: { ...documentBody, bodyKind: writeBodyKind },
2257
+ importBody: { paramCount: 1, needsBody: true, maxBytes: maxImportBytes },
2258
+ spooledBody: { paramCount: 1, spoolsBody: true, maxBytes: maxRestoreBytes },
2259
+ newIndexBody: { needsBody: true, maxBytes: maxBodyBytes }
2260
+ };
2261
+ }
2262
+
2263
+ // src/server/routes/table.ts
2264
+ function serverRoutes(limits) {
2265
+ const shared = sharedRouteOptions(limits);
1649
2266
  return [
1650
- { method: "get", path: "/livez", handler: "livez", options: probe },
1651
- { method: "get", path: "/readyz", handler: "readyz", options: probe },
1652
- { method: "get", path: "/health", handler: "readyz", options: probe },
1653
- { method: "get", path: "/version", handler: "version", options: probe },
1654
- { method: "get", path: "/capabilities", handler: "capabilities", options: probe },
1655
- { method: "get", path: "/cluster", handler: "clusterTopology", options: bare },
1656
- { method: "get", path: "/cluster/health", handler: "clusterHealth", options: bare },
1657
- { method: "get", path: "/metrics", handler: "metrics", options: bare },
1658
- { method: "get", path: "/stats/memory", handler: "memory", options: bare },
1659
- { method: "get", path: "/tasks", handler: "listTasks", options: bare },
1660
- { method: "get", path: "/tasks/:id", handler: "getTask", options: named },
1661
- { method: "post", path: "/tasks/:id/_cancel", handler: "cancelTask", options: named },
1662
- { method: "post", path: "/indexes", handler: "createIndex", options: { needsBody: true, maxBytes: maxBodyBytes } },
1663
- { method: "get", path: "/indexes", handler: "listIndexes", options: bare },
1664
- { method: "del", path: "/indexes/:name", handler: "dropIndex", options: named },
1665
- { method: "get", path: "/indexes/:name/stats", handler: "indexStats", options: named },
1666
- { method: "get", path: "/indexes/:name/partitions", handler: "indexPartitions", options: named },
1667
- { method: "get", path: "/indexes/:name/cluster", handler: "clusterAllocation", options: named },
1668
- {
1669
- method: "put",
1670
- path: "/indexes/:name/replication-factor",
1671
- handler: "clusterReplicationFactor",
1672
- options: namedBody
1673
- },
1674
- { method: "post", path: "/indexes/:name/_clear", handler: "clearIndex", options: named },
1675
- { method: "post", path: "/indexes/:name/_open", handler: "openIndex", options: named },
1676
- { method: "post", path: "/indexes/:name/_close", handler: "closeIndex", options: named },
1677
- { method: "get", path: "/indexes/:name/count", handler: "count", options: named },
1678
- { method: "post", path: "/indexes/:name/documents", handler: "insert", options: writeBody },
1679
- {
1680
- method: "post",
1681
- path: "/indexes/:name/documents/_batch",
1682
- handler: "batch",
1683
- options: { ...namedBody, bodyKind: batchBodyKindOf }
1684
- },
1685
- { method: "post", path: "/indexes/:name/documents/_list", handler: "list", options: readBody2 },
1686
- { method: "post", path: "/indexes/:name/documents/_multi-get", handler: "multiGet", options: readBody2 },
1687
- {
1688
- method: "post",
1689
- path: "/indexes/:name/documents/_import",
1690
- handler: "importNdjson",
1691
- options: { paramCount: 1, needsBody: true, maxBytes: maxImportBytes }
1692
- },
1693
- { method: "post", path: "/indexes/:name/_wait-for-writes", handler: "waitForWrites", options: named },
1694
- { method: "get", path: "/indexes/:name/documents/:id", handler: "get", options: document },
1695
- { method: "get", path: "/indexes/:name/documents/:id/_exists", handler: "exists", options: document },
1696
- { method: "put", path: "/indexes/:name/documents/:id", handler: "put", options: documentWriteBody },
1697
- { method: "patch", path: "/indexes/:name/documents/:id", handler: "patch", options: documentWriteBody },
1698
- { method: "del", path: "/indexes/:name/documents/:id", handler: "remove", options: document },
1699
- { method: "post", path: "/indexes/:name/search", handler: "search", options: readBody2 },
1700
- { method: "post", path: "/indexes/:name/search/preflight", handler: "preflight", options: readBody2 },
1701
- { method: "post", path: "/indexes/:name/suggest", handler: "suggest", options: readBody2 },
1702
- { method: "post", path: "/indexes/:name/_checkpoint", handler: "checkpoint", options: named },
1703
- { method: "post", path: "/indexes/:name/_rebuild-analysis", handler: "rebuildAnalysis", options: named },
1704
- { method: "get", path: "/indexes/:name/snapshot", handler: "snapshot", options: named },
1705
- { method: "get", path: "/indexes/:name/vector-maintenance", handler: "vectorMaintenance", options: named },
1706
- { method: "post", path: "/indexes/:name/vectors/_compact", handler: "compact", options: namedBody },
1707
- { method: "post", path: "/indexes/:name/vectors/_optimize", handler: "optimize", options: namedBody },
1708
- { method: "post", path: "/indexes/:name/_rebalance", handler: "rebalance", options: namedBody },
1709
- { method: "post", path: "/indexes/:name/partition-config", handler: "partitionConfig", options: namedBody },
1710
- { method: "get", path: "/indexes/:name/synonyms", handler: "readSynonyms", options: named },
1711
- { method: "post", path: "/indexes/:name/synonyms", handler: "replaceSynonyms", options: namedBody },
1712
- { method: "post", path: "/indexes/:name/bm25", handler: "updateBm25", options: namedBody },
1713
- {
1714
- method: "post",
1715
- path: "/indexes/:name/restore",
1716
- handler: "restore",
1717
- options: { paramCount: 1, spoolsBody: true, maxBytes: limits.maxRestoreBytes }
1718
- },
1719
- { method: "get", path: "/indexes/:name/export", handler: "exportDocuments", options: named },
1720
- {
1721
- method: "post",
1722
- path: "/indexes/:name/import",
1723
- handler: "importExport",
1724
- options: { paramCount: 1, spoolsBody: true, maxBytes: limits.maxRestoreBytes }
1725
- }
2267
+ ...infoRoutes(shared),
2268
+ ...indexRoutes(shared),
2269
+ ...documentRoutes(shared),
2270
+ ...searchRoutes(shared),
2271
+ ...maintenanceRoutes(shared)
1726
2272
  ];
1727
2273
  }
2274
+
2275
+ // src/server/routes/register.ts
1728
2276
  function registerServerRoutes(app, run, handlers, limits, cors) {
1729
2277
  if (cors) {
1730
2278
  app.options("/*", (res, req) => {
@@ -1836,4 +2384,4 @@ async function departureConfirmation(word) {
1836
2384
  if (waiting.async) await waiting.value;
1837
2385
  }
1838
2386
 
1839
- export { ASYNC_IMPORT_CAPABILITY, BM25_TUNING_CAPABILITY, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_BODY_BYTES_IN_FLIGHT_FRACTION, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RERANK_WINDOW, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_RETAINED_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_TASK_PAGE_SIZE, DOCUMENT_EXPORT_CAPABILITY, DOCUMENT_EXPORT_CONTENT_TYPE, IMPORT_FLUSHES_IN_FLIGHT, INDEX_LIFECYCLE_CAPABILITY, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, MAIN_THREAD_GATE_SLOT, MAX_BODY_BYTES_IN_FLIGHT_FRACTION, MAX_INDEX_TOUCH_INTERVAL_MS, MAX_LONG_QUERIES_IN_FLIGHT, MIN_COUNTED_SERVER_LIMIT, MIN_UNBOUNDED_SERVER_LIMIT, REBUILD_ANALYSIS_CAPABILITY, RELAY_STREAM_CHUNKS_IN_FLIGHT, REQUEST_THREAD_CLOSE_AT_EXIT_MS, REQUEST_THREAD_DEPARTURE_DRAIN_MS, REQUEST_THREAD_MOVE_AFTER_MS, RUNNING_TASK_TTL_MS, SEARCH_CLOCK_SAMPLE_UNITS, SERVER_CAPABILITIES, SNAPSHOT_ARCHIVE_CONTENT_TYPE, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, TASK_PROGRESS_WRITE_INTERVAL_MS, TERMINAL_TASK_TTL_MS, acceptorOf, authorizerFor, awaitDepartureConfirmation, badRequest, childAppOf, clearBodyBudgetSlot, clearGateSlot, closeEveryThreadAtExit, closeWhenTheProcessExits, confirmDeparture, corsHeaderReader, createBodyBudgetBuffer, createCloseAtExitWords, createDepartureWord, createDocumentReadHandlers, createRouteRunner, createSharedBodyBudget, createSharedGateBuffer, createSharedRequestGate, createVersionHandler, departureConfirmation, departureConfirmed, encodeJson, gateSlotOfWorker, httpStatusForNarsilError, isRemoveOnlyBatch, loadUWebSockets, parseJson, parseJsonOptional, parseRefusalOf, parseTaskListQuery, parseWriteJson, refuseRegex, registerServerRoutes, rejectInvalid, resolveCors, respondAnswer, respondError, respondJson, sendError, sendRelayed, sendStream, sendText, serializeBatchResult, serializeNarsilError, serverRoutes, statusLine, toHttpError, validateBatch, validateCreateIndex, validateDocumentBody, validateQuery, validateRebalance, validateSuggest, versionReport, withServerRerankWindow };
2387
+ export { ASYNC_IMPORT_CAPABILITY, BM25_TUNING_CAPABILITY, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_BODY_BYTES_IN_FLIGHT_FRACTION, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RERANK_WINDOW, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_RETAINED_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_TASK_PAGE_SIZE, DOCUMENT_EXPORT_CAPABILITY, DOCUMENT_EXPORT_CONTENT_TYPE, IMPORT_FLUSHES_IN_FLIGHT, INDEX_LIFECYCLE_CAPABILITY, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, MAIN_THREAD_GATE_SLOT, MAX_BODY_BYTES_IN_FLIGHT_FRACTION, MAX_INDEX_TOUCH_INTERVAL_MS, MAX_LONG_QUERIES_IN_FLIGHT, MIN_COUNTED_SERVER_LIMIT, MIN_UNBOUNDED_SERVER_LIMIT, PROMETHEUS_TEXT_CONTENT_TYPE, REBUILD_ANALYSIS_CAPABILITY, RELAY_STREAM_CHUNKS_IN_FLIGHT, REQUEST_THREAD_CLOSE_AT_EXIT_MS, REQUEST_THREAD_DEPARTURE_DRAIN_MS, REQUEST_THREAD_MOVE_AFTER_MS, RUNNING_TASK_TTL_MS, SEARCH_CLOCK_SAMPLE_UNITS, SERVER_CAPABILITIES, SNAPSHOT_ARCHIVE_CONTENT_TYPE, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, TASK_PROGRESS_WRITE_INTERVAL_MS, TERMINAL_TASK_TTL_MS, acceptorOf, authorizerFor, awaitDepartureConfirmation, badRequest, childAppOf, clearBodyBudgetSlot, clearGateSlot, closeEveryThreadAtExit, closeWhenTheProcessExits, confirmDeparture, corsHeaderReader, createBodyBudgetBuffer, createCloseAtExitWords, createDepartureWord, createDocumentReadHandlers, createRouteRunner, createSharedBodyBudget, createSharedGateBuffer, createSharedRequestGate, createVersionHandler, departureConfirmation, departureConfirmed, encodeJson, gateSlotOfWorker, httpStatusForNarsilError, isRemoveOnlyBatch, loadUWebSockets, parseJson, parseJsonOptional, parseRefusalOf, parseTaskListQuery, parseWriteJson, refuseRegex, registerServerRoutes, rejectInvalid, resolveCors, respondAnswer, respondError, respondJson, sendError, sendRelayed, sendStream, sendText, serializeBatchResult, serializeNarsilError, serverRoutes, statusLine, toHttpError, validateBatch, validateCreateIndex, validateDocumentBody, validateQuery, validateRebalance, validateSuggest, versionReport, withServerRerankWindow };