@rebasepro/server-postgres 0.9.1-canary.f0ac103 → 0.9.1-canary.fd3754b

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 (51) hide show
  1. package/dist/PostgresBackendDriver.d.ts +2 -25
  2. package/dist/PostgresBootstrapper.d.ts +0 -10
  3. package/dist/auth/services.d.ts +0 -16
  4. package/dist/chunk-DSJWtz9O.js +40 -0
  5. package/dist/connection.d.ts +0 -21
  6. package/dist/data-transformer.d.ts +2 -9
  7. package/dist/index.es.js +2604 -2007
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/schema/auth-default-policies.d.ts +10 -0
  10. package/dist/security/policy-drift.d.ts +5 -16
  11. package/dist/security/rls-enforcement.d.ts +2 -27
  12. package/dist/services/FetchService.d.ts +24 -4
  13. package/dist/services/PersistService.d.ts +1 -27
  14. package/dist/services/RelationService.d.ts +1 -34
  15. package/dist/services/collection-helpers.d.ts +14 -79
  16. package/dist/services/dataService.d.ts +1 -3
  17. package/dist/services/index.d.ts +1 -1
  18. package/dist/services/realtimeService.d.ts +0 -7
  19. package/dist/src-Eh-CZosp.js +595 -0
  20. package/dist/src-Eh-CZosp.js.map +1 -0
  21. package/package.json +17 -15
  22. package/src/PostgresBackendDriver.ts +13 -127
  23. package/src/PostgresBootstrapper.ts +26 -68
  24. package/src/auth/ensure-tables.ts +11 -73
  25. package/src/auth/services.ts +19 -49
  26. package/src/cli-helpers.ts +20 -2
  27. package/src/connection.ts +1 -61
  28. package/src/data-transformer.ts +9 -11
  29. package/src/databasePoolManager.ts +0 -2
  30. package/src/schema/auth-default-policies.ts +125 -0
  31. package/src/schema/doctor-cli.ts +1 -5
  32. package/src/schema/generate-drizzle-schema-logic.ts +29 -24
  33. package/src/schema/generate-postgres-ddl-logic.ts +28 -76
  34. package/src/schema/introspect-db.ts +2 -19
  35. package/src/security/policy-drift.test.ts +14 -48
  36. package/src/security/policy-drift.ts +10 -72
  37. package/src/security/rls-enforcement.ts +3 -64
  38. package/src/services/BranchService.ts +10 -42
  39. package/src/services/FetchService.ts +270 -65
  40. package/src/services/PersistService.ts +14 -130
  41. package/src/services/RelationService.ts +94 -153
  42. package/src/services/collection-helpers.ts +47 -164
  43. package/src/services/dataService.ts +2 -3
  44. package/src/services/index.ts +0 -1
  45. package/src/services/realtimeService.ts +19 -40
  46. package/src/utils/drizzle-conditions.ts +0 -13
  47. package/src/websocket.ts +1 -4
  48. package/dist/collections/buildRegistry.d.ts +0 -27
  49. package/dist/services/row-pipeline.d.ts +0 -63
  50. package/src/collections/buildRegistry.ts +0 -59
  51. package/src/services/row-pipeline.ts +0 -215
@@ -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, SaveProps, 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 {
@@ -88,20 +88,7 @@ export declare class PostgresBackendDriver implements DataDriver {
88
88
  listenCollection<M extends Record<string, unknown>>({ path, collection, filter, limit, offset, startAfter, orderBy, searchString, order, onUpdate, onError }: ListenCollectionProps<M>): () => void;
89
89
  fetchOne<M extends Record<string, unknown>>({ path, id, databaseId, collection }: FetchOneProps<M>): Promise<Record<string, unknown> | undefined>;
90
90
  listenOne<M extends Record<string, unknown>>({ path, id, collection, onUpdate, onError }: ListenOneProps<M>): () => void;
91
- save<M extends Record<string, unknown>>({ path, id, values, collection, status, upsert }: SaveProps<M>): Promise<Record<string, unknown>>;
92
- /**
93
- * Write many rows through the same pipeline as {@link save}.
94
- *
95
- * The batch runs in one transaction of its own, so a failure part-way leaves
96
- * nothing behind — the point of a batch is that a re-run starts from a known
97
- * state. When this driver is already inside a transaction (the authenticated
98
- * path, via `withTransaction`) the nested call becomes a savepoint, which is
99
- * still atomic and still commits once.
100
- *
101
- * Rows are applied in order, so a batch that touches the same key twice ends
102
- * with the last write winning, exactly as separate calls would.
103
- */
104
- saveMany<M extends Record<string, unknown>>({ path, rows, collection, upsert }: SaveManyProps<M>): Promise<Record<string, unknown>[]>;
91
+ save<M extends Record<string, unknown>>({ path, id, values, collection, status }: SaveProps<M>): Promise<Record<string, unknown>>;
105
92
  delete<M extends Record<string, unknown>>({ row, collection }: DeleteProps<M>): Promise<void>;
106
93
  deleteAll(path: string): Promise<void>;
107
94
  checkUniqueField(path: string, name: string, value: unknown, id?: string, collection?: CollectionConfig): Promise<boolean>;
@@ -156,16 +143,6 @@ export declare class AuthenticatedPostgresBackendDriver implements DataDriver {
156
143
  fetchOne<M extends Record<string, unknown>>(props: FetchOneProps<M>): Promise<Record<string, unknown> | undefined>;
157
144
  listenOne<M extends Record<string, unknown>>(props: ListenOneProps<M>): () => void;
158
145
  save<M extends Record<string, unknown>>(props: SaveProps<M>): Promise<Record<string, unknown>>;
159
- /**
160
- * One transaction for the whole batch, rather than one per row.
161
- *
162
- * This is the point of the method: `save` opens a transaction per call, so
163
- * importing 10k rows through it means 10k transactions (and, over HTTP, 10k
164
- * round trips). Here the RLS context is established once and every row lands
165
- * or none does. Realtime notifications are already deferred to commit by
166
- * `withTransaction`, so a batch does not flood subscribers mid-flight.
167
- */
168
- saveMany<M extends Record<string, unknown>>(props: SaveManyProps<M>): Promise<Record<string, unknown>[]>;
169
146
  delete<M extends Record<string, unknown>>(props: DeleteProps<M>): Promise<void>;
170
147
  deleteAll(path: string): Promise<void>;
171
148
  checkUniqueField(path: string, name: string, value: unknown, id?: string, collection?: CollectionConfig): Promise<boolean>;
@@ -9,7 +9,6 @@ import { PostgresBackendDriver } from "./PostgresBackendDriver";
9
9
  import { RealtimeService } from "./services/realtimeService";
10
10
  import { DatabasePoolManager } from "./databasePoolManager";
11
11
  import { PostgresCollectionRegistry } from "./collections/PostgresCollectionRegistry";
12
- import { type CdcTableRef } from "./services/cdc/trigger-cdc";
13
12
  export interface PostgresDriverConfig {
14
13
  connectionString?: string;
15
14
  adminConnectionString?: string;
@@ -37,15 +36,6 @@ export interface PostgresDriverInternals {
37
36
  realtimeService: RealtimeService;
38
37
  driver: PostgresBackendDriver;
39
38
  poolManager?: DatabasePoolManager;
40
- /**
41
- * Attach CDC triggers to tables that did not exist when the driver
42
- * bootstrapped. Only set when database-level capture is actually active.
43
- *
44
- * Auth owns its own tables and creates them later in boot, so at driver
45
- * bootstrap they are legitimately missing and get skipped; without this
46
- * they would stay uninstrumented until the next restart.
47
- */
48
- provisionCdcForTables?: (tables: CdcTableRef[]) => Promise<void>;
49
39
  }
50
40
  /**
51
41
  * Default PostgreSQL bootstrapper.
@@ -19,22 +19,6 @@ export declare class UserService implements UserRepository {
19
19
  private userIdentitiesTable;
20
20
  constructor(db: NodePgDatabase, tableOrTables?: RebasePgTable | Partial<AuthSchemaTables>);
21
21
  private getQualifiedUsersTableName;
22
- /**
23
- * Run a privileged auth write with an explicitly cleared RLS context.
24
- *
25
- * The auth services run on the base/owner connection, which by design
26
- * carries a NULL `app.user_id` so the `auth.uid() IS NULL` server-escape
27
- * in the default policies applies. That NULL is normally guaranteed by
28
- * `set_config(..., is_local = true)` resetting at transaction end — but a
29
- * GUC that survives on a pooled connection (or a connection role that
30
- * doesn't bypass RLS: FORCE ROW LEVEL SECURITY, or a non-owner role)
31
- * turns the trusted write into an RLS-scoped one and denies it with
32
- * SQLSTATE 42501. Clearing the GUCs here, transaction-locally at the
33
- * single chokepoint, makes the server context deterministic instead of
34
- * trusting whatever state the pool hands us. `auth.uid()` reads '' as
35
- * NULL via NULLIF, so '' is the server context.
36
- */
37
- private withServerContext;
38
22
  private mapRowToUser;
39
23
  private mapPayload;
40
24
  createUser(data: CreateUserData): Promise<UserData>;
@@ -0,0 +1,40 @@
1
+ import { createRequire as __createRequire } from "module";
2
+ import "process";
3
+ const require = __createRequire(import.meta.url);
4
+ //#region \0rolldown/runtime.js
5
+ var __create = Object.create;
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
12
+ var __exportAll = (all, no_symbols) => {
13
+ let target = {};
14
+ for (var name in all) __defProp(target, name, {
15
+ get: all[name],
16
+ enumerable: true
17
+ });
18
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
19
+ return target;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
23
+ key = keys[i];
24
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
25
+ get: ((k) => from[k]).bind(null, key),
26
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
+ });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
32
+ value: mod,
33
+ enumerable: true
34
+ }) : target, mod));
35
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
36
+ if (typeof require !== "undefined") return require.apply(this, arguments);
37
+ throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
38
+ });
39
+ //#endregion
40
+ export { __toESM as i, __exportAll as n, __require as r, __commonJSMin as t };
@@ -19,27 +19,6 @@ export interface PostgresPoolConfig {
19
19
  /** Enable TCP keep-alive (default: true) */
20
20
  keepAlive?: boolean;
21
21
  }
22
- /**
23
- * Destroy pool clients that are released while still inside a transaction.
24
- *
25
- * pg-pool returns a client to the idle list whenever `release()` is called
26
- * without an error — even if the connection is still mid-transaction (status
27
- * `T`/`E`). That happens in practice: drizzle's pool transaction releases in
28
- * a `finally` after attempting ROLLBACK, and if the ROLLBACK itself fails
29
- * (e.g. it was queued behind a statement that hit the client-side
30
- * query_timeout), the client goes back dirty. The next checkout then runs
31
- * its statements inside the zombie transaction — with the previous request's
32
- * `app.*` RLS GUCs still applied, which turns unrelated queries into
33
- * RLS-scoped ones (observed in production as registration failing with
34
- * SQLSTATE 42501 under a leaked anonymous context).
35
- *
36
- * pg-pool emits `release` before it consults its private `_expired` set, so
37
- * marking the client expired here makes `_release()` destroy it instead of
38
- * pooling it. Both `client._txStatus` (pg ≥ 8.16) and `pool._expired` are
39
- * private APIs — feature-detect and fall back to loud logging so an upstream
40
- * change degrades to observability, never to silent corruption.
41
- */
42
- export declare function guardPoolAgainstDirtyRelease(pool: Pool, label: string): void;
43
22
  /**
44
23
  * Create a Drizzle-backed Postgres connection with a production-grade
45
24
  * connection pool.
@@ -12,19 +12,12 @@ import { PostgresCollectionRegistry } from "./collections/PostgresCollectionRegi
12
12
  export interface SerializedEntityData {
13
13
  /** Scalar column values ready for INSERT/UPDATE. */
14
14
  scalarData: Record<string, unknown>;
15
- /**
16
- * Inverse relation updates that must be applied to target tables.
17
- *
18
- * No address here: the row being written does not know its own. These are
19
- * applied by `PersistService`, which addresses them with the id it holds —
20
- * the one it was given for an update, or the one the INSERT returned — and
21
- * that is the authority. This item used to carry a `currentId` derived from
22
- * the *input* values, which nothing ever read.
23
- */
15
+ /** Inverse relation updates that must be applied to target tables. */
24
16
  inverseRelationUpdates: Array<{
25
17
  relationKey: string;
26
18
  relation: Relation;
27
19
  newValue: unknown;
20
+ currentId?: string | number;
28
21
  }>;
29
22
  /** JoinPath relation updates that require multi-hop writes. */
30
23
  joinPathRelationUpdates: Array<{