@fireproof/core 0.19.8-dev-alldocs → 0.19.8-dev-cra

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/{chunk-DG6XSV44.js → chunk-BNL4PVBF.js} +25 -81
  2. package/chunk-BNL4PVBF.js.map +1 -0
  3. package/{chunk-OWQAHX2V.js → chunk-JW2QT6BF.js} +24 -4
  4. package/chunk-JW2QT6BF.js.map +1 -0
  5. package/index.cjs +443 -1300
  6. package/index.cjs.map +1 -1
  7. package/index.d.cts +156 -167
  8. package/index.d.ts +156 -167
  9. package/index.global.js +1036 -1214
  10. package/index.global.js.map +1 -1
  11. package/index.js +64 -59
  12. package/index.js.map +1 -1
  13. package/metafile-cjs.json +1 -1
  14. package/metafile-esm.json +1 -1
  15. package/metafile-iife.json +1 -1
  16. package/node-sys-container-MIEX6ELJ.js +29 -0
  17. package/node-sys-container-MIEX6ELJ.js.map +1 -0
  18. package/package.json +3 -2
  19. package/{store-file-WD746RSY.js → store-file-VJ6BI4II.js} +6 -8
  20. package/{store-file-WD746RSY.js.map → store-file-VJ6BI4II.js.map} +1 -1
  21. package/{chunk-5UFCF36O.js → store-indexdb-WLRSICCB.js} +7 -17
  22. package/store-indexdb-WLRSICCB.js.map +1 -0
  23. package/tests/fireproof/config.test.ts +14 -70
  24. package/tests/fireproof/database.test.ts +4 -4
  25. package/tests/fireproof/fireproof.test.ts +5 -5
  26. package/tests/fireproof/hello.test.ts +2 -2
  27. package/chunk-5UFCF36O.js.map +0 -1
  28. package/chunk-DG6XSV44.js.map +0 -1
  29. package/chunk-OWQAHX2V.js.map +0 -1
  30. package/chunk-PRQHQG4I.js +0 -39
  31. package/chunk-PRQHQG4I.js.map +0 -1
  32. package/chunk-VZGT7ZYP.js +0 -22
  33. package/chunk-VZGT7ZYP.js.map +0 -1
  34. package/node-sys-container-TTGEC66A.js +0 -29
  35. package/node-sys-container-TTGEC66A.js.map +0 -1
  36. package/sqlite-data-store-MA55LVQE.js +0 -120
  37. package/sqlite-data-store-MA55LVQE.js.map +0 -1
  38. package/sqlite-meta-store-UNQKVYRM.js +0 -137
  39. package/sqlite-meta-store-UNQKVYRM.js.map +0 -1
  40. package/sqlite-wal-store-KVUOC4PO.js +0 -123
  41. package/sqlite-wal-store-KVUOC4PO.js.map +0 -1
  42. package/store-indexdb-NG45BU3Q.js +0 -20
  43. package/store-indexdb-NG45BU3Q.js.map +0 -1
  44. package/store-sql-QVFNIGND.js +0 -344
  45. package/store-sql-QVFNIGND.js.map +0 -1
package/index.js CHANGED
@@ -1,11 +1,6 @@
1
- import {
2
- guardVersion
3
- } from "./chunk-5UFCF36O.js";
4
1
  import {
5
2
  NotFoundError,
6
- isNotFoundError
7
- } from "./chunk-VZGT7ZYP.js";
8
- import {
3
+ Result,
9
4
  dataDir,
10
5
  decodeFile,
11
6
  encodeFile,
@@ -15,16 +10,17 @@ import {
15
10
  getKey,
16
11
  getName,
17
12
  getStore,
13
+ isNotFoundError,
18
14
  runtime_exports,
19
15
  toCryptoOpts
20
- } from "./chunk-DG6XSV44.js";
16
+ } from "./chunk-BNL4PVBF.js";
21
17
  import {
22
18
  SysContainer,
23
19
  __export,
24
20
  falsyToUndef,
25
21
  isFalsy,
26
22
  throwFalsy
27
- } from "./chunk-OWQAHX2V.js";
23
+ } from "./chunk-JW2QT6BF.js";
28
24
 
29
25
  // src/database.ts
30
26
  import { uuidv7 } from "uuidv7";
@@ -280,7 +276,7 @@ import { KeyedResolvOnce } from "@adviser/cement";
280
276
  // src/blockstore/store.ts
281
277
  import pLimit2 from "p-limit";
282
278
  import { format, parse } from "@ipld/dag-json";
283
- import { ResolveOnce as ResolveOnce2, Result } from "@adviser/cement";
279
+ import { ResolveOnce as ResolveOnce2, Result as Result2 } from "@adviser/cement";
284
280
 
285
281
  // src/blockstore/loader.ts
286
282
  import pLimit from "p-limit";
@@ -1243,6 +1239,12 @@ var Loader = class {
1243
1239
  };
1244
1240
 
1245
1241
  // src/blockstore/store.ts
1242
+ function guardVersion(url) {
1243
+ if (!url.searchParams.has("version")) {
1244
+ return Result2.Err(`missing version: ${url.toString()}`);
1245
+ }
1246
+ return Result2.Ok(url);
1247
+ }
1246
1248
  var VersionedStore = class {
1247
1249
  constructor(name, url, logger) {
1248
1250
  this._onStarted = [];
@@ -1288,14 +1290,14 @@ var MetaStore = class extends VersionedStore {
1288
1290
  this.logger.Debug().Str("branch", branch || "").Msg("loading");
1289
1291
  const url = await this.gateway.buildUrl(this.url, branch || "main");
1290
1292
  if (url.isErr()) {
1291
- throw this.logger.Error().Err(url.Err()).Str("branch", branch || "").Str("url", this.url.toString()).Msg("got error from gateway.buildUrl").AsError();
1293
+ throw this.logger.Error().Result("buidUrl", url).Str("branch", branch || "").Url(this.url).Msg("got error from gateway.buildUrl").AsError();
1292
1294
  }
1293
1295
  const bytes = await this.gateway.get(url.Ok());
1294
1296
  if (bytes.isErr()) {
1295
1297
  if (isNotFoundError(bytes)) {
1296
1298
  return void 0;
1297
1299
  }
1298
- throw this.logger.Error().Err(bytes.Err()).Msg("gateway get").AsError();
1300
+ throw this.logger.Error().Url(url.Ok()).Result("bytes:", bytes).Msg("gateway get").AsError();
1299
1301
  }
1300
1302
  try {
1301
1303
  return [this.parseHeader(textDecoder.decode(bytes.Ok()))];
@@ -1319,7 +1321,7 @@ var MetaStore = class extends VersionedStore {
1319
1321
  async close() {
1320
1322
  await this.gateway.close(this.url);
1321
1323
  this._onClosed.forEach((fn) => fn());
1322
- return Result.Ok(void 0);
1324
+ return Result2.Ok(void 0);
1323
1325
  }
1324
1326
  async destroy() {
1325
1327
  return this.gateway.destroy(this.url);
@@ -1341,13 +1343,13 @@ var DataStore = class extends VersionedStore {
1341
1343
  this.logger.Debug().Msg("starting-gateway");
1342
1344
  const res = await this.gateway.start(this.url);
1343
1345
  if (res.isErr()) {
1344
- this.logger.Error().Err(res.Err()).Msg("started-gateway");
1346
+ this.logger.Error().Result("gw-start", res).Msg("started-gateway");
1345
1347
  return res;
1346
1348
  }
1347
1349
  this._onStarted.forEach((fn) => fn());
1348
1350
  const version = guardVersion(this.url);
1349
1351
  if (version.isErr()) {
1350
- this.logger.Error().Err(res.Err()).Msg("guardVersion");
1352
+ this.logger.Error().Result("version", version).Msg("guardVersion");
1351
1353
  await this.close();
1352
1354
  return version;
1353
1355
  }
@@ -1389,7 +1391,7 @@ var DataStore = class extends VersionedStore {
1389
1391
  async close() {
1390
1392
  await this.gateway.close(this.url);
1391
1393
  this._onClosed.forEach((fn) => fn());
1392
- return Result.Ok(void 0);
1394
+ return Result2.Ok(void 0);
1393
1395
  }
1394
1396
  destroy() {
1395
1397
  return this.gateway.destroy(this.url);
@@ -1574,7 +1576,7 @@ var RemoteWAL = class extends VersionedStore {
1574
1576
  async close() {
1575
1577
  await this.gateway.close(this.url);
1576
1578
  this._onClosed.forEach((fn) => fn());
1577
- return Result.Ok(void 0);
1579
+ return Result2.Ok(void 0);
1578
1580
  }
1579
1581
  destroy() {
1580
1582
  return this.gateway.destroy(this.url);
@@ -1617,17 +1619,26 @@ function buildURL(optURL, loader) {
1617
1619
  return toURL(optURL || obuUrl || dataDir(loader.name, storeOpts.stores?.base), storeOpts.isIndex);
1618
1620
  }
1619
1621
  function registerStoreProtocol(item) {
1620
- if (storeFactory.has(item.protocol)) {
1621
- throw new Error(`protocol ${item.protocol} already registered`);
1622
+ let protocol = item.protocol;
1623
+ if (!protocol.endsWith(":")) {
1624
+ protocol += ":";
1625
+ }
1626
+ if (storeFactory.has(protocol)) {
1627
+ if (!item.overrideBaseURL && storeFactory.get(protocol) !== item) {
1628
+ const logger = ensureLogger({}, "registerStoreProtocol", { protocol });
1629
+ logger.Warn().Msg(`protocol ${protocol} already registered`);
1630
+ return () => {
1631
+ };
1632
+ }
1622
1633
  }
1623
1634
  if (item.overrideBaseURL) {
1624
1635
  Array.from(storeFactory.values()).forEach((items) => {
1625
1636
  items.overrideBaseURL = void 0;
1626
1637
  });
1627
1638
  }
1628
- storeFactory.set(item.protocol, item);
1639
+ storeFactory.set(protocol, item);
1629
1640
  return () => {
1630
- storeFactory.delete(item.protocol);
1641
+ storeFactory.delete(protocol);
1631
1642
  };
1632
1643
  }
1633
1644
  function runStoreFactory(url, logger, run) {
@@ -1653,7 +1664,10 @@ async function dataStoreFactory(loader) {
1653
1664
  return onceDataStoreFactory.get(url.toString()).once(async () => {
1654
1665
  const gateway = await loadDataGateway(url, logger);
1655
1666
  const store = new DataStore(loader.name, url, loader.logger, gateway);
1656
- await store.start();
1667
+ const ret = await store.start();
1668
+ if (ret.isErr()) {
1669
+ throw logger.Error().Result("start", ret).Msg("start failed").AsError();
1670
+ }
1657
1671
  logger.Debug().Str("prepared", store.url.toString()).Msg("produced");
1658
1672
  return store;
1659
1673
  });
@@ -1674,7 +1688,10 @@ async function metaStoreFactory(loader) {
1674
1688
  logger.Debug().Str("protocol", url.protocol).Msg("pre-protocol switch");
1675
1689
  const gateway = await loadMetaGateway(url, logger);
1676
1690
  const store = new MetaStore(loader.name, url, loader.logger, gateway);
1677
- await store.start();
1691
+ const ret = await store.start();
1692
+ if (ret.isErr()) {
1693
+ throw logger.Error().Result("start", ret).Msg("start failed").AsError();
1694
+ }
1678
1695
  return store;
1679
1696
  });
1680
1697
  }
@@ -1694,7 +1711,10 @@ async function remoteWalFactory(loader) {
1694
1711
  const gateway = await loadWalGateway(url, logger);
1695
1712
  logger.Debug().Str("prepared", url.toString()).Msg("produced");
1696
1713
  const store = new RemoteWAL(loader, url, loader.logger, gateway);
1697
- await store.start();
1714
+ const ret = await store.start();
1715
+ if (ret.isErr()) {
1716
+ throw logger.Error().Result("start", ret).Msg("start failed").AsError();
1717
+ }
1698
1718
  return store;
1699
1719
  });
1700
1720
  }
@@ -1729,60 +1749,41 @@ function toStoreRuntime(opts, ilogger) {
1729
1749
  registerStoreProtocol({
1730
1750
  protocol: "file:",
1731
1751
  data: async (logger) => {
1732
- const { FileDataGateway } = await import("./store-file-WD746RSY.js");
1752
+ const { FileDataGateway } = await import("./store-file-VJ6BI4II.js");
1733
1753
  return new FileDataGateway(logger);
1734
1754
  },
1735
1755
  meta: async (logger) => {
1736
- const { FileMetaGateway } = await import("./store-file-WD746RSY.js");
1756
+ const { FileMetaGateway } = await import("./store-file-VJ6BI4II.js");
1737
1757
  return new FileMetaGateway(logger);
1738
1758
  },
1739
1759
  wal: async (logger) => {
1740
- const { FileWALGateway } = await import("./store-file-WD746RSY.js");
1760
+ const { FileWALGateway } = await import("./store-file-VJ6BI4II.js");
1741
1761
  return new FileWALGateway(logger);
1742
1762
  },
1743
1763
  test: async (logger) => {
1744
- const { FileTestStore } = await import("./store-file-WD746RSY.js");
1764
+ const { FileTestStore } = await import("./store-file-VJ6BI4II.js");
1745
1765
  return new FileTestStore(logger);
1746
1766
  }
1747
1767
  });
1748
1768
  registerStoreProtocol({
1749
1769
  protocol: "indexdb:",
1750
1770
  data: async (logger) => {
1751
- const { IndexDBDataGateway } = await import("./store-indexdb-NG45BU3Q.js");
1771
+ const { IndexDBDataGateway } = await import("./store-indexdb-WLRSICCB.js");
1752
1772
  return new IndexDBDataGateway(logger);
1753
1773
  },
1754
1774
  meta: async (logger) => {
1755
- const { IndexDBMetaGateway } = await import("./store-indexdb-NG45BU3Q.js");
1775
+ const { IndexDBMetaGateway } = await import("./store-indexdb-WLRSICCB.js");
1756
1776
  return new IndexDBMetaGateway(logger);
1757
1777
  },
1758
1778
  wal: async (logger) => {
1759
- const { IndexDBMetaGateway } = await import("./store-indexdb-NG45BU3Q.js");
1779
+ const { IndexDBMetaGateway } = await import("./store-indexdb-WLRSICCB.js");
1760
1780
  return new IndexDBMetaGateway(logger);
1761
1781
  },
1762
1782
  test: async (logger) => {
1763
- const { IndexDBTestStore } = await import("./store-indexdb-NG45BU3Q.js");
1783
+ const { IndexDBTestStore } = await import("./store-indexdb-WLRSICCB.js");
1764
1784
  return new IndexDBTestStore(logger);
1765
1785
  }
1766
1786
  });
1767
- registerStoreProtocol({
1768
- protocol: "sqlite:",
1769
- data: async (logger) => {
1770
- const { SQLDataGateway } = await import("./store-sql-QVFNIGND.js");
1771
- return new SQLDataGateway(logger);
1772
- },
1773
- meta: async (logger) => {
1774
- const { SQLMetaGateway } = await import("./store-sql-QVFNIGND.js");
1775
- return new SQLMetaGateway(logger);
1776
- },
1777
- wal: async (logger) => {
1778
- const { SQLWalGateway } = await import("./store-sql-QVFNIGND.js");
1779
- return new SQLWalGateway(logger);
1780
- },
1781
- test: async (logger) => {
1782
- const { SQLTestStore } = await import("./store-sql-QVFNIGND.js");
1783
- return new SQLTestStore(logger);
1784
- }
1785
- });
1786
1787
 
1787
1788
  // src/crdt-helpers.ts
1788
1789
  function time(tag) {
@@ -2687,9 +2688,8 @@ var Database = class {
2687
2688
  });
2688
2689
  }
2689
2690
  async get(id) {
2690
- this.logger.Debug().Str("id", id).Msg("get-pre-ready");
2691
2691
  await this.ready();
2692
- this.logger.Debug().Str("id", id).Msg("get-post-ready");
2692
+ this.logger.Debug().Str("id", id).Msg("get");
2693
2693
  const got = await this._crdt.get(id).catch((e) => {
2694
2694
  throw new NotFoundError(`Not found: ${id} - ${e.message}`);
2695
2695
  });
@@ -2698,9 +2698,8 @@ var Database = class {
2698
2698
  return { ...doc, _id: id };
2699
2699
  }
2700
2700
  async put(doc) {
2701
- this.logger.Debug().Str("id", doc._id).Msg("put-pre-ready");
2702
2701
  await this.ready();
2703
- this.logger.Debug().Str("id", doc._id).Msg("put-post-ready");
2702
+ this.logger.Debug().Str("id", doc._id).Msg("put");
2704
2703
  const { _id, ...value } = doc;
2705
2704
  const docId = _id || uuidv7();
2706
2705
  const result = await this._writeQueue.push({
@@ -2710,36 +2709,40 @@ var Database = class {
2710
2709
  _id: docId
2711
2710
  }
2712
2711
  });
2713
- return { id: docId, clock: result?.head };
2712
+ return { id: docId, clock: result?.head, name: this.name };
2714
2713
  }
2715
2714
  async del(id) {
2716
2715
  await this.ready();
2716
+ this.logger.Debug().Str("id", id).Msg("del");
2717
2717
  const result = await this._writeQueue.push({ id, del: true });
2718
- return { id, clock: result?.head };
2718
+ return { id, clock: result?.head, name: this.name };
2719
2719
  }
2720
2720
  async changes(since = [], opts = {}) {
2721
2721
  await this.ready();
2722
+ this.logger.Debug().Any("since", since).Any("opts", opts).Msg("changes");
2722
2723
  const { result, head } = await this._crdt.changes(since, opts);
2723
2724
  const rows = result.map(({ id: key, value, del, clock }) => ({
2724
2725
  key,
2725
2726
  value: del ? { _id: key, _deleted: true } : { _id: key, ...value },
2726
2727
  clock
2727
2728
  }));
2728
- return { rows, clock: head };
2729
+ return { rows, clock: head, name: this.name };
2729
2730
  }
2730
2731
  async allDocs(opts = {}) {
2731
2732
  await this.ready();
2733
+ this.logger.Debug().Msg("allDocs");
2732
2734
  const { result, head } = await this._crdt.allDocs();
2733
2735
  const rows = result.map(({ id: key, value, del }) => ({
2734
2736
  key,
2735
2737
  value: del ? { _id: key, _deleted: true } : { _id: key, ...value }
2736
2738
  }));
2737
- return { rows, clock: head };
2739
+ return { rows, clock: head, name: this.name };
2738
2740
  }
2739
2741
  async allDocuments() {
2740
2742
  return this.allDocs();
2741
2743
  }
2742
2744
  subscribe(listener, updates) {
2745
+ this.logger.Debug().Bool("updates", updates).Msg("subscribe");
2743
2746
  if (updates) {
2744
2747
  if (!this._listening) {
2745
2748
  this._listening = true;
@@ -2761,6 +2764,7 @@ var Database = class {
2761
2764
  // todo if we add this onto dbs in fireproof.ts then we can make index.ts a separate package
2762
2765
  async query(field, opts = {}) {
2763
2766
  await this.ready();
2767
+ this.logger.Debug().Any("field", field).Any("opts", opts).Msg("query");
2764
2768
  const _crdt = this._crdt;
2765
2769
  const idx = typeof field === "string" ? index({ _crdt }, field) : index({ _crdt }, makeName(field.toString()), field);
2766
2770
  return await idx.query(opts);
@@ -2830,13 +2834,14 @@ function makeName(fnString) {
2830
2834
 
2831
2835
  // src/version.ts
2832
2836
  var PACKAGE_VERSION = Object.keys({
2833
- "0.0.0-dev": "xxxx"
2837
+ "0.19.8-dev-cra": "xxxx"
2834
2838
  })[0];
2835
2839
  export {
2836
2840
  CRDT,
2837
2841
  Database,
2838
2842
  Index,
2839
2843
  PACKAGE_VERSION,
2844
+ Result,
2840
2845
  blockstore_exports as blockstore,
2841
2846
  blockstore_exports as bs,
2842
2847
  ensureLogger,