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

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,42 @@ 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
+ */
4539
+ declare function parse(yson: string): YSONValue {
4540
+ try {
4541
+ // Preprocess YSON string to handle special types
4542
+ const processed = preprocessYSON(yson);
4543
+
4544
+ // Parse as JSON
4545
+ const parsed = JSON.parse(processed);
4546
+
4547
+ // Post-process to restore type information
4548
+ return postprocessValue(parsed);
4549
+ } catch (err) {
4550
+ throw new YorkieError(
4551
+ Code.ErrInvalidArgument,
4552
+ `Failed to parse YSON: ${err instanceof Error ? err.message : String(err)}`,
4553
+ );
4554
+ }
4555
+ }
4556
+
4417
4557
  /**
4418
4558
  * `PathOf` represents the type of all possible paths in the Document.subscribe.
4419
4559
  */
@@ -4733,8 +4873,14 @@ export declare interface RevisionSummary {
4733
4873
  */
4734
4874
  description: string;
4735
4875
  /**
4736
- * `snapshot` is the serialized document content (JSON format) at this revision point.
4737
- * This contains only the pure data without CRDT metadata.
4876
+ * `snapshot` is the serialized document content in YSON format at this revision point.
4877
+ *
4878
+ * Use `YSON.parse()` to convert this string to a typed JavaScript object:
4879
+ *
4880
+ * ```javascript
4881
+ * import { YSON } from 'yorkie-js-sdk';
4882
+ * const snapshot = YSON.parse(revision.snapshot);
4883
+ * ```
4738
4884
  */
4739
4885
  snapshot: string;
4740
4886
  /**
@@ -5804,6 +5950,22 @@ export declare type TextPosStruct = {
5804
5950
  */
5805
5951
  export declare type TextPosStructRange = [TextPosStruct, TextPosStruct];
5806
5952
 
5953
+ /**
5954
+ * `textToString` extracts plain text content from YSONText.
5955
+ *
5956
+ * @param text - YSONText object
5957
+ * @returns Plain text string
5958
+ *
5959
+ * @example
5960
+ * ```typescript
5961
+ * const text = { type: 'Text', nodes: [{val: 'H'}, {val: 'i'}] };
5962
+ * textToString(text); // "Hi"
5963
+ * ```
5964
+ */
5965
+ declare function textToString(text: YSONText): string {
5966
+ return text.nodes.map((node) => node.val).join('');
5967
+ }
5968
+
5807
5969
  /**
5808
5970
  * `TextValueType` is a value of Text
5809
5971
  * which has a attributes that expresses the text style.
@@ -6367,6 +6529,16 @@ declare type TreeStyleOpInfo_2 = {
6367
6529
  */
6368
6530
  declare type TreeToken<T> = [T, TokenType];
6369
6531
 
6532
+ /**
6533
+ * `treeToXML` converts YSONTree to XML string representation.
6534
+ *
6535
+ * @param tree - YSONTree object
6536
+ * @returns XML string
6537
+ */
6538
+ declare function treeToXML(tree: YSONTree): string {
6539
+ return treeNodeToXML(tree.root);
6540
+ }
6541
+
6370
6542
  export declare type Unsubscribe = () => void;
6371
6543
 
6372
6544
  export declare interface UnwatchedEvent<P extends Indexable> extends BaseDocEvent_2 {
@@ -6577,4 +6749,208 @@ declare interface WatchedEvent_2<P extends Indexable_2> extends BaseDocEvent {
6577
6749
  */
6578
6750
  export declare type WrappedElement<T = unknown, A extends Indexable = Indexable> = Primitive | JSONObject<T> | JSONArray<T> | Text_2<A> | Counter | Tree;
6579
6751
 
6752
+ declare namespace YSON {
6753
+ export {
6754
+ YSONValue,
6755
+ YSONText,
6756
+ YSONTree,
6757
+ YSONTextNode,
6758
+ YSONTreeNode,
6759
+ YSONInt,
6760
+ YSONLong,
6761
+ YSONDate,
6762
+ YSONBinData,
6763
+ YSONCounter,
6764
+ isText,
6765
+ isTree,
6766
+ isInt,
6767
+ isLong,
6768
+ isDate,
6769
+ isBinData,
6770
+ isCounter,
6771
+ isObject,
6772
+ parse,
6773
+ textToString,
6774
+ treeToXML
6775
+ }
6776
+ }
6777
+
6778
+ /**
6779
+ * `YSONBinData` represents Base64-encoded binary data.
6780
+ *
6781
+ * @example
6782
+ * ```typescript
6783
+ * { type: 'BinData', value: 'AQID' }
6784
+ * ```
6785
+ */
6786
+ declare interface YSONBinData {
6787
+ type: 'BinData';
6788
+ value: string;
6789
+ }
6790
+
6791
+ /**
6792
+ * `YSONCounter` represents a Counter CRDT for collaborative counting.
6793
+ *
6794
+ * @example
6795
+ * ```typescript
6796
+ * { type: 'Counter', value: { type: 'Int', value: 10 } }
6797
+ * ```
6798
+ */
6799
+ declare interface YSONCounter {
6800
+ type: 'Counter';
6801
+ value: YSONInt | YSONLong;
6802
+ }
6803
+
6804
+ /**
6805
+ * `YSONDate` represents an ISO 8601 timestamp.
6806
+ *
6807
+ * @example
6808
+ * ```typescript
6809
+ * { type: 'Date', value: '2025-01-02T15:04:05.058Z' }
6810
+ * ```
6811
+ */
6812
+ declare interface YSONDate {
6813
+ type: 'Date';
6814
+ value: string;
6815
+ }
6816
+
6817
+ /**
6818
+ * `YSONInt` represents a 32-bit integer.
6819
+ *
6820
+ * @example
6821
+ * ```typescript
6822
+ * { type: 'Int', value: 42 }
6823
+ * ```
6824
+ */
6825
+ declare interface YSONInt {
6826
+ type: 'Int';
6827
+ value: number;
6828
+ }
6829
+
6830
+ /**
6831
+ * `YSONLong` represents a 64-bit integer.
6832
+ *
6833
+ * @example
6834
+ * ```typescript
6835
+ * { type: 'Long', value: 64 }
6836
+ * ```
6837
+ */
6838
+ declare interface YSONLong {
6839
+ type: 'Long';
6840
+ value: number;
6841
+ }
6842
+
6843
+ /**
6844
+ * `YSONText` represents a Text CRDT structure.
6845
+ *
6846
+ * @example
6847
+ * ```typescript
6848
+ * {
6849
+ * type: 'Text',
6850
+ * nodes: [
6851
+ * { val: 'H' },
6852
+ * { val: 'i' }
6853
+ * ]
6854
+ * }
6855
+ * ```
6856
+ */
6857
+ declare interface YSONText {
6858
+ type: 'Text';
6859
+ nodes: Array<YSONTextNode>;
6860
+ }
6861
+
6862
+ /**
6863
+ * `YSONTextNode` represents a single character in a Text CRDT.
6864
+ *
6865
+ * @example
6866
+ * ```typescript
6867
+ * { val: 'H', attrs: { bold: true } }
6868
+ * ```
6869
+ */
6870
+ declare interface YSONTextNode {
6871
+ /**
6872
+ * The character value
6873
+ */
6874
+ val: string;
6875
+
6876
+ /**
6877
+ * Optional attributes (e.g., formatting)
6878
+ */
6879
+ attrs?: Record<string, any>;
6880
+ }
6881
+
6882
+ /**
6883
+ * `YSONTree` represents a Tree CRDT structure.
6884
+ *
6885
+ * @example
6886
+ * ```typescript
6887
+ * {
6888
+ * type: 'Tree',
6889
+ * root: {
6890
+ * type: 'doc',
6891
+ * children: [
6892
+ * { type: 'p', children: [{ type: 'text', value: 'Hello' }] }
6893
+ * ]
6894
+ * }
6895
+ * }
6896
+ * ```
6897
+ */
6898
+ declare interface YSONTree {
6899
+ type: 'Tree';
6900
+ root: YSONTreeNode;
6901
+ }
6902
+
6903
+ /**
6904
+ * `YSONTreeNode` represents a node in a Tree CRDT.
6905
+ *
6906
+ * For text nodes: `{ type: 'text', value: 'content' }`
6907
+ * For element nodes: `{ type: 'p', children: [...] }`
6908
+ */
6909
+ declare interface YSONTreeNode {
6910
+ /**
6911
+ * Node type (e.g., 'text', 'p', 'div')
6912
+ */
6913
+ type: string;
6914
+
6915
+ /**
6916
+ * Text content (for text nodes)
6917
+ */
6918
+ value?: string;
6919
+
6920
+ /**
6921
+ * Attributes (for element nodes)
6922
+ */
6923
+ attrs?: Record<string, string>;
6924
+
6925
+ /**
6926
+ * Child nodes (for element nodes)
6927
+ */
6928
+ children?: Array<YSONTreeNode>;
6929
+ }
6930
+
6931
+ /**
6932
+ * `YSONValue` represents any valid YSON value.
6933
+ *
6934
+ * Can be:
6935
+ * - Primitives: string, number, boolean, null
6936
+ * - Collections: arrays, objects
6937
+ * - CRDT types: Text, Tree, Counter
6938
+ * - Special types: Int, Long, Date, BinData
6939
+ */
6940
+ declare type YSONValue =
6941
+ | string
6942
+ | number
6943
+ | boolean
6944
+ // eslint-disable-next-line @typescript-eslint/no-restricted-types
6945
+ | null
6946
+ | YSONText
6947
+ | YSONTree
6948
+ | YSONInt
6949
+ | YSONLong
6950
+ | YSONDate
6951
+ | YSONBinData
6952
+ | YSONCounter
6953
+ | { [key: string]: YSONValue }
6954
+ | Array<YSONValue>;
6955
+
6580
6956
  export { }