@marktiderman/genesis-cli 1.19.0 → 1.21.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.
Files changed (42) hide show
  1. package/README.md +98 -1
  2. package/dist/cli.js +682 -74
  3. package/dist/cli.js.map +1 -1
  4. package/dist/doctor.d.ts +1 -1
  5. package/dist/doctor.js +270 -8
  6. package/dist/doctor.js.map +1 -1
  7. package/dist/eslint.cjs +99 -0
  8. package/dist/eslint.cjs.map +1 -0
  9. package/dist/eslint.d.cts +68 -0
  10. package/dist/eslint.d.ts +68 -0
  11. package/dist/eslint.js +72 -0
  12. package/dist/eslint.js.map +1 -0
  13. package/dist/genesis-catalog.json +86 -14
  14. package/dist/index.js +278 -16
  15. package/dist/index.js.map +1 -1
  16. package/dist/starter/README.md +17 -5
  17. package/dist/starter/__tests__/components/setup.ts +11 -0
  18. package/dist/starter/__tests__/starter.test.ts +19 -0
  19. package/dist/starter/eslint.config.js +8 -1
  20. package/dist/starter/nativewind-env.d.ts +1 -0
  21. package/dist/starter/package.json +5 -3
  22. package/dist/starter/src/lib/app.ts +13 -5
  23. package/dist/starter/src/lib/define-starter.ts +1 -1
  24. package/dist/starter/src/lib/devtools-overlay.ts +3 -4
  25. package/dist/starter/src/lib/native-modules.ts +5 -1
  26. package/dist/starter/src/lib/offline.ts +14 -0
  27. package/dist/starter/supabase/migrations/20261024000750_support_default_tenant.sql +18 -0
  28. package/dist/starter/supabase/migrations/20261024000800_genesis_support_tickets.sql +800 -0
  29. package/dist/starter/supabase/migrations/20261025000070_starter_tenancy.sql +26 -0
  30. package/dist/starter/supabase/migrations/20261025000080_genesis_chat_tenants.sql +716 -0
  31. package/dist/starter/supabase/tests/database/chat_people.test.sql +1 -1
  32. package/dist/starter/supabase/tests/database/genesis_chat.test.sql +10 -2
  33. package/dist/starter/supabase/tests/database/genesis_chat_coaching.test.sql +8 -0
  34. package/dist/starter/supabase/tests/database/genesis_chat_search_threads.test.sql +8 -0
  35. package/dist/starter/supabase/tests/database/genesis_chat_tenants.test.sql +259 -0
  36. package/dist/starter/supabase/tests/database/genesis_support.test.sql +15 -3
  37. package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +10 -0
  38. package/dist/starter/supabase/tests/database/genesis_support_tickets.test.sql +327 -0
  39. package/dist/starter/supabase/tests/database/starter_tenancy.test.sql +19 -0
  40. package/dist/vite.js +270 -8
  41. package/dist/vite.js.map +1 -1
  42. package/package.json +18 -4
package/dist/vite.js CHANGED
@@ -455,14 +455,14 @@ function inherit(own, source) {
455
455
  }
456
456
  function resolveViews(relations) {
457
457
  const done = /* @__PURE__ */ new Set();
458
- const resolve17 = (relation, depth) => {
458
+ const resolve18 = (relation, depth) => {
459
459
  if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
460
460
  done.add(relation.oid);
461
461
  const sources = new Set([...relation.origins.values()].map((o) => o.relation));
462
462
  if (sources.size !== 1) return;
463
463
  const source = relations.get([...sources][0]);
464
464
  if (!source) return;
465
- resolve17(source, depth + 1);
465
+ resolve18(source, depth + 1);
466
466
  const viewAttnumOf = /* @__PURE__ */ new Map();
467
467
  for (const [attnum, origin] of relation.origins) {
468
468
  const own = relation.columns.get(attnum);
@@ -485,7 +485,7 @@ function resolveViews(relations) {
485
485
  };
486
486
  if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
487
487
  };
488
- for (const relation of relations.values()) resolve17(relation, 0);
488
+ for (const relation of relations.values()) resolve18(relation, 0);
489
489
  }
490
490
  async function introspectPostgres(sql, schemas, options = {}) {
491
491
  const relations = /* @__PURE__ */ new Map();
@@ -1143,7 +1143,7 @@ function globToRegExp(glob) {
1143
1143
  }
1144
1144
  function globMatcher(globs) {
1145
1145
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1146
- return (path40) => res.some((re) => re.test(path40));
1146
+ return (path44) => res.some((re) => re.test(path44));
1147
1147
  }
1148
1148
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1149
1149
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -1455,6 +1455,7 @@ var FUNCTION_NAME = /^[a-z0-9][a-z0-9_-]*$/;
1455
1455
  var ROUTE = /^\/(?:[A-Za-z0-9_\-[\]().]+\/?)*$/;
1456
1456
  var INSTALL_SPEC = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9.^~<>=|* -]+)?$/;
1457
1457
  var SECRET = /^[A-Z][A-Z0-9_]*$/;
1458
+ var SQL_FUNCTION = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*$/;
1458
1459
  var ManifestError = class extends Error {
1459
1460
  constructor(problems) {
1460
1461
  super(`Invalid block manifest:
@@ -1549,6 +1550,39 @@ function parseManifest(home, id, raw, version, options = {}) {
1549
1550
  });
1550
1551
  }
1551
1552
  }
1553
+ if (m["needs"] !== void 0) {
1554
+ if (!Array.isArray(m["needs"])) problems.push(`${where2}.needs: must be a list of { function, how }`);
1555
+ else {
1556
+ out.needs = m["needs"].flatMap((n, j) => {
1557
+ const at2 = `${where2}.needs[${j}]`;
1558
+ if (!isObject2(n) || typeof n["function"] !== "string" || typeof n["how"] !== "string" || !n["how"].trim()) {
1559
+ problems.push(`${at2}: must be { function: "schema.name", how: "what to add" }`);
1560
+ return [];
1561
+ }
1562
+ if (!SQL_FUNCTION.test(n["function"])) {
1563
+ problems.push(`${at2}.function: "${n["function"]}" must be a schema-qualified function name, like private.genesis_viewer_people`);
1564
+ return [];
1565
+ }
1566
+ return [{ function: n["function"], how: n["how"].trim() }];
1567
+ });
1568
+ }
1569
+ }
1570
+ if (m["runsBefore"] !== void 0) {
1571
+ if (!Array.isArray(m["runsBefore"])) problems.push(`${where2}.runsBefore: must be a list of { package, file }`);
1572
+ else {
1573
+ out.runsBefore = m["runsBefore"].map((r, j) => {
1574
+ const at2 = `${where2}.runsBefore[${j}]`;
1575
+ if (!isObject2(r)) {
1576
+ problems.push(`${at2}: must be an object`);
1577
+ return { package: home, file: "" };
1578
+ }
1579
+ const before = { package: pkgOf(r["package"], at2), file: pathOf(r["file"], `${at2}.file`) };
1580
+ if (before.file && !MIGRATION_FILE.test(before.file.split("/").pop())) problems.push(`${at2}.file: "${before.file}" must be named NNNN_name.sql`);
1581
+ if (before.package === out.package && before.file === file) problems.push(`${at2}: a migration can't run before itself`);
1582
+ return before;
1583
+ });
1584
+ }
1585
+ }
1552
1586
  if (m["test"] !== void 0) {
1553
1587
  out.test = pathOf(m["test"], `${where2}.test`);
1554
1588
  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`);
@@ -2356,8 +2390,8 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
2356
2390
  } catch {
2357
2391
  continue;
2358
2392
  }
2359
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2360
- const spec = json[section]?.[name];
2393
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
2394
+ const spec = json[section2]?.[name];
2361
2395
  const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
2362
2396
  const parsed = v && parseVersion(v);
2363
2397
  if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
@@ -2510,7 +2544,9 @@ var BUILTIN_RULES = [
2510
2544
  // genesis.lock.json against the files (lock-files.ts)
2511
2545
  "lock-files",
2512
2546
  // an app whose database files live in another app (database.ts)
2513
- "database-elsewhere"
2547
+ "database-elsewhere",
2548
+ // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
2549
+ "genesis-eslint-config"
2514
2550
  ];
2515
2551
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2516
2552
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -5562,6 +5598,31 @@ function readsPracticeId(text) {
5562
5598
  var augmentsResourceScope = (text) => /\binterface\s+ResourceScope\b/.test(text);
5563
5599
  var PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
5564
5600
 
5601
+ // src/upgrade/eslint-config.ts
5602
+ var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
5603
+ var TESTING_LIBRARY = "eslint-plugin-testing-library";
5604
+ var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
5605
+ function findEslintConfig(root) {
5606
+ return FLAT_CONFIG_FILES.find((name) => existsSync(path20.join(root, name))) ?? null;
5607
+ }
5608
+ function readPackageJson(root) {
5609
+ try {
5610
+ return JSON.parse(readFileSync(path20.join(root, "package.json"), "utf8"));
5611
+ } catch {
5612
+ return null;
5613
+ }
5614
+ }
5615
+ var declares = (pkg, name) => Boolean(pkg?.dependencies?.[name] ?? pkg?.devDependencies?.[name] ?? pkg?.peerDependencies?.[name]);
5616
+ function appPlatform(pkg) {
5617
+ return declares(pkg, "expo") || declares(pkg, "react-native") ? "native" : "web";
5618
+ }
5619
+ function hasTestingLibrary(pkg) {
5620
+ return declares(pkg, TESTING_LIBRARY);
5621
+ }
5622
+ function usesGenesisLint(text) {
5623
+ return text.includes(ESLINT_EXPORT);
5624
+ }
5625
+
5565
5626
  // src/upgrade/codemods.ts
5566
5627
  var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
5567
5628
  var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
@@ -6304,9 +6365,179 @@ function blockOfSource(source, manifests) {
6304
6365
  }
6305
6366
  return null;
6306
6367
  }
6368
+ var BUN_LOCK = "bun.lock";
6369
+ var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
6370
+ var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
6371
+ function skipSpace(text, i) {
6372
+ for (; ; ) {
6373
+ while (i < text.length && /\s/.test(text[i])) i++;
6374
+ if (text.startsWith("//", i)) {
6375
+ const nl = text.indexOf("\n", i);
6376
+ i = nl === -1 ? text.length : nl + 1;
6377
+ } else if (text.startsWith("/*", i)) {
6378
+ const close = text.indexOf("*/", i + 2);
6379
+ i = close === -1 ? text.length : close + 2;
6380
+ } else return i;
6381
+ }
6382
+ }
6383
+ function skipString(text, i) {
6384
+ for (let j = i + 1; j < text.length; j++) {
6385
+ if (text[j] === "\\") j++;
6386
+ else if (text[j] === '"') return j + 1;
6387
+ }
6388
+ throw new Error("an unterminated string");
6389
+ }
6390
+ function skipValue(text, i) {
6391
+ const c = text[i];
6392
+ if (c === '"') return skipString(text, i);
6393
+ if (c === "{" || c === "[") {
6394
+ let depth = 0;
6395
+ for (let j2 = i; j2 < text.length; ) {
6396
+ const d = text[j2];
6397
+ if (d === '"') {
6398
+ j2 = skipString(text, j2);
6399
+ continue;
6400
+ }
6401
+ if (text.startsWith("//", j2) || text.startsWith("/*", j2)) {
6402
+ j2 = skipSpace(text, j2);
6403
+ continue;
6404
+ }
6405
+ if (d === "{" || d === "[") depth++;
6406
+ else if (d === "}" || d === "]") {
6407
+ depth--;
6408
+ if (depth === 0) return j2 + 1;
6409
+ }
6410
+ j2++;
6411
+ }
6412
+ throw new Error("an unclosed object or array");
6413
+ }
6414
+ let j = i;
6415
+ while (j < text.length && !/[\s,}\]]/.test(text[j])) j++;
6416
+ if (j === i) throw new Error(`an unexpected ${JSON.stringify(c ?? "end")} at ${i}`);
6417
+ return j;
6418
+ }
6419
+ function members(text, open) {
6420
+ const out = [];
6421
+ let i = skipSpace(text, open + 1);
6422
+ while (text[i] !== "}") {
6423
+ if (text[i] !== '"') throw new Error(`a key expected at ${i}`);
6424
+ const keyEnd = skipString(text, i);
6425
+ const key2 = JSON.parse(text.slice(i, keyEnd));
6426
+ let j = skipSpace(text, keyEnd);
6427
+ if (text[j] !== ":") throw new Error(`":" expected at ${j}`);
6428
+ const value = skipSpace(text, j + 1);
6429
+ const end = skipValue(text, value);
6430
+ out.push({ key: key2, start: i, end, value });
6431
+ j = skipSpace(text, end);
6432
+ if (text[j] === ",") j = skipSpace(text, j + 1);
6433
+ i = j;
6434
+ if (i >= text.length) throw new Error("an unclosed object");
6435
+ }
6436
+ return out;
6437
+ }
6438
+ function section(text, name) {
6439
+ const open = skipSpace(text, 0);
6440
+ if (text[open] !== "{") throw new Error("not an object");
6441
+ const m = members(text, open).find((x) => x.key === name);
6442
+ return m && text[m.value] === "{" ? m : null;
6443
+ }
6444
+ function parseLoose(fragment) {
6445
+ let out = "";
6446
+ for (let i = 0; i < fragment.length; ) {
6447
+ const c = fragment[i];
6448
+ if (c === '"') {
6449
+ const end = skipString(fragment, i);
6450
+ out += fragment.slice(i, end);
6451
+ i = end;
6452
+ } else if (c === ",") {
6453
+ const next = skipSpace(fragment, i + 1);
6454
+ if (fragment[next] !== "}" && fragment[next] !== "]") out += c;
6455
+ i++;
6456
+ } else if (fragment.startsWith("//", i) || fragment.startsWith("/*", i)) {
6457
+ i = skipSpace(fragment, i);
6458
+ } else {
6459
+ out += c;
6460
+ i++;
6461
+ }
6462
+ }
6463
+ return JSON.parse(out);
6464
+ }
6465
+ function resolution(value) {
6466
+ const first = Array.isArray(value) ? value[0] : null;
6467
+ if (typeof first !== "string") return null;
6468
+ const at = first.lastIndexOf("@");
6469
+ if (at <= 0) return null;
6470
+ return { name: first.slice(0, at), spec: first.slice(at + 1) };
6471
+ }
6472
+ function staleNestedEntries(text, want = () => null) {
6473
+ const packages = section(text, "packages");
6474
+ if (!packages) return [];
6475
+ const list = members(text, packages.value);
6476
+ const value = (m) => parseLoose(text.slice(m.value, m.end));
6477
+ const byKey = new Map(list.map((m) => [m.key, m]));
6478
+ const out = [];
6479
+ for (const m of list) {
6480
+ const tail = GENESIS_TAIL.exec(m.key);
6481
+ if (!tail || tail[1] === m.key) continue;
6482
+ const name = tail[1];
6483
+ const nested = resolution(value(m));
6484
+ if (!nested || nested.name !== name || !PLAIN_VERSION.test(nested.spec)) continue;
6485
+ const rootEntry = byKey.get(name);
6486
+ const rootRes = rootEntry ? resolution(value(rootEntry)) : null;
6487
+ const target = want(name) ?? (rootRes && PLAIN_VERSION.test(rootRes.spec) ? rootRes.spec : null);
6488
+ if (!rootEntry || !target || target === nested.spec) continue;
6489
+ const parent = m.key.slice(0, m.key.length - name.length - 1);
6490
+ const parentEntry = byKey.get(parent);
6491
+ const meta = parentEntry ? value(parentEntry)[2] : void 0;
6492
+ const declared = meta && typeof meta === "object" ? meta : {};
6493
+ const range = ["dependencies", "peerDependencies", "optionalDependencies"].map((s) => declared[s]?.[name]).find((r) => typeof r === "string");
6494
+ if (!range || satisfies(target, range) !== true) continue;
6495
+ out.push({ key: m.key, name, parent, version: nested.spec, root: target, range });
6496
+ }
6497
+ return out;
6498
+ }
6499
+ function readBunLock(dir) {
6500
+ const file = path20.join(dir, BUN_LOCK);
6501
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
6502
+ }
6503
+ function findLockfile(root) {
6504
+ let dir = path20.resolve(root);
6505
+ for (; ; ) {
6506
+ if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
6507
+ if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
6508
+ if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
6509
+ if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
6510
+ const parent = path20.dirname(dir);
6511
+ if (parent === dir) return null;
6512
+ dir = parent;
6513
+ }
6514
+ }
6307
6515
 
6308
6516
  // src/doctor/lock-files.ts
6517
+ function checkBunLock(ctx) {
6518
+ const found = findLockfile(ctx.root);
6519
+ if (found?.pm !== "bun") return;
6520
+ const text = readBunLock(found.dir);
6521
+ if (text === null) return;
6522
+ const file = path20.relative(ctx.root, path20.join(found.dir, BUN_LOCK)).split(path20.sep).join("/");
6523
+ let stale;
6524
+ try {
6525
+ stale = staleNestedEntries(text);
6526
+ } catch {
6527
+ return;
6528
+ }
6529
+ for (const s of stale) {
6530
+ ctx.report({
6531
+ rule: "lock-files",
6532
+ level: "warn",
6533
+ file,
6534
+ subject: s.key,
6535
+ message: `keeps a nested copy of ${s.name}@${s.version} under ${s.parent} beside the root's ${s.root}, which satisfies its ${s.range}: Bun keeps it across installs, so the app runs two copies (a provider from one is invisible to hooks from the other). Delete the "${s.key}" entry from ${file}'s packages, then reinstall (bun install); genesis upgrade does both`
6536
+ });
6537
+ }
6538
+ }
6309
6539
  async function checkLockFiles(ctx) {
6540
+ checkBunLock(ctx);
6310
6541
  if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
6311
6542
  let lock;
6312
6543
  try {
@@ -6419,7 +6650,37 @@ function checkDatabaseHome(ctx) {
6419
6650
  });
6420
6651
  }
6421
6652
  }
6422
- var RATCHETED_BY_DEFAULT = ["deprecated-import"];
6653
+ function checkEslintConfig(ctx) {
6654
+ const pkg = readPackageJson(ctx.root);
6655
+ const native = appPlatform(pkg) === "native" || (ctx.config.packs?.includes("native") ?? false);
6656
+ if (!native) return;
6657
+ const file = findEslintConfig(ctx.root);
6658
+ if (!file) return;
6659
+ let text;
6660
+ try {
6661
+ text = readFileSync(path20.join(ctx.root, file), "utf8");
6662
+ } catch {
6663
+ return;
6664
+ }
6665
+ if (!usesGenesisLint(text)) {
6666
+ ctx.report({
6667
+ rule: "genesis-eslint-config",
6668
+ level: "warn",
6669
+ file,
6670
+ subject: "@marktiderman/genesis-cli/eslint",
6671
+ message: `doesn't load Genesis's lint rules, so genesis upgrade can't bring new ones (React Native Testing Library 14's await rules today). Run genesis codemod genesis-cli-eslint-config, or add const { genesis } = require("@marktiderman/genesis-cli/eslint") (import { genesis } from \u2026 in an ES module) and ...genesis("native") last in the array the config exports, with ${TESTING_LIBRARY} in devDependencies`
6672
+ });
6673
+ } else if (!hasTestingLibrary(pkg)) {
6674
+ ctx.report({
6675
+ rule: "genesis-eslint-config",
6676
+ level: "warn",
6677
+ file: "package.json",
6678
+ subject: TESTING_LIBRARY,
6679
+ message: `${file} loads Genesis's native lint rules, which need ${TESTING_LIBRARY}: add it to devDependencies (pnpm add -D ${TESTING_LIBRARY}), or the lint can't load its config`
6680
+ });
6681
+ }
6682
+ }
6683
+ var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
6423
6684
  async function runDoctor(options = {}) {
6424
6685
  const root = path20.resolve(options.root ?? process.cwd());
6425
6686
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
@@ -6522,6 +6783,7 @@ function builtinChecks(config, options = {}) {
6522
6783
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
6523
6784
  { name: "lock-files", check: checkLockFiles },
6524
6785
  { name: "database-elsewhere", check: checkDatabaseHome },
6786
+ { name: "eslint-config", check: checkEslintConfig },
6525
6787
  ...(config.packs ?? []).map((p) => packs[p]),
6526
6788
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
6527
6789
  ];