@rebasepro/server-postgresql 0.0.1-canary.4d4fb3e → 0.0.1-canary.ca2cb6e
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/dist/common/src/collections/CollectionRegistry.d.ts +8 -0
- package/dist/common/src/util/entities.d.ts +22 -0
- package/dist/common/src/util/relations.d.ts +14 -4
- package/dist/common/src/util/resolutions.d.ts +1 -1
- package/dist/index.es.js +1254 -591
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1254 -591
- package/dist/index.umd.js.map +1 -1
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +17 -29
- package/dist/server-postgresql/src/auth/services.d.ts +7 -3
- package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +1 -1
- package/dist/server-postgresql/src/connection.d.ts +34 -1
- package/dist/server-postgresql/src/data-transformer.d.ts +26 -4
- package/dist/server-postgresql/src/databasePoolManager.d.ts +2 -2
- package/dist/server-postgresql/src/schema/auth-schema.d.ts +139 -38
- 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 +1 -1
- package/dist/server-postgresql/src/schema/test-schema.d.ts +24 -0
- package/dist/server-postgresql/src/services/EntityFetchService.d.ts +22 -8
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +1 -1
- package/dist/server-postgresql/src/services/RelationService.d.ts +11 -5
- package/dist/server-postgresql/src/services/entity-helpers.d.ts +16 -2
- package/dist/server-postgresql/src/services/entityService.d.ts +8 -6
- package/dist/server-postgresql/src/services/realtimeService.d.ts +2 -0
- package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +2 -2
- package/dist/types/src/controllers/auth.d.ts +2 -0
- package/dist/types/src/controllers/client.d.ts +119 -7
- package/dist/types/src/controllers/collection_registry.d.ts +4 -3
- package/dist/types/src/controllers/customization_controller.d.ts +7 -1
- package/dist/types/src/controllers/data.d.ts +34 -7
- package/dist/types/src/controllers/data_driver.d.ts +20 -28
- package/dist/types/src/controllers/database_admin.d.ts +2 -2
- package/dist/types/src/controllers/email.d.ts +34 -0
- package/dist/types/src/controllers/index.d.ts +1 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +4 -4
- package/dist/types/src/controllers/navigation.d.ts +5 -5
- package/dist/types/src/controllers/registry.d.ts +6 -3
- package/dist/types/src/controllers/side_entity_controller.d.ts +7 -6
- package/dist/types/src/controllers/storage.d.ts +24 -26
- package/dist/types/src/rebase_context.d.ts +8 -4
- package/dist/types/src/types/backend.d.ts +4 -1
- package/dist/types/src/types/builders.d.ts +5 -4
- package/dist/types/src/types/chips.d.ts +1 -1
- package/dist/types/src/types/collections.d.ts +169 -125
- package/dist/types/src/types/cron.d.ts +102 -0
- package/dist/types/src/types/data_source.d.ts +1 -1
- package/dist/types/src/types/entity_actions.d.ts +8 -8
- package/dist/types/src/types/entity_callbacks.d.ts +15 -15
- package/dist/types/src/types/entity_link_builder.d.ts +1 -1
- package/dist/types/src/types/entity_overrides.d.ts +2 -1
- package/dist/types/src/types/entity_views.d.ts +8 -8
- package/dist/types/src/types/export_import.d.ts +3 -3
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/plugins.d.ts +72 -18
- package/dist/types/src/types/properties.d.ts +118 -33
- package/dist/types/src/types/relations.d.ts +1 -1
- package/dist/types/src/types/slots.d.ts +30 -6
- package/dist/types/src/types/translations.d.ts +44 -0
- package/dist/types/src/types/user_management_delegate.d.ts +1 -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/package.json +88 -89
- package/scratch.ts +41 -0
- package/src/PostgresBackendDriver.ts +63 -79
- package/src/PostgresBootstrapper.ts +7 -8
- package/src/auth/ensure-tables.ts +158 -86
- package/src/auth/services.ts +109 -50
- package/src/cli.ts +259 -16
- package/src/collections/PostgresCollectionRegistry.ts +6 -6
- package/src/connection.ts +70 -48
- package/src/data-transformer.ts +155 -116
- package/src/databasePoolManager.ts +6 -5
- package/src/history/HistoryService.ts +3 -12
- package/src/interfaces.ts +3 -3
- package/src/schema/auth-schema.ts +26 -3
- package/src/schema/doctor-cli.ts +47 -0
- package/src/schema/doctor.ts +595 -0
- package/src/schema/generate-drizzle-schema-logic.ts +204 -57
- package/src/schema/generate-drizzle-schema.ts +6 -6
- package/src/schema/test-schema.ts +11 -0
- package/src/services/BranchService.ts +5 -5
- package/src/services/EntityFetchService.ts +317 -188
- package/src/services/EntityPersistService.ts +15 -17
- package/src/services/RelationService.ts +299 -37
- package/src/services/entity-helpers.ts +39 -13
- package/src/services/entityService.ts +11 -9
- package/src/services/realtimeService.ts +58 -29
- package/src/utils/drizzle-conditions.ts +25 -24
- package/src/websocket.ts +52 -21
- package/test/auth-services.test.ts +131 -39
- package/test/batch-many-to-many-regression.test.ts +573 -0
- package/test/branchService.test.ts +22 -12
- 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/entityService.errors.test.ts +31 -16
- package/test/entityService.relations.test.ts +155 -59
- package/test/entityService.subcollection-search.test.ts +107 -57
- package/test/entityService.test.ts +105 -47
- package/test/generate-drizzle-schema.test.ts +262 -69
- package/test/historyService.test.ts +31 -16
- package/test/n-plus-one-regression.test.ts +314 -0
- package/test/postgresDataDriver.test.ts +260 -168
- package/test/realtimeService.test.ts +70 -39
- package/test/relation-pipeline-gaps.test.ts +637 -0
- package/test/relations.test.ts +492 -39
- 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 +2 -2
- package/test_find_changed.mjs +3 -1
- package/test_hash.js +14 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +5 -5
|
@@ -76,37 +76,40 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
76
76
|
this.branchService = new BranchService(db, poolManager);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Typed admin capabilities (SQLAdmin + SchemaAdmin + BranchAdmin).
|
|
83
|
+
* Implemented as a getter so method references are resolved at call-time,
|
|
84
|
+
* allowing test spies applied after construction to take effect.
|
|
85
|
+
*/
|
|
86
|
+
get admin(): DatabaseAdmin {
|
|
87
|
+
return {
|
|
88
|
+
executeSql: (...args: Parameters<NonNullable<DatabaseAdmin["executeSql"]>>) => this.executeSql(...args),
|
|
89
|
+
fetchAvailableDatabases: () => this.fetchAvailableDatabases(),
|
|
90
|
+
fetchAvailableRoles: () => this.fetchAvailableRoles(),
|
|
91
|
+
fetchCurrentDatabase: () => this.fetchCurrentDatabase(),
|
|
92
|
+
fetchUnmappedTables: (...args: Parameters<NonNullable<DatabaseAdmin["fetchUnmappedTables"]>>) => this.fetchUnmappedTables(...args),
|
|
93
|
+
fetchTableMetadata: (...args: Parameters<NonNullable<DatabaseAdmin["fetchTableMetadata"]>>) => this.fetchTableMetadata(...args),
|
|
88
94
|
// Branch operations (only available when poolManager is configured)
|
|
89
95
|
...(this.branchService ? {
|
|
90
96
|
createBranch: this.branchService.createBranch.bind(this.branchService),
|
|
91
97
|
deleteBranch: this.branchService.deleteBranch.bind(this.branchService),
|
|
92
98
|
listBranches: this.branchService.listBranches.bind(this.branchService),
|
|
93
|
-
getBranchInfo: this.branchService.getBranchInfo.bind(this.branchService)
|
|
94
|
-
} : {})
|
|
99
|
+
getBranchInfo: this.branchService.getBranchInfo.bind(this.branchService)
|
|
100
|
+
} : {})
|
|
95
101
|
};
|
|
96
102
|
}
|
|
97
103
|
|
|
98
|
-
/**
|
|
99
|
-
* Typed admin capabilities (SQLAdmin + SchemaAdmin + BranchAdmin).
|
|
100
|
-
*/
|
|
101
|
-
admin: DatabaseAdmin;
|
|
102
|
-
|
|
103
|
-
|
|
104
104
|
|
|
105
|
-
private resolveCollectionCallbacks<M extends Record<string,
|
|
106
|
-
if (!collection && !path) return { collection: undefined,
|
|
105
|
+
private resolveCollectionCallbacks<M extends Record<string, unknown>>(collection: EntityCollection<M> | undefined, path: string) {
|
|
106
|
+
if (!collection && !path) return { collection: undefined,
|
|
107
|
+
callbacks: undefined,
|
|
108
|
+
propertyCallbacks: undefined };
|
|
107
109
|
const registryCollection = this.registry.getCollectionByPath(path);
|
|
108
110
|
const resolvedCollection = registryCollection
|
|
109
|
-
? { ...collection,
|
|
111
|
+
? { ...collection,
|
|
112
|
+
...registryCollection } as EntityCollection<M>
|
|
110
113
|
: collection as EntityCollection<M>;
|
|
111
114
|
|
|
112
115
|
const callbacks = resolvedCollection?.callbacks;
|
|
@@ -122,11 +125,12 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
async fetchCollection<M extends Record<string,
|
|
128
|
+
async fetchCollection<M extends Record<string, unknown>>({
|
|
126
129
|
path,
|
|
127
130
|
collection,
|
|
128
131
|
filter,
|
|
129
132
|
limit,
|
|
133
|
+
offset,
|
|
130
134
|
startAfter,
|
|
131
135
|
orderBy,
|
|
132
136
|
searchString,
|
|
@@ -138,6 +142,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
138
142
|
orderBy,
|
|
139
143
|
order,
|
|
140
144
|
limit,
|
|
145
|
+
offset,
|
|
141
146
|
startAfter: startAfter as Record<string, unknown> | undefined,
|
|
142
147
|
databaseId: collection?.databaseId,
|
|
143
148
|
searchString
|
|
@@ -167,7 +172,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
167
172
|
path,
|
|
168
173
|
entity: fetched,
|
|
169
174
|
context: contextForCallback
|
|
170
|
-
}) ?? fetched;
|
|
175
|
+
}) as Entity<M> ?? fetched;
|
|
171
176
|
}
|
|
172
177
|
return fetched;
|
|
173
178
|
}));
|
|
@@ -176,11 +181,12 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
176
181
|
return entities;
|
|
177
182
|
}
|
|
178
183
|
|
|
179
|
-
listenCollection<M extends Record<string,
|
|
184
|
+
listenCollection<M extends Record<string, unknown>>({
|
|
180
185
|
path,
|
|
181
186
|
collection,
|
|
182
187
|
filter,
|
|
183
188
|
limit,
|
|
189
|
+
offset,
|
|
184
190
|
startAfter,
|
|
185
191
|
orderBy,
|
|
186
192
|
searchString,
|
|
@@ -206,6 +212,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
206
212
|
orderBy,
|
|
207
213
|
order,
|
|
208
214
|
limit,
|
|
215
|
+
offset,
|
|
209
216
|
startAfter: startAfter as Record<string, unknown> | undefined,
|
|
210
217
|
databaseId: collection?.databaseId,
|
|
211
218
|
searchString
|
|
@@ -221,6 +228,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
221
228
|
collection,
|
|
222
229
|
filter,
|
|
223
230
|
limit,
|
|
231
|
+
offset,
|
|
224
232
|
startAfter,
|
|
225
233
|
orderBy,
|
|
226
234
|
searchString,
|
|
@@ -237,7 +245,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
237
245
|
};
|
|
238
246
|
}
|
|
239
247
|
|
|
240
|
-
async fetchEntity<M extends Record<string,
|
|
248
|
+
async fetchEntity<M extends Record<string, unknown>>({
|
|
241
249
|
path,
|
|
242
250
|
entityId,
|
|
243
251
|
databaseId,
|
|
@@ -271,14 +279,14 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
271
279
|
path,
|
|
272
280
|
entity,
|
|
273
281
|
context: contextForCallback
|
|
274
|
-
}) ?? entity;
|
|
282
|
+
}) as Entity<M> ?? entity;
|
|
275
283
|
}
|
|
276
284
|
}
|
|
277
285
|
|
|
278
286
|
return entity;
|
|
279
287
|
}
|
|
280
288
|
|
|
281
|
-
listenEntity<M extends Record<string,
|
|
289
|
+
listenEntity<M extends Record<string, unknown>>({
|
|
282
290
|
path,
|
|
283
291
|
entityId,
|
|
284
292
|
collection,
|
|
@@ -323,7 +331,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
323
331
|
};
|
|
324
332
|
}
|
|
325
333
|
|
|
326
|
-
async saveEntity<M extends Record<string,
|
|
334
|
+
async saveEntity<M extends Record<string, unknown>>({
|
|
327
335
|
path,
|
|
328
336
|
entityId,
|
|
329
337
|
values,
|
|
@@ -401,7 +409,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
401
409
|
path,
|
|
402
410
|
entity: savedEntity,
|
|
403
411
|
context: contextForCallback
|
|
404
|
-
}) ?? savedEntity;
|
|
412
|
+
}) as Entity<M> ?? savedEntity;
|
|
405
413
|
}
|
|
406
414
|
}
|
|
407
415
|
|
|
@@ -411,7 +419,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
411
419
|
collection: resolvedCollection as EntityCollection<M>,
|
|
412
420
|
path,
|
|
413
421
|
entityId: savedEntity.id,
|
|
414
|
-
values:
|
|
422
|
+
values: savedEntity.values,
|
|
415
423
|
previousValues: previousValuesForHistory,
|
|
416
424
|
status,
|
|
417
425
|
context: contextForCallback
|
|
@@ -422,7 +430,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
422
430
|
collection: resolvedCollection as EntityCollection<M>,
|
|
423
431
|
path,
|
|
424
432
|
entityId: savedEntity.id,
|
|
425
|
-
values:
|
|
433
|
+
values: savedEntity.values,
|
|
426
434
|
previousValues: previousValuesForHistory,
|
|
427
435
|
status,
|
|
428
436
|
context: contextForCallback
|
|
@@ -489,7 +497,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
489
497
|
}
|
|
490
498
|
}
|
|
491
499
|
|
|
492
|
-
async deleteEntity<M extends Record<string,
|
|
500
|
+
async deleteEntity<M extends Record<string, unknown>>({
|
|
493
501
|
entity,
|
|
494
502
|
collection
|
|
495
503
|
}: DeleteEntityProps<M>): Promise<void> {
|
|
@@ -598,14 +606,16 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
598
606
|
}
|
|
599
607
|
|
|
600
608
|
|
|
601
|
-
async countEntities<M extends Record<string,
|
|
609
|
+
async countEntities<M extends Record<string, unknown>>({
|
|
602
610
|
path,
|
|
603
611
|
collection,
|
|
604
|
-
filter
|
|
612
|
+
filter,
|
|
613
|
+
searchString
|
|
605
614
|
}: FetchCollectionProps<M>): Promise<number> {
|
|
606
615
|
return this.entityService.countEntities(
|
|
607
616
|
path,
|
|
608
|
-
{ filter
|
|
617
|
+
{ filter,
|
|
618
|
+
searchString }
|
|
609
619
|
);
|
|
610
620
|
}
|
|
611
621
|
|
|
@@ -676,7 +686,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
676
686
|
}
|
|
677
687
|
|
|
678
688
|
async fetchAvailableRoles(): Promise<string[]> {
|
|
679
|
-
const result = await this.executeSql(
|
|
689
|
+
const result = await this.executeSql("SELECT rolname FROM pg_roles;");
|
|
680
690
|
return result.map((r: Record<string, unknown>) => r.rolname as string);
|
|
681
691
|
}
|
|
682
692
|
|
|
@@ -752,7 +762,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
752
762
|
return filteredTables.filter((name: string) => !mappedSet.has(name.toLowerCase()));
|
|
753
763
|
}
|
|
754
764
|
|
|
755
|
-
|
|
765
|
+
|
|
756
766
|
/**
|
|
757
767
|
* Fetch metadata for a given table from information_schema (columns, policies, constraints).
|
|
758
768
|
*/
|
|
@@ -890,17 +900,17 @@ export class AuthenticatedPostgresBackendDriver implements DataDriver {
|
|
|
890
900
|
operation: (delegate: PostgresBackendDriver) => Promise<T>
|
|
891
901
|
): Promise<T> {
|
|
892
902
|
const pendingNotifications: PostgresBackendDriver["_pendingNotifications"] = [];
|
|
893
|
-
|
|
903
|
+
|
|
894
904
|
const result = await this.delegate.db.transaction(async (tx) => {
|
|
895
905
|
let userId = this.user?.uid;
|
|
896
906
|
if (!userId) {
|
|
897
|
-
console.warn(
|
|
898
|
-
userId =
|
|
907
|
+
console.warn("[DataDriver] User ID (uid) is missing for authenticated delegate. Using 'anonymous'. User object:", this.user);
|
|
908
|
+
userId = "anonymous";
|
|
899
909
|
}
|
|
900
910
|
|
|
901
|
-
|
|
911
|
+
const userRoles = this.user?.roles ?? [];
|
|
902
912
|
if (!this.user?.roles) {
|
|
903
|
-
console.warn(
|
|
913
|
+
console.warn("[DataDriver] User roles are missing for authenticated delegate. Using empty array. User object:", this.user);
|
|
904
914
|
}
|
|
905
915
|
const normalizedRoles = userRoles.map((r: unknown) =>
|
|
906
916
|
typeof r === "string" ? r : (r as Record<string, unknown>)?.id ?? String(r)
|
|
@@ -911,12 +921,13 @@ export class AuthenticatedPostgresBackendDriver implements DataDriver {
|
|
|
911
921
|
SELECT
|
|
912
922
|
set_config('app.user_id', ${userId}, true),
|
|
913
923
|
set_config('app.user_roles', ${rolesString}, true),
|
|
914
|
-
set_config('app.jwt', ${JSON.stringify({ sub: userId,
|
|
924
|
+
set_config('app.jwt', ${JSON.stringify({ sub: userId,
|
|
925
|
+
roles: userRoles })}, true)
|
|
915
926
|
`);
|
|
916
927
|
|
|
917
928
|
const txEntityService = new EntityService(tx, this.delegate.registry);
|
|
918
929
|
const txDelegate = new PostgresBackendDriver(tx, this.delegate.realtimeService, this.delegate.registry, this.user, this.delegate.poolManager, this.delegate.historyService);
|
|
919
|
-
|
|
930
|
+
|
|
920
931
|
txDelegate.entityService = txEntityService;
|
|
921
932
|
txDelegate._deferNotifications = true;
|
|
922
933
|
txDelegate._pendingNotifications = pendingNotifications;
|
|
@@ -940,7 +951,7 @@ export class AuthenticatedPostgresBackendDriver implements DataDriver {
|
|
|
940
951
|
return result;
|
|
941
952
|
}
|
|
942
953
|
|
|
943
|
-
async fetchCollection<M extends Record<string,
|
|
954
|
+
async fetchCollection<M extends Record<string, unknown>>(props: FetchCollectionProps<M>): Promise<Entity<M>[]> {
|
|
944
955
|
return this.withTransaction((delegate) => delegate.fetchCollection(props));
|
|
945
956
|
}
|
|
946
957
|
|
|
@@ -949,7 +960,8 @@ export class AuthenticatedPostgresBackendDriver implements DataDriver {
|
|
|
949
960
|
* registered realtime subscription so RLS-aware polling can apply.
|
|
950
961
|
*/
|
|
951
962
|
private injectAuthContext(unsubscribe: () => void): () => void {
|
|
952
|
-
const authContext = { userId: this.user?.uid || "anonymous",
|
|
963
|
+
const authContext = { userId: this.user?.uid || "anonymous",
|
|
964
|
+
roles: this.user?.roles ?? [] };
|
|
953
965
|
const entries = Array.from(this.delegate.realtimeService.subscriptions.entries());
|
|
954
966
|
const lastEntry = entries[entries.length - 1];
|
|
955
967
|
const lastSub = lastEntry?.[1] as Record<string, unknown> | undefined;
|
|
@@ -959,23 +971,23 @@ export class AuthenticatedPostgresBackendDriver implements DataDriver {
|
|
|
959
971
|
return unsubscribe;
|
|
960
972
|
}
|
|
961
973
|
|
|
962
|
-
listenCollection<M extends Record<string,
|
|
974
|
+
listenCollection<M extends Record<string, unknown>>(props: ListenCollectionProps<M>): () => void {
|
|
963
975
|
return this.injectAuthContext(this.delegate.listenCollection(props));
|
|
964
976
|
}
|
|
965
977
|
|
|
966
|
-
async fetchEntity<M extends Record<string,
|
|
978
|
+
async fetchEntity<M extends Record<string, unknown>>(props: FetchEntityProps<M>): Promise<Entity<M> | undefined> {
|
|
967
979
|
return this.withTransaction((delegate) => delegate.fetchEntity(props));
|
|
968
980
|
}
|
|
969
981
|
|
|
970
|
-
listenEntity<M extends Record<string,
|
|
982
|
+
listenEntity<M extends Record<string, unknown>>(props: ListenEntityProps<M>): () => void {
|
|
971
983
|
return this.injectAuthContext(this.delegate.listenEntity(props));
|
|
972
984
|
}
|
|
973
985
|
|
|
974
|
-
async saveEntity<M extends Record<string,
|
|
986
|
+
async saveEntity<M extends Record<string, unknown>>(props: SaveEntityProps<M>): Promise<Entity<M>> {
|
|
975
987
|
return this.withTransaction((delegate) => delegate.saveEntity(props));
|
|
976
988
|
}
|
|
977
989
|
|
|
978
|
-
async deleteEntity<M extends Record<string,
|
|
990
|
+
async deleteEntity<M extends Record<string, unknown>>(props: DeleteEntityProps<M>): Promise<void> {
|
|
979
991
|
return this.withTransaction((delegate) => delegate.deleteEntity(props));
|
|
980
992
|
}
|
|
981
993
|
|
|
@@ -989,36 +1001,8 @@ export class AuthenticatedPostgresBackendDriver implements DataDriver {
|
|
|
989
1001
|
return this.withTransaction((delegate) => delegate.checkUniqueField(path, name, value, entityId, collection));
|
|
990
1002
|
}
|
|
991
1003
|
|
|
992
|
-
async countEntities<M extends Record<string,
|
|
1004
|
+
async countEntities<M extends Record<string, unknown>>(props: FetchCollectionProps<M>): Promise<number> {
|
|
993
1005
|
return this.withTransaction((delegate) => delegate.countEntities(props));
|
|
994
1006
|
}
|
|
995
1007
|
|
|
996
|
-
/**
|
|
997
|
-
* Intentionally delegates to the base delegate WITHOUT RLS wrapping.
|
|
998
|
-
* executeSql is an admin-only feature; access control should be enforced
|
|
999
|
-
* at the API route level, not via database-level RLS.
|
|
1000
|
-
*/
|
|
1001
|
-
async executeSql(sqlText: string, options?: { database?: string, role?: string }): Promise<Record<string, unknown>[]> {
|
|
1002
|
-
return this.delegate.executeSql(sqlText, options);
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
async fetchAvailableDatabases(): Promise<string[]> {
|
|
1006
|
-
return this.delegate.fetchAvailableDatabases();
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
async fetchAvailableRoles(): Promise<string[]> {
|
|
1010
|
-
return this.delegate.fetchAvailableRoles();
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
async fetchCurrentDatabase(): Promise<string | undefined> {
|
|
1014
|
-
return this.delegate.fetchCurrentDatabase();
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
async fetchUnmappedTables(mappedPaths?: string[]): Promise<string[]> {
|
|
1018
|
-
return this.delegate.fetchUnmappedTables(mappedPaths);
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
async fetchTableMetadata(tableName: string) {
|
|
1022
|
-
return this.delegate.fetchTableMetadata(tableName);
|
|
1023
|
-
}
|
|
1024
1008
|
}
|
|
@@ -26,7 +26,6 @@ import { RealtimeService } from "./services/realtimeService";
|
|
|
26
26
|
import { DatabasePoolManager } from "./databasePoolManager";
|
|
27
27
|
import { PostgresCollectionRegistry } from "./collections/PostgresCollectionRegistry";
|
|
28
28
|
import {
|
|
29
|
-
configureGoogleOAuth,
|
|
30
29
|
createAuthRoutes,
|
|
31
30
|
createAdminRoutes,
|
|
32
31
|
requireAuth,
|
|
@@ -87,6 +86,7 @@ export function createPostgresBootstrapper(pgConfig: PostgresDriverConfig): Back
|
|
|
87
86
|
const registry = new PostgresCollectionRegistry();
|
|
88
87
|
if (collections) {
|
|
89
88
|
registry.registerMultiple(collections);
|
|
89
|
+
console.log(`📋 [PostgresRegistry] Registered ${registry.getCollections().length} collections: [${registry.getCollections().map(c => c.slug).join(", ")}]`);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
// Register tables
|
|
@@ -159,7 +159,7 @@ export function createPostgresBootstrapper(pgConfig: PostgresDriverConfig): Back
|
|
|
159
159
|
driver,
|
|
160
160
|
realtimeProvider: realtimeService,
|
|
161
161
|
collectionRegistry: registry,
|
|
162
|
-
internals
|
|
162
|
+
internals
|
|
163
163
|
};
|
|
164
164
|
},
|
|
165
165
|
|
|
@@ -172,10 +172,6 @@ export function createPostgresBootstrapper(pgConfig: PostgresDriverConfig): Back
|
|
|
172
172
|
|
|
173
173
|
await ensureAuthTablesExist(db);
|
|
174
174
|
|
|
175
|
-
if (authConfig.google?.clientId) {
|
|
176
|
-
configureGoogleOAuth(authConfig.google.clientId);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
175
|
let emailService: EmailService | undefined;
|
|
180
176
|
if (authConfig.email) {
|
|
181
177
|
emailService = createEmailService(authConfig.email);
|
|
@@ -185,7 +181,10 @@ export function createPostgresBootstrapper(pgConfig: PostgresDriverConfig): Back
|
|
|
185
181
|
const roleService = new RoleService(db);
|
|
186
182
|
const authRepository = new PostgresAuthRepository(db);
|
|
187
183
|
|
|
188
|
-
return { userService,
|
|
184
|
+
return { userService,
|
|
185
|
+
roleService,
|
|
186
|
+
emailService,
|
|
187
|
+
authRepository };
|
|
189
188
|
},
|
|
190
189
|
|
|
191
190
|
async initializeHistory(config: unknown, driverResult: InitializedDriver): Promise<{ historyService: HistoryService } | undefined> {
|
|
@@ -196,7 +195,7 @@ export function createPostgresBootstrapper(pgConfig: PostgresDriverConfig): Back
|
|
|
196
195
|
const db = internals.db;
|
|
197
196
|
|
|
198
197
|
await ensureHistoryTableExists(db);
|
|
199
|
-
|
|
198
|
+
|
|
200
199
|
const retention = typeof historyConfig === "object" && historyConfig !== null ? (historyConfig as { retention?: number }).retention : undefined;
|
|
201
200
|
const historyService = new HistoryService(db, retention ? { ttlDays: retention } : undefined);
|
|
202
201
|
|