@innovatorved/code-lab 0.6.1 → 0.7.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 (131) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +35 -0
  3. package/README.md +38 -1
  4. package/dist/apps/web/src/index.d.ts +0 -9
  5. package/dist/code-lab-sql.esm.js +19 -19
  6. package/dist/code-lab-sql.umd.js +20 -20
  7. package/dist/code-lab.css +1 -1
  8. package/dist/code-lab.d.ts +19 -1
  9. package/dist/code-lab.esm.js +933 -1685
  10. package/dist/code-lab.js +932 -1684
  11. package/dist/extensions/cpp.esm.js +132 -8751
  12. package/dist/extensions/cpp.js +124 -8761
  13. package/dist/extensions/guided-lab.esm.js +33 -6827
  14. package/dist/extensions/guided-lab.js +33 -6845
  15. package/dist/extensions/javascript.esm.js +1 -36
  16. package/dist/extensions/javascript.js +1 -58
  17. package/dist/extensions/python.esm.js +79 -8109
  18. package/dist/extensions/python.js +79 -8127
  19. package/dist/extensions/typescript.esm.js +1 -55
  20. package/dist/extensions/typescript.js +1 -77
  21. package/dist/index.d.ts +1 -1
  22. package/dist/modular-kernel.d.ts +0 -4
  23. package/dist/preview-sw.js +1 -1
  24. package/dist/runtime.esm.js +79 -79
  25. package/dist/runtime.js +79 -79
  26. package/dist/schemas.d.ts +22 -1
  27. package/dist/schemas.esm.js +33 -6806
  28. package/dist/schemas.js +33 -6822
  29. package/dist/shell.esm.js +248 -242
  30. package/dist/shell.js +248 -242
  31. package/dist/terminal.esm.js +8 -6
  32. package/dist/terminal.js +6 -6
  33. package/dist/workbench/command-palette.d.ts +0 -4
  34. package/dist/workbench/index.d.ts +0 -20
  35. package/dist/workbench/intellisense.d.ts +1 -7
  36. package/package.json +3 -10
  37. package/src/code-lab.css +11 -503
  38. package/src/extensions/cpp.ts +11 -29
  39. package/src/extensions/guided-lab.ts +6 -2
  40. package/src/extensions/python.ts +9 -3
  41. package/src/index.ts +1 -1
  42. package/src/modular-kernel.ts +0 -4
  43. package/src/runtime.ts +153 -42
  44. package/src/schemas.ts +12 -3
  45. package/src/shell.ts +109 -16
  46. package/src/terminal.ts +4 -2
  47. package/src/workbench/command-palette.ts +22 -302
  48. package/src/workbench/diff-editor.ts +2 -0
  49. package/src/workbench/icons.ts +1 -1
  50. package/src/workbench/index.ts +0 -15
  51. package/src/workbench/intellisense.ts +17 -4
  52. package/src/workbench.ts +432 -456
  53. package/dist/code-lab.umd.js +0 -6109
  54. package/dist/packages/editor/src/index.d.ts +0 -118
  55. package/dist/packages/preview/src/index.d.ts +0 -34
  56. package/dist/packages/runtime/src/index.d.ts +0 -47
  57. package/dist/packages/terminal/src/index.d.ts +0 -54
  58. package/dist/workbench/drawer.d.ts +0 -18
  59. package/dist/workbench/file-tree.d.ts +0 -11
  60. package/dist/workbench/guided-pane.d.ts +0 -11
  61. package/dist/workbench/styles.d.ts +0 -4
  62. package/dist/workbench/toolbar.d.ts +0 -17
  63. package/packages/commands/README.md +0 -7
  64. package/packages/commands/package.json +0 -16
  65. package/packages/commands/src/index.ts +0 -467
  66. package/packages/commands/tsconfig.json +0 -22
  67. package/packages/core/README.md +0 -12
  68. package/packages/core/package.json +0 -13
  69. package/packages/core/src/di.ts +0 -147
  70. package/packages/core/src/disposable.ts +0 -112
  71. package/packages/core/src/errors.ts +0 -205
  72. package/packages/core/src/events.ts +0 -157
  73. package/packages/core/src/index.ts +0 -49
  74. package/packages/core/src/path.ts +0 -118
  75. package/packages/core/src/registry.ts +0 -61
  76. package/packages/core/tsconfig.json +0 -19
  77. package/packages/editor/README.md +0 -9
  78. package/packages/editor/package.json +0 -18
  79. package/packages/editor/src/index.ts +0 -344
  80. package/packages/editor/tsconfig.json +0 -24
  81. package/packages/fs/README.md +0 -7
  82. package/packages/fs/package.json +0 -16
  83. package/packages/fs/src/backends.ts +0 -301
  84. package/packages/fs/src/index.ts +0 -18
  85. package/packages/fs/src/types.ts +0 -44
  86. package/packages/fs/src/vfs-service.ts +0 -257
  87. package/packages/fs/tsconfig.json +0 -22
  88. package/packages/preview/README.md +0 -3
  89. package/packages/preview/package.json +0 -16
  90. package/packages/preview/src/index.ts +0 -125
  91. package/packages/preview/tsconfig.json +0 -22
  92. package/packages/runtime/README.md +0 -3
  93. package/packages/runtime/package.json +0 -17
  94. package/packages/runtime/src/index.ts +0 -134
  95. package/packages/runtime/tsconfig.json +0 -23
  96. package/packages/settings/README.md +0 -7
  97. package/packages/settings/package.json +0 -16
  98. package/packages/settings/src/builtin-schemas.ts +0 -246
  99. package/packages/settings/src/configuration-service.ts +0 -609
  100. package/packages/settings/src/index.ts +0 -38
  101. package/packages/settings/src/jsonc.ts +0 -189
  102. package/packages/settings/src/schema.ts +0 -164
  103. package/packages/settings/tsconfig.json +0 -22
  104. package/packages/sql/README.md +0 -12
  105. package/packages/sql/package.json +0 -13
  106. package/packages/sql/src/completions.ts +0 -359
  107. package/packages/sql/src/diagnostics.ts +0 -200
  108. package/packages/sql/src/formatter.ts +0 -271
  109. package/packages/sql/src/index.ts +0 -54
  110. package/packages/sql/src/sql-editor.ts +0 -802
  111. package/packages/sql/src/styles.ts +0 -524
  112. package/packages/sql/src/tokenizer.ts +0 -457
  113. package/packages/sql/src/types.ts +0 -148
  114. package/packages/sql/tsconfig.json +0 -19
  115. package/packages/terminal/README.md +0 -3
  116. package/packages/terminal/package.json +0 -16
  117. package/packages/terminal/src/index.ts +0 -183
  118. package/packages/terminal/tsconfig.json +0 -22
  119. package/packages/ui/README.md +0 -8
  120. package/packages/ui/package.json +0 -18
  121. package/packages/ui/src/index.ts +0 -40
  122. package/packages/ui/src/observability.ts +0 -173
  123. package/packages/ui/src/plugin-registry.ts +0 -289
  124. package/packages/ui/src/settings-dialog.ts +0 -911
  125. package/packages/ui/src/themes.ts +0 -333
  126. package/packages/ui/tsconfig.json +0 -24
  127. package/src/workbench/drawer.ts +0 -157
  128. package/src/workbench/file-tree.ts +0 -51
  129. package/src/workbench/guided-pane.ts +0 -43
  130. package/src/workbench/styles.ts +0 -211
  131. package/src/workbench/toolbar.ts +0 -182
@@ -1,457 +0,0 @@
1
- import type { SqlDiagnostic, SqlDialect } from './types';
2
-
3
- export type SqlTokenType =
4
- | 'keyword'
5
- | 'function'
6
- | 'type'
7
- | 'string'
8
- | 'number'
9
- | 'operator'
10
- | 'cast'
11
- | 'param'
12
- | 'identifier'
13
- | 'quoted-ident'
14
- | 'comment'
15
- | 'punctuation'
16
- | 'whitespace';
17
-
18
- export interface SqlToken {
19
- readonly type: SqlTokenType;
20
- readonly value: string;
21
- readonly start: number;
22
- readonly end: number;
23
- }
24
-
25
- const COMMON_KEYWORDS = new Set([
26
- 'SELECT', 'FROM', 'WHERE', 'AND', 'OR', 'NOT', 'IN', 'EXISTS', 'BETWEEN', 'LIKE', 'IS', 'NULL',
27
- 'TRUE', 'FALSE', 'AS', 'JOIN', 'INNER', 'LEFT', 'RIGHT', 'FULL', 'OUTER', 'CROSS', 'NATURAL',
28
- 'ON', 'USING', 'GROUP', 'BY', 'HAVING', 'WINDOW', 'QUALIFY', 'ORDER', 'ASC', 'DESC', 'NULLS',
29
- 'FIRST', 'LAST', 'LIMIT', 'OFFSET', 'FETCH', 'NEXT', 'ROWS', 'ONLY', 'WITH', 'RECURSIVE',
30
- 'UNION', 'ALL', 'INTERSECT', 'EXCEPT', 'DISTINCT', 'CASE', 'WHEN', 'THEN', 'ELSE', 'END',
31
- 'INSERT', 'INTO', 'VALUES', 'DEFAULT', 'UPDATE', 'SET', 'DELETE', 'MERGE', 'CREATE', 'ALTER',
32
- 'DROP', 'TRUNCATE', 'TABLE', 'TEMP', 'TEMPORARY', 'IF', 'VIEW', 'MATERIALIZED', 'INDEX',
33
- 'UNIQUE', 'PRIMARY', 'KEY', 'FOREIGN', 'REFERENCES', 'CHECK', 'CONSTRAINT', 'CASCADE',
34
- 'RESTRICT', 'ADD', 'COLUMN', 'RENAME', 'TO', 'TRIGGER', 'BEFORE', 'AFTER', 'INSTEAD', 'OF',
35
- 'EACH', 'ROW', 'FOR', 'BEGIN', 'COMMIT', 'ROLLBACK', 'SAVEPOINT', 'RELEASE', 'TRANSACTION',
36
- 'EXPLAIN', 'QUERY', 'PLAN', 'OVER', 'PARTITION', 'RANGE', 'GROUPS', 'UNBOUNDED', 'PRECEDING',
37
- 'FOLLOWING', 'CURRENT', 'EXCLUDE', 'TIES', 'OTHERS', 'NO', 'ACTION', 'CONFLICT', 'DO', 'NOTHING',
38
- 'REPLACE', 'ABORT', 'FAIL', 'IGNORE', 'CAST', 'COLLATE', 'ESCAPE', 'HAVING', 'ANY', 'SOME'
39
- ]);
40
-
41
- const POSTGRES_KEYWORDS = new Set([
42
- 'ILIKE', 'SIMILAR', 'LATERAL', 'RETURNING', 'FILTER', 'ANALYZE', 'BUFFERS', 'VERBOSE', 'COSTS',
43
- 'SETTINGS', 'WAL', 'SUMMARY', 'TIMING', 'FORMAT', 'CONCURRENTLY', 'GENERATED', 'ALWAYS',
44
- 'IDENTITY', 'OVERRIDING', 'SYSTEM', 'USER', 'VALUE', 'LOCK', 'SHARE', 'NOWAIT', 'SKIP', 'LOCKED',
45
- 'EXTENSION', 'SCHEMA', 'SEQUENCE', 'DOMAIN', 'TYPE', 'ENUM', 'FUNCTION', 'PROCEDURE', 'LANGUAGE',
46
- 'PLPGSQL', 'SQL', 'IMMUTABLE', 'STABLE', 'VOLATILE', 'PARALLEL', 'SAFE', 'TABLESAMPLE',
47
- 'BERNOULLI', 'UNNEST', 'ORDINALITY', 'WITHIN', 'GROUPING', 'SETS', 'CUBE', 'ROLLUP'
48
- ]);
49
-
50
- const SQLITE_KEYWORDS = new Set([
51
- 'PRAGMA', 'WITHOUT', 'ROWID', 'STRICT', 'GLOB', 'REGEXP', 'MATCH', 'AUTOINCREMENT', 'VACUUM',
52
- 'ATTACH', 'DETACH', 'DATABASE', 'REINDEX', 'INDEXED', 'RETURNING', 'FILTER', 'GENERATED',
53
- 'ALWAYS', 'STORED', 'VIRTUAL'
54
- ]);
55
-
56
- const SQL_TYPES = new Set([
57
- 'INT', 'INTEGER', 'SMALLINT', 'BIGINT', 'SERIAL', 'SMALLSERIAL', 'BIGSERIAL', 'REAL', 'FLOAT',
58
- 'DOUBLE', 'PRECISION', 'NUMERIC', 'DECIMAL', 'MONEY', 'TEXT', 'VARCHAR', 'CHAR', 'CHARACTER',
59
- 'VARYING', 'BPCHAR', 'BYTEA', 'BLOB', 'BOOLEAN', 'BOOL', 'DATE', 'TIME', 'TIMETZ', 'TIMESTAMP',
60
- 'TIMESTAMPTZ', 'INTERVAL', 'UUID', 'JSON', 'JSONB', 'XML', 'INET', 'CIDR', 'MACADDR', 'TSVECTOR',
61
- 'TSQUERY', 'ARRAY', 'INT2', 'INT4', 'INT8', 'FLOAT4', 'FLOAT8', 'ANYARRAY'
62
- ]);
63
-
64
- const SQL_FUNCTIONS = new Set([
65
- 'COUNT', 'SUM', 'AVG', 'MIN', 'MAX', 'COALESCE', 'NULLIF', 'GREATEST', 'LEAST', 'ABS', 'ROUND',
66
- 'CEIL', 'CEILING', 'FLOOR', 'MOD', 'POWER', 'SQRT', 'RANDOM', 'LENGTH', 'CHAR_LENGTH', 'LOWER',
67
- 'UPPER', 'TRIM', 'LTRIM', 'RTRIM', 'SUBSTR', 'SUBSTRING', 'POSITION', 'STRPOS', 'CONCAT',
68
- 'CONCAT_WS', 'SPLIT_PART', 'REGEXP_REPLACE', 'REGEXP_MATCHES', 'NOW', 'CURRENT_DATE',
69
- 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CLOCK_TIMESTAMP', 'DATE_TRUNC', 'DATE_PART', 'EXTRACT',
70
- 'AGE', 'TO_CHAR', 'TO_DATE', 'TO_TIMESTAMP', 'MAKE_INTERVAL', 'STRFTIME', 'DATETIME', 'JULIANDAY',
71
- 'UNIXEPOCH', 'ROW_NUMBER', 'RANK', 'DENSE_RANK', 'PERCENT_RANK', 'CUME_DIST', 'NTILE', 'LAG',
72
- 'LEAD', 'FIRST_VALUE', 'LAST_VALUE', 'NTH_VALUE', 'ARRAY_AGG', 'STRING_AGG', 'GROUP_CONCAT',
73
- 'BOOL_AND', 'BOOL_OR', 'JSON_AGG', 'JSONB_AGG', 'JSON_OBJECT', 'JSON_BUILD_OBJECT',
74
- 'JSONB_BUILD_OBJECT', 'JSON_EXTRACT', 'JSONB_EXTRACT_PATH_TEXT', 'JSONB_SET', 'JSON_EACH',
75
- 'JSONB_EACH', 'GENERATE_SERIES', 'PG_SLEEP', 'PG_SIZE_PRETTY', 'PG_TOTAL_RELATION_SIZE', 'IIF',
76
- 'PRINTF', 'TYPEOF', 'TOTAL', 'CHANGES'
77
- ]);
78
-
79
- export function getDialectKeywords(dialect: SqlDialect): ReadonlySet<string> {
80
- const out = new Set<string>(COMMON_KEYWORDS);
81
- const extra = dialect === 'postgres' ? POSTGRES_KEYWORDS : SQLITE_KEYWORDS;
82
- for (const k of extra) out.add(k);
83
- return out;
84
- }
85
-
86
- export function getSqlBuiltinFunctions(): ReadonlySet<string> {
87
- return SQL_FUNCTIONS;
88
- }
89
-
90
- function matchDollarQuoteTag(sql: string, pos: number): string | null {
91
- if (sql[pos] !== '$') return null;
92
- let end = pos + 1;
93
- if (end < sql.length && sql[end] === '$') {
94
- return '$$';
95
- }
96
- if (end < sql.length && /[A-Za-z_]/.test(sql[end])) {
97
- end++;
98
- while (end < sql.length && /[A-Za-z0-9_]/.test(sql[end])) {
99
- end++;
100
- }
101
- if (end < sql.length && sql[end] === '$') {
102
- return sql.slice(pos, end + 1);
103
- }
104
- }
105
- return null;
106
- }
107
-
108
- export function tokenizeSql(sql: string, dialect: SqlDialect = 'postgres'): SqlToken[] {
109
- const tokens: SqlToken[] = [];
110
- const keywords = getDialectKeywords(dialect);
111
- const len = sql.length;
112
- let i = 0;
113
-
114
- while (i < len) {
115
- const ch = sql[i];
116
- const next = sql[i + 1];
117
-
118
- // 1. Whitespace
119
- if (/\s/.test(ch)) {
120
- const start = i;
121
- while (i < len && /\s/.test(sql[i])) i++;
122
- tokens.push({ type: 'whitespace', value: sql.slice(start, i), start, end: i });
123
- continue;
124
- }
125
-
126
- // 2. Single-line comment `-- ...`
127
- if (ch === '-' && next === '-') {
128
- const start = i;
129
- i += 2;
130
- while (i < len && sql[i] !== '\n') i++;
131
- tokens.push({ type: 'comment', value: sql.slice(start, i), start, end: i });
132
- continue;
133
- }
134
-
135
- // 3. Block comment `/* ... */` (supports nested Postgres block comments)
136
- if (ch === '/' && next === '*') {
137
- const start = i;
138
- i += 2;
139
- let depth = 1;
140
- while (i < len && depth > 0) {
141
- if (sql[i] === '/' && sql[i + 1] === '*') {
142
- depth++;
143
- i += 2;
144
- } else if (sql[i] === '*' && sql[i + 1] === '/') {
145
- depth--;
146
- i += 2;
147
- } else {
148
- i++;
149
- }
150
- }
151
- tokens.push({ type: 'comment', value: sql.slice(start, i), start, end: i });
152
- continue;
153
- }
154
-
155
- // 4. Postgres dollar-quoted strings `$$...$$` or `$tag$...$tag$`
156
- if (dialect === 'postgres' && ch === '$') {
157
- const tag = matchDollarQuoteTag(sql, i);
158
- if (tag) {
159
- const start = i;
160
- i += tag.length;
161
- const closeIdx = sql.indexOf(tag, i);
162
- if (closeIdx === -1) {
163
- i = len;
164
- } else {
165
- i = closeIdx + tag.length;
166
- }
167
- tokens.push({ type: 'string', value: sql.slice(start, i), start, end: i });
168
- continue;
169
- }
170
- }
171
-
172
- // 5. Positional/named parameters (`$1` in Postgres; `?1`, `:param`, `@param` in SQLite)
173
- if (ch === '$' && /[0-9]/.test(next ?? '')) {
174
- const start = i;
175
- i++;
176
- while (i < len && /[0-9]/.test(sql[i])) i++;
177
- tokens.push({ type: 'param', value: sql.slice(start, i), start, end: i });
178
- continue;
179
- }
180
- if (dialect === 'sqlite' && (ch === ':' || ch === '@') && /[A-Za-z_]/.test(next ?? '')) {
181
- const start = i;
182
- i++;
183
- while (i < len && /[A-Za-z0-9_]/.test(sql[i])) i++;
184
- tokens.push({ type: 'param', value: sql.slice(start, i), start, end: i });
185
- continue;
186
- }
187
- if (dialect === 'sqlite' && ch === '?' && /[0-9]/.test(next ?? '')) {
188
- const start = i;
189
- i++;
190
- while (i < len && /[0-9]/.test(sql[i])) i++;
191
- tokens.push({ type: 'param', value: sql.slice(start, i), start, end: i });
192
- continue;
193
- }
194
-
195
- // 6. Postgres `::type` cast
196
- if (dialect === 'postgres' && ch === ':' && next === ':') {
197
- const start = i;
198
- i += 2;
199
- while (i < len && /\s/.test(sql[i])) i++;
200
- while (i < len && /[A-Za-z0-9_[\]]/.test(sql[i])) i++;
201
- tokens.push({ type: 'cast', value: sql.slice(start, i), start, end: i });
202
- continue;
203
- }
204
-
205
- // 7. Single-quoted string (or Postgres E'...' / X'...')
206
- if (ch === '\'' || ((ch === 'E' || ch === 'e' || ch === 'X' || ch === 'x') && next === '\'')) {
207
- const start = i;
208
- const isEscaped = ch !== '\'';
209
- i += isEscaped ? 2 : 1;
210
- while (i < len) {
211
- if (isEscaped && sql[i] === '\\' && i + 1 < len) {
212
- i += 2;
213
- continue;
214
- }
215
- if (sql[i] === '\'') {
216
- if (sql[i + 1] === '\'') {
217
- i += 2;
218
- continue;
219
- }
220
- i++;
221
- break;
222
- }
223
- i++;
224
- }
225
- tokens.push({ type: 'string', value: sql.slice(start, i), start, end: i });
226
- continue;
227
- }
228
-
229
- // 8. Quoted identifiers (`"..."`, SQLite `` `...` `` or `[...]`)
230
- if (ch === '"' || (dialect === 'sqlite' && (ch === '`' || ch === '['))) {
231
- const start = i;
232
- const closeChar = ch === '[' ? ']' : ch;
233
- i++;
234
- while (i < len) {
235
- if (sql[i] === closeChar) {
236
- if (closeChar !== ']' && sql[i + 1] === closeChar) {
237
- i += 2;
238
- continue;
239
- }
240
- i++;
241
- break;
242
- }
243
- i++;
244
- }
245
- tokens.push({ type: 'quoted-ident', value: sql.slice(start, i), start, end: i });
246
- continue;
247
- }
248
-
249
- // 9. Numeric literals
250
- if (/[0-9]/.test(ch) || (ch === '.' && /[0-9]/.test(next ?? ''))) {
251
- const start = i;
252
- if (ch === '0' && (next === 'x' || next === 'X')) {
253
- i += 2;
254
- while (i < len && /[0-9a-fA-F_]/.test(sql[i])) i++;
255
- } else {
256
- while (i < len && /[0-9_]/.test(sql[i])) i++;
257
- if (i < len && sql[i] === '.' && /[0-9]/.test(sql[i + 1] ?? '')) {
258
- i++;
259
- while (i < len && /[0-9_]/.test(sql[i])) i++;
260
- }
261
- if (i < len && (sql[i] === 'e' || sql[i] === 'E')) {
262
- i++;
263
- if (sql[i] === '+' || sql[i] === '-') i++;
264
- while (i < len && /[0-9]/.test(sql[i])) i++;
265
- }
266
- }
267
- tokens.push({ type: 'number', value: sql.slice(start, i), start, end: i });
268
- continue;
269
- }
270
-
271
- // 10. Multi-char JSONB & relational operators (`->>`, `#>>`, `->`, `#>`, `@>`, `<@`, `?|`, `?&`, `||`, `<>`, `!=`, `<=`, `>=`, `!~*`, `~*`)
272
- const three = sql.slice(i, i + 3);
273
- if (three === '->>' || three === '#>>' || three === '!~*') {
274
- tokens.push({ type: 'operator', value: three, start: i, end: i + 3 });
275
- i += 3;
276
- continue;
277
- }
278
- const two = sql.slice(i, i + 2);
279
- if (
280
- two === '->' || two === '#>' || two === '@>' || two === '<@' ||
281
- two === '?|' || two === '?&' || two === '||' || two === '<>' ||
282
- two === '!=' || two === '<=' || two === '>=' || two === '~*' ||
283
- two === '!~' || two === '<<' || two === '>>'
284
- ) {
285
- tokens.push({ type: 'operator', value: two, start: i, end: i + 2 });
286
- i += 2;
287
- continue;
288
- }
289
-
290
- // 11. Single-char punctuation vs operators
291
- if ('(),.;[]'.includes(ch)) {
292
- tokens.push({ type: 'punctuation', value: ch, start: i, end: i + 1 });
293
- i++;
294
- continue;
295
- }
296
- if ('+-*/%=<>?&|~^!'.includes(ch)) {
297
- tokens.push({ type: 'operator', value: ch, start: i, end: i + 1 });
298
- i++;
299
- continue;
300
- }
301
-
302
- // 12. Identifiers, Keywords, Types & Functions
303
- if (/[A-Za-z_]/.test(ch)) {
304
- const start = i;
305
- i++;
306
- while (i < len && /[A-Za-z0-9_$]/.test(sql[i])) i++;
307
- const word = sql.slice(start, i);
308
- const upper = word.toUpperCase();
309
-
310
- let look = i;
311
- while (look < len && /\s/.test(sql[look])) look++;
312
- const followedByParen = sql[look] === '(';
313
-
314
- // Check previous non-whitespace token: if `.` precede this word, it's a column/member identifier
315
- let prevNonWs: SqlToken | undefined;
316
- for (let k = tokens.length - 1; k >= 0; k--) {
317
- if (tokens[k].type !== 'whitespace' && tokens[k].type !== 'comment') {
318
- prevNonWs = tokens[k];
319
- break;
320
- }
321
- }
322
-
323
- if (prevNonWs && prevNonWs.value === '.') {
324
- tokens.push({ type: 'identifier', value: word, start, end: i });
325
- } else if (followedByParen && SQL_FUNCTIONS.has(upper)) {
326
- tokens.push({ type: 'function', value: word, start, end: i });
327
- } else if (keywords.has(upper)) {
328
- tokens.push({ type: 'keyword', value: word, start, end: i });
329
- } else if (SQL_TYPES.has(upper)) {
330
- tokens.push({ type: 'type', value: word, start, end: i });
331
- } else {
332
- tokens.push({ type: 'identifier', value: word, start, end: i });
333
- }
334
- continue;
335
- }
336
-
337
- tokens.push({ type: 'punctuation', value: ch, start: i, end: i + 1 });
338
- i++;
339
- }
340
-
341
- return tokens;
342
- }
343
-
344
- export function escapeSqlHtml(raw: string): string {
345
- return raw
346
- .replace(/&/g, '&amp;')
347
- .replace(/</g, '&lt;')
348
- .replace(/>/g, '&gt;')
349
- .replace(/"/g, '&quot;');
350
- }
351
-
352
- function tokenCssClass(type: SqlTokenType): string | null {
353
- switch (type) {
354
- case 'keyword':
355
- return 'cl-sql-tok-kw';
356
- case 'function':
357
- return 'cl-sql-tok-fn';
358
- case 'type':
359
- case 'cast':
360
- return 'cl-sql-tok-type';
361
- case 'string':
362
- return 'cl-sql-tok-str';
363
- case 'number':
364
- return 'cl-sql-tok-num';
365
- case 'operator':
366
- return 'cl-sql-tok-op';
367
- case 'param':
368
- return 'cl-sql-tok-param';
369
- case 'quoted-ident':
370
- return 'cl-sql-tok-qident';
371
- case 'comment':
372
- return 'cl-sql-tok-comment';
373
- default:
374
- return null;
375
- }
376
- }
377
-
378
- interface NormalizedDiagRange {
379
- readonly from: number;
380
- readonly to: number;
381
- readonly severity: 'error' | 'warning' | 'info';
382
- readonly message: string;
383
- }
384
-
385
- function resolveDiagRanges(sql: string, diagnostics: readonly SqlDiagnostic[]): NormalizedDiagRange[] {
386
- if (diagnostics.length === 0) return [];
387
- const lineStarts: number[] = [0];
388
- for (let i = 0; i < sql.length; i++) {
389
- if (sql[i] === '\n') lineStarts.push(i + 1);
390
- }
391
- const ranges: NormalizedDiagRange[] = [];
392
- for (const d of diagnostics) {
393
- let from = d.fromOffset;
394
- let to = d.toOffset;
395
- if (from === undefined && d.line !== undefined && d.line >= 1) {
396
- const lineIdx = Math.min(d.line - 1, lineStarts.length - 1);
397
- const lineStart = lineStarts[lineIdx];
398
- const nextNewline = sql.indexOf('\n', lineStart);
399
- const lineEnd = nextNewline === -1 ? sql.length : nextNewline;
400
- if (d.column !== undefined && d.column >= 1) {
401
- from = Math.min(lineStart + d.column - 1, lineEnd);
402
- let tokEnd = from;
403
- while (tokEnd < lineEnd && !/\s|[(),;]/.test(sql[tokEnd])) tokEnd++;
404
- to = tokEnd > from ? tokEnd : Math.min(from + 1, lineEnd);
405
- } else {
406
- from = lineStart;
407
- to = lineEnd;
408
- }
409
- }
410
- if (from !== undefined) {
411
- const safeFrom = Math.max(0, Math.min(from, sql.length));
412
- const safeTo = Math.max(safeFrom + 1, Math.min(to ?? safeFrom + 1, sql.length));
413
- if (safeFrom < sql.length) {
414
- ranges.push({
415
- from: safeFrom,
416
- to: safeTo,
417
- severity: d.severity,
418
- message: d.message
419
- });
420
- }
421
- }
422
- }
423
- return ranges;
424
- }
425
-
426
- export function highlightSql(
427
- sql: string,
428
- dialect: SqlDialect = 'postgres',
429
- diagnostics: readonly SqlDiagnostic[] = []
430
- ): string {
431
- const tokens = tokenizeSql(sql, dialect);
432
- const diagRanges = resolveDiagRanges(sql, diagnostics);
433
- const parts: string[] = [];
434
-
435
- for (const tok of tokens) {
436
- const cls = tokenCssClass(tok.type);
437
- const overlapping = diagRanges.find((r) => tok.start < r.to && tok.end > r.from);
438
- const escaped = escapeSqlHtml(tok.value);
439
- let rendered = cls ? `<span class="${cls}">${escaped}</span>` : escaped;
440
- if (overlapping && tok.type !== 'whitespace') {
441
- const diagCls =
442
- overlapping.severity === 'error'
443
- ? 'cl-sql-diag-error'
444
- : overlapping.severity === 'warning'
445
- ? 'cl-sql-diag-warning'
446
- : 'cl-sql-diag-info';
447
- rendered = `<span class="${diagCls}" title="${escapeSqlHtml(overlapping.message)}">${rendered}</span>`;
448
- }
449
- parts.push(rendered);
450
- }
451
-
452
- // Trailing newline keeps `<pre>` height matched with `<textarea>` when sql ends with `\n`
453
- if (sql.endsWith('\n') || sql.length === 0) {
454
- parts.push(' ');
455
- }
456
- return parts.join('');
457
- }
@@ -1,148 +0,0 @@
1
- export type SqlDialect = 'postgres' | 'sqlite';
2
-
3
- export type SqlEditorMode = 'inline' | 'playground' | 'workbench';
4
-
5
- export type SqlThemeMode = 'dark' | 'light' | 'auto';
6
-
7
- export interface SqlColumnSchema {
8
- readonly name: string;
9
- readonly type: string;
10
- readonly pk?: boolean;
11
- readonly primaryKey?: boolean;
12
- readonly fk?: string;
13
- readonly references?: string;
14
- readonly nullable?: boolean;
15
- readonly comment?: string;
16
- }
17
-
18
- export interface SqlTableSchema {
19
- readonly name: string;
20
- readonly rowCount?: number;
21
- readonly columns: readonly SqlColumnSchema[];
22
- }
23
-
24
- export interface SqlFunctionSchema {
25
- readonly name: string;
26
- readonly signature: string;
27
- readonly description?: string;
28
- }
29
-
30
- export interface SqlSchema {
31
- readonly dialect: SqlDialect;
32
- readonly tables: readonly SqlTableSchema[];
33
- readonly functions?: readonly SqlFunctionSchema[];
34
- }
35
-
36
- export interface SqlDiagnostic {
37
- readonly severity: 'error' | 'warning' | 'info';
38
- readonly message: string;
39
- readonly hint?: string;
40
- readonly line?: number;
41
- readonly column?: number;
42
- readonly fromOffset?: number;
43
- readonly toOffset?: number;
44
- }
45
-
46
- export interface SqlRunPayload {
47
- readonly sql: string;
48
- readonly selectedSql: string;
49
- readonly effectiveSql: string;
50
- readonly dialect: SqlDialect;
51
- }
52
-
53
- export interface SqlFormatOptions {
54
- readonly dialect?: SqlDialect;
55
- readonly indent?: number;
56
- readonly keywordCase?: 'upper' | 'lower' | 'preserve';
57
- }
58
-
59
- export type SqlCompletionKind = 'table' | 'column' | 'function' | 'keyword' | 'cte';
60
-
61
- export interface SqlCompletionItem {
62
- readonly label: string;
63
- readonly insertText: string;
64
- readonly kind: SqlCompletionKind;
65
- readonly detail?: string;
66
- readonly badge?: string;
67
- readonly secondaryBadge?: string;
68
- readonly description?: string;
69
- readonly replaceFrom: number;
70
- readonly replaceTo: number;
71
- }
72
-
73
- export interface SqlEditorOptions {
74
- readonly value?: string;
75
- readonly dialect?: SqlDialect;
76
- readonly mode?: SqlEditorMode;
77
- readonly schema?: SqlSchema | null;
78
- readonly theme?: SqlThemeMode;
79
- readonly readOnly?: boolean;
80
- readonly ariaLabel?: string;
81
- readonly placeholder?: string;
82
- readonly minLines?: number;
83
- readonly maxLines?: number;
84
- readonly showToolbar?: boolean;
85
- readonly onRun?: (payload: SqlRunPayload) => void | Promise<void>;
86
- readonly onExplain?: (payload: SqlRunPayload) => void | Promise<void>;
87
- readonly onChange?: (value: string) => void;
88
- readonly onFormat?: (formatted: string) => void;
89
- }
90
-
91
- export interface SqlEditorInstance {
92
- getValue(): string;
93
- setValue(sql: string): void;
94
- getSelection(): string;
95
- insertAtCursor(text: string): void;
96
- format(): string;
97
- setDialect(dialect: SqlDialect): void;
98
- getDialect(): SqlDialect;
99
- setSchema(schema: SqlSchema | null): void;
100
- getSchema(): SqlSchema | null;
101
- setDiagnostics(diagnostics: readonly SqlDiagnostic[]): void;
102
- clearDiagnostics(): void;
103
- getDiagnostics(): readonly SqlDiagnostic[];
104
- setTheme(theme: SqlThemeMode): void;
105
- getTheme(): SqlThemeMode;
106
- setReadOnly(readOnly: boolean): void;
107
- focus(): void;
108
- destroy(): void;
109
- /** Playground slot elements when `mode === 'playground'` */
110
- readonly slots?: {
111
- readonly header: HTMLElement | null;
112
- readonly footer: HTMLElement | null;
113
- readonly results: HTMLElement | null;
114
- };
115
- }
116
-
117
- export interface SqlRunnerStepInfo {
118
- readonly index: number;
119
- readonly id?: string;
120
- readonly title?: string;
121
- }
122
-
123
- export interface SqlRunnerRequest {
124
- readonly sql: string;
125
- readonly selectedSql: string;
126
- readonly effectiveSql: string;
127
- readonly dialect: SqlDialect;
128
- readonly step?: SqlRunnerStepInfo | null;
129
- readonly mode: 'run' | 'verify' | 'explain';
130
- }
131
-
132
- export interface SqlRunnerVerification {
133
- readonly passed: boolean;
134
- readonly message?: string;
135
- readonly details?: readonly string[];
136
- }
137
-
138
- export interface SqlRunnerResult {
139
- readonly columns?: readonly string[];
140
- readonly rows?: ReadonlyArray<ReadonlyArray<unknown> | Readonly<Record<string, unknown>>>;
141
- readonly rowCount?: number;
142
- readonly execMs?: number;
143
- readonly plan?: string | Readonly<Record<string, unknown>> | ReadonlyArray<unknown>;
144
- readonly verification?: SqlRunnerVerification;
145
- readonly error?: unknown;
146
- }
147
-
148
- export type SqlRunnerFn = (request: SqlRunnerRequest) => Promise<SqlRunnerResult> | SqlRunnerResult;
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "lib": ["ES2022", "DOM"],
7
- "strict": true,
8
- "noImplicitAny": true,
9
- "strictNullChecks": true,
10
- "noUnusedLocals": true,
11
- "noUnusedParameters": true,
12
- "noImplicitReturns": true,
13
- "noFallthroughCasesInSwitch": true,
14
- "noEmit": true,
15
- "skipLibCheck": true,
16
- "forceConsistentCasingInFileNames": true
17
- },
18
- "include": ["src/**/*.ts"]
19
- }
@@ -1,3 +0,0 @@
1
- # `@code-lab/terminal`
2
-
3
- Layer 2 (`services`) multi-session terminal coordinator (`ITerminalService`, `TerminalService`) and ANSI SGR stream parser (`parseAnsiSegments`).
@@ -1,16 +0,0 @@
1
- {
2
- "name": "@code-lab/terminal",
3
- "version": "0.6.1",
4
- "description": "Typed multi-session terminal service & ANSI stream parser for CodeLab.",
5
- "type": "module",
6
- "main": "./src/index.ts",
7
- "types": "./src/index.ts",
8
- "exports": {
9
- ".": "./src/index.ts"
10
- },
11
- "dependencies": {
12
- "@code-lab/core": "workspace:*"
13
- },
14
- "sideEffects": false,
15
- "license": "MIT"
16
- }