prostgles-server 4.2.159 → 4.2.161
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/Auth/setEmailProvider.js +2 -2
- package/dist/Auth/setEmailProvider.js.map +1 -1
- package/lib/Auth/AuthHandler.ts +436 -0
- package/lib/Auth/AuthTypes.ts +280 -0
- package/lib/Auth/getSafeReturnURL.ts +35 -0
- package/lib/Auth/sendEmail.ts +83 -0
- package/lib/Auth/setAuthProviders.ts +128 -0
- package/lib/Auth/setEmailProvider.ts +85 -0
- package/lib/Auth/setupAuthRoutes.ts +161 -0
- package/lib/DBEventsManager.ts +178 -0
- package/lib/DBSchemaBuilder.ts +225 -0
- package/lib/DboBuilder/DboBuilder.ts +319 -0
- package/lib/DboBuilder/DboBuilderTypes.ts +361 -0
- package/lib/DboBuilder/QueryBuilder/Functions.ts +1153 -0
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +288 -0
- package/lib/DboBuilder/QueryBuilder/getJoinQuery.ts +263 -0
- package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +271 -0
- package/lib/DboBuilder/QueryBuilder/getSelectQuery.ts +136 -0
- package/lib/DboBuilder/QueryBuilder/prepareHaving.ts +22 -0
- package/lib/DboBuilder/QueryStreamer.ts +250 -0
- package/lib/DboBuilder/TableHandler/DataValidator.ts +428 -0
- package/lib/DboBuilder/TableHandler/TableHandler.ts +205 -0
- package/lib/DboBuilder/TableHandler/delete.ts +115 -0
- package/lib/DboBuilder/TableHandler/insert.ts +183 -0
- package/lib/DboBuilder/TableHandler/insertTest.ts +78 -0
- package/lib/DboBuilder/TableHandler/onDeleteFromFileTable.ts +62 -0
- package/lib/DboBuilder/TableHandler/runInsertUpdateQuery.ts +134 -0
- package/lib/DboBuilder/TableHandler/update.ts +126 -0
- package/lib/DboBuilder/TableHandler/updateBatch.ts +49 -0
- package/lib/DboBuilder/TableHandler/updateFile.ts +48 -0
- package/lib/DboBuilder/TableHandler/upsert.ts +34 -0
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +393 -0
- package/lib/DboBuilder/ViewHandler/count.ts +38 -0
- package/lib/DboBuilder/ViewHandler/find.ts +153 -0
- package/lib/DboBuilder/ViewHandler/getExistsCondition.ts +73 -0
- package/lib/DboBuilder/ViewHandler/getExistsFilters.ts +74 -0
- package/lib/DboBuilder/ViewHandler/getInfo.ts +32 -0
- package/lib/DboBuilder/ViewHandler/getTableJoinQuery.ts +84 -0
- package/lib/DboBuilder/ViewHandler/parseComplexFilter.ts +96 -0
- package/lib/DboBuilder/ViewHandler/parseFieldFilter.ts +105 -0
- package/lib/DboBuilder/ViewHandler/parseJoinPath.ts +208 -0
- package/lib/DboBuilder/ViewHandler/prepareSortItems.ts +163 -0
- package/lib/DboBuilder/ViewHandler/prepareWhere.ts +90 -0
- package/lib/DboBuilder/ViewHandler/size.ts +37 -0
- package/lib/DboBuilder/ViewHandler/subscribe.ts +118 -0
- package/lib/DboBuilder/ViewHandler/validateViewRules.ts +70 -0
- package/lib/DboBuilder/dboBuilderUtils.ts +222 -0
- package/lib/DboBuilder/getColumns.ts +114 -0
- package/lib/DboBuilder/getCondition.ts +201 -0
- package/lib/DboBuilder/getSubscribeRelatedTables.ts +190 -0
- package/lib/DboBuilder/getTablesForSchemaPostgresSQL.ts +426 -0
- package/lib/DboBuilder/insertNestedRecords.ts +355 -0
- package/lib/DboBuilder/parseUpdateRules.ts +187 -0
- package/lib/DboBuilder/prepareShortestJoinPaths.ts +186 -0
- package/lib/DboBuilder/runSQL.ts +182 -0
- package/lib/DboBuilder/runTransaction.ts +50 -0
- package/lib/DboBuilder/sqlErrCodeToMsg.ts +254 -0
- package/lib/DboBuilder/uploadFile.ts +69 -0
- package/lib/Event_Trigger_Tags.ts +118 -0
- package/lib/FileManager/FileManager.ts +358 -0
- package/lib/FileManager/getValidatedFileType.ts +69 -0
- package/lib/FileManager/initFileManager.ts +187 -0
- package/lib/FileManager/upload.ts +62 -0
- package/lib/FileManager/uploadStream.ts +79 -0
- package/lib/Filtering.ts +463 -0
- package/lib/JSONBValidation/validate_jsonb_schema_sql.ts +502 -0
- package/lib/JSONBValidation/validation.ts +143 -0
- package/lib/Logging.ts +127 -0
- package/lib/PostgresNotifListenManager.ts +143 -0
- package/lib/Prostgles.ts +485 -0
- package/lib/ProstglesTypes.ts +196 -0
- package/lib/PubSubManager/PubSubManager.ts +609 -0
- package/lib/PubSubManager/addSub.ts +138 -0
- package/lib/PubSubManager/addSync.ts +141 -0
- package/lib/PubSubManager/getCreatePubSubManagerError.ts +72 -0
- package/lib/PubSubManager/getPubSubManagerInitQuery.ts +662 -0
- package/lib/PubSubManager/initPubSubManager.ts +79 -0
- package/lib/PubSubManager/notifListener.ts +173 -0
- package/lib/PubSubManager/orphanTriggerCheck.ts +70 -0
- package/lib/PubSubManager/pushSubData.ts +55 -0
- package/lib/PublishParser/PublishParser.ts +162 -0
- package/lib/PublishParser/getFileTableRules.ts +124 -0
- package/lib/PublishParser/getSchemaFromPublish.ts +141 -0
- package/lib/PublishParser/getTableRulesWithoutFileTable.ts +177 -0
- package/lib/PublishParser/publishTypesAndUtils.ts +399 -0
- package/lib/RestApi.ts +127 -0
- package/lib/SchemaWatch/SchemaWatch.ts +90 -0
- package/lib/SchemaWatch/createSchemaWatchEventTrigger.ts +3 -0
- package/lib/SchemaWatch/getValidatedWatchSchemaType.ts +45 -0
- package/lib/SchemaWatch/getWatchSchemaTagList.ts +27 -0
- package/lib/SyncReplication.ts +557 -0
- package/lib/TableConfig/TableConfig.ts +468 -0
- package/lib/TableConfig/getColumnDefinitionQuery.ts +111 -0
- package/lib/TableConfig/getConstraintDefinitionQueries.ts +95 -0
- package/lib/TableConfig/getFutureTableSchema.ts +64 -0
- package/lib/TableConfig/getPGIndexes.ts +53 -0
- package/lib/TableConfig/getTableColumnQueries.ts +129 -0
- package/lib/TableConfig/initTableConfig.ts +326 -0
- package/lib/index.ts +13 -0
- package/lib/initProstgles.ts +319 -0
- package/lib/onSocketConnected.ts +102 -0
- package/lib/runClientRequest.ts +129 -0
- package/lib/shortestPath.ts +122 -0
- package/lib/typeTests/DBoGenerated.d.ts +320 -0
- package/lib/typeTests/dboTypeCheck.ts +81 -0
- package/lib/utils.ts +15 -0
- package/package.json +1 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { DBSchemaTable, MethodKey, TableInfo, TableSchemaForClient, getKeys, pickKeys } from "prostgles-types";
|
|
2
|
+
import { AuthResult, ExpressReq } from "../Auth/AuthTypes";
|
|
3
|
+
import { getErrorAsObject, PRGLIOSocket } from "../DboBuilder/DboBuilder";
|
|
4
|
+
import { PublishObject, PublishParser } from "./PublishParser"
|
|
5
|
+
import { TABLE_METHODS } from "../Prostgles";
|
|
6
|
+
|
|
7
|
+
type Args = ({
|
|
8
|
+
socket: PRGLIOSocket;
|
|
9
|
+
httpReq?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
httpReq: ExpressReq;
|
|
12
|
+
socket?: undefined;
|
|
13
|
+
}) & {
|
|
14
|
+
userData: AuthResult | undefined;
|
|
15
|
+
}
|
|
16
|
+
export async function getSchemaFromPublish(this: PublishParser, { userData, ...clientReq }: Args): Promise<{ schema: TableSchemaForClient; tables: DBSchemaTable[] }> {
|
|
17
|
+
const schema: TableSchemaForClient = {};
|
|
18
|
+
let tables: DBSchemaTable[] = []
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
/* Publish tables and views based on socket */
|
|
22
|
+
const clientInfo = userData ?? await this.prostgles.authHandler?.getClientInfo(clientReq);
|
|
23
|
+
|
|
24
|
+
let _publish: PublishObject | undefined;
|
|
25
|
+
try {
|
|
26
|
+
_publish = await this.getPublish(clientReq, clientInfo);
|
|
27
|
+
} catch(err){
|
|
28
|
+
console.error("Error within then Publish function ", err)
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if (_publish && Object.keys(_publish).length) {
|
|
34
|
+
let txKey = "tx";
|
|
35
|
+
if (!this.prostgles.opts.transactions) txKey = "";
|
|
36
|
+
if (typeof this.prostgles.opts.transactions === "string") txKey = this.prostgles.opts.transactions;
|
|
37
|
+
|
|
38
|
+
const tableNames = Object.keys(_publish).filter(k => !txKey || txKey !== k);
|
|
39
|
+
|
|
40
|
+
const fileTableName = this.prostgles.fileManager?.tableName;
|
|
41
|
+
if(fileTableName && this.dbo[fileTableName]?.is_media && !tableNames.includes(fileTableName)){
|
|
42
|
+
const isReferenced = this.prostgles.dboBuilder.tablesOrViews?.some(t => t.columns.some(c => c.references?.some(r => r.ftable === fileTableName)))
|
|
43
|
+
if(isReferenced){
|
|
44
|
+
tableNames.unshift(fileTableName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await Promise.all(tableNames
|
|
48
|
+
.map(async tableName => {
|
|
49
|
+
if (!this.dbo[tableName]) {
|
|
50
|
+
const errMsg = [
|
|
51
|
+
`Table ${tableName} does not exist`,
|
|
52
|
+
`Expecting one of: ${JSON.stringify(this.prostgles.dboBuilder.tablesOrViews?.map(tov => tov.name))}`,
|
|
53
|
+
`DBO tables: ${JSON.stringify(Object.keys(this.dbo).filter(k => (this.dbo[k] as any).find))}`,
|
|
54
|
+
].join("\n");
|
|
55
|
+
throw errMsg;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const table_rules = await this.getTableRules({ localParams: clientReq, tableName }, clientInfo);
|
|
59
|
+
|
|
60
|
+
if (table_rules && Object.keys(table_rules).length) {
|
|
61
|
+
schema[tableName] = {};
|
|
62
|
+
const tableSchema = schema[tableName]!;
|
|
63
|
+
let methods: MethodKey[] = [];
|
|
64
|
+
let tableInfo: TableInfo | undefined;
|
|
65
|
+
let tableColumns: DBSchemaTable["columns"] | undefined;
|
|
66
|
+
|
|
67
|
+
if (typeof table_rules === "object") {
|
|
68
|
+
methods = getKeys(table_rules) as any;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if(!this.prostgles.dboBuilder.canSubscribe){
|
|
72
|
+
methods = methods.filter(m => !["subscribe", "subscribeOne", "sync", "unsubscribe", "unsync"].includes(m));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await Promise.all(methods.filter(m => m !== "select" as any)
|
|
76
|
+
.map(async method => {
|
|
77
|
+
if (method === "sync" && table_rules[method]) {
|
|
78
|
+
|
|
79
|
+
/* Pass sync info */
|
|
80
|
+
tableSchema[method] = table_rules[method];
|
|
81
|
+
} else if ((table_rules as any)[method]) {
|
|
82
|
+
|
|
83
|
+
tableSchema[method] = method === "insert"? pickKeys(table_rules.insert!, ["allowedNestedInserts"]) : {};
|
|
84
|
+
|
|
85
|
+
/* Test for issues with the common table CRUD methods () */
|
|
86
|
+
if (TABLE_METHODS.includes(method as any)) {
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const valid_table_command_rules = await this.getValidatedRequestRule({ tableName, command: method, localParams: clientReq }, clientInfo);
|
|
90
|
+
if(this.prostgles.opts.testRulesOnConnect){
|
|
91
|
+
await (this.dbo[tableName] as any)[method]({}, {}, {}, valid_table_command_rules, { ...clientReq, isRemoteRequest: true, testRule: true });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
} catch (e) {
|
|
95
|
+
tableSchema[method] = {
|
|
96
|
+
err: "Internal publish error. Check server logs"
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
throw {
|
|
100
|
+
...getErrorAsObject(e),
|
|
101
|
+
publish_path: `publish.${tableName}.${method}: \n -> ${e}`
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (method === "getInfo" || method === "getColumns") {
|
|
107
|
+
const tableRules = await this.getValidatedRequestRule({ tableName, command: method, localParams: clientReq }, clientInfo);
|
|
108
|
+
const res = await (this.dbo[tableName] as any)[method](undefined, undefined, undefined, tableRules, { ...clientReq, isRemoteRequest: true });
|
|
109
|
+
if (method === "getInfo") {
|
|
110
|
+
tableInfo = res;
|
|
111
|
+
} else if (method === "getColumns") {
|
|
112
|
+
tableColumns = res;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
if (tableInfo && tableColumns) {
|
|
119
|
+
|
|
120
|
+
tables.push({
|
|
121
|
+
name: tableName,
|
|
122
|
+
info: tableInfo,
|
|
123
|
+
columns: tableColumns
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return true;
|
|
129
|
+
})
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.error("Prostgles \nERRORS IN PUBLISH: ", JSON.stringify(e));
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
tables = tables.sort((a, b) => a.name.localeCompare(b.name));
|
|
140
|
+
return { schema, tables };
|
|
141
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { getKeys, isObject } from "prostgles-types";
|
|
2
|
+
import { AuthResult } from "../Auth/AuthTypes";
|
|
3
|
+
import { TableHandler } from "../DboBuilder/TableHandler/TableHandler";
|
|
4
|
+
import { ViewHandler } from "../DboBuilder/ViewHandler/ViewHandler";
|
|
5
|
+
import { DEFAULT_SYNC_BATCH_SIZE } from "../PubSubManager/PubSubManager";
|
|
6
|
+
import { PublishParser } from "./PublishParser";
|
|
7
|
+
import {
|
|
8
|
+
DboTable, ParsedPublishTable, PublishObject, PublishTableRule,
|
|
9
|
+
PublishViewRule, RULE_TO_METHODS, SubscribeRule
|
|
10
|
+
} from "./publishTypesAndUtils";
|
|
11
|
+
|
|
12
|
+
export async function getTableRulesWithoutFileTable(this: PublishParser, { tableName, localParams }: DboTable, clientInfo?: AuthResult, overridenPublish?: PublishObject): Promise<ParsedPublishTable | undefined> {
|
|
13
|
+
|
|
14
|
+
if (!localParams || !tableName) throw { stack: ["getTableRules()"], message: "publish OR socket OR dbo OR tableName are missing" };
|
|
15
|
+
|
|
16
|
+
const _publish = overridenPublish ?? await this.getPublish(localParams, clientInfo);
|
|
17
|
+
|
|
18
|
+
const raw_table_rules = _publish[tableName];
|
|
19
|
+
if (!raw_table_rules || isObject(raw_table_rules) && Object.values(raw_table_rules).every(v => !v)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let parsed_table: ParsedPublishTable = {};
|
|
24
|
+
|
|
25
|
+
/* Get view or table specific rules */
|
|
26
|
+
const tHandler = (this.dbo[tableName] as TableHandler | ViewHandler);
|
|
27
|
+
const is_view = tHandler.is_view;
|
|
28
|
+
/**
|
|
29
|
+
* Allow subscribing to a view if it has primary key columns from other tables
|
|
30
|
+
*/
|
|
31
|
+
const canSubscribe = (!is_view || tHandler.columns.some(c => c.references));
|
|
32
|
+
if (!tHandler) {
|
|
33
|
+
throw { stack: ["getTableRules()"], message: `${tableName} could not be found in dbo` };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const MY_RULES = RULE_TO_METHODS.filter(r => {
|
|
37
|
+
|
|
38
|
+
/** Check PG User privileges */
|
|
39
|
+
const pgUserIsAllowedThis = tHandler.tableOrViewInfo.privileges[r.sqlRule];
|
|
40
|
+
let result = (!is_view || !r.table_only) && pgUserIsAllowedThis;
|
|
41
|
+
|
|
42
|
+
if (!pgUserIsAllowedThis && isObject(raw_table_rules) && (raw_table_rules as PublishTableRule)[r.sqlRule]) {
|
|
43
|
+
throw `Your postgres user is not allowed ${r.sqlRule} on table ${tableName}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// TODO: Implement comprehensive canSubscribe check
|
|
47
|
+
// if ((r.rule === "subscribe" || r.rule === "sync") && !this.prostgles.isSuperUser) {
|
|
48
|
+
// result = false;
|
|
49
|
+
// if (isObject(raw_table_rules) && (raw_table_rules as PublishTableRule)[r.rule]) {
|
|
50
|
+
// throw `Cannot publish realtime rule ${tableName}.${r.rule}. Superuser is required for this`
|
|
51
|
+
// }
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
if(r.rule === "subscribe" && !canSubscribe){
|
|
55
|
+
result = false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return result;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/* All methods allowed. Add no limits for table rules */
|
|
64
|
+
if ([true, "*"].includes(raw_table_rules as any)) {
|
|
65
|
+
parsed_table = {};
|
|
66
|
+
MY_RULES.filter(r => r.no_limits).forEach(r => {
|
|
67
|
+
parsed_table[r.rule] = { ...r.no_limits as object } as any;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/** Specific rules allowed */
|
|
71
|
+
} else if (isObject(raw_table_rules) && getKeys(raw_table_rules).length) {
|
|
72
|
+
const allRuleKeys: (keyof PublishViewRule | keyof PublishTableRule)[] = getKeys(raw_table_rules);
|
|
73
|
+
const dissallowedRuleKeys = allRuleKeys.filter(m => !(raw_table_rules as PublishTableRule)[m])
|
|
74
|
+
|
|
75
|
+
MY_RULES.map(r => {
|
|
76
|
+
/** Unless specifically disabled these are allowed */
|
|
77
|
+
if (["getInfo", "getColumns"].includes(r.rule) && !dissallowedRuleKeys.includes(r.rule as any)) {
|
|
78
|
+
parsed_table[r.rule] = r.no_limits as any;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Add no_limit values for implied/ fully allowed methods */
|
|
83
|
+
if ([true, "*"].includes((raw_table_rules as PublishTableRule)[r.rule] as any) && r.no_limits) {
|
|
84
|
+
parsed_table[r.rule] = Object.assign({}, r.no_limits) as any;
|
|
85
|
+
|
|
86
|
+
/** Carry over detailed config */
|
|
87
|
+
} else if (isObject((raw_table_rules as any)[r.rule])) {
|
|
88
|
+
parsed_table[r.rule] = (raw_table_rules as any)[r.rule]
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
allRuleKeys.filter(m => parsed_table[m])
|
|
93
|
+
.forEach((method) => {
|
|
94
|
+
const rule = parsed_table[method];
|
|
95
|
+
|
|
96
|
+
const rm = MY_RULES.find(r => r.rule === method || (r.methods as readonly string[]).includes(method));
|
|
97
|
+
if (!rm) {
|
|
98
|
+
let extraInfo = "";
|
|
99
|
+
if (is_view && RULE_TO_METHODS.find(r => !is_view && r.rule === method || (r.methods as any).includes(method))) {
|
|
100
|
+
extraInfo = "You've specified table rules to a view\n";
|
|
101
|
+
}
|
|
102
|
+
throw `Invalid rule in publish.${tableName} -> ${method} \n${extraInfo}Expecting any of: ${MY_RULES.flatMap(r => [r.rule, ...r.methods]).join(", ")}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* Check RULES for invalid params */
|
|
106
|
+
/* Methods do not have params -> They use them from rules */
|
|
107
|
+
if (method === rm.rule && isObject(rule)) {
|
|
108
|
+
const method_params = Object.keys(rule);
|
|
109
|
+
const allowed_params = Object.keys(rm?.allowed_params)
|
|
110
|
+
const iparam = method_params.find(p => !allowed_params.includes(p));
|
|
111
|
+
if (iparam) {
|
|
112
|
+
throw `Invalid setting in publish.${tableName}.${method} -> ${iparam}. \n Expecting any of: ${allowed_params.join(", ")}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* Add default params (if missing) */
|
|
117
|
+
if (method === "sync") {
|
|
118
|
+
|
|
119
|
+
if ([true, "*"].includes(parsed_table[method] as any)) {
|
|
120
|
+
throw "Invalid sync rule. Expecting { id_fields: string[], synced_field: string } ";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (typeof parsed_table[method]?.throttle !== "number") {
|
|
124
|
+
parsed_table[method]!.throttle = 100;
|
|
125
|
+
}
|
|
126
|
+
if (typeof parsed_table[method]?.batch_size !== "number") {
|
|
127
|
+
parsed_table[method]!.batch_size = DEFAULT_SYNC_BATCH_SIZE;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* Enable subscribe if not explicitly disabled OR if VIEW with referenced tables */
|
|
132
|
+
const subKey = "subscribe" as const;
|
|
133
|
+
|
|
134
|
+
if (method === "select" && !dissallowedRuleKeys.includes(subKey)) {
|
|
135
|
+
const sr = MY_RULES.find(r => r.rule === subKey);
|
|
136
|
+
if (sr && canSubscribe) {
|
|
137
|
+
parsed_table[subKey] = { ...sr.no_limits as SubscribeRule };
|
|
138
|
+
parsed_table.subscribeOne = { ...sr.no_limits as SubscribeRule };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
} else {
|
|
144
|
+
throw "Unexpected publish"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const getImpliedMethods = (tableRules: ParsedPublishTable): ParsedPublishTable => {
|
|
148
|
+
const res = { ...tableRules };
|
|
149
|
+
|
|
150
|
+
/* Add implied methods if not specifically dissallowed */
|
|
151
|
+
MY_RULES.map(r => {
|
|
152
|
+
|
|
153
|
+
/** THIS IS A MESS -> some methods cannot be dissallowed (unsync, unsubscribe...) */
|
|
154
|
+
r.methods.forEach(method => {
|
|
155
|
+
const isAllowed = tableRules[r.rule] && (tableRules as any)[method] === undefined;
|
|
156
|
+
if (isAllowed) {
|
|
157
|
+
|
|
158
|
+
if (method === "updateBatch" && (!tableRules.update || tableRules.update.checkFilter || tableRules.update.postValidate)) {
|
|
159
|
+
// not allowed
|
|
160
|
+
|
|
161
|
+
} else if (method === "upsert" && (!tableRules.update || !tableRules.insert)) {
|
|
162
|
+
// not allowed
|
|
163
|
+
|
|
164
|
+
} else {
|
|
165
|
+
(res as any)[method] ??= true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return res;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
parsed_table = getImpliedMethods(parsed_table);
|
|
175
|
+
|
|
176
|
+
return parsed_table;
|
|
177
|
+
}
|