@supacloud/cli 0.126.1 → 0.127.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/dist/index.js +477 -87
- package/dist/shared/tools/db-governance-tools.d.ts +10 -3
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -16480,7 +16480,7 @@ var init_context = __esm(() => {
|
|
|
16480
16480
|
|
|
16481
16481
|
// src/shared/tools/developer-experience-tools.ts
|
|
16482
16482
|
import { existsSync as existsSync18 } from "node:fs";
|
|
16483
|
-
import { mkdir as mkdir8, readdir as readdir7, readFile as
|
|
16483
|
+
import { mkdir as mkdir8, readdir as readdir7, readFile as readFile8, writeFile as writeFile8 } from "node:fs/promises";
|
|
16484
16484
|
import { dirname as dirname13, join as join20, resolve as resolve27 } from "node:path";
|
|
16485
16485
|
function textResult4(text, isError = false) {
|
|
16486
16486
|
return { isError, content: [{ type: "text", text }] };
|
|
@@ -16510,7 +16510,7 @@ async function readPackageManifest(root) {
|
|
|
16510
16510
|
if (!existsSync18(path))
|
|
16511
16511
|
return {};
|
|
16512
16512
|
try {
|
|
16513
|
-
const parsed = JSON.parse(await
|
|
16513
|
+
const parsed = JSON.parse(await readFile8(path, "utf8"));
|
|
16514
16514
|
const value = record7(parsed);
|
|
16515
16515
|
if (!value)
|
|
16516
16516
|
throw new Error("package.json must contain an object");
|
|
@@ -16528,7 +16528,7 @@ async function readPackageManifest(root) {
|
|
|
16528
16528
|
}
|
|
16529
16529
|
async function writeNewFile(path, content) {
|
|
16530
16530
|
try {
|
|
16531
|
-
await
|
|
16531
|
+
await writeFile8(path, content, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
16532
16532
|
return true;
|
|
16533
16533
|
} catch (error) {
|
|
16534
16534
|
if (error instanceof Error && "code" in error && error.code === "EEXIST")
|
|
@@ -16538,7 +16538,7 @@ async function writeNewFile(path, content) {
|
|
|
16538
16538
|
}
|
|
16539
16539
|
async function ensureGitignore(root) {
|
|
16540
16540
|
const path = join20(root, ".gitignore");
|
|
16541
|
-
const existing = existsSync18(path) ? await
|
|
16541
|
+
const existing = existsSync18(path) ? await readFile8(path, "utf8") : "";
|
|
16542
16542
|
const required = [".env.supacloud.*", "!.env.supacloud.*.example"];
|
|
16543
16543
|
const missing = required.filter((entry) => !existing.split(/\r?\n/).includes(entry));
|
|
16544
16544
|
if (missing.length === 0)
|
|
@@ -16546,7 +16546,7 @@ async function ensureGitignore(root) {
|
|
|
16546
16546
|
const prefix = existing.length > 0 && !existing.endsWith(`
|
|
16547
16547
|
`) ? `${existing}
|
|
16548
16548
|
` : existing;
|
|
16549
|
-
await
|
|
16549
|
+
await writeFile8(path, `${prefix}${missing.join(`
|
|
16550
16550
|
`)}
|
|
16551
16551
|
`, "utf8");
|
|
16552
16552
|
return true;
|
|
@@ -16569,7 +16569,7 @@ async function initializeProject(request, options = {}) {
|
|
|
16569
16569
|
};
|
|
16570
16570
|
const created = [];
|
|
16571
16571
|
try {
|
|
16572
|
-
await
|
|
16572
|
+
await writeFile8(configPath, `${JSON.stringify(config, null, 2)}
|
|
16573
16573
|
`, {
|
|
16574
16574
|
encoding: "utf8",
|
|
16575
16575
|
flag: "wx",
|
|
@@ -16657,9 +16657,9 @@ var init_developer_experience_tools = __esm(() => {
|
|
|
16657
16657
|
});
|
|
16658
16658
|
|
|
16659
16659
|
// src/shared/tools/deploy-tools.ts
|
|
16660
|
-
import { access as access2, lstat as
|
|
16660
|
+
import { access as access2, lstat as lstat8, mkdtemp as mkdtemp3, opendir as opendir2, readFile as readFile14, realpath as realpath6, rm as rm4, writeFile as writeFile13 } from "node:fs/promises";
|
|
16661
16661
|
import { spawn as spawn3 } from "node:child_process";
|
|
16662
|
-
import { createHash as
|
|
16662
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
16663
16663
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
16664
16664
|
import { basename as basename10, dirname as dirname16, join as join26, relative as relative12, resolve as resolve33, sep as sep7 } from "node:path";
|
|
16665
16665
|
function isPublicBuildEnv2(name) {
|
|
@@ -16692,7 +16692,7 @@ function frontendDeployment2(candidate) {
|
|
|
16692
16692
|
}
|
|
16693
16693
|
async function readJson3(path) {
|
|
16694
16694
|
try {
|
|
16695
|
-
return JSON.parse(await
|
|
16695
|
+
return JSON.parse(await readFile14(path, "utf8"));
|
|
16696
16696
|
} catch (error) {
|
|
16697
16697
|
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
16698
16698
|
return null;
|
|
@@ -16925,7 +16925,7 @@ async function runBuild2(command, cwd, environment, json) {
|
|
|
16925
16925
|
});
|
|
16926
16926
|
}
|
|
16927
16927
|
async function collectArchiveFiles2(root) {
|
|
16928
|
-
const rootStat = await
|
|
16928
|
+
const rootStat = await lstat8(root).catch(() => null);
|
|
16929
16929
|
if (!rootStat?.isDirectory() || rootStat.isSymbolicLink()) {
|
|
16930
16930
|
throw new Error(`Frontend output directory does not exist or is not a regular directory: ${root}`);
|
|
16931
16931
|
}
|
|
@@ -16937,7 +16937,7 @@ async function collectArchiveFiles2(root) {
|
|
|
16937
16937
|
entries.sort((left, right) => left.name.localeCompare(right.name, "en"));
|
|
16938
16938
|
for (const entry of entries) {
|
|
16939
16939
|
const path = join26(directory, entry.name);
|
|
16940
|
-
const stats = await
|
|
16940
|
+
const stats = await lstat8(path);
|
|
16941
16941
|
if (stats.isSymbolicLink())
|
|
16942
16942
|
throw new Error(`Frontend output cannot contain symbolic links: ${path}`);
|
|
16943
16943
|
if (stats.isDirectory())
|
|
@@ -16955,15 +16955,15 @@ async function collectArchiveFiles2(root) {
|
|
|
16955
16955
|
const files = new Map;
|
|
16956
16956
|
const digests = [];
|
|
16957
16957
|
for (const path of paths) {
|
|
16958
|
-
const data = new Uint8Array(await
|
|
16958
|
+
const data = new Uint8Array(await readFile14(path));
|
|
16959
16959
|
bytes += data.byteLength;
|
|
16960
16960
|
if (bytes > MAX_SOURCE_BYTES2)
|
|
16961
16961
|
throw new Error(`Frontend output exceeds ${MAX_SOURCE_BYTES2} bytes`);
|
|
16962
16962
|
const archivePath = relative12(root, path).split(sep7).join("/");
|
|
16963
16963
|
files.set(archivePath, data);
|
|
16964
|
-
digests.push({ path: archivePath, size: data.byteLength, sha256:
|
|
16964
|
+
digests.push({ path: archivePath, size: data.byteLength, sha256: createHash14("sha256").update(data).digest("hex") });
|
|
16965
16965
|
}
|
|
16966
|
-
const tree =
|
|
16966
|
+
const tree = createHash14("sha256");
|
|
16967
16967
|
for (const file of digests.sort((left, right) => left.path.localeCompare(right.path))) {
|
|
16968
16968
|
const pathBytes = Buffer.from(file.path, "utf8");
|
|
16969
16969
|
const frame = Buffer.alloc(12);
|
|
@@ -16978,8 +16978,8 @@ async function createCollectedFrontendArchive2(outputDirectory, collected) {
|
|
|
16978
16978
|
const archivePath = join26(temporaryDirectory, `${basename10(outputDirectory)}.tar.zst`);
|
|
16979
16979
|
try {
|
|
16980
16980
|
const archiveBytes = await createFrontendTarZstd(collected.files);
|
|
16981
|
-
await
|
|
16982
|
-
const sha256 =
|
|
16981
|
+
await writeFile13(archivePath, archiveBytes);
|
|
16982
|
+
const sha256 = createHash14("sha256").update(archiveBytes).digest("hex");
|
|
16983
16983
|
return {
|
|
16984
16984
|
archivePath,
|
|
16985
16985
|
sha256,
|
|
@@ -16996,7 +16996,7 @@ async function createCollectedFrontendArchive2(outputDirectory, collected) {
|
|
|
16996
16996
|
}
|
|
16997
16997
|
async function publishConfiguredFrontend2(http, projectRef, configRoot, target, skipBuild, json, environmentVariables) {
|
|
16998
16998
|
const projectDirectory = target.root;
|
|
16999
|
-
const targetState = await
|
|
16999
|
+
const targetState = await lstat8(projectDirectory).catch(() => null);
|
|
17000
17000
|
if (!targetState?.isDirectory() || targetState.isSymbolicLink()) {
|
|
17001
17001
|
throw new Error(`Deploy target '${target.name}' root is not a regular directory: ${projectDirectory}`);
|
|
17002
17002
|
}
|
|
@@ -17070,9 +17070,9 @@ var init_deploy_tools = __esm(() => {
|
|
|
17070
17070
|
|
|
17071
17071
|
// src/shared/tools/workspace-plan.ts
|
|
17072
17072
|
import { execFile as execFile2 } from "node:child_process";
|
|
17073
|
-
import { createHash as
|
|
17073
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
17074
17074
|
import { constants as constants2 } from "node:fs";
|
|
17075
|
-
import { lstat as
|
|
17075
|
+
import { lstat as lstat9, open as open4, readdir as readdir10, realpath as realpath7 } from "node:fs/promises";
|
|
17076
17076
|
import { isAbsolute as isAbsolute8, join as join27, relative as relative13, resolve as resolve34 } from "node:path";
|
|
17077
17077
|
import { promisify as promisify2 } from "node:util";
|
|
17078
17078
|
function isNodeError(error, code) {
|
|
@@ -17137,7 +17137,7 @@ function canonical3(value) {
|
|
|
17137
17137
|
return JSON.stringify(value) ?? "null";
|
|
17138
17138
|
}
|
|
17139
17139
|
function digest3(value) {
|
|
17140
|
-
return
|
|
17140
|
+
return createHash15("sha256").update(canonical3(value)).digest("hex");
|
|
17141
17141
|
}
|
|
17142
17142
|
function assertUniqueJsonKeys(text) {
|
|
17143
17143
|
const invalid = () => new WorkspacePlanError("workspace-config-invalid", "supacloud.workspace.json is not valid JSON");
|
|
@@ -17328,7 +17328,7 @@ async function pathKind(rootReal, relativePath) {
|
|
|
17328
17328
|
for (let index = 0;index < segments.length; index += 1) {
|
|
17329
17329
|
current = join27(current, segments[index]);
|
|
17330
17330
|
try {
|
|
17331
|
-
const stat = await
|
|
17331
|
+
const stat = await lstat9(current);
|
|
17332
17332
|
if (stat.isSymbolicLink())
|
|
17333
17333
|
return "symlink";
|
|
17334
17334
|
} catch (error) {
|
|
@@ -17600,7 +17600,7 @@ async function loadGraph(rootReal, config) {
|
|
|
17600
17600
|
if (kind !== "ok")
|
|
17601
17601
|
diagnostics.push({ code: kind === "symlink" ? "symlink-rejected" : "invalid-path", severity: "error", application_id: application.id, message: `Application root '${application.root}' is not a contained directory` });
|
|
17602
17602
|
else {
|
|
17603
|
-
const stat = await
|
|
17603
|
+
const stat = await lstat9(join27(rootReal, application.root)).catch(() => null);
|
|
17604
17604
|
if (!stat?.isDirectory())
|
|
17605
17605
|
diagnostics.push({ code: "application-root-missing", severity: "error", application_id: application.id, message: `Application root '${application.root}' is not a directory` });
|
|
17606
17606
|
}
|
|
@@ -17766,7 +17766,7 @@ async function createWorkspacePlan(input) {
|
|
|
17766
17766
|
} catch {
|
|
17767
17767
|
return blockedPlan(environment, "workspace-root-missing", "The workspace root does not exist");
|
|
17768
17768
|
}
|
|
17769
|
-
const rootStat = await
|
|
17769
|
+
const rootStat = await lstat9(rootReal).catch(() => null);
|
|
17770
17770
|
if (!rootStat?.isDirectory())
|
|
17771
17771
|
return blockedPlan(environment, "workspace-root-missing", "The workspace root is not a directory");
|
|
17772
17772
|
let changedFiles;
|
|
@@ -18140,14 +18140,14 @@ var init_workspace_publish = __esm(() => {
|
|
|
18140
18140
|
});
|
|
18141
18141
|
|
|
18142
18142
|
// src/shared/tools/workspace-execute.ts
|
|
18143
|
-
import { createHash as
|
|
18144
|
-
import { readFile as
|
|
18143
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
18144
|
+
import { readFile as readFile15 } from "node:fs/promises";
|
|
18145
18145
|
import { join as join28, resolve as resolve36 } from "node:path";
|
|
18146
18146
|
function textResult8(text, isError = false) {
|
|
18147
18147
|
return { isError, content: [{ type: "text", text }] };
|
|
18148
18148
|
}
|
|
18149
18149
|
function workspaceMutationId(parts) {
|
|
18150
|
-
const hash =
|
|
18150
|
+
const hash = createHash16("sha256").update(parts.join("\x00")).digest("hex");
|
|
18151
18151
|
return `${hash.slice(0, 8)}-${hash.slice(8, 12)}-4${hash.slice(13, 16)}-a${hash.slice(17, 20)}-${hash.slice(20, 32)}`;
|
|
18152
18152
|
}
|
|
18153
18153
|
function blocked(operation, code, message, plan = null) {
|
|
@@ -18222,7 +18222,7 @@ function affectedTargets(plan, applicationId) {
|
|
|
18222
18222
|
return plan.applications.filter((entry) => entry.impact === "affected" && entry.target && (!applicationId || entry.id === applicationId));
|
|
18223
18223
|
}
|
|
18224
18224
|
async function observeWorkspace(input, plan) {
|
|
18225
|
-
const text = await
|
|
18225
|
+
const text = await readFile15(join28(resolve36(input.root), WORKSPACE_CONFIG_FILE), "utf8");
|
|
18226
18226
|
const parsed = JSON.parse(text);
|
|
18227
18227
|
const names = [...new Set((parsed.applications ?? []).flatMap((application) => Object.keys(application.environments ?? {})))].sort((a, b) => a.localeCompare(b, "en"));
|
|
18228
18228
|
const observations = [];
|
|
@@ -18598,7 +18598,7 @@ async function runWorkspaceCommand(args, cwd = process.cwd(), client) {
|
|
|
18598
18598
|
const root = resolve36(typeof args.root === "string" ? args.root : cwd);
|
|
18599
18599
|
let configDigest = "";
|
|
18600
18600
|
try {
|
|
18601
|
-
configDigest =
|
|
18601
|
+
configDigest = createHash16("sha256").update(await readFile15(join28(root, WORKSPACE_CONFIG_FILE))).digest("hex");
|
|
18602
18602
|
} catch {
|
|
18603
18603
|
return textResult8("supacloud.workspace.json was not found", true);
|
|
18604
18604
|
}
|
|
@@ -19071,13 +19071,22 @@ async function runCli(cliTools, args, options = {}) {
|
|
|
19071
19071
|
return;
|
|
19072
19072
|
}
|
|
19073
19073
|
let startIdx = 1;
|
|
19074
|
+
let nestedAction;
|
|
19074
19075
|
if (args.length > 1 && !args[1].startsWith("--")) {
|
|
19075
19076
|
startIdx = 2;
|
|
19077
|
+
if (toolName === "db" && args[1] === "operation-ownership" && args[2] !== undefined && !args[2].startsWith("--")) {
|
|
19078
|
+
nestedAction = args[2];
|
|
19079
|
+
startIdx = 3;
|
|
19080
|
+
}
|
|
19076
19081
|
}
|
|
19077
19082
|
try {
|
|
19078
19083
|
const parsedArgs = parseCliFlags(args, startIdx, tool.schema);
|
|
19079
|
-
if (
|
|
19084
|
+
if (nestedAction !== undefined) {
|
|
19085
|
+
parsedArgs.action = args[1];
|
|
19086
|
+
parsedArgs.operation_action = nestedAction;
|
|
19087
|
+
} else if (startIdx === 2) {
|
|
19080
19088
|
parsedArgs.action = args[1];
|
|
19089
|
+
}
|
|
19081
19090
|
assertCurrentDeploymentInput(args[0], parsedArgs);
|
|
19082
19091
|
validateToolArguments2(tool.schema, parsedArgs);
|
|
19083
19092
|
const result = await tool.callback(parsedArgs);
|
|
@@ -19540,7 +19549,7 @@ var ACTION_POLICY = {
|
|
|
19540
19549
|
write: ["release", "upload", "configure", "transfer", "promote", "promote-reconcile", "deploy", "rollback", "reconcile", "retire", "preview", "preview-create", "preview-reconcile", "preview-cleanup", "preview-pr"]
|
|
19541
19550
|
},
|
|
19542
19551
|
db: {
|
|
19543
|
-
local: ["context", "lint", "explain", "diff", "role_sql"],
|
|
19552
|
+
local: ["context", "lint", "explain", "operation-ownership", "diff", "role_sql"],
|
|
19544
19553
|
read: ["check", "module_check", "reverse", "plan", "role_check"],
|
|
19545
19554
|
write: ["apply"]
|
|
19546
19555
|
},
|
|
@@ -30111,7 +30120,7 @@ var starter_metadata_default = {
|
|
|
30111
30120
|
generatedBy: "supacloud/starter-metadata-v1",
|
|
30112
30121
|
packages: {
|
|
30113
30122
|
compiler: {
|
|
30114
|
-
version: "0.
|
|
30123
|
+
version: "0.64.0"
|
|
30115
30124
|
},
|
|
30116
30125
|
app: {
|
|
30117
30126
|
version: "0.39.5",
|
|
@@ -30129,7 +30138,7 @@ var starter_metadata_default = {
|
|
|
30129
30138
|
version: "0.16.3"
|
|
30130
30139
|
},
|
|
30131
30140
|
db: {
|
|
30132
|
-
version: "0.
|
|
30141
|
+
version: "0.26.0",
|
|
30133
30142
|
dependencies: {},
|
|
30134
30143
|
devDependencies: {},
|
|
30135
30144
|
peerDependencies: {
|
|
@@ -31390,7 +31399,7 @@ function modelCommandTemplateFiles(name, sdk) {
|
|
|
31390
31399
|
}),
|
|
31391
31400
|
"supacloud.config.ts": `import { defineSupacloudConfig } from "@supacloud/compiler";
|
|
31392
31401
|
export default defineSupacloudConfig({
|
|
31393
|
-
databaseGovernance: { mode: "check" },
|
|
31402
|
+
databaseGovernance: { mode: "check", ownership: "assist" },
|
|
31394
31403
|
commandCapabilities: { requirePersistentAdapters: true, permission: true, audit: true, idempotency: true, transaction: true,
|
|
31395
31404
|
rpc: { modelOrders: { boundary: "database", transaction: true, audit: true, idempotency: true } } },
|
|
31396
31405
|
delivery: {
|
|
@@ -34278,7 +34287,7 @@ PORT=3000
|
|
|
34278
34287
|
"supacloud.config.ts": `import { defineSupacloudConfig } from "@supacloud/compiler";
|
|
34279
34288
|
|
|
34280
34289
|
export default defineSupacloudConfig({
|
|
34281
|
-
databaseGovernance: { mode: "check" },
|
|
34290
|
+
databaseGovernance: { mode: "check", ownership: "assist" },
|
|
34282
34291
|
delivery: {
|
|
34283
34292
|
version: 1,
|
|
34284
34293
|
build: {
|
|
@@ -38693,14 +38702,19 @@ function registerAppTools(server, options = {}) {
|
|
|
38693
38702
|
|
|
38694
38703
|
// src/shared/tools/db-governance-tools.ts
|
|
38695
38704
|
init_build();
|
|
38705
|
+
import { createHash as createHash10, randomUUID as randomUUID3 } from "node:crypto";
|
|
38696
38706
|
import { existsSync as existsSync15 } from "node:fs";
|
|
38707
|
+
import { lstat as lstat5, readFile as readFile7, rename as rename4, unlink as unlink2, writeFile as writeFile7 } from "node:fs/promises";
|
|
38697
38708
|
import { join as join18, resolve as resolve23 } from "node:path";
|
|
38709
|
+
import * as ts from "@supacloud/db/typescript";
|
|
38698
38710
|
import {
|
|
38699
38711
|
buildDatabaseManifest,
|
|
38700
38712
|
explainObject,
|
|
38701
38713
|
lintModule,
|
|
38714
|
+
normalizeOperationOwnership,
|
|
38702
38715
|
readCatalog,
|
|
38703
|
-
reconcileModule
|
|
38716
|
+
reconcileModule,
|
|
38717
|
+
suggestOperationOwnership
|
|
38704
38718
|
} from "@supacloud/db";
|
|
38705
38719
|
import { databaseSources } from "@supacloud/db/source-contracts";
|
|
38706
38720
|
|
|
@@ -39367,13 +39381,15 @@ function normalizeModule(candidate, sourcePath) {
|
|
|
39367
39381
|
throw new Error(`Invalid database module export in ${sourcePath}(应导出 defineDatabaseModule(...) 结果)`);
|
|
39368
39382
|
}
|
|
39369
39383
|
const raw = candidate;
|
|
39384
|
+
const tables = raw.tables ?? [];
|
|
39370
39385
|
return {
|
|
39371
39386
|
name: raw.name,
|
|
39372
|
-
tables
|
|
39387
|
+
tables,
|
|
39373
39388
|
policies: raw.policies ?? [],
|
|
39374
39389
|
functions: raw.functions ?? [],
|
|
39375
39390
|
triggers: raw.triggers ?? [],
|
|
39376
|
-
grants: raw.grants ?? []
|
|
39391
|
+
grants: raw.grants ?? [],
|
|
39392
|
+
operationOwnership: normalizeOperationOwnership(raw.operationOwnership, tables)
|
|
39377
39393
|
};
|
|
39378
39394
|
}
|
|
39379
39395
|
async function loadDatabaseModules(root, moduleFile) {
|
|
@@ -39452,6 +39468,16 @@ function moduleObjects(module) {
|
|
|
39452
39468
|
module: module.name,
|
|
39453
39469
|
source: grant.source,
|
|
39454
39470
|
tests: []
|
|
39471
|
+
})),
|
|
39472
|
+
...(module.operationOwnership ?? []).map((ownership) => ({
|
|
39473
|
+
kind: "operation",
|
|
39474
|
+
name: `${ownership.table}.${ownership.operation}`,
|
|
39475
|
+
module: module.name,
|
|
39476
|
+
table: ownership.table,
|
|
39477
|
+
operation: ownership.operation,
|
|
39478
|
+
owner: ownership.owner,
|
|
39479
|
+
source: null,
|
|
39480
|
+
tests: []
|
|
39455
39481
|
}))
|
|
39456
39482
|
];
|
|
39457
39483
|
}
|
|
@@ -39505,6 +39531,357 @@ function parseSchemas(schema) {
|
|
|
39505
39531
|
const schemas = schema?.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
39506
39532
|
return schemas && schemas.length > 0 ? schemas : ["public"];
|
|
39507
39533
|
}
|
|
39534
|
+
function moduleForTable(modules, table) {
|
|
39535
|
+
const owners = modules.filter((module) => module.tables.includes(table));
|
|
39536
|
+
return owners.length === 1 ? owners[0] ?? null : null;
|
|
39537
|
+
}
|
|
39538
|
+
function ownershipSuggestionReport(modules, selected) {
|
|
39539
|
+
const selectedNames = new Set(selected.map((module) => module.name));
|
|
39540
|
+
const suggestions = suggestOperationOwnership(modules).filter((suggestion) => {
|
|
39541
|
+
const owners = modules.filter((module) => module.tables.includes(suggestion.table));
|
|
39542
|
+
return owners.some((module) => selectedNames.has(module.name));
|
|
39543
|
+
}).map((suggestion) => ({
|
|
39544
|
+
...suggestion,
|
|
39545
|
+
module: moduleForTable(modules, suggestion.table)?.name ?? null
|
|
39546
|
+
}));
|
|
39547
|
+
return {
|
|
39548
|
+
version: 1,
|
|
39549
|
+
scope: "operation-ownership",
|
|
39550
|
+
action: "suggest",
|
|
39551
|
+
modules: selected.map((module) => module.name),
|
|
39552
|
+
suggestions,
|
|
39553
|
+
summary: {
|
|
39554
|
+
declared: suggestions.filter((suggestion) => suggestion.status === "declared").length,
|
|
39555
|
+
suggested: suggestions.filter((suggestion) => suggestion.status === "suggested").length,
|
|
39556
|
+
ambiguous: suggestions.filter((suggestion) => suggestion.status === "ambiguous").length,
|
|
39557
|
+
unknown: suggestions.filter((suggestion) => suggestion.status === "unknown").length,
|
|
39558
|
+
adoptable: suggestions.filter((suggestion) => suggestion.status === "suggested" && suggestion.owner !== null && suggestion.module !== null).length
|
|
39559
|
+
}
|
|
39560
|
+
};
|
|
39561
|
+
}
|
|
39562
|
+
async function selectedDatabaseModules(args, root) {
|
|
39563
|
+
const modules = await loadDatabaseModules(root, args.module_file);
|
|
39564
|
+
const selected = args.module ? modules.filter((module) => module.name === args.module) : modules;
|
|
39565
|
+
if (args.module && selected.length === 0) {
|
|
39566
|
+
throw new Error(`未找到数据库模块: ${args.module}(可用: ${modules.map((module) => module.name).join(", ") || "none"})`);
|
|
39567
|
+
}
|
|
39568
|
+
return {
|
|
39569
|
+
modules,
|
|
39570
|
+
selected,
|
|
39571
|
+
modulePath: resolve23(root, args.module_file ?? "db/modules.ts")
|
|
39572
|
+
};
|
|
39573
|
+
}
|
|
39574
|
+
function requireOwnershipAction(args) {
|
|
39575
|
+
const action = args.operation_action;
|
|
39576
|
+
if (action !== "suggest" && action !== "adopt") {
|
|
39577
|
+
throw new Error("db operation-ownership requires suggest or adopt");
|
|
39578
|
+
}
|
|
39579
|
+
return action;
|
|
39580
|
+
}
|
|
39581
|
+
function explicitAdoption(args, modules) {
|
|
39582
|
+
const hasExplicitOwner = args.owner !== undefined || args.operation !== undefined || args.target !== undefined;
|
|
39583
|
+
if (!hasExplicitOwner)
|
|
39584
|
+
return null;
|
|
39585
|
+
if (args.owner === undefined || args.operation === undefined || !args.target?.trim()) {
|
|
39586
|
+
throw new Error("显式 adopt 需要同时提供 --target、--operation 和 --owner");
|
|
39587
|
+
}
|
|
39588
|
+
const module = moduleForTable(modules, args.target.trim());
|
|
39589
|
+
if (module === null) {
|
|
39590
|
+
throw new Error(`无法唯一确定表所属模块: ${args.target.trim()}(表必须只由一个模块声明)`);
|
|
39591
|
+
}
|
|
39592
|
+
if ((module.operationOwnership ?? []).some((entry) => entry.table === args.target.trim() && entry.operation === args.operation)) {
|
|
39593
|
+
throw new Error(`已存在 operation ownership: ${args.target.trim()}.${args.operation}`);
|
|
39594
|
+
}
|
|
39595
|
+
return {
|
|
39596
|
+
module: module.name,
|
|
39597
|
+
table: args.target.trim(),
|
|
39598
|
+
operation: args.operation,
|
|
39599
|
+
owner: args.owner,
|
|
39600
|
+
source: "explicit",
|
|
39601
|
+
evidence: [{
|
|
39602
|
+
kind: "declaration",
|
|
39603
|
+
detail: `explicit adopt: ${args.target.trim()}.${args.operation} = ${args.owner}`
|
|
39604
|
+
}]
|
|
39605
|
+
};
|
|
39606
|
+
}
|
|
39607
|
+
function adoptionEntries(args, modules, selected) {
|
|
39608
|
+
const explicit = explicitAdoption(args, modules);
|
|
39609
|
+
if (explicit !== null) {
|
|
39610
|
+
if (!selected.some((module) => module.name === explicit.module)) {
|
|
39611
|
+
throw new Error(`模块 ${explicit.module} 不在当前 --module 范围内`);
|
|
39612
|
+
}
|
|
39613
|
+
return { changes: [explicit], skipped: [] };
|
|
39614
|
+
}
|
|
39615
|
+
const selectedNames = new Set(selected.map((module) => module.name));
|
|
39616
|
+
const changes = [];
|
|
39617
|
+
const skipped = [];
|
|
39618
|
+
for (const suggestion of suggestOperationOwnership(modules)) {
|
|
39619
|
+
const module = moduleForTable(modules, suggestion.table);
|
|
39620
|
+
const owners = modules.filter((candidate) => candidate.tables.includes(suggestion.table));
|
|
39621
|
+
if (module === null) {
|
|
39622
|
+
if (owners.some((candidate) => selectedNames.has(candidate.name))) {
|
|
39623
|
+
skipped.push({
|
|
39624
|
+
table: suggestion.table,
|
|
39625
|
+
operation: suggestion.operation,
|
|
39626
|
+
reason: "table is declared by multiple modules; resolve module ownership first"
|
|
39627
|
+
});
|
|
39628
|
+
}
|
|
39629
|
+
continue;
|
|
39630
|
+
}
|
|
39631
|
+
if (!selectedNames.has(module.name))
|
|
39632
|
+
continue;
|
|
39633
|
+
if (suggestion.status === "suggested" && suggestion.owner !== null) {
|
|
39634
|
+
changes.push({
|
|
39635
|
+
module: module.name,
|
|
39636
|
+
table: suggestion.table,
|
|
39637
|
+
operation: suggestion.operation,
|
|
39638
|
+
owner: suggestion.owner,
|
|
39639
|
+
source: "suggested",
|
|
39640
|
+
evidence: suggestion.evidence
|
|
39641
|
+
});
|
|
39642
|
+
continue;
|
|
39643
|
+
}
|
|
39644
|
+
if (suggestion.status !== "declared") {
|
|
39645
|
+
skipped.push({
|
|
39646
|
+
table: suggestion.table,
|
|
39647
|
+
operation: suggestion.operation,
|
|
39648
|
+
reason: suggestion.status === "ambiguous" ? "ambiguous evidence; choose --owner explicitly" : "no ownership evidence; choose --owner explicitly"
|
|
39649
|
+
});
|
|
39650
|
+
}
|
|
39651
|
+
}
|
|
39652
|
+
return { changes, skipped };
|
|
39653
|
+
}
|
|
39654
|
+
function propertyNameMatches(property, name) {
|
|
39655
|
+
return (ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)) && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) && property.name.text === name;
|
|
39656
|
+
}
|
|
39657
|
+
function staticProperty(object, name) {
|
|
39658
|
+
const properties = object.properties.filter((property) => propertyNameMatches(property, name));
|
|
39659
|
+
if (properties.length > 1)
|
|
39660
|
+
throw new Error(`数据库模块存在重复 '${name}' 属性`);
|
|
39661
|
+
return properties[0] && ts.isPropertyAssignment(properties[0]) ? properties[0] : undefined;
|
|
39662
|
+
}
|
|
39663
|
+
function staticPropertyValue(object, name) {
|
|
39664
|
+
const assignment = staticProperty(object, name);
|
|
39665
|
+
if (assignment)
|
|
39666
|
+
return assignment.initializer;
|
|
39667
|
+
const shorthand = object.properties.filter((property) => ts.isShorthandPropertyAssignment(property) && propertyNameMatches(property, name));
|
|
39668
|
+
if (shorthand.length > 1)
|
|
39669
|
+
throw new Error(`数据库模块存在重复 '${name}' 属性`);
|
|
39670
|
+
return shorthand[0] && ts.isIdentifier(shorthand[0].name) ? shorthand[0].name : undefined;
|
|
39671
|
+
}
|
|
39672
|
+
function unwrapStaticExpression(expression) {
|
|
39673
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression)) {
|
|
39674
|
+
return unwrapStaticExpression(expression.expression);
|
|
39675
|
+
}
|
|
39676
|
+
return expression;
|
|
39677
|
+
}
|
|
39678
|
+
function staticBindings(source) {
|
|
39679
|
+
const bindings = new Map;
|
|
39680
|
+
const visit = (node) => {
|
|
39681
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer !== undefined) {
|
|
39682
|
+
bindings.set(node.name.text, node.initializer);
|
|
39683
|
+
}
|
|
39684
|
+
ts.forEachChild(node, visit);
|
|
39685
|
+
};
|
|
39686
|
+
visit(source);
|
|
39687
|
+
return bindings;
|
|
39688
|
+
}
|
|
39689
|
+
function resolveStaticExpression(expression, bindings, seen = new Set) {
|
|
39690
|
+
if (!expression)
|
|
39691
|
+
return;
|
|
39692
|
+
const unwrapped = unwrapStaticExpression(expression);
|
|
39693
|
+
if (!ts.isIdentifier(unwrapped) || seen.has(unwrapped.text))
|
|
39694
|
+
return unwrapped;
|
|
39695
|
+
const binding = bindings.get(unwrapped.text);
|
|
39696
|
+
if (!binding)
|
|
39697
|
+
return unwrapped;
|
|
39698
|
+
const nextSeen = new Set(seen);
|
|
39699
|
+
nextSeen.add(unwrapped.text);
|
|
39700
|
+
return resolveStaticExpression(binding, bindings, nextSeen);
|
|
39701
|
+
}
|
|
39702
|
+
function exportedModuleObjects(source, bindings) {
|
|
39703
|
+
const result = new Set;
|
|
39704
|
+
const factoryNames = new Set(["defineDatabaseModule"]);
|
|
39705
|
+
for (const statement of source.statements) {
|
|
39706
|
+
if (!ts.isImportDeclaration(statement) || !statement.importClause || !statement.importClause.namedBindings || !ts.isNamedImports(statement.importClause.namedBindings)) {
|
|
39707
|
+
continue;
|
|
39708
|
+
}
|
|
39709
|
+
for (const element of statement.importClause.namedBindings.elements) {
|
|
39710
|
+
const imported = element.propertyName?.text ?? element.name.text;
|
|
39711
|
+
if (imported === "defineDatabaseModule")
|
|
39712
|
+
factoryNames.add(element.name.text);
|
|
39713
|
+
}
|
|
39714
|
+
}
|
|
39715
|
+
const addExpression = (expression) => {
|
|
39716
|
+
const resolved = resolveStaticExpression(expression, bindings);
|
|
39717
|
+
if (!resolved)
|
|
39718
|
+
return;
|
|
39719
|
+
if (ts.isObjectLiteralExpression(resolved)) {
|
|
39720
|
+
result.add(resolved);
|
|
39721
|
+
return;
|
|
39722
|
+
}
|
|
39723
|
+
if (ts.isArrayLiteralExpression(resolved)) {
|
|
39724
|
+
for (const element of resolved.elements) {
|
|
39725
|
+
if (!ts.isExpression(element))
|
|
39726
|
+
continue;
|
|
39727
|
+
addExpression(element);
|
|
39728
|
+
}
|
|
39729
|
+
return;
|
|
39730
|
+
}
|
|
39731
|
+
if (ts.isCallExpression(resolved) && ts.isIdentifier(resolved.expression) && factoryNames.has(resolved.expression.text)) {
|
|
39732
|
+
addExpression(resolved.arguments[0]);
|
|
39733
|
+
}
|
|
39734
|
+
};
|
|
39735
|
+
for (const statement of source.statements) {
|
|
39736
|
+
if (ts.isExportAssignment(statement)) {
|
|
39737
|
+
addExpression(statement.expression);
|
|
39738
|
+
continue;
|
|
39739
|
+
}
|
|
39740
|
+
if (ts.isExportDeclaration(statement)) {
|
|
39741
|
+
if (!statement.exportClause || !ts.isNamedExports(statement.exportClause))
|
|
39742
|
+
continue;
|
|
39743
|
+
for (const element of statement.exportClause.elements) {
|
|
39744
|
+
if ((element.name.text === "modules" || element.propertyName?.text === "modules") && ts.isIdentifier(element.name)) {
|
|
39745
|
+
addExpression(bindings.get(element.propertyName?.text ?? element.name.text));
|
|
39746
|
+
}
|
|
39747
|
+
}
|
|
39748
|
+
continue;
|
|
39749
|
+
}
|
|
39750
|
+
if (!ts.isVariableStatement(statement) || !statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
39751
|
+
continue;
|
|
39752
|
+
}
|
|
39753
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
39754
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === "modules") {
|
|
39755
|
+
addExpression(declaration.initializer);
|
|
39756
|
+
}
|
|
39757
|
+
}
|
|
39758
|
+
}
|
|
39759
|
+
return [...result];
|
|
39760
|
+
}
|
|
39761
|
+
async function parseSource(file, content) {
|
|
39762
|
+
const source = await ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
39763
|
+
const diagnostics = await ts.transpileModule(content, {
|
|
39764
|
+
fileName: file,
|
|
39765
|
+
reportDiagnostics: true,
|
|
39766
|
+
compilerOptions: { target: ts.ScriptTarget.ESNext }
|
|
39767
|
+
});
|
|
39768
|
+
if (diagnostics.diagnostics?.some((item) => item.category === ts.DiagnosticCategory.Error)) {
|
|
39769
|
+
throw new Error(`数据库模块源文件语法无效: ${file}`);
|
|
39770
|
+
}
|
|
39771
|
+
return source;
|
|
39772
|
+
}
|
|
39773
|
+
async function findModuleObjects(file, content) {
|
|
39774
|
+
const source = await parseSource(file, content);
|
|
39775
|
+
const bindings = staticBindings(source);
|
|
39776
|
+
const result = [];
|
|
39777
|
+
for (const object of exportedModuleObjects(source, bindings)) {
|
|
39778
|
+
const name = resolveStaticExpression(staticPropertyValue(object, "name"), bindings);
|
|
39779
|
+
const tables = resolveStaticExpression(staticPropertyValue(object, "tables"), bindings);
|
|
39780
|
+
if (name && ts.isStringLiteral(name) && tables && ts.isArrayLiteralExpression(tables)) {
|
|
39781
|
+
result.push({ name: name.text, object });
|
|
39782
|
+
}
|
|
39783
|
+
}
|
|
39784
|
+
return result;
|
|
39785
|
+
}
|
|
39786
|
+
function lineIndent(source, position) {
|
|
39787
|
+
const lineStart = source.lastIndexOf(`
|
|
39788
|
+
`, position - 1) + 1;
|
|
39789
|
+
return source.slice(lineStart, position).match(/^[ \t]*/)?.[0] ?? "";
|
|
39790
|
+
}
|
|
39791
|
+
function entryText(entry) {
|
|
39792
|
+
return `{ table: ${JSON.stringify(entry.table)}, operation: ${JSON.stringify(entry.operation)}, owner: ${JSON.stringify(entry.owner)} }`;
|
|
39793
|
+
}
|
|
39794
|
+
async function editOperationOwnershipSource(file, original, changes) {
|
|
39795
|
+
const modules = await findModuleObjects(file, original);
|
|
39796
|
+
const edits = [];
|
|
39797
|
+
for (const group of new Set(changes.map((change) => change.module))) {
|
|
39798
|
+
const moduleChanges = changes.filter((change) => change.module === group);
|
|
39799
|
+
const matchingModules = modules.filter((module) => module.name === group);
|
|
39800
|
+
if (matchingModules.length !== 1) {
|
|
39801
|
+
throw new Error(matchingModules.length === 0 ? `源文件中找不到数据库模块: ${group}` : `源文件中数据库模块名称不唯一: ${group}`);
|
|
39802
|
+
}
|
|
39803
|
+
const moduleNode = matchingModules[0];
|
|
39804
|
+
const ownership = staticProperty(moduleNode.object, "operationOwnership");
|
|
39805
|
+
const ownershipValue = staticPropertyValue(moduleNode.object, "operationOwnership");
|
|
39806
|
+
if (ownership === undefined && ownershipValue !== undefined) {
|
|
39807
|
+
throw new Error(`模块 ${group} 的 operationOwnership 必须是静态数组`);
|
|
39808
|
+
}
|
|
39809
|
+
const objectIndent = lineIndent(original, moduleNode.object.getStart());
|
|
39810
|
+
const propertyIndent = `${objectIndent} `;
|
|
39811
|
+
const values = moduleChanges.map(entryText);
|
|
39812
|
+
if (ownership) {
|
|
39813
|
+
if (!ts.isArrayLiteralExpression(ownership.initializer)) {
|
|
39814
|
+
throw new Error(`模块 ${group} 的 operationOwnership 必须是静态数组`);
|
|
39815
|
+
}
|
|
39816
|
+
const arrayIndent = lineIndent(original, ownership.getStart());
|
|
39817
|
+
const entryIndent = `${arrayIndent} `;
|
|
39818
|
+
const existing = ownership.initializer.elements.map((element) => original.slice(element.getStart(), element.end).trim());
|
|
39819
|
+
const all = [...existing, ...values];
|
|
39820
|
+
const replacement = `[
|
|
39821
|
+
${all.map((value) => `${entryIndent}${value}`).join(`,
|
|
39822
|
+
`)}
|
|
39823
|
+
${arrayIndent}]`;
|
|
39824
|
+
edits.push({
|
|
39825
|
+
start: ownership.initializer.getStart(),
|
|
39826
|
+
end: ownership.initializer.end,
|
|
39827
|
+
text: replacement
|
|
39828
|
+
});
|
|
39829
|
+
continue;
|
|
39830
|
+
}
|
|
39831
|
+
const hasProperties = moduleNode.object.properties.length > 0;
|
|
39832
|
+
const separator = hasProperties && !moduleNode.object.properties.hasTrailingComma ? "," : "";
|
|
39833
|
+
const replacement = `${separator}
|
|
39834
|
+
${propertyIndent}operationOwnership: [
|
|
39835
|
+
${values.map((value) => `${propertyIndent} ${value}`).join(`,
|
|
39836
|
+
`)}
|
|
39837
|
+
${propertyIndent}]
|
|
39838
|
+
${objectIndent}`;
|
|
39839
|
+
edits.push({
|
|
39840
|
+
start: moduleNode.object.end - 1,
|
|
39841
|
+
end: moduleNode.object.end - 1,
|
|
39842
|
+
text: replacement
|
|
39843
|
+
});
|
|
39844
|
+
}
|
|
39845
|
+
return edits.sort((left, right) => right.start - left.start).reduce((content, edit) => content.slice(0, edit.start) + edit.text + content.slice(edit.end), original);
|
|
39846
|
+
}
|
|
39847
|
+
async function runOperationOwnershipSuggest(args, root) {
|
|
39848
|
+
const { modules, selected } = await selectedDatabaseModules(args, root);
|
|
39849
|
+
return textResult3(JSON.stringify(ownershipSuggestionReport(modules, selected), null, 2));
|
|
39850
|
+
}
|
|
39851
|
+
async function runOperationOwnershipAdopt(args, root) {
|
|
39852
|
+
const { modules, selected, modulePath } = await selectedDatabaseModules(args, root);
|
|
39853
|
+
const { changes, skipped } = adoptionEntries(args, modules, selected);
|
|
39854
|
+
const stat = await lstat5(modulePath);
|
|
39855
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
39856
|
+
throw new Error(`模块文件必须是普通文件: ${modulePath}`);
|
|
39857
|
+
const original = await readFile7(modulePath, "utf8");
|
|
39858
|
+
const sourceHash = createHash10("sha256").update(original).digest("hex");
|
|
39859
|
+
const updated = changes.length > 0 ? await editOperationOwnershipSource(modulePath, original, changes) : original;
|
|
39860
|
+
const mode = args.write === true ? "write" : "preview";
|
|
39861
|
+
if (args.write === true && updated !== original) {
|
|
39862
|
+
if (await readFile7(modulePath, "utf8") !== original) {
|
|
39863
|
+
throw new Error("模块文件在 adopt 期间发生变化,请重新执行 suggest");
|
|
39864
|
+
}
|
|
39865
|
+
const temporary = `${modulePath}.supacloud-ownership-${randomUUID3()}`;
|
|
39866
|
+
try {
|
|
39867
|
+
await writeFile7(temporary, updated, { encoding: "utf8", flag: "wx", mode: stat.mode });
|
|
39868
|
+
await rename4(temporary, modulePath);
|
|
39869
|
+
} finally {
|
|
39870
|
+
await unlink2(temporary).catch(() => {});
|
|
39871
|
+
}
|
|
39872
|
+
}
|
|
39873
|
+
const report = {
|
|
39874
|
+
version: 1,
|
|
39875
|
+
scope: "operation-ownership",
|
|
39876
|
+
action: "adopt",
|
|
39877
|
+
mode,
|
|
39878
|
+
moduleFile: modulePath,
|
|
39879
|
+
sourceHash,
|
|
39880
|
+
changes,
|
|
39881
|
+
skipped
|
|
39882
|
+
};
|
|
39883
|
+
return textResult3(JSON.stringify(report, null, 2), changes.length === 0 && skipped.length > 0 ? false : undefined);
|
|
39884
|
+
}
|
|
39508
39885
|
async function collectLintIssues(args, root) {
|
|
39509
39886
|
const modules = await loadDatabaseModules(root, args.module_file);
|
|
39510
39887
|
const selected = args.module ? modules.filter((module) => module.name === args.module) : modules;
|
|
@@ -39660,6 +40037,11 @@ function remoteModuleManifest(modules) {
|
|
|
39660
40037
|
object: grant.object,
|
|
39661
40038
|
privilege: grant.privilege,
|
|
39662
40039
|
role: grant.role
|
|
40040
|
+
})),
|
|
40041
|
+
operationOwnership: (module.operationOwnership ?? []).map((ownership) => ({
|
|
40042
|
+
table: ownership.table,
|
|
40043
|
+
operation: ownership.operation,
|
|
40044
|
+
owner: ownership.owner
|
|
39663
40045
|
}))
|
|
39664
40046
|
}));
|
|
39665
40047
|
}
|
|
@@ -39727,12 +40109,16 @@ function registerDbGovernanceTools(server, options = {}) {
|
|
|
39727
40109
|
const environment = options.environment || process.env;
|
|
39728
40110
|
const fallbackRoot = options.currentWorkingDirectory || process.cwd();
|
|
39729
40111
|
const liteSpawn = options.liteSpawn || defaultLiteSpawn;
|
|
39730
|
-
registerTool(server, "db", "Database governance (@supacloud/db): inspect, reverse-adopt, diff, plan and apply through explicit source and migration boundaries. Actions: context, lint, explain, module_check, reverse, diff, plan, apply, role_check, role_sql", {
|
|
39731
|
-
action: withDescription(stringEnum2(["context", "lint", "check", "explain", "module_check", "reverse", "diff", "plan", "apply", "role_check", "role_sql"]), "Database governance action"),
|
|
40112
|
+
registerTool(server, "db", "Database governance (@supacloud/db): inspect, reverse-adopt, diff, plan and apply through explicit source and migration boundaries. Actions: context, lint, check, explain, module_check, operation-ownership suggest|adopt, reverse, diff, plan, apply, role_check, role_sql", {
|
|
40113
|
+
action: withDescription(stringEnum2(["context", "lint", "check", "explain", "module_check", "operation-ownership", "reverse", "diff", "plan", "apply", "role_check", "role_sql"]), "Database governance action"),
|
|
40114
|
+
operation_action: optional(stringEnum2(["suggest", "adopt"]), "[operation-ownership] Nested action"),
|
|
39732
40115
|
module: optional(String2(), "[context/lint] Only select this manifest module (default: all)"),
|
|
39733
40116
|
root: optional(String2(), "[*] Project root (default: current directory)"),
|
|
39734
40117
|
module_file: optional(String2(), "[*] File exporting defineDatabaseModule(...) (default: <root>/db/modules.ts)"),
|
|
39735
|
-
target: optional(String2(), "[context/explain] Policy / function / table name
|
|
40118
|
+
target: optional(String2(), "[context/explain/operation-ownership] Policy / function / table name; adopt uses a table"),
|
|
40119
|
+
operation: optional(stringEnum2(["select", "insert", "update", "delete"]), "[operation-ownership adopt] Table operation for explicit adoption"),
|
|
40120
|
+
owner: optional(stringEnum2(["postgrest-data-api", "durable-command", "governed-sql-rpc", "legacy-rpc"]), "[operation-ownership adopt] Explicit owner; required for ambiguous/unknown operations"),
|
|
40121
|
+
write: optional(Boolean2(), "[operation-ownership adopt] Write the previewed ownership declarations (default: preview only)"),
|
|
39736
40122
|
database_url: optional(String2(), "[module_check] Postgres connection URL (default: DATABASE_URL)"),
|
|
39737
40123
|
schema: optional(String2(), "[module_check] Comma-separated schemas to inspect (default: public)"),
|
|
39738
40124
|
lite: optional(Boolean2(), "[module_check] Reconcile against a local SupaCloud Lite project (runs supacloud-lite db check)"),
|
|
@@ -39760,6 +40146,10 @@ function registerDbGovernanceTools(server, options = {}) {
|
|
|
39760
40146
|
return runExplain2(request, root);
|
|
39761
40147
|
case "module_check":
|
|
39762
40148
|
return runModuleCheckAction(request, root, environment, liteSpawn, options.liteBinary, options);
|
|
40149
|
+
case "operation-ownership": {
|
|
40150
|
+
const operationAction = requireOwnershipAction(request);
|
|
40151
|
+
return operationAction === "suggest" ? runOperationOwnershipSuggest(request, root) : runOperationOwnershipAdopt(request, root);
|
|
40152
|
+
}
|
|
39763
40153
|
case "role_check":
|
|
39764
40154
|
if (request.remote)
|
|
39765
40155
|
return runRoleCheckRemote(request, options);
|
|
@@ -39791,7 +40181,7 @@ init_build();
|
|
|
39791
40181
|
init_project_ref();
|
|
39792
40182
|
init_schema7();
|
|
39793
40183
|
init_tool_server();
|
|
39794
|
-
import { randomUUID as
|
|
40184
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
39795
40185
|
import { readFileSync as readFileSync11, statSync as statSync9 } from "node:fs";
|
|
39796
40186
|
import { resolve as resolve24 } from "node:path";
|
|
39797
40187
|
import { isDeepStrictEqual } from "node:util";
|
|
@@ -40101,7 +40491,7 @@ function readOnlyResult2() {
|
|
|
40101
40491
|
}
|
|
40102
40492
|
function createRequest(args, environment) {
|
|
40103
40493
|
return {
|
|
40104
|
-
request_id:
|
|
40494
|
+
request_id: randomUUID4(),
|
|
40105
40495
|
name: requiredName(args, "create"),
|
|
40106
40496
|
slug: requiredSlug(args, "create"),
|
|
40107
40497
|
cron: requiredCron(args, "create"),
|
|
@@ -40163,7 +40553,7 @@ function updateRequest(args, environment) {
|
|
|
40163
40553
|
throw new Error("Scheduled Function update requires at least one field");
|
|
40164
40554
|
}
|
|
40165
40555
|
return {
|
|
40166
|
-
request_id:
|
|
40556
|
+
request_id: randomUUID4(),
|
|
40167
40557
|
expected_updated_at: expectedUpdatedAt,
|
|
40168
40558
|
...mutationFields
|
|
40169
40559
|
};
|
|
@@ -40269,7 +40659,7 @@ init_build();
|
|
|
40269
40659
|
init_schema7();
|
|
40270
40660
|
init_tool_server();
|
|
40271
40661
|
init_release_contract();
|
|
40272
|
-
import { createHash as
|
|
40662
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
40273
40663
|
import { existsSync as existsSync16, mkdirSync as mkdirSync5, readdirSync as readdirSync5, readFileSync as readFileSync12, writeFileSync as writeFileSync4 } from "node:fs";
|
|
40274
40664
|
import { dirname as dirname12, join as join19, relative as relative10, resolve as resolve25 } from "node:path";
|
|
40275
40665
|
var SAFE_PROJECT_REF = /^[A-Za-z0-9_-]{1,64}$/;
|
|
@@ -40512,7 +40902,7 @@ function genericScopedReleaseScopeJson(scope) {
|
|
|
40512
40902
|
return JSON.stringify(canonicalValue(scope));
|
|
40513
40903
|
}
|
|
40514
40904
|
function genericScopedReleaseScopeSha256(scope) {
|
|
40515
|
-
return
|
|
40905
|
+
return createHash11("sha256").update(genericScopedReleaseScopeJson(scope)).digest("hex");
|
|
40516
40906
|
}
|
|
40517
40907
|
function scopeEnvironmentId(scope, action) {
|
|
40518
40908
|
const environmentId = isRecord6(scope) ? scope.targetEnvironmentId : undefined;
|
|
@@ -41134,9 +41524,9 @@ init_frontend_release_control();
|
|
|
41134
41524
|
init_deployment_upgrade();
|
|
41135
41525
|
init_project_deployment();
|
|
41136
41526
|
init_developer_experience_tools();
|
|
41137
|
-
import { access, lstat as
|
|
41527
|
+
import { access, lstat as lstat6, mkdtemp as mkdtemp2, opendir, readFile as readFile9, realpath as realpath5, rm as rm3, writeFile as writeFile9 } from "node:fs/promises";
|
|
41138
41528
|
import { spawn as spawn2 } from "node:child_process";
|
|
41139
|
-
import { createHash as
|
|
41529
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
41140
41530
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
41141
41531
|
import { basename as basename9, dirname as dirname14, join as join21, relative as relative11, resolve as resolve28, sep as sep6 } from "node:path";
|
|
41142
41532
|
var MAX_SOURCE_BYTES = 256 * 1024 * 1024;
|
|
@@ -41184,7 +41574,7 @@ function frontendDeployment(candidate) {
|
|
|
41184
41574
|
}
|
|
41185
41575
|
async function readJson(path) {
|
|
41186
41576
|
try {
|
|
41187
|
-
return JSON.parse(await
|
|
41577
|
+
return JSON.parse(await readFile9(path, "utf8"));
|
|
41188
41578
|
} catch (error) {
|
|
41189
41579
|
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
41190
41580
|
return null;
|
|
@@ -41485,7 +41875,7 @@ async function runBuild(command, cwd, environment, json) {
|
|
|
41485
41875
|
});
|
|
41486
41876
|
}
|
|
41487
41877
|
async function collectArchiveFiles(root) {
|
|
41488
|
-
const rootStat = await
|
|
41878
|
+
const rootStat = await lstat6(root).catch(() => null);
|
|
41489
41879
|
if (!rootStat?.isDirectory() || rootStat.isSymbolicLink()) {
|
|
41490
41880
|
throw new Error(`Frontend output directory does not exist or is not a regular directory: ${root}`);
|
|
41491
41881
|
}
|
|
@@ -41497,7 +41887,7 @@ async function collectArchiveFiles(root) {
|
|
|
41497
41887
|
entries.sort((left, right) => left.name.localeCompare(right.name, "en"));
|
|
41498
41888
|
for (const entry of entries) {
|
|
41499
41889
|
const path = join21(directory, entry.name);
|
|
41500
|
-
const stats = await
|
|
41890
|
+
const stats = await lstat6(path);
|
|
41501
41891
|
if (stats.isSymbolicLink())
|
|
41502
41892
|
throw new Error(`Frontend output cannot contain symbolic links: ${path}`);
|
|
41503
41893
|
if (stats.isDirectory())
|
|
@@ -41515,15 +41905,15 @@ async function collectArchiveFiles(root) {
|
|
|
41515
41905
|
const files = new Map;
|
|
41516
41906
|
const digests = [];
|
|
41517
41907
|
for (const path of paths) {
|
|
41518
|
-
const data = new Uint8Array(await
|
|
41908
|
+
const data = new Uint8Array(await readFile9(path));
|
|
41519
41909
|
bytes += data.byteLength;
|
|
41520
41910
|
if (bytes > MAX_SOURCE_BYTES)
|
|
41521
41911
|
throw new Error(`Frontend output exceeds ${MAX_SOURCE_BYTES} bytes`);
|
|
41522
41912
|
const archivePath = relative11(root, path).split(sep6).join("/");
|
|
41523
41913
|
files.set(archivePath, data);
|
|
41524
|
-
digests.push({ path: archivePath, size: data.byteLength, sha256:
|
|
41914
|
+
digests.push({ path: archivePath, size: data.byteLength, sha256: createHash12("sha256").update(data).digest("hex") });
|
|
41525
41915
|
}
|
|
41526
|
-
const tree =
|
|
41916
|
+
const tree = createHash12("sha256");
|
|
41527
41917
|
for (const file of digests.sort((left, right) => left.path.localeCompare(right.path))) {
|
|
41528
41918
|
const pathBytes = Buffer.from(file.path, "utf8");
|
|
41529
41919
|
const frame = Buffer.alloc(12);
|
|
@@ -41538,8 +41928,8 @@ async function createCollectedFrontendArchive(outputDirectory, collected) {
|
|
|
41538
41928
|
const archivePath = join21(temporaryDirectory, `${basename9(outputDirectory)}.tar.zst`);
|
|
41539
41929
|
try {
|
|
41540
41930
|
const archiveBytes = await createFrontendTarZstd(collected.files);
|
|
41541
|
-
await
|
|
41542
|
-
const sha256 =
|
|
41931
|
+
await writeFile9(archivePath, archiveBytes);
|
|
41932
|
+
const sha256 = createHash12("sha256").update(archiveBytes).digest("hex");
|
|
41543
41933
|
return {
|
|
41544
41934
|
archivePath,
|
|
41545
41935
|
sha256,
|
|
@@ -41556,7 +41946,7 @@ async function createCollectedFrontendArchive(outputDirectory, collected) {
|
|
|
41556
41946
|
}
|
|
41557
41947
|
async function publishConfiguredFrontend(http, projectRef, configRoot, target, skipBuild, json, environmentVariables) {
|
|
41558
41948
|
const projectDirectory = target.root;
|
|
41559
|
-
const targetState = await
|
|
41949
|
+
const targetState = await lstat6(projectDirectory).catch(() => null);
|
|
41560
41950
|
if (!targetState?.isDirectory() || targetState.isSymbolicLink()) {
|
|
41561
41951
|
throw new Error(`Deploy target '${target.name}' root is not a regular directory: ${projectDirectory}`);
|
|
41562
41952
|
}
|
|
@@ -41666,9 +42056,9 @@ init_build();
|
|
|
41666
42056
|
init_schema7();
|
|
41667
42057
|
init_tool_server();
|
|
41668
42058
|
import { existsSync as existsSync19 } from "node:fs";
|
|
41669
|
-
import { readFile as
|
|
42059
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
41670
42060
|
import { readdir as readdir8 } from "node:fs/promises";
|
|
41671
|
-
import { createHash as
|
|
42061
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
41672
42062
|
import { join as join22, resolve as resolve29 } from "node:path";
|
|
41673
42063
|
import { compileProject as compileProject2 } from "@supacloud/compiler";
|
|
41674
42064
|
var SAFE_TOKEN = /^[A-Za-z0-9._:@/+,-]+$/;
|
|
@@ -41701,7 +42091,7 @@ async function readProjectConfig(root) {
|
|
|
41701
42091
|
if (!existsSync19(file))
|
|
41702
42092
|
return {};
|
|
41703
42093
|
try {
|
|
41704
|
-
const parsed = JSON.parse(await
|
|
42094
|
+
const parsed = JSON.parse(await readFile10(file, "utf8"));
|
|
41705
42095
|
if (parsed && typeof parsed === "object" && "dev" in parsed && parsed.dev && typeof parsed.dev === "object" && "database" in parsed.dev) {
|
|
41706
42096
|
throw new Error("dev.database was removed; use db:plan/db:apply through the Management API");
|
|
41707
42097
|
}
|
|
@@ -41727,10 +42117,10 @@ async function sourceFingerprint(root) {
|
|
|
41727
42117
|
}
|
|
41728
42118
|
};
|
|
41729
42119
|
await visit(root);
|
|
41730
|
-
const hash =
|
|
42120
|
+
const hash = createHash13("sha256");
|
|
41731
42121
|
for (const file of files) {
|
|
41732
42122
|
hash.update(file.slice(root.length).replace(/\\/g, "/"));
|
|
41733
|
-
hash.update(await
|
|
42123
|
+
hash.update(await readFile10(file));
|
|
41734
42124
|
}
|
|
41735
42125
|
return hash.digest("hex");
|
|
41736
42126
|
}
|
|
@@ -41900,7 +42290,7 @@ init_schema7();
|
|
|
41900
42290
|
init_tool_server();
|
|
41901
42291
|
init_configuration_tools();
|
|
41902
42292
|
import { existsSync as existsSync20 } from "node:fs";
|
|
41903
|
-
import { mkdir as mkdir9, readdir as readdir9, readFile as
|
|
42293
|
+
import { mkdir as mkdir9, readdir as readdir9, readFile as readFile11, writeFile as writeFile10 } from "node:fs/promises";
|
|
41904
42294
|
import { dirname as dirname15, join as join23, resolve as resolve30 } from "node:path";
|
|
41905
42295
|
var initToolSchema2 = {
|
|
41906
42296
|
root: optional(String2(), "Project directory to initialize (default: current directory)"),
|
|
@@ -41957,7 +42347,7 @@ async function readPackageManifest2(root) {
|
|
|
41957
42347
|
if (!existsSync20(path))
|
|
41958
42348
|
return {};
|
|
41959
42349
|
try {
|
|
41960
|
-
const parsed = JSON.parse(await
|
|
42350
|
+
const parsed = JSON.parse(await readFile11(path, "utf8"));
|
|
41961
42351
|
const value = record9(parsed);
|
|
41962
42352
|
if (!value)
|
|
41963
42353
|
throw new Error("package.json must contain an object");
|
|
@@ -41975,7 +42365,7 @@ async function readPackageManifest2(root) {
|
|
|
41975
42365
|
}
|
|
41976
42366
|
async function writeNewFile2(path, content) {
|
|
41977
42367
|
try {
|
|
41978
|
-
await
|
|
42368
|
+
await writeFile10(path, content, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
41979
42369
|
return true;
|
|
41980
42370
|
} catch (error) {
|
|
41981
42371
|
if (error instanceof Error && "code" in error && error.code === "EEXIST")
|
|
@@ -41985,7 +42375,7 @@ async function writeNewFile2(path, content) {
|
|
|
41985
42375
|
}
|
|
41986
42376
|
async function ensureGitignore2(root) {
|
|
41987
42377
|
const path = join23(root, ".gitignore");
|
|
41988
|
-
const existing = existsSync20(path) ? await
|
|
42378
|
+
const existing = existsSync20(path) ? await readFile11(path, "utf8") : "";
|
|
41989
42379
|
const required = [".env.supacloud.*", "!.env.supacloud.*.example"];
|
|
41990
42380
|
const missing = required.filter((entry) => !existing.split(/\r?\n/).includes(entry));
|
|
41991
42381
|
if (missing.length === 0)
|
|
@@ -41993,7 +42383,7 @@ async function ensureGitignore2(root) {
|
|
|
41993
42383
|
const prefix = existing.length > 0 && !existing.endsWith(`
|
|
41994
42384
|
`) ? `${existing}
|
|
41995
42385
|
` : existing;
|
|
41996
|
-
await
|
|
42386
|
+
await writeFile10(path, `${prefix}${missing.join(`
|
|
41997
42387
|
`)}
|
|
41998
42388
|
`, "utf8");
|
|
41999
42389
|
return true;
|
|
@@ -42016,7 +42406,7 @@ async function initializeProject2(request, options = {}) {
|
|
|
42016
42406
|
};
|
|
42017
42407
|
const created = [];
|
|
42018
42408
|
try {
|
|
42019
|
-
await
|
|
42409
|
+
await writeFile10(configPath, `${JSON.stringify(config, null, 2)}
|
|
42020
42410
|
`, {
|
|
42021
42411
|
encoding: "utf8",
|
|
42022
42412
|
flag: "wx",
|
|
@@ -42116,7 +42506,7 @@ async function inspectProfile(profile) {
|
|
|
42116
42506
|
environmentName: profile.name
|
|
42117
42507
|
});
|
|
42118
42508
|
const status = statusMissing(context);
|
|
42119
|
-
const configText = await
|
|
42509
|
+
const configText = await readFile11(join23(dirname15(profile.path), "supacloud.json"), "utf8").catch((error) => {
|
|
42120
42510
|
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
42121
42511
|
return "{}";
|
|
42122
42512
|
throw error;
|
|
@@ -42226,7 +42616,7 @@ init_build();
|
|
|
42226
42616
|
init_schema7();
|
|
42227
42617
|
init_tool_server();
|
|
42228
42618
|
import { existsSync as existsSync21 } from "node:fs";
|
|
42229
|
-
import { mkdir as mkdir10, readFile as
|
|
42619
|
+
import { mkdir as mkdir10, readFile as readFile12, writeFile as writeFile11 } from "node:fs/promises";
|
|
42230
42620
|
import { join as join24, resolve as resolve31 } from "node:path";
|
|
42231
42621
|
var MANAGEMENT_CONFIGURATION_KEYS = ["SUPACLOUD_API_URL", "SUPACLOUD_API_TOKEN", "SUPACLOUD_PROJECT_REF"];
|
|
42232
42622
|
var APPLICATION_CONFIGURATION_KEYS = ["SUPABASE_URL", "SUPABASE_SERVICE_ROLE_KEY", "SUPACLOUD_PROJECT_REF"];
|
|
@@ -42285,14 +42675,14 @@ function parseEnvironment2(content) {
|
|
|
42285
42675
|
async function readJsonObject2(path) {
|
|
42286
42676
|
if (!existsSync21(path))
|
|
42287
42677
|
return {};
|
|
42288
|
-
const parsed = JSON.parse(await
|
|
42678
|
+
const parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
42289
42679
|
const value = record10(parsed);
|
|
42290
42680
|
if (!value)
|
|
42291
42681
|
throw new Error(`${path} must contain a JSON object`);
|
|
42292
42682
|
return value;
|
|
42293
42683
|
}
|
|
42294
42684
|
async function writeJsonObject2(path, value) {
|
|
42295
|
-
await
|
|
42685
|
+
await writeFile11(path, `${JSON.stringify(value, null, 2)}
|
|
42296
42686
|
`, { encoding: "utf8", mode: 420 });
|
|
42297
42687
|
}
|
|
42298
42688
|
function contextFromConfig2(config) {
|
|
@@ -42422,7 +42812,7 @@ async function runConfiguration(args, options) {
|
|
|
42422
42812
|
const root = resolve31(typeof args.root === "string" ? args.root : options.cwd ?? process.cwd());
|
|
42423
42813
|
const config = await readJsonObject2(join24(root, "supacloud.json"));
|
|
42424
42814
|
const environment = options.activeContext?.environment || "";
|
|
42425
|
-
const profileValues = environment && existsSync21(join24(root, `.env.supacloud.${environment}`)) ? parseEnvironment2(await
|
|
42815
|
+
const profileValues = environment && existsSync21(join24(root, `.env.supacloud.${environment}`)) ? parseEnvironment2(await readFile12(join24(root, `.env.supacloud.${environment}`), "utf8")) : {};
|
|
42426
42816
|
const metadata = environment ? environmentContext2(config, environment) : {};
|
|
42427
42817
|
const values = {
|
|
42428
42818
|
...Object.fromEntries(Object.entries(metadata).filter(([, value]) => typeof value === "string")),
|
|
@@ -42467,7 +42857,7 @@ init_build();
|
|
|
42467
42857
|
init_schema7();
|
|
42468
42858
|
init_tool_server();
|
|
42469
42859
|
import { existsSync as existsSync22 } from "node:fs";
|
|
42470
|
-
import { lstat as
|
|
42860
|
+
import { lstat as lstat7, mkdir as mkdir11, readFile as readFile13, writeFile as writeFile12 } from "node:fs/promises";
|
|
42471
42861
|
import { join as join25, resolve as resolve32 } from "node:path";
|
|
42472
42862
|
var pipelineToolSchema = {
|
|
42473
42863
|
action: withDescription(stringEnum2(["connect"]), "Pipeline configuration action"),
|
|
@@ -42489,7 +42879,7 @@ function record11(value) {
|
|
|
42489
42879
|
async function readJson2(path) {
|
|
42490
42880
|
if (!existsSync22(path))
|
|
42491
42881
|
return {};
|
|
42492
|
-
const parsed = JSON.parse(await
|
|
42882
|
+
const parsed = JSON.parse(await readFile13(path, "utf8"));
|
|
42493
42883
|
return record11(parsed) ?? {};
|
|
42494
42884
|
}
|
|
42495
42885
|
function workspacePlanWorkflow(provider) {
|
|
@@ -42598,7 +42988,7 @@ ${previewSteps}`;
|
|
|
42598
42988
|
async function workspaceManifest(root) {
|
|
42599
42989
|
const path = join25(root, "supacloud.workspace.json");
|
|
42600
42990
|
try {
|
|
42601
|
-
const stat = await
|
|
42991
|
+
const stat = await lstat7(path);
|
|
42602
42992
|
if (stat.isSymbolicLink() || !stat.isFile())
|
|
42603
42993
|
return "unsafe";
|
|
42604
42994
|
return "plan";
|
|
@@ -42651,7 +43041,7 @@ async function connectPipeline(args, options = {}) {
|
|
|
42651
43041
|
}
|
|
42652
43042
|
await mkdir11(resolve32(workflowPath, ".."), { recursive: true });
|
|
42653
43043
|
const body = workspacePlanOnly ? workspacePlanWorkflow(provider) : workflow(provider, args.preview === true);
|
|
42654
|
-
await
|
|
43044
|
+
await writeFile12(workflowPath, body, { encoding: "utf8", mode: 420 });
|
|
42655
43045
|
return jsonResult5({ ...result, written: true });
|
|
42656
43046
|
}
|
|
42657
43047
|
function registerPipelineTools(server, options = {}) {
|
|
@@ -42665,9 +43055,9 @@ init_src();
|
|
|
42665
43055
|
init_schema7();
|
|
42666
43056
|
init_tool_server();
|
|
42667
43057
|
import { execFile as execFile3 } from "node:child_process";
|
|
42668
|
-
import { createHash as
|
|
43058
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
42669
43059
|
import { constants as constants3 } from "node:fs";
|
|
42670
|
-
import { lstat as
|
|
43060
|
+
import { lstat as lstat10, open as open5, readdir as readdir11, realpath as realpath8 } from "node:fs/promises";
|
|
42671
43061
|
import { isAbsolute as isAbsolute9, join as join29, relative as relative14, resolve as resolve37 } from "node:path";
|
|
42672
43062
|
import { promisify as promisify3 } from "node:util";
|
|
42673
43063
|
var execFileAsync3 = promisify3(execFile3);
|
|
@@ -42798,7 +43188,7 @@ function canonical4(value) {
|
|
|
42798
43188
|
return JSON.stringify(value) ?? "null";
|
|
42799
43189
|
}
|
|
42800
43190
|
function digest4(value) {
|
|
42801
|
-
return
|
|
43191
|
+
return createHash17("sha256").update(canonical4(value)).digest("hex");
|
|
42802
43192
|
}
|
|
42803
43193
|
function assertUniqueJsonKeys2(text) {
|
|
42804
43194
|
const invalid = () => new WorkspacePlanError2("workspace-config-invalid", "supacloud.workspace.json is not valid JSON");
|
|
@@ -42989,7 +43379,7 @@ async function pathKind2(rootReal, relativePath) {
|
|
|
42989
43379
|
for (let index = 0;index < segments.length; index += 1) {
|
|
42990
43380
|
current = join29(current, segments[index]);
|
|
42991
43381
|
try {
|
|
42992
|
-
const stat = await
|
|
43382
|
+
const stat = await lstat10(current);
|
|
42993
43383
|
if (stat.isSymbolicLink())
|
|
42994
43384
|
return "symlink";
|
|
42995
43385
|
} catch (error) {
|
|
@@ -43241,7 +43631,7 @@ async function loadGraph2(rootReal, config) {
|
|
|
43241
43631
|
if (kind !== "ok")
|
|
43242
43632
|
diagnostics.push({ code: kind === "symlink" ? "symlink-rejected" : "invalid-path", severity: "error", application_id: application.id, message: `Application root '${application.root}' is not a contained directory` });
|
|
43243
43633
|
else {
|
|
43244
|
-
const stat = await
|
|
43634
|
+
const stat = await lstat10(join29(rootReal, application.root)).catch(() => null);
|
|
43245
43635
|
if (!stat?.isDirectory())
|
|
43246
43636
|
diagnostics.push({ code: "application-root-missing", severity: "error", application_id: application.id, message: `Application root '${application.root}' is not a directory` });
|
|
43247
43637
|
}
|
|
@@ -43407,7 +43797,7 @@ async function createWorkspacePlan2(input) {
|
|
|
43407
43797
|
} catch {
|
|
43408
43798
|
return blockedPlan2(environment, "workspace-root-missing", "The workspace root does not exist");
|
|
43409
43799
|
}
|
|
43410
|
-
const rootStat = await
|
|
43800
|
+
const rootStat = await lstat10(rootReal).catch(() => null);
|
|
43411
43801
|
if (!rootStat?.isDirectory())
|
|
43412
43802
|
return blockedPlan2(environment, "workspace-root-missing", "The workspace root is not a directory");
|
|
43413
43803
|
let changedFiles;
|
|
@@ -43870,7 +44260,7 @@ async function runProjectDeployment(http, args) {
|
|
|
43870
44260
|
// package.json
|
|
43871
44261
|
var package_default = {
|
|
43872
44262
|
name: "@supacloud/cli",
|
|
43873
|
-
version: "0.
|
|
44263
|
+
version: "0.127.0",
|
|
43874
44264
|
description: "Project-scoped CLI for SupaCloud users",
|
|
43875
44265
|
type: "module",
|
|
43876
44266
|
main: "./dist/index.js",
|
|
@@ -43922,17 +44312,17 @@ var package_default = {
|
|
|
43922
44312
|
directory: "packages/cli"
|
|
43923
44313
|
},
|
|
43924
44314
|
dependencies: {
|
|
43925
|
-
"@supacloud/compiler": "^0.
|
|
44315
|
+
"@supacloud/compiler": "^0.64.0",
|
|
43926
44316
|
"@supacloud/delivery": "0.30.0",
|
|
43927
|
-
"@supacloud/db": "0.
|
|
44317
|
+
"@supacloud/db": "0.26.0",
|
|
43928
44318
|
typebox: "1.4.3"
|
|
43929
44319
|
},
|
|
43930
44320
|
overrides: {
|
|
43931
44321
|
"@supacloud/contracts": "0.16.3",
|
|
43932
44322
|
"@supacloud/delivery": "0.30.0",
|
|
43933
44323
|
"@graphql-tools/utils": "^12.0.4",
|
|
43934
|
-
"@supacloud/compiler": "^0.
|
|
43935
|
-
"@supacloud/db": "0.
|
|
44324
|
+
"@supacloud/compiler": "^0.64.0",
|
|
44325
|
+
"@supacloud/db": "0.26.0",
|
|
43936
44326
|
"deepmerge-ts": "8.0.2",
|
|
43937
44327
|
prisma: "6.19.3"
|
|
43938
44328
|
},
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { type DatabaseModule, type QueryExecutor, type ReconcileReport } from "@supacloud/db";
|
|
1
|
+
import { type DatabaseModule, type OperationOwner, type QueryExecutor, type ReconcileReport, type TableOperation } from "@supacloud/db";
|
|
2
2
|
import { type DbWorkflowAction } from "./db-workflow";
|
|
3
3
|
import { type ToolServer, type ToolResult } from "../tool-server";
|
|
4
4
|
export interface DbToolArguments {
|
|
5
|
-
action: "context" | "lint" | "check" | "explain" | "module_check" | DbWorkflowAction;
|
|
5
|
+
action: "context" | "lint" | "check" | "explain" | "module_check" | "operation-ownership" | DbWorkflowAction;
|
|
6
|
+
/** Nested action for `db operation-ownership suggest|adopt`. */
|
|
7
|
+
operation_action?: "suggest" | "adopt";
|
|
6
8
|
module?: string;
|
|
7
9
|
root?: string;
|
|
8
10
|
module_file?: string;
|
|
9
11
|
target?: string;
|
|
12
|
+
operation?: TableOperation;
|
|
13
|
+
owner?: OperationOwner;
|
|
14
|
+
write?: boolean;
|
|
10
15
|
database_url?: string;
|
|
11
16
|
schema?: string;
|
|
12
17
|
lite?: boolean;
|
|
@@ -23,10 +28,12 @@ export interface DbToolArguments {
|
|
|
23
28
|
database?: string;
|
|
24
29
|
}
|
|
25
30
|
export interface DatabaseAiContextObject {
|
|
26
|
-
kind: "table" | "policy" | "function" | "trigger" | "grant";
|
|
31
|
+
kind: "table" | "policy" | "function" | "trigger" | "grant" | "operation";
|
|
27
32
|
name: string;
|
|
28
33
|
module: string;
|
|
29
34
|
table?: string;
|
|
35
|
+
operation?: TableOperation;
|
|
36
|
+
owner?: OperationOwner;
|
|
30
37
|
source: string | null;
|
|
31
38
|
tests: string[];
|
|
32
39
|
security?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.127.0",
|
|
4
4
|
"description": "Project-scoped CLI for SupaCloud users",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"directory": "packages/cli"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@supacloud/compiler": "^0.
|
|
55
|
+
"@supacloud/compiler": "^0.64.0",
|
|
56
56
|
"@supacloud/delivery": "0.30.0",
|
|
57
|
-
"@supacloud/db": "0.
|
|
57
|
+
"@supacloud/db": "0.26.0",
|
|
58
58
|
"typebox": "1.4.3"
|
|
59
59
|
},
|
|
60
60
|
"overrides": {
|
|
61
61
|
"@supacloud/contracts": "0.16.3",
|
|
62
62
|
"@supacloud/delivery": "0.30.0",
|
|
63
63
|
"@graphql-tools/utils": "^12.0.4",
|
|
64
|
-
"@supacloud/compiler": "^0.
|
|
65
|
-
"@supacloud/db": "0.
|
|
64
|
+
"@supacloud/compiler": "^0.64.0",
|
|
65
|
+
"@supacloud/db": "0.26.0",
|
|
66
66
|
"deepmerge-ts": "8.0.2",
|
|
67
67
|
"prisma": "6.19.3"
|
|
68
68
|
},
|