fastify-auto-sqlapi 0.5.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +5 -5
- package/AGENTS_BACKEND.md +166 -130
- package/AGENTS_FRONTEND.md +60 -38
- package/BREAKING_CHANGES.md +9 -893
- package/CHANGELOG.md +246 -15
- package/README.md +71 -45
- package/dist/bin/generate-schema.js +12 -12
- package/dist/bin/generate-tables.js +1 -2
- package/dist/bin/utils.d.ts +2 -6
- package/dist/bin/utils.d.ts.map +1 -1
- package/dist/bin/utils.js +13 -33
- package/dist/index.d.ts +13 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -37
- package/dist/lib/adapters/mysql-adapter.d.ts +5 -2
- package/dist/lib/adapters/mysql-adapter.d.ts.map +1 -1
- package/dist/lib/adapters/pg-adapter.d.ts +5 -2
- package/dist/lib/adapters/pg-adapter.d.ts.map +1 -1
- package/dist/lib/agent/manifest.d.ts +27 -10
- package/dist/lib/agent/manifest.d.ts.map +1 -1
- package/dist/lib/agent/manifest.js +43 -26
- package/dist/lib/agent/tool-schemas.d.ts +5 -4
- package/dist/lib/agent/tool-schemas.d.ts.map +1 -1
- package/dist/lib/agent/tool-schemas.js +5 -5
- package/dist/lib/cli/config.d.ts +37 -2
- package/dist/lib/cli/config.d.ts.map +1 -1
- package/dist/lib/cli/config.js +106 -16
- package/dist/lib/cli/mysql-introspect.d.ts +6 -1
- package/dist/lib/cli/mysql-introspect.d.ts.map +1 -1
- package/dist/lib/cli/mysql-introspect.js +15 -15
- package/dist/lib/cli/pg-introspect.d.ts +0 -1
- package/dist/lib/cli/pg-introspect.d.ts.map +1 -1
- package/dist/lib/cli/pg-introspect.js +2 -13
- package/dist/lib/cli/tables-codegen.d.ts +0 -4
- package/dist/lib/cli/tables-codegen.d.ts.map +1 -1
- package/dist/lib/cli/tables-codegen.js +24 -87
- package/dist/lib/db.d.ts +42 -17
- package/dist/lib/db.d.ts.map +1 -1
- package/dist/lib/db.js +114 -40
- package/dist/lib/dialect.d.ts +5 -0
- package/dist/lib/dialect.d.ts.map +1 -1
- package/dist/lib/dialect.js +3 -0
- package/dist/lib/engine/bulk/bulk-delete.d.ts +5 -0
- package/dist/lib/engine/bulk/bulk-delete.d.ts.map +1 -1
- package/dist/lib/engine/bulk/bulk-delete.js +66 -30
- package/dist/lib/engine/bulk/bulk-upsert.d.ts.map +1 -1
- package/dist/lib/engine/bulk/bulk-upsert.js +45 -26
- package/dist/lib/engine/read-hooks.d.ts +3 -3
- package/dist/lib/engine/read-hooks.d.ts.map +1 -1
- package/dist/lib/engine/read-hooks.js +3 -3
- package/dist/lib/engine/rest/delete.d.ts.map +1 -1
- package/dist/lib/engine/rest/delete.js +12 -18
- package/dist/lib/engine/rest/get.js +8 -8
- package/dist/lib/engine/rest/insert.d.ts.map +1 -1
- package/dist/lib/engine/rest/insert.js +31 -18
- package/dist/lib/engine/rest/update.d.ts.map +1 -1
- package/dist/lib/engine/rest/update.js +34 -17
- package/dist/lib/engine/search/aggregations.d.ts +3 -3
- package/dist/lib/engine/search/aggregations.d.ts.map +1 -1
- package/dist/lib/engine/search/aggregations.js +20 -16
- package/dist/lib/engine/search/conditions.d.ts +9 -5
- package/dist/lib/engine/search/conditions.d.ts.map +1 -1
- package/dist/lib/engine/search/conditions.js +31 -20
- package/dist/lib/engine/search/fields.d.ts +44 -11
- package/dist/lib/engine/search/fields.d.ts.map +1 -1
- package/dist/lib/engine/search/fields.js +93 -27
- package/dist/lib/engine/search/join-families.d.ts +7 -7
- package/dist/lib/engine/search/join-families.d.ts.map +1 -1
- package/dist/lib/engine/search/join-families.js +84 -75
- package/dist/lib/engine/search/joins.d.ts +15 -7
- package/dist/lib/engine/search/joins.d.ts.map +1 -1
- package/dist/lib/engine/search/joins.js +23 -13
- package/dist/lib/engine/search/order-by.d.ts +11 -12
- package/dist/lib/engine/search/order-by.d.ts.map +1 -1
- package/dist/lib/engine/search/order-by.js +24 -28
- package/dist/lib/engine/search/search.d.ts.map +1 -1
- package/dist/lib/engine/search/search.js +111 -64
- package/dist/lib/engine/validate.d.ts +21 -3
- package/dist/lib/engine/validate.d.ts.map +1 -1
- package/dist/lib/engine/validate.js +106 -16
- package/dist/lib/engine/write-helpers.d.ts +69 -16
- package/dist/lib/engine/write-helpers.d.ts.map +1 -1
- package/dist/lib/engine/write-helpers.js +257 -105
- package/dist/lib/errors.d.ts +42 -10
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +69 -15
- package/dist/lib/nullable.d.ts +3 -2
- package/dist/lib/nullable.d.ts.map +1 -1
- package/dist/lib/nullable.js +14 -5
- package/dist/lib/read-access.d.ts +25 -16
- package/dist/lib/read-access.d.ts.map +1 -1
- package/dist/lib/read-access.js +33 -17
- package/dist/lib/schema/bulk-delete.d.ts +13 -7
- package/dist/lib/schema/bulk-delete.d.ts.map +1 -1
- package/dist/lib/schema/bulk-delete.js +18 -8
- package/dist/lib/schema/bulk-upsert.d.ts +3 -3
- package/dist/lib/schema/bulk-upsert.d.ts.map +1 -1
- package/dist/lib/schema/bulk-upsert.js +9 -14
- package/dist/lib/schema/get.d.ts +1 -1
- package/dist/lib/schema/get.d.ts.map +1 -1
- package/dist/lib/schema/get.js +2 -2
- package/dist/lib/schema/helpers.d.ts +41 -23
- package/dist/lib/schema/helpers.d.ts.map +1 -1
- package/dist/lib/schema/helpers.js +80 -33
- package/dist/lib/schema/insert.d.ts +1 -1
- package/dist/lib/schema/insert.d.ts.map +1 -1
- package/dist/lib/schema/insert.js +12 -20
- package/dist/lib/schema/search.d.ts +2 -13
- package/dist/lib/schema/search.d.ts.map +1 -1
- package/dist/lib/schema/search.js +64 -61
- package/dist/lib/schema/update.d.ts +1 -1
- package/dist/lib/schema/update.d.ts.map +1 -1
- package/dist/lib/schema/update.js +6 -13
- package/dist/lib/sql-api.d.ts +47 -25
- package/dist/lib/sql-api.d.ts.map +1 -1
- package/dist/lib/sql-api.js +70 -27
- package/dist/lib/table-helpers.d.ts +92 -14
- package/dist/lib/table-helpers.d.ts.map +1 -1
- package/dist/lib/table-helpers.js +367 -128
- package/dist/lib/tenant.d.ts +16 -22
- package/dist/lib/tenant.d.ts.map +1 -1
- package/dist/lib/tenant.js +38 -54
- package/dist/lib/write-access.d.ts +15 -9
- package/dist/lib/write-access.d.ts.map +1 -1
- package/dist/lib/write-access.js +12 -4
- package/dist/routes/auto/agent-manifest.routes.d.ts +1 -1
- package/dist/routes/auto/agent-manifest.routes.js +2 -2
- package/dist/routes/auto/bulk-delete.routes.d.ts +2 -2
- package/dist/routes/auto/bulk-delete.routes.d.ts.map +1 -1
- package/dist/routes/auto/bulk-delete.routes.js +1 -7
- package/dist/routes/auto/bulk-upsert.routes.d.ts +2 -2
- package/dist/routes/auto/bulk-upsert.routes.d.ts.map +1 -1
- package/dist/routes/auto/bulk-upsert.routes.js +2 -2
- package/dist/routes/auto/delete.routes.d.ts +2 -2
- package/dist/routes/auto/delete.routes.d.ts.map +1 -1
- package/dist/routes/auto/delete.routes.js +8 -10
- package/dist/routes/auto/get.routes.d.ts +2 -2
- package/dist/routes/auto/get.routes.d.ts.map +1 -1
- package/dist/routes/auto/get.routes.js +5 -5
- package/dist/routes/auto/insert.routes.d.ts +2 -2
- package/dist/routes/auto/insert.routes.d.ts.map +1 -1
- package/dist/routes/auto/insert.routes.js +1 -7
- package/dist/routes/auto/plugin.d.ts +6 -0
- package/dist/routes/auto/plugin.d.ts.map +1 -1
- package/dist/routes/auto/plugin.js +60 -36
- package/dist/routes/auto/route-helpers.d.ts +26 -12
- package/dist/routes/auto/route-helpers.d.ts.map +1 -1
- package/dist/routes/auto/route-helpers.js +50 -19
- package/dist/routes/auto/search.routes.d.ts +2 -2
- package/dist/routes/auto/search.routes.d.ts.map +1 -1
- package/dist/routes/auto/search.routes.js +36 -24
- package/dist/routes/auto/update.routes.d.ts +2 -2
- package/dist/routes/auto/update.routes.d.ts.map +1 -1
- package/dist/routes/auto/update.routes.js +1 -8
- package/dist/routes/sql-api-decorator.d.ts +30 -12
- package/dist/routes/sql-api-decorator.d.ts.map +1 -1
- package/dist/routes/sql-api-decorator.js +44 -27
- package/dist/types/cli.d.ts +17 -6
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/computed.d.ts +1 -1
- package/dist/types/computed.d.ts.map +1 -1
- package/dist/types/conditions.d.ts +3 -1
- package/dist/types/conditions.d.ts.map +1 -1
- package/dist/types/db.d.ts +44 -4
- package/dist/types/db.d.ts.map +1 -1
- package/dist/types/dml.d.ts +26 -17
- package/dist/types/dml.d.ts.map +1 -1
- package/dist/types/hooks.d.ts +62 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/hooks.js +1 -0
- package/dist/types/join.d.ts +25 -8
- package/dist/types/join.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +58 -19
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/plugin.js +2 -0
- package/dist/types/request.d.ts +2 -2
- package/dist/types/schema.d.ts +3 -3
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/types/search.d.ts +28 -13
- package/dist/types/search.d.ts.map +1 -1
- package/dist/types/search.js +2 -1
- package/dist/types/table.d.ts +109 -94
- package/dist/types/table.d.ts.map +1 -1
- package/dist/types/table.js +7 -2
- package/dist/types/tenant.d.ts +28 -2
- package/dist/types/tenant.d.ts.map +1 -1
- package/dist/types/tenant.js +7 -1
- package/dist/types/validation.d.ts +69 -13
- package/dist/types/validation.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/docs/GLOSSARY.md +11 -5
- package/docs/adr/0003-bulk-not-transactional.md +2 -1
- package/docs/adr/0006-raw-db-errors.md +2 -1
- package/docs/adr/0013-sanitized-db-errors.md +2 -1
- package/docs/adr/0014-what-follows-a-write-join.md +1 -1
- package/docs/adr/0022-stay-on-0x-while-every-consumer-is-first-party.md +88 -0
- package/docs/adr/0023-a-write-runs-in-a-transaction-or-not-at-all.md +60 -0
- package/docs/adr/0024-the-consumer-maps-driver-codes-through-dberrors.md +78 -0
- package/docs/adr/0025-validatebulk-replaces-validate-in-a-bulk-upsert.md +46 -0
- package/docs/adr/0026-update-carries-its-primary-key-in-main.md +43 -0
- package/docs/adr/0027-the-1-0-contract.md +74 -0
- package/docs/adr/0028-select-star-is-the-default-projection.md +64 -0
- package/docs/adr/0029-a-write-names-its-child-rows-by-action.md +96 -0
- package/docs/adr/0030-a-child-row-is-validated-by-its-own-table.md +117 -0
- package/docs/adr/0031-an-insert-excluded-upsert-key-addresses-an-existing-row.md +58 -0
- package/docs/adr/0032-tenant-scope-names-schema-fields.md +56 -0
- package/docs/adr/README.md +12 -1
- package/docs/upgrading/0.x.md +906 -0
- package/docs/upgrading/1.0.md +628 -0
- package/package.json +4 -5
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
-
import { loadConfig } from '../lib/cli/config.js';
|
|
5
|
-
import {
|
|
4
|
+
import { loadConfig, maskPassword, resolveConnection } from '../lib/cli/config.js';
|
|
5
|
+
import { introspectTables } from '../lib/cli/pg-introspect.js';
|
|
6
6
|
import { buildMysqlConnectionConfig, introspectMysqlTables } from '../lib/cli/mysql-introspect.js';
|
|
7
7
|
import { applyExcludeColumns, applyExcludeTables, buildTableMap, generateSchemaFile, } from '../lib/cli/schema-codegen.js';
|
|
8
|
-
import {
|
|
8
|
+
import { CONSOLE_COLORS, display, displayAsTableRow, parseArgs, runCli } from './utils.js';
|
|
9
9
|
const STATUS_COLOR = {
|
|
10
10
|
created: CONSOLE_COLORS.green,
|
|
11
11
|
updated: CONSOLE_COLORS.cyan,
|
|
12
12
|
untouched: CONSOLE_COLORS.gray,
|
|
13
13
|
};
|
|
14
|
-
function introspect(
|
|
15
|
-
if (dialect === 'mysql' || dialect === 'mariadb') {
|
|
16
|
-
const connConfig = buildMysqlConnectionConfig();
|
|
14
|
+
function introspect(connection, schema) {
|
|
15
|
+
if (connection.dialect === 'mysql' || connection.dialect === 'mariadb') {
|
|
16
|
+
const connConfig = buildMysqlConnectionConfig(connection.url);
|
|
17
17
|
return introspectMysqlTables(connConfig, connConfig.database);
|
|
18
18
|
}
|
|
19
|
-
return introspectTables(
|
|
19
|
+
return introspectTables(connection.url, schema);
|
|
20
20
|
}
|
|
21
21
|
/** Narrow the map to the `--tables` selection. Returns false when nothing matched. */
|
|
22
22
|
function keepOnlyRequestedTables(tableMap, tableNames) {
|
|
@@ -132,19 +132,19 @@ await runCli('fastify-auto-sqlapi: generating schemas', async () => {
|
|
|
132
132
|
const cliArgs = parseArgs({
|
|
133
133
|
output: { type: 'value' },
|
|
134
134
|
tables: { type: 'list' },
|
|
135
|
-
|
|
135
|
+
url: { type: 'value' },
|
|
136
136
|
});
|
|
137
137
|
const config = await loadConfig();
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
const schema = config.schema || 'public';
|
|
138
|
+
const connection = resolveConnection({ url: cliArgs.url, config, env: process.env });
|
|
139
|
+
const schema = config.schema;
|
|
141
140
|
const outputDir = path.resolve(process.cwd(), cliArgs.output || config.outputDir);
|
|
142
141
|
const schemasDir = path.join(outputDir, 'schemas');
|
|
143
142
|
if (!fs.existsSync(schemasDir)) {
|
|
144
143
|
fs.mkdirSync(schemasDir, { recursive: true });
|
|
145
144
|
display(`Created directory: ${schemasDir}`, CONSOLE_COLORS.green);
|
|
146
145
|
}
|
|
147
|
-
|
|
146
|
+
display(`Introspecting ${maskPassword(connection.url)}`, CONSOLE_COLORS.gray);
|
|
147
|
+
const rows = await introspect(connection, schema);
|
|
148
148
|
if (rows.length === 0) {
|
|
149
149
|
display(`No tables found in schema "${schema}".`, CONSOLE_COLORS.magenta);
|
|
150
150
|
return;
|
|
@@ -3,7 +3,7 @@ import * as fs from 'node:fs';
|
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
import { loadConfig } from '../lib/cli/config.js';
|
|
5
5
|
import { parseSchemaFile, generateSingleTableFile, generateDbTablesIndex } from '../lib/cli/tables-codegen.js';
|
|
6
|
-
import {
|
|
6
|
+
import { CONSOLE_COLORS, display, displayAsTableRow, error, parseArgs, runCli } from './utils.js';
|
|
7
7
|
function printHelp() {
|
|
8
8
|
console.log('');
|
|
9
9
|
display('Usage:', CONSOLE_COLORS.yellow);
|
|
@@ -101,7 +101,6 @@ await runCli('fastify-auto-sqlapi: generating tables template', async () => {
|
|
|
101
101
|
process.exit(1);
|
|
102
102
|
}
|
|
103
103
|
const config = await loadConfig();
|
|
104
|
-
loadEnvFile(config.envFile);
|
|
105
104
|
const outputDir = path.resolve(process.cwd(), cliArgs.output || config.outputDir);
|
|
106
105
|
const schemasDir = path.join(outputDir, 'schemas');
|
|
107
106
|
const tablesDir = path.join(outputDir, 'tables');
|
package/dist/bin/utils.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load .env file from cwd if it exists.
|
|
3
|
-
* Does not override already-set environment variables.
|
|
4
|
-
*/
|
|
5
|
-
export declare function loadEnvFile(envFile?: string): void;
|
|
6
1
|
export declare const CONSOLE_COLORS: {
|
|
7
2
|
readonly black: 30;
|
|
8
3
|
readonly gray: 90;
|
|
@@ -24,7 +19,8 @@ type ArgSpec = {
|
|
|
24
19
|
};
|
|
25
20
|
type ArgValue<S extends ArgSpec> = S['type'] extends 'flag' ? boolean : S['type'] extends 'list' ? string[] : string | undefined;
|
|
26
21
|
/**
|
|
27
|
-
* Tiny declarative argv parser for the bundled CLIs.
|
|
22
|
+
* Tiny declarative argv parser for the bundled CLIs. An option not in `spec` is an error: left
|
|
23
|
+
* unread, its value would be taken for a positional table name.
|
|
28
24
|
* - `value` → recognized as `--name X`, last value wins
|
|
29
25
|
* - `flag` → recognized as `--name`, default false
|
|
30
26
|
* - `list` → comma-separated `--name a,b,c`; can also accept positional comma-/space- separated tokens
|
package/dist/bin/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/bin/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/bin/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;;;;;;CAQjB,CAAC;AAEX,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,MAAU,GAChB,IAAI,CAQN;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,IAAI,CAE7D;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAExC;AAED,KAAK,OAAO,GACR;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAErB,KAAK,QAAQ,CAAC,CAAC,SAAS,OAAO,IAC7B,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,GAAG,OAAO,GAClC,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GACnC,MAAM,GAAG,SAAS,CAAC;AAOrB;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,IAAI,EAAE,CAAC,EACP,IAAI,WAAwB,GAC3B;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG;IAAE,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAmB/D;AA2DD;;;GAGG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAQjF"}
|
package/dist/bin/utils.js
CHANGED
|
@@ -1,33 +1,3 @@
|
|
|
1
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
/**
|
|
4
|
-
* Load .env file from cwd if it exists.
|
|
5
|
-
* Does not override already-set environment variables.
|
|
6
|
-
*/
|
|
7
|
-
export function loadEnvFile(envFile) {
|
|
8
|
-
const envPath = resolve(process.cwd(), envFile || '.env');
|
|
9
|
-
if (!existsSync(envPath))
|
|
10
|
-
return;
|
|
11
|
-
const content = readFileSync(envPath, 'utf-8');
|
|
12
|
-
for (const line of content.split('\n')) {
|
|
13
|
-
const trimmed = line.trim();
|
|
14
|
-
if (!trimmed || trimmed.startsWith('#'))
|
|
15
|
-
continue;
|
|
16
|
-
const eqIndex = trimmed.indexOf('=');
|
|
17
|
-
if (eqIndex === -1)
|
|
18
|
-
continue;
|
|
19
|
-
const key = trimmed.slice(0, eqIndex).trim();
|
|
20
|
-
let value = trimmed.slice(eqIndex + 1).trim();
|
|
21
|
-
// Strip surrounding quotes
|
|
22
|
-
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
23
|
-
(value.startsWith("'") && value.endsWith("'"))) {
|
|
24
|
-
value = value.slice(1, -1);
|
|
25
|
-
}
|
|
26
|
-
if (!(key in process.env)) {
|
|
27
|
-
process.env[key] = value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
1
|
export const CONSOLE_COLORS = {
|
|
32
2
|
black: 30,
|
|
33
3
|
gray: 90,
|
|
@@ -52,8 +22,13 @@ export function display(text, color = 0) {
|
|
|
52
22
|
export function error(text) {
|
|
53
23
|
display(text, CONSOLE_COLORS.red);
|
|
54
24
|
}
|
|
25
|
+
/** Options retired in 1.0, each with what replaces it. */
|
|
26
|
+
const RETIRED_OPTIONS = {
|
|
27
|
+
dialect: 'the dialect is the scheme of the connection URL (postgres://, mysql://, mariadb://)',
|
|
28
|
+
};
|
|
55
29
|
/**
|
|
56
|
-
* Tiny declarative argv parser for the bundled CLIs.
|
|
30
|
+
* Tiny declarative argv parser for the bundled CLIs. An option not in `spec` is an error: left
|
|
31
|
+
* unread, its value would be taken for a positional table name.
|
|
57
32
|
* - `value` → recognized as `--name X`, last value wins
|
|
58
33
|
* - `flag` → recognized as `--name`, default false
|
|
59
34
|
* - `list` → comma-separated `--name a,b,c`; can also accept positional comma-/space- separated tokens
|
|
@@ -94,9 +69,14 @@ function pushCsv(target, raw) {
|
|
|
94
69
|
*/
|
|
95
70
|
function readOption(out, spec, argv, i) {
|
|
96
71
|
const name = argv[i].slice(2);
|
|
72
|
+
if (!Object.hasOwn(spec, name)) {
|
|
73
|
+
if (Object.hasOwn(RETIRED_OPTIONS, name)) {
|
|
74
|
+
throw new Error(`--${name} was removed in 1.0: ${RETIRED_OPTIONS[name]}`);
|
|
75
|
+
}
|
|
76
|
+
const known = Object.keys(spec).map((n) => '--' + n).join(', ');
|
|
77
|
+
throw new Error(`unknown option --${name}. Known options: ${known}`);
|
|
78
|
+
}
|
|
97
79
|
const def = spec[name];
|
|
98
|
-
if (!def)
|
|
99
|
-
return 0;
|
|
100
80
|
const hasNext = i + 1 < argv.length;
|
|
101
81
|
if (def.type === 'flag') {
|
|
102
82
|
out[name] = true;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { QueryClient, createQueryClient,
|
|
3
|
-
export
|
|
4
|
-
export { pgQueryable } from './lib/adapters/pg-adapter.js';
|
|
5
|
-
export { mysqlQueryable } from './lib/adapters/mysql-adapter.js';
|
|
6
|
-
export {
|
|
1
|
+
export { httpError, type HttpErrorField } from './lib/errors.js';
|
|
2
|
+
export { QueryClient, createQueryClient, type BulkUpsertOptions } from './lib/db.js';
|
|
3
|
+
export type { DialectName } from './lib/dialect.js';
|
|
4
|
+
export { pgQueryable, type PgQueryable } from './lib/adapters/pg-adapter.js';
|
|
5
|
+
export { mysqlQueryable, type MysqlQueryable } from './lib/adapters/mysql-adapter.js';
|
|
6
|
+
export { defineTable, buildRelation } from './lib/table-helpers.js';
|
|
7
|
+
export type { TableDefinition, BuildRelationOptions } from './lib/table-helpers.js';
|
|
7
8
|
export { Nullable } from './lib/nullable.js';
|
|
8
|
-
export { buildAgentManifest, renderAgentManifestMd, type AgentManifest, type ManifestTable, } from './lib/agent/manifest.js';
|
|
9
|
+
export { buildAgentManifest, renderAgentManifestMd, type AgentManifest, type ManifestTable, type ManifestField, type ManifestJoin, } from './lib/agent/manifest.js';
|
|
9
10
|
export { agentToolSchemas, type AgentToolSchemas } from './lib/agent/tool-schemas.js';
|
|
10
|
-
export {
|
|
11
|
-
export { resolveTenant } from './lib/tenant.js';
|
|
11
|
+
export { TENANT_ADMIN } from './types.js';
|
|
12
12
|
export { SqlApi, createSqlApi } from './lib/sql-api.js';
|
|
13
|
-
export type { SqlApiOptions, SqlApiSearchParams, SqlApiInsertParams, SqlApiUpdateParams } from './lib/sql-api.js';
|
|
13
|
+
export type { SqlApiOptions, SqlApiSearchParams, SqlApiInsertParams, SqlApiUpdateParams, SqlApiBulkDeleteParams } from './lib/sql-api.js';
|
|
14
14
|
export { default as fastifyAutoSqlApi } from './routes/auto/plugin.js';
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export { default as searchRoutes } from './routes/auto/search.routes.js';
|
|
19
|
-
export { insertEngine } from './lib/engine/rest/insert.js';
|
|
20
|
-
export { InsertTableBody, InsertTableResponse } from './lib/schema/insert.js';
|
|
21
|
-
export { default as insertRoutes } from './routes/auto/insert.routes.js';
|
|
22
|
-
export { getEngine } from './lib/engine/rest/get.js';
|
|
23
|
-
export { default as getRoutes } from './routes/auto/get.routes.js';
|
|
24
|
-
export { deleteEngine } from './lib/engine/rest/delete.js';
|
|
25
|
-
export { default as deleteRoutes } from './routes/auto/delete.routes.js';
|
|
26
|
-
export { updateEngine } from './lib/engine/rest/update.js';
|
|
27
|
-
export { UpdateTableBody, UpdateTableResponse } from './lib/schema/update.js';
|
|
28
|
-
export { default as updateRoutes } from './routes/auto/update.routes.js';
|
|
29
|
-
export { bulkUpsertEngine } from './lib/engine/bulk/bulk-upsert.js';
|
|
30
|
-
export { BulkUpsertTableBody, BulkUpsertTableResponse } from './lib/schema/bulk-upsert.js';
|
|
31
|
-
export { default as bulkUpsertRoutes } from './routes/auto/bulk-upsert.routes.js';
|
|
32
|
-
export { bulkDeleteEngine } from './lib/engine/bulk/bulk-delete.js';
|
|
33
|
-
export { BulkDeleteTableBody, BulkDeleteTableResponse } from './lib/schema/bulk-delete.js';
|
|
34
|
-
export { default as bulkDeleteRoutes } from './routes/auto/bulk-delete.routes.js';
|
|
35
|
-
export { Type, type Static } from '@sinclair/typebox';
|
|
36
|
-
export { ConditionBuilder, Expression } from 'node-condition-builder';
|
|
37
|
-
export type { ApiRequest, SqlApiConfig, ColumnInfo, TableMap, Queryable, TransactionQueryable, SqlResult, DbRecord, DbRecordValue, SelectOptions, SchemaDefinition, JoinDefinition, ITable, TableOperation, DbTables, SqlApiPluginOptions, SwaggerOptions, SearchParams, SearchResult, Paginator, PaginationResult, TableFilterFn, ExtendedConditionFn, FilterRecord, AggregationRequest, JoinGroupRequest, ComputedFieldFn, ComputedFieldContext, ComputedFieldExpr, GetParams, GetResult, DeleteParams, DeleteResult, InsertParams, InsertResult, BulkUpsertItem, BulkUpsertParams, BulkUpsertResult, BulkDeleteParams, BulkDeleteResult, ConditionMethod, SearchCondition, UpdateParams, UpdateResult, TenantId, TenantScope, TenantScopeDirect, TenantScopeIndirect, TenantScopeAnyOf, TenantContext, ValidationError, ValidatorFn, BulkValidatorItem, BulkValidatorFn, } from './types.js';
|
|
15
|
+
export { Type, type Static, type TSchema, type TObject, type TUnsafe } from 'typebox';
|
|
16
|
+
export { ConditionBuilder, Expression, type ConditionValueOrUndefined } from 'node-condition-builder';
|
|
17
|
+
export type { ApiRequest, ApiReply, CliConfig, Queryable, TransactionQueryable, SqlResult, DbRecord, DbRecordValue, WriteAction, WrittenRow, PrimaryKeyValue, SelectOptions, SchemaDefinition, JoinDefinition, JoinFetchRequest, JoinRefFilter, RowsByAlias, WriteJoinSections, TableConfig, TableOperation, DbTables, SqlApiPluginOptions, SwaggerOptions, DbErrorMapping, SearchResult, Paginator, ComputeFn, ComputeRequest, ComputedResult, PaginationResult, ExtendedConditionFn, ExtendedConditionContext, FilterRecord, AggregationRequest, JoinGroupRequest, ComputedFieldFn, ComputedFieldContext, ComputedFieldExpr, GetResult, DeleteResult, InsertResult, BulkUpsertItem, BulkUpsertResult, BulkDeleteResult, ConditionMethod, SearchCondition, UpdateResult, TenantId, TenantAdmin, TenantResolution, GetTenantId, TenantScope, TenantScopeDirect, TenantScopeIndirect, TenantScopeAnyOf, ValidationField, ValidateContext, ValidateParent, BulkValidateContext, HookContext, WriteRecord, WriteHookContext, AfterInsertContext, AfterUpdateContext, AfterReadContext, ReadSource, DeleteHookContext, BulkDeleteHookContext, ValidatorFn, ValidatorResult, BulkValidatorItem, BulkValidatorFn, } from './types.js';
|
|
38
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrF,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAGtF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACpE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGtF,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAI1I,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGvE,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,KAAK,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAGtG,YAAY,EACV,UAAU,EACV,QAAQ,EACR,SAAS,EACT,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,QAAQ,EACR,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,SAAS,EACT,SAAS,EACT,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,53 +1,22 @@
|
|
|
1
|
-
//
|
|
2
|
-
export {
|
|
1
|
+
// Errors: throw from a hook to answer in the plugin's envelope (a 400 with `fields`)
|
|
2
|
+
export { httpError } from './lib/errors.js';
|
|
3
3
|
// DB
|
|
4
|
-
export { QueryClient, createQueryClient
|
|
5
|
-
// Dialect
|
|
6
|
-
export { getDialect } from './lib/dialect.js';
|
|
4
|
+
export { QueryClient, createQueryClient } from './lib/db.js';
|
|
7
5
|
// Adapters
|
|
8
6
|
export { pgQueryable } from './lib/adapters/pg-adapter.js';
|
|
9
7
|
export { mysqlQueryable } from './lib/adapters/mysql-adapter.js';
|
|
10
8
|
// Table helpers
|
|
11
|
-
export {
|
|
9
|
+
export { defineTable, buildRelation } from './lib/table-helpers.js';
|
|
12
10
|
export { Nullable } from './lib/nullable.js';
|
|
13
11
|
// Agent / LLM client helpers
|
|
14
12
|
export { buildAgentManifest, renderAgentManifestMd, } from './lib/agent/manifest.js';
|
|
15
13
|
export { agentToolSchemas } from './lib/agent/tool-schemas.js';
|
|
16
|
-
export { default as agentManifestRoutes } from './routes/auto/agent-manifest.routes.js';
|
|
17
14
|
// Tenant
|
|
18
|
-
export {
|
|
15
|
+
export { TENANT_ADMIN } from './types.js';
|
|
19
16
|
// SqlApi — programmatic high-level API
|
|
20
17
|
export { SqlApi, createSqlApi } from './lib/sql-api.js';
|
|
21
18
|
// Plugin
|
|
22
19
|
export { default as fastifyAutoSqlApi } from './routes/auto/plugin.js';
|
|
23
|
-
// Swagger
|
|
24
|
-
export { setupSwagger } from './routes/setup-swagger.js';
|
|
25
|
-
// Search
|
|
26
|
-
export { searchEngine } from './lib/engine/search/search.js';
|
|
27
|
-
export { SearchTableBodyPost, SearchTableQuery, SearchTableQueryString, SearchTableResponse } from './lib/schema/search.js';
|
|
28
|
-
export { default as searchRoutes } from './routes/auto/search.routes.js';
|
|
29
|
-
// Insert
|
|
30
|
-
export { insertEngine } from './lib/engine/rest/insert.js';
|
|
31
|
-
export { InsertTableBody, InsertTableResponse } from './lib/schema/insert.js';
|
|
32
|
-
export { default as insertRoutes } from './routes/auto/insert.routes.js';
|
|
33
|
-
// Get
|
|
34
|
-
export { getEngine } from './lib/engine/rest/get.js';
|
|
35
|
-
export { default as getRoutes } from './routes/auto/get.routes.js';
|
|
36
|
-
// Delete
|
|
37
|
-
export { deleteEngine } from './lib/engine/rest/delete.js';
|
|
38
|
-
export { default as deleteRoutes } from './routes/auto/delete.routes.js';
|
|
39
|
-
// Update
|
|
40
|
-
export { updateEngine } from './lib/engine/rest/update.js';
|
|
41
|
-
export { UpdateTableBody, UpdateTableResponse } from './lib/schema/update.js';
|
|
42
|
-
export { default as updateRoutes } from './routes/auto/update.routes.js';
|
|
43
|
-
// Bulk Upsert
|
|
44
|
-
export { bulkUpsertEngine } from './lib/engine/bulk/bulk-upsert.js';
|
|
45
|
-
export { BulkUpsertTableBody, BulkUpsertTableResponse } from './lib/schema/bulk-upsert.js';
|
|
46
|
-
export { default as bulkUpsertRoutes } from './routes/auto/bulk-upsert.routes.js';
|
|
47
|
-
// Bulk Delete
|
|
48
|
-
export { bulkDeleteEngine } from './lib/engine/bulk/bulk-delete.js';
|
|
49
|
-
export { BulkDeleteTableBody, BulkDeleteTableResponse } from './lib/schema/bulk-delete.js';
|
|
50
|
-
export { default as bulkDeleteRoutes } from './routes/auto/bulk-delete.routes.js';
|
|
51
20
|
// Re-export deps
|
|
52
|
-
export { Type } from '
|
|
21
|
+
export { Type } from 'typebox';
|
|
53
22
|
export { ConditionBuilder, Expression } from 'node-condition-builder';
|
|
@@ -4,8 +4,11 @@ export interface MysqlQueryable {
|
|
|
4
4
|
affectedRows?: number;
|
|
5
5
|
insertId?: number;
|
|
6
6
|
}, unknown]>;
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Present on mysql2 promise pools (and @fastify/mysql): checks out a dedicated connection. Only
|
|
9
|
+
* its `query` and `release` are used.
|
|
10
|
+
*/
|
|
11
|
+
getConnection?(): Promise<Pick<MysqlQueryable, 'query'> & {
|
|
9
12
|
release(): void;
|
|
10
13
|
}>;
|
|
11
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql-adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/adapters/mysql-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmC,MAAM,gBAAgB,CAAC;AAEjF,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1E
|
|
1
|
+
{"version":3,"file":"mysql-adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/adapters/mysql-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmC,MAAM,gBAAgB,CAAC;AAEjF,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1E;;;OAGG;IACH,aAAa,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG;QAAE,OAAO,IAAI,IAAI,CAAA;KAAE,CAAC,CAAC;CAChF;AA2BD,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,CAc9D"}
|
|
@@ -4,8 +4,11 @@ export interface PgQueryable {
|
|
|
4
4
|
rows: T[];
|
|
5
5
|
rowCount: number | null;
|
|
6
6
|
}>;
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Present on pg.Pool (and @fastify/postgres): checks out a dedicated client. Only its `query`
|
|
9
|
+
* and `release` are used — a PoolClient's own `connect()` is not a checkout.
|
|
10
|
+
*/
|
|
11
|
+
connect?(): Promise<Pick<PgQueryable, 'query'> & {
|
|
9
12
|
release(): void;
|
|
10
13
|
}>;
|
|
11
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg-adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/adapters/pg-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmC,MAAM,gBAAgB,CAAC;AAEjF,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACnD
|
|
1
|
+
{"version":3,"file":"pg-adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/adapters/pg-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmC,MAAM,gBAAgB,CAAC;AAEjF,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACnD;;;OAGG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG;QAAE,OAAO,IAAI,IAAI,CAAA;KAAE,CAAC,CAAC;CACvE;AAeD,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAc1D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DbTables,
|
|
2
|
-
interface ManifestField {
|
|
1
|
+
import type { DbTables, TableConfig, TableOperation } from '../../types.js';
|
|
2
|
+
export interface ManifestField {
|
|
3
3
|
type: string;
|
|
4
4
|
/** Present (true) when the field must be sent on insert. */
|
|
5
5
|
required?: boolean;
|
|
@@ -10,11 +10,16 @@ interface ManifestField {
|
|
|
10
10
|
/** Present (true) when the field is returned by reads but refused by every write. */
|
|
11
11
|
readOnly?: boolean;
|
|
12
12
|
}
|
|
13
|
-
interface ManifestJoin {
|
|
13
|
+
export interface ManifestJoin {
|
|
14
14
|
alias: string;
|
|
15
15
|
table: string;
|
|
16
16
|
/** '1:N' → usable in joinMustExist/joinMultiple/joinGroup; 'N:1' → usable in joinLeft. */
|
|
17
17
|
kind: '1:N' | 'N:1';
|
|
18
|
+
/**
|
|
19
|
+
* On a write join: the key its child rows upsert on. Present, the alias also takes `replace`
|
|
20
|
+
* — the complete set of child rows, the ones left out deleted (ADR 0029).
|
|
21
|
+
*/
|
|
22
|
+
upsertKey?: string[];
|
|
18
23
|
}
|
|
19
24
|
export interface ManifestTable {
|
|
20
25
|
/** URL segment for this table's routes. */
|
|
@@ -24,12 +29,18 @@ export interface ManifestTable {
|
|
|
24
29
|
fields: Record<string, ManifestField>;
|
|
25
30
|
/** Fields stripped from client input on insert (server-generated: PKs, timestamps). */
|
|
26
31
|
serverGenerated?: string[];
|
|
27
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* The key insert and bulkUpsert upsert on: a row carrying it updates the row it names.
|
|
34
|
+
* Every row must carry it (400 `missing_key`), except a serverGenerated key: absent, the row
|
|
35
|
+
* is inserted; present, it must name an existing row (400 `not_found`, ADR 0031).
|
|
36
|
+
*/
|
|
37
|
+
upsertKey?: string[];
|
|
38
|
+
/** Computed (virtual) fields: usable in filters/conditions/orderBy/compute and listed in select (next to '*' for every readable field). */
|
|
28
39
|
computed?: Record<string, string>;
|
|
29
40
|
/** Extra filter names accepted in `filters` beyond schema fields. */
|
|
30
41
|
extraFilters?: Record<string, string>;
|
|
31
42
|
readJoins?: ManifestJoin[];
|
|
32
|
-
/** Aliases accepted
|
|
43
|
+
/** Aliases accepted under `upsert`/`delete` in writes, and under `replace` when they carry an `upsertKey`. */
|
|
33
44
|
writeJoins?: ManifestJoin[];
|
|
34
45
|
/** Present (true) when rows are automatically scoped to the caller's tenant. */
|
|
35
46
|
tenantScoped?: boolean;
|
|
@@ -38,20 +49,26 @@ export interface ManifestTable {
|
|
|
38
49
|
export interface AgentManifest {
|
|
39
50
|
tables: Record<string, ManifestTable>;
|
|
40
51
|
}
|
|
41
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The operations a table exposes: its own `operations` (all when omitted), within `allowed`
|
|
54
|
+
* — the registration's `operations` — when given, minus the single-PK ones on a composite PK.
|
|
55
|
+
*/
|
|
56
|
+
export declare function tableOperations(tableConf: TableConfig, allowed?: readonly TableOperation[]): TableOperation[];
|
|
42
57
|
/**
|
|
43
58
|
* Build the machine-readable description of every table exposed by this deployment:
|
|
44
59
|
* fields (type/required/nullable), enabled operations, join aliases, computed fields,
|
|
45
|
-
* extra filters, tenant scoping. Derived entirely from `
|
|
60
|
+
* extra filters, tenant scoping. Derived entirely from `dbTables`, so it is always in
|
|
46
61
|
* sync with the running configuration. Pairs with AGENTS_FRONTEND.md (the request grammar)
|
|
47
|
-
* to give an LLM client everything it needs to drive the API.
|
|
62
|
+
* to give an LLM client everything it needs to drive the API. `operations` is the
|
|
63
|
+
* registration's own, when it narrows what the tables expose.
|
|
48
64
|
*/
|
|
49
|
-
export declare function buildAgentManifest(dbTables: DbTables
|
|
65
|
+
export declare function buildAgentManifest(dbTables: DbTables, options?: {
|
|
66
|
+
operations?: readonly TableOperation[];
|
|
67
|
+
}): AgentManifest;
|
|
50
68
|
/**
|
|
51
69
|
* Compact markdown rendering of the manifest, designed for an LLM system prompt.
|
|
52
70
|
* Notation: `!` required on insert, `?` nullable, `(writeOnly)` never returned by reads,
|
|
53
71
|
* `(readOnly)` returned by reads and refused by every write.
|
|
54
72
|
*/
|
|
55
73
|
export declare function renderAgentManifestMd(manifest: AgentManifest): string;
|
|
56
|
-
export {};
|
|
57
74
|
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../../src/lib/agent/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../../src/lib/agent/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAkB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAM5F,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2FAA2F;IAC3F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qFAAqF;IACrF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACtC,uFAAuF;IACvF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,2IAA2I;IAC3I,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;IAC3B,8GAA8G;IAC9G,UAAU,CAAC,EAAE,YAAY,EAAE,CAAC;IAC5B,gFAAgF;IAChF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACvC;AAiCD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,SAAS,cAAc,EAAE,GAAG,cAAc,EAAE,CAK7G;AA+DD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,SAAS,cAAc,EAAE,CAAA;CAAO,GACvD,aAAa,CAMf;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAuBrE"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { isCompositePrimary } from '../../types.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
];
|
|
6
|
-
const SINGLE_PK_OPERATIONS = new Set(['get', 'delete', 'bulkDelete']);
|
|
1
|
+
import { isCompositePrimary, TABLE_OPERATIONS } from '../../types.js';
|
|
2
|
+
import { extraFilterFields } from '../read-access.js';
|
|
3
|
+
import { writeExcludedFields, insertExcludedFields } from '../write-access.js';
|
|
4
|
+
const SINGLE_PK_OPERATIONS = new Set(['get', 'delete']);
|
|
7
5
|
function shortType(schema) {
|
|
8
6
|
if (!schema)
|
|
9
7
|
return 'any';
|
|
@@ -14,7 +12,9 @@ function shortType(schema) {
|
|
|
14
12
|
return types[0] ?? 'any';
|
|
15
13
|
}
|
|
16
14
|
function isNullable(schema) {
|
|
17
|
-
|
|
15
|
+
if (!schema)
|
|
16
|
+
return false;
|
|
17
|
+
const t = schema.type;
|
|
18
18
|
return Array.isArray(t) && t.includes('null');
|
|
19
19
|
}
|
|
20
20
|
function computedTypes(tableConf) {
|
|
@@ -35,15 +35,20 @@ function computedTypes(tableConf) {
|
|
|
35
35
|
}
|
|
36
36
|
return Object.keys(out).length ? out : undefined;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
/**
|
|
39
|
+
* The operations a table exposes: its own `operations` (all when omitted), within `allowed`
|
|
40
|
+
* — the registration's `operations` — when given, minus the single-PK ones on a composite PK.
|
|
41
|
+
*/
|
|
42
|
+
export function tableOperations(tableConf, allowed) {
|
|
43
|
+
const requested = (tableConf.operations ?? TABLE_OPERATIONS)
|
|
44
|
+
.filter((op) => !allowed || allowed.includes(op));
|
|
40
45
|
if (!isCompositePrimary(tableConf.primary))
|
|
41
|
-
return
|
|
46
|
+
return requested;
|
|
42
47
|
return requested.filter((op) => !SINGLE_PK_OPERATIONS.has(op));
|
|
43
48
|
}
|
|
44
49
|
/** Field descriptors: type, plus the flags an agent needs to build a valid payload. */
|
|
45
50
|
function manifestFields(tableConf) {
|
|
46
|
-
const schema = tableConf.
|
|
51
|
+
const schema = tableConf.schema;
|
|
47
52
|
const required = new Set((schema.validation.required) ?? []);
|
|
48
53
|
const readExcluded = new Set(tableConf.readExclude ?? []);
|
|
49
54
|
const writeExcluded = writeExcludedFields(tableConf, schema);
|
|
@@ -67,28 +72,32 @@ function manifestJoins(joins) {
|
|
|
67
72
|
alias: j.alias,
|
|
68
73
|
table: j.joinSchema.tableName,
|
|
69
74
|
kind: j.unique ? 'N:1' : '1:N',
|
|
75
|
+
...(j.upsertKey ? { upsertKey: [...j.upsertKey] } : {}),
|
|
70
76
|
}));
|
|
71
77
|
}
|
|
72
78
|
function manifestExtraFilters(tableConf) {
|
|
73
|
-
const entries = Object.entries(tableConf
|
|
79
|
+
const entries = Object.entries(extraFilterFields(tableConf));
|
|
74
80
|
if (entries.length === 0)
|
|
75
81
|
return undefined;
|
|
76
82
|
return Object.fromEntries(entries.map(([n, s]) => [n, shortType(s)]));
|
|
77
83
|
}
|
|
78
84
|
/** One table's entry. Optional keys are omitted entirely when empty, to keep the prompt small. */
|
|
79
|
-
function manifestTable(tableConf) {
|
|
85
|
+
function manifestTable(tableConf, allowed) {
|
|
80
86
|
const entry = {
|
|
81
|
-
table: tableConf.
|
|
87
|
+
table: tableConf.schema.tableName,
|
|
82
88
|
primary: tableConf.primary,
|
|
83
|
-
operations: tableOperations(tableConf),
|
|
89
|
+
operations: tableOperations(tableConf, allowed),
|
|
84
90
|
fields: manifestFields(tableConf),
|
|
85
91
|
};
|
|
86
92
|
const computed = computedTypes(tableConf);
|
|
87
93
|
const extraFilters = manifestExtraFilters(tableConf);
|
|
88
|
-
const readJoins = manifestJoins(tableConf.
|
|
89
|
-
const writeJoins = manifestJoins(tableConf.
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
const readJoins = manifestJoins(tableConf.readJoins);
|
|
95
|
+
const writeJoins = manifestJoins(tableConf.writeJoins);
|
|
96
|
+
const serverGenerated = insertExcludedFields(tableConf);
|
|
97
|
+
if (serverGenerated.length)
|
|
98
|
+
entry.serverGenerated = [...serverGenerated];
|
|
99
|
+
if (tableConf.upsertKey)
|
|
100
|
+
entry.upsertKey = [...tableConf.upsertKey];
|
|
92
101
|
if (computed)
|
|
93
102
|
entry.computed = computed;
|
|
94
103
|
if (extraFilters)
|
|
@@ -106,14 +115,15 @@ function manifestTable(tableConf) {
|
|
|
106
115
|
/**
|
|
107
116
|
* Build the machine-readable description of every table exposed by this deployment:
|
|
108
117
|
* fields (type/required/nullable), enabled operations, join aliases, computed fields,
|
|
109
|
-
* extra filters, tenant scoping. Derived entirely from `
|
|
118
|
+
* extra filters, tenant scoping. Derived entirely from `dbTables`, so it is always in
|
|
110
119
|
* sync with the running configuration. Pairs with AGENTS_FRONTEND.md (the request grammar)
|
|
111
|
-
* to give an LLM client everything it needs to drive the API.
|
|
120
|
+
* to give an LLM client everything it needs to drive the API. `operations` is the
|
|
121
|
+
* registration's own, when it narrows what the tables expose.
|
|
112
122
|
*/
|
|
113
|
-
export function buildAgentManifest(dbTables) {
|
|
123
|
+
export function buildAgentManifest(dbTables, options = {}) {
|
|
114
124
|
const tables = {};
|
|
115
125
|
for (const [key, tableConf] of Object.entries(dbTables)) {
|
|
116
|
-
tables[key] = manifestTable(tableConf);
|
|
126
|
+
tables[key] = manifestTable(tableConf, options.operations);
|
|
117
127
|
}
|
|
118
128
|
return { tables };
|
|
119
129
|
}
|
|
@@ -128,9 +138,13 @@ export function renderAgentManifestMd(manifest) {
|
|
|
128
138
|
'',
|
|
129
139
|
'Notation: `!`=required on insert, `?`=nullable, `(writeOnly)`=writable, never in reads, ' +
|
|
130
140
|
'`(readOnly)`=returned by reads, refused by every write (omit it from write payloads).',
|
|
131
|
-
'serverGenerated fields: omit on insert (values from client are ignored).',
|
|
141
|
+
'serverGenerated fields: omit on insert (values from client are ignored), except in the upsertKey.',
|
|
142
|
+
'upsertKey: insert and bulkUpsert update the row with that key; every row must carry it ' +
|
|
143
|
+
'(400 missing_key), except a serverGenerated key: absent → new row, present → must name an ' +
|
|
144
|
+
'existing row (400 not_found).',
|
|
132
145
|
'readJoins aliases: `1:N` → joinMustExist/joinMultiple/joinGroup; `N:1` → joinLeft.',
|
|
133
|
-
'writeJoins aliases: keys for `
|
|
146
|
+
'writeJoins aliases: keys for `upsert`/`delete` in writes. `[key]`: the upsert key; such an ' +
|
|
147
|
+
'alias also takes `replace`, the complete set of child rows (a row left out is deleted).',
|
|
134
148
|
'filters: unknown keys are rejected (400), never ignored. extraFilters do not apply ' +
|
|
135
149
|
'under joinLeft — use joinMustExist on the same relation.',
|
|
136
150
|
'',
|
|
@@ -170,6 +184,8 @@ function renderTableMd(t) {
|
|
|
170
184
|
lines.push(`fields: ${fieldParts.join(', ')}`);
|
|
171
185
|
if (t.serverGenerated)
|
|
172
186
|
lines.push(`serverGenerated: ${t.serverGenerated.join(', ')}`);
|
|
187
|
+
if (t.upsertKey)
|
|
188
|
+
lines.push(`upsertKey: ${t.upsertKey.join(', ')}`);
|
|
173
189
|
if (t.computed)
|
|
174
190
|
lines.push(`computed: ${namedTypes(t.computed)}`);
|
|
175
191
|
if (t.extraFilters)
|
|
@@ -179,7 +195,8 @@ function renderTableMd(t) {
|
|
|
179
195
|
lines.push(`readJoins: ${readJoins.join(', ')}`);
|
|
180
196
|
}
|
|
181
197
|
if (t.writeJoins) {
|
|
182
|
-
const
|
|
198
|
+
const keyOf = (j) => (j.upsertKey ? '[' + j.upsertKey.join('+') + ']' : '');
|
|
199
|
+
const writeJoins = t.writeJoins.map((j) => `${j.alias}→${j.table}${keyOf(j)}`);
|
|
183
200
|
lines.push(`writeJoins: ${writeJoins.join(', ')}`);
|
|
184
201
|
}
|
|
185
202
|
if (t.defaultOrder)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { DbTables } from '../../types.js';
|
|
1
|
+
import type { DbTables, TableOperation } from '../../types.js';
|
|
2
2
|
export interface AgentToolSchemas {
|
|
3
|
-
/** POST /search/{table}:
|
|
3
|
+
/** POST /search/{table}: the whole request, `orderBy`/`paginator`/`compute` included. */
|
|
4
4
|
search?: {
|
|
5
5
|
body: object;
|
|
6
|
-
querystring: object;
|
|
7
6
|
};
|
|
8
7
|
insert?: {
|
|
9
8
|
body: object;
|
|
@@ -22,7 +21,8 @@ export interface AgentToolSchemas {
|
|
|
22
21
|
* Ready-to-use JSON Schemas for exposing a table's operations as strict LLM tools —
|
|
23
22
|
* the same TypeBox schemas the HTTP routes validate with (TypeBox objects ARE plain
|
|
24
23
|
* JSON Schema). Only the operations actually enabled for the table are included
|
|
25
|
-
* (`operations` whitelist, composite-PK rules). `
|
|
24
|
+
* (`operations` whitelist, composite-PK rules). `opts` mirrors the plugin options of the
|
|
25
|
+
* registration the tools call: its caps and its `operations`. `get` and `delete` take a single PK
|
|
26
26
|
* path param and need no schema.
|
|
27
27
|
*
|
|
28
28
|
* Strict tools trade prompt size for provider-side validation; the lighter
|
|
@@ -32,5 +32,6 @@ export interface AgentToolSchemas {
|
|
|
32
32
|
export declare function agentToolSchemas(dbTables: DbTables, tableName: string, opts?: {
|
|
33
33
|
maxItemsPerPage?: number;
|
|
34
34
|
maxBulkItems?: number;
|
|
35
|
+
operations?: TableOperation[];
|
|
35
36
|
}): AgentToolSchemas;
|
|
36
37
|
//# sourceMappingURL=tool-schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-schemas.d.ts","sourceRoot":"","sources":["../../../src/lib/agent/tool-schemas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/
|
|
1
|
+
{"version":3,"file":"tool-schemas.d.ts","sourceRoot":"","sources":["../../../src/lib/agent/tool-schemas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE/D,MAAM,WAAW,gBAAgB;IAC/B,yFAAyF;IACzF,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;CAAE,GACxF,gBAAgB,CA4BlB"}
|