@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.
- package/README.md +18 -4
- package/access/findings.d.ts +93 -0
- package/access/findings.js +434 -0
- package/access/index.d.ts +5 -0
- package/access/index.js +27 -0
- package/access/policies.d.ts +142 -0
- package/access/policies.js +338 -0
- package/access/provisioning.d.ts +121 -0
- package/access/provisioning.js +381 -0
- package/access/rule-check.d.ts +52 -0
- package/access/rule-check.js +307 -0
- package/access/words.d.ts +38 -0
- package/access/words.js +530 -0
- package/app-workspace.d.ts +1 -0
- package/app-workspace.js +7 -9
- package/blueprint/blueprint-defaults.d.ts +9 -0
- package/blueprint/blueprint-defaults.js +77 -0
- package/blueprint/blueprint-schema.d.ts +68 -0
- package/blueprint/blueprint-schema.js +139 -0
- package/blueprint/field-type.d.ts +4 -0
- package/blueprint/field-type.js +100 -0
- package/blueprint/internal-policies.d.ts +1 -0
- package/blueprint/internal-policies.js +10 -0
- package/blueprint-construction.d.ts +10 -6
- package/blueprint-construction.js +34 -25
- package/context.d.ts +15 -0
- package/context.js +132 -69
- package/db-probe.d.ts +1 -1
- package/db-probe.js +19 -4
- package/esm/access/findings.d.ts +93 -0
- package/esm/access/findings.js +428 -0
- package/esm/access/index.d.ts +5 -0
- package/esm/access/index.js +5 -0
- package/esm/access/policies.d.ts +142 -0
- package/esm/access/policies.js +315 -0
- package/esm/access/provisioning.d.ts +121 -0
- package/esm/access/provisioning.js +375 -0
- package/esm/access/rule-check.d.ts +52 -0
- package/esm/access/rule-check.js +297 -0
- package/esm/access/words.d.ts +38 -0
- package/esm/access/words.js +524 -0
- package/esm/app-workspace.d.ts +1 -0
- package/esm/app-workspace.js +7 -10
- package/esm/blueprint/blueprint-defaults.d.ts +9 -0
- package/esm/blueprint/blueprint-defaults.js +74 -0
- package/esm/blueprint/blueprint-schema.d.ts +68 -0
- package/esm/blueprint/blueprint-schema.js +134 -0
- package/esm/blueprint/field-type.d.ts +4 -0
- package/esm/blueprint/field-type.js +95 -0
- package/esm/blueprint/internal-policies.d.ts +1 -0
- package/esm/blueprint/internal-policies.js +7 -0
- package/esm/blueprint-construction.d.ts +10 -6
- package/esm/blueprint-construction.js +32 -24
- package/esm/context.d.ts +15 -0
- package/esm/context.js +133 -70
- package/esm/db-probe.d.ts +1 -1
- package/esm/db-probe.js +21 -6
- package/esm/failure.d.ts +89 -0
- package/esm/failure.js +362 -0
- package/esm/gate.d.ts +6 -4
- package/esm/gate.js +42 -14
- package/esm/graphql-http.d.ts +27 -6
- package/esm/graphql-http.js +96 -24
- package/esm/host.d.ts +33 -8
- package/esm/host.js +42 -2
- package/esm/index.d.ts +22 -12
- package/esm/index.js +21 -39
- package/esm/provision-database/env-file.d.ts +7 -0
- package/esm/provision-database/env-file.js +30 -0
- package/esm/provision-database/preset-match.js +1 -2
- package/esm/provision-database/provision.d.ts +21 -4
- package/esm/provision-database/provision.js +330 -85
- package/esm/provision-database/request-database.d.ts +22 -3
- package/esm/provision-database/request-database.js +46 -13
- package/esm/ready.d.ts +20 -0
- package/esm/ready.js +45 -0
- package/esm/run-codegen/barrels.js +1 -1
- package/esm/run-codegen/endpoints.js +5 -6
- package/esm/schema-model/normalize.js +1 -1
- package/esm/schema-model.js +4 -5
- package/esm/schema-resolve.d.ts +50 -0
- package/esm/schema-resolve.js +200 -14
- package/esm/table-access.d.ts +116 -0
- package/esm/table-access.js +418 -0
- package/esm/tools/access.d.ts +218 -0
- package/esm/tools/access.js +651 -0
- package/esm/tools/add-policies.d.ts +44 -12
- package/esm/tools/add-policies.js +84 -84
- package/esm/tools/add-records.d.ts +23 -2
- package/esm/tools/add-records.js +113 -75
- package/esm/tools/add-relation-schema.d.ts +5 -5
- package/esm/tools/add-relation-schema.js +13 -14
- package/esm/tools/add-relation.d.ts +11 -2
- package/esm/tools/add-relation.js +68 -31
- package/esm/tools/create-api-key.d.ts +18 -4
- package/esm/tools/create-api-key.js +105 -54
- package/esm/tools/describe-schema.d.ts +5 -7
- package/esm/tools/describe-schema.js +41 -118
- package/esm/tools/entity-types.d.ts +54 -0
- package/esm/tools/entity-types.js +233 -0
- package/esm/tools/index.d.ts +26 -0
- package/esm/tools/index.js +151 -0
- package/esm/tools/mutations.d.ts +36 -7
- package/esm/tools/mutations.js +245 -99
- package/esm/tools/provision-blueprint.d.ts +25 -1
- package/esm/tools/provision-blueprint.js +184 -42
- package/esm/tools/provision-database.d.ts +7 -5
- package/esm/tools/provision-database.js +31 -17
- package/esm/tools/run-codegen.d.ts +27 -4
- package/esm/tools/run-codegen.js +143 -76
- package/esm/tools/templates.d.ts +30 -7
- package/esm/tools/templates.js +166 -95
- package/failure.d.ts +89 -0
- package/failure.js +375 -0
- package/gate.d.ts +6 -4
- package/gate.js +41 -13
- package/graphql-http.d.ts +27 -6
- package/graphql-http.js +105 -25
- package/host.d.ts +33 -8
- package/host.js +45 -2
- package/index.d.ts +22 -12
- package/index.js +86 -43
- package/package.json +6 -5
- package/provision-database/env-file.d.ts +7 -0
- package/provision-database/env-file.js +32 -1
- package/provision-database/preset-match.js +1 -2
- package/provision-database/provision.d.ts +21 -4
- package/provision-database/provision.js +327 -81
- package/provision-database/request-database.d.ts +22 -3
- package/provision-database/request-database.js +49 -14
- package/ready.d.ts +20 -0
- package/ready.js +52 -0
- package/run-codegen/barrels.js +1 -1
- package/run-codegen/endpoints.js +5 -6
- package/schema-model/normalize.js +4 -4
- package/schema-model.js +4 -5
- package/schema-resolve.d.ts +50 -0
- package/schema-resolve.js +209 -14
- package/table-access.d.ts +116 -0
- package/table-access.js +437 -0
- package/tools/access.d.ts +218 -0
- package/tools/access.js +669 -0
- package/tools/add-policies.d.ts +44 -12
- package/tools/add-policies.js +86 -84
- package/tools/add-records.d.ts +23 -2
- package/tools/add-records.js +113 -74
- package/tools/add-relation-schema.d.ts +5 -5
- package/tools/add-relation-schema.js +13 -14
- package/tools/add-relation.d.ts +11 -2
- package/tools/add-relation.js +69 -31
- package/tools/create-api-key.d.ts +18 -4
- package/tools/create-api-key.js +104 -53
- package/tools/describe-schema.d.ts +5 -7
- package/tools/describe-schema.js +40 -117
- package/tools/entity-types.d.ts +54 -0
- package/tools/entity-types.js +240 -0
- package/tools/index.d.ts +26 -0
- package/tools/index.js +154 -0
- package/tools/mutations.d.ts +36 -7
- package/tools/mutations.js +252 -101
- package/tools/provision-blueprint.d.ts +25 -1
- package/tools/provision-blueprint.js +186 -43
- package/tools/provision-database.d.ts +7 -5
- package/tools/provision-database.js +33 -18
- package/tools/run-codegen.d.ts +27 -4
- package/tools/run-codegen.js +141 -73
- package/tools/templates.d.ts +30 -7
- package/tools/templates.js +167 -94
- package/esm/policy/add-policies-to-table.d.ts +0 -26
- package/esm/policy/add-policies-to-table.js +0 -66
- package/esm/policy/provision-helpers.d.ts +0 -38
- package/esm/policy/provision-helpers.js +0 -50
- package/esm/tools/manage-entity-types.d.ts +0 -40
- package/esm/tools/manage-entity-types.js +0 -201
- package/policy/add-policies-to-table.d.ts +0 -26
- package/policy/add-policies-to-table.js +0 -71
- package/policy/provision-helpers.d.ts +0 -38
- package/policy/provision-helpers.js +0 -58
- package/tools/manage-entity-types.d.ts +0 -40
- 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 {};
|