|
1 | 1 | # Schemas
|
2 | 2 |
|
| 3 | +Yjs is untyped. We must know what each attribute contains at build-time and cast its values when accessing them. It is essential to ensure both models use the same schema, to prevent errors at run-time because of a wrong cast. For this purpose, in the following sections, we can find the description of the schema used by each model in case we want to extend them to create a custom model. |
| 4 | + |
3 | 5 | ## YFile
|
4 | 6 |
|
5 |
| -Coming soon! |
| 7 | +```typescript |
| 8 | +{ |
| 9 | + /** |
| 10 | + * Contains the state of the document. |
| 11 | + * At the moment the only mandatory attributes are path and dirty. |
| 12 | + */ |
| 13 | + "state": YMap<string, any>, |
| 14 | + /** |
| 15 | + * Contains the content of the document. |
| 16 | + */ |
| 17 | + "source": YText |
| 18 | + |
| 19 | +} |
| 20 | +``` |
6 | 21 |
|
| 22 | +### state: |
| 23 | +```typescript |
| 24 | +{ |
| 25 | + /** |
| 26 | + * Whether the document is dirty. |
| 27 | + */ |
| 28 | + "dirty": bool, |
| 29 | + /** |
| 30 | + * Document's path. |
| 31 | + */ |
| 32 | + "path": str |
| 33 | +} |
| 34 | +``` |
7 | 35 |
|
8 | 36 | ## YNotebook
|
9 | 37 |
|
10 |
| -Coming soon! |
| 38 | +```typescript |
| 39 | +{ |
| 40 | + /** |
| 41 | + * Contains the state of the document. |
| 42 | + * At the moment the only mandatory attributes are path and dirty. |
| 43 | + */ |
| 44 | + "state": YMap<string, any>, |
| 45 | + /** |
| 46 | + * Contains document's metadata. |
| 47 | + * |
| 48 | + * Note: Do not confuse it with the notebook's metadata attribute, |
| 49 | + * "meta" has `nbformat`, `nbformat_minor`, and `metadata` |
| 50 | + */ |
| 51 | + "meta": YMap<string, any>, |
| 52 | + /** |
| 53 | + * The list of YMap that stores the data of each cell. |
| 54 | + */ |
| 55 | + "cells": YArray<YMap<string, any>> |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### state: |
| 60 | +```typescript |
| 61 | +{ |
| 62 | + /** |
| 63 | + * Whether the document is dirty. |
| 64 | + */ |
| 65 | + "dirty": bool, |
| 66 | + /** |
| 67 | + * Document's path. |
| 68 | + */ |
| 69 | + "path": str |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +### meta: |
| 74 | +```typescript |
| 75 | +{ |
| 76 | + /** |
| 77 | + * The version of the notebook format supported by the schema. |
| 78 | + */ |
| 79 | + "nbformat": number, |
| 80 | + /** |
| 81 | + * The minor version of the notebook format. |
| 82 | + */ |
| 83 | + "nbformat_minor": number, |
| 84 | + /** |
| 85 | + * Notebook's metadata. |
| 86 | + */ |
| 87 | + "metadata": YMap<string, any> |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +### cells |
| 92 | +```typescript |
| 93 | +[ |
| 94 | + /** |
| 95 | + * The following JSON object is actually a YMap that contains |
| 96 | + * the described attributes. |
| 97 | + */ |
| 98 | + { |
| 99 | + /** |
| 100 | + * Cell's id. |
| 101 | + */ |
| 102 | + "id": str, |
| 103 | + /** |
| 104 | + * Cell type. |
| 105 | + */ |
| 106 | + "cell_type": str, |
| 107 | + /** |
| 108 | + * The content of the cell (the code). |
| 109 | + */ |
| 110 | + "source": YText, |
| 111 | + /** |
| 112 | + * Cell's metadata. |
| 113 | + */ |
| 114 | + "metadata": YMap<string, any>, |
| 115 | + /** |
| 116 | + * The execution count. |
| 117 | + */ |
| 118 | + "execution_count": Int | None, |
| 119 | + /** |
| 120 | + * Cell's outputs. |
| 121 | + */ |
| 122 | + "outputs": [] | None, |
| 123 | + /** |
| 124 | + * Cell's attachments. |
| 125 | + */ |
| 126 | + "attachments": {} | None |
| 127 | + } |
| 128 | +] |
| 129 | +``` |
0 commit comments