prostgles-server 4.2.618 → 4.2.620

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 (90) hide show
  1. package/debug/access-profile-source.patch +14 -0
  2. package/debug/client-profile-perf.cjs +17 -0
  3. package/debug/client-schema-test.log +10 -0
  4. package/debug/client-schema-types/DBGeneratedSchema.ts +57 -0
  5. package/debug/client-typecheck.ts +11 -0
  6. package/debug/profile-perf.cjs +26 -0
  7. package/debug/prostgles-types-4.0.282.tgz +0 -0
  8. package/debug/publish-schema-test.log +16 -0
  9. package/debug/run-client-schema.cjs +3 -0
  10. package/debug/run-publish-schema.cjs +3 -0
  11. package/debug/server-lib-tests.log +28 -0
  12. package/debug/types-pack.log +162 -0
  13. package/dist/DBSchemaBuilder/constants.d.ts +2 -0
  14. package/dist/DBSchemaBuilder/constants.d.ts.map +1 -0
  15. package/dist/DBSchemaBuilder/constants.js +5 -0
  16. package/dist/DBSchemaBuilder/constants.js.map +1 -0
  17. package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.d.ts +9 -0
  18. package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.d.ts.map +1 -0
  19. package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.js +77 -0
  20. package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.js.map +1 -0
  21. package/dist/DBSchemaBuilder/getColumnTypescriptDefinition.js +2 -2
  22. package/dist/DBSchemaBuilder/getDBGeneratedSchema.d.ts +3 -1
  23. package/dist/DBSchemaBuilder/getDBGeneratedSchema.d.ts.map +1 -1
  24. package/dist/DBSchemaBuilder/getDBGeneratedSchema.js +7 -5
  25. package/dist/DBSchemaBuilder/getDBGeneratedSchema.js.map +1 -1
  26. package/dist/DBSchemaBuilder/getPublishSchemas.d.ts +4 -0
  27. package/dist/DBSchemaBuilder/getPublishSchemas.d.ts.map +1 -0
  28. package/dist/DBSchemaBuilder/getPublishSchemas.js +34 -0
  29. package/dist/DBSchemaBuilder/getPublishSchemas.js.map +1 -0
  30. package/dist/DboBuilder/DboBuilder.d.ts +5 -8
  31. package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
  32. package/dist/DboBuilder/DboBuilder.js +11 -14
  33. package/dist/DboBuilder/DboBuilder.js.map +1 -1
  34. package/dist/Prostgles.d.ts +3 -2
  35. package/dist/Prostgles.d.ts.map +1 -1
  36. package/dist/Prostgles.js +9 -3
  37. package/dist/Prostgles.js.map +1 -1
  38. package/dist/PublishParser/PublishParser.d.ts +3 -2
  39. package/dist/PublishParser/PublishParser.d.ts.map +1 -1
  40. package/dist/PublishParser/PublishParser.js +16 -5
  41. package/dist/PublishParser/PublishParser.js.map +1 -1
  42. package/dist/PublishParser/getFileTableRules.d.ts +2 -2
  43. package/dist/PublishParser/getFileTableRules.d.ts.map +1 -1
  44. package/dist/PublishParser/getFileTableRules.js +2 -2
  45. package/dist/PublishParser/getFileTableRules.js.map +1 -1
  46. package/dist/PublishParser/getPublishedTableNames.d.ts +4 -0
  47. package/dist/PublishParser/getPublishedTableNames.d.ts.map +1 -0
  48. package/dist/PublishParser/getPublishedTableNames.js +23 -0
  49. package/dist/PublishParser/getPublishedTableNames.js.map +1 -0
  50. package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
  51. package/dist/PublishParser/getSchemaFromPublish.js +2 -13
  52. package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
  53. package/dist/PublishParser/publishTypesAndUtils.d.ts +7 -1
  54. package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
  55. package/dist/PublishParser/validatePublishProfiles.d.ts +7 -0
  56. package/dist/PublishParser/validatePublishProfiles.d.ts.map +1 -0
  57. package/dist/PublishParser/validatePublishProfiles.js +27 -0
  58. package/dist/PublishParser/validatePublishProfiles.js.map +1 -0
  59. package/dist/SchemaWatch/SchemaWatch.js +1 -1
  60. package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
  61. package/dist/index.d.ts +4 -2
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +3 -1
  64. package/dist/index.js.map +1 -1
  65. package/dist/initProstgles.d.ts +2 -2
  66. package/dist/initProstgles.d.ts.map +1 -1
  67. package/dist/initProstgles.js +2 -4
  68. package/dist/initProstgles.js.map +1 -1
  69. package/dist/updateConfiguration.d.ts.map +1 -1
  70. package/dist/updateConfiguration.js +6 -2
  71. package/dist/updateConfiguration.js.map +1 -1
  72. package/eslint.config.mjs +1 -1
  73. package/lib/DBSchemaBuilder/constants.ts +1 -0
  74. package/lib/DBSchemaBuilder/getClientDBGeneratedSchemas.ts +91 -0
  75. package/lib/DBSchemaBuilder/getColumnTypescriptDefinition.ts +2 -2
  76. package/lib/DBSchemaBuilder/getDBGeneratedSchema.ts +11 -4
  77. package/lib/DBSchemaBuilder/getPublishSchemas.ts +41 -0
  78. package/lib/DboBuilder/DboBuilder.ts +15 -22
  79. package/lib/Prostgles.ts +10 -4
  80. package/lib/PublishParser/PublishParser.ts +24 -4
  81. package/lib/PublishParser/getFileTableRules.ts +3 -2
  82. package/lib/PublishParser/getPublishedTableNames.ts +29 -0
  83. package/lib/PublishParser/getSchemaFromPublish.ts +2 -17
  84. package/lib/PublishParser/publishTypesAndUtils.ts +7 -0
  85. package/lib/PublishParser/validatePublishProfiles.ts +22 -0
  86. package/lib/SchemaWatch/SchemaWatch.ts +1 -1
  87. package/lib/index.ts +10 -11
  88. package/lib/initProstgles.ts +7 -19
  89. package/lib/updateConfiguration.ts +5 -1
  90. package/package.json +2 -2
@@ -35,6 +35,7 @@ import { prepareShortestJoinPaths } from "./joins/prepareShortestJoinPaths";
35
35
  import { cacheDBTypes, runSQL } from "./runSql/runSQL";
36
36
  import { getDetailedFieldInfo, type getDbTypes } from "./runSql/runSqlUtils";
37
37
  import { getTablesForSchemaPostgresSQL } from "./schema/getTablesForSchemaPostgresSQL";
38
+ import { getPublishSchemas } from "../DBSchemaBuilder/getPublishSchemas";
38
39
 
39
40
  export * from "./DboBuilderTypes";
40
41
  export * from "./dboBuilderUtils";
@@ -208,8 +209,8 @@ export class DboBuilder {
208
209
  return this.shortestJoinPaths;
209
210
  }
210
211
 
211
- prepareShortestJoinPaths = async () => {
212
- const { joins, shortestJoinPaths, joinGraph } = await prepareShortestJoinPaths(this);
212
+ prepareShortestJoinPaths = () => {
213
+ const { joins, shortestJoinPaths, joinGraph } = prepareShortestJoinPaths(this);
213
214
  this.joinGraph = joinGraph;
214
215
  this.joins = joins;
215
216
  this.shortestJoinPaths = shortestJoinPaths;
@@ -276,7 +277,7 @@ export class DboBuilder {
276
277
  this.prostgles.dbForSchema!,
277
278
  this.prostgles.opts.schemaFilter,
278
279
  );
279
- await this.prepareShortestJoinPaths();
280
+ this.prepareShortestJoinPaths();
280
281
 
281
282
  this.dbo = {};
282
283
  this.tablesOrViews.map((tov) => {
@@ -349,7 +350,7 @@ export class DboBuilder {
349
350
  }
350
351
  return this.tablesOrViews;
351
352
  };
352
- getTsDefinitions = <DDL extends string | undefined = undefined>({
353
+ getTsDefinitions = async ({
353
354
  excludeFunctions,
354
355
  extraTables = [],
355
356
  ddlWithRollback,
@@ -362,12 +363,13 @@ export class DboBuilder {
362
363
  * This is useful for generating an updated TypeScript schema after running a migration SQL file, for example.
363
364
  * Note that this will be run within a transaction that is rolled back, so it SHOULD not affect the actual database schema.
364
365
  */
365
- ddlWithRollback?: DDL;
366
- } = {}): DDL extends string ? Promise<{ tsSchema: string; tablesOrViews: TableSchema[] }>
367
- : { tsSchema: string; tablesOrViews: TableSchema[] } => {
366
+ ddlWithRollback?: string;
367
+ } = {}): Promise<{ tsSchema: string; tablesOrViews: TableSchema[] }> => {
368
+ const clientSchemas = this.publishParser && (await getPublishSchemas(this.publishParser));
368
369
  const getSchema = (tablesOrViews: TableSchema[]) => {
369
370
  const tableTsDefinitions = getDBGeneratedSchema({
370
371
  config: this.prostgles.mergedTableConfig.tableConfig,
372
+ clientSchemas,
371
373
  tablesOrViews: [
372
374
  ...tablesOrViews,
373
375
  ...extraTables.filter(
@@ -386,26 +388,17 @@ export class DboBuilder {
386
388
  return { tsSchema, tablesOrViews };
387
389
  };
388
390
  if (ddlWithRollback) {
389
- return new Promise<{ tsSchema: string; tablesOrViews: TableSchema[] }>((resolve, reject) => {
390
- getTablesForSchemaPostgresSQL(this, {
391
- schemaFilter: this.prostgles.opts.schemaFilter,
392
- ddlWithRollback,
393
- })
394
- .then((res) => {
395
- const tablesOrViews = res.result;
396
- resolve(getSchema(tablesOrViews));
397
- })
398
- .catch(reject);
399
- }) as DDL extends string ? Promise<{ tsSchema: string; tablesOrViews: TableSchema[] }>
400
- : { tsSchema: string; tablesOrViews: TableSchema[] };
391
+ const { result } = await getTablesForSchemaPostgresSQL(this, {
392
+ schemaFilter: this.prostgles.opts.schemaFilter,
393
+ ddlWithRollback,
394
+ });
395
+ return getSchema(result);
401
396
  }
402
397
  const tablesOrViews = this.tablesOrViews;
403
398
  if (!tablesOrViews) {
404
399
  throw new Error("Unexpected error: tablesOrViews is undefined");
405
400
  }
406
- return getSchema(tablesOrViews) as DDL extends string ?
407
- Promise<{ tsSchema: string; tablesOrViews: TableSchema[] }>
408
- : { tsSchema: string; tablesOrViews: TableSchema[] };
401
+ return getSchema(tablesOrViews);
409
402
  };
410
403
 
411
404
  getShortestJoinPath = (
package/lib/Prostgles.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { DB_GENERATED_SCHEMA_NAME } from "./DBSchemaBuilder/constants";
1
2
  import type pgPromise from "pg-promise";
2
3
  import { AuthHandler } from "./Auth/AuthHandler";
3
4
  import type { SessionUser } from "./Auth/AuthTypes";
@@ -21,7 +22,7 @@ export { applyTableConfig } from "./TableConfig/applyTableConfig";
21
22
 
22
23
  import { CHANNELS, tryCatchV2 } from "prostgles-types";
23
24
  import type { DBEventsManager } from "./DBEventsManager";
24
- import type { PublishParser } from "./PublishParser/PublishParser";
25
+ import { PublishParser } from "./PublishParser/PublishParser";
25
26
  import { pushSocketSchema } from "./WebsocketAPI/pushSocketSchema";
26
27
 
27
28
  export type DB = pgPromise.IDatabase<{}, pg.IClient>;
@@ -229,7 +230,7 @@ export class Prostgles {
229
230
  }
230
231
 
231
232
  getTSFileName() {
232
- const fileName = "DBGeneratedSchema.ts";
233
+ const fileName = `${DB_GENERATED_SCHEMA_NAME}.ts`;
233
234
  const _dir = this.opts.tsGeneratedTypesDir || "";
234
235
  const dir = _dir.endsWith("/") ? _dir : `${_dir}/`;
235
236
  const fullPath = dir + fileName;
@@ -240,10 +241,10 @@ export class Prostgles {
240
241
  * Will write the Schema Typescript definitions to file (tsGeneratedTypesDir)
241
242
  * force is used for hotReloadMode to trigger a restart
242
243
  */
243
- writeDBSchema(force = false) {
244
+ async writeDBSchema(force = false) {
244
245
  if (this.opts.tsGeneratedTypesDir) {
246
+ const { tsSchema: fileContent } = await this.dboBuilder.getTsDefinitions();
245
247
  const { fullPath, fileName } = this.getTSFileName();
246
- const { tsSchema: fileContent } = this.dboBuilder.getTsDefinitions();
247
248
  fs.mkdirSync(dirname(fullPath), { recursive: true });
248
249
 
249
250
  const existingContent =
@@ -348,6 +349,11 @@ export class Prostgles {
348
349
  this.restApi = this.opts.restApi && new RestApi({ prostgles: this, ...this.opts.restApi });
349
350
  };
350
351
 
352
+ initPublishParser = () => {
353
+ this.publishParser = new PublishParser(this);
354
+ this.dboBuilder.publishParser = this.publishParser;
355
+ };
356
+
351
357
  initAuthHandler = () => {
352
358
  this.authHandler.destroy();
353
359
  this.authHandler = new AuthHandler(this);
@@ -25,9 +25,12 @@ import {
25
25
  type PermissionScope,
26
26
  type PublishObject,
27
27
  } from "./publishTypesAndUtils";
28
+ import { validatePublishProfiles } from "./validatePublishProfiles";
28
29
 
29
30
  export class PublishParser {
30
- publish: ProstglesInitOptions<void, SessionUser, any>["publish"];
31
+ publish:
32
+ | Exclude<ProstglesInitOptions<void, SessionUser, any>["publish"], unknown[]>
33
+ | ReturnType<typeof validatePublishProfiles>;
31
34
  publishRawSQL?: any;
32
35
  dbo: DBHandlerServer;
33
36
  db: DB;
@@ -35,7 +38,8 @@ export class PublishParser {
35
38
 
36
39
  constructor(prostgles: Prostgles) {
37
40
  this.prostgles = prostgles;
38
- this.publish = prostgles.opts.publish;
41
+ const { publish } = prostgles.opts;
42
+ this.publish = Array.isArray(publish) ? validatePublishProfiles(publish) : publish;
39
43
 
40
44
  // eslint-disable-next-line @typescript-eslint/unbound-method
41
45
  this.publishRawSQL = prostgles.opts.publishRawSQL;
@@ -146,7 +150,17 @@ export class PublishParser {
146
150
  clientInfo: AuthResultWithSID | undefined,
147
151
  ): Promise<PublishObject | undefined> {
148
152
  const publishParams = await this.getPublishParams(clientReq, clientInfo);
149
- const publish = await applyParamsIfFunc(this.publish, publishParams);
153
+
154
+ const publish = await (() => {
155
+ if (Array.isArray(this.publish)) {
156
+ const { user } = publishParams;
157
+ if (!user) return undefined;
158
+ return this.publish.find((publishRule) => publishRule.userTypes.includes(user.type))
159
+ ?.publish;
160
+ }
161
+
162
+ return applyParamsIfFunc(this.publish, publishParams);
163
+ })();
150
164
 
151
165
  if (publish === "*") {
152
166
  const publish: PublishObject = {};
@@ -271,13 +285,18 @@ export class PublishParser {
271
285
  args: DboTable,
272
286
  clientInfo: AuthResultWithSID | undefined,
273
287
  scope: PermissionScope | undefined,
288
+ overriddenPublish?: PublishObject,
274
289
  ): Promise<ParsedTableRule | undefined> {
275
290
  const { tableName } = args;
276
291
  const tableHandler = this.dbo[tableName];
277
292
  if (!tableHandler) {
278
293
  throw "INTERNAL ERROR: table handler not found for " + args.tableName;
279
294
  }
280
- const fileTablePublishRules = await this.getTableRulesWithoutFileTable(args, clientInfo);
295
+ const fileTablePublishRules = await this.getTableRulesWithoutFileTable(
296
+ args,
297
+ clientInfo,
298
+ overriddenPublish,
299
+ );
281
300
  if (this.dbo[args.tableName]?.is_media) {
282
301
  const { rules: fileTableRules } = await getFileTableRules.bind(this)(
283
302
  args.tableName,
@@ -285,6 +304,7 @@ export class PublishParser {
285
304
  args.clientReq,
286
305
  clientInfo,
287
306
  scope,
307
+ overriddenPublish,
288
308
  );
289
309
  return applyScopeToTableRules(
290
310
  tableName,
@@ -3,7 +3,7 @@ import { includes, isDefined } from "prostgles-types";
3
3
  import type { AuthClientRequest, AuthResultWithSID } from "../Auth/AuthTypes";
4
4
  import { parseFieldFilter } from "../DboBuilder/ViewHandler/parseFieldFilter";
5
5
  import type { PublishParser } from "./PublishParser";
6
- import type { ParsedPublishTable, UpdateRule } from "./publishTypesAndUtils";
6
+ import type { ParsedPublishTable, PublishObject, UpdateRule } from "./publishTypesAndUtils";
7
7
  import type { LocalParams } from "../DboBuilder/DboBuilder";
8
8
 
9
9
  /**
@@ -21,6 +21,7 @@ export async function getFileTableRules(
21
21
  clientReq: AuthClientRequest | undefined,
22
22
  clientInfo: AuthResultWithSID | undefined,
23
23
  scope: LocalParams["scope"],
24
+ overriddenPublish?: PublishObject,
24
25
  ) {
25
26
  const forcedDeleteFilters: FullFilter<AnyObject, void>[] = [];
26
27
  const forcedSelectFilters: FullFilter<AnyObject, void>[] = [];
@@ -42,7 +43,7 @@ export async function getFileTableRules(
42
43
  .filter(isDefined);
43
44
  if (referencedColumns?.length) {
44
45
  for (const { tableName, fileColumns, allColumns } of referencedColumns) {
45
- const tableRules = await this.getTableRules({ clientReq, tableName }, clientInfo, scope);
46
+ const tableRules = await this.getTableRules({ clientReq, tableName }, clientInfo, scope, overriddenPublish);
46
47
  if (tableRules) {
47
48
  fileColumns.map((column) => {
48
49
  const path = [{ table: tableName, on: [{ id: column }] }];
@@ -0,0 +1,29 @@
1
+ import type { PublishParser } from "./PublishParser";
2
+ import { type PublishObject } from "./PublishParser";
3
+
4
+ export const getPublishedTableNames = (
5
+ publishParserInstance: PublishParser,
6
+ publishObject: PublishObject,
7
+ ) => {
8
+ const txKey = !publishParserInstance.prostgles.opts.transactions ? "" : "tx";
9
+ const tableNames = Object.keys(publishObject).filter((k) => !txKey || txKey !== k);
10
+
11
+ /**
12
+ * Add file table to the list of published tables if it's referenced by other published tables.
13
+ * Access to the file table is controlled through the publish rules of the tables referencing it.
14
+ */
15
+ const fileTableName = publishParserInstance.prostgles.opts.fileTable?.tableName;
16
+ if (
17
+ fileTableName &&
18
+ publishParserInstance.dbo[fileTableName]?.is_media &&
19
+ !tableNames.includes(fileTableName)
20
+ ) {
21
+ const isReferenced = publishParserInstance.prostgles.dboBuilder.tablesOrViews?.some((t) =>
22
+ t.columns.some((c) => c.references?.some((r) => r.ftable === fileTableName)),
23
+ );
24
+ if (isReferenced) {
25
+ tableNames.unshift(fileTableName);
26
+ }
27
+ }
28
+ return tableNames;
29
+ };
@@ -4,6 +4,7 @@ import type { AuthClientRequest, AuthResultWithSID } from "../Auth/AuthTypes";
4
4
  import type { PublishParser } from "./PublishParser";
5
5
  import { type PermissionScope, type PublishObject } from "./PublishParser";
6
6
  import { getDBSchemaTable } from "./getDBSchemaTable";
7
+ import { getPublishedTableNames } from "./getPublishedTableNames";
7
8
 
8
9
  type Args = AuthClientRequest & {
9
10
  userData: AuthResultWithSID | undefined;
@@ -19,8 +20,6 @@ export async function getSchemaFromPublish(
19
20
  const tableSchemaErrors: TableSchemaErrors = {};
20
21
  const tables: DBSchemaTable[] = [];
21
22
 
22
- const txKey = !this.prostgles.opts.transactions ? "" : "tx";
23
-
24
23
  try {
25
24
  /* Publish tables and views based on socket */
26
25
  const clientInfo =
@@ -39,21 +38,7 @@ export async function getSchemaFromPublish(
39
38
  if (!publish || !Object.keys(publish).length) {
40
39
  return { tables, tableSchemaErrors };
41
40
  }
42
- const tableNames = Object.keys(publish).filter((k) => !txKey || txKey !== k);
43
-
44
- /**
45
- * Add file table to the list of published tables if it's referenced by other published tables.
46
- * Access to the file table is controlled through the publish rules of the tables referencing it.
47
- */
48
- const fileTableName = this.prostgles.opts.fileTable?.tableName;
49
- if (fileTableName && this.dbo[fileTableName]?.is_media && !tableNames.includes(fileTableName)) {
50
- const isReferenced = this.prostgles.dboBuilder.tablesOrViews?.some((t) =>
51
- t.columns.some((c) => c.references?.some((r) => r.ftable === fileTableName)),
52
- );
53
- if (isReferenced) {
54
- tableNames.unshift(fileTableName);
55
- }
56
- }
41
+ const tableNames = getPublishedTableNames(this, publish);
57
42
 
58
43
  await Promise.all(
59
44
  tableNames.map(async (tableName) => {
@@ -556,6 +556,13 @@ export type ParsedPublishTables = {
556
556
 
557
557
  type PublishAllOrNothingRoot = Exclude<PublishAllOrNothing, boolean>;
558
558
  export type PublishedResult<Schema = void> = PublishAllOrNothingRoot | PublishFullyTyped<Schema>;
559
+ export type PublishProfile<Schema = void> = {
560
+ /** Exported schema type name; defaults to Publish1Schema, Publish2Schema, etc. */
561
+ name?: string;
562
+ userTypes: string[];
563
+ publish: PublishedResult<Schema>;
564
+ };
559
565
  export type Publish<Schema = void, SUser extends SessionUser = SessionUser> =
566
+ | PublishProfile<Schema>[]
560
567
  | PublishedResult<Schema>
561
568
  | ((params: PublishParams<Schema, SUser>) => Awaitable<PublishedResult<Schema>>);
@@ -0,0 +1,22 @@
1
+ import { validateClientSchemaName } from "../DBSchemaBuilder/getClientDBGeneratedSchemas";
2
+ import type { PublishProfile } from "./publishTypesAndUtils";
3
+
4
+ export const validatePublishProfiles = (profiles: PublishProfile[]) => {
5
+ const names = new Set<string>();
6
+ const userTypes = new Set<string>();
7
+ const entries = profiles.map((profile, index) => {
8
+ const name = profile.name ?? `Publish${index + 1}Schema`;
9
+ validateClientSchemaName(name);
10
+ if (names.has(name)) throw new Error(`Duplicate publish schema name: ${name}`);
11
+ names.add(name);
12
+ if (!profile.userTypes.length) {
13
+ throw new Error(`Publish ${name}: userTypes must not be empty`);
14
+ }
15
+ for (const userType of profile.userTypes) {
16
+ if (userTypes.has(userType)) throw new Error(`Duplicate publish user type: ${userType}`);
17
+ userTypes.add(userType);
18
+ }
19
+ return { ...profile, name };
20
+ });
21
+ return entries;
22
+ };
@@ -81,7 +81,7 @@ export class SchemaWatch {
81
81
  console.log("watchSchema: Re-writing TS schema");
82
82
 
83
83
  await this.dboBuilder.prostgles.refreshDBO();
84
- this.dboBuilder.prostgles.writeDBSchema(true);
84
+ await this.dboBuilder.prostgles.writeDBSchema(true);
85
85
  }
86
86
  } else {
87
87
  /* Full re-init. Sockets must reconnect */
package/lib/index.ts CHANGED
@@ -1,18 +1,13 @@
1
+ import { defineJoin } from "prostgles-types";
1
2
  import type { SessionUser } from "./Auth/AuthTypes";
2
3
  import type { InitResult, OnReadyCallbackBasic } from "./initProstgles";
3
4
  import { Prostgles } from "./Prostgles";
4
5
  import type { ProstglesInitOptions } from "./ProstglesTypes";
5
6
 
6
- function prostgles<
7
- S = void,
8
- SUser extends SessionUser = SessionUser,
9
- Context = undefined,
10
- >(
7
+ function prostgles<S = void, SUser extends SessionUser = SessionUser, Context = undefined>(
11
8
  params: ProstglesInitOptions<S, SUser, Context>,
12
9
  ) {
13
- const prgl = new Prostgles(
14
- params as unknown as ProstglesInitOptions<void, SessionUser, any>,
15
- );
10
+ const prgl = new Prostgles(params as unknown as ProstglesInitOptions<void, SessionUser, any>);
16
11
  return prgl.init(params.onReady as unknown as OnReadyCallbackBasic, {
17
12
  type: "init",
18
13
  }) as unknown as Promise<InitResult<S, SUser, Context>>;
@@ -25,7 +20,7 @@ export const createProstgles = <S = void, SUser extends SessionUser = SessionUse
25
20
  };
26
21
  export * from "./PublishParser/defineServerFunction";
27
22
  export * from "./Auth/AuthTypes";
28
- export type { PublishParams } from "./PublishParser/publishTypesAndUtils";
23
+ export type { PublishParams, PublishProfile } from "./PublishParser/publishTypesAndUtils";
29
24
  export type { DBOFullyTyped } from "./DBSchemaBuilder/DBSchemaBuilder";
30
25
  export type { DBHandlerServer } from "./Prostgles";
31
26
  export type { StorageClient as CloudClient } from "./StorageClient/StorageClientTypes";
@@ -46,5 +41,9 @@ export * from "./Auth/utils/upsertNamedExpressMiddleware";
46
41
  export type { RequestWithUser } from "./Auth/middleware/userContextMiddleware";
47
42
  export default prostgles;
48
43
  export type { FileTableRow } from "./StorageClient/getFileTableConfig";
49
-
50
- export { AUDIT_TABLE_COLUMN_DEFINITIONS, AUDIT_TABLE_COLUMNS, type AuditTableRow } from "./Audit/AuditTable";
44
+ export { defineJoin };
45
+ export {
46
+ AUDIT_TABLE_COLUMN_DEFINITIONS,
47
+ AUDIT_TABLE_COLUMNS,
48
+ type AuditTableRow,
49
+ } from "./Audit/AuditTable";
@@ -12,7 +12,7 @@ import { getDbConnection } from "./getDbConnection";
12
12
  import type { DBHandlerServer, Prostgles } from "./Prostgles";
13
13
  import { getIsSuperUser } from "./Prostgles";
14
14
  import type { ProstglesInitOptions } from "./ProstglesTypes";
15
- import { PublishParser, type PermissionScope } from "./PublishParser/PublishParser";
15
+ import type { PermissionScope } from "./PublishParser/PublishParser";
16
16
  import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
17
17
  import { runSQLFile } from "./TableConfig/runSQLFile";
18
18
  import { updateConfiguration, type clientOnlyUpdateKeys } from "./updateConfiguration";
@@ -92,15 +92,9 @@ export type CreateContextParams<S> = OnReadyParamsCommon & {
92
92
  dbo: DBOFullyTyped<S>;
93
93
  onCleanup: (cleanup: ContextCleanup) => void;
94
94
  };
95
- export type CreateContext<S, Context> = (
96
- params: CreateContextParams<S>,
97
- ) => MaybePromise<Context>;
95
+ export type CreateContext<S, Context> = (params: CreateContextParams<S>) => MaybePromise<Context>;
98
96
 
99
- export type OnReadyCallback<
100
- S,
101
- SUser extends SessionUser,
102
- Context = undefined,
103
- > = (
97
+ export type OnReadyCallback<S, SUser extends SessionUser, Context = undefined> = (
104
98
  params: OnReadyParams<S, Context>,
105
99
  update: (newOpts: UpdatableOptions<S, SUser, Context>, force?: true) => Promise<void>,
106
100
  ) => void | Promise<void>;
@@ -109,11 +103,7 @@ export type OnReadyCallbackBasic = (
109
103
  update: (newOpts: UpdatableOptions<void, SessionUser, any>, force?: true) => Promise<void>,
110
104
  ) => void | Promise<void>;
111
105
 
112
- export type InitResult<
113
- S = void,
114
- SUser extends SessionUser = SessionUser,
115
- Context = undefined,
116
- > = {
106
+ export type InitResult<S = void, SUser extends SessionUser = SessionUser, Context = undefined> = {
117
107
  db: DBOFullyTyped<S>;
118
108
  context: Context;
119
109
  sql: SQLHandler;
@@ -126,7 +116,7 @@ export type InitResult<
126
116
  */
127
117
  getTSSchema: typeof DboBuilder.prototype.getTsDefinitions;
128
118
  getSchema: typeof DboBuilder.prototype.getSchema;
129
- reWriteDBSchema: () => void;
119
+ reWriteDBSchema: () => Promise<void>;
130
120
  update: (newOpts: UpdatableOptions<S, SUser, Context>, force?: true) => Promise<void>;
131
121
  restart: () => Promise<InitResult<S, SUser, Context>>;
132
122
  options: ProstglesInitOptions<S, SUser, Context>;
@@ -259,10 +249,8 @@ export const initProstgles = async function (
259
249
  /* 3.9 Check auth config */
260
250
  this.initAuthHandler();
261
251
 
262
- this.publishParser = new PublishParser(this);
263
- this.dboBuilder.publishParser = this.publishParser;
264
-
265
252
  /* 4. Set publish and auth listeners */
253
+ this.initPublishParser();
266
254
  this.setupSocketIO();
267
255
  } else if (this.opts.auth) {
268
256
  throw "Auth config does not work without publish";
@@ -270,7 +258,7 @@ export const initProstgles = async function (
270
258
 
271
259
  this.dbEventsManager = new DBEventsManager(db, pgp);
272
260
 
273
- this.writeDBSchema();
261
+ await this.writeDBSchema();
274
262
 
275
263
  /* 5. Finish init and provide DBO object */
276
264
  try {
@@ -32,6 +32,9 @@ export const updateConfiguration = async (
32
32
  if (includes(optionsThatChanged, "schema")) {
33
33
  await prgl.refreshDBO();
34
34
  }
35
+ if (includes(optionsThatChanged, "publish")) {
36
+ prgl.initPublishParser();
37
+ }
35
38
  if (includes(optionsThatChanged, "auth")) {
36
39
  prgl.initAuthHandler();
37
40
  }
@@ -42,10 +45,11 @@ export const updateConfiguration = async (
42
45
  }
43
46
 
44
47
  if (
48
+ includes(optionsThatChanged, "publish") ||
45
49
  includes(optionsThatChanged, "tsGeneratedTypesDir") ||
46
50
  includes(optionsThatChanged, "tsGeneratedTypesFunctionsPath")
47
51
  ) {
48
- prgl.writeDBSchema();
52
+ await prgl.writeDBSchema();
49
53
  }
50
54
 
51
55
  if (isEmpty(newOpts)) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "4.2.618",
3
+ "version": "4.2.620",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -57,7 +57,7 @@
57
57
  "pg": "^8.23.0",
58
58
  "pg-cursor": "^2.22.0",
59
59
  "pg-promise": "^12.7.1",
60
- "prostgles-types": "^4.0.282"
60
+ "prostgles-types": "^4.0.283"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@eslint/js": "^9.22.0",