@rebasepro/server-postgres 0.9.1-canary.16c42e9 → 0.9.1-canary.5809e39

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.
@@ -2,7 +2,7 @@ import { CollectionConfig, Property } from "@rebasepro/types";
2
2
  export type IssueSeverity = "error" | "warning" | "info";
3
3
  export interface DoctorIssue {
4
4
  severity: IssueSeverity;
5
- category: "missing_table" | "missing_column" | "type_mismatch" | "missing_constraint" | "schema_stale" | "missing_enum" | "enum_value_mismatch" | "missing_foreign_key" | "sdk_stale";
5
+ category: "missing_table" | "missing_column" | "type_mismatch" | "missing_constraint" | "schema_stale" | "missing_enum" | "enum_value_mismatch" | "missing_foreign_key" | "sdk_stale" | "sdk_not_generated";
6
6
  table?: string;
7
7
  column?: string;
8
8
  expected?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rebasepro/server-postgres",
3
3
  "type": "module",
4
- "version": "0.9.1-canary.16c42e9",
4
+ "version": "0.9.1-canary.5809e39",
5
5
  "description": "PostgreSQL data source backend implementation for Rebase with Drizzle ORM",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/rebaseco"
@@ -71,11 +71,11 @@
71
71
  "execa": "^9.6.1",
72
72
  "pg": "^8.21.0",
73
73
  "ws": "^8.21.0",
74
- "@rebasepro/codegen": "0.9.1-canary.16c42e9",
75
- "@rebasepro/server": "0.9.1-canary.16c42e9",
76
- "@rebasepro/types": "0.9.1-canary.16c42e9",
77
- "@rebasepro/utils": "0.9.1-canary.16c42e9",
78
- "@rebasepro/common": "0.9.1-canary.16c42e9"
74
+ "@rebasepro/codegen": "0.9.1-canary.5809e39",
75
+ "@rebasepro/common": "0.9.1-canary.5809e39",
76
+ "@rebasepro/server": "0.9.1-canary.5809e39",
77
+ "@rebasepro/types": "0.9.1-canary.5809e39",
78
+ "@rebasepro/utils": "0.9.1-canary.5809e39"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@hono/node-server": "^2.0.9",
@@ -37,7 +37,7 @@ export type IssueSeverity = "error" | "warning" | "info";
37
37
 
38
38
  export interface DoctorIssue {
39
39
  severity: IssueSeverity;
40
- category: "missing_table" | "missing_column" | "type_mismatch" | "missing_constraint" | "schema_stale" | "missing_enum" | "enum_value_mismatch" | "missing_foreign_key" | "sdk_stale";
40
+ category: "missing_table" | "missing_column" | "type_mismatch" | "missing_constraint" | "schema_stale" | "missing_enum" | "enum_value_mismatch" | "missing_foreign_key" | "sdk_stale" | "sdk_not_generated";
41
41
  table?: string;
42
42
  column?: string;
43
43
  expected?: string;
@@ -61,19 +61,29 @@ export function getExpectedColumnType(prop: Property): string | null {
61
61
  const sp = prop as StringProperty;
62
62
  if (sp.enum) return "USER-DEFINED"; // pgEnum → USER-DEFINED in information_schema
63
63
  if ("isId" in sp && sp.isId === "uuid") return "uuid";
64
- if (sp.columnType === "text") return "text";
64
+ if (sp.columnType === "uuid") return "uuid";
65
+ // A markdown/multiline string compiles to `text`, not varchar — the
66
+ // generator treats those UI hints as column-type signals, so the
67
+ // expectation here must too or every such column reads as drift.
68
+ if (sp.columnType === "text" || sp.ui?.markdown || sp.ui?.multiline) return "text";
65
69
  if (sp.columnType === "char") return "character";
66
70
  return "character varying";
67
71
  }
68
72
  case "number": {
69
73
  const np = prop as NumberProperty;
70
- if (np.columnType === "double precision") return "double precision";
71
- if (np.columnType === "real") return "real";
72
- if (np.columnType === "bigint") return "bigint";
73
- if (np.columnType === "serial") return "integer"; // serial is integer under the hood
74
- if (np.columnType === "bigserial") return "bigint";
75
- if (np.columnType === "integer") return "integer";
76
- if (np.columnType === "numeric") return "numeric";
74
+ if (np.columnType) {
75
+ // The generator passes any columnType straight through to drizzle,
76
+ // so mirror that rather than enumerating a subset (which reported
77
+ // drift for anything unlisted, e.g. smallint). Serial types are
78
+ // integers with a sequence default; information_schema reports the
79
+ // underlying width.
80
+ const serialWidths: Record<string, string> = {
81
+ serial: "integer",
82
+ bigserial: "bigint",
83
+ smallserial: "smallint"
84
+ };
85
+ return serialWidths[np.columnType] ?? np.columnType;
86
+ }
77
87
  if (np.validation?.integer || ("isId" in np && np.isId)) return "integer";
78
88
  return "numeric";
79
89
  }
@@ -201,15 +211,18 @@ export async function checkCollectionsVsSdk(
201
211
  ): Promise<{ passed: boolean; issues: DoctorIssue[] }> {
202
212
  const issues: DoctorIssue[] = [];
203
213
 
204
- // Check if SDK file exists
214
+ // The typed SDK is opt-in — nothing in a scaffolded project imports it until
215
+ // you choose to. A project that never generated one isn't drifting, so report
216
+ // it as information rather than a warning; otherwise `doctor` can never come
217
+ // back clean on a fresh project and users learn to ignore its output.
205
218
  if (!fs.existsSync(sdkFilePath)) {
206
219
  issues.push({
207
- severity: "warning",
208
- category: "sdk_stale",
209
- message: `Generated SDK typedefs file does not exist at "${sdkFilePath}".`,
210
- fix: "Run `rebase generate-sdk`"
220
+ severity: "info",
221
+ category: "sdk_not_generated",
222
+ message: "Typed SDK not generated (optional).",
223
+ fix: "Run `rebase generate-sdk` if you want typed collection access"
211
224
  });
212
- return { passed: false,
225
+ return { passed: true,
213
226
  issues };
214
227
  }
215
228
 
@@ -631,11 +644,15 @@ export function renderReport(report: DoctorReport): void {
631
644
  }
632
645
 
633
646
  function renderPhase(label: string, passed: boolean, issues: DoctorIssue[]): void {
634
- if (passed) {
647
+ const errorCount = issues.filter((i) => i.severity === "error").length;
648
+ const warnCount = issues.filter((i) => i.severity === "warning").length;
649
+ const infoIssues = issues.filter((i) => i.severity === "info");
650
+
651
+ // Informational notes don't make a phase unhealthy, so key the header off
652
+ // real problems rather than `passed` alone.
653
+ if (errorCount === 0 && warnCount === 0) {
635
654
  logger.info(` ${chalk.green("✅")} ${label}: ${chalk.green("In sync")}`);
636
655
  } else {
637
- const errorCount = issues.filter((i) => i.severity === "error").length;
638
- const warnCount = issues.filter((i) => i.severity === "warning").length;
639
656
  const parts: string[] = [];
640
657
  if (errorCount > 0) parts.push(`${errorCount} error${errorCount > 1 ? "s" : ""}`);
641
658
  if (warnCount > 0) parts.push(`${warnCount} warning${warnCount > 1 ? "s" : ""}`);
@@ -643,7 +660,14 @@ function renderPhase(label: string, passed: boolean, issues: DoctorIssue[]): voi
643
660
  }
644
661
  logger.info("");
645
662
 
646
- for (const issue of issues) {
663
+ // Notes render as a quiet one-liner, not a full drift box.
664
+ for (const issue of infoIssues) {
665
+ const fixPart = issue.fix ? chalk.gray(` — ${issue.fix}`) : "";
666
+ logger.info(` ${chalk.gray("ℹ")} ${chalk.gray(issue.message)}${fixPart}`);
667
+ logger.info("");
668
+ }
669
+
670
+ for (const issue of issues.filter((i) => i.severity !== "info")) {
647
671
  const severityIcon = issue.severity === "error" ? chalk.red("✗") : chalk.yellow("⚠");
648
672
  const categoryLabel = formatCategory(issue.category);
649
673
  logger.info(` ${chalk.gray("┌─")} ${severityIcon} ${chalk.bold(categoryLabel)} ${chalk.gray("─".repeat(Math.max(0, 42 - categoryLabel.length)))}`);
@@ -674,7 +698,8 @@ function formatCategory(cat: DoctorIssue["category"]): string {
674
698
  missing_enum: "Missing Enum",
675
699
  enum_value_mismatch: "Enum Value Mismatch",
676
700
  missing_foreign_key: "Missing Foreign Key",
677
- sdk_stale: "Stale SDK Types"
701
+ sdk_stale: "Stale SDK Types",
702
+ sdk_not_generated: "SDK Types Not Generated"
678
703
  };
679
704
  return labels[cat];
680
705
  }
@@ -91,6 +91,30 @@ function coerceDeclaredNumbers(
91
91
  }
92
92
 
93
93
  /** Render one target row in the requested style. */
94
+ /**
95
+ * Drop every column the collection marked `excludeFromApi`.
96
+ *
97
+ * Password hashes and verification tokens have to be readable server-side but
98
+ * must never reach a client — and "never" has to mean every exit from this
99
+ * pipeline, including relation targets, or a secret leaks through whichever
100
+ * path was overlooked. Keyed by both the property name and its column name,
101
+ * since a row can arrive keyed either way depending on the caller.
102
+ */
103
+ function stripExcluded(
104
+ row: Record<string, unknown>,
105
+ collection: CollectionConfig
106
+ ): Record<string, unknown> {
107
+ const properties = collection.properties as Record<string, Property> | undefined;
108
+ if (!properties) return row;
109
+
110
+ for (const [key, property] of Object.entries(properties)) {
111
+ if (!property?.excludeFromApi) continue;
112
+ delete row[key];
113
+ if (property.columnName) delete row[property.columnName];
114
+ }
115
+ return row;
116
+ }
117
+
94
118
  function renderTarget(
95
119
  targetRow: Record<string, unknown>,
96
120
  targetCollection: CollectionConfig,
@@ -100,7 +124,7 @@ function renderTarget(
100
124
  if (style === "inline") {
101
125
  // The target's columns, and only those: its address is the consumer's
102
126
  // to derive, and merging one in overwrites a real `id` column.
103
- return coerceDeclaredNumbers({ ...targetRow }, targetCollection);
127
+ return stripExcluded(coerceDeclaredNumbers({ ...targetRow }, targetCollection), targetCollection);
104
128
  }
105
129
 
106
130
  const address = relationTargetAddress(targetRow, targetCollection, registry);
@@ -168,7 +192,7 @@ export function toCmsRow(
168
192
  }
169
193
  }
170
194
 
171
- return normalized;
195
+ return stripExcluded(normalized, collection);
172
196
  }
173
197
 
174
198
  /**
@@ -211,5 +235,5 @@ export function toRestRow(
211
235
  }
212
236
  }
213
237
 
214
- return flat;
238
+ return stripExcluded(flat, collection);
215
239
  }