@marktiderman/genesis-cli 1.10.0 → 1.11.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.
@@ -53,7 +53,7 @@
53
53
  }
54
54
  },
55
55
  "@marktiderman/genesis-core": {
56
- "version": "1.9.0"
56
+ "version": "1.10.0"
57
57
  },
58
58
  "@marktiderman/genesis-switchboard": {
59
59
  "version": "2.1.0"
@@ -89,10 +89,10 @@
89
89
  "version": "0.6.3"
90
90
  },
91
91
  "@marktiderman/genesis": {
92
- "version": "0.9.7"
92
+ "version": "0.9.8"
93
93
  },
94
94
  "@marktiderman/genesis-cli": {
95
- "version": "1.10.0"
95
+ "version": "1.11.0"
96
96
  },
97
97
  "@marktiderman/genesis-native": {
98
98
  "version": "0.4.1",
@@ -480,6 +480,33 @@
480
480
  "Add one job route with createJobsHandler from @marktiderman/genesis-supabase/jobs, and set GENESIS_JOBS_SECRET on the server.",
481
481
  "For schedules: enable pg_cron and pg_net, add the Vault secrets genesis_jobs_url (the route's base URL) and genesis_jobs_secret (the same secret), then call genesis_schedule_job(name, cron, job) in a migration."
482
482
  ]
483
+ },
484
+ "feature-mirror": {
485
+ "feature": {
486
+ "name": "Registry in the app's database",
487
+ "summary": "The feature registry mirrored into the database on deploy, entitlements, per-tenant flag values and SQL feature_on(), for the feature gate.",
488
+ "keywords": [
489
+ "feature gate",
490
+ "entitlements",
491
+ "flags",
492
+ "feature_on"
493
+ ],
494
+ "audience": [
495
+ "developer"
496
+ ]
497
+ },
498
+ "requires": [
499
+ "tenant-features"
500
+ ],
501
+ "migrations": [
502
+ {
503
+ "file": "migrations/0008_genesis_feature_registry.sql",
504
+ "test": "migrations/tests/0008_genesis_feature_registry.test.sql"
505
+ }
506
+ ],
507
+ "steps": [
508
+ "Sync the registry on every deploy with the service key: syncFeatureRegistry(admin, features.json, { version: BUILD_TIME }). Grant paid features by writing feature_entitlements from your billing webhook."
509
+ ]
483
510
  }
484
511
  }
485
512
  },
@@ -674,7 +701,7 @@
674
701
  }
675
702
  },
676
703
  "@marktiderman/genesis-ui": {
677
- "version": "2.15.0"
704
+ "version": "2.16.0"
678
705
  },
679
706
  "@marktiderman/genesis-ui-native": {
680
707
  "version": "2.4.1"
package/dist/index.js CHANGED
@@ -1918,7 +1918,8 @@ var BUILTIN_RULES = [
1918
1918
  "migration-rls",
1919
1919
  "migration-definer-search-path",
1920
1920
  "migration-edited",
1921
- "migration-testing-kit"
1921
+ "migration-testing-kit",
1922
+ "migration-view-rls"
1922
1923
  ];
1923
1924
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
1924
1925
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2747,6 +2748,7 @@ function checkSupabasePack(ctx) {
2747
2748
  checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
2748
2749
  }
2749
2750
  checkRls(ctx, migrations, exposed);
2751
+ checkViewInvoker(ctx, migrations, exposed);
2750
2752
  checkDefinerSearchPath(ctx, migrations);
2751
2753
  checkTestingKit(ctx, migrations);
2752
2754
  }
@@ -2876,6 +2878,50 @@ function checkRls(ctx, migrations, exposed) {
2876
2878
  });
2877
2879
  }
2878
2880
  }
2881
+ function checkViewInvoker(ctx, migrations, exposed) {
2882
+ const views = /* @__PURE__ */ new Map();
2883
+ const name = String.raw`([\w$.]+)`;
2884
+ const invokerOn = /\bsecurity_invoker\s*(?:=\s*(?:true|on|yes|1|'true'|'on'))?\s*(?:,|\))/;
2885
+ for (const { file, statements } of migrations) {
2886
+ for (const { sql, line } of statements) {
2887
+ const create = new RegExp(String.raw`^create (?:or replace )?(?:temp |temporary )?(?:recursive )?view ${name}`).exec(sql);
2888
+ if (create) {
2889
+ if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
2890
+ const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
2891
+ views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
2892
+ continue;
2893
+ }
2894
+ const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
2895
+ if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
2896
+ const state = views.get(qualify(alter[1]));
2897
+ if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
2898
+ continue;
2899
+ }
2900
+ const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
2901
+ if (rename) {
2902
+ const from = qualify(rename[1]);
2903
+ const state = views.get(from);
2904
+ if (state) {
2905
+ views.delete(from);
2906
+ views.set(`${schemaOf(from)}.${rename[2]}`, state);
2907
+ }
2908
+ continue;
2909
+ }
2910
+ const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
2911
+ if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
2912
+ }
2913
+ }
2914
+ for (const [v, at] of views) {
2915
+ if (at.invoker || !exposed.has(schemaOf(v))) continue;
2916
+ ctx.report({
2917
+ rule: "migration-view-rls",
2918
+ file: at.file,
2919
+ line: at.line,
2920
+ subject: v,
2921
+ message: `${v} runs as its owner, so it reads past row level security; create it "with (security_invoker = true)" or add "alter view ${v} set (security_invoker = true);"`
2922
+ });
2923
+ }
2924
+ }
2879
2925
  function checkDefinerSearchPath(ctx, migrations) {
2880
2926
  const fns = /* @__PURE__ */ new Map();
2881
2927
  const keysFor = (sql, nameEnd, fnName) => {
@@ -3086,6 +3132,7 @@ function satisfies(version, range) {
3086
3132
  // src/doctor/installs.ts
3087
3133
  var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
3088
3134
  var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
3135
+ var NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
3089
3136
  var readManifest = (dir) => {
3090
3137
  try {
3091
3138
  return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
@@ -3160,12 +3207,14 @@ function genesisInstalls(root) {
3160
3207
  return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
3161
3208
  });
3162
3209
  const app = readManifest(root);
3163
- let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
3164
- let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
3165
- if (Object.keys(runtimeDeps).length === 0) {
3166
- runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
3167
- devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
3168
- }
3210
+ const declaredDev = Object.entries(app?.devDependencies ?? {});
3211
+ const runtimeDeps = {
3212
+ ...Object.fromEntries(declaredDev.filter(([n]) => !NON_SHIPPING.test(n))),
3213
+ ...app?.peerDependencies,
3214
+ ...app?.optionalDependencies,
3215
+ ...app?.dependencies
3216
+ };
3217
+ const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
3169
3218
  walk("runtime", rootsOf(runtimeDeps, "the app"));
3170
3219
  const top = path14.join(root, "node_modules");
3171
3220
  walk(
@@ -3248,11 +3297,21 @@ function stripForImports(code) {
3248
3297
  const templates = [];
3249
3298
  let depth = 0;
3250
3299
  let i = 0;
3300
+ let sure = true;
3251
3301
  const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
3252
- const opensString = () => {
3253
- const before = out.slice(-12).join("");
3254
- if (!/[\w$]$/.test(before)) return true;
3255
- return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
3302
+ const before = () => out.slice(-24).join("");
3303
+ const KEYWORD = /(?:^|[^\w$.])(?:return|typeof|instanceof|case|do|else|in|of|new|delete|void|throw|yield|await|from|import|export|default|require)\s*$/;
3304
+ const startsExpression = (b) => {
3305
+ const t = b.replace(/\s+$/, "");
3306
+ if (!t) return true;
3307
+ if (KEYWORD.test(b)) return true;
3308
+ return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
3309
+ };
3310
+ const exprStart = () => startsExpression(before());
3311
+ const taggedTemplate = () => {
3312
+ const b = out.slice(-48).join("");
3313
+ const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
3314
+ return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
3256
3315
  };
3257
3316
  const templateBody = () => {
3258
3317
  while (i < n) {
@@ -3275,8 +3334,9 @@ function stripForImports(code) {
3275
3334
  i++;
3276
3335
  }
3277
3336
  }
3337
+ sure = false;
3278
3338
  };
3279
- while (i < n) {
3339
+ while (i < n && sure) {
3280
3340
  const ch = code[i];
3281
3341
  const next = code[i + 1];
3282
3342
  if (ch === "/" && next === "/") {
@@ -3295,7 +3355,45 @@ function stripForImports(code) {
3295
3355
  out.push(" ");
3296
3356
  i += 2;
3297
3357
  }
3298
- } else if ((ch === '"' || ch === "'") && opensString()) {
3358
+ } else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
3359
+ const afterBrace = /[}>]\s*$/.test(before());
3360
+ const start = i;
3361
+ const mark = out.length;
3362
+ out.push("/");
3363
+ i++;
3364
+ let inClass = false;
3365
+ for (; ; ) {
3366
+ const c = code[i];
3367
+ if (c === void 0 || c === "\n") {
3368
+ if (afterBrace) {
3369
+ out.length = mark;
3370
+ out.push("/");
3371
+ i = start + 1;
3372
+ } else sure = false;
3373
+ break;
3374
+ }
3375
+ if (c === "\\") {
3376
+ out.push(" ", blank(code[i + 1] ?? ""));
3377
+ i += 2;
3378
+ continue;
3379
+ }
3380
+ i++;
3381
+ if (c === "[") inClass = true;
3382
+ else if (c === "]") inClass = false;
3383
+ else if (c === "/" && !inClass) {
3384
+ if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
3385
+ out.length = mark;
3386
+ out.push("/");
3387
+ i = start + 1;
3388
+ break;
3389
+ }
3390
+ out.push("/");
3391
+ break;
3392
+ }
3393
+ out.push(" ");
3394
+ }
3395
+ if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
3396
+ } else if ((ch === '"' || ch === "'") && exprStart()) {
3299
3397
  const keep = isSpecifier();
3300
3398
  out.push(ch);
3301
3399
  i++;
@@ -3308,11 +3406,12 @@ function stripForImports(code) {
3308
3406
  i++;
3309
3407
  }
3310
3408
  }
3311
- if (i < n) {
3409
+ if (code[i] !== ch) sure = false;
3410
+ else {
3312
3411
  out.push(code[i]);
3313
3412
  i++;
3314
3413
  }
3315
- } else if (ch === "`") {
3414
+ } else if (ch === "`" && (exprStart() || taggedTemplate())) {
3316
3415
  out.push("`");
3317
3416
  i++;
3318
3417
  templateBody();
@@ -3329,7 +3428,7 @@ function stripForImports(code) {
3329
3428
  i++;
3330
3429
  }
3331
3430
  }
3332
- return out.join("");
3431
+ return sure && templates.length === 0 ? out.join("") : null;
3333
3432
  }
3334
3433
  function bindings(clause) {
3335
3434
  const out = [];
@@ -3443,6 +3542,11 @@ function createTrail(ctx) {
3443
3542
  const files = [];
3444
3543
  let lost = false;
3445
3544
  const code = stripped(file);
3545
+ if (code === null) {
3546
+ const out2 = { files: [], lost: true };
3547
+ importsCache.set(file.absolutePath, out2);
3548
+ return out2;
3549
+ }
3446
3550
  const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
3447
3551
  for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
3448
3552
  for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
@@ -3479,20 +3583,23 @@ function createTrail(ctx) {
3479
3583
  };
3480
3584
  const strippedCache = /* @__PURE__ */ new Map();
3481
3585
  const stripped = (file) => {
3482
- let c = strippedCache.get(file.absolutePath);
3483
- if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
3484
- return c;
3586
+ if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
3587
+ return strippedCache.get(file.absolutePath);
3485
3588
  };
3486
3589
  const memo = /* @__PURE__ */ new WeakMap();
3487
3590
  const reach = (file, test2, depth, seen) => {
3488
3591
  let cache = memo.get(test2);
3489
- if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
3592
+ if (!cache) memo.set(test2, cache = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
3490
3593
  const k = `${file.absolutePath}\0${depth}`;
3491
- const cached = cache.get(k);
3492
- if (cached) return [cached, false];
3594
+ const free = cache.free.get(k);
3595
+ if (free) return [free, /* @__PURE__ */ new Set()];
3596
+ const reusable = cache.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
3597
+ if (reusable) return [reusable.result, new Set(reusable.cut)];
3493
3598
  let result;
3494
- let cut = false;
3495
- if (test2(stripped(file))) result = "yes";
3599
+ const cut = /* @__PURE__ */ new Set();
3600
+ const code = stripped(file);
3601
+ if (code === null) result = "unknown";
3602
+ else if (test2(code)) result = "yes";
3496
3603
  else {
3497
3604
  const { files, lost } = importsOf(file);
3498
3605
  let unknown = lost && depth > 0;
@@ -3501,7 +3608,7 @@ function createTrail(ctx) {
3501
3608
  seen.add(file.absolutePath);
3502
3609
  for (const abs of files) {
3503
3610
  if (seen.has(abs)) {
3504
- cut = true;
3611
+ cut.add(abs);
3505
3612
  continue;
3506
3613
  }
3507
3614
  const target = read(abs);
@@ -3510,7 +3617,7 @@ function createTrail(ctx) {
3510
3617
  continue;
3511
3618
  }
3512
3619
  const [r, c] = reach(target, test2, depth - 1, seen);
3513
- if (c) cut = true;
3620
+ for (const m of c) cut.add(m);
3514
3621
  if (r === "yes") {
3515
3622
  result = "yes";
3516
3623
  break;
@@ -3518,11 +3625,18 @@ function createTrail(ctx) {
3518
3625
  if (r === "unknown") unknown = true;
3519
3626
  }
3520
3627
  seen.delete(file.absolutePath);
3628
+ cut.delete(file.absolutePath);
3521
3629
  }
3522
3630
  if (result === "no" && unknown) result = "unknown";
3523
3631
  }
3524
- if (result === "yes" || !cut) cache.set(k, result);
3525
- return [result, cut && result !== "yes"];
3632
+ if (result === "yes" || cut.size === 0) {
3633
+ cache.free.set(k, result);
3634
+ return [result, /* @__PURE__ */ new Set()];
3635
+ }
3636
+ const entries = cache.cut.get(k) ?? [];
3637
+ entries.push({ cut: [...cut], result });
3638
+ cache.cut.set(k, entries);
3639
+ return [result, cut];
3526
3640
  };
3527
3641
  return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
3528
3642
  }