@liveblocks/core 3.23.1-exp2 → 3.23.1
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.cjs +367 -1840
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +273 -612
- package/dist/index.d.ts +273 -612
- package/dist/index.js +295 -1768
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -217,6 +217,118 @@ type BaseUserMeta = {
|
|
|
217
217
|
info?: IUserInfo;
|
|
218
218
|
};
|
|
219
219
|
|
|
220
|
+
type CrdtType = (typeof CrdtType)[keyof typeof CrdtType];
|
|
221
|
+
declare const CrdtType: Readonly<{
|
|
222
|
+
OBJECT: 0;
|
|
223
|
+
LIST: 1;
|
|
224
|
+
MAP: 2;
|
|
225
|
+
REGISTER: 3;
|
|
226
|
+
FILE: 5;
|
|
227
|
+
}>;
|
|
228
|
+
declare namespace CrdtType {
|
|
229
|
+
type OBJECT = typeof CrdtType.OBJECT;
|
|
230
|
+
type LIST = typeof CrdtType.LIST;
|
|
231
|
+
type MAP = typeof CrdtType.MAP;
|
|
232
|
+
type REGISTER = typeof CrdtType.REGISTER;
|
|
233
|
+
type FILE = typeof CrdtType.FILE;
|
|
234
|
+
}
|
|
235
|
+
type SerializedCrdt = SerializedRootObject | SerializedChild;
|
|
236
|
+
type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister | SerializedFile;
|
|
237
|
+
type LiveFileData = {
|
|
238
|
+
readonly id: string;
|
|
239
|
+
readonly name: string;
|
|
240
|
+
readonly size: number;
|
|
241
|
+
readonly mimeType: string;
|
|
242
|
+
};
|
|
243
|
+
type SerializedRootObject = {
|
|
244
|
+
readonly type: CrdtType.OBJECT;
|
|
245
|
+
readonly data: JsonObject;
|
|
246
|
+
readonly parentId?: never;
|
|
247
|
+
readonly parentKey?: never;
|
|
248
|
+
};
|
|
249
|
+
type SerializedObject = {
|
|
250
|
+
readonly type: CrdtType.OBJECT;
|
|
251
|
+
readonly parentId: string;
|
|
252
|
+
readonly parentKey: string;
|
|
253
|
+
readonly data: JsonObject;
|
|
254
|
+
};
|
|
255
|
+
type SerializedList = {
|
|
256
|
+
readonly type: CrdtType.LIST;
|
|
257
|
+
readonly parentId: string;
|
|
258
|
+
readonly parentKey: string;
|
|
259
|
+
};
|
|
260
|
+
type SerializedMap = {
|
|
261
|
+
readonly type: CrdtType.MAP;
|
|
262
|
+
readonly parentId: string;
|
|
263
|
+
readonly parentKey: string;
|
|
264
|
+
};
|
|
265
|
+
type SerializedRegister = {
|
|
266
|
+
readonly type: CrdtType.REGISTER;
|
|
267
|
+
readonly parentId: string;
|
|
268
|
+
readonly parentKey: string;
|
|
269
|
+
readonly data: Json;
|
|
270
|
+
};
|
|
271
|
+
type SerializedFile = {
|
|
272
|
+
readonly type: CrdtType.FILE;
|
|
273
|
+
readonly parentId: string;
|
|
274
|
+
readonly parentKey: string;
|
|
275
|
+
readonly data: LiveFileData;
|
|
276
|
+
};
|
|
277
|
+
type StorageNode = RootStorageNode | ChildStorageNode;
|
|
278
|
+
type ChildStorageNode = ObjectStorageNode | ListStorageNode | MapStorageNode | RegisterStorageNode | FileStorageNode;
|
|
279
|
+
type RootStorageNode = [id: "root", value: SerializedRootObject];
|
|
280
|
+
type ObjectStorageNode = [id: string, value: SerializedObject];
|
|
281
|
+
type ListStorageNode = [id: string, value: SerializedList];
|
|
282
|
+
type MapStorageNode = [id: string, value: SerializedMap];
|
|
283
|
+
type RegisterStorageNode = [id: string, value: SerializedRegister];
|
|
284
|
+
type FileStorageNode = [id: string, value: SerializedFile];
|
|
285
|
+
type NodeMap = Map<string, SerializedCrdt>;
|
|
286
|
+
type NodeStream = Iterable<StorageNode>;
|
|
287
|
+
declare function isRootStorageNode(node: StorageNode): node is RootStorageNode;
|
|
288
|
+
declare function isObjectStorageNode(node: StorageNode): node is RootStorageNode | ObjectStorageNode;
|
|
289
|
+
declare function isListStorageNode(node: StorageNode): node is ListStorageNode;
|
|
290
|
+
declare function isMapStorageNode(node: StorageNode): node is MapStorageNode;
|
|
291
|
+
declare function isRegisterStorageNode(node: StorageNode): node is RegisterStorageNode;
|
|
292
|
+
declare function isFileStorageNode(node: StorageNode): node is FileStorageNode;
|
|
293
|
+
type CompactNode = CompactRootNode | CompactChildNode;
|
|
294
|
+
type CompactChildNode = CompactObjectNode | CompactListNode | CompactMapNode | CompactRegisterNode | CompactFileNode;
|
|
295
|
+
type CompactRootNode = readonly [id: "root", data: JsonObject];
|
|
296
|
+
type CompactObjectNode = readonly [
|
|
297
|
+
id: string,
|
|
298
|
+
type: CrdtType.OBJECT,
|
|
299
|
+
parentId: string,
|
|
300
|
+
parentKey: string,
|
|
301
|
+
data: JsonObject
|
|
302
|
+
];
|
|
303
|
+
type CompactListNode = readonly [
|
|
304
|
+
id: string,
|
|
305
|
+
type: CrdtType.LIST,
|
|
306
|
+
parentId: string,
|
|
307
|
+
parentKey: string
|
|
308
|
+
];
|
|
309
|
+
type CompactMapNode = readonly [
|
|
310
|
+
id: string,
|
|
311
|
+
type: CrdtType.MAP,
|
|
312
|
+
parentId: string,
|
|
313
|
+
parentKey: string
|
|
314
|
+
];
|
|
315
|
+
type CompactRegisterNode = readonly [
|
|
316
|
+
id: string,
|
|
317
|
+
type: CrdtType.REGISTER,
|
|
318
|
+
parentId: string,
|
|
319
|
+
parentKey: string,
|
|
320
|
+
data: Json
|
|
321
|
+
];
|
|
322
|
+
type CompactFileNode = readonly [
|
|
323
|
+
id: string,
|
|
324
|
+
type: CrdtType.FILE,
|
|
325
|
+
parentId: string,
|
|
326
|
+
parentKey: string,
|
|
327
|
+
data: LiveFileData
|
|
328
|
+
];
|
|
329
|
+
declare function compactNodesToNodeStream(compactNodes: CompactNode[]): NodeStream;
|
|
330
|
+
declare function nodeStreamToCompactNodes(nodes: NodeStream): Iterable<CompactNode>;
|
|
331
|
+
|
|
220
332
|
declare const brand: unique symbol;
|
|
221
333
|
type Brand<T, TBrand extends string> = T & {
|
|
222
334
|
[brand]: TBrand;
|
|
@@ -302,8 +414,6 @@ declare const OpCode: Readonly<{
|
|
|
302
414
|
DELETE_OBJECT_KEY: 6;
|
|
303
415
|
CREATE_MAP: 7;
|
|
304
416
|
CREATE_REGISTER: 8;
|
|
305
|
-
CREATE_TEXT: 9;
|
|
306
|
-
UPDATE_TEXT: 10;
|
|
307
417
|
CREATE_FILE: 11;
|
|
308
418
|
}>;
|
|
309
419
|
declare namespace OpCode {
|
|
@@ -316,49 +426,14 @@ declare namespace OpCode {
|
|
|
316
426
|
type DELETE_OBJECT_KEY = typeof OpCode.DELETE_OBJECT_KEY;
|
|
317
427
|
type CREATE_MAP = typeof OpCode.CREATE_MAP;
|
|
318
428
|
type CREATE_REGISTER = typeof OpCode.CREATE_REGISTER;
|
|
319
|
-
type CREATE_TEXT = typeof OpCode.CREATE_TEXT;
|
|
320
|
-
type UPDATE_TEXT = typeof OpCode.UPDATE_TEXT;
|
|
321
429
|
type CREATE_FILE = typeof OpCode.CREATE_FILE;
|
|
322
430
|
}
|
|
323
|
-
type TextAttributes = JsonObject;
|
|
324
|
-
/**
|
|
325
|
-
* A single segment in a {@link LiveTextData} document.
|
|
326
|
-
*
|
|
327
|
-
* @example
|
|
328
|
-
* ["Hello world"]
|
|
329
|
-
* ["Hello ", { bold: true }]
|
|
330
|
-
*/
|
|
331
|
-
type LiveTextSegment = [text: string] | [text: string, attributes: TextAttributes];
|
|
332
|
-
/**
|
|
333
|
-
* Serialized form of a {@link LiveText} document: an ordered list of text
|
|
334
|
-
* segments with optional inline attributes.
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* [["Hello world"]]
|
|
338
|
-
* [["Hello ", { bold: true }], ["world"]]
|
|
339
|
-
*/
|
|
340
|
-
type LiveTextData = LiveTextSegment[];
|
|
341
|
-
type TextOperation = {
|
|
342
|
-
type: "insert";
|
|
343
|
-
index: number;
|
|
344
|
-
text: string;
|
|
345
|
-
attributes?: TextAttributes;
|
|
346
|
-
} | {
|
|
347
|
-
type: "delete";
|
|
348
|
-
index: number;
|
|
349
|
-
length: number;
|
|
350
|
-
} | {
|
|
351
|
-
type: "format";
|
|
352
|
-
index: number;
|
|
353
|
-
length: number;
|
|
354
|
-
attributes: JsonObject;
|
|
355
|
-
};
|
|
356
431
|
/**
|
|
357
432
|
* These operations are the payload for {@link UpdateStorageServerMsg} messages
|
|
358
433
|
* only.
|
|
359
434
|
*/
|
|
360
|
-
type Op = CreateOp | UpdateObjectOp |
|
|
361
|
-
type CreateOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp |
|
|
435
|
+
type Op = CreateOp | UpdateObjectOp | DeleteCrdtOp | SetParentKeyOp | DeleteObjectKeyOp;
|
|
436
|
+
type CreateOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp | CreateFileOp;
|
|
362
437
|
type UpdateObjectOp = {
|
|
363
438
|
readonly opId?: string;
|
|
364
439
|
readonly id: string;
|
|
@@ -403,17 +478,6 @@ type CreateRegisterOp = {
|
|
|
403
478
|
readonly intent?: "set" | "push";
|
|
404
479
|
readonly deletedId?: string;
|
|
405
480
|
};
|
|
406
|
-
type CreateTextOp = {
|
|
407
|
-
readonly opId?: string;
|
|
408
|
-
readonly id: string;
|
|
409
|
-
readonly type: OpCode.CREATE_TEXT;
|
|
410
|
-
readonly parentId: string;
|
|
411
|
-
readonly parentKey: string;
|
|
412
|
-
readonly data: LiveTextData;
|
|
413
|
-
readonly version: number;
|
|
414
|
-
readonly intent?: "set" | "push";
|
|
415
|
-
readonly deletedId?: string;
|
|
416
|
-
};
|
|
417
481
|
type CreateFileOp = {
|
|
418
482
|
readonly opId?: string;
|
|
419
483
|
readonly id: string;
|
|
@@ -424,14 +488,6 @@ type CreateFileOp = {
|
|
|
424
488
|
readonly intent?: "set" | "push";
|
|
425
489
|
readonly deletedId?: string;
|
|
426
490
|
};
|
|
427
|
-
type UpdateTextOp = {
|
|
428
|
-
readonly opId?: string;
|
|
429
|
-
readonly id: string;
|
|
430
|
-
readonly type: OpCode.UPDATE_TEXT;
|
|
431
|
-
readonly baseVersion: number;
|
|
432
|
-
readonly version?: number;
|
|
433
|
-
readonly ops: TextOperation[];
|
|
434
|
-
};
|
|
435
491
|
type DeleteCrdtOp = {
|
|
436
492
|
readonly opId?: string;
|
|
437
493
|
readonly id: string;
|
|
@@ -474,155 +530,132 @@ type TheirOp = DistributiveOmit<Op, "opId"> & {
|
|
|
474
530
|
opId?: undefined;
|
|
475
531
|
};
|
|
476
532
|
|
|
477
|
-
type
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
type
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
type SerializedCrdt = SerializedRootObject | SerializedChild;
|
|
495
|
-
type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister | SerializedText | SerializedFile;
|
|
496
|
-
type LiveFileData = {
|
|
497
|
-
readonly id: string;
|
|
498
|
-
readonly name: string;
|
|
499
|
-
readonly size: number;
|
|
500
|
-
readonly mimeType: string;
|
|
501
|
-
};
|
|
502
|
-
type SerializedRootObject = {
|
|
503
|
-
readonly type: CrdtType.OBJECT;
|
|
504
|
-
readonly data: JsonObject;
|
|
505
|
-
readonly parentId?: never;
|
|
506
|
-
readonly parentKey?: never;
|
|
507
|
-
};
|
|
508
|
-
type SerializedObject = {
|
|
509
|
-
readonly type: CrdtType.OBJECT;
|
|
510
|
-
readonly parentId: string;
|
|
511
|
-
readonly parentKey: string;
|
|
512
|
-
readonly data: JsonObject;
|
|
513
|
-
};
|
|
514
|
-
type SerializedList = {
|
|
515
|
-
readonly type: CrdtType.LIST;
|
|
516
|
-
readonly parentId: string;
|
|
517
|
-
readonly parentKey: string;
|
|
518
|
-
};
|
|
519
|
-
type SerializedMap = {
|
|
520
|
-
readonly type: CrdtType.MAP;
|
|
521
|
-
readonly parentId: string;
|
|
522
|
-
readonly parentKey: string;
|
|
523
|
-
};
|
|
524
|
-
type SerializedRegister = {
|
|
525
|
-
readonly type: CrdtType.REGISTER;
|
|
526
|
-
readonly parentId: string;
|
|
527
|
-
readonly parentKey: string;
|
|
528
|
-
readonly data: Json;
|
|
529
|
-
};
|
|
530
|
-
type SerializedText = {
|
|
531
|
-
readonly type: CrdtType.TEXT;
|
|
532
|
-
readonly parentId: string;
|
|
533
|
-
readonly parentKey: string;
|
|
534
|
-
readonly data: LiveTextData;
|
|
535
|
-
readonly version: number;
|
|
533
|
+
type LiveListUpdateDelta = {
|
|
534
|
+
type: "insert";
|
|
535
|
+
index: number;
|
|
536
|
+
item: Lson;
|
|
537
|
+
} | {
|
|
538
|
+
type: "delete";
|
|
539
|
+
index: number;
|
|
540
|
+
deletedItem: Lson;
|
|
541
|
+
} | {
|
|
542
|
+
type: "move";
|
|
543
|
+
index: number;
|
|
544
|
+
previousIndex: number;
|
|
545
|
+
item: Lson;
|
|
546
|
+
} | {
|
|
547
|
+
type: "set";
|
|
548
|
+
index: number;
|
|
549
|
+
item: Lson;
|
|
536
550
|
};
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
551
|
+
/**
|
|
552
|
+
* A LiveList notification that is sent in-client to any subscribers whenever
|
|
553
|
+
* one or more of the items inside the LiveList instance have changed.
|
|
554
|
+
*/
|
|
555
|
+
type LiveListUpdates<TItem extends Lson> = {
|
|
556
|
+
type: "LiveList";
|
|
557
|
+
node: LiveList<TItem>;
|
|
558
|
+
updates: LiveListUpdateDelta[];
|
|
542
559
|
};
|
|
543
|
-
type StorageNode = RootStorageNode | ChildStorageNode;
|
|
544
|
-
type ChildStorageNode = ObjectStorageNode | ListStorageNode | MapStorageNode | RegisterStorageNode | TextStorageNode | FileStorageNode;
|
|
545
|
-
type RootStorageNode = [id: "root", value: SerializedRootObject];
|
|
546
|
-
type ObjectStorageNode = [id: string, value: SerializedObject];
|
|
547
|
-
type ListStorageNode = [id: string, value: SerializedList];
|
|
548
|
-
type MapStorageNode = [id: string, value: SerializedMap];
|
|
549
|
-
type RegisterStorageNode = [id: string, value: SerializedRegister];
|
|
550
|
-
type TextStorageNode = [id: string, value: SerializedText];
|
|
551
|
-
type FileStorageNode = [id: string, value: SerializedFile];
|
|
552
|
-
type NodeMap = Map<string, SerializedCrdt>;
|
|
553
|
-
type NodeStream = Iterable<StorageNode>;
|
|
554
|
-
declare function isRootStorageNode(node: StorageNode): node is RootStorageNode;
|
|
555
|
-
declare function isObjectStorageNode(node: StorageNode): node is RootStorageNode | ObjectStorageNode;
|
|
556
|
-
declare function isListStorageNode(node: StorageNode): node is ListStorageNode;
|
|
557
|
-
declare function isMapStorageNode(node: StorageNode): node is MapStorageNode;
|
|
558
|
-
declare function isRegisterStorageNode(node: StorageNode): node is RegisterStorageNode;
|
|
559
|
-
declare function isTextStorageNode(node: StorageNode): node is TextStorageNode;
|
|
560
|
-
declare function isFileStorageNode(node: StorageNode): node is FileStorageNode;
|
|
561
|
-
type CompactNode = CompactRootNode | CompactChildNode;
|
|
562
|
-
type CompactChildNode = CompactObjectNode | CompactListNode | CompactMapNode | CompactRegisterNode | CompactTextNode | CompactFileNode;
|
|
563
|
-
type CompactRootNode = readonly [id: "root", data: JsonObject];
|
|
564
|
-
type CompactObjectNode = readonly [
|
|
565
|
-
id: string,
|
|
566
|
-
type: CrdtType.OBJECT,
|
|
567
|
-
parentId: string,
|
|
568
|
-
parentKey: string,
|
|
569
|
-
data: JsonObject
|
|
570
|
-
];
|
|
571
|
-
type CompactListNode = readonly [
|
|
572
|
-
id: string,
|
|
573
|
-
type: CrdtType.LIST,
|
|
574
|
-
parentId: string,
|
|
575
|
-
parentKey: string
|
|
576
|
-
];
|
|
577
|
-
type CompactMapNode = readonly [
|
|
578
|
-
id: string,
|
|
579
|
-
type: CrdtType.MAP,
|
|
580
|
-
parentId: string,
|
|
581
|
-
parentKey: string
|
|
582
|
-
];
|
|
583
|
-
type CompactRegisterNode = readonly [
|
|
584
|
-
id: string,
|
|
585
|
-
type: CrdtType.REGISTER,
|
|
586
|
-
parentId: string,
|
|
587
|
-
parentKey: string,
|
|
588
|
-
data: Json
|
|
589
|
-
];
|
|
590
|
-
type CompactTextNode = readonly [
|
|
591
|
-
id: string,
|
|
592
|
-
type: CrdtType.TEXT,
|
|
593
|
-
parentId: string,
|
|
594
|
-
parentKey: string,
|
|
595
|
-
data: LiveTextData,
|
|
596
|
-
version: number
|
|
597
|
-
];
|
|
598
|
-
type CompactFileNode = readonly [
|
|
599
|
-
id: string,
|
|
600
|
-
type: CrdtType.FILE,
|
|
601
|
-
parentId: string,
|
|
602
|
-
parentKey: string,
|
|
603
|
-
data: LiveFileData
|
|
604
|
-
];
|
|
605
|
-
declare function compactNodesToNodeStream(compactNodes: CompactNode[]): NodeStream;
|
|
606
|
-
declare function nodeStreamToCompactNodes(nodes: NodeStream): Iterable<CompactNode>;
|
|
607
|
-
|
|
608
560
|
/**
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
* @example
|
|
612
|
-
* Object.defineProperty(
|
|
613
|
-
* {
|
|
614
|
-
* public,
|
|
615
|
-
* [kInternal]: {
|
|
616
|
-
* private
|
|
617
|
-
* },
|
|
618
|
-
* },
|
|
619
|
-
* kInternal,
|
|
620
|
-
* {
|
|
621
|
-
* enumerable: false,
|
|
622
|
-
* }
|
|
623
|
-
* );
|
|
561
|
+
* The LiveList class represents an ordered collection of items that is synchronized across clients.
|
|
624
562
|
*/
|
|
625
|
-
declare
|
|
563
|
+
declare class LiveList<TItem extends Lson> extends AbstractCrdt {
|
|
564
|
+
#private;
|
|
565
|
+
constructor(items: TItem[]);
|
|
566
|
+
/**
|
|
567
|
+
* Returns the number of elements.
|
|
568
|
+
*/
|
|
569
|
+
get length(): number;
|
|
570
|
+
/**
|
|
571
|
+
* Adds one element to the end of the LiveList.
|
|
572
|
+
* @param element The element to add to the end of the LiveList.
|
|
573
|
+
*/
|
|
574
|
+
push(element: TItem): void;
|
|
575
|
+
/**
|
|
576
|
+
* Inserts one element at a specified index.
|
|
577
|
+
* @param element The element to insert.
|
|
578
|
+
* @param index The index at which you want to insert the element.
|
|
579
|
+
*/
|
|
580
|
+
insert(element: TItem, index: number): void;
|
|
581
|
+
/**
|
|
582
|
+
* Move one element from one index to another.
|
|
583
|
+
* @param index The index of the element to move
|
|
584
|
+
* @param targetIndex The index where the element should be after moving.
|
|
585
|
+
*/
|
|
586
|
+
move(index: number, targetIndex: number): void;
|
|
587
|
+
/**
|
|
588
|
+
* Deletes an element at the specified index
|
|
589
|
+
* @param index The index of the element to delete
|
|
590
|
+
*/
|
|
591
|
+
delete(index: number): void;
|
|
592
|
+
clear(): void;
|
|
593
|
+
set(index: number, item: TItem): void;
|
|
594
|
+
/**
|
|
595
|
+
* Tests whether all elements pass the test implemented by the provided function.
|
|
596
|
+
* @param predicate Function to test for each element, taking two arguments (the element and its index).
|
|
597
|
+
* @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
|
|
598
|
+
*/
|
|
599
|
+
every(predicate: (value: TItem, index: number) => unknown): boolean;
|
|
600
|
+
/**
|
|
601
|
+
* Creates an array with all elements that pass the test implemented by the provided function.
|
|
602
|
+
* @param predicate Function to test each element of the LiveList. Return a value that coerces to true to keep the element, or to false otherwise.
|
|
603
|
+
* @returns An array with the elements that pass the test.
|
|
604
|
+
*/
|
|
605
|
+
filter(predicate: (value: TItem, index: number) => unknown): TItem[];
|
|
606
|
+
/**
|
|
607
|
+
* Returns the first element that satisfies the provided testing function.
|
|
608
|
+
* @param predicate Function to execute on each value.
|
|
609
|
+
* @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
610
|
+
*/
|
|
611
|
+
find(predicate: (value: TItem, index: number) => unknown): TItem | undefined;
|
|
612
|
+
/**
|
|
613
|
+
* Returns the index of the first element in the LiveList that satisfies the provided testing function.
|
|
614
|
+
* @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
|
|
615
|
+
* @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
|
|
616
|
+
*/
|
|
617
|
+
findIndex(predicate: (value: TItem, index: number) => unknown): number;
|
|
618
|
+
/**
|
|
619
|
+
* Executes a provided function once for each element.
|
|
620
|
+
* @param callbackfn Function to execute on each element.
|
|
621
|
+
*/
|
|
622
|
+
forEach(callbackfn: (value: TItem, index: number) => void): void;
|
|
623
|
+
/**
|
|
624
|
+
* Get the element at the specified index.
|
|
625
|
+
* @param index The index on the element to get.
|
|
626
|
+
* @returns The element at the specified index or undefined.
|
|
627
|
+
*/
|
|
628
|
+
get(index: number): TItem | undefined;
|
|
629
|
+
/**
|
|
630
|
+
* Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
|
|
631
|
+
* @param searchElement Element to locate.
|
|
632
|
+
* @param fromIndex The index to start the search at.
|
|
633
|
+
* @returns The first index of the element in the LiveList; -1 if not found.
|
|
634
|
+
*/
|
|
635
|
+
indexOf(searchElement: TItem, fromIndex?: number): number;
|
|
636
|
+
/**
|
|
637
|
+
* Returns the last index at which a given element can be found in the LiveList, or -1 if it is not present. The LiveList is searched backwards, starting at fromIndex.
|
|
638
|
+
* @param searchElement Element to locate.
|
|
639
|
+
* @param fromIndex The index at which to start searching backwards.
|
|
640
|
+
* @returns The last index of the element in the LiveList; -1 if not found.
|
|
641
|
+
*/
|
|
642
|
+
lastIndexOf(searchElement: TItem, fromIndex?: number): number;
|
|
643
|
+
/**
|
|
644
|
+
* Creates an array populated with the results of calling a provided function on every element.
|
|
645
|
+
* @param callback Function that is called for every element.
|
|
646
|
+
* @returns An array with each element being the result of the callback function.
|
|
647
|
+
*/
|
|
648
|
+
map<U>(callback: (value: TItem, index: number) => U): U[];
|
|
649
|
+
/**
|
|
650
|
+
* Tests whether at least one element in the LiveList passes the test implemented by the provided function.
|
|
651
|
+
* @param predicate Function to test for each element.
|
|
652
|
+
* @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
|
|
653
|
+
*/
|
|
654
|
+
some(predicate: (value: TItem, index: number) => unknown): boolean;
|
|
655
|
+
[Symbol.iterator](): IterableIterator<TItem>;
|
|
656
|
+
toJSON(): readonly ToJson<TItem>[];
|
|
657
|
+
clone(): LiveList<TItem>;
|
|
658
|
+
}
|
|
626
659
|
|
|
627
660
|
type UpdateDelta = {
|
|
628
661
|
type: "update";
|
|
@@ -641,7 +674,6 @@ type LiveMapUpdates<TKey extends string, TValue extends Lson> = {
|
|
|
641
674
|
updates: {
|
|
642
675
|
[key: string]: UpdateDelta;
|
|
643
676
|
};
|
|
644
|
-
source: UpdateSource;
|
|
645
677
|
};
|
|
646
678
|
/**
|
|
647
679
|
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
|
|
@@ -781,7 +813,6 @@ type LiveObjectUpdates<TData extends LsonObject> = {
|
|
|
781
813
|
type: "LiveObject";
|
|
782
814
|
node: LiveObject<TData>;
|
|
783
815
|
updates: LiveObjectUpdateDelta<TData>;
|
|
784
|
-
source: UpdateSource;
|
|
785
816
|
};
|
|
786
817
|
/**
|
|
787
818
|
* The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
|
|
@@ -868,356 +899,6 @@ declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
|
|
|
868
899
|
clone(): LiveObject<O>;
|
|
869
900
|
}
|
|
870
901
|
|
|
871
|
-
/**
|
|
872
|
-
* The position of the ops being transformed relative to the ops they are
|
|
873
|
-
* transformed over, in the final (server-serialized) timeline:
|
|
874
|
-
*
|
|
875
|
-
* - "after": the transformed ops will be ordered after the `over` ops. Used
|
|
876
|
-
* when rebasing a not-yet-accepted op over already-accepted ops. On
|
|
877
|
-
* same-index insert ties, the transformed op shifts right (the earlier op
|
|
878
|
-
* stays left), and conflicting format attributes are kept (they will
|
|
879
|
-
* overwrite, since the op applies later).
|
|
880
|
-
* - "before": the transformed ops were ordered before the `over` ops. Used
|
|
881
|
-
* when applying an accepted remote op on top of locally-pending ops. On
|
|
882
|
-
* same-index insert ties, the transformed op stays left, and conflicting
|
|
883
|
-
* format attributes are dropped on overlapping ranges (the later `over` op
|
|
884
|
-
* wins).
|
|
885
|
-
*/
|
|
886
|
-
type TransformOrder = "before" | "after";
|
|
887
|
-
/**
|
|
888
|
-
* Transform `ops` over `over` (see {@link transformTextOperationsX}),
|
|
889
|
-
* returning only the transformed `ops`.
|
|
890
|
-
*/
|
|
891
|
-
declare function transformTextOperations(ops: readonly TextOperation[], over: readonly TextOperation[], order: TransformOrder): TextOperation[];
|
|
892
|
-
declare function applyLiveTextOperations(data: LiveTextData, ops: readonly TextOperation[]): LiveTextData;
|
|
893
|
-
|
|
894
|
-
type LiveTextAttributes = TextAttributes;
|
|
895
|
-
type LiveTextAttributesPatch = JsonObject;
|
|
896
|
-
|
|
897
|
-
type LiveTextChange = {
|
|
898
|
-
/** Text was inserted at {@link LiveTextChange.index}. */
|
|
899
|
-
readonly type: "insert";
|
|
900
|
-
readonly index: number;
|
|
901
|
-
readonly text: string;
|
|
902
|
-
readonly attributes?: TextAttributes;
|
|
903
|
-
} | {
|
|
904
|
-
/** Text was deleted starting at {@link LiveTextChange.index}. */
|
|
905
|
-
readonly type: "delete";
|
|
906
|
-
readonly index: number;
|
|
907
|
-
readonly length: number;
|
|
908
|
-
readonly deletedText: string;
|
|
909
|
-
} | {
|
|
910
|
-
/** Inline attributes were updated on a range of text. */
|
|
911
|
-
readonly type: "format";
|
|
912
|
-
readonly index: number;
|
|
913
|
-
readonly length: number;
|
|
914
|
-
readonly attributes: LiveTextAttributesPatch;
|
|
915
|
-
};
|
|
916
|
-
/** Notification payload when a {@link LiveText} node changes. */
|
|
917
|
-
type LiveTextUpdates = {
|
|
918
|
-
type: "LiveText";
|
|
919
|
-
node: LiveText;
|
|
920
|
-
version: number;
|
|
921
|
-
updates: LiveTextChange[];
|
|
922
|
-
source: UpdateSource;
|
|
923
|
-
};
|
|
924
|
-
/**
|
|
925
|
-
* @private
|
|
926
|
-
*
|
|
927
|
-
* Private methods on a LiveText node. As a user of Liveblocks, NEVER USE ANY
|
|
928
|
-
* OF THESE DIRECTLY, because bad things will probably happen if you do.
|
|
929
|
-
*/
|
|
930
|
-
type PrivateLiveTextApi = PrivateLiveNodeApi & {
|
|
931
|
-
/**
|
|
932
|
-
* Encode a local-document index into server-confirmed coordinates suitable
|
|
933
|
-
* for broadcasting to peers via presence or any other side channel. Pair
|
|
934
|
-
* the result with {@link LiveText.version} at the same instant when
|
|
935
|
-
* sending.
|
|
936
|
-
*/
|
|
937
|
-
encodeIndex(localIndex: number): number;
|
|
938
|
-
/**
|
|
939
|
-
* Decode an `(index, fromVersion)` pair from a peer into an offset in this
|
|
940
|
-
* LiveText's current local document.
|
|
941
|
-
*/
|
|
942
|
-
decodeIndex(index: number, fromVersion: number): number | null;
|
|
943
|
-
};
|
|
944
|
-
|
|
945
|
-
/**
|
|
946
|
-
* LiveText is a collaborative rich-text primitive built on server-ordered
|
|
947
|
-
* operational transformation.
|
|
948
|
-
*
|
|
949
|
-
* Use it to store plain text with optional inline formatting attributes in
|
|
950
|
-
* Liveblocks Storage. Each document is a flat sequence of text segments; it
|
|
951
|
-
* cannot contain child Storage structures.
|
|
952
|
-
*
|
|
953
|
-
* Outbound model (one-in-flight): at most one UpdateTextOp per node is
|
|
954
|
-
* awaiting server acknowledgement at any time. Local edits made while an op
|
|
955
|
-
* is in flight are queued and sent (composed into a single op) once the ack
|
|
956
|
-
* arrives. This guarantees every wire op is expressed against server-state
|
|
957
|
-
* coordinates, so the server can transform it over exactly the (foreign)
|
|
958
|
-
* ops the client hadn't seen — never over the client's own pending ops.
|
|
959
|
-
*
|
|
960
|
-
* Inbound model: accepted remote ops are transformed over the local pending
|
|
961
|
-
* ops before being applied ("before" order: the accepted op wins ties), and
|
|
962
|
-
* the pending ops are re-expressed over the remote op in turn ("after"
|
|
963
|
-
* order), keeping them in server coordinates at all times.
|
|
964
|
-
*
|
|
965
|
-
* @example
|
|
966
|
-
* const text = new LiveText("Hello");
|
|
967
|
-
* text.insert(5, " world");
|
|
968
|
-
* text.format(0, 5, { bold: true });
|
|
969
|
-
*
|
|
970
|
-
* // [["Hello", { bold: true }], [" world"]]
|
|
971
|
-
* text.toJSON();
|
|
972
|
-
*
|
|
973
|
-
* @example
|
|
974
|
-
* // Use in Storage
|
|
975
|
-
* declare global {
|
|
976
|
-
* interface Liveblocks {
|
|
977
|
-
* Storage: { document: LiveText };
|
|
978
|
-
* }
|
|
979
|
-
* }
|
|
980
|
-
*
|
|
981
|
-
* const { root } = await room.getStorage();
|
|
982
|
-
* root.get("document").replace(0, root.get("document").length, "Updated");
|
|
983
|
-
*/
|
|
984
|
-
declare class LiveText extends AbstractCrdt {
|
|
985
|
-
#private;
|
|
986
|
-
/**
|
|
987
|
-
* @private
|
|
988
|
-
*
|
|
989
|
-
* Private methods and variables used in the core internals, but as a user
|
|
990
|
-
* of Liveblocks, NEVER USE ANY OF THESE DIRECTLY, because bad things
|
|
991
|
-
* will probably happen if you do.
|
|
992
|
-
*/
|
|
993
|
-
readonly [kInternal]: PrivateLiveTextApi;
|
|
994
|
-
/**
|
|
995
|
-
* Creates a new LiveText document.
|
|
996
|
-
*
|
|
997
|
-
* @param textOrData Initial plain text, or an array of `[text]` /
|
|
998
|
-
* `[text, attributes]` segments. Defaults to an empty document.
|
|
999
|
-
*
|
|
1000
|
-
* @example
|
|
1001
|
-
* new LiveText();
|
|
1002
|
-
* new LiveText("Hello world");
|
|
1003
|
-
* new LiveText([["Hello ", { bold: true }], ["world"]]);
|
|
1004
|
-
*/
|
|
1005
|
-
constructor(textOrData?: string | LiveTextData, version?: number);
|
|
1006
|
-
get version(): number;
|
|
1007
|
-
get length(): number;
|
|
1008
|
-
/**
|
|
1009
|
-
* Inserts text at the given index.
|
|
1010
|
-
*
|
|
1011
|
-
* @param index Character index at which to insert. Values outside the
|
|
1012
|
-
* document range are clipped.
|
|
1013
|
-
* @param text Text to insert.
|
|
1014
|
-
* @param attributes Optional inline attributes for the inserted text.
|
|
1015
|
-
*
|
|
1016
|
-
* @example
|
|
1017
|
-
* const text = new LiveText("Hello");
|
|
1018
|
-
* text.insert(5, " world");
|
|
1019
|
-
* text.insert(0, "Say: ", { italic: true });
|
|
1020
|
-
*/
|
|
1021
|
-
insert(index: number, text: string, attributes?: TextAttributes): void;
|
|
1022
|
-
/**
|
|
1023
|
-
* Deletes `length` characters starting at `index`.
|
|
1024
|
-
*
|
|
1025
|
-
* @example
|
|
1026
|
-
* const text = new LiveText("Hello world");
|
|
1027
|
-
* text.delete(5, 6); // "Hello"
|
|
1028
|
-
*/
|
|
1029
|
-
delete(index: number, length: number): void;
|
|
1030
|
-
/**
|
|
1031
|
-
* Replaces a range of text with new text.
|
|
1032
|
-
*
|
|
1033
|
-
* @example
|
|
1034
|
-
* const text = new LiveText("Hello world");
|
|
1035
|
-
* text.replace(0, 5, "Hi"); // "Hi world"
|
|
1036
|
-
*/
|
|
1037
|
-
replace(index: number, length: number, text: string, attributes?: TextAttributes): void;
|
|
1038
|
-
/**
|
|
1039
|
-
* Applies or removes inline attributes on a range of text.
|
|
1040
|
-
*
|
|
1041
|
-
* Set an attribute to `null` to remove it from the range.
|
|
1042
|
-
*
|
|
1043
|
-
* @example
|
|
1044
|
-
* const text = new LiveText("Hello world");
|
|
1045
|
-
* text.format(0, 5, { bold: true });
|
|
1046
|
-
* text.format(0, 5, { bold: null });
|
|
1047
|
-
*/
|
|
1048
|
-
format(index: number, length: number, attributes: LiveTextAttributesPatch): void;
|
|
1049
|
-
/** Returns the plain text content without attributes. Equivalent to joining the text from each segment in {@link LiveText.toJSON}. */
|
|
1050
|
-
toString(): string;
|
|
1051
|
-
/**
|
|
1052
|
-
* Returns a JSON-compatible snapshot of the document as a {@link LiveTextData}
|
|
1053
|
-
* array.
|
|
1054
|
-
*
|
|
1055
|
-
* @example
|
|
1056
|
-
* new LiveText([["Hello ", { bold: true }], ["world"]]).toJSON();
|
|
1057
|
-
* // [["Hello ", { bold: true }], ["world"]]
|
|
1058
|
-
*/
|
|
1059
|
-
toJSON(): LiveTextData;
|
|
1060
|
-
clone(): LiveText;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
type StorageCallback = (updates: StorageUpdate[]) => void;
|
|
1064
|
-
type LiveMapUpdate = LiveMapUpdates<string, Lson>;
|
|
1065
|
-
type LiveObjectUpdate = LiveObjectUpdates<LsonObject>;
|
|
1066
|
-
type LiveListUpdate = LiveListUpdates<Lson>;
|
|
1067
|
-
type LiveTextUpdate = LiveTextUpdates;
|
|
1068
|
-
type Via = "edit" | "undo" | "redo";
|
|
1069
|
-
/**
|
|
1070
|
-
* Where a Storage update came from.
|
|
1071
|
-
*
|
|
1072
|
-
* Updates with `origin: "remote"` were made by another client, and reached
|
|
1073
|
-
* this client over the network. Updates with `origin: "local"` were made by
|
|
1074
|
-
* this client, and `via` says how: a regular edit, or a replay from the
|
|
1075
|
-
* undo/redo history.
|
|
1076
|
-
*/
|
|
1077
|
-
type UpdateSource = {
|
|
1078
|
-
origin: "remote";
|
|
1079
|
-
} | {
|
|
1080
|
-
origin: "local";
|
|
1081
|
-
via: Via;
|
|
1082
|
-
};
|
|
1083
|
-
/**
|
|
1084
|
-
* The payload of notifications sent (in-client) when LiveStructures change.
|
|
1085
|
-
* Messages of this kind are not originating from the network, but are 100%
|
|
1086
|
-
* in-client.
|
|
1087
|
-
*
|
|
1088
|
-
* Every update carries a `source`, saying where the change came from. See
|
|
1089
|
-
* {@link UpdateSource}.
|
|
1090
|
-
*/
|
|
1091
|
-
type StorageUpdate = LiveMapUpdate | LiveObjectUpdate | LiveListUpdate | LiveTextUpdate;
|
|
1092
|
-
|
|
1093
|
-
type LiveListUpdateDelta = {
|
|
1094
|
-
type: "insert";
|
|
1095
|
-
index: number;
|
|
1096
|
-
item: Lson;
|
|
1097
|
-
} | {
|
|
1098
|
-
type: "delete";
|
|
1099
|
-
index: number;
|
|
1100
|
-
deletedItem: Lson;
|
|
1101
|
-
} | {
|
|
1102
|
-
type: "move";
|
|
1103
|
-
index: number;
|
|
1104
|
-
previousIndex: number;
|
|
1105
|
-
item: Lson;
|
|
1106
|
-
} | {
|
|
1107
|
-
type: "set";
|
|
1108
|
-
index: number;
|
|
1109
|
-
item: Lson;
|
|
1110
|
-
};
|
|
1111
|
-
/**
|
|
1112
|
-
* A LiveList notification that is sent in-client to any subscribers whenever
|
|
1113
|
-
* one or more of the items inside the LiveList instance have changed.
|
|
1114
|
-
*/
|
|
1115
|
-
type LiveListUpdates<TItem extends Lson> = {
|
|
1116
|
-
type: "LiveList";
|
|
1117
|
-
node: LiveList<TItem>;
|
|
1118
|
-
updates: LiveListUpdateDelta[];
|
|
1119
|
-
source: UpdateSource;
|
|
1120
|
-
};
|
|
1121
|
-
/**
|
|
1122
|
-
* The LiveList class represents an ordered collection of items that is synchronized across clients.
|
|
1123
|
-
*/
|
|
1124
|
-
declare class LiveList<TItem extends Lson> extends AbstractCrdt {
|
|
1125
|
-
#private;
|
|
1126
|
-
constructor(items: TItem[]);
|
|
1127
|
-
/**
|
|
1128
|
-
* Returns the number of elements.
|
|
1129
|
-
*/
|
|
1130
|
-
get length(): number;
|
|
1131
|
-
/**
|
|
1132
|
-
* Adds one element to the end of the LiveList.
|
|
1133
|
-
* @param element The element to add to the end of the LiveList.
|
|
1134
|
-
*/
|
|
1135
|
-
push(element: TItem): void;
|
|
1136
|
-
/**
|
|
1137
|
-
* Inserts one element at a specified index.
|
|
1138
|
-
* @param element The element to insert.
|
|
1139
|
-
* @param index The index at which you want to insert the element.
|
|
1140
|
-
*/
|
|
1141
|
-
insert(element: TItem, index: number): void;
|
|
1142
|
-
/**
|
|
1143
|
-
* Move one element from one index to another.
|
|
1144
|
-
* @param index The index of the element to move
|
|
1145
|
-
* @param targetIndex The index where the element should be after moving.
|
|
1146
|
-
*/
|
|
1147
|
-
move(index: number, targetIndex: number): void;
|
|
1148
|
-
/**
|
|
1149
|
-
* Deletes an element at the specified index
|
|
1150
|
-
* @param index The index of the element to delete
|
|
1151
|
-
*/
|
|
1152
|
-
delete(index: number): void;
|
|
1153
|
-
clear(): void;
|
|
1154
|
-
set(index: number, item: TItem): void;
|
|
1155
|
-
/**
|
|
1156
|
-
* Tests whether all elements pass the test implemented by the provided function.
|
|
1157
|
-
* @param predicate Function to test for each element, taking two arguments (the element and its index).
|
|
1158
|
-
* @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
|
|
1159
|
-
*/
|
|
1160
|
-
every(predicate: (value: TItem, index: number) => unknown): boolean;
|
|
1161
|
-
/**
|
|
1162
|
-
* Creates an array with all elements that pass the test implemented by the provided function.
|
|
1163
|
-
* @param predicate Function to test each element of the LiveList. Return a value that coerces to true to keep the element, or to false otherwise.
|
|
1164
|
-
* @returns An array with the elements that pass the test.
|
|
1165
|
-
*/
|
|
1166
|
-
filter(predicate: (value: TItem, index: number) => unknown): TItem[];
|
|
1167
|
-
/**
|
|
1168
|
-
* Returns the first element that satisfies the provided testing function.
|
|
1169
|
-
* @param predicate Function to execute on each value.
|
|
1170
|
-
* @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
1171
|
-
*/
|
|
1172
|
-
find(predicate: (value: TItem, index: number) => unknown): TItem | undefined;
|
|
1173
|
-
/**
|
|
1174
|
-
* Returns the index of the first element in the LiveList that satisfies the provided testing function.
|
|
1175
|
-
* @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
|
|
1176
|
-
* @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
|
|
1177
|
-
*/
|
|
1178
|
-
findIndex(predicate: (value: TItem, index: number) => unknown): number;
|
|
1179
|
-
/**
|
|
1180
|
-
* Executes a provided function once for each element.
|
|
1181
|
-
* @param callbackfn Function to execute on each element.
|
|
1182
|
-
*/
|
|
1183
|
-
forEach(callbackfn: (value: TItem, index: number) => void): void;
|
|
1184
|
-
/**
|
|
1185
|
-
* Get the element at the specified index.
|
|
1186
|
-
* @param index The index on the element to get.
|
|
1187
|
-
* @returns The element at the specified index or undefined.
|
|
1188
|
-
*/
|
|
1189
|
-
get(index: number): TItem | undefined;
|
|
1190
|
-
/**
|
|
1191
|
-
* Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
|
|
1192
|
-
* @param searchElement Element to locate.
|
|
1193
|
-
* @param fromIndex The index to start the search at.
|
|
1194
|
-
* @returns The first index of the element in the LiveList; -1 if not found.
|
|
1195
|
-
*/
|
|
1196
|
-
indexOf(searchElement: TItem, fromIndex?: number): number;
|
|
1197
|
-
/**
|
|
1198
|
-
* Returns the last index at which a given element can be found in the LiveList, or -1 if it is not present. The LiveList is searched backwards, starting at fromIndex.
|
|
1199
|
-
* @param searchElement Element to locate.
|
|
1200
|
-
* @param fromIndex The index at which to start searching backwards.
|
|
1201
|
-
* @returns The last index of the element in the LiveList; -1 if not found.
|
|
1202
|
-
*/
|
|
1203
|
-
lastIndexOf(searchElement: TItem, fromIndex?: number): number;
|
|
1204
|
-
/**
|
|
1205
|
-
* Creates an array populated with the results of calling a provided function on every element.
|
|
1206
|
-
* @param callback Function that is called for every element.
|
|
1207
|
-
* @returns An array with each element being the result of the callback function.
|
|
1208
|
-
*/
|
|
1209
|
-
map<U>(callback: (value: TItem, index: number) => U): U[];
|
|
1210
|
-
/**
|
|
1211
|
-
* Tests whether at least one element in the LiveList passes the test implemented by the provided function.
|
|
1212
|
-
* @param predicate Function to test for each element.
|
|
1213
|
-
* @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
|
|
1214
|
-
*/
|
|
1215
|
-
some(predicate: (value: TItem, index: number) => unknown): boolean;
|
|
1216
|
-
[Symbol.iterator](): IterableIterator<TItem>;
|
|
1217
|
-
toJSON(): readonly ToJson<TItem>[];
|
|
1218
|
-
clone(): LiveList<TItem>;
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
902
|
/**
|
|
1222
903
|
* INTERNAL
|
|
1223
904
|
*/
|
|
@@ -1228,7 +909,7 @@ declare class LiveRegister<TValue extends Json> extends AbstractCrdt {
|
|
|
1228
909
|
clone(): TValue;
|
|
1229
910
|
}
|
|
1230
911
|
|
|
1231
|
-
type LiveStructure = LiveObject<LsonObject> | LiveList<Lson> | LiveMap<string, Lson> |
|
|
912
|
+
type LiveStructure = LiveObject<LsonObject> | LiveList<Lson> | LiveMap<string, Lson> | LiveFile;
|
|
1232
913
|
/**
|
|
1233
914
|
* Think of Lson as a sibling of the Json data tree, except that the nested
|
|
1234
915
|
* data structure can contain a mix of Json values and LiveStructure instances.
|
|
@@ -1264,10 +945,21 @@ type ToJson<L extends Lson | LsonObject> = L extends LiveList<infer I extends Ls
|
|
|
1264
945
|
readonly [K in keyof O]: ToJson<Exclude<O[K], undefined>> | (undefined extends O[K] ? undefined : never);
|
|
1265
946
|
} : L extends LiveMap<infer KS extends string, infer V extends Lson> ? Lson extends V ? ReadonlyJsonObject : {
|
|
1266
947
|
readonly [K in KS]: ToJson<V>;
|
|
1267
|
-
} : L extends
|
|
948
|
+
} : L extends LiveFile ? LiveFileData : L extends LsonObject ? string extends keyof L ? ReadonlyJsonObject : {
|
|
1268
949
|
readonly [K in keyof L]: ToJson<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
|
|
1269
950
|
} : L extends Json ? L : never;
|
|
1270
951
|
|
|
952
|
+
type StorageCallback = (updates: StorageUpdate[]) => void;
|
|
953
|
+
type LiveMapUpdate = LiveMapUpdates<string, Lson>;
|
|
954
|
+
type LiveObjectUpdate = LiveObjectUpdates<LsonObject>;
|
|
955
|
+
type LiveListUpdate = LiveListUpdates<Lson>;
|
|
956
|
+
/**
|
|
957
|
+
* The payload of notifications sent (in-client) when LiveStructures change.
|
|
958
|
+
* Messages of this kind are not originating from the network, but are 100%
|
|
959
|
+
* in-client.
|
|
960
|
+
*/
|
|
961
|
+
type StorageUpdate = LiveMapUpdate | LiveObjectUpdate | LiveListUpdate;
|
|
962
|
+
|
|
1271
963
|
/**
|
|
1272
964
|
* Read-only query surface over {@link UnacknowledgedOps}, handed to CRDTs so
|
|
1273
965
|
* they can look up their own still-pending Create ops without being able to
|
|
@@ -1292,27 +984,6 @@ interface ReadonlyUnacknowledgedOps {
|
|
|
1292
984
|
isPossiblyStored(opId: string): boolean;
|
|
1293
985
|
}
|
|
1294
986
|
|
|
1295
|
-
type DispatchOptions = {
|
|
1296
|
-
/**
|
|
1297
|
-
* Whether this dispatch should clear the redo stack. Defaults to true when
|
|
1298
|
-
* any forward ops are included (a fresh local mutation), false otherwise.
|
|
1299
|
-
* LiveText uses this to dispatch queued ops after an acknowledgement
|
|
1300
|
-
* (which should not clear redo), and to register fresh local edits that
|
|
1301
|
-
* don't carry wire ops yet (which should).
|
|
1302
|
-
*/
|
|
1303
|
-
clearRedoStack?: boolean;
|
|
1304
|
-
};
|
|
1305
|
-
/**
|
|
1306
|
-
* Private methods on any Liveblocks CRDT node. As a user of Liveblocks, NEVER
|
|
1307
|
-
* USE ANY OF THESE DIRECTLY, because bad things will probably happen if you do.
|
|
1308
|
-
*/
|
|
1309
|
-
type PrivateLiveNodeApi = {
|
|
1310
|
-
/**
|
|
1311
|
-
* Returns the CRDT node id once attached to the room pool. Detached nodes
|
|
1312
|
-
* that have not entered storage yet return `undefined`.
|
|
1313
|
-
*/
|
|
1314
|
-
getId(): string | undefined;
|
|
1315
|
-
};
|
|
1316
987
|
/**
|
|
1317
988
|
* The managed pool is a namespace registry (i.e. a context) that "owns" all
|
|
1318
989
|
* the individual live nodes, ensuring each one has a unique ID, and holding on
|
|
@@ -1331,7 +1002,7 @@ interface ManagedPool {
|
|
|
1331
1002
|
* - Add reverse operations to the undo/redo stack
|
|
1332
1003
|
* - Notify room subscribers with updates (in-client, no networking)
|
|
1333
1004
|
*/
|
|
1334
|
-
dispatch: (ops: ClientWireOp[], reverseOps: Op[], storageUpdates: Map<string, StorageUpdate
|
|
1005
|
+
dispatch: (ops: ClientWireOp[], reverseOps: Op[], storageUpdates: Map<string, StorageUpdate>) => void;
|
|
1335
1006
|
/**
|
|
1336
1007
|
* Ensures storage can be written to else throws an error.
|
|
1337
1008
|
* This is used to prevent writing to storage when the user does not have
|
|
@@ -1356,7 +1027,7 @@ type CreateManagedPoolOptions = {
|
|
|
1356
1027
|
/**
|
|
1357
1028
|
* Will get invoked when any Live structure calls .dispatch() on the pool.
|
|
1358
1029
|
*/
|
|
1359
|
-
onDispatch?: (ops: ClientWireOp[], reverse: Op[], storageUpdates: Map<string, StorageUpdate
|
|
1030
|
+
onDispatch?: (ops: ClientWireOp[], reverse: Op[], storageUpdates: Map<string, StorageUpdate>) => void;
|
|
1360
1031
|
/**
|
|
1361
1032
|
* Will get invoked when any Live structure calls .assertStorageIsWritable()
|
|
1362
1033
|
* on the pool. Defaults to true when not provided. Return false if you want
|
|
@@ -1378,8 +1049,6 @@ type CreateManagedPoolOptions = {
|
|
|
1378
1049
|
declare function createManagedPool(options: CreateManagedPoolOptions): ManagedPool;
|
|
1379
1050
|
declare abstract class AbstractCrdt {
|
|
1380
1051
|
#private;
|
|
1381
|
-
readonly [kInternal]: PrivateLiveNodeApi;
|
|
1382
|
-
constructor();
|
|
1383
1052
|
/**
|
|
1384
1053
|
* @private
|
|
1385
1054
|
* Returns true if the cached JSON snapshot exists and is reference-equal
|
|
@@ -2392,6 +2061,25 @@ interface LiveblocksHttpApi<TM extends BaseMetadata, CM extends BaseMetadata> ex
|
|
|
2392
2061
|
getGroup(groupId: string): Promise<GroupData | undefined>;
|
|
2393
2062
|
}
|
|
2394
2063
|
|
|
2064
|
+
/**
|
|
2065
|
+
* Use this symbol to brand an object property as internal.
|
|
2066
|
+
*
|
|
2067
|
+
* @example
|
|
2068
|
+
* Object.defineProperty(
|
|
2069
|
+
* {
|
|
2070
|
+
* public,
|
|
2071
|
+
* [kInternal]: {
|
|
2072
|
+
* private
|
|
2073
|
+
* },
|
|
2074
|
+
* },
|
|
2075
|
+
* kInternal,
|
|
2076
|
+
* {
|
|
2077
|
+
* enumerable: false,
|
|
2078
|
+
* }
|
|
2079
|
+
* );
|
|
2080
|
+
*/
|
|
2081
|
+
declare const kInternal: unique symbol;
|
|
2082
|
+
|
|
2395
2083
|
/**
|
|
2396
2084
|
* Back-port of TypeScript 5.4's built-in NoInfer utility type.
|
|
2397
2085
|
* See https://stackoverflow.com/a/56688073/148872
|
|
@@ -4542,14 +4230,7 @@ interface SyncSource {
|
|
|
4542
4230
|
*/
|
|
4543
4231
|
type PrivateRoomApi = {
|
|
4544
4232
|
presenceBuffer: Json | undefined;
|
|
4545
|
-
undoStack: readonly
|
|
4546
|
-
readonly id: number;
|
|
4547
|
-
readonly frames: readonly Readonly<Stackframe<JsonObject>>[];
|
|
4548
|
-
}[];
|
|
4549
|
-
redoStack: readonly {
|
|
4550
|
-
readonly id: number;
|
|
4551
|
-
readonly frames: readonly Readonly<Stackframe<JsonObject>>[];
|
|
4552
|
-
}[];
|
|
4233
|
+
undoStack: readonly (readonly Readonly<Stackframe<JsonObject>>[])[];
|
|
4553
4234
|
nodeCount: number;
|
|
4554
4235
|
getYjsProvider(): IYjsProvider | undefined;
|
|
4555
4236
|
setYjsProvider(provider: IYjsProvider | undefined): void;
|
|
@@ -4590,21 +4271,6 @@ type PrivateRoomApi = {
|
|
|
4590
4271
|
};
|
|
4591
4272
|
attachmentUrlsStore: BatchStore<string, string>;
|
|
4592
4273
|
fileUrlsStore: BatchStore<FileUrlData, string>;
|
|
4593
|
-
readonly history: Observable<{
|
|
4594
|
-
action: "push";
|
|
4595
|
-
id: number;
|
|
4596
|
-
} | {
|
|
4597
|
-
action: "undo";
|
|
4598
|
-
id: number;
|
|
4599
|
-
} | {
|
|
4600
|
-
action: "redo";
|
|
4601
|
-
id: number;
|
|
4602
|
-
} | {
|
|
4603
|
-
action: "clear";
|
|
4604
|
-
} | {
|
|
4605
|
-
action: "discard";
|
|
4606
|
-
ids: number[];
|
|
4607
|
-
}>;
|
|
4608
4274
|
};
|
|
4609
4275
|
type Stackframe<P extends JsonObject> = Op | PresenceStackframe<P>;
|
|
4610
4276
|
type PresenceStackframe<P extends JsonObject> = {
|
|
@@ -5504,16 +5170,11 @@ type PlainLsonList = {
|
|
|
5504
5170
|
liveblocksType: "LiveList";
|
|
5505
5171
|
data: PlainLson[];
|
|
5506
5172
|
};
|
|
5507
|
-
type PlainLsonText = {
|
|
5508
|
-
liveblocksType: "LiveText";
|
|
5509
|
-
data: LiveTextData;
|
|
5510
|
-
version?: number;
|
|
5511
|
-
};
|
|
5512
5173
|
type PlainLsonFile = {
|
|
5513
5174
|
liveblocksType: "LiveFile";
|
|
5514
5175
|
data: LiveFileData;
|
|
5515
5176
|
};
|
|
5516
|
-
type PlainLson = PlainLsonObject | PlainLsonMap | PlainLsonList |
|
|
5177
|
+
type PlainLson = PlainLsonObject | PlainLsonMap | PlainLsonList | PlainLsonFile | Json;
|
|
5517
5178
|
|
|
5518
5179
|
/**
|
|
5519
5180
|
* Returns PlainLson for a given Json or LiveStructure, suitable for calling the storage init api
|
|
@@ -6229,4 +5890,4 @@ type EnsureJson<T> = T extends Json ? T : T extends Array<infer I> ? (EnsureJson
|
|
|
6229
5890
|
[K in keyof T as EnsureJson<T[K]> extends never ? never : K]: EnsureJson<T[K]>;
|
|
6230
5891
|
};
|
|
6231
5892
|
|
|
6232
|
-
export { type AccessLevel, type ActivityData, type AiAssistantContentPart, type AiAssistantMessage, type AiChat, type AiChatMessage, type AiChatsQuery, type AiKnowledgeRetrievalPart, type AiKnowledgeSource, type AiOpaqueToolDefinition, type AiOpaqueToolInvocationProps, type AiReasoningPart, type AiRetrievalPart, type AiSourcesPart, type AiTextPart, type AiToolDefinition, type AiToolExecuteCallback, type AiToolExecuteContext, type AiToolInvocationPart, type AiToolInvocationProps, type AiToolTypePack, type AiUrlSource, type AiUserMessage, type AiWebRetrievalPart, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type Awaitable, type BaseActivitiesData, type BaseAuthResult, type BaseGroupInfo, type BaseMetadata, type BaseRoomInfo, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type ChildStorageNode, type Client, type ClientMsg, ClientMsgCode, type ClientOptions, type ClientWireOp, type CommentAttachment, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentLocalAttachment, type CommentMixedAttachment, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, type CommentsEventServerMsg, type CompactChildNode, type CompactFileNode, type CompactListNode, type CompactMapNode, type CompactNode, type CompactObjectNode, type CompactRegisterNode, type CompactRootNode, type
|
|
5893
|
+
export { type AccessLevel, type ActivityData, type AiAssistantContentPart, type AiAssistantMessage, type AiChat, type AiChatMessage, type AiChatsQuery, type AiKnowledgeRetrievalPart, type AiKnowledgeSource, type AiOpaqueToolDefinition, type AiOpaqueToolInvocationProps, type AiReasoningPart, type AiRetrievalPart, type AiSourcesPart, type AiTextPart, type AiToolDefinition, type AiToolExecuteCallback, type AiToolExecuteContext, type AiToolInvocationPart, type AiToolInvocationProps, type AiToolTypePack, type AiUrlSource, type AiUserMessage, type AiWebRetrievalPart, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type Awaitable, type BaseActivitiesData, type BaseAuthResult, type BaseGroupInfo, type BaseMetadata, type BaseRoomInfo, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type ChildStorageNode, type Client, type ClientMsg, ClientMsgCode, type ClientOptions, type ClientWireOp, type CommentAttachment, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentLocalAttachment, type CommentMixedAttachment, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, type CommentsEventServerMsg, type CompactChildNode, type CompactFileNode, type CompactListNode, type CompactMapNode, type CompactNode, type CompactObjectNode, type CompactRegisterNode, type CompactRootNode, type ContextualPromptContext, type ContextualPromptResponse, type CopilotId, CrdtType, type CreateFileOp, type CreateListOp, type CreateManagedPoolOptions, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type Cursor, type CustomAuthenticationResult, type DAD, type DCM, type DE, type DFM, type DFMD, type DGI, type DP, type DRI, type DS, type DTM, type DU, DefaultMap, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, Deque, DerivedSignal, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type DistributiveOmit, type EnsureJson, type EnterOptions, type EventSource, type Feed, type FeedCreateMetadata, type FeedDeletedServerMsg, type FeedFetchMetadataFilter, type FeedMessage, type FeedMessagesAddedServerMsg, type FeedMessagesDeletedServerMsg, type FeedMessagesListServerMsg, type FeedMessagesUpdatedServerMsg, type FeedRequestError, FeedRequestErrorCode, type FeedRequestFailedServerMsg, type FeedUpdateMetadata, type FeedsAddedServerMsg, type FeedsEventServerMsg, type FeedsListServerMsg, type FeedsUpdatedServerMsg, type FetchStorageClientMsg, type FetchYDocClientMsg, type FileStorageNode, type FileUrlData, type GetThreadsOptions, type GroupData, type GroupDataPlain, type GroupMemberData, type GroupMentionData, type GroupScopes, type HasOpId, type History, type HistoryVersion, HttpError, type ISODateString, type ISignal, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IYjsProvider, type IgnoredOp, type Immutable, type InboxNotificationCustomData, type InboxNotificationCustomDataPlain, type InboxNotificationData, type InboxNotificationDataPlain, type InboxNotificationDeleteInfo, type InboxNotificationTextMentionData, type InboxNotificationTextMentionDataPlain, type InboxNotificationThreadData, type InboxNotificationThreadDataPlain, type InferFromSchema, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, type LayerKey, type ListStorageNode, LiveFile, type LiveFileData, type LiveFileReference, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LiveblocksErrorContext, type LostConnectionEvent, type Lson, type LsonObject, MENTION_CHARACTER, type ManagedPool, type MapStorageNode, type MentionData, type MessageId, MutableSignal, type NoInfr, type NodeMap, type NodeStream, type NotificationChannel, type NotificationChannelSettings, type NotificationKind, type NotificationSettings, type NotificationSettingsPlain, type ObjectStorageNode, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialNotificationSettings, type PartialUnless, type Patchable, Permission, type PermissionMatrix, type PermissionResources, type PlainLson, type PlainLsonFields, type PlainLsonFile, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type Poller, type PrivateClientApi, type PrivateRoomApi, Promise_withResolvers, type QueryMetadata, type QueryParams, type ReadonlyJson, type ReadonlyJsonObject, type RegisterStorageNode, type RejectedStorageOpServerMsg, type Relax, type RenderableToolResultResponse, type RequiredAccessLevel, type Resolve, type ResolveGroupsInfoArgs, type ResolveMentionSuggestionsArgs, type ResolveRoomsInfoArgs, type ResolveUsersArgs, type Room, type RoomAccesses, type RoomEventMessage, type RoomPermissions, type RoomStateServerMsg, type RoomSubscriptionSettings, type RootStorageNode, type SearchCommentsResult, type SerializedChild, type SerializedCrdt, type SerializedFile, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type ServerWireOp, type SetParentKeyOp, Signal, type SignalType, SortedList, type Status, type StorageChunkServerMsg, type StorageNode, type StorageStatus, type StorageUpdate, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type SubscriptionData, type SubscriptionDataPlain, type SubscriptionDeleteInfo, type SubscriptionDeleteInfoPlain, type SubscriptionKey, type SyncConfig, type SyncMode, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ThreadVisibility, type ToJson, type ToolResultResponse, type URLSafeString, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateRoomAccesses, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type UploadFileOptions, type UrlMetadata, type User, type UserJoinServerMsg, type UserLeftServerMsg, type UserMentionData, type UserRoomSubscriptionSettings, type UserSubscriptionData, type UserSubscriptionDataPlain, WebsocketCloseCodes, type WithNavigation, type WithOptional, type WithRequired, type YDocUpdateServerMsg, type YjsSyncStatus, asPos, assert, assertNever, autoRetry, b64decode, batch, checkBounds, chunk, cloneLson, compactNodesToNodeStream, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToGroupData, convertToInboxNotificationData, convertToSubscriptionData, convertToThreadData, convertToUserSubscriptionData, createClient, createCommentAttachmentId, createCommentId, createInboxNotificationId, createManagedPool, createNotificationSettings, createStorageFileId, createThreadId, deepLiveify, defineAiTool, deprecate, deprecateIf, detectDupes, entries, errorIf, findLastIndex, freeze, generateUrl, getLiveFileId, getMentionsFromCommentBody, getSubscriptionKey, hasPermissionAccess, html, htmlSafe, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isFileStorageNode, isJsonArray, isJsonObject, isJsonScalar, isListStorageNode, isLiveNode, isMapStorageNode, isNotificationChannelEnabled, isNumberOperator, isObjectStorageNode, isPlainObject, isRegisterStorageNode, isRootStorageNode, isStartsWithOperator, isUrl, kInternal, keys, makeAbortController, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, mergeRoomPermissionScopes, nanoid, nn, nodeStreamToCompactNodes, normalizeRoomAccesses, normalizeRoomPermissions, normalizeUpdateRoomAccesses, objectToQuery, patchNotificationSettings, permissionMatrixFromScopes, raise, resolveMentionsInCommentBody, sanitizeUrl, shallow, shallow2, stableStringify, stringifyCommentBody, throwUsageError, toPlainLson, tryParseJson, url, urljoin, validatePermissionsSet, wait, warnOnce, warnOnceIf, withTimeout };
|