@outs-tand-ing/postgres 0.6.0 → 0.7.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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks that every table referenced in PowerSync sync rules has an RLS policy in setup-rls.sql.
|
|
3
|
+
* Run: bun run check-rls
|
|
4
|
+
*
|
|
5
|
+
* Tables in sync rules but missing RLS → API mode returns 0 rows (silent data loss).
|
|
6
|
+
* This script catches that before it reaches production.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=check-rls-coverage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-rls-coverage.d.ts","sourceRoot":"","sources":["../../src/scripts/check-rls-coverage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks that every table referenced in PowerSync sync rules has an RLS policy in setup-rls.sql.
|
|
3
|
+
* Run: bun run check-rls
|
|
4
|
+
*
|
|
5
|
+
* Tables in sync rules but missing RLS → API mode returns 0 rows (silent data loss).
|
|
6
|
+
* This script catches that before it reaches production.
|
|
7
|
+
*/
|
|
8
|
+
const scriptDir = import.meta.dir;
|
|
9
|
+
const SYNC_RULES_PATH = `${scriptDir}/../../../powersync/config/sync-rules.yaml`;
|
|
10
|
+
const RLS_SCRIPT_PATH = `${scriptDir}/setup-rls.sql`;
|
|
11
|
+
// Tables that intentionally have no RLS policy (admin-only, accessed via owner role)
|
|
12
|
+
const EXCLUDED_TABLES = new Set(['account_subscriptions_to_seasons']);
|
|
13
|
+
const extractTables = (content, pattern) => {
|
|
14
|
+
const tables = new Set();
|
|
15
|
+
for (const match of content.matchAll(pattern)) {
|
|
16
|
+
const table = match[1].toLowerCase();
|
|
17
|
+
if (!table.startsWith('pg_') && !EXCLUDED_TABLES.has(table))
|
|
18
|
+
tables.add(table);
|
|
19
|
+
}
|
|
20
|
+
return tables;
|
|
21
|
+
};
|
|
22
|
+
const syncRules = await Bun.file(SYNC_RULES_PATH).text();
|
|
23
|
+
const rlsScript = await Bun.file(RLS_SCRIPT_PATH).text();
|
|
24
|
+
// Extract tables from sync rules: FROM "table", FROM table, JOIN "table", JOIN table
|
|
25
|
+
const syncTables = extractTables(syncRules, /(?:FROM|JOIN)\s+"?(\w+)"?/gi);
|
|
26
|
+
// Extract tables with RLS policies: CREATE POLICY ... ON table
|
|
27
|
+
const rlsTables = extractTables(rlsScript, /CREATE\s+POLICY\s+\w+\s+ON\s+(\w+)/gi);
|
|
28
|
+
// Also extract tables that are explicitly covered via helper functions (referenced inside USING)
|
|
29
|
+
// These are indirect — e.g. account_subscriptions is queried inside api_user_season_ids()
|
|
30
|
+
const helperTables = extractTables(rlsScript, /FROM\s+(\w+)\s+WHERE/gi);
|
|
31
|
+
const coveredTables = new Set([...rlsTables, ...helperTables]);
|
|
32
|
+
const missing = [];
|
|
33
|
+
const covered = [];
|
|
34
|
+
for (const table of [...syncTables].sort()) {
|
|
35
|
+
if (coveredTables.has(table))
|
|
36
|
+
covered.push(table);
|
|
37
|
+
else
|
|
38
|
+
missing.push(table);
|
|
39
|
+
}
|
|
40
|
+
console.log(`\n Sync rule tables: ${syncTables.size}`);
|
|
41
|
+
console.log(` RLS policies: ${rlsTables.size}`);
|
|
42
|
+
console.log(` Covered: ${covered.length}`);
|
|
43
|
+
if (missing.length) {
|
|
44
|
+
console.log(`\n MISSING RLS POLICY:`);
|
|
45
|
+
for (const t of missing)
|
|
46
|
+
console.log(` - ${t}`);
|
|
47
|
+
console.log(`\n These tables will return 0 rows in API mode.`);
|
|
48
|
+
console.log(` Add policies to setup-rls.sql and re-run it.\n`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log(`\n All sync rule tables have RLS coverage.\n`);
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=check-rls-coverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-rls-coverage.js","sourceRoot":"","sources":["../../src/scripts/check-rls-coverage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAA;AACjC,MAAM,eAAe,GAAG,GAAG,SAAS,4CAA4C,CAAA;AAChF,MAAM,eAAe,GAAG,GAAG,SAAS,gBAAgB,CAAA;AAEpD,qFAAqF;AACrF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAA;AAErE,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,OAAe,EAAe,EAAE;IACtE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAChC,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QACpC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAChF,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,CAAA;AACxD,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,CAAA;AAExD,qFAAqF;AACrF,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,EAAE,6BAA6B,CAAC,CAAA;AAE1E,+DAA+D;AAC/D,MAAM,SAAS,GAAG,aAAa,CAAC,SAAS,EAAE,sCAAsC,CAAC,CAAA;A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2
|
"name": "@outs-tand-ing/postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "PostgreSQL database with Drizzle ORM for Outs project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"typecheck": "tsc --noEmit",
|
|
80
80
|
"lint": "eslint .",
|
|
81
81
|
"lint:fix": "eslint . --fix",
|
|
82
|
+
"check-rls": "bun run src/scripts/check-rls-coverage.ts",
|
|
82
83
|
"backup": "bun run src/scripts/backup.ts",
|
|
83
84
|
"restore": "bun run src/scripts/restore.ts",
|
|
84
85
|
"test": "bun test"
|