@aigne/afs-sqlite 1.11.0-beta.1 → 1.11.0-beta.10
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 +3 -3
- package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.cjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.mjs +10 -0
- package/dist/_virtual/rolldown_runtime.mjs +7 -0
- package/dist/actions/built-in.cjs +1262 -15
- 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 +1262 -15
- 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/registry.cjs +35 -3
- package/dist/actions/registry.d.cts +36 -17
- package/dist/actions/registry.d.cts.map +1 -1
- package/dist/actions/registry.d.mts +36 -17
- package/dist/actions/registry.d.mts.map +1 -1
- package/dist/actions/registry.mjs +35 -3
- package/dist/actions/registry.mjs.map +1 -1
- package/dist/actions/types.cjs +33 -0
- package/dist/actions/types.d.cts +46 -5
- package/dist/actions/types.d.cts.map +1 -1
- package/dist/actions/types.d.mts +46 -5
- 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 +4 -3
- package/dist/index.d.cts +4 -3
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -2
- package/dist/node/builder.cjs +74 -91
- package/dist/node/builder.d.cts +11 -15
- package/dist/node/builder.d.cts.map +1 -1
- package/dist/node/builder.d.mts +11 -15
- package/dist/node/builder.d.mts.map +1 -1
- package/dist/node/builder.mjs +72 -89
- package/dist/node/builder.mjs.map +1 -1
- package/dist/operations/crud.cjs +24 -68
- package/dist/operations/crud.d.cts +23 -38
- package/dist/operations/crud.d.cts.map +1 -1
- package/dist/operations/crud.d.mts +23 -38
- package/dist/operations/crud.d.mts.map +1 -1
- package/dist/operations/crud.mjs +25 -69
- package/dist/operations/crud.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 +5 -11
- package/dist/operations/search.d.cts +19 -23
- package/dist/operations/search.d.cts.map +1 -1
- package/dist/operations/search.d.mts +19 -23
- package/dist/operations/search.d.mts.map +1 -1
- package/dist/operations/search.mjs +5 -11
- package/dist/operations/search.mjs.map +1 -1
- package/dist/router/path-router.cjs +7 -15
- package/dist/router/path-router.d.cts +4 -7
- package/dist/router/path-router.d.cts.map +1 -1
- package/dist/router/path-router.d.mts +4 -7
- package/dist/router/path-router.d.mts.map +1 -1
- package/dist/router/path-router.mjs +7 -15
- package/dist/router/path-router.mjs.map +1 -1
- package/dist/router/types.d.cts.map +1 -1
- package/dist/router/types.d.mts.map +1 -1
- package/dist/schema/introspector.d.cts +19 -19
- package/dist/schema/introspector.d.cts.map +1 -1
- package/dist/schema/introspector.d.mts +19 -19
- package/dist/schema/introspector.d.mts.map +1 -1
- package/dist/schema/service.cjs +86 -0
- package/dist/schema/service.d.cts +52 -0
- package/dist/schema/service.d.cts.map +1 -0
- package/dist/schema/service.d.mts +52 -0
- package/dist/schema/service.d.mts.map +1 -0
- package/dist/schema/service.mjs +87 -0
- package/dist/schema/service.mjs.map +1 -0
- package/dist/schema/types.d.cts.map +1 -1
- package/dist/schema/types.d.mts.map +1 -1
- package/dist/sqlite-afs.cjs +693 -121
- package/dist/sqlite-afs.d.cts +279 -101
- package/dist/sqlite-afs.d.cts.map +1 -1
- package/dist/sqlite-afs.d.mts +279 -101
- package/dist/sqlite-afs.d.mts.map +1 -1
- package/dist/sqlite-afs.mjs +696 -123
- package/dist/sqlite-afs.mjs.map +1 -1
- package/package.json +5 -4
package/dist/node/builder.mjs
CHANGED
|
@@ -10,7 +10,8 @@ function buildRowEntry(table, schema, row, options) {
|
|
|
10
10
|
id: `${table}:${pk}`,
|
|
11
11
|
path: `${basePath}/${table}/${pk}`,
|
|
12
12
|
content: row,
|
|
13
|
-
|
|
13
|
+
meta: {
|
|
14
|
+
kind: "sqlite:row",
|
|
14
15
|
table,
|
|
15
16
|
primaryKey: pkColumn,
|
|
16
17
|
primaryKeyValue: pk
|
|
@@ -26,91 +27,18 @@ function buildTableEntry(table, schema, options) {
|
|
|
26
27
|
return {
|
|
27
28
|
id: table,
|
|
28
29
|
path: `${options?.basePath ?? ""}/${table}`,
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
meta: {
|
|
31
|
+
kind: "sqlite:table",
|
|
32
|
+
description: `Table: ${table} (${schema.columns.length} columns)`,
|
|
31
33
|
table,
|
|
32
34
|
columnCount: schema.columns.length,
|
|
33
35
|
primaryKey: schema.primaryKey,
|
|
34
|
-
childrenCount: options?.rowCount
|
|
36
|
+
childrenCount: options?.rowCount || -1
|
|
35
37
|
}
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
|
-
* Builds an AFSEntry for
|
|
40
|
-
*/
|
|
41
|
-
function buildSchemaEntry(table, schema, options) {
|
|
42
|
-
const basePath = options?.basePath ?? "";
|
|
43
|
-
return {
|
|
44
|
-
id: `${table}:@schema`,
|
|
45
|
-
path: `${basePath}/${table}/@schema`,
|
|
46
|
-
description: `Schema for table: ${table}`,
|
|
47
|
-
content: {
|
|
48
|
-
name: schema.name,
|
|
49
|
-
columns: schema.columns.map((col) => ({
|
|
50
|
-
name: col.name,
|
|
51
|
-
type: col.type,
|
|
52
|
-
nullable: !col.notnull,
|
|
53
|
-
primaryKey: col.pk > 0,
|
|
54
|
-
defaultValue: col.dfltValue
|
|
55
|
-
})),
|
|
56
|
-
primaryKey: schema.primaryKey,
|
|
57
|
-
foreignKeys: schema.foreignKeys.map((fk) => ({
|
|
58
|
-
column: fk.from,
|
|
59
|
-
references: {
|
|
60
|
-
table: fk.table,
|
|
61
|
-
column: fk.to
|
|
62
|
-
},
|
|
63
|
-
onUpdate: fk.onUpdate,
|
|
64
|
-
onDelete: fk.onDelete
|
|
65
|
-
})),
|
|
66
|
-
indexes: schema.indexes.map((idx) => ({
|
|
67
|
-
name: idx.name,
|
|
68
|
-
unique: idx.unique,
|
|
69
|
-
origin: idx.origin
|
|
70
|
-
}))
|
|
71
|
-
},
|
|
72
|
-
metadata: {
|
|
73
|
-
table,
|
|
74
|
-
type: "schema"
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Builds an AFSEntry for an attribute (single column value)
|
|
80
|
-
*/
|
|
81
|
-
function buildAttributeEntry(table, pk, column, value, options) {
|
|
82
|
-
const basePath = options?.basePath ?? "";
|
|
83
|
-
return {
|
|
84
|
-
id: `${table}:${pk}:@attr:${column}`,
|
|
85
|
-
path: `${basePath}/${table}/${pk}/@attr/${column}`,
|
|
86
|
-
content: value,
|
|
87
|
-
metadata: {
|
|
88
|
-
table,
|
|
89
|
-
primaryKeyValue: pk,
|
|
90
|
-
column,
|
|
91
|
-
type: "attribute"
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Builds an AFSEntry listing all attributes for a row
|
|
97
|
-
*/
|
|
98
|
-
function buildAttributeListEntry(table, schema, pk, row, options) {
|
|
99
|
-
const basePath = options?.basePath ?? "";
|
|
100
|
-
return schema.columns.map((col) => ({
|
|
101
|
-
id: `${table}:${pk}:@attr:${col.name}`,
|
|
102
|
-
path: `${basePath}/${table}/${pk}/@attr/${col.name}`,
|
|
103
|
-
summary: col.name,
|
|
104
|
-
description: `${col.type}${col.notnull ? " NOT NULL" : ""}`,
|
|
105
|
-
content: row[col.name],
|
|
106
|
-
metadata: {
|
|
107
|
-
column: col.name,
|
|
108
|
-
type: col.type
|
|
109
|
-
}
|
|
110
|
-
}));
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Builds an AFSEntry for row metadata
|
|
41
|
+
* Builds an AFSEntry for row metadata (using @meta suffix)
|
|
114
42
|
*/
|
|
115
43
|
function buildMetaEntry(table, schema, pk, row, options) {
|
|
116
44
|
const basePath = options?.basePath ?? "";
|
|
@@ -128,25 +56,64 @@ function buildMetaEntry(table, schema, pk, row, options) {
|
|
|
128
56
|
foreignKeys: schema.foreignKeys.filter((fk) => Object.keys(row).includes(fk.from)),
|
|
129
57
|
rowid: row.rowid
|
|
130
58
|
},
|
|
131
|
-
|
|
59
|
+
meta: {
|
|
132
60
|
table,
|
|
133
61
|
type: "meta"
|
|
134
62
|
}
|
|
135
63
|
};
|
|
136
64
|
}
|
|
137
65
|
/**
|
|
138
|
-
* Builds AFSEntry for actions list
|
|
66
|
+
* Builds AFSEntry for row-level actions list
|
|
139
67
|
*/
|
|
140
68
|
function buildActionsListEntry(table, pk, actions, options) {
|
|
141
69
|
const basePath = options?.basePath ?? "";
|
|
142
70
|
return actions.map((action) => ({
|
|
143
|
-
id: `${table}:${pk}
|
|
144
|
-
path: `${basePath}/${table}/${pk}
|
|
145
|
-
summary: action,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
71
|
+
id: `${table}:${pk}:.actions:${action.name}`,
|
|
72
|
+
path: `${basePath}/${table}/${pk}/.actions/${action.name}`,
|
|
73
|
+
summary: action.name,
|
|
74
|
+
meta: {
|
|
75
|
+
kind: "afs:executable",
|
|
76
|
+
kinds: ["afs:executable", "afs:node"],
|
|
77
|
+
name: action.name,
|
|
78
|
+
description: action.description ?? `Execute ${action.name} action on ${table}:${pk}`,
|
|
79
|
+
inputSchema: action.inputSchema
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Builds AFSEntry for table-level actions list
|
|
85
|
+
*/
|
|
86
|
+
function buildTableActionsListEntry(table, actions, options) {
|
|
87
|
+
const basePath = options?.basePath ?? "";
|
|
88
|
+
return actions.map((action) => ({
|
|
89
|
+
id: `${table}:.actions:${action.name}`,
|
|
90
|
+
path: `${basePath}/${table}/.actions/${action.name}`,
|
|
91
|
+
summary: action.name,
|
|
92
|
+
meta: {
|
|
93
|
+
kind: "afs:executable",
|
|
94
|
+
kinds: ["afs:executable", "afs:node"],
|
|
95
|
+
name: action.name,
|
|
96
|
+
description: action.description ?? `Execute ${action.name} action on table ${table}`,
|
|
97
|
+
inputSchema: action.inputSchema
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Builds AFSEntry for root-level actions list
|
|
103
|
+
*/
|
|
104
|
+
function buildRootActionsListEntry(actions, options) {
|
|
105
|
+
const basePath = options?.basePath ?? "";
|
|
106
|
+
return actions.map((action) => ({
|
|
107
|
+
id: `:actions:${action.name}`,
|
|
108
|
+
path: `${basePath}/.actions/${action.name}`,
|
|
109
|
+
summary: action.name,
|
|
110
|
+
meta: {
|
|
111
|
+
kind: "afs:executable",
|
|
112
|
+
kinds: ["afs:executable", "afs:node"],
|
|
113
|
+
name: action.name,
|
|
114
|
+
description: action.description ?? `Execute ${action.name} action`,
|
|
115
|
+
inputSchema: action.inputSchema
|
|
116
|
+
}
|
|
150
117
|
}));
|
|
151
118
|
}
|
|
152
119
|
/**
|
|
@@ -158,6 +125,22 @@ function buildSearchEntry(table, schema, row, snippet, options) {
|
|
|
158
125
|
return entry;
|
|
159
126
|
}
|
|
160
127
|
/**
|
|
128
|
+
* Builds an AFSEntry for the root (database)
|
|
129
|
+
*/
|
|
130
|
+
function buildRootEntry(schemas, options) {
|
|
131
|
+
const basePath = options?.basePath ?? "";
|
|
132
|
+
return {
|
|
133
|
+
id: "root",
|
|
134
|
+
path: basePath === "" ? "/" : basePath,
|
|
135
|
+
meta: {
|
|
136
|
+
kind: "sqlite:database",
|
|
137
|
+
description: "SQLite database root",
|
|
138
|
+
childrenCount: schemas.size,
|
|
139
|
+
tableCount: schemas.size
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
161
144
|
* Parses a date from various formats
|
|
162
145
|
*/
|
|
163
146
|
function parseDate(value) {
|
|
@@ -168,5 +151,5 @@ function parseDate(value) {
|
|
|
168
151
|
}
|
|
169
152
|
|
|
170
153
|
//#endregion
|
|
171
|
-
export { buildActionsListEntry,
|
|
154
|
+
export { buildActionsListEntry, buildMetaEntry, buildRootActionsListEntry, buildRootEntry, buildRowEntry, buildSearchEntry, buildTableActionsListEntry, buildTableEntry };
|
|
172
155
|
//# sourceMappingURL=builder.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.mjs","names":[],"sources":["../../src/node/builder.ts"],"sourcesContent":["import type { AFSEntry } from \"@aigne/afs\";\nimport type { TableSchema } from \"../schema/types.js\";\n\n/**\n * Options for building an AFSEntry\n */\nexport interface BuildEntryOptions {\n /** Base path prefix (e.g., empty string or module mount path) */\n basePath?: string;\n}\n\n/**\n * Builds an AFSEntry from a database row\n */\nexport function buildRowEntry(\n table: string,\n schema: TableSchema,\n row: Record<string, unknown>,\n options?: BuildEntryOptions,\n): AFSEntry {\n const pkColumn = schema.primaryKey[0] ?? \"rowid\";\n const pk = String(row[pkColumn] ?? row.rowid);\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: `${table}:${pk}`,\n path: `${basePath}/${table}/${pk}`,\n content: row,\n metadata: {\n table,\n primaryKey: pkColumn,\n primaryKeyValue: pk,\n },\n createdAt: parseDate(row.created_at ?? row.createdAt),\n updatedAt: parseDate(row.updated_at ?? row.updatedAt),\n };\n}\n\n/**\n * Builds an AFSEntry for a table listing\n */\nexport function buildTableEntry(\n table: string,\n schema: TableSchema,\n options?: BuildEntryOptions & { rowCount?: number },\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: table,\n path: `${basePath}/${table}`,\n description: `Table: ${table} (${schema.columns.length} columns)`,\n metadata: {\n table,\n columnCount: schema.columns.length,\n primaryKey: schema.primaryKey,\n childrenCount: options?.rowCount,\n },\n };\n}\n\n/**\n * Builds an AFSEntry for table schema\n */\nexport function buildSchemaEntry(\n table: string,\n schema: TableSchema,\n options?: BuildEntryOptions,\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: `${table}:@schema`,\n path: `${basePath}/${table}/@schema`,\n description: `Schema for table: ${table}`,\n content: {\n name: schema.name,\n columns: schema.columns.map((col) => ({\n name: col.name,\n type: col.type,\n nullable: !col.notnull,\n primaryKey: col.pk > 0,\n defaultValue: col.dfltValue,\n })),\n primaryKey: schema.primaryKey,\n foreignKeys: schema.foreignKeys.map((fk) => ({\n column: fk.from,\n references: {\n table: fk.table,\n column: fk.to,\n },\n onUpdate: fk.onUpdate,\n onDelete: fk.onDelete,\n })),\n indexes: schema.indexes.map((idx) => ({\n name: idx.name,\n unique: idx.unique,\n origin: idx.origin,\n })),\n },\n metadata: {\n table,\n type: \"schema\",\n },\n };\n}\n\n/**\n * Builds an AFSEntry for an attribute (single column value)\n */\nexport function buildAttributeEntry(\n table: string,\n pk: string,\n column: string,\n value: unknown,\n options?: BuildEntryOptions,\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: `${table}:${pk}:@attr:${column}`,\n path: `${basePath}/${table}/${pk}/@attr/${column}`,\n content: value,\n metadata: {\n table,\n primaryKeyValue: pk,\n column,\n type: \"attribute\",\n },\n };\n}\n\n/**\n * Builds an AFSEntry listing all attributes for a row\n */\nexport function buildAttributeListEntry(\n table: string,\n schema: TableSchema,\n pk: string,\n row: Record<string, unknown>,\n options?: BuildEntryOptions,\n): AFSEntry[] {\n const basePath = options?.basePath ?? \"\";\n\n return schema.columns.map((col) => ({\n id: `${table}:${pk}:@attr:${col.name}`,\n path: `${basePath}/${table}/${pk}/@attr/${col.name}`,\n summary: col.name,\n description: `${col.type}${col.notnull ? \" NOT NULL\" : \"\"}`,\n content: row[col.name],\n metadata: {\n column: col.name,\n type: col.type,\n },\n }));\n}\n\n/**\n * Builds an AFSEntry for row metadata\n */\nexport function buildMetaEntry(\n table: string,\n schema: TableSchema,\n pk: string,\n row: Record<string, unknown>,\n options?: BuildEntryOptions,\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: `${table}:${pk}:@meta`,\n path: `${basePath}/${table}/${pk}/@meta`,\n content: {\n table,\n primaryKey: schema.primaryKey[0] ?? \"rowid\",\n primaryKeyValue: pk,\n schema: {\n columns: schema.columns.map((c) => c.name),\n types: Object.fromEntries(schema.columns.map((c) => [c.name, c.type])),\n },\n foreignKeys: schema.foreignKeys.filter((fk) => Object.keys(row).includes(fk.from)),\n rowid: row.rowid,\n },\n metadata: {\n table,\n type: \"meta\",\n },\n };\n}\n\n/**\n * Builds AFSEntry for actions list\n */\nexport function buildActionsListEntry(\n table: string,\n pk: string,\n actions: string[],\n options?: BuildEntryOptions,\n): AFSEntry[] {\n const basePath = options?.basePath ?? \"\";\n\n return actions.map((action) => ({\n id: `${table}:${pk}:@actions:${action}`,\n path: `${basePath}/${table}/${pk}/@actions/${action}`,\n summary: action,\n metadata: {\n execute: {\n name: action,\n description: `Execute ${action} action on ${table}:${pk}`,\n },\n },\n }));\n}\n\n/**\n * Builds a search result entry with highlights\n */\nexport function buildSearchEntry(\n table: string,\n schema: TableSchema,\n row: Record<string, unknown>,\n snippet?: string,\n options?: BuildEntryOptions,\n): AFSEntry {\n const entry = buildRowEntry(table, schema, row, options);\n\n if (snippet) {\n entry.summary = snippet;\n }\n\n return entry;\n}\n\n/**\n * Parses a date from various formats\n */\nfunction parseDate(value: unknown): Date | undefined {\n if (!value) return undefined;\n if (value instanceof Date) return value;\n if (typeof value === \"string\") return new Date(value);\n if (typeof value === \"number\") return new Date(value);\n return undefined;\n}\n"],"mappings":";;;;AAcA,SAAgB,cACd,OACA,QACA,KACA,SACU;CACV,MAAM,WAAW,OAAO,WAAW,MAAM;CACzC,MAAM,KAAK,OAAO,IAAI,aAAa,IAAI,MAAM;CAC7C,MAAM,WAAW,SAAS,YAAY;AAEtC,QAAO;EACL,IAAI,GAAG,MAAM,GAAG;EAChB,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG;EAC9B,SAAS;EACT,UAAU;GACR;GACA,YAAY;GACZ,iBAAiB;GAClB;EACD,WAAW,UAAU,IAAI,cAAc,IAAI,UAAU;EACrD,WAAW,UAAU,IAAI,cAAc,IAAI,UAAU;EACtD;;;;;AAMH,SAAgB,gBACd,OACA,QACA,SACU;AAGV,QAAO;EACL,IAAI;EACJ,MAAM,GAJS,SAAS,YAAY,GAIlB,GAAG;EACrB,aAAa,UAAU,MAAM,IAAI,OAAO,QAAQ,OAAO;EACvD,UAAU;GACR;GACA,aAAa,OAAO,QAAQ;GAC5B,YAAY,OAAO;GACnB,eAAe,SAAS;GACzB;EACF;;;;;AAMH,SAAgB,iBACd,OACA,QACA,SACU;CACV,MAAM,WAAW,SAAS,YAAY;AAEtC,QAAO;EACL,IAAI,GAAG,MAAM;EACb,MAAM,GAAG,SAAS,GAAG,MAAM;EAC3B,aAAa,qBAAqB;EAClC,SAAS;GACP,MAAM,OAAO;GACb,SAAS,OAAO,QAAQ,KAAK,SAAS;IACpC,MAAM,IAAI;IACV,MAAM,IAAI;IACV,UAAU,CAAC,IAAI;IACf,YAAY,IAAI,KAAK;IACrB,cAAc,IAAI;IACnB,EAAE;GACH,YAAY,OAAO;GACnB,aAAa,OAAO,YAAY,KAAK,QAAQ;IAC3C,QAAQ,GAAG;IACX,YAAY;KACV,OAAO,GAAG;KACV,QAAQ,GAAG;KACZ;IACD,UAAU,GAAG;IACb,UAAU,GAAG;IACd,EAAE;GACH,SAAS,OAAO,QAAQ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GAClF,OAAO,IAAI;GACZ;EACD,UAAU;GACR;GACA,MAAM;GACP;EACF;;;;;AAMH,SAAgB,sBACd,OACA,IACA,SACA,SACY;CACZ,MAAM,WAAW,SAAS,YAAY;AAEtC,QAAO,QAAQ,KAAK,YAAY;EAC9B,IAAI,GAAG,MAAM,GAAG,GAAG,YAAY;EAC/B,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,GAAG,YAAY;EAC7C,SAAS;EACT,UAAU,EACR,SAAS;GACP,MAAM;GACN,aAAa,WAAW,OAAO,aAAa,MAAM,GAAG;GACtD,EACF;EACF,EAAE;;;;;AAML,SAAgB,iBACd,OACA,QACA,KACA,SACA,SACU;CACV,MAAM,QAAQ,cAAc,OAAO,QAAQ,KAAK,QAAQ;AAExD,KAAI,QACF,OAAM,UAAU;AAGlB,QAAO;;;;;AAMT,SAAS,UAAU,OAAkC;AACnD,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,iBAAiB,KAAM,QAAO;AAClC,KAAI,OAAO,UAAU,SAAU,QAAO,IAAI,KAAK,MAAM;AACrD,KAAI,OAAO,UAAU,SAAU,QAAO,IAAI,KAAK,MAAM"}
|
|
1
|
+
{"version":3,"file":"builder.mjs","names":[],"sources":["../../src/node/builder.ts"],"sourcesContent":["import type { AFSEntry } from \"@aigne/afs\";\nimport type { TableSchema } from \"../schema/types.js\";\n\n/**\n * Options for building an AFSEntry\n */\nexport interface BuildEntryOptions {\n /** Base path prefix (e.g., empty string or module mount path) */\n basePath?: string;\n}\n\n/**\n * Builds an AFSEntry from a database row\n */\nexport function buildRowEntry(\n table: string,\n schema: TableSchema,\n row: Record<string, unknown>,\n options?: BuildEntryOptions,\n): AFSEntry {\n const pkColumn = schema.primaryKey[0] ?? \"rowid\";\n const pk = String(row[pkColumn] ?? row.rowid);\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: `${table}:${pk}`,\n path: `${basePath}/${table}/${pk}`,\n content: row,\n meta: {\n kind: \"sqlite:row\",\n table,\n primaryKey: pkColumn,\n primaryKeyValue: pk,\n },\n createdAt: parseDate(row.created_at ?? row.createdAt),\n updatedAt: parseDate(row.updated_at ?? row.updatedAt),\n };\n}\n\n/**\n * Builds an AFSEntry for a table listing\n */\nexport function buildTableEntry(\n table: string,\n schema: TableSchema,\n options?: BuildEntryOptions & { rowCount?: number },\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: table,\n path: `${basePath}/${table}`,\n meta: {\n kind: \"sqlite:table\",\n description: `Table: ${table} (${schema.columns.length} columns)`,\n table,\n columnCount: schema.columns.length,\n primaryKey: schema.primaryKey,\n childrenCount: options?.rowCount || -1,\n },\n };\n}\n\n/**\n * Builds an AFSEntry for row metadata (using @meta suffix)\n */\nexport function buildMetaEntry(\n table: string,\n schema: TableSchema,\n pk: string,\n row: Record<string, unknown>,\n options?: BuildEntryOptions,\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: `${table}:${pk}:@meta`,\n path: `${basePath}/${table}/${pk}/@meta`,\n content: {\n table,\n primaryKey: schema.primaryKey[0] ?? \"rowid\",\n primaryKeyValue: pk,\n schema: {\n columns: schema.columns.map((c) => c.name),\n types: Object.fromEntries(schema.columns.map((c) => [c.name, c.type])),\n },\n foreignKeys: schema.foreignKeys.filter((fk) => Object.keys(row).includes(fk.from)),\n rowid: row.rowid,\n },\n meta: {\n table,\n type: \"meta\",\n },\n };\n}\n\n/**\n * Builds an AFSEntry for row metadata (using .meta suffix - conformance standard)\n */\nexport function buildRowDotMetaEntry(\n table: string,\n schema: TableSchema,\n pk: string,\n _row: Record<string, unknown>,\n options?: BuildEntryOptions,\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: `${table}:${pk}:.meta`,\n path: `${basePath}/${table}/${pk}/.meta`,\n meta: {\n table,\n primaryKey: schema.primaryKey[0] ?? \"rowid\",\n primaryKeyValue: pk,\n columnCount: schema.columns.length,\n columns: schema.columns.map((c) => c.name),\n },\n };\n}\n\n/**\n * Action definition with optional schema\n */\nexport interface ActionDefinitionInfo {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\n/**\n * Builds AFSEntry for row-level actions list\n */\nexport function buildActionsListEntry(\n table: string,\n pk: string,\n actions: ActionDefinitionInfo[],\n options?: BuildEntryOptions,\n): AFSEntry[] {\n const basePath = options?.basePath ?? \"\";\n\n return actions.map((action) => ({\n id: `${table}:${pk}:.actions:${action.name}`,\n path: `${basePath}/${table}/${pk}/.actions/${action.name}`,\n summary: action.name,\n meta: {\n kind: \"afs:executable\",\n kinds: [\"afs:executable\", \"afs:node\"],\n name: action.name,\n description: action.description ?? `Execute ${action.name} action on ${table}:${pk}`,\n inputSchema: action.inputSchema,\n },\n }));\n}\n\n/**\n * Builds AFSEntry for table-level actions list\n */\nexport function buildTableActionsListEntry(\n table: string,\n actions: ActionDefinitionInfo[],\n options?: BuildEntryOptions,\n): AFSEntry[] {\n const basePath = options?.basePath ?? \"\";\n\n return actions.map((action) => ({\n id: `${table}:.actions:${action.name}`,\n path: `${basePath}/${table}/.actions/${action.name}`,\n summary: action.name,\n meta: {\n kind: \"afs:executable\",\n kinds: [\"afs:executable\", \"afs:node\"],\n name: action.name,\n description: action.description ?? `Execute ${action.name} action on table ${table}`,\n inputSchema: action.inputSchema,\n },\n }));\n}\n\n/**\n * Builds AFSEntry for root-level actions list\n */\nexport function buildRootActionsListEntry(\n actions: ActionDefinitionInfo[],\n options?: BuildEntryOptions,\n): AFSEntry[] {\n const basePath = options?.basePath ?? \"\";\n\n return actions.map((action) => ({\n id: `:actions:${action.name}`,\n path: `${basePath}/.actions/${action.name}`,\n summary: action.name,\n meta: {\n kind: \"afs:executable\",\n kinds: [\"afs:executable\", \"afs:node\"],\n name: action.name,\n description: action.description ?? `Execute ${action.name} action`,\n inputSchema: action.inputSchema,\n },\n }));\n}\n\n/**\n * Builds a search result entry with highlights\n */\nexport function buildSearchEntry(\n table: string,\n schema: TableSchema,\n row: Record<string, unknown>,\n snippet?: string,\n options?: BuildEntryOptions,\n): AFSEntry {\n const entry = buildRowEntry(table, schema, row, options);\n\n if (snippet) {\n entry.summary = snippet;\n }\n\n return entry;\n}\n\n/**\n * Builds an AFSEntry for the root (database)\n */\nexport function buildRootEntry(\n schemas: Map<string, TableSchema>,\n options?: BuildEntryOptions,\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: \"root\",\n path: basePath === \"\" ? \"/\" : basePath,\n meta: {\n kind: \"sqlite:database\",\n description: \"SQLite database root\",\n childrenCount: schemas.size,\n tableCount: schemas.size,\n },\n };\n}\n\n/**\n * Builds an AFSEntry for root metadata\n */\nexport function buildRootMetaEntry(\n schemas: Map<string, TableSchema>,\n options?: BuildEntryOptions,\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: \"root:meta\",\n path: `${basePath}/.meta`,\n meta: {\n description: \"SQLite database metadata\",\n tableCount: schemas.size,\n tables: Array.from(schemas.keys()),\n },\n };\n}\n\n/**\n * Builds an AFSEntry for table metadata (directory-level, not row-level)\n */\nexport function buildTableMetaEntry(\n table: string,\n schema: TableSchema,\n options?: BuildEntryOptions & { rowCount?: number },\n): AFSEntry {\n const basePath = options?.basePath ?? \"\";\n\n return {\n id: `${table}:meta`,\n path: `${basePath}/${table}/.meta`,\n meta: {\n description: `Table metadata for: ${table}`,\n table,\n columnCount: schema.columns.length,\n primaryKey: schema.primaryKey,\n columns: schema.columns.map((c) => c.name),\n rowCount: options?.rowCount,\n },\n };\n}\n\n/**\n * Parses a date from various formats\n */\nfunction parseDate(value: unknown): Date | undefined {\n if (!value) return undefined;\n if (value instanceof Date) return value;\n if (typeof value === \"string\") return new Date(value);\n if (typeof value === \"number\") return new Date(value);\n return undefined;\n}\n"],"mappings":";;;;AAcA,SAAgB,cACd,OACA,QACA,KACA,SACU;CACV,MAAM,WAAW,OAAO,WAAW,MAAM;CACzC,MAAM,KAAK,OAAO,IAAI,aAAa,IAAI,MAAM;CAC7C,MAAM,WAAW,SAA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QAAQ;GACrB;EACF;;;;;AAkDH,SAAS,UAAU,OAAkC;AACnD,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,iBAAiB,KAAM,QAAO;AAClC,KAAI,OAAO,UAAU,SAAU,QAAO,IAAI,KAAK,MAAM;AACrD,KAAI,OAAO,UAAU,SAAU,QAAO,IAAI,KAAK,MAAM"}
|
package/dist/operations/crud.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_builder = require('../node/builder.cjs');
|
|
2
2
|
const require_query_builder = require('./query-builder.cjs');
|
|
3
3
|
let _aigne_sqlite = require("@aigne/sqlite");
|
|
4
|
+
let _aigne_afs = require("@aigne/afs");
|
|
4
5
|
|
|
5
6
|
//#region src/operations/crud.ts
|
|
6
7
|
/**
|
|
@@ -19,9 +20,9 @@ async function execRun(db, query) {
|
|
|
19
20
|
* CRUD operations for SQLite AFS
|
|
20
21
|
*/
|
|
21
22
|
var CRUDOperations = class {
|
|
22
|
-
constructor(db,
|
|
23
|
+
constructor(db, schemaService, basePath = "") {
|
|
23
24
|
this.db = db;
|
|
24
|
-
this.
|
|
25
|
+
this.schemaService = schemaService;
|
|
25
26
|
this.basePath = basePath;
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
@@ -30,7 +31,8 @@ var CRUDOperations = class {
|
|
|
30
31
|
async listTables() {
|
|
31
32
|
const entries = [];
|
|
32
33
|
const buildOptions = { basePath: this.basePath };
|
|
33
|
-
|
|
34
|
+
const schemas = await this.schemaService.getAllSchemas();
|
|
35
|
+
for (const [name, schema] of schemas) {
|
|
34
36
|
const rowCount = (await execAll(this.db, `SELECT COUNT(*) as count FROM "${name}"`))[0]?.count ?? 0;
|
|
35
37
|
entries.push(require_builder.buildTableEntry(name, schema, {
|
|
36
38
|
...buildOptions,
|
|
@@ -43,11 +45,8 @@ var CRUDOperations = class {
|
|
|
43
45
|
* Lists rows in a table
|
|
44
46
|
*/
|
|
45
47
|
async listTable(table, options) {
|
|
46
|
-
const schema = this.
|
|
47
|
-
if (!schema)
|
|
48
|
-
data: [],
|
|
49
|
-
message: `Table '${table}' not found`
|
|
50
|
-
};
|
|
48
|
+
const schema = await this.schemaService.getSchema(table);
|
|
49
|
+
if (!schema) throw new _aigne_afs.AFSNotFoundError(`/${table}`);
|
|
51
50
|
const buildOptions = { basePath: this.basePath };
|
|
52
51
|
const queryStr = require_query_builder.buildSelectAll(table, {
|
|
53
52
|
limit: options?.limit ?? 100,
|
|
@@ -59,67 +58,30 @@ var CRUDOperations = class {
|
|
|
59
58
|
* Reads a single row by primary key
|
|
60
59
|
*/
|
|
61
60
|
async readRow(table, pk) {
|
|
62
|
-
const schema = this.
|
|
63
|
-
if (!schema)
|
|
61
|
+
const schema = await this.schemaService.getSchema(table);
|
|
62
|
+
if (!schema) throw new _aigne_afs.AFSNotFoundError(`/${table}`);
|
|
64
63
|
const buildOptions = { basePath: this.basePath };
|
|
65
64
|
const row = (await execAll(this.db, require_query_builder.buildSelectByPK(table, schema, pk)))[0];
|
|
66
|
-
if (!row)
|
|
65
|
+
if (!row) throw new _aigne_afs.AFSNotFoundError(`/${table}/${pk}`);
|
|
67
66
|
return { data: require_builder.buildRowEntry(table, schema, row, buildOptions) };
|
|
68
67
|
}
|
|
69
68
|
/**
|
|
70
|
-
* Gets table schema
|
|
71
|
-
*/
|
|
72
|
-
getSchema(table) {
|
|
73
|
-
const schema = this.schemas.get(table);
|
|
74
|
-
if (!schema) return { message: `Table '${table}' not found` };
|
|
75
|
-
return { data: require_builder.buildSchemaEntry(table, schema, { basePath: this.basePath }) };
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Lists attributes (columns) for a row
|
|
79
|
-
*/
|
|
80
|
-
async listAttributes(table, pk) {
|
|
81
|
-
const schema = this.schemas.get(table);
|
|
82
|
-
if (!schema) return {
|
|
83
|
-
data: [],
|
|
84
|
-
message: `Table '${table}' not found`
|
|
85
|
-
};
|
|
86
|
-
const buildOptions = { basePath: this.basePath };
|
|
87
|
-
const row = (await execAll(this.db, require_query_builder.buildSelectByPK(table, schema, pk)))[0];
|
|
88
|
-
if (!row) return {
|
|
89
|
-
data: [],
|
|
90
|
-
message: `Row with pk '${pk}' not found`
|
|
91
|
-
};
|
|
92
|
-
return { data: require_builder.buildAttributeListEntry(table, schema, pk, row, buildOptions) };
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Gets a single attribute (column value) for a row
|
|
96
|
-
*/
|
|
97
|
-
async getAttribute(table, pk, column) {
|
|
98
|
-
const schema = this.schemas.get(table);
|
|
99
|
-
if (!schema) return { message: `Table '${table}' not found` };
|
|
100
|
-
if (!schema.columns.find((c) => c.name === column)) return { message: `Column '${column}' not found in table '${table}'` };
|
|
101
|
-
const buildOptions = { basePath: this.basePath };
|
|
102
|
-
const rows = await execAll(this.db, require_query_builder.buildSelectByPK(table, schema, pk));
|
|
103
|
-
if (rows.length === 0) return { message: `Row with pk '${pk}' not found` };
|
|
104
|
-
return { data: require_builder.buildAttributeEntry(table, pk, column, rows[0]?.[column], buildOptions) };
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
69
|
* Gets row metadata
|
|
108
70
|
*/
|
|
109
71
|
async getMeta(table, pk) {
|
|
110
|
-
const schema = this.
|
|
111
|
-
if (!schema)
|
|
72
|
+
const schema = await this.schemaService.getSchema(table);
|
|
73
|
+
if (!schema) throw new _aigne_afs.AFSNotFoundError(`/${table}`);
|
|
112
74
|
const buildOptions = { basePath: this.basePath };
|
|
113
75
|
const row = (await execAll(this.db, require_query_builder.buildSelectByPK(table, schema, pk)))[0];
|
|
114
|
-
if (!row)
|
|
76
|
+
if (!row) throw new _aigne_afs.AFSNotFoundError(`/${table}/${pk}/@meta`);
|
|
115
77
|
return { data: require_builder.buildMetaEntry(table, schema, pk, row, buildOptions) };
|
|
116
78
|
}
|
|
117
79
|
/**
|
|
118
80
|
* Creates a new row in a table
|
|
119
81
|
*/
|
|
120
82
|
async createRow(table, content) {
|
|
121
|
-
const schema = this.
|
|
122
|
-
if (!schema) throw new
|
|
83
|
+
const schema = await this.schemaService.getSchema(table);
|
|
84
|
+
if (!schema) throw new _aigne_afs.AFSNotFoundError(`/${table}`);
|
|
123
85
|
const buildOptions = { basePath: this.basePath };
|
|
124
86
|
await execRun(this.db, require_query_builder.buildInsert(table, schema, content));
|
|
125
87
|
const lastId = (await execAll(this.db, require_query_builder.buildGetLastRowId()))[0]?.id;
|
|
@@ -134,8 +96,8 @@ var CRUDOperations = class {
|
|
|
134
96
|
* Updates an existing row
|
|
135
97
|
*/
|
|
136
98
|
async updateRow(table, pk, content) {
|
|
137
|
-
const schema = this.
|
|
138
|
-
if (!schema) throw new
|
|
99
|
+
const schema = await this.schemaService.getSchema(table);
|
|
100
|
+
if (!schema) throw new _aigne_afs.AFSNotFoundError(`/${table}`);
|
|
139
101
|
const buildOptions = { basePath: this.basePath };
|
|
140
102
|
await execRun(this.db, require_query_builder.buildUpdate(table, schema, pk, content));
|
|
141
103
|
const row = (await execAll(this.db, require_query_builder.buildSelectByPK(table, schema, pk)))[0];
|
|
@@ -146,29 +108,23 @@ var CRUDOperations = class {
|
|
|
146
108
|
* Deletes a row by primary key
|
|
147
109
|
*/
|
|
148
110
|
async deleteRow(table, pk) {
|
|
149
|
-
const schema = this.
|
|
150
|
-
if (!schema) throw new
|
|
151
|
-
if ((await execAll(this.db, require_query_builder.buildSelectByPK(table, schema, pk))).length === 0)
|
|
111
|
+
const schema = await this.schemaService.getSchema(table);
|
|
112
|
+
if (!schema) throw new _aigne_afs.AFSNotFoundError(`/${table}`);
|
|
113
|
+
if ((await execAll(this.db, require_query_builder.buildSelectByPK(table, schema, pk))).length === 0) throw new _aigne_afs.AFSNotFoundError(`/${table}/${pk}`);
|
|
152
114
|
await execRun(this.db, require_query_builder.buildDelete(table, schema, pk));
|
|
153
115
|
return { message: `Deleted row '${pk}' from table '${table}'` };
|
|
154
116
|
}
|
|
155
117
|
/**
|
|
156
118
|
* Checks if a table exists
|
|
157
119
|
*/
|
|
158
|
-
hasTable(table) {
|
|
159
|
-
return this.
|
|
120
|
+
async hasTable(table) {
|
|
121
|
+
return this.schemaService.hasTable(table);
|
|
160
122
|
}
|
|
161
123
|
/**
|
|
162
124
|
* Gets the schema for a table
|
|
163
125
|
*/
|
|
164
|
-
getTableSchema(table) {
|
|
165
|
-
return this.
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Updates the schemas map (after refresh)
|
|
169
|
-
*/
|
|
170
|
-
setSchemas(schemas) {
|
|
171
|
-
this.schemas = schemas;
|
|
126
|
+
async getTableSchema(table) {
|
|
127
|
+
return this.schemaService.getSchema(table);
|
|
172
128
|
}
|
|
173
129
|
};
|
|
174
130
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TableSchema } from "../schema/types.cjs";
|
|
2
|
+
import { SchemaService } from "../schema/service.cjs";
|
|
2
3
|
import { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
3
4
|
import { AFSDeleteResult, AFSListOptions, AFSListResult, AFSReadResult, AFSWriteResult } from "@aigne/afs";
|
|
4
5
|
|
|
@@ -8,61 +9,45 @@ import { AFSDeleteResult, AFSListOptions, AFSListResult, AFSReadResult, AFSWrite
|
|
|
8
9
|
*/
|
|
9
10
|
declare class CRUDOperations {
|
|
10
11
|
private db;
|
|
11
|
-
private
|
|
12
|
+
private schemaService;
|
|
12
13
|
private basePath;
|
|
13
|
-
constructor(db: LibSQLDatabase,
|
|
14
|
+
constructor(db: LibSQLDatabase, schemaService: SchemaService, basePath?: string);
|
|
14
15
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
* Lists all tables
|
|
17
|
+
*/
|
|
17
18
|
listTables(): Promise<AFSListResult>;
|
|
18
19
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
* Lists rows in a table
|
|
21
|
+
*/
|
|
21
22
|
listTable(table: string, options?: AFSListOptions): Promise<AFSListResult>;
|
|
22
23
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
* Reads a single row by primary key
|
|
25
|
+
*/
|
|
25
26
|
readRow(table: string, pk: string): Promise<AFSReadResult>;
|
|
26
27
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
getSchema(table: string): AFSReadResult;
|
|
30
|
-
/**
|
|
31
|
-
* Lists attributes (columns) for a row
|
|
32
|
-
*/
|
|
33
|
-
listAttributes(table: string, pk: string): Promise<AFSListResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Gets a single attribute (column value) for a row
|
|
36
|
-
*/
|
|
37
|
-
getAttribute(table: string, pk: string, column: string): Promise<AFSReadResult>;
|
|
38
|
-
/**
|
|
39
|
-
* Gets row metadata
|
|
40
|
-
*/
|
|
28
|
+
* Gets row metadata
|
|
29
|
+
*/
|
|
41
30
|
getMeta(table: string, pk: string): Promise<AFSReadResult>;
|
|
42
31
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
* Creates a new row in a table
|
|
33
|
+
*/
|
|
45
34
|
createRow(table: string, content: Record<string, unknown>): Promise<AFSWriteResult>;
|
|
46
35
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
* Updates an existing row
|
|
37
|
+
*/
|
|
49
38
|
updateRow(table: string, pk: string, content: Record<string, unknown>): Promise<AFSWriteResult>;
|
|
50
39
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
* Deletes a row by primary key
|
|
41
|
+
*/
|
|
53
42
|
deleteRow(table: string, pk: string): Promise<AFSDeleteResult>;
|
|
54
43
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
hasTable(table: string): boolean
|
|
58
|
-
/**
|
|
59
|
-
* Gets the schema for a table
|
|
60
|
-
*/
|
|
61
|
-
getTableSchema(table: string): TableSchema | undefined;
|
|
44
|
+
* Checks if a table exists
|
|
45
|
+
*/
|
|
46
|
+
hasTable(table: string): Promise<boolean>;
|
|
62
47
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
48
|
+
* Gets the schema for a table
|
|
49
|
+
*/
|
|
50
|
+
getTableSchema(table: string): Promise<TableSchema | undefined>;
|
|
66
51
|
}
|
|
67
52
|
//#endregion
|
|
68
53
|
export { CRUDOperations };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.d.cts","names":[],"sources":["../../src/operations/crud.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"crud.d.cts","names":[],"sources":["../../src/operations/crud.ts"],"mappings":";;;;;;;;AA6CA;cAAa,cAAA;EAAA,QAED,EAAA;EAAA,QACA,aAAA;EAAA,QACA,QAAA;cAFA,EAAA,EAAI,cAAA,EACJ,aAAA,EAAe,aAAA,EACf,QAAA;EAMU;;;EAAd,UAAA,CAAA,GAAc,OAAA,CAAQ,aAAA;EA6CsB;;;EAvB5C,SAAA,CAAU,KAAA,UAAe,OAAA,GAAU,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAuE1B;;;EAhDlC,OAAA,CAAQ,KAAA,UAAe,EAAA,WAAa,OAAA,CAAQ,aAAA;EA2FvC;;;EAnEL,OAAA,CAAQ,KAAA,UAAe,EAAA,WAAa,OAAA,CAAQ,aAAA;EAwHnB;;;EAhGzB,SAAA,CAAU,KAAA,UAAe,OAAA,EAAS,MAAA,oBAA0B,OAAA,CAAQ,cAAA;EAuG9B;;;EAhEtC,SAAA,CACJ,KAAA,UACA,EAAA,UACA,OAAA,EAAS,MAAA,oBACR,OAAA,CAAQ,cAAA;;;;EA4BL,SAAA,CAAU,KAAA,UAAe,EAAA,WAAa,OAAA,CAAQ,eAAA;EA3K1C;;;EAoMJ,QAAA,CAAS,KAAA,WAAgB,OAAA;EA7LH;;;EAoMtB,cAAA,CAAe,KAAA,WAAgB,OAAA,CAAQ,WAAA;AAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TableSchema } from "../schema/types.mjs";
|
|
2
|
+
import { SchemaService } from "../schema/service.mjs";
|
|
2
3
|
import { AFSDeleteResult, AFSListOptions, AFSListResult, AFSReadResult, AFSWriteResult } from "@aigne/afs";
|
|
3
4
|
import { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
4
5
|
|
|
@@ -8,61 +9,45 @@ import { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
|
8
9
|
*/
|
|
9
10
|
declare class CRUDOperations {
|
|
10
11
|
private db;
|
|
11
|
-
private
|
|
12
|
+
private schemaService;
|
|
12
13
|
private basePath;
|
|
13
|
-
constructor(db: LibSQLDatabase,
|
|
14
|
+
constructor(db: LibSQLDatabase, schemaService: SchemaService, basePath?: string);
|
|
14
15
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
* Lists all tables
|
|
17
|
+
*/
|
|
17
18
|
listTables(): Promise<AFSListResult>;
|
|
18
19
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
* Lists rows in a table
|
|
21
|
+
*/
|
|
21
22
|
listTable(table: string, options?: AFSListOptions): Promise<AFSListResult>;
|
|
22
23
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
* Reads a single row by primary key
|
|
25
|
+
*/
|
|
25
26
|
readRow(table: string, pk: string): Promise<AFSReadResult>;
|
|
26
27
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
getSchema(table: string): AFSReadResult;
|
|
30
|
-
/**
|
|
31
|
-
* Lists attributes (columns) for a row
|
|
32
|
-
*/
|
|
33
|
-
listAttributes(table: string, pk: string): Promise<AFSListResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Gets a single attribute (column value) for a row
|
|
36
|
-
*/
|
|
37
|
-
getAttribute(table: string, pk: string, column: string): Promise<AFSReadResult>;
|
|
38
|
-
/**
|
|
39
|
-
* Gets row metadata
|
|
40
|
-
*/
|
|
28
|
+
* Gets row metadata
|
|
29
|
+
*/
|
|
41
30
|
getMeta(table: string, pk: string): Promise<AFSReadResult>;
|
|
42
31
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
* Creates a new row in a table
|
|
33
|
+
*/
|
|
45
34
|
createRow(table: string, content: Record<string, unknown>): Promise<AFSWriteResult>;
|
|
46
35
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
* Updates an existing row
|
|
37
|
+
*/
|
|
49
38
|
updateRow(table: string, pk: string, content: Record<string, unknown>): Promise<AFSWriteResult>;
|
|
50
39
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
* Deletes a row by primary key
|
|
41
|
+
*/
|
|
53
42
|
deleteRow(table: string, pk: string): Promise<AFSDeleteResult>;
|
|
54
43
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
hasTable(table: string): boolean
|
|
58
|
-
/**
|
|
59
|
-
* Gets the schema for a table
|
|
60
|
-
*/
|
|
61
|
-
getTableSchema(table: string): TableSchema | undefined;
|
|
44
|
+
* Checks if a table exists
|
|
45
|
+
*/
|
|
46
|
+
hasTable(table: string): Promise<boolean>;
|
|
62
47
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
48
|
+
* Gets the schema for a table
|
|
49
|
+
*/
|
|
50
|
+
getTableSchema(table: string): Promise<TableSchema | undefined>;
|
|
66
51
|
}
|
|
67
52
|
//#endregion
|
|
68
53
|
export { CRUDOperations };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.d.mts","names":[],"sources":["../../src/operations/crud.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"crud.d.mts","names":[],"sources":["../../src/operations/crud.ts"],"mappings":";;;;;;;;AA6CA;cAAa,cAAA;EAAA,QAED,EAAA;EAAA,QACA,aAAA;EAAA,QACA,QAAA;cAFA,EAAA,EAAI,cAAA,EACJ,aAAA,EAAe,aAAA,EACf,QAAA;EAMU;;;EAAd,UAAA,CAAA,GAAc,OAAA,CAAQ,aAAA;EA6CsB;;;EAvB5C,SAAA,CAAU,KAAA,UAAe,OAAA,GAAU,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAuE1B;;;EAhDlC,OAAA,CAAQ,KAAA,UAAe,EAAA,WAAa,OAAA,CAAQ,aAAA;EA2FvC;;;EAnEL,OAAA,CAAQ,KAAA,UAAe,EAAA,WAAa,OAAA,CAAQ,aAAA;EAwHnB;;;EAhGzB,SAAA,CAAU,KAAA,UAAe,OAAA,EAAS,MAAA,oBAA0B,OAAA,CAAQ,cAAA;EAuG9B;;;EAhEtC,SAAA,CACJ,KAAA,UACA,EAAA,UACA,OAAA,EAAS,MAAA,oBACR,OAAA,CAAQ,cAAA;;;;EA4BL,SAAA,CAAU,KAAA,UAAe,EAAA,WAAa,OAAA,CAAQ,eAAA;EA3K1C;;;EAoMJ,QAAA,CAAS,KAAA,WAAgB,OAAA;EA7LH;;;EAoMtB,cAAA,CAAe,KAAA,WAAgB,OAAA,CAAQ,WAAA;AAAA"}
|