@grapecity-software/js-collaboration-ot 18.2.4 → 19.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export interface IOp<T = unknown> {
5
5
  create?: ICreateComponent;
6
6
  op?: T;
7
7
  del?: boolean;
8
+ restore?: IRestoreComponent;
8
9
  }
9
10
 
10
11
  export interface ICreateComponent {
@@ -12,6 +13,11 @@ export interface ICreateComponent {
12
13
  data: unknown;
13
14
  }
14
15
 
16
+ export interface IRestoreComponent {
17
+ v: number;
18
+ data: unknown;
19
+ }
20
+
15
21
  export interface ISnapshot<S = unknown> {
16
22
  id: string;
17
23
  v: number;
@@ -29,14 +35,21 @@ export interface ISnapshotFragmentsChanges<S = unknown> {
29
35
  createFragments?: { [key: string]: S };
30
36
  updateFragments?: { [key: string]: S };
31
37
  deleteFragments?: string[];
38
+ /**
39
+ * Complete delete of all snapshot fragments.
40
+ */
32
41
  deleteSnapshot?: boolean;
42
+ /**
43
+ * Complete replacement of all snapshot fragments.
44
+ */
45
+ setSnapshotFragments?: { [key: string]: S };
33
46
  }
34
47
 
35
48
  export interface ISnapshotFragmentsRequest<S = unknown> {
36
- getFragment(id: string): Promise<S | undefined>;
37
- createFragment(id: string, data: S): void;
38
- updateFragment(id: string, data: S): void;
39
- deleteFragment(id: string): void;
49
+ getFragment(id: string): Promise<S | null>;
50
+ createFragment(id: string, data: S): Promise<void>;
51
+ updateFragment(id: string, data: S): Promise<void>;
52
+ deleteFragment(id: string): Promise<void>;
40
53
  }
41
54
 
42
55
  export interface ISnapshotMeta {
@@ -56,6 +69,7 @@ export interface IRequestMessage<T> {
56
69
  create?: ICreateComponent;
57
70
  op?: T;
58
71
  del?: boolean;
72
+ restore?: IRestoreComponent;
59
73
  error?: IErrorData;
60
74
  }
61
75
 
@@ -74,6 +88,7 @@ export interface IReplyMessage<S, T> {
74
88
  create?: ICreateComponent;
75
89
  op?: T;
76
90
  del?: boolean;
91
+ restore?: IRestoreComponent;
77
92
  error?: IErrorData;
78
93
  data?: ISnapshot<S>;
79
94
  }
@@ -101,6 +116,7 @@ export enum MessageActions {
101
116
  * ```
102
117
  */
103
118
  export declare function documentFeature<S = unknown, T = unknown>(service?: DocumentServices<S, T>): IFeature;
119
+
104
120
  /**
105
121
  * Provides document services for collaborative operational transformation.
106
122
  * @template S - The type of snapshot data.
@@ -213,6 +229,10 @@ export interface IDocMiddlewareContext<S, T> {
213
229
  * Context for initiating the submission of an operation.
214
230
  */
215
231
  submit: IDocSubmitMiddlewareContext<S, T>;
232
+ /**
233
+ * Context for applying an operation to the snapshot.
234
+ */
235
+ apply: IDocSubmitMiddlewareContext<S, T>;
216
236
  /**
217
237
  * Context for preparing an operation to be committed to the database.
218
238
  */
@@ -221,18 +241,6 @@ export interface IDocMiddlewareContext<S, T> {
221
241
  * Context for after an operation has been successfully written to the database.
222
242
  */
223
243
  afterWrite: IDocSubmitMiddlewareContext<S, T>;
224
- /**
225
- * Context for initiating the submission of a snapshot.
226
- */
227
- submitSnapshot: IDocSubmitSnapshotMiddlewareContext<S, T>;
228
- /**
229
- * Context for applying an operation to the snapshot.
230
- */
231
- apply: IDocSubmitSnapshotMiddlewareContext<S, T>;
232
- /**
233
- * Context for preparing a snapshot to be committed to the database.
234
- */
235
- commitSnapshot: IDocSubmitSnapshotMiddlewareContext<S, T>;
236
244
  /**
237
245
  * Context for when one or more snapshots are loaded from the database for fetch or subscribe operations.
238
246
  */
@@ -292,13 +300,6 @@ export interface IDocSubmitMiddlewareContext<S, T> extends IDocMiddlewareContext
292
300
  request: SubmitRequest<S, T>;
293
301
  }
294
302
 
295
- /**
296
- * Context for submitting a snapshot in document middleware.
297
- */
298
- export interface IDocSubmitSnapshotMiddlewareContext<S, T> extends IDocMiddlewareContextBase {
299
- request: SubmitSnapshotRequest<S, T>;
300
- }
301
-
302
303
  /**
303
304
  * Context for reading snapshots in document middleware.
304
305
  */
@@ -340,10 +341,6 @@ export declare class ReadSnapshotsRequest<S> {
340
341
  rejectSnapshotReadSilent(snapshot: ISnapshot<S>, errorMessage: string): void;
341
342
  }
342
343
 
343
- export interface IAfterCommitCallback<S, T> {
344
- (request: SubmitRequest<S, T>): void;
345
- }
346
-
347
344
  export declare class SubmitRequest<S, T> {
348
345
  doc: DocumentServices<S, T>;
349
346
  context: IContext;
@@ -354,38 +351,8 @@ export declare class SubmitRequest<S, T> {
354
351
  maxRetries?: number;
355
352
  start: number;
356
353
  document: IDocument | null;
357
- ops: IOp<T>[];
358
- }
359
-
360
- /**
361
- * The trigger source of submit snapshot.
362
- */
363
- export enum SubmitSnapshotTrigger {
364
- submitOp = 'submitOp',
365
- fetchSnapshot = 'fetchSnapshot',
366
- manual = 'manual',
367
- }
368
-
369
- export interface ISubmitSnapshotContext<T> extends IContext {
370
- trigger?: SubmitSnapshotTrigger;
371
- op?: IOp<T>;
372
- }
373
-
374
- export declare class SubmitSnapshotRequest<S, T> {
375
- doc: DocumentServices<S, T>;
376
- id: string;
377
- context: ISubmitSnapshotContext<T>;
378
- fromVersion: number;
379
- toVersion: number;
380
- ops: IOp<T>[] | null;
381
- extra: unknown;
382
- retries: number;
383
- maxRetries?: number;
384
- start: number;
385
- saveSnapshot: boolean | null;
386
- saveMilestoneSnapshot: boolean | null;
387
- document: IDocument | null;
388
354
  snapshot: ICommitSnapshot<S> | null;
355
+ ops: IOp<T>[];
389
356
  }
390
357
 
391
358
  /**
@@ -461,6 +428,25 @@ export declare class TypesManager {
461
428
  static getType<S, T>(typeUri: string): OT_Type<S, T>;
462
429
  }
463
430
 
431
+ /**
432
+ * Abstract base class implementing the database adapter interface.
433
+ * @template S - The type of snapshot data.
434
+ * @template T - The type of operation data.
435
+ */
436
+ export declare abstract class Db<S, T> implements IDatabaseAdapter<S, T> {
437
+ abstract getOps(id: string, from: number, to?: number, options?: unknown): Promise<IOp<T>[]>;
438
+ abstract getDocument(id: string, options?: unknown): Promise<IDocument | null>;
439
+ abstract getSnapshot(id: string, options?: unknown): Promise<ISnapshot<S> | null>;
440
+ abstract getFragment(id: string, fragmentId: string, options?: unknown): Promise<{ version: number; data: S | null } | null>;
441
+ abstract commitOp(id: string, op: IOp<T>, document: IDocument, options?: unknown): Promise<boolean>;
442
+ abstract commitSnapshot(id: string, snapshot: ICommitSnapshot<S>, options?: unknown): Promise<boolean>;
443
+ abstract close(): Promise<void>;
444
+ /**
445
+ * Retrieves the committed version of an operation if it exists.
446
+ */
447
+ getCommittedOpVersion(id: string, to: number, op: IOp<object>): Promise<number | null>;
448
+ }
449
+
464
450
  /**
465
451
  * Defines the interface for a database adapter in operational transformation.
466
452
  * @template S - The type of snapshot data.
@@ -480,32 +466,24 @@ export interface IDatabaseAdapter<S = unknown, T = unknown> {
480
466
  * Retrieves document information by ID.
481
467
  * @param {string} id - The document ID.
482
468
  * @param {unknown} [options] - Additional options (optional).
483
- * @returns {Promise<IDocument | undefined | null>} A promise resolving to the document info or undefined/null if not found.
469
+ * @returns {Promise<IDocument | null>} A promise resolving to the document info or null if not found.
484
470
  */
485
- getDocument(id: string, options?: unknown): Promise<IDocument | undefined | null>;
471
+ getDocument(id: string, options?: unknown): Promise<IDocument | null>;
486
472
  /**
487
473
  * Retrieves the snapshot of a document by ID.
488
474
  * @param {string} id - The document ID.
489
475
  * @param {unknown} [options] - Additional options (optional).
490
- * @returns {Promise<ISnapshot<S> | undefined | null>} A promise resolving to the snapshot or undefined/null if not found.
476
+ * @returns {Promise<ISnapshot<S> | null>} A promise resolving to the snapshot or null if not found.
491
477
  */
492
- getSnapshot(id: string, options?: unknown): Promise<ISnapshot<S> | undefined | null>;
478
+ getSnapshot(id: string, options?: unknown): Promise<ISnapshot<S> | null>;
493
479
  /**
494
480
  * Retrieves a specific fragment of a document by ID.
495
481
  * @param {string} id - The document ID.
496
482
  * @param {string} fragmentId - The ID of the fragment.
497
483
  * @param {unknown} [options] - Additional options (optional).
498
- * @returns {Promise<S | undefined | null>} A promise resolving to the fragment data or undefined/null if not found.
484
+ * @returns {Promise<{ version: number, data: S | null } | null>} Resolves to an object with fragment version and data, or null if the document does not exist. If the document exists but the fragment does not, data is null.
499
485
  */
500
- getFragment(id: string, fragmentId: string, options?: unknown): Promise<S | undefined | null>;
501
- /**
502
- * Retrieves multiple fragments of a document by ID.
503
- * @param {string} id - The document ID.
504
- * @param {string[]} [fragmentIds] - The IDs of the fragments (optional).
505
- * @param {unknown} [options] - Additional options (optional).
506
- * @returns {Promise<{ [id: string]: S }>} A promise resolving to an object mapping fragment IDs to their data.
507
- */
508
- getFragments(id: string, fragmentIds?: string[], options?: unknown): Promise<{ [id: string]: S }>;
486
+ getFragment(id: string, fragmentId: string, options?: unknown): Promise<{ version: number; data: S | null } | null>;
509
487
  /**
510
488
  * Commits an operation to the database.
511
489
  * @param {string} id - The document ID.
@@ -528,9 +506,9 @@ export interface IDatabaseAdapter<S = unknown, T = unknown> {
528
506
  * @param {string} id - The document ID.
529
507
  * @param {number} to - The ending version to check up to.
530
508
  * @param {IOp<T>} op - The operation to verify.
531
- * @returns {Promise<number | undefined>} A promise resolving to the committed version or undefined if not committed.
509
+ * @returns {Promise<number | null>} A promise resolving to the committed version or null if not committed.
532
510
  */
533
- getCommittedOpVersion(id: string, to: number, op: IOp): Promise<number | undefined>;
511
+ getCommittedOpVersion(id: string, to: number, op: IOp): Promise<number | null>;
534
512
  /**
535
513
  * Closes the database connection.
536
514
  * @returns {Promise<void>} A promise that resolves when the database is closed.
@@ -538,31 +516,10 @@ export interface IDatabaseAdapter<S = unknown, T = unknown> {
538
516
  close(): Promise<void>;
539
517
  }
540
518
 
541
- /**
542
- * Abstract base class implementing the database adapter interface.
543
- * @template S - The type of snapshot data.
544
- * @template T - The type of operation data.
545
- */
546
- export declare abstract class Db<S, T> implements IDatabaseAdapter<S, T> {
547
- abstract getOps(id: string, from: number, to?: number, options?: unknown): Promise<IOp<T>[]>;
548
- abstract getDocument(id: string, options?: unknown): Promise<IDocument | undefined | null>;
549
- abstract getSnapshot(id: string, options?: unknown): Promise<ISnapshot<S> | undefined | null>;
550
- abstract getFragment(id: string, fragmentId: string, options?: unknown): Promise<S | undefined | null>;
551
- abstract getFragments(id: string, fragmentIds?: string[], options?: unknown): Promise<{ [id: string]: S }>;
552
- abstract commitOp(id: string, op: IOp<T>, document: IDocument, options?: unknown): Promise<boolean>;
553
- abstract commitSnapshot(id: string, snapshot: ICommitSnapshot<S>, options?: unknown): Promise<boolean>;
554
- abstract close(): Promise<void>;
555
- /**
556
- * Retrieves the committed version of an operation if it exists.
557
- */
558
- getCommittedOpVersion(id: string, to: number, op: IOp<object>): Promise<number | undefined>;
559
- }
560
-
561
519
  export declare class MemoryDb<S = unknown, T = unknown> extends Db<S, T> {
562
- getSnapshot(roomId: string): Promise<ISnapshot<S> | undefined>;
563
- getDocument(roomId: string): Promise<IDocument | undefined>;
564
- getFragments(roomId: string): Promise<{ [key: string]: S }>;
565
- getFragment(roomId: string, fragmentId: string): Promise<S | undefined>;
520
+ getSnapshot(roomId: string): Promise<ISnapshot<S> | null>;
521
+ getDocument(roomId: string): Promise<IDocument | null>;
522
+ getFragment(roomId: string, fragmentId: string): Promise<{ version: number; data: S | null } | null>;
566
523
  getOps(roomId: string, fromVersion: number, toVersion?: number): Promise<IOp<T>[]>;
567
524
  commitOp(id: string, op: IOp<T>, document: IDocument): Promise<boolean>;
568
525
  commitSnapshot(roomId: string, snapshot: ICommitSnapshot<S>): Promise<boolean>;
@@ -574,8 +531,7 @@ export declare class MemoryDb<S = unknown, T = unknown> extends Db<S, T> {
574
531
  */
575
532
  export interface IMilestoneDatabaseAdapter<S> {
576
533
  /**
577
- * The interval for saving milestone snapshots.
578
- * @default 1000
534
+ * The interval for saving milestone snapshots; -1 means milestone snapshot saving is disabled.
579
535
  */
580
536
  interval: number;
581
537
  /**
@@ -585,5 +541,5 @@ export interface IMilestoneDatabaseAdapter<S> {
585
541
  /**
586
542
  * Retrieves a milestone snapshot by document ID and version.
587
543
  */
588
- getMilestoneSnapshot(id: string, version: number): Promise<ISnapshot<S> | undefined>;
544
+ getMilestoneSnapshot(id: string, version: number): Promise<ISnapshot<S> | null>;
589
545
  }
package/dist/index.js CHANGED
@@ -1 +1,12 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@grapecity-software/js-collaboration"));else if("function"==typeof define&&define.amd)define(["@grapecity-software/js-collaboration"],t);else{var s="object"==typeof exports?t(require("@grapecity-software/js-collaboration")):t(e["@grapecity-software/js-collaboration"]);for(var r in s)("object"==typeof exports?exports:e)[r]=s[r]}}(this,(e=>(()=>{"use strict";var t={619:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Db=void 0,t.Db=class{async getCommittedOpVersion(e,t,s){const r=await this.getOps(e,0,t);for(let e=r.length;e--;){const t=r[e];if(s.src===t.src&&s.seq===t.seq)return t.v}}}},985:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MemoryDb=void 0;const r=s(619);class n extends r.Db{constructor(e){var t;super(),this.ops=new Map,this.documents=new Map,this.fragments=new Map,this.mockWaitTime=null!==(t=null==e?void 0:e.mockWaitTime)&&void 0!==t?t:0}async getSnapshot(e){return this.execute((async()=>{const t=this.documents.get(e);if(!t)return;const s=await this.getFragments(e);return{id:e,v:t.snapshotVersion,type:t.type,fragments:s}}))}getDocument(e){return this.execute((()=>{const t=this.documents.get(e);if(t)return JSON.parse(JSON.stringify(t))}))}getFragments(e){return this.execute((()=>{const t=this.fragments.get(e);return t?JSON.parse(JSON.stringify(Object.fromEntries(t))):void 0}))}getFragment(e,t){return this.execute((()=>{var s;const r=null===(s=this.fragments.get(e))||void 0===s?void 0:s.get(t);if(r)return JSON.parse(JSON.stringify(r))}))}getOps(e,t,s){return this.execute((()=>{const r=this.ops.get(e);if(!r)return[];s=null!=s?s:Number.MAX_SAFE_INTEGER;const n=r.filter((e=>e.v>=t&&e.v<s));return JSON.parse(JSON.stringify(n))}))}commitOp(e,t,s){return this.execute((()=>{var r;if(t=JSON.parse(JSON.stringify(t)),s=JSON.parse(JSON.stringify(s)),t.create){if(this.documents.has(e))return!1;const{version:r,snapshotVersion:n,type:i}=s;return this.documents.set(e,{id:e,version:r,snapshotVersion:n,type:i}),this.ops.set(e,[t]),this.fragments.set(e,new Map),!0}if(t.del)return!!this.documents.has(e)&&(this.documents.delete(e),this.ops.delete(e),this.fragments.delete(e),!0);{const n=null===(r=this.ops.get(e))||void 0===r?void 0:r.length;return t.v===n&&(this.ops.get(e).push(t),this.documents.get(e).version=s.version,!0)}}))}commitSnapshot(e,t){return this.execute((()=>{var s,r,n;t=JSON.parse(JSON.stringify(t));const i=this.documents.get(e);if(t.fromVersion!==i.snapshotVersion)return!1;if(t.v<=i.snapshotVersion)return!1;i.snapshotVersion=t.v;const o=t.fragmentsChanges;if(o.deleteSnapshot)this.fragments.delete(e);else{const t=this.fragments.get(e);Object.entries(null!==(s=o.createFragments)&&void 0!==s?s:{}).forEach((async([e,s])=>{t.set(e,s)})),Object.entries(null!==(r=o.updateFragments)&&void 0!==r?r:{}).forEach((async([e,s])=>{t.set(e,s)})),null===(n=o.deleteFragments)||void 0===n||n.forEach((e=>{t.delete(e)}))}return!0}))}close(){return this.execute((()=>{}))}dump(){const e={ops:this.ops,documents:this.documents,fragments:this.fragments};return JSON.parse(JSON.stringify(e,((e,t)=>t instanceof Map?Object.fromEntries(t.entries()):t)))}_wait(){return new Promise((e=>setTimeout(e,this.mockWaitTime)))}async execute(e){return await this._wait(),await e()}}t.MemoryDb=n},347:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DocumentController=void 0;const r=s(127),n=s(961),i=s(660),o=r.LoggerManager.createLogger("OT.Document"),a=i.MessageActions,c=i.OTError.CODES,_="ot-doc-subscribed";function u(e){return{id:e.id,v:e.v,data:e.data,type:e.type}}t.DocumentController=class{constructor(e){this.service=e}async trigger(e,t,s){await this.service.trigger(e,t,s)}send(e,t){e.send(JSON.stringify(t),i.OT_DOC_MESSAGE_TYPE)}_sendOp(e,t){const s={a:a.op,v:t.v,src:t.src,seq:t.seq};"op"in t&&(s.op=t.op),t.create&&(s.create=t.create),t.del&&(s.del=!0),this.send(e,s)}_broadcastOp(e,t){const s={a:i.MessageActions.op,v:t.v,src:t.src,seq:t.seq};"op"in t&&(s.op=t.op),t.create&&(s.create=t.create),t.del&&(s.del=!0),e.broadcastWithFilter(JSON.stringify(s),i.OT_DOC_MESSAGE_TYPE,(t=>e.id!==t.id&&!!t.innerTags.get(_)))}_sendOps(e,t){if(t&&0!==t.length)for(let s=0;s<t.length;s++)this._sendOp(e,t[s])}async _reply(e,t,s){s.a=t.a;const r={connection:e,request:t,reply:s};await this.trigger("reply",r,(s=>{s?this._replyError(e,t,s):this.send(e,r.reply)}))}async _replyError(e,t,s){t.error=function(e){return e instanceof i.OTError?{code:e.code,message:e.message}:e instanceof Error?{code:c.ERR_UNKNOWN_ERROR,message:e.message}:"string"==typeof e?{code:c.ERR_UNKNOWN_ERROR,message:e}:void o.warn("unknown error",e)}(s),this.send(e,t)}async _messageHandler(e,t){const s=this;if("string"!=typeof t)return void s.close(e,new i.OTError(c.ERR_MESSAGE_BADLY_FORMED,"Received non-object message"));let r;try{r=JSON.parse(t)}catch(t){return void s.close(e,new i.OTError(c.ERR_MESSAGE_BADLY_FORMED,"Received non-object message"))}await this.trigger("receive",{connection:e,request:r},(async t=>{t?await s._replyError(e,r,t):await s._handleMessage(e,r,((t,n)=>{t?s._replyError(e,r,t):s._reply(e,r,n||{})}))}))}_checkRequest(e){if(e.a===a.op&&!(0,n.isNullOrUndefined)(e.v)&&("number"!=typeof e.v||e.v<0))return"Invalid version"}async _handleMessage(e,t,s){const r=this._checkRequest(t);if(r)return s(new i.OTError(c.ERR_MESSAGE_BADLY_FORMED,r));switch(t.a){case a.fetch:return await this._fetch(e,t.v,s);case a.subscribe:return await this._subscribe(e,t.v,s);case a.unsubscribe:return this._unsubscribe(e);case a.op:return await this._submit(e,t,s);case a.fetchHistorySnapshot:return await this._fetchHistorySnapshot(e,t,s);default:return await s(new i.OTError(c.ERR_MESSAGE_BADLY_FORMED,"Invalid or unknown message"))}}async _fetch(e,t,s){if(!(0,n.isNullOrUndefined)(t))return await this._fetchOps(e,t,s);await this.service._fetch(e.roomId,{connection:e},((e,t)=>e?s(e):s(null,{data:u(t)})))}async _fetchOps(e,t,s){await this.service._getOps(e.roomId,t,void 0,{connection:e},((t,r)=>t?s(t):(this._sendOps(e,r),s())))}async _subscribe(e,t,s){const r=this;await this.service._subscribe(e.roomId,t,{connection:e},((t,n)=>{if(t)return s(t);const{ops:i,snapshot:o}=n;return i&&r._sendOps(e,i),e.innerTags.set(_,!0),o?s(null,{data:u(o)}):s()}))}_unsubscribe(e){e.innerTags.delete(_)}async _submit(e,t,s){const r=function(e,t){const s=e.src||t;return e.op?function(e,t,s,r,n){return{src:e,seq:t,v:s,op:r,x:n,m:void 0}}(s,e.seq,e.v,e.op,e.x):e.create?function(e,t,s,r,n){return{src:e,seq:t,v:s,create:r,x:n,m:void 0}}(s,e.seq,e.v,e.create,e.x):e.del?function(e,t,s,r,n){return{src:e,seq:t,v:s,del:r,x:n,m:void 0}}(s,e.seq,e.v,e.del,e.x):void 0}(t,e.id);return r?r.seq>=i.util.MAX_SAFE_INTEGER?s(new i.OTError(c.ERR_CONNECTION_SEQ_INTEGER_OVERFLOW,"Connection seq has exceeded the max safe integer, maybe from being open for too long")):await this._submitOp(e,r,s):s(new i.OTError(c.ERR_MESSAGE_BADLY_FORMED,"Invalid op message"))}async _submitOp(e,t,s){const r=this;await this.service._submit(e.roomId,t,{connection:e},(t=>{r._broadcastOp(e,t.op)}),((n,o)=>{const a={src:t.src,seq:t.seq,v:t.v};return n?n instanceof i.OTError&&n.code==c.ERR_OP_ALREADY_SUBMITTED?s(null,a):s(n):(r._sendOps(e,o),s(null,a))}))}async _fetchHistorySnapshot(e,t,s){if(void 0===t.v)return s(new i.OTError(c.ERR_MESSAGE_BADLY_FORMED,"Invalid fetch history snapshot message"));await this.service._fetchHistorySnapshot(e.roomId,t.v,{connection:e},((e,r)=>e?s(e):s(null,{id:t.id,data:r})))}close(e,t){t&&o.warn("Connection closed due to error",e.id,t.stack||t),e.close()}}},763:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.documentFeature=function(e){const t=e||new r.DocumentServices,s=new n.DocumentController(t);return{middlewares:{message:async(e,t)=>e.type!==i.OT_DOC_MESSAGE_TYPE?await t():s._messageHandler(e.connection,e.data)}}};const r=s(89),n=s(347),i=s(660)},89:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DocumentServices=void 0;const r=s(660),n=s(127),i=s(961),o=s(985),a=s(259),c=s(551),_=s(155),u=s(936),p=s(469),h=s(36),E=s(769),O=r.OTError.CODES;class d extends n.Middleware{constructor(e){var t,s,r;super(),e=null!=e?e:{},this.db=null!==(t=e.db)&&void 0!==t?t:new o.MemoryDb,this.milestoneDb=null!==(s=e.milestoneDb)&&void 0!==s?s:new u.MilestoneDB,this.maxSubmitRetries=e.maxSubmitRetries,this.submitSnapshotBatchSize=null!==(r=e.submitSnapshotBatchSize)&&void 0!==r?r:10}async fetch(e,t){let s;const r=await this._fetch(e,t||{},(e=>{s=e}));if(s)throw s;return r}async _fetch(e,t,s){const r=Date.now(),n=this;try{const i=await n._getSnapshot(e,t);return await n._sanitizeSnapshots([i],a.SnapshotTypes.current,t,(async o=>o?s(o):(await n._emitTiming("fetch",Date.now()-r,Object.assign(Object.assign({},t),{id:e})),s(null,i)))),i}catch(e){await s(e)}}async getOps(e,t,s,r){let n;const i=await this._getOps(e,t,s,r||{},(e=>{n=e}));if(n)throw n;return i}async _getOps(e,t,s,r,n){const i=this,o=Date.now();return await i._getSanitizedOps(e,t,s,r||{},(async(a,c)=>a?n(a):(await i._emitTiming("getOps",Date.now()-o,Object.assign(Object.assign({},r),{id:e,from:t,to:s})),n(null,c))))}async _subscribe(e,t,s,r){const n=this,o=Date.now();(0,i.isNullOrUndefined)(t)?await n._fetch(e,s,(async(i,a)=>i?r(i):(await n._emitTiming("subscribe.snapshot",Date.now()-o,Object.assign(Object.assign({},s),{id:e,version:t})),r(null,{snapshot:a})))):await n._getSanitizedOps(e,t,void 0,s,(async(i,a)=>i?r(i):(await n._emitTiming("subscribe.ops",Date.now()-o,Object.assign(Object.assign({},s),{id:e,version:t})),r(null,{ops:a}))))}async submit(e,t,s,r){let n;const i=await this._submit(e,t,s||{},r||(()=>{}),(e=>{n=e}));if(n)throw n;return i}async _submit(e,t,s,r,n){const i=_.ot.checkOp(t);if(i)return n(i),[];const o=this,a=new c.SubmitRequest(this,e,t,s),u={connection:s.connection,request:a},p=(e,t)=>(o.emit("submitRequestEnd",{request:a,err:e}),n(e,t));return await o.trigger("submit",u,(async t=>{if(t)return p(t);await a.submit(r,(async t=>{if(t)return p(t);await o._sanitizeOps(e,a.ops,u,(async e=>e?p(e):(o._emitTiming("submit.op.total",Date.now()-a.start,a),p(null,a.ops))))}))})),a.ops}async fetchHistorySnapshot(e,t,s){let r;const n=await this._fetchHistorySnapshot(e,t,s||{},(e=>{r=e}));if(r)throw r;return n}async _fetchHistorySnapshot(e,t,s,r){try{const n=Date.now(),i=await this._fetchHistorySnapshotImp(e,t),o=a.SnapshotTypes.byVersion;return await this._sanitizeSnapshots([i],o,s,(async e=>e?r(e):(await this._emitTiming("fetchSnapshot",Date.now()-n,Object.assign(Object.assign({},s),{version:t})),r(null,i)))),i}catch(e){await r(e)}}async _fetchHistorySnapshotImp(e,t){const s=this.db;if(void 0===t)return await this._getSnapshot(e);const n=await this.milestoneDb.getMilestoneSnapshot(e,t),i=n?n.v:0,o=await s.getOps(e,i,t),a=await this._buildSnapshotFromOps(e,n,o);if(t>a.v)throw new r.OTError(O.ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT,"Requested version exceeds latest snapshot version");return a}async _buildSnapshotFromOps(e,t,s){const r=null!=t?t:{id:e,v:0},n=new h.SnapshotFragmentsRequest(e,void 0,r.fragments),i=await _.ot.applyOps(r,s,n);if(i)throw i;return n.applyChangesToSnapshot(r),_.ot.composeFragments(r),r}async _sanitizeSnapshots(e,t,s,r){const n=new p.ReadSnapshotsRequest(e,t,s);await this.trigger("readSnapshots",{connection:s.connection,request:n},(e=>e?r((0,i.wrapError)(e,O.ERR_SNAPSHOT_READS_REJECTED)):n.hasSnapshotRejection()?r(n.getReadSnapshotsError()):r()))}async _getSanitizedOps(e,t,s,r,n){const i=await this.db.getOps(e,t,s,null==r?void 0:r.options);return await this._sanitizeOps(e,i,r,(e=>e?n(e):n(null,i))),i}async _sanitizeOps(e,t,s,r){for(const n of t){let t;if(await this._sanitizeOp(e,n,s,(e=>{t=e})),t)return r(t)}return r()}async _sanitizeOp(e,t,s,r){await this.trigger("readOp",{connection:s.connection,request:{id:e,op:t,context:s}},(e=>e?r((0,i.wrapError)(e)):r()))}async _getSnapshot(e,t){var s;const r=null==t?void 0:t.options,n=await this.db.getDocument(e,r);if(!n)return{id:e,v:0};if(n.snapshotVersion<n.version){const s=new E.SubmitSnapshotRequest(this,e,n,Object.assign(Object.assign({},t),{trigger:E.SubmitSnapshotTrigger.fetchSnapshot}));await s.submitSnapshot((e=>{if(e)throw e}))}const i=null!==(s=await this.db.getSnapshot(e,r))&&void 0!==s?s:{id:e,v:0};return _.ot.composeFragments(i),i}_emitTiming(e,t,s){return this.emit("timing",{action:e,cost:t,m:s})}}t.DocumentServices=d},259:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Hooks=t.SnapshotTypes=void 0,t.SnapshotTypes={current:"current",byVersion:"byVersion",byTimestamp:"byTimestamp"},t.Hooks={submitRequestEnd:"submitRequestEnd",timing:"timing"}},936:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MilestoneDB=void 0;const r=s(660),n=s(961),i=r.OTError.CODES;t.MilestoneDB=class{constructor(e){var t;this.interval=null!==(t=null==e?void 0:e.interval)&&void 0!==t?t:1e3,this.map=new Map}saveMilestoneSnapshot(e){return new Promise((t=>{let s=this.map.get(e.id);s||(s=[],this.map.set(e.id,s)),s.push(e),s.sort(((e,t)=>e.v-t.v)),t(!0)}))}getMilestoneSnapshot(e,t){const s=function(e){return function(t,s){return!(0,n.isNullOrUndefined)(e)&&s.v>e}}(t);return this._findMilestoneSnapshot(e,s)}_findMilestoneSnapshot(e,t){return new Promise((s=>{if(!e)throw new r.OTError(i.ERR_MILESTONE_ARGUMENT_INVALID,"Missing ID");const n=this._getMilestoneSnapshots(e);let o;for(let e=0;e<n.length;e++){const s=n[e];if(t(o,s))break;o=s}s(o)}))}_getMilestoneSnapshots(e){var t;return null!==(t=this.map.get(e))&&void 0!==t?t:[]}}},155:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ot=t.composeFragments=t.applyOps=t.transform=t.apply=t.normalizeType=t.checkOp=void 0;const r=s(513),n=s(961),i=s(660),o=i.OTError.CODES,a="default";t.checkOp=function(e){if((0,n.isNullOrUndefined)(e)||"object"!=typeof e)return new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if((0,n.isNullOrUndefined)(e.create)){if((0,n.isNullOrUndefined)(e.del)){if(!("op"in e))return new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del")}else if(!0!==e.del)return new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else{if("object"!=typeof e.create)return new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");const t=e.create.type;if("string"!=typeof t)return new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"Missing create type");const s=r.TypesManager.map[t];if((0,n.isNullOrUndefined)(s)||"object"!=typeof s)return new i.OTError(o.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}return(0,n.isNullOrUndefined)(e.src)||"string"==typeof e.src?(0,n.isNullOrUndefined)(e.seq)||"number"==typeof e.seq?(0,n.isNullOrUndefined)(e.src)&&!(0,n.isNullOrUndefined)(e.seq)||!(0,n.isNullOrUndefined)(e.src)&&(0,n.isNullOrUndefined)(e.seq)?new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together"):(0,n.isNullOrUndefined)(e.m)||"object"==typeof e.m?void 0:new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null"):new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"seq must be a number"):new i.OTError(o.ERR_OT_OP_BADLY_FORMED,"src must be a string")},t.normalizeType=function(e){return r.TypesManager.map[e]&&r.TypesManager.map[e].uri},t.apply=async function(e,t,s){if("object"!=typeof e)return new i.OTError(o.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(!(0,n.isNullOrUndefined)(e.v)&&!(0,n.isNullOrUndefined)(t.v)&&e.v!==t.v)return new i.OTError(o.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(t.create){const n=t.create,c=r.TypesManager.map[n.type];if(!c)return new i.OTError(o.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{let t;t=c.createFragments?c.createFragments(n.data):{[a]:c.create(n.data)},s.create(t),e.type=c.uri,e.v++}catch(e){return e}}else if(t.del)s.delete(),e.data=void 0,e.type=void 0,e.v++;else if("op"in t){const n=await async function(e,t,s){if(!e.type)return new i.OTError(o.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(void 0===t)return new i.OTError(o.ERR_OT_OP_NOT_PROVIDED,"Missing op");const n=r.TypesManager.map[e.type];if(!n)return new i.OTError(o.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{if(n.applyFragments)await n.applyFragments(s,t);else{const e=await s.getFragment(a),r=n.apply(e,t);s.updateFragment(a,r)}}catch(e){return new i.OTError(o.ERR_OT_OP_NOT_APPLIED,e.message)}}(e,t.op,s);if(n)return n;e.v++}else e.v++},t.transform=function(e,t,s){if(!(0,n.isNullOrUndefined)(t.v)&&t.v!==s.v)return new i.OTError(o.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(s.del){if(t.create||"op"in t)return new i.OTError(o.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(s.create&&("op"in t||t.create||t.del)||"op"in s&&t.create)return new i.OTError(o.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in s&&"op"in t){if(!e)return new i.OTError(o.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if("string"==typeof e&&!(e=r.TypesManager.map[e]))return new i.OTError(o.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{t.op=e.transform(t.op,s.op,"left")}catch(e){return new i.OTError(o.ERR_OT_OP_TRANSFORM_FAILED,"Op transform failed")}}}(0,n.isNullOrUndefined)(t.v)||t.v++},t.applyOps=async function(e,s,r){for(let n=0;n<s.length;n++){const i=s[n];e.v=i.v;const o=await(0,t.apply)(e,i,r);if(o)return o}},t.composeFragments=function(e){if(!e.type)return;const t=r.TypesManager.map[e.type];t&&e.fragments&&(t.composeFragments?e.data=t.composeFragments(e.fragments):e.data=e.fragments[a],delete e.fragments)},t.ot={checkOp:t.checkOp,normalizeType:t.normalizeType,apply:t.apply,transform:t.transform,applyOps:t.applyOps,composeFragments:t.composeFragments}},469:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ReadSnapshotsRequest=void 0;const r=s(660),n=s(961);t.ReadSnapshotsRequest=class{constructor(e,t,s){this._idToError=null,this.snapshots=e,this.snapshotType=t,this.context=s||{}}rejectSnapshotRead(e,t){this._idToError||(this._idToError=Object.create(null)),this._idToError[e.id]=t}rejectSnapshotReadSilent(e,t){this.rejectSnapshotRead(e,this.silentRejectionError(t))}silentRejectionError(e){return new r.OTError(r.OTError.CODES.ERR_SNAPSHOT_READ_SILENT_REJECTION,e)}hasSnapshotRejection(){return!(0,n.isNullOrUndefined)(this._idToError)}getReadSnapshotsError(){const e=this.snapshots,t=this._idToError;if(0===e.length)return;if(1===e.length){return t[e[0].id]||void 0}const s=new r.OTError(r.OTError.CODES.ERR_SNAPSHOT_READS_REJECTED);return s.idToError=t,s}}},36:(e,t)=>{function s(e,t){var s,r,n;const i=null!==(s=e.fragments)&&void 0!==s?s:{};if(t.deleteSnapshot)e.fragments={};else{for(const[e,s]of Object.entries(null!==(r=t.createFragments)&&void 0!==r?r:{}))i[e]=s;for(const[e,s]of Object.entries(null!==(n=t.updateFragments)&&void 0!==n?n:{}))i[e]=s;t.deleteFragments&&t.deleteFragments.length>0&&t.deleteFragments.forEach((e=>delete i[e])),e.fragments=i}}Object.defineProperty(t,"__esModule",{value:!0}),t.SnapshotFragmentsRequest=void 0,t.applyChangesToSnapshot=s,t.SnapshotFragmentsRequest=class{constructor(e,t,s){this._fragmentsMap=new Map,this._createFragments=new Map,this._updateFragments=new Map,this._deleteFragments=new Set,this._deleteSnapshot=!1,this._docId=e,this._db=t,s&&Object.entries(s).forEach((([e,t])=>{this._fragmentsMap.set(e,t)}))}async _loadFragment(e){const t=await this._db.getFragment(this._docId,e);this._fragmentsMap.set(e,t)}async getFragment(e){return this._db&&!this._fragmentsMap.has(e)&&await this._loadFragment(e),this._fragmentsMap.get(e)}createFragment(e,t){this._deleteFragments.has(e)?(this._deleteFragments.delete(e),this._updateFragments.set(e,t)):this._createFragments.set(e,t),this._fragmentsMap.set(e,t)}updateFragment(e,t){this._deleteFragments.has(e)||(this._createFragments.has(e)?this._createFragments.set(e,t):this._updateFragments.set(e,t),this._fragmentsMap.set(e,t))}deleteFragment(e){this._deleteFragments.add(e),this._createFragments.delete(e),this._updateFragments.delete(e),this._fragmentsMap.set(e,void 0)}create(e){Object.entries(e).forEach((([e,t])=>{this.createFragment(e,t)}))}delete(){this._deleteSnapshot=!0,this._createFragments.clear(),this._updateFragments.clear(),this._deleteFragments.clear(),this._fragmentsMap.clear()}getChanges(){return{createFragments:Object.fromEntries(this._createFragments.entries()),updateFragments:Object.fromEntries(this._updateFragments.entries()),deleteFragments:Array.from(this._deleteFragments),deleteSnapshot:this._deleteSnapshot}}applyChangesToSnapshot(e){s(e,this.getChanges())}}},551:function(e,t,s){var r,n=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var n=Object.getOwnPropertyDescriptor(t,s);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,n)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(r=function(e){return r=Object.getOwnPropertyNames||function(e){var t=[];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[t.length]=s);return t},r(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s=r(e),o=0;o<s.length;o++)"default"!==s[o]&&n(t,e,s[o]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.SubmitRequest=void 0;const a=s(961),c=s(660),_=o(s(155)),u=s(769),p=s(513),h=c.OTError.CODES,E=p.TypesManager.getType;t.SubmitRequest=class{constructor(e,t,s,r){this.doc=e,this.context=r||{},this.id=t,this.op=s,this.extra=s.x,delete s.x,this.start=Date.now(),this._addOpMeta(),this.maxRetries=e.maxSubmitRetries,this.retries=0,this.ops=[]}async submit(e,t){var s;const r=this,n=this.doc.db,i=this.id,o=this.op,c=Date.now(),_=null!==(s=await n.getDocument(i))&&void 0!==s?s:{id:i,version:0,snapshotVersion:0};r.document=_,await r.doc._emitTiming("submit.op.db.getDocumentInfo",Date.now()-c,r);const u=_.version;if((0,a.isNullOrUndefined)(o.v)){if(o.create&&_.type&&o.src){const e=await n.getCommittedOpVersion(i,u,o);return(0,a.isNullOrUndefined)(e)?t(r.alreadyCreatedError()):(o.v=e,t(r.alreadySubmittedError()))}o.v=u}if(o.v>u)return t(r.newerVersionError());if(o.v<u){const e=Date.now(),s=o.v,a=await n.getOps(i,s,u);if(r.doc._emitTiming("submit.op.db.getOpsForTransform",Date.now()-e,r),!a||a.length!==u-s)return t(r.missingOpsError());const c=Date.now(),_=r._transformOp(a);if(_)return t(_);if(await r.doc._emitTiming("submit.op.transform",Date.now()-c,r),o.v!==u)return t(r.versionAfterTransformError())}if(_.type){if(o.create)return t(r.alreadyCreatedError())}else if(!o.create)return t(r.docDoesNotExistError());r._updateDocument(),await r.commitOp(e,t)}_addOpMeta(){this.op.m={ts:this.start},this.op.create&&(this.op.create.type=_.normalizeType(this.op.create.type))}_updateDocument(){if(!this.document)return;const e=this.document,t=this.op;t.create?(e.type=_.normalizeType(t.create.type),e.snapshotVersion=0):t.del&&(e.type=void 0),e.version++,this._updateDocumentMeta()}_updateDocumentMeta(){const e=this.document.m||(this.document.m={});this.op.create&&(e.ctime=this.start),e.mtime=this.start}_transformOp(e){const t=E(this.document.type);for(let s=0;s<e.length;s++){const r=e[s];if(this.op.src&&this.op.src===r.src&&this.op.seq===r.seq)return this.alreadySubmittedError();if(this.op.v!==r.v)return this.versionDuringTransformError();const n=_.transform(t,this.op,r);if(n)return n;delete r.m,this.ops.push(r)}}async commitOp(e,t){const s=this,r=this.doc;await s._trigger("commit",(async n=>{if(n)return t(n);const i=Date.now();if(!await r.db.commitOp(s.id,s.op,s.document,s.context.options))return await s._retry(e,t);s.op.m=void 0,await r._emitTiming("submit.op.db.commit",Date.now()-i,s),e(s),await s._trigger("afterWrite",(async e=>{if(e)return t(e);const n=new u.SubmitSnapshotRequest(r,s.id,s.document,Object.assign(Object.assign({},s.context),{trigger:u.SubmitSnapshotTrigger.submitOp,op:s.op}));await n.submitSnapshot(t)}))}))}async _retry(e,t){if(this.retries++,null!=this.maxRetries&&this.retries>this.maxRetries)return t(this.maxRetriesError());await this.doc._emitTiming("submit.op.retry",Date.now()-this.start,this),await this.submit(e,t)}async _trigger(e,t){const s=Object.assign(Object.assign({},this.context),{request:this});await this.doc.trigger(e,s,t),this.context.options=s.options}alreadyCreatedError(){return new c.OTError(h.ERR_DOC_ALREADY_CREATED,"Invalid op submitted. Document already created")}docDoesNotExistError(){return new c.OTError(h.ERR_DOC_DOES_NOT_EXIST,"Document does not exist")}rejectedError(){return new c.OTError(h.ERR_OP_SUBMIT_REJECTED,"Op submit rejected")}alreadySubmittedError(){return new c.OTError(h.ERR_OP_ALREADY_SUBMITTED,"Op already submitted")}maxRetriesError(){return new c.OTError(h.ERR_MAX_SUBMIT_RETRIES_EXCEEDED,"Op submit failed. Exceeded max submit retries of "+this.maxRetries)}versionDuringTransformError(){return new c.OTError(h.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Op submit failed. Versions mismatched during op transform")}newerVersionError(){return new c.OTError(h.ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT,"Invalid op submitted. Op version newer than current snapshot")}missingOpsError(){return new c.OTError(h.ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND,"Op submit failed. DB missing ops needed to transform it up to the current snapshot version")}versionAfterTransformError(){return new c.OTError(h.ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM,"Op submit failed. Op version mismatches snapshot after op transform")}}},769:function(e,t,s){var r,n=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var n=Object.getOwnPropertyDescriptor(t,s);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,n)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(r=function(e){return r=Object.getOwnPropertyNames||function(e){var t=[];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[t.length]=s);return t},r(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s=r(e),o=0;o<s.length;o++)"default"!==s[o]&&n(t,e,s[o]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.SubmitSnapshotRequest=t.SubmitSnapshotTrigger=void 0;const a=s(127),c=s(660),_=s(36),u=o(s(155)),p=c.OTError.CODES,h=a.LoggerManager.createLogger("OT.Document");var E;!function(e){e.submitOp="submitOp",e.fetchSnapshot="fetchSnapshot",e.manual="manual"}(E||(t.SubmitSnapshotTrigger=E={})),t.SubmitSnapshotRequest=class{constructor(e,t,s,r){this.doc=e,this.context=r||{},this.id=t,this.document=s,this.fromVersion=s.snapshotVersion,this.toVersion=s.version,this.start=Date.now(),this.saveSnapshot=null,this.saveMilestoneSnapshot=null,this.maxRetries=e.maxSubmitRetries,this.retries=0,this.snapshot=null}async submitSnapshot(e){const t=this,s=this.doc;await t._trigger("submitSnapshot",(async r=>{if(r)return e(r);if(!t._shouldSubmitSnapshot())return e();const n=Date.now(),i=await s.db.getOps(t.id,t.fromVersion,t.toVersion);if(await t.doc._emitTiming("submit.snapshot.db.getOpsForApply",Date.now()-n,t),!i||i.length!==t.toVersion-t.fromVersion)return h.error("submit.snapshot.missingApplyOps",{id:t.id,fromVersion:t.fromVersion,toVersion:t.toVersion}),e();t.ops=i,await this.apply((async t=>{if(t)return e(t);await this.commitSnapshot(e)}))}))}_addSnapshotMeta(){if(!this.snapshot)return;const e=this.snapshot;this.ops.forEach((t=>{const s=e.m||(e.m={});t.create&&(s.ctime=this.start),s.mtime=this.start}))}async apply(e){const t=this,s=this.doc.db,r=this.id,n=this.ops,i=t.document,o=Date.now();t.snapshot={id:r,fromVersion:i.snapshotVersion,v:i.snapshotVersion,type:i.type},t._addSnapshotMeta(),await t._trigger("apply",(async i=>{if(i)return e(i);const a=t.snapshot,c=new _.SnapshotFragmentsRequest(r,s),p=await u.applyOps(a,n,c);return p?(h.error("submit.snapshot.apply",p),e(p)):(a.fragmentsChanges=c.getChanges(),t.doc._emitTiming("submit.snapshot.apply",Date.now()-o,t),e())}))}async commitSnapshot(e){const t=this,s=this.doc;await t._trigger("commitSnapshot",(async r=>{if(r)return e(r);const n=Date.now();if(!await s.db.commitSnapshot(t.id,t.snapshot,t.context.options))return await this._retry(e);if(await s._emitTiming("submit.snapshot.db.commit",Date.now()-n,t),t._shouldSaveMilestoneSnapshot()){const e=await t.doc.db.getSnapshot(t.id);await t.doc.milestoneDb.saveMilestoneSnapshot(e)}return e()}))}async _retry(e){if(this.retries++,null!=this.maxRetries&&this.retries>this.maxRetries)return e(this.maxRetriesError());const t=Date.now(),s=await this.doc.db.getDocument(this.id,this.context.options);return this.doc._emitTiming("submit.snapshot.retry.db.getDocumentInfo",Date.now()-t,this),s?s.snapshotVersion!==this.fromVersion?s.snapshotVersion>=this.toVersion?e():(this.document=s,this.fromVersion=s.snapshotVersion,await this.doc._emitTiming("submit.snapshot.retry",Date.now()-this.start,this),await this.submitSnapshot(e)):(await this.doc._emitTiming("submit.snapshot.retry",Date.now()-this.start,this),await this.submitSnapshot(e)):e()}_shouldSubmitSnapshot(){var e,t;const s=this.fromVersion,r=this.toVersion,n=null===(e=this.context)||void 0===e?void 0:e.trigger,i=null===(t=this.context)||void 0===t?void 0:t.op;return!(r<=s)&&(!(n!==E.submitOp||!i||!i.create&&!i.del)||n===E.fetchSnapshot||0===s||!!this._shouldSaveMilestoneSnapshot()||(null===this.saveSnapshot?r-s>=this.doc.submitSnapshotBatchSize:this.saveSnapshot))}_shouldSaveMilestoneSnapshot(){return null===this.saveMilestoneSnapshot?this.toVersion%this.doc.milestoneDb.interval==0:this.saveMilestoneSnapshot}async _trigger(e,t){const s=Object.assign(Object.assign({},this.context),{request:this});await this.doc.trigger(e,s,t),this.context.options=s.options}maxRetriesError(){return new c.OTError(p.ERR_MAX_SUBMIT_SNAPSHOT_RETRIES_EXCEEDED,"Snapshot submit failed. Exceeded max submit retries of "+this.maxRetries)}}},513:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TypesManager=void 0;class s{static register(e){e.uri&&(s.map[e.uri]=e),e.name&&(s.map[e.name]=e)}static getType(e){return s.map[e]}}t.TypesManager=s,s.map={}},961:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isNullOrUndefined=function(e){return null==e},t.wrapError=function(e,t){if(e instanceof r.OTError)return e;t=null!=t?t:r.OTError.CODES.ERR_UNKNOWN_ERROR;const s="string"==typeof e?e:e.message;return new r.OTError(t,s)};const r=s(660)},127:t=>{t.exports=e},872:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.OTError=t.ERROR_CODES=void 0,function(e){e[e.ERR_DOC_ALREADY_CREATED=0]="ERR_DOC_ALREADY_CREATED",e[e.ERR_DOC_DOES_NOT_EXIST=1]="ERR_DOC_DOES_NOT_EXIST",e[e.ERR_DOC_TYPE_NOT_RECOGNIZED=2]="ERR_DOC_TYPE_NOT_RECOGNIZED",e[e.ERR_DOC_WAS_DELETED=3]="ERR_DOC_WAS_DELETED",e[e.ERR_MAX_SUBMIT_RETRIES_EXCEEDED=4]="ERR_MAX_SUBMIT_RETRIES_EXCEEDED",e[e.ERR_MAX_SUBMIT_SNAPSHOT_RETRIES_EXCEEDED=5]="ERR_MAX_SUBMIT_SNAPSHOT_RETRIES_EXCEEDED",e[e.ERR_MESSAGE_BADLY_FORMED=6]="ERR_MESSAGE_BADLY_FORMED",e[e.ERR_OP_ALREADY_SUBMITTED=7]="ERR_OP_ALREADY_SUBMITTED",e[e.ERR_HARD_ROLLBACK_FETCH_FAILED=8]="ERR_HARD_ROLLBACK_FETCH_FAILED",e[e.ERR_OT_OP_NOT_APPLIED=9]="ERR_OT_OP_NOT_APPLIED",e[e.ERR_OT_OP_TRANSFORM_FAILED=10]="ERR_OT_OP_TRANSFORM_FAILED",e[e.ERR_SNAPSHOT_READS_REJECTED=11]="ERR_SNAPSHOT_READS_REJECTED",e[e.ERR_SNAPSHOT_READ_SILENT_REJECTION=12]="ERR_SNAPSHOT_READ_SILENT_REJECTION",e[e.ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND=13]="ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",e[e.ERR_CONNECTION_SEQ_INTEGER_OVERFLOW=14]="ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",e[e.ERR_OT_OP_BADLY_FORMED=15]="ERR_OT_OP_BADLY_FORMED",e[e.ERR_HISTORY_SNAPSHOT_NOT_FOUND=16]="ERR_HISTORY_SNAPSHOT_NOT_FOUND",e[e.ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT=17]="ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",e[e.ERR_DOC_MISSING_VERSION=18]="ERR_DOC_MISSING_VERSION",e[e.ERR_OP_SUBMIT_REJECTED=19]="ERR_OP_SUBMIT_REJECTED",e[e.ERR_PENDING_OP_REMOVED_BY_OP_SUBMIT_REJECTED=20]="ERR_PENDING_OP_REMOVED_BY_OP_SUBMIT_REJECTED",e[e.ERR_MILESTONE_ARGUMENT_INVALID=21]="ERR_MILESTONE_ARGUMENT_INVALID",e[e.ERR_OT_OP_NOT_PROVIDED=22]="ERR_OT_OP_NOT_PROVIDED",e[e.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT=23]="ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",e[e.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM=24]="ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",e[e.ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION=25]="ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",e[e.ERR_APPLY_SNAPSHOT_NOT_PROVIDED=26]="ERR_APPLY_SNAPSHOT_NOT_PROVIDED",e[e.ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM=27]="ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",e[e.ERR_UNKNOWN_ERROR=1e3]="ERR_UNKNOWN_ERROR"}(s||(t.ERROR_CODES=s={}));class r extends Error{constructor(e,t){super(t),this.code=e,this.name="OTError",this.code=e}}t.OTError=r,r.CODES=s},660:function(e,t,s){var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var n=Object.getOwnPropertyDescriptor(t,s);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,n)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),n=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),t.OT_DOC_MESSAGE_TYPE=void 0,n(s(872),t),n(s(549),t),n(s(802),t),t.OT_DOC_MESSAGE_TYPE="ot-doc"},549:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.MessageActions=void 0,function(e){e[e.fetch=0]="fetch",e[e.fetchOps=1]="fetchOps",e[e.fetchHistorySnapshot=2]="fetchHistorySnapshot",e[e.subscribe=3]="subscribe",e[e.unsubscribe=4]="unsubscribe",e[e.op=5]="op"}(s||(t.MessageActions=s={}))},802:(e,t)=>{function s(e,t,s){let r=!1;return e.forEach((function(e){e&&(e(t,s),r=!0)})),r}function r(e){return e?JSON.parse(JSON.stringify(e)):e}Object.defineProperty(t,"__esModule",{value:!0}),t.util=t.nextTick=t.MAX_SAFE_INTEGER=void 0,t.callEach=s,t.clone=r,t.MAX_SAFE_INTEGER=9007199254740991,t.nextTick=function(e){if("undefined"!=typeof process&&process.nextTick)return process.nextTick(e);setTimeout((function(){e()}))},t.util={MAX_SAFE_INTEGER:t.MAX_SAFE_INTEGER,callEach:s,nextTick:t.nextTick,clone:r}}},s={};function r(e){var n=s[e];if(void 0!==n)return n.exports;var i=s[e]={exports:{}};return t[e].call(i.exports,i,i.exports,r),i.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.documentFeature=e.MemoryDb=e.Db=e.DocumentServices=e.TypesManager=void 0,r(259),r(36);const t=r(89);Object.defineProperty(e,"DocumentServices",{enumerable:!0,get:function(){return t.DocumentServices}});const s=r(619);Object.defineProperty(e,"Db",{enumerable:!0,get:function(){return s.Db}});const i=r(985);Object.defineProperty(e,"MemoryDb",{enumerable:!0,get:function(){return i.MemoryDb}});const o=r(763);Object.defineProperty(e,"documentFeature",{enumerable:!0,get:function(){return o.documentFeature}});const a=r(513);Object.defineProperty(e,"TypesManager",{enumerable:!0,get:function(){return a.TypesManager}})})(),n})()));
1
+ /*!
2
+ *
3
+ * SpreadJS Library 19.0.0
4
+ *
5
+ * Copyright(c) GrapeCity Software inc. All rights reserved.
6
+ *
7
+ * Licensed under the SpreadJS Commercial License.
8
+ * info.xa@grapecity.com
9
+ * https://www.grapecity.com.cn/developer/spreadjs
10
+ *
11
+ */
12
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@grapecity-software/js-collaboration"));else if("function"==typeof define&&define.amd)define(["@grapecity-software/js-collaboration"],t);else{var s="object"==typeof exports?t(require("@grapecity-software/js-collaboration")):t(e["@grapecity-software/js-collaboration"]);for(var r in s)("object"==typeof exports?exports:e)[r]=s[r]}}(this,(e=>(()=>{"use strict";var t={654:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SUBSCRIBED_TAG_NAME=void 0,t.SUBSCRIBED_TAG_NAME="ot-doc-subscribed"},619:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Db=void 0;t.Db=class{async getCommittedOpVersion(e,t,s){const r=await this.getOps(e,0,t);for(let e=r.length;e--;){const t=r[e];if(s.src===t.src&&s.seq===t.seq)return t.v}return null}}},985:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MemoryDb=void 0;const r=s(619);class n extends r.Db{constructor(e){var t,s;super(),this.ops=new Map,this.documents=new Map,this.fragments=new Map,this.mockWaitTime=null!==(t=null==e?void 0:e.mockWaitTime)&&void 0!==t?t:0,this.randomWaitTime=null!==(s=null==e?void 0:e.randomWaitTime)&&void 0!==s&&s}async getSnapshot(e){return this.execute((async()=>{const t=this.documents.get(e);if(!t)return null;const s=this.fragments.get(e),r=s?JSON.parse(JSON.stringify(Object.fromEntries(s))):{};return{id:e,v:t.snapshotVersion,type:t.type,fragments:r}}))}getDocument(e){return this.execute((()=>{const t=this.documents.get(e);return t?JSON.parse(JSON.stringify(t)):null}))}getFragment(e,t){return this.execute((()=>{var s;const r=this.documents.get(e);if(!r)return null;const n=r.snapshotVersion,i=null===(s=this.fragments.get(e))||void 0===s?void 0:s.get(t);return{version:n,data:i?JSON.parse(JSON.stringify(i)):null}}))}getOps(e,t,s){return this.execute((()=>{const r=this.ops.get(e);if(!r)return[];s=null!=s?s:Number.MAX_SAFE_INTEGER;const n=r.filter((e=>e.v>=t&&e.v<s));return JSON.parse(JSON.stringify(n))}))}commitOp(e,t,s){return this.execute((()=>{var r;if(t=JSON.parse(JSON.stringify(t)),s=JSON.parse(JSON.stringify(s)),t.create){if(this.documents.has(e))return!1;const{version:r,snapshotVersion:n,type:i}=s;return this.documents.set(e,{id:e,version:r,snapshotVersion:n,type:i}),this.ops.set(e,[t]),this.fragments.set(e,new Map),!0}if(t.del)return!!this.documents.has(e)&&(this.documents.delete(e),this.ops.delete(e),this.fragments.delete(e),!0);{const n=null===(r=this.ops.get(e))||void 0===r?void 0:r.length;return t.v===n&&(this.ops.get(e).push(t),this.documents.get(e).version=s.version,!0)}}))}commitSnapshot(e,t){return this.execute((()=>{var s,r,n;t=JSON.parse(JSON.stringify(t));const i=this.documents.get(e);if(t.fragmentsChanges.deleteSnapshot&&!i)return!0;if(t.fromVersion!==i.snapshotVersion)return!1;if(t.v<=i.snapshotVersion)return!1;i.snapshotVersion=t.v;const a=t.fragmentsChanges;if(a.deleteSnapshot)this.fragments.delete(e);else{if(a.setSnapshotFragments){const t=this.fragments.get(e);return t.clear(),Object.entries(a.setSnapshotFragments).forEach((([e,s])=>{t.set(e,s)})),!0}{const t=this.fragments.get(e);Object.entries(null!==(s=a.createFragments)&&void 0!==s?s:{}).forEach((async([e,s])=>{t.has(e)||t.set(e,s)})),Object.entries(null!==(r=a.updateFragments)&&void 0!==r?r:{}).forEach((async([e,s])=>{t.has(e)&&t.set(e,s)})),null===(n=a.deleteFragments)||void 0===n||n.forEach((e=>{t.delete(e)}))}}return!0}))}close(){return this.execute((()=>{}))}dump(){const e={ops:this.ops,documents:this.documents,fragments:this.fragments};return JSON.parse(JSON.stringify(e,((e,t)=>t instanceof Map?Object.fromEntries(t.entries()):t)))}_wait(){const e=this.randomWaitTime?Math.random()*this.mockWaitTime:this.mockWaitTime;return new Promise((t=>setTimeout(t,e)))}async execute(e){return await this._wait(),await e()}}t.MemoryDb=n},347:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DocumentController=void 0;const r=s(127),n=s(961),i=s(660),a=s(124),o=s(654),c=r.LoggerManager.createLogger("OT.Document"),_=i.MessageActions,h=i.OTError.CODES,u=new a.SerialQueueGroup;function l(e){return{id:e.id,v:e.v,data:e.data,type:e.type}}t.DocumentController=class{constructor(e){this.service=e}async trigger(e,t,s){await this.service.trigger(e,t,s)}send(e,t){e.send(t,i.OT_DOC_MESSAGE_TYPE)}_sendOp(e,t){const s=(0,n.createOpMessage)(t);this.send(e,s)}_broadcastOp(e,t){const s=(0,n.createOpMessage)(t);e.broadcastToRoomChannel(o.SUBSCRIBED_TAG_NAME,s,i.OT_DOC_MESSAGE_TYPE)}_sendOps(e,t){if(t&&0!==t.length)for(let s=0;s<t.length;s++)this._sendOp(e,t[s])}async _reply(e,t,s){s.a=t.a;const r={connection:e,request:t,reply:s};await this.trigger("reply",r,(s=>{s?this._replyError(e,t,s):this.send(e,r.reply)}))}async _replyError(e,t,s){t.error=function(e){if(e instanceof i.OTError)return{code:e.code,message:e.message};if(e instanceof Error)return{code:h.ERR_UNKNOWN_ERROR,message:e.message};if("string"==typeof e)return{code:h.ERR_UNKNOWN_ERROR,message:e};c.warn("Unknown error type",{error:e})}(s),this.send(e,t)}async _messageHandler(e,t){const s=this;if(null===t||"object"!=typeof t)return void s.close(e,new i.OTError(h.ERR_MESSAGE_BADLY_FORMED,"Received non-object message"));const r=t;await this.trigger("receive",{connection:e,request:r},(async t=>{t?await s._replyError(e,r,t):await s._handleMessage(e,r,((t,n)=>{t?s._replyError(e,r,t):s._reply(e,r,n||{})}))}))}_checkRequest(e){if(e.a===_.op&&!(0,n.isNullOrUndefined)(e.v)&&("number"!=typeof e.v||e.v<0))return"Invalid version"}async _handleMessage(e,t,s){const r=this._checkRequest(t);if(r)return s(new i.OTError(h.ERR_MESSAGE_BADLY_FORMED,r));switch(t.a){case _.fetch:return await this._fetch(e,t.v,s);case _.subscribe:return await this._subscribe(e,t.v,s);case _.unsubscribe:return await this._unsubscribe(e);case _.op:return await this._submit(e,t,s);case _.fetchHistorySnapshot:return await this._fetchHistorySnapshot(e,t,s);default:return await s(new i.OTError(h.ERR_MESSAGE_BADLY_FORMED,"Invalid or unknown message"))}}async _fetch(e,t,s){if(!(0,n.isNullOrUndefined)(t))return await this._fetchOps(e,t,s);c.info("Fetching snapshot",{docId:e.roomId,connectionId:e.id}),await this.service._fetch(e.roomId,{connection:e},((t,r)=>t?(c.warn("Fetch snapshot failed",{docId:e.roomId,connectionId:e.id,error:t}),s(t)):(c.info("Snapshot fetched successfully",{docId:e.roomId,connectionId:e.id,version:r.v}),s(null,{data:l(r)}))))}async _fetchOps(e,t,s){await this.service._getOps(e.roomId,t,void 0,{connection:e},((t,r)=>t?s(t):(this._sendOps(e,r),s())))}async _subscribe(e,t,s){const r=this;c.info("Subscribing to document",{docId:e.roomId,connectionId:e.id,version:t}),await this.service._subscribe(e.roomId,t,{connection:e},(async(n,i)=>{if(n)return c.warn("Subscribe failed",{docId:e.roomId,connectionId:e.id,version:t,error:n}),s(n);const{ops:a,snapshot:_}=i;return a&&r._sendOps(e,a),await e.joinRoomChannel(o.SUBSCRIBED_TAG_NAME),c.info("Client subscribed successfully",{docId:e.roomId,connectionId:e.id,version:(null==_?void 0:_.v)||t}),_?s(null,{data:l(_)}):s()}))}async _unsubscribe(e){await e.leaveRoomChannel(o.SUBSCRIBED_TAG_NAME)}async _submit(e,t,s){const r=function(e,t){const s=e.src||t;if(e.op)return function(e,t,s,r,n,i){return{src:e,seq:t,v:s,op:r,x:n,m:i}}(s,e.seq,e.v,e.op,e.x);if(e.create)return function(e,t,s,r,n,i){return{src:e,seq:t,v:s,create:r,x:n,m:i}}(s,e.seq,e.v,e.create,e.x);if(e.del)return function(e,t,s,r,n,i){return{src:e,seq:t,v:s,del:r,x:n,m:i}}(s,e.seq,e.v,e.del,e.x);if(e.restore)return function(e,t,s,r,n,i){return{src:e,seq:t,v:s,restore:r,x:n,m:i}}(s,e.seq,e.v,e.restore,e.x)}(t,e.id);return r?r.seq>=i.util.MAX_SAFE_INTEGER?s(new i.OTError(h.ERR_CONNECTION_SEQ_INTEGER_OVERFLOW,"Connection seq has exceeded the max safe integer, maybe from being open for too long")):await u.get(e.roomId).add((()=>this._submitOp(e,r,s))):s(new i.OTError(h.ERR_MESSAGE_BADLY_FORMED,"Invalid op message"))}async _submitOp(e,t,s){const r=this;await this.service._submit(e.roomId,t,{connection:e},(t=>{const s=performance.now();r._broadcastOp(e,t.op),r.service._emitTiming("submit.op.broadcast",performance.now()-s)}),((n,a)=>{const o={src:t.src,seq:t.seq,v:t.v};return n?n instanceof i.OTError&&n.code==h.ERR_OP_ALREADY_SUBMITTED?s(null,o):s(n):(r._sendOps(e,a),s(null,o))}))}async _fetchHistorySnapshot(e,t,s){if(void 0===t.v)return s(new i.OTError(h.ERR_MESSAGE_BADLY_FORMED,"Invalid fetch history snapshot message"));c.info("Fetching history snapshot",{docId:e.roomId,connectionId:e.id,version:t.v}),await this.service._fetchHistorySnapshot(e.roomId,t.v,{connection:e},((r,n)=>r?(c.warn("Fetch history snapshot failed",{docId:e.roomId,connectionId:e.id,version:t.v,error:r}),s(r)):(c.info("History snapshot fetched successfully",{docId:e.roomId,connectionId:e.id,version:t.v}),s(null,{id:t.id,data:n}))))}close(e,t){t&&c.warn("Connection closed due to error",{connectionId:e.id,roomId:e.roomId,error:t}),e.close()}}},763:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.documentFeature=function(e){const t=e||new r.DocumentServices,s=new n.DocumentController(t);return{middlewares:{message:async(e,t)=>e.type!==i.OT_DOC_MESSAGE_TYPE?await t():s._messageHandler(e.connection,e.data)},onUseFeature:e=>{t._server=e}}};const r=s(89),n=s(347),i=s(660)},89:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DocumentServices=void 0;const r=s(660),n=s(127),i=s(259),a=s(961),o=s(551),c=s(155),_=s(469),h=s(36),u=s(985),l=s(96),d=s(930),E=s(576),m=s(654),p=s(449),O=r.OTError.CODES;class R extends n.Middleware{constructor(e){var t,s,r;super(),e=null!=e?e:{},this.db=null!==(t=e.db)&&void 0!==t?t:new u.MemoryDb,this.milestoneDb=null!==(s=e.milestoneDb)&&void 0!==s?s:new l.MemoryMilestoneDB,this.maxSubmitRetries=e.maxSubmitRetries,this.submitSnapshotBatchSize=null!==(r=e.submitSnapshotBatchSize)&&void 0!==r?r:100,this._cache=new d.MemoryCache,this._fragmentsCache=new p.FragmentsCache(this._cache),this._store=new E.Store(this.db,this._fragmentsCache,{submitSnapshotBatchSize:this.submitSnapshotBatchSize,maxSubmitRetries:this.maxSubmitRetries})}async fetch(e,t){let s;const r=await this._fetch(e,t||{},(e=>{s=e}));if(s)throw s;return r}async _fetch(e,t,s){const r=Date.now(),n=this;try{const a=await n._getSnapshot(e,t);return await n._sanitizeSnapshots([a],i.SnapshotTypes.current,t,(async i=>i?s(i):(await n._emitTiming("fetch",Date.now()-r,Object.assign(Object.assign({},t),{id:e})),s(null,a)))),a}catch(e){await s(e)}}async getOps(e,t,s,r){let n;const i=await this._getOps(e,t,s,r||{},(e=>{n=e}));if(n)throw n;return i}async _getOps(e,t,s,r,n){const i=this,a=Date.now();return await i._getSanitizedOps(e,t,s,r||{},(async(o,c)=>o?n(o):(await i._emitTiming("getOps",Date.now()-a,Object.assign(Object.assign({},r),{id:e,from:t,to:s})),n(null,c))))}async _subscribe(e,t,s,r){const n=this,i=Date.now();(0,a.isNullOrUndefined)(t)?await n._fetch(e,s,(async(a,o)=>a?r(a):(await n._emitTiming("subscribe.snapshot",Date.now()-i,Object.assign(Object.assign({},s),{id:e,version:t})),r(null,{snapshot:o})))):await n._getSanitizedOps(e,t,void 0,s,(async(a,o)=>a?r(a):(await n._emitTiming("subscribe.ops",Date.now()-i,Object.assign(Object.assign({},s),{id:e,version:t})),r(null,{ops:o}))))}async submit(e,t,s){let n;const i=this._server,o=await this._submit(e,t,s||{},(t=>{if(i){const s=(0,a.createOpMessage)(t.op);i.broadcastToRoomChannel(e,m.SUBSCRIBED_TAG_NAME,s,r.OT_DOC_MESSAGE_TYPE)}}),(e=>{n=e}));if(n)throw n;return o}async _submit(e,t,s,r,n){const i=c.ot.checkOp(t);if(i)return n(i),[];const a=this,_=new o.SubmitRequest(this,e,t,s),h={connection:s.connection,request:_},u=(e,t)=>(a.emit("submitRequestEnd",{request:_,err:e}),n(e,t));return await a.trigger("submit",h,(async t=>{if(t)return u(t);await _.submit(r,(async t=>{if(t)return u(t);await a._sanitizeOps(e,_.ops,h,(async e=>e?u(e):(a._emitTiming("submit.op.total",Date.now()-_.start,_),u(null,_.ops))))}))})),_.ops}async fetchHistorySnapshot(e,t,s){let r;const n=await this._fetchHistorySnapshot(e,t,s||{},(e=>{r=e}));if(r)throw r;return n}async _fetchHistorySnapshot(e,t,s,r){try{const n=Date.now(),a=await this._fetchHistorySnapshotImp(e,t),o=i.SnapshotTypes.byVersion;return await this._sanitizeSnapshots([a],o,s,(async e=>e?r(e):(await this._emitTiming("fetchSnapshot",Date.now()-n,Object.assign(Object.assign({},s),{version:t})),r(null,a)))),a}catch(e){await r(e)}}async _fetchHistorySnapshotImp(e,t){const s=this._store,n=this;if(void 0===t)return await n._getSnapshot(e);const i=await this.milestoneDb.getMilestoneSnapshot(e,t),a=i?i.v:0,o=await s.getOps(e,a,t),c=await n._buildSnapshotFromOps(e,i,o);if(t>c.v)throw new r.OTError(O.ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT,"Requested version exceeds latest snapshot version");return c}async _buildSnapshotFromOps(e,t,s){const r=null!=t?t:{id:e,v:0},n=new h.SnapshotFragmentsRequest(e,void 0,r.v,r.fragments),i=await c.ot.applyOps(r,s,n);if(i)throw i;return n.applyChangesToSnapshot(r),c.ot.composeFragments(r),r}async _sanitizeSnapshots(e,t,s,n){const i=new _.ReadSnapshotsRequest(e,t,s);await this.trigger("readSnapshots",{connection:s.connection,request:i},(e=>e?n((0,r.wrapError)(e,O.ERR_SNAPSHOT_READS_REJECTED)):i.hasSnapshotRejection()?n(i.getReadSnapshotsError()):n()))}async _getSanitizedOps(e,t,s,r,n){const i=await this._store.getOps(e,t,s,null==r?void 0:r.options);return await this._sanitizeOps(e,i,r,(e=>e?n(e):n(null,i))),i}async _sanitizeOps(e,t,s,r){for(const n of t){let t;if(await this._sanitizeOp(e,n,s,(e=>{t=e})),t)return r(t)}return r()}async _sanitizeOp(e,t,s,n){await this.trigger("readOp",{connection:s.connection,request:{id:e,op:t,context:s}},(e=>e?n((0,r.wrapError)(e)):n()))}async _getSnapshot(e,t){const s=null==t?void 0:t.options,r=await this._store.getSnapshot(e,s);return r?(c.ot.composeFragments(r),r):{id:e,v:0}}_emitTiming(e,t,s){return this.emit("timing",{action:e,cost:t,m:s})}}t.DocumentServices=R},259:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Hooks=t.SnapshotTypes=void 0,t.SnapshotTypes={current:"current",byVersion:"byVersion",byTimestamp:"byTimestamp"},t.Hooks={submitRequestEnd:"submitRequestEnd",timing:"timing"}},96:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MemoryMilestoneDB=void 0;const r=s(660),n=s(961),i=r.OTError.CODES;t.MemoryMilestoneDB=class{constructor(e){var t;this.interval=null!==(t=null==e?void 0:e.interval)&&void 0!==t?t:-1,this.map=new Map}saveMilestoneSnapshot(e){return new Promise((t=>{let s=this.map.get(e.id);s||(s=[],this.map.set(e.id,s)),s.push((0,r.clone)(e)),s.length>=2&&s[s.length-2].v>s[s.length-1].v&&s.sort(((e,t)=>e.v-t.v)),t(!0)}))}getMilestoneSnapshot(e,t){const s=function(e){return function(t,s){return!(0,n.isNullOrUndefined)(e)&&s.v>e}}(t);return this._findMilestoneSnapshot(e,s)}_findMilestoneSnapshot(e,t){return new Promise((s=>{if(!e)throw new r.OTError(i.ERR_MILESTONE_ARGUMENT_INVALID,"Missing ID");const n=this._getMilestoneSnapshots(e);let a=null;for(let e=0;e<n.length;e++){const s=n[e];if(t(a,s))break;a=s}s((0,r.clone)(a))}))}_getMilestoneSnapshots(e){var t;return null!==(t=this.map.get(e))&&void 0!==t?t:[]}}},155:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ot=t.composeFragments=t.applyOps=t.transform=t.apply=t.normalizeType=t.checkOp=void 0;const r=s(513),n=s(961),i=s(660),a=i.OTError.CODES,o="default";t.checkOp=function(e){if((0,n.isNullOrUndefined)(e)||"object"!=typeof e)return new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if((0,n.isNullOrUndefined)(e.create)){if((0,n.isNullOrUndefined)(e.del)){if((0,n.isNullOrUndefined)(e.restore)){if(!("op"in e))return new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"Missing op, create, del, or restore")}else if("object"!=typeof e.restore||"number"!=typeof e.restore.v||e.restore.v<=0)return new i.OTError(a.ERR_RESTORE_TARGET_VERSION_INVALID,"restore must be an object with valid version number")}else if(!0!==e.del)return new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else{if("object"!=typeof e.create)return new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");const t=e.create.type;if("string"!=typeof t)return new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"Missing create type");const s=r.TypesManager.map[t];if((0,n.isNullOrUndefined)(s)||"object"!=typeof s)return new i.OTError(a.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}return(0,n.isNullOrUndefined)(e.src)||"string"==typeof e.src?(0,n.isNullOrUndefined)(e.seq)||"number"==typeof e.seq?(0,n.isNullOrUndefined)(e.src)&&!(0,n.isNullOrUndefined)(e.seq)||!(0,n.isNullOrUndefined)(e.src)&&(0,n.isNullOrUndefined)(e.seq)?new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together"):(0,n.isNullOrUndefined)(e.m)||"object"==typeof e.m?void 0:new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null"):new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"seq must be a number"):new i.OTError(a.ERR_OT_OP_BADLY_FORMED,"src must be a string")};t.normalizeType=function(e){return r.TypesManager.map[e]&&r.TypesManager.map[e].uri};function c(e,t){let s;return s=e.createFragments?e.createFragments(t):{[o]:e.create(t)},s}t.apply=async function(e,t,s){if("object"!=typeof e)return new i.OTError(a.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(!(0,n.isNullOrUndefined)(e.v)&&!(0,n.isNullOrUndefined)(t.v)&&e.v!==t.v)return new i.OTError(a.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(t.create){const n=t.create,o=r.TypesManager.map[n.type];if(!o)return new i.OTError(a.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{const t=c(o,n.data);s.create(t),e.type=o.uri,e.v++}catch(e){return(0,i.createOTError)(a.ERR_OT_OP_NOT_APPLIED,e)}}else if(t.del)s.delete(),e.data=void 0,e.type=void 0,e.v++;else if(t.restore){if(!e.type)return new i.OTError(a.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");const o=r.TypesManager.map[e.type];if(!o)return new i.OTError(a.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");const _=t.restore.v;if(_<=0||_>=e.v)return new i.OTError(a.ERR_RESTORE_TARGET_VERSION_INVALID,`Target version ${_} is invalid. Current version is ${e.v}`);if((0,n.isNullOrUndefined)(t.restore.data))return new i.OTError(a.ERR_RESTORE_TARGET_DATA_INVALID,"Target data is invalid");try{s.setSnapshotFragments(c(o,t.restore.data))}catch(e){return(0,i.createOTError)(a.ERR_OT_OP_NOT_APPLIED,e)}e.v++}else if("op"in t){const n=await async function(e,t,s){if(!e.type)return new i.OTError(a.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(void 0===t)return new i.OTError(a.ERR_OT_OP_NOT_PROVIDED,"Missing op");const n=r.TypesManager.map[e.type];if(!n)return new i.OTError(a.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{if(n.applyFragments)await n.applyFragments(s,t);else{const e=await s.getFragment(o),r=n.apply(e,t);await s.updateFragment(o,r)}}catch(e){return i.InternalOTError.isError(e,i.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION)?e:(0,i.createOTError)(a.ERR_OT_OP_NOT_APPLIED,e)}}(e,t.op,s);if(n)return n;e.v++}else e.v++};t.transform=function(e,t,s){if(!(0,n.isNullOrUndefined)(t.v)&&t.v!==s.v)return new i.OTError(a.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(s.del){if(t.create||"op"in t||t.restore)return new i.OTError(a.ERR_DOC_WAS_DELETED,"Document was deleted")}else if(s.restore){if(t.create||"op"in t||t.del||t.restore)return new i.OTError(a.ERR_DOC_WAS_RESTORE,"Document was restored, please refetch")}else{if(s.create&&("op"in t||t.create||t.del||t.restore)||"op"in s&&t.create)return new i.OTError(a.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in s&&"op"in t){if(!e)return new i.OTError(a.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if("string"==typeof e&&!(e=r.TypesManager.map[e]))return new i.OTError(a.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{t.op=e.transform(t.op,s.op,"left")}catch(e){return new i.OTError(a.ERR_OT_OP_TRANSFORM_FAILED,"Op transform failed")}}}(0,n.isNullOrUndefined)(t.v)||t.v++};t.applyOps=async function(e,s,r){for(let n=0;n<s.length;n++){const i=s[n];e.v=i.v;const a=await(0,t.apply)(e,i,r);if(a)return a}};t.composeFragments=function(e){if(!e.type)return;const t=r.TypesManager.map[e.type];t&&e.fragments&&(t.composeFragments?e.data=t.composeFragments(e.fragments):e.data=e.fragments[o],delete e.fragments)},t.ot={checkOp:t.checkOp,normalizeType:t.normalizeType,apply:t.apply,transform:t.transform,applyOps:t.applyOps,composeFragments:t.composeFragments}},766:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Queue=void 0;class s{constructor(e){this.value=e}}t.Queue=class{constructor(){this._size=0}enqueue(e){const t=new s(e);this._head?(this._tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._size++}dequeue(){const e=this._head;if(e)return e.next?(this._head=e.next,e.next=void 0):(this._head=void 0,this._tail=void 0),this._size--,e.value}peek(){if(this._head)return this._head.value}clear(){this._head=void 0,this._tail=void 0,this._size=0}get size(){return this._size}get isEmpty(){return 0===this._size}}},124:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SerialQueueGroup=void 0;const r=s(56);t.SerialQueueGroup=class{constructor(e){this._cleaner=null,this.queues=new Map,this._serialQueTimeout=null!=e?e:3e5,this._autoCleanupInterval=Math.floor(this._serialQueTimeout/2)}get(e){let t=this.queues.get(e);return t||(t=new r.SerialQueue,this.queues.set(e,t),this._startAutoCleanup()),t}_startAutoCleanup(){this._cleaner||0===this.queues.size||(this._cleaner=setTimeout((()=>{const e=Date.now();this.queues.forEach(((t,s)=>{t.isEmpty&&e-t.lastActiveTime>this._serialQueTimeout&&this.queues.delete(s)})),this._cleaner=null,this.queues.size>0&&this._startAutoCleanup()}),this._autoCleanupInterval),this._cleaner&&this._cleaner.unref&&this._cleaner.unref())}}},56:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SerialQueue=void 0;const r=s(766);t.SerialQueue=class{constructor(){this._isActive=!1,this._queue=new r.Queue,this._lastActiveTime=Date.now()}async add(e){return new Promise(((t,s)=>{this._queue.enqueue({task:e,resolve:t,reject:s}),this._isActive||this._runNext()}))}async _runNext(){if(this._isActive||0===this._queue.size)return;this._isActive=!0;const{task:e,resolve:t,reject:s}=this._queue.dequeue();try{t(await e())}catch(e){s(e)}finally{this._isActive=!1,this._lastActiveTime=Date.now(),this._queue.size&&this._runNext()}}get isActive(){return this._isActive}get pendingCount(){return this._queue.size}get isEmpty(){return!this._isActive&&this._queue.isEmpty}get lastActiveTime(){return this._lastActiveTime}}},469:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ReadSnapshotsRequest=void 0;const r=s(660),n=s(961);t.ReadSnapshotsRequest=class{constructor(e,t,s){this._idToError=null,this.snapshots=e,this.snapshotType=t,this.context=s||{}}rejectSnapshotRead(e,t){this._idToError||(this._idToError=Object.create(null)),this._idToError[e.id]=t}rejectSnapshotReadSilent(e,t){this.rejectSnapshotRead(e,this.silentRejectionError(t))}silentRejectionError(e){return new r.OTError(r.OTError.CODES.ERR_SNAPSHOT_READ_SILENT_REJECTION,e)}hasSnapshotRejection(){return!(0,n.isNullOrUndefined)(this._idToError)}getReadSnapshotsError(){const e=this.snapshots,t=this._idToError;if(0===e.length)return;if(1===e.length){const s=t[e[0].id];return s||void 0}const s=new r.OTError(r.OTError.CODES.ERR_SNAPSHOT_READS_REJECTED);return s.idToError=t,s}}},36:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SnapshotFragmentsRequest=void 0,t.applyChangesToSnapshot=n;const r=s(961);function n(e,t){var s,r,n;if(t.deleteSnapshot)e.fragments={};else if(t.setSnapshotFragments)e.fragments=Object.assign({},t.setSnapshotFragments);else{const i=null!==(s=e.fragments)&&void 0!==s?s:{};for(const[e,s]of Object.entries(null!==(r=t.createFragments)&&void 0!==r?r:{}))i[e]=s;for(const[e,s]of Object.entries(null!==(n=t.updateFragments)&&void 0!==n?n:{}))i[e]=s;t.deleteFragments&&t.deleteFragments.length>0&&t.deleteFragments.forEach((e=>delete i[e])),e.fragments=i}}t.SnapshotFragmentsRequest=class{constructor(e,t,s,n){this._originFragmentsIsExist=new Map,this._fragmentsMap=new Map,this._fragmentsStatus=new Map,this._deleteSnapshot=!1,this._isFullReplacementFragments=!1,this._docId=e,this._fetcher=t,this._version=null!=s?s:-1,n&&Object.entries(n).forEach((([e,t])=>{this._originFragmentsIsExist.set(e,!(0,r.isNullOrUndefined)(t)),this._fragmentsMap.set(e,t)}))}async _loadFragment(e){const t=await this._fetcher.getFragment(this._docId,e,this._version);this._fragmentsMap.set(e,t),this._originFragmentsIsExist.set(e,!(0,r.isNullOrUndefined)(t))}async getFragment(e){var t;return!this._fetcher||this._isFullReplacementFragments||this._fragmentsMap.has(e)||await this._loadFragment(e),null!==(t=this._fragmentsMap.get(e))&&void 0!==t?t:null}async createFragment(e,t){await this._checkOperationValid(e,"create"),await this._createOrUpdateFragment(e,t)}async updateFragment(e,t){await this._checkOperationValid(e,"update"),await this._createOrUpdateFragment(e,t)}async deleteFragment(e){await this._checkOperationValid(e,"delete");await this._fragmentIsOriginExist(e)?this._fragmentsStatus.set(e,"delete"):this._fragmentsStatus.delete(e),this._fragmentsMap.set(e,null)}async _createOrUpdateFragment(e,t){await this._fragmentIsOriginExist(e)?this._fragmentsStatus.set(e,"update"):this._fragmentsStatus.set(e,"create"),this._fragmentsMap.set(e,t)}create(e){Object.entries(e).forEach((([e,t])=>{(0,r.isNullOrUndefined)(t)||(this._fragmentsStatus.set(e,"create"),this._fragmentsMap.set(e,t))}))}delete(){this._deleteSnapshot=!0,this._fragmentsStatus.clear(),this._fragmentsMap.clear()}setSnapshotFragments(e){this._isFullReplacementFragments=!0,this._fragmentsStatus.clear(),this._fragmentsMap.clear(),this._originFragmentsIsExist.clear(),Object.entries(e).forEach((([e,t])=>{this._fragmentsMap.set(e,t),this._originFragmentsIsExist.set(e,!0)}))}getChanges(){if(this._isFullReplacementFragments){const e={};return this._fragmentsMap.forEach(((t,s)=>{(0,r.isNullOrUndefined)(t)||(e[s]=t)})),{setSnapshotFragments:e}}const e=this._fragmentsMap,t=this._deleteSnapshot,s={},n={},i=[];return this._fragmentsStatus.forEach(((t,a)=>{if("create"===t){const t=e.get(a);(0,r.isNullOrUndefined)(t)||(s[a]=t)}else if("update"===t){const t=e.get(a);(0,r.isNullOrUndefined)(t)||(n[a]=t)}else"delete"===t&&i.push(a)})),{createFragments:s,updateFragments:n,deleteFragments:i,deleteSnapshot:t}}applyChangesToSnapshot(e){n(e,this.getChanges())}async _checkOperationValid(e,t){const s=await this._currentFragmentState(e);if(!this._checkOperationTypeValid(s,t))throw new Error(`Invalid snapshot fragment operation: ${e} ${s} -> ${t}`)}async _currentFragmentState(e){const t=this._fragmentsStatus.get(e);if(t)return t;return await this._fragmentIsOriginExist(e)?"exist":"notExist"}async _fragmentIsOriginExist(e){return this._originFragmentsIsExist.has(e)?this._originFragmentsIsExist.get(e):!!this._fetcher&&(await this._loadFragment(e),this._originFragmentsIsExist.get(e))}_checkOperationTypeValid(e,t){return"exist"===e||"create"===e||"update"===e?"update"===t||"delete"===t:("notExist"===e||"delete"===e)&&("delete"===t||"create"===t)}}},930:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MemoryCache=void 0;const s={stdTTL:6e4,checkPeriod:6e4};t.MemoryCache=class{constructor(e={}){this.get=this.get.bind(this),this.multiSet=this.multiSet.bind(this),this.del=this.del.bind(this),this.keys=this.keys.bind(this),this.has=this.has.bind(this),this.getStats=this.getStats.bind(this),this.flushStats=this.flushStats.bind(this),this.close=this.close.bind(this),this._checkData=this._checkData.bind(this),this._wrap=this._wrap.bind(this),this._unwrap=this._unwrap.bind(this),this.data=new Map,this.checkTimeout=null,this.options=Object.assign(s,e),this.stats={hits:0,misses:0,keys:0},this._checkData()}async get(e){return this._getImp(e)}async multiGet(e){const t={};for(const s of e)t[s]=this._getImp(s);return t}_getImp(e){const t=this.data.get(e);if(t)return this.stats.hits++,t.t=this._timeoutDate(),this._unwrap(t);this.stats.misses++}async set(e,t,s,r){this._setImp(e,t,s,r)}async multiSet(e){for(const t of e){const{key:e,val:s,meta:r,options:n}=t;this._setImp(e,s,r,n)}}_setImp(e,t,s,r){var n;const i=null!==(n=null==r?void 0:r.ttl)&&void 0!==n?n:this.options.stdTTL,a=null==r?void 0:r.shouldUpdate;if(a&&void 0!==s){const t=this.data.get(e);if(t&&!a(t.m,s))return}const o=!this.data.has(e);this.data.set(e,this._wrap(t,s,i)),o&&this.stats.keys++}async del(e){this._delImp(e)}async multiDel(e){for(const t of e)this._delImp(t)}_delImp(e){this.data.has(e)&&(this.data.delete(e),this.stats.keys--)}async keys(){return[...this.data.keys()]}async has(e){return this.data.has(e)}async getStats(){return this.stats}async flushStats(){this.stats={hits:0,misses:0,keys:0}}async close(){this._killCheckPeriod()}async clear(){this.data.clear(),this.stats.keys=0}_checkData(){const e=Date.now();this.data.forEach(((t,s)=>{t.t<e&&(this.stats.keys--,this.data.delete(s))})),this.options.checkPeriod>0&&(this.checkTimeout=setTimeout((()=>this._checkData()),this.options.checkPeriod),this.checkTimeout&&this.checkTimeout.unref&&this.checkTimeout.unref())}_killCheckPeriod(){this.checkTimeout&&(clearTimeout(this.checkTimeout),this.checkTimeout=null)}_timeoutDate(e){return Date.now()+(null!=e?e:this.options.stdTTL)}_wrap(e,t,s){s=null!=s?s:this.options.stdTTL;return{t:this._timeoutDate(s),v:JSON.stringify(e),m:t}}_unwrap(e){if(e)return{v:JSON.parse(e.v),m:e.m}}}},771:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentsCacheManager=void 0;const r=s(961);t.FragmentsCacheManager=class{constructor(e){this.cacheStats={fragmentHitCount:0,fragmentMissCount:0,fragmentGetCount:0,fragmentSetCount:0,fragmentDeleteCount:0},this.timeStats={},this.cache=e}async getFragmentCache(e,t){const s=await this.cache.getFragment(e,t);return s?(this.cacheStats.fragmentHitCount++,s):(this.cacheStats.fragmentMissCount++,null)}async updateFragmentCacheBySnapshot(e,t){if(null==t?void 0:t.fragments)return this._multiSetFragmentCache(e,t.v,t.fragments)}async updateFragmentCacheByFragmentChanges(e,t){const{createFragments:s,updateFragments:r,deleteFragments:n,deleteSnapshot:i,setSnapshotFragments:a}=t.fragmentsChanges;i?await this.delAllFragmentCache(e):a?(await this.delAllFragmentCache(e),await this._multiSetFragmentCache(e,t.v,a)):((s||r)&&await this._multiSetFragmentCache(e,t.v,Object.assign(Object.assign({},s),r)),n&&n.length>0&&await this._multiDelFragmentCache(e,n))}async setFragmentCache(e,t,s){if((0,r.isNullOrUndefined)(s))return await this._delFragmentCache(e,t);this.cacheStats.fragmentSetCount++,await this.cache.setFragment(e,t,s.version,s.data)}async delFragmentCache(e,t){await this._delFragmentCache(e,t)}async delAllFragmentCache(e){this.cacheStats.fragmentDeleteCount++,await this.cache.delAllFragments(e)}async getCacheStats(){return Object.assign({},this.cacheStats)}async flushCacheStats(){this.cacheStats.fragmentHitCount=0,this.cacheStats.fragmentMissCount=0,this.cacheStats.fragmentGetCount=0,this.cacheStats.fragmentSetCount=0,this.cacheStats.fragmentDeleteCount=0}async _multiSetFragmentCache(e,t,s){this.cacheStats.fragmentSetCount++,await this.cache.multiSetFragments(e,t,s)}async _multiDelFragmentCache(e,t){this.cacheStats.fragmentDeleteCount++,await this.cache.multiDelFragments(e,t)}async _delFragmentCache(e,t){this.cacheStats.fragmentDeleteCount++,await this.cache.delFragment(e,t)}}},449:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentsCache=void 0;t.FragmentsCache=class{constructor(e){this._cache=e}async getFragment(e,t){const s=await this._cache.get(this._fragmentKey(e,t));return s?{data:s.v,version:s.m.version}:void 0}async setFragment(e,t,s,r){const n=this._fragmentKey(e,t);await this._cache.set(n,r,{version:s},{shouldUpdate:this._shouldUpdate})}async multiSetFragments(e,t,s){const r=Object.entries(s).map((([s,r])=>({key:this._fragmentKey(e,s),val:r,meta:{version:t},options:{shouldUpdate:this._shouldUpdate}})));0!==r.length&&await this._cache.multiSet(r)}async delFragment(e,t){await this._cache.del(this._fragmentKey(e,t))}async multiDelFragments(e,t){const s=t.map((t=>this._fragmentKey(e,t)));await this._cache.multiDel(s)}async delAllFragments(e){const t=await this._getAllFragmentKeys(e);return await this._cache.multiDel(t)}async clearFragments(){return await this._cache.clear()}_fragmentKey(e,t){return`fragment:${e}:${t}`}async _getAllFragmentKeys(e){const t=`fragment:${e}:`;return(await this._cache.keys()).filter((e=>e.startsWith(t)))}_shouldUpdate(e,t){return t.version>e.version}}},576:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Store=void 0,t.buildFetcherByDb=_;const r=s(127),n=s(660),i=s(36),a=s(771),o=s(155),c=r.LoggerManager.createLogger("OT.Store");function _(e){return{getFragment:async(t,s,r)=>{const i=await e.getFragment(t,s);if(!i||r!==i.version)throw new n.InternalOTError(n.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION);return i.data}}}t.Store=class{constructor(e,t,s){this.db=e,this.fragmentsCache=new a.FragmentsCacheManager(t),this.submitSnapshotBatchSize=s.submitSnapshotBatchSize,this.maxSubmitRetries=s.maxSubmitRetries}async getSnapshot(e,t){const s=await this.db.getDocument(e,t);if(!s)return null;s.snapshotVersion<s.version&&(c.debug("Rebuilding snapshot",{docId:e,fromVersion:s.snapshotVersion,toVersion:s.version}),await this._buildThenCommitSnapshotToDb(e,s.type,s.snapshotVersion,s.version,0));const r=await this.db.getSnapshot(e,t);return await this.fragmentsCache.updateFragmentCacheBySnapshot(e,r),r}async getFragment(e,t,s){const{data:r,needUpdateDbSnapshot:i}=await this._getFragmentImpl(e,t,s);if(!i)return r;if(i){const t=await this.getDocument(e);if(!t||s<t.version)throw new n.InternalOTError(n.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION);if(s>t.version)throw new n.OTError(n.ERROR_CODES.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT);const r=await this._buildThenCommitSnapshotToDb(e,t.type,t.snapshotVersion,t.version,0);r&&await this.fragmentsCache.updateFragmentCacheByFragmentChanges(e,r)}const a=await this._getFragmentImpl(e,t,s);if(a.needUpdateDbSnapshot)throw new n.OTError(n.ERROR_CODES.ERR_UNKNOWN_ERROR,`store get fragment failed, docId:${e}, fragmentId:${t}, requestFragmentVersion:${s}`);return a.data}async _getFragmentImpl(e,t,s){const r=await this._getFragmentCache(e,t,s);if(r)return r;const i=await this.db.getFragment(e,t);if(!i)throw await this.fragmentsCache.delAllFragmentCache(e),new n.InternalOTError(n.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION);if(s<i.version)throw await this.fragmentsCache.setFragmentCache(e,t,i),new n.InternalOTError(n.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION);return s===i.version?(await this.fragmentsCache.setFragmentCache(e,t,i),{data:i.data}):{data:null,needUpdateDbSnapshot:!0}}async _getFragmentCache(e,t,s){const r=await this.fragmentsCache.getFragmentCache(e,t);if(r){const i=r.version;if(s===i)return{data:r.data};if(s>i)await this.fragmentsCache.delFragmentCache(e,t);else{const r=await this.getDocument(e);if(!r)throw await this.fragmentsCache.delAllFragmentCache(e),new n.InternalOTError(n.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION);if(!(i>r.version))throw new n.InternalOTError(n.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION);c.warn("Cache version exceeds database version, database may have been modified externally",{docId:e,fragmentId:t,cacheVersion:i,dbVersion:r.version,requestVersion:s}),await this.fragmentsCache.delAllFragmentCache(e)}}return null}async commitOp(e,t,s,r){return await this.db.commitOp(e,t,s,r)}async commitSnapshot(e,t,s,r){await this.fragmentsCache.updateFragmentCacheByFragmentChanges(e,s);this._shouldSubmitSnapshot(t,r)&&(r.snapshotVersion+1===r.version?await this._commitSnapshotToDb(s,0):await this._buildThenCommitSnapshotToDb(e,r.type,r.snapshotVersion,r.version,0))}_shouldSubmitSnapshot(e,t){return e.create||e.del||e.restore||0===t.snapshotVersion||t.version-t.snapshotVersion>=this.submitSnapshotBatchSize}async getDocument(e,t){return await this.db.getDocument(e,t)}async getOps(e,t,s,r){return this.db.getOps(e,t,s,r)}async getCommittedOpVersion(e,t,s){return this.db.getCommittedOpVersion(e,t,s)}async close(){await this.db.close()}async _buildThenCommitSnapshotToDb(e,t,s,r,a){if(s>=r)return null;const h=await this.db.getOps(e,s,r);if(h.length!==r-s){if(!await this.getDocument(e))return null;throw c.error("Missing ops for snapshot build",{docId:e,fromVersion:s,toVersion:r,expectedOps:r-s,actualOps:h.length}),this._missApplyOpsError()}const u={id:e,type:t,fromVersion:s,v:s,fragmentsChanges:{}},l=new i.SnapshotFragmentsRequest(e,_(this.db),s),d=await o.ot.applyOps(u,h,l);if(d){if(n.InternalOTError.isError(d,n.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION))return c.warn("Snapshot build retry due to version conflict",{docId:e,fromVersion:s,toVersion:r,retryCount:a}),await this._retryBuildThenSubmitSnapshot(e,t,r,a);throw c.warn("Snapshot build failed",{docId:e,fromVersion:s,toVersion:r,error:d.message}),d}return u.fragmentsChanges=l.getChanges(),c.debug("Snapshot built successfully",{docId:e,version:u.v}),await this._commitSnapshotToDb(u,0)}async _retryBuildThenSubmitSnapshot(e,t,s,r){const n=await this.db.getDocument(e);if(!n||s<=n.snapshotVersion)return null;if(r++,void 0!==this.maxSubmitRetries&&r>this.maxSubmitRetries)throw this._maxRetriesError();return await this._buildThenCommitSnapshotToDb(e,t,n.snapshotVersion,s,r)}async _commitSnapshotToDb(e,t){return await this.db.commitSnapshot(e.id,e)?e:await this._retryBuildThenSubmitSnapshot(e.id,e.type,e.v,t)}async getCacheStats(){return await this.fragmentsCache.getCacheStats()}async flushCacheStats(){await this.fragmentsCache.flushCacheStats()}_maxRetriesError(){return new n.OTError(n.ERROR_CODES.ERR_MAX_SUBMIT_SNAPSHOT_RETRIES_EXCEEDED,"Snapshot submit failed. Exceeded max submit retries of "+this.maxSubmitRetries)}_missApplyOpsError(){return new n.OTError(n.ERROR_CODES.ERR_APPLY_OPS_NOT_FOUND,"Build snapshot failed. DB missing ops needed to apply it up to the current snapshot version")}}},551:function(e,t,s){var r,n=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var n=Object.getOwnPropertyDescriptor(t,s);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,n)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(r=function(e){return r=Object.getOwnPropertyNames||function(e){var t=[];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[t.length]=s);return t},r(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s=r(e),a=0;a<s.length;a++)"default"!==s[a]&&n(t,e,s[a]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.SubmitRequest=void 0;const o=s(660),c=s(127),_=s(961),h=a(s(155)),u=s(513),l=s(36),d=o.OTError.CODES,E=u.TypesManager.getType,m=c.LoggerManager.createLogger("OT.SubmitRequest");t.SubmitRequest=class{constructor(e,t,s,r){this.doc=e,this.context=r||{},this.id=t,this.op=s,this.extra=s.x,delete s.x,this.start=Date.now(),this._addOpMeta(),this.maxRetries=e.maxSubmitRetries,this.retries=0,this.ops=[]}async submit(e,t){var s;const r=this,n=this.doc._store,i=this.id,a=this.op,c=performance.now(),h=null!==(s=await n.getDocument(i))&&void 0!==s?s:{id:i,version:0,snapshotVersion:0};r.document=h,r._addDocumentMeta(),await r.doc._emitTiming("submit.op.store.getDocumentInfo",performance.now()-c,r),m.info("Op submit started",this.getLogContext());const u=h.version;if((0,_.isNullOrUndefined)(a.v)){if(a.create&&h.type&&a.src){const e=await n.getCommittedOpVersion(i,u,a);return(0,_.isNullOrUndefined)(e)?t(r.alreadyCreatedError()):(a.v=e,t(r.alreadySubmittedError()))}a.v=u}if(a.v>u)return t(r.newerVersionError());if(a.v<u){const e=performance.now(),s=a.v,o=await n.getOps(i,s,u);if(await r.doc._emitTiming("submit.op.store.getOpsForTransform",performance.now()-e,r),!o||o.length!==u-s)return t(r.missingOpsError());const c=performance.now(),_=r._transformOp(o);if(_)return t(_);if(await r.doc._emitTiming("submit.op.transform",performance.now()-c,r),a.v!==u)return t(r.versionAfterTransformError())}if(h.type){if(a.create)return t(r.alreadyCreatedError())}else if(!a.create)return t(r.docDoesNotExistError());await r.applyOp((async s=>{if(s)return o.InternalOTError.isError(s,o.INTERNAL_ERROR_CODES.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION)?await r._retry(e,t):t(s);await r.commitOp(e,t)}))}_addOpMeta(){this.op.m={ts:this.start},this.op.create&&(this.op.create.type=h.normalizeType(this.op.create.type))}_addDocumentMeta(){const e=this.document.m||(this.document.m={});this.op.create&&(e.ctime=this.start),e.mtime=this.start}_transformOp(e){const t=E(this.document.type);for(let s=0;s<e.length;s++){const r=e[s];if(this.op.src&&this.op.src===r.src&&this.op.seq===r.seq)return this.alreadySubmittedError();if(this.op.v!==r.v)return this.versionDuringTransformError();const n=h.transform(t,this.op,r);if(n)return n;delete r.m,this.ops.push(r)}}async applyOp(e){const t=this,s=t.doc._store,r=t.id,n=t.document;t.snapshot={id:r,fromVersion:n.version,v:n.version,type:n.type},t._addSnapshotMeta(),await t._trigger("apply",(async r=>{if(r)return e(r);const i=performance.now(),a=new l.SnapshotFragmentsRequest(t.snapshot.id,s,t.snapshot.fromVersion),o=await h.apply(t.snapshot,t.op,a);return o?e(o):(t.snapshot.fragmentsChanges=a.getChanges(),n.version=t.snapshot.v,n.type=t.snapshot.type,await t.doc._emitTiming("submit.op.apply",performance.now()-i,t),e())}))}_addSnapshotMeta(){if(!this.snapshot)return;const e=this.snapshot,t=e.m||(e.m={});this.op.create&&(t.ctime=this.start),t.mtime=this.start}async commitOp(e,t){const s=this,r=this.doc;await s._trigger("commit",(async n=>{if(n)return t(n);const i=performance.now();let a=!1;try{a=await r._store.commitOp(s.id,s.op,s.document,s.context.options)}catch(e){return t(e)}if(await r._emitTiming("submit.op.store.commit",performance.now()-i,s),!a)return await s._retry(e,t);s.op.m=void 0,m.info("Op committed successfully",Object.assign(Object.assign({},this.getLogContext()),{duration:Date.now()-s.start})),e(s),await s._trigger("afterWrite",(async e=>e?t(e):(await s._commitSnapshot(),await s._saveMilestoneSnapshot(),t())))}))}async _commitSnapshot(){const e=this,t=this.doc,s=performance.now();try{await t._store.commitSnapshot(e.id,e.op,e.snapshot,e.document),await t._emitTiming("submit.op.store.commitSnapshot",performance.now()-s,e)}catch(t){m.warn("Failed to commit snapshot, will rebuild on next access",Object.assign(Object.assign({},e.getLogContext()),{error:t}))}}async _saveMilestoneSnapshot(){const e=this,t=this.doc;if(e._shouldSaveMilestoneSnapshot())try{const s=performance.now(),r=await t._store.getSnapshot(e.id);r&&await t.milestoneDb.saveMilestoneSnapshot(r),await t._emitTiming("submit.op.store.saveMilestoneSnapshot",performance.now()-s,e)}catch(t){m.warn("Failed to save milestone snapshot",Object.assign(Object.assign({},e.getLogContext()),{error:t}))}}async _retry(e,t){if(this.retries++,null!=this.maxRetries&&this.retries>this.maxRetries)return t(this.maxRetriesError());m.warn("Op submit retry",this.getLogContext()),await this.doc._emitTiming("submit.op.retry",Date.now()-this.start,this),await this.submit(e,t)}_shouldSaveMilestoneSnapshot(){const e=this.doc.milestoneDb.interval;return!(e<=0)&&this.document.version%e==0}async _trigger(e,t){const s=Object.assign(Object.assign({},this.context),{request:this});await this.doc.trigger(e,s,t),this.context.options=s.options}getLogContext(){return{docId:this.id,document:this.document,op:this.op,retries:this.retries,maxRetries:this.maxRetries}}alreadyCreatedError(){return new o.OTError(d.ERR_DOC_ALREADY_CREATED,"Invalid op submitted. Document already created")}docDoesNotExistError(){return new o.OTError(d.ERR_DOC_DOES_NOT_EXIST,"Document does not exist")}rejectedError(){return new o.OTError(d.ERR_OP_SUBMIT_REJECTED,"Op submit rejected")}alreadySubmittedError(){return new o.OTError(d.ERR_OP_ALREADY_SUBMITTED,"Op already submitted")}maxRetriesError(){return new o.OTError(d.ERR_MAX_SUBMIT_RETRIES_EXCEEDED,"Op submit failed. Exceeded max submit retries of "+this.maxRetries)}versionDuringTransformError(){return new o.OTError(d.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Op submit failed. Versions mismatched during op transform")}newerVersionError(){return new o.OTError(d.ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT,"Invalid op submitted. Op version newer than current snapshot")}missingOpsError(){return new o.OTError(d.ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND,"Op submit failed. DB missing ops needed to transform it up to the current snapshot version")}versionAfterTransformError(){return new o.OTError(d.ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM,"Op submit failed. Op version mismatches snapshot after op transform")}}},513:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TypesManager=void 0;class s{static register(e){e.uri&&(s.map[e.uri]=e),e.name&&(s.map[e.name]=e)}static getType(e){return s.map[e]}}t.TypesManager=s,s.map={}},961:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isNullOrUndefined=function(e){return null==e},t.createOpMessage=function(e){const t={a:r.MessageActions.op,v:e.v,src:e.src,seq:e.seq};"op"in e&&(t.op=e.op);e.create&&(t.create=e.create);e.del&&(t.del=!0);e.restore&&(t.restore=e.restore);return t};const r=s(660)},127:t=>{t.exports=e},872:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.OTError=t.ERROR_CODES=void 0,function(e){e[e.ERR_DOC_ALREADY_CREATED=0]="ERR_DOC_ALREADY_CREATED",e[e.ERR_DOC_DOES_NOT_EXIST=1]="ERR_DOC_DOES_NOT_EXIST",e[e.ERR_DOC_TYPE_NOT_RECOGNIZED=2]="ERR_DOC_TYPE_NOT_RECOGNIZED",e[e.ERR_DOC_WAS_DELETED=3]="ERR_DOC_WAS_DELETED",e[e.ERR_MAX_SUBMIT_RETRIES_EXCEEDED=4]="ERR_MAX_SUBMIT_RETRIES_EXCEEDED",e[e.ERR_MAX_SUBMIT_SNAPSHOT_RETRIES_EXCEEDED=5]="ERR_MAX_SUBMIT_SNAPSHOT_RETRIES_EXCEEDED",e[e.ERR_MESSAGE_BADLY_FORMED=6]="ERR_MESSAGE_BADLY_FORMED",e[e.ERR_OP_ALREADY_SUBMITTED=7]="ERR_OP_ALREADY_SUBMITTED",e[e.ERR_HARD_ROLLBACK_FETCH_FAILED=8]="ERR_HARD_ROLLBACK_FETCH_FAILED",e[e.ERR_OT_OP_NOT_APPLIED=9]="ERR_OT_OP_NOT_APPLIED",e[e.ERR_OT_OP_TRANSFORM_FAILED=10]="ERR_OT_OP_TRANSFORM_FAILED",e[e.ERR_SNAPSHOT_READS_REJECTED=11]="ERR_SNAPSHOT_READS_REJECTED",e[e.ERR_SNAPSHOT_READ_SILENT_REJECTION=12]="ERR_SNAPSHOT_READ_SILENT_REJECTION",e[e.ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND=13]="ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",e[e.ERR_CONNECTION_SEQ_INTEGER_OVERFLOW=14]="ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",e[e.ERR_OT_OP_BADLY_FORMED=15]="ERR_OT_OP_BADLY_FORMED",e[e.ERR_HISTORY_SNAPSHOT_NOT_FOUND=16]="ERR_HISTORY_SNAPSHOT_NOT_FOUND",e[e.ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT=17]="ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",e[e.ERR_DOC_MISSING_VERSION=18]="ERR_DOC_MISSING_VERSION",e[e.ERR_OP_SUBMIT_REJECTED=19]="ERR_OP_SUBMIT_REJECTED",e[e.ERR_PENDING_OP_REMOVED_BY_OP_SUBMIT_REJECTED=20]="ERR_PENDING_OP_REMOVED_BY_OP_SUBMIT_REJECTED",e[e.ERR_MILESTONE_ARGUMENT_INVALID=21]="ERR_MILESTONE_ARGUMENT_INVALID",e[e.ERR_OT_OP_NOT_PROVIDED=22]="ERR_OT_OP_NOT_PROVIDED",e[e.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT=23]="ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",e[e.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM=24]="ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",e[e.ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION=25]="ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",e[e.ERR_APPLY_SNAPSHOT_NOT_PROVIDED=26]="ERR_APPLY_SNAPSHOT_NOT_PROVIDED",e[e.ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM=27]="ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",e[e.ERR_APPLY_OPS_NOT_FOUND=28]="ERR_APPLY_OPS_NOT_FOUND",e[e.ERR_RESTORE_TARGET_VERSION_INVALID=29]="ERR_RESTORE_TARGET_VERSION_INVALID",e[e.ERR_RESTORE_TARGET_DATA_INVALID=30]="ERR_RESTORE_TARGET_DATA_INVALID",e[e.ERR_RESTORE_ON_DELETED_DOC=31]="ERR_RESTORE_ON_DELETED_DOC",e[e.ERR_DOC_WAS_RESTORE=32]="ERR_DOC_WAS_RESTORE",e[e.ERR_UNKNOWN_ERROR=1e3]="ERR_UNKNOWN_ERROR"}(s||(t.ERROR_CODES=s={}));class r extends Error{constructor(e,t){super(t),this.code=e,this.name="OTError",this.code=e}}t.OTError=r,r.CODES=s},660:function(e,t,s){var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var n=Object.getOwnPropertyDescriptor(t,s);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,n)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),n=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),t.OT_DOC_MESSAGE_TYPE=void 0,n(s(872),t),n(s(969),t),n(s(549),t),n(s(802),t),t.OT_DOC_MESSAGE_TYPE="ot-doc"},549:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.MessageActions=void 0,function(e){e[e.fetch=0]="fetch",e[e.fetchOps=1]="fetchOps",e[e.fetchHistorySnapshot=2]="fetchHistorySnapshot",e[e.subscribe=3]="subscribe",e[e.unsubscribe=4]="unsubscribe",e[e.op=5]="op"}(s||(t.MessageActions=s={}))},969:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.InternalOTError=t.INTERNAL_ERROR_CODES=void 0,function(e){e[e.ERR_REQUEST_FRAGMENT_OUT_OF_VERSION=0]="ERR_REQUEST_FRAGMENT_OUT_OF_VERSION"}(s||(t.INTERNAL_ERROR_CODES=s={}));class r extends Error{constructor(e,t){super(null!=t?t:`InternalOTError: ${e}`),this.code=e,this.code=e}static isError(e,t){return e instanceof r&&e.code===t}}t.InternalOTError=r,r.CODES=s},802:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.util=t.nextTick=t.MAX_SAFE_INTEGER=void 0,t.callEach=n,t.clone=i,t.wrapError=a,t.createOTError=o;const r=s(872);function n(e,t,s){let r=!1;return e.forEach((function(e){e&&(e(t,s),r=!0)})),r}t.MAX_SAFE_INTEGER=9007199254740991;function i(e){return e?JSON.parse(JSON.stringify(e)):e}function a(e,t){return e instanceof r.OTError?e:o(null!=t?t:r.OTError.CODES.ERR_UNKNOWN_ERROR,e)}function o(e,t){let s="";return s=t instanceof Error?t.message:"string"==typeof t?t:t+"",new r.OTError(e,s)}t.nextTick=function(e){if("undefined"!=typeof process&&process.nextTick)return process.nextTick(e);setTimeout((function(){e()}))},t.util={MAX_SAFE_INTEGER:t.MAX_SAFE_INTEGER,callEach:n,nextTick:t.nextTick,clone:i,wrapError:a,createOTError:o}}},s={};function r(e){var n=s[e];if(void 0!==n)return n.exports;var i=s[e]={exports:{}};return t[e].call(i.exports,i,i.exports,r),i.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.MemoryDb=e.Db=e.DocumentServices=e.TypesManager=e.documentFeature=void 0,r(259),r(36);const t=r(89);Object.defineProperty(e,"DocumentServices",{enumerable:!0,get:function(){return t.DocumentServices}});const s=r(619);Object.defineProperty(e,"Db",{enumerable:!0,get:function(){return s.Db}});const i=r(985);Object.defineProperty(e,"MemoryDb",{enumerable:!0,get:function(){return i.MemoryDb}});const a=r(763);Object.defineProperty(e,"documentFeature",{enumerable:!0,get:function(){return a.documentFeature}});const o=r(513);Object.defineProperty(e,"TypesManager",{enumerable:!0,get:function(){return o.TypesManager}})})(),n})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grapecity-software/js-collaboration-ot",
3
- "version": "18.2.4",
3
+ "version": "19.0.0",
4
4
  "type": "commonjs",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -25,7 +25,7 @@
25
25
  "license": "Commercial",
26
26
  "description": "SpreadJS Collaboration plugin",
27
27
  "dependencies": {
28
- "@grapecity-software/js-collaboration": "18.2.4"
28
+ "@grapecity-software/js-collaboration": "19.0.0"
29
29
  },
30
30
  "homepage": "http://www.grapecity.com.cn/"
31
31
  }