@liveblocks/core 1.8.1 → 1.8.3-oss1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -96,6 +96,25 @@ declare type AckOp = {
96
96
  readonly id: "ACK";
97
97
  readonly opId: string;
98
98
  };
99
+ /**
100
+ * Create an Op that can be used as an acknowledgement for the given opId, to
101
+ * send back to the originating client in cases where the server decided to
102
+ * ignore the Op and not forward it.
103
+ *
104
+ * Why?
105
+ * It's important for the client to receive an acknowledgement for this, so
106
+ * that it can correctly update its own unacknowledged Ops administration.
107
+ * Otherwise it could get in "synchronizing" state indefinitely.
108
+ *
109
+ * CLEVER HACK
110
+ * Introducing a new Op type for this would not be backward-compatible as
111
+ * receiving such Op would crash old clients :(
112
+ * So the clever backward-compatible hack pulled here is that we codify the
113
+ * acknowledgement as a "deletion Op" for the non-existing node id "ACK". In
114
+ * old clients such Op is accepted, but will effectively be a no-op as that
115
+ * node does not exist, but as a side-effect the Op will get acknowledged.
116
+ */
117
+ declare function ackOp(opId: string): AckOp;
99
118
  declare type SetParentKeyOp = {
100
119
  readonly opId?: string;
101
120
  readonly id: string;
@@ -686,13 +705,16 @@ declare type CommentBody = {
686
705
  content: CommentBodyBlockElement[];
687
706
  };
688
707
 
689
- declare type CommentReactionUser = {
690
- id: string;
708
+ declare type DateToString<T> = {
709
+ [P in keyof T]: T[P] extends Date ? string : T[P];
691
710
  };
711
+
692
712
  declare type CommentReaction = {
693
713
  emoji: string;
694
- createdAt: string;
695
- users: CommentReactionUser[];
714
+ createdAt: Date;
715
+ users: {
716
+ id: string;
717
+ }[];
696
718
  };
697
719
  /**
698
720
  * Represents a comment.
@@ -703,17 +725,33 @@ declare type CommentData = {
703
725
  threadId: string;
704
726
  roomId: string;
705
727
  userId: string;
706
- createdAt: string;
707
- editedAt?: string;
728
+ createdAt: Date;
729
+ editedAt?: Date;
708
730
  reactions: CommentReaction[];
709
731
  } & ({
710
732
  body: CommentBody;
711
733
  deletedAt?: never;
734
+ } | {
735
+ body?: never;
736
+ deletedAt: Date;
737
+ });
738
+ declare type CommentDataPlain = Omit<DateToString<CommentData>, "reaction" | "body"> & {
739
+ reactions: DateToString<CommentReaction[]>;
740
+ } & ({
741
+ body: CommentBody;
742
+ deletedAt?: never;
712
743
  } | {
713
744
  body?: never;
714
745
  deletedAt: string;
715
746
  });
716
747
 
748
+ declare type CommentUserReaction = {
749
+ emoji: string;
750
+ createdAt: Date;
751
+ userId: string;
752
+ };
753
+ declare type CommentUserReactionPlain = DateToString<CommentUserReaction>;
754
+
717
755
  /**
718
756
  * Represents a thread of comments.
719
757
  */
@@ -721,11 +759,15 @@ declare type ThreadData<TThreadMetadata extends BaseMetadata = never> = {
721
759
  type: "thread";
722
760
  id: string;
723
761
  roomId: string;
724
- createdAt: string;
725
- updatedAt?: string;
762
+ createdAt: Date;
763
+ updatedAt?: Date;
726
764
  comments: CommentData[];
727
765
  metadata: [TThreadMetadata] extends [never] ? Record<string, never> : TThreadMetadata;
728
766
  };
767
+ declare type ThreadDataPlain<TThreadMetadata extends BaseMetadata = never> = Omit<DateToString<ThreadData<TThreadMetadata>>, "comments" | "metadata"> & {
768
+ comments: CommentDataPlain[];
769
+ metadata: [TThreadMetadata] extends [never] ? Record<string, never> : TThreadMetadata;
770
+ };
729
771
 
730
772
  declare type Options = {
731
773
  baseUrl: string;
@@ -744,7 +786,7 @@ declare type CommentsApi<TThreadMetadata extends BaseMetadata> = {
744
786
  editThreadMetadata(options: {
745
787
  metadata: PartialNullable<TThreadMetadata>;
746
788
  threadId: string;
747
- }): Promise<ThreadData<TThreadMetadata>>;
789
+ }): Promise<TThreadMetadata>;
748
790
  createComment(options: {
749
791
  threadId: string;
750
792
  commentId: string;
@@ -763,12 +805,12 @@ declare type CommentsApi<TThreadMetadata extends BaseMetadata> = {
763
805
  threadId: string;
764
806
  commentId: string;
765
807
  emoji: string;
766
- }): Promise<CommentData>;
808
+ }): Promise<CommentUserReaction>;
767
809
  removeReaction(options: {
768
810
  threadId: string;
769
811
  commentId: string;
770
812
  emoji: string;
771
- }): Promise<CommentData>;
813
+ }): Promise<void>;
772
814
  };
773
815
  declare class CommentsApiError extends Error {
774
816
  message: string;
@@ -2007,8 +2049,8 @@ declare function assert(condition: boolean, errmsg: string): asserts condition;
2007
2049
  */
2008
2050
  declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
2009
2051
 
2010
- declare type PromiseOrNot<T> = T | Promise<T>;
2011
- declare type AsyncCacheFunction<T, A extends any[] = any[]> = (...args: A) => PromiseOrNot<T>;
2052
+ declare type PromiseOrNot$1<T> = T | Promise<T>;
2053
+ declare type AsyncCacheFunction<T, A extends any[] = any[]> = (...args: A) => PromiseOrNot$1<T>;
2012
2054
  declare type AsyncCacheOptions<T, E> = {
2013
2055
  isStateEqual?: (a: AsyncState<T, E>, b: AsyncState<T, E>) => boolean;
2014
2056
  };
@@ -2130,12 +2172,7 @@ declare const fancyConsole_errorWithTitle: typeof errorWithTitle;
2130
2172
  declare const fancyConsole_warn: typeof warn;
2131
2173
  declare const fancyConsole_warnWithTitle: typeof warnWithTitle;
2132
2174
  declare namespace fancyConsole {
2133
- export {
2134
- fancyConsole_error as error,
2135
- fancyConsole_errorWithTitle as errorWithTitle,
2136
- fancyConsole_warn as warn,
2137
- fancyConsole_warnWithTitle as warnWithTitle,
2138
- };
2175
+ export { fancyConsole_error as error, fancyConsole_errorWithTitle as errorWithTitle, fancyConsole_warn as warn, fancyConsole_warnWithTitle as warnWithTitle };
2139
2176
  }
2140
2177
 
2141
2178
  /**
@@ -2300,14 +2337,7 @@ type DevToolsTreeNode_LsonTreeNode = LsonTreeNode;
2300
2337
  type DevToolsTreeNode_TreeNode = TreeNode;
2301
2338
  type DevToolsTreeNode_UserTreeNode = UserTreeNode;
2302
2339
  declare namespace DevToolsTreeNode {
2303
- export {
2304
- DevToolsTreeNode_CustomEventTreeNode as CustomEventTreeNode,
2305
- DevToolsTreeNode_JsonTreeNode as JsonTreeNode,
2306
- DevToolsTreeNode_LiveTreeNode as LiveTreeNode,
2307
- DevToolsTreeNode_LsonTreeNode as LsonTreeNode,
2308
- DevToolsTreeNode_TreeNode as TreeNode,
2309
- DevToolsTreeNode_UserTreeNode as UserTreeNode,
2310
- };
2340
+ export type { DevToolsTreeNode_CustomEventTreeNode as CustomEventTreeNode, DevToolsTreeNode_JsonTreeNode as JsonTreeNode, DevToolsTreeNode_LiveTreeNode as LiveTreeNode, DevToolsTreeNode_LsonTreeNode as LsonTreeNode, DevToolsTreeNode_TreeNode as TreeNode, DevToolsTreeNode_UserTreeNode as UserTreeNode };
2311
2341
  }
2312
2342
 
2313
2343
  /**
@@ -2427,14 +2457,120 @@ type protocol_FullClientToPanelMessage = FullClientToPanelMessage;
2427
2457
  type protocol_FullPanelToClientMessage = FullPanelToClientMessage;
2428
2458
  type protocol_PanelToClientMessage = PanelToClientMessage;
2429
2459
  declare namespace protocol {
2430
- export {
2431
- protocol_ClientToPanelMessage as ClientToPanelMessage,
2432
- protocol_FullClientToPanelMessage as FullClientToPanelMessage,
2433
- protocol_FullPanelToClientMessage as FullPanelToClientMessage,
2434
- protocol_PanelToClientMessage as PanelToClientMessage,
2435
- };
2460
+ export type { protocol_ClientToPanelMessage as ClientToPanelMessage, protocol_FullClientToPanelMessage as FullClientToPanelMessage, protocol_FullPanelToClientMessage as FullPanelToClientMessage, protocol_PanelToClientMessage as PanelToClientMessage };
2436
2461
  }
2437
2462
 
2463
+ declare type PromiseOrNot<T> = T | Promise<T>;
2464
+ declare type CommentBodyResolveUsersArgs = {
2465
+ /**
2466
+ * The ID of the users to resolve.
2467
+ */
2468
+ userIds: string[];
2469
+ };
2470
+ declare type CommentBodyParagraphElementArgs = {
2471
+ /**
2472
+ * The paragraph element.
2473
+ */
2474
+ element: CommentBodyParagraph;
2475
+ /**
2476
+ * The text content of the paragraph.
2477
+ */
2478
+ children: string;
2479
+ };
2480
+ declare type CommentBodyTextElementArgs = {
2481
+ /**
2482
+ * The text element.
2483
+ */
2484
+ element: CommentBodyText;
2485
+ };
2486
+ declare type CommentBodyLinkElementArgs = {
2487
+ /**
2488
+ * The link element.
2489
+ */
2490
+ element: CommentBodyLink;
2491
+ /**
2492
+ * The absolute URL of the link.
2493
+ */
2494
+ href: string;
2495
+ };
2496
+ declare type CommentBodyMentionElementArgs<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
2497
+ /**
2498
+ * The mention element.
2499
+ */
2500
+ element: CommentBodyMention;
2501
+ /**
2502
+ * The mention's user info, if the `resolvedUsers` option was provided.
2503
+ */
2504
+ user?: TUserMeta["info"];
2505
+ };
2506
+ declare type StringifyCommentBodyElements<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
2507
+ /**
2508
+ * The element used to display paragraphs.
2509
+ */
2510
+ paragraph: (args: CommentBodyParagraphElementArgs, index: number) => string;
2511
+ /**
2512
+ * The element used to display text elements.
2513
+ */
2514
+ text: (args: CommentBodyTextElementArgs, index: number) => string;
2515
+ /**
2516
+ * The element used to display links.
2517
+ */
2518
+ link: (args: CommentBodyLinkElementArgs, index: number) => string;
2519
+ /**
2520
+ * The element used to display mentions.
2521
+ */
2522
+ mention: (args: CommentBodyMentionElementArgs<TUserMeta>, index: number) => string;
2523
+ };
2524
+ declare type StringifyCommentBodyOptions<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
2525
+ /**
2526
+ * Which format to convert the comment to.
2527
+ */
2528
+ format?: "plain" | "html" | "markdown";
2529
+ /**
2530
+ * The elements used to customize the resulting string. Each element has
2531
+ * priority over the defaults inherited from the `format` option.
2532
+ */
2533
+ elements?: Partial<StringifyCommentBodyElements<TUserMeta>>;
2534
+ /**
2535
+ * The separator used between paragraphs.
2536
+ */
2537
+ separator?: string;
2538
+ /**
2539
+ * A function that returns user info from user IDs.
2540
+ */
2541
+ resolveUsers?: (args: CommentBodyResolveUsersArgs) => PromiseOrNot<(TUserMeta["info"] | undefined)[] | undefined>;
2542
+ };
2543
+ /**
2544
+ * Get an array of each user's ID that has been mentioned in a `CommentBody`.
2545
+ */
2546
+ declare function getMentionedIdsFromCommentBody(body: CommentBody): string[];
2547
+ /**
2548
+ * Convert a `CommentBody` into either a plain string,
2549
+ * Markdown, HTML, or a custom format.
2550
+ */
2551
+ declare function stringifyCommentBody<TUserMeta extends BaseUserMeta = BaseUserMeta>(body: CommentBody, options?: StringifyCommentBodyOptions<TUserMeta>): Promise<string>;
2552
+ /**
2553
+ * Converts a plain comment data object (usually returned by the API) to a comment data object that can be used by the client.
2554
+ * This is necessary because the plain data object stores dates as ISO strings, but the client expects them as Date objects.
2555
+ * @param data The plain comment data object (usually returned by the API)
2556
+ * @returns The rich comment data object that can be used by the client.
2557
+ */
2558
+ declare function convertToCommentData(data: CommentDataPlain): CommentData;
2559
+ /**
2560
+ * Converts a plain thread data object (usually returned by the API) to a thread data object that can be used by the client.
2561
+ * This is necessary because the plain data object stores dates as ISO strings, but the client expects them as Date objects.
2562
+ * @param data The plain thread data object (usually returned by the API)
2563
+ * @returns The rich hread data object that can be used by the client.
2564
+ */
2565
+ declare function convertToThreadData<TThreadMetadata extends BaseMetadata = never>(data: ThreadDataPlain<TThreadMetadata>): ThreadData<TThreadMetadata>;
2566
+ /**
2567
+ * Converts a plain comment reaction object (usually returned by the API) to a comment reaction object that can be used by the client.
2568
+ * This is necessary because the plain data object stores dates as ISO strings, but the client expects them as Date objects.
2569
+ * @param data The plain comment reaction object (usually returned by the API)
2570
+ * @returns The rich comment reaction object that can be used by the client.
2571
+ */
2572
+ declare function convertToCommentUserReaction(data: CommentUserReactionPlain): CommentUserReaction;
2573
+
2438
2574
  /**
2439
2575
  * Helper type to help users adopt to Lson types from interface definitions.
2440
2576
  * You should only use this to wrap interfaces you don't control. For more
@@ -2447,4 +2583,4 @@ declare type EnsureJson<T> = [
2447
2583
  [K in keyof T]: EnsureJson<T[K]>;
2448
2584
  };
2449
2585
 
2450
- export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, Brand, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentBodyText, CommentData, CommentReaction, CommentsApi, CommentsApiError, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EnterOptions, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IUserInfo, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, OthersEvent, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, raise, shallow, stringify, throwUsageError, toPlainLson, tryParseJson, withTimeout };
2586
+ export { type AckOp, type AsyncCache, type AsyncState, type AsyncStateError, type AsyncStateInitial, type AsyncStateLoading, type AsyncStateResolved, type AsyncStateSuccess, type BaseAuthResult, type BaseMetadata, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type Client, type ClientMsg, ClientMsgCode, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyResolveUsersArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, type CommentsApi, CommentsApiError, CrdtType, type CreateListOp, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type CustomAuthenticationResult, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type EnsureJson, type EnterOptions, type EventSource, type FetchStorageClientMsg, type FetchYDocClientMsg, type History, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IdTuple, type Immutable, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type LegacyConnectionStatus, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, type LostConnectionEvent, type Lson, type LsonObject, type NodeMap, type Op, OpCode, type Others, type OthersEvent, type ParentToChildNodeMap, type PlainLson, type PlainLsonFields, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type RejectedStorageOpServerMsg, type Resolve, type Room, type RoomEventMessage, type RoomInitializers, type RoomStateServerMsg, type SerializedChild, type SerializedCrdt, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type SetParentKeyOp, type Status, type StorageStatus, type StorageUpdate, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type ThreadData, type ThreadDataPlain, type ToImmutable, type ToJson, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type User, type UserJoinServerMsg, type UserLeftServerMsg, WebsocketCloseCodes, type YDocUpdateServerMsg, ackOp, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToThreadData, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, getMentionedIdsFromCommentBody, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, raise, shallow, stringify, stringifyCommentBody, throwUsageError, toPlainLson, tryParseJson, withTimeout };
package/dist/index.d.ts CHANGED
@@ -96,6 +96,25 @@ declare type AckOp = {
96
96
  readonly id: "ACK";
97
97
  readonly opId: string;
98
98
  };
99
+ /**
100
+ * Create an Op that can be used as an acknowledgement for the given opId, to
101
+ * send back to the originating client in cases where the server decided to
102
+ * ignore the Op and not forward it.
103
+ *
104
+ * Why?
105
+ * It's important for the client to receive an acknowledgement for this, so
106
+ * that it can correctly update its own unacknowledged Ops administration.
107
+ * Otherwise it could get in "synchronizing" state indefinitely.
108
+ *
109
+ * CLEVER HACK
110
+ * Introducing a new Op type for this would not be backward-compatible as
111
+ * receiving such Op would crash old clients :(
112
+ * So the clever backward-compatible hack pulled here is that we codify the
113
+ * acknowledgement as a "deletion Op" for the non-existing node id "ACK". In
114
+ * old clients such Op is accepted, but will effectively be a no-op as that
115
+ * node does not exist, but as a side-effect the Op will get acknowledged.
116
+ */
117
+ declare function ackOp(opId: string): AckOp;
99
118
  declare type SetParentKeyOp = {
100
119
  readonly opId?: string;
101
120
  readonly id: string;
@@ -686,13 +705,16 @@ declare type CommentBody = {
686
705
  content: CommentBodyBlockElement[];
687
706
  };
688
707
 
689
- declare type CommentReactionUser = {
690
- id: string;
708
+ declare type DateToString<T> = {
709
+ [P in keyof T]: T[P] extends Date ? string : T[P];
691
710
  };
711
+
692
712
  declare type CommentReaction = {
693
713
  emoji: string;
694
- createdAt: string;
695
- users: CommentReactionUser[];
714
+ createdAt: Date;
715
+ users: {
716
+ id: string;
717
+ }[];
696
718
  };
697
719
  /**
698
720
  * Represents a comment.
@@ -703,17 +725,33 @@ declare type CommentData = {
703
725
  threadId: string;
704
726
  roomId: string;
705
727
  userId: string;
706
- createdAt: string;
707
- editedAt?: string;
728
+ createdAt: Date;
729
+ editedAt?: Date;
708
730
  reactions: CommentReaction[];
709
731
  } & ({
710
732
  body: CommentBody;
711
733
  deletedAt?: never;
734
+ } | {
735
+ body?: never;
736
+ deletedAt: Date;
737
+ });
738
+ declare type CommentDataPlain = Omit<DateToString<CommentData>, "reaction" | "body"> & {
739
+ reactions: DateToString<CommentReaction[]>;
740
+ } & ({
741
+ body: CommentBody;
742
+ deletedAt?: never;
712
743
  } | {
713
744
  body?: never;
714
745
  deletedAt: string;
715
746
  });
716
747
 
748
+ declare type CommentUserReaction = {
749
+ emoji: string;
750
+ createdAt: Date;
751
+ userId: string;
752
+ };
753
+ declare type CommentUserReactionPlain = DateToString<CommentUserReaction>;
754
+
717
755
  /**
718
756
  * Represents a thread of comments.
719
757
  */
@@ -721,11 +759,15 @@ declare type ThreadData<TThreadMetadata extends BaseMetadata = never> = {
721
759
  type: "thread";
722
760
  id: string;
723
761
  roomId: string;
724
- createdAt: string;
725
- updatedAt?: string;
762
+ createdAt: Date;
763
+ updatedAt?: Date;
726
764
  comments: CommentData[];
727
765
  metadata: [TThreadMetadata] extends [never] ? Record<string, never> : TThreadMetadata;
728
766
  };
767
+ declare type ThreadDataPlain<TThreadMetadata extends BaseMetadata = never> = Omit<DateToString<ThreadData<TThreadMetadata>>, "comments" | "metadata"> & {
768
+ comments: CommentDataPlain[];
769
+ metadata: [TThreadMetadata] extends [never] ? Record<string, never> : TThreadMetadata;
770
+ };
729
771
 
730
772
  declare type Options = {
731
773
  baseUrl: string;
@@ -744,7 +786,7 @@ declare type CommentsApi<TThreadMetadata extends BaseMetadata> = {
744
786
  editThreadMetadata(options: {
745
787
  metadata: PartialNullable<TThreadMetadata>;
746
788
  threadId: string;
747
- }): Promise<ThreadData<TThreadMetadata>>;
789
+ }): Promise<TThreadMetadata>;
748
790
  createComment(options: {
749
791
  threadId: string;
750
792
  commentId: string;
@@ -763,12 +805,12 @@ declare type CommentsApi<TThreadMetadata extends BaseMetadata> = {
763
805
  threadId: string;
764
806
  commentId: string;
765
807
  emoji: string;
766
- }): Promise<CommentData>;
808
+ }): Promise<CommentUserReaction>;
767
809
  removeReaction(options: {
768
810
  threadId: string;
769
811
  commentId: string;
770
812
  emoji: string;
771
- }): Promise<CommentData>;
813
+ }): Promise<void>;
772
814
  };
773
815
  declare class CommentsApiError extends Error {
774
816
  message: string;
@@ -2007,8 +2049,8 @@ declare function assert(condition: boolean, errmsg: string): asserts condition;
2007
2049
  */
2008
2050
  declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
2009
2051
 
2010
- declare type PromiseOrNot<T> = T | Promise<T>;
2011
- declare type AsyncCacheFunction<T, A extends any[] = any[]> = (...args: A) => PromiseOrNot<T>;
2052
+ declare type PromiseOrNot$1<T> = T | Promise<T>;
2053
+ declare type AsyncCacheFunction<T, A extends any[] = any[]> = (...args: A) => PromiseOrNot$1<T>;
2012
2054
  declare type AsyncCacheOptions<T, E> = {
2013
2055
  isStateEqual?: (a: AsyncState<T, E>, b: AsyncState<T, E>) => boolean;
2014
2056
  };
@@ -2130,12 +2172,7 @@ declare const fancyConsole_errorWithTitle: typeof errorWithTitle;
2130
2172
  declare const fancyConsole_warn: typeof warn;
2131
2173
  declare const fancyConsole_warnWithTitle: typeof warnWithTitle;
2132
2174
  declare namespace fancyConsole {
2133
- export {
2134
- fancyConsole_error as error,
2135
- fancyConsole_errorWithTitle as errorWithTitle,
2136
- fancyConsole_warn as warn,
2137
- fancyConsole_warnWithTitle as warnWithTitle,
2138
- };
2175
+ export { fancyConsole_error as error, fancyConsole_errorWithTitle as errorWithTitle, fancyConsole_warn as warn, fancyConsole_warnWithTitle as warnWithTitle };
2139
2176
  }
2140
2177
 
2141
2178
  /**
@@ -2300,14 +2337,7 @@ type DevToolsTreeNode_LsonTreeNode = LsonTreeNode;
2300
2337
  type DevToolsTreeNode_TreeNode = TreeNode;
2301
2338
  type DevToolsTreeNode_UserTreeNode = UserTreeNode;
2302
2339
  declare namespace DevToolsTreeNode {
2303
- export {
2304
- DevToolsTreeNode_CustomEventTreeNode as CustomEventTreeNode,
2305
- DevToolsTreeNode_JsonTreeNode as JsonTreeNode,
2306
- DevToolsTreeNode_LiveTreeNode as LiveTreeNode,
2307
- DevToolsTreeNode_LsonTreeNode as LsonTreeNode,
2308
- DevToolsTreeNode_TreeNode as TreeNode,
2309
- DevToolsTreeNode_UserTreeNode as UserTreeNode,
2310
- };
2340
+ export type { DevToolsTreeNode_CustomEventTreeNode as CustomEventTreeNode, DevToolsTreeNode_JsonTreeNode as JsonTreeNode, DevToolsTreeNode_LiveTreeNode as LiveTreeNode, DevToolsTreeNode_LsonTreeNode as LsonTreeNode, DevToolsTreeNode_TreeNode as TreeNode, DevToolsTreeNode_UserTreeNode as UserTreeNode };
2311
2341
  }
2312
2342
 
2313
2343
  /**
@@ -2427,14 +2457,120 @@ type protocol_FullClientToPanelMessage = FullClientToPanelMessage;
2427
2457
  type protocol_FullPanelToClientMessage = FullPanelToClientMessage;
2428
2458
  type protocol_PanelToClientMessage = PanelToClientMessage;
2429
2459
  declare namespace protocol {
2430
- export {
2431
- protocol_ClientToPanelMessage as ClientToPanelMessage,
2432
- protocol_FullClientToPanelMessage as FullClientToPanelMessage,
2433
- protocol_FullPanelToClientMessage as FullPanelToClientMessage,
2434
- protocol_PanelToClientMessage as PanelToClientMessage,
2435
- };
2460
+ export type { protocol_ClientToPanelMessage as ClientToPanelMessage, protocol_FullClientToPanelMessage as FullClientToPanelMessage, protocol_FullPanelToClientMessage as FullPanelToClientMessage, protocol_PanelToClientMessage as PanelToClientMessage };
2436
2461
  }
2437
2462
 
2463
+ declare type PromiseOrNot<T> = T | Promise<T>;
2464
+ declare type CommentBodyResolveUsersArgs = {
2465
+ /**
2466
+ * The ID of the users to resolve.
2467
+ */
2468
+ userIds: string[];
2469
+ };
2470
+ declare type CommentBodyParagraphElementArgs = {
2471
+ /**
2472
+ * The paragraph element.
2473
+ */
2474
+ element: CommentBodyParagraph;
2475
+ /**
2476
+ * The text content of the paragraph.
2477
+ */
2478
+ children: string;
2479
+ };
2480
+ declare type CommentBodyTextElementArgs = {
2481
+ /**
2482
+ * The text element.
2483
+ */
2484
+ element: CommentBodyText;
2485
+ };
2486
+ declare type CommentBodyLinkElementArgs = {
2487
+ /**
2488
+ * The link element.
2489
+ */
2490
+ element: CommentBodyLink;
2491
+ /**
2492
+ * The absolute URL of the link.
2493
+ */
2494
+ href: string;
2495
+ };
2496
+ declare type CommentBodyMentionElementArgs<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
2497
+ /**
2498
+ * The mention element.
2499
+ */
2500
+ element: CommentBodyMention;
2501
+ /**
2502
+ * The mention's user info, if the `resolvedUsers` option was provided.
2503
+ */
2504
+ user?: TUserMeta["info"];
2505
+ };
2506
+ declare type StringifyCommentBodyElements<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
2507
+ /**
2508
+ * The element used to display paragraphs.
2509
+ */
2510
+ paragraph: (args: CommentBodyParagraphElementArgs, index: number) => string;
2511
+ /**
2512
+ * The element used to display text elements.
2513
+ */
2514
+ text: (args: CommentBodyTextElementArgs, index: number) => string;
2515
+ /**
2516
+ * The element used to display links.
2517
+ */
2518
+ link: (args: CommentBodyLinkElementArgs, index: number) => string;
2519
+ /**
2520
+ * The element used to display mentions.
2521
+ */
2522
+ mention: (args: CommentBodyMentionElementArgs<TUserMeta>, index: number) => string;
2523
+ };
2524
+ declare type StringifyCommentBodyOptions<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
2525
+ /**
2526
+ * Which format to convert the comment to.
2527
+ */
2528
+ format?: "plain" | "html" | "markdown";
2529
+ /**
2530
+ * The elements used to customize the resulting string. Each element has
2531
+ * priority over the defaults inherited from the `format` option.
2532
+ */
2533
+ elements?: Partial<StringifyCommentBodyElements<TUserMeta>>;
2534
+ /**
2535
+ * The separator used between paragraphs.
2536
+ */
2537
+ separator?: string;
2538
+ /**
2539
+ * A function that returns user info from user IDs.
2540
+ */
2541
+ resolveUsers?: (args: CommentBodyResolveUsersArgs) => PromiseOrNot<(TUserMeta["info"] | undefined)[] | undefined>;
2542
+ };
2543
+ /**
2544
+ * Get an array of each user's ID that has been mentioned in a `CommentBody`.
2545
+ */
2546
+ declare function getMentionedIdsFromCommentBody(body: CommentBody): string[];
2547
+ /**
2548
+ * Convert a `CommentBody` into either a plain string,
2549
+ * Markdown, HTML, or a custom format.
2550
+ */
2551
+ declare function stringifyCommentBody<TUserMeta extends BaseUserMeta = BaseUserMeta>(body: CommentBody, options?: StringifyCommentBodyOptions<TUserMeta>): Promise<string>;
2552
+ /**
2553
+ * Converts a plain comment data object (usually returned by the API) to a comment data object that can be used by the client.
2554
+ * This is necessary because the plain data object stores dates as ISO strings, but the client expects them as Date objects.
2555
+ * @param data The plain comment data object (usually returned by the API)
2556
+ * @returns The rich comment data object that can be used by the client.
2557
+ */
2558
+ declare function convertToCommentData(data: CommentDataPlain): CommentData;
2559
+ /**
2560
+ * Converts a plain thread data object (usually returned by the API) to a thread data object that can be used by the client.
2561
+ * This is necessary because the plain data object stores dates as ISO strings, but the client expects them as Date objects.
2562
+ * @param data The plain thread data object (usually returned by the API)
2563
+ * @returns The rich hread data object that can be used by the client.
2564
+ */
2565
+ declare function convertToThreadData<TThreadMetadata extends BaseMetadata = never>(data: ThreadDataPlain<TThreadMetadata>): ThreadData<TThreadMetadata>;
2566
+ /**
2567
+ * Converts a plain comment reaction object (usually returned by the API) to a comment reaction object that can be used by the client.
2568
+ * This is necessary because the plain data object stores dates as ISO strings, but the client expects them as Date objects.
2569
+ * @param data The plain comment reaction object (usually returned by the API)
2570
+ * @returns The rich comment reaction object that can be used by the client.
2571
+ */
2572
+ declare function convertToCommentUserReaction(data: CommentUserReactionPlain): CommentUserReaction;
2573
+
2438
2574
  /**
2439
2575
  * Helper type to help users adopt to Lson types from interface definitions.
2440
2576
  * You should only use this to wrap interfaces you don't control. For more
@@ -2447,4 +2583,4 @@ declare type EnsureJson<T> = [
2447
2583
  [K in keyof T]: EnsureJson<T[K]>;
2448
2584
  };
2449
2585
 
2450
- export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, Brand, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentBodyText, CommentData, CommentReaction, CommentsApi, CommentsApiError, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EnterOptions, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IUserInfo, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, OthersEvent, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, raise, shallow, stringify, throwUsageError, toPlainLson, tryParseJson, withTimeout };
2586
+ export { type AckOp, type AsyncCache, type AsyncState, type AsyncStateError, type AsyncStateInitial, type AsyncStateLoading, type AsyncStateResolved, type AsyncStateSuccess, type BaseAuthResult, type BaseMetadata, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type Client, type ClientMsg, ClientMsgCode, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyResolveUsersArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, type CommentsApi, CommentsApiError, CrdtType, type CreateListOp, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type CustomAuthenticationResult, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type EnsureJson, type EnterOptions, type EventSource, type FetchStorageClientMsg, type FetchYDocClientMsg, type History, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IdTuple, type Immutable, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type LegacyConnectionStatus, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, type LostConnectionEvent, type Lson, type LsonObject, type NodeMap, type Op, OpCode, type Others, type OthersEvent, type ParentToChildNodeMap, type PlainLson, type PlainLsonFields, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type RejectedStorageOpServerMsg, type Resolve, type Room, type RoomEventMessage, type RoomInitializers, type RoomStateServerMsg, type SerializedChild, type SerializedCrdt, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type SetParentKeyOp, type Status, type StorageStatus, type StorageUpdate, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type ThreadData, type ThreadDataPlain, type ToImmutable, type ToJson, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type User, type UserJoinServerMsg, type UserLeftServerMsg, WebsocketCloseCodes, type YDocUpdateServerMsg, ackOp, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToThreadData, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, getMentionedIdsFromCommentBody, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, raise, shallow, stringify, stringifyCommentBody, throwUsageError, toPlainLson, tryParseJson, withTimeout };