Skip to content

Commit b33d713

Browse files
committed
feat: 🎸 allow to specify session ID in .load() call
1 parent 00af492 commit b33d713

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/json-crdt-repo/session/EditSessionFactory.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class EditSessionFactory {
4545
const repo = this.opts.repo;
4646
try {
4747
const {model, cursor} = await repo.get({id});
48-
const session = new EditSession(repo, id, model, cursor);
48+
const session = new EditSession(repo, id, model, cursor, opts.session);
4949
session.log.end.api.autoFlush();
5050
return session;
5151
} catch (error) {
@@ -56,7 +56,7 @@ export class EditSessionFactory {
5656
try {
5757
const {model, cursor} = await (typeof timeoutMs === 'number' ? timeout(timeoutMs, repo.pull(id)) : repo.pull(id));
5858
if (remote.throwIf === 'exists') throw new Error('EXISTS');
59-
const session = new EditSession(repo, id, model, cursor);
59+
const session = new EditSession(repo, id, model, cursor, opts.session);
6060
session.log.end.api.autoFlush();
6161
return session;
6262
} catch (error) {
@@ -67,7 +67,7 @@ export class EditSessionFactory {
6767
} else throw error;
6868
}
6969
}
70-
if (opts.make) return this.make({...opts.make, id});
70+
if (opts.make) return this.make({session: opts.session, ...opts.make, id});
7171
}
7272
throw error;
7373
}
@@ -114,6 +114,11 @@ export interface EditSessionLoadOpts {
114114
/** Thew new block schema, if any. */
115115
schema?: NodeBuilder;
116116

117+
/**
118+
* Internal unique session ID.
119+
*/
120+
session?: number;
121+
117122
remote?: {
118123
/**
119124
* Time in milliseconds to wait for the remote to respond. If the remote

0 commit comments

Comments
 (0)