@rebasepro/server-postgres 0.12.0 → 0.12.1-canary.g06f263c

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 (53) hide show
  1. package/dist/PostgresBootstrapper.d.ts +25 -1
  2. package/dist/auth/services.d.ts +16 -0
  3. package/dist/backup-service-vAKWJkYL.js +8867 -0
  4. package/dist/backup-service-vAKWJkYL.js.map +1 -0
  5. package/dist/cli-helpers.d.ts +24 -0
  6. package/dist/connection-BuZ97wsr.js +250 -0
  7. package/dist/connection-BuZ97wsr.js.map +1 -0
  8. package/dist/connection.d.ts +42 -0
  9. package/dist/ensure-collection-policies-BjSwj0FM.js +57 -0
  10. package/dist/ensure-collection-policies-BjSwj0FM.js.map +1 -0
  11. package/dist/ensure-collection-tables-D6-XhqnQ.js +590 -0
  12. package/dist/ensure-collection-tables-D6-XhqnQ.js.map +1 -0
  13. package/dist/index.es.js +545 -9629
  14. package/dist/index.es.js.map +1 -1
  15. package/dist/policy-CeA1JcxP.js +105 -0
  16. package/dist/policy-CeA1JcxP.js.map +1 -0
  17. package/dist/schema/auth-schema.d.ts +83 -144
  18. package/dist/schema/ensure-collection-policies.d.ts +60 -0
  19. package/dist/schema/ensure-collection-tables.d.ts +24 -2
  20. package/dist/schema/generate-postgres-ddl-logic.d.ts +116 -1
  21. package/dist/{src-BbFOPJ1S.js → src-C_NHNVW2.js} +94 -153
  22. package/dist/src-C_NHNVW2.js.map +1 -0
  23. package/dist/{src-Zqwaw3P5.js → src-DoU9yPqq.js} +3 -159
  24. package/dist/src-DoU9yPqq.js.map +1 -0
  25. package/dist/utils/pg-error-utils.d.ts +19 -0
  26. package/dist/websocket-DB7TbFPT.js +529 -0
  27. package/dist/websocket-DB7TbFPT.js.map +1 -0
  28. package/package.json +14 -14
  29. package/src/PostgresAdapter.ts +14 -0
  30. package/src/PostgresBootstrapper.ts +192 -33
  31. package/src/auth/ensure-tables.ts +164 -9
  32. package/src/auth/services.ts +21 -2
  33. package/src/cli-helpers.ts +44 -0
  34. package/src/cli.ts +31 -3
  35. package/src/connection.ts +73 -0
  36. package/src/databasePoolManager.ts +5 -2
  37. package/src/schema/auth-schema.ts +30 -19
  38. package/src/schema/ensure-collection-policies.ts +105 -0
  39. package/src/schema/ensure-collection-tables.test.ts +105 -9
  40. package/src/schema/ensure-collection-tables.ts +142 -25
  41. package/src/schema/generate-drizzle-schema-logic.ts +16 -5
  42. package/src/schema/generate-postgres-ddl-logic.ts +335 -16
  43. package/src/schema/introspect-runtime.test.ts +56 -8
  44. package/src/schema/introspect-runtime.ts +31 -9
  45. package/src/services/RelationService.ts +38 -3
  46. package/src/services/realtimeService.ts +3 -3
  47. package/src/utils/pg-error-utils.ts +46 -0
  48. package/src/websocket.ts +3 -3
  49. package/dist/chunk-DSJWtz9O.js +0 -40
  50. package/dist/ensure-collection-tables-CNTcZGvn.js +0 -304
  51. package/dist/ensure-collection-tables-CNTcZGvn.js.map +0 -1
  52. package/dist/src-BbFOPJ1S.js.map +0 -1
  53. package/dist/src-Zqwaw3P5.js.map +0 -1
@@ -4,7 +4,7 @@
4
4
  * Implements the `BackendBootstrapper` interface for PostgreSQL.
5
5
  */
6
6
  import { NodePgDatabase } from "drizzle-orm/node-postgres";
7
- import { BackendBootstrapper, type RealtimeChannelsConfig } from "@rebasepro/types";
7
+ import { BackendBootstrapper, CollectionConfig, type RealtimeChannelsConfig } from "@rebasepro/types";
8
8
  import { PostgresBackendDriver } from "./PostgresBackendDriver";
9
9
  import { RealtimeService } from "./services/realtimeService";
10
10
  import { DatabasePoolManager } from "./databasePoolManager";
@@ -65,6 +65,30 @@ export interface PostgresDriverInternals {
65
65
  */
66
66
  provisionCdcForTables?: (tables: CdcTableRef[]) => Promise<void>;
67
67
  }
68
+ /**
69
+ * Which table name the boot-time drift check should look for, for one collection.
70
+ *
71
+ * A declared `table` IS the table name, not a hint to be second-guessed. This
72
+ * used to ask the registry whether it had indexed the declared name and fall
73
+ * back to the SLUG when it had not — but "the registry does not know this table"
74
+ * is exactly the condition the drift check exists to report, so the fallback
75
+ * fired precisely when it was most harmful.
76
+ *
77
+ * A collection with `slug: "usage-daily", table: "usage_daily"` was reported as
78
+ * missing table `usage-daily`: a name that does not exist, should never exist,
79
+ * and that nobody can find by looking. Worse, the remediation the caller prints
80
+ * says to run `rebase db push` — which would then CREATE that invented table
81
+ * beside the correct one, the same "second copy" hazard the misplaced-schema
82
+ * branch further down exists to prevent. Seen in production, where a correctly
83
+ * migrated database reported drift on every boot.
84
+ *
85
+ * The slug is used only when nothing was declared, which is the config shape
86
+ * where the slug genuinely is the table name.
87
+ *
88
+ * Exported for its own test: the caller needs a live pool and a real database,
89
+ * and this is the part that was wrong.
90
+ */
91
+ export declare function resolveDriftCheckName(col: CollectionConfig, registeredTableNames: string[]): string;
68
92
  /**
69
93
  * Default PostgreSQL bootstrapper.
70
94
  *
@@ -9,6 +9,22 @@ export interface AuthSchemaTables {
9
9
  appConfig: RebasePgTable;
10
10
  userIdentities: RebasePgTable;
11
11
  }
12
+ /**
13
+ * The single definition of what an email address looks like in storage.
14
+ *
15
+ * Reads have always folded case; writes did not, and normalising was left to
16
+ * each caller. That asymmetry is only ever one forgotten `.toLowerCase()` away
17
+ * from a row no lookup can find — the account exists, every sign-in path
18
+ * reports no such user, and the byte-exact UNIQUE on the column does not stop a
19
+ * duplicate differing only in case. Applied on both sides here so the guarantee
20
+ * belongs to the repository rather than to its callers' discipline; the
21
+ * `lower(email)` unique index added in `ensureAuthTablesExist` is the database
22
+ * half of the same rule.
23
+ *
24
+ * Whitespace goes too: a trailing space survives the fold and reproduces the
25
+ * problem exactly.
26
+ */
27
+ export declare function normalizeEmail<T>(email: T): T | string;
12
28
  /**
13
29
  * PostgreSQL implementation of UserRepository.
14
30
  * Handles all user-related database operations using Drizzle ORM.