@rebasepro/server-postgresql 0.7.0 → 0.8.0
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.
- package/build-errors.txt +37 -0
- package/dist/PostgresAdapter.d.ts +6 -0
- package/dist/PostgresBackendDriver.d.ts +118 -0
- package/dist/PostgresBootstrapper.d.ts +46 -0
- package/dist/auth/ensure-tables.d.ts +10 -0
- package/dist/auth/services.d.ts +251 -0
- package/dist/cli-errors.d.ts +29 -0
- package/dist/cli-helpers.d.ts +7 -0
- package/dist/cli.d.ts +1 -0
- package/dist/collections/PostgresCollectionRegistry.d.ts +47 -0
- package/dist/connection.d.ts +65 -0
- package/dist/data-transformer.d.ts +55 -0
- package/dist/databasePoolManager.d.ts +20 -0
- package/dist/history/HistoryService.d.ts +71 -0
- package/dist/history/ensure-history-table.d.ts +7 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.es.js +13560 -0
- package/dist/index.es.js.map +1 -0
- package/dist/interfaces.d.ts +18 -0
- package/dist/schema/auth-default-policies.d.ts +12 -0
- package/dist/schema/auth-schema.d.ts +2376 -0
- package/dist/schema/doctor-cli.d.ts +2 -0
- package/dist/schema/doctor.d.ts +52 -0
- package/dist/schema/generate-drizzle-schema-logic.d.ts +2 -0
- package/dist/schema/generate-drizzle-schema.d.ts +1 -0
- package/dist/schema/generate-postgres-ddl-logic.d.ts +5 -0
- package/dist/schema/generate-postgres-ddl.d.ts +1 -0
- package/dist/schema/introspect-db-inference.d.ts +5 -0
- package/dist/schema/introspect-db-logic.d.ts +118 -0
- package/dist/schema/introspect-db.d.ts +1 -0
- package/dist/schema/test-schema.d.ts +24 -0
- package/dist/services/BranchService.d.ts +47 -0
- package/dist/services/EntityFetchService.d.ts +214 -0
- package/dist/services/EntityPersistService.d.ts +40 -0
- package/dist/services/RelationService.d.ts +98 -0
- package/dist/services/entity-helpers.d.ts +38 -0
- package/dist/services/entityService.d.ts +110 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/realtimeService.d.ts +220 -0
- package/dist/types.d.ts +3 -0
- package/dist/utils/drizzle-conditions.d.ts +138 -0
- package/dist/utils/pg-array-null-patch.d.ts +16 -0
- package/dist/utils/pg-error-utils.d.ts +65 -0
- package/dist/utils/table-classification.d.ts +8 -0
- package/dist/websocket.d.ts +11 -0
- package/package.json +17 -17
- package/src/PostgresBackendDriver.ts +135 -24
- package/src/cli.ts +73 -1
- package/src/collections/PostgresCollectionRegistry.ts +6 -6
- package/src/data-transformer.ts +2 -2
- package/src/schema/auth-default-policies.ts +13 -6
- package/src/schema/generate-drizzle-schema-logic.ts +16 -79
- package/src/schema/generate-postgres-ddl-logic.ts +14 -51
- package/src/services/realtimeService.ts +26 -2
- package/test/entity-callbacks-redaction.test.ts +86 -0
- package/test/postgresDataDriver.test.ts +2 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { EntityCollection, Properties, Property, Relation } from "@rebasepro/types";
|
|
3
|
+
import { PostgresCollectionRegistry } from "./collections/PostgresCollectionRegistry";
|
|
4
|
+
/**
|
|
5
|
+
* Data transformation utilities for converting between frontend and database formats.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Typed result from `serializeDataToServer`.
|
|
9
|
+
* Replaces the hidden `__inverseRelationUpdates` / `__joinPathRelationUpdates`
|
|
10
|
+
* dunder-property mutation pattern with explicit, typed state management.
|
|
11
|
+
*/
|
|
12
|
+
export interface SerializedEntityData {
|
|
13
|
+
/** Scalar column values ready for INSERT/UPDATE. */
|
|
14
|
+
scalarData: Record<string, unknown>;
|
|
15
|
+
/** Inverse relation updates that must be applied to target tables. */
|
|
16
|
+
inverseRelationUpdates: Array<{
|
|
17
|
+
relationKey: string;
|
|
18
|
+
relation: Relation;
|
|
19
|
+
newValue: unknown;
|
|
20
|
+
currentEntityId?: string | number;
|
|
21
|
+
}>;
|
|
22
|
+
/** JoinPath relation updates that require multi-hop writes. */
|
|
23
|
+
joinPathRelationUpdates: Array<{
|
|
24
|
+
relationKey: string;
|
|
25
|
+
relation: Relation;
|
|
26
|
+
newTargetId: string | number | null;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Helper function to sanitize and convert dates to ISO strings
|
|
31
|
+
*/
|
|
32
|
+
export declare function sanitizeAndConvertDates(obj: unknown): unknown;
|
|
33
|
+
/**
|
|
34
|
+
* Transform relations for database storage (relation objects to IDs)
|
|
35
|
+
*/
|
|
36
|
+
export declare function serializeDataToServer<M extends Record<string, unknown>>(entity: M, properties: Properties, collection?: EntityCollection, registry?: PostgresCollectionRegistry): SerializedEntityData;
|
|
37
|
+
/**
|
|
38
|
+
* Serialize a single property value for database storage
|
|
39
|
+
*/
|
|
40
|
+
export declare function serializePropertyToServer(value: unknown, property: Property): unknown;
|
|
41
|
+
/**
|
|
42
|
+
* Transform IDs back to relation objects for frontend
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseDataFromServer<M extends Record<string, unknown>>(data: M, collection: EntityCollection, db?: NodePgDatabase<Record<string, unknown>>, registry?: PostgresCollectionRegistry): Promise<M>;
|
|
45
|
+
export declare function parsePropertyFromServer(value: unknown, property: Property, collection: EntityCollection, propertyKey?: string): unknown;
|
|
46
|
+
/**
|
|
47
|
+
* Lightweight value normalization for db.query results.
|
|
48
|
+
* Only handles type coercion (dates, numbers, NaN) and property filtering.
|
|
49
|
+
* Does NOT query the database for relations — those are already resolved
|
|
50
|
+
* by Drizzle's relational query API.
|
|
51
|
+
*
|
|
52
|
+
* Use this instead of `parseDataFromServer` when processing results from
|
|
53
|
+
* `db.query.findFirst/findMany` which return pre-hydrated relation data.
|
|
54
|
+
*/
|
|
55
|
+
export declare function normalizeDbValues<M extends Record<string, unknown>>(data: M, collection: EntityCollection): M;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Pool } from "pg";
|
|
2
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
+
export declare class DatabasePoolManager {
|
|
4
|
+
private pools;
|
|
5
|
+
private drizzleInstances;
|
|
6
|
+
readonly defaultDatabaseName: string;
|
|
7
|
+
private readonly rootConnectionString;
|
|
8
|
+
constructor(adminConnectionString: string);
|
|
9
|
+
getDrizzle(databaseName: string): NodePgDatabase<Record<string, never>>;
|
|
10
|
+
getPool(databaseName: string): Pool;
|
|
11
|
+
/**
|
|
12
|
+
* Disconnect and remove the pool for a specific database.
|
|
13
|
+
* Required before `CREATE DATABASE ... TEMPLATE` or `DROP DATABASE`,
|
|
14
|
+
* which need exclusive access to the target database.
|
|
15
|
+
*/
|
|
16
|
+
disconnectDatabase(databaseName: string): Promise<void>;
|
|
17
|
+
/** Check if a pool exists for a given database name. */
|
|
18
|
+
hasPool(databaseName: string): boolean;
|
|
19
|
+
shutdown(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
export interface HistoryEntry {
|
|
3
|
+
id: string;
|
|
4
|
+
table_name: string;
|
|
5
|
+
entity_id: string;
|
|
6
|
+
action: "create" | "update" | "delete";
|
|
7
|
+
changed_fields: string[] | null;
|
|
8
|
+
values: Record<string, unknown> | null;
|
|
9
|
+
previous_values: Record<string, unknown> | null;
|
|
10
|
+
updated_by: string | null;
|
|
11
|
+
updated_at: string;
|
|
12
|
+
}
|
|
13
|
+
export interface RecordHistoryParams {
|
|
14
|
+
tableName: string;
|
|
15
|
+
entityId: string;
|
|
16
|
+
action: "create" | "update" | "delete";
|
|
17
|
+
values?: Record<string, unknown> | null;
|
|
18
|
+
previousValues?: Record<string, unknown> | null;
|
|
19
|
+
updatedBy?: string | null;
|
|
20
|
+
}
|
|
21
|
+
export interface FetchHistoryOptions {
|
|
22
|
+
limit?: number;
|
|
23
|
+
offset?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface HistoryRetentionConfig {
|
|
26
|
+
/** Max entries per entity. Oldest pruned first. Default 200. */
|
|
27
|
+
maxEntries: number;
|
|
28
|
+
/** Entries older than this many days are pruned. Default 90. */
|
|
29
|
+
ttlDays: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Service for recording and querying entity change history.
|
|
33
|
+
* Stores snapshots in the `rebase.entity_history` table.
|
|
34
|
+
*/
|
|
35
|
+
export declare class HistoryService {
|
|
36
|
+
private db;
|
|
37
|
+
retention: HistoryRetentionConfig;
|
|
38
|
+
constructor(db: NodePgDatabase, retention?: Partial<HistoryRetentionConfig>);
|
|
39
|
+
/**
|
|
40
|
+
* Record a history entry for an entity change.
|
|
41
|
+
* This is intentionally fire-and-forget safe — errors are logged but never
|
|
42
|
+
* bubble up to block the main save/delete operation.
|
|
43
|
+
*
|
|
44
|
+
* After inserting, kicks off a non-blocking pruning pass for this entity.
|
|
45
|
+
*/
|
|
46
|
+
recordHistory(params: RecordHistoryParams): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Fetch history entries for an entity, ordered by most recent first.
|
|
49
|
+
*/
|
|
50
|
+
fetchHistory(tableName: string, entityId: string, options?: FetchHistoryOptions): Promise<{
|
|
51
|
+
data: HistoryEntry[];
|
|
52
|
+
total: number;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Fetch a single history entry by ID.
|
|
56
|
+
*/
|
|
57
|
+
fetchHistoryEntry(historyId: string): Promise<HistoryEntry | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Prune history for a single entity: enforce maxEntries and TTL.
|
|
60
|
+
*/
|
|
61
|
+
pruneEntity(tableName: string, entityId: string): Promise<number>;
|
|
62
|
+
/**
|
|
63
|
+
* Global prune: enforce TTL across ALL entities in a single sweep.
|
|
64
|
+
* Intended to be called periodically (e.g. once per hour or daily).
|
|
65
|
+
*/
|
|
66
|
+
pruneExpired(): Promise<number>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Shallow comparison to find top-level keys that changed between two objects.
|
|
70
|
+
*/
|
|
71
|
+
export declare function findChangedFields(oldValues: Record<string, unknown>, newValues: Record<string, unknown>): string[] | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
/**
|
|
3
|
+
* Auto-create the entity history table if it doesn't exist.
|
|
4
|
+
* This runs on startup when history is enabled, following the same
|
|
5
|
+
* pattern as `ensureAuthTablesExist`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ensureHistoryTableExists(db: NodePgDatabase): Promise<void>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./connection";
|
|
2
|
+
export * from "./interfaces";
|
|
3
|
+
export * from "./PostgresBackendDriver";
|
|
4
|
+
export * from "./databasePoolManager";
|
|
5
|
+
export * from "./schema/auth-schema";
|
|
6
|
+
export * from "./schema/generate-drizzle-schema-logic";
|
|
7
|
+
export * from "./schema/generate-drizzle-schema";
|
|
8
|
+
export * from "./utils/drizzle-conditions";
|
|
9
|
+
export * from "./services/realtimeService";
|
|
10
|
+
export * from "./websocket";
|
|
11
|
+
export * from "./collections/PostgresCollectionRegistry";
|
|
12
|
+
export * from "./services/BranchService";
|
|
13
|
+
export * from "./PostgresBootstrapper";
|
|
14
|
+
export * from "./PostgresAdapter";
|