@rebasepro/server-postgres 0.13.0 → 0.13.1-canary.g06dbe5b

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 (85) hide show
  1. package/dist/PostgresBackendDriver.d.ts +48 -1
  2. package/dist/auth/services.d.ts +19 -0
  3. package/dist/{src-DlPBctw_.js → auth-users-columns-CBEOeYqa.js} +835 -63
  4. package/dist/auth-users-columns-CBEOeYqa.js.map +1 -0
  5. package/dist/{backup-service-CD8o_1Sl.js → backup-service-Bww-Lg0s.js} +2 -2
  6. package/dist/{backup-service-CD8o_1Sl.js.map → backup-service-Bww-Lg0s.js.map} +1 -1
  7. package/dist/cli-helpers.d.ts +57 -1
  8. package/dist/data-transformer.d.ts +7 -2
  9. package/dist/data_driver-ULAyJEi9.js +193 -0
  10. package/dist/data_driver-ULAyJEi9.js.map +1 -0
  11. package/dist/{ensure-collection-policies-ViG8XiPn.js → ensure-collection-policies-B_JMGa5K.js} +2 -2
  12. package/dist/{ensure-collection-policies-ViG8XiPn.js.map → ensure-collection-policies-B_JMGa5K.js.map} +1 -1
  13. package/dist/{ensure-collection-tables-CBQdOETu.js → ensure-collection-tables-DzeTEvMv.js} +170 -20
  14. package/dist/ensure-collection-tables-DzeTEvMv.js.map +1 -0
  15. package/dist/index.es.js +1365 -338
  16. package/dist/index.es.js.map +1 -1
  17. package/dist/rls-bootstrap-sql-Bpv3nUZo.js +244 -0
  18. package/dist/rls-bootstrap-sql-Bpv3nUZo.js.map +1 -0
  19. package/dist/schema/auth-schema.d.ts +102 -0
  20. package/dist/schema/auth-users-columns.d.ts +97 -0
  21. package/dist/schema/doctor-policy-checks.d.ts +28 -0
  22. package/dist/schema/doctor.d.ts +23 -25
  23. package/dist/schema/ensure-collection-tables.d.ts +61 -7
  24. package/dist/schema/generate-drizzle-schema-logic.d.ts +10 -2
  25. package/dist/schema/generate-postgres-ddl-logic.d.ts +53 -5
  26. package/dist/schema/generated-schema-staleness.d.ts +39 -0
  27. package/dist/schema/rls-bootstrap-sql.d.ts +135 -0
  28. package/dist/schema/search-column.d.ts +248 -0
  29. package/dist/security/rls-enforcement.d.ts +61 -5
  30. package/dist/services/FetchService.d.ts +34 -7
  31. package/dist/services/RelationService.d.ts +30 -0
  32. package/dist/services/collection-helpers.d.ts +26 -0
  33. package/dist/services/dataService.d.ts +5 -0
  34. package/dist/services/realtimeService.d.ts +131 -21
  35. package/dist/{src-DoU9yPqq.js → src-C_wvdMnl.js} +91 -2
  36. package/dist/src-C_wvdMnl.js.map +1 -0
  37. package/dist/utils/drizzle-conditions.d.ts +124 -2
  38. package/dist/{websocket-B2LsrINK.js → websocket-D1qbmLZ2.js} +75 -18
  39. package/dist/websocket-D1qbmLZ2.js.map +1 -0
  40. package/package.json +9 -8
  41. package/src/PostgresBackendDriver.ts +172 -6
  42. package/src/PostgresBootstrapper.ts +55 -6
  43. package/src/auth/ensure-tables.ts +207 -86
  44. package/src/auth/services.ts +69 -5
  45. package/src/cli-helpers.ts +129 -10
  46. package/src/cli.ts +232 -30
  47. package/src/collections/validate-relations.ts +124 -17
  48. package/src/data-transformer.ts +120 -17
  49. package/src/history/ensure-history-table.ts +7 -0
  50. package/src/schema/auth-schema.ts +17 -1
  51. package/src/schema/auth-users-columns.ts +131 -0
  52. package/src/schema/doctor-cli.ts +12 -63
  53. package/src/schema/doctor-policy-checks.ts +105 -0
  54. package/src/schema/doctor.ts +135 -76
  55. package/src/schema/ensure-collection-tables.ts +374 -32
  56. package/src/schema/generate-drizzle-schema-logic.ts +132 -42
  57. package/src/schema/generate-postgres-ddl-logic.ts +294 -16
  58. package/src/schema/generate-postgres-ddl.ts +25 -2
  59. package/src/schema/generated-schema-staleness.ts +169 -0
  60. package/src/schema/introspect-db-logic.ts +66 -34
  61. package/src/schema/non-sql-collections.test.ts +131 -0
  62. package/src/schema/rls-bootstrap-sql.ts +288 -0
  63. package/src/schema/search-column.ts +643 -0
  64. package/src/security/anonymous-grants.test.ts +4 -2
  65. package/src/security/rls-enforcement.ts +149 -6
  66. package/src/services/BranchService.ts +5 -0
  67. package/src/services/FetchService.ts +175 -108
  68. package/src/services/PersistService.ts +38 -2
  69. package/src/services/RelationService.ts +110 -67
  70. package/src/services/channel-history.ts +14 -0
  71. package/src/services/channel-presence.ts +13 -0
  72. package/src/services/collection-helpers.ts +54 -1
  73. package/src/services/dataService.ts +5 -0
  74. package/src/services/realtimeService.ts +344 -79
  75. package/src/utils/drizzle-conditions.ts +365 -23
  76. package/src/utils/pg-error-utils.ts +8 -3
  77. package/src/websocket.ts +113 -16
  78. package/dist/ensure-collection-tables-CBQdOETu.js.map +0 -1
  79. package/dist/policy-CeA1JcxP.js +0 -105
  80. package/dist/policy-CeA1JcxP.js.map +0 -1
  81. package/dist/schema/auth-bootstrap-sql.d.ts +0 -24
  82. package/dist/src-DlPBctw_.js.map +0 -1
  83. package/dist/src-DoU9yPqq.js.map +0 -1
  84. package/dist/websocket-B2LsrINK.js.map +0 -1
  85. package/src/schema/auth-bootstrap-sql.ts +0 -47
@@ -3,7 +3,7 @@ import { BranchService } from "./services/BranchService";
3
3
  import { RealtimeService } from "./services/realtimeService";
4
4
  import { DatabasePoolManager } from "./databasePoolManager";
5
5
  import { DrizzleClient } from "./interfaces";
6
- import { DatabaseAdmin, DataDriver, DeleteProps, CollectionConfig, FetchCollectionProps, FetchOneProps, ListenCollectionProps, ListenOneProps, RebaseClient, RebaseSdkData, RestFetchService, SaveManyProps, SaveProps, TableMetadata, User } from "@rebasepro/types";
6
+ import { DatabaseAdmin, DataDriver, DeleteProps, CollectionConfig, FetchCollectionProps, FetchOneProps, ListenCollectionProps, ListenOneProps, RebaseClient, RebaseSdkData, RestFetchService, SaveManyProps, SaveProps, UpdateManyProps, DeleteManyProps, TableMetadata, User } from "@rebasepro/types";
7
7
  import { PostgresCollectionRegistry } from "./collections/PostgresCollectionRegistry";
8
8
  import { HistoryService } from "./history/HistoryService";
9
9
  export declare class PostgresBackendDriver implements DataDriver {
@@ -62,6 +62,25 @@ export declare class PostgresBackendDriver implements DataDriver {
62
62
  * REST/SDK read leaks unmasked data (see {@link applyAfterReadForRest}).
63
63
  */
64
64
  get restFetchService(): RestFetchService;
65
+ /**
66
+ * Build the context handed to every collection callback.
67
+ *
68
+ * Note `data: this.data` — `this` is whichever driver is running the
69
+ * operation, so the callback's data plane inherits that driver's privilege.
70
+ * On a user request `AuthenticatedPostgresBackendDriver.withTransaction`
71
+ * constructs a fresh base driver bound to the RLS-scoped transaction and
72
+ * runs the operation on it, so `this.data` speaks through that connection
73
+ * and policies apply. On server-context work `this` is the base driver on
74
+ * the owner connection, and they do not. Pinned by the
75
+ * `"scopes context.data to the caller"` case in the `rls-enforcement` e2e
76
+ * suite, because it is the kind of property that is easy to break from a
77
+ * distance and impossible to notice.
78
+ *
79
+ * Previously returned through `as unknown as RebaseCallContext`, which
80
+ * disabled checking for the whole object and let `driver` — documented in
81
+ * the callbacks guide — sit on the runtime context while absent from the
82
+ * contract. Both are declared now, so this is a plain typed return.
83
+ */
65
84
  private buildCallContext;
66
85
  private resolveCollectionCallbacks;
67
86
  /**
@@ -102,6 +121,34 @@ export declare class PostgresBackendDriver implements DataDriver {
102
121
  * with the last write winning, exactly as separate calls would.
103
122
  */
104
123
  saveMany<M extends Record<string, unknown>>({ path, rows, collection, upsert }: SaveManyProps<M>): Promise<Record<string, unknown>[]>;
124
+ /**
125
+ * Update many rows through the same pipeline as {@link save}, in one
126
+ * transaction.
127
+ *
128
+ * Structurally the mirror of {@link saveMany} — same tx-bound sub-driver,
129
+ * same deferred notifications, same per-row error labelling — but it calls
130
+ * `save` with an explicit `id` and `status: "existing"`, which is precisely
131
+ * what `saveMany` cannot do: that one passes `status: "new"` and keeps the
132
+ * key inside `values`, so it inserts or upserts and can never target a
133
+ * particular row.
134
+ *
135
+ * All-or-nothing, so an id matching no row aborts the batch. A partial
136
+ * update is the outcome with no good recovery: the caller cannot tell which
137
+ * half landed without re-reading everything.
138
+ */
139
+ updateMany<M extends Record<string, unknown>>({ path, updates, collection }: UpdateManyProps<M>): Promise<Record<string, unknown>[]>;
140
+ /**
141
+ * Delete many rows in one transaction, running the full delete pipeline —
142
+ * `beforeDelete`, the delete, `afterDelete` — for each.
143
+ *
144
+ * Looping the single-row {@link delete} rather than emitting one
145
+ * `DELETE ... WHERE id = ANY($1)` is the deliberate choice: a single
146
+ * statement would be faster and would skip every callback, so a collection
147
+ * relying on `beforeDelete` to veto or on `afterDelete` to clean up
148
+ * dependents would behave differently depending on how many rows the caller
149
+ * happened to delete at once. Same pipeline, one transaction.
150
+ */
151
+ deleteMany<M extends Record<string, unknown>>({ path, ids, collection }: DeleteManyProps<M>): Promise<void>;
105
152
  delete<M extends Record<string, unknown>>({ row, collection }: DeleteProps<M>): Promise<void>;
106
153
  deleteAll(path: string): Promise<void>;
107
154
  checkUniqueField(path: string, name: string, value: unknown, id?: string, collection?: CollectionConfig): Promise<boolean>;
@@ -296,6 +296,8 @@ export declare class PostgresAuthRepository implements AuthRepository {
296
296
  getUnusedRecoveryCodeCount(uid: string): Promise<number>;
297
297
  deleteAllRecoveryCodes(uid: string): Promise<void>;
298
298
  hasVerifiedMfaFactors(uid: string): Promise<boolean>;
299
+ claimMfaFactorCounter(factorId: string, counter: number): Promise<boolean>;
300
+ recordMfaChallengeAttempt(challengeId: string): Promise<number>;
299
301
  }
300
302
  /**
301
303
  * PostgreSQL implementation of MfaRepository.
@@ -311,10 +313,27 @@ export declare class MfaService implements MfaRepository {
311
313
  getMfaFactorById(factorId: string): Promise<(MfaFactor & {
312
314
  secretEncrypted: string;
313
315
  }) | null>;
316
+ /**
317
+ * Spend a TOTP time step, once and only once.
318
+ *
319
+ * One statement: the `WHERE` is the check, the `UPDATE` is the act, and
320
+ * `RETURNING` reports which of two concurrent requests carrying the same
321
+ * six digits won. Reading the counter and then writing it would let both
322
+ * pass — the exact replay this closes.
323
+ */
324
+ claimMfaFactorCounter(factorId: string, counter: number): Promise<boolean>;
314
325
  verifyMfaFactor(factorId: string): Promise<void>;
315
326
  deleteMfaFactor(factorId: string, uid: string): Promise<void>;
316
327
  createMfaChallenge(factorId: string, ipAddress?: string): Promise<MfaChallengeInfo>;
317
328
  getMfaChallengeById(challengeId: string): Promise<MfaChallengeInfo | null>;
329
+ /**
330
+ * Count one failed guess against a challenge and report the new total.
331
+ *
332
+ * Incremented in the database rather than in the route so that guesses
333
+ * arriving in parallel — the shape any real brute-force takes — cannot
334
+ * share a single increment.
335
+ */
336
+ recordMfaChallengeAttempt(challengeId: string): Promise<number>;
318
337
  verifyMfaChallenge(challengeId: string): Promise<void>;
319
338
  createRecoveryCodes(uid: string, codeHashes: string[]): Promise<void>;
320
339
  useRecoveryCode(uid: string, codeHash: string): Promise<boolean>;