prostgles-server 4.2.506 → 4.2.508

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 (149) hide show
  1. package/dist/DBSchemaBuilder/DBSchemaBuilder.d.ts +2 -2
  2. package/dist/DBSchemaBuilder/DBSchemaBuilder.d.ts.map +1 -1
  3. package/dist/DBSchemaBuilder/DBSchemaBuilder.spec.js +0 -4
  4. package/dist/DBSchemaBuilder/DBSchemaBuilder.spec.js.map +1 -1
  5. package/dist/DboBuilder/DboBuilder.d.ts +4 -5
  6. package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
  7. package/dist/DboBuilder/DboBuilder.js +13 -22
  8. package/dist/DboBuilder/DboBuilder.js.map +1 -1
  9. package/dist/DboBuilder/DboBuilderTypes.d.ts +15 -23
  10. package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
  11. package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
  12. package/dist/DboBuilder/TableHandler/DataValidator.js +1 -1
  13. package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
  14. package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
  15. package/dist/DboBuilder/TableHandler/TableHandler.js +9 -8
  16. package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
  17. package/dist/DboBuilder/TableHandler/insert/insert.d.ts.map +1 -1
  18. package/dist/DboBuilder/TableHandler/insert/insert.js +1 -1
  19. package/dist/DboBuilder/TableHandler/insert/insert.js.map +1 -1
  20. package/dist/DboBuilder/TableHandler/insert/insertRowWithNestedRecords.js +2 -2
  21. package/dist/DboBuilder/TableHandler/insert/insertRowWithNestedRecords.js.map +1 -1
  22. package/dist/DboBuilder/TableHandler/insertTest.d.ts.map +1 -1
  23. package/dist/DboBuilder/TableHandler/insertTest.js +1 -1
  24. package/dist/DboBuilder/TableHandler/insertTest.js.map +1 -1
  25. package/dist/DboBuilder/TableHandler/updateFile.js +1 -1
  26. package/dist/DboBuilder/TableHandler/updateFile.js.map +1 -1
  27. package/dist/DboBuilder/TableRules/{getValidatedRules.d.ts → getValidatedTableRules.d.ts} +2 -2
  28. package/dist/DboBuilder/TableRules/getValidatedTableRules.d.ts.map +1 -0
  29. package/dist/DboBuilder/TableRules/{getValidatedRules.js → getValidatedTableRules.js} +5 -13
  30. package/dist/DboBuilder/TableRules/getValidatedTableRules.js.map +1 -0
  31. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +3 -7
  32. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
  33. package/dist/DboBuilder/ViewHandler/ViewHandler.js +2 -35
  34. package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
  35. package/dist/DboBuilder/ViewHandler/getInfo.d.ts.map +1 -1
  36. package/dist/DboBuilder/ViewHandler/getInfo.js +20 -16
  37. package/dist/DboBuilder/ViewHandler/getInfo.js.map +1 -1
  38. package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.d.ts +2 -2
  39. package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.d.ts.map +1 -1
  40. package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.js +2 -2
  41. package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.js.map +1 -1
  42. package/dist/DboBuilder/ViewHandler/subscribe.js +1 -1
  43. package/dist/DboBuilder/ViewHandler/subscribe.js.map +1 -1
  44. package/dist/DboBuilder/getColumns.d.ts.map +1 -1
  45. package/dist/DboBuilder/getColumns.js +0 -2
  46. package/dist/DboBuilder/getColumns.js.map +1 -1
  47. package/dist/FileManager/FileManager.d.ts.map +1 -1
  48. package/dist/FileManager/FileManager.js +3 -3
  49. package/dist/FileManager/FileManager.js.map +1 -1
  50. package/dist/FileManager/initFileManager.js +1 -1
  51. package/dist/FileManager/initFileManager.js.map +1 -1
  52. package/dist/Prostgles.d.ts +1 -1
  53. package/dist/Prostgles.d.ts.map +1 -1
  54. package/dist/Prostgles.js +9 -1
  55. package/dist/Prostgles.js.map +1 -1
  56. package/dist/PubSubManager/PubSubManager.d.ts +5 -7
  57. package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
  58. package/dist/PubSubManager/PubSubManager.js.map +1 -1
  59. package/dist/PubSubManager/PubSubManagerUtils.d.ts +1 -0
  60. package/dist/PubSubManager/PubSubManagerUtils.d.ts.map +1 -1
  61. package/dist/PubSubManager/PubSubManagerUtils.js +2 -1
  62. package/dist/PubSubManager/PubSubManagerUtils.js.map +1 -1
  63. package/dist/PubSubManager/addSync.d.ts.map +1 -1
  64. package/dist/PubSubManager/addSync.js +5 -5
  65. package/dist/PubSubManager/addSync.js.map +1 -1
  66. package/dist/PubSubManager/addTrigger.js +1 -1
  67. package/dist/PubSubManager/addTrigger.js.map +1 -1
  68. package/dist/PublishParser/PublishParser.d.ts +1 -2
  69. package/dist/PublishParser/PublishParser.d.ts.map +1 -1
  70. package/dist/PublishParser/PublishParser.js +23 -12
  71. package/dist/PublishParser/PublishParser.js.map +1 -1
  72. package/dist/PublishParser/getDBSchemaTable.d.ts +6 -0
  73. package/dist/PublishParser/getDBSchemaTable.d.ts.map +1 -0
  74. package/dist/PublishParser/getDBSchemaTable.js +58 -0
  75. package/dist/PublishParser/getDBSchemaTable.js.map +1 -0
  76. package/dist/PublishParser/getSchemaFromPublish.d.ts +1 -2
  77. package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
  78. package/dist/PublishParser/getSchemaFromPublish.js +39 -104
  79. package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
  80. package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
  81. package/dist/PublishParser/getTableRulesWithoutFileTable.js +58 -127
  82. package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
  83. package/dist/PublishParser/publishTypesAndUtils.d.ts +31 -140
  84. package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
  85. package/dist/PublishParser/publishTypesAndUtils.js +18 -118
  86. package/dist/PublishParser/publishTypesAndUtils.js.map +1 -1
  87. package/dist/SyncReplication.d.ts.map +1 -1
  88. package/dist/SyncReplication.js +4 -6
  89. package/dist/SyncReplication.js.map +1 -1
  90. package/dist/TableConfig/TableConfig.d.ts +12 -5
  91. package/dist/TableConfig/TableConfig.d.ts.map +1 -1
  92. package/dist/TableConfig/TableConfig.js +16 -9
  93. package/dist/TableConfig/TableConfig.js.map +1 -1
  94. package/dist/TableConfig/getCreateSchemaQueries.d.ts +4 -9
  95. package/dist/TableConfig/getCreateSchemaQueries.d.ts.map +1 -1
  96. package/dist/TableConfig/getCreateSchemaQueries.js.map +1 -1
  97. package/dist/TableConfig/getTableColumnQueries.js +1 -1
  98. package/dist/TableConfig/getTableColumnQueries.js.map +1 -1
  99. package/dist/TableConfig/getTableConfigSchemaQueries.d.ts +4 -9
  100. package/dist/TableConfig/getTableConfigSchemaQueries.d.ts.map +1 -1
  101. package/dist/WebsocketAPI/getClientSchema.d.ts.map +1 -1
  102. package/dist/WebsocketAPI/getClientSchema.js +3 -3
  103. package/dist/WebsocketAPI/getClientSchema.js.map +1 -1
  104. package/dist/index.js.map +1 -1
  105. package/dist/initProstgles.d.ts +2 -3
  106. package/dist/initProstgles.d.ts.map +1 -1
  107. package/dist/initProstgles.js.map +1 -1
  108. package/dist/runClientRequest.d.ts.map +1 -1
  109. package/dist/runClientRequest.js +4 -8
  110. package/dist/runClientRequest.js.map +1 -1
  111. package/lib/DBSchemaBuilder/DBSchemaBuilder.spec.ts +1 -5
  112. package/lib/DBSchemaBuilder/DBSchemaBuilder.ts +2 -8
  113. package/lib/DboBuilder/DboBuilder.ts +18 -26
  114. package/lib/DboBuilder/DboBuilderTypes.ts +70 -59
  115. package/lib/DboBuilder/TableHandler/DataValidator.ts +1 -1
  116. package/lib/DboBuilder/TableHandler/TableHandler.ts +10 -14
  117. package/lib/DboBuilder/TableHandler/insert/insert.ts +1 -7
  118. package/lib/DboBuilder/TableHandler/insert/insertRowWithNestedRecords.ts +3 -3
  119. package/lib/DboBuilder/TableHandler/insertTest.ts +5 -5
  120. package/lib/DboBuilder/TableHandler/updateFile.ts +1 -1
  121. package/lib/DboBuilder/TableRules/{getValidatedRules.ts → getValidatedTableRules.ts} +3 -10
  122. package/lib/DboBuilder/ViewHandler/ViewHandler.ts +7 -41
  123. package/lib/DboBuilder/ViewHandler/getInfo.ts +24 -20
  124. package/lib/DboBuilder/ViewHandler/getValidatedSubscribeOptions.ts +4 -4
  125. package/lib/DboBuilder/ViewHandler/subscribe.ts +1 -1
  126. package/lib/DboBuilder/getColumns.ts +4 -14
  127. package/lib/FileManager/FileManager.ts +5 -6
  128. package/lib/FileManager/initFileManager.ts +1 -1
  129. package/lib/Prostgles.ts +10 -1
  130. package/lib/PubSubManager/PubSubManager.ts +12 -13
  131. package/lib/PubSubManager/PubSubManagerUtils.ts +1 -0
  132. package/lib/PubSubManager/addSync.ts +4 -7
  133. package/lib/PubSubManager/addTrigger.ts +1 -1
  134. package/lib/PublishParser/PublishParser.ts +30 -17
  135. package/lib/PublishParser/getDBSchemaTable.ts +73 -0
  136. package/lib/PublishParser/getSchemaFromPublish.ts +56 -147
  137. package/lib/PublishParser/getTableRulesWithoutFileTable.ts +74 -162
  138. package/lib/PublishParser/publishTypesAndUtils.ts +41 -167
  139. package/lib/SyncReplication.ts +6 -8
  140. package/lib/TableConfig/TableConfig.ts +25 -11
  141. package/lib/TableConfig/getCreateSchemaQueries.ts +8 -8
  142. package/lib/TableConfig/getTableColumnQueries.ts +1 -1
  143. package/lib/WebsocketAPI/getClientSchema.ts +5 -3
  144. package/lib/index.ts +1 -1
  145. package/lib/initProstgles.ts +2 -3
  146. package/lib/runClientRequest.ts +4 -6
  147. package/package.json +2 -2
  148. package/dist/DboBuilder/TableRules/getValidatedRules.d.ts.map +0 -1
  149. package/dist/DboBuilder/TableRules/getValidatedRules.js.map +0 -1
@@ -6,12 +6,20 @@ import type {
6
6
  EXISTS_KEY,
7
7
  RawJoinPath,
8
8
  SQLHandler,
9
+ SyncTableInfo,
9
10
  TableInfo as TInfo,
10
11
  UserLike,
11
12
  } from "prostgles-types";
12
13
  import type { AuthClientRequest, BasicSession, SessionUser } from "../Auth/AuthTypes";
13
14
  import type { BasicCallback } from "../PubSubManager/PubSubManager";
14
- import type { PermissionScope, PublishAllOrNothing } from "../PublishParser/PublishParser";
15
+ import type {
16
+ DeleteRule,
17
+ InsertRule,
18
+ PermissionScope,
19
+ PublishAllOrNothing,
20
+ SelectRule,
21
+ UpdateRule,
22
+ } from "../PublishParser/PublishParser";
15
23
  import type { FieldSpec } from "./QueryBuilder/Functions/Functions";
16
24
  import type { TableHandler } from "./TableHandler/TableHandler";
17
25
  import type { ParsedJoinPath } from "./ViewHandler/parseJoinPath";
@@ -107,10 +115,10 @@ export type TX<TH = TableHandlers> = {
107
115
  };
108
116
 
109
117
  export type TableHandlers = {
110
- [key: string]: Partial<TableHandler>;
118
+ [key: string]: TableHandler;
111
119
  };
112
120
  export type DbTxTableHandlers = {
113
- [key: string]: Omit<Partial<TableHandler>, "dbTx"> | Omit<TableHandler, "dbTx">;
121
+ [key: string]: Omit<TableHandler, "dbTx">;
114
122
  };
115
123
 
116
124
  export type SQLHandlerServer = SQLHandler<LocalParams>;
@@ -264,75 +272,78 @@ export type JoinInfo = {
264
272
  target: string;
265
273
  }[];
266
274
  };
275
+ type MergeOverwrite<T, U> = Omit<T, keyof U> & U;
267
276
 
268
- export type CommonTableRules = {
269
- /**
270
- * True by default. Allows clients to get column information on any columns that are allowed in (select, insert, update) field rules.
271
- */
272
- getColumns?: PublishAllOrNothing;
273
-
274
- /**
275
- * True by default. Allows clients to get table information (oid, comment, label, has_media).
276
- */
277
- getInfo?: PublishAllOrNothing;
278
- };
279
-
280
- export type ValidatedTableRules = CommonTableRules & {
277
+ export type ValidatedTableRules = {
281
278
  /* All columns of the view/table. Includes computed fields as well */
282
279
  allColumns: FieldSpec[];
283
280
 
284
- select?: {
285
- /* Fields you can select */
286
- fields: string[];
281
+ select?: MergeOverwrite<
282
+ SelectRule,
283
+ {
284
+ /* Fields you can select */
285
+ fields: string[];
287
286
 
288
- /* Fields you can select */
289
- orderByFields: string[];
287
+ /* Fields you can select */
288
+ orderByFields: string[];
290
289
 
291
- /* Filter applied to every select */
292
- filterFields: string[];
290
+ /* Filter applied to every select */
291
+ filterFields: string[];
293
292
 
294
- /* Filter applied to every select */
295
- forcedFilter: AnyObject | undefined;
296
-
297
- /* Max limit allowed for each select. 1000 by default. If null then an unlimited select is allowed when providing { limit: null } */
298
- maxLimit: number | null;
299
- };
300
- update?: {
301
- /* Fields you can update */
302
- fields: string[];
293
+ /* Filter applied to every select */
294
+ forcedFilter: AnyObject | undefined;
303
295
 
304
- /* Fields you can return after updating */
305
- returningFields: string[];
296
+ /* Max limit allowed for each select. 1000 by default. If null then an unlimited select is allowed when providing { limit: null } */
297
+ maxLimit: number | null;
306
298
 
307
- /* Fields you can use in filtering when updating */
308
- filterFields: string[];
309
-
310
- /* Filter applied to every update. Filter fields cannot be updated */
311
- forcedFilter: AnyObject | undefined;
312
-
313
- /* Data applied to every update */
314
- forcedData: AnyObject;
315
- };
316
- insert?: {
317
- /* Fields you can insert */
318
- fields: string[];
299
+ syncConfig: SyncTableInfo | undefined;
300
+ }
301
+ >;
302
+ update?: MergeOverwrite<
303
+ UpdateRule,
304
+ {
305
+ /* Fields you can update */
306
+ fields: string[];
319
307
 
320
- /* Fields you can return after inserting. Will return select.fields by default */
321
- returningFields: string[];
308
+ /* Fields you can return after updating */
309
+ returningFields: string[];
322
310
 
323
- /* Data applied to every insert */
324
- forcedData: AnyObject;
325
- };
326
- delete?: {
327
- /* Fields to filter by when deleting */
328
- filterFields: string[];
311
+ /* Fields you can use in filtering when updating */
312
+ filterFields: string[];
329
313
 
330
- /* Filter applied to every deletes */
331
- forcedFilter: AnyObject | undefined;
314
+ /* Filter applied to every update. Filter fields cannot be updated */
315
+ forcedFilter: AnyObject | undefined;
332
316
 
333
- /* Fields you can return after deleting */
334
- returningFields: string[];
335
- };
317
+ /* Data applied to every update */
318
+ forcedData: AnyObject;
319
+ }
320
+ >;
321
+ insert?: MergeOverwrite<
322
+ InsertRule,
323
+ {
324
+ /* Fields you can insert */
325
+ fields: string[];
326
+
327
+ /* Fields you can return after inserting. Will return select.fields by default */
328
+ returningFields: string[];
329
+
330
+ /* Data applied to every insert */
331
+ forcedData: AnyObject;
332
+ }
333
+ >;
334
+ delete?: MergeOverwrite<
335
+ DeleteRule,
336
+ {
337
+ /* Fields to filter by when deleting */
338
+ filterFields: string[];
339
+
340
+ /* Filter applied to every deletes */
341
+ forcedFilter: AnyObject | undefined;
342
+
343
+ /* Fields you can return after deleting */
344
+ returningFields: string[];
345
+ }
346
+ >;
336
347
  };
337
348
 
338
349
  export type ExistsFilterConfig = {
@@ -159,7 +159,7 @@ export const prepareNewData = ({
159
159
  tableConfigurator,
160
160
  tableHandler,
161
161
  }: ValidatedParams) => {
162
- const synced_field = (tableRules ?? {}).sync?.synced_field;
162
+ const synced_field = tableHandler.config?.syncConfig?.synced_field;
163
163
 
164
164
  /* Update synced_field if sync is on and missing */
165
165
  if (synced_field && !row[synced_field]) {
@@ -9,12 +9,7 @@ import type {
9
9
  } from "prostgles-types";
10
10
  import { asName, isDefined } from "prostgles-types";
11
11
  import type { DB } from "../../Prostgles";
12
- import type {
13
- InsertRule,
14
- ParsedTableRule,
15
- SyncRule,
16
- UpdateRule,
17
- } from "../../PublishParser/PublishParser";
12
+ import type { InsertRule, ParsedTableRule, UpdateRule } from "../../PublishParser/PublishParser";
18
13
  import type TableConfigurator from "../../TableConfig/TableConfig";
19
14
  import type { TableDefinition } from "../../TableConfig/TableConfig";
20
15
  import type { DboBuilder, Filter, LocalParams, TableHandlers } from "../DboBuilder";
@@ -214,31 +209,33 @@ export class TableHandler extends ViewHandler {
214
209
  throw "Cannot subscribe. PubSubManager not initiated";
215
210
  }
216
211
 
217
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
218
212
  if (!localParams.clientReq) throw "Sync not allowed within the server code";
219
213
  const { socket } = localParams.clientReq;
220
214
  if (!socket) throw "socket missing";
221
215
 
216
+ const syncConfig = this.dboBuilder.prostgles.tableConfigurator?.getTableSyncConfig(this.name);
222
217
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
223
- if (!table_rules || !table_rules.sync || !table_rules.select)
218
+ if (!table_rules || !table_rules.select || !syncConfig) {
224
219
  throw "sync or select table rules missing";
220
+ }
225
221
 
226
222
  if (this.tx) throw "Sync not allowed within transactions";
227
223
 
228
224
  const ALLOWED_PARAMS = ["select"];
229
225
  const invalidParams = Object.keys(params).filter((k) => !ALLOWED_PARAMS.includes(k));
230
- if (invalidParams.length)
226
+ if (invalidParams.length) {
231
227
  throw "Invalid or dissallowed params found: " + invalidParams.join(", ");
228
+ }
232
229
 
233
- const { synced_field }: SyncRule = table_rules.sync;
230
+ const { synced_field } = syncConfig;
234
231
 
235
- if (!table_rules.sync.id_fields.length || !synced_field) {
232
+ if (!syncConfig.id_fields.length || !synced_field) {
236
233
  const err = "INTERNAL ERROR: id_fields OR synced_field missing from publish";
237
234
  console.error(err);
238
235
  throw err;
239
236
  }
240
237
 
241
- const id_fields = this.parseFieldFilter(table_rules.sync.id_fields, false);
238
+ const id_fields = this.parseFieldFilter(syncConfig.id_fields, false);
242
239
  const syncFields = [...id_fields, synced_field];
243
240
 
244
241
  const allowedSelect = this.parseFieldFilter(table_rules.select.fields);
@@ -279,8 +276,7 @@ export class TableHandler extends ViewHandler {
279
276
  .addSync({
280
277
  table_info: this.tableOrViewInfo,
281
278
  condition,
282
- id_fields,
283
- synced_field,
279
+ ...syncConfig,
284
280
  socket,
285
281
  table_rules,
286
282
  filter: { ...filter },
@@ -35,13 +35,7 @@ export async function insert(
35
35
  /** Post validate and checkFilter require a transaction dbo handler because they happen after the insert */
36
36
  if (this.shouldWrapInTx({ name: ACTION, rule }, localParams)) {
37
37
  return this.dboBuilder.getTX((_dbtx) =>
38
- _dbtx[this.name]?.[ACTION]?.(
39
- rowOrRows,
40
- insertParams,
41
- param3_unused,
42
- tableRules,
43
- localParams,
44
- ),
38
+ _dbtx[this.name]?.[ACTION](rowOrRows, insertParams, param3_unused, tableRules, localParams),
45
39
  );
46
40
  }
47
41
 
@@ -154,8 +154,8 @@ export async function insertRowWithNestedRecords(
154
154
  localParams?.scope,
155
155
  );
156
156
 
157
- const cols2 = this.dboBuilder.dbo[tbl2!]!.columns || [];
158
- if (!this.dboBuilder.dbo[tbl2!]) throw "Invalid/disallowed table: " + tbl2;
157
+ const cols2 = this.dboBuilder.dboMap.get(tbl2!)?.columns || [];
158
+ if (!this.dboBuilder.dboMap.get(tbl2!)) throw "Invalid/disallowed table: " + tbl2;
159
159
  const colsRefT1 = cols2.filter((c) =>
160
160
  c.references?.some((rc) => rc.cols.length === 1 && rc.ftable === tbl1),
161
161
  );
@@ -299,7 +299,7 @@ const referencedInsert = async (
299
299
 
300
300
  const results: AnyObject[] = [];
301
301
  for (const dataItem of (Array.isArray(targetData) ? targetData : [targetData]) as AnyObject[]) {
302
- const result: AnyObject = await (dbTX[targetTable] as TableHandler)
302
+ const result: AnyObject = await dbTX[targetTable]
303
303
  .insert(dataItem, { returning: "*", onConflict }, undefined, childRules, localParams)
304
304
  .catch((e) => {
305
305
  return Promise.reject(e);
@@ -1,6 +1,6 @@
1
1
  import type { AnyObject, FieldFilter, FullFilter } from "prostgles-types";
2
2
  import { asName } from "prostgles-types";
3
- import type { LocalParams} from "../DboBuilder";
3
+ import type { LocalParams } from "../DboBuilder";
4
4
  import { pgp } from "../DboBuilder";
5
5
  import type { ParsedTableRule } from "../../PublishParser/PublishParser";
6
6
  import { asValue } from "../../PubSubManager/PubSubManagerUtils";
@@ -53,13 +53,13 @@ export async function insertTest(this: TableHandler, { localParams, tableRules }
53
53
  if (keys.length) {
54
54
  const dataCols = keys.filter((k) => this.column_names.includes(k));
55
55
  const nestedInsertCols = keys.filter(
56
- (k) => !this.column_names.includes(k) && this.dboBuilder.dbo[k]?.insert
56
+ (k) => !this.column_names.includes(k) && this.dboBuilder.dboMap.has(k),
57
57
  );
58
58
  if (nestedInsertCols.length) {
59
59
  throw `Nested insert not supported for forcedData rule: ${nestedInsertCols}`;
60
60
  }
61
61
  const badCols = keys.filter(
62
- (k) => !dataCols.includes(k) && !nestedInsertCols.includes(k)
62
+ (k) => !dataCols.includes(k) && !nestedInsertCols.includes(k),
63
63
  );
64
64
  if (badCols.length) {
65
65
  throw `Invalid columns found in forced filter: ${badCols.join(", ")}`;
@@ -72,7 +72,7 @@ export async function insertTest(this: TableHandler, { localParams, tableRules }
72
72
  (k) =>
73
73
  asValue(forcedData![k]) +
74
74
  "::" +
75
- this.columns.find((c) => c.name === k)!.udt_name
75
+ this.columns.find((c) => c.name === k)!.udt_name,
76
76
  )
77
77
  .join(", ") +
78
78
  ")",
@@ -81,7 +81,7 @@ export async function insertTest(this: TableHandler, { localParams, tableRules }
81
81
  "EXPLAIN INSERT INTO " +
82
82
  this.escapedName +
83
83
  " (${colNames:raw}) SELECT * FROM ( VALUES ${values:raw} ) t WHERE FALSE;",
84
- { colNames, values }
84
+ { colNames, values },
85
85
  );
86
86
  await this.db.any(query);
87
87
  } catch (e: any) {
@@ -57,7 +57,7 @@ export const updateFile = async function (
57
57
  : undefined;
58
58
 
59
59
  const existingFile: Media | undefined = await (
60
- (localParams?.tx?.dbTX[this.name] as TableHandler | undefined) || this
60
+ (localParams?.tx?.dbTX[this.name]) || this
61
61
  ).findOne({ id: existingMediaId });
62
62
 
63
63
  if (!existingFile?.name) throw new Error("Existing file record not found");
@@ -6,7 +6,7 @@ import type { ViewHandler } from "../ViewHandler/ViewHandler";
6
6
  import { COMPUTED_FIELDS } from "../QueryBuilder/Functions/COMPUTED_FIELDS";
7
7
  import { asNameAlias } from "../../utils/asNameAlias";
8
8
 
9
- export function getValidatedRules(
9
+ export function getValidatedTableRules(
10
10
  this: ViewHandler,
11
11
  tableRules?: ParsedTableRule,
12
12
  localParams?: LocalParams,
@@ -61,8 +61,6 @@ export function getValidatedRules(
61
61
 
62
62
  const res: ValidatedTableRules = {
63
63
  allColumns,
64
- getColumns: tableRules.getColumns ?? true,
65
- getInfo: tableRules.getColumns ?? true,
66
64
  };
67
65
 
68
66
  if (tableRules.select) {
@@ -93,6 +91,7 @@ export function getValidatedRules(
93
91
  forcedFilter: { ...tableRules.select.forcedFilter },
94
92
  filterFields: this.parseFieldFilter(tableRules.select.filterFields),
95
93
  maxLimit,
94
+ syncConfig: this.dboBuilder.prostgles.tableConfigurator?.getTableSyncConfig(this.name),
96
95
  };
97
96
  }
98
97
 
@@ -136,24 +135,18 @@ export function getValidatedRules(
136
135
  };
137
136
  }
138
137
 
139
- if (!tableRules.select && !tableRules.update && !tableRules.delete && !tableRules.insert) {
140
- if ([null, false].includes(tableRules.getInfo as any)) res.getInfo = false;
141
- if ([null, false].includes(tableRules.getColumns as any)) res.getColumns = false;
142
- }
143
-
144
138
  return res;
145
139
  }
146
140
  const allCols = this.column_names.slice(0);
147
141
  return {
148
142
  allColumns,
149
- getColumns: true,
150
- getInfo: true,
151
143
  select: {
152
144
  fields: allCols,
153
145
  filterFields: allCols,
154
146
  orderByFields: allCols,
155
147
  forcedFilter: {},
156
148
  maxLimit: null,
149
+ syncConfig: this.dboBuilder.prostgles.tableConfigurator?.getTableSyncConfig(this.name),
157
150
  },
158
151
  update: {
159
152
  fields: allCols,
@@ -6,6 +6,7 @@ import type {
6
6
  SelectParams,
7
7
  SubscribeParams,
8
8
  SubscriptionChannels,
9
+ SubscriptionHandler,
9
10
  } from "prostgles-types";
10
11
  import { asName, isObject, postgresToTsType } from "prostgles-types";
11
12
  import type { TableEvent } from "../../Logging";
@@ -16,7 +17,7 @@ import type { Graph } from "../../shortestPath";
16
17
  import type { DboBuilder, Filter, LocalParams, TableHandlers } from "../DboBuilder";
17
18
  import { getSerializedClientErrorFromPGError } from "../DboBuilder";
18
19
  import type { TableSchema } from "../DboBuilderTypes";
19
- import { getValidatedRules } from "../TableRules/getValidatedRules";
20
+ import { getValidatedTableRules } from "../TableRules/getValidatedTableRules";
20
21
  import { getColumns } from "../getColumns";
21
22
  import { count } from "./count";
22
23
  import { find } from "./find";
@@ -151,41 +152,6 @@ export class ViewHandler {
151
152
 
152
153
  validateViewRules = validateViewRules.bind(this);
153
154
 
154
- // DEAD CODE?!
155
- // getShortestJoin(
156
- // table1: string,
157
- // table2: string,
158
- // startAlias: number,
159
- // isInner = false
160
- // ): { query: string; toOne: boolean } {
161
- // const getJoinCondition = (
162
- // on: Record<string, string>[],
163
- // leftTable: string,
164
- // rightTable: string
165
- // ) => {
166
- // return on
167
- // .map((cond) =>
168
- // Object.keys(cond)
169
- // .map((lKey) => `${leftTable}.${lKey} = ${rightTable}.${cond[lKey]}`)
170
- // .join("\nAND ")
171
- // )
172
- // .join(" OR ");
173
- // };
174
-
175
- // // let toOne = true;
176
- // const query = this.joins
177
- // .map(({ tables, on, type }, i) => {
178
- // if (type.split("-")[1] === "many") {
179
- // // toOne = false;
180
- // }
181
- // const tl = `tl${startAlias + i}`,
182
- // tr = `tr${startAlias + i}`;
183
- // return `FROM ${tables[0]} ${tl} ${isInner ? "INNER" : "LEFT"} JOIN ${tables[1]} ${tr} ON ${getJoinCondition(on, tl, tr)}`;
184
- // })
185
- // .join("\n");
186
- // return { query, toOne: false };
187
- // }
188
-
189
155
  checkFilter(filter: any) {
190
156
  if (filter === null || (filter && !isObject(filter)))
191
157
  throw `invalid filter -> ${JSON.stringify(filter)} \nExpecting: undefined | {} | { field_name: "value" } | { field: { $gt: 22 } } ... `;
@@ -195,7 +161,7 @@ export class ViewHandler {
195
161
 
196
162
  getColumns = getColumns.bind(this);
197
163
 
198
- getValidatedRules = getValidatedRules.bind(this);
164
+ getValidatedRules = getValidatedTableRules.bind(this);
199
165
 
200
166
  find = find.bind(this);
201
167
 
@@ -239,7 +205,7 @@ export class ViewHandler {
239
205
  filter: Filter,
240
206
  params: SubscribeParams,
241
207
  onData: OnData,
242
- ): Promise<{ unsubscribe: () => any }>;
208
+ ): Promise<SubscriptionHandler>;
243
209
 
244
210
  async subscribe(
245
211
  filter: Filter,
@@ -255,7 +221,7 @@ export class ViewHandler {
255
221
  onData?: OnData,
256
222
  table_rules?: ParsedTableRule,
257
223
  localParams?: LocalParams,
258
- ): Promise<{ unsubscribe: () => any } | SubscriptionChannels> {
224
+ ): Promise<SubscriptionHandler | SubscriptionChannels> {
259
225
  const result = await subscribe.bind(this)(
260
226
  filter,
261
227
  params,
@@ -272,7 +238,7 @@ export class ViewHandler {
272
238
  filter: Filter,
273
239
  params: SubscribeParams,
274
240
  onData: (item: AnyObject | undefined, error?: unknown) => any,
275
- ): Promise<{ unsubscribe: () => any }>;
241
+ ): Promise<SubscriptionHandler>;
276
242
  subscribeOne(
277
243
  filter: Filter,
278
244
  params: SubscribeParams,
@@ -286,7 +252,7 @@ export class ViewHandler {
286
252
  onData?: (item: AnyObject | undefined, error?: unknown) => void,
287
253
  table_rules?: ParsedTableRule,
288
254
  localParams?: LocalParams,
289
- ): Promise<SubscriptionChannels | { unsubscribe: () => any }> {
255
+ ): Promise<SubscriptionChannels | SubscriptionHandler> {
290
256
  const func =
291
257
  localParams || !onData ? undefined : (
292
258
  (rows: AnyObject[], error?: unknown) => onData(rows[0], error)
@@ -9,19 +9,9 @@ export async function getInfo(
9
9
  param2?: any,
10
10
  param3?: any,
11
11
  tableRules?: ParsedTableRule,
12
- localParams?: LocalParams
12
+ localParams?: LocalParams,
13
13
  ): Promise<TInfo> {
14
- const p = this.getValidatedRules(tableRules, localParams);
15
- if (!p.getInfo) {
16
- await this._log({
17
- command: "getInfo",
18
- localParams,
19
- data: { lang },
20
- duration: 0,
21
- error: "Not allowed",
22
- });
23
- throw "Not allowed";
24
- }
14
+ const validatedTableRules = this.getValidatedRules(tableRules, localParams);
25
15
 
26
16
  const fileTableName = this.dboBuilder.prostgles.opts.fileTable?.tableName;
27
17
 
@@ -33,13 +23,14 @@ export async function getInfo(
33
23
  });
34
24
  const allowedFieldsToSelect = this.parseFieldFilter(tableRules?.select?.fields);
35
25
  const { requiredNestedInserts, allowedNestedInserts } = tableRules?.insert ?? {};
26
+ const label = this.dboBuilder.prostgles.tableConfigurator?.getTableLabel({
27
+ tableName: this.name,
28
+ lang,
29
+ });
36
30
  return {
37
31
  oid: this.tableOrViewInfo.oid,
38
32
  comment: this.tableOrViewInfo.comment,
39
- info: this.dboBuilder.prostgles.tableConfigurator?.getTableInfo({
40
- tableName: this.name,
41
- lang,
42
- }),
33
+ label,
43
34
  isFileTable:
44
35
  !this.is_media ? undefined : (
45
36
  {
@@ -49,8 +40,8 @@ export async function getInfo(
49
40
  isView: this.is_view,
50
41
  hasFiles: Boolean(
51
42
  !this.is_media &&
52
- fileTableName &&
53
- this.columns.some((c) => c.references?.some((r) => r.ftable === fileTableName))
43
+ fileTableName &&
44
+ this.columns.some((c) => c.references?.some((r) => r.ftable === fileTableName)),
54
45
  ),
55
46
  fileTableName,
56
47
  dynamicRules: {
@@ -60,8 +51,21 @@ export async function getInfo(
60
51
  * Only show column groups that are fully allowed to be selected by the user
61
52
  */
62
53
  uniqueColumnGroups: this.tableOrViewInfo.uniqueColumnGroups?.filter(
63
- (g) => !localParams || g.every((c) => allowedFieldsToSelect.includes(c))
54
+ (g) => !localParams || g.every((c) => allowedFieldsToSelect.includes(c)),
64
55
  ),
65
- ...(requiredNestedInserts && { requiredNestedInserts }),
56
+ publishInfo: {
57
+ select: validatedTableRules.select && {
58
+ disabledMethods: validatedTableRules.select.disableMethods,
59
+ syncConfig: this.dboBuilder.prostgles.tableConfigurator?.getTableSyncConfig(this.name),
60
+ },
61
+ insert: validatedTableRules.insert && {
62
+ requiredNestedInserts,
63
+ allowedNestedInserts: allowedNestedInserts?.map((t) => t.table),
64
+ },
65
+ update: validatedTableRules.update && {
66
+ disabledMethods: tableRules?.update?.disableMethods,
67
+ },
68
+ delete: validatedTableRules.delete && {},
69
+ },
66
70
  };
67
71
  }
@@ -4,11 +4,11 @@ import {
4
4
  isEmpty,
5
5
  type SubscribeOptions,
6
6
  } from "prostgles-types";
7
- import { type Required_ish, type SubscribeRule } from "../../PublishParser/PublishParser";
7
+ import { type Required_ish, type SelectRule } from "../../PublishParser/PublishParser";
8
8
 
9
9
  export const getValidatedSubscribeOptions = (
10
10
  rawVal: Required_ish<SubscribeOptions>,
11
- subscribeRule: SubscribeRule | undefined
11
+ selectRule: SelectRule | undefined,
12
12
  ): Required_ish<SubscribeOptions> => {
13
13
  const { data, error } = getJSONBObjectSchemaValidationError(
14
14
  {
@@ -46,13 +46,13 @@ export const getValidatedSubscribeOptions = (
46
46
  },
47
47
  } as const,
48
48
  rawVal,
49
- "subscribeParams"
49
+ "subscribeParams",
50
50
  );
51
51
  if (error !== undefined) {
52
52
  throw error;
53
53
  }
54
54
 
55
- const publishedThrottle = subscribeRule?.throttle || 0;
55
+ const publishedThrottle = selectRule?.subscribeThrottle || 0;
56
56
  const {
57
57
  actions,
58
58
  throttleOpts,
@@ -90,7 +90,7 @@ async function subscribe(
90
90
  selectParams: { ...selectParams },
91
91
  subscribeOptions: getValidatedSubscribeOptions(
92
92
  { actions, skipFirst, throttle, throttleOpts, skipChangedColumnsCheck },
93
- table_rules?.subscribe,
93
+ table_rules?.select,
94
94
  ),
95
95
  lastPushed: 0,
96
96
  tracked_columns: !firstField ? undefined : [firstField, ...otherFields],
@@ -1,15 +1,7 @@
1
- import type {
2
- AnyObject,
3
- ValidatedColumnInfo} from "prostgles-types";
4
- import {
5
- _PG_geometric,
6
- isDefined,
7
- isObject,
8
- omitKeys,
9
- postgresToTsType,
10
- } from "prostgles-types";
1
+ import type { AnyObject, ValidatedColumnInfo } from "prostgles-types";
2
+ import { _PG_geometric, isDefined, isObject, omitKeys, postgresToTsType } from "prostgles-types";
11
3
  import type { ParsedTableRule } from "../PublishParser/PublishParser";
12
- import type { LocalParams} from "./DboBuilder";
4
+ import type { LocalParams } from "./DboBuilder";
13
5
  import { getErrorAsObject, getSerializedClientErrorFromPGError } from "./DboBuilder";
14
6
  import type { TableHandler } from "./TableHandler/TableHandler";
15
7
  import type { ViewHandler } from "./ViewHandler/ViewHandler";
@@ -22,14 +14,12 @@ export async function getColumns(
22
14
  params?: { rule: "update"; filter: AnyObject },
23
15
  _param3?: undefined,
24
16
  tableRules?: ParsedTableRule,
25
- localParams?: LocalParams
17
+ localParams?: LocalParams,
26
18
  ): Promise<ValidatedColumnInfo[]> {
27
19
  const start = Date.now();
28
20
  try {
29
21
  const rules = this.getValidatedRules(tableRules, localParams);
30
22
 
31
- if (!rules.getColumns) throw "Not allowed";
32
-
33
23
  let dynamicUpdateFields = this.column_names;
34
24
 
35
25
  if (params && tableRules && isTableHandler(this)) {
@@ -138,11 +138,10 @@ export class FileManager {
138
138
  const fileTable = fullConfig.tableName;
139
139
  const daysDelay = fullConfig.delayedDelete?.deleteAfterNDays ?? 0;
140
140
  if (fileTable && this.dbo[fileTable]?.delete && daysDelay) {
141
- const filesToDelete =
142
- (await this.dbo[fileTable].find?.({
143
- deleted_from_storage: null,
144
- deleted: { ">": Date.now() - daysDelay * HOUR * 24 },
145
- })) ?? [];
141
+ const filesToDelete = await this.dbo[fileTable].find({
142
+ deleted_from_storage: null,
143
+ deleted: { ">": Date.now() - daysDelay * HOUR * 24 },
144
+ });
146
145
  for (const file of filesToDelete) {
147
146
  await this.deleteFile(file.name);
148
147
  }
@@ -278,7 +277,7 @@ export class FileManager {
278
277
  }): ValidatedColumnInfo["file"] | undefined => {
279
278
  const { colName, tableName } = args;
280
279
  const tableConfig = this.prostgles?.opts.fileTable?.referencedTables?.[tableName];
281
- const isReferencingFileTable = this.dbo[tableName]?.columns?.some(
280
+ const isReferencingFileTable = this.dbo[tableName]?.columns.some(
282
281
  (c) =>
283
282
  c.name === colName &&
284
283
  c.references &&