@marktiderman/genesis-cli 1.28.0 → 1.29.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.
@@ -35,7 +35,7 @@
35
35
  "version": "0.1.2"
36
36
  },
37
37
  "@marktiderman/genesis-chat": {
38
- "version": "0.11.0",
38
+ "version": "0.11.1",
39
39
  "blocks": {
40
40
  "chat": {
41
41
  "feature": {
@@ -108,25 +108,25 @@
108
108
  "version": "0.4.0"
109
109
  },
110
110
  "@marktiderman/genesis-core": {
111
- "version": "2.17.0"
111
+ "version": "2.18.0"
112
112
  },
113
113
  "@marktiderman/genesis-design-system": {
114
114
  "version": "1.13.0"
115
115
  },
116
116
  "@marktiderman/genesis-extension": {
117
- "version": "0.2.2"
117
+ "version": "0.2.3"
118
118
  },
119
119
  "@marktiderman/genesis-features": {
120
- "version": "0.9.0"
120
+ "version": "0.9.1"
121
121
  },
122
122
  "@marktiderman/genesis-forms": {
123
123
  "version": "0.11.1"
124
124
  },
125
125
  "@marktiderman/genesis-forms-builder": {
126
- "version": "0.6.7"
126
+ "version": "0.6.8"
127
127
  },
128
128
  "@marktiderman/genesis-forms-devtools": {
129
- "version": "0.1.4"
129
+ "version": "0.1.5"
130
130
  },
131
131
  "@marktiderman/genesis-forms-native": {
132
132
  "version": "0.3.0"
@@ -135,16 +135,16 @@
135
135
  "version": "0.3.3"
136
136
  },
137
137
  "@marktiderman/genesis-forms-studio": {
138
- "version": "0.6.4"
138
+ "version": "0.6.5"
139
139
  },
140
140
  "@marktiderman/genesis-forms-web": {
141
- "version": "0.8.1"
141
+ "version": "0.8.2"
142
142
  },
143
143
  "@marktiderman/genesis": {
144
- "version": "0.10.25"
144
+ "version": "0.11.1"
145
145
  },
146
146
  "@marktiderman/genesis-cli": {
147
- "version": "1.28.0"
147
+ "version": "1.29.0"
148
148
  },
149
149
  "@marktiderman/genesis-media": {
150
150
  "version": "0.3.0"
@@ -328,7 +328,7 @@
328
328
  }
329
329
  },
330
330
  "@marktiderman/genesis-notifications": {
331
- "version": "0.4.3",
331
+ "version": "0.4.4",
332
332
  "blocks": {
333
333
  "notifications": {
334
334
  "feature": {
@@ -423,7 +423,7 @@
423
423
  }
424
424
  },
425
425
  "@marktiderman/genesis-sites": {
426
- "version": "0.7.2",
426
+ "version": "0.7.3",
427
427
  "blocks": {
428
428
  "sites": {
429
429
  "feature": {
@@ -467,7 +467,7 @@
467
467
  }
468
468
  },
469
469
  "@marktiderman/genesis-studio": {
470
- "version": "0.4.2"
470
+ "version": "0.4.3"
471
471
  },
472
472
  "@marktiderman/genesis-studio-server": {
473
473
  "version": "0.6.0"
@@ -712,7 +712,7 @@
712
712
  }
713
713
  },
714
714
  "@marktiderman/genesis-support": {
715
- "version": "0.9.0",
715
+ "version": "0.10.0",
716
716
  "blocks": {
717
717
  "support-feedback": {
718
718
  "feature": {
@@ -1050,10 +1050,10 @@
1050
1050
  "version": "0.1.1"
1051
1051
  },
1052
1052
  "@marktiderman/genesis-ui": {
1053
- "version": "2.36.0"
1053
+ "version": "3.1.0"
1054
1054
  },
1055
1055
  "@marktiderman/genesis-ui-native": {
1056
- "version": "3.13.0"
1056
+ "version": "3.14.0"
1057
1057
  }
1058
1058
  }
1059
1059
  }
package/dist/index.js CHANGED
@@ -833,9 +833,9 @@ async function runScaffold(opts, fs) {
833
833
  function joinPath(...parts) {
834
834
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
835
835
  }
836
- function dirname(path50) {
837
- const idx = path50.lastIndexOf("/");
838
- return idx === -1 ? "." : path50.slice(0, idx);
836
+ function dirname(path51) {
837
+ const idx = path51.lastIndexOf("/");
838
+ return idx === -1 ? "." : path51.slice(0, idx);
839
839
  }
840
840
  function brandPackageJson(consumer, genesisVersion) {
841
841
  return JSON.stringify(
@@ -1093,8 +1093,8 @@ function routeTags(source) {
1093
1093
  var GUARD = /<((?:[A-Z]\w*)?(?:Admin|Staff)\w*(?:Guard|Route|Only)|RequireAdmin|RequireStaff)>/;
1094
1094
  function wireStudioRoute(source, route, pageImportPath) {
1095
1095
  const tags = routeTags(source);
1096
- const relative14 = route.replace(/^\//, "");
1097
- const existing = tags.find((t) => new RegExp(`path=["'](/?${relative14.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
1096
+ const relative15 = route.replace(/^\//, "");
1097
+ const existing = tags.find((t) => new RegExp(`path=["'](/?${relative15.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
1098
1098
  if (existing) {
1099
1099
  return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
1100
1100
  }
@@ -1102,17 +1102,17 @@ function wireStudioRoute(source, route, pageImportPath) {
1102
1102
  const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
1103
1103
  if (roots.length !== 1) {
1104
1104
  return {
1105
- skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative14}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
1105
+ skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative15}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
1106
1106
  };
1107
1107
  }
1108
1108
  const layout = roots[0];
1109
1109
  const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
1110
- if (base && !relative14.startsWith(`${base}/`)) {
1110
+ if (base && !relative15.startsWith(`${base}/`)) {
1111
1111
  return {
1112
1112
  skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
1113
1113
  };
1114
1114
  }
1115
- const childPath = base ? relative14.slice(base.length + 1) : relative14;
1115
+ const childPath = base ? relative15.slice(base.length + 1) : relative15;
1116
1116
  const guard = GUARD.exec(source)?.[1];
1117
1117
  const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
1118
1118
  const before = source.slice(0, layout.close);
@@ -1918,7 +1918,7 @@ function globToRegExp(glob) {
1918
1918
  }
1919
1919
  function globMatcher(globs) {
1920
1920
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1921
- return (path50) => res.some((re) => re.test(path50));
1921
+ return (path51) => res.some((re) => re.test(path51));
1922
1922
  }
1923
1923
  var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
1924
1924
  var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
@@ -3883,7 +3883,10 @@ var BUILTIN_RULES = [
3883
3883
  "custom-view-states",
3884
3884
  // the app's client layer (client-layer.ts)
3885
3885
  "client/layer",
3886
- "client/one-view-per-resource"
3886
+ "client/one-view-per-resource",
3887
+ // how the app reaches its database (data-access.ts)
3888
+ "data/declared-access",
3889
+ "data/access-rule-tests"
3887
3890
  ];
3888
3891
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
3889
3892
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -7280,6 +7283,167 @@ function importedNames(filePath, code) {
7280
7283
  return out;
7281
7284
  }
7282
7285
  var SCRIPT_EXTS7 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
7286
+ var SKIP_DIRS4 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage", ".expo"]);
7287
+ var TEST_FILE = /(^|\/)(__tests__\/|[^/]+\.(test|spec)\.[cm]?[jt]sx?$)/;
7288
+ var DOCS = "docs/DATA-ACCESS.md";
7289
+ var TABLE_WRITE = /\.from\(\s*(["'`])([\w.]+)\1\s*\)\s*\.\s*(insert|update|upsert|delete)\s*\(/g;
7290
+ var STORAGE_BEFORE = /\bstorage\s*\??\.?\s*$/;
7291
+ function balanced(code, start) {
7292
+ const open = code[start];
7293
+ const close = open === "{" ? "}" : open === "(" ? ")" : open === "[" ? "]" : "";
7294
+ if (!close) return "";
7295
+ const blank = blankStrings(code);
7296
+ let depth = 0;
7297
+ for (let i = start; i < blank.length; i++) {
7298
+ const ch = blank[i];
7299
+ if (ch === "{" || ch === "(" || ch === "[") depth++;
7300
+ else if (ch === "}" || ch === ")" || ch === "]") {
7301
+ depth--;
7302
+ if (depth === 0) return ch === close ? code.slice(start, i + 1) : "";
7303
+ }
7304
+ }
7305
+ return "";
7306
+ }
7307
+ function testFiles(root) {
7308
+ const out = [];
7309
+ const walk3 = (dir) => {
7310
+ let entries;
7311
+ try {
7312
+ entries = readdirSync(dir, { withFileTypes: true });
7313
+ } catch {
7314
+ return;
7315
+ }
7316
+ for (const entry of entries) {
7317
+ if (entry.isDirectory()) {
7318
+ if (!SKIP_DIRS4.has(entry.name) && !entry.name.startsWith(".")) walk3(path21.join(dir, entry.name));
7319
+ continue;
7320
+ }
7321
+ const abs = path21.join(dir, entry.name);
7322
+ const rel = path21.relative(root, abs).split(path21.sep).join("/");
7323
+ if (SCRIPT_EXTS7.has(path21.extname(entry.name)) && TEST_FILE.test(rel)) out.push(abs);
7324
+ }
7325
+ };
7326
+ walk3(root);
7327
+ return out;
7328
+ }
7329
+ function initializer(code, blank, name) {
7330
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7331
+ const decl = new RegExp(`\\b(const|let|var)\\s+${escaped}(?![\\w$])[^=;]*=\\s*\\{`).exec(blank);
7332
+ if (!decl) return null;
7333
+ const text = balanced(code, decl.index + decl[0].length - 1);
7334
+ return text ? { text, keyword: decl[1], at: decl.index } : null;
7335
+ }
7336
+ function objectDeclares(object) {
7337
+ const blank = blankStrings(object);
7338
+ let depth = 0;
7339
+ let declaredAt = -1;
7340
+ let lastAccess = -1;
7341
+ let lastSpread = -1;
7342
+ for (let i = 0; i < blank.length; i++) {
7343
+ const ch = blank[i];
7344
+ if (ch === "{" || ch === "(" || ch === "[") depth++;
7345
+ else if (ch === "}" || ch === ")" || ch === "]") depth--;
7346
+ else if (depth === 1 && blank.startsWith("...", i)) lastSpread = i;
7347
+ else if (depth === 1 && blank[i] === object[i] && /[\s{,]/.test(blank[i - 1] ?? " ") && /^(["'`]?)access\1\s*:/.test(object.slice(i))) {
7348
+ lastAccess = i;
7349
+ const value = /^(["'`]?)access\1\s*:\s*(["'`])([^"'`]*)\2/.exec(object.slice(i));
7350
+ declaredAt = value?.[3] === "declared" ? i : -1;
7351
+ }
7352
+ }
7353
+ return declaredAt !== -1 && declaredAt === lastAccess && lastSpread < declaredAt;
7354
+ }
7355
+ function inlineDeclares(call) {
7356
+ const blank = blankStrings(call);
7357
+ let depth = 0;
7358
+ for (let i = 0; i < blank.length; i++) {
7359
+ const ch = blank[i];
7360
+ if (ch === "{" && depth === 1 && objectDeclares(balanced(call, i))) return true;
7361
+ if (ch === "{" || ch === "(" || ch === "[") depth++;
7362
+ else if (ch === "}" || ch === ")" || ch === "]") depth--;
7363
+ }
7364
+ return false;
7365
+ }
7366
+ function optionsConstDeclares(code, blank, call) {
7367
+ const args = blankStrings(call).slice(1, -1);
7368
+ for (const [, name] of args.matchAll(/(?:^|,)\s*([A-Za-z_$][\w$]*)\s*(?=,|$)/g)) {
7369
+ const found = initializer(code, blank, name);
7370
+ if (!found || !objectDeclares(found.text)) continue;
7371
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7372
+ const reassigned = found.keyword !== "const" && new RegExp(`(?<![\\w$.])${escaped}\\s*=(?!=)`, "g").test(blank.slice(found.at + found.keyword.length + 1 + name.length));
7373
+ const changed = new RegExp(
7374
+ `(?<![\\w$.])${escaped}\\s*(?:\\.\\s*access|\\[[^\\]]*\\])\\s*=(?!=)|\\bdelete\\s+${escaped}\\s*(?:\\.\\s*access|\\[)|Object\\.assign\\(\\s*${escaped}(?![\\w$])`
7375
+ ).test(blank);
7376
+ if (!reassigned && !changed) return true;
7377
+ }
7378
+ return false;
7379
+ }
7380
+ function coverageTested(root) {
7381
+ for (const abs of testFiles(root)) {
7382
+ let code;
7383
+ try {
7384
+ code = stripBlockComments(readFileSync(abs, "utf8"), true);
7385
+ } catch {
7386
+ continue;
7387
+ }
7388
+ if (!code.includes("expectAccessRulesCover")) continue;
7389
+ if (/\bexpectAccessRulesCover\s*\(/.test(blankStrings(code))) return true;
7390
+ }
7391
+ return false;
7392
+ }
7393
+ function checkDataAccess(ctx) {
7394
+ for (const file of ctx.files) {
7395
+ if (!SCRIPT_EXTS7.has(file.ext)) continue;
7396
+ const blank = blankStrings(file.code);
7397
+ for (const m of blank.matchAll(/\bcreateSupabaseProvider\s*\(/g)) {
7398
+ const call = balanced(file.code, (m.index ?? 0) + m[0].length - 1);
7399
+ if (inlineDeclares(call) || optionsConstDeclares(file.code, blank, call)) continue;
7400
+ ctx.report({
7401
+ rule: "data/declared-access",
7402
+ level: "warn",
7403
+ file: file.path,
7404
+ line: lineAt(file.code, m.index ?? 0),
7405
+ subject: "createSupabaseProvider",
7406
+ message: `leaves its resources free to read and write their tables undeclared. Pass access: "declared", give each resource its read (source: a view or a function) and its writes (writes: named database functions), and opt a table in only with table: { \u2026, why } (${DOCS})`
7407
+ });
7408
+ }
7409
+ if (file.path.startsWith("supabase/") || file.path.includes("/supabase/functions/")) continue;
7410
+ for (const m of file.code.matchAll(TABLE_WRITE)) {
7411
+ const at = m.index ?? 0;
7412
+ if (blank[at] !== ".") continue;
7413
+ if (STORAGE_BEFORE.test(blank.slice(Math.max(0, at - 40), at))) continue;
7414
+ ctx.report({
7415
+ rule: "data/declared-access",
7416
+ level: "warn",
7417
+ file: file.path,
7418
+ line: lineAt(file.code, at),
7419
+ subject: `${m[2]}.${m[3]}`,
7420
+ message: `writes the ${m[2]} table directly (${m[3]}). Write through a named database function (the resource's writes, or a call to it), which holds the access rule; a write that must stay on the table is an allow entry for data/declared-access with its reason (${DOCS})`
7421
+ });
7422
+ }
7423
+ }
7424
+ const providers = providerCalls(ctx.files);
7425
+ if (providers.length === 0 || coverageTested(ctx.root)) return;
7426
+ const first = providers[0];
7427
+ ctx.report({
7428
+ rule: "data/access-rule-tests",
7429
+ level: "warn",
7430
+ file: first.file,
7431
+ line: first.line,
7432
+ subject: "expectAccessRulesCover",
7433
+ message: `no test checks that every database function the provider declares has an access-rule test. Add expectAccessRulesCover(providerOptions, [/* each accessRules spec */]) (@marktiderman/genesis-core/testing) to a test file: it fails for each declared function without one (${DOCS})`
7434
+ });
7435
+ }
7436
+ function providerCalls(files) {
7437
+ const out = [];
7438
+ for (const file of files) {
7439
+ if (!SCRIPT_EXTS7.has(file.ext)) continue;
7440
+ for (const m of blankStrings(file.code).matchAll(/\bcreateSupabaseProvider\s*\(/g)) {
7441
+ out.push({ file: file.path, line: lineAt(file.code, m.index ?? 0) });
7442
+ }
7443
+ }
7444
+ return out;
7445
+ }
7446
+ var SCRIPT_EXTS8 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
7283
7447
  var DECLARATION = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\n(?:export\s+)?(?:declare\s+)?(?:abstract\s+)?(?:function|const|let|class|interface|type|enum|namespace)\s+([A-Za-z_$][\w$]*)/g;
7284
7448
  var REEXPORT = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\nexport\s+(?:type\s+)?\{([^}]*)\}/g;
7285
7449
  function specifierParts(spec) {
@@ -7369,7 +7533,7 @@ function checkStabilityImports(ctx) {
7369
7533
  return cache2.get(pkg);
7370
7534
  };
7371
7535
  for (const file of ctx.files) {
7372
- if (!SCRIPT_EXTS7.has(file.ext)) continue;
7536
+ if (!SCRIPT_EXTS8.has(file.ext)) continue;
7373
7537
  for (const { pkg, specifier, names, line } of genesisNamedImports(file.code)) {
7374
7538
  const tags = tagsOf(pkg);
7375
7539
  if (!tags) continue;
@@ -7828,6 +7992,7 @@ var RULES = [
7828
7992
  "Never copy an older screen as a template. Old screens predate the primitives; the doctor flags what they did.",
7829
7993
  "A list screen is a view (`defineView`) rendered by `ResourceView`; a record view is `RecordView`; on the phone, `NativeResourceView`.",
7830
7994
  "Screens never call the database client (`supabase.from`, `.rpc`) directly: reads go through a view or a named data function, writes through the resource's provider rules.",
7995
+ `Data access is declared: the Supabase provider runs with \`access: "declared"\`; each resource reads through a view or a function (\`source\`) and writes through named database functions (\`writes\`, \`actions\`) that hold the access rule; a table is touched only with \`table: { \u2026, why }\`. Every declared function gets an access-rule test (\`accessRules\`), and one test (\`expectAccessRulesCover\`) fails for any declared function whose name no spec carries: it compares names only, so give it the same specs the cases are registered from. See ${GENESIS_DOCS}/DATA-ACCESS.md.`,
7831
7996
  "When a Genesis piece is close and does the same job, extend it: a prop, a variant, a slot, or your own component that wraps it. Never build a parallel copy beside it.",
7832
7997
  "When no Genesis piece does the job, invent it in the app: your own screens and components, on Genesis tokens and primitives. Genesis asks for no write-up or approval first (your app's own design review still applies); you may add it to `docs/genesis-upstream.md` if you think Genesis should have it.",
7833
7998
  "Run `genesis doctor` before you finish; it enforces these rules."
@@ -8995,6 +9160,7 @@ function builtinChecks(config, options = {}) {
8995
9160
  { name: "removed-scope-names", check: checkRemovedScopeNames },
8996
9161
  { name: "app-parts", check: checkAppParts },
8997
9162
  { name: "client-layer", check: checkClientLayer },
9163
+ { name: "data-access", check: checkDataAccess },
8998
9164
  { name: "stability-imports", check: checkStabilityImports },
8999
9165
  { name: "agent-guide", check: (ctx) => {
9000
9166
  checkAgentGuide(ctx);