+ | InitializedEvent
+ | WatchedEvent
+ | UnwatchedEvent
+ | PresenceChangedEvent
;
+
+/**
+ * `DocEventsForReplay` is a list of events used to replay a document.
+ */
+export type DocEventsForReplay = Array;
+
+/**
+ * `isDocEventForReplay` checks if an event can be used to replay a document.
+ */
+export function isDocEventForReplay(
+ event: DocEvent,
+): event is DocEventForReplay {
+ const types = [
+ DocEventType.StatusChanged,
+ DocEventType.Snapshot,
+ DocEventType.LocalChange,
+ DocEventType.RemoteChange,
+ DocEventType.Initialized,
+ DocEventType.Watched,
+ DocEventType.Unwatched,
+ DocEventType.PresenceChanged,
+ ];
+
+ return types.includes(event.type);
+}
+
+/**
+ * `isDocEventsForReplay` checks if a list of events can be used to replay a document.
+ */
+export function isDocEventsForReplay(
+ events: Array,
+): events is DocEventsForReplay {
+ return events.every(isDocEventForReplay);
+}
diff --git a/packages/sdk/src/document/document.ts b/packages/sdk/src/document/document.ts
index 92aa1a39f..025b9572a 100644
--- a/packages/sdk/src/document/document.ts
+++ b/packages/sdk/src/document/document.ts
@@ -228,12 +228,10 @@ export type DocEvent =
| AuthErrorEvent;
/**
- * `TransactionEvent` represents document events that occur within
+ * `DocEvents` represents document events that occur within
* a single transaction (e.g., doc.update).
*/
-export type TransactionEvent
= Array<
- DocEvent
->;
+export type DocEvents
= Array>;
/**
* @internal
@@ -449,7 +447,7 @@ type DocEventCallbackMap = {
broadcast: NextFn;
'local-broadcast': NextFn;
'auth-error': NextFn;
- all: NextFn>;
+ all: NextFn>;
};
export type DocEventTopic = keyof DocEventCallbackMap;
export type DocEventCallback =
@@ -633,8 +631,8 @@ export class Document {
presences: Map;
};
- private eventStream: Observable>;
- private eventStreamObserver!: Observer>;
+ private eventStream: Observable>;
+ private eventStreamObserver!: Observer>;
/**
* `onlineClients` is a set of client IDs that are currently online.
@@ -673,7 +671,7 @@ export class Document {
this.checkpoint = InitialCheckpoint;
this.localChanges = [];
- this.eventStream = createObservable>((observer) => {
+ this.eventStream = createObservable>((observer) => {
this.eventStreamObserver = observer;
});
@@ -771,7 +769,7 @@ export class Document {
// 03. Publish the document change event.
// NOTE(chacha912): Check opInfos, which represent the actually executed operations.
- const event: TransactionEvent = [];
+ const event: DocEvents
= [];
if (opInfos.length > 0) {
event.push({
type: DocEventType.LocalChange,
@@ -1168,7 +1166,7 @@ export class Document {
* `publish` triggers an event in this document, which can be received by
* callback functions from document.subscribe().
*/
- public publish(event: TransactionEvent) {
+ public publish(event: DocEvents
) {
if (this.eventStreamObserver) {
this.eventStreamObserver.next(event);
}
@@ -1522,7 +1520,7 @@ export class Document {
this.ensureClone();
change.execute(this.clone!.root, this.clone!.presences, source);
- const event: TransactionEvent = [];
+ const event: DocEvents
= [];
const actorID = change.getID().getActorID();
if (change.hasPresenceChange() && this.onlineClients.has(actorID)) {
const presenceChange = change.getPresenceChange()!;
@@ -1718,9 +1716,9 @@ export class Document {
}
/**
- * `applyDocEvent` applies the docEvent into this document.
+ * `applyDocEventForReplay` applies the given event into this document.
*/
- public applyDocEvent(event: DocEvent) {
+ public applyDocEventForReplay(event: Devtools.DocEventForReplay
) {
if (event.type === DocEventType.StatusChanged) {
this.applyStatus(event.value.status);
if (event.value.status === DocStatus.Attached) {
@@ -1782,11 +1780,11 @@ export class Document {
}
/**
- * `applyTransactionEvent` applies the given TransactionEvent into this document.
+ * `applyDocEventsForReplay` applies the given events into this document.
*/
- public applyTransactionEvent(event: TransactionEvent) {
+ public applyDocEventsForReplay(event: Array>) {
for (const docEvent of event) {
- this.applyDocEvent(docEvent);
+ this.applyDocEventForReplay(docEvent);
}
}
@@ -2034,7 +2032,7 @@ export class Document {
this.localChanges.push(change);
this.changeID = change.getID();
const actorID = this.changeID.getActorID();
- const event: TransactionEvent = [];
+ const event: DocEvents
= [];
if (opInfos.length > 0) {
event.push({
type: DocEventType.LocalChange,
@@ -2133,7 +2131,7 @@ export class Document {
this.localChanges.push(change);
this.changeID = change.getID();
const actorID = this.changeID.getActorID();
- const event: TransactionEvent = [];
+ const event: DocEvents
= [];
if (opInfos.length > 0) {
event.push({
type: DocEventType.LocalChange,
diff --git a/packages/sdk/src/yorkie.ts b/packages/sdk/src/yorkie.ts
index ae1aff558..8abcb9ccc 100644
--- a/packages/sdk/src/yorkie.ts
+++ b/packages/sdk/src/yorkie.ts
@@ -44,8 +44,9 @@ export {
DocSyncStatus,
DocStatus,
type Indexable,
+ type Json,
type DocEvent,
- type TransactionEvent,
+ type DocEvents,
Document,
type ChangeInfo,
} from '@yorkie-js-sdk/src/document/document';