prostgles-server 4.2.470 → 4.2.472

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 (39) hide show
  1. package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
  2. package/dist/DboBuilder/DboBuilder.js +16 -2
  3. package/dist/DboBuilder/DboBuilder.js.map +1 -1
  4. package/dist/DboBuilder/TableHandler/TableHandler.d.ts +49 -5
  5. package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
  6. package/dist/DboBuilder/TableHandler/TableHandler.js +40 -2
  7. package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
  8. package/dist/DboBuilder/TableHandler/insert/insert.d.ts.map +1 -1
  9. package/dist/DboBuilder/TableHandler/insert/insert.js +4 -6
  10. package/dist/DboBuilder/TableHandler/insert/insert.js.map +1 -1
  11. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.d.ts +1 -1
  12. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.d.ts.map +1 -1
  13. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js +53 -9
  14. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js.map +1 -1
  15. package/dist/DboBuilder/TableHandler/update.js +1 -1
  16. package/dist/DboBuilder/TableHandler/update.js.map +1 -1
  17. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +13 -4
  18. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
  19. package/dist/DboBuilder/ViewHandler/ViewHandler.js +3 -1
  20. package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
  21. package/dist/PublishParser/publishTypesAndUtils.d.ts +18 -5
  22. package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
  23. package/dist/PublishParser/publishTypesAndUtils.js.map +1 -1
  24. package/dist/TableConfig/TableConfig.d.ts +32 -11
  25. package/dist/TableConfig/TableConfig.d.ts.map +1 -1
  26. package/dist/TableConfig/TableConfig.js.map +1 -1
  27. package/dist/TableConfig/getCreateSchemaQueries.d.ts +48 -9
  28. package/dist/TableConfig/getCreateSchemaQueries.d.ts.map +1 -1
  29. package/dist/TableConfig/getTableConfigSchemaQueries.d.ts +55 -16
  30. package/dist/TableConfig/getTableConfigSchemaQueries.d.ts.map +1 -1
  31. package/lib/DboBuilder/DboBuilder.ts +16 -14
  32. package/lib/DboBuilder/TableHandler/TableHandler.ts +80 -16
  33. package/lib/DboBuilder/TableHandler/insert/insert.ts +12 -15
  34. package/lib/DboBuilder/TableHandler/runInsertUpdateQuery.ts +58 -10
  35. package/lib/DboBuilder/TableHandler/update.ts +1 -1
  36. package/lib/DboBuilder/ViewHandler/ViewHandler.ts +18 -7
  37. package/lib/PublishParser/publishTypesAndUtils.ts +25 -5
  38. package/lib/TableConfig/TableConfig.ts +41 -12
  39. package/package.json +1 -1
@@ -7,9 +7,15 @@ import type {
7
7
  Select,
8
8
  UpdateParams,
9
9
  } from "prostgles-types";
10
- import { asName } from "prostgles-types";
10
+ import { asName, isDefined } from "prostgles-types";
11
11
  import type { DB } from "../../Prostgles";
12
- import type { SyncRule, ParsedTableRule } from "../../PublishParser/PublishParser";
12
+ import type {
13
+ SyncRule,
14
+ ParsedTableRule,
15
+ InsertRule,
16
+ UpdateRule,
17
+ DeleteRule,
18
+ } from "../../PublishParser/PublishParser";
13
19
  import type TableConfigurator from "../../TableConfig/TableConfig";
14
20
  import type { DboBuilder, Filter, LocalParams, TableHandlers } from "../DboBuilder";
15
21
  import { getErrorAsObject, getSerializedClientErrorFromPGError } from "../DboBuilder";
@@ -26,6 +32,7 @@ import { update } from "./update";
26
32
  import { updateBatch } from "./updateBatch";
27
33
  import { upsert } from "./upsert";
28
34
  import { COMPUTED_FIELDS } from "../QueryBuilder/Functions/COMPUTED_FIELDS";
35
+ import type { TableDefinition } from "../../TableConfig/TableConfig";
29
36
 
30
37
  export type ValidatedParams = {
31
38
  row: AnyObject;
@@ -39,14 +46,22 @@ export type ValidatedParams = {
39
46
 
40
47
  export class TableHandler extends ViewHandler {
41
48
  dataValidator: DataValidator;
42
- constructor(
43
- db: DB,
44
- tableOrViewInfo: TableSchema,
45
- dboBuilder: DboBuilder,
46
- tx?: { t: pgPromise.ITask<{}>; dbTX: TableHandlers },
47
- joinPaths?: JoinPaths
48
- ) {
49
- super(db, tableOrViewInfo, dboBuilder, tx, joinPaths);
49
+ constructor({
50
+ db,
51
+ config,
52
+ dboBuilder,
53
+ tableOrViewInfo,
54
+ tx,
55
+ joinPaths,
56
+ }: {
57
+ db: DB;
58
+ tableOrViewInfo: TableSchema;
59
+ dboBuilder: DboBuilder;
60
+ config: TableDefinition<any> | undefined;
61
+ tx?: { t: pgPromise.ITask<{}>; dbTX: TableHandlers };
62
+ joinPaths?: JoinPaths;
63
+ }) {
64
+ super({ db, tableOrViewInfo, dboBuilder, config, tx, joinPaths });
50
65
 
51
66
  // eslint-disable-next-line @typescript-eslint/unbound-method
52
67
  this.remove = this.delete;
@@ -59,6 +74,55 @@ export class TableHandler extends ViewHandler {
59
74
  getFinalDBtx = (localParams: LocalParams | undefined) => {
60
75
  return localParams?.tx?.dbTX ?? this.tx?.dbTX;
61
76
  };
77
+
78
+ getHooksAndChecks = (
79
+ command:
80
+ | { name: "update"; rule: undefined | UpdateRule }
81
+ | { name: "insert"; rule: undefined | InsertRule },
82
+ ) => {
83
+ const { checkFilter, postValidate } = command.rule ?? {};
84
+ const afterEachHooks = this.config?.hooks?.afterEach
85
+ ?.map((hook) => {
86
+ const { commands } = hook;
87
+ if (!commands[command.name]) {
88
+ return;
89
+ }
90
+ return {
91
+ type: "afterEach",
92
+ ...hook,
93
+ } as const;
94
+ })
95
+ .filter(isDefined);
96
+
97
+ const afterAllHooks = this.config?.hooks?.afterAll
98
+ ?.map((hook) => {
99
+ const { commands } = hook;
100
+ if (!commands[command.name]) {
101
+ return;
102
+ }
103
+ return {
104
+ type: "afterAll",
105
+ ...hook,
106
+ } as const;
107
+ })
108
+ .filter(isDefined);
109
+ return [
110
+ ...(afterEachHooks ?? []),
111
+ ...(postValidate ? [{ type: "postValidate", validate: postValidate } as const] : []),
112
+ ...(checkFilter ? [{ type: "checkFilter", checkFilter } as const] : []),
113
+ ...(afterAllHooks ?? []),
114
+ ];
115
+ };
116
+ shouldWrapInTx = (
117
+ command:
118
+ | { name: "update"; rule: undefined | UpdateRule }
119
+ | { name: "insert"; rule: undefined | InsertRule },
120
+ localParams: LocalParams | undefined,
121
+ ) => {
122
+ const finalDBtx = this.getFinalDBtx(localParams);
123
+ const hasAfterChecks = this.getHooksAndChecks(command).length > 0;
124
+ return !finalDBtx && hasAfterChecks;
125
+ };
62
126
  getFinalDbo = (localParams: LocalParams | undefined) => {
63
127
  return this.getFinalDBtx(localParams) ?? this.dboBuilder.dbo;
64
128
  };
@@ -73,14 +137,14 @@ export class TableHandler extends ViewHandler {
73
137
  param2?: InsertParams,
74
138
  param3_unused?: undefined,
75
139
  tableRules?: ParsedTableRule,
76
- _localParams?: LocalParams
140
+ _localParams?: LocalParams,
77
141
  ): Promise<any> {
78
142
  return insert.bind(this)(rowOrRows, param2, param3_unused, tableRules, _localParams);
79
143
  }
80
144
 
81
145
  prepareReturning = async (
82
146
  returning: Select | undefined,
83
- allowedFields: string[]
147
+ allowedFields: string[],
84
148
  ): Promise<SelectItemValidated[]> => {
85
149
  const result: SelectItemValidated[] = [];
86
150
  if (returning) {
@@ -111,7 +175,7 @@ export class TableHandler extends ViewHandler {
111
175
  params?: DeleteParams,
112
176
  param3_unused?: undefined,
113
177
  table_rules?: ParsedTableRule,
114
- localParams?: LocalParams
178
+ localParams?: LocalParams,
115
179
  ): Promise<any> {
116
180
  return _delete.bind(this)(filter, params, param3_unused, table_rules, localParams);
117
181
  }
@@ -121,7 +185,7 @@ export class TableHandler extends ViewHandler {
121
185
  params?: UpdateParams,
122
186
  param3_unused?: undefined,
123
187
  tableRules?: ParsedTableRule,
124
- localParams?: LocalParams
188
+ localParams?: LocalParams,
125
189
  ) {
126
190
  return this.delete(filter, params, param3_unused, tableRules, localParams);
127
191
  }
@@ -134,7 +198,7 @@ export class TableHandler extends ViewHandler {
134
198
  params: { select?: FieldFilter },
135
199
  param3_unused: undefined,
136
200
  table_rules: ParsedTableRule,
137
- localParams: LocalParams
201
+ localParams: LocalParams,
138
202
  ) {
139
203
  const start = Date.now();
140
204
  try {
@@ -187,7 +251,7 @@ export class TableHandler extends ViewHandler {
187
251
  { select, limit: 0 },
188
252
  undefined,
189
253
  table_rules,
190
- localParams
254
+ localParams,
191
255
  ).then(async (_isValid) => {
192
256
  const { filterFields, forcedFilter } = table_rules.select || {};
193
257
  const condition = (
@@ -28,24 +28,21 @@ export async function insert(
28
28
  const { removeDisallowedFields = false } = insertParams ?? {};
29
29
  const { returnQuery = false, nestedInsert } = localParams ?? {};
30
30
 
31
- const finalDBtx = this.getFinalDBtx(localParams);
32
31
  const rule = tableRules?.[ACTION];
33
- const { postValidate, checkFilter, validate, allowedNestedInserts, requiredNestedInserts } =
34
- rule ?? {};
32
+ const { validate, allowedNestedInserts, requiredNestedInserts } = rule ?? {};
35
33
 
34
+ const finalDBtx = this.getFinalDBtx(localParams);
36
35
  /** Post validate and checkFilter require a transaction dbo handler because they happen after the insert */
37
- if (postValidate || checkFilter) {
38
- if (!finalDBtx) {
39
- return this.dboBuilder.getTX((_dbtx) =>
40
- _dbtx[this.name]?.[ACTION]?.(
41
- rowOrRows,
42
- insertParams,
43
- param3_unused,
44
- tableRules,
45
- localParams,
46
- ),
47
- );
48
- }
36
+ if (this.shouldWrapInTx({ name: ACTION, rule }, localParams)) {
37
+ return this.dboBuilder.getTX((_dbtx) =>
38
+ _dbtx[this.name]?.[ACTION]?.(
39
+ rowOrRows,
40
+ insertParams,
41
+ param3_unused,
42
+ tableRules,
43
+ localParams,
44
+ ),
45
+ );
49
46
  }
50
47
 
51
48
  const { testOnly, fields, forcedData, returningFields } = await insertTest.bind(this)({
@@ -17,7 +17,7 @@ type RunInsertUpdateQueryArgs = {
17
17
  command: "insert";
18
18
  params: InsertParams | undefined;
19
19
  rule: InsertRule | undefined;
20
- data: AnyObject;
20
+ data: AnyObject | AnyObject[];
21
21
  isMultiInsert: boolean;
22
22
  nestedInsertsResultsObj?: undefined;
23
23
  }
@@ -49,7 +49,7 @@ export const runInsertUpdateQuery = async (args: RunInsertUpdateQueryArgs) => {
49
49
  params?.returning,
50
50
  tableHandler.parseFieldFilter(returningFields),
51
51
  );
52
- const { checkFilter, postValidate } = rule ?? {};
52
+ const { checkFilter } = rule ?? {};
53
53
  let checkCondition = "WHERE FALSE";
54
54
  if (checkFilter) {
55
55
  const checkCond = await tableHandler.prepareWhere({
@@ -111,7 +111,7 @@ export const runInsertUpdateQuery = async (args: RunInsertUpdateQueryArgs) => {
111
111
 
112
112
  const tx = localParams?.tx?.t || tableHandler.tx?.t;
113
113
  if (tx) {
114
- result = await tx[queryType](query).catch((err: any) =>
114
+ result = await tx[queryType](query).catch((err: unknown) =>
115
115
  getClientErrorFromPGError(err, {
116
116
  type: "tableMethod",
117
117
  localParams,
@@ -138,21 +138,69 @@ export const runInsertUpdateQuery = async (args: RunInsertUpdateQueryArgs) => {
138
138
  );
139
139
  }
140
140
 
141
+ const rows = result.modified ?? [];
141
142
  const finalDBtx = tableHandler.getFinalDBtx(localParams);
142
- if (postValidate) {
143
- if (!finalDBtx) throw new Error("Unexpected: no dbTX for postValidate");
144
- if (!localParams) throw new Error("Unexpected: no localParams for postValidate");
143
+ const { postValidate } = rule ?? {};
144
+ const hooks = tableHandler.getHooksAndChecks(
145
+ command === "insert" ? { name: command, rule } : { name: command, rule },
146
+ );
147
+ let changedFieldsSet = undefined as undefined | Set<string>;
148
+ const getChangedFieldsSet = () => {
149
+ changedFieldsSet ??= new Set<string>(rows.map((row) => Object.keys(row)).flat());
150
+ return changedFieldsSet;
151
+ };
152
+ const applicableHooks = hooks.filter((hook) => {
153
+ if (hook.type === "checkFilter") return;
154
+ if (hook.type === "postValidate") return true;
155
+ const { commands, changedFields } = hook;
156
+ return (
157
+ commands[command] &&
158
+ (!changedFields || changedFields.some((f) => getChangedFieldsSet().has(f)))
159
+ );
160
+ });
161
+
162
+ if (postValidate && !localParams) {
163
+ throw new Error("Unexpected: no localParams for postValidate");
164
+ }
165
+
166
+ if (applicableHooks.length) {
167
+ if (!finalDBtx) throw new Error("Unexpected: no dbTX for hooks/postValidate");
145
168
 
146
- const rows = result.modified ?? [];
147
169
  for (const row of rows) {
148
- await postValidate({
170
+ const commonParams = {
149
171
  row: row,
150
172
  tx: tx || tableHandler.db,
151
173
  dbx: finalDBtx,
152
- localParams,
153
174
  command,
154
175
  data,
155
- });
176
+ } as const;
177
+ for (const hook of applicableHooks) {
178
+ if (hook.type === "afterEach") {
179
+ await hook.validate({
180
+ ...commonParams,
181
+ localParams,
182
+ });
183
+ } else if (hook.type === "postValidate") {
184
+ if (!localParams) throw new Error("Unexpected: no localParams for postValidate");
185
+ await hook.validate({
186
+ ...commonParams,
187
+ localParams,
188
+ });
189
+ }
190
+ }
191
+ }
192
+
193
+ for (const hook of applicableHooks) {
194
+ if (hook.type === "afterAll") {
195
+ await hook.validate({
196
+ tx: tx || tableHandler.db,
197
+ dbx: finalDBtx,
198
+ command,
199
+ data: Array.isArray(data) ? data : [data],
200
+ rows,
201
+ localParams,
202
+ });
203
+ }
156
204
  }
157
205
  }
158
206
 
@@ -32,7 +32,7 @@ export async function update(
32
32
  ),
33
33
  );
34
34
  const rule = tableRules?.[ACTION];
35
- if (rule?.postValidate && !finalDBtx) {
35
+ if (this.shouldWrapInTx({ name: ACTION, rule }, localParams)) {
36
36
  return wrapInTx();
37
37
  }
38
38
 
@@ -28,6 +28,7 @@ import type { OnData } from "./subscribe";
28
28
  import { subscribe } from "./subscribe";
29
29
  import { validateViewRules } from "./validateViewRules";
30
30
  import { escapeTSNames } from "../../utils/utils";
31
+ import type { TableDefinition } from "../../TableConfig/TableConfig";
31
32
 
32
33
  export type JoinPaths = {
33
34
  t1: string;
@@ -48,6 +49,7 @@ export class ViewHandler {
48
49
  joinGraph?: Graph;
49
50
  joinPaths?: JoinPaths;
50
51
  dboBuilder: DboBuilder;
52
+ config: TableDefinition<any> | undefined;
51
53
 
52
54
  tx?: {
53
55
  t: pgPromise.ITask<{}>;
@@ -60,13 +62,22 @@ export class ViewHandler {
60
62
  is_view = true;
61
63
  filterDef = "";
62
64
  is_media = false;
63
- constructor(
64
- db: DB,
65
- tableOrViewInfo: TableSchema,
66
- dboBuilder: DboBuilder,
67
- tx?: { t: pgPromise.ITask<{}>; dbTX: TableHandlers },
68
- joinPaths?: JoinPaths,
69
- ) {
65
+ constructor({
66
+ db,
67
+ config,
68
+ dboBuilder,
69
+ tableOrViewInfo,
70
+ tx,
71
+ joinPaths,
72
+ }: {
73
+ db: DB;
74
+ tableOrViewInfo: TableSchema;
75
+ dboBuilder: DboBuilder;
76
+ config: TableDefinition<any> | undefined;
77
+ tx?: { t: pgPromise.ITask<{}>; dbTX: TableHandlers };
78
+ joinPaths?: JoinPaths;
79
+ }) {
80
+ this.config = config;
70
81
  this.db = db;
71
82
  this.tx = tx;
72
83
  this.joinPaths = joinPaths;
@@ -181,7 +181,6 @@ export type ValidateRowArgsCommon<R = AnyObject, DBX = DBHandlerServer> = {
181
181
  row: R;
182
182
  dbx: DBX;
183
183
  tx: pgPromise.ITask<{}> | DB;
184
- localParams: LocalParams;
185
184
  } & (
186
185
  | {
187
186
  command: "insert";
@@ -193,6 +192,27 @@ export type ValidateRowArgsCommon<R = AnyObject, DBX = DBHandlerServer> = {
193
192
  }
194
193
  );
195
194
 
195
+ export type ValidateRowsArgsCommon<R = AnyObject, DBX = DBHandlerServer> = {
196
+ rows: R[];
197
+ dbx: DBX;
198
+ tx: pgPromise.ITask<{}> | DB;
199
+ } & (
200
+ | {
201
+ command: "insert";
202
+ data: R[];
203
+ }
204
+ | {
205
+ command: "update";
206
+ data: Partial<R>[];
207
+ }
208
+ );
209
+
210
+ export type ValidateRowArgs<R = AnyObject, DBX = DBHandlerServer> = ValidateRowArgsCommon<
211
+ R,
212
+ DBX
213
+ > & {
214
+ localParams: LocalParams;
215
+ };
196
216
  export type ValidateUpdateRowArgs<U = Partial<AnyObject>, F = Filter, DBX = DBHandlerServer> = {
197
217
  update: U;
198
218
  filter: F;
@@ -200,13 +220,13 @@ export type ValidateUpdateRowArgs<U = Partial<AnyObject>, F = Filter, DBX = DBHa
200
220
  localParams: LocalParams;
201
221
  };
202
222
  export type ValidateRow<R extends AnyObject = AnyObject, S = void> = (
203
- args: ValidateRowArgsCommon<R, DBOFullyTyped<S>>,
223
+ args: ValidateRowArgs<R, DBOFullyTyped<S>>,
204
224
  ) => R | Promise<R>;
205
225
  export type PostValidateRow<R extends AnyObject = AnyObject, S = void> = (
206
- args: ValidateRowArgsCommon<R, DBOFullyTyped<S>>,
226
+ args: ValidateRowArgs<R, DBOFullyTyped<S>>,
207
227
  ) => void | Promise<void>;
208
- export type PostValidateRowBasic = (args: ValidateRowArgsCommon) => void | Promise<void>;
209
- export type ValidateRowBasic = (args: ValidateRowArgsCommon) => AnyObject | Promise<AnyObject>;
228
+ export type PostValidateRowBasic = (args: ValidateRowArgs) => void | Promise<void>;
229
+ export type ValidateRowBasic = (args: ValidateRowArgs) => AnyObject | Promise<AnyObject>;
210
230
  export type ValidateUpdateRow<R extends AnyObject = AnyObject, S extends DBSchema | void = void> = (
211
231
  args: ValidateUpdateRowArgs<Partial<R>, FullFilter<R, S>, DBOFullyTyped<S>>,
212
232
  ) => Partial<R> | Promise<Partial<R>>;
@@ -3,6 +3,7 @@ import type {
3
3
  ALLOWED_EXTENSION,
4
4
  AnyObject,
5
5
  ColumnInfo,
6
+ DBSchema,
6
7
  JSONB,
7
8
  StrictUnion,
8
9
  TableInfo,
@@ -12,7 +13,11 @@ import type { JoinInfo, LocalParams } from "../DboBuilder/DboBuilder";
12
13
  import type { TableHandler } from "../DboBuilder/TableHandler/TableHandler";
13
14
  import { uploadFile } from "../DboBuilder/uploadFile";
14
15
  import type { DB, DBHandlerServer, Prostgles } from "../Prostgles";
15
- import type { InsertRule, ValidateRowArgsCommon } from "../PublishParser/PublishParser";
16
+ import type {
17
+ InsertRule,
18
+ ValidateRowArgsCommon,
19
+ ValidateRowsArgsCommon,
20
+ } from "../PublishParser/PublishParser";
16
21
  import { initTableConfig } from "./initTableConfig";
17
22
 
18
23
  type ColExtraInfo = {
@@ -41,7 +46,7 @@ export const parseI18N = <Config extends LangToTranslation>(params: {
41
46
  return defaultValue;
42
47
  };
43
48
 
44
- type BaseTableDefinition = {
49
+ type BaseTableDefinition<R = AnyObject, DBX = DBHandlerServer> = {
45
50
  info?: {
46
51
  label?: string | LangToTranslation;
47
52
  };
@@ -55,6 +60,24 @@ type BaseTableDefinition = {
55
60
  getPreInsertRow?: (
56
61
  args: GetPreInsertRowArgs,
57
62
  ) => Promise<{ row: AnyObject; onInserted: Promise<void> }>;
63
+ afterEach?: {
64
+ commands: Partial<Record<"insert" | "update", 1>>;
65
+ changedFields?: string[];
66
+ validate: <R = AnyObject, DBX = DBHandlerServer>(
67
+ params: ValidateRowArgsCommon<R, DBX> & {
68
+ localParams: undefined | LocalParams;
69
+ },
70
+ ) => Promise<void>;
71
+ }[];
72
+ afterAll?: {
73
+ commands: Partial<Record<"insert" | "update", 1>>;
74
+ changedFields?: string[];
75
+ validate: <R = AnyObject, DBX = DBHandlerServer>(
76
+ params: ValidateRowsArgsCommon<R, DBX> & {
77
+ localParams: undefined | LocalParams;
78
+ },
79
+ ) => Promise<void>;
80
+ }[];
58
81
  };
59
82
  triggers?: {
60
83
  [triggerName: string]: {
@@ -89,7 +112,7 @@ type BaseTableDefinition = {
89
112
  };
90
113
  };
91
114
 
92
- type LookupTableDefinition<LANG_IDS> = {
115
+ type LookupTableDefinition<LANG_IDS> = BaseTableDefinition & {
93
116
  isLookupTable: {
94
117
  values: {
95
118
  [id_value: string]:
@@ -230,7 +253,11 @@ type ConstraintType = "PRIMARY KEY" | "UNIQUE" | "CHECK" | "FOREIGN KEY";
230
253
  * Each column definition cannot reference to tables that appear later in the table definition.
231
254
  * These references should be specified in constraints property
232
255
  */
233
- export type TableDefinition<LANG_IDS> = {
256
+ export type TableDefinition<
257
+ LANG_IDS = { en: 1 },
258
+ R = AnyObject,
259
+ DBX = DBHandlerServer,
260
+ > = BaseTableDefinition<R, DBX> & {
234
261
  onMount?: (params: {
235
262
  dbo: DBHandlerServer;
236
263
  _db: DB;
@@ -318,18 +345,20 @@ export type TableDefinition<LANG_IDS> = {
318
345
  };
319
346
 
320
347
  type GetPreInsertRowArgs = Omit<ValidateRowArgsCommon, "localParams"> & {
321
- // preValidate: InsertRule["preValidate"];
322
348
  validate: InsertRule["validate"];
323
349
  localParams: LocalParams | undefined;
324
350
  };
325
351
 
326
- /**
327
- * Helper utility to create lookup tables for TEXT columns
328
- */
329
- export type TableConfig<LANG_IDS = { en: 1 }> = {
330
- [table_name: string]: BaseTableDefinition &
331
- (TableDefinition<LANG_IDS> | LookupTableDefinition<LANG_IDS>);
332
- };
352
+ export type TableConfig<LANG_IDS = { en: 1 }, S = void, DBX = DBHandlerServer> =
353
+ S extends DBSchema ?
354
+ {
355
+ [TableName in keyof S]:
356
+ | TableDefinition<LANG_IDS, S[TableName]["columns"], DBX>
357
+ | LookupTableDefinition<LANG_IDS>;
358
+ }
359
+ : {
360
+ [table_name: string]: TableDefinition<LANG_IDS> | LookupTableDefinition<LANG_IDS>;
361
+ };
333
362
 
334
363
  /**
335
364
  * Will be run between initSQL and fileTable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "4.2.470",
3
+ "version": "4.2.472",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",