@yorkie-js/sdk 0.6.41-rc → 0.6.41-rc3

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.
@@ -2328,8 +2328,10 @@ declare const _default: {
2328
2328
  Text: typeof Text_2;
2329
2329
  Counter: typeof Counter;
2330
2330
  Tree: typeof Tree;
2331
+ Devtools: typeof Devtools;
2331
2332
  Channel: typeof Channel;
2332
2333
  ChannelEventType: typeof ChannelEventType;
2334
+ YSON: typeof YSON;
2333
2335
  LogLevel: typeof LogLevel;
2334
2336
  setLogLevel: typeof setLogLevel;
2335
2337
  IntType: CounterType;
@@ -3498,6 +3500,42 @@ declare interface InitializedEvent_2<P extends Indexable_2> extends BaseDocEvent
3498
3500
  value: Array<{ clientID: ActorID_2; presence: P }>;
3499
3501
  }
3500
3502
 
3503
+ /**
3504
+ * `isBinData` checks if a value is a YSONBinData object.
3505
+ */
3506
+ declare function isBinData(value: any): value is YSONBinData {
3507
+ return (
3508
+ typeof value === 'object' &&
3509
+ value !== null &&
3510
+ value.type === 'BinData' &&
3511
+ typeof value.value === 'string'
3512
+ );
3513
+ }
3514
+
3515
+ /**
3516
+ * `isCounter` checks if a value is a YSONCounter object.
3517
+ */
3518
+ declare function isCounter(value: any): value is YSONCounter {
3519
+ return (
3520
+ typeof value === 'object' &&
3521
+ value !== null &&
3522
+ value.type === 'Counter' &&
3523
+ typeof value.value === 'object'
3524
+ );
3525
+ }
3526
+
3527
+ /**
3528
+ * `isDate` checks if a value is a YSONDate object.
3529
+ */
3530
+ declare function isDate(value: any): value is YSONDate {
3531
+ return (
3532
+ typeof value === 'object' &&
3533
+ value !== null &&
3534
+ value.type === 'Date' &&
3535
+ typeof value.value === 'string'
3536
+ );
3537
+ }
3538
+
3501
3539
  /**
3502
3540
  * `isDocEventForReplay` checks if an event can be used to replay a document.
3503
3541
  */
@@ -3527,6 +3565,72 @@ events: Array<DocEvent_2>,
3527
3565
  return events.every(isDocEventForReplay);
3528
3566
  }
3529
3567
 
3568
+ /**
3569
+ * `isInt` checks if a value is a YSONInt object.
3570
+ */
3571
+ declare function isInt(value: any): value is YSONInt {
3572
+ return (
3573
+ typeof value === 'object' &&
3574
+ value !== null &&
3575
+ value.type === 'Int' &&
3576
+ typeof value.value === 'number'
3577
+ );
3578
+ }
3579
+
3580
+ /**
3581
+ * `isLong` checks if a value is a YSONLong object.
3582
+ */
3583
+ declare function isLong(value: any): value is YSONLong {
3584
+ return (
3585
+ typeof value === 'object' &&
3586
+ value !== null &&
3587
+ value.type === 'Long' &&
3588
+ typeof value.value === 'number'
3589
+ );
3590
+ }
3591
+
3592
+ /**
3593
+ * `isObject` checks if a value is a plain YSON object (not a special type).
3594
+ */
3595
+ declare function isObject(value: any): value is { [key: string]: YSONValue } {
3596
+ return (
3597
+ typeof value === 'object' &&
3598
+ value !== null &&
3599
+ !Array.isArray(value) &&
3600
+ !isText(value) &&
3601
+ !isTree(value) &&
3602
+ !isInt(value) &&
3603
+ !isLong(value) &&
3604
+ !isDate(value) &&
3605
+ !isBinData(value) &&
3606
+ !isCounter(value)
3607
+ );
3608
+ }
3609
+
3610
+ /**
3611
+ * `isText` checks if a value is a YSONText object.
3612
+ */
3613
+ declare function isText(value: any): value is YSONText {
3614
+ return (
3615
+ typeof value === 'object' &&
3616
+ value !== null &&
3617
+ value.type === 'Text' &&
3618
+ Array.isArray(value.nodes)
3619
+ );
3620
+ }
3621
+
3622
+ /**
3623
+ * `isTree` checks if a value is a YSONTree object.
3624
+ */
3625
+ declare function isTree(value: any): value is YSONTree {
3626
+ return (
3627
+ typeof value === 'object' &&
3628
+ value !== null &&
3629
+ value.type === 'Tree' &&
3630
+ typeof value.root === 'object'
3631
+ );
3632
+ }
3633
+
3530
3634
  /**
3531
3635
  * `Json` represents the JSON data type. It is used to represent the data
3532
3636
  * structure of the document.
@@ -4414,6 +4518,46 @@ export declare type PanelToSDKMessage =
4414
4518
  docKey: string;
4415
4519
  };
4416
4520
 
4521
+ /**
4522
+ * `parse` parses a YSON string into a typed JavaScript object.
4523
+ *
4524
+ * YSON extends JSON to support Yorkie CRDT types:
4525
+ * - `Text([...])` for Text CRDT
4526
+ * - `Tree(...)` for Tree CRDT
4527
+ * - Standard JSON for primitives, objects, and arrays
4528
+ *
4529
+ * @param yson - YSON formatted string
4530
+ * @returns Parsed YSONValue
4531
+ * @throws YorkieError if parsing fails
4532
+ *
4533
+ * @example
4534
+ * ```typescript
4535
+ * const data = parse('{"content":Text([{"val":"Hi"}])}');
4536
+ * // { content: { type: 'Text', nodes: [{ val: 'Hi' }] } }
4537
+ *
4538
+ * // With type parameter:
4539
+ * const data = parse<{ content: YSONText }>('{"content":Text([{"val":"Hi"}])}');
4540
+ * // data.content is now typed as YSONText
4541
+ * ```
4542
+ */
4543
+ declare function parse<T = YSONValue>(yson: string): T {
4544
+ try {
4545
+ // Preprocess YSON string to handle special types
4546
+ const processed = preprocessYSON(yson);
4547
+
4548
+ // Parse as JSON
4549
+ const parsed = JSON.parse(processed);
4550
+
4551
+ // Post-process to restore type information
4552
+ return postprocessValue(parsed) as T;
4553
+ } catch (err) {
4554
+ throw new YorkieError(
4555
+ Code.ErrInvalidArgument,
4556
+ `Failed to parse YSON: ${err instanceof Error ? err.message : String(err)}`,
4557
+ );
4558
+ }
4559
+ }
4560
+
4417
4561
  /**
4418
4562
  * `PathOf` represents the type of all possible paths in the Document.subscribe.
4419
4563
  */
@@ -4733,8 +4877,14 @@ export declare interface RevisionSummary {
4733
4877
  */
4734
4878
  description: string;
4735
4879
  /**
4736
- * `snapshot` is the serialized document content (JSON format) at this revision point.
4737
- * This contains only the pure data without CRDT metadata.
4880
+ * `snapshot` is the serialized document content in YSON format at this revision point.
4881
+ *
4882
+ * Use `YSON.parse()` to convert this string to a typed JavaScript object:
4883
+ *
4884
+ * ```javascript
4885
+ * import { YSON } from 'yorkie-js-sdk';
4886
+ * const snapshot = YSON.parse(revision.snapshot);
4887
+ * ```
4738
4888
  */
4739
4889
  snapshot: string;
4740
4890
  /**
@@ -5804,6 +5954,22 @@ export declare type TextPosStruct = {
5804
5954
  */
5805
5955
  export declare type TextPosStructRange = [TextPosStruct, TextPosStruct];
5806
5956
 
5957
+ /**
5958
+ * `textToString` extracts plain text content from YSONText.
5959
+ *
5960
+ * @param text - YSONText object
5961
+ * @returns Plain text string
5962
+ *
5963
+ * @example
5964
+ * ```typescript
5965
+ * const text = { type: 'Text', nodes: [{val: 'H'}, {val: 'i'}] };
5966
+ * textToString(text); // "Hi"
5967
+ * ```
5968
+ */
5969
+ declare function textToString(text: YSONText): string {
5970
+ return text.nodes.map((node) => node.val).join('');
5971
+ }
5972
+
5807
5973
  /**
5808
5974
  * `TextValueType` is a value of Text
5809
5975
  * which has a attributes that expresses the text style.
@@ -6367,6 +6533,16 @@ declare type TreeStyleOpInfo_2 = {
6367
6533
  */
6368
6534
  declare type TreeToken<T> = [T, TokenType];
6369
6535
 
6536
+ /**
6537
+ * `treeToXML` converts YSONTree to XML string representation.
6538
+ *
6539
+ * @param tree - YSONTree object
6540
+ * @returns XML string
6541
+ */
6542
+ declare function treeToXML(tree: YSONTree): string {
6543
+ return treeNodeToXML(tree.root);
6544
+ }
6545
+
6370
6546
  export declare type Unsubscribe = () => void;
6371
6547
 
6372
6548
  export declare interface UnwatchedEvent<P extends Indexable> extends BaseDocEvent_2 {
@@ -6577,4 +6753,209 @@ declare interface WatchedEvent_2<P extends Indexable_2> extends BaseDocEvent {
6577
6753
  */
6578
6754
  export declare type WrappedElement<T = unknown, A extends Indexable = Indexable> = Primitive | JSONObject<T> | JSONArray<T> | Text_2<A> | Counter | Tree;
6579
6755
 
6756
+ declare namespace YSON {
6757
+ export {
6758
+ YSONValue,
6759
+ YSONText as Text,
6760
+ YSONTree as Tree,
6761
+ YSONTextNode as TextNode,
6762
+ YSONTreeNode as TreeNode,
6763
+ YSONInt as Int,
6764
+ YSONLong as Long,
6765
+ YSONDate as Date,
6766
+ YSONBinData as BinData,
6767
+ YSONCounter as Counter,
6768
+ isText,
6769
+ isTree,
6770
+ isInt,
6771
+ isLong,
6772
+ isDate,
6773
+ isBinData,
6774
+ isCounter,
6775
+ isObject,
6776
+ parse,
6777
+ textToString,
6778
+ treeToXML
6779
+ }
6780
+ }
6781
+ export { YSON }
6782
+
6783
+ /**
6784
+ * `YSONBinData` represents Base64-encoded binary data.
6785
+ *
6786
+ * @example
6787
+ * ```typescript
6788
+ * { type: 'BinData', value: 'AQID' }
6789
+ * ```
6790
+ */
6791
+ declare interface YSONBinData {
6792
+ type: 'BinData';
6793
+ value: string;
6794
+ }
6795
+
6796
+ /**
6797
+ * `YSONCounter` represents a Counter CRDT for collaborative counting.
6798
+ *
6799
+ * @example
6800
+ * ```typescript
6801
+ * { type: 'Counter', value: { type: 'Int', value: 10 } }
6802
+ * ```
6803
+ */
6804
+ declare interface YSONCounter {
6805
+ type: 'Counter';
6806
+ value: YSONInt | YSONLong;
6807
+ }
6808
+
6809
+ /**
6810
+ * `YSONDate` represents an ISO 8601 timestamp.
6811
+ *
6812
+ * @example
6813
+ * ```typescript
6814
+ * { type: 'Date', value: '2025-01-02T15:04:05.058Z' }
6815
+ * ```
6816
+ */
6817
+ declare interface YSONDate {
6818
+ type: 'Date';
6819
+ value: string;
6820
+ }
6821
+
6822
+ /**
6823
+ * `YSONInt` represents a 32-bit integer.
6824
+ *
6825
+ * @example
6826
+ * ```typescript
6827
+ * { type: 'Int', value: 42 }
6828
+ * ```
6829
+ */
6830
+ declare interface YSONInt {
6831
+ type: 'Int';
6832
+ value: number;
6833
+ }
6834
+
6835
+ /**
6836
+ * `YSONLong` represents a 64-bit integer.
6837
+ *
6838
+ * @example
6839
+ * ```typescript
6840
+ * { type: 'Long', value: 64 }
6841
+ * ```
6842
+ */
6843
+ declare interface YSONLong {
6844
+ type: 'Long';
6845
+ value: number;
6846
+ }
6847
+
6848
+ /**
6849
+ * `YSONText` represents a Text CRDT structure.
6850
+ *
6851
+ * @example
6852
+ * ```typescript
6853
+ * {
6854
+ * type: 'Text',
6855
+ * nodes: [
6856
+ * { val: 'H' },
6857
+ * { val: 'i' }
6858
+ * ]
6859
+ * }
6860
+ * ```
6861
+ */
6862
+ declare interface YSONText {
6863
+ type: 'Text';
6864
+ nodes: Array<YSONTextNode>;
6865
+ }
6866
+
6867
+ /**
6868
+ * `YSONTextNode` represents a single character in a Text CRDT.
6869
+ *
6870
+ * @example
6871
+ * ```typescript
6872
+ * { val: 'H', attrs: { bold: true } }
6873
+ * ```
6874
+ */
6875
+ declare interface YSONTextNode {
6876
+ /**
6877
+ * The character value
6878
+ */
6879
+ val: string;
6880
+
6881
+ /**
6882
+ * Optional attributes (e.g., formatting)
6883
+ */
6884
+ attrs?: Record<string, any>;
6885
+ }
6886
+
6887
+ /**
6888
+ * `YSONTree` represents a Tree CRDT structure.
6889
+ *
6890
+ * @example
6891
+ * ```typescript
6892
+ * {
6893
+ * type: 'Tree',
6894
+ * root: {
6895
+ * type: 'doc',
6896
+ * children: [
6897
+ * { type: 'p', children: [{ type: 'text', value: 'Hello' }] }
6898
+ * ]
6899
+ * }
6900
+ * }
6901
+ * ```
6902
+ */
6903
+ declare interface YSONTree {
6904
+ type: 'Tree';
6905
+ root: YSONTreeNode;
6906
+ }
6907
+
6908
+ /**
6909
+ * `YSONTreeNode` represents a node in a Tree CRDT.
6910
+ *
6911
+ * For text nodes: `{ type: 'text', value: 'content' }`
6912
+ * For element nodes: `{ type: 'p', children: [...] }`
6913
+ */
6914
+ declare interface YSONTreeNode {
6915
+ /**
6916
+ * Node type (e.g., 'text', 'p', 'div')
6917
+ */
6918
+ type: string;
6919
+
6920
+ /**
6921
+ * Text content (for text nodes)
6922
+ */
6923
+ value?: string;
6924
+
6925
+ /**
6926
+ * Attributes (for element nodes)
6927
+ */
6928
+ attrs?: Record<string, string>;
6929
+
6930
+ /**
6931
+ * Child nodes (for element nodes)
6932
+ */
6933
+ children?: Array<YSONTreeNode>;
6934
+ }
6935
+
6936
+ /**
6937
+ * `YSONValue` represents any valid YSON value.
6938
+ *
6939
+ * Can be:
6940
+ * - Primitives: string, number, boolean, null
6941
+ * - Collections: arrays, objects
6942
+ * - CRDT types: Text, Tree, Counter
6943
+ * - Special types: Int, Long, Date, BinData
6944
+ */
6945
+ declare type YSONValue =
6946
+ | string
6947
+ | number
6948
+ | boolean
6949
+ // eslint-disable-next-line @typescript-eslint/no-restricted-types
6950
+ | null
6951
+ | YSONText
6952
+ | YSONTree
6953
+ | YSONInt
6954
+ | YSONLong
6955
+ | YSONDate
6956
+ | YSONBinData
6957
+ | YSONCounter
6958
+ | { [key: string]: YSONValue }
6959
+ | Array<YSONValue>;
6960
+
6580
6961
  export { }