@liveblocks/server 1.5.0 → 1.6.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 +364 -363
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -261
- package/dist/index.d.ts +266 -261
- package/dist/index.js +339 -338
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Json, asPos, IUserInfo, SerializedCrdt, JsonObject, DistributiveOmit, SetParentKeyOp, DeleteCrdtOp, ClientMsg as ClientMsg$1, Brand, SerializedRootObject, SerializedChild, StorageNode,
|
|
1
|
+
import { Json, asPos, IUserInfo, SerializedCrdt, JsonObject, DistributiveOmit, SetParentKeyOp, DeleteCrdtOp, ClientMsg as ClientMsg$1, Brand, SerializedRootObject, SerializedChild, StorageNode, CompactNode, PlainLsonObject, NodeMap as NodeMap$1, NodeStream as NodeStream$1, ClientWireOp, CreateOp, HasOpId, ServerMsg as ServerMsg$1, BaseUserMeta, IgnoredOp } from '@liveblocks/core';
|
|
2
2
|
export { BroadcastEventClientMsg, ClientMsg, ClientWireOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, DeleteCrdtOp, DeleteObjectKeyOp, FetchStorageClientMsg, FetchYDocClientMsg, HasOpId, IgnoredOp, Op, RoomStateServerMsg, ServerMsg, ServerWireOp, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMsg, UpdateStorageClientMsg, UpdateYDocClientMsg } from '@liveblocks/core';
|
|
3
3
|
import * as decoders from 'decoders';
|
|
4
4
|
import { Decoder } from 'decoders';
|
|
@@ -521,96 +521,6 @@ interface IServerWebSocket {
|
|
|
521
521
|
getLastPongTimestamp?(): Date | null;
|
|
522
522
|
}
|
|
523
523
|
|
|
524
|
-
/**
|
|
525
|
-
* Copyright (c) Liveblocks Inc.
|
|
526
|
-
*
|
|
527
|
-
* This program is free software: you can redistribute it and/or modify
|
|
528
|
-
* it under the terms of the GNU Affero General Public License as published
|
|
529
|
-
* by the Free Software Foundation, either version 3 of the License, or
|
|
530
|
-
* (at your option) any later version.
|
|
531
|
-
*
|
|
532
|
-
* This program is distributed in the hope that it will be useful,
|
|
533
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
534
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
535
|
-
* GNU Affero General Public License for more details.
|
|
536
|
-
*
|
|
537
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
538
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
539
|
-
*/
|
|
540
|
-
|
|
541
|
-
declare enum LogLevel {
|
|
542
|
-
DEBUG = 0,
|
|
543
|
-
INFO = 1,
|
|
544
|
-
WARNING = 2,
|
|
545
|
-
ERROR = 3
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Inherit from this abstract log target to implement your own custom
|
|
549
|
-
* LogTarget.
|
|
550
|
-
*/
|
|
551
|
-
declare abstract class LogTarget {
|
|
552
|
-
#private;
|
|
553
|
-
readonly level: LogLevel;
|
|
554
|
-
constructor(level?: LogLevel | keyof typeof LogLevelNames);
|
|
555
|
-
/** Helper for formatting a log level */
|
|
556
|
-
protected formatLevel(level: LogLevel): string;
|
|
557
|
-
/** Helper for formatting an Arg */
|
|
558
|
-
protected formatArg(arg: string | Error): string;
|
|
559
|
-
/**
|
|
560
|
-
* Helper for formatting a Context. Override this in a subclass to change the
|
|
561
|
-
* formatting.
|
|
562
|
-
*/
|
|
563
|
-
protected formatContextImpl(context: JsonObject): string;
|
|
564
|
-
/**
|
|
565
|
-
* Helper for formatting a Context. Will only compute the string once for
|
|
566
|
-
* every Context instance, and keep its computed string value cached for
|
|
567
|
-
* performance.
|
|
568
|
-
*/
|
|
569
|
-
protected formatContext(context: JsonObject): string;
|
|
570
|
-
/**
|
|
571
|
-
* Implement this in a concrete subclass. The goal is to do whatever to log
|
|
572
|
-
* the given log level, context, and log arg. You'll typically want to
|
|
573
|
-
* utilize the pre-defined helper methods .formatContext() and .formatArg()
|
|
574
|
-
* to implement this.
|
|
575
|
-
*/
|
|
576
|
-
abstract log(level: LogLevel, context: JsonObject, arg: string | Error): void;
|
|
577
|
-
}
|
|
578
|
-
declare class ConsoleTarget extends LogTarget {
|
|
579
|
-
log(level: LogLevel, context: JsonObject, arg: string | Error): void;
|
|
580
|
-
}
|
|
581
|
-
declare const LogLevelNames: {
|
|
582
|
-
readonly debug: LogLevel.DEBUG;
|
|
583
|
-
readonly info: LogLevel.INFO;
|
|
584
|
-
readonly warning: LogLevel.WARNING;
|
|
585
|
-
readonly error: LogLevel.ERROR;
|
|
586
|
-
};
|
|
587
|
-
type LogFn = (arg: string | Error) => void;
|
|
588
|
-
/**
|
|
589
|
-
* Structured logger with configurable log targets.
|
|
590
|
-
*/
|
|
591
|
-
declare class Logger {
|
|
592
|
-
readonly debug: LogFn;
|
|
593
|
-
readonly info: LogFn;
|
|
594
|
-
readonly warn: LogFn;
|
|
595
|
-
readonly error: LogFn;
|
|
596
|
-
readonly o: {
|
|
597
|
-
readonly debug?: LogFn;
|
|
598
|
-
readonly info?: LogFn;
|
|
599
|
-
readonly warn?: LogFn;
|
|
600
|
-
readonly error?: LogFn;
|
|
601
|
-
};
|
|
602
|
-
private readonly _context;
|
|
603
|
-
private readonly _targets;
|
|
604
|
-
constructor(target?: LogTarget | readonly LogTarget[], context?: JsonObject);
|
|
605
|
-
/**
|
|
606
|
-
* Creates a new Logger instance with the given extra context applied. All
|
|
607
|
-
* log calls made from that new Logger will carry all current _and_ the extra
|
|
608
|
-
* context, with the extra context taking precedence. Assign an explicit
|
|
609
|
-
* `undefined` value to a key to "remove" it from the context.
|
|
610
|
-
*/
|
|
611
|
-
withContext(extra: JsonObject): Logger;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
524
|
/**
|
|
615
525
|
* Copyright (c) Liveblocks Inc.
|
|
616
526
|
*
|
|
@@ -697,14 +607,20 @@ interface IReadableSnapshot {
|
|
|
697
607
|
destroy(): void;
|
|
698
608
|
}
|
|
699
609
|
/**
|
|
700
|
-
*
|
|
610
|
+
* Persistent storage backend for Liveblocks room data: CRDT nodes, metadata,
|
|
611
|
+
* actor IDs, and Yjs updates.
|
|
612
|
+
*
|
|
613
|
+
* The node methods will initialize lazily (but synchronously): on first node
|
|
614
|
+
* access, the driver loads/repairs its node state internally, at most once per
|
|
615
|
+
* instance. DANGEROUSLY_reset_nodes() invalidates that state, after which the
|
|
616
|
+
* next access transparently re-runs the load/repair sanitization.
|
|
701
617
|
*
|
|
702
618
|
* INVARIANTS:
|
|
703
619
|
* - A virtual root node `{type: OBJECT, data: {}}` always exists.
|
|
704
620
|
* - All non-root nodes have parentId and parentKey forming a tree.
|
|
705
|
-
* - Reads reflect writes immediately
|
|
621
|
+
* - Reads reflect writes immediately.
|
|
706
622
|
*/
|
|
707
|
-
interface
|
|
623
|
+
interface IStorageDriver {
|
|
708
624
|
/**
|
|
709
625
|
* Return the node with the given id, or undefined if no such node exists.
|
|
710
626
|
* Must always return a valid root node for id="root", even if empty.
|
|
@@ -769,18 +685,18 @@ interface IStorageDriverNodeAPI {
|
|
|
769
685
|
* If allowOverwrite=true: replace any existing node at this id, deleting its
|
|
770
686
|
* entire subtree if it has children.
|
|
771
687
|
*/
|
|
772
|
-
set_child(id: string, node: SerializedChild, allowOverwrite?: boolean):
|
|
688
|
+
set_child(id: string, node: SerializedChild, allowOverwrite?: boolean): void;
|
|
773
689
|
/**
|
|
774
690
|
* Change a node's parentKey, effectively repositioning the node within its
|
|
775
691
|
* parent. The new position must be free.
|
|
776
692
|
* Throw if another node already occupies (parentId, newPos).
|
|
777
693
|
*/
|
|
778
|
-
move_sibling(id: string, newPos: Pos):
|
|
694
|
+
move_sibling(id: string, newPos: Pos): void;
|
|
779
695
|
/**
|
|
780
696
|
* Delete a node and its entire subtree recursively.
|
|
781
697
|
* Ignore if id="root" (root is immortal).
|
|
782
698
|
*/
|
|
783
|
-
delete_node(id: string):
|
|
699
|
+
delete_node(id: string): void;
|
|
784
700
|
/**
|
|
785
701
|
* Delete a key from node `id`. Handle two cases:
|
|
786
702
|
*
|
|
@@ -790,7 +706,7 @@ interface IStorageDriverNodeAPI {
|
|
|
790
706
|
*
|
|
791
707
|
* No-op if neither applies or if the node doesn't exist.
|
|
792
708
|
*/
|
|
793
|
-
delete_child_key(id: string, key: string):
|
|
709
|
+
delete_child_key(id: string, key: string): void;
|
|
794
710
|
/**
|
|
795
711
|
* Replace the data object of an OBJECT node.
|
|
796
712
|
*
|
|
@@ -799,7 +715,7 @@ interface IStorageDriverNodeAPI {
|
|
|
799
715
|
* If allowOverwrite=true: first delete any conflicting children (and their
|
|
800
716
|
* entire subtrees), then set the data.
|
|
801
717
|
*/
|
|
802
|
-
set_object_data(id: string, data: JsonObject, allowOverwrite?: boolean):
|
|
718
|
+
set_object_data(id: string, data: JsonObject, allowOverwrite?: boolean): void;
|
|
803
719
|
/**
|
|
804
720
|
* Return a readable snapshot of the storage tree.
|
|
805
721
|
*
|
|
@@ -808,45 +724,39 @@ interface IStorageDriverNodeAPI {
|
|
|
808
724
|
* access.
|
|
809
725
|
*/
|
|
810
726
|
get_snapshot(lowMemory?: boolean): IReadableSnapshot;
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Persistent storage backend for Liveblocks room data: CRDT nodes, metadata,
|
|
814
|
-
* actor IDs, and Yjs updates. All methods may be async.
|
|
815
|
-
*/
|
|
816
|
-
interface IStorageDriver {
|
|
817
727
|
/**
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
728
|
+
* Release any lazily-initialized in-memory node state (caches/indexes
|
|
729
|
+
* built on first node access), freeing it up for garbage collection.
|
|
730
|
+
* Persisted data is NOT touched — the next node access transparently
|
|
731
|
+
* re-initializes. (Contrast with DANGEROUSLY_reset_nodes(), which deletes
|
|
732
|
+
* the actual data.)
|
|
823
733
|
*/
|
|
824
|
-
|
|
734
|
+
reinitialize(): void;
|
|
825
735
|
/**
|
|
826
736
|
* Delete all CRDT nodes and replace them with the given document.
|
|
827
737
|
* Does NOT affect metadata, actor IDs, or Yjs updates.
|
|
828
|
-
* Invalidates
|
|
738
|
+
* Invalidates the driver's internally loaded node state.
|
|
829
739
|
*
|
|
830
740
|
* Pass `{ liveblocksType: "LiveObject", data: {} }` to reset to an empty root.
|
|
831
741
|
*/
|
|
832
|
-
DANGEROUSLY_reset_nodes(doc: PlainLsonObject):
|
|
742
|
+
DANGEROUSLY_reset_nodes(doc: PlainLsonObject): void;
|
|
833
743
|
/**
|
|
834
744
|
* Return the value for `key`, or undefined if not set.
|
|
835
745
|
*/
|
|
836
|
-
get_meta(key: string):
|
|
746
|
+
get_meta(key: string): Json | undefined;
|
|
837
747
|
/**
|
|
838
748
|
* Store `value` under `key`. Overwrite any existing value.
|
|
839
749
|
*/
|
|
840
|
-
put_meta(key: string, value: Json):
|
|
750
|
+
put_meta(key: string, value: Json): void;
|
|
841
751
|
/**
|
|
842
752
|
* Delete the value under `key`. No-op if not set.
|
|
843
753
|
*/
|
|
844
|
-
delete_meta(key: string):
|
|
754
|
+
delete_meta(key: string): void;
|
|
845
755
|
/**
|
|
846
756
|
* Return a unique actor ID. Each call must return a distinct integer ≥ 0.
|
|
847
757
|
* Concurrent calls must never return duplicates.
|
|
848
758
|
*/
|
|
849
|
-
next_actor():
|
|
759
|
+
next_actor(): number;
|
|
850
760
|
/**
|
|
851
761
|
* If defined, called once before each storage mutation batch. Can be used by
|
|
852
762
|
* the driver to more efficiently implement snapshot isolation.
|
|
@@ -855,42 +765,42 @@ interface IStorageDriver {
|
|
|
855
765
|
/**
|
|
856
766
|
* Return all Yjs updates for docId as [key, data] pairs. Return empty if none.
|
|
857
767
|
*/
|
|
858
|
-
iter_y_updates(docId: YDocId):
|
|
768
|
+
iter_y_updates(docId: YDocId): Iterable<[string, Uint8Array]>;
|
|
859
769
|
/**
|
|
860
770
|
* Store a Yjs update under (docId, key). Overwrite if key exists.
|
|
861
771
|
*/
|
|
862
|
-
write_y_updates(docId: YDocId, key: string, data: Uint8Array):
|
|
772
|
+
write_y_updates(docId: YDocId, key: string, data: Uint8Array): void;
|
|
863
773
|
/**
|
|
864
774
|
* Delete the specified keys for docId.
|
|
865
775
|
*/
|
|
866
|
-
delete_y_updates(docId: YDocId, keys: string[]):
|
|
776
|
+
delete_y_updates(docId: YDocId, keys: string[]): void;
|
|
867
777
|
/**
|
|
868
778
|
* Delete ALL Yjs updates across ALL documents.
|
|
869
779
|
* @private Test-only: never use in production.
|
|
870
780
|
*/
|
|
871
|
-
DANGEROUSLY_wipe_all_y_updates():
|
|
781
|
+
DANGEROUSLY_wipe_all_y_updates(): void;
|
|
872
782
|
/**
|
|
873
783
|
* List all leased sessions.
|
|
874
784
|
* Note: Does NOT filter by expiration - returns all stored sessions.
|
|
875
785
|
* Expiration logic is handled at the Room.ts level.
|
|
876
786
|
*/
|
|
877
|
-
list_leased_sessions():
|
|
787
|
+
list_leased_sessions(): Iterable<[sessionId: string, session: LeasedSession]>;
|
|
878
788
|
/**
|
|
879
789
|
* Get a specific leased session by session ID.
|
|
880
790
|
* Note: Does NOT check expiration - returns the stored session if it exists.
|
|
881
791
|
* Expiration logic is handled at the Room.ts level.
|
|
882
792
|
*/
|
|
883
|
-
get_leased_session(sessionId: string):
|
|
793
|
+
get_leased_session(sessionId: string): LeasedSession | undefined;
|
|
884
794
|
/**
|
|
885
795
|
* Create or update a leased session.
|
|
886
796
|
* Note: This is a full replace operation - the caller is responsible for
|
|
887
797
|
* merging/patching presence if needed.
|
|
888
798
|
*/
|
|
889
|
-
put_leased_session(session: LeasedSession):
|
|
799
|
+
put_leased_session(session: LeasedSession): void;
|
|
890
800
|
/**
|
|
891
801
|
* Delete a leased session by session ID.
|
|
892
802
|
*/
|
|
893
|
-
delete_leased_session(sessionId: string):
|
|
803
|
+
delete_leased_session(sessionId: string): void;
|
|
894
804
|
/**
|
|
895
805
|
* Return the number of storage rows written since last call to this method,
|
|
896
806
|
* and reset the counter.
|
|
@@ -900,41 +810,41 @@ interface IStorageDriver {
|
|
|
900
810
|
* List feeds with pagination, filtering, and metadata querying.
|
|
901
811
|
* Feeds are sorted by createdAt descending (newest first).
|
|
902
812
|
*/
|
|
903
|
-
list_feeds(options?: ListFeedsOptions):
|
|
813
|
+
list_feeds(options?: ListFeedsOptions): ListFeedsResult;
|
|
904
814
|
/**
|
|
905
815
|
* Get a specific feed by feed ID.
|
|
906
816
|
* Returns feed metadata only (without messages).
|
|
907
817
|
* Use list_feed_messages to retrieve messages for this feed.
|
|
908
818
|
* Returns undefined if the feed doesn't exist.
|
|
909
819
|
*/
|
|
910
|
-
get_feed(feedId: string):
|
|
820
|
+
get_feed(feedId: string): Feed | undefined;
|
|
911
821
|
/**
|
|
912
822
|
* Create a new feed.
|
|
913
823
|
* If feedId already exists, throws an error.
|
|
914
824
|
*/
|
|
915
|
-
create_feed(feed: Feed):
|
|
825
|
+
create_feed(feed: Feed): void;
|
|
916
826
|
/**
|
|
917
827
|
* Update a feed's metadata.
|
|
918
828
|
* The feed must exist, otherwise throws an error.
|
|
919
829
|
*/
|
|
920
|
-
update_feed_metadata(feedId: string, metadata: Json):
|
|
830
|
+
update_feed_metadata(feedId: string, metadata: Json): void;
|
|
921
831
|
/**
|
|
922
832
|
* Delete a feed by feed ID.
|
|
923
833
|
* Also deletes all messages associated with the feed (via CASCADE).
|
|
924
834
|
* No-op if feed doesn't exist.
|
|
925
835
|
*/
|
|
926
|
-
delete_feed(feedId: string):
|
|
836
|
+
delete_feed(feedId: string): void;
|
|
927
837
|
/**
|
|
928
838
|
* List feed messages for a feed with pagination.
|
|
929
839
|
* Messages are sorted by createdAt descending (newest first).
|
|
930
840
|
*/
|
|
931
|
-
list_feed_messages(feedId: string, options?: ListFeedMessagesOptions):
|
|
841
|
+
list_feed_messages(feedId: string, options?: ListFeedMessagesOptions): ListFeedMessagesResult;
|
|
932
842
|
/**
|
|
933
843
|
* Add a message to a feed.
|
|
934
844
|
* The message must have id, createdAt, and updatedAt already set (handled by Room layer).
|
|
935
845
|
* The feed must exist, otherwise throws an error.
|
|
936
846
|
*/
|
|
937
|
-
add_feed_message(feedId: string, message: FeedMessage):
|
|
847
|
+
add_feed_message(feedId: string, message: FeedMessage): void;
|
|
938
848
|
/**
|
|
939
849
|
* Update a feed message's data.
|
|
940
850
|
* Returns the updated message.
|
|
@@ -942,12 +852,12 @@ interface IStorageDriver {
|
|
|
942
852
|
* If timestamp is not provided, current server time is used.
|
|
943
853
|
* Messages are only updated if the provided timestamp is greater than or equal to the stored updatedAt.
|
|
944
854
|
*/
|
|
945
|
-
update_feed_message(feedId: string, messageId: string, data: Json, timestamp?: number):
|
|
855
|
+
update_feed_message(feedId: string, messageId: string, data: Json, timestamp?: number): FeedMessage;
|
|
946
856
|
/**
|
|
947
857
|
* Delete a feed message.
|
|
948
858
|
* The feed and message must exist, otherwise throws an error.
|
|
949
859
|
*/
|
|
950
|
-
delete_feed_message(feedId: string, messageId: string):
|
|
860
|
+
delete_feed_message(feedId: string, messageId: string): void;
|
|
951
861
|
}
|
|
952
862
|
|
|
953
863
|
/**
|
|
@@ -1093,10 +1003,10 @@ declare function makeInMemorySnapshot(values: NodeMap$1 | NodeStream$1): IReadab
|
|
|
1093
1003
|
*/
|
|
1094
1004
|
|
|
1095
1005
|
interface MetadataDB {
|
|
1096
|
-
get(key: string):
|
|
1097
|
-
get<T>(decoder: Decoder<T>, key: string):
|
|
1098
|
-
put(key: string, value: Json):
|
|
1099
|
-
delete(key: string):
|
|
1006
|
+
get(key: string): Json | undefined;
|
|
1007
|
+
get<T>(decoder: Decoder<T>, key: string): T | undefined;
|
|
1008
|
+
put(key: string, value: Json): void;
|
|
1009
|
+
delete(key: string): void;
|
|
1100
1010
|
}
|
|
1101
1011
|
/**
|
|
1102
1012
|
* Returns a thin wrapper around an IStorageDriver to provide MetadataDB
|
|
@@ -1121,7 +1031,108 @@ declare function makeMetadataDB(driver: IStorageDriver): MetadataDB;
|
|
|
1121
1031
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
1122
1032
|
*/
|
|
1123
1033
|
|
|
1124
|
-
|
|
1034
|
+
declare enum LogLevel {
|
|
1035
|
+
DEBUG = 0,
|
|
1036
|
+
INFO = 1,
|
|
1037
|
+
WARNING = 2,
|
|
1038
|
+
ERROR = 3
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Inherit from this abstract log target to implement your own custom
|
|
1042
|
+
* LogTarget.
|
|
1043
|
+
*/
|
|
1044
|
+
declare abstract class LogTarget {
|
|
1045
|
+
#private;
|
|
1046
|
+
readonly level: LogLevel;
|
|
1047
|
+
constructor(level?: LogLevel | keyof typeof LogLevelNames);
|
|
1048
|
+
/** Helper for formatting a log level */
|
|
1049
|
+
protected formatLevel(level: LogLevel): string;
|
|
1050
|
+
/** Helper for formatting an Arg */
|
|
1051
|
+
protected formatArg(arg: string | Error): string;
|
|
1052
|
+
/**
|
|
1053
|
+
* Helper for formatting a Context. Override this in a subclass to change the
|
|
1054
|
+
* formatting.
|
|
1055
|
+
*/
|
|
1056
|
+
protected formatContextImpl(context: JsonObject): string;
|
|
1057
|
+
/**
|
|
1058
|
+
* Helper for formatting a Context. Will only compute the string once for
|
|
1059
|
+
* every Context instance, and keep its computed string value cached for
|
|
1060
|
+
* performance.
|
|
1061
|
+
*/
|
|
1062
|
+
protected formatContext(context: JsonObject): string;
|
|
1063
|
+
/**
|
|
1064
|
+
* Implement this in a concrete subclass. The goal is to do whatever to log
|
|
1065
|
+
* the given log level, context, and log arg. You'll typically want to
|
|
1066
|
+
* utilize the pre-defined helper methods .formatContext() and .formatArg()
|
|
1067
|
+
* to implement this.
|
|
1068
|
+
*/
|
|
1069
|
+
abstract log(level: LogLevel, context: JsonObject, arg: string | Error): void;
|
|
1070
|
+
}
|
|
1071
|
+
declare class ConsoleTarget extends LogTarget {
|
|
1072
|
+
log(level: LogLevel, context: JsonObject, arg: string | Error): void;
|
|
1073
|
+
}
|
|
1074
|
+
declare const LogLevelNames: {
|
|
1075
|
+
readonly debug: LogLevel.DEBUG;
|
|
1076
|
+
readonly info: LogLevel.INFO;
|
|
1077
|
+
readonly warning: LogLevel.WARNING;
|
|
1078
|
+
readonly error: LogLevel.ERROR;
|
|
1079
|
+
};
|
|
1080
|
+
type LogFn = (arg: string | Error) => void;
|
|
1081
|
+
/**
|
|
1082
|
+
* Structured logger with configurable log targets.
|
|
1083
|
+
*/
|
|
1084
|
+
declare class Logger {
|
|
1085
|
+
readonly debug: LogFn;
|
|
1086
|
+
readonly info: LogFn;
|
|
1087
|
+
readonly warn: LogFn;
|
|
1088
|
+
readonly error: LogFn;
|
|
1089
|
+
readonly o: {
|
|
1090
|
+
readonly debug?: LogFn;
|
|
1091
|
+
readonly info?: LogFn;
|
|
1092
|
+
readonly warn?: LogFn;
|
|
1093
|
+
readonly error?: LogFn;
|
|
1094
|
+
};
|
|
1095
|
+
private readonly _context;
|
|
1096
|
+
private readonly _targets;
|
|
1097
|
+
constructor(target?: LogTarget | readonly LogTarget[], context?: JsonObject);
|
|
1098
|
+
/**
|
|
1099
|
+
* Creates a new Logger instance with the given extra context applied. All
|
|
1100
|
+
* log calls made from that new Logger will carry all current _and_ the extra
|
|
1101
|
+
* context, with the extra context taking precedence. Assign an explicit
|
|
1102
|
+
* `undefined` value to a key to "remove" it from the context.
|
|
1103
|
+
*/
|
|
1104
|
+
withContext(extra: JsonObject): Logger;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Copyright (c) Liveblocks Inc.
|
|
1109
|
+
*
|
|
1110
|
+
* This program is free software: you can redistribute it and/or modify
|
|
1111
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
1112
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
1113
|
+
* (at your option) any later version.
|
|
1114
|
+
*
|
|
1115
|
+
* This program is distributed in the hope that it will be useful,
|
|
1116
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
1117
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
1118
|
+
* GNU Affero General Public License for more details.
|
|
1119
|
+
*
|
|
1120
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
1121
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
1122
|
+
*/
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* The three possible outcomes of applying a client op. They differ along
|
|
1126
|
+
* when the op (first) changed storage state, who hears about it, and what
|
|
1127
|
+
* gets sent back to the originating client:
|
|
1128
|
+
*
|
|
1129
|
+
* | | state change | fan out to others | reply to sender |
|
|
1130
|
+
* |-------------|--------------|-------------------|------------------|
|
|
1131
|
+
* | OpAccepted | now | yes | ack echo (+ fix) |
|
|
1132
|
+
* | OpRectified | in the past | no | ack echo + fix |
|
|
1133
|
+
* | OpIgnored | never | no | bare (H)Ack |
|
|
1134
|
+
*/
|
|
1135
|
+
type ApplyOpResult = OpAccepted | OpIgnored | OpRectified;
|
|
1125
1136
|
type OpAccepted = {
|
|
1126
1137
|
action: "accepted";
|
|
1127
1138
|
op: ClientWireOp;
|
|
@@ -1131,24 +1142,32 @@ type OpIgnored = {
|
|
|
1131
1142
|
action: "ignored";
|
|
1132
1143
|
ignoredOpId?: string;
|
|
1133
1144
|
};
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1145
|
+
type OpRectified = {
|
|
1146
|
+
action: "rectified";
|
|
1147
|
+
/**
|
|
1148
|
+
* Echo of the client's op, with the stored, authoritative parentKey. Sent
|
|
1149
|
+
* back to the originating client as the acknowledgement, instead of the
|
|
1150
|
+
* bare (H)Ack. Used for re-sent CREATE ops whose node the server already
|
|
1151
|
+
* stored: the echo carries the authoritative position, so the client can
|
|
1152
|
+
* correct any optimistic local position it may have predicted while the op
|
|
1153
|
+
* was pending. Never fanned out to others: they already received the op
|
|
1154
|
+
* when it was originally accepted.
|
|
1155
|
+
*/
|
|
1156
|
+
ackOp: CreateOp & HasOpId;
|
|
1140
1157
|
/**
|
|
1141
|
-
*
|
|
1142
|
-
*
|
|
1143
|
-
* Storage tree, and special keys where we store usage metrics, or room
|
|
1144
|
-
* metadata.
|
|
1158
|
+
* A corrective op to send back to the originating client, stating that
|
|
1159
|
+
* same authoritative position (see ackOp).
|
|
1145
1160
|
*/
|
|
1146
|
-
|
|
1147
|
-
|
|
1161
|
+
fix: FixOp;
|
|
1162
|
+
};
|
|
1163
|
+
declare class Storage {
|
|
1164
|
+
readonly driver: IStorageDriver;
|
|
1165
|
+
constructor(driver: IStorageDriver);
|
|
1166
|
+
raw_iter_nodes(): Iterable<[string, SerializedCrdt]>;
|
|
1148
1167
|
/**
|
|
1149
1168
|
* Applies a batch of Ops.
|
|
1150
1169
|
*/
|
|
1151
|
-
applyOps(ops: ClientWireOp[]):
|
|
1170
|
+
applyOps(ops: ClientWireOp[]): ApplyOpResult[];
|
|
1152
1171
|
/**
|
|
1153
1172
|
* Applies a single Op.
|
|
1154
1173
|
*/
|
|
@@ -1228,41 +1247,46 @@ declare class Storage {
|
|
|
1228
1247
|
declare class YjsStorage {
|
|
1229
1248
|
private readonly driver;
|
|
1230
1249
|
private readonly updateCountThreshold;
|
|
1231
|
-
|
|
1250
|
+
/**
|
|
1251
|
+
* The root Y.Doc instance, which may not have been hydrated from storage
|
|
1252
|
+
* yet. Use getRootDoc() instead, which lazily hydrates it on first access —
|
|
1253
|
+
* only touch this field directly when the unhydrated instance is fine
|
|
1254
|
+
* (e.g. identity checks, subdoc traversal).
|
|
1255
|
+
*/
|
|
1256
|
+
private readonly rawRootDoc;
|
|
1232
1257
|
private readonly lastSnapshotById;
|
|
1233
|
-
private readonly
|
|
1258
|
+
private readonly docsById;
|
|
1234
1259
|
private readonly storedKeysById;
|
|
1235
1260
|
constructor(driver: IStorageDriver, updateCountThreshold?: number);
|
|
1236
|
-
getYDoc(logger: Logger, docId: YDocId):
|
|
1261
|
+
getYDoc(logger: Logger, docId: YDocId): Y.Doc;
|
|
1262
|
+
/**
|
|
1263
|
+
* Returns the root Y.Doc, lazily loading it from storage first if it
|
|
1264
|
+
* hasn't been loaded yet during this instance's lifetime.
|
|
1265
|
+
*/
|
|
1266
|
+
private getRootDoc;
|
|
1237
1267
|
/**
|
|
1238
1268
|
* If passed a state vector, an update with diff will be returned, if not the entire doc is returned.
|
|
1239
1269
|
*
|
|
1240
1270
|
* @param stateVector a base64 encoded target state vector created by running Y.encodeStateVector(Doc) on the client
|
|
1241
1271
|
* @returns a base64 encoded array of YJS updates
|
|
1242
1272
|
*/
|
|
1243
|
-
getYDocUpdate(logger: Logger, stateVector?: string, guid?: Guid, isV2?: boolean):
|
|
1244
|
-
getYDocUpdateBinary(logger: Logger, stateVector?: string, guid?: Guid, isV2?: boolean):
|
|
1245
|
-
getYStateVector(logger: Logger, guid?: Guid):
|
|
1273
|
+
getYDocUpdate(logger: Logger, stateVector?: string, guid?: Guid, isV2?: boolean): string | null;
|
|
1274
|
+
getYDocUpdateBinary(logger: Logger, stateVector?: string, guid?: Guid, isV2?: boolean): Uint8Array<ArrayBuffer> | null;
|
|
1275
|
+
getYStateVector(logger: Logger, guid?: Guid): string | null;
|
|
1246
1276
|
getSnapshotHash(logger: Logger, options: {
|
|
1247
1277
|
guid?: Guid;
|
|
1248
1278
|
isV2?: boolean;
|
|
1249
|
-
}):
|
|
1279
|
+
}): string | null;
|
|
1250
1280
|
/**
|
|
1251
1281
|
* @param update base64 encoded uint8array
|
|
1252
1282
|
* @returns { isUpdated: boolean; snapshotHash: string }
|
|
1253
1283
|
* isUpdated: true if the update had an effect on the YDoc
|
|
1254
1284
|
* snapshotHash: the hash of the new snapshot
|
|
1255
1285
|
*/
|
|
1256
|
-
addYDocUpdate(logger: Logger, update: string | Uint8Array, guid?: Guid, isV2?: boolean):
|
|
1286
|
+
addYDocUpdate(logger: Logger, update: string | Uint8Array, guid?: Guid, isV2?: boolean): {
|
|
1257
1287
|
isUpdated: boolean;
|
|
1258
1288
|
snapshotHash: string;
|
|
1259
|
-
}
|
|
1260
|
-
loadDocByIdIfNotAlreadyLoaded(logger: Logger, docId: YDocId): Promise<Y.Doc>;
|
|
1261
|
-
load(logger: Logger): Promise<void>;
|
|
1262
|
-
/**
|
|
1263
|
-
* Unloads the Yjs documents from memory.
|
|
1264
|
-
*/
|
|
1265
|
-
unload(): void;
|
|
1289
|
+
};
|
|
1266
1290
|
private _getOrPutLastSnapshot;
|
|
1267
1291
|
private _putLastSnapshot;
|
|
1268
1292
|
private _compactYJSUpdates;
|
|
@@ -1292,7 +1316,6 @@ declare class YjsStorage {
|
|
|
1292
1316
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
1293
1317
|
*/
|
|
1294
1318
|
|
|
1295
|
-
type LoadingState = "initial" | "loading" | "loaded";
|
|
1296
1319
|
type ActorID = Brand<number, "ActorID">;
|
|
1297
1320
|
/** Number of milliseconds since Unix epoch. */
|
|
1298
1321
|
type Millis = Brand<number, "Millis">;
|
|
@@ -1401,14 +1424,8 @@ type RoomOptions<SM, CM extends JsonObject, C> = {
|
|
|
1401
1424
|
};
|
|
1402
1425
|
/** Called whenever the server acknowledged a ping with a pong */
|
|
1403
1426
|
onDidPong?: (ctx?: C) => void | Promise<void>;
|
|
1404
|
-
/** Called before the room is attempted to be loaded */
|
|
1405
|
-
onRoomWillLoad?: (ctx?: C) => void | Promise<void>;
|
|
1406
|
-
/** Called right after the room's contents are loaded, but before any session has been started */
|
|
1407
|
-
onRoomDidLoad?: (ctx?: C) => void | Promise<void>;
|
|
1408
1427
|
/** Called right before the room is attempted to be unloaded. Synchronous. May throw to abort the unloading. */
|
|
1409
1428
|
onRoomWillUnload?: (ctx?: C) => void;
|
|
1410
|
-
/** Called right after the room has been unloaded from memory. Synchronous. */
|
|
1411
|
-
onRoomDidUnload?: (ctx?: C) => void;
|
|
1412
1429
|
/** Called when a new user entered the room. */
|
|
1413
1430
|
onSessionDidStart?: (session: BrowserSession<SM, CM>, ctx?: C) => void | Promise<void>;
|
|
1414
1431
|
/** Called when a user left the room. */
|
|
@@ -1444,7 +1461,6 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
|
|
|
1444
1461
|
#private;
|
|
1445
1462
|
meta: RM;
|
|
1446
1463
|
readonly driver: IStorageDriver;
|
|
1447
|
-
logger: Logger;
|
|
1448
1464
|
/**
|
|
1449
1465
|
* While a room is in "maintenance mode", all WebSocket connections to the
|
|
1450
1466
|
* room should be rejected until it's pulled out of maintenance mode again.
|
|
@@ -1454,18 +1470,18 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
|
|
|
1454
1470
|
* init-storage, storage-reset, etc.) cannot interfere with one another.
|
|
1455
1471
|
*/
|
|
1456
1472
|
private readonly _maintenanceMode;
|
|
1457
|
-
private
|
|
1458
|
-
private
|
|
1473
|
+
private _storage;
|
|
1474
|
+
private _yjsStorage;
|
|
1475
|
+
readonly mutex: Mutex;
|
|
1476
|
+
get storage(): Storage;
|
|
1477
|
+
get yjsStorage(): YjsStorage;
|
|
1459
1478
|
private _qsize;
|
|
1460
1479
|
private readonly sessions;
|
|
1461
1480
|
private readonly hooks;
|
|
1462
1481
|
constructor(meta: RM, options?: RoomOptions<SM, CM, C>);
|
|
1463
|
-
get
|
|
1482
|
+
get logger(): Logger;
|
|
1483
|
+
addLoggerContext(attrs: JsonObject): void;
|
|
1464
1484
|
get numSessions(): number;
|
|
1465
|
-
get storage(): Storage;
|
|
1466
|
-
get yjsStorage(): YjsStorage;
|
|
1467
|
-
get mutex(): Mutex;
|
|
1468
|
-
private get data();
|
|
1469
1485
|
/**
|
|
1470
1486
|
* Returns true if the room is currently in maintenance mode.
|
|
1471
1487
|
* When in maintenance mode, callers should refuse new WebSocket connections.
|
|
@@ -1476,17 +1492,11 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
|
|
|
1476
1492
|
* If the room is already in maintenance mode, throws E_ALREADY_LOCKED
|
|
1477
1493
|
* immediately instead of queuing the request.
|
|
1478
1494
|
*/
|
|
1479
|
-
runInMaintenanceMode<T>(callback: () => Promise<T>): Promise<T>;
|
|
1480
|
-
/**
|
|
1481
|
-
* Initializes the Room, so it's ready to start accepting connections. Safe
|
|
1482
|
-
* to call multiple times. After awaiting `room.load()` the Room is ready to
|
|
1483
|
-
* be used.
|
|
1484
|
-
*/
|
|
1485
|
-
load(ctx?: C): Promise<void>;
|
|
1495
|
+
runInMaintenanceMode<T>(callback: () => T | Promise<T>): Promise<T>;
|
|
1486
1496
|
/**
|
|
1487
|
-
* Releases the currently-loaded storage tree
|
|
1488
|
-
* up to be garbage collected. The next time
|
|
1489
|
-
*
|
|
1497
|
+
* Releases the currently-loaded storage tree and Yjs documents from worker
|
|
1498
|
+
* memory, freeing them up to be garbage collected. The next time the room
|
|
1499
|
+
* is used, fresh instances will lazily be created.
|
|
1490
1500
|
*/
|
|
1491
1501
|
unload(ctx?: C): void;
|
|
1492
1502
|
/**
|
|
@@ -1500,11 +1510,11 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
|
|
|
1500
1510
|
* connection is established. If the socket is never established, this
|
|
1501
1511
|
* unused Ticket will simply get garbage collected.
|
|
1502
1512
|
*/
|
|
1503
|
-
createTicket(options?: CreateTicketOptions<SM, CM>):
|
|
1504
|
-
createBackendSession_experimental():
|
|
1513
|
+
createTicket(options?: CreateTicketOptions<SM, CM>): Ticket<SM, CM>;
|
|
1514
|
+
createBackendSession_experimental(): [
|
|
1505
1515
|
session: BackendSession,
|
|
1506
1516
|
outgoingMessages: jstring<ServerMsg>[]
|
|
1507
|
-
]
|
|
1517
|
+
];
|
|
1508
1518
|
/**
|
|
1509
1519
|
* Restores the given sessions as the Room server's session list. Can only be
|
|
1510
1520
|
* called as long as there are no existing sessions.
|
|
@@ -1531,7 +1541,7 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
|
|
|
1531
1541
|
* - Sends a ROOM_STATE message to the socket.
|
|
1532
1542
|
* - Broadcasts a USER_JOINED message to all other sessions in the room.
|
|
1533
1543
|
*/
|
|
1534
|
-
startBrowserSession(ticket: Ticket<SM, CM>, socket: IServerWebSocket, ctx?: C, defer?: (promise: Promise<void>) => void):
|
|
1544
|
+
startBrowserSession(ticket: Ticket<SM, CM>, socket: IServerWebSocket, ctx?: C, defer?: (promise: Promise<void>) => void): void;
|
|
1535
1545
|
/**
|
|
1536
1546
|
* Unregisters the BrowserSession for the given actor. Call this when the socket has
|
|
1537
1547
|
* been closed from the client's end.
|
|
@@ -1587,46 +1597,46 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
|
|
|
1587
1597
|
* Upsert a leased session. Creates a new session if it doesn't exist (or is expired),
|
|
1588
1598
|
* or updates an existing session with merged presence.
|
|
1589
1599
|
*/
|
|
1590
|
-
upsertLeasedSession(sessionId: string, presence: JsonObject, ttl: number, info: IUserInfo, ctx?: C, defer?: (promise: Promise<void>) => void):
|
|
1600
|
+
upsertLeasedSession(sessionId: string, presence: JsonObject, ttl: number, info: IUserInfo, ctx?: C, defer?: (promise: Promise<void>) => void): void;
|
|
1591
1601
|
/**
|
|
1592
1602
|
* List all server sessions. As a side effect, it will delete expired sessions.
|
|
1593
1603
|
*/
|
|
1594
|
-
listLeasedSessions(ctx?: C, defer?: (promise: Promise<void>) => void):
|
|
1604
|
+
listLeasedSessions(ctx?: C, defer?: (promise: Promise<void>) => void): LeasedSession[];
|
|
1595
1605
|
/**
|
|
1596
1606
|
* Delete a server session and broadcast USER_LEFT to all sessions.
|
|
1597
1607
|
*/
|
|
1598
|
-
deleteLeasedSession(session: LeasedSession, ctx?: C, defer?: (promise: Promise<void>) => void):
|
|
1608
|
+
deleteLeasedSession(session: LeasedSession, ctx?: C, defer?: (promise: Promise<void>) => void): void;
|
|
1599
1609
|
/**
|
|
1600
1610
|
* Delete all server sessions and broadcast USER_LEFT to all sessions.
|
|
1601
1611
|
*/
|
|
1602
|
-
deleteAllLeasedSessions(ctx?: C, defer?: (promise: Promise<void>) => void):
|
|
1612
|
+
deleteAllLeasedSessions(ctx?: C, defer?: (promise: Promise<void>) => void): void;
|
|
1603
1613
|
/**
|
|
1604
1614
|
* List feeds with pagination and filtering.
|
|
1605
1615
|
*/
|
|
1606
|
-
listFeeds(options?: ListFeedsOptions):
|
|
1616
|
+
listFeeds(options?: ListFeedsOptions): ListFeedsResult;
|
|
1607
1617
|
/**
|
|
1608
1618
|
* Get a specific feed by feed ID.
|
|
1609
1619
|
*/
|
|
1610
|
-
getFeed(feedId: string):
|
|
1620
|
+
getFeed(feedId: string): Feed | undefined;
|
|
1611
1621
|
/**
|
|
1612
1622
|
* Create a new feed.
|
|
1613
1623
|
* If timestamp is not provided, current server time is used.
|
|
1614
1624
|
*/
|
|
1615
1625
|
createFeed(feed: Omit<Feed, "createdAt" | "updatedAt"> & {
|
|
1616
1626
|
timestamp?: number;
|
|
1617
|
-
}):
|
|
1627
|
+
}): Feed;
|
|
1618
1628
|
/**
|
|
1619
1629
|
* Update a feed's metadata.
|
|
1620
1630
|
*/
|
|
1621
|
-
updateFeedMetadata(feedId: string, metadata: Json):
|
|
1631
|
+
updateFeedMetadata(feedId: string, metadata: Json): void;
|
|
1622
1632
|
/**
|
|
1623
1633
|
* Delete a feed.
|
|
1624
1634
|
*/
|
|
1625
|
-
deleteFeed(feedId: string):
|
|
1635
|
+
deleteFeed(feedId: string): void;
|
|
1626
1636
|
/**
|
|
1627
1637
|
* List feed messages for a feed with pagination.
|
|
1628
1638
|
*/
|
|
1629
|
-
listFeedMessages(feedId: string, options?: ListFeedMessagesOptions):
|
|
1639
|
+
listFeedMessages(feedId: string, options?: ListFeedMessagesOptions): ListFeedMessagesResult;
|
|
1630
1640
|
/**
|
|
1631
1641
|
* Add a message to a feed.
|
|
1632
1642
|
* If message id is not provided, a unique ID is automatically generated.
|
|
@@ -1634,16 +1644,16 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
|
|
|
1634
1644
|
*/
|
|
1635
1645
|
addFeedMessage(feedId: string, message: Omit<FeedMessage, "id" | "createdAt" | "updatedAt"> & Partial<Pick<FeedMessage, "id">> & {
|
|
1636
1646
|
timestamp?: number;
|
|
1637
|
-
}):
|
|
1647
|
+
}): FeedMessage;
|
|
1638
1648
|
/**
|
|
1639
1649
|
* Update a feed message's data.
|
|
1640
1650
|
* Returns the updated message.
|
|
1641
1651
|
*/
|
|
1642
|
-
updateFeedMessage(feedId: string, messageId: string, data: Json, timestamp?: number):
|
|
1652
|
+
updateFeedMessage(feedId: string, messageId: string, data: Json, timestamp?: number): FeedMessage;
|
|
1643
1653
|
/**
|
|
1644
1654
|
* Delete a feed message.
|
|
1645
1655
|
*/
|
|
1646
|
-
deleteFeedMessage(feedId: string, messageId: string):
|
|
1656
|
+
deleteFeedMessage(feedId: string, messageId: string): void;
|
|
1647
1657
|
/**
|
|
1648
1658
|
* Will send the given ServerMsg through all Session, except the Session
|
|
1649
1659
|
* where the message originates from.
|
|
@@ -1653,13 +1663,10 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
|
|
|
1653
1663
|
* Will broadcast the given ServerMsg to all Sessions in the Room.
|
|
1654
1664
|
*/
|
|
1655
1665
|
sendToAll(serverMsg: ServerMsg | readonly ServerMsg[], ctx?: C, defer?: (promise: Promise<void>) => void): void;
|
|
1656
|
-
private _loadStorage;
|
|
1657
|
-
private _loadYjsStorage;
|
|
1658
|
-
private _load;
|
|
1659
1666
|
/**
|
|
1660
1667
|
* Returns a new, unique, actor ID.
|
|
1661
1668
|
*/
|
|
1662
|
-
|
|
1669
|
+
getNextActor(): ActorID;
|
|
1663
1670
|
/**
|
|
1664
1671
|
* Iterates over all *other* Sessions and their session keys.
|
|
1665
1672
|
*/
|
|
@@ -1716,32 +1723,8 @@ declare function isLeasedSessionExpired(leasedSession: LeasedSession): boolean;
|
|
|
1716
1723
|
* You should have received a copy of the GNU Affero General Public License
|
|
1717
1724
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
1718
1725
|
*/
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
* This pattern avoids having to build deeply nested try / catch clauses, where
|
|
1722
|
-
* success variables need to be defined as a `let` outside of the `try` block.
|
|
1723
|
-
*
|
|
1724
|
-
* Turns:
|
|
1725
|
-
*
|
|
1726
|
-
* let result;
|
|
1727
|
-
* try {
|
|
1728
|
-
* result = await doSomething();
|
|
1729
|
-
* } catch (error) {
|
|
1730
|
-
* // do something with error
|
|
1731
|
-
* }
|
|
1732
|
-
*
|
|
1733
|
-
* doAnotherThing(result);
|
|
1734
|
-
*
|
|
1735
|
-
* Into:
|
|
1736
|
-
*
|
|
1737
|
-
* const [result, error] = await tryCatch(doSomething());
|
|
1738
|
-
* if (error) {
|
|
1739
|
-
* // do something with error
|
|
1740
|
-
* }
|
|
1741
|
-
* doAnotherThing(result);
|
|
1742
|
-
*
|
|
1743
|
-
*/
|
|
1744
|
-
declare function tryCatch<T, E = Error>(promise: Promise<T> | (() => Promise<T>) | (() => T)): Promise<[T, undefined] | [undefined, E]>;
|
|
1726
|
+
declare function tryCatch<T, E = Error>(promise: PromiseLike<T> | (() => PromiseLike<T>)): Promise<[T, undefined] | [undefined, E]>;
|
|
1727
|
+
declare function tryCatch<T, E = Error>(fn: () => T): [T, undefined] | [undefined, E];
|
|
1745
1728
|
|
|
1746
1729
|
/**
|
|
1747
1730
|
* Copyright (c) Liveblocks Inc.
|
|
@@ -1924,6 +1907,7 @@ declare class UniqueMap<K, V, UK> extends Map<K, V> {
|
|
|
1924
1907
|
declare class InMemoryDriver implements IStorageDriver {
|
|
1925
1908
|
private _nextActor;
|
|
1926
1909
|
private _nodes;
|
|
1910
|
+
private _nodesApi?;
|
|
1927
1911
|
private _metadb;
|
|
1928
1912
|
private _ydb;
|
|
1929
1913
|
private _leasedSessions;
|
|
@@ -1934,32 +1918,53 @@ declare class InMemoryDriver implements IStorageDriver {
|
|
|
1934
1918
|
initialNodes?: Iterable<[string, SerializedCrdt]>;
|
|
1935
1919
|
});
|
|
1936
1920
|
raw_iter_nodes(): MapIterator<[string, SerializedCrdt]>;
|
|
1921
|
+
reinitialize(): void;
|
|
1937
1922
|
/** Deletes all nodes and replaces them with the given document. */
|
|
1938
1923
|
DANGEROUSLY_reset_nodes(doc: PlainLsonObject): void;
|
|
1939
|
-
get_meta(key: string):
|
|
1940
|
-
put_meta(key: string, value: Json):
|
|
1941
|
-
delete_meta(key: string):
|
|
1942
|
-
list_leased_sessions():
|
|
1943
|
-
get_leased_session(sessionId: string):
|
|
1944
|
-
put_leased_session(session: LeasedSession):
|
|
1945
|
-
delete_leased_session(sessionId: string):
|
|
1924
|
+
get_meta(key: string): Json | undefined;
|
|
1925
|
+
put_meta(key: string, value: Json): void;
|
|
1926
|
+
delete_meta(key: string): void;
|
|
1927
|
+
list_leased_sessions(): MapIterator<[string, LeasedSession]>;
|
|
1928
|
+
get_leased_session(sessionId: string): LeasedSession | undefined;
|
|
1929
|
+
put_leased_session(session: LeasedSession): void;
|
|
1930
|
+
delete_leased_session(sessionId: string): void;
|
|
1946
1931
|
takeRowsWritten(): number;
|
|
1947
|
-
list_feeds(options?: ListFeedsOptions):
|
|
1948
|
-
get_feed(feedId: string):
|
|
1949
|
-
create_feed(feed: Feed):
|
|
1950
|
-
update_feed_metadata(feedId: string, metadata: Json):
|
|
1951
|
-
delete_feed(feedId: string):
|
|
1952
|
-
list_feed_messages(feedId: string, options?: ListFeedMessagesOptions):
|
|
1953
|
-
add_feed_message(feedId: string, message: FeedMessage):
|
|
1954
|
-
update_feed_message(feedId: string, messageId: string, data: Json, timestamp?: number):
|
|
1955
|
-
delete_feed_message(feedId: string, messageId: string):
|
|
1932
|
+
list_feeds(options?: ListFeedsOptions): ListFeedsResult;
|
|
1933
|
+
get_feed(feedId: string): Feed | undefined;
|
|
1934
|
+
create_feed(feed: Feed): void;
|
|
1935
|
+
update_feed_metadata(feedId: string, metadata: Json): void;
|
|
1936
|
+
delete_feed(feedId: string): void;
|
|
1937
|
+
list_feed_messages(feedId: string, options?: ListFeedMessagesOptions): ListFeedMessagesResult;
|
|
1938
|
+
add_feed_message(feedId: string, message: FeedMessage): void;
|
|
1939
|
+
update_feed_message(feedId: string, messageId: string, data: Json, timestamp?: number): FeedMessage;
|
|
1940
|
+
delete_feed_message(feedId: string, messageId: string): void;
|
|
1956
1941
|
next_actor(): number;
|
|
1957
|
-
iter_y_updates(docId: YDocId):
|
|
1958
|
-
write_y_updates(docId: YDocId, key: string, data: Uint8Array):
|
|
1959
|
-
delete_y_updates(docId: YDocId, keys: string[]):
|
|
1942
|
+
iter_y_updates(docId: YDocId): IterableIterator<[string, Uint8Array<ArrayBufferLike>]>;
|
|
1943
|
+
write_y_updates(docId: YDocId, key: string, data: Uint8Array): void;
|
|
1944
|
+
delete_y_updates(docId: YDocId, keys: string[]): void;
|
|
1960
1945
|
/** @private Only use this in unit tests, never in production. */
|
|
1961
|
-
DANGEROUSLY_wipe_all_y_updates():
|
|
1962
|
-
|
|
1946
|
+
DANGEROUSLY_wipe_all_y_updates(): void;
|
|
1947
|
+
/**
|
|
1948
|
+
* The lazily-built node API. Building it ensures the root node exists and
|
|
1949
|
+
* constructs the reverse-lookup index. Invalidated by
|
|
1950
|
+
* DANGEROUSLY_reset_nodes(), after which the next access rebuilds it.
|
|
1951
|
+
*/
|
|
1952
|
+
private get loadedApi();
|
|
1953
|
+
get_node(id: string): SerializedCrdt | undefined;
|
|
1954
|
+
iter_nodes(): NodeStream$1;
|
|
1955
|
+
iter_nodes_optimized(): Iterable<jstring<CompactNode>>;
|
|
1956
|
+
has_node(id: string): boolean;
|
|
1957
|
+
get_child_at(parentId: string, parentKey: string): string | undefined;
|
|
1958
|
+
has_child_at(parentId: string, parentKey: string): boolean;
|
|
1959
|
+
get_next_sibling(parentId: string, pos: Pos): Pos | undefined;
|
|
1960
|
+
get_last_sibling(parentId: string): Pos | undefined;
|
|
1961
|
+
set_child(id: string, node: SerializedChild, allowOverwrite?: boolean): void;
|
|
1962
|
+
move_sibling(id: string, newPos: Pos): void;
|
|
1963
|
+
delete_node(id: string): void;
|
|
1964
|
+
delete_child_key(id: string, key: string): void;
|
|
1965
|
+
set_object_data(id: string, data: JsonObject, allowOverwrite?: boolean): void;
|
|
1966
|
+
get_snapshot(lowMemory?: boolean): IReadableSnapshot;
|
|
1967
|
+
private _loadNodesApi;
|
|
1963
1968
|
}
|
|
1964
1969
|
|
|
1965
|
-
export { type ActorID, type AddFeedClientMsg, type AddFeedMessageClientMsg, BackendSession, BrowserSession, ConsoleTarget, type CreateTicketOptions, DefaultMap, type DeleteFeedClientMsg, type DeleteFeedMessageClientMsg, type Feed, type FeedDeletedServerMsg, type FeedMessage, type FeedMessagesAddedServerMsg, type FeedMessagesDeletedServerMsg, type FeedMessagesListServerMsg, type FeedMessagesServerMsg, type FeedMessagesUpdatedServerMsg, FeedMsgCode, FeedRequestErrorCode, type FeedRequestFailedServerMsg, type FeedsAddedServerMsg, type FeedsListServerMsg, type FeedsServerMsg, type FeedsUpdatedServerMsg, type FetchFeedMessagesClientMsg, type FetchFeedsClientMsg, type FixOp, type Guid, type IReadableSnapshot, type IServerWebSocket, type IStorageDriver, type
|
|
1970
|
+
export { type ActorID, type AddFeedClientMsg, type AddFeedMessageClientMsg, BackendSession, BrowserSession, ConsoleTarget, type CreateTicketOptions, DefaultMap, type DeleteFeedClientMsg, type DeleteFeedMessageClientMsg, type Feed, type FeedDeletedServerMsg, type FeedMessage, type FeedMessagesAddedServerMsg, type FeedMessagesDeletedServerMsg, type FeedMessagesListServerMsg, type FeedMessagesServerMsg, type FeedMessagesUpdatedServerMsg, FeedMsgCode, FeedRequestErrorCode, type FeedRequestFailedServerMsg, type FeedsAddedServerMsg, type FeedsListServerMsg, type FeedsServerMsg, type FeedsUpdatedServerMsg, type FetchFeedMessagesClientMsg, type FetchFeedsClientMsg, type FixOp, type Guid, type IReadableSnapshot, type IServerWebSocket, type IStorageDriver, type IUserData, InMemoryDriver, type LeasedSession, type ListFeedMessagesOptions, type ListFeedMessagesResult, type ListFeedsOptions, type ListFeedsResult, LogLevel, LogTarget, Logger, type MetadataDB, type Millis, NestedMap, type NodeMap, type NodeStream, type NodeTuple, type Pos, ProtocolVersion, ROOT_YDOC_ID, Room, type SessionKey, type Ticket, UniqueMap, type UpdateFeedClientMsg, type UpdateFeedMessageClientMsg, type YDocId, type YUpdate, type YVector, ackIgnoredOp, clientMsgDecoder, concatUint8Arrays, feedFailureServerMsg, feedMetadataIdDecoder, feedMetadataUpdateDecoder, feedRequestFailed, fetchFeedsMetadataFilterDecoder, guidDecoder, isLeasedSessionExpired, jsonObjectYolo, jsonYolo, type jstring, makeInMemorySnapshot, makeMetadataDB, mapFeedError, optionalFeedMetadataDecoder, plainLsonToNodeStream, protocolVersionDecoder, quote, serialize as serializeServerMsg, snapshotToLossyJson_eager, snapshotToLossyJson_lazy, snapshotToNodeStream, snapshotToPlainLson_eager, snapshotToPlainLson_lazy, Storage as test_only__Storage, YjsStorage as test_only__YjsStorage, transientClientMsgDecoder, tryCatch };
|