@rebasepro/server-postgres 0.13.1-canary.g18cfeb7 → 0.13.1-canary.g1bf9303

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.
Files changed (88) hide show
  1. package/dist/PostgresBootstrapper.d.ts +26 -0
  2. package/dist/auth/services.d.ts +21 -0
  3. package/dist/{auth-users-columns-Do9mw5Y5.js → auth-users-columns-BxT6FRyu.js} +819 -68
  4. package/dist/auth-users-columns-BxT6FRyu.js.map +1 -0
  5. package/dist/{backup-service-Bww-Lg0s.js → backup-service-BH0Dzo_h.js} +2 -3
  6. package/dist/{backup-service-Bww-Lg0s.js.map → backup-service-BH0Dzo_h.js.map} +1 -1
  7. package/dist/cli-helpers.d.ts +56 -0
  8. package/dist/cli-output.d.ts +34 -0
  9. package/dist/data-transformer.d.ts +7 -2
  10. package/dist/data_driver-ULAyJEi9.js +193 -0
  11. package/dist/data_driver-ULAyJEi9.js.map +1 -0
  12. package/dist/ensure-collection-policies-CP5_YttS.js +124 -0
  13. package/dist/ensure-collection-policies-CP5_YttS.js.map +1 -0
  14. package/dist/{ensure-collection-tables-DSIxvLLD.js → ensure-collection-tables-DWVISfcC.js} +119 -13
  15. package/dist/ensure-collection-tables-DWVISfcC.js.map +1 -0
  16. package/dist/index.es.js +998 -600
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/{rls-bootstrap-sql-Bpv3nUZo.js → rls-bootstrap-sql-69hYT8nr.js} +2 -2
  19. package/dist/{rls-bootstrap-sql-Bpv3nUZo.js.map → rls-bootstrap-sql-69hYT8nr.js.map} +1 -1
  20. package/dist/rls-enforcement-Ct9ab42o.js +425 -0
  21. package/dist/rls-enforcement-Ct9ab42o.js.map +1 -0
  22. package/dist/schema/auth-schema.d.ts +102 -0
  23. package/dist/schema/doctor-policy-checks.d.ts +28 -0
  24. package/dist/schema/doctor.d.ts +41 -25
  25. package/dist/schema/ensure-collection-policies.d.ts +33 -9
  26. package/dist/schema/ensure-collection-tables.d.ts +60 -6
  27. package/dist/schema/generate-drizzle-schema-logic.d.ts +9 -1
  28. package/dist/schema/generate-postgres-ddl-logic.d.ts +48 -0
  29. package/dist/schema/search-column.d.ts +248 -0
  30. package/dist/security/rls-enforcement.d.ts +8 -3
  31. package/dist/services/FetchService.d.ts +24 -0
  32. package/dist/services/RelationService.d.ts +30 -0
  33. package/dist/services/collection-helpers.d.ts +26 -0
  34. package/dist/services/dataService.d.ts +3 -0
  35. package/dist/services/realtimeService.d.ts +139 -2
  36. package/dist/{src-C_wvdMnl.js → src-DCdn3Val.js} +35 -3
  37. package/dist/src-DCdn3Val.js.map +1 -0
  38. package/dist/utils/drizzle-conditions.d.ts +124 -2
  39. package/dist/{websocket-D0TBU3ia.js → websocket-C8ZqVBiV.js} +75 -18
  40. package/dist/websocket-C8ZqVBiV.js.map +1 -0
  41. package/package.json +6 -6
  42. package/src/PostgresBackendDriver.ts +7 -3
  43. package/src/PostgresBootstrapper.ts +95 -9
  44. package/src/auth/ensure-tables.ts +27 -5
  45. package/src/auth/services.ts +82 -5
  46. package/src/backup/backup-cli.ts +59 -57
  47. package/src/cli-errors.ts +6 -6
  48. package/src/cli-helpers.ts +110 -4
  49. package/src/cli-output.ts +43 -0
  50. package/src/cli.ts +210 -145
  51. package/src/collections/buildRegistry.ts +3 -1
  52. package/src/data-transformer.ts +107 -14
  53. package/src/history/ensure-history-table.ts +2 -2
  54. package/src/schema/auth-schema.ts +17 -1
  55. package/src/schema/doctor-cli.ts +14 -65
  56. package/src/schema/doctor-policy-checks.ts +105 -0
  57. package/src/schema/doctor.ts +149 -72
  58. package/src/schema/ensure-collection-policies.ts +99 -6
  59. package/src/schema/ensure-collection-tables.ts +286 -13
  60. package/src/schema/generate-drizzle-schema-logic.ts +126 -42
  61. package/src/schema/generate-drizzle-schema.ts +11 -10
  62. package/src/schema/generate-postgres-ddl-logic.ts +204 -10
  63. package/src/schema/generate-postgres-ddl.ts +38 -14
  64. package/src/schema/introspect-db-logic.ts +65 -33
  65. package/src/schema/introspect-db.ts +24 -24
  66. package/src/schema/search-column.ts +643 -0
  67. package/src/security/rls-enforcement.ts +9 -4
  68. package/src/services/FetchService.ts +229 -15
  69. package/src/services/PersistService.ts +24 -1
  70. package/src/services/RelationService.ts +119 -69
  71. package/src/services/cdc/trigger-cdc.ts +5 -1
  72. package/src/services/channel-history.ts +9 -3
  73. package/src/services/channel-presence.ts +10 -3
  74. package/src/services/collection-helpers.ts +54 -1
  75. package/src/services/dataService.ts +3 -0
  76. package/src/services/pg-notify-listener.ts +1 -1
  77. package/src/services/realtimeService.ts +347 -86
  78. package/src/utils/drizzle-conditions.ts +365 -23
  79. package/src/utils/pg-error-utils.ts +8 -3
  80. package/src/websocket.ts +113 -16
  81. package/dist/auth-users-columns-Do9mw5Y5.js.map +0 -1
  82. package/dist/ensure-collection-policies-DMUdRQdM.js +0 -57
  83. package/dist/ensure-collection-policies-DMUdRQdM.js.map +0 -1
  84. package/dist/ensure-collection-tables-DSIxvLLD.js.map +0 -1
  85. package/dist/policy-CPkCqVTz.js +0 -105
  86. package/dist/policy-CPkCqVTz.js.map +0 -1
  87. package/dist/src-C_wvdMnl.js.map +0 -1
  88. package/dist/websocket-D0TBU3ia.js.map +0 -1
@@ -17,7 +17,7 @@ import {
17
17
  import { countRowsUpTo, readSchemaMetadata } from "./introspect-db-queries";
18
18
  import { classifyTables, lookupCandidates, LOOKUP_MAX_ROWS } from "./introspect-db-structure";
19
19
  import { parseCheckConstraints } from "./introspect-db-constraints";
20
- import { logger } from "@rebasepro/server";
20
+ import { out, outWarn, outError } from "../cli-output";
21
21
 
22
22
  async function main() {
23
23
  const args = arg(
@@ -59,14 +59,14 @@ async function main() {
59
59
 
60
60
  for (const p of envPaths) {
61
61
  if (fs.existsSync(p)) {
62
- dotenv.config({ path: p });
62
+ dotenv.config({ path: p, quiet: true });
63
63
  break;
64
64
  }
65
65
  }
66
66
 
67
67
  const databaseUrl = process.env.DATABASE_URL || process.env.ADMIN_CONNECTION_STRING;
68
68
  if (!databaseUrl) {
69
- logger.error(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
69
+ outError(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
70
70
  process.exit(1);
71
71
  }
72
72
 
@@ -75,15 +75,15 @@ async function main() {
75
75
  try {
76
76
  await client.connect();
77
77
  } catch (err) {
78
- logger.error(chalk.red(`✗ Failed to connect to database: ${err instanceof Error ? err.message : String(err)}`));
79
- logger.error(chalk.gray(" Check your DATABASE_URL and ensure the database is reachable."));
78
+ outError(chalk.red(`✗ Failed to connect to database: ${err instanceof Error ? err.message : String(err)}`));
79
+ outError(chalk.gray(" Check your DATABASE_URL and ensure the database is reachable."));
80
80
  process.exit(1);
81
81
  }
82
82
 
83
83
  // Log the host portion safely — handle URLs without "@"
84
84
  const hostPart = safeHostFromUrl(databaseUrl);
85
- logger.info(chalk.gray(`Connected to database: ${hostPart}`));
86
- logger.info(chalk.gray(`Introspecting schema '${pgSchema}'...`));
85
+ out(chalk.gray(`Connected to database: ${hostPart}`));
86
+ out(chalk.gray(`Introspecting schema '${pgSchema}'...`));
87
87
 
88
88
  try {
89
89
  const metadata = await readSchemaMetadata(client, pgSchema);
@@ -101,7 +101,7 @@ async function main() {
101
101
  } catch (err) {
102
102
  // A table this run cannot read is simply not classified as a code
103
103
  // list; everything else about it still generates.
104
- logger.info(chalk.gray(` (skipped row count for ${table}: ${err instanceof Error ? err.message : String(err)})`));
104
+ out(chalk.gray(` (skipped row count for ${table}: ${err instanceof Error ? err.message : String(err)})`));
105
105
  }
106
106
  }
107
107
 
@@ -116,8 +116,8 @@ async function main() {
116
116
  const roleCount = (role: string) =>
117
117
  Array.from(classifications.values()).filter((c) => c.role === role).length;
118
118
 
119
- logger.info(chalk.blue(`Found ${tablesMap.size} tables.`));
120
- logger.info(chalk.gray(
119
+ out(chalk.blue(`Found ${tablesMap.size} tables.`));
120
+ out(chalk.gray(
121
121
  ` ${roleCount("entity")} entities, ${joinTables.size} join tables (folded into relations), ` +
122
122
  `${roleCount("lookup")} code lists, ${roleCount("owned-child")} owned by another table (hidden from navigation).`
123
123
  ));
@@ -130,7 +130,7 @@ async function main() {
130
130
  } else if (!process.stdin.isTTY) {
131
131
  // No terminal to answer the question below (scaffolding scripts, CI,
132
132
  // `rebase init --introspect`) — asking would hang forever.
133
- logger.info(chalk.gray("Skipping data inference (non-interactive run; pass --data-inference to enable)."));
133
+ out(chalk.gray("Skipping data inference (non-interactive run; pass --data-inference to enable)."));
134
134
  } else {
135
135
  const rl = readline.createInterface({
136
136
  input: process.stdin,
@@ -142,7 +142,7 @@ async function main() {
142
142
  }
143
143
 
144
144
  if (runDataInference) {
145
- logger.info(chalk.gray("Sampling database rows for data inference..."));
145
+ out(chalk.gray("Sampling database rows for data inference..."));
146
146
  }
147
147
 
148
148
  // Generate Collections
@@ -169,7 +169,7 @@ async function main() {
169
169
  const { rows } = await client.query(`SELECT * FROM "${pgSchema}"."${tableName}" LIMIT 100`);
170
170
  sampleData = rows;
171
171
  } catch (err) {
172
- logger.error(chalk.yellow(`⚠ Failed to sample data for table ${tableName}: ${err instanceof Error ? err.message : String(err)}`));
172
+ outError(chalk.yellow(`⚠ Failed to sample data for table ${tableName}: ${err instanceof Error ? err.message : String(err)}`));
173
173
  }
174
174
  }
175
175
 
@@ -186,7 +186,7 @@ async function main() {
186
186
 
187
187
  fs.writeFileSync(filePath, fileContent, "utf-8");
188
188
  generatedFiles.push(tableName);
189
- logger.info(chalk.green(` ✓ ${filePath}`));
189
+ out(chalk.green(` ✓ ${filePath}`));
190
190
  }));
191
191
  }
192
192
 
@@ -213,21 +213,21 @@ async function main() {
213
213
  const indexContent = generateIndexContent(allFiles);
214
214
  fs.writeFileSync(indexPath, indexContent, "utf-8");
215
215
  }
216
- logger.info(chalk.green(` ✓ ${indexPath}`));
216
+ out(chalk.green(` ✓ ${indexPath}`));
217
217
  }
218
218
 
219
- logger.info("");
219
+ out("");
220
220
  if (skippedFiles.length > 0) {
221
- logger.info(chalk.yellow(`⚠ Skipped ${skippedFiles.length} existing file(s): ${skippedFiles.join(", ")}`));
222
- logger.info(chalk.gray(" Use --force to overwrite existing files."));
223
- logger.info("");
221
+ out(chalk.yellow(`⚠ Skipped ${skippedFiles.length} existing file(s): ${skippedFiles.join(", ")}`));
222
+ out(chalk.gray(" Use --force to overwrite existing files."));
223
+ out("");
224
224
  }
225
- logger.info(chalk.bold.green(`✓ Introspected ${tablesMap.size} tables — generated ${generatedFiles.length} collection(s).`));
226
- logger.info(chalk.gray(` Review the generated files in ${outDir} and customize properties as needed.`));
227
- logger.info("");
225
+ out(chalk.bold.green(`✓ Introspected ${tablesMap.size} tables — generated ${generatedFiles.length} collection(s).`));
226
+ out(chalk.gray(` Review the generated files in ${outDir} and customize properties as needed.`));
227
+ out("");
228
228
 
229
229
  } catch (e) {
230
- logger.error(chalk.red(`✗ Error introspecting database: ${e instanceof Error ? e.message : String(e)}`));
230
+ outError(chalk.red(`✗ Error introspecting database: ${e instanceof Error ? e.message : String(e)}`));
231
231
  process.exit(1);
232
232
  } finally {
233
233
  await client.end();
@@ -235,6 +235,6 @@ async function main() {
235
235
  }
236
236
 
237
237
  main().catch((err) => {
238
- logger.error(String(err));
238
+ outError(String(err));
239
239
  process.exit(1);
240
240
  });