@marktiderman/genesis-cli 1.18.0 → 1.19.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 CHANGED
@@ -456,14 +456,14 @@ function inherit(own, source) {
456
456
  }
457
457
  function resolveViews(relations) {
458
458
  const done = /* @__PURE__ */ new Set();
459
- const resolve15 = (relation, depth) => {
459
+ const resolve16 = (relation, depth) => {
460
460
  if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
461
461
  done.add(relation.oid);
462
462
  const sources = new Set([...relation.origins.values()].map((o) => o.relation));
463
463
  if (sources.size !== 1) return;
464
464
  const source = relations.get([...sources][0]);
465
465
  if (!source) return;
466
- resolve15(source, depth + 1);
466
+ resolve16(source, depth + 1);
467
467
  const viewAttnumOf = /* @__PURE__ */ new Map();
468
468
  for (const [attnum, origin] of relation.origins) {
469
469
  const own = relation.columns.get(attnum);
@@ -486,7 +486,7 @@ function resolveViews(relations) {
486
486
  };
487
487
  if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
488
488
  };
489
- for (const relation of relations.values()) resolve15(relation, 0);
489
+ for (const relation of relations.values()) resolve16(relation, 0);
490
490
  }
491
491
  async function introspectPostgres(sql, schemas, options = {}) {
492
492
  const relations = /* @__PURE__ */ new Map();
@@ -816,9 +816,9 @@ async function runScaffold(opts, fs) {
816
816
  function joinPath(...parts) {
817
817
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
818
818
  }
819
- function dirname(path36) {
820
- const idx = path36.lastIndexOf("/");
821
- return idx === -1 ? "." : path36.slice(0, idx);
819
+ function dirname(path39) {
820
+ const idx = path39.lastIndexOf("/");
821
+ return idx === -1 ? "." : path39.slice(0, idx);
822
822
  }
823
823
  function brandPackageJson(consumer, genesisVersion) {
824
824
  return JSON.stringify(
@@ -1587,8 +1587,26 @@ function readGenesisConfig(root) {
1587
1587
  const out = { raw };
1588
1588
  if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
1589
1589
  if (raw.privacy !== void 0) out.privacy = validatePrivacy(raw.privacy, file);
1590
+ if (raw.supabase !== void 0) {
1591
+ const supabase = validateSupabase(raw.supabase, file);
1592
+ if (supabase !== true) out.supabase = supabase;
1593
+ }
1590
1594
  return out;
1591
1595
  }
1596
+ function validateSupabase(raw, source = "config") {
1597
+ const fail = (msg) => {
1598
+ throw new GenesisConfigError(`${source}: ${msg}`);
1599
+ };
1600
+ if (typeof raw === "boolean") return raw ? true : false;
1601
+ if (!isObject(raw)) return fail(`"supabase" must be false or { "app": "<the folder of the app that holds supabase/>" }`);
1602
+ for (const key2 of Object.keys(raw)) if (key2 !== "app" && key2 !== "$comment") fail(`supabase: unknown setting "${key2}" (known: app)`);
1603
+ const app = raw.app;
1604
+ if (typeof app !== "string" || !app.trim()) return fail(`supabase.app must be the folder of the app that holds supabase/, relative to this one (e.g. "../app")`);
1605
+ if (path20.isAbsolute(app) || /^[A-Za-z]:[\\/]/.test(app) || app.includes("\\")) fail(`supabase.app must be relative to this app, with forward slashes ("${app}")`);
1606
+ const norm = path20.posix.normalize(app).replace(/\/+$/, "");
1607
+ if (norm === "." || norm === "") fail(`supabase.app names this app itself; leave "supabase" out instead`);
1608
+ return { app: norm };
1609
+ }
1592
1610
  var PRIVACY_KEYS = /* @__PURE__ */ new Set(["blocks", "collects", "tracking"]);
1593
1611
  var DATA_USE_KEYS = /* @__PURE__ */ new Set(["type", "purposes", "linked", "tracking"]);
1594
1612
  function validatePrivacy(raw, source = "config") {
@@ -1813,7 +1831,7 @@ function globToRegExp(glob) {
1813
1831
  }
1814
1832
  function globMatcher(globs) {
1815
1833
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1816
- return (path36) => res.some((re) => re.test(path36));
1834
+ return (path39) => res.some((re) => re.test(path39));
1817
1835
  }
1818
1836
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1819
1837
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -2199,6 +2217,26 @@ function parseManifest(home, id, raw, version, options = {}) {
2199
2217
  const file = pathOf(m["file"], `${where2}.file`);
2200
2218
  if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
2201
2219
  const out = { package: pkgOf(m["package"], where2), file };
2220
+ if (m["provides"] !== void 0) {
2221
+ if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
2222
+ else {
2223
+ out.provides = m["provides"].map((p, j) => {
2224
+ const at2 = `${where2}.provides[${j}]`;
2225
+ if (!isObject2(p)) {
2226
+ problems.push(`${at2}: must be an object`);
2227
+ return { package: home, file: "" };
2228
+ }
2229
+ const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
2230
+ if (p["functions"] !== void 0) {
2231
+ if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
2232
+ else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
2233
+ }
2234
+ if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
2235
+ if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
2236
+ return provided;
2237
+ });
2238
+ }
2239
+ }
2202
2240
  if (m["test"] !== void 0) {
2203
2241
  out.test = pathOf(m["test"], `${where2}.test`);
2204
2242
  if (out.test && !/^[a-z0-9_]+\.test\.sql$/.test(out.test.split("/").pop().replace(/^\d{4}_/, ""))) problems.push(`${where2}.test: "${out.test}" must be named [NNNN_]name.test.sql`);
@@ -2342,10 +2380,6 @@ function appPath2(root, rel) {
2342
2380
  if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
2343
2381
  return target;
2344
2382
  }
2345
- function readApp(root, rel) {
2346
- const file = appPath2(root, rel);
2347
- return existsSync(file) ? readFileSync(file, "utf8") : null;
2348
- }
2349
2383
 
2350
2384
  // src/blocks/local.ts
2351
2385
  var LOCAL_PACKAGES_KEY = "localPackages";
@@ -3165,7 +3199,9 @@ var BUILTIN_RULES = [
3165
3199
  // supabase pack: contracts (contracts.ts)
3166
3200
  "contracts-stale",
3167
3201
  // genesis.lock.json against the files (lock-files.ts)
3168
- "lock-files"
3202
+ "lock-files",
3203
+ // an app whose database files live in another app (database.ts)
3204
+ "database-elsewhere"
3169
3205
  ];
3170
3206
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
3171
3207
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -3388,7 +3424,7 @@ function privacyApisFor(dependencies2) {
3388
3424
  var EAS_PLACEHOLDERS = {
3389
3425
  REPLACE_WITH_APP_STORE_CONNECT_APP_ID: "the app's Apple ID from App Store Connect (create the app there, then App Information \u2192 General Information \u2192 Apple ID, a number)",
3390
3426
  REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
3391
- REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the path to your Google Play service account key, a JSON file kept out of git (Play Console \u2192 Setup \u2192 API access); or delete submit.production.android until you ship to Google Play",
3427
+ REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the Google Play service account key uploaded to EAS, not a local path (deploy-production.yml submits on EAS, where a local file isn't there): create a Google Cloud service account and its JSON key, invite it in Play Console \u2192 Users and permissions, upload the key with `eas credentials` (Android \u2192 Google Service Account), then remove only this serviceAccountKeyPath line (https://docs.expo.dev/submit/android/). Until you ship to Google Play, remove the submit_android job from deploy-production.yml instead, and keep submit.production.android as it is (the internal track, as a draft)",
3392
3428
  REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
3393
3429
  };
3394
3430
  function placeholderKey(line, placeholder) {
@@ -4297,11 +4333,21 @@ async function blocksOfInstalled(dir, warnings = [], options = {}) {
4297
4333
  const out = [];
4298
4334
  for (const id of [...ids].sort()) {
4299
4335
  const fromJson = raw[id] ?? {};
4300
- const manifest = tryParse(() => parseManifest(pkg.name, id, { ...fromJson, ...declared[id] }, pkg.version, options), warnings);
4336
+ const merged = { ...fromJson, ...declared[id] };
4337
+ if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
4338
+ const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
4301
4339
  if (manifest) out.push(manifest);
4302
4340
  }
4303
4341
  return out;
4304
4342
  }
4343
+ function withProvides(declared, json) {
4344
+ if (!Array.isArray(declared)) return declared;
4345
+ const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
4346
+ return declared.map((m) => {
4347
+ const same = json.find((j) => fileOf(j) === fileOf(m));
4348
+ return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
4349
+ });
4350
+ }
4305
4351
  async function allBlocks(root, warnings = []) {
4306
4352
  const out = [];
4307
4353
  for (const local of localPackages(root)) {
@@ -5160,6 +5206,45 @@ function checkPackagesPack(ctx) {
5160
5206
  if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
5161
5207
  }
5162
5208
  }
5209
+ var LOCK_FILE = "genesis.lock.json";
5210
+ function emptyLock() {
5211
+ return { version: 1, blocks: {}, files: {} };
5212
+ }
5213
+ function readLock(root) {
5214
+ const file = path20.join(root, LOCK_FILE);
5215
+ if (!existsSync(file)) return emptyLock();
5216
+ const raw = JSON.parse(readFileSync(file, "utf8"));
5217
+ if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
5218
+ return {
5219
+ version: 1,
5220
+ ...raw.substitutions ? { substitutions: raw.substitutions } : {},
5221
+ blocks: raw.blocks ?? {},
5222
+ files: raw.files ?? {},
5223
+ ...raw.migrations ? { migrations: raw.migrations } : {}
5224
+ };
5225
+ }
5226
+ function parseSource(source) {
5227
+ const at = source.indexOf(":");
5228
+ if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
5229
+ return { package: source.slice(0, at), path: source.slice(at + 1) };
5230
+ }
5231
+
5232
+ // src/blocks/database.ts
5233
+ function databaseElsewhere(root) {
5234
+ const setting = readGenesisConfig(root)?.supabase;
5235
+ if (setting === void 0) return null;
5236
+ if (setting === false) return { app: null, dir: null, hasSupabase: false };
5237
+ const resolved = path20.resolve(root, setting.app);
5238
+ const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
5239
+ const dir = real2(resolved);
5240
+ if (dir === real2(path20.resolve(root))) throw new GenesisConfigError(`${path20.join(root, "genesis.config.json")}: supabase.app "${setting.app}" is this app itself; leave "supabase" out instead`);
5241
+ return { app: setting.app, dir, hasSupabase: existsSync(path20.join(dir, "supabase")) };
5242
+ }
5243
+ function isSupabasePath(rel) {
5244
+ return rel === "supabase" || rel.startsWith("supabase/");
5245
+ }
5246
+
5247
+ // src/doctor/supabase.ts
5163
5248
  var DEFAULT_MIGRATIONS = "supabase/migrations";
5164
5249
  var DEFAULT_BASE = "origin/main";
5165
5250
  var DEFAULT_EXPOSED = ["public"];
@@ -5340,6 +5425,7 @@ function gitView(root, dir, base) {
5340
5425
  return { touched: touched2, edited };
5341
5426
  }
5342
5427
  function checkSupabasePack(ctx) {
5428
+ if (databaseElsewhere(ctx.root)) return;
5343
5429
  const settings = ctx.config.supabase ?? {};
5344
5430
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
5345
5431
  const abs = path20.join(ctx.root, dir);
@@ -6759,28 +6845,6 @@ function checkAgentGuide(ctx) {
6759
6845
  ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
6760
6846
  }
6761
6847
  }
6762
- var LOCK_FILE = "genesis.lock.json";
6763
- function emptyLock() {
6764
- return { version: 1, blocks: {}, files: {} };
6765
- }
6766
- function readLock(root) {
6767
- const file = path20.join(root, LOCK_FILE);
6768
- if (!existsSync(file)) return emptyLock();
6769
- const raw = JSON.parse(readFileSync(file, "utf8"));
6770
- if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
6771
- return {
6772
- version: 1,
6773
- ...raw.substitutions ? { substitutions: raw.substitutions } : {},
6774
- blocks: raw.blocks ?? {},
6775
- files: raw.files ?? {},
6776
- ...raw.migrations ? { migrations: raw.migrations } : {}
6777
- };
6778
- }
6779
- function parseSource(source) {
6780
- const at = source.indexOf(":");
6781
- if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
6782
- return { package: source.slice(0, at), path: source.slice(at + 1) };
6783
- }
6784
6848
  var CLI = "@marktiderman/genesis-cli";
6785
6849
  function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
6786
6850
  let parsed;
@@ -6823,8 +6887,25 @@ function featuresBody(text) {
6823
6887
  const m = /\bfeatures:\s*\{/.exec(text);
6824
6888
  if (!m) return null;
6825
6889
  const start = m.index + m[0].length;
6826
- const end = text.indexOf("}", start);
6827
- return end < 0 ? null : { start, body: text.slice(start, end) };
6890
+ let depth = 1;
6891
+ for (let i = start; i < text.length; i++) {
6892
+ const c = text[i];
6893
+ if (c === "/" && text[i + 1] === "/") {
6894
+ const nl = text.indexOf("\n", i);
6895
+ if (nl < 0) return null;
6896
+ i = nl;
6897
+ } else if (c === "/" && text[i + 1] === "*") {
6898
+ const close = text.indexOf("*/", i + 2);
6899
+ if (close < 0) return null;
6900
+ i = close + 1;
6901
+ } else if (c === '"' || c === "'" || c === "`") {
6902
+ let j = i + 1;
6903
+ while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1;
6904
+ i = j;
6905
+ } else if (c === "{") depth++;
6906
+ else if (c === "}" && --depth === 0) return { start, body: text.slice(start, i) };
6907
+ }
6908
+ return null;
6828
6909
  }
6829
6910
  function parseStarterFeatures(text) {
6830
6911
  const found = featuresBody(text);
@@ -6846,6 +6927,7 @@ function parseStarterBlocks(json, source = GENESIS_CONFIG) {
6846
6927
  const starter = raw?.starter;
6847
6928
  if (starter === void 0) return null;
6848
6929
  const blocks = starter?.blocks;
6930
+ if (blocks === void 0 && typeof starter === "object" && starter !== null && !Array.isArray(starter)) return null;
6849
6931
  if (typeof blocks !== "object" || blocks === null || Array.isArray(blocks)) throw new Error(`${source}: starter.blocks must map each feature switch to a list of block ids`);
6850
6932
  const out = {};
6851
6933
  for (const [name, ids] of Object.entries(blocks)) {
@@ -6944,15 +7026,44 @@ async function checkLockFiles(ctx) {
6944
7026
  });
6945
7027
  }
6946
7028
  const local = localPackageNames(ctx.root);
7029
+ let home = null;
7030
+ try {
7031
+ home = databaseElsewhere(ctx.root);
7032
+ } catch {
7033
+ }
7034
+ const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
7035
+ if (home && elsewhere.length) {
7036
+ ctx.report({
7037
+ rule: "lock-files",
7038
+ level: "info",
7039
+ file: LOCK_FILE,
7040
+ subject: "supabase/",
7041
+ message: `lists ${elsewhere.length} file${elsewhere.length === 1 ? "" : "s"} under supabase/, but this app's database files live ${home.app ? `in ${home.app}` : "nowhere"} (genesis.config.json supabase): genesis upgrade leaves them alone, so delete those entries`
7042
+ });
7043
+ }
6947
7044
  for (const [rel, entry] of Object.entries(lock.files)) {
7045
+ if (home && isSupabasePath(rel)) continue;
6948
7046
  if (ownedKeyProblem(rel, entry.source, local)) continue;
6949
7047
  if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
6950
- let text;
7048
+ let file;
6951
7049
  try {
6952
- text = readApp(ctx.root, rel);
7050
+ file = appPath2(ctx.root, rel);
6953
7051
  } catch {
6954
7052
  continue;
6955
7053
  }
7054
+ let text;
7055
+ try {
7056
+ text = existsSync(file) ? readFileSync(file, "utf8") : null;
7057
+ } catch (err) {
7058
+ ctx.report({
7059
+ rule: "lock-files",
7060
+ level: "warn",
7061
+ file: rel,
7062
+ subject: rel,
7063
+ message: `is in ${LOCK_FILE} (from ${entry.source}) but can't be read (${err instanceof Error ? err.message : String(err)}), so genesis upgrade can't refresh it. Make it a file again, or remove its entry from ${LOCK_FILE}`
7064
+ });
7065
+ continue;
7066
+ }
6956
7067
  if (text === null) {
6957
7068
  if (entry.deleted) continue;
6958
7069
  ctx.report({
@@ -6977,6 +7088,28 @@ async function checkLockFiles(ctx) {
6977
7088
  });
6978
7089
  }
6979
7090
  }
7091
+ function checkDatabaseHome(ctx) {
7092
+ const home = databaseElsewhere(ctx.root);
7093
+ if (!home) return;
7094
+ if (home.app && !home.hasSupabase) {
7095
+ ctx.report({
7096
+ rule: "database-elsewhere",
7097
+ level: "warn",
7098
+ file: "genesis.config.json",
7099
+ subject: home.app,
7100
+ message: `supabase.app is ${home.app}, which has no supabase folder; name the app that holds this app's database (its migrations, tests and Edge Functions)`
7101
+ });
7102
+ }
7103
+ if (existsSync(path20.join(ctx.root, "supabase"))) {
7104
+ ctx.report({
7105
+ rule: "database-elsewhere",
7106
+ level: "warn",
7107
+ file: "supabase",
7108
+ subject: "supabase/",
7109
+ message: `is here, but genesis.config.json says this app's database files live ${home.app ? `in ${home.app}/supabase` : "nowhere"}: genesis add, migrate and upgrade never plan it, so it is a second, unused copy. Delete it`
7110
+ });
7111
+ }
7112
+ }
6980
7113
  var RATCHETED_BY_DEFAULT = ["deprecated-import"];
6981
7114
  async function runDoctor(options = {}) {
6982
7115
  const root = path20.resolve(options.root ?? process.cwd());
@@ -7079,6 +7212,7 @@ function builtinChecks(config, options = {}) {
7079
7212
  { name: "agent-guide", check: checkAgentGuide },
7080
7213
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
7081
7214
  { name: "lock-files", check: checkLockFiles },
7215
+ { name: "database-elsewhere", check: checkDatabaseHome },
7082
7216
  ...(config.packs ?? []).map((p) => packs[p]),
7083
7217
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
7084
7218
  ];