prostgles-server 4.2.187 → 4.2.189
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/.eslintignore +2 -1
- package/.eslintrc.json +2 -0
- package/dist/Auth/AuthHandler.d.ts +20 -11
- package/dist/Auth/AuthHandler.d.ts.map +1 -1
- package/dist/Auth/AuthHandler.js +98 -120
- package/dist/Auth/AuthHandler.js.map +1 -1
- package/dist/Auth/AuthTypes.d.ts +69 -71
- package/dist/Auth/AuthTypes.d.ts.map +1 -1
- package/dist/Auth/{setEmailProvider.d.ts → authProviders/setEmailProvider.d.ts} +1 -1
- package/dist/Auth/authProviders/setEmailProvider.d.ts.map +1 -0
- package/dist/Auth/authProviders/setEmailProvider.js +27 -0
- package/dist/Auth/authProviders/setEmailProvider.js.map +1 -0
- package/dist/Auth/authProviders/setOAuthProviders.d.ts +5 -0
- package/dist/Auth/authProviders/setOAuthProviders.d.ts.map +1 -0
- package/dist/Auth/authProviders/setOAuthProviders.js +78 -0
- package/dist/Auth/authProviders/setOAuthProviders.js.map +1 -0
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.d.ts +7 -0
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.d.ts.map +1 -0
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js +29 -0
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js.map +1 -0
- package/dist/Auth/endpoints/getRegisterRequestHandler.d.ts +7 -0
- package/dist/Auth/endpoints/getRegisterRequestHandler.d.ts.map +1 -0
- package/dist/Auth/endpoints/getRegisterRequestHandler.js +77 -0
- package/dist/Auth/endpoints/getRegisterRequestHandler.js.map +1 -0
- package/dist/Auth/setAuthProviders.d.ts.map +1 -1
- package/dist/Auth/setAuthProviders.js +4 -74
- package/dist/Auth/setAuthProviders.js.map +1 -1
- package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
- package/dist/Auth/setupAuthRoutes.js +23 -33
- package/dist/Auth/setupAuthRoutes.js.map +1 -1
- package/dist/Auth/utils/checkDmarc.d.ts +2 -0
- package/dist/Auth/utils/checkDmarc.d.ts.map +1 -0
- package/dist/Auth/utils/checkDmarc.js +22 -0
- package/dist/Auth/utils/checkDmarc.js.map +1 -0
- package/dist/Auth/utils/getClientRequestIPsInfo.d.ts +3 -0
- package/dist/Auth/utils/getClientRequestIPsInfo.d.ts.map +1 -0
- package/dist/Auth/utils/getClientRequestIPsInfo.js +29 -0
- package/dist/Auth/utils/getClientRequestIPsInfo.js.map +1 -0
- package/dist/Auth/utils/getReturnUrl.d.ts +3 -0
- package/dist/Auth/utils/getReturnUrl.d.ts.map +1 -0
- package/dist/Auth/utils/getReturnUrl.js +15 -0
- package/dist/Auth/utils/getReturnUrl.js.map +1 -0
- package/dist/Auth/utils/getSafeReturnURL.d.ts.map +1 -0
- package/dist/Auth/utils/getSafeReturnURL.js.map +1 -0
- package/dist/DBEventsManager.d.ts.map +1 -1
- package/dist/DBEventsManager.js +4 -5
- package/dist/DBEventsManager.js.map +1 -1
- package/dist/DBSchemaBuilder.js +1 -1
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts +0 -1
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +3 -12
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.d.ts +4 -4
- package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions.js +38 -76
- package/dist/DboBuilder/QueryBuilder/Functions.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +4 -12
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js +23 -33
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.js +6 -6
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.js.map +1 -1
- package/dist/DboBuilder/QueryStreamer.d.ts.map +1 -1
- package/dist/DboBuilder/QueryStreamer.js +13 -19
- package/dist/DboBuilder/QueryStreamer.js.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.js +7 -16
- package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.js +7 -5
- 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 +5 -8
- package/dist/DboBuilder/TableHandler/delete.js.map +1 -1
- package/dist/DboBuilder/TableHandler/insert.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/insert.js +10 -15
- package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
- package/dist/DboBuilder/TableHandler/insertTest.js +1 -1
- package/dist/DboBuilder/TableHandler/insertTest.js.map +1 -1
- package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js +1 -1
- package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js.map +1 -1
- package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/update.js +5 -9
- package/dist/DboBuilder/TableHandler/update.js.map +1 -1
- package/dist/DboBuilder/TableHandler/updateFile.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/updateFile.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/updateFile.js +7 -9
- package/dist/DboBuilder/TableHandler/updateFile.js.map +1 -1
- package/dist/DboBuilder/TableHandler/upsert.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/upsert.js +1 -1
- package/dist/DboBuilder/TableHandler/upsert.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +11 -13
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/count.js +1 -1
- package/dist/DboBuilder/ViewHandler/count.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.js +20 -27
- package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getExistsCondition.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/getExistsCondition.js +4 -10
- package/dist/DboBuilder/ViewHandler/getExistsCondition.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getInfo.js +2 -2
- package/dist/DboBuilder/ViewHandler/getInfo.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js +6 -22
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseFieldFilter.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseFieldFilter.js +6 -10
- package/dist/DboBuilder/ViewHandler/parseFieldFilter.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseJoinPath.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseJoinPath.js +8 -11
- package/dist/DboBuilder/ViewHandler/parseJoinPath.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareSortItems.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareSortItems.js +7 -12
- package/dist/DboBuilder/ViewHandler/prepareSortItems.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareWhere.js +6 -10
- package/dist/DboBuilder/ViewHandler/prepareWhere.js.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.d.ts.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.js +8 -23
- package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
- package/dist/DboBuilder/getColumns.d.ts.map +1 -1
- package/dist/DboBuilder/getColumns.js +19 -26
- package/dist/DboBuilder/getColumns.js.map +1 -1
- package/dist/DboBuilder/getCondition.d.ts.map +1 -1
- package/dist/DboBuilder/getCondition.js +7 -9
- package/dist/DboBuilder/getCondition.js.map +1 -1
- package/dist/DboBuilder/getSubscribeRelatedTables.js +2 -2
- package/dist/DboBuilder/getSubscribeRelatedTables.js.map +1 -1
- package/dist/DboBuilder/getTablesForSchemaPostgresSQL.d.ts.map +1 -1
- package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js +14 -15
- package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js.map +1 -1
- package/dist/DboBuilder/insertNestedRecords.d.ts.map +1 -1
- package/dist/DboBuilder/insertNestedRecords.js +26 -40
- package/dist/DboBuilder/insertNestedRecords.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.js +1 -1
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
- package/dist/DboBuilder/prepareShortestJoinPaths.d.ts.map +1 -1
- package/dist/DboBuilder/prepareShortestJoinPaths.js +12 -18
- package/dist/DboBuilder/prepareShortestJoinPaths.js.map +1 -1
- package/dist/DboBuilder/runSQL.d.ts +1 -1
- package/dist/DboBuilder/runSQL.d.ts.map +1 -1
- package/dist/DboBuilder/runSQL.js +14 -27
- package/dist/DboBuilder/runSQL.js.map +1 -1
- package/dist/DboBuilder/uploadFile.d.ts +1 -1
- package/dist/DboBuilder/uploadFile.d.ts.map +1 -1
- package/dist/DboBuilder/uploadFile.js +4 -11
- package/dist/DboBuilder/uploadFile.js.map +1 -1
- package/dist/FileManager/FileManager.d.ts.map +1 -1
- package/dist/FileManager/FileManager.js +11 -13
- package/dist/FileManager/FileManager.js.map +1 -1
- package/dist/FileManager/initFileManager.d.ts.map +1 -1
- package/dist/FileManager/initFileManager.js +60 -62
- package/dist/FileManager/initFileManager.js.map +1 -1
- package/dist/FileManager/uploadStream.js +2 -2
- package/dist/FileManager/uploadStream.js.map +1 -1
- package/dist/Filtering.d.ts +1 -1
- package/dist/Filtering.d.ts.map +1 -1
- package/dist/Filtering.js +12 -35
- package/dist/Filtering.js.map +1 -1
- package/dist/JSONBValidation/validation.d.ts.map +1 -1
- package/dist/JSONBValidation/validation.js +20 -26
- package/dist/JSONBValidation/validation.js.map +1 -1
- package/dist/Logging.d.ts +1 -0
- package/dist/Logging.d.ts.map +1 -1
- package/dist/PostgresNotifListenManager.d.ts.map +1 -1
- package/dist/PostgresNotifListenManager.js +1 -5
- package/dist/PostgresNotifListenManager.js.map +1 -1
- package/dist/Prostgles.d.ts +1 -1
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +18 -33
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +8 -13
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSub.d.ts.map +1 -1
- package/dist/PubSubManager/addSub.js +1 -1
- package/dist/PubSubManager/addSub.js.map +1 -1
- package/dist/PubSubManager/addSync.d.ts.map +1 -1
- package/dist/PubSubManager/addSync.js +4 -7
- package/dist/PubSubManager/addSync.js.map +1 -1
- package/dist/PubSubManager/getCreatePubSubManagerError.js +6 -6
- package/dist/PubSubManager/getCreatePubSubManagerError.js.map +1 -1
- package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/initPubSubManager.js +2 -3
- package/dist/PubSubManager/initPubSubManager.js.map +1 -1
- package/dist/PubSubManager/pushSubData.d.ts.map +1 -1
- package/dist/PubSubManager/pushSubData.js +0 -2
- package/dist/PubSubManager/pushSubData.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +8 -13
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getFileTableRules.js +1 -1
- package/dist/PublishParser/getFileTableRules.js.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +6 -13
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js +14 -19
- package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
- package/dist/RestApi.d.ts +1 -1
- package/dist/RestApi.d.ts.map +1 -1
- package/dist/RestApi.js +2 -2
- package/dist/RestApi.js.map +1 -1
- package/dist/SchemaWatch/SchemaWatch.d.ts.map +1 -1
- package/dist/SchemaWatch/SchemaWatch.js +2 -2
- package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
- package/dist/SyncReplication.d.ts.map +1 -1
- package/dist/SyncReplication.js +31 -41
- package/dist/SyncReplication.js.map +1 -1
- package/dist/TableConfig/TableConfig.d.ts.map +1 -1
- package/dist/TableConfig/TableConfig.js +7 -9
- package/dist/TableConfig/TableConfig.js.map +1 -1
- package/dist/TableConfig/getConstraintDefinitionQueries.d.ts.map +1 -1
- package/dist/TableConfig/getConstraintDefinitionQueries.js +1 -6
- package/dist/TableConfig/getConstraintDefinitionQueries.js.map +1 -1
- package/dist/TableConfig/getFutureTableSchema.d.ts.map +1 -1
- package/dist/TableConfig/getFutureTableSchema.js +16 -28
- package/dist/TableConfig/getFutureTableSchema.js.map +1 -1
- package/dist/TableConfig/getTableColumnQueries.d.ts.map +1 -1
- package/dist/TableConfig/getTableColumnQueries.js +5 -9
- package/dist/TableConfig/getTableColumnQueries.js.map +1 -1
- package/dist/TableConfig/initTableConfig.d.ts.map +1 -1
- package/dist/TableConfig/initTableConfig.js +22 -25
- package/dist/TableConfig/initTableConfig.js.map +1 -1
- package/dist/initProstgles.js +1 -1
- package/dist/initProstgles.js.map +1 -1
- package/dist/onSocketConnected.d.ts.map +1 -1
- package/dist/onSocketConnected.js +2 -4
- package/dist/onSocketConnected.js.map +1 -1
- package/dist/runClientRequest.d.ts.map +1 -1
- package/dist/runClientRequest.js +14 -13
- package/dist/runClientRequest.js.map +1 -1
- package/lib/Auth/AuthHandler.ts +114 -135
- package/lib/Auth/AuthTypes.ts +96 -81
- package/lib/Auth/authProviders/setEmailProvider.ts +29 -0
- package/lib/Auth/authProviders/setOAuthProviders.ts +97 -0
- package/lib/Auth/endpoints/getConfirmEmailRequestHandler.ts +39 -0
- package/lib/Auth/endpoints/getRegisterRequestHandler.ts +88 -0
- package/lib/Auth/setAuthProviders.ts +8 -111
- package/lib/Auth/setupAuthRoutes.ts +105 -148
- package/lib/Auth/utils/checkDmarc.ts +19 -0
- package/lib/Auth/utils/getClientRequestIPsInfo.ts +25 -0
- package/lib/Auth/utils/getReturnUrl.ts +13 -0
- package/lib/DBEventsManager.ts +12 -26
- package/lib/DBSchemaBuilder.ts +1 -1
- package/lib/DboBuilder/DboBuilder.ts +23 -52
- package/lib/DboBuilder/DboBuilderTypes.ts +9 -23
- package/lib/DboBuilder/QueryBuilder/Functions.ts +86 -188
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +11 -36
- package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +102 -129
- package/lib/DboBuilder/QueryBuilder/getSelectQuery.ts +14 -27
- package/lib/DboBuilder/QueryStreamer.ts +26 -57
- package/lib/DboBuilder/TableHandler/DataValidator.ts +58 -90
- package/lib/DboBuilder/TableHandler/TableHandler.ts +19 -45
- package/lib/DboBuilder/TableHandler/delete.ts +9 -18
- package/lib/DboBuilder/TableHandler/insert.ts +18 -31
- package/lib/DboBuilder/TableHandler/insertTest.ts +1 -1
- package/lib/DboBuilder/TableHandler/runInsertUpdateQuery.ts +8 -19
- package/lib/DboBuilder/TableHandler/update.ts +17 -46
- package/lib/DboBuilder/TableHandler/updateFile.ts +18 -21
- package/lib/DboBuilder/TableHandler/upsert.ts +7 -24
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +13 -15
- package/lib/DboBuilder/ViewHandler/count.ts +1 -1
- package/lib/DboBuilder/ViewHandler/find.ts +28 -35
- package/lib/DboBuilder/ViewHandler/getExistsCondition.ts +8 -30
- package/lib/DboBuilder/ViewHandler/getInfo.ts +2 -2
- package/lib/DboBuilder/ViewHandler/getTableJoinQuery.ts +16 -32
- package/lib/DboBuilder/ViewHandler/parseFieldFilter.ts +9 -16
- package/lib/DboBuilder/ViewHandler/parseJoinPath.ts +26 -44
- package/lib/DboBuilder/ViewHandler/prepareSortItems.ts +58 -82
- package/lib/DboBuilder/ViewHandler/prepareWhere.ts +14 -27
- package/lib/DboBuilder/dboBuilderUtils.ts +19 -46
- package/lib/DboBuilder/getColumns.ts +24 -46
- package/lib/DboBuilder/getCondition.ts +18 -30
- package/lib/DboBuilder/getSubscribeRelatedTables.ts +2 -2
- package/lib/DboBuilder/getTablesForSchemaPostgresSQL.ts +44 -62
- package/lib/DboBuilder/insertNestedRecords.ts +67 -135
- package/lib/DboBuilder/parseUpdateRules.ts +1 -1
- package/lib/DboBuilder/prepareShortestJoinPaths.ts +23 -58
- package/lib/DboBuilder/runSQL.ts +41 -76
- package/lib/DboBuilder/uploadFile.ts +26 -37
- package/lib/FileManager/FileManager.ts +27 -58
- package/lib/FileManager/initFileManager.ts +68 -76
- package/lib/FileManager/uploadStream.ts +2 -2
- package/lib/Filtering.ts +30 -87
- package/lib/JSONBValidation/validation.ts +36 -75
- package/lib/Logging.ts +1 -1
- package/lib/PostgresNotifListenManager.ts +11 -35
- package/lib/Prostgles.ts +42 -100
- package/lib/PubSubManager/PubSubManager.ts +30 -66
- package/lib/PubSubManager/addSub.ts +11 -18
- package/lib/PubSubManager/addSync.ts +5 -12
- package/lib/PubSubManager/getCreatePubSubManagerError.ts +9 -9
- package/lib/PubSubManager/initPubSubManager.ts +7 -13
- package/lib/PubSubManager/pushSubData.ts +1 -7
- package/lib/PublishParser/PublishParser.ts +8 -12
- package/lib/PublishParser/getFileTableRules.ts +1 -1
- package/lib/PublishParser/getSchemaFromPublish.ts +26 -42
- package/lib/PublishParser/getTableRulesWithoutFileTable.ts +22 -37
- package/lib/RestApi.ts +4 -12
- package/lib/SchemaWatch/SchemaWatch.ts +11 -24
- package/lib/SyncReplication.ts +96 -190
- package/lib/TableConfig/TableConfig.ts +16 -38
- package/lib/TableConfig/getConstraintDefinitionQueries.ts +2 -8
- package/lib/TableConfig/getFutureTableSchema.ts +20 -34
- package/lib/TableConfig/getTableColumnQueries.ts +13 -35
- package/lib/TableConfig/initTableConfig.ts +40 -64
- package/lib/initProstgles.ts +1 -1
- package/lib/onSocketConnected.ts +8 -12
- package/lib/runClientRequest.ts +31 -54
- package/package.json +2 -2
- package/dist/Auth/getSafeReturnURL.d.ts.map +0 -1
- package/dist/Auth/getSafeReturnURL.js.map +0 -1
- package/dist/Auth/setEmailProvider.d.ts.map +0 -1
- package/dist/Auth/setEmailProvider.js +0 -133
- package/dist/Auth/setEmailProvider.js.map +0 -1
- package/dist/DboBuilder/runTransaction.d.ts +0 -9
- package/dist/DboBuilder/runTransaction.d.ts.map +0 -1
- package/dist/DboBuilder/runTransaction.js +0 -49
- package/dist/DboBuilder/runTransaction.js.map +0 -1
- package/lib/Auth/setEmailProvider.ts +0 -132
- package/lib/DboBuilder/QueryBuilder/prepareHaving.ts +0 -27
- package/lib/DboBuilder/runTransaction.ts +0 -61
- package/lib/SchemaWatch/createSchemaWatchEventTrigger.ts +0 -3
- /package/dist/Auth/{getSafeReturnURL.d.ts → utils/getSafeReturnURL.d.ts} +0 -0
- /package/dist/Auth/{getSafeReturnURL.js → utils/getSafeReturnURL.js} +0 -0
- /package/lib/Auth/{getSafeReturnURL.ts → utils/getSafeReturnURL.ts} +0 -0
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
import { RequestHandler } from "express";
|
|
1
|
+
import { RequestHandler, Response } from "express";
|
|
2
|
+
import { AuthResponse } from "prostgles-types";
|
|
2
3
|
import { DBOFullyTyped } from "../DBSchemaBuilder";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./AuthHandler";
|
|
9
|
-
import {
|
|
10
|
-
AuthClientRequest,
|
|
11
|
-
ExpressReq,
|
|
12
|
-
ExpressRes,
|
|
13
|
-
LoginParams,
|
|
14
|
-
} from "./AuthTypes";
|
|
15
|
-
import {
|
|
16
|
-
setAuthProviders,
|
|
17
|
-
upsertNamedExpressMiddleware,
|
|
18
|
-
} from "./setAuthProviders";
|
|
19
|
-
|
|
4
|
+
import { AUTH_ROUTES_AND_PARAMS, AuthHandler, HTTP_FAIL_CODES } from "./AuthHandler";
|
|
5
|
+
import { AuthClientRequest, ExpressReq, ExpressRes, LoginParams } from "./AuthTypes";
|
|
6
|
+
import { setAuthProviders, upsertNamedExpressMiddleware } from "./setAuthProviders";
|
|
7
|
+
import { getClientRequestIPsInfo } from "./utils/getClientRequestIPsInfo";
|
|
8
|
+
import { getReturnUrl } from "./utils/getReturnUrl";
|
|
20
9
|
export async function setupAuthRoutes(this: AuthHandler) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const { login, getUser, expressConfig } = this.opts;
|
|
10
|
+
const { login, expressConfig } = this.opts;
|
|
24
11
|
|
|
25
12
|
if (!login) {
|
|
26
13
|
throw "Invalid auth: Provide { sidKeyName: string } ";
|
|
@@ -30,18 +17,10 @@ export async function setupAuthRoutes(this: AuthHandler) {
|
|
|
30
17
|
throw "sidKeyName cannot be 'sid' due to collision with socket.io";
|
|
31
18
|
}
|
|
32
19
|
|
|
33
|
-
if (!getUser) throw "getUser missing from auth config";
|
|
34
|
-
|
|
35
20
|
if (!expressConfig) {
|
|
36
21
|
return;
|
|
37
22
|
}
|
|
38
|
-
const {
|
|
39
|
-
app,
|
|
40
|
-
publicRoutes = [],
|
|
41
|
-
onGetRequestOK,
|
|
42
|
-
magicLinks,
|
|
43
|
-
use,
|
|
44
|
-
} = expressConfig;
|
|
23
|
+
const { app, publicRoutes = [], onGetRequestOK, onMagicLink, use } = expressConfig;
|
|
45
24
|
if (publicRoutes.find((r) => typeof r !== "string" || !r)) {
|
|
46
25
|
throw "Invalid or empty string provided within publicRoutes ";
|
|
47
26
|
}
|
|
@@ -59,79 +38,66 @@ export async function setupAuthRoutes(this: AuthHandler) {
|
|
|
59
38
|
db: this.db,
|
|
60
39
|
});
|
|
61
40
|
};
|
|
62
|
-
upsertNamedExpressMiddleware(
|
|
63
|
-
app,
|
|
64
|
-
prostglesUseMiddleware,
|
|
65
|
-
"prostglesUseMiddleware",
|
|
66
|
-
);
|
|
41
|
+
upsertNamedExpressMiddleware(app, prostglesUseMiddleware, "prostglesUseMiddleware");
|
|
67
42
|
}
|
|
68
43
|
|
|
69
|
-
if (
|
|
70
|
-
const { check } = magicLinks;
|
|
71
|
-
if (!check) {
|
|
72
|
-
throw "Check must be defined for magicLinks";
|
|
73
|
-
}
|
|
74
|
-
|
|
44
|
+
if (onMagicLink) {
|
|
75
45
|
app.get(
|
|
76
46
|
AUTH_ROUTES_AND_PARAMS.magicLinksExpressRoute,
|
|
77
|
-
async (
|
|
78
|
-
|
|
47
|
+
async (
|
|
48
|
+
req: ExpressReq,
|
|
49
|
+
res: Response<AuthResponse.MagicLinkAuthFailure | AuthResponse.MagicLinkAuthSuccess>
|
|
50
|
+
) => {
|
|
51
|
+
const { id } = req.params;
|
|
79
52
|
|
|
80
53
|
if (typeof id !== "string" || !id) {
|
|
81
54
|
res
|
|
82
|
-
.status(
|
|
83
|
-
.json({
|
|
55
|
+
.status(HTTP_FAIL_CODES.BAD_REQUEST)
|
|
56
|
+
.json({ success: false, code: "something-went-wrong", message: "Invalid magic link" });
|
|
84
57
|
} else {
|
|
85
58
|
try {
|
|
86
|
-
const
|
|
87
|
-
return
|
|
59
|
+
const response = await this.throttledFunc(async () => {
|
|
60
|
+
return onMagicLink(
|
|
88
61
|
id,
|
|
89
62
|
this.dbo as any,
|
|
90
63
|
this.db,
|
|
91
|
-
|
|
64
|
+
getClientRequestIPsInfo({ httpReq: req })
|
|
92
65
|
);
|
|
93
66
|
});
|
|
94
|
-
if (!session) {
|
|
95
|
-
res
|
|
96
|
-
.status(HTTPCODES.AUTH_ERROR)
|
|
97
|
-
.json({ error: "Invalid magic-link" });
|
|
67
|
+
if (!response.session) {
|
|
68
|
+
res.status(HTTP_FAIL_CODES.UNAUTHORIZED).json(response.response);
|
|
98
69
|
} else {
|
|
99
|
-
this.setCookieAndGoToReturnURLIFSet(session, { req, res });
|
|
70
|
+
this.setCookieAndGoToReturnURLIFSet(response.session, { req, res });
|
|
100
71
|
}
|
|
101
72
|
} catch (e) {
|
|
102
|
-
res
|
|
73
|
+
res
|
|
74
|
+
.status(HTTP_FAIL_CODES.UNAUTHORIZED)
|
|
75
|
+
.json({ success: false, code: "something-went-wrong" });
|
|
103
76
|
}
|
|
104
77
|
}
|
|
105
|
-
}
|
|
78
|
+
}
|
|
106
79
|
);
|
|
107
80
|
}
|
|
108
81
|
|
|
109
|
-
app.post(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
);
|
|
82
|
+
app.post(AUTH_ROUTES_AND_PARAMS.login, async (req: ExpressReq, res: ExpressRes) => {
|
|
83
|
+
try {
|
|
84
|
+
const loginParams: LoginParams = {
|
|
85
|
+
type: "username",
|
|
86
|
+
...req.body,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
await this.loginThrottledAndSetCookie(req, res, loginParams);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
res.status(HTTP_FAIL_CODES.BAD_REQUEST).json({ error });
|
|
92
|
+
}
|
|
93
|
+
});
|
|
124
94
|
|
|
125
95
|
const onLogout = async (req: ExpressReq, res: ExpressRes) => {
|
|
126
|
-
const sid = this.validateSid(req
|
|
96
|
+
const sid = this.validateSid(req.cookies?.[this.sidKeyName]);
|
|
127
97
|
if (sid) {
|
|
128
98
|
try {
|
|
129
99
|
await this.throttledFunc(() => {
|
|
130
|
-
return this.opts
|
|
131
|
-
req?.cookies?.[this.sidKeyName],
|
|
132
|
-
this.dbo as any,
|
|
133
|
-
this.db,
|
|
134
|
-
);
|
|
100
|
+
return this.opts.logout?.(req.cookies?.[this.sidKeyName], this.dbo as any, this.db);
|
|
135
101
|
});
|
|
136
102
|
} catch (err) {
|
|
137
103
|
console.error(err);
|
|
@@ -141,83 +107,74 @@ export async function setupAuthRoutes(this: AuthHandler) {
|
|
|
141
107
|
};
|
|
142
108
|
|
|
143
109
|
/* Redirect if not logged in and requesting non public content */
|
|
144
|
-
app.get(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
next();
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
110
|
+
app.get(AUTH_ROUTES_AND_PARAMS.catchAll, async (req: ExpressReq, res: ExpressRes, next) => {
|
|
111
|
+
const clientReq: AuthClientRequest = { httpReq: req };
|
|
112
|
+
const getUser = this.getUser;
|
|
113
|
+
if (this.prostgles.restApi) {
|
|
114
|
+
if (
|
|
115
|
+
Object.values(this.prostgles.restApi.routes).some((restRoute) =>
|
|
116
|
+
this.matchesRoute(restRoute.split("/:")[0], req.path)
|
|
117
|
+
)
|
|
118
|
+
) {
|
|
119
|
+
next();
|
|
120
|
+
return;
|
|
158
121
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (this.matchesRoute(AUTH_ROUTES_AND_PARAMS.logoutGetPath, req.path)) {
|
|
163
|
-
await onLogout(req, res);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
this.matchesRoute(AUTH_ROUTES_AND_PARAMS.loginWithProvider, req.path)
|
|
169
|
-
) {
|
|
170
|
-
next();
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Requesting a User route
|
|
175
|
-
*/
|
|
176
|
-
if (this.isUserRoute(req.path)) {
|
|
177
|
-
/* Check auth. Redirect to login if unauthorized */
|
|
178
|
-
const u = await getUser(clientReq);
|
|
179
|
-
if (!u) {
|
|
180
|
-
res.redirect(
|
|
181
|
-
`${AUTH_ROUTES_AND_PARAMS.login}?returnURL=${encodeURIComponent(req.originalUrl)}`,
|
|
182
|
-
);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const returnURL = getReturnUrl(req);
|
|
185
125
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
126
|
+
if (this.matchesRoute(AUTH_ROUTES_AND_PARAMS.logoutGetPath, req.path)) {
|
|
127
|
+
await onLogout(req, res);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
190
130
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
131
|
+
if (this.matchesRoute(AUTH_ROUTES_AND_PARAMS.loginWithProvider, req.path)) {
|
|
132
|
+
next();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Requesting a User route
|
|
137
|
+
*/
|
|
138
|
+
if (this.isUserRoute(req.path)) {
|
|
139
|
+
/* Check auth. Redirect to login if unauthorized */
|
|
140
|
+
const u = await getUser(clientReq);
|
|
141
|
+
if (!u) {
|
|
142
|
+
res.redirect(
|
|
143
|
+
`${AUTH_ROUTES_AND_PARAMS.login}?returnURL=${encodeURIComponent(req.originalUrl)}`
|
|
144
|
+
);
|
|
197
145
|
return;
|
|
198
146
|
}
|
|
199
147
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
: "";
|
|
213
|
-
res
|
|
214
|
-
.status(HTTPCODES.AUTH_ERROR)
|
|
215
|
-
.json({
|
|
216
|
-
error:
|
|
217
|
-
"Something went wrong when processing your request" +
|
|
218
|
-
(errorMessage ? ": " + errorMessage : ""),
|
|
219
|
-
});
|
|
148
|
+
/* If authorized and going to returnUrl then redirect. Otherwise serve file */
|
|
149
|
+
} else if (returnURL && (await getUser(clientReq))) {
|
|
150
|
+
res.redirect(returnURL);
|
|
151
|
+
return;
|
|
152
|
+
|
|
153
|
+
/** If Logged in and requesting login then redirect to main page */
|
|
154
|
+
} else if (
|
|
155
|
+
this.matchesRoute(AUTH_ROUTES_AND_PARAMS.login, req.path) &&
|
|
156
|
+
(await getUser(clientReq))
|
|
157
|
+
) {
|
|
158
|
+
res.redirect("/");
|
|
159
|
+
return;
|
|
220
160
|
}
|
|
221
|
-
|
|
222
|
-
|
|
161
|
+
|
|
162
|
+
onGetRequestOK?.(req, res, {
|
|
163
|
+
getUser: () => getUser(clientReq),
|
|
164
|
+
dbo: this.dbo as DBOFullyTyped,
|
|
165
|
+
db: this.db,
|
|
166
|
+
});
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error(error);
|
|
169
|
+
const errorMessage =
|
|
170
|
+
typeof error === "string" ? error
|
|
171
|
+
: error instanceof Error ? error.message
|
|
172
|
+
: "";
|
|
173
|
+
res.status(HTTP_FAIL_CODES.UNAUTHORIZED).json({
|
|
174
|
+
error:
|
|
175
|
+
"Something went wrong when processing your request" +
|
|
176
|
+
(errorMessage ? ": " + errorMessage : ""),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
223
180
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { promises } from "node:dns";
|
|
2
|
+
|
|
3
|
+
export const checkDmarc = async (websiteUrl: string) => {
|
|
4
|
+
const { host, hostname } = new URL(websiteUrl);
|
|
5
|
+
const ignoredHosts = ["localhost", "127.0.0.1"];
|
|
6
|
+
if (!hostname || ignoredHosts.includes(hostname)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const dmarc = await promises.resolveTxt(`_dmarc.${host}`);
|
|
10
|
+
const dmarkTxt = dmarc[0]?.[0];
|
|
11
|
+
if (
|
|
12
|
+
!dmarkTxt?.includes("v=DMARC1") ||
|
|
13
|
+
(!dmarkTxt.includes("p=reject") && !dmarkTxt.includes("p=quarantine"))
|
|
14
|
+
) {
|
|
15
|
+
throw new Error("DMARC not set to reject/quarantine");
|
|
16
|
+
} else {
|
|
17
|
+
console.log("DMARC set to reject");
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AuthClientRequest, LoginClientInfo } from "../AuthTypes";
|
|
2
|
+
export const getClientRequestIPsInfo = <T extends AuthClientRequest>(
|
|
3
|
+
req: T
|
|
4
|
+
): T & LoginClientInfo => {
|
|
5
|
+
if (req.httpReq) {
|
|
6
|
+
const ip_address = req.httpReq.ip;
|
|
7
|
+
if (!ip_address) throw new Error("ip_address missing from req.httpReq");
|
|
8
|
+
const user_agent = req.httpReq.headers["user-agent"];
|
|
9
|
+
return {
|
|
10
|
+
...req,
|
|
11
|
+
ip_address,
|
|
12
|
+
ip_address_remote: req.httpReq.connection.remoteAddress,
|
|
13
|
+
x_real_ip: req.httpReq.headers["x-real-ip"] as any,
|
|
14
|
+
user_agent,
|
|
15
|
+
};
|
|
16
|
+
} else {
|
|
17
|
+
return {
|
|
18
|
+
...req,
|
|
19
|
+
ip_address: req.socket.handshake.address,
|
|
20
|
+
ip_address_remote: req.socket.request.connection.remoteAddress,
|
|
21
|
+
x_real_ip: req.socket.handshake.headers?.["x-real-ip"],
|
|
22
|
+
user_agent: req.socket.handshake.headers?.["user-agent"],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AUTH_ROUTES_AND_PARAMS } from "../AuthHandler";
|
|
2
|
+
import { ExpressReq } from "../AuthTypes";
|
|
3
|
+
import { getSafeReturnURL } from "./getSafeReturnURL";
|
|
4
|
+
|
|
5
|
+
export const getReturnUrl = (req: ExpressReq) => {
|
|
6
|
+
const { returnUrlParamName } = AUTH_ROUTES_AND_PARAMS;
|
|
7
|
+
if (req.query[returnUrlParamName]) {
|
|
8
|
+
const returnURL = decodeURIComponent(req.query[returnUrlParamName] as string);
|
|
9
|
+
|
|
10
|
+
return getSafeReturnURL(returnURL, returnUrlParamName);
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
};
|
package/lib/DBEventsManager.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PostgresNotifListenManager,
|
|
3
|
-
PrglNotifListener,
|
|
4
|
-
} from "./PostgresNotifListenManager";
|
|
1
|
+
import { PostgresNotifListenManager, PrglNotifListener } from "./PostgresNotifListenManager";
|
|
5
2
|
import { DB, PGP } from "./Prostgles";
|
|
6
3
|
import { getKeys, CHANNELS } from "prostgles-types";
|
|
7
4
|
import { PRGLIOSocket } from "./DboBuilder/DboBuilder";
|
|
@@ -53,7 +50,7 @@ export class DBEventsManager {
|
|
|
53
50
|
};
|
|
54
51
|
|
|
55
52
|
onNotice = (notice: any) => {
|
|
56
|
-
if (this.notice
|
|
53
|
+
if (this.notice.sockets.length) {
|
|
57
54
|
this.notice.sockets.map((s) => {
|
|
58
55
|
s.emit(this.notice.socketChannel, notice);
|
|
59
56
|
});
|
|
@@ -68,7 +65,7 @@ export class DBEventsManager {
|
|
|
68
65
|
async addNotify(
|
|
69
66
|
query: string,
|
|
70
67
|
socket?: PRGLIOSocket,
|
|
71
|
-
func?: any
|
|
68
|
+
func?: any
|
|
72
69
|
): Promise<{
|
|
73
70
|
socketChannel: string;
|
|
74
71
|
socketUnsubChannel: string;
|
|
@@ -120,17 +117,10 @@ export class DBEventsManager {
|
|
|
120
117
|
socketChannel,
|
|
121
118
|
sockets: socket ? [socket] : [],
|
|
122
119
|
localFuncs: func ? [func] : [],
|
|
123
|
-
notifMgr: await PostgresNotifListenManager.create(
|
|
124
|
-
this.db_pg,
|
|
125
|
-
this.onNotif,
|
|
126
|
-
channel,
|
|
127
|
-
),
|
|
120
|
+
notifMgr: await PostgresNotifListenManager.create(this.db_pg, this.onNotif, channel),
|
|
128
121
|
};
|
|
129
122
|
} else {
|
|
130
|
-
if (
|
|
131
|
-
socket &&
|
|
132
|
-
!this.notifies[notifChannel]!.sockets.find((s) => s.id === socket.id)
|
|
133
|
-
) {
|
|
123
|
+
if (socket && !this.notifies[notifChannel]!.sockets.find((s) => s.id === socket.id)) {
|
|
134
124
|
this.notifies[notifChannel]!.sockets.push(socket);
|
|
135
125
|
} else if (func) {
|
|
136
126
|
this.notifies[notifChannel]!.localFuncs.push(func);
|
|
@@ -155,13 +145,9 @@ export class DBEventsManager {
|
|
|
155
145
|
const notifChannel = channel && this.notifies[channel];
|
|
156
146
|
if (notifChannel) {
|
|
157
147
|
if (socket) {
|
|
158
|
-
notifChannel.sockets = notifChannel.sockets.filter(
|
|
159
|
-
(s) => s.id !== socket.id,
|
|
160
|
-
);
|
|
148
|
+
notifChannel.sockets = notifChannel.sockets.filter((s) => s.id !== socket.id);
|
|
161
149
|
} else if (func) {
|
|
162
|
-
notifChannel.localFuncs = notifChannel.localFuncs.filter(
|
|
163
|
-
(f) => f !== func,
|
|
164
|
-
);
|
|
150
|
+
notifChannel.localFuncs = notifChannel.localFuncs.filter((f) => f !== func);
|
|
165
151
|
}
|
|
166
152
|
|
|
167
153
|
/* UNLISTEN if no listeners ?? */
|
|
@@ -169,15 +155,15 @@ export class DBEventsManager {
|
|
|
169
155
|
|
|
170
156
|
if (socket) {
|
|
171
157
|
getKeys(this.notifies).forEach((channel) => {
|
|
172
|
-
this.notifies[channel]!.sockets = this.notifies[
|
|
173
|
-
|
|
174
|
-
|
|
158
|
+
this.notifies[channel]!.sockets = this.notifies[channel]!.sockets.filter(
|
|
159
|
+
(s) => s.id !== socket.id
|
|
160
|
+
);
|
|
175
161
|
});
|
|
176
162
|
}
|
|
177
163
|
}
|
|
178
164
|
|
|
179
165
|
addNotice(socket: PRGLIOSocket) {
|
|
180
|
-
if (!socket
|
|
166
|
+
if (!socket.id) throw "Expecting a socket obj with id";
|
|
181
167
|
|
|
182
168
|
if (!this.notice.sockets.find((s) => s.id === socket.id)) {
|
|
183
169
|
this.notice.sockets.push(socket);
|
|
@@ -194,7 +180,7 @@ export class DBEventsManager {
|
|
|
194
180
|
}
|
|
195
181
|
|
|
196
182
|
removeNotice(socket: PRGLIOSocket) {
|
|
197
|
-
if (!socket
|
|
183
|
+
if (!socket.id) throw "Expecting a socket obj with id";
|
|
198
184
|
this.notice.sockets = this.notice.sockets.filter((s) => s.id !== socket.id);
|
|
199
185
|
}
|
|
200
186
|
}
|
package/lib/DBSchemaBuilder.ts
CHANGED
|
@@ -40,7 +40,6 @@ import {
|
|
|
40
40
|
import { getTablesForSchemaPostgresSQL } from "./getTablesForSchemaPostgresSQL";
|
|
41
41
|
import { prepareShortestJoinPaths } from "./prepareShortestJoinPaths";
|
|
42
42
|
import { cacheDBTypes, runSQL } from "./runSQL";
|
|
43
|
-
import { runClientTransactionStatement } from "./runTransaction";
|
|
44
43
|
|
|
45
44
|
export * from "./DboBuilderTypes";
|
|
46
45
|
export * from "./dboBuilderUtils";
|
|
@@ -167,9 +166,7 @@ export class DboBuilder {
|
|
|
167
166
|
|
|
168
167
|
_joins?: Join[];
|
|
169
168
|
get joins(): Join[] {
|
|
170
|
-
return clone(this._joins ?? []).filter(
|
|
171
|
-
(j) => j.tables[0] !== j.tables[1],
|
|
172
|
-
) as Join[];
|
|
169
|
+
return clone(this._joins ?? []).filter((j) => j.tables[0] !== j.tables[1]) as Join[];
|
|
173
170
|
}
|
|
174
171
|
|
|
175
172
|
set joins(j: Join[]) {
|
|
@@ -181,8 +178,7 @@ export class DboBuilder {
|
|
|
181
178
|
}
|
|
182
179
|
|
|
183
180
|
prepareShortestJoinPaths = async () => {
|
|
184
|
-
const { joins, shortestJoinPaths, joinGraph } =
|
|
185
|
-
await prepareShortestJoinPaths(this);
|
|
181
|
+
const { joins, shortestJoinPaths, joinGraph } = await prepareShortestJoinPaths(this);
|
|
186
182
|
this.joinGraph = joinGraph;
|
|
187
183
|
this.joins = joins;
|
|
188
184
|
this.shortestJoinPaths = shortestJoinPaths;
|
|
@@ -192,7 +188,7 @@ export class DboBuilder {
|
|
|
192
188
|
query: string,
|
|
193
189
|
params: any,
|
|
194
190
|
options: SQLOptions | undefined,
|
|
195
|
-
localParams?: LocalParams
|
|
191
|
+
localParams?: LocalParams
|
|
196
192
|
) => {
|
|
197
193
|
return runSQL
|
|
198
194
|
.bind(this)(query, params, options, localParams)
|
|
@@ -201,8 +197,8 @@ export class DboBuilder {
|
|
|
201
197
|
getSerializedClientErrorFromPGError(error, {
|
|
202
198
|
type: "sql",
|
|
203
199
|
localParams,
|
|
204
|
-
})
|
|
205
|
-
)
|
|
200
|
+
})
|
|
201
|
+
)
|
|
206
202
|
);
|
|
207
203
|
};
|
|
208
204
|
|
|
@@ -215,7 +211,7 @@ export class DboBuilder {
|
|
|
215
211
|
if (subscribeError) {
|
|
216
212
|
console.error(
|
|
217
213
|
"Could not initiate PubSubManager. Realtime data/Subscriptions will not work. Error: ",
|
|
218
|
-
subscribeError
|
|
214
|
+
subscribeError
|
|
219
215
|
);
|
|
220
216
|
this.canSubscribe = false;
|
|
221
217
|
} else {
|
|
@@ -226,7 +222,7 @@ export class DboBuilder {
|
|
|
226
222
|
const start = Date.now();
|
|
227
223
|
const tablesOrViewsReq = await getTablesForSchemaPostgresSQL(
|
|
228
224
|
this,
|
|
229
|
-
this.prostgles.opts.schemaFilter
|
|
225
|
+
this.prostgles.opts.schemaFilter
|
|
230
226
|
);
|
|
231
227
|
await this.prostgles.opts.onLog?.({
|
|
232
228
|
type: "debug",
|
|
@@ -236,36 +232,30 @@ export class DboBuilder {
|
|
|
236
232
|
});
|
|
237
233
|
this.tablesOrViews = tablesOrViewsReq.result;
|
|
238
234
|
|
|
239
|
-
this.constraints = await getConstraints(
|
|
240
|
-
this.db,
|
|
241
|
-
this.prostgles.opts.schemaFilter,
|
|
242
|
-
);
|
|
235
|
+
this.constraints = await getConstraints(this.db, this.prostgles.opts.schemaFilter);
|
|
243
236
|
await this.prepareShortestJoinPaths();
|
|
244
237
|
|
|
245
238
|
this.dbo = {};
|
|
246
239
|
this.tablesOrViews.map((tov) => {
|
|
247
|
-
const columnsForTypes = tov.columns
|
|
248
|
-
.slice(0)
|
|
249
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
240
|
+
const columnsForTypes = tov.columns.slice(0).sort((a, b) => a.name.localeCompare(b.name));
|
|
250
241
|
|
|
251
242
|
const filterKeywords = Object.values(this.prostgles.keywords);
|
|
252
|
-
const $filterCol = columnsForTypes.find((c) =>
|
|
253
|
-
filterKeywords.includes(c.name),
|
|
254
|
-
);
|
|
243
|
+
const $filterCol = columnsForTypes.find((c) => filterKeywords.includes(c.name));
|
|
255
244
|
if ($filterCol) {
|
|
256
245
|
throw `DboBuilder init error: \n\nTable ${JSON.stringify(tov.name)} column ${JSON.stringify($filterCol.name)} is colliding with Prostgles filtering functionality ($filter keyword)
|
|
257
246
|
Please provide a replacement keyword name using the $filter_keyName init option.
|
|
258
247
|
Alternatively you can rename the table column\n`;
|
|
259
248
|
}
|
|
260
249
|
|
|
261
|
-
this.dbo[tov.escaped_identifier] = new (
|
|
262
|
-
|
|
263
|
-
|
|
250
|
+
this.dbo[tov.escaped_identifier] = new (tov.is_view ? ViewHandler : TableHandler)(
|
|
251
|
+
this.db,
|
|
252
|
+
tov,
|
|
253
|
+
this,
|
|
254
|
+
undefined,
|
|
255
|
+
this.shortestJoinPaths
|
|
256
|
+
);
|
|
264
257
|
|
|
265
|
-
if (
|
|
266
|
-
this.shortestJoinPaths &&
|
|
267
|
-
this.shortestJoinPaths.find((jp) => [jp.t1, jp.t2].includes(tov.name))
|
|
268
|
-
) {
|
|
258
|
+
if (this.shortestJoinPaths.find((jp) => [jp.t1, jp.t2].includes(tov.name))) {
|
|
269
259
|
const table = tov.name;
|
|
270
260
|
|
|
271
261
|
this.dbo.innerJoin ??= {};
|
|
@@ -293,9 +283,7 @@ export class DboBuilder {
|
|
|
293
283
|
if (!this.dbo.sql) {
|
|
294
284
|
this.dbo.sql = this.runSQL;
|
|
295
285
|
} else {
|
|
296
|
-
console.warn(
|
|
297
|
-
`Could not create dbo.sql handler because there is already a table named "sql"`,
|
|
298
|
-
);
|
|
286
|
+
console.warn(`Could not create dbo.sql handler because there is already a table named "sql"`);
|
|
299
287
|
}
|
|
300
288
|
|
|
301
289
|
this.tsTypesDefinition = [
|
|
@@ -309,18 +297,16 @@ export class DboBuilder {
|
|
|
309
297
|
|
|
310
298
|
getShortestJoinPath = (
|
|
311
299
|
viewHandler: ViewHandler,
|
|
312
|
-
target: string
|
|
300
|
+
target: string
|
|
313
301
|
): JoinPaths[number] | undefined => {
|
|
314
302
|
const source = viewHandler.name;
|
|
315
303
|
if (source === target) {
|
|
316
|
-
|
|
304
|
+
parseJoinPath({
|
|
317
305
|
rawPath: target,
|
|
318
306
|
rootTable: source,
|
|
319
307
|
viewHandler,
|
|
320
308
|
});
|
|
321
309
|
|
|
322
|
-
if (!joinPath) return undefined;
|
|
323
|
-
|
|
324
310
|
return {
|
|
325
311
|
t1: source,
|
|
326
312
|
t2: target,
|
|
@@ -328,9 +314,7 @@ export class DboBuilder {
|
|
|
328
314
|
};
|
|
329
315
|
}
|
|
330
316
|
|
|
331
|
-
const jp = this.shortestJoinPaths.find(
|
|
332
|
-
(jp) => jp.t1 === source && jp.t2 === target,
|
|
333
|
-
);
|
|
317
|
+
const jp = this.shortestJoinPaths.find((jp) => jp.t1 === source && jp.t2 === target);
|
|
334
318
|
return jp;
|
|
335
319
|
};
|
|
336
320
|
|
|
@@ -339,13 +323,7 @@ export class DboBuilder {
|
|
|
339
323
|
const dbTX: DbTxTableHandlers & Pick<DBHandlerServer, "sql"> = {};
|
|
340
324
|
this.tablesOrViews?.map((tov) => {
|
|
341
325
|
const handlerClass = tov.is_view ? ViewHandler : TableHandler;
|
|
342
|
-
dbTX[tov.name] = new handlerClass(
|
|
343
|
-
this.db,
|
|
344
|
-
tov,
|
|
345
|
-
this,
|
|
346
|
-
{ t, dbTX },
|
|
347
|
-
this.shortestJoinPaths,
|
|
348
|
-
);
|
|
326
|
+
dbTX[tov.name] = new handlerClass(this.db, tov, this, { t, dbTX }, this.shortestJoinPaths);
|
|
349
327
|
});
|
|
350
328
|
dbTX.sql = (q, args, opts, localP) =>
|
|
351
329
|
this.runSQL(q, args, opts, { tx: { dbTX, t }, ...(localP ?? {}) });
|
|
@@ -357,11 +335,4 @@ export class DboBuilder {
|
|
|
357
335
|
};
|
|
358
336
|
|
|
359
337
|
cacheDBTypes = cacheDBTypes.bind(this);
|
|
360
|
-
|
|
361
|
-
runClientTransactionStatement = (statement: string) => {
|
|
362
|
-
return runClientTransactionStatement(
|
|
363
|
-
statement,
|
|
364
|
-
this.prostgles.opts.dbConnection as any,
|
|
365
|
-
);
|
|
366
|
-
};
|
|
367
338
|
}
|