Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make snapshotTopic configurable from wksp.create() #11

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/adaptors/yjs-ndn-adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class NdnSvsAdaptor {
// Verify this part if there's a change in naming convention.
// NOTE: Currently naming convention is hard-coded. May need organizing.
// WARNING: It does not support multiple Yjs documents in the same app.
const snapshotPrefix = this.syncAgent.appPrefix.append('32=snapshot');
const snapshotPrefix = this.syncAgent.appPrefix.append('32=' + this.snapshotTopic);
// New SVS encodings
const snapshotName = snapshotPrefix.append(new Component(Version.type, encodedSV));

Expand Down Expand Up @@ -156,7 +156,7 @@ export class NdnSvsAdaptor {

// NOTE: The following code depend on snapshot naming convention to work.
// Verify this part if there's a change in naming convention.
const snapshotPrefix = this.syncAgent.appPrefix.append('32=snapshot');
const snapshotPrefix = this.syncAgent.appPrefix.append('32=' + this.snapshotTopic);

// NOTE: The following code depend on snapshot naming convention to work.
// Verify this part if there's a change in naming convention.
Expand Down
5 changes: 4 additions & 1 deletion src/sync-agent/sync-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class SyncAgent implements AsyncDisposable {
readonly latestOnly: LatestOnlyDelivery,
readonly onReset?: () => void,
readonly groupKey?: CryptoKey,
readonly snapshotTopic: string = 'snapshot',
) {
atLeastOnce.onReset = () => this.onResetTriggered();
latestOnly.onReset = () => this.onResetTriggered();
Expand Down Expand Up @@ -356,7 +357,7 @@ export class SyncAgent implements AsyncDisposable {

// NOTE: The following code depend on snapshot naming convention to work.
// Verify this part if there's a change in naming convention.
if (intName.get(this.appPrefix.length)?.equals(Component.from('32=snapshot'))) {
if (intName.get(this.appPrefix.length)?.equals(Component.from('32=' + this.snapshotTopic))) {
const wire = await this.persistStorage.get(intName.toString());
if (wire === undefined || wire.length === 0) {
// console.warn(`A remote peer is fetching a non-existing object: ${intName.toString()}`);
Expand Down Expand Up @@ -460,6 +461,7 @@ export class SyncAgent implements AsyncDisposable {
verifier: Verifier,
onReset?: () => void,
groupKeyBits?: Uint8Array,
snapshotTopic?: string,
) {
const tempStorage = new InMemoryStorage();
// Note: we need the signer name to be /[appPrefix]/<nodeId>/KEY/<keyID>
Expand Down Expand Up @@ -510,6 +512,7 @@ export class SyncAgent implements AsyncDisposable {
latestOnly,
onReset,
groupKey,
snapshotTopic,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are passing an undefined to a default parameter. Though it works in JS/TS, I think this style may cause confusion. How about moving the default argument to create().

);
resolver!((content, id) => ret.onUpdate(content, id));
return ret;
Expand Down
3 changes: 3 additions & 0 deletions src/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Workspace implements AsyncDisposable {
useBundler?: boolean;
groupKeyBits?: Uint8Array;
snapshotInterval?: number;
snapshotTopic?: string;
}) {
// Always init a new one, and then load.
if (opts.createNewDoc) {
Expand All @@ -47,6 +48,7 @@ export class Workspace implements AsyncDisposable {
opts.verifier,
opts.onReset,
opts.groupKeyBits,
opts.snapshotTopic ?? 'snapshot',
);

// Root doc using CRDT and Sync
Expand All @@ -56,6 +58,7 @@ export class Workspace implements AsyncDisposable {
'doc',
opts.useBundler ?? false,
opts.snapshotInterval ?? 100,
opts.snapshotTopic ?? 'snapshot',
);
const yjsSnapshotMgr = new YjsStateManager(
() => encodeSyncState(syncAgent!.getUpdateSyncSV()),
Expand Down