@agentic-kit/db-tools 0.12.47 → 0.13.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 +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
|
@@ -63,10 +63,29 @@ export declare class ProvisionPendingError extends Error {
|
|
|
63
63
|
* see it. Nothing says the provision stopped, so a caller must not request
|
|
64
64
|
* the same database again on this alone.
|
|
65
65
|
*/
|
|
66
|
+
/** A ticket read the backend refused because the sign-in has ended: the provision may still be running. */
|
|
67
|
+
export declare class ProvisionSignedOutError extends Error {
|
|
68
|
+
readonly ticketId: string;
|
|
69
|
+
constructor(message: string, ticketId: string, options?: {
|
|
70
|
+
cause?: unknown;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
66
73
|
export declare class ProvisionTicketLostError extends Error {
|
|
67
74
|
readonly ticketId: string;
|
|
68
75
|
constructor(message: string, ticketId: string);
|
|
69
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* The provision ticket failed. `ticketError` is the text the backend's job
|
|
79
|
+
* stored on the ticket, a column rather than a GraphQL error, so it carries no
|
|
80
|
+
* extensions: a refusal the job raised reads as its code ("[run]
|
|
81
|
+
* BILLING_PLAN_REQUIRED", or "LIMIT_REACHED"), anything else as the job's own
|
|
82
|
+
* text, which is for decisions only. The message names the ticket instead,
|
|
83
|
+
* which the backend operator can look up.
|
|
84
|
+
*/
|
|
85
|
+
export declare class ProvisionJobError extends Error {
|
|
86
|
+
readonly ticketError: string;
|
|
87
|
+
constructor(ticketError: string, step: 'provisioning' | 'owner bootstrap', ticketId: string);
|
|
88
|
+
}
|
|
70
89
|
export declare function createProvisionExecutor(args: {
|
|
71
90
|
apiEndpoint: string;
|
|
72
91
|
modulesEndpoint: string;
|
|
@@ -77,9 +96,9 @@ export declare function isTicketInFlight(ticket: ProvisionTicket): boolean;
|
|
|
77
96
|
/**
|
|
78
97
|
* Whether an error reading or requesting a ticket says only that the backend
|
|
79
98
|
* couldn't be reached or failed: a network error thrown before any response,
|
|
80
|
-
* or an HTTP 5xx
|
|
81
|
-
* (validation, permission, an expired or
|
|
82
|
-
* ticket can't be followed any further.
|
|
99
|
+
* or errors that all carry an HTTP 5xx or 429 (inside the error, or from the
|
|
100
|
+
* adapter). Any other GraphQL error (validation, permission, an expired or
|
|
101
|
+
* rejected token) is an answer, so the ticket can't be followed any further.
|
|
83
102
|
*/
|
|
84
103
|
export declare function isTransientProvisionError(err: unknown): boolean;
|
|
85
104
|
/**
|
|
@@ -10,15 +10,16 @@
|
|
|
10
10
|
// bootstrap completes the new database has zero users, so its per-DB API
|
|
11
11
|
// would reject the owner token under RLS. requestDatabase owns the database
|
|
12
12
|
// to the JWT user — there is no owner input. The generated ORM's default
|
|
13
|
-
// adapter is plain fetch, so the SDK's FetchAdapter is injected to keep
|
|
14
|
-
//
|
|
13
|
+
// adapter is plain fetch, so the SDK's FetchAdapter is injected to keep the
|
|
14
|
+
// routing of per-database subdomains working in Node.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.ProvisionTicketLostError = exports.ProvisionPendingError = exports.MAX_CONSECUTIVE_POLL_FAILURES = exports.POLL_DEADLINE_MS = exports.POLL_INTERVAL_MS = void 0;
|
|
16
|
+
exports.ProvisionJobError = exports.ProvisionTicketLostError = exports.ProvisionSignedOutError = exports.ProvisionPendingError = exports.MAX_CONSECUTIVE_POLL_FAILURES = exports.POLL_DEADLINE_MS = exports.POLL_INTERVAL_MS = void 0;
|
|
17
17
|
exports.createProvisionExecutor = createProvisionExecutor;
|
|
18
18
|
exports.isTicketInFlight = isTicketInFlight;
|
|
19
19
|
exports.isTransientProvisionError = isTransientProvisionError;
|
|
20
20
|
exports.requestDatabaseProvision = requestDatabaseProvision;
|
|
21
21
|
const sdk_1 = require("@constructive-io/sdk");
|
|
22
|
+
const graphql_http_1 = require("../graphql-http");
|
|
22
23
|
exports.POLL_INTERVAL_MS = 2_000;
|
|
23
24
|
/** Stays under airpage's 5-minute per-tool timeout. */
|
|
24
25
|
exports.POLL_DEADLINE_MS = 240_000;
|
|
@@ -48,6 +49,16 @@ exports.ProvisionPendingError = ProvisionPendingError;
|
|
|
48
49
|
* see it. Nothing says the provision stopped, so a caller must not request
|
|
49
50
|
* the same database again on this alone.
|
|
50
51
|
*/
|
|
52
|
+
/** A ticket read the backend refused because the sign-in has ended: the provision may still be running. */
|
|
53
|
+
class ProvisionSignedOutError extends Error {
|
|
54
|
+
ticketId;
|
|
55
|
+
constructor(message, ticketId, options) {
|
|
56
|
+
super(message, options);
|
|
57
|
+
this.ticketId = ticketId;
|
|
58
|
+
this.name = 'ProvisionSignedOutError';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ProvisionSignedOutError = ProvisionSignedOutError;
|
|
51
62
|
class ProvisionTicketLostError extends Error {
|
|
52
63
|
ticketId;
|
|
53
64
|
constructor(message, ticketId) {
|
|
@@ -57,6 +68,23 @@ class ProvisionTicketLostError extends Error {
|
|
|
57
68
|
}
|
|
58
69
|
}
|
|
59
70
|
exports.ProvisionTicketLostError = ProvisionTicketLostError;
|
|
71
|
+
/**
|
|
72
|
+
* The provision ticket failed. `ticketError` is the text the backend's job
|
|
73
|
+
* stored on the ticket, a column rather than a GraphQL error, so it carries no
|
|
74
|
+
* extensions: a refusal the job raised reads as its code ("[run]
|
|
75
|
+
* BILLING_PLAN_REQUIRED", or "LIMIT_REACHED"), anything else as the job's own
|
|
76
|
+
* text, which is for decisions only. The message names the ticket instead,
|
|
77
|
+
* which the backend operator can look up.
|
|
78
|
+
*/
|
|
79
|
+
class ProvisionJobError extends Error {
|
|
80
|
+
ticketError;
|
|
81
|
+
constructor(ticketError, step, ticketId) {
|
|
82
|
+
super(`the backend's ${step} job failed (ticket ${ticketId})`);
|
|
83
|
+
this.ticketError = ticketError;
|
|
84
|
+
this.name = 'ProvisionJobError';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ProvisionJobError = ProvisionJobError;
|
|
60
88
|
const TICKET_SELECT = {
|
|
61
89
|
id: true,
|
|
62
90
|
status: true,
|
|
@@ -120,21 +148,24 @@ const NETWORK_ERROR_RE = /fetch failed|network|socket hang up|ECONNRESET|ECONNRE
|
|
|
120
148
|
/**
|
|
121
149
|
* Whether an error reading or requesting a ticket says only that the backend
|
|
122
150
|
* couldn't be reached or failed: a network error thrown before any response,
|
|
123
|
-
* or an HTTP 5xx
|
|
124
|
-
* (validation, permission, an expired or
|
|
125
|
-
* ticket can't be followed any further.
|
|
151
|
+
* or errors that all carry an HTTP 5xx or 429 (inside the error, or from the
|
|
152
|
+
* adapter). Any other GraphQL error (validation, permission, an expired or
|
|
153
|
+
* rejected token) is an answer, so the ticket can't be followed any further.
|
|
126
154
|
*/
|
|
127
155
|
function isTransientProvisionError(err) {
|
|
128
156
|
const errors = err?.errors;
|
|
129
157
|
if (Array.isArray(errors)) {
|
|
130
|
-
return errors.length > 0 &&
|
|
158
|
+
return (errors.length > 0 &&
|
|
159
|
+
errors.every((e) => {
|
|
160
|
+
const status = (0, graphql_http_1.statusOf)(e);
|
|
161
|
+
return status !== undefined && (status >= 500 || status === 429);
|
|
162
|
+
}));
|
|
131
163
|
}
|
|
132
164
|
if (!(err instanceof Error))
|
|
133
165
|
return false;
|
|
134
166
|
const code = err.cause?.code;
|
|
135
167
|
return NETWORK_ERROR_RE.test(`${err.message} ${typeof code === 'string' ? code : ''}`);
|
|
136
168
|
}
|
|
137
|
-
const errorText = (err) => (err instanceof Error ? err.message : String(err));
|
|
138
169
|
function sleep(ms) {
|
|
139
170
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
140
171
|
}
|
|
@@ -170,9 +201,11 @@ async function requestDatabaseProvision(args) {
|
|
|
170
201
|
}
|
|
171
202
|
catch (err) {
|
|
172
203
|
if (isTransientProvisionError(err)) {
|
|
173
|
-
throw new ProvisionPendingError(
|
|
204
|
+
throw new ProvisionPendingError((0, graphql_http_1.thrownText)(err), args.resumeTicketId, { cause: err });
|
|
174
205
|
}
|
|
175
|
-
|
|
206
|
+
if ((0, graphql_http_1.answersSignedOut)(err))
|
|
207
|
+
throw new ProvisionSignedOutError((0, graphql_http_1.thrownText)(err), args.resumeTicketId, { cause: err });
|
|
208
|
+
throw new Error(`provision ticket ${args.resumeTicketId} could not be read: ${(0, graphql_http_1.thrownText)(err)}`, {
|
|
176
209
|
cause: err,
|
|
177
210
|
});
|
|
178
211
|
}
|
|
@@ -195,10 +228,10 @@ async function requestDatabaseProvision(args) {
|
|
|
195
228
|
let failures = 0;
|
|
196
229
|
for (;;) {
|
|
197
230
|
if (ticket.status === 'failed') {
|
|
198
|
-
throw new
|
|
231
|
+
throw new ProvisionJobError(ticket.errorMessage ?? '', 'provisioning', ticketId);
|
|
199
232
|
}
|
|
200
233
|
if (ticket.bootstrapStatus === 'failed') {
|
|
201
|
-
throw new
|
|
234
|
+
throw new ProvisionJobError(ticket.bootstrapError ?? '', 'owner bootstrap', ticketId);
|
|
202
235
|
}
|
|
203
236
|
if (ticket.status === 'completed' && ticket.bootstrapStatus === 'completed') {
|
|
204
237
|
if (!ticket.databaseId)
|
|
@@ -218,13 +251,15 @@ async function requestDatabaseProvision(args) {
|
|
|
218
251
|
polled = await executor.poll(ticketId);
|
|
219
252
|
}
|
|
220
253
|
catch (err) {
|
|
254
|
+
if ((0, graphql_http_1.answersSignedOut)(err))
|
|
255
|
+
throw new ProvisionSignedOutError((0, graphql_http_1.thrownText)(err), ticketId, { cause: err });
|
|
221
256
|
if (!isTransientProvisionError(err)) {
|
|
222
|
-
throw new Error(`provision ticket ${ticketId} could not be read: ${
|
|
257
|
+
throw new Error(`provision ticket ${ticketId} could not be read: ${(0, graphql_http_1.thrownText)(err)}`, {
|
|
223
258
|
cause: err,
|
|
224
259
|
});
|
|
225
260
|
}
|
|
226
261
|
if (++failures > exports.MAX_CONSECUTIVE_POLL_FAILURES) {
|
|
227
|
-
throw new ProvisionPendingError(
|
|
262
|
+
throw new ProvisionPendingError((0, graphql_http_1.thrownText)(err), ticketId, { cause: err });
|
|
228
263
|
}
|
|
229
264
|
continue;
|
|
230
265
|
}
|
package/ready.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PlanTarget } from '@agentic-kit/harness';
|
|
2
|
+
import { type ProjectContext } from './context';
|
|
3
|
+
import { type Result } from './failure';
|
|
4
|
+
/** The bound database a change goes to, at the backend and as the account the context resolved. */
|
|
5
|
+
export declare function databaseTarget(context: ProjectContext, appUserId?: string): Extract<PlanTarget, {
|
|
6
|
+
kind: 'database';
|
|
7
|
+
}>;
|
|
8
|
+
/** A change to what the account owns beside its databases (its templates), at the context's backend. */
|
|
9
|
+
export declare function accountTarget(context: ProjectContext): PlanTarget;
|
|
10
|
+
/** The project context of `cwd`, on the plane the tool acts on. */
|
|
11
|
+
export declare function projectReady(cwd: string, plane?: 'control' | 'data'): Promise<Result<ProjectContext>>;
|
|
12
|
+
/** The control-plane context of a project whose binding names its owner. */
|
|
13
|
+
export declare function ownedProjectReady(cwd: string): Promise<Result<ProjectContext & {
|
|
14
|
+
ownerId: string;
|
|
15
|
+
}>>;
|
|
16
|
+
/** A data-plane token of the person signed in to the app. */
|
|
17
|
+
export declare function appSessionReady(context: ProjectContext): Promise<Result<{
|
|
18
|
+
token: string;
|
|
19
|
+
userId?: string;
|
|
20
|
+
}>>;
|
package/ready.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// What a tool resolves before it changes anything. A tool runs its check first
|
|
3
|
+
// and stops with the failure; the gate runs the very same check
|
|
4
|
+
// (`toolPreconditions` in ./tools) and blocks the call with that failure, so
|
|
5
|
+
// the gate and the tool cannot disagree about whether a call can run.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.databaseTarget = databaseTarget;
|
|
8
|
+
exports.accountTarget = accountTarget;
|
|
9
|
+
exports.projectReady = projectReady;
|
|
10
|
+
exports.ownedProjectReady = ownedProjectReady;
|
|
11
|
+
exports.appSessionReady = appSessionReady;
|
|
12
|
+
const context_1 = require("./context");
|
|
13
|
+
const failure_1 = require("./failure");
|
|
14
|
+
const accountOf = (context) => ({
|
|
15
|
+
userId: context.accountUserId,
|
|
16
|
+
...(context.accountEmail ? { email: context.accountEmail } : {}),
|
|
17
|
+
...(context.accountAgent ? { agent: context.accountAgent } : {}),
|
|
18
|
+
});
|
|
19
|
+
/** The bound database a change goes to, at the backend and as the account the context resolved. */
|
|
20
|
+
function databaseTarget(context, appUserId) {
|
|
21
|
+
return {
|
|
22
|
+
kind: 'database',
|
|
23
|
+
database: { name: context.databaseName, id: context.databaseId },
|
|
24
|
+
apiEndpoint: context.controlApiEndpoint,
|
|
25
|
+
account: accountOf(context),
|
|
26
|
+
...(appUserId ? { appUserId } : {}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** A change to what the account owns beside its databases (its templates), at the context's backend. */
|
|
30
|
+
function accountTarget(context) {
|
|
31
|
+
return { kind: 'account', apiEndpoint: context.controlApiEndpoint, account: accountOf(context) };
|
|
32
|
+
}
|
|
33
|
+
/** The project context of `cwd`, on the plane the tool acts on. */
|
|
34
|
+
async function projectReady(cwd, plane = 'control') {
|
|
35
|
+
const resolved = await (0, context_1.resolveProjectContext)(cwd, { plane });
|
|
36
|
+
return resolved.context ? { kind: 'ok', value: resolved.context } : { kind: 'failed', failure: resolved.failure };
|
|
37
|
+
}
|
|
38
|
+
/** The control-plane context of a project whose binding names its owner. */
|
|
39
|
+
async function ownedProjectReady(cwd) {
|
|
40
|
+
const ready = await projectReady(cwd);
|
|
41
|
+
if (ready.kind === 'failed')
|
|
42
|
+
return ready;
|
|
43
|
+
const { ownerId } = ready.value;
|
|
44
|
+
return ownerId ? { kind: 'ok', value: { ...ready.value, ownerId } } : { kind: 'failed', failure: failure_1.MISSING_OWNER };
|
|
45
|
+
}
|
|
46
|
+
/** A data-plane token of the person signed in to the app. */
|
|
47
|
+
async function appSessionReady(context) {
|
|
48
|
+
const token = await (0, context_1.resolveDataToken)(context);
|
|
49
|
+
return token.token
|
|
50
|
+
? { kind: 'ok', value: { token: token.token, userId: token.userId } }
|
|
51
|
+
: { kind: 'failed', failure: token.failure };
|
|
52
|
+
}
|
package/run-codegen/barrels.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Turbopack barrel normalization
|
|
2
|
+
// Turbopack barrel normalization.
|
|
3
3
|
//
|
|
4
4
|
// Codegen emits directory barrel re-exports like `export * from './hooks'` where
|
|
5
5
|
// `./hooks` is a directory with an index.ts. Next.js 16's Turbopack cannot
|
package/run-codegen/endpoints.js
CHANGED
|
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.derivePlaneEndpoints = derivePlaneEndpoints;
|
|
4
4
|
exports.codegenEndpointEnv = codegenEndpointEnv;
|
|
5
5
|
exports.envLocalContent = envLocalContent;
|
|
6
|
-
// Codegen and the Next.js dev server default every per-DB vhost to
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// `app-<db>` (SUBDOMAIN-001).
|
|
6
|
+
// Codegen and the Next.js dev server default every per-DB vhost to a local
|
|
7
|
+
// host, which only exists on a local backend. Derive the real vhosts from the
|
|
8
|
+
// api endpoint the binding belongs to by swapping its first host label
|
|
9
|
+
// (api.example.com -> admin-<db>.example.com) — the same scheme context.ts uses
|
|
10
|
+
// for the data plane. The app DATA plane is `api-<db>`, not `app-<db>`.
|
|
12
11
|
function derivePlaneEndpoints(apiEndpoint, databaseName) {
|
|
13
12
|
const derive = (label) => {
|
|
14
13
|
try {
|
|
@@ -6,7 +6,7 @@ exports.normalizeType = normalizeType;
|
|
|
6
6
|
exports.columnDefault = columnDefault;
|
|
7
7
|
exports.readCheck = readCheck;
|
|
8
8
|
exports.fkAction = fkAction;
|
|
9
|
-
const
|
|
9
|
+
const field_type_1 = require("../blueprint/field-type");
|
|
10
10
|
const TYPE_ALIASES = {
|
|
11
11
|
int: 'integer',
|
|
12
12
|
int4: 'integer',
|
|
@@ -32,7 +32,7 @@ const TYPE_ALIASES = {
|
|
|
32
32
|
};
|
|
33
33
|
/** A field's type as one name (`integer`, `timestamptz`, `email`, …) plus `[]` per array dimension. */
|
|
34
34
|
function normalizeType(rawType) {
|
|
35
|
-
const name = (0,
|
|
35
|
+
const name = (0, field_type_1.fieldTypeToTypeName)(rawType).trim().toLowerCase();
|
|
36
36
|
const dims = /(\[\])*$/.exec(name)?.[0] ?? '';
|
|
37
37
|
const base = name.slice(0, name.length - dims.length).trim();
|
|
38
38
|
return (TYPE_ALIASES[base] ?? base) + dims;
|
|
@@ -56,7 +56,7 @@ function columnDefault(raw) {
|
|
|
56
56
|
if (typeof raw === 'number' || typeof raw === 'boolean')
|
|
57
57
|
return { kind: 'value', value: raw };
|
|
58
58
|
if (typeof raw === 'string') {
|
|
59
|
-
const parsed = (0,
|
|
59
|
+
const parsed = (0, field_type_1.toFieldDefault)(raw);
|
|
60
60
|
return parsed ? fromStructured(parsed) : null;
|
|
61
61
|
}
|
|
62
62
|
if (typeof raw === 'object' && !Array.isArray(raw))
|
|
@@ -114,7 +114,7 @@ function renderDefault(def) {
|
|
|
114
114
|
text = d.value === null ? 'NULL' : sqlLiteral(d.value);
|
|
115
115
|
else
|
|
116
116
|
return JSON.stringify(def);
|
|
117
|
-
const cast = (0,
|
|
117
|
+
const cast = (0, field_type_1.fieldTypeToTypeName)(d.cast);
|
|
118
118
|
return cast ? `${text}::${cast}` : text;
|
|
119
119
|
}
|
|
120
120
|
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
package/schema-model.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.SchemaReadError = void 0;
|
|
8
8
|
exports.accessOf = accessOf;
|
|
9
9
|
exports.readSchemaModel = readSchemaModel;
|
|
10
|
-
const
|
|
10
|
+
const internal_policies_1 = require("./blueprint/internal-policies");
|
|
11
11
|
const graphql_http_1 = require("./graphql-http");
|
|
12
12
|
const normalize_1 = require("./schema-model/normalize");
|
|
13
13
|
/** A read failed, so there is no model: a partial one would look like columns dropped outside. */
|
|
@@ -68,7 +68,7 @@ function modeOf(policy) {
|
|
|
68
68
|
* policies don't count.
|
|
69
69
|
*/
|
|
70
70
|
function accessOf(policies) {
|
|
71
|
-
const live = policies.filter((policy) => !policy.disabled && !(0,
|
|
71
|
+
const live = policies.filter((policy) => !policy.disabled && !(0, internal_policies_1.isInternalPolicy)(policy.type));
|
|
72
72
|
if (live.length === 0)
|
|
73
73
|
return 'custom';
|
|
74
74
|
const modes = new Set(live.map(modeOf));
|
|
@@ -87,10 +87,10 @@ async function read(step, query) {
|
|
|
87
87
|
result = await query.execute();
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
|
-
throw new SchemaReadError(`Could not read ${step}: ${
|
|
90
|
+
throw new SchemaReadError(`Could not read ${step}: ${(0, graphql_http_1.thrownText)(err)}`, step);
|
|
91
91
|
}
|
|
92
92
|
if (!result.ok) {
|
|
93
|
-
throw new SchemaReadError(`Could not read ${step}: ${(0, graphql_http_1.
|
|
93
|
+
throw new SchemaReadError(`Could not read ${step}: ${(0, graphql_http_1.answerText)(result.errors ?? [])}`, step, result.errors);
|
|
94
94
|
}
|
|
95
95
|
return result.data;
|
|
96
96
|
}
|
|
@@ -268,7 +268,6 @@ async function readSchemaModel(context) {
|
|
|
268
268
|
})
|
|
269
269
|
.sort((a, b) => a.order - b.order || a.name.localeCompare(b.name));
|
|
270
270
|
const policies = (policiesByTable.get(table.id) ?? [])
|
|
271
|
-
.filter((policy) => !(0, harness_1.isInternalPolicy)(policy.policyType))
|
|
272
271
|
.map((policy) => ({
|
|
273
272
|
id: policy.id,
|
|
274
273
|
type: policy.policyType ?? '',
|
package/schema-resolve.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToolFailure } from '@agentic-kit/harness';
|
|
1
2
|
import type { ProjectContext } from './context';
|
|
2
3
|
export type ResolvedField = {
|
|
3
4
|
id: string;
|
|
@@ -18,6 +19,55 @@ export type ResolvedSchema = {
|
|
|
18
19
|
tables: ResolvedTable[];
|
|
19
20
|
};
|
|
20
21
|
export declare function resolveSchema(context: ProjectContext): Promise<ResolvedSchema>;
|
|
22
|
+
/**
|
|
23
|
+
* A name that is not found, and the stored form of it when one of `names` has
|
|
24
|
+
* it: a person often asks for a table or field by the name they made it with.
|
|
25
|
+
*/
|
|
26
|
+
export declare function notFound(what: 'Table' | 'Field', name: string, message: string, names: readonly string[]): ToolFailure;
|
|
21
27
|
export declare function resolveTable(schema: ResolvedSchema, tableName: string): ResolvedTable;
|
|
22
28
|
export declare function resolveField(table: ResolvedTable, fieldName: string): ResolvedField;
|
|
23
29
|
export declare function findUniqueConstraintId(table: ResolvedTable, fieldId: string): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The name the backend stores for a new table or field named `name`, as it
|
|
32
|
+
* rewrites every new name: a capital starts a word, separators become one
|
|
33
|
+
* underscore, and a word of one letter joins its neighbour (`r2_rows_a` is
|
|
34
|
+
* stored as `r2_rowsa`). Undefined for a
|
|
35
|
+
* name with a character outside ASCII, which the backend strips of accents
|
|
36
|
+
* first (unaccent), so this cannot say.
|
|
37
|
+
*/
|
|
38
|
+
export declare function storedName(name: string): string | undefined;
|
|
39
|
+
/** The name the backend stores for `name`, when it differs from it. */
|
|
40
|
+
export declare function renamed(name: string): string | undefined;
|
|
41
|
+
/** What a plan says about a new table or field name the backend stores differently, or cannot say. */
|
|
42
|
+
export declare function renameNote(what: 'table' | 'field', name: string): string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* A not-found failure for each table a blueprint's relations name that
|
|
45
|
+
* neither the blueprint makes nor the project database has, or null. An end
|
|
46
|
+
* given as a module's table names no table here.
|
|
47
|
+
*/
|
|
48
|
+
export declare function relationTablesMissing(context: ProjectContext, made: readonly string[], relations: ReadonlyArray<{
|
|
49
|
+
source_table?: string;
|
|
50
|
+
source_schema?: string;
|
|
51
|
+
target_table?: string;
|
|
52
|
+
target_schema?: string;
|
|
53
|
+
}>, schemas: ReadonlyMap<string, string>): Promise<ToolFailure | null>;
|
|
54
|
+
/** The stored names of the tables of `ids`, read back from the control plane. */
|
|
55
|
+
export declare function storedTableNames(context: ProjectContext, ids: string[]): Promise<Map<string, string>>;
|
|
56
|
+
/** The schemas of the project database by name: the default one of the project (app_public) and any other. */
|
|
57
|
+
export declare function readSchemas(context: ProjectContext): Promise<{
|
|
58
|
+
kind: 'ok';
|
|
59
|
+
value: Map<string, string>;
|
|
60
|
+
} | {
|
|
61
|
+
kind: 'failed';
|
|
62
|
+
failure: ToolFailure;
|
|
63
|
+
}>;
|
|
64
|
+
/** A not-found failure for each schema a blueprint names that the project database does not have, or null. */
|
|
65
|
+
export declare function schemasMissing(named: readonly string[], schemas: ReadonlyMap<string, string>): ToolFailure | null;
|
|
66
|
+
/**
|
|
67
|
+
* A `name-taken` failure for the tables of `tables` that their schema already has (the project's own, app_public,
|
|
68
|
+
* when a table names none; `schemas` maps the others' names to ids), or null when none does.
|
|
69
|
+
*/
|
|
70
|
+
export declare function tablesTaken(context: ProjectContext, tables: ReadonlyArray<{
|
|
71
|
+
name: string;
|
|
72
|
+
schema?: string;
|
|
73
|
+
}>, schemas?: ReadonlyMap<string, string>): Promise<ToolFailure | null>;
|