prostgles-server 4.2.582 → 4.2.584
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/DBSchemaBuilder/resolveTypeToStructure.d.ts.map +1 -1
- package/dist/DBSchemaBuilder/resolveTypeToStructure.js +12 -0
- package/dist/DBSchemaBuilder/resolveTypeToStructure.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +6 -4
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts +8 -6
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.js +6 -6
- package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
- package/dist/DboBuilder/TableHandler/delete.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/delete.js +1 -1
- package/dist/DboBuilder/TableHandler/delete.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +4 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +3 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/schema/getTablesForSchemaPostgresSQL.d.ts +1 -1
- package/dist/Prostgles.d.ts +4 -50
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +9 -6
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesTypes.d.ts +5 -0
- package/dist/ProstglesTypes.d.ts.map +1 -1
- package/dist/ProstglesTypes.js.map +1 -1
- package/dist/StorageClient/getFileTableConfig.d.ts +5 -1
- package/dist/StorageClient/getFileTableConfig.d.ts.map +1 -1
- package/dist/StorageClient/getFileTableConfig.js +57 -50
- package/dist/StorageClient/getFileTableConfig.js.map +1 -1
- package/dist/TableConfig/TableConfigTypes.d.ts +6 -38
- package/dist/TableConfig/TableConfigTypes.d.ts.map +1 -1
- package/dist/TableConfig/TableConfigurator.d.ts +1 -51
- package/dist/TableConfig/TableConfigurator.d.ts.map +1 -1
- package/dist/TableConfig/TableConfigurator.js +1 -1
- package/dist/TableConfig/TableConfigurator.js.map +1 -1
- package/dist/TableConfig/getCreateSchemaQueries.d.ts +3 -102
- package/dist/TableConfig/getCreateSchemaQueries.d.ts.map +1 -1
- package/dist/TableConfig/getTableConfigSchemaQueries.d.ts +3 -102
- package/dist/TableConfig/getTableConfigSchemaQueries.d.ts.map +1 -1
- package/dist/TableHooks/TableHooks.d.ts +38 -0
- package/dist/TableHooks/TableHooks.d.ts.map +1 -0
- package/dist/TableHooks/TableHooks.js +3 -0
- package/dist/TableHooks/TableHooks.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/updateConfiguration.d.ts.map +1 -1
- package/dist/updateConfiguration.js +8 -2
- package/dist/updateConfiguration.js.map +1 -1
- package/lib/DBSchemaBuilder/resolveTypeToStructure.ts +18 -0
- package/lib/DboBuilder/DboBuilder.ts +6 -4
- package/lib/DboBuilder/TableHandler/TableHandler.ts +8 -7
- package/lib/DboBuilder/TableHandler/delete.ts +2 -3
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +5 -0
- package/lib/Prostgles.ts +11 -6
- package/lib/ProstglesTypes.ts +6 -0
- package/lib/StorageClient/getFileTableConfig.ts +66 -59
- package/lib/TableConfig/TableConfigTypes.ts +5 -43
- package/lib/TableConfig/TableConfigurator.ts +1 -1
- package/lib/TableHooks/TableHooks.ts +48 -0
- package/lib/index.ts +1 -0
- package/lib/updateConfiguration.ts +8 -2
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { omitKeys } from "prostgles-types";
|
|
2
|
+
import { onDeleteFromFileTable } from "../DboBuilder/TableHandler/onDeleteFromFileTable";
|
|
2
3
|
import { updateFile } from "../DboBuilder/TableHandler/updateFile";
|
|
3
4
|
import { assertFileObjectValid, uploadFile } from "../DboBuilder/TableHandler/uploadFile";
|
|
4
5
|
import type { Prostgles } from "../Prostgles";
|
|
6
|
+
import type { BeforeEachTsTrigger } from "../PublishParser/publishTypesAndUtils";
|
|
5
7
|
import type { TableConfig } from "../TableConfig/TableConfigTypes";
|
|
8
|
+
import type { TableHooks } from "../TableHooks/TableHooks";
|
|
6
9
|
import { setupFileServeHandler } from "./setupFileServeHandler";
|
|
7
|
-
import { onDeleteFromFileTable } from "../DboBuilder/TableHandler/onDeleteFromFileTable";
|
|
8
|
-
import type { BeforeEachTsTrigger } from "../PublishParser/publishTypesAndUtils";
|
|
9
10
|
|
|
10
11
|
const FILE_TABLE_COLUMN_DEFINITIONS = {
|
|
11
12
|
id: `UUID PRIMARY KEY DEFAULT gen_random_uuid()`,
|
|
@@ -41,10 +42,12 @@ export type FileTableRow = {
|
|
|
41
42
|
: string | null;
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
export const getFileTableConfig = (
|
|
45
|
-
|
|
45
|
+
export const getFileTableConfig = (
|
|
46
|
+
prg: Prostgles,
|
|
47
|
+
): { tableConfig: TableConfig | undefined; tableHooks: TableHooks | undefined } => {
|
|
48
|
+
const { fileTable, tableConfig, tableHooks } = prg.opts;
|
|
46
49
|
if (!fileTable) {
|
|
47
|
-
return tableConfig;
|
|
50
|
+
return { tableConfig, tableHooks };
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
const { expressApp } = fileTable;
|
|
@@ -76,7 +79,7 @@ export const getFileTableConfig = (prg: Prostgles): TableConfig | undefined => {
|
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
|
|
82
|
+
const mergedTableConfig: TableConfig = {
|
|
80
83
|
[fileTableName]: {
|
|
81
84
|
...userFileTableConfig,
|
|
82
85
|
columns: {
|
|
@@ -94,71 +97,75 @@ export const getFileTableConfig = (prg: Prostgles): TableConfig | undefined => {
|
|
|
94
97
|
onUnmount: destroy,
|
|
95
98
|
};
|
|
96
99
|
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
{
|
|
101
|
-
commands: {
|
|
102
|
-
insert: 1,
|
|
103
|
-
update: 1,
|
|
104
|
-
},
|
|
105
|
-
validate: async ({ data: insertData, localParams, command, filter }) => {
|
|
106
|
-
const tableHandler = prg.dboBuilder.dboMap.get(fileTableName);
|
|
107
|
-
if (!tableHandler) throw "Storage tableHandler not found";
|
|
108
|
-
assertFileObjectValid(insertData);
|
|
100
|
+
},
|
|
101
|
+
...omitKeys(tableConfig ?? {}, [fileTableName]),
|
|
102
|
+
};
|
|
109
103
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
return {
|
|
126
|
-
row: newData,
|
|
127
|
-
hookContext: {
|
|
128
|
-
data,
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
104
|
+
const userFileTableHooks = tableHooks?.[fileTableName];
|
|
105
|
+
const mergedTableHooks: TableHooks = {
|
|
106
|
+
[fileTableName]: {
|
|
107
|
+
...userFileTableHooks,
|
|
108
|
+
beforeEach: [
|
|
109
|
+
{
|
|
110
|
+
commands: {
|
|
111
|
+
insert: 1,
|
|
112
|
+
update: 1,
|
|
113
|
+
},
|
|
114
|
+
validate: async ({ data: insertData, localParams, command, filter }) => {
|
|
115
|
+
const tableHandler = prg.dboBuilder.dboMap.get(fileTableName);
|
|
116
|
+
if (!tableHandler) throw "Storage tableHandler not found";
|
|
117
|
+
assertFileObjectValid(insertData);
|
|
132
118
|
|
|
133
|
-
|
|
119
|
+
const { data: dataBlob, original_name, id, original_last_modified = null } = insertData;
|
|
120
|
+
const data = dataBlob as unknown as Buffer;
|
|
121
|
+
if (command === "update") {
|
|
122
|
+
const { newData } = await updateFile(tableHandler, fileTable, {
|
|
123
|
+
filter: filter ?? {},
|
|
124
|
+
localParams,
|
|
134
125
|
data,
|
|
135
126
|
original_name,
|
|
136
|
-
localParams,
|
|
137
|
-
mediaId: id,
|
|
138
127
|
original_last_modified,
|
|
139
128
|
});
|
|
140
|
-
|
|
141
129
|
return {
|
|
142
|
-
row:
|
|
130
|
+
row: newData,
|
|
143
131
|
hookContext: {
|
|
144
132
|
data,
|
|
145
133
|
},
|
|
146
134
|
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const media = await uploadFile(fileTable, {
|
|
138
|
+
data,
|
|
139
|
+
original_name,
|
|
140
|
+
localParams,
|
|
141
|
+
mediaId: id,
|
|
142
|
+
original_last_modified,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
row: media,
|
|
147
|
+
hookContext: {
|
|
148
|
+
data,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
} satisfies BeforeEachTsTrigger<FileTableRow, {}>,
|
|
153
|
+
...(userFileTableHooks?.beforeEach || []),
|
|
154
|
+
],
|
|
155
|
+
onInsteadOfDelete: async ({ dbx, tx, returningQuery, isOneOrNone, filterOpts }) => {
|
|
156
|
+
return onDeleteFromFileTable(fileTable, {
|
|
157
|
+
dbTX: dbx,
|
|
158
|
+
t: tx,
|
|
159
|
+
returningQuery,
|
|
160
|
+
isOneOrNone,
|
|
161
|
+
filterOpts,
|
|
162
|
+
});
|
|
160
163
|
},
|
|
161
164
|
},
|
|
162
|
-
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
tableConfig: mergedTableConfig,
|
|
169
|
+
tableHooks: mergedTableHooks,
|
|
163
170
|
};
|
|
164
171
|
};
|
|
@@ -28,36 +28,14 @@ export type ColExtraInfo = {
|
|
|
28
28
|
|
|
29
29
|
export type LangToTranslation = Record<string, string>;
|
|
30
30
|
|
|
31
|
-
type BaseTableDefinition
|
|
31
|
+
type BaseTableDefinition = {
|
|
32
32
|
info?: {
|
|
33
33
|
label?: string | LangToTranslation;
|
|
34
34
|
};
|
|
35
35
|
dropIfExistsCascade?: boolean;
|
|
36
36
|
dropIfExists?: boolean;
|
|
37
37
|
syncConfig?: SyncConfig;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Hook used to run custom logic before inserting a row.
|
|
41
|
-
* The returned row must satisfy the table schema.
|
|
42
|
-
*/
|
|
43
|
-
getPreInsertRow?: (
|
|
44
|
-
args: GetPreInsertRowArgs,
|
|
45
|
-
) => Promise<{ row: AnyObject; onInserted: Promise<void> }>;
|
|
46
|
-
beforeEach?: BeforeEachTsTrigger<R, DBX>[];
|
|
47
|
-
afterEach?: AfterEachTsTrigger<R, DBX>[];
|
|
48
|
-
afterAll?: AfterAllTsTrigger<R, DBX>[];
|
|
49
|
-
onInsteadOfDelete?: (args: {
|
|
50
|
-
dbx: DBX;
|
|
51
|
-
tx: pgPromise.ITask<{}>;
|
|
52
|
-
returningQuery: string;
|
|
53
|
-
isOneOrNone: boolean;
|
|
54
|
-
queryType: "any" | "none";
|
|
55
|
-
filterOpts: {
|
|
56
|
-
where: string;
|
|
57
|
-
filter: AnyObject;
|
|
58
|
-
};
|
|
59
|
-
}) => Promise<AnyObject[]>;
|
|
60
|
-
};
|
|
38
|
+
|
|
61
39
|
triggers?: {
|
|
62
40
|
[triggerName: string]: {
|
|
63
41
|
/**
|
|
@@ -232,11 +210,7 @@ type ConstraintType = "PRIMARY KEY" | "UNIQUE" | "CHECK" | "FOREIGN KEY";
|
|
|
232
210
|
* Each column definition cannot reference to tables that appear later in the table definition.
|
|
233
211
|
* These references should be specified in constraints property
|
|
234
212
|
*/
|
|
235
|
-
export type TableDefinition<
|
|
236
|
-
LANG_IDS = { en: 1 },
|
|
237
|
-
R = AnyObject,
|
|
238
|
-
DBX = DBHandlerServer,
|
|
239
|
-
> = BaseTableDefinition<R, DBX> & {
|
|
213
|
+
export type TableDefinition<LANG_IDS = { en: 1 }> = BaseTableDefinition & {
|
|
240
214
|
onMount?: (params: {
|
|
241
215
|
dbo: DBHandlerServer;
|
|
242
216
|
_db: DB;
|
|
@@ -323,18 +297,6 @@ export type TableDefinition<
|
|
|
323
297
|
};
|
|
324
298
|
};
|
|
325
299
|
|
|
326
|
-
type
|
|
327
|
-
|
|
328
|
-
localParams: LocalParams | undefined;
|
|
300
|
+
export type TableConfig<LANG_IDS = { en: 1 }> = {
|
|
301
|
+
[table_name: string]: TableDefinition<LANG_IDS> | LookupTableDefinition<LANG_IDS>;
|
|
329
302
|
};
|
|
330
|
-
|
|
331
|
-
export type TableConfig<LANG_IDS = { en: 1 }, S = void> =
|
|
332
|
-
S extends DBSchema ?
|
|
333
|
-
Partial<{
|
|
334
|
-
[TableName in keyof S]:
|
|
335
|
-
| TableDefinition<LANG_IDS, S[TableName]["columns"], DBOFullyTyped<S>>
|
|
336
|
-
| LookupTableDefinition<LANG_IDS>;
|
|
337
|
-
}>
|
|
338
|
-
: {
|
|
339
|
-
[table_name: string]: TableDefinition<LANG_IDS> | LookupTableDefinition<LANG_IDS>;
|
|
340
|
-
};
|
|
@@ -16,7 +16,7 @@ export class TableConfigurator {
|
|
|
16
16
|
instanceId = Date.now() + Math.random();
|
|
17
17
|
|
|
18
18
|
get config() {
|
|
19
|
-
return this.prostgles.mergedTableConfig ?? {};
|
|
19
|
+
return this.prostgles.mergedTableConfig.tableConfig ?? {};
|
|
20
20
|
}
|
|
21
21
|
get dbo(): DBHandlerServer {
|
|
22
22
|
if (!this.prostgles.dbo) throw "this.prostgles.dbo missing";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type pgPromise from "pg-promise";
|
|
2
|
+
import type { AnyObject, DBSchema } from "prostgles-types";
|
|
3
|
+
|
|
4
|
+
import type { DbTxTableHandlers, LocalParams } from "../DboBuilder/DboBuilderTypes";
|
|
5
|
+
import type { DBOFullyTyped } from "../DBSchemaBuilder/DBSchemaBuilder";
|
|
6
|
+
import type {
|
|
7
|
+
AfterAllTsTrigger,
|
|
8
|
+
AfterEachTsTrigger,
|
|
9
|
+
BeforeEachTsTrigger,
|
|
10
|
+
InsertRule,
|
|
11
|
+
ValidateRowArgsCommon,
|
|
12
|
+
} from "../PublishParser/PublishParser";
|
|
13
|
+
|
|
14
|
+
export type TableHooks<S = void> =
|
|
15
|
+
S extends DBSchema ?
|
|
16
|
+
Partial<{
|
|
17
|
+
[tableName in keyof S]: TableHooksDefinition<S[tableName]["columns"], DBOFullyTyped<S>>;
|
|
18
|
+
}>
|
|
19
|
+
: Record<string, TableHooksDefinition>;
|
|
20
|
+
|
|
21
|
+
export type TableHooksDefinition<R = AnyObject, DBX = DbTxTableHandlers> = {
|
|
22
|
+
/**
|
|
23
|
+
* Hook used to run custom logic before inserting a row.
|
|
24
|
+
* The returned row must satisfy the table schema.
|
|
25
|
+
*/
|
|
26
|
+
getPreInsertRow?: (
|
|
27
|
+
args: PreInsertRowArgs,
|
|
28
|
+
) => Promise<{ row: AnyObject; onInserted: Promise<void> }>;
|
|
29
|
+
beforeEach?: BeforeEachTsTrigger<R, DBX>[];
|
|
30
|
+
afterEach?: AfterEachTsTrigger<R, DBX>[];
|
|
31
|
+
afterAll?: AfterAllTsTrigger<R, DBX>[];
|
|
32
|
+
onInsteadOfDelete?: (args: {
|
|
33
|
+
dbx: DBX;
|
|
34
|
+
tx: pgPromise.ITask<{}>;
|
|
35
|
+
returningQuery: string;
|
|
36
|
+
isOneOrNone: boolean;
|
|
37
|
+
queryType: "any" | "none";
|
|
38
|
+
filterOpts: {
|
|
39
|
+
where: string;
|
|
40
|
+
filter: AnyObject;
|
|
41
|
+
};
|
|
42
|
+
}) => Promise<AnyObject[] | undefined>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type PreInsertRowArgs = Omit<ValidateRowArgsCommon, "localParams"> & {
|
|
46
|
+
validate: InsertRule["validate"];
|
|
47
|
+
localParams: LocalParams | undefined;
|
|
48
|
+
};
|
package/lib/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type { StorageClient as CloudClient } from "./StorageClient/StorageClient
|
|
|
20
20
|
export * from "./StorageClient/getLocalStorageClient";
|
|
21
21
|
export type { DB } from "./initProstgles";
|
|
22
22
|
export type * from "./TableConfig/TableConfigTypes";
|
|
23
|
+
export type * from "./TableHooks/TableHooks";
|
|
23
24
|
export * from "./Auth/utils/upsertNamedExpressMiddleware";
|
|
24
25
|
export type { RequestWithUser } from "./Auth/middleware/userContextMiddleware";
|
|
25
26
|
export default prostgles;
|
|
@@ -29,7 +29,10 @@ export const updateConfiguration = async <DBSchema, UserSchema extends SessionUs
|
|
|
29
29
|
prgl.initRestApi();
|
|
30
30
|
}
|
|
31
31
|
if (includes(optionsThatChanged, "tableConfig")) {
|
|
32
|
-
await prgl.initTableConfig({
|
|
32
|
+
await prgl.initTableConfig({
|
|
33
|
+
type: "prgl.update",
|
|
34
|
+
newOpts: newOpts,
|
|
35
|
+
});
|
|
33
36
|
}
|
|
34
37
|
if (includes(optionsThatChanged, "schema")) {
|
|
35
38
|
await prgl.refreshDBO();
|
|
@@ -61,7 +64,10 @@ export const updateConfiguration = async <DBSchema, UserSchema extends SessionUs
|
|
|
61
64
|
) {
|
|
62
65
|
prgl.setupSocketIO();
|
|
63
66
|
} else {
|
|
64
|
-
await prgl.init(onReady, {
|
|
67
|
+
await prgl.init(onReady, {
|
|
68
|
+
type: "prgl.update",
|
|
69
|
+
newOpts: newOpts,
|
|
70
|
+
});
|
|
65
71
|
}
|
|
66
72
|
};
|
|
67
73
|
|