Skip to content

Commit d2bedf0

Browse files
committed
Add schema package with initial configuration (#968)
Introduced a dedicated schema package featuring a live editor with real-time linting for schema definitions. The implementation includes a new grammar and parser for Yorkie schema definitions, enabling structured validation capabilities.
1 parent c45f63b commit d2bedf0

30 files changed

+8160
-4201
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ packages/sdk/lib
1111

1212
# examples
1313
examples/react-tldraw/src/tldraw.d.ts
14+
15+
# schema
16+
packages/schema/antlr

.github/workflows/ci.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,31 @@ jobs:
4141
if: steps.cache.outputs.cache-hit != 'true'
4242
run: pnpm install
4343

44-
- run: pnpm lint
45-
- run: pnpm sdk build
46-
- run: pnpm build:examples
47-
- run: docker compose -f docker/docker-compose-ci.yml up --build -d
48-
- run: pnpm sdk test:ci
44+
- name: Lint
45+
run: pnpm lint
4946

47+
- name: Build and Test SDK
48+
run: |
49+
pnpm sdk build
50+
docker compose -f docker/docker-compose-ci.yml up --build -d
51+
pnpm sdk test:ci
5052
- name: Upload coverage to Codecov
5153
uses: codecov/codecov-action@v5
5254
with:
5355
files: ./coverage/lcov.info
5456
env:
5557
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5658

59+
- name: Build Examples
60+
run: pnpm build:examples
61+
62+
- name: Build React
63+
run: pnpm react build
64+
65+
- name: Build and Test Schema
66+
run: |
67+
pnpm schema build
68+
pnpm schema test
69+
5770
- name: Run benchmark
5871
run: pnpm sdk test:bench

.github/workflows/npm-publish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ jobs:
5050
run: pnpm publish --filter=@yorkie-js/react --no-git-checks --provenance
5151
env:
5252
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
53+
54+
- name: Schema Build
55+
run: pnpm schema build
56+
- name: Schema Publish
57+
run: pnpm publish --filter=@yorkie-js/schema --no-git-checks --provenance
58+
env:
59+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

examples/react-tldraw/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"build": "tsc && vite build",
8+
"build": "vite build",
99
"preview": "vite preview"
1010
},
1111
"dependencies": {

examples/vanilla-codemirror6/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
"vite": "^5.0.12"
1414
},
1515
"dependencies": {
16-
"@codemirror/commands": "6.1.2",
17-
"@codemirror/highlight": "^0.19.8",
18-
"@codemirror/lang-markdown": "^6.0.2",
19-
"@codemirror/language-data": "^6.1.0",
2016
"@codemirror/state": "^6.4.1",
21-
"@codemirror/view": "6.23.1",
2217
"codemirror": "^6.0.1",
2318
"@yorkie-js/sdk": "workspace:*"
2419
}

examples/vanilla-codemirror6/src/main.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/* eslint-disable jsdoc/require-jsdoc */
2-
import yorkie, { DocEventType } from '@yorkie-js/sdk';
32
import type { EditOpInfo, OperationInfo } from '@yorkie-js/sdk';
3+
import yorkie, { DocEventType } from '@yorkie-js/sdk';
44
import { basicSetup, EditorView } from 'codemirror';
5-
import { keymap } from '@codemirror/view';
6-
import {
7-
markdown,
8-
markdownKeymap,
9-
markdownLanguage,
10-
} from '@codemirror/lang-markdown';
115
import { Transaction, TransactionSpec } from '@codemirror/state';
126
import { network } from './network';
137
import { displayLog, displayPeers } from './utils';
@@ -144,12 +138,7 @@ async function main() {
144138
// 03-2. create codemirror instance
145139
const view = new EditorView({
146140
doc: '',
147-
extensions: [
148-
basicSetup,
149-
markdown({ base: markdownLanguage }),
150-
keymap.of(markdownKeymap),
151-
updateListener,
152-
],
141+
extensions: [basicSetup, updateListener],
153142
parent: editorParentElem,
154143
});
155144

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"sdk": "pnpm --filter=@yorkie-js/sdk",
99
"devtools": "pnpm --filter=@yorkie-js/devtools",
1010
"react": "pnpm --filter=@yorkie-js/react",
11+
"schema": "pnpm --filter=@yorkie-js/schema",
1112
"nextjs-scheduler": "pnpm --filter=nextjs-scheduler",
1213
"nextjs-todolist": "pnpm --filter=nextjs-todolist",
1314
"react-tldraw": "pnpm --filter=react-tldraw",

packages/react/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
26+
# lib
27+
lib

packages/schema/.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
# Antlr
27+
*.antlr

packages/schema/antlr/YorkieSchema.g4

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
grammar YorkieSchema;
2+
3+
// Top-level structure
4+
document: declaration* EOF;
5+
6+
declaration
7+
: typeAliasDeclaration
8+
| variableDeclaration
9+
;
10+
11+
typeAliasDeclaration
12+
: 'type' Identifier typeParameters? '=' type ';'
13+
;
14+
15+
variableDeclaration
16+
: 'let' Identifier typeAnnotation? ('=' expression)? ';'
17+
;
18+
19+
// Type definitions
20+
typeAnnotation
21+
: ':' type
22+
;
23+
24+
type
25+
: unionType
26+
;
27+
28+
unionType
29+
: intersectionType ('|' intersectionType)*
30+
;
31+
32+
intersectionType
33+
: arrayType ('&' arrayType)*
34+
;
35+
36+
arrayType
37+
: primaryType ('[' ']')*
38+
| 'Array' typeArguments
39+
;
40+
41+
primaryType
42+
: parenthesizedType
43+
| primitiveType
44+
| objectType
45+
| yorkieType
46+
| typeReference
47+
| literal
48+
;
49+
50+
primitiveType
51+
: 'number'
52+
| 'string'
53+
| 'boolean'
54+
| 'any'
55+
| 'void'
56+
| 'null'
57+
| 'undefined'
58+
;
59+
60+
objectType
61+
: '{' (propertySignature)* '}'
62+
;
63+
64+
propertySignature
65+
: propertyName '?'? typeAnnotation ';'
66+
;
67+
68+
propertyName
69+
: Identifier
70+
| StringLiteral
71+
;
72+
73+
// Yorkie specific types
74+
yorkieType
75+
: 'yorkie.Object' typeArguments
76+
| 'yorkie.Array' typeArguments
77+
| 'yorkie.Counter' typeArguments?
78+
| 'yorkie.Text' typeArguments?
79+
| 'yorkie.Tree' typeArguments?
80+
;
81+
82+
typeReference
83+
: Identifier typeArguments?
84+
;
85+
86+
parenthesizedType
87+
: '(' type ')'
88+
;
89+
90+
// Generics
91+
typeParameters
92+
: '<' typeParameter (',' typeParameter)* '>'
93+
;
94+
95+
typeParameter
96+
: Identifier ('extends' type)?
97+
;
98+
99+
typeArguments
100+
: '<' type (',' type)* '>'
101+
;
102+
103+
// Expressions
104+
expression
105+
: Identifier
106+
| literal
107+
;
108+
109+
literal
110+
: StringLiteral
111+
| NumberLiteral
112+
| BooleanLiteral
113+
;
114+
115+
// Lexer rules
116+
Identifier: [a-zA-Z_][a-zA-Z0-9_]*;
117+
StringLiteral: '"' (~["\r\n])* '"';
118+
NumberLiteral: [0-9]+('.'[0-9]+)?;
119+
BooleanLiteral: 'true' | 'false';
120+
SingleLineComment: '//' ~[\r\n]* -> channel(HIDDEN);
121+
MultiLineComment: '/*' .*? '*/' -> channel(HIDDEN);
122+
WS: [ \t\r\n]+ -> skip;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
token literal names:
2+
null
3+
'type'
4+
'='
5+
';'
6+
'let'
7+
':'
8+
'|'
9+
'&'
10+
'['
11+
']'
12+
'Array'
13+
'number'
14+
'string'
15+
'boolean'
16+
'any'
17+
'void'
18+
'null'
19+
'undefined'
20+
'{'
21+
'}'
22+
'?'
23+
'yorkie.Object'
24+
'yorkie.Array'
25+
'yorkie.Counter'
26+
'yorkie.Text'
27+
'yorkie.Tree'
28+
'('
29+
')'
30+
'<'
31+
','
32+
'>'
33+
'extends'
34+
null
35+
null
36+
null
37+
null
38+
null
39+
null
40+
null
41+
42+
token symbolic names:
43+
null
44+
null
45+
null
46+
null
47+
null
48+
null
49+
null
50+
null
51+
null
52+
null
53+
null
54+
null
55+
null
56+
null
57+
null
58+
null
59+
null
60+
null
61+
null
62+
null
63+
null
64+
null
65+
null
66+
null
67+
null
68+
null
69+
null
70+
null
71+
null
72+
null
73+
null
74+
null
75+
Identifier
76+
StringLiteral
77+
NumberLiteral
78+
BooleanLiteral
79+
SingleLineComment
80+
MultiLineComment
81+
WS
82+
83+
rule names:
84+
document
85+
declaration
86+
typeAliasDeclaration
87+
variableDeclaration
88+
typeAnnotation
89+
type
90+
unionType
91+
intersectionType
92+
arrayType
93+
primaryType
94+
primitiveType
95+
objectType
96+
propertySignature
97+
propertyName
98+
yorkieType
99+
typeReference
100+
parenthesizedType
101+
typeParameters
102+
typeParameter
103+
typeArguments
104+
expression
105+
literal
106+
107+
108+
atn:
109+
[3, 51485, 51898, 1421, 44986, 20307, 1543, 60043, 49729, 3, 40, 199, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 3, 2, 7, 2, 48, 10, 2, 12, 2, 14, 2, 51, 11, 2, 3, 2, 3, 2, 3, 3, 3, 3, 5, 3, 57, 10, 3, 3, 4, 3, 4, 3, 4, 5, 4, 62, 10, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 5, 5, 71, 10, 5, 3, 5, 3, 5, 5, 5, 75, 10, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 7, 8, 87, 10, 8, 12, 8, 14, 8, 90, 11, 8, 3, 9, 3, 9, 3, 9, 7, 9, 95, 10, 9, 12, 9, 14, 9, 98, 11, 9, 3, 10, 3, 10, 3, 10, 7, 10, 103, 10, 10, 12, 10, 14, 10, 106, 11, 10, 3, 10, 3, 10, 5, 10, 110, 10, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 5, 11, 118, 10, 11, 3, 12, 3, 12, 3, 13, 3, 13, 7, 13, 124, 10, 13, 12, 13, 14, 13, 127, 11, 13, 3, 13, 3, 13, 3, 14, 3, 14, 5, 14, 133, 10, 14, 3, 14, 3, 14, 3, 14, 3, 15, 3, 15, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 5, 16, 146, 10, 16, 3, 16, 3, 16, 5, 16, 150, 10, 16, 3, 16, 3, 16, 5, 16, 154, 10, 16, 5, 16, 156, 10, 16, 3, 17, 3, 17, 5, 17, 160, 10, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 19, 3, 19, 3, 19, 3, 19, 7, 19, 170, 10, 19, 12, 19, 14, 19, 173, 11, 19, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 5, 20, 180, 10, 20, 3, 21, 3, 21, 3, 21, 3, 21, 7, 21, 186, 10, 21, 12, 21, 14, 21, 189, 11, 21, 3, 21, 3, 21, 3, 22, 3, 22, 5, 22, 195, 10, 22, 3, 23, 3, 23, 3, 23, 2, 2, 2, 24, 2, 2, 4, 2, 6, 2, 8, 2, 10, 2, 12, 2, 14, 2, 16, 2, 18, 2, 20, 2, 22, 2, 24, 2, 26, 2, 28, 2, 30, 2, 32, 2, 34, 2, 36, 2, 38, 2, 40, 2, 42, 2, 44, 2, 2, 5, 3, 2, 13, 19, 3, 2, 34, 35, 3, 2, 35, 37, 2, 204, 2, 49, 3, 2, 2, 2, 4, 56, 3, 2, 2, 2, 6, 58, 3, 2, 2, 2, 8, 67, 3, 2, 2, 2, 10, 78, 3, 2, 2, 2, 12, 81, 3, 2, 2, 2, 14, 83, 3, 2, 2, 2, 16, 91, 3, 2, 2, 2, 18, 109, 3, 2, 2, 2, 20, 117, 3, 2, 2, 2, 22, 119, 3, 2, 2, 2, 24, 121, 3, 2, 2, 2, 26, 130, 3, 2, 2, 2, 28, 137, 3, 2, 2, 2, 30, 155, 3, 2, 2, 2, 32, 157, 3, 2, 2, 2, 34, 161, 3, 2, 2, 2, 36, 165, 3, 2, 2, 2, 38, 176, 3, 2, 2, 2, 40, 181, 3, 2, 2, 2, 42, 194, 3, 2, 2, 2, 44, 196, 3, 2, 2, 2, 46, 48, 5, 4, 3, 2, 47, 46, 3, 2, 2, 2, 48, 51, 3, 2, 2, 2, 49, 47, 3, 2, 2, 2, 49, 50, 3, 2, 2, 2, 50, 52, 3, 2, 2, 2, 51, 49, 3, 2, 2, 2, 52, 53, 7, 2, 2, 3, 53, 3, 3, 2, 2, 2, 54, 57, 5, 6, 4, 2, 55, 57, 5, 8, 5, 2, 56, 54, 3, 2, 2, 2, 56, 55, 3, 2, 2, 2, 57, 5, 3, 2, 2, 2, 58, 59, 7, 3, 2, 2, 59, 61, 7, 34, 2, 2, 60, 62, 5, 36, 19, 2, 61, 60, 3, 2, 2, 2, 61, 62, 3, 2, 2, 2, 62, 63, 3, 2, 2, 2, 63, 64, 7, 4, 2, 2, 64, 65, 5, 12, 7, 2, 65, 66, 7, 5, 2, 2, 66, 7, 3, 2, 2, 2, 67, 68, 7, 6, 2, 2, 68, 70, 7, 34, 2, 2, 69, 71, 5, 10, 6, 2, 70, 69, 3, 2, 2, 2, 70, 71, 3, 2, 2, 2, 71, 74, 3, 2, 2, 2, 72, 73, 7, 4, 2, 2, 73, 75, 5, 42, 22, 2, 74, 72, 3, 2, 2, 2, 74, 75, 3, 2, 2, 2, 75, 76, 3, 2, 2, 2, 76, 77, 7, 5, 2, 2, 77, 9, 3, 2, 2, 2, 78, 79, 7, 7, 2, 2, 79, 80, 5, 12, 7, 2, 80, 11, 3, 2, 2, 2, 81, 82, 5, 14, 8, 2, 82, 13, 3, 2, 2, 2, 83, 88, 5, 16, 9, 2, 84, 85, 7, 8, 2, 2, 85, 87, 5, 16, 9, 2, 86, 84, 3, 2, 2, 2, 87, 90, 3, 2, 2, 2, 88, 86, 3, 2, 2, 2, 88, 89, 3, 2, 2, 2, 89, 15, 3, 2, 2, 2, 90, 88, 3, 2, 2, 2, 91, 96, 5, 18, 10, 2, 92, 93, 7, 9, 2, 2, 93, 95, 5, 18, 10, 2, 94, 92, 3, 2, 2, 2, 95, 98, 3, 2, 2, 2, 96, 94, 3, 2, 2, 2, 96, 97, 3, 2, 2, 2, 97, 17, 3, 2, 2, 2, 98, 96, 3, 2, 2, 2, 99, 104, 5, 20, 11, 2, 100, 101, 7, 10, 2, 2, 101, 103, 7, 11, 2, 2, 102, 100, 3, 2, 2, 2, 103, 106, 3, 2, 2, 2, 104, 102, 3, 2, 2, 2, 104, 105, 3, 2, 2, 2, 105, 110, 3, 2, 2, 2, 106, 104, 3, 2, 2, 2, 107, 108, 7, 12, 2, 2, 108, 110, 5, 40, 21, 2, 109, 99, 3, 2, 2, 2, 109, 107, 3, 2, 2, 2, 110, 19, 3, 2, 2, 2, 111, 118, 5, 34, 18, 2, 112, 118, 5, 22, 12, 2, 113, 118, 5, 24, 13, 2, 114, 118, 5, 30, 16, 2, 115, 118, 5, 32, 17, 2, 116, 118, 5, 44, 23, 2, 117, 111, 3, 2, 2, 2, 117, 112, 3, 2, 2, 2, 117, 113, 3, 2, 2, 2, 117, 114, 3, 2, 2, 2, 117, 115, 3, 2, 2, 2, 117, 116, 3, 2, 2, 2, 118, 21, 3, 2, 2, 2, 119, 120, 9, 2, 2, 2, 120, 23, 3, 2, 2, 2, 121, 125, 7, 20, 2, 2, 122, 124, 5, 26, 14, 2, 123, 122, 3, 2, 2, 2, 124, 127, 3, 2, 2, 2, 125, 123, 3, 2, 2, 2, 125, 126, 3, 2, 2, 2, 126, 128, 3, 2, 2, 2, 127, 125, 3, 2, 2, 2, 128, 129, 7, 21, 2, 2, 129, 25, 3, 2, 2, 2, 130, 132, 5, 28, 15, 2, 131, 133, 7, 22, 2, 2, 132, 131, 3, 2, 2, 2, 132, 133, 3, 2, 2, 2, 133, 134, 3, 2, 2, 2, 134, 135, 5, 10, 6, 2, 135, 136, 7, 5, 2, 2, 136, 27, 3, 2, 2, 2, 137, 138, 9, 3, 2, 2, 138, 29, 3, 2, 2, 2, 139, 140, 7, 23, 2, 2, 140, 156, 5, 40, 21, 2, 141, 142, 7, 24, 2, 2, 142, 156, 5, 40, 21, 2, 143, 145, 7, 25, 2, 2, 144, 146, 5, 40, 21, 2, 145, 144, 3, 2, 2, 2, 145, 146, 3, 2, 2, 2, 146, 156, 3, 2, 2, 2, 147, 149, 7, 26, 2, 2, 148, 150, 5, 40, 21, 2, 149, 148, 3, 2, 2, 2, 149, 150, 3, 2, 2, 2, 150, 156, 3, 2, 2, 2, 151, 153, 7, 27, 2, 2, 152, 154, 5, 40, 21, 2, 153, 152, 3, 2, 2, 2, 153, 154, 3, 2, 2, 2, 154, 156, 3, 2, 2, 2, 155, 139, 3, 2, 2, 2, 155, 141, 3, 2, 2, 2, 155, 143, 3, 2, 2, 2, 155, 147, 3, 2, 2, 2, 155, 151, 3, 2, 2, 2, 156, 31, 3, 2, 2, 2, 157, 159, 7, 34, 2, 2, 158, 160, 5, 40, 21, 2, 159, 158, 3, 2, 2, 2, 159, 160, 3, 2, 2, 2, 160, 33, 3, 2, 2, 2, 161, 162, 7, 28, 2, 2, 162, 163, 5, 12, 7, 2, 163, 164, 7, 29, 2, 2, 164, 35, 3, 2, 2, 2, 165, 166, 7, 30, 2, 2, 166, 171, 5, 38, 20, 2, 167, 168, 7, 31, 2, 2, 168, 170, 5, 38, 20, 2, 169, 167, 3, 2, 2, 2, 170, 173, 3, 2, 2, 2, 171, 169, 3, 2, 2, 2, 171, 172, 3, 2, 2, 2, 172, 174, 3, 2, 2, 2, 173, 171, 3, 2, 2, 2, 174, 175, 7, 32, 2, 2, 175, 37, 3, 2, 2, 2, 176, 179, 7, 34, 2, 2, 177, 178, 7, 33, 2, 2, 178, 180, 5, 12, 7, 2, 179, 177, 3, 2, 2, 2, 179, 180, 3, 2, 2, 2, 180, 39, 3, 2, 2, 2, 181, 182, 7, 30, 2, 2, 182, 187, 5, 12, 7, 2, 183, 184, 7, 31, 2, 2, 184, 186, 5, 12, 7, 2, 185, 183, 3, 2, 2, 2, 186, 189, 3, 2, 2, 2, 187, 185, 3, 2, 2, 2, 187, 188, 3, 2, 2, 2, 188, 190, 3, 2, 2, 2, 189, 187, 3, 2, 2, 2, 190, 191, 7, 32, 2, 2, 191, 41, 3, 2, 2, 2, 192, 195, 7, 34, 2, 2, 193, 195, 5, 44, 23, 2, 194, 192, 3, 2, 2, 2, 194, 193, 3, 2, 2, 2, 195, 43, 3, 2, 2, 2, 196, 197, 9, 4, 2, 2, 197, 45, 3, 2, 2, 2, 23, 49, 56, 61, 70, 74, 88, 96, 104, 109, 117, 125, 132, 145, 149, 153, 155, 159, 171, 179, 187, 194]

0 commit comments

Comments
 (0)