@aigne/afs-sqlite 1.11.0-beta.6 → 1.11.0-beta.8
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/dist/_virtual/rolldown_runtime.mjs +7 -0
- package/dist/actions/built-in.cjs +870 -16
- package/dist/actions/built-in.d.cts.map +1 -1
- package/dist/actions/built-in.d.mts.map +1 -1
- package/dist/actions/built-in.mjs +870 -16
- package/dist/actions/built-in.mjs.map +1 -1
- package/dist/actions/operators.cjs +156 -0
- package/dist/actions/operators.mjs +157 -0
- package/dist/actions/operators.mjs.map +1 -0
- package/dist/actions/types.cjs +33 -0
- package/dist/actions/types.d.cts +22 -0
- package/dist/actions/types.d.cts.map +1 -1
- package/dist/actions/types.d.mts +22 -0
- package/dist/actions/types.d.mts.map +1 -1
- package/dist/actions/types.mjs +32 -0
- package/dist/actions/types.mjs.map +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +9 -36
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +9 -36
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +1 -1
- package/dist/config.mjs.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/node/builder.cjs +11 -8
- package/dist/node/builder.d.cts.map +1 -1
- package/dist/node/builder.d.mts.map +1 -1
- package/dist/node/builder.mjs +11 -8
- package/dist/node/builder.mjs.map +1 -1
- package/dist/operations/query-builder.cjs +2 -2
- package/dist/operations/query-builder.d.cts.map +1 -1
- package/dist/operations/query-builder.d.mts.map +1 -1
- package/dist/operations/query-builder.mjs +2 -2
- package/dist/operations/query-builder.mjs.map +1 -1
- package/dist/operations/search.cjs +1 -1
- package/dist/operations/search.mjs +1 -1
- package/dist/operations/search.mjs.map +1 -1
- package/dist/sqlite-afs.cjs +268 -26
- package/dist/sqlite-afs.d.cts +50 -48
- package/dist/sqlite-afs.d.cts.map +1 -1
- package/dist/sqlite-afs.d.mts +50 -48
- package/dist/sqlite-afs.d.mts.map +1 -1
- package/dist/sqlite-afs.mjs +270 -27
- package/dist/sqlite-afs.mjs.map +1 -1
- package/package.json +5 -4
package/dist/sqlite-afs.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __require } from "./_virtual/rolldown_runtime.mjs";
|
|
1
2
|
import { registerBuiltInActions } from "./actions/built-in.mjs";
|
|
2
3
|
import { ActionsRegistry } from "./actions/registry.mjs";
|
|
3
4
|
import { sqliteAFSConfigSchema } from "./config.mjs";
|
|
@@ -8,7 +9,8 @@ import { SchemaService } from "./schema/service.mjs";
|
|
|
8
9
|
import { __decorate } from "./_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.mjs";
|
|
9
10
|
import { initDatabase, sql } from "@aigne/sqlite";
|
|
10
11
|
import { AFSNotFoundError } from "@aigne/afs";
|
|
11
|
-
import {
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { AFSBaseProvider, Actions, Delete, Explain, List, Meta, Read, Search, Stat, Write } from "@aigne/afs/provider";
|
|
12
14
|
|
|
13
15
|
//#region src/sqlite-afs.ts
|
|
14
16
|
/**
|
|
@@ -31,6 +33,16 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
31
33
|
constructor(options) {
|
|
32
34
|
super();
|
|
33
35
|
this.options = options;
|
|
36
|
+
if (options.localPath && !options.url) options.url = `file:${options.localPath}`;
|
|
37
|
+
if (options.url.startsWith("file:")) {
|
|
38
|
+
const { existsSync, mkdirSync, writeFileSync } = __require("node:fs");
|
|
39
|
+
const { dirname } = __require("node:path");
|
|
40
|
+
const dbPath = options.url.slice(5);
|
|
41
|
+
if (!existsSync(dbPath)) {
|
|
42
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
43
|
+
writeFileSync(dbPath, "");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
34
46
|
this.name = options.name ?? "sqlite-afs";
|
|
35
47
|
this.description = options.description ?? `SQLite database: ${options.url}`;
|
|
36
48
|
this.accessMode = options.accessMode ?? "readwrite";
|
|
@@ -44,11 +56,21 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
44
56
|
static schema() {
|
|
45
57
|
return sqliteAFSConfigSchema;
|
|
46
58
|
}
|
|
59
|
+
static manifest() {
|
|
60
|
+
return {
|
|
61
|
+
name: "sqlite",
|
|
62
|
+
description: "Mount a SQLite database as a virtual filesystem",
|
|
63
|
+
uriTemplate: "sqlite://{localPath+}",
|
|
64
|
+
category: "database",
|
|
65
|
+
schema: z.object({ localPath: z.string() }),
|
|
66
|
+
tags: ["sqlite", "database"]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
47
69
|
/**
|
|
48
70
|
* Loads a module instance from configuration
|
|
49
71
|
*/
|
|
50
|
-
static async load({
|
|
51
|
-
return new SQLiteAFS(sqliteAFSConfigSchema.parse(
|
|
72
|
+
static async load({ config } = {}) {
|
|
73
|
+
return new SQLiteAFS(sqliteAFSConfigSchema.parse(config));
|
|
52
74
|
}
|
|
53
75
|
/**
|
|
54
76
|
* Initializes the database connection and schema service
|
|
@@ -78,33 +100,29 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
78
100
|
}
|
|
79
101
|
/**
|
|
80
102
|
* List all tables
|
|
103
|
+
* Note: list() returns only children, never the path itself (per new semantics)
|
|
81
104
|
*/
|
|
82
105
|
async listTablesHandler(_ctx) {
|
|
83
106
|
await this.ensureInitialized();
|
|
84
|
-
|
|
85
|
-
return { data: [buildRootEntry(await this.schemaService.getAllSchemas(), { basePath: "" }), ...result.data] };
|
|
107
|
+
return { data: (await this.crud.listTables()).data };
|
|
86
108
|
}
|
|
87
109
|
/**
|
|
88
110
|
* List rows in a table
|
|
111
|
+
* Note: list() returns only children (rows), never the table itself (per new semantics)
|
|
89
112
|
*/
|
|
90
113
|
async listTableHandler(ctx) {
|
|
91
114
|
await this.ensureInitialized();
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const result = await this.crud.listTable(ctx.params.table, ctx.options);
|
|
95
|
-
const rowCount = (await this.db.all(sql.raw(`SELECT COUNT(*) as count FROM "${ctx.params.table}"`)))[0]?.count ?? 0;
|
|
96
|
-
return { data: [buildTableEntry(ctx.params.table, schema, {
|
|
97
|
-
basePath: "",
|
|
98
|
-
rowCount
|
|
99
|
-
}), ...result.data] };
|
|
115
|
+
if (!await this.schemaService.getSchema(ctx.params.table)) throw new AFSNotFoundError(`/${ctx.params.table}`);
|
|
116
|
+
return { data: (await this.crud.listTable(ctx.params.table, ctx.options)).data };
|
|
100
117
|
}
|
|
101
118
|
/**
|
|
102
|
-
* List a row
|
|
119
|
+
* List a row - rows are leaf nodes with no children
|
|
120
|
+
* Note: list() returns only children, never the path itself (per new semantics)
|
|
103
121
|
*/
|
|
104
122
|
async listRowHandler(ctx) {
|
|
105
123
|
await this.ensureInitialized();
|
|
106
|
-
|
|
107
|
-
return { data:
|
|
124
|
+
if (!(await this.crud.readRow(ctx.params.table, ctx.params.pk)).data) throw new AFSNotFoundError(`/${ctx.params.table}/${ctx.params.pk}`);
|
|
125
|
+
return { data: [] };
|
|
108
126
|
}
|
|
109
127
|
/**
|
|
110
128
|
* List actions for a row
|
|
@@ -165,17 +183,80 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
165
183
|
path: "/.meta",
|
|
166
184
|
content: {
|
|
167
185
|
type: "sqlite",
|
|
168
|
-
url: this.options.url,
|
|
169
186
|
tableCount: schemas.size,
|
|
170
187
|
tables
|
|
171
188
|
},
|
|
172
|
-
|
|
189
|
+
meta: {
|
|
173
190
|
childrenCount: tables.length,
|
|
174
191
|
tables: tables.map((t) => t.name)
|
|
175
192
|
}
|
|
176
193
|
};
|
|
177
194
|
}
|
|
178
195
|
/**
|
|
196
|
+
* Read capabilities manifest
|
|
197
|
+
* Returns information about available actions at different levels
|
|
198
|
+
*/
|
|
199
|
+
async readCapabilitiesHandler(_ctx) {
|
|
200
|
+
await this.ensureInitialized();
|
|
201
|
+
const actionCatalogs = [];
|
|
202
|
+
const rootActions = this.actions.listWithInfo({ rootLevel: true }, { schemaService: this.schemaService });
|
|
203
|
+
if (rootActions.length > 0) actionCatalogs.push({
|
|
204
|
+
kind: "sqlite:root",
|
|
205
|
+
description: "Database-level operations",
|
|
206
|
+
catalog: rootActions.map((a) => ({
|
|
207
|
+
name: a.name,
|
|
208
|
+
description: a.description,
|
|
209
|
+
inputSchema: a.inputSchema
|
|
210
|
+
})),
|
|
211
|
+
discovery: {
|
|
212
|
+
pathTemplate: "/.actions",
|
|
213
|
+
note: "Available at database root"
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
const tableActions = this.actions.listWithInfo({ tableLevel: true }, { schemaService: this.schemaService });
|
|
217
|
+
if (tableActions.length > 0) actionCatalogs.push({
|
|
218
|
+
kind: "sqlite:table",
|
|
219
|
+
description: "Table-level operations",
|
|
220
|
+
catalog: tableActions.map((a) => ({
|
|
221
|
+
name: a.name,
|
|
222
|
+
description: a.description,
|
|
223
|
+
inputSchema: a.inputSchema
|
|
224
|
+
})),
|
|
225
|
+
discovery: {
|
|
226
|
+
pathTemplate: "/:table/.actions",
|
|
227
|
+
note: "Replace :table with actual table name"
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
const rowActions = this.actions.listWithInfo({ rowLevel: true }, { schemaService: this.schemaService });
|
|
231
|
+
if (rowActions.length > 0) actionCatalogs.push({
|
|
232
|
+
kind: "sqlite:row",
|
|
233
|
+
description: "Row-level operations",
|
|
234
|
+
catalog: rowActions.map((a) => ({
|
|
235
|
+
name: a.name,
|
|
236
|
+
description: a.description,
|
|
237
|
+
inputSchema: a.inputSchema
|
|
238
|
+
})),
|
|
239
|
+
discovery: {
|
|
240
|
+
pathTemplate: "/:table/:pk/.actions",
|
|
241
|
+
note: "Replace :table with table name, :pk with primary key value"
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return {
|
|
245
|
+
id: "/.meta/.capabilities",
|
|
246
|
+
path: "/.meta/.capabilities",
|
|
247
|
+
content: {
|
|
248
|
+
schemaVersion: 1,
|
|
249
|
+
provider: this.name,
|
|
250
|
+
version: "1.0.0",
|
|
251
|
+
description: this.description,
|
|
252
|
+
tools: [],
|
|
253
|
+
actions: actionCatalogs,
|
|
254
|
+
operations: this.getOperationsDeclaration()
|
|
255
|
+
},
|
|
256
|
+
meta: { kind: "afs:capabilities" }
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
179
260
|
* Read table (directory) entry
|
|
180
261
|
*/
|
|
181
262
|
async readTableHandler(ctx) {
|
|
@@ -224,7 +305,7 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
224
305
|
})),
|
|
225
306
|
rowCount
|
|
226
307
|
},
|
|
227
|
-
|
|
308
|
+
meta: {
|
|
228
309
|
table: ctx.params.table,
|
|
229
310
|
description: `Table "${ctx.params.table}" with ${columns.length} columns`,
|
|
230
311
|
childrenCount: rowCount,
|
|
@@ -276,7 +357,7 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
276
357
|
referencesColumn: fk.to
|
|
277
358
|
}))
|
|
278
359
|
},
|
|
279
|
-
|
|
360
|
+
meta: {
|
|
280
361
|
table: ctx.params.table,
|
|
281
362
|
primaryKeyValue: ctx.params.pk,
|
|
282
363
|
columns: schema.columns.map((col) => col.name)
|
|
@@ -355,12 +436,13 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
355
436
|
const schemas = await this.schemaService.getAllSchemas();
|
|
356
437
|
const actions = this.actions.listWithInfo({ rootLevel: true }, { schemaService: this.schemaService });
|
|
357
438
|
return { data: {
|
|
439
|
+
id: "/",
|
|
358
440
|
path: "/",
|
|
359
|
-
childrenCount: schemas.size,
|
|
360
441
|
meta: {
|
|
361
442
|
kind: "sqlite:database",
|
|
362
443
|
kinds: ["sqlite:database", "afs:node"],
|
|
363
|
-
tableCount: schemas.size
|
|
444
|
+
tableCount: schemas.size,
|
|
445
|
+
childrenCount: schemas.size
|
|
364
446
|
},
|
|
365
447
|
actions: actions.length > 0 ? actions.map((a) => ({
|
|
366
448
|
name: a.name,
|
|
@@ -381,15 +463,23 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
381
463
|
tableName: ctx.params.table,
|
|
382
464
|
schemaService: this.schemaService
|
|
383
465
|
});
|
|
466
|
+
const columns = schema.columns.map((col) => ({
|
|
467
|
+
name: col.name,
|
|
468
|
+
type: col.type,
|
|
469
|
+
nullable: !col.notnull,
|
|
470
|
+
primaryKey: col.pk > 0
|
|
471
|
+
}));
|
|
384
472
|
return { data: {
|
|
473
|
+
id: ctx.params.table,
|
|
385
474
|
path: `/${ctx.params.table}`,
|
|
386
|
-
childrenCount: rowCount,
|
|
387
475
|
meta: {
|
|
388
476
|
kind: "sqlite:table",
|
|
389
477
|
kinds: ["sqlite:table", "afs:node"],
|
|
390
478
|
table: ctx.params.table,
|
|
391
479
|
columnCount: schema.columns.length,
|
|
392
|
-
|
|
480
|
+
columns,
|
|
481
|
+
primaryKey: schema.primaryKey[0],
|
|
482
|
+
childrenCount: rowCount
|
|
393
483
|
},
|
|
394
484
|
actions: actions.length > 0 ? actions.map((a) => ({
|
|
395
485
|
name: a.name,
|
|
@@ -410,14 +500,23 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
410
500
|
tableName: ctx.params.table,
|
|
411
501
|
schemaService: this.schemaService
|
|
412
502
|
});
|
|
503
|
+
const columns = schema.columns.map((col) => ({
|
|
504
|
+
name: col.name,
|
|
505
|
+
type: col.type,
|
|
506
|
+
nullable: !col.notnull,
|
|
507
|
+
primaryKey: col.pk > 0
|
|
508
|
+
}));
|
|
413
509
|
return { data: {
|
|
510
|
+
id: ctx.params.pk,
|
|
414
511
|
path: `/${ctx.params.table}/${ctx.params.pk}`,
|
|
415
|
-
childrenCount: 0,
|
|
416
512
|
meta: {
|
|
417
513
|
kind: "sqlite:row",
|
|
418
514
|
kinds: ["sqlite:row", "afs:node"],
|
|
419
515
|
table: ctx.params.table,
|
|
420
|
-
primaryKey: ctx.params.pk
|
|
516
|
+
primaryKey: ctx.params.pk,
|
|
517
|
+
columnCount: schema.columns.length,
|
|
518
|
+
columns,
|
|
519
|
+
childrenCount: 0
|
|
421
520
|
},
|
|
422
521
|
actions: actions.length > 0 ? actions.map((a) => ({
|
|
423
522
|
name: a.name,
|
|
@@ -426,6 +525,139 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
426
525
|
} };
|
|
427
526
|
}
|
|
428
527
|
/**
|
|
528
|
+
* Explain root (database level)
|
|
529
|
+
*/
|
|
530
|
+
async explainRootHandler(ctx) {
|
|
531
|
+
await this.ensureInitialized();
|
|
532
|
+
const format = ctx.options?.format || "markdown";
|
|
533
|
+
const schemas = await this.schemaService.getAllSchemas();
|
|
534
|
+
const tables = Array.from(schemas.values());
|
|
535
|
+
const lines = [];
|
|
536
|
+
if (format === "markdown") {
|
|
537
|
+
lines.push(`# ${this.name}`);
|
|
538
|
+
lines.push("");
|
|
539
|
+
lines.push(`**Type:** SQLite Database`);
|
|
540
|
+
lines.push(`**Tables:** ${tables.length}`);
|
|
541
|
+
lines.push("");
|
|
542
|
+
if (tables.length > 0) {
|
|
543
|
+
lines.push("## Tables");
|
|
544
|
+
lines.push("");
|
|
545
|
+
lines.push("| Table | Columns | Primary Key |");
|
|
546
|
+
lines.push("|-------|---------|-------------|");
|
|
547
|
+
for (const table of tables) {
|
|
548
|
+
const pk = table.primaryKey.join(", ") || "rowid";
|
|
549
|
+
lines.push(`| ${table.name} | ${table.columns.length} | ${pk} |`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
} else {
|
|
553
|
+
lines.push(`${this.name} (SQLite Database)`);
|
|
554
|
+
lines.push(`Tables: ${tables.length}`);
|
|
555
|
+
for (const table of tables) lines.push(` - ${table.name} (${table.columns.length} columns)`);
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
content: lines.join("\n"),
|
|
559
|
+
format
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Explain a table
|
|
564
|
+
*/
|
|
565
|
+
async explainTableHandler(ctx) {
|
|
566
|
+
await this.ensureInitialized();
|
|
567
|
+
const format = ctx.options?.format || "markdown";
|
|
568
|
+
const schema = await this.schemaService.getSchema(ctx.params.table);
|
|
569
|
+
if (!schema) throw new AFSNotFoundError(`/${ctx.params.table}`);
|
|
570
|
+
const rowCount = (await this.db.all(sql.raw(`SELECT COUNT(*) as count FROM "${ctx.params.table}"`)))[0]?.count ?? 0;
|
|
571
|
+
const lines = [];
|
|
572
|
+
if (format === "markdown") {
|
|
573
|
+
lines.push(`# ${ctx.params.table}`);
|
|
574
|
+
lines.push("");
|
|
575
|
+
lines.push(`**Type:** SQLite Table`);
|
|
576
|
+
lines.push(`**Rows:** ${rowCount}`);
|
|
577
|
+
lines.push(`**Primary Key:** ${schema.primaryKey.join(", ") || "rowid"}`);
|
|
578
|
+
lines.push("");
|
|
579
|
+
lines.push("## Columns");
|
|
580
|
+
lines.push("");
|
|
581
|
+
lines.push("| Column | Type | Nullable | Primary Key | Default |");
|
|
582
|
+
lines.push("|--------|------|----------|-------------|---------|");
|
|
583
|
+
for (const col of schema.columns) {
|
|
584
|
+
const nullable = col.notnull ? "NO" : "YES";
|
|
585
|
+
const pk = col.pk > 0 ? "YES" : "";
|
|
586
|
+
const dflt = col.dfltValue !== null && col.dfltValue !== void 0 ? String(col.dfltValue) : "";
|
|
587
|
+
lines.push(`| ${col.name} | ${col.type} | ${nullable} | ${pk} | ${dflt} |`);
|
|
588
|
+
}
|
|
589
|
+
if (schema.indexes.length > 0) {
|
|
590
|
+
lines.push("");
|
|
591
|
+
lines.push("## Indexes");
|
|
592
|
+
lines.push("");
|
|
593
|
+
for (const idx of schema.indexes) {
|
|
594
|
+
const uniqueStr = idx.unique ? " (UNIQUE)" : "";
|
|
595
|
+
lines.push(`- **${idx.name}**${uniqueStr}`);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (schema.foreignKeys.length > 0) {
|
|
599
|
+
lines.push("");
|
|
600
|
+
lines.push("## Foreign Keys");
|
|
601
|
+
lines.push("");
|
|
602
|
+
for (const fk of schema.foreignKeys) lines.push(`- \`${fk.from}\` → \`${fk.table}\`(\`${fk.to}\`) ON DELETE ${fk.onDelete}`);
|
|
603
|
+
}
|
|
604
|
+
} else {
|
|
605
|
+
lines.push(`${ctx.params.table} (SQLite Table)`);
|
|
606
|
+
lines.push(`Rows: ${rowCount}`);
|
|
607
|
+
lines.push(`Primary Key: ${schema.primaryKey.join(", ") || "rowid"}`);
|
|
608
|
+
lines.push(`Columns: ${schema.columns.map((c) => `${c.name} (${c.type})`).join(", ")}`);
|
|
609
|
+
if (schema.indexes.length > 0) lines.push(`Indexes: ${schema.indexes.map((i) => i.name).join(", ")}`);
|
|
610
|
+
if (schema.foreignKeys.length > 0) lines.push(`Foreign Keys: ${schema.foreignKeys.map((fk) => `${fk.from} → ${fk.table}(${fk.to})`).join(", ")}`);
|
|
611
|
+
}
|
|
612
|
+
return {
|
|
613
|
+
content: lines.join("\n"),
|
|
614
|
+
format
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Explain a row
|
|
619
|
+
*/
|
|
620
|
+
async explainRowHandler(ctx) {
|
|
621
|
+
await this.ensureInitialized();
|
|
622
|
+
const format = ctx.options?.format || "markdown";
|
|
623
|
+
const schema = await this.schemaService.getSchema(ctx.params.table);
|
|
624
|
+
if (!schema) throw new AFSNotFoundError(`/${ctx.params.table}`);
|
|
625
|
+
const result = await this.crud.readRow(ctx.params.table, ctx.params.pk);
|
|
626
|
+
if (!result.data) throw new AFSNotFoundError(`/${ctx.params.table}/${ctx.params.pk}`);
|
|
627
|
+
const rowContent = result.data.content;
|
|
628
|
+
const pkColumn = schema.primaryKey[0] ?? "rowid";
|
|
629
|
+
const lines = [];
|
|
630
|
+
if (format === "markdown") {
|
|
631
|
+
lines.push(`# ${ctx.params.table}/${ctx.params.pk}`);
|
|
632
|
+
lines.push("");
|
|
633
|
+
lines.push(`**Table:** ${ctx.params.table}`);
|
|
634
|
+
lines.push(`**Primary Key:** ${pkColumn} = ${ctx.params.pk}`);
|
|
635
|
+
lines.push("");
|
|
636
|
+
if (rowContent) {
|
|
637
|
+
lines.push("## Values");
|
|
638
|
+
lines.push("");
|
|
639
|
+
lines.push("| Column | Value |");
|
|
640
|
+
lines.push("|--------|-------|");
|
|
641
|
+
for (const col of schema.columns) {
|
|
642
|
+
const val = rowContent[col.name];
|
|
643
|
+
const displayVal = val === null || val === void 0 ? "*null*" : truncateValue(String(val), 100);
|
|
644
|
+
lines.push(`| ${col.name} | ${displayVal} |`);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
} else {
|
|
648
|
+
lines.push(`${ctx.params.table}/${ctx.params.pk} (SQLite Row)`);
|
|
649
|
+
lines.push(`Table: ${ctx.params.table}, ${pkColumn} = ${ctx.params.pk}`);
|
|
650
|
+
if (rowContent) for (const col of schema.columns) {
|
|
651
|
+
const val = rowContent[col.name];
|
|
652
|
+
lines.push(` ${col.name}: ${val === null || val === void 0 ? "null" : truncateValue(String(val), 100)}`);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return {
|
|
656
|
+
content: lines.join("\n"),
|
|
657
|
+
format
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
429
661
|
* Execute action via exec (row-level)
|
|
430
662
|
*/
|
|
431
663
|
async handleRowActionExec(ctx, args) {
|
|
@@ -562,13 +794,14 @@ var SQLiteAFS = class SQLiteAFS extends AFSBaseProvider {
|
|
|
562
794
|
}
|
|
563
795
|
};
|
|
564
796
|
__decorate([List("/")], SQLiteAFS.prototype, "listTablesHandler", null);
|
|
565
|
-
__decorate([List("/:table"
|
|
797
|
+
__decorate([List("/:table")], SQLiteAFS.prototype, "listTableHandler", null);
|
|
566
798
|
__decorate([List("/:table/:pk")], SQLiteAFS.prototype, "listRowHandler", null);
|
|
567
799
|
__decorate([Actions("/:table/:pk")], SQLiteAFS.prototype, "listActionsHandler", null);
|
|
568
800
|
__decorate([Actions("/:table")], SQLiteAFS.prototype, "listTableActionsHandler", null);
|
|
569
801
|
__decorate([Actions("/")], SQLiteAFS.prototype, "listRootActionsHandler", null);
|
|
570
802
|
__decorate([Read("/")], SQLiteAFS.prototype, "readRootHandler", null);
|
|
571
803
|
__decorate([Meta("/")], SQLiteAFS.prototype, "readRootMetaHandler", null);
|
|
804
|
+
__decorate([Read("/.meta/.capabilities")], SQLiteAFS.prototype, "readCapabilitiesHandler", null);
|
|
572
805
|
__decorate([Read("/:table")], SQLiteAFS.prototype, "readTableHandler", null);
|
|
573
806
|
__decorate([Meta("/:table")], SQLiteAFS.prototype, "readTableMetaHandler", null);
|
|
574
807
|
__decorate([Read("/:table/:pk")], SQLiteAFS.prototype, "readRowHandler", null);
|
|
@@ -586,9 +819,19 @@ __decorate([Search("/:table")], SQLiteAFS.prototype, "searchTableHandler", null)
|
|
|
586
819
|
__decorate([Stat("/")], SQLiteAFS.prototype, "statRootHandler", null);
|
|
587
820
|
__decorate([Stat("/:table")], SQLiteAFS.prototype, "statTableHandler", null);
|
|
588
821
|
__decorate([Stat("/:table/:pk")], SQLiteAFS.prototype, "statRowHandler", null);
|
|
822
|
+
__decorate([Explain("/")], SQLiteAFS.prototype, "explainRootHandler", null);
|
|
823
|
+
__decorate([Explain("/:table")], SQLiteAFS.prototype, "explainTableHandler", null);
|
|
824
|
+
__decorate([Explain("/:table/:pk")], SQLiteAFS.prototype, "explainRowHandler", null);
|
|
589
825
|
__decorate([Actions.Exec("/:table/:pk")], SQLiteAFS.prototype, "handleRowActionExec", null);
|
|
590
826
|
__decorate([Actions.Exec("/:table")], SQLiteAFS.prototype, "handleTableActionExec", null);
|
|
591
827
|
__decorate([Actions.Exec("/")], SQLiteAFS.prototype, "handleRootActionExec", null);
|
|
828
|
+
/**
|
|
829
|
+
* Truncate a string value for display purposes.
|
|
830
|
+
*/
|
|
831
|
+
function truncateValue(value, maxLength) {
|
|
832
|
+
if (value.length <= maxLength) return value;
|
|
833
|
+
return `${value.slice(0, maxLength)}...`;
|
|
834
|
+
}
|
|
592
835
|
|
|
593
836
|
//#endregion
|
|
594
837
|
export { SQLiteAFS };
|