@agentic-kit/db-tools 0.13.1 → 0.15.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.
Files changed (46) hide show
  1. package/README.md +3 -3
  2. package/access/provisioning.js +1 -0
  3. package/esm/access/provisioning.js +1 -0
  4. package/esm/host.d.ts +7 -0
  5. package/esm/index.d.ts +2 -1
  6. package/esm/records/delete-effects.d.ts +64 -0
  7. package/esm/records/delete-effects.js +239 -0
  8. package/esm/records/delete-selection.d.ts +29 -0
  9. package/esm/records/delete-selection.js +168 -0
  10. package/esm/records/meta.d.ts +7 -2
  11. package/esm/records/meta.js +17 -8
  12. package/esm/records/rows.d.ts +82 -0
  13. package/esm/records/rows.js +250 -0
  14. package/esm/schema-model.d.ts +2 -0
  15. package/esm/schema-model.js +2 -0
  16. package/esm/tools/add-records.d.ts +5 -32
  17. package/esm/tools/add-records.js +15 -145
  18. package/esm/tools/add-relation-schema.d.ts +4 -4
  19. package/esm/tools/delete-records.d.ts +33 -0
  20. package/esm/tools/delete-records.js +208 -0
  21. package/esm/tools/index.d.ts +6 -2
  22. package/esm/tools/index.js +13 -0
  23. package/esm/tools/update-records.d.ts +16 -0
  24. package/esm/tools/update-records.js +57 -0
  25. package/host.d.ts +7 -0
  26. package/index.d.ts +2 -1
  27. package/package.json +5 -5
  28. package/records/delete-effects.d.ts +64 -0
  29. package/records/delete-effects.js +250 -0
  30. package/records/delete-selection.d.ts +29 -0
  31. package/records/delete-selection.js +171 -0
  32. package/records/meta.d.ts +7 -2
  33. package/records/meta.js +17 -8
  34. package/records/rows.d.ts +82 -0
  35. package/records/rows.js +269 -0
  36. package/schema-model.d.ts +2 -0
  37. package/schema-model.js +2 -0
  38. package/tools/add-records.d.ts +5 -32
  39. package/tools/add-records.js +14 -144
  40. package/tools/add-relation-schema.d.ts +4 -4
  41. package/tools/delete-records.d.ts +33 -0
  42. package/tools/delete-records.js +212 -0
  43. package/tools/index.d.ts +6 -2
  44. package/tools/index.js +13 -0
  45. package/tools/update-records.d.ts +16 -0
  46. package/tools/update-records.js +61 -0
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteRecordsTool = void 0;
4
+ exports.deleteRecordsPlan = deleteRecordsPlan;
5
+ const harness_1 = require("@agentic-kit/harness");
6
+ const generators_1 = require("@constructive-io/graphql-query/generators");
7
+ const zod_1 = require("zod");
8
+ const failure_1 = require("../failure");
9
+ const graphql_http_1 = require("../graphql-http");
10
+ const ready_1 = require("../ready");
11
+ const delete_effects_1 = require("../records/delete-effects");
12
+ const delete_selection_1 = require("../records/delete-selection");
13
+ const meta_1 = require("../records/meta");
14
+ const rows_1 = require("../records/rows");
15
+ const DeleteTableZod = (0, harness_1.strictObject)('a table', {
16
+ table_name: (0, harness_1.identifierParam)().describe('Name of the table to delete rows from (snake_case, singular or plural).'),
17
+ rows: zod_1.z
18
+ .array(zod_1.z.union([zod_1.z.string(), zod_1.z.number()]))
19
+ .min(1)
20
+ .describe('The rows to delete, by primary key, or "@<table>[<index>]" for a sample row seeded when the app was built.')
21
+ .optional(),
22
+ where: zod_1.z
23
+ .record(zod_1.z.string(), zod_1.z.unknown())
24
+ .describe('Delete every row whose columns have these values: column name (snake_case) -> value; null matches an empty column.')
25
+ .optional(),
26
+ sample: zod_1.z.literal(true).describe('Delete every sample row seeded when the app was built that is still there.').optional(),
27
+ all: zod_1.z.literal(true).describe('Delete every row of the table that the person signed in to the app can see.').optional(),
28
+ });
29
+ const DeleteRecordsZod = (0, harness_1.strictObject)('the input', {
30
+ tables: zod_1.z
31
+ .array(DeleteTableZod)
32
+ .min(1)
33
+ .max(20)
34
+ .describe('The tables to delete rows from, each with exactly one of rows, where, sample or all.'),
35
+ });
36
+ /** The plan of a records delete: the exact rows as the target, and the card's preview. */
37
+ function deleteRecordsPlan({ context, userId, selection, notes }) {
38
+ return {
39
+ target: { ...(0, ready_1.databaseTarget)(context, userId), rows: selection.tables.map(({ tableName, keys }) => ({ tableName, keys })) },
40
+ preview: { kind: 'delete-records', ...selection },
41
+ ...(notes.length ? { notes } : {}),
42
+ };
43
+ }
44
+ const sameTarget = (a, b) => a.database.id === b.database.id && a.apiEndpoint === b.apiEndpoint && a.account.userId === b.account.userId &&
45
+ a.account.agent?.principalId === b.account.agent?.principalId && a.appUserId === b.appUserId;
46
+ /** The app table and key of each table of the rows to delete, still on the app API with a delete. */
47
+ function plannedRows(tables, rows) {
48
+ const planned = [];
49
+ for (const { tableName, keys } of rows) {
50
+ const table = tables.find((candidate) => (0, delete_effects_1.sqlName)(candidate) === tableName);
51
+ const key = table && (0, rows_1.primaryKeyOf)(table);
52
+ if (!table || !key || !table.query?.delete) {
53
+ return {
54
+ kind: 'failed',
55
+ failure: {
56
+ code: 'failed',
57
+ message: `${tableName} changed on the app API after its rows were chosen, so nothing was deleted.`,
58
+ hint: 'Review the rows and approve a new request.',
59
+ },
60
+ };
61
+ }
62
+ planned.push({ tableName, table, keyName: key.name, keys });
63
+ }
64
+ return { kind: 'ok', value: planned };
65
+ }
66
+ const plural = (count, word) => `${count} ${word}${count === 1 ? '' : 's'}`;
67
+ const NO_ROW_DELETED = 'The backend answered without the deleted row, so it does not exist, or this account may not delete it.';
68
+ /** One delete per row, in order, until the database is suspended, and the call's result from each row's answer. */
69
+ async function deleteRows({ adapter, tables }, planned, kept) {
70
+ const all = tables.map(meta_1.cleanTable);
71
+ const results = [];
72
+ const errors = [];
73
+ let suspended = false;
74
+ for (const { tableName, table: rawTable, keyName, keys } of planned) {
75
+ if (suspended)
76
+ break;
77
+ const table = (0, meta_1.cleanTable)(rawTable);
78
+ const mutation = (0, generators_1.buildPostGraphileDelete)(table, all).toString();
79
+ const mutationName = (0, generators_1.toDeleteMutationName)(table.name, table);
80
+ const result = { tableName, deleted: 0, failed: [] };
81
+ results.push(result);
82
+ for (const key of keys) {
83
+ let rowErrors;
84
+ try {
85
+ const answer = await adapter.execute(mutation, { input: { [keyName]: key } });
86
+ if (answer.ok) {
87
+ if (answer.data?.[mutationName])
88
+ result.deleted += 1;
89
+ else
90
+ result.failed.push({ key, message: NO_ROW_DELETED });
91
+ continue;
92
+ }
93
+ if ((0, rows_1.isSuspended)(answer.errors)) {
94
+ suspended = true;
95
+ break;
96
+ }
97
+ rowErrors = answer.errors;
98
+ }
99
+ catch (err) {
100
+ // The request threw before any answer came back, so the error is the local one.
101
+ rowErrors = [{ message: (0, graphql_http_1.thrownText)(err), extensions: { code: 'NETWORK' } }];
102
+ }
103
+ errors.push(...rowErrors);
104
+ result.failed.push({ key, message: (0, graphql_http_1.answerText)(rowErrors) });
105
+ }
106
+ }
107
+ const deletedCount = results.reduce((sum, result) => sum + result.deleted, 0);
108
+ const failedCount = results.reduce((sum, result) => sum + result.failed.length, 0);
109
+ const details = { deletedCount, tables: [...results, ...kept.map((tableName) => ({ tableName, deleted: 0, kept: true, failed: [] }))] };
110
+ const done = results.filter((result) => result.deleted > 0);
111
+ const message = [
112
+ done.length ? `Deleted ${(0, harness_1.listed)(done.map((result, index) => `${index === 0 ? plural(result.deleted, 'row') : result.deleted} from ${result.tableName}`))}.` : '',
113
+ ...results.filter((result) => result.failed.length > 0).map(({ tableName, failed: [first, ...rest] }) => `${plural(rest.length + 1, 'row')} of ${tableName} ${rest.length ? 'were' : 'was'} not deleted (${first.key}: ${first.message}).`),
114
+ kept.length ? `Nothing was deleted from ${(0, harness_1.listed)(kept)}: the person unticked ${kept.length === 1 ? 'it, or it' : 'them, or they'} had no rows to delete.` : '',
115
+ ].filter(Boolean).join(' ');
116
+ const failed = (failure) => (0, rows_1.recordsFailed)(failure, details);
117
+ if (suspended) {
118
+ const before = deletedCount === 0 ? 'No rows were deleted.' : `${deletedCount === 1 ? '1 row was' : `${deletedCount} rows were`} deleted before it stopped.`;
119
+ return failed({ code: 'database-unavailable', message: `${rows_1.UNAVAILABLE} ${before}` });
120
+ }
121
+ if (failedCount > 0 && deletedCount === 0) {
122
+ const action = `Failed to delete rows from ${(0, harness_1.listed)(results.map((result) => result.tableName))}`;
123
+ return failed(errors.length ? (0, failure_1.failureFromErrors)(errors, action, { rows: { table: results[0].tableName } }) : (0, failure_1.noRowsChanged)(action, failure_1.DESCRIBE_SCHEMA));
124
+ }
125
+ if (failedCount > 0) {
126
+ return failed({
127
+ code: 'partial',
128
+ message,
129
+ hint: 'Fix what the backend said about the rows in details.tables, then call again with only those rows: the deleted rows are gone.',
130
+ });
131
+ }
132
+ return { content: [{ type: 'text', text: message }], details: { success: true, message, ...details } };
133
+ }
134
+ /** Why the approved rows cannot go while the person keeps the table that `effect` reaches, and what to do instead. */
135
+ function keptReached(effect) {
136
+ const { parent, child } = effect;
137
+ const what = effect.effect === 'cascade'
138
+ ? `deleting ${parent} deletes them too`
139
+ : effect.effect === 'set_null'
140
+ ? `deleting ${parent} clears ${(0, harness_1.listed)(effect.columns)} on them`
141
+ : effect.effect === 'set_default'
142
+ ? `deleting ${parent} sets ${(0, harness_1.listed)(effect.columns)} to ${effect.columns.length === 1 ? 'its default' : 'their defaults'} on them`
143
+ : `${parent} rows can't be deleted while they're there`;
144
+ return `You kept ${child}, but ${(0, delete_effects_1.rowsOf)(effect)} ${(0, delete_effects_1.pointOf)(effect)} at ${parent} you'd delete, and ${what}. Approve again with ${child} ticked, or keep ${parent} too.`;
145
+ }
146
+ /** Why the check could not rule out that the approved rows reach `table`, which the person kept, and what to do. */
147
+ function keptNotChecked(effect, table) {
148
+ if (effect.upTo)
149
+ return `Nothing was deleted: there are too many related rows to check that ${table} stays untouched. Delete in smaller steps, or tick ${table}.`;
150
+ const why = effect.uncounted
151
+ ? `the ${effect.child} rows that point at ${effect.parent} can't be counted`
152
+ : `the rows that point at the ${effect.child} rows it deletes can't be followed`;
153
+ return `Nothing was deleted: ${why}, so it can't check that ${table} stays untouched. Tick ${table}, or keep ${effect.parent} too.`;
154
+ }
155
+ exports.deleteRecordsTool = {
156
+ name: 'delete_records',
157
+ label: 'Delete records',
158
+ description: "Delete rows from one or more tables in the project's app database: rows named by primary key, the rows whose columns have given values, the sample rows seeded when the app was built, or every row. One call for every table: the person sees the exact rows first and can keep any table.",
159
+ promptSnippet: 'delete_records: delete rows from one or many tables, by key, by column values, the sample rows, or all rows. Gated.',
160
+ parameters: DeleteRecordsZod,
161
+ effect: 'write',
162
+ async execute(params, ctx) {
163
+ const approved = ctx.toolCallId ? (0, harness_1.takeApprovedTable)(ctx.toolCallId, ctx.cwd) : undefined;
164
+ const fail = (failure) => (0, rows_1.recordsFailed)(failure, { deletedCount: 0, tables: [] });
165
+ if (!approved?.rows) {
166
+ // The same checks as the gate, so a call that cannot run fails the same way; a call that can still deletes
167
+ // nothing, because only an approved target says which rows the person saw and kept.
168
+ const ready = await (0, delete_selection_1.deleteRecordsReady)(params, ctx.cwd);
169
+ if (ready.kind === 'failed')
170
+ return fail(ready.failure);
171
+ return fail({
172
+ code: 'failed',
173
+ message: 'This delete has no approval (it may have expired), so nothing was deleted. Ask again to see the rows and approve them.',
174
+ });
175
+ }
176
+ const ready = await (0, rows_1.appReady)(ctx.cwd, 'deleted');
177
+ if (ready.kind === 'failed')
178
+ return fail(ready.failure);
179
+ if (!sameTarget(approved, (0, ready_1.databaseTarget)(ready.value.context, ready.value.userId))) {
180
+ return fail({
181
+ code: 'failed',
182
+ message: 'The current project or app sign-in does not match the approved delete target, so nothing was deleted.',
183
+ hint: 'Review the rows and approve a new request.',
184
+ });
185
+ }
186
+ const planned = plannedRows(ready.value.tables, approved.rows);
187
+ if (planned.kind === 'failed')
188
+ return fail(planned.failure);
189
+ // A table of the input that the approved rows leave out was unticked, or had no rows when the card was built.
190
+ const approvedTables = new Set(planned.value.map((entry) => entry.table));
191
+ const kept = params.tables
192
+ .map((input) => (0, meta_1.findMetaTable)(ready.value.tables, input.table_name))
193
+ .filter((table) => Boolean(table) && !approvedTables.has(table))
194
+ .map(delete_effects_1.sqlName);
195
+ if (kept.length > 0) {
196
+ const found = await (0, delete_effects_1.deleteEffects)(ready.value, approved.rows);
197
+ if (found.kind === 'failed')
198
+ return fail(found.failure);
199
+ const { effects, model } = found.value;
200
+ const reached = effects.find((effect) => !effect.uncounted && kept.includes(effect.child));
201
+ if (reached)
202
+ return fail({ code: 'conflict', message: keptReached(reached) });
203
+ // An effect the check could not count or follow may still reach a kept table, so it counts as reaching it.
204
+ for (const effect of effects) {
205
+ const table = (0, delete_effects_1.tablesNotChecked)(effect, model).find((name) => kept.includes(name));
206
+ if (table)
207
+ return fail({ code: 'conflict', message: keptNotChecked(effect, table) });
208
+ }
209
+ }
210
+ return deleteRows(ready.value, planned.value, kept);
211
+ },
212
+ };
package/tools/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyHarnessTool, PlanTableAccess, PlanTarget } from '@agentic-kit/harness';
1
+ import type { AnyHarnessTool, ConfirmPreview, PlanTableAccess, PlanTarget } from '@agentic-kit/harness';
2
2
  import type { Result } from '../failure';
3
3
  /**
4
4
  * The Constructive database tools, in registration order.
@@ -8,11 +8,15 @@ import type { Result } from '../failure';
8
8
  * dependency (see `toPiTool` in `@agentic-kit/pi` for that binding).
9
9
  */
10
10
  export declare const constructiveDbTools: readonly AnyHarnessTool[];
11
- /** What a plan names that the tool's check resolved: its target, the access of the tables it creates or changes, and what it must say that the input does not. */
11
+ /**
12
+ * What a plan names that the tool's check resolved: its target, the access of the tables it creates or changes, what
13
+ * it must say that the input does not, and the card's preview when only the check can build it.
14
+ */
12
15
  export type Resolved = {
13
16
  target: PlanTarget;
14
17
  access?: PlanTableAccess[];
15
18
  notes?: string[];
19
+ preview?: ConfirmPreview;
16
20
  };
17
21
  type Precondition = (params: any, cwd: string) => Promise<Result<Resolved>>;
18
22
  /**
package/tools/index.js CHANGED
@@ -5,6 +5,7 @@ const access_1 = require("../access");
5
5
  const field_type_1 = require("../blueprint/field-type");
6
6
  const provision_1 = require("../provision-database/provision");
7
7
  const ready_1 = require("../ready");
8
+ const delete_selection_1 = require("../records/delete-selection");
8
9
  const schema_resolve_1 = require("../schema-resolve");
9
10
  const table_access_1 = require("../table-access");
10
11
  const access_2 = require("./access");
@@ -12,6 +13,7 @@ const add_policies_1 = require("./add-policies");
12
13
  const add_records_1 = require("./add-records");
13
14
  const add_relation_1 = require("./add-relation");
14
15
  const create_api_key_1 = require("./create-api-key");
16
+ const delete_records_1 = require("./delete-records");
15
17
  const describe_schema_1 = require("./describe-schema");
16
18
  const entity_types_1 = require("./entity-types");
17
19
  const mutations_1 = require("./mutations");
@@ -19,6 +21,7 @@ const provision_blueprint_1 = require("./provision-blueprint");
19
21
  const provision_database_1 = require("./provision-database");
20
22
  const run_codegen_1 = require("./run-codegen");
21
23
  const templates_1 = require("./templates");
24
+ const update_records_1 = require("./update-records");
22
25
  /**
23
26
  * The Constructive database tools, in registration order.
24
27
  *
@@ -44,6 +47,8 @@ exports.constructiveDbTools = [
44
47
  templates_1.updateTemplateTool,
45
48
  templates_1.deleteTemplateTool,
46
49
  add_records_1.addRecordsTool,
50
+ update_records_1.updateRecordsTool,
51
+ delete_records_1.deleteRecordsTool,
47
52
  entity_types_1.listEntityTypesTool,
48
53
  entity_types_1.createEntityTypeTool,
49
54
  entity_types_1.deleteEntityTypeTool,
@@ -135,6 +140,14 @@ exports.toolPreconditions = new Map([
135
140
  [templates_1.updateTemplateTool.name, targeting(templates_1.templateReady, ({ context }) => (0, ready_1.accountTarget)(context))],
136
141
  [templates_1.deleteTemplateTool.name, targeting(templates_1.templateReady, ({ context }) => (0, ready_1.accountTarget)(context))],
137
142
  [add_records_1.addRecordsTool.name, targeting(add_records_1.addRecordsReady, ({ context, userId }) => (0, ready_1.databaseTarget)(context, userId))],
143
+ [update_records_1.updateRecordsTool.name, targeting(update_records_1.updateRecordsReady, ({ context, userId }) => (0, ready_1.databaseTarget)(context, userId))],
144
+ [
145
+ delete_records_1.deleteRecordsTool.name,
146
+ async (params, cwd) => {
147
+ const ready = await (0, delete_selection_1.deleteRecordsReady)(params, cwd);
148
+ return ready.kind === 'failed' ? ready : { kind: 'ok', value: (0, delete_records_1.deleteRecordsPlan)(ready.value) };
149
+ },
150
+ ],
138
151
  [entity_types_1.listEntityTypesTool.name, onDatabase(project)],
139
152
  [entity_types_1.createEntityTypeTool.name, onDatabase(entity_types_1.createEntityTypeReady)],
140
153
  [entity_types_1.deleteEntityTypeTool.name, onDatabase(entity_types_1.deleteEntityTypeReady)],
@@ -0,0 +1,16 @@
1
+ import { type HarnessTool } from '@agentic-kit/harness';
2
+ import { z } from 'zod';
3
+ import type { Result } from '../failure';
4
+ import { type RawField } from '../records/meta';
5
+ import { type RecordsDetails, type RecordsReady } from '../records/rows';
6
+ declare const UpdateRecordsZod: z.ZodObject<{
7
+ table_name: z.ZodString;
8
+ records: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
9
+ }, z.core.$strict>;
10
+ type UpdateRecordsParams = z.infer<typeof UpdateRecordsZod>;
11
+ /** What update_records checks before it changes anything: the table on the app's API, its key, and for every record the row it names and the columns it sets. */
12
+ export declare function updateRecordsReady(params: UpdateRecordsParams, cwd: string): Promise<Result<RecordsReady & {
13
+ primaryKey: RawField;
14
+ }>>;
15
+ export declare const updateRecordsTool: HarnessTool<typeof UpdateRecordsZod, RecordsDetails>;
16
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateRecordsTool = void 0;
4
+ exports.updateRecordsReady = updateRecordsReady;
5
+ const harness_1 = require("@agentic-kit/harness");
6
+ const generators_1 = require("@constructive-io/graphql-query/generators");
7
+ const zod_1 = require("zod");
8
+ const meta_1 = require("../records/meta");
9
+ const rows_1 = require("../records/rows");
10
+ const UpdateRecordsZod = (0, harness_1.strictObject)('the input', {
11
+ table_name: (0, harness_1.identifierParam)()
12
+ .describe('Name of the table whose rows to change (snake_case, singular or plural).'),
13
+ records: zod_1.z
14
+ .array(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()))
15
+ .describe('One object per row. Its primary key column (usually "id") names the row: its id, or "@<table>[<index>]" for a sample row seeded when the app was built. The other keys are the columns to set, by column name (snake_case); a value may also be "@<table>[<index>]".'),
16
+ });
17
+ /** What update_records checks before it changes anything: the table on the app's API, its key, and for every record the row it names and the columns it sets. */
18
+ async function updateRecordsReady(params, cwd) {
19
+ const ready = await (0, rows_1.recordsReady)('update', params, cwd);
20
+ if (ready.kind === 'failed')
21
+ return ready;
22
+ const { table, records } = ready.value;
23
+ const primaryKey = (0, rows_1.primaryKeyOf)(table);
24
+ if (!primaryKey) {
25
+ return { kind: 'failed', failure: { code: 'unsupported', message: `${params.table_name} has no single-column primary key, so its rows can't be named.` } };
26
+ }
27
+ if (!table.query?.update) {
28
+ return { kind: 'failed', failure: { code: 'unsupported', message: `The app API can't update ${params.table_name} rows.` } };
29
+ }
30
+ const fields = new Map((0, rows_1.fieldsOf)(table).map((field) => [field.name, field]));
31
+ const keyColumn = (0, rows_1.columnOf)(primaryKey);
32
+ for (const [index, { [primaryKey.name]: key, ...patch }] of records.entries()) {
33
+ if (key == null)
34
+ return (0, rows_1.invalid)(`Row ${index} names no row: give its "${keyColumn}".`);
35
+ const kept = Object.keys(patch).find((name) => fields.get(name)?.isWritableOnUpdate === false);
36
+ if (kept)
37
+ return (0, rows_1.invalid)(`Row ${index} sets "${(0, rows_1.columnOf)(fields.get(kept))}", which the app API does not let anyone change.`);
38
+ if (Object.keys(patch).length === 0)
39
+ return (0, rows_1.invalid)(`Row ${index} sets no column besides "${keyColumn}".`);
40
+ }
41
+ return { kind: 'ok', value: { ...ready.value, primaryKey } };
42
+ }
43
+ exports.updateRecordsTool = {
44
+ name: 'update_records',
45
+ label: 'Update records',
46
+ description: "Set columns on rows that are already in the project's app database, each row named by its primary key. Use it to link rows, for example a key column of a row add_records made to a sample row seeded when the app was built.",
47
+ promptSnippet: 'update_records: set columns on existing rows by primary key, such as linking rows. Gated.',
48
+ parameters: UpdateRecordsZod,
49
+ effect: 'write',
50
+ async execute(params, ctx) {
51
+ const ready = await updateRecordsReady(params, ctx.cwd);
52
+ if (ready.kind === 'failed')
53
+ return (0, rows_1.recordsFailed)(ready.failure);
54
+ const { tables, records, primaryKey } = ready.value;
55
+ const table = (0, meta_1.cleanTable)(ready.value.table);
56
+ const patchField = (0, generators_1.toPatchFieldName)(table.name, table);
57
+ const inputs = records.map(({ [primaryKey.name]: key, ...patch }) => ({ [primaryKey.name]: key, [patchField]: patch }));
58
+ const mutation = (0, generators_1.buildPostGraphileUpdate)(table, tables.map(meta_1.cleanTable)).toString();
59
+ return (0, rows_1.writeRecords)('update', params.table_name, ready.value, mutation, (0, generators_1.toUpdateMutationName)(table.name, table), inputs);
60
+ },
61
+ };