diff --git a/dist/provider.d.ts b/dist/provider.d.ts
index 7a81faf..9610feb 100644
--- a/dist/provider.d.ts
+++ b/dist/provider.d.ts
@@ -1,6 +1,6 @@
///
import { FirebaseApp } from "@firebase/app";
-import { Firestore } from "@firebase/firestore";
+import { Firestore, Bytes } from "@firebase/firestore";
import * as Y from "yjs";
import { ObservableV2 } from "lib0/observable";
import * as awarenessProtocol from "y-protocols/awareness";
@@ -9,6 +9,7 @@ export interface Parameters {
firebaseApp: FirebaseApp;
ydoc: Y.Doc;
path: string;
+ docMapper?: (bytes: Bytes) => object;
maxUpdatesThreshold?: number;
maxWaitTime?: number;
maxWaitFirestoreTime?: number;
@@ -43,6 +44,7 @@ export declare class FireProvider extends ObservableV2 {
peersReceivers: Set;
peersSenders: Set;
peersRTC: PeersRTC;
+ documentMapper: (bytes: Bytes) => object;
cache: Uint8Array | null;
maxCacheUpdates: number;
cacheUpdateCount: number;
@@ -91,7 +93,7 @@ export declare class FireProvider extends ObservableV2 {
consoleHandler: (message: any, data?: any) => void;
destroy: () => void;
kill: (keepReadOnly?: boolean) => void;
- constructor({ firebaseApp, ydoc, path, maxUpdatesThreshold, maxWaitTime, maxWaitFirestoreTime, }: Parameters);
+ constructor({ firebaseApp, ydoc, path, docMapper, maxUpdatesThreshold, maxWaitTime, maxWaitFirestoreTime, }: Parameters);
}
export {};
//# sourceMappingURL=provider.d.ts.map
\ No newline at end of file
diff --git a/dist/provider.d.ts.map b/dist/provider.d.ts.map
index f0fce07..aeeb00e 100644
--- a/dist/provider.d.ts.map
+++ b/dist/provider.d.ts.map
@@ -1 +1 @@
-{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAEL,SAAS,EAMV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,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,aACF,MAAM,EAAE,YACR,IAAI,MAAM,CAAC,YACX,OAAO,cAuCjB;IAEF,eAAe;cAKP,OAAO;iBACJ,OAAO;cACV,UAAU,GAAG,IAAI;eAoBvB;IAEF,eAAe,sBAiBb;IAEF,oBAAoB,aAelB;IAEF,SAAS,SAAU,MAAM,UASvB;IAEF,WAAW;cAA8B,OAAO;gBAAU,UAAU;eA4BlE;IAEF,aAAa,WAAY,UAAU,UAAU,GAAG,UAyB9C;IAEF,sBAAsB;eAKR,MAAM,EAAE;iBAAW,MAAM,EAAE;iBAAW,MAAM,EAAE;eAClD,OAAO,UAWf;IAEF,cAAc,YAAa,GAAG,SAAQ,GAAG,UAQvC;IAIF,OAAO,aAKL;IAEF,IAAI,kBAAkB,OAAO,UA+B3B;gBAEU,EACV,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,mBAAmB,EACnB,WAAW,EACX,oBAAoB,GACrB,EAAE,UAAU;CAiBd"}
\ No newline at end of file
diff --git a/dist/provider.js b/dist/provider.js
index 94014e6..a90dc73 100644
--- a/dist/provider.js
+++ b/dist/provider.js
@@ -30,7 +30,7 @@ export class FireProvider extends ObservableV2 {
get clientTimeOffset() {
return this.timeOffset;
}
- constructor({ firebaseApp, ydoc, path, maxUpdatesThreshold, maxWaitTime, maxWaitFirestoreTime, }) {
+ constructor({ firebaseApp, ydoc, path, docMapper, maxUpdatesThreshold, maxWaitTime, maxWaitFirestoreTime, }) {
super();
this.timeOffset = 0; // offset to server time in mili seconds
this.clients = [];
@@ -40,6 +40,7 @@ export class FireProvider extends ObservableV2 {
receivers: {},
senders: {},
};
+ this.documentMapper = (bytes) => ({ content: bytes });
this.maxCacheUpdates = 20;
this.cacheUpdateCount = 0;
this.maxRTCWait = 100;
@@ -237,7 +238,7 @@ export class FireProvider extends ObservableV2 {
try {
// current document to firestore
const ref = doc(this.db, this.documentPath);
- yield setDoc(ref, { content: Bytes.fromUint8Array(Y.encodeStateAsUpdate(this.doc)) }, { merge: true });
+ yield setDoc(ref, this.documentMapper(Bytes.fromUint8Array(Y.encodeStateAsUpdate(this.doc))), { merge: true });
this.deleteLocal(); // We have successfully saved to Firestore, empty indexedDb for now
}
catch (error) {
@@ -382,6 +383,8 @@ export class FireProvider extends ObservableV2 {
this.db = getFirestore(this.firebaseApp);
this.doc = ydoc;
this.documentPath = path;
+ if (docMapper)
+ this.documentMapper = docMapper;
if (maxUpdatesThreshold)
this.maxCacheUpdates = maxUpdatesThreshold;
if (maxWaitTime)
diff --git a/package.json b/package.json
index ee58e85..3e5bc24 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "y-fire",
- "version": "2.1.0",
+ "version": "2.1.1",
"description": "A firebase (firestore) provider for Yjs",
"main": "dist/index.js",
"types": "dist/index.d.ts",