prostgles-server 4.2.178 → 4.2.180
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/.vscode/settings.json +10 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.js +4 -4
- package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/insert.js +3 -3
- package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
- package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/update.js +45 -19
- package/dist/DboBuilder/TableHandler/update.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +2 -2
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.js +1 -1
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
- package/dist/Logging.d.ts +10 -3
- package/dist/Logging.d.ts.map +1 -1
- package/dist/Prostgles.d.ts +2 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +118 -53
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesTypes.d.ts +77 -23
- package/dist/ProstglesTypes.d.ts.map +1 -1
- package/dist/ProstglesTypes.js.map +1 -1
- package/dist/SyncReplication.js +2 -2
- package/dist/SyncReplication.js.map +1 -1
- package/dist/initProstgles.d.ts +9 -2
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +65 -57
- package/dist/initProstgles.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/documentation/CLIENT.md +542 -0
- package/documentation/SERVER.md +104 -0
- package/documentation/utils/clientTypes.ts +8436 -0
- package/documentation/utils/dist/clientTypes.d.ts +7705 -0
- package/documentation/utils/dist/clientTypes.d.ts.map +1 -0
- package/documentation/utils/dist/clientTypes.js +8438 -0
- package/documentation/utils/dist/definitions.d.ts +7705 -0
- package/documentation/utils/dist/definitions.d.ts.map +1 -0
- package/documentation/utils/dist/definitions.js +8438 -0
- package/documentation/utils/dist/generateClientDocs.d.ts +3 -0
- package/documentation/utils/dist/generateClientDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateClientDocs.js +115 -0
- package/documentation/utils/dist/generateDocs.d.ts +2 -0
- package/documentation/utils/dist/generateDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateDocs.js +6 -0
- package/documentation/utils/dist/generateMarkdown.d.ts +2 -0
- package/documentation/utils/dist/generateMarkdown.d.ts.map +1 -0
- package/documentation/utils/dist/generateMarkdown.js +68 -0
- package/documentation/utils/dist/generateServerDocs.d.ts +2 -0
- package/documentation/utils/dist/generateServerDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateServerDocs.js +80 -0
- package/documentation/utils/dist/getResolvedTypes.d.ts +15 -0
- package/documentation/utils/dist/getResolvedTypes.d.ts.map +1 -0
- package/documentation/utils/dist/getResolvedTypes.js +29 -0
- package/documentation/utils/dist/getSerializableType.d.ts +69 -0
- package/documentation/utils/dist/getSerializableType.d.ts.map +1 -0
- package/documentation/utils/dist/getSerializableType.js +273 -0
- package/documentation/utils/dist/getSymbolComments.d.ts +11 -0
- package/documentation/utils/dist/getSymbolComments.d.ts.map +1 -0
- package/documentation/utils/dist/getSymbolComments.js +60 -0
- package/documentation/utils/dist/loadTsFile.d.ts +7 -0
- package/documentation/utils/dist/loadTsFile.d.ts.map +1 -0
- package/documentation/utils/dist/loadTsFile.js +33 -0
- package/documentation/utils/dist/moduleResolver.d.ts +9 -0
- package/documentation/utils/dist/moduleResolver.d.ts.map +1 -0
- package/documentation/utils/dist/moduleResolver.js +27 -0
- package/documentation/utils/dist/serverTypes.d.ts +307 -0
- package/documentation/utils/dist/serverTypes.d.ts.map +1 -0
- package/documentation/utils/dist/serverTypes.js +347 -0
- package/documentation/utils/generateClientDocs.ts +142 -0
- package/documentation/utils/generateDocs.ts +4 -0
- package/documentation/utils/generateServerDocs.ts +82 -0
- package/documentation/utils/getResolvedTypes.ts +45 -0
- package/documentation/utils/getSerializableType.ts +479 -0
- package/documentation/utils/loadTsFile.ts +45 -0
- package/documentation/utils/moduleResolver.ts +31 -0
- package/documentation/utils/node_modules/.package-lock.json +67 -0
- package/documentation/utils/node_modules/@types/node/LICENSE +21 -0
- package/documentation/utils/node_modules/@types/node/README.md +15 -0
- package/documentation/utils/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/documentation/utils/node_modules/@types/node/assert.d.ts +1040 -0
- package/documentation/utils/node_modules/@types/node/async_hooks.d.ts +541 -0
- package/documentation/utils/node_modules/@types/node/buffer.buffer.d.ts +385 -0
- package/documentation/utils/node_modules/@types/node/buffer.d.ts +1934 -0
- package/documentation/utils/node_modules/@types/node/child_process.d.ts +1548 -0
- package/documentation/utils/node_modules/@types/node/cluster.d.ts +578 -0
- package/documentation/utils/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
- package/documentation/utils/node_modules/@types/node/compatibility/index.d.ts +9 -0
- package/documentation/utils/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
- package/documentation/utils/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/documentation/utils/node_modules/@types/node/console.d.ts +452 -0
- package/documentation/utils/node_modules/@types/node/constants.d.ts +19 -0
- package/documentation/utils/node_modules/@types/node/crypto.d.ts +4519 -0
- package/documentation/utils/node_modules/@types/node/dgram.d.ts +596 -0
- package/documentation/utils/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
- package/documentation/utils/node_modules/@types/node/dns/promises.d.ts +477 -0
- package/documentation/utils/node_modules/@types/node/dns.d.ts +864 -0
- package/documentation/utils/node_modules/@types/node/dom-events.d.ts +124 -0
- package/documentation/utils/node_modules/@types/node/domain.d.ts +170 -0
- package/documentation/utils/node_modules/@types/node/events.d.ts +931 -0
- package/documentation/utils/node_modules/@types/node/fs/promises.d.ts +1245 -0
- package/documentation/utils/node_modules/@types/node/fs.d.ts +4317 -0
- package/documentation/utils/node_modules/@types/node/globals.d.ts +468 -0
- package/documentation/utils/node_modules/@types/node/globals.typedarray.d.ts +21 -0
- package/documentation/utils/node_modules/@types/node/http.d.ts +1944 -0
- package/documentation/utils/node_modules/@types/node/http2.d.ts +2555 -0
- package/documentation/utils/node_modules/@types/node/https.d.ts +544 -0
- package/documentation/utils/node_modules/@types/node/index.d.ts +91 -0
- package/documentation/utils/node_modules/@types/node/inspector.d.ts +3696 -0
- package/documentation/utils/node_modules/@types/node/module.d.ts +315 -0
- package/documentation/utils/node_modules/@types/node/net.d.ts +1005 -0
- package/documentation/utils/node_modules/@types/node/os.d.ts +495 -0
- package/documentation/utils/node_modules/@types/node/package.json +220 -0
- package/documentation/utils/node_modules/@types/node/path.d.ts +200 -0
- package/documentation/utils/node_modules/@types/node/perf_hooks.d.ts +934 -0
- package/documentation/utils/node_modules/@types/node/process.d.ts +1879 -0
- package/documentation/utils/node_modules/@types/node/punycode.d.ts +117 -0
- package/documentation/utils/node_modules/@types/node/querystring.d.ts +153 -0
- package/documentation/utils/node_modules/@types/node/readline/promises.d.ts +162 -0
- package/documentation/utils/node_modules/@types/node/readline.d.ts +589 -0
- package/documentation/utils/node_modules/@types/node/repl.d.ts +430 -0
- package/documentation/utils/node_modules/@types/node/sea.d.ts +153 -0
- package/documentation/utils/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/documentation/utils/node_modules/@types/node/stream/promises.d.ts +90 -0
- package/documentation/utils/node_modules/@types/node/stream/web.d.ts +524 -0
- package/documentation/utils/node_modules/@types/node/stream.d.ts +1726 -0
- package/documentation/utils/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/documentation/utils/node_modules/@types/node/test.d.ts +1938 -0
- package/documentation/utils/node_modules/@types/node/timers/promises.d.ts +97 -0
- package/documentation/utils/node_modules/@types/node/timers.d.ts +240 -0
- package/documentation/utils/node_modules/@types/node/tls.d.ts +1217 -0
- package/documentation/utils/node_modules/@types/node/trace_events.d.ts +197 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +385 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +19 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/index.d.ts +91 -0
- package/documentation/utils/node_modules/@types/node/tty.d.ts +208 -0
- package/documentation/utils/node_modules/@types/node/url.d.ts +955 -0
- package/documentation/utils/node_modules/@types/node/util.d.ts +2306 -0
- package/documentation/utils/node_modules/@types/node/v8.d.ts +808 -0
- package/documentation/utils/node_modules/@types/node/vm.d.ts +922 -0
- package/documentation/utils/node_modules/@types/node/wasi.d.ts +181 -0
- package/documentation/utils/node_modules/@types/node/worker_threads.d.ts +694 -0
- package/documentation/utils/node_modules/@types/node/zlib.d.ts +539 -0
- package/documentation/utils/node_modules/undici-types/LICENSE +21 -0
- package/documentation/utils/node_modules/undici-types/README.md +6 -0
- package/documentation/utils/node_modules/undici-types/agent.d.ts +31 -0
- package/documentation/utils/node_modules/undici-types/api.d.ts +43 -0
- package/documentation/utils/node_modules/undici-types/balanced-pool.d.ts +29 -0
- package/documentation/utils/node_modules/undici-types/cache.d.ts +36 -0
- package/documentation/utils/node_modules/undici-types/client.d.ts +108 -0
- package/documentation/utils/node_modules/undici-types/connector.d.ts +34 -0
- package/documentation/utils/node_modules/undici-types/content-type.d.ts +21 -0
- package/documentation/utils/node_modules/undici-types/cookies.d.ts +28 -0
- package/documentation/utils/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
- package/documentation/utils/node_modules/undici-types/dispatcher.d.ts +255 -0
- package/documentation/utils/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
- package/documentation/utils/node_modules/undici-types/errors.d.ts +149 -0
- package/documentation/utils/node_modules/undici-types/eventsource.d.ts +63 -0
- package/documentation/utils/node_modules/undici-types/fetch.d.ts +209 -0
- package/documentation/utils/node_modules/undici-types/file.d.ts +39 -0
- package/documentation/utils/node_modules/undici-types/filereader.d.ts +54 -0
- package/documentation/utils/node_modules/undici-types/formdata.d.ts +108 -0
- package/documentation/utils/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/documentation/utils/node_modules/undici-types/global-origin.d.ts +7 -0
- package/documentation/utils/node_modules/undici-types/handlers.d.ts +15 -0
- package/documentation/utils/node_modules/undici-types/header.d.ts +4 -0
- package/documentation/utils/node_modules/undici-types/index.d.ts +71 -0
- package/documentation/utils/node_modules/undici-types/interceptors.d.ts +15 -0
- package/documentation/utils/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/documentation/utils/node_modules/undici-types/mock-client.d.ts +25 -0
- package/documentation/utils/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/documentation/utils/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/documentation/utils/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/documentation/utils/node_modules/undici-types/package.json +55 -0
- package/documentation/utils/node_modules/undici-types/patch.d.ts +71 -0
- package/documentation/utils/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/documentation/utils/node_modules/undici-types/pool.d.ts +39 -0
- package/documentation/utils/node_modules/undici-types/proxy-agent.d.ts +28 -0
- package/documentation/utils/node_modules/undici-types/readable.d.ts +60 -0
- package/documentation/utils/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/documentation/utils/node_modules/undici-types/retry-handler.d.ts +116 -0
- package/documentation/utils/node_modules/undici-types/util.d.ts +18 -0
- package/documentation/utils/node_modules/undici-types/webidl.d.ts +222 -0
- package/documentation/utils/node_modules/undici-types/websocket.d.ts +152 -0
- package/documentation/utils/package-lock.json +75 -0
- package/documentation/utils/package.json +14 -0
- package/documentation/utils/serverTypes.ts +345 -0
- package/documentation/utils/tsconfig.json +28 -0
- package/examples/full-example-typescript/DBoGenerated.d.ts +2 -2
- package/examples/full-example-typescript/DBoGenerated.ts +2 -2
- package/examples/full-example-typescript/index.ts +39 -45
- package/examples/full-example-vanilla/index.js +51 -53
- package/examples/server/typescript/index.ts +24 -30
- package/lib/DboBuilder/TableHandler/DataValidator.ts +5 -5
- package/lib/DboBuilder/TableHandler/TableHandler.ts +1 -1
- package/lib/DboBuilder/TableHandler/insert.ts +3 -3
- package/lib/DboBuilder/TableHandler/update.ts +106 -48
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +2 -2
- package/lib/DboBuilder/parseUpdateRules.ts +1 -1
- package/lib/Logging.ts +7 -3
- package/lib/Prostgles.ts +209 -142
- package/lib/ProstglesTypes.ts +130 -51
- package/lib/SyncReplication.ts +2 -2
- package/lib/initProstgles.ts +145 -111
- package/lib/utils.ts +4 -5
- package/package.json +3 -2
- package/examples/server/typescript/index.d.ts +0 -2
- package/examples/server/typescript/index.d.ts.map +0 -1
- package/examples/server/typescript/index.js +0 -54
- package/examples/server/typescript/index.js.map +0 -1
|
@@ -82,7 +82,7 @@ type PrepareFieldValuesArgs = {
|
|
|
82
82
|
row: AnyObject | undefined;
|
|
83
83
|
forcedData: AnyObject | undefined;
|
|
84
84
|
allowedCols: FieldFilter | undefined;
|
|
85
|
-
|
|
85
|
+
removeDisallowedFields?: boolean;
|
|
86
86
|
tableHandler: TableHandler;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -94,7 +94,7 @@ type PrepareFieldValuesArgs = {
|
|
|
94
94
|
* @param {Object} forcedData - set/override property
|
|
95
95
|
* @param {string[]} allowed_cols - allowed columns (excluding forcedData) from table rules
|
|
96
96
|
*/
|
|
97
|
-
const getValidatedRow = ({ row = {}, forcedData = {}, allowedCols,
|
|
97
|
+
const getValidatedRow = ({ row = {}, forcedData = {}, allowedCols, removeDisallowedFields = false, tableHandler }: PrepareFieldValuesArgs): AnyObject => {
|
|
98
98
|
const column_names = tableHandler.column_names.slice(0);
|
|
99
99
|
if (!column_names.length) {
|
|
100
100
|
throw "table column_names mising";
|
|
@@ -102,7 +102,7 @@ const getValidatedRow = ({ row = {}, forcedData = {}, allowedCols, removeDisallo
|
|
|
102
102
|
const validatedAllowedColumns = tableHandler.parseFieldFilter(allowedCols, false);
|
|
103
103
|
|
|
104
104
|
let finalRow = { ...row };
|
|
105
|
-
if (
|
|
105
|
+
if (removeDisallowedFields && !isEmpty(finalRow)) {
|
|
106
106
|
finalRow = pickKeys(finalRow, validatedAllowedColumns);
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -124,7 +124,7 @@ const getValidatedRow = ({ row = {}, forcedData = {}, allowedCols, removeDisallo
|
|
|
124
124
|
* prepareFieldValues(): Apply forcedData, remove disallowed columns, validate against allowed columns
|
|
125
125
|
* tableConfigurator?.checkColVal(): Validate column min/max/isText/lowerCased/trimmed values
|
|
126
126
|
*/
|
|
127
|
-
export const prepareNewData = async ({ row, forcedData, allowedFields, tableRules,
|
|
127
|
+
export const prepareNewData = async ({ row, forcedData, allowedFields, tableRules, removeDisallowedFields = false, tableConfigurator, tableHandler }: ValidatedParams) => {
|
|
128
128
|
const synced_field = (tableRules ?? {})?.sync?.synced_field;
|
|
129
129
|
|
|
130
130
|
/* Update synced_field if sync is on and missing */
|
|
@@ -132,7 +132,7 @@ export const prepareNewData = async ({ row, forcedData, allowedFields, tableRule
|
|
|
132
132
|
row[synced_field] = Date.now();
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
const data = getValidatedRow({ tableHandler, row, forcedData, allowedCols: allowedFields
|
|
135
|
+
const data = getValidatedRow({ tableHandler, row, forcedData, allowedCols: allowedFields, removeDisallowedFields });
|
|
136
136
|
const dataKeys = getKeys(data);
|
|
137
137
|
|
|
138
138
|
dataKeys.forEach(col => {
|
|
@@ -22,7 +22,7 @@ export type ValidatedParams = {
|
|
|
22
22
|
forcedData?: AnyObject;
|
|
23
23
|
allowedFields?: FieldFilter;
|
|
24
24
|
tableRules?: TableRule;
|
|
25
|
-
|
|
25
|
+
removeDisallowedFields: boolean;
|
|
26
26
|
tableConfigurator: TableConfigurator | undefined;
|
|
27
27
|
tableHandler: TableHandler;
|
|
28
28
|
}
|
|
@@ -13,7 +13,7 @@ export async function insert(this: TableHandler, rowOrRows: AnyObject | AnyObjec
|
|
|
13
13
|
const start = Date.now();
|
|
14
14
|
try {
|
|
15
15
|
|
|
16
|
-
const {
|
|
16
|
+
const { removeDisallowedFields = false } = insertParams || {};
|
|
17
17
|
const { returnQuery = false, nestedInsert } = localParams || {};
|
|
18
18
|
|
|
19
19
|
const finalDBtx = this.getFinalDBtx(localParams);
|
|
@@ -79,7 +79,7 @@ export async function insert(this: TableHandler, rowOrRows: AnyObject | AnyObjec
|
|
|
79
79
|
forcedData,
|
|
80
80
|
allowedFields: fields,
|
|
81
81
|
tableRules,
|
|
82
|
-
|
|
82
|
+
removeDisallowedFields,
|
|
83
83
|
tableConfigurator: this.dboBuilder.prostgles.tableConfigurator,
|
|
84
84
|
tableHandler: this,
|
|
85
85
|
});
|
|
@@ -165,7 +165,7 @@ const validateInsertParams = (params: InsertParams | undefined) => {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
if (params) {
|
|
168
|
-
const good_paramsObj: Record<keyof InsertParams, 1> = { returning: 1, returnType: 1,
|
|
168
|
+
const good_paramsObj: Record<keyof InsertParams, 1> = { returning: 1, returnType: 1, removeDisallowedFields: 1, onConflict: 1 };
|
|
169
169
|
const good_params = Object.keys(good_paramsObj);
|
|
170
170
|
const bad_params = Object.keys(params).filter(k => !good_params.includes(k));
|
|
171
171
|
if (bad_params && bad_params.length) throw "Invalid params: " + bad_params.join(", ") + " \n Expecting: " + good_params.join(", ");
|
|
@@ -1,30 +1,46 @@
|
|
|
1
1
|
import { AnyObject, UpdateParams } from "prostgles-types";
|
|
2
2
|
import { TableRule } from "../../PublishParser/PublishParser";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Filter,
|
|
5
|
+
LocalParams,
|
|
6
|
+
getErrorAsObject,
|
|
7
|
+
getSerializedClientErrorFromPGError,
|
|
8
|
+
withUserRLS,
|
|
9
|
+
} from "../DboBuilder";
|
|
4
10
|
import { getInsertTableRules, getReferenceColumnInserts } from "../insertNestedRecords";
|
|
5
11
|
import { prepareNewData } from "./DataValidator";
|
|
6
12
|
import { runInsertUpdateQuery } from "./runInsertUpdateQuery";
|
|
7
13
|
import { TableHandler } from "./TableHandler";
|
|
8
14
|
import { updateFile } from "./updateFile";
|
|
9
15
|
|
|
10
|
-
export async function update(
|
|
16
|
+
export async function update(
|
|
17
|
+
this: TableHandler,
|
|
18
|
+
filter: Filter,
|
|
19
|
+
_newData: AnyObject,
|
|
20
|
+
params?: UpdateParams,
|
|
21
|
+
tableRules?: TableRule,
|
|
22
|
+
localParams?: LocalParams
|
|
23
|
+
): Promise<AnyObject | void> {
|
|
11
24
|
const ACTION = "update";
|
|
12
25
|
const start = Date.now();
|
|
13
26
|
try {
|
|
14
27
|
/** postValidate */
|
|
15
28
|
const finalDBtx = this.getFinalDBtx(localParams);
|
|
16
|
-
const wrapInTx = () =>
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
const wrapInTx = () =>
|
|
30
|
+
this.dboBuilder.getTX((_dbtx) =>
|
|
31
|
+
_dbtx[this.name]?.[ACTION]?.(filter, _newData, params, tableRules, localParams)
|
|
32
|
+
);
|
|
33
|
+
const rule = tableRules?.[ACTION];
|
|
34
|
+
if (rule?.postValidate && !finalDBtx) {
|
|
19
35
|
return wrapInTx();
|
|
20
36
|
}
|
|
21
37
|
|
|
22
38
|
let newData = _newData;
|
|
23
|
-
if(this.is_media){
|
|
39
|
+
if (this.is_media) {
|
|
24
40
|
({ newData } = await updateFile.bind(this)({ newData, filter, localParams, tableRules }));
|
|
25
41
|
}
|
|
26
42
|
|
|
27
|
-
const parsedRules = await this.parseUpdateRules(filter, params, tableRules, localParams)
|
|
43
|
+
const parsedRules = await this.parseUpdateRules(filter, params, tableRules, localParams);
|
|
28
44
|
if (localParams?.testRule) {
|
|
29
45
|
return parsedRules;
|
|
30
46
|
}
|
|
@@ -33,25 +49,34 @@ export async function update(this: TableHandler, filter: Filter, _newData: AnyOb
|
|
|
33
49
|
throw "no update data provided\nEXPECTING db.table.update(filter, updateData, options)";
|
|
34
50
|
}
|
|
35
51
|
|
|
36
|
-
const { fields, validateRow, forcedData,
|
|
37
|
-
|
|
52
|
+
const { fields, validateRow, forcedData, returningFields, forcedFilter, filterFields } =
|
|
53
|
+
parsedRules;
|
|
54
|
+
const { removeDisallowedFields = false } = params || {};
|
|
38
55
|
const { returnQuery = false } = localParams ?? {};
|
|
39
56
|
|
|
40
57
|
if (params) {
|
|
41
|
-
const good_paramsObj: Record<keyof UpdateParams, 1> = {
|
|
58
|
+
const good_paramsObj: Record<keyof UpdateParams, 1> = {
|
|
59
|
+
returning: 1,
|
|
60
|
+
returnType: 1,
|
|
61
|
+
removeDisallowedFields: 1,
|
|
62
|
+
multi: 1,
|
|
63
|
+
};
|
|
42
64
|
const good_params = Object.keys(good_paramsObj);
|
|
43
|
-
const bad_params = Object.keys(params).filter(k => !good_params.includes(k));
|
|
44
|
-
if (bad_params && bad_params.length)
|
|
65
|
+
const bad_params = Object.keys(params).filter((k) => !good_params.includes(k));
|
|
66
|
+
if (bad_params && bad_params.length)
|
|
67
|
+
throw (
|
|
68
|
+
"Invalid params: " + bad_params.join(", ") + " \n Expecting: " + good_params.join(", ")
|
|
69
|
+
);
|
|
45
70
|
}
|
|
46
71
|
|
|
47
|
-
const { data, allowedCols } = await prepareNewData({
|
|
48
|
-
row: newData,
|
|
49
|
-
forcedData,
|
|
50
|
-
allowedFields: fields,
|
|
51
|
-
tableRules,
|
|
52
|
-
|
|
72
|
+
const { data, allowedCols } = await prepareNewData({
|
|
73
|
+
row: newData,
|
|
74
|
+
forcedData,
|
|
75
|
+
allowedFields: fields,
|
|
76
|
+
tableRules,
|
|
77
|
+
removeDisallowedFields,
|
|
53
78
|
tableConfigurator: this.dboBuilder.prostgles.tableConfigurator,
|
|
54
|
-
tableHandler: this,
|
|
79
|
+
tableHandler: this,
|
|
55
80
|
});
|
|
56
81
|
|
|
57
82
|
const updateFilter = await this.prepareWhere({
|
|
@@ -60,46 +85,68 @@ export async function update(this: TableHandler, filter: Filter, _newData: AnyOb
|
|
|
60
85
|
forcedFilter,
|
|
61
86
|
filterFields,
|
|
62
87
|
localParams,
|
|
63
|
-
tableRule: tableRules
|
|
64
|
-
})
|
|
65
|
-
|
|
88
|
+
tableRule: tableRules,
|
|
89
|
+
});
|
|
90
|
+
|
|
66
91
|
/**
|
|
67
92
|
* Nested inserts
|
|
68
93
|
*/
|
|
69
94
|
const nData = { ...data };
|
|
70
95
|
const nestedInserts = getReferenceColumnInserts(this, nData, true);
|
|
71
96
|
const nestedInsertsResultsObj: Record<string, any> = {};
|
|
72
|
-
if(nestedInserts.length){
|
|
97
|
+
if (nestedInserts.length) {
|
|
73
98
|
const updateCount = await this.count(updateFilter.filter);
|
|
74
|
-
if(+updateCount > 1){
|
|
99
|
+
if (+updateCount > 1) {
|
|
75
100
|
throw "Cannot do a nestedInsert from an update that targets more than 1 row";
|
|
76
101
|
}
|
|
77
|
-
if(!finalDBtx){
|
|
102
|
+
if (!finalDBtx) {
|
|
78
103
|
return wrapInTx();
|
|
79
104
|
}
|
|
80
|
-
await Promise.all(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
await Promise.all(
|
|
106
|
+
nestedInserts.map(async (nestedInsert) => {
|
|
107
|
+
const nesedTableHandler = finalDBtx[nestedInsert.tableName] as TableHandler | undefined;
|
|
108
|
+
if (!nesedTableHandler)
|
|
109
|
+
throw `nestedInsert Tablehandler not found for ${nestedInsert.tableName}`;
|
|
110
|
+
const refTableRules = !localParams
|
|
111
|
+
? undefined
|
|
112
|
+
: await getInsertTableRules(this, nestedInsert.tableName, localParams);
|
|
113
|
+
const nestedLocalParams: LocalParams = {
|
|
114
|
+
...localParams,
|
|
115
|
+
nestedInsert: {
|
|
116
|
+
depth: 1,
|
|
117
|
+
previousData: nData,
|
|
118
|
+
previousTable: this.name,
|
|
119
|
+
referencingColumn: nestedInsert.col,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
const nestedInsertResult = await nesedTableHandler.insert(
|
|
123
|
+
nestedInsert.data,
|
|
124
|
+
{ returning: "*" },
|
|
125
|
+
undefined,
|
|
126
|
+
refTableRules,
|
|
127
|
+
nestedLocalParams
|
|
128
|
+
);
|
|
129
|
+
nestedInsertsResultsObj[nestedInsert.col] = nestedInsertResult;
|
|
87
130
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
131
|
+
nData[nestedInsert.col] = nestedInsertResult[nestedInsert.fcol];
|
|
132
|
+
return {
|
|
133
|
+
...nestedInsert,
|
|
134
|
+
result: nestedInsertResult,
|
|
135
|
+
};
|
|
136
|
+
})
|
|
137
|
+
);
|
|
94
138
|
}
|
|
95
139
|
|
|
96
|
-
|
|
97
|
-
|
|
140
|
+
let query = (
|
|
141
|
+
await this.dataValidator.parse({
|
|
142
|
+
command: "update",
|
|
143
|
+
rows: [nData],
|
|
144
|
+
allowedCols,
|
|
145
|
+
dbTx: this.getFinalDbo(localParams),
|
|
146
|
+
validationOptions: { validate: validateRow, localParams },
|
|
147
|
+
})
|
|
148
|
+
).getQuery();
|
|
98
149
|
query += "\n" + updateFilter.where;
|
|
99
|
-
if (onConflict === "DoNothing") query += " ON CONFLICT DO NOTHING ";
|
|
100
|
-
if(onConflict === "DoUpdate"){
|
|
101
|
-
throw "onConflict 'DoUpdate' not possible for an update";
|
|
102
|
-
}
|
|
103
150
|
const queryWithoutUserRLS = query;
|
|
104
151
|
query = withUserRLS(localParams, query);
|
|
105
152
|
|
|
@@ -115,12 +162,23 @@ export async function update(this: TableHandler, filter: Filter, _newData: AnyOb
|
|
|
115
162
|
returningFields,
|
|
116
163
|
rule,
|
|
117
164
|
type: "update",
|
|
118
|
-
nestedInsertsResultsObj
|
|
165
|
+
nestedInsertsResultsObj,
|
|
166
|
+
});
|
|
167
|
+
await this._log({
|
|
168
|
+
command: "update",
|
|
169
|
+
localParams,
|
|
170
|
+
data: { filter, _newData, params },
|
|
171
|
+
duration: Date.now() - start,
|
|
119
172
|
});
|
|
120
|
-
await this._log({ command: "update", localParams, data: { filter, _newData, params }, duration: Date.now() - start });
|
|
121
173
|
return result;
|
|
122
174
|
} catch (e) {
|
|
123
|
-
await this._log({
|
|
175
|
+
await this._log({
|
|
176
|
+
command: "update",
|
|
177
|
+
localParams,
|
|
178
|
+
data: { filter, _newData, params },
|
|
179
|
+
duration: Date.now() - start,
|
|
180
|
+
error: getErrorAsObject(e),
|
|
181
|
+
});
|
|
124
182
|
throw getSerializedClientErrorFromPGError(e, { type: "tableMethod", localParams, view: this });
|
|
125
183
|
}
|
|
126
|
-
}
|
|
184
|
+
}
|
|
@@ -353,7 +353,7 @@ export class ViewHandler {
|
|
|
353
353
|
*/
|
|
354
354
|
prepareWhere = prepareWhere.bind(this);
|
|
355
355
|
|
|
356
|
-
intersectColumns(allowedFields: FieldFilter, dissallowedFields: FieldFilter,
|
|
356
|
+
intersectColumns(allowedFields: FieldFilter, dissallowedFields: FieldFilter, removeDisallowedFields = false): string[] {
|
|
357
357
|
let result: string[] = [];
|
|
358
358
|
if (allowedFields) {
|
|
359
359
|
result = this.parseFieldFilter(allowedFields);
|
|
@@ -361,7 +361,7 @@ export class ViewHandler {
|
|
|
361
361
|
if (dissallowedFields) {
|
|
362
362
|
const _dissalowed = this.parseFieldFilter(dissallowedFields);
|
|
363
363
|
|
|
364
|
-
if (!
|
|
364
|
+
if (!removeDisallowedFields) {
|
|
365
365
|
|
|
366
366
|
throw `dissallowed/invalid field found for ${this.name}: `
|
|
367
367
|
}
|
|
@@ -136,7 +136,7 @@ export async function parseUpdateRules(
|
|
|
136
136
|
forcedData: undefined,
|
|
137
137
|
allowedFields: "*",
|
|
138
138
|
tableRules,
|
|
139
|
-
|
|
139
|
+
removeDisallowedFields: false,
|
|
140
140
|
tableConfigurator: this.dboBuilder.prostgles.tableConfigurator,
|
|
141
141
|
tableHandler: this,
|
|
142
142
|
});
|
package/lib/Logging.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject } from "prostgles-types";
|
|
1
|
+
import { AnyObject, ClientSchema } from "prostgles-types";
|
|
2
2
|
import { LocalParams } from "./DboBuilder/DboBuilder";
|
|
3
3
|
import { TableHandler } from "./DboBuilder/TableHandler/TableHandler";
|
|
4
4
|
|
|
@@ -93,7 +93,7 @@ export namespace EventTypes {
|
|
|
93
93
|
| { command: "login"; }
|
|
94
94
|
);
|
|
95
95
|
|
|
96
|
-
export type Debug = DebugInfo & {
|
|
96
|
+
export type Debug = DebugInfo & ({
|
|
97
97
|
type: "debug";
|
|
98
98
|
command:
|
|
99
99
|
| "initFileTable"
|
|
@@ -112,7 +112,11 @@ export namespace EventTypes {
|
|
|
112
112
|
| "DboBuilder.getTablesForSchemaPostgresSQL"
|
|
113
113
|
| "PubSubManager.create"
|
|
114
114
|
data?: AnyObject;
|
|
115
|
-
}
|
|
115
|
+
} | {
|
|
116
|
+
type: "debug";
|
|
117
|
+
command: "pushSocketSchema";
|
|
118
|
+
data: { socketId: string, clientSchema: ClientSchema; }
|
|
119
|
+
})
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
export type EventInfo =
|