@agentic-kit/db-tools 0.14.0 → 0.15.1
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/esm/host.d.ts +2 -1
- package/esm/records/delete-effects.d.ts +64 -0
- package/esm/records/delete-effects.js +239 -0
- package/esm/records/delete-selection.d.ts +29 -0
- package/esm/records/delete-selection.js +168 -0
- package/esm/records/rows.d.ts +27 -4
- package/esm/records/rows.js +53 -36
- package/esm/schema-model.d.ts +2 -0
- package/esm/schema-model.js +2 -0
- package/esm/tools/add-relation-schema.d.ts +4 -4
- package/esm/tools/delete-records.d.ts +33 -0
- package/esm/tools/delete-records.js +208 -0
- package/esm/tools/index.d.ts +6 -2
- package/esm/tools/index.js +10 -0
- package/host.d.ts +2 -1
- package/package.json +3 -3
- package/records/delete-effects.d.ts +64 -0
- package/records/delete-effects.js +250 -0
- package/records/delete-selection.d.ts +29 -0
- package/records/delete-selection.js +171 -0
- package/records/rows.d.ts +27 -4
- package/records/rows.js +64 -39
- package/schema-model.d.ts +2 -0
- package/schema-model.js +2 -0
- package/tools/add-relation-schema.d.ts +4 -4
- package/tools/delete-records.d.ts +33 -0
- package/tools/delete-records.js +212 -0
- package/tools/index.d.ts +6 -2
- package/tools/index.js +10 -0
package/README.md
CHANGED
|
@@ -27,11 +27,11 @@ npm install @agentic-kit/db-tools
|
|
|
27
27
|
|
|
28
28
|
## What's inside
|
|
29
29
|
|
|
30
|
-
- **
|
|
30
|
+
- **27 typed db tools** — `provision_database` / `replace_database`, `provision_blueprint`, `describe_schema`, `add_relation`, `delete_table`, `create_field` / `update_field` / `retype_field` / `delete_field`, `add_policies`, `add_records` / `update_records` / `delete_records`, `list_entity_types` / `create_entity_type` / `delete_entity_type`, `create_api_key`, `run_codegen`, the template suite (`list` / `create` / `apply` / `update` / `delete`), the access tools (`explain_access`, `set_access`), and `describe_policy_type`. `constructiveDbTools` is the list, in registration order. Each states one effect (`read`, `write` or `destructive`) for every call; a change whose effect differs is its own tool (`retype_field` beside `update_field`, `replace_database` beside `provision_database`). Every failing call returns a `failure` (code, message, hint) beside the `details` it always had. A message or hint names no tool and no parameter: the calls that help travel as data (`failure.calls`, `result.calls`). Every object of a tool's own input refuses a key it does not have and names the nearest known one, instead of dropping it; Every change that names a table, a field, a template or an entity type finds it, or finds a new name's stored form free, before there is a plan to approve. A call that did only part of what was asked (a field without its unique constraint, some of the rows) returns the code `partial`, and its `details` hold the errors of the part that failed. Backend errors are read by their `extensions.code` and `extensions.class`, then the HTTP status (`extensions.http` first: the server answers HTTP 200 and puts the status there), then a masked internal error with its `errorId`; message text never decides, because the server masks the text it does not mean to show. `failureFromErrors(errors, action, meaning?)` is that mapping, exported for code that sends its own GraphQL (`postGraphQL`, which takes an `operationName`), and `FailureMeaning` names what a unique violation means for the call.
|
|
31
31
|
|
|
32
32
|
The public `extensions.context` of the error that decided goes into `failure.context`: a query over the backend's request limits (`QUERY_TOO_COSTLY`, `QUERY_TOO_DEEP`, `PAGE_SIZE_TOO_LARGE`, `REQUEST_TOO_LARGE`) is `query-too-large` with its numbers there, for example `{ cost, limit }`. An update or delete that answers with no row in its payload changed nothing: that is how row-level security answers for a row this account cannot see, so every tool that updates or deletes fails `no-rows-changed` there instead of reporting success. A create that answers without the new row fails `no-rows-changed` as well: the row may not exist, or a policy lets the account create it but not read it, and the hint names the call that shows whether it exists. `STEP_UP_REQUIRED` is `step-up-required`: the change needs a recent sign-in.
|
|
33
33
|
|
|
34
|
-
`constructiveGateDeps().precondition` runs each tool's own first check and returns the plan's target from what it resolved (`toolPreconditions`, one per tool, provision_database included), and for a change to a table's access the access before and after; a tool the map does not hold is blocked as `unsupported`.
|
|
34
|
+
`constructiveGateDeps().precondition` runs each tool's own first check and returns the plan's target from what it resolved (`toolPreconditions`, one per tool, provision_database included), and for a change to a table's access the access before and after; a tool the map does not hold is blocked as `unsupported`. For `delete_records` the check resolves the exact rows once, as the person signed in to the app: each table's rows by key, by column values (`where`), its sample rows still there, or all its rows, at most 500 in all, ordered so a row goes before the rows it points at, with what the delete does to the rows it does not select: the rows that point at them, counted on the app API by the foreign keys and followed through each cascade (search chunk tables left out). The target names those rows (`rows`) and the card's preview shows them (`delete-records`). The tool then deletes only the rows the approved target names (`takeApprovedTable`). When a host leaves tables out of the target, the tool counts the effects of the approved rows again first, and deletes nothing when they would delete, clear or be blocked by rows of a table the person kept, or when it can't count or follow the rows that could reach one (too many related rows, a table with no single-column key, a key it can't read).
|
|
35
35
|
|
|
36
36
|
**Access.** The access of a table is its stored rules, grants and row security (`readTables`), and nothing here says who can or cannot reach a row. `explain_access` gives one plain sentence per stored rule (`explainPolicy`, from the words of the rule's Authz node), the grants, row security and the structural findings (`accessFindings`), each of which says what may happen. It and `describe_schema` return each stored rule through `asWritten`, in the one shape a caller writes (`{ $type, privileges, permissive, policy_role, data, with_check? }`), with every key the node's closed `parameter_schema` marks `readOnly` left out, nested nodes included, so a read carries no part the closed world refuses. A plan's rules use the same keys, with `words` in place of `data`. `set_access` replaces every rule of a table in one change with `owns: ['policies']`; the grants stay, and the Data nodes the rules need add their columns when the table lacks them. `add_policies` adds rules without replacing any. Both take rules only in the registry's blueprint shape (`{ $type, privileges, permissive, policy_role, policy_name, data }`, `AccessPolicyZod`), check each rule's shape against the registry's `BlueprintPolicy`, and check its data with `checkRule` (ajv over the node's closed `parameter_schema`, and the rule shapes these tools do not support) and its role before any plan. Every tool that sends rules, `provision_blueprint` included, sends them through `rulesToSend`: rules of one policy type, role, kind and data become one rule with all their privileges, and a rule the backend would skip (the same policy type and data as another) or refuse (a second policy row of one role, privilege and name) is refused before the plan. The plan holds the rules, grants and row security now and after, one sentence per rule, the findings the change adds and removes, the columns it adds (name, type, required, default) and the ones it reuses as they are. A reused column of another type than its Data node needs is blocked before the change (`conflict`, with `retype_field` and `delete_field`). When the person signed in to the app sees a row, a change that adds a required column with no value for the rows is blocked before anything is sent; otherwise the backend's refused NOT NULL comes back as a `conflict` with the `create_field` call that adds the column as optional first. After the change, the table is read back and compared with the plan by meaning (`policyDifference`); a difference is a `conflict`, and a read that fails is `unverified`. A refusal on the rows of an app table (`add_records`) suggests the read of its rules; a refusal on the control plane does not, because it is about the account's rights on the database.
|
|
37
37
|
|
|
@@ -76,7 +76,7 @@ const result = await describeSchemaTool.execute({ database_name: 'my-app' }, { c
|
|
|
76
76
|
|
|
77
77
|
Only `missing` means the database is gone. On a backend without `hash`, the probe retries once without it and `hash` is undefined. `resolveProjectContext` reports the same states as `db-missing`, `db-suspended`, `account-mismatch` and `backend-unreachable` (with `cause`), and a resolved context carries `hash`.
|
|
78
78
|
|
|
79
|
-
Tenant APIs answer `ACCESS_SUSPENDED` (a 403 with a JSON body) for a deleted or suspended database. The SDK's `FetchAdapter` drops that body, so `postGraphQL` and `statusAdapter` (a drop-in ORM adapter) keep each error's `extensions.code` and HTTP status, and `classifyBackendErrors` sorts them into `suspended`, `network`, `server`, `auth`, `forbidden` or `graphql`. `add_records`, `run_codegen` and `create_api_key` return `details.code: 'database-unavailable'` on `ACCESS_SUSPENDED`, and `run_codegen` doesn't retry a refused introspection.
|
|
79
|
+
Tenant APIs answer `ACCESS_SUSPENDED` (a 403 with a JSON body) for a deleted or suspended database. The SDK's `FetchAdapter` drops that body, so `postGraphQL` and `statusAdapter` (a drop-in ORM adapter) keep each error's `extensions.code` and HTTP status, and `classifyBackendErrors` sorts them into `suspended`, `network`, `server`, `auth`, `forbidden` or `graphql`. `add_records`, `update_records`, `delete_records`, `run_codegen` and `create_api_key` return `details.code: 'database-unavailable'` on `ACCESS_SUSPENDED`, and `run_codegen` doesn't retry a refused introspection.
|
|
80
80
|
|
|
81
81
|
## The live schema
|
|
82
82
|
|
package/esm/host.d.ts
CHANGED
|
@@ -179,7 +179,8 @@ export interface ToolsHost {
|
|
|
179
179
|
persistBinding?(binding: ProjectBinding): Promise<void>;
|
|
180
180
|
/**
|
|
181
181
|
* The ids of the sample rows the host seeded into the project's database, by table name, in seed order (null for
|
|
182
|
-
* a row that did not land). A
|
|
182
|
+
* a row that did not land). A value "@<table>[<index>]" in add_records, update_records or delete_records names one of them, and delete_records
|
|
183
|
+
* can delete every seeded row of a table that is still there.
|
|
183
184
|
* A host that seeds no rows leaves it out, and such a value then fails.
|
|
184
185
|
*/
|
|
185
186
|
seededRows?(cwd: string): Promise<Readonly<Record<string, readonly (string | null)[]>> | null>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type DeleteRecordsLink } from '@agentic-kit/harness';
|
|
2
|
+
import { type Result } from '../failure';
|
|
3
|
+
import { type SchemaModel } from '../schema-model';
|
|
4
|
+
import { type RawMetaTable } from './meta';
|
|
5
|
+
import { type AppReady } from './rows';
|
|
6
|
+
/** The most rows one call deletes, over all its tables, and the most rows its effects read. */
|
|
7
|
+
export declare const MAX_DELETED_ROWS = 500;
|
|
8
|
+
/** The SQL name of an app table, as the person and the schema model name it. */
|
|
9
|
+
export declare const sqlName: (table: RawMetaTable) => string;
|
|
10
|
+
export type Read = {
|
|
11
|
+
total: number;
|
|
12
|
+
nodes: Record<string, unknown>[];
|
|
13
|
+
};
|
|
14
|
+
/** The first rows the filter selects, with the given fields, and how many it selects in all. */
|
|
15
|
+
export declare function readRows(ready: AppReady, { name, table }: {
|
|
16
|
+
name: string;
|
|
17
|
+
table: RawMetaTable;
|
|
18
|
+
}, filter: Record<string, unknown> | undefined, select: string[], first: number): Promise<Result<Read>>;
|
|
19
|
+
export type Effect = 'cascade' | 'set_null' | 'set_default' | 'restrict';
|
|
20
|
+
/**
|
|
21
|
+
* Rows of `child` that point at rows of `parent` the delete removes and that the delete does not select: what happens
|
|
22
|
+
* to them, by which columns, how many there are, and how many of the parent rows they point at. `upTo` is set when
|
|
23
|
+
* there were more than the read could take: then the count is at most that many. `unfollowed` is set when the rows go
|
|
24
|
+
* and other rows point at them, but `child` has no single-column key to follow them by. `uncounted` is set when the
|
|
25
|
+
* rows cannot be read on the app API, or the values the key points at cannot be read from the deleted rows.
|
|
26
|
+
*/
|
|
27
|
+
export type DeleteEffect = {
|
|
28
|
+
parent: string;
|
|
29
|
+
child: string;
|
|
30
|
+
effect: Effect;
|
|
31
|
+
columns: string[];
|
|
32
|
+
rows: number;
|
|
33
|
+
parents: number;
|
|
34
|
+
upTo?: number;
|
|
35
|
+
unfollowed?: true;
|
|
36
|
+
uncounted?: true;
|
|
37
|
+
};
|
|
38
|
+
export declare const rowsOf: (effect: DeleteEffect) => string;
|
|
39
|
+
/** "points" for one row, "point" for more. */
|
|
40
|
+
export declare const pointOf: (effect: DeleteEffect) => string;
|
|
41
|
+
/** One plain line for the card. */
|
|
42
|
+
export declare function effectLine(effect: DeleteEffect): string;
|
|
43
|
+
/** The foreign keys between the tables a delete names, one for each child, parent and effect, for the card to warn with. */
|
|
44
|
+
export declare function linksOf(names: readonly string[], model: SchemaModel): DeleteRecordsLink[];
|
|
45
|
+
/**
|
|
46
|
+
* The tables an effect may change that it does not count: its own table when its rows were not counted, and when its
|
|
47
|
+
* rows go and were not all followed, every table whose rows point at them.
|
|
48
|
+
*/
|
|
49
|
+
export declare function tablesNotChecked(effect: DeleteEffect, model: SchemaModel): string[];
|
|
50
|
+
type Key = string | number;
|
|
51
|
+
/**
|
|
52
|
+
* The schema model, and what deleting the selected rows does to the rows that point at them and are not selected, and
|
|
53
|
+
* through a cascade to the rows that point at those, each row followed once, over at most 500 rows read: one
|
|
54
|
+
* effect for each table, kind of effect and table it points at, with the union of the columns. A search chunk table the
|
|
55
|
+
* backend keeps is left out, because its rows always go with their parent row. A table with no rows there gives none.
|
|
56
|
+
*/
|
|
57
|
+
export declare function deleteEffects(ready: AppReady, selected: ReadonlyArray<{
|
|
58
|
+
tableName: string;
|
|
59
|
+
keys: readonly Key[];
|
|
60
|
+
}>): Promise<Result<{
|
|
61
|
+
model: SchemaModel;
|
|
62
|
+
effects: DeleteEffect[];
|
|
63
|
+
}>>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// What a records delete does to rows it does not select, counted on the app API as the person signed in to the app:
|
|
2
|
+
// the rows that point at the deleted rows, by the foreign keys the schema model reads.
|
|
3
|
+
import { listed } from '@agentic-kit/harness';
|
|
4
|
+
import { buildSelect, toCamelCasePlural } from '@constructive-io/graphql-query/generators';
|
|
5
|
+
import { failureFromError, failureFromErrors } from '../failure';
|
|
6
|
+
import { readSchemaModel } from '../schema-model';
|
|
7
|
+
import { cleanTable } from './meta';
|
|
8
|
+
import { columnOf, fieldNamed, isSuspended, primaryKeyOf, UNAVAILABLE } from './rows';
|
|
9
|
+
/** The most rows one call deletes, over all its tables, and the most rows its effects read. */
|
|
10
|
+
export const MAX_DELETED_ROWS = 500;
|
|
11
|
+
/** The SQL name of an app table, as the person and the schema model name it. */
|
|
12
|
+
export const sqlName = (table) => table.tableName ?? table.name;
|
|
13
|
+
/** The first rows the filter selects, with the given fields, and how many it selects in all. */
|
|
14
|
+
export async function readRows(ready, { name, table }, filter, select, first) {
|
|
15
|
+
const clean = cleanTable(table);
|
|
16
|
+
const variables = { first, ...(filter ? { where: filter } : {}) };
|
|
17
|
+
const query = buildSelect(clean, ready.tables.map(cleanTable), { ...variables, fieldSelection: { select } }).toString();
|
|
18
|
+
const action = `Failed to read the rows of ${name}`;
|
|
19
|
+
try {
|
|
20
|
+
const result = await ready.adapter.execute(query, variables);
|
|
21
|
+
if (!result.ok) {
|
|
22
|
+
const failure = isSuspended(result.errors)
|
|
23
|
+
? { code: 'database-unavailable', message: `${UNAVAILABLE} No rows were deleted.` }
|
|
24
|
+
: failureFromErrors(result.errors, action, { rows: { table: name } });
|
|
25
|
+
return { kind: 'failed', failure };
|
|
26
|
+
}
|
|
27
|
+
const connection = result.data?.[toCamelCasePlural(clean.name, clean)];
|
|
28
|
+
const nodes = (connection?.nodes ?? []).filter((node) => Boolean(node));
|
|
29
|
+
return { kind: 'ok', value: { total: connection?.totalCount ?? nodes.length, nodes } };
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
return { kind: 'failed', failure: failureFromError(err, action) };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const EFFECTS = {
|
|
36
|
+
cascade: 'cascade',
|
|
37
|
+
set_null: 'set_null',
|
|
38
|
+
set_default: 'set_default',
|
|
39
|
+
restrict: 'restrict',
|
|
40
|
+
no_action: 'restrict',
|
|
41
|
+
};
|
|
42
|
+
export const rowsOf = (effect) => {
|
|
43
|
+
const count = effect.upTo ?? effect.rows;
|
|
44
|
+
return `${effect.upTo ? 'up to ' : ''}${count} ${effect.child} row${count === 1 ? '' : 's'}`;
|
|
45
|
+
};
|
|
46
|
+
const one = (effect) => !effect.upTo && effect.rows === 1;
|
|
47
|
+
/** "points" for one row, "point" for more. */
|
|
48
|
+
export const pointOf = (effect) => (one(effect) ? 'points' : 'point');
|
|
49
|
+
/** One plain line for the card. */
|
|
50
|
+
export function effectLine(effect) {
|
|
51
|
+
if (effect.uncounted)
|
|
52
|
+
return `Deleting ${effect.parent} may also change the ${effect.child} rows that point at them (not counted).`;
|
|
53
|
+
const point = pointOf(effect);
|
|
54
|
+
switch (effect.effect) {
|
|
55
|
+
case 'cascade': {
|
|
56
|
+
const further = effect.unfollowed ? ', and the rows that point at those go too, not counted' : '';
|
|
57
|
+
return `Also deletes ${rowsOf(effect)} that ${point} at the ${effect.parent} you delete${further}.`;
|
|
58
|
+
}
|
|
59
|
+
case 'set_null':
|
|
60
|
+
return `Clears ${listed(effect.columns)} on ${rowsOf(effect)} that ${point} at the ${effect.parent} you delete.`;
|
|
61
|
+
case 'set_default': {
|
|
62
|
+
const defaults = effect.columns.length === 1 ? 'its default' : 'their defaults';
|
|
63
|
+
return `Sets ${listed(effect.columns)} to ${defaults} on ${rowsOf(effect)} that ${point} at the ${effect.parent} you delete.`;
|
|
64
|
+
}
|
|
65
|
+
case 'restrict': {
|
|
66
|
+
const parents = effect.upTo ? `Some ${effect.parent} rows` : `${effect.parents} ${effect.parent} row${effect.parents === 1 ? '' : 's'}`;
|
|
67
|
+
return `${parents} can't be deleted while ${rowsOf(effect)} ${point} at ${effect.parents === 1 && !effect.upTo ? 'it' : 'them'}.`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** The foreign keys between the tables a delete names, one for each child, parent and effect, for the card to warn with. */
|
|
72
|
+
export function linksOf(names, model) {
|
|
73
|
+
const named = new Set(names);
|
|
74
|
+
const links = new Map();
|
|
75
|
+
for (const child of model.tables.filter((table) => named.has(table.name))) {
|
|
76
|
+
for (const fk of child.foreignKeys) {
|
|
77
|
+
const effect = EFFECTS[fk.onDelete];
|
|
78
|
+
if (fk.targetTable === child.name || !named.has(fk.targetTable))
|
|
79
|
+
continue;
|
|
80
|
+
// A set-default key loses its link the way a set-null key does, which is what the card warns about.
|
|
81
|
+
const link = effect === 'set_default' ? 'set_null' : effect;
|
|
82
|
+
links.set(JSON.stringify([fk.targetTable, child.name, link]), { parent: fk.targetTable, child: child.name, effect: link });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return [...links.values()];
|
|
86
|
+
}
|
|
87
|
+
/** Every table whose rows point at rows of `table`, directly or through other tables. */
|
|
88
|
+
function pointingAt(table, model) {
|
|
89
|
+
const reached = new Set();
|
|
90
|
+
const queue = [table];
|
|
91
|
+
while (queue.length > 0) {
|
|
92
|
+
const parent = queue.shift();
|
|
93
|
+
for (const child of model.tables.filter((other) => other.foreignKeys.some((fk) => fk.targetTable === parent))) {
|
|
94
|
+
if (reached.has(child.name))
|
|
95
|
+
continue;
|
|
96
|
+
reached.add(child.name);
|
|
97
|
+
queue.push(child.name);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return reached;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The tables an effect may change that it does not count: its own table when its rows were not counted, and when its
|
|
104
|
+
* rows go and were not all followed, every table whose rows point at them.
|
|
105
|
+
*/
|
|
106
|
+
export function tablesNotChecked(effect, model) {
|
|
107
|
+
const own = effect.uncounted ? [effect.child] : [];
|
|
108
|
+
const further = effect.effect === 'cascade' && (effect.uncounted || effect.upTo || effect.unfollowed) ? pointingAt(effect.child, model) : [];
|
|
109
|
+
return [...new Set([...own, ...further])];
|
|
110
|
+
}
|
|
111
|
+
/** The ids of the search chunk tables the backend keeps for the database's tables (`embedding_chunks`). */
|
|
112
|
+
async function chunkTableIds({ api, databaseId }) {
|
|
113
|
+
const data = await api.embeddingChunk
|
|
114
|
+
.findMany({ select: { chunksTableId: true }, where: { databaseId: { equalTo: databaseId } } })
|
|
115
|
+
.unwrap();
|
|
116
|
+
return new Set((data.embeddingChunks?.nodes ?? []).flatMap((node) => (node?.chunksTableId ? [node.chunksTableId] : [])));
|
|
117
|
+
}
|
|
118
|
+
const isKey = (value) => typeof value === 'string' || typeof value === 'number';
|
|
119
|
+
/**
|
|
120
|
+
* The child field the key sets, and the values it has on the rows that point at the deleted parent rows: their keys,
|
|
121
|
+
* or for a key on another unique column, that column read from them. Null when the key cannot be read that way.
|
|
122
|
+
*/
|
|
123
|
+
async function linkValues(ready, parent, keys, fk, childTable) {
|
|
124
|
+
const at = fk.targetColumns.indexOf(columnOf(parent.key));
|
|
125
|
+
if (at >= 0) {
|
|
126
|
+
const field = fieldNamed(childTable, fk.columns[at]);
|
|
127
|
+
return { kind: 'ok', value: field ? { field, values: [...keys] } : null };
|
|
128
|
+
}
|
|
129
|
+
const target = fk.targetColumns.length === 1 ? fieldNamed(parent.table, fk.targetColumns[0]) : undefined;
|
|
130
|
+
const field = fieldNamed(childTable, fk.columns[0]);
|
|
131
|
+
if (!target || !field)
|
|
132
|
+
return { kind: 'ok', value: null };
|
|
133
|
+
const read = await readRows(ready, parent, { [parent.key.name]: { in: keys } }, [target.name], keys.length + 1);
|
|
134
|
+
if (read.kind === 'failed')
|
|
135
|
+
return read;
|
|
136
|
+
return { kind: 'ok', value: { field, values: read.value.nodes.map((node) => node[target.name]).filter((value) => value !== null && value !== undefined) } };
|
|
137
|
+
}
|
|
138
|
+
const entryOf = (parent, child, effect) => ({
|
|
139
|
+
effect: { parent, child, effect, columns: [], rows: 0, parents: 0 },
|
|
140
|
+
rows: new Set(),
|
|
141
|
+
keyless: 0,
|
|
142
|
+
parents: new Set(),
|
|
143
|
+
columns: new Set(),
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* The schema model, and what deleting the selected rows does to the rows that point at them and are not selected, and
|
|
147
|
+
* through a cascade to the rows that point at those, each row followed once, over at most 500 rows read: one
|
|
148
|
+
* effect for each table, kind of effect and table it points at, with the union of the columns. A search chunk table the
|
|
149
|
+
* backend keeps is left out, because its rows always go with their parent row. A table with no rows there gives none.
|
|
150
|
+
*/
|
|
151
|
+
export async function deleteEffects(ready, selected) {
|
|
152
|
+
let model;
|
|
153
|
+
let chunks;
|
|
154
|
+
try {
|
|
155
|
+
[model, chunks] = await Promise.all([readSchemaModel(ready.context), chunkTableIds(ready.context)]);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
return { kind: 'failed', failure: failureFromError(err, 'Failed to read the foreign keys of the project database') };
|
|
159
|
+
}
|
|
160
|
+
const tables = new Map(ready.tables.map((table) => [sqlName(table), table]));
|
|
161
|
+
const going = new Map(selected.map(({ tableName, keys }) => [tableName, new Set(keys)]));
|
|
162
|
+
const queue = selected.map(({ tableName, keys }) => ({ parent: tableName, keys: [...keys] }));
|
|
163
|
+
const found = new Map();
|
|
164
|
+
const pointedAt = (table) => model.tables.some((other) => !chunks.has(other.id) && other.foreignKeys.some((fk) => fk.targetTable === table));
|
|
165
|
+
let budget = MAX_DELETED_ROWS;
|
|
166
|
+
while (queue.length > 0) {
|
|
167
|
+
const { parent, keys } = queue.shift();
|
|
168
|
+
const parentTable = tables.get(parent);
|
|
169
|
+
const parentKey = parentTable && primaryKeyOf(parentTable);
|
|
170
|
+
if (!parentKey)
|
|
171
|
+
continue;
|
|
172
|
+
for (const child of model.tables.filter((table) => !chunks.has(table.id))) {
|
|
173
|
+
const childTable = tables.get(child.name);
|
|
174
|
+
// Without a single-column key the rows are counted, but they cannot be told apart or followed further.
|
|
175
|
+
const childKey = childTable && primaryKeyOf(childTable);
|
|
176
|
+
const toParent = child.foreignKeys.filter((key) => key.targetTable === parent);
|
|
177
|
+
// Rows without a key cannot be told apart, so two keys to the parent could count one row twice.
|
|
178
|
+
const countable = childTable && (childKey || toParent.length === 1);
|
|
179
|
+
for (const fk of toParent) {
|
|
180
|
+
const effect = EFFECTS[fk.onDelete];
|
|
181
|
+
const id = JSON.stringify([parent, child.name, effect]);
|
|
182
|
+
const link = countable ? await linkValues(ready, { name: parent, table: parentTable, key: parentKey }, keys, fk, childTable) : undefined;
|
|
183
|
+
if (link?.kind === 'failed')
|
|
184
|
+
return link;
|
|
185
|
+
if (!childTable || !link?.value) {
|
|
186
|
+
found.set(id, { ...(found.get(id) ?? entryOf(parent, child.name, effect)), uncounted: true });
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const { field, values } = link.value;
|
|
190
|
+
if (values.length === 0)
|
|
191
|
+
continue;
|
|
192
|
+
const select = childKey ? [childKey.name, field.name] : [field.name];
|
|
193
|
+
const read = await readRows(ready, { name: child.name, table: childTable }, { [field.name]: { in: values } }, select, budget + 1);
|
|
194
|
+
if (read.kind === 'failed')
|
|
195
|
+
return read;
|
|
196
|
+
budget = Math.max(0, budget - read.value.nodes.length);
|
|
197
|
+
const own = going.get(child.name);
|
|
198
|
+
const outside = childKey ? read.value.nodes.filter((node) => !own?.has(node[childKey.name])) : read.value.nodes;
|
|
199
|
+
const truncated = childKey !== undefined && read.value.total > read.value.nodes.length;
|
|
200
|
+
if (outside.length === 0 && !truncated)
|
|
201
|
+
continue;
|
|
202
|
+
const entry = found.get(id) ?? entryOf(parent, child.name, effect);
|
|
203
|
+
found.set(id, entry);
|
|
204
|
+
(fk.deleteSetColumns ?? fk.columns).forEach((column) => entry.columns.add(column));
|
|
205
|
+
for (const node of outside) {
|
|
206
|
+
if (childKey && isKey(node[childKey.name]))
|
|
207
|
+
entry.rows.add(node[childKey.name]);
|
|
208
|
+
if (isKey(node[field.name]))
|
|
209
|
+
entry.parents.add(node[field.name]);
|
|
210
|
+
}
|
|
211
|
+
if (!childKey) {
|
|
212
|
+
entry.keyless += read.value.total;
|
|
213
|
+
if (effect === 'cascade' && pointedAt(child.name))
|
|
214
|
+
entry.effect.unfollowed = true;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (truncated) {
|
|
218
|
+
// Past the read limit the count is only an upper bound, so this branch stops here.
|
|
219
|
+
entry.effect.upTo = Math.max(entry.effect.upTo ?? 0, read.value.total);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (effect !== 'cascade')
|
|
223
|
+
continue;
|
|
224
|
+
// The cascaded rows go too, so the rows that point at them are followed once each.
|
|
225
|
+
const cascaded = outside.map((node) => node[childKey.name]).filter(isKey);
|
|
226
|
+
going.set(child.name, new Set([...(own ?? []), ...cascaded]));
|
|
227
|
+
queue.push({ parent: child.name, keys: cascaded });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const effects = [...found.values()].map(({ effect, rows, keyless, parents, columns, uncounted }) => ({
|
|
232
|
+
...effect,
|
|
233
|
+
columns: [...columns],
|
|
234
|
+
rows: rows.size + keyless,
|
|
235
|
+
parents: parents.size,
|
|
236
|
+
...(uncounted ? { uncounted } : {}),
|
|
237
|
+
}));
|
|
238
|
+
return { kind: 'ok', value: { model, effects } };
|
|
239
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type DeleteRecordsLink, type DeleteRecordsTable } from '@agentic-kit/harness';
|
|
2
|
+
import { type Result } from '../failure';
|
|
3
|
+
import { type AppReady } from './rows';
|
|
4
|
+
export type DeleteTableInput = {
|
|
5
|
+
table_name: string;
|
|
6
|
+
rows?: Array<string | number>;
|
|
7
|
+
where?: Record<string, unknown>;
|
|
8
|
+
sample?: true;
|
|
9
|
+
all?: true;
|
|
10
|
+
};
|
|
11
|
+
export type DeleteSelection = {
|
|
12
|
+
tables: DeleteRecordsTable[];
|
|
13
|
+
effects: string[];
|
|
14
|
+
links: DeleteRecordsLink[];
|
|
15
|
+
};
|
|
16
|
+
export type DeleteRecordsReady = AppReady & {
|
|
17
|
+
selection: DeleteSelection;
|
|
18
|
+
/** A table the input names that has no rows to delete, one sentence each. */
|
|
19
|
+
notes: string[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* What a records delete checks before it deletes anything, and the exact rows it deletes: one selector for each
|
|
23
|
+
* table, the project, an app sign-in, each table on the app's API with a key and a delete, the rows each selector
|
|
24
|
+
* names that are there (no more than 500 in all), the order that deletes a row before the rows it points at, and
|
|
25
|
+
* what the delete does to the rows it does not select.
|
|
26
|
+
*/
|
|
27
|
+
export declare function deleteRecordsReady(params: {
|
|
28
|
+
tables: DeleteTableInput[];
|
|
29
|
+
}, cwd: string): Promise<Result<DeleteRecordsReady>>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// The rows a records delete removes, resolved once from the call's input as the person signed in to the app: the
|
|
2
|
+
// gate's precondition and the tool both use `deleteRecordsReady`, so the card and the delete cannot disagree.
|
|
3
|
+
import { listed, nearestName } from '@agentic-kit/harness';
|
|
4
|
+
import { DESCRIBE_SCHEMA, explainAccessCall } from '../failure';
|
|
5
|
+
import { deleteEffects, effectLine, linksOf, MAX_DELETED_ROWS, readRows, sqlName } from './delete-effects';
|
|
6
|
+
import { findMetaTable } from './meta';
|
|
7
|
+
import { appReady, fieldNamed, fieldsOf, invalid, isRowRef, notAColumn, primaryKeyOf, seededIds, seededValue, tableKey } from './rows';
|
|
8
|
+
const SELECTORS = ['rows', 'where', 'sample', 'all'];
|
|
9
|
+
/** The filter that selects the rows the input names, null when it names none, or why the input is not valid. */
|
|
10
|
+
function filterOf({ input, table, name, key }, seeded) {
|
|
11
|
+
if (input.rows) {
|
|
12
|
+
const keys = input.rows.map((value) => seededValue(value, seeded));
|
|
13
|
+
const missing = input.rows.find((_, index) => keys[index] === undefined);
|
|
14
|
+
if (missing !== undefined)
|
|
15
|
+
return invalid(`${name} names "${missing}", but no sample row was seeded there: use the row's ${key.columnName ?? key.name}.`);
|
|
16
|
+
return { kind: 'ok', value: { [key.name]: { in: keys } } };
|
|
17
|
+
}
|
|
18
|
+
if (input.where) {
|
|
19
|
+
const unknown = notAColumn(table, name, Object.keys(input.where));
|
|
20
|
+
if (unknown)
|
|
21
|
+
return invalid(`The where of ${name} names ${unknown}`);
|
|
22
|
+
const filter = {};
|
|
23
|
+
for (const [column, given] of Object.entries(input.where)) {
|
|
24
|
+
const value = seededValue(given, seeded);
|
|
25
|
+
if (value === undefined)
|
|
26
|
+
return invalid(`The where of ${name} names "${given}", but no sample row was seeded there: use the row's id.`);
|
|
27
|
+
filter[fieldNamed(table, column).name] = value === null ? { isNull: true } : { equalTo: value };
|
|
28
|
+
}
|
|
29
|
+
return { kind: 'ok', value: filter };
|
|
30
|
+
}
|
|
31
|
+
if (input.sample) {
|
|
32
|
+
const ids = (seeded.get(tableKey(name)) ?? seeded.get(tableKey(input.table_name)) ?? []).filter((id) => Boolean(id));
|
|
33
|
+
return { kind: 'ok', value: ids.length ? { [key.name]: { in: ids } } : null };
|
|
34
|
+
}
|
|
35
|
+
return { kind: 'ok', value: undefined };
|
|
36
|
+
}
|
|
37
|
+
const NONE_LEFT = {
|
|
38
|
+
rows: (name) => `${name} has none of the rows given.`,
|
|
39
|
+
where: (name) => `${name} has no rows that match.`,
|
|
40
|
+
sample: (name) => `${name} has no sample rows left.`,
|
|
41
|
+
all: (name) => `${name} has no rows.`,
|
|
42
|
+
};
|
|
43
|
+
const selectorOf = (input) => SELECTORS.find((selector) => input[selector] !== undefined) ?? 'all';
|
|
44
|
+
const READABLE_TYPES = new Set(['String', 'Int', 'Float', 'BigFloat', 'BigInt', 'Boolean', 'Date', 'Datetime']);
|
|
45
|
+
/** Up to three columns that tell rows apart on the card, text first; keys of other rows say nothing to a person. */
|
|
46
|
+
function readableFields(table, key) {
|
|
47
|
+
return fieldsOf(table)
|
|
48
|
+
.filter((field) => field !== key && !field.type.isArray && READABLE_TYPES.has(field.type.gqlType) && !/Id$/.test(field.name))
|
|
49
|
+
.sort((a, b) => Number(b.type.gqlType === 'String') - Number(a.type.gqlType === 'String'))
|
|
50
|
+
.slice(0, 3);
|
|
51
|
+
}
|
|
52
|
+
/** The tables in an order that deletes a row before the rows it points at: each table before the listed tables it points at. */
|
|
53
|
+
function childrenFirst(tables, model) {
|
|
54
|
+
const pointsAt = new Map(model.tables.map((table) => [table.name, new Set(table.foreignKeys.map((fk) => fk.targetTable))]));
|
|
55
|
+
const left = [...tables];
|
|
56
|
+
const ordered = [];
|
|
57
|
+
while (left.length > 0) {
|
|
58
|
+
const pointedAt = (table) => left.some((other) => other !== table && pointsAt.get(other.tableName)?.has(table.tableName));
|
|
59
|
+
// A cycle leaves no table that nothing points at, so the rest keep the order of the input.
|
|
60
|
+
const next = left.find((table) => !pointedAt(table)) ?? left[0];
|
|
61
|
+
ordered.push(next);
|
|
62
|
+
left.splice(left.indexOf(next), 1);
|
|
63
|
+
}
|
|
64
|
+
return ordered;
|
|
65
|
+
}
|
|
66
|
+
/** Every table the input names on the app API, once each, with a key the API deletes by. */
|
|
67
|
+
function pickTables(tables, inputs) {
|
|
68
|
+
const picked = [];
|
|
69
|
+
for (const input of inputs) {
|
|
70
|
+
const table = findMetaTable(tables, input.table_name);
|
|
71
|
+
if (!table) {
|
|
72
|
+
const nearest = nearestName(input.table_name, tables.map(sqlName));
|
|
73
|
+
return {
|
|
74
|
+
kind: 'failed',
|
|
75
|
+
failure: {
|
|
76
|
+
code: 'not-found',
|
|
77
|
+
message: `Table "${input.table_name}" was not found in the app database${nearest ? `: use "${nearest}".` : '.'}`,
|
|
78
|
+
hint: 'Check the table names that exist, then retry.',
|
|
79
|
+
calls: [DESCRIBE_SCHEMA],
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const name = sqlName(table);
|
|
84
|
+
const twice = picked.find((other) => other.table === table);
|
|
85
|
+
if (twice)
|
|
86
|
+
return invalid(`The call names ${name} twice ("${twice.input.table_name}" and "${input.table_name}"): name each table once, with all its rows in one selection.`);
|
|
87
|
+
const key = primaryKeyOf(table);
|
|
88
|
+
if (!key)
|
|
89
|
+
return { kind: 'failed', failure: { code: 'unsupported', message: `${name} has no single-column primary key, so its rows can't be named.` } };
|
|
90
|
+
if (!table.query?.delete) {
|
|
91
|
+
return {
|
|
92
|
+
kind: 'failed',
|
|
93
|
+
failure: {
|
|
94
|
+
code: 'unsupported',
|
|
95
|
+
message: `The app API can't delete ${name} rows.`,
|
|
96
|
+
hint: 'The rules of the table may let no one delete rows: read them to see who they let delete.',
|
|
97
|
+
calls: [explainAccessCall(name)],
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
picked.push({ input, table, name, key });
|
|
102
|
+
}
|
|
103
|
+
return { kind: 'ok', value: picked };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* What a records delete checks before it deletes anything, and the exact rows it deletes: one selector for each
|
|
107
|
+
* table, the project, an app sign-in, each table on the app's API with a key and a delete, the rows each selector
|
|
108
|
+
* names that are there (no more than 500 in all), the order that deletes a row before the rows it points at, and
|
|
109
|
+
* what the delete does to the rows it does not select.
|
|
110
|
+
*/
|
|
111
|
+
export async function deleteRecordsReady(params, cwd) {
|
|
112
|
+
for (const input of params.tables) {
|
|
113
|
+
const given = SELECTORS.filter((selector) => input[selector] !== undefined);
|
|
114
|
+
if (given.length === 0)
|
|
115
|
+
return invalid(`Nothing says which rows of ${input.table_name} to delete: give one of rows, where, sample or all.`);
|
|
116
|
+
if (given.length > 1)
|
|
117
|
+
return invalid(`${input.table_name} gives ${listed(given)}: give only one of rows, where, sample and all.`);
|
|
118
|
+
if (input.where && Object.keys(input.where).length === 0) {
|
|
119
|
+
return invalid(`The where of ${input.table_name} names no column: give a column and the value its rows have, or use all for every row.`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const ready = await appReady(cwd, 'deleted');
|
|
123
|
+
if (ready.kind === 'failed')
|
|
124
|
+
return ready;
|
|
125
|
+
const picked = pickTables(ready.value.tables, params.tables);
|
|
126
|
+
if (picked.kind === 'failed')
|
|
127
|
+
return picked;
|
|
128
|
+
const needsSeeded = params.tables.some((input) => input.sample || input.rows?.some(isRowRef) || Object.values(input.where ?? {}).some(isRowRef));
|
|
129
|
+
const seeded = needsSeeded ? await seededIds(cwd) : { kind: 'ok', value: new Map() };
|
|
130
|
+
if (seeded.kind === 'failed')
|
|
131
|
+
return seeded;
|
|
132
|
+
const tables = [];
|
|
133
|
+
const notes = [];
|
|
134
|
+
let total = 0;
|
|
135
|
+
for (const pick of picked.value) {
|
|
136
|
+
const filter = filterOf(pick, seeded.value);
|
|
137
|
+
if (filter.kind === 'failed')
|
|
138
|
+
return filter;
|
|
139
|
+
const select = [pick.key.name, ...readableFields(pick.table, pick.key).map((field) => field.name)];
|
|
140
|
+
const read = filter.value === null
|
|
141
|
+
? { kind: 'ok', value: { total: 0, nodes: [] } }
|
|
142
|
+
: await readRows(ready.value, pick, filter.value, select, MAX_DELETED_ROWS + 1);
|
|
143
|
+
if (read.kind === 'failed')
|
|
144
|
+
return read;
|
|
145
|
+
total += read.value.total;
|
|
146
|
+
const keys = read.value.nodes.map((node) => node[pick.key.name]).filter((key) => typeof key === 'string' || typeof key === 'number');
|
|
147
|
+
if (keys.length === 0) {
|
|
148
|
+
notes.push(NONE_LEFT[selectorOf(pick.input)](pick.name));
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const missing = new Set(pick.input.rows ?? []).size - keys.length;
|
|
152
|
+
if (missing > 0)
|
|
153
|
+
notes.push(`${missing} of the rows given for ${pick.name} ${missing === 1 ? 'is' : 'are'} not there, so the delete leaves ${missing === 1 ? 'it' : 'them'} out.`);
|
|
154
|
+
tables.push({ tableName: pick.name, keyName: pick.key.name, keys, count: keys.length, rows: read.value.nodes.slice(0, 5) });
|
|
155
|
+
}
|
|
156
|
+
if (total > MAX_DELETED_ROWS) {
|
|
157
|
+
return invalid(`The call selects ${total} rows in all, more than the ${MAX_DELETED_ROWS} one call deletes: narrow it with rows or where, or delete the tables in several calls.`);
|
|
158
|
+
}
|
|
159
|
+
if (tables.length === 0)
|
|
160
|
+
return { kind: 'failed', failure: { code: 'not-found', message: notes.join(' ') } };
|
|
161
|
+
const found = await deleteEffects(ready.value, tables);
|
|
162
|
+
if (found.kind === 'failed')
|
|
163
|
+
return found;
|
|
164
|
+
const { model, effects } = found.value;
|
|
165
|
+
const ordered = childrenFirst(tables, model);
|
|
166
|
+
const links = linksOf(ordered.map((table) => table.tableName), model);
|
|
167
|
+
return { kind: 'ok', value: { ...ready.value, selection: { tables: ordered, effects: effects.map(effectLine), links }, notes } };
|
|
168
|
+
}
|
package/esm/records/rows.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type HarnessToolResult, type ToolFailure } from '@agentic-kit/harness';
|
|
2
2
|
import type { ProjectContext } from '../context';
|
|
3
3
|
import { type Result } from '../failure';
|
|
4
|
-
import { statusAdapter } from '../graphql-http';
|
|
4
|
+
import { type GraphQLError, statusAdapter } from '../graphql-http';
|
|
5
5
|
import { type RawField, type RawMetaTable } from './meta';
|
|
6
6
|
export type RecordsDetails = {
|
|
7
7
|
success: boolean;
|
|
@@ -21,19 +21,32 @@ export type RecordsDetails = {
|
|
|
21
21
|
}[];
|
|
22
22
|
};
|
|
23
23
|
type Verb = 'insert' | 'update';
|
|
24
|
-
export declare
|
|
24
|
+
export declare const UNAVAILABLE = "The app database is unavailable: the backend answered ACCESS_SUSPENDED, so it was deleted or is suspended. Retrying won't help until it is restored.";
|
|
25
|
+
export declare const isSuspended: (errors: readonly GraphQLError[]) => boolean;
|
|
26
|
+
type RecordsFlags = {
|
|
27
|
+
success: boolean;
|
|
28
|
+
message: string;
|
|
29
|
+
needsAuth?: boolean;
|
|
30
|
+
code?: 'database-unavailable';
|
|
31
|
+
};
|
|
32
|
+
export declare function recordsFailed<D extends RecordsFlags = RecordsDetails>(failure: ToolFailure, extra?: Partial<NoInfer<D>>): HarnessToolResult<D>;
|
|
25
33
|
export declare const invalid: (message: string) => Result<never>;
|
|
26
|
-
|
|
34
|
+
/** The app's tables as the person signed in to the app sees them, and the API to reach them. */
|
|
35
|
+
export type AppReady = {
|
|
27
36
|
context: ProjectContext;
|
|
28
37
|
token: string;
|
|
29
38
|
userId?: string;
|
|
30
39
|
/** The app's own API, as the person signed in to the app. */
|
|
31
40
|
adapter: ReturnType<typeof statusAdapter>;
|
|
32
41
|
tables: RawMetaTable[];
|
|
42
|
+
};
|
|
43
|
+
export type RecordsReady = AppReady & {
|
|
33
44
|
table: RawMetaTable;
|
|
34
45
|
/** The records with each key as the API's field name. */
|
|
35
46
|
records: Record<string, unknown>[];
|
|
36
47
|
};
|
|
48
|
+
/** The project, its data endpoint, an app sign-in, and the tables of the app's API; `done` ends a suspended message. */
|
|
49
|
+
export declare function appReady(cwd: string, done: string): Promise<Result<AppReady>>;
|
|
37
50
|
/**
|
|
38
51
|
* What a records call checks before it writes anything: rows to write, the project, its data endpoint, an app
|
|
39
52
|
* sign-in, the table on the app's API, and every record's keys and seeded-row values.
|
|
@@ -46,7 +59,11 @@ export declare const fieldsOf: (table: RawMetaTable) => RawField[];
|
|
|
46
59
|
export declare const columnOf: (field: RawField) => string;
|
|
47
60
|
/** The table's single-column primary key, or undefined for none or a composite one. */
|
|
48
61
|
export declare function primaryKeyOf(table: RawMetaTable): RawField | undefined;
|
|
49
|
-
|
|
62
|
+
export declare const isRowRef: (value: unknown) => value is string;
|
|
63
|
+
export declare const tableKey: (value: string) => string;
|
|
64
|
+
export type SeededIds = ReadonlyMap<string, readonly (string | null)[]>;
|
|
65
|
+
/** The ids of the sample rows the host seeded, by `tableKey`; none on a host that seeds no rows. */
|
|
66
|
+
export declare function seededIds(cwd: string): Promise<Result<SeededIds>>;
|
|
50
67
|
/**
|
|
51
68
|
* A record with each key as the API's field name. A key may be a field name or a column name, and the field name's
|
|
52
69
|
* value wins when both carry one; an empty value never replaces a given one. With nothing but empty values, a column
|
|
@@ -54,6 +71,12 @@ type SeededIds = ReadonlyMap<string, readonly (string | null)[]>;
|
|
|
54
71
|
* seeded row's id.
|
|
55
72
|
*/
|
|
56
73
|
export declare function recordAsFields(table: RawMetaTable, tableName: string, index: number, record: Record<string, unknown>, seeded: SeededIds, clear: boolean): Result<Record<string, unknown>>;
|
|
74
|
+
/** The value, or the id of the seeded row a "@<table>[<index>]" value names: undefined when none was seeded there. */
|
|
75
|
+
export declare function seededValue(value: unknown, seeded: SeededIds): unknown;
|
|
76
|
+
/** The first key that names no column (or field) of the table, with the column to use instead, as the end of a sentence. */
|
|
77
|
+
export declare function notAColumn(table: RawMetaTable, tableName: string, keys: readonly string[]): string | undefined;
|
|
78
|
+
/** The field a key names, by its field name or its column name. */
|
|
79
|
+
export declare const fieldNamed: (table: RawMetaTable, key: string) => RawField | undefined;
|
|
57
80
|
/** One write per input, in order, until the database is suspended, and the call's result from each row's answer. */
|
|
58
81
|
export declare function writeRecords(verb: Verb, tableName: string, { adapter, table: rawTable }: RecordsReady, mutation: string, mutationName: string, inputs: readonly Record<string, unknown>[]): Promise<HarnessToolResult<RecordsDetails>>;
|
|
59
82
|
export {};
|