@solidactions/cli 3.6.0 → 3.7.0
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/README.md +64 -0
- package/dist/command-manifest.json +567 -1
- package/dist/commands/database.js +1315 -0
- package/dist/commands/device-login.js +1 -1
- package/dist/index.js +96 -0
- package/dist/utils/api.js +25 -1
- package/dist/utils/database-client-support.js +68 -0
- package/dist/utils/database-data-plane.js +237 -0
- package/dist/utils/database-sql-import-runner.js +466 -0
- package/dist/utils/database-sql-import.js +381 -0
- package/dist/utils/examples-ref.js +6 -3
- package/dist/utils/skills.js +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseSqlStatementAccumulator = void 0;
|
|
4
|
+
exports.scanDatabaseSqlGroups = scanDatabaseSqlGroups;
|
|
5
|
+
exports.parseDatabaseImportSql = parseDatabaseImportSql;
|
|
6
|
+
const database_data_plane_1 = require("./database-data-plane");
|
|
7
|
+
const MAX_IMPORT_GROUP_BYTES = 8 * 1024 * 1024;
|
|
8
|
+
const INCOMPLETE_DOWNLOAD_MARKER = /(?:^|\n)[\t ]*--[\t ]+DOWNLOAD INCOMPLETE\b/;
|
|
9
|
+
function importError(message) {
|
|
10
|
+
return new database_data_plane_1.DatabaseOperationError('import_failed', message);
|
|
11
|
+
}
|
|
12
|
+
function decodeSource(source) {
|
|
13
|
+
if (typeof source === 'string') {
|
|
14
|
+
if (source.startsWith('\uFEFF')) {
|
|
15
|
+
const text = source.slice(1);
|
|
16
|
+
if (text.startsWith('\uFEFF')) {
|
|
17
|
+
throw importError('The SQL import source has more than one leading UTF-8 BOM.');
|
|
18
|
+
}
|
|
19
|
+
return { text, byteBase: 3 };
|
|
20
|
+
}
|
|
21
|
+
return { text: source, byteBase: 0 };
|
|
22
|
+
}
|
|
23
|
+
const hasBom = source.length >= 3
|
|
24
|
+
&& source[0] === 0xef
|
|
25
|
+
&& source[1] === 0xbb
|
|
26
|
+
&& source[2] === 0xbf;
|
|
27
|
+
let text;
|
|
28
|
+
try {
|
|
29
|
+
// TextDecoder consumes the first UTF-8 BOM. A second BOM remains in
|
|
30
|
+
// the decoded text and is deliberately not normalized away.
|
|
31
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(source);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
throw importError('The SQL import source is not valid UTF-8.');
|
|
35
|
+
}
|
|
36
|
+
if (hasBom && text.startsWith('\uFEFF')) {
|
|
37
|
+
throw importError('The SQL import source has more than one leading UTF-8 BOM.');
|
|
38
|
+
}
|
|
39
|
+
return { text, byteBase: hasBom ? 3 : 0 };
|
|
40
|
+
}
|
|
41
|
+
function codePointWidth(text, index) {
|
|
42
|
+
const point = text.codePointAt(index);
|
|
43
|
+
return point !== undefined && point > 0xffff ? 2 : 1;
|
|
44
|
+
}
|
|
45
|
+
function byteOffsets(text, byteBase) {
|
|
46
|
+
const offsets = new Uint32Array(text.length + 1);
|
|
47
|
+
let bytes = byteBase;
|
|
48
|
+
let index = 0;
|
|
49
|
+
while (index < text.length) {
|
|
50
|
+
offsets[index] = bytes;
|
|
51
|
+
const width = codePointWidth(text, index);
|
|
52
|
+
if (width === 2)
|
|
53
|
+
offsets[index + 1] = bytes;
|
|
54
|
+
bytes += Buffer.byteLength(text.slice(index, index + width), 'utf8');
|
|
55
|
+
index += width;
|
|
56
|
+
offsets[index] = bytes;
|
|
57
|
+
}
|
|
58
|
+
return offsets;
|
|
59
|
+
}
|
|
60
|
+
function isWhitespace(character) {
|
|
61
|
+
return /\s/u.test(character);
|
|
62
|
+
}
|
|
63
|
+
function isIdentifierStart(character) {
|
|
64
|
+
return /[A-Za-z_]/.test(character);
|
|
65
|
+
}
|
|
66
|
+
function isIdentifierPart(character) {
|
|
67
|
+
return /[A-Za-z0-9_$]/.test(character);
|
|
68
|
+
}
|
|
69
|
+
function isTriggerDeclaration(tokens) {
|
|
70
|
+
if (tokens[0]?.value !== 'CREATE')
|
|
71
|
+
return false;
|
|
72
|
+
if (tokens[1]?.value === 'TRIGGER')
|
|
73
|
+
return true;
|
|
74
|
+
return ['TEMP', 'TEMPORARY'].includes(tokens[1]?.value)
|
|
75
|
+
&& tokens[2]?.value === 'TRIGGER';
|
|
76
|
+
}
|
|
77
|
+
function scanDatabaseSqlGroupsWithTokens(text, byteBase = 0) {
|
|
78
|
+
const offsets = byteOffsets(text, byteBase);
|
|
79
|
+
const groups = [];
|
|
80
|
+
let index = 0;
|
|
81
|
+
let line = 1;
|
|
82
|
+
let groupStart = -1;
|
|
83
|
+
let groupStartLine = 1;
|
|
84
|
+
let hasSql = false;
|
|
85
|
+
let tokens = [];
|
|
86
|
+
let trigger = false;
|
|
87
|
+
let triggerBeginDepth = 0;
|
|
88
|
+
let triggerCaseDepth = 0;
|
|
89
|
+
let triggerEnded = false;
|
|
90
|
+
const advance = () => {
|
|
91
|
+
if (text[index] === '\n')
|
|
92
|
+
line += 1;
|
|
93
|
+
index += codePointWidth(text, index);
|
|
94
|
+
};
|
|
95
|
+
const startGroup = () => {
|
|
96
|
+
if (groupStart < 0) {
|
|
97
|
+
groupStart = index;
|
|
98
|
+
groupStartLine = line;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const resetGroup = () => {
|
|
102
|
+
groupStart = -1;
|
|
103
|
+
groupStartLine = line;
|
|
104
|
+
hasSql = false;
|
|
105
|
+
tokens = [];
|
|
106
|
+
trigger = false;
|
|
107
|
+
triggerBeginDepth = 0;
|
|
108
|
+
triggerCaseDepth = 0;
|
|
109
|
+
triggerEnded = false;
|
|
110
|
+
};
|
|
111
|
+
const finishGroup = (endIndex, endLine) => {
|
|
112
|
+
const startByte = offsets[groupStart];
|
|
113
|
+
const endByte = offsets[endIndex];
|
|
114
|
+
if (endByte - startByte > MAX_IMPORT_GROUP_BYTES) {
|
|
115
|
+
throw importError(`SQL statement at line ${groupStartLine} exceeds the 8 MiB import limit.`);
|
|
116
|
+
}
|
|
117
|
+
groups.push({
|
|
118
|
+
sql: text.slice(groupStart, endIndex),
|
|
119
|
+
startByte,
|
|
120
|
+
endByte,
|
|
121
|
+
startLine: groupStartLine,
|
|
122
|
+
endLine,
|
|
123
|
+
tokens,
|
|
124
|
+
});
|
|
125
|
+
resetGroup();
|
|
126
|
+
};
|
|
127
|
+
const scanQuoted = (closing, doubledEscape) => {
|
|
128
|
+
const quoteLine = line;
|
|
129
|
+
advance();
|
|
130
|
+
while (index < text.length) {
|
|
131
|
+
if (text[index] === closing) {
|
|
132
|
+
if (doubledEscape && text[index + 1] === closing) {
|
|
133
|
+
advance();
|
|
134
|
+
advance();
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
advance();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
advance();
|
|
141
|
+
}
|
|
142
|
+
throw importError(`Unterminated SQL quote at line ${quoteLine}.`);
|
|
143
|
+
};
|
|
144
|
+
while (index < text.length) {
|
|
145
|
+
const character = text[index];
|
|
146
|
+
if (isWhitespace(character)) {
|
|
147
|
+
advance();
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (character === '-' && text[index + 1] === '-') {
|
|
151
|
+
startGroup();
|
|
152
|
+
advance();
|
|
153
|
+
advance();
|
|
154
|
+
while (index < text.length && text[index] !== '\n')
|
|
155
|
+
advance();
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (character === '/' && text[index + 1] === '*') {
|
|
159
|
+
const commentLine = line;
|
|
160
|
+
startGroup();
|
|
161
|
+
advance();
|
|
162
|
+
advance();
|
|
163
|
+
let closed = false;
|
|
164
|
+
while (index < text.length) {
|
|
165
|
+
if (text[index] === '*' && text[index + 1] === '/') {
|
|
166
|
+
advance();
|
|
167
|
+
advance();
|
|
168
|
+
closed = true;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
advance();
|
|
172
|
+
}
|
|
173
|
+
if (!closed)
|
|
174
|
+
throw importError(`Unterminated SQL comment at line ${commentLine}.`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
startGroup();
|
|
178
|
+
hasSql = true;
|
|
179
|
+
if (character === '\'' || character === '"' || character === '`') {
|
|
180
|
+
scanQuoted(character, true);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (character === '[') {
|
|
184
|
+
scanQuoted(']', true);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (isIdentifierStart(character)) {
|
|
188
|
+
const tokenLine = line;
|
|
189
|
+
const tokenStart = index;
|
|
190
|
+
while (index < text.length && isIdentifierPart(text[index]))
|
|
191
|
+
advance();
|
|
192
|
+
const value = text.slice(tokenStart, index).toUpperCase();
|
|
193
|
+
tokens.push({ value, line: tokenLine });
|
|
194
|
+
if (!trigger && isTriggerDeclaration(tokens))
|
|
195
|
+
trigger = true;
|
|
196
|
+
if (trigger) {
|
|
197
|
+
if (triggerBeginDepth === 0 && !triggerEnded && value === 'BEGIN') {
|
|
198
|
+
triggerBeginDepth = 1;
|
|
199
|
+
}
|
|
200
|
+
else if (triggerBeginDepth > 0 && !triggerEnded) {
|
|
201
|
+
if (value === 'CASE') {
|
|
202
|
+
triggerCaseDepth += 1;
|
|
203
|
+
}
|
|
204
|
+
else if (value === 'BEGIN' && triggerCaseDepth === 0) {
|
|
205
|
+
triggerBeginDepth += 1;
|
|
206
|
+
}
|
|
207
|
+
else if (value === 'END') {
|
|
208
|
+
if (triggerCaseDepth > 0) {
|
|
209
|
+
triggerCaseDepth -= 1;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
triggerBeginDepth -= 1;
|
|
213
|
+
if (triggerBeginDepth === 0)
|
|
214
|
+
triggerEnded = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (character === ';') {
|
|
222
|
+
const endLine = line;
|
|
223
|
+
advance();
|
|
224
|
+
if (!trigger || triggerEnded)
|
|
225
|
+
finishGroup(index, endLine);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
advance();
|
|
229
|
+
}
|
|
230
|
+
if (hasSql) {
|
|
231
|
+
if (trigger) {
|
|
232
|
+
throw importError(`Incomplete SQL trigger at line ${groupStartLine}.`);
|
|
233
|
+
}
|
|
234
|
+
throw importError(`Incomplete SQL statement at line ${groupStartLine}; a complete boundary could not be proven.`);
|
|
235
|
+
}
|
|
236
|
+
return groups;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Scan complete SQLite statement groups without interpreting transaction or
|
|
240
|
+
* PRAGMA policy. Import normalization builds on this scanner, while the
|
|
241
|
+
* foreground SQL session can reuse the same quote/comment/trigger boundaries.
|
|
242
|
+
*/
|
|
243
|
+
function scanDatabaseSqlGroups(text, byteBase = 0) {
|
|
244
|
+
return scanDatabaseSqlGroupsWithTokens(text, byteBase).map(({ tokens: _tokens, ...group }) => group);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Incrementally frame complete SQLite input using the same quote, comment,
|
|
248
|
+
* identifier, and trigger grammar as SQL imports.
|
|
249
|
+
*/
|
|
250
|
+
class DatabaseSqlStatementAccumulator {
|
|
251
|
+
lines = [];
|
|
252
|
+
get pending() {
|
|
253
|
+
return this.lines.some((line) => line.trim() !== '');
|
|
254
|
+
}
|
|
255
|
+
push(line) {
|
|
256
|
+
if (!this.pending && line.trim() === '')
|
|
257
|
+
return null;
|
|
258
|
+
this.lines.push(line);
|
|
259
|
+
const sql = this.lines.join('\n');
|
|
260
|
+
let groups;
|
|
261
|
+
try {
|
|
262
|
+
groups = scanDatabaseSqlGroupsWithTokens(sql);
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
if (error instanceof database_data_plane_1.DatabaseOperationError
|
|
266
|
+
&& /^(?:Unterminated|Incomplete) SQL\b/.test(error.message)) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
if (groups.length === 0)
|
|
272
|
+
return null;
|
|
273
|
+
const first = sqlWithoutLeadingComments(groups[0].sql);
|
|
274
|
+
const last = sqlWithoutLeadingComments(groups[groups.length - 1].sql);
|
|
275
|
+
const explicitTransaction = /^BEGIN(?:\s+TRANSACTION)?\s*;$/i.test(first);
|
|
276
|
+
if (explicitTransaction && !/^(?:COMMIT|END|ROLLBACK)\s*;$/i.test(last)) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
this.lines = [];
|
|
280
|
+
return {
|
|
281
|
+
sql,
|
|
282
|
+
multiple: explicitTransaction || groups.length > 1,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.DatabaseSqlStatementAccumulator = DatabaseSqlStatementAccumulator;
|
|
287
|
+
function sqlWithoutLeadingComments(sql) {
|
|
288
|
+
let index = 0;
|
|
289
|
+
while (index < sql.length) {
|
|
290
|
+
while (index < sql.length && isWhitespace(sql[index]))
|
|
291
|
+
index += codePointWidth(sql, index);
|
|
292
|
+
if (sql[index] === '-' && sql[index + 1] === '-') {
|
|
293
|
+
index += 2;
|
|
294
|
+
while (index < sql.length && sql[index] !== '\n')
|
|
295
|
+
index += codePointWidth(sql, index);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (sql[index] === '/' && sql[index + 1] === '*') {
|
|
299
|
+
const close = sql.indexOf('*/', index + 2);
|
|
300
|
+
index = close < 0 ? sql.length : close + 2;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
return sql.slice(index).trim();
|
|
306
|
+
}
|
|
307
|
+
function classifyGroup(group) {
|
|
308
|
+
const values = group.tokens.map((token) => token.value);
|
|
309
|
+
const first = values[0] ?? '';
|
|
310
|
+
const semanticSql = sqlWithoutLeadingComments(group.sql);
|
|
311
|
+
if (first === 'PRAGMA') {
|
|
312
|
+
if (/^PRAGMA\s+foreign_keys\s*=\s*OFF\s*;$/i.test(semanticSql)) {
|
|
313
|
+
return 'foreign-keys-off';
|
|
314
|
+
}
|
|
315
|
+
if (/^PRAGMA\s+foreign_keys\s*=\s*ON\s*;$/i.test(semanticSql)) {
|
|
316
|
+
return 'foreign-keys-on';
|
|
317
|
+
}
|
|
318
|
+
return 'pragma';
|
|
319
|
+
}
|
|
320
|
+
if (/^BEGIN(?:\s+TRANSACTION)?\s*;$/i.test(semanticSql)) {
|
|
321
|
+
return 'begin';
|
|
322
|
+
}
|
|
323
|
+
if (/^COMMIT\s*;$/i.test(semanticSql))
|
|
324
|
+
return 'commit';
|
|
325
|
+
if (['BEGIN', 'END', 'COMMIT', 'ROLLBACK', 'SAVEPOINT', 'RELEASE'].includes(first)) {
|
|
326
|
+
return 'transaction';
|
|
327
|
+
}
|
|
328
|
+
return 'ordinary';
|
|
329
|
+
}
|
|
330
|
+
function rejectDisallowedGroup(group, kind) {
|
|
331
|
+
const first = group.tokens[0];
|
|
332
|
+
const line = first?.line ?? group.startLine;
|
|
333
|
+
if (kind === 'pragma' || kind === 'foreign-keys-off' || kind === 'foreign-keys-on') {
|
|
334
|
+
const name = group.tokens[1]?.value.toLowerCase() ?? 'unknown';
|
|
335
|
+
throw importError(`Unsupported PRAGMA ${name} at line ${line}.`);
|
|
336
|
+
}
|
|
337
|
+
if (kind === 'begin' || kind === 'commit' || kind === 'transaction') {
|
|
338
|
+
const control = first?.value ?? 'TRANSACTION';
|
|
339
|
+
throw importError(`Unsupported top-level ${control} at line ${line}.`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function parseDatabaseImportSql(source) {
|
|
343
|
+
const decoded = decodeSource(source);
|
|
344
|
+
if (INCOMPLETE_DOWNLOAD_MARKER.test(decoded.text.replace(/\r\n/g, '\n'))) {
|
|
345
|
+
throw importError('The SQL import source contains an incomplete download marker.');
|
|
346
|
+
}
|
|
347
|
+
const scanned = scanDatabaseSqlGroupsWithTokens(decoded.text, decoded.byteBase);
|
|
348
|
+
if (scanned.length === 0)
|
|
349
|
+
return { groups: [], foreignKeysOff: false };
|
|
350
|
+
const kinds = scanned.map(classifyGroup);
|
|
351
|
+
let first = 0;
|
|
352
|
+
let last = scanned.length;
|
|
353
|
+
let foreignKeysOff = false;
|
|
354
|
+
if (kinds[first] === 'foreign-keys-off') {
|
|
355
|
+
foreignKeysOff = true;
|
|
356
|
+
first += 1;
|
|
357
|
+
}
|
|
358
|
+
const hasCanonicalBegin = kinds[first] === 'begin';
|
|
359
|
+
if (hasCanonicalBegin)
|
|
360
|
+
first += 1;
|
|
361
|
+
if (kinds[last - 1] === 'foreign-keys-on')
|
|
362
|
+
last -= 1;
|
|
363
|
+
const hasCanonicalCommit = kinds[last - 1] === 'commit';
|
|
364
|
+
if (hasCanonicalCommit)
|
|
365
|
+
last -= 1;
|
|
366
|
+
const canonicalEnvelope = hasCanonicalBegin && hasCanonicalCommit;
|
|
367
|
+
if (!canonicalEnvelope) {
|
|
368
|
+
for (let index = 0; index < scanned.length; index += 1) {
|
|
369
|
+
rejectDisallowedGroup(scanned[index], kinds[index]);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const inner = canonicalEnvelope ? scanned.slice(first, last) : scanned;
|
|
373
|
+
const innerKinds = canonicalEnvelope ? kinds.slice(first, last) : kinds;
|
|
374
|
+
for (let index = 0; index < inner.length; index += 1) {
|
|
375
|
+
rejectDisallowedGroup(inner[index], innerKinds[index]);
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
foreignKeysOff: canonicalEnvelope && foreignKeysOff,
|
|
379
|
+
groups: inner.map(({ tokens: _tokens, ...group }) => group),
|
|
380
|
+
};
|
|
381
|
+
}
|
|
@@ -28,7 +28,10 @@ exports.EXAMPLES_REF = void 0;
|
|
|
28
28
|
* users. If solidactions-examples ever starts publishing tags in step with the
|
|
29
29
|
* SDK, replace this with a derivation the way sdk-version.ts does.
|
|
30
30
|
*
|
|
31
|
-
* Currently: solidactions-examples
|
|
32
|
-
*
|
|
31
|
+
* Currently: solidactions-examples PR #29 head @ 8a47ced4 "docs: add database
|
|
32
|
+
* CLI guidance". Pinning this immutable PR-head commit is a temporary build-time necessity
|
|
33
|
+
* while the coordinated wave is pending merge; no delivery override
|
|
34
|
+
* was granted. Before any CLI release, repin EXAMPLES_REF to the
|
|
35
|
+
* merged mainline SHA and verify that exact ref during the release ritual.
|
|
33
36
|
*/
|
|
34
|
-
exports.EXAMPLES_REF = '
|
|
37
|
+
exports.EXAMPLES_REF = 'c232c416a86f5873c4b209f83132290322495e15';
|
package/dist/utils/skills.js
CHANGED
|
@@ -22,7 +22,7 @@ exports.SOLIDACTIONS_SKILL_NAMES = [
|
|
|
22
22
|
];
|
|
23
23
|
const EXAMPLES_OWNER = 'SolidActions';
|
|
24
24
|
const EXAMPLES_REPO = 'solidactions-examples';
|
|
25
|
-
const SKILLS_PATH_PREFIX = 'skills';
|
|
25
|
+
const SKILLS_PATH_PREFIX = 'content/skills';
|
|
26
26
|
/**
|
|
27
27
|
* Resolve the skills directory for an AI helper target.
|
|
28
28
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidactions/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "SolidActions CLI - Deploy and manage workflow automation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"test:watch": "vitest"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@libsql/client": "0.17.4",
|
|
43
44
|
"archiver": "^8.0.0",
|
|
44
45
|
"axios": "^1.18.1",
|
|
45
46
|
"chalk": "^4.1.2",
|