@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.
- package/LICENSE.md +20 -0
- package/README.md +15 -2
- package/package.json +36 -4
- package/src/components/CodeEditor.ts +298 -0
- package/src/components/studio/BrowseTab.ts +457 -0
- package/src/components/studio/CellEditorSheet.ts +165 -0
- package/src/components/studio/DatabaseTab.ts +148 -0
- package/src/components/studio/GraphCanvas.ts +90 -0
- package/src/components/studio/GraphTab.ts +110 -0
- package/src/components/studio/InsertRowSheet.ts +180 -0
- package/src/components/studio/MapCanvas.ts +177 -0
- package/src/components/studio/MapTab.ts +121 -0
- package/src/components/studio/NewObjectSheet.ts +235 -0
- package/src/components/studio/QueryHistorySheet.ts +111 -0
- package/src/components/studio/RowSheets.ts +226 -0
- package/src/components/studio/SqlConsole.ts +281 -0
- package/src/components/studio/StructureTab.ts +209 -0
- package/src/components/studio/icon-button.ts +21 -0
- package/src/lib/filters.ts +44 -0
- package/src/lib/graph.ts +214 -0
- package/src/lib/romeql.ts +106 -0
- package/src/lib/spatial.ts +518 -0
- package/src/lib/sql-text.ts +208 -0
- package/src/lib/studio-types.ts +268 -0
- package/src/lib/values.ts +305 -0
- package/src/monaco-standalone.d.ts +27 -0
- package/src/schema-draft.ts +41 -0
- package/src/schema-store.ts +8 -0
- package/src/server/backend.ts +77 -0
- package/src/server/data.ts +142 -0
- package/src/server/edits.ts +92 -0
- package/src/server/graph.ts +66 -0
- package/src/server/queries.ts +108 -0
- package/src/server/schema.ts +272 -0
- package/src/server/spatial.ts +74 -0
- package/src/studio-page.ts +84 -0
- package/src/workspace/StudioWorkspace.ts +1970 -0
- package/src/workspace/workspace.css +38 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import type { PortableValue } from '@romedb/client';
|
|
2
|
+
import type { StudioForeignKey } from './studio-types';
|
|
3
|
+
import { numberText, portableBytes, recordText } from './values';
|
|
4
|
+
|
|
5
|
+
export function quoteIdentifier(name: string): string {
|
|
6
|
+
return `"${name.replaceAll('"', '""')}"`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** SQL literal used only for the human-readable browse query. */
|
|
10
|
+
export function sqlLiteral(value: PortableValue): string {
|
|
11
|
+
switch (value.type) {
|
|
12
|
+
case 'Null': return 'NULL';
|
|
13
|
+
case 'Boolean': return value.value ? 'true' : 'false';
|
|
14
|
+
case 'Integer': return value.value;
|
|
15
|
+
case 'Number': return numberText(value.value);
|
|
16
|
+
case 'String': return `'${value.value.replaceAll("'", "''")}'`;
|
|
17
|
+
case 'Record': return recordText(value.value);
|
|
18
|
+
case 'Binary': return `X'${portableBytes(value.value).map(byte => byte.toString(16).padStart(2, '0')).join('')}'`;
|
|
19
|
+
default: return `'${JSON.stringify(value.value).replaceAll("'", "''")}'`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Splits editor text into statements on top-level semicolons. Quotes,
|
|
25
|
+
* bracketed identifiers, comments and RomeQL braces are respected.
|
|
26
|
+
*/
|
|
27
|
+
export function splitStatements(text: string): string[] {
|
|
28
|
+
const statements: string[] = [];
|
|
29
|
+
let current = '';
|
|
30
|
+
let depth = 0;
|
|
31
|
+
for (let index = 0; index < text.length; index++) {
|
|
32
|
+
const character = text[index];
|
|
33
|
+
const next = text[index + 1];
|
|
34
|
+
if (character === '-' && next === '-') {
|
|
35
|
+
const end = text.indexOf('\n', index);
|
|
36
|
+
const stop = end < 0 ? text.length : end;
|
|
37
|
+
current += text.slice(index, stop);
|
|
38
|
+
index = stop - 1;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (character === '/' && next === '*') {
|
|
42
|
+
const end = text.indexOf('*/', index + 2);
|
|
43
|
+
const stop = end < 0 ? text.length : end + 2;
|
|
44
|
+
current += text.slice(index, stop);
|
|
45
|
+
index = stop - 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (character === "'" || character === '"' || character === '`' || character === '[') {
|
|
49
|
+
const close = character === '[' ? ']' : character;
|
|
50
|
+
let stop = index + 1;
|
|
51
|
+
while (stop < text.length) {
|
|
52
|
+
if (text[stop] === close) {
|
|
53
|
+
if (close !== ']' && text[stop + 1] === close) { stop += 2; continue; }
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
stop++;
|
|
57
|
+
}
|
|
58
|
+
current += text.slice(index, stop + 1);
|
|
59
|
+
index = stop;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (character === '{' || character === '(') depth++;
|
|
63
|
+
if ((character === '}' || character === ')') && depth > 0) depth--;
|
|
64
|
+
if (character === ';' && depth === 0) {
|
|
65
|
+
if (stripComments(current).trim()) statements.push(current.trim());
|
|
66
|
+
current = '';
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
current += character;
|
|
70
|
+
}
|
|
71
|
+
if (stripComments(current).trim()) statements.push(current.trim());
|
|
72
|
+
return statements;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Named parameters that one statement references. RomeDB rejects parameters a
|
|
77
|
+
* statement does not use, so editor parameters are bound per statement. Names
|
|
78
|
+
* inside strings, quoted identifiers and comments do not count, and `$a` does
|
|
79
|
+
* not match `$ab`.
|
|
80
|
+
*/
|
|
81
|
+
export function statementParameters<T>(sql: string, parameters: Record<string, T>): Record<string, T> {
|
|
82
|
+
const used = new Set<string>();
|
|
83
|
+
for (let index = 0; index < sql.length; index++) {
|
|
84
|
+
const character = sql[index];
|
|
85
|
+
const next = sql[index + 1];
|
|
86
|
+
if (character === '-' && next === '-') {
|
|
87
|
+
const end = sql.indexOf('\n', index);
|
|
88
|
+
index = end < 0 ? sql.length : end;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (character === '/' && next === '*') {
|
|
92
|
+
const end = sql.indexOf('*/', index + 2);
|
|
93
|
+
index = end < 0 ? sql.length : end + 1;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (character === "'" || character === '"' || character === '`') {
|
|
97
|
+
let stop = index + 1;
|
|
98
|
+
while (stop < sql.length && (sql[stop] !== character || sql[stop + 1] === character)) stop += sql[stop] === character ? 2 : 1;
|
|
99
|
+
index = stop;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if ((character === '$' || character === ':' || character === '@') && !/[A-Za-z0-9_$]/.test(sql[index - 1] ?? '')) {
|
|
103
|
+
const name = sql.slice(index).match(/^[$:@][A-Za-z_][A-Za-z0-9_]*/)?.[0];
|
|
104
|
+
if (name) { used.add(name); index += name.length - 1; }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return Object.fromEntries(Object.entries(parameters).filter(([name]) => used.has(name)));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function stripComments(sql: string): string {
|
|
111
|
+
return sql.replace(/--[^\n]*/g, ' ').replace(/\/\*[\s\S]*?(?:\*\/|$)/g, ' ');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const WRITE_STATEMENT = /^\s*(?:WITH\b[\s\S]*?\b)?(?:INSERT|UPDATE|DELETE|UPSERT|REPLACE|CREATE|ALTER|DROP|DEFINE|REMOVE|RELATE|MERGE|PATCH|REINDEX)\b/i;
|
|
115
|
+
|
|
116
|
+
/** True when a statement changes data or schema, so it must run as an atomic write. */
|
|
117
|
+
export function isWriteStatement(sql: string): boolean {
|
|
118
|
+
const text = stripComments(sql).trim();
|
|
119
|
+
if (/^(?:EXPLAIN|SELECT|INFO|VALUES|FETCH)\b/i.test(text)) return false;
|
|
120
|
+
return WRITE_STATEMENT.test(text);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Foreign keys declared in a CREATE TABLE statement. */
|
|
124
|
+
export function parseForeignKeys(createSql: string | null, primaryKeyOf: (table: string) => string[] = () => []): StudioForeignKey[] {
|
|
125
|
+
if (!createSql) return [];
|
|
126
|
+
const open = createSql.indexOf('(');
|
|
127
|
+
const close = createSql.lastIndexOf(')');
|
|
128
|
+
if (open < 0 || close <= open) return [];
|
|
129
|
+
const body = createSql.slice(open + 1, close);
|
|
130
|
+
const result: StudioForeignKey[] = [];
|
|
131
|
+
for (const part of splitTopLevel(body)) {
|
|
132
|
+
const text = part.trim();
|
|
133
|
+
const tableConstraint = text.match(/^(?:CONSTRAINT\s+\S+\s+)?FOREIGN\s+KEY\s*\(([^)]*)\)\s*REFERENCES\s+("(?:[^"]|"")+"|`[^`]+`|\[[^\]]+\]|[^\s(]+)\s*(?:\(([^)]*)\))?(.*)$/is);
|
|
134
|
+
if (tableConstraint) {
|
|
135
|
+
const columns = identifierList(tableConstraint[1]);
|
|
136
|
+
const referencedTable = unquote(tableConstraint[2]);
|
|
137
|
+
const referenced = tableConstraint[3] ? identifierList(tableConstraint[3]) : primaryKeyOf(referencedTable);
|
|
138
|
+
result.push(foreignKey(referencedTable, columns, referenced, tableConstraint[4]));
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const inline = text.match(/^("(?:[^"]|"")+"|`[^`]+`|\[[^\]]+\]|[^\s]+)[\s\S]*?\bREFERENCES\s+("(?:[^"]|"")+"|`[^`]+`|\[[^\]]+\]|[^\s(]+)\s*(?:\(([^)]*)\))?(.*)$/is);
|
|
142
|
+
if (inline && !/^(?:CONSTRAINT|PRIMARY|UNIQUE|CHECK)\b/i.test(text)) {
|
|
143
|
+
const referencedTable = unquote(inline[2]);
|
|
144
|
+
const referenced = inline[3] ? identifierList(inline[3]) : primaryKeyOf(referencedTable);
|
|
145
|
+
result.push(foreignKey(referencedTable, [unquote(inline[1])], referenced, inline[4]));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return result.filter(key => key.columns.length && key.columns.every(column => column.referencedColumn));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Column names from CREATE INDEX ... ON table (columns). */
|
|
152
|
+
export function parseIndexColumns(indexSql: string | null): string[] {
|
|
153
|
+
if (!indexSql) return [];
|
|
154
|
+
const match = indexSql.match(/\bON\s+(?:"(?:[^"]|"")+"|`[^`]+`|\[[^\]]+\]|[^\s(]+)\s*(?:USING\s+\w+\s*)?\(([\s\S]*)\)\s*(?:WHERE\b[\s\S]*)?$/i);
|
|
155
|
+
if (!match) return [];
|
|
156
|
+
return splitTopLevel(match[1]).map(part => {
|
|
157
|
+
const trimmed = part.trim();
|
|
158
|
+
const identifier = trimmed.match(/^("(?:[^"]|"")+"|`[^`]+`|\[[^\]]+\]|[A-Za-z_][\w$]*)(\s+(?:COLLATE\s+\S+\s*)?(ASC|DESC))?\s*$/i);
|
|
159
|
+
return identifier ? `${unquote(identifier[1])}${identifier[3]?.toUpperCase() === 'DESC' ? ' DESC' : ''}` : trimmed;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function foreignKey(referencedTable: string, columns: string[], referenced: string[], tail: string): StudioForeignKey {
|
|
164
|
+
const action = (event: string) => tail.match(new RegExp(`ON\\s+${event}\\s+(SET\\s+NULL|SET\\s+DEFAULT|CASCADE|RESTRICT|NO\\s+ACTION)`, 'i'))?.[1].toUpperCase().replace(/\s+/g, ' ') ?? null;
|
|
165
|
+
return {
|
|
166
|
+
referencedTable,
|
|
167
|
+
columns: columns.map((column, index) => ({ column, referencedColumn: referenced[index] ?? '' })),
|
|
168
|
+
onUpdate: action('UPDATE'),
|
|
169
|
+
onDelete: action('DELETE'),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function splitTopLevel(text: string): string[] {
|
|
174
|
+
const parts: string[] = [];
|
|
175
|
+
let depth = 0;
|
|
176
|
+
let current = '';
|
|
177
|
+
let quote = '';
|
|
178
|
+
for (const character of text) {
|
|
179
|
+
if (quote) {
|
|
180
|
+
current += character;
|
|
181
|
+
if (character === quote) quote = '';
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (character === '"' || character === "'" || character === '`') quote = character;
|
|
185
|
+
else if (character === '[') quote = ']';
|
|
186
|
+
else if (character === '(') depth++;
|
|
187
|
+
else if (character === ')') depth--;
|
|
188
|
+
else if (character === ',' && depth === 0) {
|
|
189
|
+
parts.push(current);
|
|
190
|
+
current = '';
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
current += character;
|
|
194
|
+
}
|
|
195
|
+
if (current.trim()) parts.push(current);
|
|
196
|
+
return parts;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function identifierList(text: string): string[] {
|
|
200
|
+
return splitTopLevel(text).map(part => unquote(part.trim().match(/^("(?:[^"]|"")+"|`[^`]+`|\[[^\]]+\]|[^\s]+)/)?.[1] ?? ''));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function unquote(name: string): string {
|
|
204
|
+
const text = name.trim();
|
|
205
|
+
if (text.startsWith('"') && text.endsWith('"')) return text.slice(1, -1).replaceAll('""', '"');
|
|
206
|
+
if ((text.startsWith('`') && text.endsWith('`')) || (text.startsWith('[') && text.endsWith(']'))) return text.slice(1, -1);
|
|
207
|
+
return text;
|
|
208
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import type { PortableValue } from '@romedb/client';
|
|
2
|
+
|
|
3
|
+
/** Logical storage model reported by RomeDB metadata. */
|
|
4
|
+
export type ObjectModel = 'relational' | 'document' | 'view';
|
|
5
|
+
|
|
6
|
+
export interface StudioColumn {
|
|
7
|
+
name: string;
|
|
8
|
+
/** Declared SQL type, or the RomeDB field type for document fields. */
|
|
9
|
+
dataType: string;
|
|
10
|
+
affinity: 'integer' | 'real' | 'text' | 'blob' | 'numeric' | 'any';
|
|
11
|
+
nullable: boolean;
|
|
12
|
+
defaultValue: string | null;
|
|
13
|
+
primaryKeyPosition: number;
|
|
14
|
+
hidden: boolean;
|
|
15
|
+
/** Document field options from DEFINE FIELD. */
|
|
16
|
+
required?: boolean;
|
|
17
|
+
readonly?: boolean;
|
|
18
|
+
check?: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface StudioIndex {
|
|
22
|
+
name: string;
|
|
23
|
+
kind: string;
|
|
24
|
+
unique: boolean;
|
|
25
|
+
origin: string;
|
|
26
|
+
partial: boolean;
|
|
27
|
+
columns: string[];
|
|
28
|
+
/** Spatial indexes: whether the field holds points or Polygon/MultiPolygon regions. */
|
|
29
|
+
geometry?: SpatialGeometryKind;
|
|
30
|
+
/** Index format as INFO reports it: two-dimensional (2.5) or the released 2.4.0 latitude format. */
|
|
31
|
+
spatialFormat?: 'two_dimensional' | 'latitude';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type SpatialGeometryKind = 'point' | 'region';
|
|
35
|
+
|
|
36
|
+
export interface StudioForeignKey {
|
|
37
|
+
referencedTable: string;
|
|
38
|
+
columns: { column: string; referencedColumn: string }[];
|
|
39
|
+
onUpdate: string | null;
|
|
40
|
+
onDelete: string | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface StudioObject {
|
|
44
|
+
name: string;
|
|
45
|
+
kind: 'table' | 'view';
|
|
46
|
+
model: ObjectModel;
|
|
47
|
+
sql: string | null;
|
|
48
|
+
columns: StudioColumn[];
|
|
49
|
+
indexes: StudioIndex[];
|
|
50
|
+
foreignKeys: StudioForeignKey[];
|
|
51
|
+
/** Fields that identify one row: primary-key columns, or `id` for documents. */
|
|
52
|
+
keyFields: string[];
|
|
53
|
+
editable: boolean;
|
|
54
|
+
readOnlyReason?: string;
|
|
55
|
+
strict?: boolean;
|
|
56
|
+
capabilities?: string[];
|
|
57
|
+
/** Present on edge tables declared with CREATE EDGE TABLE. */
|
|
58
|
+
edge?: StudioEdge;
|
|
59
|
+
/** Edge tables that name this collection as an endpoint. */
|
|
60
|
+
edgeTables?: string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface StudioEdge {
|
|
64
|
+
source: string;
|
|
65
|
+
target: string;
|
|
66
|
+
onDelete: 'restrict' | 'cascade';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type GraphDirection = 'out' | 'in' | 'both';
|
|
70
|
+
|
|
71
|
+
export interface GraphRequest {
|
|
72
|
+
root: PortableValue;
|
|
73
|
+
edge: string;
|
|
74
|
+
direction: GraphDirection;
|
|
75
|
+
depth: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface GraphNode {
|
|
79
|
+
key: string;
|
|
80
|
+
id: PortableValue;
|
|
81
|
+
label: string;
|
|
82
|
+
table: string;
|
|
83
|
+
depth: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface GraphEdge {
|
|
87
|
+
key: string;
|
|
88
|
+
id: PortableValue | null;
|
|
89
|
+
source: string;
|
|
90
|
+
target: string;
|
|
91
|
+
label: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface GraphView {
|
|
95
|
+
nodes: GraphNode[];
|
|
96
|
+
edges: GraphEdge[];
|
|
97
|
+
query: string;
|
|
98
|
+
durationMs: number;
|
|
99
|
+
sequence: number;
|
|
100
|
+
error?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Longitude, latitude in WGS84 degrees. */
|
|
104
|
+
export type Position = [number, number];
|
|
105
|
+
|
|
106
|
+
/** The RomeDB 2.5 geometry subset, decoded from ordinary `{type, coordinates}` objects. */
|
|
107
|
+
export type Geometry =
|
|
108
|
+
| { type: 'Point'; coordinates: Position }
|
|
109
|
+
| { type: 'Polygon'; coordinates: Position[][] }
|
|
110
|
+
| { type: 'MultiPolygon'; coordinates: Position[][][] };
|
|
111
|
+
|
|
112
|
+
export interface MapFeature {
|
|
113
|
+
key: string;
|
|
114
|
+
id: PortableValue | null;
|
|
115
|
+
label: string;
|
|
116
|
+
table: string;
|
|
117
|
+
column: string;
|
|
118
|
+
geometry: Geometry;
|
|
119
|
+
summary: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface MapRequest {
|
|
123
|
+
table: string;
|
|
124
|
+
index: string;
|
|
125
|
+
limit: number;
|
|
126
|
+
/** Point indexes: west, south, east, north. `west > east` crosses the antimeridian. */
|
|
127
|
+
bbox?: [number, number, number, number];
|
|
128
|
+
/** Region indexes: longitude, latitude of a point the regions must cover. */
|
|
129
|
+
point?: Position;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface MapView {
|
|
133
|
+
features: MapFeature[];
|
|
134
|
+
rows: number;
|
|
135
|
+
limit: number;
|
|
136
|
+
truncated: boolean;
|
|
137
|
+
geometry?: SpatialGeometryKind;
|
|
138
|
+
query: string;
|
|
139
|
+
durationMs: number;
|
|
140
|
+
sequence: number;
|
|
141
|
+
error?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface StudioConnectionInfo {
|
|
145
|
+
connectionId: string;
|
|
146
|
+
profileId: string;
|
|
147
|
+
name: string;
|
|
148
|
+
kind: 'file' | 'url';
|
|
149
|
+
endpoint: string;
|
|
150
|
+
databaseId: string;
|
|
151
|
+
sequence: number;
|
|
152
|
+
remote: boolean;
|
|
153
|
+
capabilities: Record<string, unknown>;
|
|
154
|
+
limits: Record<string, unknown>;
|
|
155
|
+
journalMode?: string;
|
|
156
|
+
/** For example "RomeDB 2.7.0 · SQLite 3.50.4". */
|
|
157
|
+
databaseVersion?: string;
|
|
158
|
+
/** RomeDB release of the engine, when known. */
|
|
159
|
+
engineVersion?: string;
|
|
160
|
+
/** RomeDB Node SDK release that Studio uses. */
|
|
161
|
+
clientVersion?: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface StudioSchema {
|
|
165
|
+
connection: StudioConnectionInfo | null;
|
|
166
|
+
objects: StudioObject[];
|
|
167
|
+
sequence: number;
|
|
168
|
+
error?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type BrowseFilterOperator =
|
|
172
|
+
| 'eq' | 'ne' | 'contains' | 'starts-with' | 'ends-with'
|
|
173
|
+
| 'gt' | 'gte' | 'lt' | 'lte' | 'is-null' | 'is-not-null';
|
|
174
|
+
|
|
175
|
+
/** How a filter's text is converted to a typed RomeDB value. */
|
|
176
|
+
export type FilterValueType = 'auto' | 'text' | 'integer' | 'number' | 'boolean' | 'record';
|
|
177
|
+
|
|
178
|
+
export interface BrowseFilter {
|
|
179
|
+
column: string;
|
|
180
|
+
operator: BrowseFilterOperator;
|
|
181
|
+
value?: string;
|
|
182
|
+
valueType?: FilterValueType;
|
|
183
|
+
/** Exact typed value, used by reference navigation. */
|
|
184
|
+
typed?: PortableValue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface BrowseSort {
|
|
188
|
+
column: string;
|
|
189
|
+
direction: 'asc' | 'desc';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type GridRow = Record<string, PortableValue>;
|
|
193
|
+
|
|
194
|
+
export interface GridResult {
|
|
195
|
+
columns: string[];
|
|
196
|
+
rows: GridRow[];
|
|
197
|
+
affectedRows: number;
|
|
198
|
+
durationMs: number;
|
|
199
|
+
truncated: boolean;
|
|
200
|
+
totalRows: number;
|
|
201
|
+
page: number;
|
|
202
|
+
pageSize: number;
|
|
203
|
+
objectName: string;
|
|
204
|
+
query: string;
|
|
205
|
+
sequence: number;
|
|
206
|
+
error?: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface StatementResult {
|
|
210
|
+
columns: string[];
|
|
211
|
+
rows: GridRow[];
|
|
212
|
+
affectedRows: number;
|
|
213
|
+
truncated: boolean;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface SqlRun {
|
|
217
|
+
results: StatementResult[];
|
|
218
|
+
durationMs: number;
|
|
219
|
+
sequence: number;
|
|
220
|
+
mode: 'read' | 'write';
|
|
221
|
+
error?: { code: string; message: string; outcome: string };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export const PAGE_SIZES = [25, 50, 100, 250, 500];
|
|
225
|
+
|
|
226
|
+
export const emptyGrid: GridResult = {
|
|
227
|
+
columns: [],
|
|
228
|
+
rows: [],
|
|
229
|
+
affectedRows: 0,
|
|
230
|
+
durationMs: 0,
|
|
231
|
+
truncated: false,
|
|
232
|
+
totalRows: 0,
|
|
233
|
+
page: 1,
|
|
234
|
+
pageSize: 100,
|
|
235
|
+
objectName: '',
|
|
236
|
+
query: '',
|
|
237
|
+
sequence: 0,
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export const emptySchema: StudioSchema = { connection: null, objects: [], sequence: 0 };
|
|
241
|
+
|
|
242
|
+
export const FILTER_OPERATORS: Array<{ value: BrowseFilterOperator; label: string }> = [
|
|
243
|
+
{ value: 'eq', label: 'equals' },
|
|
244
|
+
{ value: 'ne', label: 'does not equal' },
|
|
245
|
+
{ value: 'contains', label: 'contains' },
|
|
246
|
+
{ value: 'starts-with', label: 'starts with' },
|
|
247
|
+
{ value: 'ends-with', label: 'ends with' },
|
|
248
|
+
{ value: 'gt', label: 'greater than' },
|
|
249
|
+
{ value: 'gte', label: 'greater or equal' },
|
|
250
|
+
{ value: 'lt', label: 'less than' },
|
|
251
|
+
{ value: 'lte', label: 'less or equal' },
|
|
252
|
+
{ value: 'is-null', label: 'is NULL' },
|
|
253
|
+
{ value: 'is-not-null', label: 'is not NULL' },
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
export const FILTER_VALUE_TYPES: Array<{ value: FilterValueType; label: string }> = [
|
|
257
|
+
{ value: 'auto', label: 'Auto' },
|
|
258
|
+
{ value: 'text', label: 'Text' },
|
|
259
|
+
{ value: 'integer', label: 'Integer' },
|
|
260
|
+
{ value: 'number', label: 'Number' },
|
|
261
|
+
{ value: 'boolean', label: 'Boolean' },
|
|
262
|
+
{ value: 'record', label: 'Record ID' },
|
|
263
|
+
];
|
|
264
|
+
|
|
265
|
+
/** A moment a Cloud database can be restored to. */
|
|
266
|
+
export type RestorePoint = { at: number; sequence: number; kind?: 'checkpoint' | 'flush' };
|
|
267
|
+
export type RestorePoints = { retentionDays: number; points: RestorePoint[] };
|
|
268
|
+
export type RestoredDatabase = { restoredSequence: number; restoredAt: number; database: { id: string; name: string } };
|