@rebasepro/server-postgresql 0.0.1-canary.09e5ec5
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/LICENSE +6 -0
- package/README.md +106 -0
- package/build-errors.txt +37 -0
- package/dist/common/src/collections/CollectionRegistry.d.ts +56 -0
- package/dist/common/src/collections/index.d.ts +1 -0
- package/dist/common/src/data/buildRebaseData.d.ts +14 -0
- package/dist/common/src/index.d.ts +3 -0
- package/dist/common/src/util/builders.d.ts +57 -0
- package/dist/common/src/util/callbacks.d.ts +6 -0
- package/dist/common/src/util/collections.d.ts +11 -0
- package/dist/common/src/util/common.d.ts +2 -0
- package/dist/common/src/util/conditions.d.ts +26 -0
- package/dist/common/src/util/entities.d.ts +58 -0
- package/dist/common/src/util/enums.d.ts +3 -0
- package/dist/common/src/util/index.d.ts +16 -0
- package/dist/common/src/util/navigation_from_path.d.ts +34 -0
- package/dist/common/src/util/navigation_utils.d.ts +20 -0
- package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
- package/dist/common/src/util/paths.d.ts +14 -0
- package/dist/common/src/util/permissions.d.ts +5 -0
- package/dist/common/src/util/references.d.ts +2 -0
- package/dist/common/src/util/relations.d.ts +22 -0
- package/dist/common/src/util/resolutions.d.ts +72 -0
- package/dist/common/src/util/storage.d.ts +24 -0
- package/dist/index.es.js +11298 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +11306 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +100 -0
- package/dist/server-postgresql/src/PostgresBootstrapper.d.ts +40 -0
- package/dist/server-postgresql/src/auth/ensure-tables.d.ts +6 -0
- package/dist/server-postgresql/src/auth/services.d.ts +192 -0
- package/dist/server-postgresql/src/cli.d.ts +1 -0
- package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +43 -0
- package/dist/server-postgresql/src/connection.d.ts +40 -0
- package/dist/server-postgresql/src/data-transformer.d.ts +58 -0
- package/dist/server-postgresql/src/databasePoolManager.d.ts +20 -0
- package/dist/server-postgresql/src/history/HistoryService.d.ts +71 -0
- package/dist/server-postgresql/src/history/ensure-history-table.d.ts +7 -0
- package/dist/server-postgresql/src/index.d.ts +13 -0
- package/dist/server-postgresql/src/interfaces.d.ts +18 -0
- package/dist/server-postgresql/src/schema/auth-schema.d.ts +868 -0
- package/dist/server-postgresql/src/schema/doctor-cli.d.ts +2 -0
- package/dist/server-postgresql/src/schema/doctor.d.ts +43 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema-logic.d.ts +2 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema.d.ts +1 -0
- package/dist/server-postgresql/src/schema/introspect-db-logic.d.ts +82 -0
- package/dist/server-postgresql/src/schema/introspect-db.d.ts +1 -0
- package/dist/server-postgresql/src/schema/test-schema.d.ts +24 -0
- package/dist/server-postgresql/src/services/BranchService.d.ts +47 -0
- package/dist/server-postgresql/src/services/EntityFetchService.d.ts +209 -0
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +41 -0
- package/dist/server-postgresql/src/services/RelationService.d.ts +98 -0
- package/dist/server-postgresql/src/services/entity-helpers.d.ts +38 -0
- package/dist/server-postgresql/src/services/entityService.d.ts +104 -0
- package/dist/server-postgresql/src/services/index.d.ts +4 -0
- package/dist/server-postgresql/src/services/realtimeService.d.ts +188 -0
- package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +116 -0
- package/dist/server-postgresql/src/websocket.d.ts +5 -0
- package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
- package/dist/types/src/controllers/auth.d.ts +119 -0
- package/dist/types/src/controllers/client.d.ts +170 -0
- package/dist/types/src/controllers/collection_registry.d.ts +45 -0
- package/dist/types/src/controllers/customization_controller.d.ts +60 -0
- package/dist/types/src/controllers/data.d.ts +168 -0
- package/dist/types/src/controllers/data_driver.d.ts +160 -0
- package/dist/types/src/controllers/database_admin.d.ts +11 -0
- package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
- package/dist/types/src/controllers/effective_role.d.ts +4 -0
- package/dist/types/src/controllers/email.d.ts +34 -0
- package/dist/types/src/controllers/index.d.ts +18 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
- package/dist/types/src/controllers/navigation.d.ts +213 -0
- package/dist/types/src/controllers/registry.d.ts +54 -0
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
- package/dist/types/src/controllers/snackbar.d.ts +24 -0
- package/dist/types/src/controllers/storage.d.ts +171 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/rebase_context.d.ts +105 -0
- package/dist/types/src/types/backend.d.ts +536 -0
- package/dist/types/src/types/builders.d.ts +15 -0
- package/dist/types/src/types/chips.d.ts +5 -0
- package/dist/types/src/types/collections.d.ts +856 -0
- package/dist/types/src/types/cron.d.ts +102 -0
- package/dist/types/src/types/data_source.d.ts +64 -0
- package/dist/types/src/types/entities.d.ts +145 -0
- package/dist/types/src/types/entity_actions.d.ts +98 -0
- package/dist/types/src/types/entity_callbacks.d.ts +173 -0
- package/dist/types/src/types/entity_link_builder.d.ts +7 -0
- package/dist/types/src/types/entity_overrides.d.ts +10 -0
- package/dist/types/src/types/entity_views.d.ts +61 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/index.d.ts +23 -0
- package/dist/types/src/types/locales.d.ts +4 -0
- package/dist/types/src/types/modify_collections.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +279 -0
- package/dist/types/src/types/properties.d.ts +1176 -0
- package/dist/types/src/types/property_config.d.ts +70 -0
- package/dist/types/src/types/relations.d.ts +336 -0
- package/dist/types/src/types/slots.d.ts +252 -0
- package/dist/types/src/types/translations.d.ts +870 -0
- package/dist/types/src/types/user_management_delegate.d.ts +121 -0
- package/dist/types/src/types/websockets.d.ts +78 -0
- package/dist/types/src/users/index.d.ts +2 -0
- package/dist/types/src/users/roles.d.ts +22 -0
- package/dist/types/src/users/user.d.ts +46 -0
- package/drizzle-test/0000_woozy_junta.sql +6 -0
- package/drizzle-test/0001_youthful_arachne.sql +1 -0
- package/drizzle-test/0002_lively_dragon_lord.sql +2 -0
- package/drizzle-test/0003_mean_king_cobra.sql +2 -0
- package/drizzle-test/meta/0000_snapshot.json +47 -0
- package/drizzle-test/meta/0001_snapshot.json +48 -0
- package/drizzle-test/meta/0002_snapshot.json +38 -0
- package/drizzle-test/meta/0003_snapshot.json +48 -0
- package/drizzle-test/meta/_journal.json +34 -0
- package/drizzle-test-out/0000_tan_trauma.sql +6 -0
- package/drizzle-test-out/0001_rapid_drax.sql +1 -0
- package/drizzle-test-out/meta/0000_snapshot.json +44 -0
- package/drizzle-test-out/meta/0001_snapshot.json +54 -0
- package/drizzle-test-out/meta/_journal.json +20 -0
- package/drizzle.test.config.ts +10 -0
- package/jest-all.log +3128 -0
- package/jest.log +49 -0
- package/package.json +92 -0
- package/scratch.ts +41 -0
- package/src/PostgresBackendDriver.ts +1008 -0
- package/src/PostgresBootstrapper.ts +231 -0
- package/src/auth/ensure-tables.ts +381 -0
- package/src/auth/services.ts +799 -0
- package/src/cli.ts +648 -0
- package/src/collections/PostgresCollectionRegistry.ts +96 -0
- package/src/connection.ts +84 -0
- package/src/data-transformer.ts +608 -0
- package/src/databasePoolManager.ts +85 -0
- package/src/history/HistoryService.ts +248 -0
- package/src/history/ensure-history-table.ts +45 -0
- package/src/index.ts +13 -0
- package/src/interfaces.ts +60 -0
- package/src/schema/auth-schema.ts +169 -0
- package/src/schema/doctor-cli.ts +47 -0
- package/src/schema/doctor.ts +595 -0
- package/src/schema/generate-drizzle-schema-logic.ts +765 -0
- package/src/schema/generate-drizzle-schema.ts +151 -0
- package/src/schema/introspect-db-logic.ts +542 -0
- package/src/schema/introspect-db.ts +211 -0
- package/src/schema/test-schema.ts +11 -0
- package/src/services/BranchService.ts +237 -0
- package/src/services/EntityFetchService.ts +1576 -0
- package/src/services/EntityPersistService.ts +349 -0
- package/src/services/RelationService.ts +1274 -0
- package/src/services/entity-helpers.ts +147 -0
- package/src/services/entityService.ts +211 -0
- package/src/services/index.ts +13 -0
- package/src/services/realtimeService.ts +1034 -0
- package/src/utils/drizzle-conditions.ts +1000 -0
- package/src/websocket.ts +518 -0
- package/test/auth-services.test.ts +661 -0
- package/test/batch-many-to-many-regression.test.ts +573 -0
- package/test/branchService.test.ts +367 -0
- package/test/data-transformer-hardening.test.ts +417 -0
- package/test/data-transformer.test.ts +175 -0
- package/test/doctor.test.ts +182 -0
- package/test/drizzle-conditions.test.ts +895 -0
- package/test/entityService.errors.test.ts +367 -0
- package/test/entityService.relations.test.ts +1008 -0
- package/test/entityService.subcollection-search.test.ts +566 -0
- package/test/entityService.test.ts +1035 -0
- package/test/generate-drizzle-schema.test.ts +988 -0
- package/test/historyService.test.ts +141 -0
- package/test/introspect-db-generation.test.ts +436 -0
- package/test/introspect-db-utils.test.ts +389 -0
- package/test/n-plus-one-regression.test.ts +314 -0
- package/test/postgresDataDriver.test.ts +648 -0
- package/test/realtimeService.test.ts +307 -0
- package/test/relation-pipeline-gaps.test.ts +637 -0
- package/test/relations.test.ts +1115 -0
- package/test/unmapped-tables-safety.test.ts +345 -0
- package/test-drizzle-bug.ts +18 -0
- package/test-drizzle-out/0000_cultured_freak.sql +7 -0
- package/test-drizzle-out/0001_tiresome_professor_monster.sql +1 -0
- package/test-drizzle-out/meta/0000_snapshot.json +55 -0
- package/test-drizzle-out/meta/0001_snapshot.json +63 -0
- package/test-drizzle-out/meta/_journal.json +20 -0
- package/test-drizzle-prompt.sh +2 -0
- package/test-policy-prompt.sh +3 -0
- package/test-programmatic.ts +30 -0
- package/test-programmatic2.ts +59 -0
- package/test-schema-no-policies.ts +12 -0
- package/test_drizzle_mock.js +3 -0
- package/test_find_changed.mjs +32 -0
- package/test_hash.js +14 -0
- package/test_output.txt +3145 -0
- package/tsconfig.json +49 -0
- package/tsconfig.prod.json +20 -0
- package/vite.config.ts +82 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { CollectionRegistry } from "@rebasepro/common";
|
|
2
|
+
import { type CollectionWithRelations, type EntityCollection, type Relation, getDataSourceCapabilities } from "@rebasepro/types";
|
|
3
|
+
import { PgEnum, PgTable } from "drizzle-orm/pg-core";
|
|
4
|
+
import { Relations } from "drizzle-orm";
|
|
5
|
+
import { CollectionRegistryInterface } from "../interfaces";
|
|
6
|
+
import { getTableName } from "@rebasepro/common";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* PostgreSQL-specific collection registry.
|
|
10
|
+
* Extends the base CollectionRegistry with support for Drizzle ORM tables, enums, and relations.
|
|
11
|
+
*
|
|
12
|
+
* Satisfies CollectionRegistryInterface through inheritance from CollectionRegistry.
|
|
13
|
+
*/
|
|
14
|
+
export class PostgresCollectionRegistry extends CollectionRegistry implements CollectionRegistryInterface {
|
|
15
|
+
|
|
16
|
+
private tables = new Map<string, PgTable>();
|
|
17
|
+
private enums = new Map<string, PgEnum<[string, ...string[]]>>();
|
|
18
|
+
private relations = new Map<string, Relations>();
|
|
19
|
+
|
|
20
|
+
registerTable(table: PgTable, tableName: string) {
|
|
21
|
+
this.tables.set(tableName, table);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getTable(tableName: string): PgTable | undefined {
|
|
25
|
+
return this.tables.get(tableName);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a specific collection has a registered table
|
|
30
|
+
*/
|
|
31
|
+
hasTableForCollection(tableName: string): boolean {
|
|
32
|
+
return this.tables.has(tableName);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Finds collections assigned to a specific driver that do not have a registered table.
|
|
37
|
+
*/
|
|
38
|
+
getCollectionsWithoutTables(driverId = "(default)"): EntityCollection[] {
|
|
39
|
+
const collections = this.getCollections().filter(
|
|
40
|
+
c => c.driver === driverId || (!c.driver && driverId === "(default)")
|
|
41
|
+
);
|
|
42
|
+
return collections.filter(c => !this.tables.has(getTableName(c)));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
registerEnums(enums: Record<string, PgEnum<[string, ...string[]]>>) {
|
|
46
|
+
Object.entries(enums).forEach(([name, value]) => this.enums.set(name, value));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
registerRelations(relations: Record<string, Relations>) {
|
|
50
|
+
Object.entries(relations).forEach(([name, value]) => this.relations.set(name, value));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getEnum(name: string): PgEnum<[string, ...string[]]> | undefined {
|
|
54
|
+
return this.enums.get(name);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getRelation(name: string): Relations | undefined {
|
|
58
|
+
return this.relations.get(name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getAllEnums(): Record<string, PgEnum<[string, ...string[]]>> {
|
|
62
|
+
return Object.fromEntries(this.enums.entries());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getAllRelations(): Record<string, Relations> {
|
|
66
|
+
return Object.fromEntries(this.relations.entries());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the merged schema object (tables + relations) for use with Drizzle's
|
|
71
|
+
* relational query API (`db.query`).
|
|
72
|
+
*/
|
|
73
|
+
getMergedSchema(): Record<string, unknown> {
|
|
74
|
+
const result: Record<string, unknown> = {};
|
|
75
|
+
for (const [name, table] of this.tables.entries()) {
|
|
76
|
+
result[name] = table;
|
|
77
|
+
}
|
|
78
|
+
for (const [name, relation] of this.relations.entries()) {
|
|
79
|
+
result[name] = relation;
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get the available Drizzle relation keys for a given collection path.
|
|
86
|
+
* Maps from the collection's relation property names to the Drizzle relation names
|
|
87
|
+
* defined in the schema.
|
|
88
|
+
*/
|
|
89
|
+
getRelationKeysForCollection(collectionPath: string): string[] {
|
|
90
|
+
const collection = this.getCollectionByPath(collectionPath);
|
|
91
|
+
if (!collection || !getDataSourceCapabilities(collection.driver).supportsRelations || !(collection as CollectionWithRelations).relations) return [];
|
|
92
|
+
return (collection as CollectionWithRelations).relations!.map((r: Relation) => r.relationName || r.localKey || "").filter(Boolean);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Pool, PoolConfig } from "pg";
|
|
2
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the Postgres connection pool.
|
|
6
|
+
*
|
|
7
|
+
* Sensible defaults are provided for production Cloud Run / single-instance
|
|
8
|
+
* deployments. Override via environment variables or explicit config.
|
|
9
|
+
*/
|
|
10
|
+
export interface PostgresPoolConfig {
|
|
11
|
+
/** Maximum number of connections in the pool (default: 20) */
|
|
12
|
+
max?: number;
|
|
13
|
+
/** Close idle connections after this many ms (default: 30 000) */
|
|
14
|
+
idleTimeoutMillis?: number;
|
|
15
|
+
/** Abort connection attempts after this many ms (default: 10 000) */
|
|
16
|
+
connectionTimeoutMillis?: number;
|
|
17
|
+
/** Per-query timeout in ms (default: 30 000) */
|
|
18
|
+
queryTimeout?: number;
|
|
19
|
+
/** Per-statement timeout in ms (default: 30 000) */
|
|
20
|
+
statementTimeout?: number;
|
|
21
|
+
/** Enable TCP keep-alive (default: true) */
|
|
22
|
+
keepAlive?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DEFAULT_POOL: Required<PostgresPoolConfig> = {
|
|
26
|
+
max: 20,
|
|
27
|
+
idleTimeoutMillis: 30_000,
|
|
28
|
+
connectionTimeoutMillis: 10_000,
|
|
29
|
+
queryTimeout: 30_000,
|
|
30
|
+
statementTimeout: 30_000,
|
|
31
|
+
keepAlive: true
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create a Drizzle-backed Postgres connection with a production-grade
|
|
36
|
+
* connection pool.
|
|
37
|
+
*
|
|
38
|
+
* @param connectionString Postgres connection URL
|
|
39
|
+
* @param schema Optional Drizzle schema for the relational API
|
|
40
|
+
* @param poolConfig Optional pool tuning (merged over defaults)
|
|
41
|
+
*
|
|
42
|
+
* @returns `{ db, pool, connectionString }` — the `pool` is exposed so
|
|
43
|
+
* callers can register shutdown hooks (`pool.end()`) or monitor
|
|
44
|
+
* pool metrics.
|
|
45
|
+
*/
|
|
46
|
+
export function createPostgresDatabaseConnection(
|
|
47
|
+
connectionString: string,
|
|
48
|
+
schema?: Record<string, unknown>,
|
|
49
|
+
poolConfig?: PostgresPoolConfig
|
|
50
|
+
) {
|
|
51
|
+
const opts = { ...DEFAULT_POOL,
|
|
52
|
+
...poolConfig };
|
|
53
|
+
|
|
54
|
+
const pgPoolConfig: PoolConfig = {
|
|
55
|
+
connectionString,
|
|
56
|
+
max: opts.max,
|
|
57
|
+
idleTimeoutMillis: opts.idleTimeoutMillis,
|
|
58
|
+
connectionTimeoutMillis: opts.connectionTimeoutMillis,
|
|
59
|
+
query_timeout: opts.queryTimeout,
|
|
60
|
+
statement_timeout: opts.statementTimeout,
|
|
61
|
+
keepAlive: opts.keepAlive,
|
|
62
|
+
keepAliveInitialDelayMillis: 0
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const pool = new Pool(pgPoolConfig);
|
|
66
|
+
|
|
67
|
+
// ── Pool event logging ────────────────────────────────────────────────
|
|
68
|
+
// Uses console.* because the structured logger lives in server-core
|
|
69
|
+
// (a separate package). The caller can replace these with the structured
|
|
70
|
+
// logger if desired via pool.on() after creation.
|
|
71
|
+
pool.on("error", (err) => {
|
|
72
|
+
console.error("[pg-pool] Unexpected pool error:", err.message);
|
|
73
|
+
if (err.message.includes("ETIMEDOUT")) {
|
|
74
|
+
console.warn("[pg-pool] Connection timeout detected — pool will auto-retry");
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Create drizzle instance — pass schema when available to enable db.query relational API
|
|
79
|
+
const db = schema ? drizzle(pool, { schema }) : drizzle(pool);
|
|
80
|
+
|
|
81
|
+
return { db,
|
|
82
|
+
pool,
|
|
83
|
+
connectionString };
|
|
84
|
+
}
|