@aigne/afs-sqlite 1.11.0-beta.5 → 1.11.0-beta.7

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 (86) hide show
  1. package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.cjs +11 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.mjs +10 -0
  3. package/dist/actions/built-in.cjs +1262 -15
  4. package/dist/actions/built-in.d.cts.map +1 -1
  5. package/dist/actions/built-in.d.mts.map +1 -1
  6. package/dist/actions/built-in.mjs +1262 -15
  7. package/dist/actions/built-in.mjs.map +1 -1
  8. package/dist/actions/operators.cjs +156 -0
  9. package/dist/actions/operators.mjs +157 -0
  10. package/dist/actions/operators.mjs.map +1 -0
  11. package/dist/actions/registry.cjs +35 -3
  12. package/dist/actions/registry.d.cts +36 -17
  13. package/dist/actions/registry.d.cts.map +1 -1
  14. package/dist/actions/registry.d.mts +36 -17
  15. package/dist/actions/registry.d.mts.map +1 -1
  16. package/dist/actions/registry.mjs +35 -3
  17. package/dist/actions/registry.mjs.map +1 -1
  18. package/dist/actions/types.cjs +33 -0
  19. package/dist/actions/types.d.cts +46 -5
  20. package/dist/actions/types.d.cts.map +1 -1
  21. package/dist/actions/types.d.mts +46 -5
  22. package/dist/actions/types.d.mts.map +1 -1
  23. package/dist/actions/types.mjs +32 -0
  24. package/dist/actions/types.mjs.map +1 -0
  25. package/dist/config.d.cts.map +1 -1
  26. package/dist/config.d.mts.map +1 -1
  27. package/dist/index.cjs +4 -3
  28. package/dist/index.d.cts +4 -3
  29. package/dist/index.d.mts +4 -3
  30. package/dist/index.mjs +3 -2
  31. package/dist/node/builder.cjs +74 -91
  32. package/dist/node/builder.d.cts +11 -15
  33. package/dist/node/builder.d.cts.map +1 -1
  34. package/dist/node/builder.d.mts +11 -15
  35. package/dist/node/builder.d.mts.map +1 -1
  36. package/dist/node/builder.mjs +72 -89
  37. package/dist/node/builder.mjs.map +1 -1
  38. package/dist/operations/crud.cjs +24 -68
  39. package/dist/operations/crud.d.cts +23 -38
  40. package/dist/operations/crud.d.cts.map +1 -1
  41. package/dist/operations/crud.d.mts +23 -38
  42. package/dist/operations/crud.d.mts.map +1 -1
  43. package/dist/operations/crud.mjs +25 -69
  44. package/dist/operations/crud.mjs.map +1 -1
  45. package/dist/operations/query-builder.cjs +2 -2
  46. package/dist/operations/query-builder.d.cts.map +1 -1
  47. package/dist/operations/query-builder.d.mts.map +1 -1
  48. package/dist/operations/query-builder.mjs +2 -2
  49. package/dist/operations/query-builder.mjs.map +1 -1
  50. package/dist/operations/search.cjs +5 -11
  51. package/dist/operations/search.d.cts +19 -23
  52. package/dist/operations/search.d.cts.map +1 -1
  53. package/dist/operations/search.d.mts +19 -23
  54. package/dist/operations/search.d.mts.map +1 -1
  55. package/dist/operations/search.mjs +5 -11
  56. package/dist/operations/search.mjs.map +1 -1
  57. package/dist/router/path-router.cjs +7 -15
  58. package/dist/router/path-router.d.cts +4 -7
  59. package/dist/router/path-router.d.cts.map +1 -1
  60. package/dist/router/path-router.d.mts +4 -7
  61. package/dist/router/path-router.d.mts.map +1 -1
  62. package/dist/router/path-router.mjs +7 -15
  63. package/dist/router/path-router.mjs.map +1 -1
  64. package/dist/router/types.d.cts.map +1 -1
  65. package/dist/router/types.d.mts.map +1 -1
  66. package/dist/schema/introspector.d.cts +19 -19
  67. package/dist/schema/introspector.d.cts.map +1 -1
  68. package/dist/schema/introspector.d.mts +19 -19
  69. package/dist/schema/introspector.d.mts.map +1 -1
  70. package/dist/schema/service.cjs +86 -0
  71. package/dist/schema/service.d.cts +52 -0
  72. package/dist/schema/service.d.cts.map +1 -0
  73. package/dist/schema/service.d.mts +52 -0
  74. package/dist/schema/service.d.mts.map +1 -0
  75. package/dist/schema/service.mjs +87 -0
  76. package/dist/schema/service.mjs.map +1 -0
  77. package/dist/schema/types.d.cts.map +1 -1
  78. package/dist/schema/types.d.mts.map +1 -1
  79. package/dist/sqlite-afs.cjs +672 -121
  80. package/dist/sqlite-afs.d.cts +257 -56
  81. package/dist/sqlite-afs.d.cts.map +1 -1
  82. package/dist/sqlite-afs.d.mts +257 -56
  83. package/dist/sqlite-afs.d.mts.map +1 -1
  84. package/dist/sqlite-afs.mjs +674 -123
  85. package/dist/sqlite-afs.mjs.map +1 -1
  86. package/package.json +4 -3
@@ -1 +1 @@
1
- {"version":3,"file":"introspector.d.cts","names":[],"sources":["../../src/schema/introspector.ts"],"mappings":";;;;;AAwEA;;cAAa,kBAAA;EAAA;;;;;;EAAA,WAAA,EAAA,EAQL,cAAA,EAAA,OAAA;IAAA,qCAAA,MAAA;IAAA,aAAA;EAAA,IAOH,OAAA,CAAQ,GAAA,SAAY,WAAA;EAAA;;;;;;EAAA,gBAAA,EAAA,EA4CG,cAAA,EAAA,SAAA,WAAoC,OAAA,CAAQ,WAAA;EAAA;;;;EAAA,oBAAA,MAAA,EAsC1C,WAAA;EAAA;;;EAAA,OAAA,EAAA,EAWX,cAAA,EAAA,SAAA,WAAoC,OAAA;EAAA;;;EAAA,UAAA,EAAA,EAiB/C,cAAA,EAAA,SAAA,UAAA,OAAA,YAAA,OAAA;IAAA,4CAAA,YAAA;IAAA,YAAA;EAAA,IASH,OAAA;EAAA;;;EAAA,WAAA,EAAA,EAmDkB,cAAA,EAAA,SAAA,WAAoC,OAAA;AAAA"}
1
+ {"version":3,"file":"introspector.d.cts","names":[],"sources":["../../src/schema/introspector.ts"],"mappings":";;;;;;AAwEA;cAAa,kBAAA;;;;;;;EAOL,UAAA,CACJ,EAAA,EAAI,cAAA,EACJ,OAAA;IAkD4D,qCAhD1D,MAAA,aAiGa;IA/Fb,aAAA;EAAA,IAED,OAAA,CAAQ,GAAA,SAAY,WAAA;EAuHpB;;;;;;EA3EG,eAAA,CAAgB,EAAA,EAAI,cAAA,EAAgB,SAAA,WAAoB,OAAA,CAAQ,WAAA;EAnDpE;;;;EAyFF,mBAAA,CAAoB,MAAA,EAAQ,WAAA;EAlFjB;;;EA6FL,MAAA,CAAO,EAAA,EAAI,cAAA,EAAgB,SAAA,WAAoB,OAAA;EAjD/B;;;EAiEhB,SAAA,CACJ,EAAA,EAAI,cAAA,EACJ,SAAA,UACA,OAAA,YACA,OAAA;IA/BF,4CAiCI,YAAA,WAjCgB;IAmChB,YAAA;EAAA,IAED,OAAA;EA1BU;;;EA6EP,UAAA,CAAW,EAAA,EAAI,cAAA,EAAgB,SAAA,WAAoB,OAAA;AAAA"}
@@ -7,41 +7,41 @@ import { LibSQLDatabase } from "drizzle-orm/libsql";
7
7
  */
8
8
  declare class SchemaIntrospector {
9
9
  /**
10
- * Introspects all tables in the database
11
- * @param db - Drizzle database instance
12
- * @param options - Introspection options
13
- * @returns Map of table name to TableSchema
14
- */
10
+ * Introspects all tables in the database
11
+ * @param db - Drizzle database instance
12
+ * @param options - Introspection options
13
+ * @returns Map of table name to TableSchema
14
+ */
15
15
  introspect(db: LibSQLDatabase, options?: {
16
16
  /** Whitelist of tables to include */tables?: string[]; /** Tables to exclude */
17
17
  excludeTables?: string[];
18
18
  }): Promise<Map<string, TableSchema>>;
19
19
  /**
20
- * Introspects a single table
21
- * @param db - Drizzle database instance
22
- * @param tableName - Name of the table to introspect
23
- * @returns TableSchema for the specified table
24
- */
20
+ * Introspects a single table
21
+ * @param db - Drizzle database instance
22
+ * @param tableName - Name of the table to introspect
23
+ * @returns TableSchema for the specified table
24
+ */
25
25
  introspectTable(db: LibSQLDatabase, tableName: string): Promise<TableSchema>;
26
26
  /**
27
- * Gets the primary key column name for a table
28
- * Returns the first PK column, or 'rowid' if no explicit PK
29
- */
27
+ * Gets the primary key column name for a table
28
+ * Returns the first PK column, or 'rowid' if no explicit PK
29
+ */
30
30
  getPrimaryKeyColumn(schema: TableSchema): string;
31
31
  /**
32
- * Checks if a table has FTS (Full-Text Search) enabled
33
- */
32
+ * Checks if a table has FTS (Full-Text Search) enabled
33
+ */
34
34
  hasFTS(db: LibSQLDatabase, tableName: string): Promise<boolean>;
35
35
  /**
36
- * Creates FTS5 table for full-text search on specified columns
37
- */
36
+ * Creates FTS5 table for full-text search on specified columns
37
+ */
38
38
  createFTS(db: LibSQLDatabase, tableName: string, columns: string[], options?: {
39
39
  /** Content table (defaults to tableName) */contentTable?: string; /** Content rowid column (defaults to 'rowid') */
40
40
  contentRowid?: string;
41
41
  }): Promise<void>;
42
42
  /**
43
- * Rebuilds FTS index for a table (useful after bulk inserts)
44
- */
43
+ * Rebuilds FTS index for a table (useful after bulk inserts)
44
+ */
45
45
  rebuildFTS(db: LibSQLDatabase, tableName: string): Promise<void>;
46
46
  }
47
47
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"introspector.d.mts","names":[],"sources":["../../src/schema/introspector.ts"],"mappings":";;;;;AAwEA;;cAAa,kBAAA;EAAA;;;;;;EAAA,WAAA,EAAA,EAQL,cAAA,EAAA,OAAA;IAAA,qCAAA,MAAA;IAAA,aAAA;EAAA,IAOH,OAAA,CAAQ,GAAA,SAAY,WAAA;EAAA;;;;;;EAAA,gBAAA,EAAA,EA4CG,cAAA,EAAA,SAAA,WAAoC,OAAA,CAAQ,WAAA;EAAA;;;;EAAA,oBAAA,MAAA,EAsC1C,WAAA;EAAA;;;EAAA,OAAA,EAAA,EAWX,cAAA,EAAA,SAAA,WAAoC,OAAA;EAAA;;;EAAA,UAAA,EAAA,EAiB/C,cAAA,EAAA,SAAA,UAAA,OAAA,YAAA,OAAA;IAAA,4CAAA,YAAA;IAAA,YAAA;EAAA,IASH,OAAA;EAAA;;;EAAA,WAAA,EAAA,EAmDkB,cAAA,EAAA,SAAA,WAAoC,OAAA;AAAA"}
1
+ {"version":3,"file":"introspector.d.mts","names":[],"sources":["../../src/schema/introspector.ts"],"mappings":";;;;;;AAwEA;cAAa,kBAAA;;;;;;;EAOL,UAAA,CACJ,EAAA,EAAI,cAAA,EACJ,OAAA;IAkD4D,qCAhD1D,MAAA,aAiGa;IA/Fb,aAAA;EAAA,IAED,OAAA,CAAQ,GAAA,SAAY,WAAA;EAuHpB;;;;;;EA3EG,eAAA,CAAgB,EAAA,EAAI,cAAA,EAAgB,SAAA,WAAoB,OAAA,CAAQ,WAAA;EAnDpE;;;;EAyFF,mBAAA,CAAoB,MAAA,EAAQ,WAAA;EAlFjB;;;EA6FL,MAAA,CAAO,EAAA,EAAI,cAAA,EAAgB,SAAA,WAAoB,OAAA;EAjD/B;;;EAiEhB,SAAA,CACJ,EAAA,EAAI,cAAA,EACJ,SAAA,UACA,OAAA,YACA,OAAA;IA/BF,4CAiCI,YAAA,WAjCgB;IAmChB,YAAA;EAAA,IAED,OAAA;EA1BU;;;EA6EP,UAAA,CAAW,EAAA,EAAI,cAAA,EAAgB,SAAA,WAAoB,OAAA;AAAA"}
@@ -0,0 +1,86 @@
1
+ const require_types = require('./types.cjs');
2
+ const require_introspector = require('./introspector.cjs');
3
+ let _aigne_sqlite = require("@aigne/sqlite");
4
+
5
+ //#region src/schema/service.ts
6
+ /**
7
+ * Executes a raw SQL query and returns all rows
8
+ */
9
+ async function execAll(db, query) {
10
+ return db.all(_aigne_sqlite.sql.raw(query)).execute();
11
+ }
12
+ /**
13
+ * Schema service that queries schema on-demand (no caching)
14
+ *
15
+ * SQLite PRAGMA queries are extremely fast, so real-time queries
16
+ * are preferred over caching to avoid staleness issues.
17
+ */
18
+ var SchemaService = class {
19
+ introspector = new require_introspector.SchemaIntrospector();
20
+ constructor(db, options) {
21
+ this.db = db;
22
+ this.options = options;
23
+ }
24
+ /**
25
+ * Gets schema for a specific table (real-time query)
26
+ */
27
+ async getSchema(tableName) {
28
+ if (!tableName) return;
29
+ if (require_types.SYSTEM_TABLES.includes(tableName)) return;
30
+ if (this.options?.tables && !this.options.tables.includes(tableName)) return;
31
+ if (this.options?.excludeTables?.includes(tableName)) return;
32
+ if (!await this.hasTable(tableName)) return;
33
+ return this.introspector.introspectTable(this.db, tableName);
34
+ }
35
+ /**
36
+ * Checks if a table exists (real-time query)
37
+ */
38
+ async hasTable(tableName) {
39
+ if (!tableName) return false;
40
+ if (require_types.SYSTEM_TABLES.includes(tableName)) return false;
41
+ if (this.options?.tables && !this.options.tables.includes(tableName)) return false;
42
+ if (this.options?.excludeTables?.includes(tableName)) return false;
43
+ return ((await execAll(this.db, `SELECT COUNT(*) as count FROM sqlite_master WHERE type = 'table' AND name = '${tableName.replace(/'/g, "''")}'`))[0]?.count ?? 0) > 0;
44
+ }
45
+ /**
46
+ * Gets all table schemas (real-time query)
47
+ */
48
+ async getAllSchemas() {
49
+ return this.introspector.introspect(this.db, {
50
+ tables: this.options?.tables,
51
+ excludeTables: this.options?.excludeTables
52
+ });
53
+ }
54
+ /**
55
+ * Lists all table names (real-time query)
56
+ */
57
+ async listTableNames() {
58
+ return (await execAll(this.db, `
59
+ SELECT name FROM sqlite_master
60
+ WHERE type = 'table'
61
+ AND name NOT LIKE 'sqlite_%'
62
+ AND name NOT LIKE '%_fts%'
63
+ ORDER BY name
64
+ `)).map((r) => r.name).filter((name) => {
65
+ if (require_types.SYSTEM_TABLES.includes(name)) return false;
66
+ if (this.options?.tables && !this.options.tables.includes(name)) return false;
67
+ if (this.options?.excludeTables?.includes(name)) return false;
68
+ return true;
69
+ });
70
+ }
71
+ /**
72
+ * Gets the count of tables
73
+ */
74
+ async getTableCount() {
75
+ return (await this.listTableNames()).length;
76
+ }
77
+ /**
78
+ * Gets the primary key column name for a table
79
+ */
80
+ getPrimaryKeyColumn(schema) {
81
+ return this.introspector.getPrimaryKeyColumn(schema);
82
+ }
83
+ };
84
+
85
+ //#endregion
86
+ exports.SchemaService = SchemaService;
@@ -0,0 +1,52 @@
1
+ import { TableSchema } from "./types.cjs";
2
+ import { LibSQLDatabase } from "drizzle-orm/libsql";
3
+
4
+ //#region src/schema/service.d.ts
5
+ /**
6
+ * Options for schema service
7
+ */
8
+ interface SchemaServiceOptions {
9
+ /** Whitelist of tables to include */
10
+ tables?: string[];
11
+ /** Tables to exclude */
12
+ excludeTables?: string[];
13
+ }
14
+ /**
15
+ * Schema service that queries schema on-demand (no caching)
16
+ *
17
+ * SQLite PRAGMA queries are extremely fast, so real-time queries
18
+ * are preferred over caching to avoid staleness issues.
19
+ */
20
+ declare class SchemaService {
21
+ private db;
22
+ private options?;
23
+ private introspector;
24
+ constructor(db: LibSQLDatabase, options?: SchemaServiceOptions | undefined);
25
+ /**
26
+ * Gets schema for a specific table (real-time query)
27
+ */
28
+ getSchema(tableName: string): Promise<TableSchema | undefined>;
29
+ /**
30
+ * Checks if a table exists (real-time query)
31
+ */
32
+ hasTable(tableName: string): Promise<boolean>;
33
+ /**
34
+ * Gets all table schemas (real-time query)
35
+ */
36
+ getAllSchemas(): Promise<Map<string, TableSchema>>;
37
+ /**
38
+ * Lists all table names (real-time query)
39
+ */
40
+ listTableNames(): Promise<string[]>;
41
+ /**
42
+ * Gets the count of tables
43
+ */
44
+ getTableCount(): Promise<number>;
45
+ /**
46
+ * Gets the primary key column name for a table
47
+ */
48
+ getPrimaryKeyColumn(schema: TableSchema): string;
49
+ }
50
+ //#endregion
51
+ export { SchemaService, SchemaServiceOptions };
52
+ //# sourceMappingURL=service.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.cts","names":[],"sources":["../../src/schema/service.ts"],"mappings":";;;;;;AAeA;UAAiB,oBAAA;;EAEf,MAAA;EAEa;EAAb,aAAA;AAAA;;;;;;;cASW,aAAA;EAAA,QAID,EAAA;EAAA,QACA,OAAA;EAAA,QAJF,YAAA;cAGE,EAAA,EAAI,cAAA,EACJ,OAAA,GAAU,oBAAA;EA0HQ;;;EApHtB,SAAA,CAAU,SAAA,WAAoB,OAAA,CAAQ,WAAA;EANlC;;;EAuCJ,QAAA,CAAS,SAAA,WAAoB,OAAA;EAxCzB;;;EAuEJ,aAAA,CAAA,GAAiB,OAAA,CAAQ,GAAA,SAAY,WAAA;EAhE3B;;;EA0EV,cAAA,CAAA,GAAkB,OAAA;EAzCT;;;EA2ET,aAAA,CAAA,GAAiB,OAAA;EA5CQ;;;EAoD/B,mBAAA,CAAoB,MAAA,EAAQ,WAAA;AAAA"}
@@ -0,0 +1,52 @@
1
+ import { TableSchema } from "./types.mjs";
2
+ import { LibSQLDatabase } from "drizzle-orm/libsql";
3
+
4
+ //#region src/schema/service.d.ts
5
+ /**
6
+ * Options for schema service
7
+ */
8
+ interface SchemaServiceOptions {
9
+ /** Whitelist of tables to include */
10
+ tables?: string[];
11
+ /** Tables to exclude */
12
+ excludeTables?: string[];
13
+ }
14
+ /**
15
+ * Schema service that queries schema on-demand (no caching)
16
+ *
17
+ * SQLite PRAGMA queries are extremely fast, so real-time queries
18
+ * are preferred over caching to avoid staleness issues.
19
+ */
20
+ declare class SchemaService {
21
+ private db;
22
+ private options?;
23
+ private introspector;
24
+ constructor(db: LibSQLDatabase, options?: SchemaServiceOptions | undefined);
25
+ /**
26
+ * Gets schema for a specific table (real-time query)
27
+ */
28
+ getSchema(tableName: string): Promise<TableSchema | undefined>;
29
+ /**
30
+ * Checks if a table exists (real-time query)
31
+ */
32
+ hasTable(tableName: string): Promise<boolean>;
33
+ /**
34
+ * Gets all table schemas (real-time query)
35
+ */
36
+ getAllSchemas(): Promise<Map<string, TableSchema>>;
37
+ /**
38
+ * Lists all table names (real-time query)
39
+ */
40
+ listTableNames(): Promise<string[]>;
41
+ /**
42
+ * Gets the count of tables
43
+ */
44
+ getTableCount(): Promise<number>;
45
+ /**
46
+ * Gets the primary key column name for a table
47
+ */
48
+ getPrimaryKeyColumn(schema: TableSchema): string;
49
+ }
50
+ //#endregion
51
+ export { SchemaService, SchemaServiceOptions };
52
+ //# sourceMappingURL=service.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.mts","names":[],"sources":["../../src/schema/service.ts"],"mappings":";;;;;;AAeA;UAAiB,oBAAA;;EAEf,MAAA;EAEa;EAAb,aAAA;AAAA;;;;;;;cASW,aAAA;EAAA,QAID,EAAA;EAAA,QACA,OAAA;EAAA,QAJF,YAAA;cAGE,EAAA,EAAI,cAAA,EACJ,OAAA,GAAU,oBAAA;EA0HQ;;;EApHtB,SAAA,CAAU,SAAA,WAAoB,OAAA,CAAQ,WAAA;EANlC;;;EAuCJ,QAAA,CAAS,SAAA,WAAoB,OAAA;EAxCzB;;;EAuEJ,aAAA,CAAA,GAAiB,OAAA,CAAQ,GAAA,SAAY,WAAA;EAhE3B;;;EA0EV,cAAA,CAAA,GAAkB,OAAA;EAzCT;;;EA2ET,aAAA,CAAA,GAAiB,OAAA;EA5CQ;;;EAoD/B,mBAAA,CAAoB,MAAA,EAAQ,WAAA;AAAA"}
@@ -0,0 +1,87 @@
1
+ import { SYSTEM_TABLES } from "./types.mjs";
2
+ import { SchemaIntrospector } from "./introspector.mjs";
3
+ import { sql } from "@aigne/sqlite";
4
+
5
+ //#region src/schema/service.ts
6
+ /**
7
+ * Executes a raw SQL query and returns all rows
8
+ */
9
+ async function execAll(db, query) {
10
+ return db.all(sql.raw(query)).execute();
11
+ }
12
+ /**
13
+ * Schema service that queries schema on-demand (no caching)
14
+ *
15
+ * SQLite PRAGMA queries are extremely fast, so real-time queries
16
+ * are preferred over caching to avoid staleness issues.
17
+ */
18
+ var SchemaService = class {
19
+ introspector = new SchemaIntrospector();
20
+ constructor(db, options) {
21
+ this.db = db;
22
+ this.options = options;
23
+ }
24
+ /**
25
+ * Gets schema for a specific table (real-time query)
26
+ */
27
+ async getSchema(tableName) {
28
+ if (!tableName) return;
29
+ if (SYSTEM_TABLES.includes(tableName)) return;
30
+ if (this.options?.tables && !this.options.tables.includes(tableName)) return;
31
+ if (this.options?.excludeTables?.includes(tableName)) return;
32
+ if (!await this.hasTable(tableName)) return;
33
+ return this.introspector.introspectTable(this.db, tableName);
34
+ }
35
+ /**
36
+ * Checks if a table exists (real-time query)
37
+ */
38
+ async hasTable(tableName) {
39
+ if (!tableName) return false;
40
+ if (SYSTEM_TABLES.includes(tableName)) return false;
41
+ if (this.options?.tables && !this.options.tables.includes(tableName)) return false;
42
+ if (this.options?.excludeTables?.includes(tableName)) return false;
43
+ return ((await execAll(this.db, `SELECT COUNT(*) as count FROM sqlite_master WHERE type = 'table' AND name = '${tableName.replace(/'/g, "''")}'`))[0]?.count ?? 0) > 0;
44
+ }
45
+ /**
46
+ * Gets all table schemas (real-time query)
47
+ */
48
+ async getAllSchemas() {
49
+ return this.introspector.introspect(this.db, {
50
+ tables: this.options?.tables,
51
+ excludeTables: this.options?.excludeTables
52
+ });
53
+ }
54
+ /**
55
+ * Lists all table names (real-time query)
56
+ */
57
+ async listTableNames() {
58
+ return (await execAll(this.db, `
59
+ SELECT name FROM sqlite_master
60
+ WHERE type = 'table'
61
+ AND name NOT LIKE 'sqlite_%'
62
+ AND name NOT LIKE '%_fts%'
63
+ ORDER BY name
64
+ `)).map((r) => r.name).filter((name) => {
65
+ if (SYSTEM_TABLES.includes(name)) return false;
66
+ if (this.options?.tables && !this.options.tables.includes(name)) return false;
67
+ if (this.options?.excludeTables?.includes(name)) return false;
68
+ return true;
69
+ });
70
+ }
71
+ /**
72
+ * Gets the count of tables
73
+ */
74
+ async getTableCount() {
75
+ return (await this.listTableNames()).length;
76
+ }
77
+ /**
78
+ * Gets the primary key column name for a table
79
+ */
80
+ getPrimaryKeyColumn(schema) {
81
+ return this.introspector.getPrimaryKeyColumn(schema);
82
+ }
83
+ };
84
+
85
+ //#endregion
86
+ export { SchemaService };
87
+ //# sourceMappingURL=service.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.mjs","names":[],"sources":["../../src/schema/service.ts"],"sourcesContent":["import { sql } from \"@aigne/sqlite\";\nimport type { LibSQLDatabase } from \"drizzle-orm/libsql\";\nimport { SchemaIntrospector } from \"./introspector.js\";\nimport { SYSTEM_TABLES, type TableSchema } from \"./types.js\";\n\n/**\n * Executes a raw SQL query and returns all rows\n */\nasync function execAll<T>(db: LibSQLDatabase, query: string): Promise<T[]> {\n return db.all<T>(sql.raw(query)).execute();\n}\n\n/**\n * Options for schema service\n */\nexport interface SchemaServiceOptions {\n /** Whitelist of tables to include */\n tables?: string[];\n /** Tables to exclude */\n excludeTables?: string[];\n}\n\n/**\n * Schema service that queries schema on-demand (no caching)\n *\n * SQLite PRAGMA queries are extremely fast, so real-time queries\n * are preferred over caching to avoid staleness issues.\n */\nexport class SchemaService {\n private introspector = new SchemaIntrospector();\n\n constructor(\n private db: LibSQLDatabase,\n private options?: SchemaServiceOptions,\n ) {}\n\n /**\n * Gets schema for a specific table (real-time query)\n */\n async getSchema(tableName: string): Promise<TableSchema | undefined> {\n // Guard against undefined/null\n if (!tableName) {\n return undefined;\n }\n\n // Skip system tables\n if (SYSTEM_TABLES.includes(tableName as (typeof SYSTEM_TABLES)[number])) {\n return undefined;\n }\n\n // Apply whitelist filter\n if (this.options?.tables && !this.options.tables.includes(tableName)) {\n return undefined;\n }\n\n // Apply exclude filter\n if (this.options?.excludeTables?.includes(tableName)) {\n return undefined;\n }\n\n // Check if table exists\n const exists = await this.hasTable(tableName);\n if (!exists) {\n return undefined;\n }\n\n return this.introspector.introspectTable(this.db, tableName);\n }\n\n /**\n * Checks if a table exists (real-time query)\n */\n async hasTable(tableName: string): Promise<boolean> {\n // Guard against undefined/null\n if (!tableName) {\n return false;\n }\n\n // Skip system tables\n if (SYSTEM_TABLES.includes(tableName as (typeof SYSTEM_TABLES)[number])) {\n return false;\n }\n\n // Apply whitelist filter\n if (this.options?.tables && !this.options.tables.includes(tableName)) {\n return false;\n }\n\n // Apply exclude filter\n if (this.options?.excludeTables?.includes(tableName)) {\n return false;\n }\n\n const result = await execAll<{ count: number }>(\n this.db,\n `SELECT COUNT(*) as count FROM sqlite_master WHERE type = 'table' AND name = '${tableName.replace(/'/g, \"''\")}'`,\n );\n return (result[0]?.count ?? 0) > 0;\n }\n\n /**\n * Gets all table schemas (real-time query)\n */\n async getAllSchemas(): Promise<Map<string, TableSchema>> {\n return this.introspector.introspect(this.db, {\n tables: this.options?.tables,\n excludeTables: this.options?.excludeTables,\n });\n }\n\n /**\n * Lists all table names (real-time query)\n */\n async listTableNames(): Promise<string[]> {\n const result = await execAll<{ name: string }>(\n this.db,\n `\n SELECT name FROM sqlite_master\n WHERE type = 'table'\n AND name NOT LIKE 'sqlite_%'\n AND name NOT LIKE '%_fts%'\n ORDER BY name\n `,\n );\n\n return result\n .map((r) => r.name)\n .filter((name) => {\n // Skip system tables\n if (SYSTEM_TABLES.includes(name as (typeof SYSTEM_TABLES)[number])) {\n return false;\n }\n // Apply whitelist filter\n if (this.options?.tables && !this.options.tables.includes(name)) {\n return false;\n }\n // Apply exclude filter\n if (this.options?.excludeTables?.includes(name)) {\n return false;\n }\n return true;\n });\n }\n\n /**\n * Gets the count of tables\n */\n async getTableCount(): Promise<number> {\n const names = await this.listTableNames();\n return names.length;\n }\n\n /**\n * Gets the primary key column name for a table\n */\n getPrimaryKeyColumn(schema: TableSchema): string {\n return this.introspector.getPrimaryKeyColumn(schema);\n }\n}\n"],"mappings":";;;;;;;;AAQA,eAAe,QAAW,IAAoB,OAA6B;AACzE,QAAO,GAAG,IAAO,IAAI,IAAI,MAAM,CAAC,CAAC,SAAS;;;;;;;;AAmB5C,IAAa,gBAAb,MAA2B;CACzB,AAAQ,eAAe,IAAI,oBAAoB;CAE/C,YACE,AAAQ,IACR,AAAQ,SACR;EAFQ;EACA;;;;;CAMV,MAAM,UAAU,WAAqD;AAEnE,MAAI,CAAC,UACH;AAIF,MAAI,cAAc,SAAS,UAA4C,CACrE;AAIF,MAAI,KAAK,SAAS,UAAU,CAAC,KAAK,QAAQ,OAAO,SAAS,UAAU,CAClE;AAIF,MAAI,KAAK,SAAS,eAAe,SAAS,UAAU,CAClD;AAKF,MAAI,CADW,MAAM,KAAK,SAAS,UAAU,CAE3C;AAGF,SAAO,KAAK,aAAa,gBAAgB,KAAK,IAAI,UAAU;;;;;CAM9D,MAAM,SAAS,WAAqC;AAElD,MAAI,CAAC,UACH,QAAO;AAIT,MAAI,cAAc,SAAS,UAA4C,CACrE,QAAO;AAIT,MAAI,KAAK,SAAS,UAAU,CAAC,KAAK,QAAQ,OAAO,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