prostgles-server 4.2.187 → 4.2.188
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 +18 -11
- package/dist/Auth/AuthHandler.d.ts.map +1 -1
- package/dist/Auth/AuthHandler.js +94 -120
- package/dist/Auth/AuthHandler.js.map +1 -1
- package/dist/Auth/AuthTypes.d.ts +78 -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 +74 -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 +117 -137
- package/lib/Auth/AuthTypes.ts +97 -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 +83 -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
package/lib/SyncReplication.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PubSubManager,
|
|
3
|
-
SyncParams,
|
|
4
|
-
pickKeys,
|
|
5
|
-
omitKeys,
|
|
6
|
-
log,
|
|
7
|
-
} from "./PubSubManager/PubSubManager";
|
|
1
|
+
import { PubSubManager, SyncParams, pickKeys, omitKeys, log } from "./PubSubManager/PubSubManager";
|
|
8
2
|
import { OrderBy, WAL, AnyObject, SyncBatchParams } from "prostgles-types";
|
|
9
3
|
import { TableHandler } from "./DboBuilder/TableHandler/TableHandler";
|
|
10
4
|
|
|
@@ -45,12 +39,8 @@ export type ClientExpressData = ClientSyncInfo & {
|
|
|
45
39
|
deleted?: AnyObject[];
|
|
46
40
|
};
|
|
47
41
|
|
|
48
|
-
function getNumbers(
|
|
49
|
-
numberArr
|
|
50
|
-
): number[] {
|
|
51
|
-
return numberArr.filter(
|
|
52
|
-
(v) => v !== null && v !== undefined && Number.isFinite(+v),
|
|
53
|
-
) as any;
|
|
42
|
+
function getNumbers(numberArr: (null | undefined | string | number)[]): number[] {
|
|
43
|
+
return numberArr.filter((v) => v !== null && v !== undefined && Number.isFinite(+v)) as any;
|
|
54
44
|
}
|
|
55
45
|
|
|
56
46
|
/**
|
|
@@ -60,7 +50,7 @@ export async function syncData(
|
|
|
60
50
|
this: PubSubManager,
|
|
61
51
|
sync: SyncParams,
|
|
62
52
|
clientData: ClientExpressData | undefined,
|
|
63
|
-
source: "trigger" | "client"
|
|
53
|
+
source: "trigger" | "client"
|
|
64
54
|
) {
|
|
65
55
|
await this._log({
|
|
66
56
|
type: "sync",
|
|
@@ -70,9 +60,7 @@ export async function syncData(
|
|
|
70
60
|
source,
|
|
71
61
|
...pickKeys(sync, ["socket_id", "condition", "last_synced", "is_syncing"]),
|
|
72
62
|
lr: JSON.stringify(sync.lr),
|
|
73
|
-
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map(
|
|
74
|
-
(s) => s.id,
|
|
75
|
-
),
|
|
63
|
+
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map((s) => s.id),
|
|
76
64
|
localParams: undefined,
|
|
77
65
|
duration: -1,
|
|
78
66
|
socketId: sync.socket_id,
|
|
@@ -99,26 +87,14 @@ export async function syncData(
|
|
|
99
87
|
}
|
|
100
88
|
|
|
101
89
|
const sync_fields = [synced_field, ...id_fields.sort()],
|
|
102
|
-
orderByAsc: OrderBy = sync_fields.reduce(
|
|
103
|
-
(a, v) => ({ ...a, [v]: true }),
|
|
104
|
-
{},
|
|
105
|
-
),
|
|
90
|
+
orderByAsc: OrderBy = sync_fields.reduce((a, v) => ({ ...a, [v]: true }), {}),
|
|
106
91
|
rowsIdsMatch = (a?: AnyObject, b?: AnyObject) => {
|
|
107
|
-
return (
|
|
108
|
-
a &&
|
|
109
|
-
b &&
|
|
110
|
-
!id_fields.find((key) => a[key].toString() !== b[key].toString())
|
|
111
|
-
);
|
|
92
|
+
return a && b && !id_fields.find((key) => a[key].toString() !== b[key].toString());
|
|
112
93
|
},
|
|
113
94
|
rowsFullyMatch = (a?: AnyObject, b?: AnyObject) => {
|
|
114
|
-
return (
|
|
115
|
-
rowsIdsMatch(a, b) &&
|
|
116
|
-
a?.[synced_field].toString() === b?.[synced_field].toString()
|
|
117
|
-
);
|
|
95
|
+
return rowsIdsMatch(a, b) && a?.[synced_field].toString() === b?.[synced_field].toString();
|
|
118
96
|
},
|
|
119
|
-
getServerRowInfo = async (
|
|
120
|
-
args: SyncBatchParams = {},
|
|
121
|
-
): Promise<ServerSyncInfo> => {
|
|
97
|
+
getServerRowInfo = async (args: SyncBatchParams = {}): Promise<ServerSyncInfo> => {
|
|
122
98
|
const { from_synced = null, to_synced = null, offset = 0, limit } = args;
|
|
123
99
|
const _filter: AnyObject = { ...filter };
|
|
124
100
|
|
|
@@ -128,27 +104,19 @@ export async function syncData(
|
|
|
128
104
|
...(to_synced ? { $lte: to_synced } : {}),
|
|
129
105
|
};
|
|
130
106
|
}
|
|
131
|
-
if (
|
|
132
|
-
this.dbo?.[table_name]?.find === undefined ||
|
|
133
|
-
this?.dbo?.[table_name]?.count === undefined
|
|
134
|
-
) {
|
|
107
|
+
if (this.dbo[table_name]?.find === undefined || this.dbo[table_name]?.count === undefined) {
|
|
135
108
|
throw `dbo.${table_name}.find or .count are missing or not allowed`;
|
|
136
109
|
}
|
|
137
110
|
|
|
138
|
-
const first_rows = await this.dbo
|
|
111
|
+
const first_rows = await this.dbo[table_name]?.find?.(
|
|
139
112
|
_filter,
|
|
140
113
|
{ orderBy: orderByAsc, select: sync_fields, limit, offset },
|
|
141
114
|
undefined,
|
|
142
|
-
table_rules
|
|
115
|
+
table_rules
|
|
143
116
|
);
|
|
144
117
|
const last_rows = first_rows?.slice(-1); // Why not logic below?
|
|
145
118
|
// const last_rows = await _this?.dbo[table_name]?.find?.(_filter, { orderBy: (orderByDesc as OrderBy), select: sync_fields, limit: 1, offset: -offset || 0 }, null, table_rules);
|
|
146
|
-
const count = await this.dbo
|
|
147
|
-
_filter,
|
|
148
|
-
undefined,
|
|
149
|
-
undefined,
|
|
150
|
-
table_rules,
|
|
151
|
-
);
|
|
119
|
+
const count = await this.dbo[table_name]?.count?.(_filter, undefined, undefined, table_rules);
|
|
152
120
|
|
|
153
121
|
return {
|
|
154
122
|
s_fr: first_rows?.[0] || null,
|
|
@@ -160,22 +128,18 @@ export async function syncData(
|
|
|
160
128
|
const { from_synced = null, to_synced = null, end_offset = null } = args;
|
|
161
129
|
const res = new Promise<any>((resolve, reject) => {
|
|
162
130
|
const onSyncRequest = { from_synced, to_synced, end_offset }; //, forReal: true };
|
|
163
|
-
socket.emit(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
reject(resp.err);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
);
|
|
131
|
+
socket.emit(channel_name, { onSyncRequest }, (resp?: onSyncRequestResponse) => {
|
|
132
|
+
if (resp && "onSyncRequest" in resp && resp.onSyncRequest) {
|
|
133
|
+
const c_fr = resp.onSyncRequest.c_fr,
|
|
134
|
+
c_lr = resp.onSyncRequest.c_lr,
|
|
135
|
+
c_count = resp.onSyncRequest.c_count;
|
|
136
|
+
|
|
137
|
+
// console.log(onSyncRequest, { c_fr, c_lr, c_count }, socket._user);
|
|
138
|
+
return resolve({ c_fr, c_lr, c_count });
|
|
139
|
+
} else if (resp && "err" in resp && resp.err) {
|
|
140
|
+
reject(resp.err);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
179
143
|
});
|
|
180
144
|
|
|
181
145
|
return res;
|
|
@@ -187,20 +151,14 @@ export async function syncData(
|
|
|
187
151
|
offset: offset || 0,
|
|
188
152
|
limit: batch_size,
|
|
189
153
|
};
|
|
190
|
-
socket.emit(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
reject(
|
|
199
|
-
"unexpected onPullRequest response: " + JSON.stringify(resp),
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
);
|
|
154
|
+
socket.emit(channel_name, { onPullRequest }, async (resp?: { data?: AnyObject[] }) => {
|
|
155
|
+
if (resp && resp.data && Array.isArray(resp.data)) {
|
|
156
|
+
// console.log({ onPullRequest, resp }, socket._user)
|
|
157
|
+
resolve(sortClientData(resp.data));
|
|
158
|
+
} else {
|
|
159
|
+
reject("unexpected onPullRequest response: " + JSON.stringify(resp));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
204
162
|
});
|
|
205
163
|
|
|
206
164
|
function sortClientData(data: AnyObject[]) {
|
|
@@ -211,7 +169,9 @@ export async function syncData(
|
|
|
211
169
|
id_fields
|
|
212
170
|
.sort()
|
|
213
171
|
.map((idKey) =>
|
|
214
|
-
a[idKey] < b[idKey] ? -1
|
|
172
|
+
a[idKey] < b[idKey] ? -1
|
|
173
|
+
: a[idKey] > b[idKey] ? 1
|
|
174
|
+
: 0
|
|
215
175
|
)
|
|
216
176
|
.find((v) => v) ||
|
|
217
177
|
0
|
|
@@ -219,20 +179,16 @@ export async function syncData(
|
|
|
219
179
|
});
|
|
220
180
|
}
|
|
221
181
|
},
|
|
222
|
-
getServerData = async (
|
|
223
|
-
from_synced = 0,
|
|
224
|
-
offset = 0,
|
|
225
|
-
): Promise<AnyObject[]> => {
|
|
182
|
+
getServerData = async (from_synced = 0, offset = 0): Promise<AnyObject[]> => {
|
|
226
183
|
const _filter = {
|
|
227
184
|
...filter,
|
|
228
185
|
[synced_field]: { $gte: from_synced || 0 },
|
|
229
186
|
};
|
|
230
187
|
|
|
231
|
-
if (!this?.dbo?.[table_name]?.find
|
|
232
|
-
throw "_this?.dbo?.[table_name]?.find is missing";
|
|
188
|
+
if (!this.dbo[table_name]?.find) throw "_this?.dbo?.[table_name]?.find is missing";
|
|
233
189
|
|
|
234
190
|
try {
|
|
235
|
-
const res = this
|
|
191
|
+
const res = this.dbo[table_name]?.find?.(
|
|
236
192
|
_filter,
|
|
237
193
|
{
|
|
238
194
|
select: params.select,
|
|
@@ -241,7 +197,7 @@ export async function syncData(
|
|
|
241
197
|
limit: batch_size,
|
|
242
198
|
},
|
|
243
199
|
undefined,
|
|
244
|
-
table_rules
|
|
200
|
+
table_rules
|
|
245
201
|
);
|
|
246
202
|
|
|
247
203
|
if (!res) throw "_this?.dbo?.[table_name]?.find is missing";
|
|
@@ -263,19 +219,17 @@ export async function syncData(
|
|
|
263
219
|
id_filter,
|
|
264
220
|
undefined,
|
|
265
221
|
undefined,
|
|
266
|
-
table_rules
|
|
222
|
+
table_rules
|
|
267
223
|
);
|
|
268
224
|
return 1;
|
|
269
225
|
} catch (e) {
|
|
270
226
|
console.error(e);
|
|
271
227
|
}
|
|
272
228
|
return 0;
|
|
273
|
-
})
|
|
229
|
+
})
|
|
274
230
|
);
|
|
275
231
|
} else {
|
|
276
|
-
console.warn(
|
|
277
|
-
"client tried to delete data without permission (allow_delete is false)",
|
|
278
|
-
);
|
|
232
|
+
console.warn("client tried to delete data without permission (allow_delete is false)");
|
|
279
233
|
}
|
|
280
234
|
return false;
|
|
281
235
|
},
|
|
@@ -294,16 +248,11 @@ export async function syncData(
|
|
|
294
248
|
orderBy: orderByAsc as OrderBy,
|
|
295
249
|
},
|
|
296
250
|
undefined,
|
|
297
|
-
table_rules
|
|
298
|
-
);
|
|
299
|
-
let inserts = data.filter(
|
|
300
|
-
(d) => !existingData.find((ed) => rowsIdsMatch(ed, d)),
|
|
251
|
+
table_rules
|
|
301
252
|
);
|
|
253
|
+
let inserts = data.filter((d) => !existingData.find((ed) => rowsIdsMatch(ed, d)));
|
|
302
254
|
let updates = data.filter((d) =>
|
|
303
|
-
existingData.find(
|
|
304
|
-
(ed) =>
|
|
305
|
-
rowsIdsMatch(ed, d) && +ed[synced_field] < +d[synced_field],
|
|
306
|
-
),
|
|
255
|
+
existingData.find((ed) => rowsIdsMatch(ed, d) && +ed[synced_field] < +d[synced_field])
|
|
307
256
|
);
|
|
308
257
|
try {
|
|
309
258
|
if (!table_rules) throw "table_rules missing";
|
|
@@ -314,32 +263,24 @@ export async function syncData(
|
|
|
314
263
|
updates.map((upd) => {
|
|
315
264
|
const id_filter = pickKeys(upd, id_fields);
|
|
316
265
|
const syncSafeFilter = {
|
|
317
|
-
$and: [
|
|
318
|
-
id_filter,
|
|
319
|
-
{ [synced_field]: { "<": upd[synced_field] } },
|
|
320
|
-
],
|
|
266
|
+
$and: [id_filter, { [synced_field]: { "<": upd[synced_field] } }],
|
|
321
267
|
};
|
|
322
268
|
|
|
323
269
|
updateData.push([syncSafeFilter, omitKeys(upd, id_fields)]);
|
|
324
|
-
})
|
|
270
|
+
})
|
|
325
271
|
);
|
|
326
272
|
await tbl.updateBatch(
|
|
327
273
|
updateData,
|
|
328
274
|
{ removeDisallowedFields: true },
|
|
329
275
|
undefined,
|
|
330
|
-
table_rules
|
|
276
|
+
table_rules
|
|
331
277
|
);
|
|
332
278
|
} else {
|
|
333
279
|
updates = [];
|
|
334
280
|
}
|
|
335
281
|
|
|
336
282
|
if (table_rules.insert && inserts.length) {
|
|
337
|
-
await tbl.insert(
|
|
338
|
-
inserts,
|
|
339
|
-
{ removeDisallowedFields: true },
|
|
340
|
-
undefined,
|
|
341
|
-
table_rules,
|
|
342
|
-
);
|
|
283
|
+
await tbl.insert(inserts, { removeDisallowedFields: true }, undefined, table_rules);
|
|
343
284
|
} else {
|
|
344
285
|
inserts = [];
|
|
345
286
|
}
|
|
@@ -352,7 +293,7 @@ export async function syncData(
|
|
|
352
293
|
})
|
|
353
294
|
.then(({ inserts, updates }) => {
|
|
354
295
|
log(
|
|
355
|
-
`upsertData: inserted( ${inserts.length} ) updated( ${updates.length} ) total( ${data.length} ) \n last insert ${JSON.stringify(inserts.at(-1))} \n last update ${JSON.stringify(updates.at(-1))}
|
|
296
|
+
`upsertData: inserted( ${inserts.length} ) updated( ${updates.length} ) total( ${data.length} ) \n last insert ${JSON.stringify(inserts.at(-1))} \n last update ${JSON.stringify(updates.at(-1))}`
|
|
356
297
|
);
|
|
357
298
|
return {
|
|
358
299
|
inserted: inserts.length,
|
|
@@ -365,11 +306,9 @@ export async function syncData(
|
|
|
365
306
|
"Something went wrong with syncing to server: \n ->",
|
|
366
307
|
err,
|
|
367
308
|
data.length,
|
|
368
|
-
id_fields
|
|
369
|
-
);
|
|
370
|
-
return Promise.reject(
|
|
371
|
-
"Something went wrong with syncing to server: ",
|
|
309
|
+
id_fields
|
|
372
310
|
);
|
|
311
|
+
return Promise.reject("Something went wrong with syncing to server: ");
|
|
373
312
|
});
|
|
374
313
|
|
|
375
314
|
await this._log({
|
|
@@ -380,9 +319,7 @@ export async function syncData(
|
|
|
380
319
|
socketId: socket_id,
|
|
381
320
|
sid: sync.sid,
|
|
382
321
|
duration: Date.now() - start,
|
|
383
|
-
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map(
|
|
384
|
-
(s) => s.id,
|
|
385
|
-
),
|
|
322
|
+
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map((s) => s.id),
|
|
386
323
|
});
|
|
387
324
|
|
|
388
325
|
return result;
|
|
@@ -391,26 +328,18 @@ export async function syncData(
|
|
|
391
328
|
* Pushes the given data to client
|
|
392
329
|
* @param isSynced = true if
|
|
393
330
|
*/
|
|
394
|
-
pushData = async (
|
|
395
|
-
data?: AnyObject[],
|
|
396
|
-
isSynced = false,
|
|
397
|
-
err: any = null,
|
|
398
|
-
) => {
|
|
331
|
+
pushData = async (data?: AnyObject[], isSynced = false, err: any = null) => {
|
|
399
332
|
const start = Date.now();
|
|
400
333
|
const result = await new Promise((resolve, reject) => {
|
|
401
|
-
socket.emit(
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
console.error("Unexpected response");
|
|
411
|
-
}
|
|
412
|
-
},
|
|
413
|
-
);
|
|
334
|
+
socket.emit(channel_name, { data, isSynced }, (resp?: { ok: boolean }) => {
|
|
335
|
+
if (resp && resp.ok) {
|
|
336
|
+
// console.log("PUSHED to client: fr/lr", data[0], data[data.length - 1]);
|
|
337
|
+
resolve({ pushed: data?.length, resp });
|
|
338
|
+
} else {
|
|
339
|
+
reject(resp);
|
|
340
|
+
console.error("Unexpected response");
|
|
341
|
+
}
|
|
342
|
+
});
|
|
414
343
|
});
|
|
415
344
|
|
|
416
345
|
await this._log({
|
|
@@ -421,9 +350,7 @@ export async function syncData(
|
|
|
421
350
|
socketId: socket_id,
|
|
422
351
|
duration: Date.now() - start,
|
|
423
352
|
sid: sync.sid,
|
|
424
|
-
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map(
|
|
425
|
-
(s) => s.id,
|
|
426
|
-
),
|
|
353
|
+
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map((s) => s.id),
|
|
427
354
|
});
|
|
428
355
|
|
|
429
356
|
return result;
|
|
@@ -433,12 +360,9 @@ export async function syncData(
|
|
|
433
360
|
* If last rows don't match it will find an earlier matching last row and use that last matching from_synced
|
|
434
361
|
* If no rows or fully synced (c_lr and s_lr match) then returns null
|
|
435
362
|
*/
|
|
436
|
-
getLastSynced = async (
|
|
437
|
-
clientSyncInfo?: ClientSyncInfo,
|
|
438
|
-
): Promise<number | null> => {
|
|
363
|
+
getLastSynced = async (clientSyncInfo?: ClientSyncInfo): Promise<number | null> => {
|
|
439
364
|
// Get latest row info
|
|
440
|
-
const { c_fr, c_lr, c_count } =
|
|
441
|
-
clientSyncInfo || (await getClientRowInfo());
|
|
365
|
+
const { c_fr, c_lr, c_count } = clientSyncInfo || (await getClientRowInfo());
|
|
442
366
|
const { s_fr, s_lr, s_count } = await getServerRowInfo();
|
|
443
367
|
|
|
444
368
|
// console.log("getLastSynced", clientData, socket._user )
|
|
@@ -462,13 +386,9 @@ export async function syncData(
|
|
|
462
386
|
/* Sync from last matching synced value */
|
|
463
387
|
} else if (rowsFullyMatch(c_fr, s_fr)) {
|
|
464
388
|
if (s_lr && c_lr) {
|
|
465
|
-
result = Math.min(
|
|
466
|
-
...getNumbers([c_lr[synced_field], s_lr[synced_field]]),
|
|
467
|
-
);
|
|
389
|
+
result = Math.min(...getNumbers([c_lr[synced_field], s_lr[synced_field]]));
|
|
468
390
|
} else {
|
|
469
|
-
result = Math.min(
|
|
470
|
-
...getNumbers([c_fr[synced_field], s_fr?.[synced_field]]),
|
|
471
|
-
);
|
|
391
|
+
result = Math.min(...getNumbers([c_fr[synced_field], s_fr?.[synced_field]]));
|
|
472
392
|
}
|
|
473
393
|
|
|
474
394
|
const min_count = Math.min(...getNumbers([c_count, s_count]));
|
|
@@ -489,11 +409,11 @@ export async function syncData(
|
|
|
489
409
|
sync_fields.map((key) => {
|
|
490
410
|
_filter[key] = c_lr[key];
|
|
491
411
|
});
|
|
492
|
-
server_row = await this
|
|
412
|
+
server_row = await this.dbo[table_name]?.find?.(
|
|
493
413
|
_filter,
|
|
494
414
|
{ select: sync_fields, limit: 1 },
|
|
495
415
|
undefined,
|
|
496
|
-
table_rules
|
|
416
|
+
table_rules
|
|
497
417
|
);
|
|
498
418
|
}
|
|
499
419
|
|
|
@@ -518,16 +438,12 @@ export async function syncData(
|
|
|
518
438
|
updateSyncLR = (data: AnyObject) => {
|
|
519
439
|
if (data.length) {
|
|
520
440
|
const lastRow = data[data.length - 1];
|
|
521
|
-
if (
|
|
522
|
-
sync.lr?.[synced_field] &&
|
|
523
|
-
+sync.lr?.[synced_field] > +lastRow[synced_field]
|
|
524
|
-
) {
|
|
441
|
+
if (sync.lr?.[synced_field] && +sync.lr[synced_field] > +lastRow[synced_field]) {
|
|
525
442
|
console.error(
|
|
526
443
|
{
|
|
527
|
-
syncIssue:
|
|
528
|
-
"sync.lr[synced_field] is greater than lastRow[synced_field]",
|
|
444
|
+
syncIssue: "sync.lr[synced_field] is greater than lastRow[synced_field]",
|
|
529
445
|
},
|
|
530
|
-
sync.table_name
|
|
446
|
+
sync.table_name
|
|
531
447
|
);
|
|
532
448
|
}
|
|
533
449
|
sync.lr = lastRow;
|
|
@@ -553,31 +469,27 @@ export async function syncData(
|
|
|
553
469
|
// console.log("syncBatch", from_synced)
|
|
554
470
|
|
|
555
471
|
while (canContinue) {
|
|
556
|
-
const
|
|
472
|
+
const clientData = await getClientData(min_synced, offset);
|
|
557
473
|
|
|
558
|
-
if (
|
|
559
|
-
const res = await upsertData(
|
|
474
|
+
if (clientData.length) {
|
|
475
|
+
const res = await upsertData(clientData);
|
|
560
476
|
inserted += res.inserted;
|
|
561
477
|
updated += res.updated;
|
|
562
478
|
}
|
|
563
|
-
let
|
|
479
|
+
let serverData: AnyObject[] | undefined;
|
|
564
480
|
|
|
565
481
|
try {
|
|
566
|
-
|
|
482
|
+
serverData = await getServerData(min_synced, offset);
|
|
567
483
|
} catch (e) {
|
|
568
484
|
console.trace("sync getServerData err", e);
|
|
569
|
-
await pushData(
|
|
570
|
-
undefined,
|
|
571
|
-
undefined,
|
|
572
|
-
"Internal error. Check server logs",
|
|
573
|
-
);
|
|
485
|
+
await pushData(undefined, undefined, "Internal error. Check server logs");
|
|
574
486
|
throw " d";
|
|
575
487
|
}
|
|
576
488
|
|
|
577
489
|
// console.log("allow_delete", table_rules.delete);
|
|
578
490
|
if (allow_delete && table_rules?.delete) {
|
|
579
|
-
const to_delete =
|
|
580
|
-
!
|
|
491
|
+
const to_delete = serverData.filter((d) => {
|
|
492
|
+
return !clientData.find((c) => rowsIdsMatch(c, d));
|
|
581
493
|
});
|
|
582
494
|
await Promise.all(
|
|
583
495
|
to_delete.map((d) => {
|
|
@@ -586,38 +498,38 @@ export async function syncData(
|
|
|
586
498
|
pickKeys(d, id_fields),
|
|
587
499
|
{},
|
|
588
500
|
undefined,
|
|
589
|
-
table_rules
|
|
501
|
+
table_rules
|
|
590
502
|
);
|
|
591
|
-
})
|
|
503
|
+
})
|
|
592
504
|
);
|
|
593
|
-
|
|
505
|
+
serverData = await getServerData(min_synced, offset);
|
|
594
506
|
}
|
|
595
507
|
|
|
596
|
-
const forClient =
|
|
597
|
-
return !
|
|
598
|
-
(c) => rowsIdsMatch(c, s) && +c[synced_field] >= +s[synced_field]
|
|
508
|
+
const forClient = serverData.filter((s) => {
|
|
509
|
+
return !clientData.find(
|
|
510
|
+
(c) => rowsIdsMatch(c, s) && +c[synced_field] >= +s[synced_field]
|
|
599
511
|
);
|
|
600
512
|
});
|
|
601
513
|
if (forClient.length) {
|
|
602
514
|
const res: any = await pushData(
|
|
603
|
-
forClient.filter((d) => !sync.wal || !sync.wal.isInHistory(d))
|
|
515
|
+
forClient.filter((d) => !sync.wal || !sync.wal.isInHistory(d))
|
|
604
516
|
);
|
|
605
517
|
pushed += res.pushed;
|
|
606
518
|
}
|
|
607
519
|
|
|
608
|
-
if (
|
|
609
|
-
updateSyncLR(
|
|
610
|
-
total +=
|
|
520
|
+
if (serverData.length) {
|
|
521
|
+
updateSyncLR(serverData);
|
|
522
|
+
total += serverData.length;
|
|
611
523
|
}
|
|
612
|
-
offset +=
|
|
524
|
+
offset += serverData.length;
|
|
613
525
|
|
|
614
526
|
// canContinue = offset >= limit;
|
|
615
|
-
canContinue =
|
|
527
|
+
canContinue = serverData.length >= limit;
|
|
616
528
|
// console.log(`sData ${sData.length} limit ${limit}`);
|
|
617
529
|
}
|
|
618
530
|
log(
|
|
619
531
|
`server.syncBatch ${table_name}: inserted( ${inserted} ) updated( ${updated} ) deleted( ${deleted} ) pushed to client( ${pushed} ) total( ${total} )`,
|
|
620
|
-
socket._user
|
|
532
|
+
socket._user
|
|
621
533
|
);
|
|
622
534
|
|
|
623
535
|
return true;
|
|
@@ -686,13 +598,7 @@ export async function syncData(
|
|
|
686
598
|
* Add to WAL manager which will sync at the end
|
|
687
599
|
*/
|
|
688
600
|
if (clientData) {
|
|
689
|
-
if (
|
|
690
|
-
clientData.data &&
|
|
691
|
-
Array.isArray(clientData.data) &&
|
|
692
|
-
clientData.data.length
|
|
693
|
-
) {
|
|
694
|
-
if (!sync.wal) throw "sync.wal missing";
|
|
695
|
-
|
|
601
|
+
if (clientData.data && Array.isArray(clientData.data) && clientData.data.length) {
|
|
696
602
|
sync.wal.addData(clientData.data.map((d) => ({ current: d })));
|
|
697
603
|
return;
|
|
698
604
|
// await upsertData(clientData.data, true);
|
|
@@ -56,7 +56,7 @@ type BaseTableDefinition<LANG_IDS = AnyObject> = {
|
|
|
56
56
|
* The returned row must satisfy the table schema
|
|
57
57
|
*/
|
|
58
58
|
getPreInsertRow?: (
|
|
59
|
-
args: GetPreInsertRowArgs
|
|
59
|
+
args: GetPreInsertRowArgs
|
|
60
60
|
) => Promise<{ row: AnyObject; onInserted: Promise<void> }>;
|
|
61
61
|
};
|
|
62
62
|
triggers?: {
|
|
@@ -169,9 +169,7 @@ type MediaColumn = {
|
|
|
169
169
|
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
|
|
170
170
|
*/
|
|
171
171
|
allowedContentType?: Record<
|
|
172
|
-
Partial<
|
|
173
|
-
"audio/*" | "video/*" | "image/*" | "text/*" | ALLOWED_CONTENT_TYPE
|
|
174
|
-
>,
|
|
172
|
+
Partial<"audio/*" | "video/*" | "image/*" | "text/*" | ALLOWED_CONTENT_TYPE>,
|
|
175
173
|
1
|
|
176
174
|
>;
|
|
177
175
|
}
|
|
@@ -219,13 +217,7 @@ export type ColumnConfig<LANG_IDS = { en: 1 }> =
|
|
|
219
217
|
| NamedJoinColumn
|
|
220
218
|
| MediaColumn
|
|
221
219
|
| (BaseColumn<LANG_IDS> &
|
|
222
|
-
(
|
|
223
|
-
| SQLDefColumn
|
|
224
|
-
| ReferencedColumn
|
|
225
|
-
| TextColumn
|
|
226
|
-
| JSONBColumnDef
|
|
227
|
-
| Enum
|
|
228
|
-
))
|
|
220
|
+
(SQLDefColumn | ReferencedColumn | TextColumn | JSONBColumnDef | Enum))
|
|
229
221
|
>;
|
|
230
222
|
|
|
231
223
|
export type ColumnConfigs<LANG_IDS = { en: 1 }> = {
|
|
@@ -239,9 +231,8 @@ export type ColumnConfigs<LANG_IDS = { en: 1 }> = {
|
|
|
239
231
|
};
|
|
240
232
|
|
|
241
233
|
type UnionKeys<T> = T extends T ? keyof T : never;
|
|
242
|
-
type StrictUnionHelper<T, TAll> =
|
|
243
|
-
? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>>
|
|
244
|
-
: never;
|
|
234
|
+
type StrictUnionHelper<T, TAll> =
|
|
235
|
+
T extends any ? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>> : never;
|
|
245
236
|
export type StrictUnion<T> = StrictUnionHelper<T, T>;
|
|
246
237
|
|
|
247
238
|
export const CONSTRAINT_TYPES = ["PRIMARY KEY", "UNIQUE", "CHECK"] as const;
|
|
@@ -394,22 +385,16 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
394
385
|
}
|
|
395
386
|
};
|
|
396
387
|
|
|
397
|
-
getColumnConfig = (
|
|
398
|
-
tableName
|
|
399
|
-
colName: string,
|
|
400
|
-
): ColumnConfig | undefined => {
|
|
401
|
-
const tconf = this.config?.[tableName];
|
|
388
|
+
getColumnConfig = (tableName: string, colName: string): ColumnConfig | undefined => {
|
|
389
|
+
const tconf = this.config[tableName];
|
|
402
390
|
if (tconf && "columns" in tconf) {
|
|
403
391
|
return tconf.columns?.[colName];
|
|
404
392
|
}
|
|
405
393
|
return undefined;
|
|
406
394
|
};
|
|
407
395
|
|
|
408
|
-
getTableInfo = (params: {
|
|
409
|
-
tableName
|
|
410
|
-
lang?: string;
|
|
411
|
-
}): TableInfo["info"] | undefined => {
|
|
412
|
-
const tconf = this.config?.[params.tableName];
|
|
396
|
+
getTableInfo = (params: { tableName: string; lang?: string }): TableInfo["info"] | undefined => {
|
|
397
|
+
const tconf = this.config[params.tableName];
|
|
413
398
|
|
|
414
399
|
return {
|
|
415
400
|
label: parseI18N<LANG_IDS, string>({
|
|
@@ -425,16 +410,13 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
425
410
|
col: string;
|
|
426
411
|
table: string;
|
|
427
412
|
lang?: string;
|
|
428
|
-
}):
|
|
429
|
-
| (ColExtraInfo & { label?: string } & Pick<ColumnInfo, "jsonbSchema">)
|
|
430
|
-
| undefined => {
|
|
413
|
+
}): (ColExtraInfo & { label?: string } & Pick<ColumnInfo, "jsonbSchema">) | undefined => {
|
|
431
414
|
const colConf = this.getColumnConfig(params.table, params.col);
|
|
432
415
|
let result: Partial<ReturnType<typeof this.getColInfo>> = undefined;
|
|
433
416
|
if (colConf) {
|
|
434
417
|
if (isObject(colConf)) {
|
|
435
418
|
const { jsonbSchema, jsonbSchemaType, info } = colConf;
|
|
436
419
|
result = {
|
|
437
|
-
...(result ?? {}),
|
|
438
420
|
...info,
|
|
439
421
|
...((jsonbSchema || jsonbSchemaType) && {
|
|
440
422
|
jsonbSchema: {
|
|
@@ -449,14 +431,14 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
449
431
|
*/
|
|
450
432
|
if (colConf.label) {
|
|
451
433
|
const { lang } = params;
|
|
452
|
-
const lbl = colConf
|
|
434
|
+
const lbl = colConf.label;
|
|
453
435
|
if (["string", "object"].includes(typeof lbl)) {
|
|
454
436
|
if (typeof lbl === "string") {
|
|
455
437
|
result ??= {};
|
|
456
438
|
result.label = lbl;
|
|
457
|
-
} else if (lang && (lbl
|
|
439
|
+
} else if (lang && (lbl[lang as "en"] || lbl.en)) {
|
|
458
440
|
result ??= {};
|
|
459
|
-
result.label = lbl
|
|
441
|
+
result.label = lbl[lang as "en"] || lbl.en;
|
|
460
442
|
}
|
|
461
443
|
}
|
|
462
444
|
}
|
|
@@ -478,12 +460,8 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
478
460
|
}
|
|
479
461
|
};
|
|
480
462
|
|
|
481
|
-
getJoinInfo = (
|
|
482
|
-
sourceTable: string,
|
|
483
|
-
targetTable: string,
|
|
484
|
-
): JoinInfo | undefined => {
|
|
463
|
+
getJoinInfo = (sourceTable: string, targetTable: string): JoinInfo | undefined => {
|
|
485
464
|
if (
|
|
486
|
-
this.config &&
|
|
487
465
|
sourceTable in this.config &&
|
|
488
466
|
this.config[sourceTable] &&
|
|
489
467
|
"columns" in this.config[sourceTable]!
|
|
@@ -513,9 +491,9 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
513
491
|
|
|
514
492
|
getPreInsertRow = async (
|
|
515
493
|
tableHandler: TableHandler,
|
|
516
|
-
args: Pick<GetPreInsertRowArgs, "localParams" | "row" | "validate" | "dbx"
|
|
494
|
+
args: Pick<GetPreInsertRowArgs, "localParams" | "row" | "validate" | "dbx">
|
|
517
495
|
): Promise<AnyObject> => {
|
|
518
|
-
const tableHook = this.config
|
|
496
|
+
const tableHook = this.config[tableHandler.name]?.hooks?.getPreInsertRow;
|
|
519
497
|
if (tableHandler.is_media) {
|
|
520
498
|
return uploadFile.bind(tableHandler)(args) as Promise<AnyObject>;
|
|
521
499
|
}
|