prostgles-server 4.2.623 → 4.2.625
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/debug/client-schema-types/DBGeneratedSchema.ts +13 -1
- package/dist/Audit/AuditTable.d.ts +2 -1
- package/dist/Audit/AuditTable.d.ts.map +1 -1
- package/dist/Audit/AuditTable.js +3 -2
- package/dist/Audit/AuditTable.js.map +1 -1
- package/dist/Audit/getAuditTableRules.d.ts +7 -0
- package/dist/Audit/getAuditTableRules.d.ts.map +1 -0
- package/dist/Audit/getAuditTableRules.js +191 -0
- package/dist/Audit/getAuditTableRules.js.map +1 -0
- package/dist/Audit/getAuditTriggerConfig.d.ts.map +1 -1
- package/dist/Audit/getAuditTriggerConfig.js +14 -1
- package/dist/Audit/getAuditTriggerConfig.js.map +1 -1
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.d.ts.map +1 -1
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.js +1 -2
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +1 -1
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts +10 -5
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +90 -71
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getJoinQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getJoinQuery.js +3 -2
- package/dist/DboBuilder/QueryBuilder/getJoinQuery.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts +2 -2
- package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js +53 -116
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getQuerySource.d.ts +18 -0
- package/dist/DboBuilder/QueryBuilder/getQuerySource.d.ts.map +1 -0
- package/dist/DboBuilder/QueryBuilder/getQuerySource.js +29 -0
- package/dist/DboBuilder/QueryBuilder/getQuerySource.js.map +1 -0
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.js +6 -2
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/parseJoinSelect.d.ts +13 -0
- package/dist/DboBuilder/QueryBuilder/parseJoinSelect.d.ts.map +1 -0
- package/dist/DboBuilder/QueryBuilder/parseJoinSelect.js +57 -0
- package/dist/DboBuilder/QueryBuilder/parseJoinSelect.js.map +1 -0
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.js +2 -1
- 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 +2 -1
- package/dist/DboBuilder/TableHandler/delete.js.map +1 -1
- package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js +2 -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 +2 -1
- package/dist/DboBuilder/TableHandler/update.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +6 -16
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +2 -7
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.js +1 -1
- package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getExistsCondition.d.ts +1 -1
- package/dist/DboBuilder/ViewHandler/getExistsCondition.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/getExistsCondition.js +24 -13
- package/dist/DboBuilder/ViewHandler/getExistsCondition.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.d.ts +4 -1
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js +20 -14
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts +7 -3
- package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareWhere.js +30 -23
- package/dist/DboBuilder/ViewHandler/prepareWhere.js.map +1 -1
- package/dist/DboBuilder/getCondition.d.ts +2 -1
- package/dist/DboBuilder/getCondition.d.ts.map +1 -1
- package/dist/DboBuilder/getCondition.js +9 -8
- package/dist/DboBuilder/getCondition.js.map +1 -1
- package/dist/DboBuilder/getSubscribeRelatedTables.d.ts.map +1 -1
- package/dist/DboBuilder/getSubscribeRelatedTables.js +3 -2
- package/dist/DboBuilder/getSubscribeRelatedTables.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.d.ts.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.js +3 -2
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
- package/dist/DboBuilder/schema/getTablesForSchemaPostgresSQL.d.ts +2 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +2 -0
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesContext.spec.js +25 -0
- package/dist/ProstglesContext.spec.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +1 -1
- package/dist/PublishParser/PublishParser.d.ts +17 -8
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +59 -28
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/applyScopeToTableRules.d.ts +0 -1
- package/dist/PublishParser/applyScopeToTableRules.d.ts.map +1 -1
- package/dist/PublishParser/applyScopeToTableRules.js +3 -7
- package/dist/PublishParser/applyScopeToTableRules.js.map +1 -1
- package/dist/PublishParser/getFileTableRules.d.ts +1 -1
- package/dist/PublishParser/getFileTableRules.d.ts.map +1 -1
- package/dist/PublishParser/getFileTableRules.js +52 -41
- package/dist/PublishParser/getFileTableRules.js.map +1 -1
- package/dist/PublishParser/getParsedPublishTable.d.ts +4 -0
- package/dist/PublishParser/getParsedPublishTable.d.ts.map +1 -0
- package/dist/PublishParser/{getTableRulesWithoutFileTable.js → getParsedPublishTable.js} +13 -7
- package/dist/PublishParser/getParsedPublishTable.js.map +1 -0
- package/dist/PublishParser/getPublishSchemas.d.ts +4 -0
- package/dist/PublishParser/getPublishSchemas.d.ts.map +1 -0
- package/dist/PublishParser/getPublishSchemas.js +42 -0
- package/dist/PublishParser/getPublishSchemas.js.map +1 -0
- package/dist/PublishParser/getPublishedObjectFromResult.d.ts +4 -0
- package/dist/PublishParser/getPublishedObjectFromResult.d.ts.map +1 -0
- package/dist/PublishParser/getPublishedObjectFromResult.js +77 -0
- package/dist/PublishParser/getPublishedObjectFromResult.js.map +1 -0
- package/dist/PublishParser/getPublishedTableNames.d.ts.map +1 -1
- package/dist/PublishParser/getPublishedTableNames.js +20 -1
- package/dist/PublishParser/getPublishedTableNames.js.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +11 -5
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.d.ts +28 -7
- package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.js +6 -1
- package/dist/PublishParser/publishTypesAndUtils.js.map +1 -1
- package/dist/PublishParser/validatePublishProfiles.d.ts +2 -2
- package/dist/PublishParser/validatePublishProfiles.d.ts.map +1 -1
- package/dist/PublishParser/validatePublishProfiles.js.map +1 -1
- package/dist/TableConfig/getColumnSQLDefinitionQuery.d.ts.map +1 -1
- package/dist/TableConfig/getColumnSQLDefinitionQuery.js +1 -2
- package/dist/TableConfig/getColumnSQLDefinitionQuery.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/runClientRequest.d.ts.map +1 -1
- package/dist/runClientRequest.js +6 -1
- package/dist/runClientRequest.js.map +1 -1
- package/lib/Audit/AuditTable.ts +4 -3
- package/lib/Audit/getAuditTableRules.ts +288 -0
- package/lib/Audit/getAuditTriggerConfig.ts +14 -1
- package/lib/DBSchemaBuilder/getDBGeneratedSchema.ts +1 -2
- package/lib/DboBuilder/DboBuilder.ts +1 -1
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +118 -90
- package/lib/DboBuilder/QueryBuilder/getJoinQuery.ts +3 -2
- package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +111 -194
- package/lib/DboBuilder/QueryBuilder/getQuerySource.ts +55 -0
- package/lib/DboBuilder/QueryBuilder/getSelectQuery.ts +8 -2
- package/lib/DboBuilder/QueryBuilder/parseJoinSelect.ts +73 -0
- package/lib/DboBuilder/TableHandler/TableHandler.ts +3 -6
- package/lib/DboBuilder/TableHandler/delete.ts +2 -1
- package/lib/DboBuilder/TableHandler/runInsertUpdateQuery.ts +2 -1
- package/lib/DboBuilder/TableHandler/update.ts +2 -1
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +6 -12
- package/lib/DboBuilder/ViewHandler/find.ts +0 -1
- package/lib/DboBuilder/ViewHandler/getExistsCondition.ts +35 -28
- package/lib/DboBuilder/ViewHandler/getTableJoinQuery.ts +22 -14
- package/lib/DboBuilder/ViewHandler/prepareWhere.ts +48 -27
- package/lib/DboBuilder/getCondition.ts +11 -10
- package/lib/DboBuilder/getSubscribeRelatedTables.ts +3 -2
- package/lib/DboBuilder/parseUpdateRules.ts +3 -2
- package/lib/Prostgles.ts +1 -0
- package/lib/ProstglesContext.spec.ts +30 -0
- package/lib/PublishParser/PublishParser.ts +108 -51
- package/lib/PublishParser/applyScopeToTableRules.ts +1 -7
- package/lib/PublishParser/getFileTableRules.ts +52 -45
- package/lib/PublishParser/{getTableRulesWithoutFileTable.ts → getParsedPublishTable.ts} +16 -12
- package/lib/PublishParser/getPublishSchemas.ts +49 -0
- package/lib/PublishParser/getPublishedObjectFromResult.ts +104 -0
- package/lib/PublishParser/getPublishedTableNames.ts +28 -1
- package/lib/PublishParser/getSchemaFromPublish.ts +9 -7
- package/lib/PublishParser/publishTypesAndUtils.ts +31 -11
- package/lib/PublishParser/validatePublishProfiles.ts +1 -1
- package/lib/TableConfig/getColumnSQLDefinitionQuery.ts +8 -2
- package/lib/index.ts +14 -1
- package/lib/runClientRequest.ts +4 -3
- package/package.json +1 -1
- package/dist/DBSchemaBuilder/getPublishSchemas.d.ts +0 -4
- package/dist/DBSchemaBuilder/getPublishSchemas.d.ts.map +0 -1
- package/dist/DBSchemaBuilder/getPublishSchemas.js +0 -34
- package/dist/DBSchemaBuilder/getPublishSchemas.js.map +0 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts +0 -6
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +0 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +0 -1
- package/lib/DBSchemaBuilder/getPublishSchemas.ts +0 -41
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pickKeys } from "prostgles-types";
|
|
1
|
+
import { pickKeys, type AnyObject } from "prostgles-types";
|
|
2
2
|
import { parseFilterItem } from "../Filtering/Filtering";
|
|
3
3
|
import type { ParsedTableRule } from "../PublishParser/PublishParser";
|
|
4
4
|
import type { ExistsFilterConfig, LocalParams, PGIdentifier } from "./DboBuilder";
|
|
@@ -9,6 +9,7 @@ import type { ViewHandler } from "./ViewHandler/ViewHandler";
|
|
|
9
9
|
import { getExistsCondition } from "./ViewHandler/getExistsCondition";
|
|
10
10
|
import { getExistsFilters } from "./ViewHandler/getExistsFilters";
|
|
11
11
|
import { parseComplexFilter } from "./ViewHandler/parseComplexFilter";
|
|
12
|
+
import { isArray } from "../utils/utils";
|
|
12
13
|
|
|
13
14
|
const FILTER_FUNCS = FUNCTIONS.filter((f) => f.canBeUsedForFilter);
|
|
14
15
|
|
|
@@ -21,7 +22,7 @@ const FILTER_FUNCS = FUNCTIONS.filter((f) => f.canBeUsedForFilter);
|
|
|
21
22
|
export async function getCondition(
|
|
22
23
|
this: ViewHandler,
|
|
23
24
|
params: {
|
|
24
|
-
filter:
|
|
25
|
+
filter: AnyObject;
|
|
25
26
|
select: SelectItemValidated[] | undefined;
|
|
26
27
|
allowed_colnames: string[];
|
|
27
28
|
tableAlias?: PGIdentifier;
|
|
@@ -44,21 +45,21 @@ export async function getCondition(
|
|
|
44
45
|
|
|
45
46
|
const existsConfigs = getExistsFilters(filter, this);
|
|
46
47
|
|
|
47
|
-
const
|
|
48
|
+
const functionConditions: string[] = [];
|
|
48
49
|
const funcFilter = FILTER_FUNCS.filter((f) => f.name in filter);
|
|
49
50
|
|
|
50
51
|
funcFilter.map((f) => {
|
|
51
52
|
const funcArgs = filter[f.name];
|
|
52
|
-
if (!
|
|
53
|
+
if (!isArray(funcArgs)) {
|
|
53
54
|
throw `A function filter must contain an array. E.g: { $funcFilterName: ["col1"] } \n but got: ${JSON.stringify(pickKeys(filter, [f.name]))} `;
|
|
54
55
|
}
|
|
55
56
|
const fields = this.parseFieldFilter(f.getFields(funcArgs), true, allowed_colnames);
|
|
56
57
|
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
throw `Invalid/disallowed columns found in function filter: ${
|
|
58
|
+
const disallowedCols = fields.filter((fname) => !allowed_colnames.includes(fname));
|
|
59
|
+
if (disallowedCols.length) {
|
|
60
|
+
throw `Invalid/disallowed columns found in function filter: ${disallowedCols}`;
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
functionConditions.push(
|
|
62
63
|
f.getQuery({
|
|
63
64
|
args: funcArgs,
|
|
64
65
|
allColumns: this.columns,
|
|
@@ -84,7 +85,7 @@ export async function getCondition(
|
|
|
84
85
|
const p = this.getValidatedRules(tableRules, localParams);
|
|
85
86
|
const computedFields = p.allColumns.filter((c) => c.type === "computed");
|
|
86
87
|
const computedColConditions: string[] = [];
|
|
87
|
-
Object.keys(filter
|
|
88
|
+
Object.keys(filter).map((key) => {
|
|
88
89
|
const compCol = computedFields.find((cf) => cf.name === key);
|
|
89
90
|
if (compCol) {
|
|
90
91
|
if (!p.select) throw new Error("Computed column filter requires p.select.fields");
|
|
@@ -231,7 +232,7 @@ export async function getCondition(
|
|
|
231
232
|
let templates: string[] = q?.condition ? [q.condition] : [];
|
|
232
233
|
|
|
233
234
|
if (existsCond) templates.push(existsCond);
|
|
234
|
-
templates = templates.concat(
|
|
235
|
+
templates = templates.concat(functionConditions);
|
|
235
236
|
templates = templates.concat(computedColConditions);
|
|
236
237
|
templates = templates.concat(complexFilters);
|
|
237
238
|
|
|
@@ -8,6 +8,7 @@ import type { TableHandler } from "./TableHandler/TableHandler";
|
|
|
8
8
|
import type { ViewHandler } from "./ViewHandler/ViewHandler";
|
|
9
9
|
import { getViewRelatedTables } from "./ViewRelatedTables/getViewRelatedTables";
|
|
10
10
|
import type { AddTriggerParams } from "../PubSubManager/addTrigger";
|
|
11
|
+
import { prepareWhere } from "./ViewHandler/prepareWhere";
|
|
11
12
|
|
|
12
13
|
type Args = {
|
|
13
14
|
selectParams: Omit<SubscribeParams, "throttle">;
|
|
@@ -66,9 +67,9 @@ export async function getSubscribeRelatedTables(
|
|
|
66
67
|
isEmpty(targetTableFilter) ? reversedJoinFilter : (
|
|
67
68
|
{ $and: [targetTableFilter, reversedJoinFilter] }
|
|
68
69
|
);
|
|
69
|
-
const joinConditionInfo = await
|
|
70
|
-
select: undefined,
|
|
70
|
+
const joinConditionInfo = await prepareWhere(relatedTableOrViewHandler, {
|
|
71
71
|
filter,
|
|
72
|
+
select: undefined,
|
|
72
73
|
addWhere: false,
|
|
73
74
|
localParams: undefined,
|
|
74
75
|
tableRule: undefined,
|
|
@@ -9,6 +9,7 @@ import { type ParsedTableRule } from "../PublishParser/PublishParser";
|
|
|
9
9
|
import type { Filter, LocalParams } from "./DboBuilder";
|
|
10
10
|
import { prepareNewData } from "./TableHandler/DataValidator";
|
|
11
11
|
import type { TableHandler } from "./TableHandler/TableHandler";
|
|
12
|
+
import { prepareWhere } from "./ViewHandler/prepareWhere";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* 1) Check if publish is valid
|
|
@@ -57,7 +58,7 @@ export async function parseUpdateRules(
|
|
|
57
58
|
throw ` Invalid update rule fo r ${this.name}. fields missing `;
|
|
58
59
|
}
|
|
59
60
|
finalUpdateFilter = (
|
|
60
|
-
await
|
|
61
|
+
await prepareWhere(this, {
|
|
61
62
|
select: undefined,
|
|
62
63
|
filter,
|
|
63
64
|
forcedFilter,
|
|
@@ -77,7 +78,7 @@ export async function parseUpdateRules(
|
|
|
77
78
|
/**
|
|
78
79
|
* Validated filter and fields
|
|
79
80
|
*/
|
|
80
|
-
const condition = await
|
|
81
|
+
const condition = await prepareWhere(this, {
|
|
81
82
|
select: undefined,
|
|
82
83
|
filterFields: this.column_names,
|
|
83
84
|
filter: dfRule.filter,
|
package/lib/Prostgles.ts
CHANGED
|
@@ -2,6 +2,7 @@ import assert from "node:assert";
|
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
3
|
import type { DboBuilder } from "./DboBuilder/DboBuilder";
|
|
4
4
|
import { Prostgles } from "./Prostgles";
|
|
5
|
+
import type { PublishParser } from "./PublishParser/PublishParser";
|
|
5
6
|
|
|
6
7
|
void describe("Prostgles context", async () => {
|
|
7
8
|
await test("recreates context and runs cleanups in reverse order", async () => {
|
|
@@ -47,6 +48,35 @@ void describe("Prostgles context", async () => {
|
|
|
47
48
|
assert.equal(prostgles.context, undefined);
|
|
48
49
|
});
|
|
49
50
|
|
|
51
|
+
await test("recreates the publish parser with the rebuilt DBO", async () => {
|
|
52
|
+
const prostgles = new Prostgles({
|
|
53
|
+
dbConnection: "postgres://unused",
|
|
54
|
+
onReady: () => {},
|
|
55
|
+
});
|
|
56
|
+
prostgles.db = {} as typeof prostgles.db;
|
|
57
|
+
const rebuiltDbo = {};
|
|
58
|
+
const dboBuilder = {
|
|
59
|
+
build: () => {
|
|
60
|
+
dboBuilder.dbo = rebuiltDbo;
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
},
|
|
63
|
+
dbo: {},
|
|
64
|
+
sql: {},
|
|
65
|
+
tables: [],
|
|
66
|
+
};
|
|
67
|
+
prostgles.dboBuilder = dboBuilder as unknown as DboBuilder;
|
|
68
|
+
|
|
69
|
+
// PublishParser captures the DBO on construction, so it must be recreated after a rebuild.
|
|
70
|
+
const initialPublishParser = {} as PublishParser;
|
|
71
|
+
prostgles.publishParser = initialPublishParser;
|
|
72
|
+
|
|
73
|
+
await prostgles.rebuildDBO();
|
|
74
|
+
|
|
75
|
+
assert.equal(prostgles.dbo, rebuiltDbo);
|
|
76
|
+
assert.notEqual(prostgles.publishParser, initialPublishParser);
|
|
77
|
+
assert.equal(prostgles.publishParser.dbo, prostgles.dbo);
|
|
78
|
+
});
|
|
79
|
+
|
|
50
80
|
await test("cleans partially-created context after an error", async () => {
|
|
51
81
|
const events: string[] = [];
|
|
52
82
|
const prostgles = new Prostgles({
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getObjectEntries,
|
|
3
|
+
includes,
|
|
4
|
+
SQL_COMMAND_TABLE_METHODS,
|
|
5
|
+
type TableSchema,
|
|
6
|
+
} from "prostgles-types";
|
|
2
7
|
import { getClientRequestIPsInfo } from "../Auth/AuthHandler";
|
|
3
8
|
import type { AuthClientRequest, AuthResultWithSID, SessionUser } from "../Auth/AuthTypes";
|
|
9
|
+
import { getAuditTableRules } from "../Audit/getAuditTableRules";
|
|
4
10
|
import type { DBOFullyTyped } from "../DBSchemaBuilder/DBSchemaBuilder";
|
|
5
11
|
import type { DB, DBHandlerServer, Prostgles } from "../Prostgles";
|
|
6
|
-
import type { ProstglesInitOptions } from "../ProstglesTypes";
|
|
7
12
|
import { getClientHandlers } from "../WebsocketAPI/getClientHandlers";
|
|
8
13
|
import { applyScopeToTableRules } from "./applyScopeToTableRules";
|
|
9
14
|
import type {
|
|
@@ -12,15 +17,18 @@ import type {
|
|
|
12
17
|
UnrestrictedFunctionContext,
|
|
13
18
|
} from "./defineServerFunction";
|
|
14
19
|
import { getFileTableRules } from "./getFileTableRules";
|
|
20
|
+
import { getPublishedObjectFromResult } from "./getPublishedObjectFromResult";
|
|
15
21
|
import { getSchemaFromPublish } from "./getSchemaFromPublish";
|
|
16
|
-
import {
|
|
22
|
+
import { getParsedPublishTable } from "./getParsedPublishTable";
|
|
17
23
|
import type {
|
|
18
24
|
DboTable,
|
|
19
25
|
DboTableCommand,
|
|
20
26
|
ParsedTableRule,
|
|
27
|
+
Publish,
|
|
21
28
|
PublishParams,
|
|
22
29
|
} from "./publishTypesAndUtils";
|
|
23
30
|
import {
|
|
31
|
+
isPublishProfiles,
|
|
24
32
|
parsePublishTableRule,
|
|
25
33
|
type PermissionScope,
|
|
26
34
|
type PublishObject,
|
|
@@ -28,9 +36,7 @@ import {
|
|
|
28
36
|
import { validatePublishProfiles } from "./validatePublishProfiles";
|
|
29
37
|
|
|
30
38
|
export class PublishParser {
|
|
31
|
-
|
|
32
|
-
| Exclude<ProstglesInitOptions<void, SessionUser, any>["publish"], unknown[]>
|
|
33
|
-
| ReturnType<typeof validatePublishProfiles>;
|
|
39
|
+
parsedPublish: ReturnType<typeof getParsedPublish>;
|
|
34
40
|
publishRawSQL?: any;
|
|
35
41
|
dbo: DBHandlerServer;
|
|
36
42
|
db: DB;
|
|
@@ -39,7 +45,8 @@ export class PublishParser {
|
|
|
39
45
|
constructor(prostgles: Prostgles) {
|
|
40
46
|
this.prostgles = prostgles;
|
|
41
47
|
const { publish } = prostgles.opts;
|
|
42
|
-
|
|
48
|
+
|
|
49
|
+
this.parsedPublish = getParsedPublish(publish, prostgles.dboBuilder.tablesOrViews ?? []);
|
|
43
50
|
|
|
44
51
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
45
52
|
this.publishRawSQL = prostgles.opts.publishRawSQL;
|
|
@@ -145,50 +152,54 @@ export class PublishParser {
|
|
|
145
152
|
/**
|
|
146
153
|
* Parses the first level of publish. (If false then nothing if * then all tables and views)
|
|
147
154
|
*/
|
|
148
|
-
async
|
|
155
|
+
async getPublishObjectForUser(
|
|
149
156
|
clientReq: AuthClientRequest,
|
|
150
157
|
clientInfo: AuthResultWithSID | undefined,
|
|
151
158
|
): Promise<PublishObject | undefined> {
|
|
152
159
|
const publishParams = await this.getPublishParams(clientReq, clientInfo);
|
|
153
160
|
|
|
154
|
-
const
|
|
155
|
-
const publish =
|
|
156
|
-
Array.isArray(result) ?
|
|
157
|
-
validatePublishProfiles(result).find((profile) =>
|
|
158
|
-
publishParams.user ? profile.userTypes.includes(publishParams.user.type) : false,
|
|
159
|
-
)?.publish
|
|
160
|
-
: result;
|
|
161
|
-
|
|
162
|
-
if (publish === "*") {
|
|
163
|
-
const publish: PublishObject = {};
|
|
164
|
-
this.prostgles.dboBuilder.tablesOrViews?.map((tov) => {
|
|
165
|
-
publish[tov.name] = "*";
|
|
166
|
-
});
|
|
167
|
-
return publish;
|
|
168
|
-
}
|
|
161
|
+
const parsedPublish = await applyParamsIfFunc(this.parsedPublish, publishParams);
|
|
169
162
|
|
|
170
|
-
|
|
163
|
+
const publishResult = (() => {
|
|
164
|
+
if (!isPublishProfiles(parsedPublish)) {
|
|
165
|
+
return parsedPublish;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const { user } = publishParams;
|
|
169
|
+
if (!user) return;
|
|
170
|
+
return parsedPublish.find(({ userTypes }) => userTypes.includes(user.type))?.publish;
|
|
171
|
+
})();
|
|
172
|
+
|
|
173
|
+
if (!publishResult) return;
|
|
174
|
+
|
|
175
|
+
const publishedObject = getPublishedObjectFromResult(
|
|
176
|
+
publishResult,
|
|
177
|
+
this.prostgles.dboBuilder.tablesOrViews ?? [],
|
|
178
|
+
publishParams,
|
|
179
|
+
);
|
|
180
|
+
return publishedObject;
|
|
171
181
|
}
|
|
172
182
|
|
|
173
183
|
async getValidatedRequestRuleWusr(
|
|
174
184
|
{ tableName, command, clientReq }: DboTableCommand,
|
|
175
185
|
scope: PermissionScope | undefined,
|
|
176
186
|
): Promise<ParsedTableRule> {
|
|
177
|
-
const rules = await this.getParsedTableRule({ tableName, clientReq }, undefined, scope);
|
|
178
187
|
const clientInfo =
|
|
179
188
|
clientReq && (await this.prostgles.authHandler.getSidAndUserFromRequest(clientReq));
|
|
180
189
|
if (clientInfo === "new-session-redirect") {
|
|
181
190
|
throw "new-session-redirect";
|
|
182
191
|
}
|
|
192
|
+
const rules = await this.getParsedTableRule({ tableName, clientReq, scope, clientInfo });
|
|
183
193
|
this.validateRequestRule({ tableName, command, clientReq }, rules, scope);
|
|
184
194
|
return rules;
|
|
185
195
|
}
|
|
186
196
|
|
|
187
|
-
async getParsedTableRule(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
197
|
+
async getParsedTableRule({
|
|
198
|
+
tableName,
|
|
199
|
+
clientReq,
|
|
200
|
+
clientInfo,
|
|
201
|
+
scope,
|
|
202
|
+
}: Omit<TableRequest, "resolvedPublishObject">): Promise<ParsedTableRule> {
|
|
192
203
|
if (!tableName) throw "tableName missing";
|
|
193
204
|
|
|
194
205
|
/* Must be local request -> allow everything */
|
|
@@ -202,7 +213,7 @@ export class PublishParser {
|
|
|
202
213
|
}
|
|
203
214
|
|
|
204
215
|
/* Must be from socket. Must have a publish */
|
|
205
|
-
if (!this.
|
|
216
|
+
if (!this.parsedPublish) throw "publish is missing";
|
|
206
217
|
|
|
207
218
|
const tableErrors = clientReq.socket?.prostgles?.get(this.prostgles.appId)?.tableSchemaErrors[
|
|
208
219
|
tableName
|
|
@@ -212,7 +223,13 @@ export class PublishParser {
|
|
|
212
223
|
throw errorInfo.error;
|
|
213
224
|
});
|
|
214
225
|
|
|
215
|
-
const tableRule = await this.getTableRules({
|
|
226
|
+
const tableRule = await this.getTableRules({
|
|
227
|
+
tableName,
|
|
228
|
+
clientReq,
|
|
229
|
+
clientInfo,
|
|
230
|
+
scope,
|
|
231
|
+
resolvedPublishObject: undefined,
|
|
232
|
+
});
|
|
216
233
|
|
|
217
234
|
if (!tableRule) {
|
|
218
235
|
throw {
|
|
@@ -278,27 +295,52 @@ export class PublishParser {
|
|
|
278
295
|
}
|
|
279
296
|
}
|
|
280
297
|
|
|
281
|
-
async getTableRules(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
298
|
+
async getTableRules({
|
|
299
|
+
resolvedPublishObject: overriddenPublish,
|
|
300
|
+
scope,
|
|
301
|
+
clientInfo,
|
|
302
|
+
clientReq,
|
|
303
|
+
tableName,
|
|
304
|
+
}: TableRequest): Promise<ParsedTableRule | undefined> {
|
|
288
305
|
const tableHandler = this.dbo[tableName];
|
|
289
306
|
if (!tableHandler) {
|
|
290
|
-
throw "INTERNAL ERROR: table handler not found for " +
|
|
307
|
+
throw "INTERNAL ERROR: table handler not found for " + tableName;
|
|
291
308
|
}
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
overriddenPublish
|
|
296
|
-
|
|
297
|
-
|
|
309
|
+
const audit = this.prostgles.resolvedAuditConfig;
|
|
310
|
+
const isAuditTable = audit?.tableName === tableName;
|
|
311
|
+
const resolvedPublishObject =
|
|
312
|
+
overriddenPublish ??
|
|
313
|
+
(isAuditTable && clientReq ?
|
|
314
|
+
await this.getPublishObjectForUser(clientReq, clientInfo)
|
|
315
|
+
: undefined);
|
|
316
|
+
const publishRulesExcludingInferredTables =
|
|
317
|
+
await this.getParsedPublishTable({
|
|
318
|
+
clientReq,
|
|
319
|
+
tableName,
|
|
320
|
+
clientInfo,
|
|
321
|
+
resolvedPublishObject,
|
|
322
|
+
});
|
|
323
|
+
if (audit && isAuditTable) {
|
|
324
|
+
const auditTableRules = await getAuditTableRules.bind(this)(
|
|
325
|
+
audit,
|
|
326
|
+
publishRulesExcludingInferredTables,
|
|
327
|
+
clientReq,
|
|
328
|
+
clientInfo,
|
|
329
|
+
scope,
|
|
330
|
+
resolvedPublishObject,
|
|
331
|
+
);
|
|
332
|
+
return applyScopeToTableRules(
|
|
333
|
+
tableName,
|
|
334
|
+
tableHandler,
|
|
335
|
+
parsePublishTableRule(auditTableRules),
|
|
336
|
+
scope,
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
if (this.dbo[tableName]?.is_media) {
|
|
298
340
|
const { rules: fileTableRules } = await getFileTableRules.bind(this)(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
341
|
+
tableName,
|
|
342
|
+
publishRulesExcludingInferredTables,
|
|
343
|
+
clientReq,
|
|
302
344
|
clientInfo,
|
|
303
345
|
scope,
|
|
304
346
|
overriddenPublish,
|
|
@@ -314,17 +356,32 @@ export class PublishParser {
|
|
|
314
356
|
return applyScopeToTableRules(
|
|
315
357
|
tableName,
|
|
316
358
|
tableHandler,
|
|
317
|
-
parsePublishTableRule(
|
|
359
|
+
parsePublishTableRule(publishRulesExcludingInferredTables),
|
|
318
360
|
scope,
|
|
319
361
|
);
|
|
320
362
|
}
|
|
321
363
|
|
|
322
|
-
|
|
364
|
+
getParsedPublishTable = getParsedPublishTable.bind(this);
|
|
323
365
|
|
|
324
366
|
/* Prepares schema for client. Only allowed views and commands will be present */
|
|
325
367
|
getSchemaFromPublish = getSchemaFromPublish.bind(this);
|
|
326
368
|
}
|
|
327
369
|
|
|
370
|
+
const getParsedPublish = (publish: Publish | undefined, tablesOrViews: TableSchema[]) => {
|
|
371
|
+
if (!publish) return;
|
|
372
|
+
return (
|
|
373
|
+
isPublishProfiles(publish) ? validatePublishProfiles(publish)
|
|
374
|
+
: typeof publish === "function" ? publish
|
|
375
|
+
: getPublishedObjectFromResult(publish, tablesOrViews, undefined)
|
|
376
|
+
);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
export type TableRequest = DboTable & {
|
|
380
|
+
clientInfo: AuthResultWithSID | undefined;
|
|
381
|
+
scope: PermissionScope | undefined;
|
|
382
|
+
resolvedPublishObject: PublishObject | undefined;
|
|
383
|
+
};
|
|
384
|
+
|
|
328
385
|
export * from "./publishTypesAndUtils";
|
|
329
386
|
|
|
330
387
|
type FunctionWithArguments = (...args: any) => any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getObjectEntries, isDefined, isEmpty } from "prostgles-types";
|
|
1
|
+
import { fromEntries, getObjectEntries, isDefined, isEmpty } from "prostgles-types";
|
|
2
2
|
import type { TableHandler } from "../DboBuilder/TableHandler/TableHandler";
|
|
3
3
|
import { type ParsedTableRule, type PermissionScope } from "./PublishParser";
|
|
4
4
|
export const applyScopeToTableRules = (
|
|
@@ -68,9 +68,3 @@ export const applyScopeToTableRules = (
|
|
|
68
68
|
) as ParsedTableRule;
|
|
69
69
|
return result;
|
|
70
70
|
};
|
|
71
|
-
|
|
72
|
-
export const fromEntries = <K extends string | number | symbol, V>(
|
|
73
|
-
entries: readonly (readonly [K, V])[],
|
|
74
|
-
): Record<K, V> => {
|
|
75
|
-
return Object.fromEntries(entries) as Record<K, V>;
|
|
76
|
-
};
|
|
@@ -20,8 +20,8 @@ export async function getFileTableRules(
|
|
|
20
20
|
fileTablePublishRules: ParsedPublishTable | undefined,
|
|
21
21
|
clientReq: AuthClientRequest | undefined,
|
|
22
22
|
clientInfo: AuthResultWithSID | undefined,
|
|
23
|
-
scope: LocalParams["scope"],
|
|
24
|
-
|
|
23
|
+
scope: LocalParams["scope"] | undefined,
|
|
24
|
+
resolvedPublishObject: PublishObject | undefined,
|
|
25
25
|
) {
|
|
26
26
|
const forcedDeleteFilters: FullFilter<AnyObject, void>[] = [];
|
|
27
27
|
const forcedSelectFilters: FullFilter<AnyObject, void>[] = [];
|
|
@@ -43,51 +43,58 @@ export async function getFileTableRules(
|
|
|
43
43
|
.filter(isDefined);
|
|
44
44
|
if (referencedColumns?.length) {
|
|
45
45
|
for (const { tableName, fileColumns, allColumns } of referencedColumns) {
|
|
46
|
-
const tableRules = await this.getTableRules({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const tableRules = await this.getTableRules({
|
|
47
|
+
clientReq,
|
|
48
|
+
tableName,
|
|
49
|
+
clientInfo,
|
|
50
|
+
scope,
|
|
51
|
+
resolvedPublishObject,
|
|
52
|
+
});
|
|
53
|
+
if (!tableRules) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
fileColumns.map((column) => {
|
|
57
|
+
const path = [{ table: tableName, on: [{ id: column }] }];
|
|
58
|
+
if (tableRules.delete) {
|
|
59
|
+
forcedDeleteFilters.push({
|
|
60
|
+
$existsJoined: {
|
|
61
|
+
path,
|
|
62
|
+
filter: tableRules.delete.forcedFilter ?? {},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (tableRules.select) {
|
|
67
|
+
const parsedFields = parseFieldFilter(tableRules.select.fields, false, allColumns);
|
|
68
|
+
/** Must be allowed to view this column */
|
|
69
|
+
if (includes(parsedFields, column)) {
|
|
70
|
+
forcedSelectFilters.push({
|
|
52
71
|
$existsJoined: {
|
|
53
72
|
path,
|
|
54
|
-
filter: tableRules.
|
|
73
|
+
filter: tableRules.select.forcedFilter ?? {},
|
|
55
74
|
},
|
|
56
75
|
});
|
|
57
76
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
path,
|
|
65
|
-
filter: tableRules.select.forcedFilter ?? {},
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (tableRules.insert) {
|
|
71
|
-
const parsedFields = parseFieldFilter(tableRules.insert.fields, false, allColumns);
|
|
72
|
-
/** Must be allowed to view this column */
|
|
73
|
-
if (includes(parsedFields, column)) {
|
|
74
|
-
allowedNestedInserts.push({ table: tableName, column });
|
|
75
|
-
}
|
|
77
|
+
}
|
|
78
|
+
if (tableRules.insert) {
|
|
79
|
+
const parsedFields = parseFieldFilter(tableRules.insert.fields, false, allColumns);
|
|
80
|
+
/** Must be allowed to view this column */
|
|
81
|
+
if (includes(parsedFields, column)) {
|
|
82
|
+
allowedNestedInserts.push({ table: tableName, column });
|
|
76
83
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
}
|
|
87
|
-
}
|
|
84
|
+
}
|
|
85
|
+
if (tableRules.update) {
|
|
86
|
+
const parsedFields = parseFieldFilter(tableRules.update.fields, false, allColumns);
|
|
87
|
+
/** Must be allowed to view this column */
|
|
88
|
+
if (includes(parsedFields, column)) {
|
|
89
|
+
forcedUpdateFilters.push({
|
|
90
|
+
$existsJoined: {
|
|
91
|
+
path,
|
|
92
|
+
filter: tableRules.update.forcedFilter ?? {},
|
|
93
|
+
},
|
|
94
|
+
});
|
|
88
95
|
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
100
|
|
|
@@ -137,11 +144,11 @@ export async function getFileTableRules(
|
|
|
137
144
|
};
|
|
138
145
|
}
|
|
139
146
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
const rules = await this.getParsedPublishTable.bind(this)({
|
|
148
|
+
clientReq,
|
|
149
|
+
tableName: fileTableName,
|
|
143
150
|
clientInfo,
|
|
144
|
-
{ [fileTableName]: fileTableRule },
|
|
145
|
-
);
|
|
151
|
+
resolvedPublishObject: { [fileTableName]: fileTableRule },
|
|
152
|
+
});
|
|
146
153
|
return { rules, allowedInserts: allowedNestedInserts };
|
|
147
154
|
}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import { isAuditTable } from "../Audit/getAuditTableConfig";
|
|
2
1
|
import { getObjectEntries, isObject } from "prostgles-types";
|
|
3
|
-
import
|
|
2
|
+
import { isAuditTable } from "../Audit/getAuditTableConfig";
|
|
4
3
|
import type { TableHandler } from "../DboBuilder/TableHandler/TableHandler";
|
|
5
4
|
import type { ViewHandler } from "../DboBuilder/ViewHandler/ViewHandler";
|
|
6
|
-
import type { PublishParser } from "./PublishParser";
|
|
7
|
-
import type {
|
|
8
|
-
import { TABLE_RULE_NO_LIMITS
|
|
5
|
+
import type { PublishParser, TableRequest } from "./PublishParser";
|
|
6
|
+
import type { ParsedPublishTable } from "./publishTypesAndUtils";
|
|
7
|
+
import { TABLE_RULE_NO_LIMITS } from "./publishTypesAndUtils";
|
|
9
8
|
|
|
10
|
-
export async function
|
|
9
|
+
export async function getParsedPublishTable(
|
|
11
10
|
this: PublishParser,
|
|
12
|
-
{ tableName, clientReq }:
|
|
13
|
-
clientInfo: AuthResultWithSID | undefined,
|
|
14
|
-
overridenPublish?: PublishObject,
|
|
11
|
+
{ tableName, clientReq, clientInfo, resolvedPublishObject }: Omit<TableRequest, "scope">,
|
|
15
12
|
): Promise<ParsedPublishTable | undefined> {
|
|
16
13
|
if (!tableName) {
|
|
17
14
|
throw new Error("tableName is missing in getTableRules");
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
const publish =
|
|
21
|
-
|
|
18
|
+
resolvedPublishObject ??
|
|
19
|
+
(clientReq && (await this.getPublishObjectForUser(clientReq, clientInfo)));
|
|
22
20
|
|
|
23
21
|
const rawTableRule = publish?.[tableName];
|
|
24
22
|
if (!rawTableRule || (isObject(rawTableRule) && Object.values(rawTableRule).every((v) => !v))) {
|
|
@@ -53,8 +51,14 @@ export async function getTableRulesWithoutFileTable(
|
|
|
53
51
|
}
|
|
54
52
|
: rawTableRule;
|
|
55
53
|
|
|
56
|
-
const tableRulesObject =
|
|
57
|
-
|
|
54
|
+
const tableRulesObject =
|
|
55
|
+
isAuditTable(this.prostgles, tableName) ?
|
|
56
|
+
{
|
|
57
|
+
select: rawTableRulesObject.select,
|
|
58
|
+
insert: undefined,
|
|
59
|
+
update: undefined,
|
|
60
|
+
delete: undefined,
|
|
61
|
+
}
|
|
58
62
|
: rawTableRulesObject;
|
|
59
63
|
|
|
60
64
|
const selectRule =
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { fromEntries, type DBSchemaTable } from "prostgles-types";
|
|
2
|
+
import { getRawColumns } from "../DboBuilder/getColumns";
|
|
3
|
+
import { getRawInfo } from "../DboBuilder/ViewHandler/getRawInfo";
|
|
4
|
+
import type { ClientSchemaProfiles } from "../DBSchemaBuilder/getClientDBGeneratedSchemas";
|
|
5
|
+
import { isArray } from "../utils/utils";
|
|
6
|
+
import { getPublishedObjectFromResult } from "./getPublishedObjectFromResult";
|
|
7
|
+
import { getPublishedTableNames } from "./getPublishedTableNames";
|
|
8
|
+
import type { PublishParser } from "./PublishParser";
|
|
9
|
+
|
|
10
|
+
export const getPublishSchemas = async (
|
|
11
|
+
publishParser: PublishParser,
|
|
12
|
+
): Promise<ClientSchemaProfiles | undefined> => {
|
|
13
|
+
if (!isArray(publishParser.parsedPublish)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const entries = publishParser.parsedPublish;
|
|
17
|
+
const { tablesOrViews = [] } = publishParser.prostgles.dboBuilder;
|
|
18
|
+
const profiles: ClientSchemaProfiles = fromEntries(
|
|
19
|
+
await Promise.all(
|
|
20
|
+
entries.map(async ({ name, publish }) => {
|
|
21
|
+
const resolvedPublishObject = getPublishedObjectFromResult(
|
|
22
|
+
publish,
|
|
23
|
+
tablesOrViews,
|
|
24
|
+
undefined,
|
|
25
|
+
);
|
|
26
|
+
const tableNames = getPublishedTableNames(publishParser, resolvedPublishObject);
|
|
27
|
+
const tableSchema: DBSchemaTable[] = [];
|
|
28
|
+
for (const tableName of tableNames) {
|
|
29
|
+
const rules = await publishParser.getTableRules({
|
|
30
|
+
tableName,
|
|
31
|
+
resolvedPublishObject,
|
|
32
|
+
clientReq: undefined,
|
|
33
|
+
clientInfo: undefined,
|
|
34
|
+
scope: undefined,
|
|
35
|
+
});
|
|
36
|
+
if (!rules || !Object.values(rules).some(Boolean)) continue;
|
|
37
|
+
const table = publishParser.dbo[tableName]!;
|
|
38
|
+
tableSchema.push({
|
|
39
|
+
...getRawInfo.call(table, undefined, rules),
|
|
40
|
+
name: tableName,
|
|
41
|
+
columns: await getRawColumns.call(table, undefined, undefined, rules),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return [name, { tableSchema }];
|
|
45
|
+
}),
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
return profiles;
|
|
49
|
+
};
|