@fireproof/core 0.20.0-dev-preview-13 → 0.20.0-dev-preview-14

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -240,7 +240,7 @@ interface SerdeGateway {
240
240
  put<T>(sthis: SuperThis, url: URI, body: FPEnvelope<T>, loader?: Loadable): Promise<VoidResult>;
241
241
  get<S>(sthis: SuperThis, url: URI, loader?: Loadable): Promise<SerdeGetResult<S>>;
242
242
  delete(sthis: SuperThis, url: URI, loader?: Loadable): Promise<VoidResult>;
243
- subscribe?(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<UnsubscribeResult>;
243
+ subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<UnsubscribeResult>;
244
244
  getPlain(sthis: SuperThis, url: URI, key: string, loader?: Loadable): Promise<Result<Uint8Array>>;
245
245
  destroy(sthis: SuperThis, baseUrl: URI, loader?: Loadable): Promise<VoidResult>;
246
246
  }
@@ -1538,8 +1538,10 @@ declare class DefSerdeGateway implements SerdeGateway {
1538
1538
  start(sthis: SuperThis, baseURL: URI): Promise<Result<URI>>;
1539
1539
  buildUrl(sthis: SuperThis, baseUrl: URI, key: string): Promise<Result<URI>>;
1540
1540
  close(sthis: SuperThis, uri: URI): Promise<Result<void>>;
1541
+ private subscribeFn;
1541
1542
  put<T>(sthis: SuperThis, url: URI, env: FPEnvelope<T>): Promise<Result<void>>;
1542
1543
  get<S>(sthis: SuperThis, url: URI): Promise<SerdeGetResult<S>>;
1544
+ subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>): Promise<Result<() => void>>;
1543
1545
  delete(sthis: SuperThis, url: URI): Promise<Result<void>>;
1544
1546
  destroy(sthis: SuperThis, baseURL: URI): Promise<Result<void>>;
1545
1547
  getPlain(sthis: SuperThis, iurl: URI, key: string): Promise<Result<Uint8Array<ArrayBufferLike>, Error>>;
package/index.d.ts CHANGED
@@ -240,7 +240,7 @@ interface SerdeGateway {
240
240
  put<T>(sthis: SuperThis, url: URI, body: FPEnvelope<T>, loader?: Loadable): Promise<VoidResult>;
241
241
  get<S>(sthis: SuperThis, url: URI, loader?: Loadable): Promise<SerdeGetResult<S>>;
242
242
  delete(sthis: SuperThis, url: URI, loader?: Loadable): Promise<VoidResult>;
243
- subscribe?(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<UnsubscribeResult>;
243
+ subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<UnsubscribeResult>;
244
244
  getPlain(sthis: SuperThis, url: URI, key: string, loader?: Loadable): Promise<Result<Uint8Array>>;
245
245
  destroy(sthis: SuperThis, baseUrl: URI, loader?: Loadable): Promise<VoidResult>;
246
246
  }
@@ -1538,8 +1538,10 @@ declare class DefSerdeGateway implements SerdeGateway {
1538
1538
  start(sthis: SuperThis, baseURL: URI): Promise<Result<URI>>;
1539
1539
  buildUrl(sthis: SuperThis, baseUrl: URI, key: string): Promise<Result<URI>>;
1540
1540
  close(sthis: SuperThis, uri: URI): Promise<Result<void>>;
1541
+ private subscribeFn;
1541
1542
  put<T>(sthis: SuperThis, url: URI, env: FPEnvelope<T>): Promise<Result<void>>;
1542
1543
  get<S>(sthis: SuperThis, url: URI): Promise<SerdeGetResult<S>>;
1544
+ subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>): Promise<Result<() => void>>;
1543
1545
  delete(sthis: SuperThis, url: URI): Promise<Result<void>>;
1544
1546
  destroy(sthis: SuperThis, baseURL: URI): Promise<Result<void>>;
1545
1547
  getPlain(sthis: SuperThis, iurl: URI, key: string): Promise<Result<Uint8Array<ArrayBufferLike>, Error>>;
package/index.js CHANGED
@@ -1029,9 +1029,6 @@ var MemoryGateway = class {
1029
1029
  // src/runtime/gateways/def-serde-gateway.ts
1030
1030
  import { Result as Result7 } from "@adviser/cement";
1031
1031
 
1032
- // src/runtime/gateways/fp-envelope-serialize.ts
1033
- import { exception2Result as exception2Result2, Result as Result6 } from "@adviser/cement";
1034
-
1035
1032
  // src/blockstore/fp-envelope.ts
1036
1033
  import { Result as Result5 } from "@adviser/cement";
1037
1034
  var FPEnvelopeType = /* @__PURE__ */ ((FPEnvelopeType2) => {
@@ -1049,6 +1046,7 @@ function File2FPMsg(fpfile) {
1049
1046
  }
1050
1047
 
1051
1048
  // src/runtime/gateways/fp-envelope-serialize.ts
1049
+ import { exception2Result as exception2Result2, Result as Result6 } from "@adviser/cement";
1052
1050
  import { decodeEventBlock, EventBlock } from "@fireproof/vendor/@web3-storage/pail/clock";
1053
1051
  import { base64pad } from "multiformats/bases/base64";
1054
1052
  import { CID } from "multiformats";
@@ -1202,6 +1200,7 @@ async function fpDeserialize(sthis, url, intoRaw, pdecoder) {
1202
1200
  // src/runtime/gateways/def-serde-gateway.ts
1203
1201
  var DefSerdeGateway = class {
1204
1202
  constructor(gw) {
1203
+ this.subscribeFn = /* @__PURE__ */ new Map();
1205
1204
  this.gw = gw;
1206
1205
  }
1207
1206
  start(sthis, baseURL) {
@@ -1216,13 +1215,38 @@ var DefSerdeGateway = class {
1216
1215
  async put(sthis, url, env) {
1217
1216
  const rUint8 = await fpSerialize(sthis, env);
1218
1217
  if (rUint8.isErr()) return rUint8;
1219
- return this.gw.put(url, rUint8.Ok(), sthis);
1218
+ const ret = this.gw.put(url, rUint8.Ok(), sthis);
1219
+ if (env.type === "meta" /* META */) {
1220
+ if (this.subscribeFn.has(url.toString())) {
1221
+ this.subscribeFn.get(url.toString())(env);
1222
+ }
1223
+ }
1224
+ return ret;
1220
1225
  }
1221
1226
  async get(sthis, url) {
1222
1227
  const res = await this.gw.get(url, sthis);
1223
1228
  if (res.isErr()) return Result7.Err(res.Err());
1224
1229
  return fpDeserialize(sthis, url, res);
1225
1230
  }
1231
+ async subscribe(sthis, url, callback) {
1232
+ if (!this.gw.subscribe) {
1233
+ this.subscribeFn.set(url.toString(), callback);
1234
+ return Result7.Ok(() => {
1235
+ this.subscribeFn.delete(url.toString());
1236
+ });
1237
+ }
1238
+ const unreg = await this.gw.subscribe(
1239
+ url,
1240
+ (raw2) => {
1241
+ fpDeserialize(sthis, url, Result7.Ok(raw2)).then((res) => {
1242
+ if (res.isErr()) return;
1243
+ callback(res.Ok());
1244
+ });
1245
+ },
1246
+ sthis
1247
+ );
1248
+ return unreg;
1249
+ }
1226
1250
  async delete(sthis, url) {
1227
1251
  return this.gw.delete(url, sthis);
1228
1252
  }
@@ -4613,7 +4637,7 @@ __export(file_exports, {
4613
4637
 
4614
4638
  // src/version.ts
4615
4639
  var PACKAGE_VERSION = Object.keys({
4616
- "0.20.0-dev-preview-13": "xxxx"
4640
+ "0.20.0-dev-preview-14": "xxxx"
4617
4641
  })[0];
4618
4642
  export {
4619
4643
  CRDTImpl,