@romedb/studio 0.0.0-stage → 0.1.1

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.
Files changed (38) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +15 -2
  3. package/package.json +36 -4
  4. package/src/components/CodeEditor.ts +298 -0
  5. package/src/components/studio/BrowseTab.ts +457 -0
  6. package/src/components/studio/CellEditorSheet.ts +165 -0
  7. package/src/components/studio/DatabaseTab.ts +148 -0
  8. package/src/components/studio/GraphCanvas.ts +90 -0
  9. package/src/components/studio/GraphTab.ts +110 -0
  10. package/src/components/studio/InsertRowSheet.ts +180 -0
  11. package/src/components/studio/MapCanvas.ts +177 -0
  12. package/src/components/studio/MapTab.ts +121 -0
  13. package/src/components/studio/NewObjectSheet.ts +235 -0
  14. package/src/components/studio/QueryHistorySheet.ts +111 -0
  15. package/src/components/studio/RowSheets.ts +226 -0
  16. package/src/components/studio/SqlConsole.ts +281 -0
  17. package/src/components/studio/StructureTab.ts +209 -0
  18. package/src/components/studio/icon-button.ts +21 -0
  19. package/src/lib/filters.ts +44 -0
  20. package/src/lib/graph.ts +214 -0
  21. package/src/lib/romeql.ts +106 -0
  22. package/src/lib/spatial.ts +518 -0
  23. package/src/lib/sql-text.ts +208 -0
  24. package/src/lib/studio-types.ts +268 -0
  25. package/src/lib/values.ts +305 -0
  26. package/src/monaco-standalone.d.ts +27 -0
  27. package/src/schema-draft.ts +41 -0
  28. package/src/schema-store.ts +8 -0
  29. package/src/server/backend.ts +77 -0
  30. package/src/server/data.ts +142 -0
  31. package/src/server/edits.ts +92 -0
  32. package/src/server/graph.ts +66 -0
  33. package/src/server/queries.ts +108 -0
  34. package/src/server/schema.ts +272 -0
  35. package/src/server/spatial.ts +74 -0
  36. package/src/studio-page.ts +84 -0
  37. package/src/workspace/StudioWorkspace.ts +1970 -0
  38. package/src/workspace/workspace.css +38 -0
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright 2026 RomeDB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # @romedb/studio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The database workspace of RomeDB Studio: browse and edit rows, see the structure, run
4
+ statements. A Cossack application mounts the package and extends `StudioWorkspace` in one of
5
+ its pages; the page's server methods decide who may do what and call the functions in
6
+ `server/`.
7
+
8
+ npm install @romedb/studio @romedb/client monaco-editor
9
+
10
+ Mount it in the application's `package.json` with
11
+ `"cossack": { "packages": ["@romedb/studio"] }`, import `@romedb/studio/workspace.css`,
12
+ and extend `StudioWorkspace` from `@romedb/studio/app/workspace/StudioWorkspace`.
13
+
14
+ MIT licence.
15
+
16
+ Built from RomeDB Studio 0.1.1 by scripts/build-package.js. Do not edit.
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@romedb/studio",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "The RomeDB Studio database workspace for Cossack applications",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/romedb/studio.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "files": [
15
+ "src"
16
+ ],
17
+ "exports": {
18
+ "./app/*": "./src/*.ts",
19
+ "./workspace.css": "./src/workspace/workspace.css",
20
+ "./package.json": "./package.json"
21
+ },
22
+ "imports": {
23
+ "#app/*": "./src/*.ts"
24
+ },
25
+ "cossack": {
26
+ "root": "src",
27
+ "pages": []
28
+ },
29
+ "peerDependencies": {
30
+ "@cossackframework/core": "^0.9.4",
31
+ "@cossackframework/renderer": "^0.9.4",
32
+ "@cossackframework/solar-icons": ">=0.7.1",
33
+ "@cossackframework/ui": "^0.9.4",
34
+ "@romedb/client": ">=0.2.15",
35
+ "hono": "^4.12.0",
36
+ "monaco-editor": "0.52.2"
37
+ }
38
+ }
@@ -0,0 +1,298 @@
1
+ // Adapted from Cossack Studio CodeEditor (MIT), preserving its Monaco lifecycle and worker integration.
2
+ // The declarations travel with this file, so an application that embeds the editor has them too.
3
+ /// <reference path="../monaco-standalone.d.ts" />
4
+ import {
5
+ Client,
6
+ ClientTask,
7
+ Component,
8
+ Cossack,
9
+ createRef,
10
+ type RefObject,
11
+ } from '@cossackframework/core';
12
+ import { html } from '@cossackframework/renderer';
13
+ import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
14
+ import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
15
+ import type * as Monaco from 'monaco-editor/esm/vs/editor/editor.api';
16
+ import type { StudioSchema } from '../lib/studio-types';
17
+ import { studioSchemaCatalog } from '../schema-store';
18
+ import { romeqlCompletions } from '../lib/romeql';
19
+
20
+ export interface CodeEditorProps {
21
+ value: string;
22
+ language: 'sql' | 'json' | 'plaintext';
23
+ theme?: 'light' | 'dark';
24
+ schema?: StudioSchema;
25
+ enabled?: boolean;
26
+ readOnly?: boolean;
27
+ lineNumbers?: 'on' | 'off';
28
+ ariaLabel?: string;
29
+ onChange?: (value: string) => void;
30
+ onRun?: () => void;
31
+ [key: string]: unknown;
32
+ }
33
+
34
+ interface MonacoEnvironment {
35
+ getWorker(_moduleId: string, label: string): Worker;
36
+ }
37
+
38
+ interface MonacoRuntime {
39
+ editor: Pick<typeof Monaco.editor, 'create' | 'setModelLanguage' | 'setTheme'>;
40
+ languages: Pick<typeof Monaco.languages, 'registerCompletionItemProvider'>;
41
+ KeyCode: typeof Monaco.KeyCode;
42
+ KeyMod: typeof Monaco.KeyMod;
43
+ CompletionItemKind: typeof Monaco.languages.CompletionItemKind;
44
+ }
45
+
46
+ function sqlIdentifier(name: string): string {
47
+ return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)
48
+ ? name
49
+ : `"${name.replaceAll('"', '""')}"`;
50
+ }
51
+
52
+ @Component()
53
+ export class CodeEditor extends Cossack {
54
+ declare props: CodeEditorProps;
55
+
56
+ containerRef: RefObject<HTMLDivElement> = createRef<HTMLDivElement>();
57
+ private editor?: Monaco.editor.IStandaloneCodeEditor;
58
+ private monaco?: MonacoRuntime;
59
+ private completionProvider?: Monaco.IDisposable;
60
+ private runAction?: Monaco.IDisposable;
61
+ private disposed = false;
62
+ private initializing = false;
63
+ private syncing = false;
64
+ private loadedLanguages = new Set<CodeEditorProps['language']>(['plaintext']);
65
+
66
+ onMount() {
67
+ void this.initializeEditor();
68
+ }
69
+
70
+ @Client()
71
+ private captureContainer(element: HTMLDivElement) {
72
+ this.containerRef.value = element;
73
+ // Child connectedCallback() runs before its first render, so a dynamically
74
+ // introduced editor cannot rely on onMount() seeing the ref. A function
75
+ // ref initializes Monaco at the point the container is committed.
76
+ void this.initializeEditor();
77
+ }
78
+
79
+ @Client()
80
+ private async initializeEditor() {
81
+ if (this.props.enabled === false || this.editor || this.initializing || this.disposed) return;
82
+ const container = this.containerRef.value;
83
+ if (!container) return;
84
+ this.initializing = true;
85
+
86
+ try {
87
+ (globalThis as typeof globalThis & { MonacoEnvironment?: MonacoEnvironment }).MonacoEnvironment = {
88
+ getWorker(_moduleId, label) {
89
+ return label === 'json' ? new JsonWorker() : new EditorWorker();
90
+ },
91
+ };
92
+
93
+ const [editor, languages, { KeyMod }, { CompletionItemKind, KeyCode }] = await Promise.all([
94
+ import('monaco-editor/esm/vs/editor/standalone/browser/standaloneEditor'),
95
+ import('monaco-editor/esm/vs/editor/standalone/browser/standaloneLanguages'),
96
+ import('monaco-editor/esm/vs/editor/common/services/editorBaseApi'),
97
+ import('monaco-editor/esm/vs/editor/common/standalone/standaloneEnums'),
98
+ import('monaco-editor/esm/vs/editor/contrib/suggest/browser/suggestController'),
99
+ this.loadLanguage(this.props.language),
100
+ ]);
101
+ if (this.disposed || !this.containerRef.value) return;
102
+ this.monaco = {
103
+ editor,
104
+ languages,
105
+ KeyMod,
106
+ KeyCode,
107
+ CompletionItemKind,
108
+ };
109
+ this.editor = editor.create(this.containerRef.value, {
110
+ value: this.props.value,
111
+ language: this.props.language,
112
+ theme: this.props.theme === 'light' ? 'vs' : 'vs-dark',
113
+ automaticLayout: true,
114
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
115
+ fontSize: 13,
116
+ lineHeight: 20,
117
+ minimap: { enabled: false },
118
+ overviewRulerBorder: false,
119
+ overviewRulerLanes: 0,
120
+ padding: { top: 10, bottom: 10 },
121
+ renderLineHighlight: 'line',
122
+ scrollBeyondLastLine: false,
123
+ tabSize: 2,
124
+ wordWrap: this.props.language === 'sql' ? 'off' : 'on',
125
+ readOnly: this.props.readOnly ?? false,
126
+ lineNumbers: this.props.lineNumbers ?? 'on',
127
+ folding: this.props.lineNumbers !== 'off',
128
+ glyphMargin: false,
129
+ quickSuggestions: {
130
+ other: true,
131
+ comments: false,
132
+ strings: false,
133
+ },
134
+ suggestOnTriggerCharacters: true,
135
+ wordBasedSuggestions: 'off',
136
+ ariaLabel: this.props.ariaLabel ?? 'Code editor',
137
+ });
138
+ this.editor.onDidChangeModelContent(() => {
139
+ if (this.syncing) return;
140
+ this.props.onChange?.(this.editor?.getValue() ?? '');
141
+ });
142
+ if (this.props.onRun) {
143
+ // addAction scopes the keybinding to this editor. Unscoped addCommand
144
+ // lets JSON editors shadow SQL execution or run a hidden SQL draft.
145
+ this.runAction = this.editor.addAction({
146
+ id: 'romedb.run-request',
147
+ label: 'Run RomeQL request',
148
+ keybindings: [KeyMod.CtrlCmd | KeyCode.Enter],
149
+ precondition: 'editorTextFocus && !editorReadonly',
150
+ run: () => { this.props.onRun?.(); },
151
+ });
152
+ }
153
+ this.registerSqlCompletions();
154
+ } finally {
155
+ this.initializing = false;
156
+ }
157
+ }
158
+
159
+ onCleanup() {
160
+ this.disposed = true;
161
+ this.completionProvider?.dispose();
162
+ this.runAction?.dispose();
163
+ this.editor?.dispose();
164
+ }
165
+
166
+ @ClientTask()
167
+ async syncEditor() {
168
+ await this.initializeEditor();
169
+ if (!this.editor || !this.monaco) return;
170
+ const value = this.props.value ?? '';
171
+ if (this.editor.getValue() !== value && !this.editor.hasTextFocus()) {
172
+ this.syncing = true;
173
+ try { this.editor.setValue(value); } finally { this.syncing = false; }
174
+ }
175
+ const model = this.editor.getModel();
176
+ if (model && model.getLanguageId() !== this.props.language) {
177
+ await this.loadLanguage(this.props.language);
178
+ this.monaco.editor.setModelLanguage(model, this.props.language);
179
+ this.registerSqlCompletions();
180
+ }
181
+ this.monaco.editor.setTheme(this.props.theme === 'light' ? 'vs' : 'vs-dark');
182
+ this.editor.updateOptions({
183
+ readOnly: this.props.readOnly ?? false,
184
+ lineNumbers: this.props.lineNumbers ?? 'on',
185
+ folding: this.props.lineNumbers !== 'off',
186
+ });
187
+ }
188
+
189
+ @Client()
190
+ private async loadLanguage(language: CodeEditorProps['language']) {
191
+ if (this.loadedLanguages.has(language)) return;
192
+ if (language === 'sql') {
193
+ await import('monaco-editor/esm/vs/basic-languages/sql/sql.contribution');
194
+ } else if (language === 'json') {
195
+ await import('monaco-editor/esm/vs/language/json/monaco.contribution');
196
+ }
197
+ this.loadedLanguages.add(language);
198
+ }
199
+
200
+ @Client()
201
+ private registerSqlCompletions() {
202
+ if (!this.monaco || this.props.language !== 'sql') return;
203
+ this.completionProvider?.dispose();
204
+ const monaco = this.monaco;
205
+ this.completionProvider = monaco.languages.registerCompletionItemProvider('sql', {
206
+ triggerCharacters: ['.', ' ', ':'],
207
+ provideCompletionItems: (model, position) => {
208
+ if (model !== this.editor?.getModel()) return { suggestions: [] };
209
+ const word = model.getWordUntilPosition(position);
210
+ const range = {
211
+ startLineNumber: position.lineNumber,
212
+ endLineNumber: position.lineNumber,
213
+ startColumn: word.startColumn,
214
+ endColumn: word.endColumn,
215
+ };
216
+ const schema = this.props.schema ?? studioSchemaCatalog.get();
217
+ const objects = schema?.objects ?? [];
218
+ const line = model.getLineContent(position.lineNumber).slice(0, position.column - 1);
219
+ const qualifierMatch = line.match(
220
+ /(?:^|[\s,(])(?:"((?:[^"]|"")*)"|`([^`]*)`|\[([^\]]*)\]|([A-Za-z_][\w$]*))\.\w*$/,
221
+ );
222
+ const qualifier = qualifierMatch
223
+ ? (qualifierMatch[1]?.replaceAll('""', '"') ??
224
+ qualifierMatch[2] ??
225
+ qualifierMatch[3] ??
226
+ qualifierMatch[4])
227
+ : undefined;
228
+ const qualifiedObject = qualifier
229
+ ? objects.find((object) => object.name.toLowerCase() === qualifier.toLowerCase())
230
+ : undefined;
231
+ // After `geo::` or `search::` only that namespace's functions apply.
232
+ const namespaced = /::\w*$/.test(line);
233
+ const catalog = namespaced ? [] : qualifiedObject ? [qualifiedObject] : objects;
234
+ const suggestions: Monaco.languages.CompletionItem[] = [
235
+ ...(qualifiedObject ? [] : romeqlCompletions(line).map((entry) => ({
236
+ label: entry.label,
237
+ insertText: entry.insertText,
238
+ filterText: entry.filterText,
239
+ detail: entry.detail,
240
+ kind: entry.kind === 'function' ? monaco.CompletionItemKind.Function
241
+ : entry.kind === 'keyword' ? monaco.CompletionItemKind.Keyword : monaco.CompletionItemKind.Snippet,
242
+ range,
243
+ sortText: `${entry.kind === 'function' ? '3' : '0'}-${entry.label}`,
244
+ }))),
245
+ ...catalog.flatMap((object) => [
246
+ ...(qualifiedObject ? [] : [{
247
+ label: object.name,
248
+ insertText: sqlIdentifier(object.name),
249
+ detail: object.kind === 'view' ? 'Database view' : object.model === 'document' ? 'Document collection' : 'Database table',
250
+ kind: object.kind === 'view'
251
+ ? monaco.CompletionItemKind.Interface
252
+ : monaco.CompletionItemKind.Struct,
253
+ range,
254
+ sortText: `1-${object.name}`,
255
+ }]),
256
+ ...object.columns.map((column) => ({
257
+ label: column.name,
258
+ insertText: sqlIdentifier(column.name),
259
+ detail: `${object.name} · ${column.dataType || column.affinity}`,
260
+ kind: monaco.CompletionItemKind.Field,
261
+ range,
262
+ sortText: `2-${object.name}-${column.name}`,
263
+ })),
264
+ ]),
265
+ ];
266
+ return { suggestions };
267
+ },
268
+ });
269
+ }
270
+
271
+ render() {
272
+ const {
273
+ value: _value,
274
+ language: _language,
275
+ theme: _theme,
276
+ schema: _schema,
277
+ enabled: _enabled,
278
+ readOnly: _readOnly,
279
+ lineNumbers: _lineNumbers,
280
+ ariaLabel: _ariaLabel,
281
+ onChange: _onChange,
282
+ onRun: _onRun,
283
+ class: className = '',
284
+ ...rest
285
+ } = this.props;
286
+ return html`
287
+ <div
288
+ class="studio-code-editor overflow-hidden rounded-md border bg-background ${String(className)}"
289
+ ...=${rest}
290
+ >
291
+ <div
292
+ ref=${this.captureContainer}
293
+ class="h-full ${this.props.lineNumbers === 'off' ? 'min-h-0' : 'min-h-[8rem]'}"
294
+ ></div>
295
+ </div>
296
+ `;
297
+ }
298
+ }