prostgles-server 4.2.583 → 4.2.585

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 (59) hide show
  1. package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
  2. package/dist/DboBuilder/DboBuilder.js +6 -4
  3. package/dist/DboBuilder/DboBuilder.js.map +1 -1
  4. package/dist/DboBuilder/TableHandler/TableHandler.d.ts +8 -6
  5. package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
  6. package/dist/DboBuilder/TableHandler/TableHandler.js +6 -6
  7. package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
  8. package/dist/DboBuilder/TableHandler/delete.d.ts.map +1 -1
  9. package/dist/DboBuilder/TableHandler/delete.js +1 -1
  10. package/dist/DboBuilder/TableHandler/delete.js.map +1 -1
  11. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +4 -1
  12. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
  13. package/dist/DboBuilder/ViewHandler/ViewHandler.js +3 -1
  14. package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
  15. package/dist/DboBuilder/schema/getTablesForSchemaPostgresSQL.d.ts +1 -1
  16. package/dist/Prostgles.d.ts +4 -50
  17. package/dist/Prostgles.d.ts.map +1 -1
  18. package/dist/Prostgles.js +9 -6
  19. package/dist/Prostgles.js.map +1 -1
  20. package/dist/ProstglesTypes.d.ts +5 -0
  21. package/dist/ProstglesTypes.d.ts.map +1 -1
  22. package/dist/ProstglesTypes.js.map +1 -1
  23. package/dist/StorageClient/getFileTableConfig.d.ts +5 -1
  24. package/dist/StorageClient/getFileTableConfig.d.ts.map +1 -1
  25. package/dist/StorageClient/getFileTableConfig.js +57 -50
  26. package/dist/StorageClient/getFileTableConfig.js.map +1 -1
  27. package/dist/TableConfig/TableConfigTypes.d.ts +6 -38
  28. package/dist/TableConfig/TableConfigTypes.d.ts.map +1 -1
  29. package/dist/TableConfig/TableConfigurator.d.ts +1 -51
  30. package/dist/TableConfig/TableConfigurator.d.ts.map +1 -1
  31. package/dist/TableConfig/TableConfigurator.js +1 -1
  32. package/dist/TableConfig/TableConfigurator.js.map +1 -1
  33. package/dist/TableConfig/getCreateSchemaQueries.d.ts +3 -102
  34. package/dist/TableConfig/getCreateSchemaQueries.d.ts.map +1 -1
  35. package/dist/TableConfig/getTableConfigSchemaQueries.d.ts +3 -102
  36. package/dist/TableConfig/getTableConfigSchemaQueries.d.ts.map +1 -1
  37. package/dist/TableHooks/TableHooks.d.ts +38 -0
  38. package/dist/TableHooks/TableHooks.d.ts.map +1 -0
  39. package/dist/TableHooks/TableHooks.js +3 -0
  40. package/dist/TableHooks/TableHooks.js.map +1 -0
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/updateConfiguration.d.ts.map +1 -1
  45. package/dist/updateConfiguration.js +8 -2
  46. package/dist/updateConfiguration.js.map +1 -1
  47. package/lib/DboBuilder/DboBuilder.ts +6 -4
  48. package/lib/DboBuilder/TableHandler/TableHandler.ts +8 -7
  49. package/lib/DboBuilder/TableHandler/delete.ts +2 -3
  50. package/lib/DboBuilder/ViewHandler/ViewHandler.ts +5 -0
  51. package/lib/Prostgles.ts +11 -6
  52. package/lib/ProstglesTypes.ts +6 -0
  53. package/lib/StorageClient/getFileTableConfig.ts +66 -59
  54. package/lib/TableConfig/TableConfigTypes.ts +5 -43
  55. package/lib/TableConfig/TableConfigurator.ts +1 -1
  56. package/lib/TableHooks/TableHooks.ts +51 -0
  57. package/lib/index.ts +1 -0
  58. package/lib/updateConfiguration.ts +8 -2
  59. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"getCreateSchemaQueries.d.ts","sourceRoot":"","sources":["../../lib/TableConfig/getCreateSchemaQueries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,E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CACrC,iBAAiB,CAAC,oBAAoB,CAAC,EACvC,uBAAuB,GAAG,aAAa,GAAG,WAAW,GAAG,aAAa,GAAG,OAAO,CAChF,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,IAAI,EAAE,EACN,wCAAwC,oBAAoB,EAC5D,mBAAmB,MAAM;;;;;;;;;;0BAqFH,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;;;;;0BAUb,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;;;;;;EA9DhD,CAAC"}
@@ -1,57 +1,8 @@
1
1
  import { type SchemaRelatedOptions } from "./getCreateSchemaQueries";
2
+ import type { TableConfig } from "./TableConfigTypes";
2
3
  import type { getSchemaUtils } from "./tableConfigSchemaUtils";
3
4
  export declare const getTableConfigSchemaQueries: (opts: SchemaRelatedOptions, { asName, db }: Pick<Awaited<ReturnType<typeof getSchemaUtils>>, "asName" | "db">) => Promise<{
4
- config: {
5
- [table_name: string]: import("./TableConfigTypes").TableDefinition<{
6
- en: 1;
7
- }, import("prostgles-types").AnyObject, import("..").DBHandlerServer> | ({
8
- info?: {
9
- label?: string | import("./TableConfigTypes").LangToTranslation;
10
- };
11
- dropIfExistsCascade?: boolean;
12
- dropIfExists?: boolean;
13
- syncConfig?: import("../PublishParser/publishTypesAndUtils").SyncConfig;
14
- hooks?: {
15
- getPreInsertRow?: (args: Omit<import("../PublishParser/publishTypesAndUtils").ValidateRowArgsCommon, "localParams"> & {
16
- validate: import("../PublishParser/publishTypesAndUtils").InsertRule["validate"];
17
- localParams: import("../DboBuilder/DboBuilderTypes").LocalParams | undefined;
18
- }) => Promise<{
19
- row: import("prostgles-types").AnyObject;
20
- onInserted: Promise<void>;
21
- }>;
22
- beforeEach?: import("../PublishParser/publishTypesAndUtils").BeforeEachTsTrigger<import("prostgles-types").AnyObject, import("..").DBHandlerServer>[] | undefined;
23
- afterEach?: import("../PublishParser/publishTypesAndUtils").AfterEachTsTrigger<import("prostgles-types").AnyObject, import("..").DBHandlerServer>[] | undefined;
24
- afterAll?: import("../PublishParser/publishTypesAndUtils").AfterAllTsTrigger<import("prostgles-types").AnyObject, import("..").DBHandlerServer>[] | undefined;
25
- onInsteadOfDelete?: ((args: {
26
- dbx: import("..").DBHandlerServer;
27
- tx: import("pg-promise").ITask<{}>;
28
- returningQuery: string;
29
- isOneOrNone: boolean;
30
- queryType: "any" | "none";
31
- filterOpts: {
32
- where: string;
33
- filter: import("prostgles-types").AnyObject;
34
- };
35
- }) => Promise<import("prostgles-types").AnyObject[]>) | undefined;
36
- } | undefined;
37
- triggers?: {
38
- [triggerName: string]: {
39
- type: "before" | "after" | "instead of";
40
- actions: ("insert" | "update" | "delete")[];
41
- forEach: "statement" | "row";
42
- query: string;
43
- };
44
- };
45
- } & {
46
- isLookupTable: {
47
- values: {
48
- [id_value: string]: {} | {
49
- en: string;
50
- };
51
- };
52
- };
53
- });
54
- } | undefined;
5
+ config: TableConfig | undefined;
55
6
  newConfig?: undefined;
56
7
  migrate?: undefined;
57
8
  dropTableQueries: string[];
@@ -61,57 +12,7 @@ export declare const getTableConfigSchemaQueries: (opts: SchemaRelatedOptions, {
61
12
  triggerQueries: string[];
62
13
  tableDefs: Record<string, Record<string, string>>;
63
14
  } | {
64
- newConfig: {
65
- [table_name: string]: import("./TableConfigTypes").TableDefinition<{
66
- en: 1;
67
- }, import("prostgles-types").AnyObject, import("..").DBHandlerServer> | ({
68
- info?: {
69
- label?: string | import("./TableConfigTypes").LangToTranslation;
70
- };
71
- dropIfExistsCascade?: boolean;
72
- dropIfExists?: boolean;
73
- syncConfig?: import("../PublishParser/publishTypesAndUtils").SyncConfig;
74
- hooks?: {
75
- getPreInsertRow?: (args: Omit<import("../PublishParser/publishTypesAndUtils").ValidateRowArgsCommon, "localParams"> & {
76
- validate: import("../PublishParser/publishTypesAndUtils").InsertRule["validate"];
77
- localParams: import("../DboBuilder/DboBuilderTypes").LocalParams | undefined;
78
- }) => Promise<{
79
- row: import("prostgles-types").AnyObject;
80
- onInserted: Promise<void>;
81
- }>;
82
- beforeEach?: import("../PublishParser/publishTypesAndUtils").BeforeEachTsTrigger<import("prostgles-types").AnyObject, import("..").DBHandlerServer>[] | undefined;
83
- afterEach?: import("../PublishParser/publishTypesAndUtils").AfterEachTsTrigger<import("prostgles-types").AnyObject, import("..").DBHandlerServer>[] | undefined;
84
- afterAll?: import("../PublishParser/publishTypesAndUtils").AfterAllTsTrigger<import("prostgles-types").AnyObject, import("..").DBHandlerServer>[] | undefined;
85
- onInsteadOfDelete?: ((args: {
86
- dbx: import("..").DBHandlerServer;
87
- tx: import("pg-promise").ITask<{}>;
88
- returningQuery: string;
89
- isOneOrNone: boolean;
90
- queryType: "any" | "none";
91
- filterOpts: {
92
- where: string;
93
- filter: import("prostgles-types").AnyObject;
94
- };
95
- }) => Promise<import("prostgles-types").AnyObject[]>) | undefined;
96
- } | undefined;
97
- triggers?: {
98
- [triggerName: string]: {
99
- type: "before" | "after" | "instead of";
100
- actions: ("insert" | "update" | "delete")[];
101
- forEach: "statement" | "row";
102
- query: string;
103
- };
104
- };
105
- } & {
106
- isLookupTable: {
107
- values: {
108
- [id_value: string]: {} | {
109
- en: string;
110
- };
111
- };
112
- };
113
- });
114
- };
15
+ newConfig: TableConfig;
115
16
  migrate: {
116
17
  schemaIsUpToDate: boolean;
117
18
  runMigration?: undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"getTableConfigSchemaQueries.d.ts","sourceRoot":"","sources":["../../lib/TableConfig/getTableConfigSchemaQueries.ts"],"names":[],"mappings":"AAKA,OAAO,EAA6B,KAAK,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,eAAO,MAAM,2BAA2B,GACtC,MAAM,oBAAoB,EAC1B,gBAAgB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;;;;;;qBAI3E,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsEP,CAAC"}
1
+ {"version":3,"file":"getTableConfigSchemaQueries.d.ts","sourceRoot":"","sources":["../../lib/TableConfig/getTableConfigSchemaQueries.ts"],"names":[],"mappings":"AAKA,OAAO,EAA6B,KAAK,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,eAAO,MAAM,2BAA2B,GACtC,MAAM,oBAAoB,EAC1B,gBAAgB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0ElF,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type pgPromise from "pg-promise";
2
+ import type { AnyObject, DBSchema } from "prostgles-types";
3
+ import type { DbTxTableHandlers, LocalParams } from "../DboBuilder/DboBuilderTypes";
4
+ import type { DBOFullyTyped } from "../DBSchemaBuilder/DBSchemaBuilder";
5
+ import type { AfterAllTsTrigger, AfterEachTsTrigger, BeforeEachTsTrigger, InsertRule, ValidateRowArgsCommon } from "../PublishParser/PublishParser";
6
+ export type TableHooks<S = void> = S extends DBSchema ? Partial<{
7
+ [tableName in keyof S]: TableHooksDefinition<Required<S[tableName]["columns"]>, DBOFullyTyped<S>>;
8
+ }> : Record<string, TableHooksDefinition>;
9
+ export type TableHooksDefinition<R = AnyObject, DBX = DbTxTableHandlers> = {
10
+ /**
11
+ * Hook used to run custom logic before inserting a row.
12
+ * The returned row must satisfy the table schema.
13
+ */
14
+ getPreInsertRow?: (args: PreInsertRowArgs) => Promise<{
15
+ row: AnyObject;
16
+ onInserted: Promise<void>;
17
+ }>;
18
+ beforeEach?: BeforeEachTsTrigger<R, DBX>[];
19
+ afterEach?: AfterEachTsTrigger<R, DBX>[];
20
+ afterAll?: AfterAllTsTrigger<R, DBX>[];
21
+ onInsteadOfDelete?: (args: {
22
+ dbx: DBX;
23
+ tx: pgPromise.ITask<{}>;
24
+ returningQuery: string;
25
+ isOneOrNone: boolean;
26
+ queryType: "any" | "none";
27
+ filterOpts: {
28
+ where: string;
29
+ filter: AnyObject;
30
+ };
31
+ }) => Promise<AnyObject[] | undefined>;
32
+ };
33
+ type PreInsertRowArgs = Omit<ValidateRowArgsCommon, "localParams"> & {
34
+ validate: InsertRule["validate"];
35
+ localParams: LocalParams | undefined;
36
+ };
37
+ export {};
38
+ //# sourceMappingURL=TableHooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableHooks.d.ts","sourceRoot":"","sources":["../../lib/TableHooks/TableHooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACtB,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,IAAI,IAC7B,CAAC,SAAS,QAAQ,GAChB,OAAO,CAAC;KACL,SAAS,IAAI,MAAM,CAAC,GAAG,oBAAoB,CAC1C,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,EACjC,aAAa,CAAC,CAAC,CAAC,CACjB;CACF,CAAC,G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3,"file":"TableHooks.js","sourceRoot":"","sources":["../../lib/TableHooks/TableHooks.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export type { StorageClient as CloudClient } from "./StorageClient/StorageClient
11
11
  export * from "./StorageClient/getLocalStorageClient";
12
12
  export type { DB } from "./initProstgles";
13
13
  export type * from "./TableConfig/TableConfigTypes";
14
+ export type * from "./TableHooks/TableHooks";
14
15
  export * from "./Auth/utils/upsertNamedExpressMiddleware";
15
16
  export type { RequestWithUser } from "./Auth/middleware/userContextMiddleware";
16
17
  export default prostgles;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAC;AAExE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,iBAAS,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,SAAS,WAAW,GAAG,WAAW,EAClE,MAAM,EAAE,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,GAKrB,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAC/C;AACD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,YAAY,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,aAAa,IAAI,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACvF,cAAc,uCAAuC,CAAC;AACtD,YAAY,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,mBAAmB,gCAAgC,CAAC;AACpD,cAAc,2CAA2C,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,eAAe,SAAS,CAAC;AACzB,YAAY,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAC;AAExE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,iBAAS,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,SAAS,WAAW,GAAG,WAAW,EAClE,MAAM,EAAE,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,GAKrB,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAC/C;AACD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,YAAY,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,aAAa,IAAI,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACvF,cAAc,uCAAuC,CAAC;AACtD,YAAY,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,mBAAmB,gCAAgC,CAAC;AACpD,mBAAmB,yBAAyB,CAAC;AAC7C,cAAc,2CAA2C,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,eAAe,SAAS,CAAC;AACzB,YAAY,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,2CAAwC;AAGxC,SAAS,SAAS,CAChB,MAAsC;IAEtC,MAAM,IAAI,GAAG,IAAI,qBAAS,CAAC,MAA8B,CAAC,CAAC;IAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAA0C,EAAE;QAClE,IAAI,EAAE,MAAM;KACb,CAA6C,CAAC;AACjD,CAAC;AACD,uEAAqD;AACrD,mDAAiC;AAKjC,wEAAsD;AAGtD,4EAA0D;AAE1D,kBAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,2CAAwC;AAGxC,SAAS,SAAS,CAChB,MAAsC;IAEtC,MAAM,IAAI,GAAG,IAAI,qBAAS,CAAC,MAA8B,CAAC,CAAC;IAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAA0C,EAAE;QAClE,IAAI,EAAE,MAAM;KACb,CAA6C,CAAC;AACjD,CAAC;AACD,uEAAqD;AACrD,mDAAiC;AAKjC,wEAAsD;AAItD,4EAA0D;AAE1D,kBAAe,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateConfiguration.d.ts","sourceRoot":"","sources":["../lib/updateConfiguration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,mBAAmB,GAAU,QAAQ,EAAE,UAAU,SAAS,WAAW,EAChF,MAAM,SAAS,EACf,SAAS,oBAAoB,EAC7B,SAAS,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,EAC/C,QAAQ,IAAI,kBAwDb,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,+EAOc,CAAC"}
1
+ {"version":3,"file":"updateConfiguration.d.ts","sourceRoot":"","sources":["../lib/updateConfiguration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,mBAAmB,GAAU,QAAQ,EAAE,UAAU,SAAS,WAAW,EAChF,MAAM,SAAS,EACf,SAAS,oBAAoB,EAC7B,SAAS,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,EAC/C,QAAQ,IAAI,kBA8Db,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,+EAOc,CAAC"}
@@ -22,7 +22,10 @@ const updateConfiguration = async (prgl, onReady, newOpts, force) => {
22
22
  prgl.initRestApi();
23
23
  }
24
24
  if ((0, prostgles_types_1.includes)(optionsThatChanged, "tableConfig")) {
25
- await prgl.initTableConfig({ type: "prgl.update", newOpts });
25
+ await prgl.initTableConfig({
26
+ type: "prgl.update",
27
+ newOpts: newOpts,
28
+ });
26
29
  }
27
30
  if ((0, prostgles_types_1.includes)(optionsThatChanged, "schema")) {
28
31
  await prgl.refreshDBO();
@@ -49,7 +52,10 @@ const updateConfiguration = async (prgl, onReady, newOpts, force) => {
49
52
  prgl.setupSocketIO();
50
53
  }
51
54
  else {
52
- await prgl.init(onReady, { type: "prgl.update", newOpts });
55
+ await prgl.init(onReady, {
56
+ type: "prgl.update",
57
+ newOpts: newOpts,
58
+ });
53
59
  }
54
60
  };
55
61
  exports.updateConfiguration = updateConfiguration;
@@ -1 +1 @@
1
- {"version":3,"file":"updateConfiguration.js","sourceRoot":"","sources":["../lib/updateConfiguration.ts"],"names":[],"mappings":";;;AAAA,qDAAiF;AAK1E,MAAM,mBAAmB,GAAG,KAAK,EACtC,IAAe,EACf,OAA6B,EAC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AAkB,EAAE,+BAA+B,CAAC,EAC7D,CAAC;QACD,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,IAAA,yBAAO,EAAC,OAAO,CAAC;QAAE,OAAO;IAE7B;;;OAGG;IACH,IACE,kBAAkB,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,4BAAoB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC,EAChG,CAAC;QACD,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACvB,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AAlEW,QAAA,mBAAmB,uBAkE9B;AAEF;;GAEG;AACU,QAAA,oBAAoB,GAAG;IAClC,IAAI;IACJ,MAAM;IACN,SAAS;IACT,WAAW;IACX,eAAe;IACf,oBAAoB;CACyB,CAAC"}
@@ -242,7 +242,8 @@ export class DboBuilder {
242
242
  tableOrViewInfo: tov,
243
243
  dboBuilder: this,
244
244
  tx: undefined,
245
- config: this.prostgles.mergedTableConfig?.[tov.name],
245
+ config: this.prostgles.mergedTableConfig.tableConfig?.[tov.name],
246
+ hooks: this.prostgles.mergedTableConfig.tableHooks?.[tov.name],
246
247
  joinPaths: this.shortestJoinPaths,
247
248
  });
248
249
  this.dbo[tov.name] = tableHandler;
@@ -270,7 +271,7 @@ export class DboBuilder {
270
271
  }
271
272
 
272
273
  this.tableTsDefinitions = getDBGeneratedSchema({
273
- config: this.prostgles.mergedTableConfig,
274
+ config: this.prostgles.mergedTableConfig.tableConfig,
274
275
  tablesOrViews,
275
276
  });
276
277
  this.functionTsDefinitions = getFunctionsTypescriptSchema(
@@ -306,7 +307,7 @@ export class DboBuilder {
306
307
  : { tsSchema: string; tablesOrViews: TableSchema[] } => {
307
308
  const getSchema = (tablesOrViews: TableSchema[]) => {
308
309
  const tableTsDefinitions = getDBGeneratedSchema({
309
- config: this.prostgles.mergedTableConfig,
310
+ config: this.prostgles.mergedTableConfig.tableConfig,
310
311
  tablesOrViews: [
311
312
  ...tablesOrViews,
312
313
  ...extraTables.filter(
@@ -379,7 +380,8 @@ export class DboBuilder {
379
380
  tableOrViewInfo: tov,
380
381
  dboBuilder: this,
381
382
  tx: { t, dbTX },
382
- config: this.prostgles.mergedTableConfig?.[tov.name],
383
+ config: this.prostgles.mergedTableConfig.tableConfig?.[tov.name],
384
+ hooks: this.prostgles.mergedTableConfig.tableHooks?.[tov.name],
383
385
  joinPaths: this.shortestJoinPaths,
384
386
  });
385
387
  });
@@ -35,6 +35,7 @@ import { updateBatch } from "./updateBatch";
35
35
  import { upsert } from "./upsert";
36
36
  import { isApplicableHook } from "./isApplicableHook";
37
37
  import type { TableConfigurator } from "../../TableConfig/TableConfigurator";
38
+ import type { TableHooksDefinition } from "../../TableHooks/TableHooks";
38
39
 
39
40
  export type ValidatedParams = {
40
41
  row: AnyObject;
@@ -52,6 +53,7 @@ export class TableHandler extends ViewHandler {
52
53
  constructor({
53
54
  db,
54
55
  config,
56
+ hooks,
55
57
  dboBuilder,
56
58
  tableOrViewInfo,
57
59
  tx,
@@ -61,10 +63,11 @@ export class TableHandler extends ViewHandler {
61
63
  tableOrViewInfo: TableSchema;
62
64
  dboBuilder: DboBuilder;
63
65
  config: TableDefinition<any> | undefined;
66
+ hooks: TableHooksDefinition | undefined;
64
67
  tx?: { t: pgPromise.ITask<{}>; dbTX: TableHandlers };
65
68
  joinPaths?: JoinPaths;
66
69
  }) {
67
- super({ db, tableOrViewInfo, dboBuilder, config, tx, joinPaths });
70
+ super({ db, tableOrViewInfo, dboBuilder, config, hooks, tx, joinPaths });
68
71
 
69
72
  // eslint-disable-next-line @typescript-eslint/unbound-method
70
73
  this.remove = this.delete;
@@ -75,9 +78,7 @@ export class TableHandler extends ViewHandler {
75
78
 
76
79
  getBeforeHooks = (command: "update" | "insert", rows: AnyObject[]) => {
77
80
  return (
78
- this.config?.hooks?.beforeEach?.filter((hook) =>
79
- isApplicableHook(this, rows, hook, command),
80
- ) ?? []
81
+ this.hooks?.beforeEach?.filter((hook) => isApplicableHook(this, rows, hook, command)) ?? []
81
82
  );
82
83
  };
83
84
 
@@ -133,7 +134,7 @@ export class TableHandler extends ViewHandler {
133
134
  if (postValidate && !localParams) {
134
135
  throw new Error("Unexpected: no localParams for postValidate");
135
136
  }
136
- const afterEachHooks = this.config?.hooks?.afterEach
137
+ const afterEachHooks = this.hooks?.afterEach
137
138
  ?.map((hook) => {
138
139
  const { commands } = hook;
139
140
  if (!commands[command.name]) {
@@ -146,7 +147,7 @@ export class TableHandler extends ViewHandler {
146
147
  })
147
148
  .filter(isDefined);
148
149
 
149
- const afterAllHooks = this.config?.hooks?.afterAll
150
+ const afterAllHooks = this.hooks?.afterAll
150
151
  ?.map((hook) => {
151
152
  const { commands } = hook;
152
153
  if (!commands[command.name]) {
@@ -183,7 +184,7 @@ export class TableHandler extends ViewHandler {
183
184
  command.name !== "delete" && this.getBeforeHooks(command.name, newRows).length > 0;
184
185
  return {
185
186
  shouldWrap:
186
- !transaction && (hasAfterChecks || hasBeforeHooks || this.config?.hooks?.onInsteadOfDelete),
187
+ !transaction && (hasAfterChecks || hasBeforeHooks || this.hooks?.onInsteadOfDelete),
187
188
  hasBeforeHooks,
188
189
  hasAfterChecks,
189
190
  };
@@ -8,9 +8,8 @@ import {
8
8
  rejectWithPGClientError,
9
9
  withUserRLS,
10
10
  } from "../DboBuilder";
11
- import type { TableHandler } from "./TableHandler";
12
- import { onDeleteFromFileTable } from "./onDeleteFromFileTable";
13
11
  import { getReturnTypeQuery } from "../ViewHandler/getReturnTypeQuery";
12
+ import type { TableHandler } from "./TableHandler";
14
13
  import { executeAfterHooksCheckAndPostValidation } from "./executeAfterHooksCheckAndPostValidation";
15
14
 
16
15
  export async function _delete(
@@ -149,7 +148,7 @@ export async function _delete(
149
148
  dbHandler.oneOrNone<AnyObject>(queryWithRLS).then((data) => (data ? [data] : []))
150
149
  : dbHandler.any<AnyObject>(queryWithRLS);
151
150
 
152
- const onInsteadOfDelete = this.config?.hooks?.onInsteadOfDelete;
151
+ const onInsteadOfDelete = this.hooks?.onInsteadOfDelete;
153
152
  if (onInsteadOfDelete) {
154
153
  if (!transaction) {
155
154
  throw new Error(
@@ -32,6 +32,7 @@ import { escapeTSNames } from "../../utils/utils";
32
32
  import type { TableDefinition } from "../../TableConfig/TableConfigTypes";
33
33
  import { getDbHandlerWithAbort } from "./getDbHandlerWithAbort";
34
34
  import type { VoidFunction } from "../../SchemaWatch/SchemaWatch";
35
+ import type { TableHooksDefinition } from "../../TableHooks/TableHooks";
35
36
 
36
37
  export type JoinPaths = {
37
38
  t1: string;
@@ -54,6 +55,7 @@ export class ViewHandler {
54
55
  joinPaths?: JoinPaths;
55
56
  dboBuilder: DboBuilder;
56
57
  config: TableDefinition<any> | undefined;
58
+ hooks: TableHooksDefinition | undefined;
57
59
 
58
60
  tx?: {
59
61
  t: pgPromise.ITask<{}>;
@@ -75,15 +77,18 @@ export class ViewHandler {
75
77
  tableOrViewInfo,
76
78
  tx,
77
79
  joinPaths,
80
+ hooks,
78
81
  }: {
79
82
  db: DB;
80
83
  tableOrViewInfo: TableSchema;
81
84
  dboBuilder: DboBuilder;
82
85
  config: TableDefinition<any> | undefined;
86
+ hooks: TableHooksDefinition | undefined;
83
87
  tx?: { t: pgPromise.ITask<{}>; dbTX: TableHandlers };
84
88
  joinPaths?: JoinPaths;
85
89
  }) {
86
90
  this.config = config;
91
+ this.hooks = hooks;
87
92
  this.db = db;
88
93
  this.tx = tx;
89
94
  this.joinPaths = joinPaths;
package/lib/Prostgles.ts CHANGED
@@ -61,6 +61,7 @@ import * as fs from "fs";
61
61
  import type { getAdminClient } from "./DboBuilder/runSql/getAdminClient";
62
62
  import type { TableHandler } from "./DboBuilder/TableHandler/TableHandler";
63
63
  import { getFileTableConfig } from "./StorageClient/getFileTableConfig";
64
+ import { dirname } from "path";
64
65
 
65
66
  export class Prostgles {
66
67
  /**
@@ -145,6 +146,7 @@ export class Prostgles {
145
146
  onQuery: 1,
146
147
  onConnectionError: 1,
147
148
  tableConfig: 1,
149
+ tableHooks: 1,
148
150
  tableConfigMigrations: 1,
149
151
  onNotice: 1,
150
152
  onLog: 1,
@@ -190,17 +192,20 @@ export class Prostgles {
190
192
 
191
193
  /**
192
194
  * Will write the Schema Typescript definitions to file (tsGeneratedTypesDir)
195
+ * force is used for hotReloadMode to trigger a restart
193
196
  */
194
197
  writeDBSchema(force = false) {
195
198
  if (this.opts.tsGeneratedTypesDir) {
196
199
  const { fullPath, fileName } = this.getTSFileName();
197
200
  const { tsSchema: fileContent } = this.dboBuilder.getTsDefinitions();
198
- fs.readFile(fullPath, "utf8", function (err, data) {
199
- if (err || force || data !== fileContent) {
200
- fs.writeFileSync(fullPath, fileContent);
201
- console.log("Prostgles: Created typescript schema definition file: \n " + fileName);
202
- }
203
- });
201
+ fs.mkdirSync(dirname(fullPath), { recursive: true });
202
+
203
+ const existingContent =
204
+ fs.existsSync(fullPath) ? fs.readFileSync(fullPath, "utf8") : undefined;
205
+ if (force || existingContent !== fileContent) {
206
+ fs.writeFileSync(fullPath, fileContent);
207
+ console.log("Prostgles: Created typescript schema definition file: \n " + fileName);
208
+ }
204
209
  } else if (force) {
205
210
  console.error("Schema changed. tsGeneratedTypesDir needs to be set to reload server");
206
211
  }
@@ -13,6 +13,7 @@ import type { RestApiConfig } from "./RestApi";
13
13
  import type { OnSchemaChangeCallback } from "./SchemaWatch/SchemaWatch";
14
14
  import type { PGConstraint } from "./TableConfig/fetchTableConstraints";
15
15
  import type { TableConfig } from "./TableConfig/TableConfigTypes";
16
+ import type { TableHooks } from "./TableHooks/TableHooks";
16
17
 
17
18
  import type { PRGLIOSocket } from "./DboBuilder/DboBuilder";
18
19
 
@@ -307,6 +308,11 @@ export type ProstglesInitOptions<S = void, SUser extends SessionUser = SessionUs
307
308
  */
308
309
  tableConfigMigrations?: TableConfigMigrations;
309
310
 
311
+ /**
312
+ * Allows defining hooks for table events such as insert, update, delete and select.
313
+ */
314
+ tableHooks?: TableHooks<S>;
315
+
310
316
  /**
311
317
  * Useful for logging or debugging
312
318
  */
@@ -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 = (prg: Prostgles): TableConfig | undefined => {
45
- const { fileTable, tableConfig } = prg.opts;
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
- return {
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
- hooks: {
98
- ...userFileTableConfig?.hooks,
99
- beforeEach: [
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
- const {
111
- data: dataBlob,
112
- original_name,
113
- id,
114
- original_last_modified = null,
115
- } = insertData;
116
- const data = dataBlob as unknown as Buffer;
117
- if (command === "update") {
118
- const { newData } = await updateFile(tableHandler, fileTable, {
119
- filter: filter ?? {},
120
- localParams,
121
- data,
122
- original_name,
123
- original_last_modified,
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
- const media = await uploadFile(fileTable, {
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: media,
130
+ row: newData,
143
131
  hookContext: {
144
132
  data,
145
133
  },
146
134
  };
147
- },
148
- } satisfies BeforeEachTsTrigger<FileTableRow, {}>,
149
- ...(userFileTableConfig?.hooks?.beforeEach || []),
150
- ],
151
- onInsteadOfDelete: async ({ dbx, tx, returningQuery, isOneOrNone, filterOpts }) => {
152
- return onDeleteFromFileTable(fileTable, {
153
- dbTX: dbx,
154
- t: tx,
155
- returningQuery,
156
- isOneOrNone,
157
- filterOpts,
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
- ...omitKeys(tableConfig ?? {}, [fileTableName]),
165
+ };
166
+
167
+ return {
168
+ tableConfig: mergedTableConfig,
169
+ tableHooks: mergedTableHooks,
163
170
  };
164
171
  };