@aigne/afs-sqlite 1.11.0-beta → 1.11.0-beta.2
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/LICENSE.md +17 -84
- package/README.md +3 -6
- package/dist/actions/built-in.cjs +142 -0
- package/dist/actions/built-in.d.cts +10 -0
- package/dist/actions/built-in.d.cts.map +1 -0
- package/dist/actions/built-in.d.mts +10 -0
- package/dist/actions/built-in.d.mts.map +1 -0
- package/dist/actions/built-in.mjs +143 -0
- package/dist/actions/built-in.mjs.map +1 -0
- package/dist/actions/registry.cjs +91 -0
- package/dist/actions/registry.d.cts +54 -0
- package/dist/actions/registry.d.cts.map +1 -0
- package/dist/actions/registry.d.mts +54 -0
- package/dist/actions/registry.d.mts.map +1 -0
- package/dist/actions/registry.mjs +91 -0
- package/dist/actions/registry.mjs.map +1 -0
- package/dist/actions/types.d.cts +56 -0
- package/dist/actions/types.d.cts.map +1 -0
- package/dist/actions/types.d.mts +56 -0
- package/dist/actions/types.d.mts.map +1 -0
- package/dist/config.cjs +27 -0
- package/dist/config.d.cts +81 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +81 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +28 -0
- package/dist/config.mjs.map +1 -0
- package/dist/index.cjs +38 -1324
- package/dist/index.d.cts +14 -758
- package/dist/index.d.mts +14 -758
- package/dist/index.mjs +12 -1299
- package/dist/node/builder.cjs +179 -0
- package/dist/node/builder.d.cts +48 -0
- package/dist/node/builder.d.cts.map +1 -0
- package/dist/node/builder.d.mts +48 -0
- package/dist/node/builder.d.mts.map +1 -0
- package/dist/node/builder.mjs +172 -0
- package/dist/node/builder.mjs.map +1 -0
- package/dist/operations/crud.cjs +176 -0
- package/dist/operations/crud.d.cts +69 -0
- package/dist/operations/crud.d.cts.map +1 -0
- package/dist/operations/crud.d.mts +69 -0
- package/dist/operations/crud.d.mts.map +1 -0
- package/dist/operations/crud.mjs +177 -0
- package/dist/operations/crud.mjs.map +1 -0
- package/dist/operations/query-builder.cjs +77 -0
- package/dist/operations/query-builder.d.cts +34 -0
- package/dist/operations/query-builder.d.cts.map +1 -0
- package/dist/operations/query-builder.d.mts +34 -0
- package/dist/operations/query-builder.d.mts.map +1 -0
- package/dist/operations/query-builder.mjs +72 -0
- package/dist/operations/query-builder.mjs.map +1 -0
- package/dist/operations/search.cjs +141 -0
- package/dist/operations/search.d.cts +79 -0
- package/dist/operations/search.d.cts.map +1 -0
- package/dist/operations/search.d.mts +79 -0
- package/dist/operations/search.d.mts.map +1 -0
- package/dist/operations/search.mjs +141 -0
- package/dist/operations/search.mjs.map +1 -0
- package/dist/router/path-router.cjs +79 -0
- package/dist/router/path-router.d.cts +42 -0
- package/dist/router/path-router.d.cts.map +1 -0
- package/dist/router/path-router.d.mts +42 -0
- package/dist/router/path-router.d.mts.map +1 -0
- package/dist/router/path-router.mjs +76 -0
- package/dist/router/path-router.mjs.map +1 -0
- package/dist/router/types.d.cts +34 -0
- package/dist/router/types.d.cts.map +1 -0
- package/dist/router/types.d.mts +34 -0
- package/dist/router/types.d.mts.map +1 -0
- package/dist/schema/introspector.cjs +160 -0
- package/dist/schema/introspector.d.cts +49 -0
- package/dist/schema/introspector.d.cts.map +1 -0
- package/dist/schema/introspector.d.mts +49 -0
- package/dist/schema/introspector.d.mts.map +1 -0
- package/dist/schema/introspector.mjs +161 -0
- package/dist/schema/introspector.mjs.map +1 -0
- package/dist/schema/types.cjs +15 -0
- package/dist/schema/types.d.cts +104 -0
- package/dist/schema/types.d.cts.map +1 -0
- package/dist/schema/types.d.mts +104 -0
- package/dist/schema/types.d.mts.map +1 -0
- package/dist/schema/types.mjs +15 -0
- package/dist/schema/types.mjs.map +1 -0
- package/dist/sqlite-afs.cjs +264 -0
- package/dist/sqlite-afs.d.cts +152 -0
- package/dist/sqlite-afs.d.cts.map +1 -0
- package/dist/sqlite-afs.d.mts +152 -0
- package/dist/sqlite-afs.d.mts.map +1 -0
- package/dist/sqlite-afs.mjs +265 -0
- package/dist/sqlite-afs.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,93 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
# Proprietary License
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This software and associated documentation files (the "Software") are proprietary
|
|
6
|
+
and confidential. Unauthorized copying, modification, distribution, or use of
|
|
7
|
+
this Software, via any medium, is strictly prohibited.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
The Software is provided for internal use only within ArcBlock, Inc. and its
|
|
10
|
+
authorized affiliates.
|
|
8
11
|
|
|
9
|
-
##
|
|
12
|
+
## No License Granted
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
-
the limitations and conditions below.
|
|
14
|
+
No license, express or implied, is granted to any party for any purpose.
|
|
15
|
+
All rights are reserved by ArcBlock, Inc.
|
|
15
16
|
|
|
16
|
-
##
|
|
17
|
+
## Public Artifact Distribution
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
Portions of this Software may be released publicly under separate open-source
|
|
20
|
+
licenses (such as MIT License) through designated public repositories. Such
|
|
21
|
+
public releases are governed by their respective licenses and do not affect
|
|
22
|
+
the proprietary nature of this repository.
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
-
software that is protected by the license key.
|
|
24
|
+
## Contact
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
-
to applicable law.
|
|
29
|
-
|
|
30
|
-
## Patents
|
|
31
|
-
|
|
32
|
-
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
-
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
-
sale, import and have imported the software, in each case subject to the
|
|
35
|
-
limitations and conditions in this license. This license does not cover any
|
|
36
|
-
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
-
the software. If you or your company make any written claim that the software
|
|
38
|
-
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
-
the software granted under these terms ends immediately. If your company makes
|
|
40
|
-
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
-
company.
|
|
42
|
-
|
|
43
|
-
## Notices
|
|
44
|
-
|
|
45
|
-
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
-
also gets a copy of these terms.
|
|
47
|
-
|
|
48
|
-
If you modify the software, you must include in any modified copies of the
|
|
49
|
-
software prominent notices stating that you have modified the software.
|
|
50
|
-
|
|
51
|
-
## No Other Rights
|
|
52
|
-
|
|
53
|
-
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
-
these terms.
|
|
55
|
-
|
|
56
|
-
## Termination
|
|
57
|
-
|
|
58
|
-
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
-
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
-
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
-
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
-
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
-
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
-
to terminate automatically and permanently.
|
|
65
|
-
|
|
66
|
-
## No Liability
|
|
67
|
-
|
|
68
|
-
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
-
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
-
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
-
legal claim.*
|
|
72
|
-
|
|
73
|
-
## Definitions
|
|
74
|
-
|
|
75
|
-
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
-
software the licensor makes available under these terms, including any portion
|
|
77
|
-
of it.
|
|
78
|
-
|
|
79
|
-
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
-
|
|
81
|
-
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
-
organization that you work for, plus all organizations that have control over,
|
|
83
|
-
are under the control of, or are under common control with that
|
|
84
|
-
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
-
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
-
otherwise. Control can be direct or indirect.
|
|
87
|
-
|
|
88
|
-
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
-
these terms.
|
|
90
|
-
|
|
91
|
-
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
-
|
|
93
|
-
**trademark** means trademarks, service marks, and similar rights.
|
|
26
|
+
For licensing inquiries, contact: legal@arcblock.io
|
package/README.md
CHANGED
|
@@ -278,15 +278,12 @@ afs:
|
|
|
278
278
|
|
|
279
279
|
## Related Packages
|
|
280
280
|
|
|
281
|
-
- [@aigne/afs](
|
|
282
|
-
- [@aigne/afs-history](
|
|
283
|
-
- [@aigne/afs-
|
|
281
|
+
- [@aigne/afs](../../packages/core/README.md) - Core AFS package
|
|
282
|
+
- [@aigne/afs-history](../../afs-providers/history/README.md) - History tracking module
|
|
283
|
+
- [@aigne/afs-fs](../fs/README.md) - Local file system module
|
|
284
284
|
- [@aigne/sqlite](../../packages/sqlite/README.md) - SQLite utilities
|
|
285
285
|
|
|
286
286
|
## TypeScript Support
|
|
287
287
|
|
|
288
288
|
This package includes full TypeScript type definitions.
|
|
289
289
|
|
|
290
|
-
## License
|
|
291
|
-
|
|
292
|
-
[Elastic-2.0](../../LICENSE.md)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
let _aigne_sqlite = require("@aigne/sqlite");
|
|
2
|
+
|
|
3
|
+
//#region src/actions/built-in.ts
|
|
4
|
+
/**
|
|
5
|
+
* Executes a raw SQL query and returns all rows
|
|
6
|
+
*/
|
|
7
|
+
async function execAll(db, query) {
|
|
8
|
+
return db.all(_aigne_sqlite.sql.raw(query)).execute();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Executes a raw SQL query (for INSERT, UPDATE, DELETE)
|
|
12
|
+
*/
|
|
13
|
+
async function execRun(db, query) {
|
|
14
|
+
await db.run(_aigne_sqlite.sql.raw(query)).execute();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Registers built-in actions to the registry
|
|
18
|
+
*/
|
|
19
|
+
function registerBuiltInActions(registry) {
|
|
20
|
+
registry.register({
|
|
21
|
+
name: "refresh",
|
|
22
|
+
description: "Refresh the schema cache for this module",
|
|
23
|
+
tableLevel: true,
|
|
24
|
+
rowLevel: false,
|
|
25
|
+
handler: async (ctx) => {
|
|
26
|
+
await ctx.module.refreshSchema();
|
|
27
|
+
return {
|
|
28
|
+
success: true,
|
|
29
|
+
message: "Schema refreshed successfully"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
registry.register({
|
|
34
|
+
name: "export",
|
|
35
|
+
description: "Export table data in specified format (json, csv)",
|
|
36
|
+
tableLevel: true,
|
|
37
|
+
rowLevel: false,
|
|
38
|
+
inputSchema: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: { format: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: ["json", "csv"],
|
|
43
|
+
default: "json"
|
|
44
|
+
} }
|
|
45
|
+
},
|
|
46
|
+
handler: async (ctx, params) => {
|
|
47
|
+
const format = params.format ?? "json";
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
data: await ctx.module.exportTable(ctx.table, format)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
registry.register({
|
|
55
|
+
name: "count",
|
|
56
|
+
description: "Get the total row count for this table",
|
|
57
|
+
tableLevel: true,
|
|
58
|
+
rowLevel: false,
|
|
59
|
+
handler: async (ctx) => {
|
|
60
|
+
return {
|
|
61
|
+
success: true,
|
|
62
|
+
data: { count: (await execAll(ctx.db, `SELECT COUNT(*) as count FROM "${ctx.table}"`))[0]?.count ?? 0 }
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
registry.register({
|
|
67
|
+
name: "duplicate",
|
|
68
|
+
description: "Create a copy of this row",
|
|
69
|
+
tableLevel: false,
|
|
70
|
+
rowLevel: true,
|
|
71
|
+
handler: async (ctx) => {
|
|
72
|
+
if (!ctx.row) return {
|
|
73
|
+
success: false,
|
|
74
|
+
message: "Row data not available"
|
|
75
|
+
};
|
|
76
|
+
const schema = ctx.schemas.get(ctx.table);
|
|
77
|
+
if (!schema) return {
|
|
78
|
+
success: false,
|
|
79
|
+
message: `Table '${ctx.table}' not found`
|
|
80
|
+
};
|
|
81
|
+
const pkColumn = schema.primaryKey[0] ?? "rowid";
|
|
82
|
+
const rowCopy = { ...ctx.row };
|
|
83
|
+
delete rowCopy[pkColumn];
|
|
84
|
+
delete rowCopy.rowid;
|
|
85
|
+
const columns = Object.keys(rowCopy);
|
|
86
|
+
const values = columns.map((col) => formatValueForSQL(rowCopy[col]));
|
|
87
|
+
await execRun(ctx.db, `INSERT INTO "${ctx.table}" (${columns.map((c) => `"${c}"`).join(", ")}) VALUES (${values.join(", ")})`);
|
|
88
|
+
return {
|
|
89
|
+
success: true,
|
|
90
|
+
data: { newId: (await execAll(ctx.db, "SELECT last_insert_rowid() as id"))[0]?.id },
|
|
91
|
+
message: "Row duplicated successfully"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
registry.register({
|
|
96
|
+
name: "validate",
|
|
97
|
+
description: "Validate row data against schema constraints",
|
|
98
|
+
tableLevel: false,
|
|
99
|
+
rowLevel: true,
|
|
100
|
+
handler: async (ctx) => {
|
|
101
|
+
if (!ctx.row) return {
|
|
102
|
+
success: false,
|
|
103
|
+
message: "Row data not available"
|
|
104
|
+
};
|
|
105
|
+
const schema = ctx.schemas.get(ctx.table);
|
|
106
|
+
if (!schema) return {
|
|
107
|
+
success: false,
|
|
108
|
+
message: `Table '${ctx.table}' not found`
|
|
109
|
+
};
|
|
110
|
+
const errors = [];
|
|
111
|
+
for (const col of schema.columns) if (col.notnull && (ctx.row[col.name] === null || ctx.row[col.name] === void 0)) errors.push(`Column '${col.name}' cannot be null`);
|
|
112
|
+
for (const fk of schema.foreignKeys) {
|
|
113
|
+
const value = ctx.row[fk.from];
|
|
114
|
+
if (value !== null && value !== void 0) {
|
|
115
|
+
if ((await execAll(ctx.db, `SELECT COUNT(*) as count FROM "${fk.table}" WHERE "${fk.to}" = '${String(value).replace(/'/g, "''")}'`))[0]?.count === 0) errors.push(`Foreign key violation: ${fk.from} references non-existent ${fk.table}.${fk.to}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
success: errors.length === 0,
|
|
120
|
+
data: {
|
|
121
|
+
errors,
|
|
122
|
+
valid: errors.length === 0
|
|
123
|
+
},
|
|
124
|
+
message: errors.length > 0 ? `Validation failed: ${errors.join("; ")}` : "Row is valid"
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Formats a value for SQL insertion
|
|
131
|
+
*/
|
|
132
|
+
function formatValueForSQL(value) {
|
|
133
|
+
if (value === null || value === void 0) return "NULL";
|
|
134
|
+
if (typeof value === "number") return String(value);
|
|
135
|
+
if (typeof value === "boolean") return value ? "1" : "0";
|
|
136
|
+
if (value instanceof Date) return `'${value.toISOString()}'`;
|
|
137
|
+
if (typeof value === "object") return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
|
|
138
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
exports.registerBuiltInActions = registerBuiltInActions;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionsRegistry } from "./registry.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/built-in.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Registers built-in actions to the registry
|
|
6
|
+
*/
|
|
7
|
+
declare function registerBuiltInActions(registry: ActionsRegistry): void;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { registerBuiltInActions };
|
|
10
|
+
//# sourceMappingURL=built-in.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"built-in.d.cts","names":[],"sources":["../../src/actions/built-in.ts"],"mappings":";;;;AAsBA;;iBAAgB,sBAAA,CAAA,QAAA,EAAiC,eAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionsRegistry } from "./registry.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/built-in.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Registers built-in actions to the registry
|
|
6
|
+
*/
|
|
7
|
+
declare function registerBuiltInActions(registry: ActionsRegistry): void;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { registerBuiltInActions };
|
|
10
|
+
//# sourceMappingURL=built-in.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"built-in.d.mts","names":[],"sources":["../../src/actions/built-in.ts"],"mappings":";;;;AAsBA;;iBAAgB,sBAAA,CAAA,QAAA,EAAiC,eAAA"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { sql } from "@aigne/sqlite";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/built-in.ts
|
|
4
|
+
/**
|
|
5
|
+
* Executes a raw SQL query and returns all rows
|
|
6
|
+
*/
|
|
7
|
+
async function execAll(db, query) {
|
|
8
|
+
return db.all(sql.raw(query)).execute();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Executes a raw SQL query (for INSERT, UPDATE, DELETE)
|
|
12
|
+
*/
|
|
13
|
+
async function execRun(db, query) {
|
|
14
|
+
await db.run(sql.raw(query)).execute();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Registers built-in actions to the registry
|
|
18
|
+
*/
|
|
19
|
+
function registerBuiltInActions(registry) {
|
|
20
|
+
registry.register({
|
|
21
|
+
name: "refresh",
|
|
22
|
+
description: "Refresh the schema cache for this module",
|
|
23
|
+
tableLevel: true,
|
|
24
|
+
rowLevel: false,
|
|
25
|
+
handler: async (ctx) => {
|
|
26
|
+
await ctx.module.refreshSchema();
|
|
27
|
+
return {
|
|
28
|
+
success: true,
|
|
29
|
+
message: "Schema refreshed successfully"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
registry.register({
|
|
34
|
+
name: "export",
|
|
35
|
+
description: "Export table data in specified format (json, csv)",
|
|
36
|
+
tableLevel: true,
|
|
37
|
+
rowLevel: false,
|
|
38
|
+
inputSchema: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: { format: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: ["json", "csv"],
|
|
43
|
+
default: "json"
|
|
44
|
+
} }
|
|
45
|
+
},
|
|
46
|
+
handler: async (ctx, params) => {
|
|
47
|
+
const format = params.format ?? "json";
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
data: await ctx.module.exportTable(ctx.table, format)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
registry.register({
|
|
55
|
+
name: "count",
|
|
56
|
+
description: "Get the total row count for this table",
|
|
57
|
+
tableLevel: true,
|
|
58
|
+
rowLevel: false,
|
|
59
|
+
handler: async (ctx) => {
|
|
60
|
+
return {
|
|
61
|
+
success: true,
|
|
62
|
+
data: { count: (await execAll(ctx.db, `SELECT COUNT(*) as count FROM "${ctx.table}"`))[0]?.count ?? 0 }
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
registry.register({
|
|
67
|
+
name: "duplicate",
|
|
68
|
+
description: "Create a copy of this row",
|
|
69
|
+
tableLevel: false,
|
|
70
|
+
rowLevel: true,
|
|
71
|
+
handler: async (ctx) => {
|
|
72
|
+
if (!ctx.row) return {
|
|
73
|
+
success: false,
|
|
74
|
+
message: "Row data not available"
|
|
75
|
+
};
|
|
76
|
+
const schema = ctx.schemas.get(ctx.table);
|
|
77
|
+
if (!schema) return {
|
|
78
|
+
success: false,
|
|
79
|
+
message: `Table '${ctx.table}' not found`
|
|
80
|
+
};
|
|
81
|
+
const pkColumn = schema.primaryKey[0] ?? "rowid";
|
|
82
|
+
const rowCopy = { ...ctx.row };
|
|
83
|
+
delete rowCopy[pkColumn];
|
|
84
|
+
delete rowCopy.rowid;
|
|
85
|
+
const columns = Object.keys(rowCopy);
|
|
86
|
+
const values = columns.map((col) => formatValueForSQL(rowCopy[col]));
|
|
87
|
+
await execRun(ctx.db, `INSERT INTO "${ctx.table}" (${columns.map((c) => `"${c}"`).join(", ")}) VALUES (${values.join(", ")})`);
|
|
88
|
+
return {
|
|
89
|
+
success: true,
|
|
90
|
+
data: { newId: (await execAll(ctx.db, "SELECT last_insert_rowid() as id"))[0]?.id },
|
|
91
|
+
message: "Row duplicated successfully"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
registry.register({
|
|
96
|
+
name: "validate",
|
|
97
|
+
description: "Validate row data against schema constraints",
|
|
98
|
+
tableLevel: false,
|
|
99
|
+
rowLevel: true,
|
|
100
|
+
handler: async (ctx) => {
|
|
101
|
+
if (!ctx.row) return {
|
|
102
|
+
success: false,
|
|
103
|
+
message: "Row data not available"
|
|
104
|
+
};
|
|
105
|
+
const schema = ctx.schemas.get(ctx.table);
|
|
106
|
+
if (!schema) return {
|
|
107
|
+
success: false,
|
|
108
|
+
message: `Table '${ctx.table}' not found`
|
|
109
|
+
};
|
|
110
|
+
const errors = [];
|
|
111
|
+
for (const col of schema.columns) if (col.notnull && (ctx.row[col.name] === null || ctx.row[col.name] === void 0)) errors.push(`Column '${col.name}' cannot be null`);
|
|
112
|
+
for (const fk of schema.foreignKeys) {
|
|
113
|
+
const value = ctx.row[fk.from];
|
|
114
|
+
if (value !== null && value !== void 0) {
|
|
115
|
+
if ((await execAll(ctx.db, `SELECT COUNT(*) as count FROM "${fk.table}" WHERE "${fk.to}" = '${String(value).replace(/'/g, "''")}'`))[0]?.count === 0) errors.push(`Foreign key violation: ${fk.from} references non-existent ${fk.table}.${fk.to}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
success: errors.length === 0,
|
|
120
|
+
data: {
|
|
121
|
+
errors,
|
|
122
|
+
valid: errors.length === 0
|
|
123
|
+
},
|
|
124
|
+
message: errors.length > 0 ? `Validation failed: ${errors.join("; ")}` : "Row is valid"
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Formats a value for SQL insertion
|
|
131
|
+
*/
|
|
132
|
+
function formatValueForSQL(value) {
|
|
133
|
+
if (value === null || value === void 0) return "NULL";
|
|
134
|
+
if (typeof value === "number") return String(value);
|
|
135
|
+
if (typeof value === "boolean") return value ? "1" : "0";
|
|
136
|
+
if (value instanceof Date) return `'${value.toISOString()}'`;
|
|
137
|
+
if (typeof value === "object") return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
|
|
138
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
export { registerBuiltInActions };
|
|
143
|
+
//# sourceMappingURL=built-in.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"built-in.mjs","names":[],"sources":["../../src/actions/built-in.ts"],"sourcesContent":["import { sql } from \"@aigne/sqlite\";\nimport type { LibSQLDatabase } from \"drizzle-orm/libsql\";\nimport type { ActionsRegistry } from \"./registry.js\";\nimport type { ActionContext, ActionResult } 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 * Executes a raw SQL query (for INSERT, UPDATE, DELETE)\n */\nasync function execRun(db: LibSQLDatabase, query: string): Promise<void> {\n await db.run(sql.raw(query)).execute();\n}\n\n/**\n * Registers built-in actions to the registry\n */\nexport function registerBuiltInActions(registry: ActionsRegistry): void {\n // Refresh schema action (table level)\n registry.register({\n name: \"refresh\",\n description: \"Refresh the schema cache for this module\",\n tableLevel: true,\n rowLevel: false,\n handler: async (ctx: ActionContext): Promise<ActionResult> => {\n await ctx.module.refreshSchema();\n return {\n success: true,\n message: \"Schema refreshed successfully\",\n };\n },\n });\n\n // Export table action (table level)\n registry.register({\n name: \"export\",\n description: \"Export table data in specified format (json, csv)\",\n tableLevel: true,\n rowLevel: false,\n inputSchema: {\n type: \"object\",\n properties: {\n format: {\n type: \"string\",\n enum: [\"json\", \"csv\"],\n default: \"json\",\n },\n },\n },\n handler: async (ctx: ActionContext, params): Promise<ActionResult> => {\n const format = (params.format as string) ?? \"json\";\n const data = await ctx.module.exportTable(ctx.table, format);\n return {\n success: true,\n data,\n };\n },\n });\n\n // Count rows action (table level)\n registry.register({\n name: \"count\",\n description: \"Get the total row count for this table\",\n tableLevel: true,\n rowLevel: false,\n handler: async (ctx: ActionContext): Promise<ActionResult> => {\n const result = await execAll<{ count: number }>(\n ctx.db,\n `SELECT COUNT(*) as count FROM \"${ctx.table}\"`,\n );\n return {\n success: true,\n data: { count: result[0]?.count ?? 0 },\n };\n },\n });\n\n // Duplicate row action (row level)\n registry.register({\n name: \"duplicate\",\n description: \"Create a copy of this row\",\n tableLevel: false,\n rowLevel: true,\n handler: async (ctx: ActionContext): Promise<ActionResult> => {\n if (!ctx.row) {\n return { success: false, message: \"Row data not available\" };\n }\n\n const schema = ctx.schemas.get(ctx.table);\n if (!schema) {\n return { success: false, message: `Table '${ctx.table}' not found` };\n }\n\n // Create a copy without the primary key\n const pkColumn = schema.primaryKey[0] ?? \"rowid\";\n const rowCopy = { ...ctx.row };\n delete rowCopy[pkColumn];\n delete rowCopy.rowid;\n\n // Build insert query\n const columns = Object.keys(rowCopy);\n const values = columns.map((col) => formatValueForSQL(rowCopy[col]));\n\n await execRun(\n ctx.db,\n `INSERT INTO \"${ctx.table}\" (${columns.map((c) => `\"${c}\"`).join(\", \")}) VALUES (${values.join(\", \")})`,\n );\n\n // Get the new row's ID\n const lastIdResult = await execAll<{ id: number }>(\n ctx.db,\n \"SELECT last_insert_rowid() as id\",\n );\n\n return {\n success: true,\n data: { newId: lastIdResult[0]?.id },\n message: \"Row duplicated successfully\",\n };\n },\n });\n\n // Validate row action (row level)\n registry.register({\n name: \"validate\",\n description: \"Validate row data against schema constraints\",\n tableLevel: false,\n rowLevel: true,\n handler: async (ctx: ActionContext): Promise<ActionResult> => {\n if (!ctx.row) {\n return { success: false, message: \"Row data not available\" };\n }\n\n const schema = ctx.schemas.get(ctx.table);\n if (!schema) {\n return { success: false, message: `Table '${ctx.table}' not found` };\n }\n\n const errors: string[] = [];\n\n // Check NOT NULL constraints\n for (const col of schema.columns) {\n if (col.notnull && (ctx.row[col.name] === null || ctx.row[col.name] === undefined)) {\n errors.push(`Column '${col.name}' cannot be null`);\n }\n }\n\n // Check foreign key references\n for (const fk of schema.foreignKeys) {\n const value = ctx.row[fk.from];\n if (value !== null && value !== undefined) {\n const refResult = await execAll<{ count: number }>(\n ctx.db,\n `SELECT COUNT(*) as count FROM \"${fk.table}\" WHERE \"${fk.to}\" = '${String(value).replace(/'/g, \"''\")}'`,\n );\n if (refResult[0]?.count === 0) {\n errors.push(\n `Foreign key violation: ${fk.from} references non-existent ${fk.table}.${fk.to}`,\n );\n }\n }\n }\n\n return {\n success: errors.length === 0,\n data: { errors, valid: errors.length === 0 },\n message: errors.length > 0 ? `Validation failed: ${errors.join(\"; \")}` : \"Row is valid\",\n };\n },\n });\n}\n\n/**\n * Formats a value for SQL insertion\n */\nfunction formatValueForSQL(value: unknown): string {\n if (value === null || value === undefined) {\n return \"NULL\";\n }\n if (typeof value === \"number\") {\n return String(value);\n }\n if (typeof value === \"boolean\") {\n return value ? \"1\" : \"0\";\n }\n if (value instanceof Date) {\n return `'${value.toISOString()}'`;\n }\n if (typeof value === \"object\") {\n return `'${JSON.stringify(value).replace(/'/g, \"''\")}'`;\n }\n return `'${String(value).replace(/'/g, \"''\")}'`;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/actions/registry.ts
|
|
3
|
+
/**
|
|
4
|
+
* Registry for managing action handlers
|
|
5
|
+
*/
|
|
6
|
+
var ActionsRegistry = class {
|
|
7
|
+
handlers = /* @__PURE__ */ new Map();
|
|
8
|
+
/**
|
|
9
|
+
* Registers an action handler
|
|
10
|
+
*/
|
|
11
|
+
register(definition) {
|
|
12
|
+
this.handlers.set(definition.name, definition);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Registers a simple action with just name and handler
|
|
16
|
+
*/
|
|
17
|
+
registerSimple(name, handler, options) {
|
|
18
|
+
this.register({
|
|
19
|
+
name,
|
|
20
|
+
handler,
|
|
21
|
+
description: options?.description,
|
|
22
|
+
tableLevel: options?.tableLevel ?? false,
|
|
23
|
+
rowLevel: options?.rowLevel ?? true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Unregisters an action
|
|
28
|
+
*/
|
|
29
|
+
unregister(name) {
|
|
30
|
+
return this.handlers.delete(name);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Checks if an action is registered
|
|
34
|
+
*/
|
|
35
|
+
has(name) {
|
|
36
|
+
return this.handlers.has(name);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets an action definition
|
|
40
|
+
*/
|
|
41
|
+
get(name) {
|
|
42
|
+
return this.handlers.get(name);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Lists all registered actions
|
|
46
|
+
*/
|
|
47
|
+
list(options) {
|
|
48
|
+
const actions = Array.from(this.handlers.values());
|
|
49
|
+
if (options?.tableLevel !== void 0 || options?.rowLevel !== void 0) return actions.filter((a) => {
|
|
50
|
+
if (options.tableLevel && !a.tableLevel) return false;
|
|
51
|
+
if (options.rowLevel && !a.rowLevel) return false;
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
54
|
+
return actions;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Lists action names
|
|
58
|
+
*/
|
|
59
|
+
listNames(options) {
|
|
60
|
+
return this.list(options).map((a) => a.name);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Executes an action
|
|
64
|
+
*/
|
|
65
|
+
async execute(name, ctx, params = {}) {
|
|
66
|
+
const definition = this.handlers.get(name);
|
|
67
|
+
if (!definition) return {
|
|
68
|
+
success: false,
|
|
69
|
+
message: `Unknown action: ${name}`
|
|
70
|
+
};
|
|
71
|
+
if (ctx.pk && !definition.rowLevel) return {
|
|
72
|
+
success: false,
|
|
73
|
+
message: `Action '${name}' is not available at row level`
|
|
74
|
+
};
|
|
75
|
+
if (!ctx.pk && !definition.tableLevel) return {
|
|
76
|
+
success: false,
|
|
77
|
+
message: `Action '${name}' is not available at table level`
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
return await definition.handler(ctx, params);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return {
|
|
83
|
+
success: false,
|
|
84
|
+
message: error instanceof Error ? error.message : String(error)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
exports.ActionsRegistry = ActionsRegistry;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ActionContext, ActionDefinition, ActionHandler, ActionResult } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/registry.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Registry for managing action handlers
|
|
6
|
+
*/
|
|
7
|
+
declare class ActionsRegistry {
|
|
8
|
+
private handlers;
|
|
9
|
+
/**
|
|
10
|
+
* Registers an action handler
|
|
11
|
+
*/
|
|
12
|
+
register(definition: ActionDefinition): void;
|
|
13
|
+
/**
|
|
14
|
+
* Registers a simple action with just name and handler
|
|
15
|
+
*/
|
|
16
|
+
registerSimple(name: string, handler: ActionHandler, options?: {
|
|
17
|
+
description?: string;
|
|
18
|
+
tableLevel?: boolean;
|
|
19
|
+
rowLevel?: boolean;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* Unregisters an action
|
|
23
|
+
*/
|
|
24
|
+
unregister(name: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if an action is registered
|
|
27
|
+
*/
|
|
28
|
+
has(name: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Gets an action definition
|
|
31
|
+
*/
|
|
32
|
+
get(name: string): ActionDefinition | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Lists all registered actions
|
|
35
|
+
*/
|
|
36
|
+
list(options?: {
|
|
37
|
+
tableLevel?: boolean;
|
|
38
|
+
rowLevel?: boolean;
|
|
39
|
+
}): ActionDefinition[];
|
|
40
|
+
/**
|
|
41
|
+
* Lists action names
|
|
42
|
+
*/
|
|
43
|
+
listNames(options?: {
|
|
44
|
+
tableLevel?: boolean;
|
|
45
|
+
rowLevel?: boolean;
|
|
46
|
+
}): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Executes an action
|
|
49
|
+
*/
|
|
50
|
+
execute(name: string, ctx: ActionContext, params?: Record<string, unknown>): Promise<ActionResult>;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { ActionsRegistry };
|
|
54
|
+
//# sourceMappingURL=registry.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.cts","names":[],"sources":["../../src/actions/registry.ts"],"mappings":";;;;AAKA;;cAAa,eAAA;EAAA,QAAA,QAAA;EAAA;;;EAAA,SAAA,UAAA,EAMU,gBAAA;EAAA;;;EAAA,eAAA,IAAA,UAAA,OAAA,EASV,aAAA,EAAA,OAAA;IAAA,WAAA;IAAA,UAAA;IAAA,QAAA;EAAA;EAAA;;;EAAA,WAAA,IAAA;EAAA;;;EAAA,IAAA,IAAA;EAAA;;;EAAA,IAAA,IAAA,WAiCQ,gBAAA;EAAA;;;EAAA,KAAA,OAAA;IAAA,UAAA;IAAA,QAAA;EAAA,IAO2C,gBAAA;EAAA;;;EAAA,UAAA,OAAA;IAAA,UAAA;IAAA,QAAA;EAAA;EAAA;;;EAAA,QAAA,IAAA,UAAA,GAAA,EA0BvD,aAAA,EAAA,MAAA,GACG,MAAA,oBACP,OAAA,CAAQ,YAAA;AAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ActionContext, ActionDefinition, ActionHandler, ActionResult } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/registry.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Registry for managing action handlers
|
|
6
|
+
*/
|
|
7
|
+
declare class ActionsRegistry {
|
|
8
|
+
private handlers;
|
|
9
|
+
/**
|
|
10
|
+
* Registers an action handler
|
|
11
|
+
*/
|
|
12
|
+
register(definition: ActionDefinition): void;
|
|
13
|
+
/**
|
|
14
|
+
* Registers a simple action with just name and handler
|
|
15
|
+
*/
|
|
16
|
+
registerSimple(name: string, handler: ActionHandler, options?: {
|
|
17
|
+
description?: string;
|
|
18
|
+
tableLevel?: boolean;
|
|
19
|
+
rowLevel?: boolean;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* Unregisters an action
|
|
23
|
+
*/
|
|
24
|
+
unregister(name: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if an action is registered
|
|
27
|
+
*/
|
|
28
|
+
has(name: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Gets an action definition
|
|
31
|
+
*/
|
|
32
|
+
get(name: string): ActionDefinition | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Lists all registered actions
|
|
35
|
+
*/
|
|
36
|
+
list(options?: {
|
|
37
|
+
tableLevel?: boolean;
|
|
38
|
+
rowLevel?: boolean;
|
|
39
|
+
}): ActionDefinition[];
|
|
40
|
+
/**
|
|
41
|
+
* Lists action names
|
|
42
|
+
*/
|
|
43
|
+
listNames(options?: {
|
|
44
|
+
tableLevel?: boolean;
|
|
45
|
+
rowLevel?: boolean;
|
|
46
|
+
}): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Executes an action
|
|
49
|
+
*/
|
|
50
|
+
execute(name: string, ctx: ActionContext, params?: Record<string, unknown>): Promise<ActionResult>;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { ActionsRegistry };
|
|
54
|
+
//# sourceMappingURL=registry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.mts","names":[],"sources":["../../src/actions/registry.ts"],"mappings":";;;;AAKA;;cAAa,eAAA;EAAA,QAAA,QAAA;EAAA;;;EAAA,SAAA,UAAA,EAMU,gBAAA;EAAA;;;EAAA,eAAA,IAAA,UAAA,OAAA,EASV,aAAA,EAAA,OAAA;IAAA,WAAA;IAAA,UAAA;IAAA,QAAA;EAAA;EAAA;;;EAAA,WAAA,IAAA;EAAA;;;EAAA,IAAA,IAAA;EAAA;;;EAAA,IAAA,IAAA,WAiCQ,gBAAA;EAAA;;;EAAA,KAAA,OAAA;IAAA,UAAA;IAAA,QAAA;EAAA,IAO2C,gBAAA;EAAA;;;EAAA,UAAA,OAAA;IAAA,UAAA;IAAA,QAAA;EAAA;EAAA;;;EAAA,QAAA,IAAA,UAAA,GAAA,EA0BvD,aAAA,EAAA,MAAA,GACG,MAAA,oBACP,OAAA,CAAQ,YAAA;AAAA"}
|