Skip to content

Commit

Permalink
Merge pull request #7 from podraven/2.1.1
Browse files Browse the repository at this point in the history
Updated dist files for docMapper update
  • Loading branch information
deathg0d authored Oct 7, 2024
2 parents 937b77e + 680e136 commit d958f44
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions dist/provider.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node" />
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";
Expand All @@ -9,6 +9,7 @@ export interface Parameters {
firebaseApp: FirebaseApp;
ydoc: Y.Doc;
path: string;
docMapper?: (bytes: Bytes) => object;
maxUpdatesThreshold?: number;
maxWaitTime?: number;
maxWaitFirestoreTime?: number;
Expand Down Expand Up @@ -43,6 +44,7 @@ export declare class FireProvider extends ObservableV2<any> {
peersReceivers: Set<string>;
peersSenders: Set<string>;
peersRTC: PeersRTC;
documentMapper: (bytes: Bytes) => object;
cache: Uint8Array | null;
maxCacheUpdates: number;
cacheUpdateCount: number;
Expand Down Expand Up @@ -91,7 +93,7 @@ export declare class FireProvider extends ObservableV2<any> {
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
2 changes: 1 addition & 1 deletion dist/provider.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions dist/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit d958f44

Please sign in to comment.