Skip to content

Commit ae4448c

Browse files
Add version property to Python and JavaScript documents (#139)
1 parent eea2058 commit ae4448c

File tree

8 files changed

+60
-5
lines changed

8 files changed

+60
-5
lines changed

javascript/src/api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ export interface ISharedBase extends IObservableDisposable {
8585
* This is used by, for example, docregistry to share the file-path of the edited content.
8686
*/
8787
export interface ISharedDocument extends ISharedBase {
88+
/**
89+
* Document version
90+
*/
91+
readonly version: string;
92+
8893
/**
8994
* Document state
9095
*/

javascript/src/ydocument.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import type { DocumentChange, ISharedDocument, StateChange } from './api.js';
1212
/**
1313
* Generic shareable document.
1414
*/
15-
export class YDocument<T extends DocumentChange> implements ISharedDocument {
15+
export abstract class YDocument<T extends DocumentChange>
16+
implements ISharedDocument
17+
{
1618
constructor(options?: YDocument.IOptions) {
1719
this._ydoc = options?.ydoc ?? new Y.Doc();
1820

@@ -29,11 +31,9 @@ export class YDocument<T extends DocumentChange> implements ISharedDocument {
2931
}
3032

3133
/**
32-
* Creates a standalone YDocument
34+
* Document version
3335
*/
34-
static create(): YDocument<DocumentChange> {
35-
return new YDocument();
36-
}
36+
abstract readonly version: string;
3737

3838
/**
3939
* YJS document.

javascript/src/yfile.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export class YFile
2727
this.ysource.observe(this._modelObserver);
2828
}
2929

30+
/**
31+
* Document version
32+
*/
33+
readonly version: string = '1.0.0';
34+
3035
/**
3136
* Creates a standalone YFile
3237
*/

javascript/src/ynotebook.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export class YNotebook
6666
this.ymeta.observeDeep(this._onMetaChanged);
6767
}
6868

69+
/**
70+
* Document version
71+
*/
72+
readonly version: string = '1.0.0';
73+
6974
/**
7075
* Creates a standalone YNotebook
7176
*

jupyter_ydoc/ybasedoc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ def __init__(self, ydoc: Optional[Y.YDoc] = None):
2929
self._ystate = self._ydoc.get_map("state")
3030
self._subscriptions = {}
3131

32+
@property
33+
@abstractmethod
34+
def version(self) -> str:
35+
"""
36+
Returns the version of the document.
37+
38+
:return: Document's version.
39+
:rtype: str
40+
"""
41+
3242
@property
3343
def ystate(self) -> Y.YMap:
3444
"""

jupyter_ydoc/yblob.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def __init__(self, ydoc: Optional[Y.YDoc] = None):
3838
super().__init__(ydoc)
3939
self._ysource = self._ydoc.get_map("source")
4040

41+
@property
42+
def version(self) -> str:
43+
"""
44+
Returns the version of the document.
45+
46+
:return: Document's version.
47+
:rtype: str
48+
"""
49+
return "1.0.0"
50+
4151
def get(self) -> bytes:
4252
"""
4353
Returns the content of the document.

jupyter_ydoc/ynotebook.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ def __init__(self, ydoc: Optional[Y.YDoc] = None):
5858
self._ymeta = self._ydoc.get_map("meta")
5959
self._ycells = self._ydoc.get_array("cells")
6060

61+
@property
62+
def version(self) -> str:
63+
"""
64+
Returns the version of the document.
65+
66+
:return: Document's version.
67+
:rtype: str
68+
"""
69+
return "1.0.0"
70+
6171
@property
6272
def ycells(self):
6373
"""

jupyter_ydoc/yunicode.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ def __init__(self, ydoc: Optional[Y.YDoc] = None):
3333
super().__init__(ydoc)
3434
self._ysource = self._ydoc.get_text("source")
3535

36+
@property
37+
def version(self) -> str:
38+
"""
39+
Returns the version of the document.
40+
41+
:return: Document's version.
42+
:rtype: str
43+
"""
44+
return "1.0.0"
45+
3646
def get(self) -> str:
3747
"""
3848
Returns the content of the document.

0 commit comments

Comments
 (0)