@rlabs-inc/fsdb 1.0.1 → 1.1.0
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.
- package/dist/core/database.d.ts.map +1 -1
- package/dist/index.js +90 -14
- package/dist/index.mjs +90 -14
- package/dist/persistence/markdown.d.ts +1 -1
- package/dist/persistence/markdown.d.ts.map +1 -1
- package/dist/persistence/watcher.d.ts.map +1 -1
- package/dist/vector/search.d.ts +1 -1
- package/dist/vector/search.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/core/database.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAkB,eAAe,EAAE,MAAM,SAAS,CAAA;AAUpH,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAMtE,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACrF,iCAAiC;IACjC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IAEvB,+BAA+B;IAC/B,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IAEvB,0BAA0B;IAC1B,aAAa,IAAI,IAAI,CAAA;IAErB,yBAAyB;IACzB,YAAY,IAAI,IAAI,CAAA;IAEpB,4BAA4B;IAC5B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAE5B,yCAAyC;IACzC,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAA;IAEvF,0DAA0D;IAC1D,YAAY,C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,IAAI,IAAI,CAAA;CACd;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,gBAAgB,EACnE,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/C,oBAAoB,CAAC,CAAC,CAAC,CAgRzB;AAMD,MAAM,WAAW,QAAQ;IACvB,oBAAoB;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB,gCAAgC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEzB,iCAAiC;IACjC,UAAU,CAAC,CAAC,SAAS,gBAAgB,EACnC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAC1C,oBAAoB,CAAC,CAAC,CAAC,CAAA;IAE1B,iCAAiC;IACjC,aAAa,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;IAE5F,gCAAgC;IAChC,eAAe,IAAI,MAAM,EAAE,CAAA;IAE3B,4BAA4B;IAC5B,KAAK,IAAI,IAAI,CAAA;CACd;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CA2DtE;AAGD,OAAO,EAAE,cAAc,IAAI,IAAI,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1720,6 +1720,46 @@ function createCollection(name, options) {
|
|
|
1720
1720
|
}
|
|
1721
1721
|
|
|
1722
1722
|
// src/persistence/markdown.ts
|
|
1723
|
+
var isBun = typeof Bun !== "undefined";
|
|
1724
|
+
async function readFileText(filepath) {
|
|
1725
|
+
if (isBun) {
|
|
1726
|
+
const file = Bun.file(filepath);
|
|
1727
|
+
if (!await file.exists())
|
|
1728
|
+
return null;
|
|
1729
|
+
return await file.text();
|
|
1730
|
+
} else {
|
|
1731
|
+
const fs = await import("fs/promises");
|
|
1732
|
+
try {
|
|
1733
|
+
return await fs.readFile(filepath, "utf-8");
|
|
1734
|
+
} catch {
|
|
1735
|
+
return null;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
async function writeFile(filepath, content) {
|
|
1740
|
+
if (isBun) {
|
|
1741
|
+
await Bun.write(filepath, content);
|
|
1742
|
+
return true;
|
|
1743
|
+
} else {
|
|
1744
|
+
const fs = await import("fs/promises");
|
|
1745
|
+
await fs.writeFile(filepath, content, "utf-8");
|
|
1746
|
+
return true;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
function listMarkdownFiles(dirpath) {
|
|
1750
|
+
if (isBun) {
|
|
1751
|
+
const glob = new Bun.Glob("*.md");
|
|
1752
|
+
return Array.from(glob.scanSync({ cwd: dirpath }));
|
|
1753
|
+
} else {
|
|
1754
|
+
const fs = require("fs");
|
|
1755
|
+
try {
|
|
1756
|
+
const files = fs.readdirSync(dirpath);
|
|
1757
|
+
return files.filter((f) => f.endsWith(".md"));
|
|
1758
|
+
} catch {
|
|
1759
|
+
return [];
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1723
1763
|
function idToFilename(id) {
|
|
1724
1764
|
return id.replace(/[<>:"/\\|?*\x00-\x1f]/g, "_") + ".md";
|
|
1725
1765
|
}
|
|
@@ -1829,11 +1869,10 @@ function generateMarkdown(record, schema, contentColumn) {
|
|
|
1829
1869
|
}
|
|
1830
1870
|
async function loadFromMarkdown(filepath, schema, contentColumn) {
|
|
1831
1871
|
try {
|
|
1832
|
-
const
|
|
1833
|
-
if (
|
|
1872
|
+
const text = await readFileText(filepath);
|
|
1873
|
+
if (text === null) {
|
|
1834
1874
|
return null;
|
|
1835
1875
|
}
|
|
1836
|
-
const text = await file.text();
|
|
1837
1876
|
const { frontmatter, content } = parseMarkdown(text);
|
|
1838
1877
|
const id = frontmatter.id;
|
|
1839
1878
|
if (!id) {
|
|
@@ -1866,8 +1905,7 @@ async function loadFromMarkdown(filepath, schema, contentColumn) {
|
|
|
1866
1905
|
async function saveToMarkdown(filepath, record, schema, contentColumn) {
|
|
1867
1906
|
try {
|
|
1868
1907
|
const markdown = generateMarkdown(record, schema, contentColumn);
|
|
1869
|
-
await
|
|
1870
|
-
return true;
|
|
1908
|
+
return await writeFile(filepath, markdown);
|
|
1871
1909
|
} catch {
|
|
1872
1910
|
return false;
|
|
1873
1911
|
}
|
|
@@ -1875,8 +1913,7 @@ async function saveToMarkdown(filepath, record, schema, contentColumn) {
|
|
|
1875
1913
|
async function loadFromDirectory(dirpath, schema, contentColumn) {
|
|
1876
1914
|
const results = [];
|
|
1877
1915
|
try {
|
|
1878
|
-
const
|
|
1879
|
-
const files = glob.scanSync({ cwd: dirpath });
|
|
1916
|
+
const files = listMarkdownFiles(dirpath);
|
|
1880
1917
|
for (const filename of files) {
|
|
1881
1918
|
const filepath = `${dirpath}/${filename}`;
|
|
1882
1919
|
const result = await loadFromMarkdown(filepath, schema, contentColumn);
|
|
@@ -1903,6 +1940,34 @@ async function ensureDirectory(dirpath) {
|
|
|
1903
1940
|
|
|
1904
1941
|
// src/persistence/watcher.ts
|
|
1905
1942
|
var import_fs = require("fs");
|
|
1943
|
+
var isBun2 = typeof Bun !== "undefined";
|
|
1944
|
+
async function fileExists(filepath) {
|
|
1945
|
+
if (isBun2) {
|
|
1946
|
+
return await Bun.file(filepath).exists();
|
|
1947
|
+
} else {
|
|
1948
|
+
const fs = await import("fs/promises");
|
|
1949
|
+
try {
|
|
1950
|
+
await fs.access(filepath);
|
|
1951
|
+
return true;
|
|
1952
|
+
} catch {
|
|
1953
|
+
return false;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
function listMarkdownFilesSync(dirpath) {
|
|
1958
|
+
if (isBun2) {
|
|
1959
|
+
const glob = new Bun.Glob("*.md");
|
|
1960
|
+
return Array.from(glob.scanSync({ cwd: dirpath }));
|
|
1961
|
+
} else {
|
|
1962
|
+
const fs = require("fs");
|
|
1963
|
+
try {
|
|
1964
|
+
const files = fs.readdirSync(dirpath);
|
|
1965
|
+
return files.filter((f) => f.endsWith(".md"));
|
|
1966
|
+
} catch {
|
|
1967
|
+
return [];
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1906
1971
|
function createFileWatcher(options) {
|
|
1907
1972
|
const {
|
|
1908
1973
|
dirpath,
|
|
@@ -1924,8 +1989,7 @@ function createFileWatcher(options) {
|
|
|
1924
1989
|
if (_savingIds.has(id)) {
|
|
1925
1990
|
return;
|
|
1926
1991
|
}
|
|
1927
|
-
const
|
|
1928
|
-
const exists = await file.exists();
|
|
1992
|
+
const exists = await fileExists(filepath);
|
|
1929
1993
|
let event;
|
|
1930
1994
|
if (!exists) {
|
|
1931
1995
|
if (!_knownFiles.has(filename))
|
|
@@ -1984,8 +2048,7 @@ function createFileWatcher(options) {
|
|
|
1984
2048
|
if (_isWatching.value)
|
|
1985
2049
|
return;
|
|
1986
2050
|
try {
|
|
1987
|
-
const
|
|
1988
|
-
for (const filename of glob.scanSync({ cwd: dirpath })) {
|
|
2051
|
+
for (const filename of listMarkdownFilesSync(dirpath)) {
|
|
1989
2052
|
_knownFiles.add(filename);
|
|
1990
2053
|
}
|
|
1991
2054
|
_watcher = import_fs.watch(dirpath, { recursive: false }, (eventType, filename) => {
|
|
@@ -2031,6 +2094,18 @@ function createFileWatcher(options) {
|
|
|
2031
2094
|
}
|
|
2032
2095
|
|
|
2033
2096
|
// src/vector/search.ts
|
|
2097
|
+
var isBun3 = typeof Bun !== "undefined";
|
|
2098
|
+
function hashContent(content) {
|
|
2099
|
+
if (isBun3) {
|
|
2100
|
+
return BigInt(Bun.hash(content));
|
|
2101
|
+
} else {
|
|
2102
|
+
let hash = 5381n;
|
|
2103
|
+
for (let i = 0;i < content.length; i++) {
|
|
2104
|
+
hash = (hash << 5n) + hash + BigInt(content.charCodeAt(i));
|
|
2105
|
+
}
|
|
2106
|
+
return hash;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2034
2109
|
function toFloat32Array(arr) {
|
|
2035
2110
|
if (arr instanceof Float32Array)
|
|
2036
2111
|
return arr;
|
|
@@ -2100,7 +2175,7 @@ function createEmbeddingManager() {
|
|
|
2100
2175
|
const hashes = new ReactiveMap;
|
|
2101
2176
|
return {
|
|
2102
2177
|
setEmbedding(id, column, content) {
|
|
2103
|
-
const hash =
|
|
2178
|
+
const hash = hashContent(content);
|
|
2104
2179
|
let columnHashes = hashes.get(id);
|
|
2105
2180
|
if (!columnHashes) {
|
|
2106
2181
|
columnHashes = new Map;
|
|
@@ -2115,7 +2190,7 @@ function createEmbeddingManager() {
|
|
|
2115
2190
|
const storedHash = columnHashes.get(column);
|
|
2116
2191
|
if (storedHash === undefined)
|
|
2117
2192
|
return false;
|
|
2118
|
-
const currentHash =
|
|
2193
|
+
const currentHash = hashContent(currentContent);
|
|
2119
2194
|
return storedHash !== currentHash;
|
|
2120
2195
|
},
|
|
2121
2196
|
getHash(id, column) {
|
|
@@ -2385,7 +2460,8 @@ function createDatabase(options = {}) {
|
|
|
2385
2460
|
} else if (options.local) {
|
|
2386
2461
|
basePath = `${process.cwd()}/.fsdb/${name}`;
|
|
2387
2462
|
} else {
|
|
2388
|
-
|
|
2463
|
+
const home = typeof Bun !== "undefined" ? Bun.env.HOME : process.env.HOME;
|
|
2464
|
+
basePath = `${home}/.fsdb/${name}`;
|
|
2389
2465
|
}
|
|
2390
2466
|
const collections = new ReactiveMap;
|
|
2391
2467
|
return {
|
package/dist/index.mjs
CHANGED
|
@@ -1629,6 +1629,46 @@ function createCollection(name, options) {
|
|
|
1629
1629
|
}
|
|
1630
1630
|
|
|
1631
1631
|
// src/persistence/markdown.ts
|
|
1632
|
+
var isBun = typeof Bun !== "undefined";
|
|
1633
|
+
async function readFileText(filepath) {
|
|
1634
|
+
if (isBun) {
|
|
1635
|
+
const file = Bun.file(filepath);
|
|
1636
|
+
if (!await file.exists())
|
|
1637
|
+
return null;
|
|
1638
|
+
return await file.text();
|
|
1639
|
+
} else {
|
|
1640
|
+
const fs = await import("fs/promises");
|
|
1641
|
+
try {
|
|
1642
|
+
return await fs.readFile(filepath, "utf-8");
|
|
1643
|
+
} catch {
|
|
1644
|
+
return null;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
async function writeFile(filepath, content) {
|
|
1649
|
+
if (isBun) {
|
|
1650
|
+
await Bun.write(filepath, content);
|
|
1651
|
+
return true;
|
|
1652
|
+
} else {
|
|
1653
|
+
const fs = await import("fs/promises");
|
|
1654
|
+
await fs.writeFile(filepath, content, "utf-8");
|
|
1655
|
+
return true;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
function listMarkdownFiles(dirpath) {
|
|
1659
|
+
if (isBun) {
|
|
1660
|
+
const glob = new Bun.Glob("*.md");
|
|
1661
|
+
return Array.from(glob.scanSync({ cwd: dirpath }));
|
|
1662
|
+
} else {
|
|
1663
|
+
const fs = __require("fs");
|
|
1664
|
+
try {
|
|
1665
|
+
const files = fs.readdirSync(dirpath);
|
|
1666
|
+
return files.filter((f) => f.endsWith(".md"));
|
|
1667
|
+
} catch {
|
|
1668
|
+
return [];
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1632
1672
|
function idToFilename(id) {
|
|
1633
1673
|
return id.replace(/[<>:"/\\|?*\x00-\x1f]/g, "_") + ".md";
|
|
1634
1674
|
}
|
|
@@ -1738,11 +1778,10 @@ function generateMarkdown(record, schema, contentColumn) {
|
|
|
1738
1778
|
}
|
|
1739
1779
|
async function loadFromMarkdown(filepath, schema, contentColumn) {
|
|
1740
1780
|
try {
|
|
1741
|
-
const
|
|
1742
|
-
if (
|
|
1781
|
+
const text = await readFileText(filepath);
|
|
1782
|
+
if (text === null) {
|
|
1743
1783
|
return null;
|
|
1744
1784
|
}
|
|
1745
|
-
const text = await file.text();
|
|
1746
1785
|
const { frontmatter, content } = parseMarkdown(text);
|
|
1747
1786
|
const id = frontmatter.id;
|
|
1748
1787
|
if (!id) {
|
|
@@ -1775,8 +1814,7 @@ async function loadFromMarkdown(filepath, schema, contentColumn) {
|
|
|
1775
1814
|
async function saveToMarkdown(filepath, record, schema, contentColumn) {
|
|
1776
1815
|
try {
|
|
1777
1816
|
const markdown = generateMarkdown(record, schema, contentColumn);
|
|
1778
|
-
await
|
|
1779
|
-
return true;
|
|
1817
|
+
return await writeFile(filepath, markdown);
|
|
1780
1818
|
} catch {
|
|
1781
1819
|
return false;
|
|
1782
1820
|
}
|
|
@@ -1784,8 +1822,7 @@ async function saveToMarkdown(filepath, record, schema, contentColumn) {
|
|
|
1784
1822
|
async function loadFromDirectory(dirpath, schema, contentColumn) {
|
|
1785
1823
|
const results = [];
|
|
1786
1824
|
try {
|
|
1787
|
-
const
|
|
1788
|
-
const files = glob.scanSync({ cwd: dirpath });
|
|
1825
|
+
const files = listMarkdownFiles(dirpath);
|
|
1789
1826
|
for (const filename of files) {
|
|
1790
1827
|
const filepath = `${dirpath}/${filename}`;
|
|
1791
1828
|
const result = await loadFromMarkdown(filepath, schema, contentColumn);
|
|
@@ -1812,6 +1849,34 @@ async function ensureDirectory(dirpath) {
|
|
|
1812
1849
|
|
|
1813
1850
|
// src/persistence/watcher.ts
|
|
1814
1851
|
import { watch } from "fs";
|
|
1852
|
+
var isBun2 = typeof Bun !== "undefined";
|
|
1853
|
+
async function fileExists(filepath) {
|
|
1854
|
+
if (isBun2) {
|
|
1855
|
+
return await Bun.file(filepath).exists();
|
|
1856
|
+
} else {
|
|
1857
|
+
const fs = await import("fs/promises");
|
|
1858
|
+
try {
|
|
1859
|
+
await fs.access(filepath);
|
|
1860
|
+
return true;
|
|
1861
|
+
} catch {
|
|
1862
|
+
return false;
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
function listMarkdownFilesSync(dirpath) {
|
|
1867
|
+
if (isBun2) {
|
|
1868
|
+
const glob = new Bun.Glob("*.md");
|
|
1869
|
+
return Array.from(glob.scanSync({ cwd: dirpath }));
|
|
1870
|
+
} else {
|
|
1871
|
+
const fs = __require("fs");
|
|
1872
|
+
try {
|
|
1873
|
+
const files = fs.readdirSync(dirpath);
|
|
1874
|
+
return files.filter((f) => f.endsWith(".md"));
|
|
1875
|
+
} catch {
|
|
1876
|
+
return [];
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1815
1880
|
function createFileWatcher(options) {
|
|
1816
1881
|
const {
|
|
1817
1882
|
dirpath,
|
|
@@ -1833,8 +1898,7 @@ function createFileWatcher(options) {
|
|
|
1833
1898
|
if (_savingIds.has(id)) {
|
|
1834
1899
|
return;
|
|
1835
1900
|
}
|
|
1836
|
-
const
|
|
1837
|
-
const exists = await file.exists();
|
|
1901
|
+
const exists = await fileExists(filepath);
|
|
1838
1902
|
let event;
|
|
1839
1903
|
if (!exists) {
|
|
1840
1904
|
if (!_knownFiles.has(filename))
|
|
@@ -1893,8 +1957,7 @@ function createFileWatcher(options) {
|
|
|
1893
1957
|
if (_isWatching.value)
|
|
1894
1958
|
return;
|
|
1895
1959
|
try {
|
|
1896
|
-
const
|
|
1897
|
-
for (const filename of glob.scanSync({ cwd: dirpath })) {
|
|
1960
|
+
for (const filename of listMarkdownFilesSync(dirpath)) {
|
|
1898
1961
|
_knownFiles.add(filename);
|
|
1899
1962
|
}
|
|
1900
1963
|
_watcher = watch(dirpath, { recursive: false }, (eventType, filename) => {
|
|
@@ -1940,6 +2003,18 @@ function createFileWatcher(options) {
|
|
|
1940
2003
|
}
|
|
1941
2004
|
|
|
1942
2005
|
// src/vector/search.ts
|
|
2006
|
+
var isBun3 = typeof Bun !== "undefined";
|
|
2007
|
+
function hashContent(content) {
|
|
2008
|
+
if (isBun3) {
|
|
2009
|
+
return BigInt(Bun.hash(content));
|
|
2010
|
+
} else {
|
|
2011
|
+
let hash = 5381n;
|
|
2012
|
+
for (let i = 0;i < content.length; i++) {
|
|
2013
|
+
hash = (hash << 5n) + hash + BigInt(content.charCodeAt(i));
|
|
2014
|
+
}
|
|
2015
|
+
return hash;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
1943
2018
|
function toFloat32Array(arr) {
|
|
1944
2019
|
if (arr instanceof Float32Array)
|
|
1945
2020
|
return arr;
|
|
@@ -2009,7 +2084,7 @@ function createEmbeddingManager() {
|
|
|
2009
2084
|
const hashes = new ReactiveMap;
|
|
2010
2085
|
return {
|
|
2011
2086
|
setEmbedding(id, column, content) {
|
|
2012
|
-
const hash =
|
|
2087
|
+
const hash = hashContent(content);
|
|
2013
2088
|
let columnHashes = hashes.get(id);
|
|
2014
2089
|
if (!columnHashes) {
|
|
2015
2090
|
columnHashes = new Map;
|
|
@@ -2024,7 +2099,7 @@ function createEmbeddingManager() {
|
|
|
2024
2099
|
const storedHash = columnHashes.get(column);
|
|
2025
2100
|
if (storedHash === undefined)
|
|
2026
2101
|
return false;
|
|
2027
|
-
const currentHash =
|
|
2102
|
+
const currentHash = hashContent(currentContent);
|
|
2028
2103
|
return storedHash !== currentHash;
|
|
2029
2104
|
},
|
|
2030
2105
|
getHash(id, column) {
|
|
@@ -2294,7 +2369,8 @@ function createDatabase(options = {}) {
|
|
|
2294
2369
|
} else if (options.local) {
|
|
2295
2370
|
basePath = `${process.cwd()}/.fsdb/${name}`;
|
|
2296
2371
|
} else {
|
|
2297
|
-
|
|
2372
|
+
const home = typeof Bun !== "undefined" ? Bun.env.HOME : process.env.HOME;
|
|
2373
|
+
basePath = `${home}/.fsdb/${name}`;
|
|
2298
2374
|
}
|
|
2299
2375
|
const collections = new ReactiveMap;
|
|
2300
2376
|
return {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Markdown Persistence
|
|
3
3
|
*
|
|
4
4
|
* Parse and generate markdown files with YAML frontmatter.
|
|
5
|
-
* Uses Bun file APIs
|
|
5
|
+
* Uses Bun file APIs when available, falls back to Node.js fs/promises.
|
|
6
6
|
*/
|
|
7
7
|
import type { SchemaDefinition, RecordWithMeta } from '../core/types';
|
|
8
8
|
/** Convert an ID to a safe filename */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/persistence/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAkB,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/persistence/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAkB,cAAc,EAAE,MAAM,eAAe,CAAA;AA2DrF,uCAAuC;AACvC,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED,iCAAiC;AACjC,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAMD,UAAU,cAAc;IACtB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAqC1D;AAkFD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,EACzD,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,aAAa,CAAC,EAAE,MAAM,CAAC,GACtB,MAAM,CA4BR;AAMD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,EAC/D,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,CAAC,EACT,aAAa,CAAC,EAAE,MAAM,CAAC,GACtB,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;CAAE,GAAG,IAAI,CAAC,CA6CpE;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,CAAC,SAAS,gBAAgB,EAC7D,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,aAAa,CAAC,EAAE,MAAM,CAAC,GACtB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,EAChE,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,CAAC,EACT,aAAa,CAAC,EAAE,MAAM,CAAC,GACtB,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;CAAE,EAAE,CAAC,CAkB/D;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQ3E;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../src/persistence/watcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAkB,eAAe,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../src/persistence/watcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAkB,eAAe,EAAE,MAAM,eAAe,CAAA;AAsCtF,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,gBAAgB;IACrD,qBAAqB;IACrB,KAAK,IAAI,IAAI,CAAA;IAEb,oBAAoB;IACpB,IAAI,IAAI,IAAI,CAAA;IAEZ,4BAA4B;IAC5B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAE5B,2CAA2C;IAC3C,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAA;IAEnF,wDAAwD;IACxD,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAE5B,wBAAwB;IACxB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,gBAAgB;IACxD,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAA;IAEf,+BAA+B;IAC/B,MAAM,EAAE,CAAC,CAAA;IAET,qBAAqB;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC,CAAA;IAEvB,0BAA0B;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,8CAA8C;IAC9C,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAA;CAC3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,EAC1D,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GACzB,WAAW,CAAC,CAAC,CAAC,CAkKhB"}
|
package/dist/vector/search.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface EmbeddingManager {
|
|
|
44
44
|
/**
|
|
45
45
|
* Create an embedding manager for stale detection
|
|
46
46
|
*
|
|
47
|
-
* Uses Bun.hash
|
|
47
|
+
* Uses fast content hashing for fingerprinting (Bun.hash when available)
|
|
48
48
|
*/
|
|
49
49
|
export declare function createEmbeddingManager(): EmbeddingManager;
|
|
50
50
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/vector/search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EACV,gBAAgB,EAEhB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/vector/search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EACV,gBAAgB,EAEhB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,eAAe,CAAA;AA0BtB;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,YAAY,GAAG,YAAY,CAGzE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,YAAY,GAAG,YAAY,CAY/D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,YAAY,GAAG,MAAM,EAAE,EAC1B,CAAC,EAAE,YAAY,GAAG,MAAM,EAAE,GACzB,MAAM,CAsBR;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,CAmCzC;AAMD,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAE/D,uDAAuD;IACvD,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAA;IAEpE,2CAA2C;IAC3C,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAEvD,8BAA8B;IAC9B,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAE3C,uBAAuB;IACvB,KAAK,IAAI,IAAI,CAAA;CACd;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CA4CzD;AAMD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,gBAAgB,EACrD,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,YAAY,EAAE,MAAM,CAAC,EACrB,WAAW,EAAE,YAAY,GAAG,MAAM,EAAE,EACpC,OAAO,GAAE,mBAAmB,CAAC,CAAC,CAAM,GACnC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CA4CzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rlabs-inc/fsdb",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Fractal State Database - A reactive in memory database with markdown files persistence made with parallel arrays and fine-grained reactivity.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|