@marktiderman/genesis-cli 1.27.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.
- package/README.md +67 -1
- package/dist/cli.js +1274 -424
- package/dist/cli.js.map +1 -1
- package/dist/{config-ARs2YQ60.d.ts → config-BmMsEWU-.d.ts} +7 -0
- package/dist/doctor.d.ts +3 -3
- package/dist/doctor.js +628 -7
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +11 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +41 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.js +636 -15
- package/dist/index.js.map +1 -1
- package/dist/starter/__tests__/starter.test.ts +8 -0
- package/dist/starter/fingerprint.config.js +18 -0
- package/dist/starter/supabase/migrations/20261025000095_genesis_support_ticket_fixes.sql +115 -0
- package/dist/starter/supabase/tests/database/genesis_support_ticket_fixes.test.sql +121 -0
- package/dist/verify.d.ts +209 -0
- package/dist/verify.js +549 -0
- package/dist/verify.js.map +1 -0
- package/dist/vite.js +628 -7
- package/dist/vite.js.map +1 -1
- package/package.json +18 -4
package/dist/doctor.js
CHANGED
|
@@ -24,6 +24,15 @@ var __export = (target, all) => {
|
|
|
24
24
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
// src/regexp.ts
|
|
28
|
+
function escapeRegExp(s) {
|
|
29
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
30
|
+
}
|
|
31
|
+
var init_regexp = __esm({
|
|
32
|
+
"src/regexp.ts"() {
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
27
36
|
// src/introspect/catalog-text.ts
|
|
28
37
|
function tokenize(tree) {
|
|
29
38
|
const tokens = [];
|
|
@@ -153,9 +162,6 @@ function splitTopLevel(expr, separator) {
|
|
|
153
162
|
parts.push(expr.slice(from));
|
|
154
163
|
return parts;
|
|
155
164
|
}
|
|
156
|
-
function escapeRegExp(s) {
|
|
157
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
158
|
-
}
|
|
159
165
|
function checkEnumValues(definition, column) {
|
|
160
166
|
const outer = /^CHECK \((.*)\)(?: NOT VALID)?$/s.exec(definition.trim());
|
|
161
167
|
if (!outer) return void 0;
|
|
@@ -190,6 +196,7 @@ function checkEnumValues(definition, column) {
|
|
|
190
196
|
var CAST, LITERAL;
|
|
191
197
|
var init_catalog_text = __esm({
|
|
192
198
|
"src/introspect/catalog-text.ts"() {
|
|
199
|
+
init_regexp();
|
|
193
200
|
CAST = String.raw`::[a-z][a-z ]*(?:\(\d+(?:,\d+)?\))?`;
|
|
194
201
|
LITERAL = String.raw`'((?:[^']|'')*)'${CAST}`;
|
|
195
202
|
}
|
|
@@ -938,6 +945,7 @@ function readGenesisConfig(root) {
|
|
|
938
945
|
}
|
|
939
946
|
if (raw.appFolder !== void 0) out.appFolder = validateAppFolder(raw.appFolder, file);
|
|
940
947
|
if (raw.environments !== void 0) out.environments = validateEnvironments(raw.environments, file);
|
|
948
|
+
if (raw.client !== void 0) out.client = validateClient(raw.client, file);
|
|
941
949
|
return out;
|
|
942
950
|
}
|
|
943
951
|
var PLAIN_FOLDER = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,59}(?:\/[A-Za-z0-9_][A-Za-z0-9_.-]{0,59}){0,7}$/;
|
|
@@ -949,6 +957,16 @@ function validateAppFolder(raw, source = "config") {
|
|
|
949
957
|
if (!isPlainFolder(norm)) throw new GenesisConfigError(`${source}: "appFolder" must be the app's folder from the repository root, such as "mobile" or "apps/phone" (got ${JSON.stringify(raw)})`);
|
|
950
958
|
return norm;
|
|
951
959
|
}
|
|
960
|
+
function validateClient(raw, source = "config") {
|
|
961
|
+
const fail = (msg) => {
|
|
962
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
963
|
+
};
|
|
964
|
+
if (!isObject(raw)) return fail(`"client" must be { "dir": "<the client layer's folder, e.g. src/client>" }`);
|
|
965
|
+
for (const key2 of Object.keys(raw)) if (key2 !== "dir" && key2 !== "$comment") fail(`client: unknown setting "${key2}" (known: dir)`);
|
|
966
|
+
const dir = typeof raw.dir === "string" ? raw.dir.replace(/^\.\//, "").replace(/\/+$/, "") : "";
|
|
967
|
+
if (!isPlainFolder(dir)) return fail(`client.dir must be a folder inside the app, such as "src/client" (got ${JSON.stringify(raw.dir)})`);
|
|
968
|
+
return { dir };
|
|
969
|
+
}
|
|
952
970
|
function validateSupabase(raw, source = "config") {
|
|
953
971
|
const fail = (msg) => {
|
|
954
972
|
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
@@ -1212,7 +1230,7 @@ function globToRegExp(glob) {
|
|
|
1212
1230
|
}
|
|
1213
1231
|
function globMatcher(globs) {
|
|
1214
1232
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1215
|
-
return (
|
|
1233
|
+
return (path51) => res.some((re) => re.test(path51));
|
|
1216
1234
|
}
|
|
1217
1235
|
var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
1218
1236
|
var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
@@ -2774,6 +2792,319 @@ function resolvePlugin(id, configDir) {
|
|
|
2774
2792
|
function resolveFrom(id, from) {
|
|
2775
2793
|
return createRequire(path21.join(from, "noop.js")).resolve(id);
|
|
2776
2794
|
}
|
|
2795
|
+
|
|
2796
|
+
// src/doctor/js-scan.ts
|
|
2797
|
+
var IDENT_START = /[A-Za-z_$]/;
|
|
2798
|
+
var IDENT = /[\w$]/;
|
|
2799
|
+
var PUNCT3 = ["...", "===", "!==", "**=", "<<=", ">>=", "??=", "&&=", "||="];
|
|
2800
|
+
var PUNCT2 = ["=>", "==", "!=", "<=", ">=", "&&", "||", "??", "?.", "++", "--", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "**", "<<", ">>"];
|
|
2801
|
+
var EXPRESSION_KEYWORDS = /* @__PURE__ */ new Set(["return", "typeof", "case", "do", "else", "in", "new", "delete", "void", "throw", "yield", "await", "instanceof"]);
|
|
2802
|
+
var TYPE_PARAMETERS = /^<\s*[A-Za-z_$][\w$]*\s*(?:,|extends\b)/;
|
|
2803
|
+
function scanCode(code, options = {}) {
|
|
2804
|
+
const jsx = options.jsx ?? true;
|
|
2805
|
+
const tokens = [];
|
|
2806
|
+
const push = (kind, value) => tokens.push({ kind, value, index: tokens.length });
|
|
2807
|
+
const expressionNext = (start) => {
|
|
2808
|
+
if (tokens.length <= start) return true;
|
|
2809
|
+
const t = tokens[tokens.length - 1];
|
|
2810
|
+
if (!t) return true;
|
|
2811
|
+
if (t.kind === "ident") return EXPRESSION_KEYWORDS.has(t.value);
|
|
2812
|
+
if (t.kind === "jsxTag" || t.kind === "literal") return false;
|
|
2813
|
+
return !(t.value === ")" || t.value === "]" || t.value === "}" || t.value === "<>");
|
|
2814
|
+
};
|
|
2815
|
+
const skipString2 = (i2, quote2) => {
|
|
2816
|
+
let j = i2 + 1;
|
|
2817
|
+
while (j < code.length && code[j] !== quote2) {
|
|
2818
|
+
if (code[j] === "\\") j++;
|
|
2819
|
+
else if (code[j] === "\n") return j;
|
|
2820
|
+
j++;
|
|
2821
|
+
}
|
|
2822
|
+
return j + 1;
|
|
2823
|
+
};
|
|
2824
|
+
const skipAttribute = (i2, quote2) => {
|
|
2825
|
+
const end = code.indexOf(quote2, i2 + 1);
|
|
2826
|
+
return end < 0 ? code.length : end + 1;
|
|
2827
|
+
};
|
|
2828
|
+
const skipRegex = (i2) => {
|
|
2829
|
+
let j = i2 + 1;
|
|
2830
|
+
let inClass = false;
|
|
2831
|
+
while (j < code.length && code[j] !== "\n") {
|
|
2832
|
+
const c = code[j];
|
|
2833
|
+
if (c === "\\") j++;
|
|
2834
|
+
else if (c === "[") inClass = true;
|
|
2835
|
+
else if (c === "]") inClass = false;
|
|
2836
|
+
else if (c === "/" && !inClass) {
|
|
2837
|
+
j++;
|
|
2838
|
+
while (j < code.length && IDENT.test(code[j])) j++;
|
|
2839
|
+
return j;
|
|
2840
|
+
}
|
|
2841
|
+
j++;
|
|
2842
|
+
}
|
|
2843
|
+
return j;
|
|
2844
|
+
};
|
|
2845
|
+
const skipTrivia = (i2) => {
|
|
2846
|
+
let j = i2;
|
|
2847
|
+
for (; ; ) {
|
|
2848
|
+
while (j < code.length && /\s/.test(code[j])) j++;
|
|
2849
|
+
if (code.startsWith("//", j)) {
|
|
2850
|
+
const end = code.indexOf("\n", j);
|
|
2851
|
+
j = end < 0 ? code.length : end;
|
|
2852
|
+
} else if (code.startsWith("/*", j)) {
|
|
2853
|
+
const end = code.indexOf("*/", j + 2);
|
|
2854
|
+
j = end < 0 ? code.length : end + 2;
|
|
2855
|
+
} else return j;
|
|
2856
|
+
}
|
|
2857
|
+
};
|
|
2858
|
+
const stack = [{ k: "code", depth: 0, stop: false, start: 0 }];
|
|
2859
|
+
const openCode = () => stack.push({ k: "code", depth: 0, stop: true, start: tokens.length });
|
|
2860
|
+
const openElement = (i2) => {
|
|
2861
|
+
if (code[i2 + 1] === ">") {
|
|
2862
|
+
stack.push({ k: "children" });
|
|
2863
|
+
return i2 + 2;
|
|
2864
|
+
}
|
|
2865
|
+
let j = i2 + 1;
|
|
2866
|
+
while (j < code.length && /[\w$.:-]/.test(code[j])) j++;
|
|
2867
|
+
const name = code.slice(i2 + 1, j);
|
|
2868
|
+
if (name) push("jsxTag", name.split(/[.:]/)[0]);
|
|
2869
|
+
stack.push({ k: "tag" });
|
|
2870
|
+
return j;
|
|
2871
|
+
};
|
|
2872
|
+
const closeElement = () => {
|
|
2873
|
+
stack.pop();
|
|
2874
|
+
push("punct", "<>");
|
|
2875
|
+
};
|
|
2876
|
+
let i = 0;
|
|
2877
|
+
while (i < code.length) {
|
|
2878
|
+
const top = stack[stack.length - 1];
|
|
2879
|
+
if (top.k === "code") {
|
|
2880
|
+
i = skipTrivia(i);
|
|
2881
|
+
if (i >= code.length) break;
|
|
2882
|
+
const c = code[i];
|
|
2883
|
+
if (c === '"' || c === "'") {
|
|
2884
|
+
i = skipString2(i, c);
|
|
2885
|
+
push("literal", "''");
|
|
2886
|
+
} else if (c === "`") {
|
|
2887
|
+
stack.push({ k: "template" });
|
|
2888
|
+
i++;
|
|
2889
|
+
} else if (IDENT_START.test(c)) {
|
|
2890
|
+
let j = i + 1;
|
|
2891
|
+
while (j < code.length && IDENT.test(code[j])) j++;
|
|
2892
|
+
push("ident", code.slice(i, j));
|
|
2893
|
+
i = j;
|
|
2894
|
+
} else if (/\d/.test(c) || c === "." && /\d/.test(code[i + 1] ?? "")) {
|
|
2895
|
+
let j = i + 1;
|
|
2896
|
+
while (j < code.length && /[\w.]/.test(code[j])) j++;
|
|
2897
|
+
push("literal", "0");
|
|
2898
|
+
i = j;
|
|
2899
|
+
} else if (c === "/" && expressionNext(top.start)) {
|
|
2900
|
+
i = skipRegex(i);
|
|
2901
|
+
push("literal", "//");
|
|
2902
|
+
} else if (c === "<" && jsx && expressionNext(top.start) && /[A-Za-z_$>]/.test(code[i + 1] ?? "") && !TYPE_PARAMETERS.test(code.slice(i, i + 200))) {
|
|
2903
|
+
i = openElement(i);
|
|
2904
|
+
} else if (c === "{") {
|
|
2905
|
+
top.depth++;
|
|
2906
|
+
push("punct", "{");
|
|
2907
|
+
i++;
|
|
2908
|
+
} else if (c === "}") {
|
|
2909
|
+
i++;
|
|
2910
|
+
if (top.depth === 0 && top.stop) stack.pop();
|
|
2911
|
+
else {
|
|
2912
|
+
top.depth = Math.max(0, top.depth - 1);
|
|
2913
|
+
push("punct", "}");
|
|
2914
|
+
}
|
|
2915
|
+
} else {
|
|
2916
|
+
const three = code.slice(i, i + 3);
|
|
2917
|
+
const two = code.slice(i, i + 2);
|
|
2918
|
+
const p = PUNCT3.includes(three) ? three : PUNCT2.includes(two) ? two : c;
|
|
2919
|
+
push("punct", p);
|
|
2920
|
+
i += p.length;
|
|
2921
|
+
}
|
|
2922
|
+
} else if (top.k === "template") {
|
|
2923
|
+
const c = code[i];
|
|
2924
|
+
if (c === "\\") i += 2;
|
|
2925
|
+
else if (c === "`") {
|
|
2926
|
+
stack.pop();
|
|
2927
|
+
push("literal", "``");
|
|
2928
|
+
i++;
|
|
2929
|
+
} else if (c === "$" && code[i + 1] === "{") {
|
|
2930
|
+
openCode();
|
|
2931
|
+
i += 2;
|
|
2932
|
+
} else i++;
|
|
2933
|
+
} else if (top.k === "tag") {
|
|
2934
|
+
i = skipTrivia(i);
|
|
2935
|
+
const c = code[i];
|
|
2936
|
+
if (c === void 0) break;
|
|
2937
|
+
if (c === "/" && code[i + 1] === ">") {
|
|
2938
|
+
closeElement();
|
|
2939
|
+
i += 2;
|
|
2940
|
+
} else if (c === ">") {
|
|
2941
|
+
stack[stack.length - 1] = { k: "children" };
|
|
2942
|
+
i++;
|
|
2943
|
+
} else if (c === "{") {
|
|
2944
|
+
openCode();
|
|
2945
|
+
i++;
|
|
2946
|
+
} else if (c === '"' || c === "'") i = skipAttribute(i, c);
|
|
2947
|
+
else if (c === "<") i = openElement(i);
|
|
2948
|
+
else i++;
|
|
2949
|
+
} else {
|
|
2950
|
+
const c = code[i];
|
|
2951
|
+
if (c === "<" && code[i + 1] === "/") {
|
|
2952
|
+
const end = code.indexOf(">", i);
|
|
2953
|
+
i = end < 0 ? code.length : end + 1;
|
|
2954
|
+
closeElement();
|
|
2955
|
+
} else if (c === "<" && /[A-Za-z_$>]/.test(code[i + 1] ?? "")) i = openElement(i);
|
|
2956
|
+
else if (c === "{") {
|
|
2957
|
+
openCode();
|
|
2958
|
+
i++;
|
|
2959
|
+
} else i++;
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
return tokens;
|
|
2963
|
+
}
|
|
2964
|
+
function usesAsCode(code, name, options = {}) {
|
|
2965
|
+
const tokens = scanCode(code, options);
|
|
2966
|
+
return tokens.some((t, i) => {
|
|
2967
|
+
if (t.value !== name) return false;
|
|
2968
|
+
if (t.kind === "jsxTag") return true;
|
|
2969
|
+
if (t.kind !== "ident") return false;
|
|
2970
|
+
const before = tokens[i - 1];
|
|
2971
|
+
const after = tokens[i + 1];
|
|
2972
|
+
if (before?.value === "." || before?.value === "?." || before?.value === "as" || before?.value === "import") return false;
|
|
2973
|
+
if (after?.value === ":" && (before?.value === "{" || before?.value === ",")) return false;
|
|
2974
|
+
return true;
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
var NOT_METHODS = /* @__PURE__ */ new Set(["if", "for", "while", "switch", "with", "function", "return", "typeof", "await", "new"]);
|
|
2978
|
+
var BEFORE_METHOD = /* @__PURE__ */ new Set(["{", "}", ";", ",", "*", "async", "get", "set", "static", "public", "private", "protected", "readonly", "override", "abstract", "declare", "accessor"]);
|
|
2979
|
+
var TYPE_PARAMETERS_REACH = 200;
|
|
2980
|
+
var OPENS = /* @__PURE__ */ new Set(["(", "[", "{"]);
|
|
2981
|
+
var CLOSES = /* @__PURE__ */ new Set([")", "]", "}"]);
|
|
2982
|
+
function boundNames(list) {
|
|
2983
|
+
const out = [];
|
|
2984
|
+
const params = [[]];
|
|
2985
|
+
let depth = 0;
|
|
2986
|
+
let angles = 0;
|
|
2987
|
+
let inType = false;
|
|
2988
|
+
for (const t of list) {
|
|
2989
|
+
if (OPENS.has(t.value)) depth++;
|
|
2990
|
+
else if (CLOSES.has(t.value)) depth--;
|
|
2991
|
+
else if (depth === 0 && t.value === ":") inType = true;
|
|
2992
|
+
else if (depth === 0 && t.value === "=") inType = false;
|
|
2993
|
+
else if (inType && t.value === "<") angles++;
|
|
2994
|
+
else if (inType && (t.value === ">" || t.value === ">>")) angles = Math.max(0, angles - t.value.length);
|
|
2995
|
+
if (depth === 0 && angles === 0 && t.value === ",") {
|
|
2996
|
+
params.push([]);
|
|
2997
|
+
inType = false;
|
|
2998
|
+
} else params[params.length - 1].push(t);
|
|
2999
|
+
}
|
|
3000
|
+
for (const param of params) {
|
|
3001
|
+
let d = 0;
|
|
3002
|
+
let end = param.length;
|
|
3003
|
+
for (let k = 0; k < param.length; k++) {
|
|
3004
|
+
const v = param[k].value;
|
|
3005
|
+
if (OPENS.has(v)) d++;
|
|
3006
|
+
else if (CLOSES.has(v)) d--;
|
|
3007
|
+
else if (d === 0 && (v === "=" || v === ":" || v === "?")) {
|
|
3008
|
+
end = k;
|
|
3009
|
+
break;
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
const pattern = param.slice(0, end);
|
|
3013
|
+
let skipping = -1;
|
|
3014
|
+
d = 0;
|
|
3015
|
+
for (let k = 0; k < pattern.length; k++) {
|
|
3016
|
+
const t = pattern[k];
|
|
3017
|
+
if (t.value === "[" && skipping < 0) {
|
|
3018
|
+
let depth2 = 0;
|
|
3019
|
+
let close = k;
|
|
3020
|
+
for (; close < pattern.length; close++) {
|
|
3021
|
+
const v = pattern[close].value;
|
|
3022
|
+
if (OPENS.has(v)) depth2++;
|
|
3023
|
+
else if (CLOSES.has(v) && --depth2 === 0) break;
|
|
3024
|
+
}
|
|
3025
|
+
if (pattern[close + 1]?.value === ":") {
|
|
3026
|
+
k = close;
|
|
3027
|
+
continue;
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
if (OPENS.has(t.value)) d++;
|
|
3031
|
+
else if (CLOSES.has(t.value)) {
|
|
3032
|
+
d--;
|
|
3033
|
+
if (skipping > d) skipping = -1;
|
|
3034
|
+
}
|
|
3035
|
+
if (skipping >= 0) {
|
|
3036
|
+
if (t.value === "," && d === skipping) skipping = -1;
|
|
3037
|
+
continue;
|
|
3038
|
+
}
|
|
3039
|
+
if (t.value === "=") {
|
|
3040
|
+
skipping = d;
|
|
3041
|
+
continue;
|
|
3042
|
+
}
|
|
3043
|
+
if (t.kind === "ident" && pattern[k + 1]?.value !== ":") out.push(t.value);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
return out;
|
|
3047
|
+
}
|
|
3048
|
+
function boundAsParameter(code, name, options = {}) {
|
|
3049
|
+
const tokens = scanCode(code, options);
|
|
3050
|
+
const match = new Int32Array(tokens.length).fill(-1);
|
|
3051
|
+
const open = [];
|
|
3052
|
+
tokens.forEach((t, k) => {
|
|
3053
|
+
if (t.value === "(") open.push(k);
|
|
3054
|
+
else if (t.value === ")" && open.length) match[open.pop()] = k;
|
|
3055
|
+
});
|
|
3056
|
+
const arrowAfter = (end) => {
|
|
3057
|
+
const next = tokens[end + 1];
|
|
3058
|
+
if (next?.value === "=>") return true;
|
|
3059
|
+
if (next?.value !== ":") return false;
|
|
3060
|
+
let depth = 0;
|
|
3061
|
+
for (let k = end + 2; k < Math.min(tokens.length, end + 200); k++) {
|
|
3062
|
+
const v = tokens[k].value;
|
|
3063
|
+
if (v === "(" || v === "{" || v === "[" || v === "<") depth++;
|
|
3064
|
+
else if (v === ")" || v === "}" || v === "]" || v === ">") depth--;
|
|
3065
|
+
if (depth < 0) return false;
|
|
3066
|
+
if (depth === 0 && v === "=>") return true;
|
|
3067
|
+
if (depth === 0 && (v === ";" || v === "," || v === "=")) return false;
|
|
3068
|
+
}
|
|
3069
|
+
return false;
|
|
3070
|
+
};
|
|
3071
|
+
const beforeTypeParameters = (paren) => {
|
|
3072
|
+
let k = paren - 1;
|
|
3073
|
+
if (tokens[k]?.value !== ">" && tokens[k]?.value !== ">>") return k;
|
|
3074
|
+
let depth = 0;
|
|
3075
|
+
for (const stop = Math.max(0, k - TYPE_PARAMETERS_REACH); k >= stop; k--) {
|
|
3076
|
+
const v = tokens[k].value;
|
|
3077
|
+
if (v === ">") depth++;
|
|
3078
|
+
else if (v === ">>") depth += 2;
|
|
3079
|
+
else if (v === "<" && --depth === 0) return k - 1;
|
|
3080
|
+
}
|
|
3081
|
+
return -1;
|
|
3082
|
+
};
|
|
3083
|
+
const isFunction = (paren) => {
|
|
3084
|
+
let k = beforeTypeParameters(paren);
|
|
3085
|
+
if (k < 0) return false;
|
|
3086
|
+
if (tokens[k]?.kind === "ident" && tokens[k].value !== "function") k--;
|
|
3087
|
+
if (tokens[k]?.value === "*") k--;
|
|
3088
|
+
return tokens[k]?.value === "function";
|
|
3089
|
+
};
|
|
3090
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
3091
|
+
const t = tokens[i];
|
|
3092
|
+
if (t.value === "=>" && tokens[i - 1]?.kind === "ident" && tokens[i - 1].value === name && tokens[i - 2]?.value !== ".") return true;
|
|
3093
|
+
if (t.value !== "(") continue;
|
|
3094
|
+
const end = match[i];
|
|
3095
|
+
if (end < 0) continue;
|
|
3096
|
+
const before = tokens[i - 1];
|
|
3097
|
+
const catchClause = before?.value === "catch";
|
|
3098
|
+
const nameAt = beforeTypeParameters(i);
|
|
3099
|
+
const methodName = nameAt >= 0 ? tokens[nameAt] : void 0;
|
|
3100
|
+
const typed = tokens[end + 1]?.value === ":" && !arrowAfter(end);
|
|
3101
|
+
const method = !catchClause && methodName?.kind === "ident" && !NOT_METHODS.has(methodName.value) && (tokens[end + 1]?.value === "{" || typed && (nameAt === 0 || BEFORE_METHOD.has(tokens[nameAt - 1].value)));
|
|
3102
|
+
if ((catchClause || isFunction(i) || method || arrowAfter(end)) && boundNames(tokens.slice(i + 1, end)).includes(name)) return true;
|
|
3103
|
+
}
|
|
3104
|
+
return false;
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
// src/doctor/rules.ts
|
|
2777
3108
|
var BUILTIN_RULES = [
|
|
2778
3109
|
"local-primitives",
|
|
2779
3110
|
// figma (figma/routes.ts; runs when genesis.config.json has a figma block)
|
|
@@ -2861,7 +3192,13 @@ var BUILTIN_RULES = [
|
|
|
2861
3192
|
// custom views and app parts (custom-views.ts)
|
|
2862
3193
|
"app-part-colors",
|
|
2863
3194
|
"app-part-name",
|
|
2864
|
-
"custom-view-states"
|
|
3195
|
+
"custom-view-states",
|
|
3196
|
+
// the app's client layer (client-layer.ts)
|
|
3197
|
+
"client/layer",
|
|
3198
|
+
"client/one-view-per-resource",
|
|
3199
|
+
// how the app reaches its database (data-access.ts)
|
|
3200
|
+
"data/declared-access",
|
|
3201
|
+
"data/access-rule-tests"
|
|
2865
3202
|
];
|
|
2866
3203
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
2867
3204
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -3000,14 +3337,32 @@ function checkShadowedExports(ctx) {
|
|
|
3000
3337
|
const re = /\bexport\s+(?:default\s+)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)/g;
|
|
3001
3338
|
for (const file of ctx.files) {
|
|
3002
3339
|
if (!SCRIPT_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
|
|
3340
|
+
const wrapped = wrappedGenesisNames(file.code, ctx.genesis.uiPackage, { jsx: file.ext !== ".ts" && file.ext !== ".mts" });
|
|
3003
3341
|
file.code.split("\n").forEach((text, i) => {
|
|
3004
3342
|
for (const m of text.matchAll(re)) {
|
|
3005
3343
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
3344
|
+
if (wrapped.has(m[1])) continue;
|
|
3006
3345
|
ctx.report({ rule: "shadowed-export", file: file.path, line: i + 1, subject: m[1], message: `shadows the Genesis export '${m[1]}'; reuse or extend ${m[1]} from ${ctx.genesis.uiPackage} (or rename yours if it's a different thing)` });
|
|
3007
3346
|
}
|
|
3008
3347
|
});
|
|
3009
3348
|
}
|
|
3010
3349
|
}
|
|
3350
|
+
function wrappedGenesisNames(code, uiPackage, options = {}) {
|
|
3351
|
+
const out = /* @__PURE__ */ new Set();
|
|
3352
|
+
const pkg = uiPackage.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
3353
|
+
const re = new RegExp(`\\bimport\\s+(?:type\\s+)?\\{([^}]*)\\}\\s*from\\s*["']${pkg}(?:/[^"']*)?["']`, "g");
|
|
3354
|
+
for (const m of code.matchAll(re)) {
|
|
3355
|
+
if (/^import\s+type\b/.test(m[0])) continue;
|
|
3356
|
+
for (const part of m[1].split(",")) {
|
|
3357
|
+
const spec = part.trim();
|
|
3358
|
+
if (!spec || spec.startsWith("type ")) continue;
|
|
3359
|
+
const [imported, local] = spec.split(/\s+as\s+/).map((x) => x.trim());
|
|
3360
|
+
if (!imported || !local || local === imported) continue;
|
|
3361
|
+
if (usesAsCode(code, local, options)) out.add(imported);
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
return out;
|
|
3365
|
+
}
|
|
3011
3366
|
function unusedComponents(ctx) {
|
|
3012
3367
|
const used = /* @__PURE__ */ new Set();
|
|
3013
3368
|
const pkg = ctx.genesis.uiPackage.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
@@ -6140,7 +6495,270 @@ function checkAppParts(ctx) {
|
|
|
6140
6495
|
}
|
|
6141
6496
|
}
|
|
6142
6497
|
}
|
|
6143
|
-
|
|
6498
|
+
init_regexp();
|
|
6499
|
+
var JSX_EXTS5 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
6500
|
+
var SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"]);
|
|
6501
|
+
var DEFAULT_CLIENT_DIR = "src/client";
|
|
6502
|
+
function clientLayer(root, files) {
|
|
6503
|
+
let dir = DEFAULT_CLIENT_DIR;
|
|
6504
|
+
try {
|
|
6505
|
+
dir = readGenesisConfig(root)?.client?.dir ?? DEFAULT_CLIENT_DIR;
|
|
6506
|
+
} catch {
|
|
6507
|
+
}
|
|
6508
|
+
const inside2 = `${dir}/`;
|
|
6509
|
+
const present = files.some((f) => f.path.startsWith(inside2) && /(^|\/)resource-view\.(t|j)sx?$/.test(f.path)) || existsSync(path21.join(root, dir, "resource-view.tsx"));
|
|
6510
|
+
const recordWrapper = files.some((f) => f.path.startsWith(inside2) && /(^|\/)record-view\.(t|j)sx?$/.test(f.path)) || existsSync(path21.join(root, dir, "record-view.tsx"));
|
|
6511
|
+
return { dir, present, recordWrapper };
|
|
6512
|
+
}
|
|
6513
|
+
function genesisImports(code, uiPackage) {
|
|
6514
|
+
const out = /* @__PURE__ */ new Map();
|
|
6515
|
+
const escaped = uiPackage.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
6516
|
+
const re = new RegExp(`import\\s*(?:type\\s+)?\\{([^}]*)\\}\\s*from\\s*["']${escaped}(?:/data)?["']`, "g");
|
|
6517
|
+
for (const m of code.matchAll(re)) {
|
|
6518
|
+
if (/^\s*type\s/.test(m[0].slice(6))) continue;
|
|
6519
|
+
for (const part of m[1].split(",")) {
|
|
6520
|
+
const spec = part.trim().replace(/^type\s+/, "");
|
|
6521
|
+
if (!spec || part.trim().startsWith("type ")) continue;
|
|
6522
|
+
const [imported, local] = spec.split(/\s+as\s+/).map((x) => x.trim());
|
|
6523
|
+
if (imported === "ResourceView" || imported === "RecordView") out.set(local ?? imported, imported);
|
|
6524
|
+
}
|
|
6525
|
+
}
|
|
6526
|
+
return out;
|
|
6527
|
+
}
|
|
6528
|
+
function checkClientLayer(ctx) {
|
|
6529
|
+
const layer = clientLayer(ctx.root, ctx.files);
|
|
6530
|
+
const inside2 = `${layer.dir}/`;
|
|
6531
|
+
if (layer.present) {
|
|
6532
|
+
for (const file of ctx.files) {
|
|
6533
|
+
if (!JSX_EXTS5.has(file.ext) || file.path.startsWith(inside2)) continue;
|
|
6534
|
+
const imported = genesisImports(file.code, ctx.genesis.uiPackage);
|
|
6535
|
+
for (const [local, name] of imported) {
|
|
6536
|
+
if (name === "RecordView" && !layer.recordWrapper) continue;
|
|
6537
|
+
const at = file.code.search(new RegExp(`<${local}\\b`));
|
|
6538
|
+
if (at < 0) continue;
|
|
6539
|
+
ctx.report({
|
|
6540
|
+
rule: "client/layer",
|
|
6541
|
+
level: "warn",
|
|
6542
|
+
file: file.path,
|
|
6543
|
+
line: lineAt(file.code, at),
|
|
6544
|
+
subject: name,
|
|
6545
|
+
message: `renders Genesis's <${name}> directly; the app has a client layer (${layer.dir}), so render its ${name === "ResourceView" ? "ResourceView from resource-view.tsx" : "RecordView from record-view.tsx"}, and its defaults reach this screen too (docs/adr/0020-client-layer.md)`
|
|
6546
|
+
});
|
|
6547
|
+
}
|
|
6548
|
+
}
|
|
6549
|
+
}
|
|
6550
|
+
if (!layer.present) return;
|
|
6551
|
+
const seen = /* @__PURE__ */ new Map();
|
|
6552
|
+
for (const file of ctx.files) {
|
|
6553
|
+
if (!SCRIPT_EXTS6.has(file.ext) || SHOWN_OR_TRIED.test(file.path)) continue;
|
|
6554
|
+
const imports = importedNames(file.path, file.code);
|
|
6555
|
+
for (const m of file.code.matchAll(/\bdefineView\s*(?:<[^>]*>)?\s*\(\s*([A-Za-z_$][\w$]*)((?:\s*(?:\.\s*[A-Za-z_$][\w$]*|\[\s*["'`][^"'`]+["'`]\s*\]))*)\s*[,)]/g)) {
|
|
6556
|
+
const base = m[1];
|
|
6557
|
+
const access = m[2].replace(/\s+/g, "").replace(/'|`/g, '"');
|
|
6558
|
+
const imported = imports.get(base);
|
|
6559
|
+
if (!imported && !declaredAtTop(file.code, base)) continue;
|
|
6560
|
+
if (boundAsParameter(file.code, base, { jsx: file.ext !== ".ts" && file.ext !== ".mts" })) continue;
|
|
6561
|
+
const identity = `${imported ?? `${file.path}#${base}`}${access}`;
|
|
6562
|
+
const shown = `${base}${access}`;
|
|
6563
|
+
const line = lineAt(file.code, m.index ?? 0);
|
|
6564
|
+
const first = seen.get(identity);
|
|
6565
|
+
if (!first) {
|
|
6566
|
+
seen.set(identity, { file: file.path, line });
|
|
6567
|
+
continue;
|
|
6568
|
+
}
|
|
6569
|
+
ctx.report({
|
|
6570
|
+
rule: "client/one-view-per-resource",
|
|
6571
|
+
level: "warn",
|
|
6572
|
+
file: file.path,
|
|
6573
|
+
line,
|
|
6574
|
+
subject: shown,
|
|
6575
|
+
message: `defines a second view over ${shown} (the first is in ${first.file}:${first.line}); keep one view per resource and narrow it on the screen (preset, filter, columns), so its rules can't drift (docs/adr/0020-client-layer.md)`
|
|
6576
|
+
});
|
|
6577
|
+
}
|
|
6578
|
+
}
|
|
6579
|
+
}
|
|
6580
|
+
function declaredAtTop(code, name) {
|
|
6581
|
+
const escaped = escapeRegExp(name);
|
|
6582
|
+
return new RegExp(`^(?:export\\s+)?(?:const|let|var)\\s+${escaped}\\b`, "m").test(code);
|
|
6583
|
+
}
|
|
6584
|
+
var SHOWN_OR_TRIED = /(\.stories\.|\.test\.|\.spec\.|(^|\/)__tests__\/)/;
|
|
6585
|
+
function importedNames(filePath, code) {
|
|
6586
|
+
const out = /* @__PURE__ */ new Map();
|
|
6587
|
+
const dir = path21.posix.dirname(filePath);
|
|
6588
|
+
const where2 = (spec) => spec.startsWith(".") ? path21.posix.normalize(path21.posix.join(dir, spec)).replace(/\.(t|j)sx?$/, "").replace(/\/index$/, "") : spec;
|
|
6589
|
+
for (const m of code.matchAll(/import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
|
|
6590
|
+
for (const part of m[1].split(",")) {
|
|
6591
|
+
const spec = part.trim().replace(/^type\s+/, "");
|
|
6592
|
+
if (!spec) continue;
|
|
6593
|
+
const [imported, local] = spec.split(/\s+as\s+/).map((x) => x.trim());
|
|
6594
|
+
out.set(local ?? imported, `${where2(m[2])}#${imported}`);
|
|
6595
|
+
}
|
|
6596
|
+
}
|
|
6597
|
+
for (const m of code.matchAll(/import\s+(?:\*\s+as\s+)?([A-Za-z_$][\w$]*)\s+from\s*["']([^"']+)["']/g)) out.set(m[1], `${where2(m[2])}#*`);
|
|
6598
|
+
return out;
|
|
6599
|
+
}
|
|
6600
|
+
var SCRIPT_EXTS7 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
6601
|
+
var SKIP_DIRS4 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage", ".expo"]);
|
|
6602
|
+
var TEST_FILE = /(^|\/)(__tests__\/|[^/]+\.(test|spec)\.[cm]?[jt]sx?$)/;
|
|
6603
|
+
var DOCS = "docs/DATA-ACCESS.md";
|
|
6604
|
+
var TABLE_WRITE = /\.from\(\s*(["'`])([\w.]+)\1\s*\)\s*\.\s*(insert|update|upsert|delete)\s*\(/g;
|
|
6605
|
+
var STORAGE_BEFORE = /\bstorage\s*\??\.?\s*$/;
|
|
6606
|
+
function balanced(code, start) {
|
|
6607
|
+
const open = code[start];
|
|
6608
|
+
const close = open === "{" ? "}" : open === "(" ? ")" : open === "[" ? "]" : "";
|
|
6609
|
+
if (!close) return "";
|
|
6610
|
+
const blank = blankStrings(code);
|
|
6611
|
+
let depth = 0;
|
|
6612
|
+
for (let i = start; i < blank.length; i++) {
|
|
6613
|
+
const ch = blank[i];
|
|
6614
|
+
if (ch === "{" || ch === "(" || ch === "[") depth++;
|
|
6615
|
+
else if (ch === "}" || ch === ")" || ch === "]") {
|
|
6616
|
+
depth--;
|
|
6617
|
+
if (depth === 0) return ch === close ? code.slice(start, i + 1) : "";
|
|
6618
|
+
}
|
|
6619
|
+
}
|
|
6620
|
+
return "";
|
|
6621
|
+
}
|
|
6622
|
+
function testFiles(root) {
|
|
6623
|
+
const out = [];
|
|
6624
|
+
const walk3 = (dir) => {
|
|
6625
|
+
let entries;
|
|
6626
|
+
try {
|
|
6627
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
6628
|
+
} catch {
|
|
6629
|
+
return;
|
|
6630
|
+
}
|
|
6631
|
+
for (const entry of entries) {
|
|
6632
|
+
if (entry.isDirectory()) {
|
|
6633
|
+
if (!SKIP_DIRS4.has(entry.name) && !entry.name.startsWith(".")) walk3(path21.join(dir, entry.name));
|
|
6634
|
+
continue;
|
|
6635
|
+
}
|
|
6636
|
+
const abs = path21.join(dir, entry.name);
|
|
6637
|
+
const rel = path21.relative(root, abs).split(path21.sep).join("/");
|
|
6638
|
+
if (SCRIPT_EXTS7.has(path21.extname(entry.name)) && TEST_FILE.test(rel)) out.push(abs);
|
|
6639
|
+
}
|
|
6640
|
+
};
|
|
6641
|
+
walk3(root);
|
|
6642
|
+
return out;
|
|
6643
|
+
}
|
|
6644
|
+
function initializer(code, blank, name) {
|
|
6645
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6646
|
+
const decl = new RegExp(`\\b(const|let|var)\\s+${escaped}(?![\\w$])[^=;]*=\\s*\\{`).exec(blank);
|
|
6647
|
+
if (!decl) return null;
|
|
6648
|
+
const text = balanced(code, decl.index + decl[0].length - 1);
|
|
6649
|
+
return text ? { text, keyword: decl[1], at: decl.index } : null;
|
|
6650
|
+
}
|
|
6651
|
+
function objectDeclares(object) {
|
|
6652
|
+
const blank = blankStrings(object);
|
|
6653
|
+
let depth = 0;
|
|
6654
|
+
let declaredAt = -1;
|
|
6655
|
+
let lastAccess = -1;
|
|
6656
|
+
let lastSpread = -1;
|
|
6657
|
+
for (let i = 0; i < blank.length; i++) {
|
|
6658
|
+
const ch = blank[i];
|
|
6659
|
+
if (ch === "{" || ch === "(" || ch === "[") depth++;
|
|
6660
|
+
else if (ch === "}" || ch === ")" || ch === "]") depth--;
|
|
6661
|
+
else if (depth === 1 && blank.startsWith("...", i)) lastSpread = i;
|
|
6662
|
+
else if (depth === 1 && blank[i] === object[i] && /[\s{,]/.test(blank[i - 1] ?? " ") && /^(["'`]?)access\1\s*:/.test(object.slice(i))) {
|
|
6663
|
+
lastAccess = i;
|
|
6664
|
+
const value = /^(["'`]?)access\1\s*:\s*(["'`])([^"'`]*)\2/.exec(object.slice(i));
|
|
6665
|
+
declaredAt = value?.[3] === "declared" ? i : -1;
|
|
6666
|
+
}
|
|
6667
|
+
}
|
|
6668
|
+
return declaredAt !== -1 && declaredAt === lastAccess && lastSpread < declaredAt;
|
|
6669
|
+
}
|
|
6670
|
+
function inlineDeclares(call) {
|
|
6671
|
+
const blank = blankStrings(call);
|
|
6672
|
+
let depth = 0;
|
|
6673
|
+
for (let i = 0; i < blank.length; i++) {
|
|
6674
|
+
const ch = blank[i];
|
|
6675
|
+
if (ch === "{" && depth === 1 && objectDeclares(balanced(call, i))) return true;
|
|
6676
|
+
if (ch === "{" || ch === "(" || ch === "[") depth++;
|
|
6677
|
+
else if (ch === "}" || ch === ")" || ch === "]") depth--;
|
|
6678
|
+
}
|
|
6679
|
+
return false;
|
|
6680
|
+
}
|
|
6681
|
+
function optionsConstDeclares(code, blank, call) {
|
|
6682
|
+
const args = blankStrings(call).slice(1, -1);
|
|
6683
|
+
for (const [, name] of args.matchAll(/(?:^|,)\s*([A-Za-z_$][\w$]*)\s*(?=,|$)/g)) {
|
|
6684
|
+
const found = initializer(code, blank, name);
|
|
6685
|
+
if (!found || !objectDeclares(found.text)) continue;
|
|
6686
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6687
|
+
const reassigned = found.keyword !== "const" && new RegExp(`(?<![\\w$.])${escaped}\\s*=(?!=)`, "g").test(blank.slice(found.at + found.keyword.length + 1 + name.length));
|
|
6688
|
+
const changed = new RegExp(
|
|
6689
|
+
`(?<![\\w$.])${escaped}\\s*(?:\\.\\s*access|\\[[^\\]]*\\])\\s*=(?!=)|\\bdelete\\s+${escaped}\\s*(?:\\.\\s*access|\\[)|Object\\.assign\\(\\s*${escaped}(?![\\w$])`
|
|
6690
|
+
).test(blank);
|
|
6691
|
+
if (!reassigned && !changed) return true;
|
|
6692
|
+
}
|
|
6693
|
+
return false;
|
|
6694
|
+
}
|
|
6695
|
+
function coverageTested(root) {
|
|
6696
|
+
for (const abs of testFiles(root)) {
|
|
6697
|
+
let code;
|
|
6698
|
+
try {
|
|
6699
|
+
code = stripBlockComments(readFileSync(abs, "utf8"), true);
|
|
6700
|
+
} catch {
|
|
6701
|
+
continue;
|
|
6702
|
+
}
|
|
6703
|
+
if (!code.includes("expectAccessRulesCover")) continue;
|
|
6704
|
+
if (/\bexpectAccessRulesCover\s*\(/.test(blankStrings(code))) return true;
|
|
6705
|
+
}
|
|
6706
|
+
return false;
|
|
6707
|
+
}
|
|
6708
|
+
function checkDataAccess(ctx) {
|
|
6709
|
+
for (const file of ctx.files) {
|
|
6710
|
+
if (!SCRIPT_EXTS7.has(file.ext)) continue;
|
|
6711
|
+
const blank = blankStrings(file.code);
|
|
6712
|
+
for (const m of blank.matchAll(/\bcreateSupabaseProvider\s*\(/g)) {
|
|
6713
|
+
const call = balanced(file.code, (m.index ?? 0) + m[0].length - 1);
|
|
6714
|
+
if (inlineDeclares(call) || optionsConstDeclares(file.code, blank, call)) continue;
|
|
6715
|
+
ctx.report({
|
|
6716
|
+
rule: "data/declared-access",
|
|
6717
|
+
level: "warn",
|
|
6718
|
+
file: file.path,
|
|
6719
|
+
line: lineAt(file.code, m.index ?? 0),
|
|
6720
|
+
subject: "createSupabaseProvider",
|
|
6721
|
+
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})`
|
|
6722
|
+
});
|
|
6723
|
+
}
|
|
6724
|
+
if (file.path.startsWith("supabase/") || file.path.includes("/supabase/functions/")) continue;
|
|
6725
|
+
for (const m of file.code.matchAll(TABLE_WRITE)) {
|
|
6726
|
+
const at = m.index ?? 0;
|
|
6727
|
+
if (blank[at] !== ".") continue;
|
|
6728
|
+
if (STORAGE_BEFORE.test(blank.slice(Math.max(0, at - 40), at))) continue;
|
|
6729
|
+
ctx.report({
|
|
6730
|
+
rule: "data/declared-access",
|
|
6731
|
+
level: "warn",
|
|
6732
|
+
file: file.path,
|
|
6733
|
+
line: lineAt(file.code, at),
|
|
6734
|
+
subject: `${m[2]}.${m[3]}`,
|
|
6735
|
+
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})`
|
|
6736
|
+
});
|
|
6737
|
+
}
|
|
6738
|
+
}
|
|
6739
|
+
const providers = providerCalls(ctx.files);
|
|
6740
|
+
if (providers.length === 0 || coverageTested(ctx.root)) return;
|
|
6741
|
+
const first = providers[0];
|
|
6742
|
+
ctx.report({
|
|
6743
|
+
rule: "data/access-rule-tests",
|
|
6744
|
+
level: "warn",
|
|
6745
|
+
file: first.file,
|
|
6746
|
+
line: first.line,
|
|
6747
|
+
subject: "expectAccessRulesCover",
|
|
6748
|
+
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})`
|
|
6749
|
+
});
|
|
6750
|
+
}
|
|
6751
|
+
function providerCalls(files) {
|
|
6752
|
+
const out = [];
|
|
6753
|
+
for (const file of files) {
|
|
6754
|
+
if (!SCRIPT_EXTS7.has(file.ext)) continue;
|
|
6755
|
+
for (const m of blankStrings(file.code).matchAll(/\bcreateSupabaseProvider\s*\(/g)) {
|
|
6756
|
+
out.push({ file: file.path, line: lineAt(file.code, m.index ?? 0) });
|
|
6757
|
+
}
|
|
6758
|
+
}
|
|
6759
|
+
return out;
|
|
6760
|
+
}
|
|
6761
|
+
var SCRIPT_EXTS8 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
6144
6762
|
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;
|
|
6145
6763
|
var REEXPORT = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\nexport\s+(?:type\s+)?\{([^}]*)\}/g;
|
|
6146
6764
|
function specifierParts(spec) {
|
|
@@ -6230,7 +6848,7 @@ function checkStabilityImports(ctx) {
|
|
|
6230
6848
|
return cache2.get(pkg);
|
|
6231
6849
|
};
|
|
6232
6850
|
for (const file of ctx.files) {
|
|
6233
|
-
if (!
|
|
6851
|
+
if (!SCRIPT_EXTS8.has(file.ext)) continue;
|
|
6234
6852
|
for (const { pkg, specifier, names, line } of genesisNamedImports(file.code)) {
|
|
6235
6853
|
const tags = tagsOf(pkg);
|
|
6236
6854
|
if (!tags) continue;
|
|
@@ -6712,6 +7330,7 @@ var RULES = [
|
|
|
6712
7330
|
"Never copy an older screen as a template. Old screens predate the primitives; the doctor flags what they did.",
|
|
6713
7331
|
"A list screen is a view (`defineView`) rendered by `ResourceView`; a record view is `RecordView`; on the phone, `NativeResourceView`.",
|
|
6714
7332
|
"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.",
|
|
7333
|
+
`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.`,
|
|
6715
7334
|
"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.",
|
|
6716
7335
|
"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.",
|
|
6717
7336
|
"Run `genesis doctor` before you finish; it enforces these rules."
|
|
@@ -7959,6 +8578,8 @@ function builtinChecks(config, options = {}) {
|
|
|
7959
8578
|
{ name: "studio-server-imports", check: checkStudioServerImports },
|
|
7960
8579
|
{ name: "removed-scope-names", check: checkRemovedScopeNames },
|
|
7961
8580
|
{ name: "app-parts", check: checkAppParts },
|
|
8581
|
+
{ name: "client-layer", check: checkClientLayer },
|
|
8582
|
+
{ name: "data-access", check: checkDataAccess },
|
|
7962
8583
|
{ name: "stability-imports", check: checkStabilityImports },
|
|
7963
8584
|
{ name: "agent-guide", check: (ctx) => {
|
|
7964
8585
|
checkAgentGuide(ctx);
|