@fireproof/core 0.19.100 → 0.19.102

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/index.d.cts CHANGED
@@ -232,12 +232,15 @@ declare class BaseBlockstore implements BlockFetcher {
232
232
  ready(): Promise<void>;
233
233
  close(): Promise<void>;
234
234
  destroy(): Promise<void>;
235
+ compact(): Promise<void>;
235
236
  readonly logger: Logger;
236
237
  constructor(ebOpts?: BlockstoreOpts);
237
238
  get<T, C extends number, A extends number, V extends Version>(cid: AnyAnyLink): Promise<Block$1<T, C, A, V> | undefined>;
238
239
  put(cid: AnyAnyLink, block: Uint8Array): Promise<void>;
239
240
  lastTxMeta?: unknown;
240
241
  transaction<M extends TransactionMeta>(fn: (t: CarTransaction) => Promise<M>, _opts?: CarTransactionOpts): Promise<TransactionWrapper<M>>;
242
+ openTransaction(opts?: CarTransactionOpts): CarTransaction;
243
+ commitTransaction<M extends TransactionMeta>(t: CarTransaction, done: M, opts: CarTransactionOpts): Promise<TransactionWrapper<M>>;
241
244
  entries(): AsyncIterableIterator<AnyBlock>;
242
245
  }
243
246
  declare class EncryptedBlockstore extends BaseBlockstore {
@@ -948,6 +951,7 @@ declare class CRDTClock<T extends DocTypes> {
948
951
  readonly emptyWatchers: Set<() => void>;
949
952
  readonly blockstore: BaseBlockstore;
950
953
  readonly applyHeadQueue: ApplyHeadQueue<T>;
954
+ transaction?: CarTransaction;
951
955
  readonly _ready: ResolveOnce<void>;
952
956
  ready(): Promise<void>;
953
957
  close(): Promise<void>;
package/index.d.ts CHANGED
@@ -232,12 +232,15 @@ declare class BaseBlockstore implements BlockFetcher {
232
232
  ready(): Promise<void>;
233
233
  close(): Promise<void>;
234
234
  destroy(): Promise<void>;
235
+ compact(): Promise<void>;
235
236
  readonly logger: Logger;
236
237
  constructor(ebOpts?: BlockstoreOpts);
237
238
  get<T, C extends number, A extends number, V extends Version>(cid: AnyAnyLink): Promise<Block$1<T, C, A, V> | undefined>;
238
239
  put(cid: AnyAnyLink, block: Uint8Array): Promise<void>;
239
240
  lastTxMeta?: unknown;
240
241
  transaction<M extends TransactionMeta>(fn: (t: CarTransaction) => Promise<M>, _opts?: CarTransactionOpts): Promise<TransactionWrapper<M>>;
242
+ openTransaction(opts?: CarTransactionOpts): CarTransaction;
243
+ commitTransaction<M extends TransactionMeta>(t: CarTransaction, done: M, opts: CarTransactionOpts): Promise<TransactionWrapper<M>>;
241
244
  entries(): AsyncIterableIterator<AnyBlock>;
242
245
  }
243
246
  declare class EncryptedBlockstore extends BaseBlockstore {
@@ -948,6 +951,7 @@ declare class CRDTClock<T extends DocTypes> {
948
951
  readonly emptyWatchers: Set<() => void>;
949
952
  readonly blockstore: BaseBlockstore;
950
953
  readonly applyHeadQueue: ApplyHeadQueue<T>;
954
+ transaction?: CarTransaction;
951
955
  readonly _ready: ResolveOnce<void>;
952
956
  ready(): Promise<void>;
953
957
  close(): Promise<void>;
package/index.global.js CHANGED
@@ -26050,6 +26050,8 @@ You can use close({ resize: true }) to resize header`);
26050
26050
  }
26051
26051
  async destroy() {
26052
26052
  }
26053
+ async compact() {
26054
+ }
26053
26055
  async get(cid) {
26054
26056
  if (!cid) throw this.logger.Error().Msg("required cid").AsError();
26055
26057
  for (const f of this.transactions) {
@@ -26068,6 +26070,21 @@ You can use close({ resize: true }) to resize header`);
26068
26070
  this.lastTxMeta = done;
26069
26071
  return { t, meta: done };
26070
26072
  }
26073
+ openTransaction(opts = { add: true, noLoader: false }) {
26074
+ return new CarTransaction(this, opts);
26075
+ }
26076
+ async commitTransaction(t, done, opts) {
26077
+ if (!this.loader) throw this.logger.Error().Msg("loader required to commit").AsError();
26078
+ const cars = await this.loader?.commit(t, done, opts);
26079
+ if (this.ebOpts.autoCompact && this.loader.carLog.length > this.ebOpts.autoCompact) {
26080
+ setTimeout(() => void this.compact(), 10);
26081
+ }
26082
+ if (cars) {
26083
+ this.transactions.delete(t);
26084
+ return { meta: done, cars, t };
26085
+ }
26086
+ throw this.logger.Error().Msg("failed to commit car files").AsError();
26087
+ }
26071
26088
  async *entries() {
26072
26089
  const seen = /* @__PURE__ */ new Set();
26073
26090
  for (const t of this.transactions) {
@@ -30140,21 +30157,23 @@ You can use close({ resize: true }) to resize header`);
30140
30157
  throw this.logger.Error().Msg("missing blockstore").AsError();
30141
30158
  }
30142
30159
  await validateBlocks(this.logger, newHead, this.blockstore);
30143
- const { meta } = await this.blockstore.transaction(
30144
- async (tblocks) => {
30145
- const advancedHead = await advanceBlocks(this.logger, newHead, tblocks, this.head);
30146
- const result = await root(tblocks, advancedHead);
30147
- for (const { cid, bytes } of [
30148
- ...result.additions
30149
- // ...result.removals
30150
- ]) {
30151
- tblocks.putSync(cid, bytes);
30152
- }
30153
- return { head: advancedHead };
30154
- },
30155
- { noLoader, add: false }
30156
- );
30157
- this.setHead(meta.head);
30160
+ if (!this.transaction) {
30161
+ this.transaction = this.blockstore.openTransaction({ noLoader, add: false });
30162
+ }
30163
+ const tblocks = this.transaction;
30164
+ const advancedHead = await advanceBlocks(this.logger, newHead, tblocks, this.head);
30165
+ const result = await root(tblocks, advancedHead);
30166
+ for (const { cid, bytes } of [
30167
+ ...result.additions
30168
+ // ...result.removals
30169
+ ]) {
30170
+ tblocks.putSync(cid, bytes);
30171
+ }
30172
+ if (!noLoader) {
30173
+ await this.blockstore.commitTransaction(tblocks, { head: advancedHead }, { add: false, noLoader });
30174
+ this.transaction = void 0;
30175
+ }
30176
+ this.setHead(advancedHead);
30158
30177
  }
30159
30178
  };
30160
30179
  function sortClockHead(clockHead) {
@@ -30529,7 +30548,7 @@ You can use close({ resize: true }) to resize header`);
30529
30548
 
30530
30549
  // src/version.ts
30531
30550
  var PACKAGE_VERSION = Object.keys({
30532
- "0.19.100": "xxxx"
30551
+ "0.19.102": "xxxx"
30533
30552
  })[0];
30534
30553
  return __toCommonJS(src_exports6);
30535
30554
  })();