@agentic-kit/db-tools 0.12.46 → 0.13.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 (180) hide show
  1. package/README.md +18 -4
  2. package/access/findings.d.ts +93 -0
  3. package/access/findings.js +434 -0
  4. package/access/index.d.ts +5 -0
  5. package/access/index.js +27 -0
  6. package/access/policies.d.ts +142 -0
  7. package/access/policies.js +338 -0
  8. package/access/provisioning.d.ts +121 -0
  9. package/access/provisioning.js +381 -0
  10. package/access/rule-check.d.ts +52 -0
  11. package/access/rule-check.js +307 -0
  12. package/access/words.d.ts +38 -0
  13. package/access/words.js +530 -0
  14. package/app-workspace.d.ts +1 -0
  15. package/app-workspace.js +7 -9
  16. package/blueprint/blueprint-defaults.d.ts +9 -0
  17. package/blueprint/blueprint-defaults.js +77 -0
  18. package/blueprint/blueprint-schema.d.ts +68 -0
  19. package/blueprint/blueprint-schema.js +139 -0
  20. package/blueprint/field-type.d.ts +4 -0
  21. package/blueprint/field-type.js +100 -0
  22. package/blueprint/internal-policies.d.ts +1 -0
  23. package/blueprint/internal-policies.js +10 -0
  24. package/blueprint-construction.d.ts +10 -6
  25. package/blueprint-construction.js +34 -25
  26. package/context.d.ts +15 -0
  27. package/context.js +132 -69
  28. package/db-probe.d.ts +1 -1
  29. package/db-probe.js +19 -4
  30. package/esm/access/findings.d.ts +93 -0
  31. package/esm/access/findings.js +428 -0
  32. package/esm/access/index.d.ts +5 -0
  33. package/esm/access/index.js +5 -0
  34. package/esm/access/policies.d.ts +142 -0
  35. package/esm/access/policies.js +315 -0
  36. package/esm/access/provisioning.d.ts +121 -0
  37. package/esm/access/provisioning.js +375 -0
  38. package/esm/access/rule-check.d.ts +52 -0
  39. package/esm/access/rule-check.js +297 -0
  40. package/esm/access/words.d.ts +38 -0
  41. package/esm/access/words.js +524 -0
  42. package/esm/app-workspace.d.ts +1 -0
  43. package/esm/app-workspace.js +7 -10
  44. package/esm/blueprint/blueprint-defaults.d.ts +9 -0
  45. package/esm/blueprint/blueprint-defaults.js +74 -0
  46. package/esm/blueprint/blueprint-schema.d.ts +68 -0
  47. package/esm/blueprint/blueprint-schema.js +134 -0
  48. package/esm/blueprint/field-type.d.ts +4 -0
  49. package/esm/blueprint/field-type.js +95 -0
  50. package/esm/blueprint/internal-policies.d.ts +1 -0
  51. package/esm/blueprint/internal-policies.js +7 -0
  52. package/esm/blueprint-construction.d.ts +10 -6
  53. package/esm/blueprint-construction.js +32 -24
  54. package/esm/context.d.ts +15 -0
  55. package/esm/context.js +133 -70
  56. package/esm/db-probe.d.ts +1 -1
  57. package/esm/db-probe.js +21 -6
  58. package/esm/failure.d.ts +89 -0
  59. package/esm/failure.js +362 -0
  60. package/esm/gate.d.ts +6 -4
  61. package/esm/gate.js +42 -14
  62. package/esm/graphql-http.d.ts +27 -6
  63. package/esm/graphql-http.js +96 -24
  64. package/esm/host.d.ts +33 -8
  65. package/esm/host.js +42 -2
  66. package/esm/index.d.ts +22 -12
  67. package/esm/index.js +21 -39
  68. package/esm/provision-database/env-file.d.ts +7 -0
  69. package/esm/provision-database/env-file.js +30 -0
  70. package/esm/provision-database/preset-match.js +1 -2
  71. package/esm/provision-database/provision.d.ts +21 -4
  72. package/esm/provision-database/provision.js +330 -85
  73. package/esm/provision-database/request-database.d.ts +22 -3
  74. package/esm/provision-database/request-database.js +46 -13
  75. package/esm/ready.d.ts +20 -0
  76. package/esm/ready.js +45 -0
  77. package/esm/run-codegen/barrels.js +1 -1
  78. package/esm/run-codegen/endpoints.js +5 -6
  79. package/esm/schema-model/normalize.js +1 -1
  80. package/esm/schema-model.js +4 -5
  81. package/esm/schema-resolve.d.ts +50 -0
  82. package/esm/schema-resolve.js +200 -14
  83. package/esm/table-access.d.ts +116 -0
  84. package/esm/table-access.js +418 -0
  85. package/esm/tools/access.d.ts +218 -0
  86. package/esm/tools/access.js +651 -0
  87. package/esm/tools/add-policies.d.ts +44 -12
  88. package/esm/tools/add-policies.js +84 -84
  89. package/esm/tools/add-records.d.ts +23 -2
  90. package/esm/tools/add-records.js +113 -75
  91. package/esm/tools/add-relation-schema.d.ts +5 -5
  92. package/esm/tools/add-relation-schema.js +13 -14
  93. package/esm/tools/add-relation.d.ts +11 -2
  94. package/esm/tools/add-relation.js +68 -31
  95. package/esm/tools/create-api-key.d.ts +18 -4
  96. package/esm/tools/create-api-key.js +105 -54
  97. package/esm/tools/describe-schema.d.ts +5 -7
  98. package/esm/tools/describe-schema.js +41 -118
  99. package/esm/tools/entity-types.d.ts +54 -0
  100. package/esm/tools/entity-types.js +233 -0
  101. package/esm/tools/index.d.ts +26 -0
  102. package/esm/tools/index.js +151 -0
  103. package/esm/tools/mutations.d.ts +36 -7
  104. package/esm/tools/mutations.js +245 -99
  105. package/esm/tools/provision-blueprint.d.ts +25 -1
  106. package/esm/tools/provision-blueprint.js +184 -42
  107. package/esm/tools/provision-database.d.ts +7 -5
  108. package/esm/tools/provision-database.js +31 -17
  109. package/esm/tools/run-codegen.d.ts +27 -4
  110. package/esm/tools/run-codegen.js +143 -76
  111. package/esm/tools/templates.d.ts +30 -7
  112. package/esm/tools/templates.js +166 -95
  113. package/failure.d.ts +89 -0
  114. package/failure.js +375 -0
  115. package/gate.d.ts +6 -4
  116. package/gate.js +41 -13
  117. package/graphql-http.d.ts +27 -6
  118. package/graphql-http.js +105 -25
  119. package/host.d.ts +33 -8
  120. package/host.js +45 -2
  121. package/index.d.ts +22 -12
  122. package/index.js +86 -43
  123. package/package.json +6 -5
  124. package/provision-database/env-file.d.ts +7 -0
  125. package/provision-database/env-file.js +32 -1
  126. package/provision-database/preset-match.js +1 -2
  127. package/provision-database/provision.d.ts +21 -4
  128. package/provision-database/provision.js +327 -81
  129. package/provision-database/request-database.d.ts +22 -3
  130. package/provision-database/request-database.js +49 -14
  131. package/ready.d.ts +20 -0
  132. package/ready.js +52 -0
  133. package/run-codegen/barrels.js +1 -1
  134. package/run-codegen/endpoints.js +5 -6
  135. package/schema-model/normalize.js +4 -4
  136. package/schema-model.js +4 -5
  137. package/schema-resolve.d.ts +50 -0
  138. package/schema-resolve.js +209 -14
  139. package/table-access.d.ts +116 -0
  140. package/table-access.js +437 -0
  141. package/tools/access.d.ts +218 -0
  142. package/tools/access.js +669 -0
  143. package/tools/add-policies.d.ts +44 -12
  144. package/tools/add-policies.js +86 -84
  145. package/tools/add-records.d.ts +23 -2
  146. package/tools/add-records.js +113 -74
  147. package/tools/add-relation-schema.d.ts +5 -5
  148. package/tools/add-relation-schema.js +13 -14
  149. package/tools/add-relation.d.ts +11 -2
  150. package/tools/add-relation.js +69 -31
  151. package/tools/create-api-key.d.ts +18 -4
  152. package/tools/create-api-key.js +104 -53
  153. package/tools/describe-schema.d.ts +5 -7
  154. package/tools/describe-schema.js +40 -117
  155. package/tools/entity-types.d.ts +54 -0
  156. package/tools/entity-types.js +240 -0
  157. package/tools/index.d.ts +26 -0
  158. package/tools/index.js +154 -0
  159. package/tools/mutations.d.ts +36 -7
  160. package/tools/mutations.js +252 -101
  161. package/tools/provision-blueprint.d.ts +25 -1
  162. package/tools/provision-blueprint.js +186 -43
  163. package/tools/provision-database.d.ts +7 -5
  164. package/tools/provision-database.js +33 -18
  165. package/tools/run-codegen.d.ts +27 -4
  166. package/tools/run-codegen.js +141 -73
  167. package/tools/templates.d.ts +30 -7
  168. package/tools/templates.js +167 -94
  169. package/esm/policy/add-policies-to-table.d.ts +0 -26
  170. package/esm/policy/add-policies-to-table.js +0 -66
  171. package/esm/policy/provision-helpers.d.ts +0 -38
  172. package/esm/policy/provision-helpers.js +0 -50
  173. package/esm/tools/manage-entity-types.d.ts +0 -40
  174. package/esm/tools/manage-entity-types.js +0 -201
  175. package/policy/add-policies-to-table.d.ts +0 -26
  176. package/policy/add-policies-to-table.js +0 -71
  177. package/policy/provision-helpers.d.ts +0 -38
  178. package/policy/provision-helpers.js +0 -58
  179. package/tools/manage-entity-types.d.ts +0 -40
  180. package/tools/manage-entity-types.js +0 -206
@@ -0,0 +1,218 @@
1
+ import { type HarnessTool, type PlanRule, type ToolCallSuggestion, type ToolFailure } from '@agentic-kit/harness';
2
+ import { type BlueprintNode, type BlueprintPolicy } from 'node-type-registry';
3
+ import { z } from 'zod';
4
+ import { type AccessFinding, type MembershipScope, type ResolvedPolicy, type TableAccessInput, type TablePolicy } from '../access';
5
+ import type { RuleContext } from '../access/rule-check';
6
+ import { type RelatedColumns } from '../access/words';
7
+ import { type AccessPolicy } from '../blueprint/blueprint-schema';
8
+ import type { ProjectContext } from '../context';
9
+ import { type FailureMeaning, type Result } from '../failure';
10
+ import { type ColumnChange, type Rule, type TableRecord, type WrittenRule } from '../table-access';
11
+ declare const DescribePolicyTypeZod: z.ZodObject<{
12
+ type: z.ZodOptional<z.ZodEnum<{
13
+ [x: string]: string;
14
+ }>>;
15
+ }, z.core.$strict>;
16
+ type PolicyTypeSummary = {
17
+ name: string;
18
+ summary?: string;
19
+ tableKind?: string;
20
+ };
21
+ type PolicyTypeDetail = PolicyTypeSummary & {
22
+ parameterSchema: unknown;
23
+ useWhen: string[];
24
+ avoidWhen: string[];
25
+ risks: string[];
26
+ dataNode?: unknown;
27
+ };
28
+ export declare const describePolicyTypeTool: HarnessTool<typeof DescribePolicyTypeZod, {
29
+ types?: PolicyTypeSummary[];
30
+ type?: PolicyTypeDetail;
31
+ }>;
32
+ declare const ExplainAccessZod: z.ZodObject<{
33
+ table_name: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strict>;
35
+ /** One stored rule: in the shape a caller writes it, with its words. */
36
+ export type ExplainedRule = WrittenRule & Pick<PlanRule, 'words'>;
37
+ /** The access of one live table: each rule in words, the grants, row security, and what may be wrong. */
38
+ export type ExplainedTable = {
39
+ name: string;
40
+ rules: ExplainedRule[];
41
+ grants: string[];
42
+ rowSecurity: boolean;
43
+ findings: AccessFinding[];
44
+ };
45
+ export declare const explainAccessTool: HarnessTool<typeof ExplainAccessZod, {
46
+ tables: ExplainedTable[];
47
+ }>;
48
+ declare const SetAccessZod: z.ZodObject<{
49
+ table_name: z.ZodString;
50
+ policies: z.ZodArray<z.ZodObject<{
51
+ $type: z.ZodString;
52
+ privileges: z.ZodOptional<z.ZodArray<z.ZodString>>;
53
+ permissive: z.ZodOptional<z.ZodBoolean>;
54
+ policy_role: z.ZodOptional<z.ZodString>;
55
+ policy_name: z.ZodOptional<z.ZodString>;
56
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
57
+ }, z.core.$loose>>;
58
+ }, z.core.$strict>;
59
+ type SetAccessParams = z.infer<typeof SetAccessZod>;
60
+ /** What one change of a table's access installs; `owns` names what it replaces instead of adding to. */
61
+ export type Provision = {
62
+ nodes: BlueprintNode[];
63
+ policies: BlueprintPolicy[];
64
+ grants?: unknown;
65
+ owns?: Array<'policies' | 'grants'>;
66
+ };
67
+ /**
68
+ * What a change does to the columns of an existing table, refused before
69
+ * anything changes when the backend cannot apply it: a rule reads a column
70
+ * nothing gives the table, or a required column would be added to a table
71
+ * whose rows this tool can see.
72
+ */
73
+ export declare function existingTableChange(context: ProjectContext, table: TableRecord, nodes: BlueprintNode[], rules: readonly Rule[]): Promise<Result<ColumnChange>>;
74
+ /** Installs `provision` on the table in one request: the backend applies it in one transaction. */
75
+ export declare function applyProvision(context: ProjectContext, table: {
76
+ id: string;
77
+ name: string;
78
+ }, provision: Provision, action: string, meaning: FailureMeaning): Promise<ToolFailure | null>;
79
+ /** What the table holds after a change that is not what its plan said, by meaning. */
80
+ export type AccessDifference = {
81
+ unplanned: TablePolicy[];
82
+ missing: TablePolicy[];
83
+ grants?: {
84
+ unplanned: string[];
85
+ missing: string[];
86
+ };
87
+ rowSecurityOff?: true;
88
+ columnsMissing?: string[];
89
+ };
90
+ /** The table after a change: as its plan said, different, or not readable. */
91
+ export type ReadBack = {
92
+ kind: 'same';
93
+ table: TableRecord;
94
+ } | {
95
+ kind: 'different' | 'unverified';
96
+ failure: ToolFailure;
97
+ };
98
+ /**
99
+ * Reads the access of a table again after a change returned, and compares it
100
+ * by meaning with the after state of the plan: `policyDifference` decides for
101
+ * the rules (order, duplicates, defaults, derived keys and the backend's own
102
+ * copy of the read-only block do not count), then the grants, row security
103
+ * and the columns the change added. A change made at the same moment by
104
+ * another call is what this finds: the backend's replace does not wait for
105
+ * one. `again` is the call that makes the table as the plan said, when there
106
+ * is one.
107
+ */
108
+ export declare function readBack(context: ProjectContext, table: string, planned: PlannedAccess, added: string[], again?: ToolCallSuggestion): Promise<ReadBack>;
109
+ /** A table's access after a change, as its plan says: its rules in the form the backend stores them. */
110
+ export type PlannedAccess = Omit<TableAccessInput, 'policies'> & {
111
+ policies: ResolvedPolicy[];
112
+ };
113
+ export type SetAccessReady = {
114
+ context: ProjectContext;
115
+ table: TableRecord;
116
+ provision: Provision;
117
+ after: PlannedAccess;
118
+ notes: string[];
119
+ /** The columns the change adds. */
120
+ columns: ColumnChange;
121
+ /** What a refusal of the change means. */
122
+ meaning: FailureMeaning;
123
+ };
124
+ /**
125
+ * The rule the backend adds by itself beside the first team-membership rule of a change that grants writes: a
126
+ * restrictive `AuthzNotReadOnly` for those writes. A plan's after state holds it, so the plan and the read-back after
127
+ * the change both count it.
128
+ */
129
+ export declare function addedByBackend(policies: readonly BlueprintPolicy[], grants: TableAccessInput['grants'] | undefined): TablePolicy[];
130
+ /** What a plan says about the read-only limit beside a team rule: the backend adds it only for a change that grants writes. */
131
+ export declare function readOnlyNotes(policies: readonly BlueprintPolicy[], grants: TableAccessInput['grants'] | undefined): string[];
132
+ /** The roles a rule can name: the request roles every API has, and the roles the database's APIs run as, read only when a rule names another. */
133
+ export declare function rolesFor(context: ProjectContext, policies: ReadonlyArray<{
134
+ policy_role?: string;
135
+ }>): Promise<Result<string[] | undefined>>;
136
+ /**
137
+ * The problems of the rules a caller wrote, as one failure: each rule's shape against the registry's `BlueprintPolicy`
138
+ * (`with_check` only where `withCheck` allows it), and its data against its policy type with the rule's context; each
139
+ * problem with its rule, and the calls that describe the nodes it is in.
140
+ */
141
+ export declare function ruleProblems(policies: ReadonlyArray<{
142
+ $type: string;
143
+ data?: unknown;
144
+ policy_role?: string;
145
+ }>, context: Omit<RuleContext, 'role'> & {
146
+ withCheck?: boolean;
147
+ }, label: (index: number) => string): ToolFailure | null;
148
+ /**
149
+ * The columns of the database's application tables, by id and by name, read only when a rule needs another table's
150
+ * columns; `tables` are tables already read.
151
+ */
152
+ export declare function relatedColumns(context: ProjectContext, policies: ReadonlyArray<{
153
+ type?: string;
154
+ $type?: string;
155
+ data?: unknown;
156
+ }>, tables?: TableRecord[]): Promise<Result<RelatedColumns | undefined>>;
157
+ /**
158
+ * The rules a change sends, as the backend creates them, or the failure that names the first rule the backend would
159
+ * skip or refuse. Rules of one policy type, role, kind and data become one rule with all their privileges (in lower
160
+ * case). Beside an earlier rule or one the table keeps (`table`, for an add), a rule is refused when the backend keeps
161
+ * only one of its type and data, or when it names a policy row the same way: the role's first four letters, the
162
+ * privilege's first three, and the rule's name. Every tool that sends rules sends them through this.
163
+ */
164
+ export declare function rulesToSend(given: readonly BlueprintPolicy[], { table, defaultRole, label }: {
165
+ table?: TableRecord;
166
+ defaultRole: string;
167
+ label: (index: number) => string;
168
+ }): Result<BlueprintPolicy[]>;
169
+ /** The rules a change sends, as the backend will store them, the team kinds their entity_type names, and the columns of other tables they read. */
170
+ export type StoredRules = {
171
+ policies: BlueprintPolicy[];
172
+ scopes: MembershipScope[];
173
+ related?: RelatedColumns;
174
+ };
175
+ /**
176
+ * The rules a change sends, checked before the plan: each rule's shape and data, with the role it names and the
177
+ * columns of the other tables it reads; every `entity_type` becomes the team kind the backend stores; and the rules
178
+ * go through `rulesToSend`, beside the rules the table keeps (`table`, for an add). `live` is the table the plan shows
179
+ * now, whose rules may read other tables too.
180
+ */
181
+ export declare function storedRules(context: ProjectContext, given: AccessPolicy[], { table, grants, live }: {
182
+ table?: TableRecord;
183
+ grants?: TableAccessInput['grants'];
184
+ live?: TableRecord;
185
+ }): Promise<Result<StoredRules>>;
186
+ /** The access a change leaves: `kept` (the table's rules an add keeps) and `sent`, with the rule the backend adds itself. */
187
+ export declare function plannedPolicies(kept: TablePolicy[], sent: BlueprintPolicy[], grants: TableAccessInput['grants'] | undefined, scopes: MembershipScope[]): ResolvedPolicy[];
188
+ /** The Data nodes the rules need for the columns `table` lacks, or the failure that says which rule names a column its node cannot add. */
189
+ export declare function neededNodes(policies: readonly BlueprintPolicy[], table: TableRecord): Result<BlueprintNode[]>;
190
+ /** The calls that fix a required column no rule sets: make it optional, or drop it. */
191
+ export declare const columnFixes: (table: string, column: string) => ToolCallSuggestion[];
192
+ /**
193
+ * What set_access checks before it changes anything: a list of rules, the
194
+ * table, and the columns the rules need. It resolves the replacement and the
195
+ * access the table will have.
196
+ */
197
+ export declare function setAccessReady(params: SetAccessParams, cwd: string): Promise<Result<SetAccessReady>>;
198
+ /** The plan's access for set_access: the live table now, and after the replace, with the columns it adds. */
199
+ export declare const setAccessPlan: ({ table, after, notes, columns }: SetAccessReady) => {
200
+ notes?: string[];
201
+ columnsAdded?: import("@agentic-kit/harness").PlanColumn[];
202
+ columnsReused?: import("@agentic-kit/harness").PlanColumn[];
203
+ failsIfRows?: string[];
204
+ table: string;
205
+ schema?: string;
206
+ before?: import("@agentic-kit/harness").PlanAccessState;
207
+ after: import("@agentic-kit/harness").PlanAccessState;
208
+ findingsAdded: import("@agentic-kit/harness").PlanFinding[];
209
+ findingsRemoved: import("@agentic-kit/harness").PlanFinding[];
210
+ }[];
211
+ type SetAccessDetails = {
212
+ success: boolean;
213
+ message: string;
214
+ table?: string;
215
+ access?: ExplainedTable;
216
+ };
217
+ export declare const setAccessTool: HarnessTool<typeof SetAccessZod, SetAccessDetails>;
218
+ export {};