@donotdev/cli 0.3.7 → 0.3.8
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/dependencies-matrix.json +41 -21
- package/dist/bin/commands/build.js +9 -1
- package/dist/bin/commands/db-check.js +135 -29
- package/dist/bin/commands/db.js +135 -29
- package/dist/bin/commands/deploy.js +83 -42
- package/dist/bin/commands/make-admin.js +9 -1
- package/dist/bin/commands/seed.js +146 -36
- package/dist/bin/commands/setup-cicd.js +9 -1
- package/dist/bin/commands/setup.js +748 -70
- package/dist/bin/commands/type-check.js +9 -1
- package/dist/bin/commands/uat.js +90 -49
- package/dist/bin/dndev.js +10 -2
- package/dist/index.js +90 -49
- package/package.json +1 -1
|
@@ -9879,11 +9879,19 @@ var init_command_registry = __esm({
|
|
|
9879
9879
|
},
|
|
9880
9880
|
{
|
|
9881
9881
|
flags: "--output-dir <dir>",
|
|
9882
|
-
description: "output directory for migrations (default: supabase/migrations)"
|
|
9882
|
+
description: "output directory for migrations (default: supabase/migrations of the app the command runs for: the nearest folder up with supabase/config.toml, or the only app with one under apps/; fails when none)"
|
|
9883
9883
|
},
|
|
9884
9884
|
{
|
|
9885
9885
|
flags: "--no-single-file",
|
|
9886
9886
|
description: "emit one migration file per entity"
|
|
9887
|
+
},
|
|
9888
|
+
{
|
|
9889
|
+
flags: "--only <collections...>",
|
|
9890
|
+
description: "emit only these collections into ONE new migration <version>_<first>[_and_more].sql (version: now, or the latest existing + 1 so it sorts last); never touches *_entity_tables.sql (for a live app adding a feature's entities; feature-owned collections accepted)"
|
|
9891
|
+
},
|
|
9892
|
+
{
|
|
9893
|
+
flags: "--app-dir <dir>",
|
|
9894
|
+
description: "app folder whose src/config/app.ts turns framework features on (their entities are included when installed; default: the app of the output dir)"
|
|
9887
9895
|
}
|
|
9888
9896
|
],
|
|
9889
9897
|
loader: "../generators/sql-generator.ts"
|
|
@@ -22740,7 +22748,7 @@ var init_supabase_function_secrets = __esm({
|
|
|
22740
22748
|
|
|
22741
22749
|
// packages/tooling/src/quality/uat/live-dump.ts
|
|
22742
22750
|
import { spawn as spawn2, spawnSync as spawnSync8 } from "node:child_process";
|
|
22743
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync3, rmSync as
|
|
22751
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync3, rmSync as rmSync3, statSync as statSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
22744
22752
|
import { dirname as dirname6, join as join5, relative as relative4 } from "node:path";
|
|
22745
22753
|
var LIVE_DB_PASSWORD_KEY;
|
|
22746
22754
|
var init_live_dump = __esm({
|
|
@@ -24022,7 +24030,8 @@ init_secrets_resolver();
|
|
|
24022
24030
|
init_type_guards();
|
|
24023
24031
|
import { execFileSync } from "node:child_process";
|
|
24024
24032
|
import { createHash as createHash2 } from "node:crypto";
|
|
24025
|
-
import { readlinkSync } from "node:fs";
|
|
24033
|
+
import { mkdtempSync, readlinkSync, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
24034
|
+
import { tmpdir } from "node:os";
|
|
24026
24035
|
var UPLOAD_BATCH_SIZE = 10;
|
|
24027
24036
|
var POLL_INTERVAL_MS = 3e3;
|
|
24028
24037
|
var POLL_MAX_ATTEMPTS = 100;
|
|
@@ -24183,7 +24192,11 @@ Add VERCEL_TOKEN to .dndev.secrets and VERCEL_PROJECT_ID to the app .env`
|
|
|
24183
24192
|
"Vercel CLI not found on PATH (needed by vercel build). Install it, or deploy with --from-git."
|
|
24184
24193
|
);
|
|
24185
24194
|
}
|
|
24186
|
-
logDryRunCommand(
|
|
24195
|
+
logDryRunCommand(
|
|
24196
|
+
"vercel",
|
|
24197
|
+
["build", "--yes", "--local-config", '<app vercel.json + installCommand "">'],
|
|
24198
|
+
appDir
|
|
24199
|
+
);
|
|
24187
24200
|
return;
|
|
24188
24201
|
}
|
|
24189
24202
|
const { token, orgId, projectId } = result.credentials;
|
|
@@ -24191,46 +24204,71 @@ Add VERCEL_TOKEN to .dndev.secrets and VERCEL_PROJECT_ID to the app .env`
|
|
|
24191
24204
|
CLI_TOOLS.VERCEL,
|
|
24192
24205
|
"Install the Vercel CLI: bun install -g vercel (or brew install vercel)"
|
|
24193
24206
|
);
|
|
24194
|
-
|
|
24195
|
-
|
|
24196
|
-
|
|
24197
|
-
|
|
24198
|
-
|
|
24199
|
-
|
|
24200
|
-
|
|
24201
|
-
|
|
24202
|
-
|
|
24203
|
-
|
|
24204
|
-
|
|
24205
|
-
|
|
24206
|
-
|
|
24207
|
-
|
|
24207
|
+
const configDir = mkdtempSync(joinPath(tmpdir(), "dndev-vercel-build-"));
|
|
24208
|
+
const localConfig = joinPath(configDir, "vercel.json");
|
|
24209
|
+
writeFileSync3(localConfig, JSON.stringify(localBuildConfig(appDir), null, 2));
|
|
24210
|
+
try {
|
|
24211
|
+
execFileSync("vercel", ["build", "--yes", "--local-config", localConfig], {
|
|
24212
|
+
cwd: appDir,
|
|
24213
|
+
stdio: "inherit",
|
|
24214
|
+
env: {
|
|
24215
|
+
...process.env,
|
|
24216
|
+
// UAT: process env wins over the app .env files in Next.js, so the UAT values are built in
|
|
24217
|
+
...uat?.publicEnv,
|
|
24218
|
+
// A deploy build: published URLs must be public (core isDeployBuild)
|
|
24219
|
+
DNDEV_DEPLOY: "1",
|
|
24220
|
+
VERCEL_TOKEN: token,
|
|
24221
|
+
VERCEL_PROJECT_ID: projectId,
|
|
24222
|
+
...orgId ? { VERCEL_ORG_ID: orgId } : {}
|
|
24223
|
+
}
|
|
24224
|
+
});
|
|
24225
|
+
} finally {
|
|
24226
|
+
rmSync2(configDir, { recursive: true, force: true });
|
|
24227
|
+
}
|
|
24228
|
+
}
|
|
24229
|
+
function localBuildConfig(appDir) {
|
|
24230
|
+
const appConfigPath = joinPath(appDir, "vercel.json");
|
|
24231
|
+
const appConfig = pathExists(appConfigPath) ? readSync(appConfigPath) : {};
|
|
24232
|
+
if (typeof appConfig !== "object" || appConfig === null || Array.isArray(appConfig)) {
|
|
24233
|
+
throw new Error(`${appConfigPath} must be a JSON object`);
|
|
24234
|
+
}
|
|
24235
|
+
return { ...appConfig, installCommand: "" };
|
|
24208
24236
|
}
|
|
24209
24237
|
async function uploadFiles(files, token, orgId) {
|
|
24210
|
-
const q = teamQuery(orgId);
|
|
24211
24238
|
for (let i2 = 0; i2 < files.length; i2 += UPLOAD_BATCH_SIZE) {
|
|
24212
24239
|
const batch = files.slice(i2, i2 + UPLOAD_BATCH_SIZE);
|
|
24213
|
-
await Promise.all(
|
|
24214
|
-
|
|
24215
|
-
|
|
24216
|
-
|
|
24217
|
-
|
|
24218
|
-
|
|
24219
|
-
|
|
24220
|
-
|
|
24221
|
-
|
|
24222
|
-
|
|
24223
|
-
|
|
24224
|
-
|
|
24225
|
-
|
|
24226
|
-
|
|
24227
|
-
|
|
24228
|
-
|
|
24229
|
-
|
|
24230
|
-
|
|
24231
|
-
|
|
24232
|
-
|
|
24233
|
-
|
|
24240
|
+
await Promise.all(batch.map((file) => uploadFile(file, token, orgId)));
|
|
24241
|
+
}
|
|
24242
|
+
}
|
|
24243
|
+
var UPLOAD_TIMEOUT_MS = 6e4;
|
|
24244
|
+
var UPLOAD_ATTEMPTS = 3;
|
|
24245
|
+
async function uploadFile(file, token, orgId, fetchImpl = fetch) {
|
|
24246
|
+
const q = teamQuery(orgId);
|
|
24247
|
+
for (let attempt = 1; ; attempt++) {
|
|
24248
|
+
let failure;
|
|
24249
|
+
let res;
|
|
24250
|
+
try {
|
|
24251
|
+
res = await fetchImpl(`${VERCEL_API}/v2/files${q}`, {
|
|
24252
|
+
method: "POST",
|
|
24253
|
+
headers: apiHeaders(token, {
|
|
24254
|
+
"Content-Type": "application/octet-stream",
|
|
24255
|
+
"x-vercel-digest": file.sha,
|
|
24256
|
+
"Content-Length": String(file.size)
|
|
24257
|
+
}),
|
|
24258
|
+
body: new Uint8Array(file.content),
|
|
24259
|
+
signal: AbortSignal.timeout(UPLOAD_TIMEOUT_MS)
|
|
24260
|
+
});
|
|
24261
|
+
} catch (error2) {
|
|
24262
|
+
failure = error2;
|
|
24263
|
+
}
|
|
24264
|
+
if (res) {
|
|
24265
|
+
if (res.ok) return;
|
|
24266
|
+
failure = formatVercelError(res.status, await res.text(), `upload file ${file.relativePath}`);
|
|
24267
|
+
if (res.status !== 429 && res.status < 500) throw failure;
|
|
24268
|
+
}
|
|
24269
|
+
if (attempt >= UPLOAD_ATTEMPTS) throw failure;
|
|
24270
|
+
log2.warn(`Upload of ${file.relativePath} failed (attempt ${attempt}/${UPLOAD_ATTEMPTS}), retrying...`);
|
|
24271
|
+
await new Promise((resolve5) => setTimeout(resolve5, 1e3 * attempt));
|
|
24234
24272
|
}
|
|
24235
24273
|
}
|
|
24236
24274
|
function sourceToRegex(source) {
|
|
@@ -24437,9 +24475,9 @@ async function waitForReady(deploymentId, token, orgId) {
|
|
|
24437
24475
|
}
|
|
24438
24476
|
throw new Error("Deployment timed out (5+ minutes)");
|
|
24439
24477
|
}
|
|
24440
|
-
async function logDeploymentPlan(outputDir, countFiles, orgId) {
|
|
24478
|
+
async function logDeploymentPlan(outputDir, countFiles, rebuilt, orgId) {
|
|
24441
24479
|
const q = teamQuery(orgId);
|
|
24442
|
-
const files = pathExists(outputDir) ? `${await countFiles()} files currently in ${outputDir}` : `the files of ${outputDir}, produced by the build step`;
|
|
24480
|
+
const files = !rebuilt && pathExists(outputDir) ? `${await countFiles()} files currently in ${outputDir}` : `the files of ${outputDir}, produced by the build step`;
|
|
24443
24481
|
logDryRunRequest(
|
|
24444
24482
|
"POST",
|
|
24445
24483
|
`${VERCEL_API}/v13/deployments${q}`,
|
|
@@ -24551,6 +24589,7 @@ async function deployVercelFrontend(appDir, repoRoot, config, framework = "unkno
|
|
|
24551
24589
|
const { output, sources } = await collectVercelOutputFiles(appDir, repoRoot);
|
|
24552
24590
|
return output.length + sources.length + await countFunctionFiles(functionsOutputDir);
|
|
24553
24591
|
},
|
|
24592
|
+
!config.skipBuild,
|
|
24554
24593
|
orgId
|
|
24555
24594
|
);
|
|
24556
24595
|
} else if (framework === "nextjs" && !isNextStatic) {
|
|
@@ -24579,6 +24618,7 @@ async function deployVercelFrontend(appDir, repoRoot, config, framework = "unkno
|
|
|
24579
24618
|
await logDeploymentPlan(
|
|
24580
24619
|
distDir,
|
|
24581
24620
|
async () => (await collectDistFiles(distDir)).length + 1 + await countFunctionFiles(functionsOutputDir),
|
|
24621
|
+
!config.skipBuild,
|
|
24582
24622
|
orgId
|
|
24583
24623
|
);
|
|
24584
24624
|
}
|
|
@@ -24673,6 +24713,7 @@ async function deployVercelFunctions(appDir, config, functionsOutputDir) {
|
|
|
24673
24713
|
await logDeploymentPlan(
|
|
24674
24714
|
joinPath(functionsOutputDir, "functions"),
|
|
24675
24715
|
async () => await countFunctionFiles(functionsOutputDir) + 1,
|
|
24716
|
+
!config.skipBuild,
|
|
24676
24717
|
target.orgId
|
|
24677
24718
|
);
|
|
24678
24719
|
return;
|
|
@@ -9763,11 +9763,19 @@ var init_command_registry = __esm({
|
|
|
9763
9763
|
},
|
|
9764
9764
|
{
|
|
9765
9765
|
flags: "--output-dir <dir>",
|
|
9766
|
-
description: "output directory for migrations (default: supabase/migrations)"
|
|
9766
|
+
description: "output directory for migrations (default: supabase/migrations of the app the command runs for: the nearest folder up with supabase/config.toml, or the only app with one under apps/; fails when none)"
|
|
9767
9767
|
},
|
|
9768
9768
|
{
|
|
9769
9769
|
flags: "--no-single-file",
|
|
9770
9770
|
description: "emit one migration file per entity"
|
|
9771
|
+
},
|
|
9772
|
+
{
|
|
9773
|
+
flags: "--only <collections...>",
|
|
9774
|
+
description: "emit only these collections into ONE new migration <version>_<first>[_and_more].sql (version: now, or the latest existing + 1 so it sorts last); never touches *_entity_tables.sql (for a live app adding a feature's entities; feature-owned collections accepted)"
|
|
9775
|
+
},
|
|
9776
|
+
{
|
|
9777
|
+
flags: "--app-dir <dir>",
|
|
9778
|
+
description: "app folder whose src/config/app.ts turns framework features on (their entities are included when installed; default: the app of the output dir)"
|
|
9771
9779
|
}
|
|
9772
9780
|
],
|
|
9773
9781
|
loader: "../generators/sql-generator.ts"
|
|
@@ -51534,6 +51534,100 @@ var init_supabase = __esm({
|
|
|
51534
51534
|
}
|
|
51535
51535
|
});
|
|
51536
51536
|
|
|
51537
|
+
// packages/tooling/src/generators/frameworkEntities.ts
|
|
51538
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
51539
|
+
import { pathToFileURL } from "node:url";
|
|
51540
|
+
function valueAt(config, path) {
|
|
51541
|
+
let value = config;
|
|
51542
|
+
for (const key of path) {
|
|
51543
|
+
if (!isRecord(value)) return void 0;
|
|
51544
|
+
value = value[key];
|
|
51545
|
+
}
|
|
51546
|
+
return value;
|
|
51547
|
+
}
|
|
51548
|
+
function isEntityExport(value) {
|
|
51549
|
+
return isObjectLike(value) && typeof value.name === "string" && value.name !== "" && typeof value.collection === "string" && value.collection !== "" && isRecord(value.fields);
|
|
51550
|
+
}
|
|
51551
|
+
async function readAppConfig(appDir) {
|
|
51552
|
+
const file = joinPath(appDir, ...APP_CONFIG_FILE);
|
|
51553
|
+
if (!pathExists(file, true)) return null;
|
|
51554
|
+
const mod3 = await import(pathToFileURL(file).href);
|
|
51555
|
+
const appConfig = isRecord(mod3) ? mod3.appConfig : void 0;
|
|
51556
|
+
if (!isRecord(appConfig)) {
|
|
51557
|
+
throw new DoNotDevError(
|
|
51558
|
+
`${file} does not export an appConfig object (export const appConfig: AppConfig = { \u2026 }).`,
|
|
51559
|
+
DO_NOT_DEV_ERROR_CODES.CONFIGURATION_ERROR
|
|
51560
|
+
);
|
|
51561
|
+
}
|
|
51562
|
+
return appConfig;
|
|
51563
|
+
}
|
|
51564
|
+
function isEnabled(appConfig, feature) {
|
|
51565
|
+
const setting = valueAt(appConfig, feature.configPath);
|
|
51566
|
+
return setting !== void 0 && setting !== null && setting !== false;
|
|
51567
|
+
}
|
|
51568
|
+
async function loadFeatureEntities(appDir, exclude = /* @__PURE__ */ new Set(), features = FRAMEWORK_ENTITY_FEATURES) {
|
|
51569
|
+
if (!appDir) {
|
|
51570
|
+
log2.info("App folder unknown: framework feature entities skipped (pass --app-dir).");
|
|
51571
|
+
return [];
|
|
51572
|
+
}
|
|
51573
|
+
const appConfig = await readAppConfig(appDir);
|
|
51574
|
+
if (!appConfig) {
|
|
51575
|
+
log2.info(
|
|
51576
|
+
`No ${APP_CONFIG_FILE.join("/")} in ${appDir}: framework feature entities skipped.`
|
|
51577
|
+
);
|
|
51578
|
+
return [];
|
|
51579
|
+
}
|
|
51580
|
+
const configFile = joinPath(appDir, ...APP_CONFIG_FILE);
|
|
51581
|
+
const found = [];
|
|
51582
|
+
for (const feature of features) {
|
|
51583
|
+
if (!isEnabled(appConfig, feature)) continue;
|
|
51584
|
+
let resolved;
|
|
51585
|
+
try {
|
|
51586
|
+
resolved = createRequire4(configFile).resolve(feature.module);
|
|
51587
|
+
} catch {
|
|
51588
|
+
log2.warn(
|
|
51589
|
+
`Feature ${feature.name} is on (appConfig.${feature.configPath.join(".")}) but ${feature.packageName} is not installed in ${appDir}: its tables are skipped. Install ${feature.packageName}.`
|
|
51590
|
+
);
|
|
51591
|
+
continue;
|
|
51592
|
+
}
|
|
51593
|
+
const mod3 = await import(pathToFileURL(resolved).href);
|
|
51594
|
+
if (!isRecord(mod3)) continue;
|
|
51595
|
+
const seen = /* @__PURE__ */ new Set();
|
|
51596
|
+
for (const value of Object.values(mod3)) {
|
|
51597
|
+
if (!isEntityExport(value) || seen.has(value.collection)) continue;
|
|
51598
|
+
seen.add(value.collection);
|
|
51599
|
+
if (exclude.has(value.collection)) {
|
|
51600
|
+
log2.info(
|
|
51601
|
+
`${value.collection}: defined by the app's entity files and by feature ${feature.name}; one table.`
|
|
51602
|
+
);
|
|
51603
|
+
continue;
|
|
51604
|
+
}
|
|
51605
|
+
found.push({ entity: value, feature: feature.name, path: resolved });
|
|
51606
|
+
}
|
|
51607
|
+
}
|
|
51608
|
+
return found;
|
|
51609
|
+
}
|
|
51610
|
+
var FRAMEWORK_ENTITY_FEATURES, APP_CONFIG_FILE;
|
|
51611
|
+
var init_frameworkEntities = __esm({
|
|
51612
|
+
"packages/tooling/src/generators/frameworkEntities.ts"() {
|
|
51613
|
+
"use strict";
|
|
51614
|
+
init_utils2();
|
|
51615
|
+
init_cli_output();
|
|
51616
|
+
init_errors();
|
|
51617
|
+
init_pathResolver();
|
|
51618
|
+
init_type_guards();
|
|
51619
|
+
FRAMEWORK_ENTITY_FEATURES = [
|
|
51620
|
+
{
|
|
51621
|
+
name: "chatbot",
|
|
51622
|
+
configPath: ["ai", "chatbot"],
|
|
51623
|
+
module: "@donotdev/ai/entities",
|
|
51624
|
+
packageName: "@donotdev/ai"
|
|
51625
|
+
}
|
|
51626
|
+
];
|
|
51627
|
+
APP_CONFIG_FILE = ["src", "config", "app.ts"];
|
|
51628
|
+
}
|
|
51629
|
+
});
|
|
51630
|
+
|
|
51537
51631
|
// node_modules/.bun/firebase-admin@14.5.1+c188cf0323c41673/node_modules/firebase-admin/lib/firestore/error.js
|
|
51538
51632
|
var require_error4 = __commonJS({
|
|
51539
51633
|
"node_modules/.bun/firebase-admin@14.5.1+c188cf0323c41673/node_modules/firebase-admin/lib/firestore/error.js"(exports) {
|
|
@@ -191793,15 +191887,18 @@ var init_firestore = __esm({
|
|
|
191793
191887
|
});
|
|
191794
191888
|
|
|
191795
191889
|
// packages/tooling/src/utils/coreSemantics.ts
|
|
191796
|
-
import { createRequire as
|
|
191797
|
-
import { pathToFileURL } from "node:url";
|
|
191890
|
+
import { createRequire as createRequire5 } from "node:module";
|
|
191891
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
191798
191892
|
function isFunction(value) {
|
|
191799
191893
|
return typeof value === "function";
|
|
191800
191894
|
}
|
|
191895
|
+
function isStringRecord(value) {
|
|
191896
|
+
return isRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
191897
|
+
}
|
|
191801
191898
|
async function loadCoreSemantics(fromFile2) {
|
|
191802
191899
|
let resolved;
|
|
191803
191900
|
try {
|
|
191804
|
-
resolved =
|
|
191901
|
+
resolved = createRequire5(fromFile2).resolve("@donotdev/core/server");
|
|
191805
191902
|
} catch (error2) {
|
|
191806
191903
|
throw new DoNotDevError(
|
|
191807
191904
|
`Cannot resolve @donotdev/core from ${fromFile2}: install it in the app (entities import it).`,
|
|
@@ -191809,10 +191906,10 @@ async function loadCoreSemantics(fromFile2) {
|
|
|
191809
191906
|
{ originalError: error2 instanceof Error ? error2 : void 0 }
|
|
191810
191907
|
);
|
|
191811
191908
|
}
|
|
191812
|
-
const mod3 = await import(
|
|
191813
|
-
if (!isRecord(mod3) || !isFunction(mod3.describeEntity) || !isFunction(mod3.createSchemas) || !Array.isArray(mod3.HIDDEN_STATUSES) || typeof mod3.DEFAULT_STATUS_VALUE !== "string") {
|
|
191909
|
+
const mod3 = await import(pathToFileURL2(resolved).href);
|
|
191910
|
+
if (!isRecord(mod3) || !isFunction(mod3.describeEntity) || !isFunction(mod3.createSchemas) || !Array.isArray(mod3.HIDDEN_STATUSES) || typeof mod3.DEFAULT_STATUS_VALUE !== "string" || typeof mod3.REMOVED_STATUS !== "string" || !isStringRecord(mod3.USER_ROLES) || !isStringRecord(mod3.SUBSCRIPTION_TIERS)) {
|
|
191814
191911
|
throw new DoNotDevError(
|
|
191815
|
-
`@donotdev/core at ${resolved} has no describeEntity / createSchemas / HIDDEN_STATUSES / DEFAULT_STATUS_VALUE: upgrade @donotdev/core.`,
|
|
191912
|
+
`@donotdev/core at ${resolved} has no describeEntity / createSchemas / HIDDEN_STATUSES / DEFAULT_STATUS_VALUE / REMOVED_STATUS / USER_ROLES / SUBSCRIPTION_TIERS: upgrade @donotdev/core.`,
|
|
191816
191913
|
DO_NOT_DEV_ERROR_CODES.CONFIGURATION_ERROR
|
|
191817
191914
|
);
|
|
191818
191915
|
}
|
|
@@ -191823,7 +191920,11 @@ async function loadCoreSemantics(fromFile2) {
|
|
|
191823
191920
|
describeEntity: (entity) => describeEntity(entity),
|
|
191824
191921
|
createSchemas: (entity) => createSchemas(entity),
|
|
191825
191922
|
hiddenStatuses: mod3.HIDDEN_STATUSES.map(String),
|
|
191826
|
-
defaultStatus: mod3.DEFAULT_STATUS_VALUE
|
|
191923
|
+
defaultStatus: mod3.DEFAULT_STATUS_VALUE,
|
|
191924
|
+
removedStatus: mod3.REMOVED_STATUS,
|
|
191925
|
+
// Live objects, not copies: an override run by the app's modules is seen at SQL build
|
|
191926
|
+
userRoles: mod3.USER_ROLES,
|
|
191927
|
+
subscriptionTiers: mod3.SUBSCRIPTION_TIERS
|
|
191827
191928
|
};
|
|
191828
191929
|
}
|
|
191829
191930
|
function schemaIssues(schema, value) {
|
|
@@ -191867,44 +191968,53 @@ init_utils2();
|
|
|
191867
191968
|
// packages/tooling/src/db/context.ts
|
|
191868
191969
|
init_utils2();
|
|
191869
191970
|
init_supabase();
|
|
191971
|
+
init_frameworkEntities();
|
|
191870
191972
|
init_app_selector();
|
|
191871
191973
|
init_cli_output();
|
|
191872
191974
|
init_pathResolver();
|
|
191873
191975
|
init_secrets_resolver();
|
|
191874
191976
|
init_type_guards();
|
|
191875
|
-
|
|
191977
|
+
function toLoadedEntity(value) {
|
|
191978
|
+
if (!isObjectLike(value)) return null;
|
|
191979
|
+
if (typeof value.name === "string" && value.name && typeof value.collection === "string" && value.collection && value.fields) {
|
|
191980
|
+
return {
|
|
191981
|
+
name: value.name,
|
|
191982
|
+
collection: value.collection,
|
|
191983
|
+
// why: shape produced by defineEntity() (the app's entities barrel or a framework
|
|
191984
|
+
// feature's entities module); fields/access are validated there, not re-validated here.
|
|
191985
|
+
fields: value.fields,
|
|
191986
|
+
access: value.access
|
|
191987
|
+
};
|
|
191988
|
+
}
|
|
191989
|
+
return null;
|
|
191990
|
+
}
|
|
191991
|
+
async function loadEntities(projectRoot, appDir) {
|
|
191992
|
+
const entities = [];
|
|
191876
191993
|
const entitiesDir = joinPath(projectRoot, "entities");
|
|
191994
|
+
const indexPath = joinPath(entitiesDir, "index.ts");
|
|
191877
191995
|
if (!pathExists(entitiesDir)) {
|
|
191878
191996
|
log2.warn("No entities/ directory found");
|
|
191879
|
-
|
|
191880
|
-
}
|
|
191881
|
-
const indexPath = joinPath(entitiesDir, "index.ts");
|
|
191882
|
-
if (!pathExists(indexPath)) {
|
|
191997
|
+
} else if (!pathExists(indexPath)) {
|
|
191883
191998
|
log2.warn("No entities/index.ts found");
|
|
191884
|
-
|
|
191885
|
-
|
|
191886
|
-
|
|
191887
|
-
|
|
191888
|
-
|
|
191889
|
-
|
|
191890
|
-
|
|
191891
|
-
|
|
191892
|
-
|
|
191893
|
-
const entities = [];
|
|
191894
|
-
for (const [key, value] of Object.entries(entityModule)) {
|
|
191895
|
-
if (!isObjectLike(value)) continue;
|
|
191896
|
-
const candidate = value;
|
|
191897
|
-
if (typeof candidate.name === "string" && candidate.name && typeof candidate.collection === "string" && candidate.collection && candidate.fields) {
|
|
191898
|
-
entities.push({
|
|
191899
|
-
name: candidate.name,
|
|
191900
|
-
collection: candidate.collection,
|
|
191901
|
-
// why: shape produced by defineEntity() in the app's entities barrel;
|
|
191902
|
-
// fields/access are validated there, not re-validated here.
|
|
191903
|
-
fields: candidate.fields,
|
|
191904
|
-
access: candidate.access
|
|
191905
|
-
});
|
|
191999
|
+
} else {
|
|
192000
|
+
try {
|
|
192001
|
+
const entityModule = await import(`file://${indexPath}`);
|
|
192002
|
+
for (const value of Object.values(entityModule)) {
|
|
192003
|
+
const entity = toLoadedEntity(value);
|
|
192004
|
+
if (entity) entities.push(entity);
|
|
192005
|
+
}
|
|
192006
|
+
} catch (err) {
|
|
192007
|
+
log2.error(`Failed to import entities:`, err);
|
|
191906
192008
|
}
|
|
191907
192009
|
}
|
|
192010
|
+
const features = await loadFeatureEntities(
|
|
192011
|
+
appDir,
|
|
192012
|
+
new Set(entities.map((entity) => entity.collection))
|
|
192013
|
+
);
|
|
192014
|
+
for (const { entity } of features) {
|
|
192015
|
+
const loaded = toLoadedEntity(entity);
|
|
192016
|
+
if (loaded) entities.push(loaded);
|
|
192017
|
+
}
|
|
191908
192018
|
return entities;
|
|
191909
192019
|
}
|
|
191910
192020
|
function detectProvider(appDir) {
|
|
@@ -192101,7 +192211,7 @@ async function createDbContext(options = {}) {
|
|
|
192101
192211
|
"Cannot detect database provider. Expected supabase/ or firebase.json in your app directory."
|
|
192102
192212
|
);
|
|
192103
192213
|
}
|
|
192104
|
-
const entities2 = await loadEntities(projectRoot);
|
|
192214
|
+
const entities2 = await loadEntities(projectRoot, projectRoot);
|
|
192105
192215
|
if (rootProvider === "firebase") {
|
|
192106
192216
|
return createFirebaseContext(
|
|
192107
192217
|
projectRoot,
|
|
@@ -192112,7 +192222,7 @@ async function createDbContext(options = {}) {
|
|
|
192112
192222
|
}
|
|
192113
192223
|
return createSupabaseContext(projectRoot, projectRoot, framework, entities2);
|
|
192114
192224
|
}
|
|
192115
|
-
const entities = await loadEntities(projectRoot);
|
|
192225
|
+
const entities = await loadEntities(projectRoot, appDir);
|
|
192116
192226
|
if (provider === "firebase") {
|
|
192117
192227
|
return createFirebaseContext(projectRoot, appDir, framework, entities);
|
|
192118
192228
|
}
|
|
@@ -9765,11 +9765,19 @@ var init_command_registry = __esm({
|
|
|
9765
9765
|
},
|
|
9766
9766
|
{
|
|
9767
9767
|
flags: "--output-dir <dir>",
|
|
9768
|
-
description: "output directory for migrations (default: supabase/migrations)"
|
|
9768
|
+
description: "output directory for migrations (default: supabase/migrations of the app the command runs for: the nearest folder up with supabase/config.toml, or the only app with one under apps/; fails when none)"
|
|
9769
9769
|
},
|
|
9770
9770
|
{
|
|
9771
9771
|
flags: "--no-single-file",
|
|
9772
9772
|
description: "emit one migration file per entity"
|
|
9773
|
+
},
|
|
9774
|
+
{
|
|
9775
|
+
flags: "--only <collections...>",
|
|
9776
|
+
description: "emit only these collections into ONE new migration <version>_<first>[_and_more].sql (version: now, or the latest existing + 1 so it sorts last); never touches *_entity_tables.sql (for a live app adding a feature's entities; feature-owned collections accepted)"
|
|
9777
|
+
},
|
|
9778
|
+
{
|
|
9779
|
+
flags: "--app-dir <dir>",
|
|
9780
|
+
description: "app folder whose src/config/app.ts turns framework features on (their entities are included when installed; default: the app of the output dir)"
|
|
9773
9781
|
}
|
|
9774
9782
|
],
|
|
9775
9783
|
loader: "../generators/sql-generator.ts"
|