prostgles-server 4.2.507 → 4.2.509
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DBSchemaBuilder/DBSchemaBuilder.d.ts +2 -2
- package/dist/DBSchemaBuilder/DBSchemaBuilder.d.ts.map +1 -1
- package/dist/DBSchemaBuilder/DBSchemaBuilder.spec.js +0 -4
- package/dist/DBSchemaBuilder/DBSchemaBuilder.spec.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts +4 -5
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +13 -22
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.d.ts +15 -23
- package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.js +1 -1
- 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 +9 -8
- package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
- package/dist/DboBuilder/TableHandler/insert/insert.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/insert/insert.js +1 -1
- package/dist/DboBuilder/TableHandler/insert/insert.js.map +1 -1
- package/dist/DboBuilder/TableHandler/insert/insertRowWithNestedRecords.js +2 -2
- package/dist/DboBuilder/TableHandler/insert/insertRowWithNestedRecords.js.map +1 -1
- package/dist/DboBuilder/TableHandler/insertTest.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/insertTest.js +1 -1
- package/dist/DboBuilder/TableHandler/insertTest.js.map +1 -1
- package/dist/DboBuilder/TableHandler/updateFile.js +1 -1
- package/dist/DboBuilder/TableHandler/updateFile.js.map +1 -1
- package/dist/DboBuilder/TableRules/{getValidatedRules.d.ts → getValidatedTableRules.d.ts} +2 -2
- package/dist/DboBuilder/TableRules/getValidatedTableRules.d.ts.map +1 -0
- package/dist/DboBuilder/TableRules/{getValidatedRules.js → getValidatedTableRules.js} +5 -13
- package/dist/DboBuilder/TableRules/getValidatedTableRules.js.map +1 -0
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +3 -7
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +2 -35
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getInfo.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/getInfo.js +20 -16
- package/dist/DboBuilder/ViewHandler/getInfo.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.d.ts +2 -2
- package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.js +2 -2
- package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/subscribe.js +1 -1
- package/dist/DboBuilder/ViewHandler/subscribe.js.map +1 -1
- package/dist/DboBuilder/getColumns.d.ts.map +1 -1
- package/dist/DboBuilder/getColumns.js +0 -2
- package/dist/DboBuilder/getColumns.js.map +1 -1
- package/dist/FileManager/FileManager.d.ts.map +1 -1
- package/dist/FileManager/FileManager.js +3 -3
- package/dist/FileManager/FileManager.js.map +1 -1
- package/dist/FileManager/initFileManager.js +1 -1
- package/dist/FileManager/initFileManager.js.map +1 -1
- package/dist/Prostgles.d.ts +1 -1
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +9 -1
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +5 -7
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/PubSubManagerUtils.d.ts +1 -0
- package/dist/PubSubManager/PubSubManagerUtils.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManagerUtils.js +2 -1
- package/dist/PubSubManager/PubSubManagerUtils.js.map +1 -1
- package/dist/PubSubManager/addSync.d.ts.map +1 -1
- package/dist/PubSubManager/addSync.js +5 -5
- package/dist/PubSubManager/addSync.js.map +1 -1
- package/dist/PubSubManager/addTrigger.js +1 -1
- package/dist/PubSubManager/addTrigger.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts +1 -2
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +23 -12
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getDBSchemaTable.d.ts +6 -0
- package/dist/PublishParser/getDBSchemaTable.d.ts.map +1 -0
- package/dist/PublishParser/getDBSchemaTable.js +58 -0
- package/dist/PublishParser/getDBSchemaTable.js.map +1 -0
- package/dist/PublishParser/getSchemaFromPublish.d.ts +1 -2
- package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +39 -104
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js +58 -127
- package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.d.ts +31 -140
- package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.js +18 -118
- package/dist/PublishParser/publishTypesAndUtils.js.map +1 -1
- package/dist/SyncReplication.d.ts.map +1 -1
- package/dist/SyncReplication.js +4 -6
- package/dist/SyncReplication.js.map +1 -1
- package/dist/TableConfig/TableConfig.d.ts +12 -5
- package/dist/TableConfig/TableConfig.d.ts.map +1 -1
- package/dist/TableConfig/TableConfig.js +16 -9
- package/dist/TableConfig/TableConfig.js.map +1 -1
- package/dist/TableConfig/getCreateSchemaQueries.d.ts +4 -9
- package/dist/TableConfig/getCreateSchemaQueries.d.ts.map +1 -1
- package/dist/TableConfig/getCreateSchemaQueries.js.map +1 -1
- package/dist/TableConfig/getTableColumnQueries.js +1 -1
- package/dist/TableConfig/getTableColumnQueries.js.map +1 -1
- package/dist/TableConfig/getTableConfigSchemaQueries.d.ts +4 -9
- package/dist/TableConfig/getTableConfigSchemaQueries.d.ts.map +1 -1
- package/dist/WebsocketAPI/getClientSchema.d.ts.map +1 -1
- package/dist/WebsocketAPI/getClientSchema.js +3 -3
- package/dist/WebsocketAPI/getClientSchema.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/initProstgles.d.ts +2 -3
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js.map +1 -1
- package/dist/runClientRequest.d.ts.map +1 -1
- package/dist/runClientRequest.js +4 -8
- package/dist/runClientRequest.js.map +1 -1
- package/lib/DBSchemaBuilder/DBSchemaBuilder.spec.ts +1 -5
- package/lib/DBSchemaBuilder/DBSchemaBuilder.ts +2 -8
- package/lib/DboBuilder/DboBuilder.ts +18 -26
- package/lib/DboBuilder/DboBuilderTypes.ts +70 -59
- package/lib/DboBuilder/TableHandler/DataValidator.ts +1 -1
- package/lib/DboBuilder/TableHandler/TableHandler.ts +10 -14
- package/lib/DboBuilder/TableHandler/insert/insert.ts +1 -7
- package/lib/DboBuilder/TableHandler/insert/insertRowWithNestedRecords.ts +3 -3
- package/lib/DboBuilder/TableHandler/insertTest.ts +5 -5
- package/lib/DboBuilder/TableHandler/updateFile.ts +1 -1
- package/lib/DboBuilder/TableRules/{getValidatedRules.ts → getValidatedTableRules.ts} +3 -10
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +7 -41
- package/lib/DboBuilder/ViewHandler/getInfo.ts +24 -20
- package/lib/DboBuilder/ViewHandler/getValidatedSubscribeOptions.ts +4 -4
- package/lib/DboBuilder/ViewHandler/subscribe.ts +1 -1
- package/lib/DboBuilder/getColumns.ts +4 -14
- package/lib/FileManager/FileManager.ts +5 -6
- package/lib/FileManager/initFileManager.ts +1 -1
- package/lib/Prostgles.ts +10 -1
- package/lib/PubSubManager/PubSubManager.ts +12 -13
- package/lib/PubSubManager/PubSubManagerUtils.ts +1 -0
- package/lib/PubSubManager/addSync.ts +4 -7
- package/lib/PubSubManager/addTrigger.ts +1 -1
- package/lib/PublishParser/PublishParser.ts +30 -17
- package/lib/PublishParser/getDBSchemaTable.ts +73 -0
- package/lib/PublishParser/getSchemaFromPublish.ts +56 -147
- package/lib/PublishParser/getTableRulesWithoutFileTable.ts +74 -162
- package/lib/PublishParser/publishTypesAndUtils.ts +41 -167
- package/lib/SyncReplication.ts +6 -8
- package/lib/TableConfig/TableConfig.ts +25 -11
- package/lib/TableConfig/getCreateSchemaQueries.ts +8 -8
- package/lib/TableConfig/getTableColumnQueries.ts +1 -1
- package/lib/WebsocketAPI/getClientSchema.ts +5 -3
- package/lib/index.ts +1 -1
- package/lib/initProstgles.ts +2 -3
- package/lib/runClientRequest.ts +4 -6
- package/package.json +2 -2
- package/dist/DboBuilder/TableRules/getValidatedRules.d.ts.map +0 -1
- package/dist/DboBuilder/TableRules/getValidatedRules.js.map +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDBSchemaTable = void 0;
|
|
4
|
+
const prostgles_types_1 = require("prostgles-types");
|
|
5
|
+
const dboBuilderUtils_1 = require("../DboBuilder/dboBuilderUtils");
|
|
6
|
+
const Prostgles_1 = require("../Prostgles");
|
|
7
|
+
const prostgles_types_2 = require("prostgles-types");
|
|
8
|
+
const getDBSchemaTable = async (publishParser, tableHandler, parsedTableRule, clientReq, scope) => {
|
|
9
|
+
const tableName = tableHandler.name;
|
|
10
|
+
if ((0, prostgles_types_1.getObjectEntries)(parsedTableRule).every(([_ruleName, ruleOptions]) => !ruleOptions)) {
|
|
11
|
+
throw new Error("At least one of the rules must be defined for " + tableName);
|
|
12
|
+
}
|
|
13
|
+
const info = await tableHandler.getInfo(undefined, undefined, undefined, parsedTableRule, {
|
|
14
|
+
...clientReq,
|
|
15
|
+
isRemoteRequest: {},
|
|
16
|
+
});
|
|
17
|
+
const columns = await tableHandler.getColumns(undefined, undefined, undefined, parsedTableRule, {
|
|
18
|
+
...clientReq,
|
|
19
|
+
isRemoteRequest: {},
|
|
20
|
+
});
|
|
21
|
+
const allowedCommands = (0, prostgles_types_2.getAllowedTableMethods)(info);
|
|
22
|
+
for (const method of allowedCommands) {
|
|
23
|
+
if (method === "getInfo" || method === "getColumns") {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
publishParser.validateRequestRule({
|
|
28
|
+
tableName,
|
|
29
|
+
command: method,
|
|
30
|
+
clientReq,
|
|
31
|
+
}, parsedTableRule, scope);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
console.error(`${tableName}.${method}`, e);
|
|
35
|
+
throw {
|
|
36
|
+
...(0, dboBuilderUtils_1.getErrorAsObject)(e),
|
|
37
|
+
publishPath: `publish.${tableName}.${method}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Crucial in ensuring the published client tableHandler methods work without issues */
|
|
41
|
+
if (publishParser.prostgles.opts.testRulesOnConnect && (0, prostgles_types_1.includes)(Prostgles_1.TABLE_METHODS, method)) {
|
|
42
|
+
await tableHandler.dboBuilder.dboMap.get(tableName)?.[method](
|
|
43
|
+
//@ts-expect-error
|
|
44
|
+
method === "insertMany" ? [] : {}, {}, undefined, parsedTableRule, {
|
|
45
|
+
...clientReq,
|
|
46
|
+
isRemoteRequest: {},
|
|
47
|
+
testRule: true,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
...info,
|
|
53
|
+
name: tableHandler.name,
|
|
54
|
+
columns,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.getDBSchemaTable = getDBSchemaTable;
|
|
58
|
+
//# sourceMappingURL=getDBSchemaTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDBSchemaTable.js","sourceRoot":"","sources":["../../lib/PublishParser/getDBSchemaTable.ts"],"names":[],"mappings":";;;AAAA,qDAAiF;AAEjF,mEAAiE;AAEjE,4CAA6C;AAE7C,qDAAyD;AAElD,MAAM,gBAAgB,GAAG,KAAK,EACnC,aAA4B,EAC5B,YAA0B,EAC1B,eAAgC,EAChC,SAA4B,EAC5B,KAAkC,EACV,EAAE;IAC1B,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC;IAEpC,IAAI,IAAA,kCAAgB,EAAC,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC;QACxF,MAAM,IAAI,KAAK,CAAC,gDAAgD,GAAG,SAAS,CAAC,CAAC;IAChF,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE;QACxF,GAAG,SAAS;QACZ,eAAe,EAAE,EAAE;KACpB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE;QAC9F,GAAG,SAAS;QACZ,eAAe,EAAE,EAAE;KACpB,CAAC,CAAC;IACH,MAAM,eAAe,GAAG,IAAA,wCAAsB,EAAC,IAAI,CAAC,CAAC;IACrD,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,YAAY,EAAE,CAAC;YACpD,SAAS;QACX,CAAC;QACD,IAAI,CAAC;YACH,aAAa,CAAC,mBAAmB,CAC/B;gBACE,SAAS;gBACT,OAAO,EAAE,MAAM;gBACf,SAAS;aACV,EACD,eAAe,EACf,KAAK,CACN,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;YAC3C,MAAM;gBACJ,GAAG,IAAA,kCAAgB,EAAC,CAAC,CAAC;gBACtB,WAAW,EAAE,WAAW,SAAS,IAAI,MAAM,EAAE;aAC9C,CAAC;QACJ,CAAC;QACD,wFAAwF;QACxF,IAAI,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,kBAAkB,IAAI,IAAA,0BAAQ,EAAC,yBAAa,EAAE,MAAM,CAAC,EAAE,CAAC;YACvF,MAAM,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC;YAC3D,kBAAkB;YAClB,MAAM,KAAK,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EACjC,EAAE,EACF,SAAS,EACT,eAAe,EACf;gBACE,GAAG,SAAS;gBACZ,eAAe,EAAE,EAAE;gBACnB,QAAQ,EAAE,IAAI;aACf,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,YAAY,CAAC,IAAI;QACvB,OAAO;KACgB,CAAC;AAC5B,CAAC,CAAC;AAhEW,QAAA,gBAAgB,oBAgE3B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DBSchemaTable, TableSchemaErrors
|
|
1
|
+
import type { DBSchemaTable, TableSchemaErrors } from "prostgles-types";
|
|
2
2
|
import type { AuthClientRequest, AuthResultWithSID } from "../Auth/AuthTypes";
|
|
3
3
|
import type { PublishParser } from "./PublishParser";
|
|
4
4
|
import { type PermissionScope } from "./PublishParser";
|
|
@@ -6,7 +6,6 @@ type Args = AuthClientRequest & {
|
|
|
6
6
|
userData: AuthResultWithSID | undefined;
|
|
7
7
|
};
|
|
8
8
|
export declare function getSchemaFromPublish(this: PublishParser, { userData, ...clientReq }: Args, scope: PermissionScope | undefined): Promise<{
|
|
9
|
-
schema: TableSchemaForClient;
|
|
10
9
|
tables: DBSchemaTable[];
|
|
11
10
|
tableSchemaErrors: TableSchemaErrors;
|
|
12
11
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSchemaFromPublish.d.ts","sourceRoot":"","sources":["../../lib/PublishParser/getSchemaFromPublish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getSchemaFromPublish.d.ts","sourceRoot":"","sources":["../../lib/PublishParser/getSchemaFromPublish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,iBAAiB,CAAC;AAG3E,KAAK,IAAI,GAAG,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,iBAAiB,GAAG,SAAS,CAAC;CACzC,CAAC;AAGF,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,aAAa,EACnB,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,EAAE,IAAI,EAChC,KAAK,EAAE,eAAe,GAAG,SAAS,GACjC,OAAO,CAAC;IACT,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,iBAAiB,EAAE,iBAAiB,CAAC;CACtC,CAAC,CAgFD"}
|
|
@@ -2,131 +2,66 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSchemaFromPublish = getSchemaFromPublish;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
|
-
const
|
|
6
|
-
const Prostgles_1 = require("../Prostgles");
|
|
5
|
+
const getDBSchemaTable_1 = require("./getDBSchemaTable");
|
|
7
6
|
const SUBSCRIBE_METHODS = ["subscribe", "subscribeOne", "sync", "unsubscribe", "unsync"];
|
|
8
7
|
async function getSchemaFromPublish({ userData, ...clientReq }, scope) {
|
|
9
|
-
const schema = {};
|
|
10
8
|
const tableSchemaErrors = {};
|
|
11
|
-
|
|
9
|
+
const tables = [];
|
|
10
|
+
const txKey = !this.prostgles.opts.transactions ? "" : "tx";
|
|
12
11
|
try {
|
|
13
12
|
/* Publish tables and views based on socket */
|
|
14
13
|
const clientInfo = userData ?? (await this.prostgles.authHandler.getSidAndUserFromRequest(clientReq));
|
|
15
14
|
if (clientInfo === "new-session-redirect") {
|
|
16
15
|
throw "new-session-redirect";
|
|
17
16
|
}
|
|
18
|
-
let
|
|
17
|
+
let publish;
|
|
19
18
|
try {
|
|
20
|
-
|
|
19
|
+
publish = await this.getPublishObject(clientReq, clientInfo);
|
|
21
20
|
}
|
|
22
21
|
catch (err) {
|
|
23
22
|
console.error("Error within then Publish function ", err);
|
|
24
23
|
throw err;
|
|
25
24
|
}
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
tableNames.unshift(fileTableName);
|
|
40
|
-
}
|
|
25
|
+
if (!publish || !Object.keys(publish).length) {
|
|
26
|
+
return { tables, tableSchemaErrors };
|
|
27
|
+
}
|
|
28
|
+
const tableNames = Object.keys(publish).filter((k) => !txKey || txKey !== k);
|
|
29
|
+
/**
|
|
30
|
+
* Add file table to the list of published tables if it's referenced by other published tables.
|
|
31
|
+
* Access to the file table is controlled through the publish rules of the tables referencing it.
|
|
32
|
+
*/
|
|
33
|
+
const fileTableName = this.prostgles.fileManager?.tableName;
|
|
34
|
+
if (fileTableName && this.dbo[fileTableName]?.is_media && !tableNames.includes(fileTableName)) {
|
|
35
|
+
const isReferenced = this.prostgles.dboBuilder.tablesOrViews?.some((t) => t.columns.some((c) => c.references?.some((r) => r.ftable === fileTableName)));
|
|
36
|
+
if (isReferenced) {
|
|
37
|
+
tableNames.unshift(fileTableName);
|
|
41
38
|
}
|
|
42
|
-
await Promise.all(tableNames.map(async (tableName) => {
|
|
43
|
-
const { canSubscribe, tablesOrViews } = this.prostgles.dboBuilder;
|
|
44
|
-
if (!this.dbo[tableName]) {
|
|
45
|
-
const errMsg = [
|
|
46
|
-
`Table ${tableName} does not exist`,
|
|
47
|
-
`Expecting one of: ${JSON.stringify(tablesOrViews?.map((tov) => tov.name))}`,
|
|
48
|
-
].join("\n");
|
|
49
|
-
throw errMsg;
|
|
50
|
-
}
|
|
51
|
-
const parsedTableRule = await this.getTableRules({ clientReq, tableName }, clientInfo, scope);
|
|
52
|
-
if (!parsedTableRule || (0, prostgles_types_1.isEmpty)(parsedTableRule))
|
|
53
|
-
return;
|
|
54
|
-
if (!(0, prostgles_types_1.isObject)(parsedTableRule)) {
|
|
55
|
-
throw `Invalid tableRules for table ${tableName}. Expecting an object`;
|
|
56
|
-
}
|
|
57
|
-
schema[tableName] = {};
|
|
58
|
-
const tableSchema = schema[tableName];
|
|
59
|
-
const methods = (0, prostgles_types_1.getKeys)(parsedTableRule).filter((m) => canSubscribe || !(0, prostgles_types_1.includes)(SUBSCRIBE_METHODS, m));
|
|
60
|
-
let tableInfo;
|
|
61
|
-
let tableColumns;
|
|
62
|
-
await Promise.all(methods
|
|
63
|
-
.filter((m) => m !== "select")
|
|
64
|
-
.map(async (method) => {
|
|
65
|
-
if (method === "sync") {
|
|
66
|
-
/* Pass sync info */
|
|
67
|
-
tableSchema[method] = parsedTableRule[method];
|
|
68
|
-
}
|
|
69
|
-
else if ((0, prostgles_types_1.includes)((0, prostgles_types_1.getKeys)(parsedTableRule), method) && parsedTableRule[method]) {
|
|
70
|
-
//@ts-ignore
|
|
71
|
-
tableSchema[method] =
|
|
72
|
-
method === "insert" ?
|
|
73
|
-
(0, prostgles_types_1.pickKeys)(parsedTableRule[method], ["allowedNestedInserts"])
|
|
74
|
-
: {};
|
|
75
|
-
/* Test for issues with the common table CRUD methods () */
|
|
76
|
-
if ((0, prostgles_types_1.includes)(Prostgles_1.TABLE_METHODS, method)) {
|
|
77
|
-
try {
|
|
78
|
-
this.validateRequestRule({
|
|
79
|
-
tableName,
|
|
80
|
-
command: method,
|
|
81
|
-
clientReq,
|
|
82
|
-
}, parsedTableRule, scope);
|
|
83
|
-
if (this.prostgles.opts.testRulesOnConnect) {
|
|
84
|
-
await this.dbo[tableName][method]({}, {}, undefined, parsedTableRule, {
|
|
85
|
-
...clientReq,
|
|
86
|
-
isRemoteRequest: {},
|
|
87
|
-
testRule: true,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
console.error(`${tableName}.${method}`, e);
|
|
93
|
-
tableSchemaErrors[tableName] ??= {};
|
|
94
|
-
tableSchemaErrors[tableName][method] = {
|
|
95
|
-
error: "Internal publish error. Check server logs",
|
|
96
|
-
};
|
|
97
|
-
throw {
|
|
98
|
-
...(0, DboBuilder_1.getErrorAsObject)(e),
|
|
99
|
-
publish_path: `publish.${tableName}.${method}`,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (method === "getInfo" || method === "getColumns") {
|
|
104
|
-
this.validateRequestRule({ tableName, command: method, clientReq }, parsedTableRule, scope);
|
|
105
|
-
const res = await this.dbo[tableName][method](undefined, undefined, undefined, parsedTableRule, { ...clientReq, isRemoteRequest: {} });
|
|
106
|
-
if (method === "getInfo") {
|
|
107
|
-
tableInfo = res;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
tableColumns = res;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}));
|
|
115
|
-
if (tableInfo && tableColumns) {
|
|
116
|
-
tables.push({
|
|
117
|
-
name: tableName,
|
|
118
|
-
info: tableInfo,
|
|
119
|
-
columns: tableColumns,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}));
|
|
123
39
|
}
|
|
40
|
+
await Promise.all(tableNames.map(async (tableName) => {
|
|
41
|
+
const { tablesOrViews } = this.prostgles.dboBuilder;
|
|
42
|
+
const tableHandler = this.dbo[tableName];
|
|
43
|
+
if (!tableHandler) {
|
|
44
|
+
const errMsg = [
|
|
45
|
+
`Table ${tableName} does not exist`,
|
|
46
|
+
`Expecting one of: ${JSON.stringify(tablesOrViews?.map((tov) => tov.name))}`,
|
|
47
|
+
].join("\n");
|
|
48
|
+
throw errMsg;
|
|
49
|
+
}
|
|
50
|
+
const parsedTableRule = await this.getTableRules({ clientReq, tableName }, clientInfo, scope);
|
|
51
|
+
if (!parsedTableRule || (0, prostgles_types_1.isEmpty)(parsedTableRule))
|
|
52
|
+
return;
|
|
53
|
+
if (!(0, prostgles_types_1.isObject)(parsedTableRule)) {
|
|
54
|
+
throw `Invalid tableRules for table ${tableName}. Expecting an object`;
|
|
55
|
+
}
|
|
56
|
+
const tableSchema = await (0, getDBSchemaTable_1.getDBSchemaTable)(this, tableHandler, parsedTableRule, clientReq, scope);
|
|
57
|
+
tables.push(tableSchema);
|
|
58
|
+
}));
|
|
124
59
|
}
|
|
125
60
|
catch (error) {
|
|
126
61
|
console.error("Publish error", error);
|
|
127
62
|
throw error;
|
|
128
63
|
}
|
|
129
|
-
tables = tables.sort((a, b) => a.name.localeCompare(b.name));
|
|
130
|
-
return {
|
|
64
|
+
// tables = tables.sort((a, b) => a.name.localeCompare(b.name));
|
|
65
|
+
return { tables, tableSchemaErrors };
|
|
131
66
|
}
|
|
132
67
|
//# sourceMappingURL=getSchemaFromPublish.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSchemaFromPublish.js","sourceRoot":"","sources":["../../lib/PublishParser/getSchemaFromPublish.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"getSchemaFromPublish.js","sourceRoot":"","sources":["../../lib/PublishParser/getSchemaFromPublish.ts"],"names":[],"mappings":";;AAaA,oDAuFC;AAnGD,qDAAoD;AAKpD,yDAAsD;AAKtD,MAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,CAAU,CAAC;AAE3F,KAAK,UAAU,oBAAoB,CAExC,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAQ,EAChC,KAAkC;IAKlC,MAAM,iBAAiB,GAAsB,EAAE,CAAC;IAChD,MAAM,MAAM,GAAoB,EAAE,CAAC;IAEnC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAE5D,IAAI,CAAC;QACH,8CAA8C;QAC9C,MAAM,UAAU,GACd,QAAQ,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC,CAAC;QACrF,IAAI,UAAU,KAAK,sBAAsB,EAAE,CAAC;YAC1C,MAAM,sBAAsB,CAAC;QAC/B,CAAC;QACD,IAAI,OAAkC,CAAC;QACvC,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC/D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;YAC1D,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;YAC7C,OAAO,EAAE,MA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GAAG,CAAC,IAAI,CAAC,CAAC,EAAE;iBAC7E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACb,MAAM,MAAM,CAAC;YACf,CAAC;YAED,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,aAAa,CAC9C,EAAE,SAAS,EAAE,SAAS,EAAE,EACxB,UAAU,EACV,KAAK,CACN,CAAC;YAEF,IAAI,CAAC,eAAe,IAAI,IAAA,yBAAO,EAAC,eAAe,CAAC;gBAAE,OAAO;YACzD,IAAI,CAAC,IAAA,0BAAQ,EAAC,eAAe,CAAC,EAAE,CAAC;gBAC/B,MAAM,gCAAgC,SAAS,uBAAuB,CAAC;YACzE,CAAC;YAED,MAAM,WAAW,GAAG,MAAM,IAAA,mCAAgB,EACxC,IAAI,EACJ,YAAY,EACZ,eAAe,EACf,SAAS,EACT,KAAK,CACN,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3B,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QACtC,MAAM,KAAK,CAAC;IACd,CAAC;IAED,gEAAgE;IAChE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTableRulesWithoutFileTable.d.ts","sourceRoot":"","sources":["../../lib/PublishParser/getTableRulesWithoutFileTable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"getTableRulesWithoutFileTable.d.ts","sourceRoot":"","sources":["../../lib/PublishParser/getTableRulesWithoutFileTable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAElF,wBAAsB,6BAA6B,CACjD,IAAI,EAAE,aAAa,EACnB,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,QAAQ,EAClC,UAAU,EAAE,iBAAiB,GAAG,SAAS,EACzC,gBAAgB,CAAC,EAAE,aAAa,GAC/B,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAiGzC"}
|
|
@@ -2,152 +2,83 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTableRulesWithoutFileTable = getTableRulesWithoutFileTable;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
|
-
const PubSubManagerUtils_1 = require("../PubSubManager/PubSubManagerUtils");
|
|
6
5
|
const publishTypesAndUtils_1 = require("./publishTypesAndUtils");
|
|
7
6
|
async function getTableRulesWithoutFileTable({ tableName, clientReq }, clientInfo, overridenPublish) {
|
|
8
|
-
if (!tableName)
|
|
7
|
+
if (!tableName) {
|
|
9
8
|
throw new Error("tableName is missing in getTableRules");
|
|
10
|
-
|
|
9
|
+
}
|
|
10
|
+
const publish = overridenPublish ?? (clientReq && (await this.getPublishObject(clientReq, clientInfo)));
|
|
11
11
|
const rawTableRule = publish?.[tableName];
|
|
12
12
|
if (!rawTableRule || ((0, prostgles_types_1.isObject)(rawTableRule) && Object.values(rawTableRule).every((v) => !v))) {
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
|
-
let parsedTableRule = {};
|
|
16
15
|
/* Get view or table specific rules */
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
16
|
+
const tableHandler = this.dbo[tableName];
|
|
17
|
+
if (!tableHandler) {
|
|
19
18
|
throw {
|
|
20
19
|
stack: ["getTableRules()"],
|
|
21
20
|
message: `${tableName} could not be found in dbo`,
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
|
-
const is_view =
|
|
23
|
+
const is_view = tableHandler.is_view;
|
|
25
24
|
/**
|
|
26
25
|
* Allow subscribing to a view if it has primary key columns from other tables
|
|
27
26
|
*/
|
|
28
|
-
const canSubscribe = !is_view ||
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
const canSubscribe = !is_view || tableHandler.columns.some((c) => c.references);
|
|
28
|
+
const isStarOrTrue = (value) => value === "*" || value === true;
|
|
29
|
+
const { privileges } = tableHandler.tableOrViewInfo;
|
|
30
|
+
const tableRulesObject = isStarOrTrue(rawTableRule) ?
|
|
31
|
+
{
|
|
32
|
+
select: privileges.select ? publishTypesAndUtils_1.TABLE_RULE_NO_LIMITS.select : undefined,
|
|
33
|
+
insert: privileges.insert ? publishTypesAndUtils_1.TABLE_RULE_NO_LIMITS.insert : undefined,
|
|
34
|
+
update: privileges.update ? publishTypesAndUtils_1.TABLE_RULE_NO_LIMITS.update : undefined,
|
|
35
|
+
delete: privileges.delete ? publishTypesAndUtils_1.TABLE_RULE_NO_LIMITS.delete : undefined,
|
|
36
|
+
}
|
|
37
|
+
: rawTableRule;
|
|
38
|
+
const selectRule = !tableRulesObject.select ? undefined
|
|
39
|
+
: isStarOrTrue(tableRulesObject.select) ? publishTypesAndUtils_1.TABLE_RULE_NO_LIMITS.select
|
|
40
|
+
: tableRulesObject.select;
|
|
41
|
+
const insertRule = !tableRulesObject.insert ? undefined
|
|
42
|
+
: isStarOrTrue(tableRulesObject.insert) ? publishTypesAndUtils_1.TABLE_RULE_NO_LIMITS.insert
|
|
43
|
+
: tableRulesObject.insert;
|
|
44
|
+
const updateRule = !tableRulesObject.update ? undefined
|
|
45
|
+
: isStarOrTrue(tableRulesObject.update) ? publishTypesAndUtils_1.TABLE_RULE_NO_LIMITS.update
|
|
46
|
+
: tableRulesObject.update;
|
|
47
|
+
const deleteRule = !tableRulesObject.delete ? undefined
|
|
48
|
+
: isStarOrTrue(tableRulesObject.delete) ? publishTypesAndUtils_1.TABLE_RULE_NO_LIMITS.delete
|
|
49
|
+
: tableRulesObject.delete;
|
|
50
|
+
const parsedTableRule = {
|
|
51
|
+
select: selectRule && {
|
|
52
|
+
...selectRule,
|
|
53
|
+
disableMethods: canSubscribe ?
|
|
54
|
+
selectRule.disableMethods
|
|
55
|
+
: {
|
|
56
|
+
...selectRule.disableMethods,
|
|
57
|
+
subscribe: 1,
|
|
58
|
+
},
|
|
59
|
+
subscribeThrottle: selectRule.subscribeThrottle ?? 0,
|
|
60
|
+
},
|
|
61
|
+
insert: insertRule,
|
|
62
|
+
update: updateRule,
|
|
63
|
+
delete: deleteRule,
|
|
64
|
+
};
|
|
65
|
+
const cannotBatchUpdate = !parsedTableRule.update ||
|
|
66
|
+
parsedTableRule.update.checkFilter ||
|
|
67
|
+
parsedTableRule.update.postValidate;
|
|
68
|
+
if (cannotBatchUpdate && parsedTableRule.update) {
|
|
69
|
+
parsedTableRule.update.disableMethods = {
|
|
70
|
+
updateBatch: 1,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
(0, prostgles_types_1.getObjectEntries)(parsedTableRule).forEach(([publishCommand, publishValue]) => {
|
|
74
|
+
if (!publishValue) {
|
|
75
|
+
return;
|
|
37
76
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// if (isObject(raw_table_rules) && (raw_table_rules as PublishTableRule)[r.rule]) {
|
|
42
|
-
// throw `Cannot publish realtime rule ${tableName}.${r.rule}. Superuser is required for this`
|
|
43
|
-
// }
|
|
44
|
-
// }
|
|
45
|
-
if (r.rule === "subscribe" && !canSubscribe) {
|
|
46
|
-
result = false;
|
|
77
|
+
const pgUserIsAllowedThisCommand = tableHandler.tableOrViewInfo.privileges[publishCommand];
|
|
78
|
+
if (!pgUserIsAllowedThisCommand) {
|
|
79
|
+
throw `Current postgres user is not allowed ${publishCommand} on table ${tableName}`;
|
|
47
80
|
}
|
|
48
|
-
return result;
|
|
49
81
|
});
|
|
50
|
-
/* All methods allowed. Add no limits for table rules */
|
|
51
|
-
if ((0, prostgles_types_1.includes)([true, "*"], rawTableRule)) {
|
|
52
|
-
parsedTableRule = {};
|
|
53
|
-
MY_RULES.filter((r) => r.no_limits).forEach((r) => {
|
|
54
|
-
parsedTableRule[r.rule] = { ...r.no_limits };
|
|
55
|
-
});
|
|
56
|
-
/** Specific rules allowed */
|
|
57
|
-
}
|
|
58
|
-
else if ((0, prostgles_types_1.isObject)(rawTableRule) && (0, prostgles_types_1.getKeys)(rawTableRule).length) {
|
|
59
|
-
const allRuleKeys = (0, prostgles_types_1.getKeys)(rawTableRule);
|
|
60
|
-
const dissallowedRuleKeys = allRuleKeys.filter((m) => !rawTableRule[m]);
|
|
61
|
-
MY_RULES.map((r) => {
|
|
62
|
-
/** Unless specifically disabled these are allowed */
|
|
63
|
-
if (["getInfo", "getColumns"].includes(r.rule) &&
|
|
64
|
-
!dissallowedRuleKeys.includes(r.rule)) {
|
|
65
|
-
parsedTableRule[r.rule] = r.no_limits;
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
/** Add no_limit values for implied/ fully allowed methods */
|
|
69
|
-
if ([true, "*"].includes(rawTableRule[r.rule]) && r.no_limits) {
|
|
70
|
-
parsedTableRule[r.rule] = Object.assign({}, r.no_limits);
|
|
71
|
-
/** Carry over detailed config */
|
|
72
|
-
}
|
|
73
|
-
else if ((0, prostgles_types_1.isObject)(rawTableRule[r.rule])) {
|
|
74
|
-
parsedTableRule[r.rule] = rawTableRule[r.rule];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
allRuleKeys
|
|
78
|
-
.filter((m) => parsedTableRule[m])
|
|
79
|
-
.forEach((method) => {
|
|
80
|
-
const rule = parsedTableRule[method];
|
|
81
|
-
const ruleInfo = MY_RULES.find((r) => r.rule === method || r.methods.includes(method));
|
|
82
|
-
if (!ruleInfo) {
|
|
83
|
-
let extraInfo = "";
|
|
84
|
-
if (is_view &&
|
|
85
|
-
publishTypesAndUtils_1.RULE_TO_METHODS.find((r) => r.table_only &&
|
|
86
|
-
(r.rule === method || r.methods.includes(method)))) {
|
|
87
|
-
extraInfo = "You've specified table rules to a view\n";
|
|
88
|
-
}
|
|
89
|
-
throw `Invalid rule in publish.${tableName} -> ${method} \n${extraInfo}Expecting any of: ${MY_RULES.flatMap((r) => [r.rule, ...r.methods]).join(", ")}`;
|
|
90
|
-
}
|
|
91
|
-
/* Check RULES for invalid params */
|
|
92
|
-
/* Methods do not have params -> They use them from rules */
|
|
93
|
-
if (method === ruleInfo.rule && (0, prostgles_types_1.isObject)(rule)) {
|
|
94
|
-
const method_params = Object.keys(rule);
|
|
95
|
-
const allowed_params = Object.keys(ruleInfo.allowed_params);
|
|
96
|
-
const iparam = method_params.find((p) => !allowed_params.includes(p));
|
|
97
|
-
if (iparam) {
|
|
98
|
-
throw `Invalid setting in publish.${tableName}.${method} -> ${iparam}. \n Expecting any of: ${allowed_params.join(", ")}`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/* Add default params (if missing) */
|
|
102
|
-
if (method === "sync") {
|
|
103
|
-
if ([true, "*"].includes(parsedTableRule[method])) {
|
|
104
|
-
throw "Invalid sync rule. Expecting { id_fields: string[], synced_field: string } ";
|
|
105
|
-
}
|
|
106
|
-
if (typeof parsedTableRule[method]?.throttle !== "number") {
|
|
107
|
-
parsedTableRule[method].throttle = 100;
|
|
108
|
-
}
|
|
109
|
-
if (typeof parsedTableRule[method]?.batch_size !== "number") {
|
|
110
|
-
parsedTableRule[method].batch_size = PubSubManagerUtils_1.DEFAULT_SYNC_BATCH_SIZE;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/* Enable subscribe if not explicitly disabled OR if VIEW with referenced tables */
|
|
114
|
-
const subKey = "subscribe";
|
|
115
|
-
if (method === "select" && !dissallowedRuleKeys.includes(subKey)) {
|
|
116
|
-
const sr = MY_RULES.find((r) => r.rule === subKey);
|
|
117
|
-
if (sr && canSubscribe) {
|
|
118
|
-
parsedTableRule[subKey] = { ...sr.no_limits };
|
|
119
|
-
parsedTableRule.subscribeOne = { ...sr.no_limits };
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
throw "Unexpected publish";
|
|
126
|
-
}
|
|
127
|
-
const getImpliedMethods = (tableRules) => {
|
|
128
|
-
const res = { ...tableRules };
|
|
129
|
-
/* Add implied methods if not specifically dissallowed */
|
|
130
|
-
MY_RULES.map((r) => {
|
|
131
|
-
/** THIS IS A MESS -> some methods cannot be dissallowed (unsync, unsubscribe...) */
|
|
132
|
-
r.methods.forEach((method) => {
|
|
133
|
-
const isAllowed = tableRules[r.rule] && tableRules[method] === undefined;
|
|
134
|
-
if (isAllowed) {
|
|
135
|
-
if (method === "updateBatch" &&
|
|
136
|
-
(!tableRules.update || tableRules.update.checkFilter || tableRules.update.postValidate)) {
|
|
137
|
-
// not allowed
|
|
138
|
-
}
|
|
139
|
-
else if (method === "upsert" && (!tableRules.update || !tableRules.insert)) {
|
|
140
|
-
// not allowed
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
res[method] ??= true;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
return res;
|
|
149
|
-
};
|
|
150
|
-
parsedTableRule = getImpliedMethods(parsedTableRule);
|
|
151
82
|
return parsedTableRule;
|
|
152
83
|
}
|
|
153
84
|
//# sourceMappingURL=getTableRulesWithoutFileTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTableRulesWithoutFileTable.js","sourceRoot":"","sources":["../../lib/PublishParser/getTableRulesWithoutFileTable.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"getTableRulesWithoutFileTable.js","sourceRoot":"","sources":["../../lib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