@solidactions/cli 3.16.0 → 3.18.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 +29 -4
- package/dist/command-manifest.json +388 -1
- package/dist/commands/database-push.js +6 -0
- package/dist/commands/database.js +753 -12
- package/dist/index.js +59 -0
- package/dist/utils/database-data-plane.js +13 -2
- package/dist/utils/database-ingest-digest.js +56 -0
- package/dist/utils/mutating-commands.js +16 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -253,6 +253,7 @@ driver): https://www.solidactions.com/docs/workspace-databases/`);
|
|
|
253
253
|
database
|
|
254
254
|
.command('list')
|
|
255
255
|
.description('List workspace databases')
|
|
256
|
+
.option('--kind <kind>', 'Filter by kind: libsql or duckdb')
|
|
256
257
|
.option('--json', 'Output as JSON')
|
|
257
258
|
.action(async (options) => {
|
|
258
259
|
await (0, database_1.databaseList)(options);
|
|
@@ -261,11 +262,21 @@ database
|
|
|
261
262
|
.command('create')
|
|
262
263
|
.description('Create a workspace database')
|
|
263
264
|
.argument('<name>', 'Database name')
|
|
265
|
+
.option('--kind <kind>', 'Database kind: libsql (default) or duckdb', 'libsql')
|
|
264
266
|
.option('--from <file.sql>', 'Import a SQL file after creation')
|
|
267
|
+
.option('--no-wait', 'Do not wait for analytical (duckdb) provisioning to finish')
|
|
265
268
|
.option('--json', 'Output as JSON')
|
|
266
269
|
.action(async (name, options) => {
|
|
267
270
|
await (0, database_1.databaseCreate)(name, options);
|
|
268
271
|
});
|
|
272
|
+
database
|
|
273
|
+
.command('show')
|
|
274
|
+
.description('Show database details')
|
|
275
|
+
.argument('<name>', 'Database name')
|
|
276
|
+
.option('--json', 'Output as JSON')
|
|
277
|
+
.action(async (name, options) => {
|
|
278
|
+
await (0, database_1.databaseShow)(name, options);
|
|
279
|
+
});
|
|
269
280
|
database
|
|
270
281
|
.command('delete')
|
|
271
282
|
.description('Delete a workspace database')
|
|
@@ -296,6 +307,7 @@ database
|
|
|
296
307
|
.description('Run a read-only SQL query')
|
|
297
308
|
.argument('<name>', 'Database name')
|
|
298
309
|
.argument('<sql>', 'SQL query')
|
|
310
|
+
.option('--limit <n>', 'Row cap for analytical queries (max 10000)', (value) => parseInt(value, 10))
|
|
299
311
|
.option('--json', 'Output as JSON')
|
|
300
312
|
.action(async (name, sql, options) => {
|
|
301
313
|
await (0, database_1.databaseQuery)(name, sql, options);
|
|
@@ -355,6 +367,53 @@ virtual, and shadow tables are excluded from the count.`)
|
|
|
355
367
|
.action(async (name, file, options) => {
|
|
356
368
|
await (0, database_push_1.databasePush)(name, file, options);
|
|
357
369
|
});
|
|
370
|
+
database
|
|
371
|
+
.command('ingest')
|
|
372
|
+
.description('Load a batch of rows into an analytical database')
|
|
373
|
+
.argument('<name>', 'Database name')
|
|
374
|
+
.argument('<file>', 'Parquet, CSV, or JSONL file to load')
|
|
375
|
+
.requiredOption('--table <table>', 'Target table name')
|
|
376
|
+
.option('--mode <mode>', 'append (default) or replace', 'append')
|
|
377
|
+
.option('--batch-id <id>', 'Idempotency key (default: derived from the file, table, and mode)')
|
|
378
|
+
.option('--json', 'Output as JSON')
|
|
379
|
+
.action(async (name, file, options) => {
|
|
380
|
+
await (0, database_1.databaseIngest)(name, file, { table: options.table, mode: options.mode, batchId: options.batchId, json: options.json });
|
|
381
|
+
});
|
|
382
|
+
database
|
|
383
|
+
.command('drop-table')
|
|
384
|
+
.description('Delete one table from an analytical database and free its space')
|
|
385
|
+
.argument('<name>', 'Database name')
|
|
386
|
+
.argument('<table>', 'Table name')
|
|
387
|
+
.option('-y, --yes', 'Skip confirmation')
|
|
388
|
+
.option('--json', 'Output as JSON')
|
|
389
|
+
.action(async (name, table, options) => {
|
|
390
|
+
await (0, database_1.databaseDropTable)(name, table, options);
|
|
391
|
+
});
|
|
392
|
+
database
|
|
393
|
+
.command('optimize')
|
|
394
|
+
.description('Consolidate an analytical database\'s stored files now')
|
|
395
|
+
.argument('<name>', 'Database name')
|
|
396
|
+
.option('--wait', 'Wait for optimize to finish and print files before/after')
|
|
397
|
+
.option('--json', 'Output as JSON')
|
|
398
|
+
.action(async (name, options) => {
|
|
399
|
+
await (0, database_1.databaseOptimize)(name, options);
|
|
400
|
+
});
|
|
401
|
+
database
|
|
402
|
+
.command('connect')
|
|
403
|
+
.description('Show how to connect to an analytical database')
|
|
404
|
+
.argument('<name>', 'Database name')
|
|
405
|
+
.option('--json', 'Output as JSON')
|
|
406
|
+
.action(async (name, options) => {
|
|
407
|
+
await (0, database_1.databaseConnect)(name, options);
|
|
408
|
+
});
|
|
409
|
+
database
|
|
410
|
+
.command('wake')
|
|
411
|
+
.description('Wake an idle analytical database and wait for it to become active')
|
|
412
|
+
.argument('<name>', 'Database name')
|
|
413
|
+
.option('--json', 'Output as JSON')
|
|
414
|
+
.action(async (name, options) => {
|
|
415
|
+
await (0, database_1.databaseWake)(name, options);
|
|
416
|
+
});
|
|
358
417
|
// =============================================================================
|
|
359
418
|
// project <subcommand>
|
|
360
419
|
// =============================================================================
|
|
@@ -59,12 +59,20 @@ exports.DEFAULT_DATABASE_DATA_PLANE_TIMEOUT_MS = 120_000;
|
|
|
59
59
|
class DatabaseOperationError extends Error {
|
|
60
60
|
code;
|
|
61
61
|
status;
|
|
62
|
-
|
|
62
|
+
// Populated only for `size_limit_exceeded` (the storage-cap refusal
|
|
63
|
+
// `ingest_prepare` and `create` can return) — the one error extra a
|
|
64
|
+
// caller currently needs beyond `code`/`message`/`status` to compose a
|
|
65
|
+
// useful message (spec/#1700 ingest: "surfaced with the limit").
|
|
66
|
+
sizeLimitBytes;
|
|
67
|
+
constructor(code, message, status, sizeLimitBytes) {
|
|
63
68
|
super(message);
|
|
64
69
|
this.code = code;
|
|
65
70
|
if (status !== undefined) {
|
|
66
71
|
this.status = status;
|
|
67
72
|
}
|
|
73
|
+
if (sizeLimitBytes !== undefined) {
|
|
74
|
+
this.sizeLimitBytes = sizeLimitBytes;
|
|
75
|
+
}
|
|
68
76
|
// A public command error is deliberately data-only. In particular, it
|
|
69
77
|
// must never retain an upstream stack, request, response, config, or
|
|
70
78
|
// cause that could contain either control- or data-plane credentials.
|
|
@@ -89,7 +97,10 @@ function safeDatabaseRequestError(error) {
|
|
|
89
97
|
const message = code === 'unauthenticated'
|
|
90
98
|
? `${appMessage} Run solidactions login to authenticate again.`
|
|
91
99
|
: appMessage;
|
|
92
|
-
|
|
100
|
+
const sizeLimitBytes = typeof response?.data?.size_limit_bytes === 'number'
|
|
101
|
+
? response.data.size_limit_bytes
|
|
102
|
+
: undefined;
|
|
103
|
+
return new DatabaseOperationError(code, message, status, sizeLimitBytes);
|
|
93
104
|
}
|
|
94
105
|
function positiveTimeout(value, fallback) {
|
|
95
106
|
return typeof value === 'number' && Number.isFinite(value) && value > 0
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/utils/database-ingest-digest.ts
|
|
3
|
+
//
|
|
4
|
+
// RFC 8785 (JCS) canonicalization, restricted to the fixed, flat ingest
|
|
5
|
+
// identity object spec §6.4 defines — every field is a string except the
|
|
6
|
+
// literal integer `v: 1`, so a full JCS number-formatting implementation
|
|
7
|
+
// is unnecessary; lexicographic key sorting plus JSON's own string
|
|
8
|
+
// escaping is JCS-compliant for this shape. Laravel
|
|
9
|
+
// (App\Domains\Databases\Analytical\Support\CanonicalBatchDigest) computes
|
|
10
|
+
// the identical digest over the identical object shape server-side; this
|
|
11
|
+
// file and its Laravel counterpart MUST stay byte-for-byte in sync — do
|
|
12
|
+
// not "improve" the canonicalization here without updating both sides.
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.canonicalIngestDigest = canonicalIngestDigest;
|
|
15
|
+
exports.defaultIngestBatchId = defaultIngestBatchId;
|
|
16
|
+
exports.ingestFormatFromExtension = ingestFormatFromExtension;
|
|
17
|
+
const crypto_1 = require("crypto");
|
|
18
|
+
function canonicalizeFlatObject(fields) {
|
|
19
|
+
const keys = Object.keys(fields).sort();
|
|
20
|
+
const parts = keys.map((key) => `${JSON.stringify(key)}:${JSON.stringify(fields[key])}`);
|
|
21
|
+
return `{${parts.join(',')}}`;
|
|
22
|
+
}
|
|
23
|
+
/** The §6.4 canonical digest: lower-case hex sha256 of the JCS body. */
|
|
24
|
+
function canonicalIngestDigest(identity) {
|
|
25
|
+
const canonical = canonicalizeFlatObject({
|
|
26
|
+
v: 1,
|
|
27
|
+
database_id: identity.databaseId,
|
|
28
|
+
// NOTE: JS `.trim()` strips a wider whitespace set than PHP `trim()`
|
|
29
|
+
// (e.g. NBSP/BOM/OGHAM SPACE MARK/U+3000) — inert here, since the
|
|
30
|
+
// server PHP-trims the same table name before this digest is ever
|
|
31
|
+
// computed server-side, so a character JS strips but PHP doesn't
|
|
32
|
+
// fails the `^[a-z][a-z0-9_]{0,62}$` gate with a 422 first. Do not
|
|
33
|
+
// "fix" this asymmetry without re-verifying byte-for-byte parity
|
|
34
|
+
// with the PHP canonical digest (`CanonicalBatchDigest`).
|
|
35
|
+
table: identity.table.trim().toLowerCase(),
|
|
36
|
+
mode: identity.mode,
|
|
37
|
+
ack: 'durable',
|
|
38
|
+
format: identity.format,
|
|
39
|
+
content_sha256: identity.contentSha256.toLowerCase(),
|
|
40
|
+
});
|
|
41
|
+
return (0, crypto_1.createHash)('sha256').update(canonical, 'utf8').digest('hex');
|
|
42
|
+
}
|
|
43
|
+
/** The CLI's default batch id: the first 32 hex chars of the canonical digest. */
|
|
44
|
+
function defaultIngestBatchId(identity) {
|
|
45
|
+
return canonicalIngestDigest(identity).slice(0, 32);
|
|
46
|
+
}
|
|
47
|
+
function ingestFormatFromExtension(filePath) {
|
|
48
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
49
|
+
if (ext === 'parquet')
|
|
50
|
+
return 'parquet';
|
|
51
|
+
if (ext === 'csv')
|
|
52
|
+
return 'csv';
|
|
53
|
+
if (ext === 'jsonl')
|
|
54
|
+
return 'jsonl';
|
|
55
|
+
throw new Error(`Unsupported ingest file extension ".${ext}" — use .parquet, .csv, or .jsonl.`);
|
|
56
|
+
}
|
|
@@ -49,6 +49,13 @@ exports.MUTATING_COMMANDS = new Set([
|
|
|
49
49
|
'database exec',
|
|
50
50
|
'database import',
|
|
51
51
|
'database push',
|
|
52
|
+
'database ingest',
|
|
53
|
+
'database drop-table',
|
|
54
|
+
// `optimize` dispatches a real server-side operation that rewrites the
|
|
55
|
+
// database's stored files (`StartOptimizeOperation` — a job, not just a
|
|
56
|
+
// read of existing state), the same class of deliberate write action as
|
|
57
|
+
// `run start`/`skill exec`.
|
|
58
|
+
'database optimize',
|
|
52
59
|
// Plain `database pull` is read-only (GET, writes a local file only —
|
|
53
60
|
// same family as project/env/doc/skill pull). But `--writable`
|
|
54
61
|
// (databaseWritablePullWithConfig, src/commands/database.ts:1320) mints
|
|
@@ -100,8 +107,17 @@ exports.READONLY_COMMANDS = new Set([
|
|
|
100
107
|
// Runs locally; does not touch server state for any workspace.
|
|
101
108
|
'dev',
|
|
102
109
|
'database list',
|
|
110
|
+
'database show',
|
|
103
111
|
'database schema',
|
|
104
112
|
'database query',
|
|
113
|
+
// `connect` never calls the server's admission gate — it is a pure,
|
|
114
|
+
// synchronous read of the database row (no side effects at all).
|
|
115
|
+
'database connect',
|
|
116
|
+
// `wake` is the same admission-only call `query` already makes
|
|
117
|
+
// incidentally (both can dispatch the async wake job, never touching
|
|
118
|
+
// application data) — its whole purpose is that read-intent pre-warm,
|
|
119
|
+
// spec §4.2.
|
|
120
|
+
'database wake',
|
|
105
121
|
// Downloads a dump and writes it to a local file only, like the `pull`
|
|
106
122
|
// family below — the data-plane request happens to be a POST, but no
|
|
107
123
|
// server state changes.
|