@yasainet/eslint 0.0.33 → 0.0.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yasainet/eslint",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "ESLint",
5
5
  "type": "module",
6
6
  "exports": {
@@ -3,7 +3,8 @@ import path from "path";
3
3
 
4
4
  /**
5
5
  * Extract table names from Supabase generated types file.
6
- * Looks for keys directly under `Tables: {` in the Database interface.
6
+ * Looks for top-level keys under `Tables: {` inside the `public` schema.
7
+ * Uses brace counting to handle deeply nested type definitions.
7
8
  */
8
9
  function extractTableNames(supabaseTypePath) {
9
10
  if (!fs.existsSync(supabaseTypePath)) {
@@ -11,17 +12,57 @@ function extractTableNames(supabaseTypePath) {
11
12
  }
12
13
 
13
14
  const content = fs.readFileSync(supabaseTypePath, "utf-8");
14
- const tablesMatch = content.match(/Tables:\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/);
15
- if (!tablesMatch) {
15
+
16
+ // Find `public:` excluding `graphql_public:` via negative lookbehind
17
+ const publicMatch = /(?<!\w)public:\s*\{/.exec(content);
18
+ if (!publicMatch) {
19
+ return [];
20
+ }
21
+
22
+ const tablesLabel = "Tables:";
23
+ const tablesIdx = content.indexOf(tablesLabel, publicMatch.index);
24
+ if (tablesIdx === -1) {
25
+ return [];
26
+ }
27
+
28
+ // Find the opening brace of `Tables: {`
29
+ const braceStart = content.indexOf("{", tablesIdx + tablesLabel.length);
30
+ if (braceStart === -1) {
31
+ return [];
32
+ }
33
+
34
+ // Extract the Tables block using brace counting
35
+ let depth = 0;
36
+ let blockEnd = -1;
37
+ for (let i = braceStart; i < content.length; i++) {
38
+ if (content[i] === "{") depth++;
39
+ else if (content[i] === "}") depth--;
40
+ if (depth === 0) {
41
+ blockEnd = i;
42
+ break;
43
+ }
44
+ }
45
+ if (blockEnd === -1) {
16
46
  return [];
17
47
  }
18
48
 
19
- const tablesBlock = tablesMatch[1];
20
- const keyRegex = /^\s*(\w+)\s*:/gm;
49
+ // Extract top-level keys (depth 0) inside the Tables block
50
+ const tablesBlock = content.slice(braceStart + 1, blockEnd);
21
51
  const names = [];
52
+ depth = 0;
53
+ const keyRegex = /(\w+)\s*:/g;
22
54
  let match;
23
55
  while ((match = keyRegex.exec(tablesBlock)) !== null) {
24
- names.push(match[1]);
56
+ // Count braces before this match to determine depth
57
+ const preceding = tablesBlock.slice(0, match.index);
58
+ let d = 0;
59
+ for (const ch of preceding) {
60
+ if (ch === "{") d++;
61
+ else if (ch === "}") d--;
62
+ }
63
+ if (d === 0) {
64
+ names.push(match[1]);
65
+ }
25
66
  }
26
67
  return names;
27
68
  }