prostgles-server 4.2.179 → 4.2.181
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/README.md +48 -52
- package/dist/DBSchemaBuilder.d.ts +2 -2
- package/dist/DBSchemaBuilder.d.ts.map +1 -1
- package/dist/DBSchemaBuilder.js +34 -26
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.js +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/getColumns.d.ts.map +1 -1
- package/dist/DboBuilder/getColumns.js +41 -16
- package/dist/DboBuilder/getColumns.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.js +1 -1
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
- package/dist/Prostgles.d.ts +2 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +117 -54
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesTypes.d.ts +81 -25
- 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 +68 -60
- package/dist/initProstgles.js.map +1 -1
- package/dist/typeTests/dboTypeCheck.d.ts.map +1 -1
- package/dist/typeTests/dboTypeCheck.js +11 -11
- package/dist/typeTests/dboTypeCheck.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/documentation/METHODS.md +1467 -0
- package/documentation/SERVER.md +103 -0
- package/documentation/utils/clientTypes.ts +14415 -0
- package/documentation/utils/dist/clientTypes.d.ts +13211 -0
- package/documentation/utils/dist/clientTypes.d.ts.map +1 -0
- package/documentation/utils/dist/clientTypes.js +14417 -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 +2 -0
- package/documentation/utils/dist/generateClientDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateClientDocs.js +165 -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 +81 -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 +279 -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 +29 -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 +301 -0
- package/documentation/utils/dist/serverTypes.d.ts.map +1 -0
- package/documentation/utils/dist/serverTypes.js +341 -0
- package/documentation/utils/generateClientDocs.ts +210 -0
- package/documentation/utils/generateDocs.ts +4 -0
- package/documentation/utils/generateServerDocs.ts +84 -0
- package/documentation/utils/getResolvedTypes.ts +45 -0
- package/documentation/utils/getSerializableType.ts +489 -0
- package/documentation/utils/loadTsFile.ts +41 -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 +339 -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/DBSchemaBuilder.ts +148 -118
- 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/getColumns.ts +63 -31
- package/lib/DboBuilder/parseUpdateRules.ts +1 -1
- package/lib/Prostgles.ts +208 -143
- package/lib/ProstglesTypes.ts +134 -52
- package/lib/SyncReplication.ts +2 -2
- package/lib/initProstgles.ts +151 -118
- package/lib/typeTests/DBoGenerated.d.ts +23 -19
- package/lib/typeTests/dboTypeCheck.ts +49 -35
- package/lib/utils.ts +4 -5
- package/package.json +5 -3
- 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
package/lib/DBSchemaBuilder.ts
CHANGED
|
@@ -1,112 +1,144 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AnyObject,
|
|
3
|
+
DbJoinMaker,
|
|
4
|
+
DBSchema,
|
|
5
|
+
isObject,
|
|
6
|
+
JSONB,
|
|
7
|
+
SQLHandler,
|
|
8
|
+
TableHandler,
|
|
9
|
+
ViewHandler,
|
|
10
|
+
} from "prostgles-types";
|
|
2
11
|
import prostgles from ".";
|
|
3
12
|
import { Auth } from "./Auth/AuthTypes";
|
|
4
13
|
import { DboBuilder, escapeTSNames, postgresToTsType } from "./DboBuilder/DboBuilder";
|
|
5
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
PublishAllOrNothing,
|
|
16
|
+
PublishParams,
|
|
17
|
+
PublishTableRule,
|
|
18
|
+
PublishViewRule,
|
|
19
|
+
} from "./PublishParser/PublishParser";
|
|
6
20
|
import { getJSONBSchemaTSTypes } from "./JSONBValidation/validation";
|
|
7
21
|
import { DBHandlerServer, TableSchemaColumn, TX } from "./DboBuilder/DboBuilderTypes";
|
|
8
22
|
|
|
9
|
-
|
|
10
23
|
export const getDBSchema = (dboBuilder: DboBuilder): string => {
|
|
11
24
|
const tables: string[] = [];
|
|
12
25
|
|
|
13
26
|
const getColTypeForDBSchema = (udt_name: TableSchemaColumn["udt_name"]): string => {
|
|
14
|
-
if(udt_name === "interval"){
|
|
15
|
-
const units = [
|
|
16
|
-
|
|
17
|
-
return `{ ${units.map(u => `${u}?: number;`).join(" ")} }`;
|
|
27
|
+
if (udt_name === "interval") {
|
|
28
|
+
const units = ["years", "months", "days", "hours", "minutes", "seconds", "milliseconds"];
|
|
29
|
+
|
|
30
|
+
return `{ ${units.map((u) => `${u}?: number;`).join(" ")} }`;
|
|
18
31
|
}
|
|
19
32
|
|
|
20
33
|
return postgresToTsType(udt_name);
|
|
21
|
-
}
|
|
22
|
-
|
|
34
|
+
};
|
|
35
|
+
|
|
23
36
|
/** Tables and columns are sorted to avoid infinite loops due to changing order */
|
|
24
|
-
dboBuilder.tablesOrViews
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
dboBuilder.tablesOrViews
|
|
38
|
+
?.slice(0)
|
|
39
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
40
|
+
.forEach((tov) => {
|
|
41
|
+
const cols = tov.columns.slice(0).sort((a, b) => a.name.localeCompare(b.name));
|
|
42
|
+
const getColType = (c: (typeof cols)[number]) => {
|
|
43
|
+
let type: string =
|
|
44
|
+
(c.is_nullable ? "null | " : "") + getColTypeForDBSchema(c.udt_name) + ";";
|
|
45
|
+
const colConf = dboBuilder.prostgles.tableConfigurator?.getColumnConfig(tov.name, c.name);
|
|
46
|
+
if (colConf) {
|
|
47
|
+
if (isObject(colConf) && (colConf.jsonbSchema || colConf.jsonbSchemaType)) {
|
|
48
|
+
const schema: JSONB.JSONBSchema = colConf.jsonbSchema || {
|
|
49
|
+
...colConf,
|
|
50
|
+
type: colConf.jsonbSchemaType,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type = getJSONBSchemaTSTypes(
|
|
54
|
+
schema,
|
|
55
|
+
{ nullable: colConf.nullable },
|
|
56
|
+
" ",
|
|
57
|
+
dboBuilder.tablesOrViews ?? []
|
|
58
|
+
);
|
|
59
|
+
} else if (isObject(colConf) && "enum" in colConf) {
|
|
60
|
+
if (!colConf.enum) throw "colConf.enum missing";
|
|
61
|
+
const types = colConf.enum.map((t) => (typeof t === "number" ? t : JSON.stringify(t)));
|
|
62
|
+
if (colConf.nullable) {
|
|
63
|
+
types.unshift("null");
|
|
64
|
+
}
|
|
65
|
+
type = types.join(" | ");
|
|
40
66
|
}
|
|
41
|
-
type = types.join(" | ");
|
|
42
67
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
tables.push(`${escapeTSNames(tov.name)}: {
|
|
68
|
+
/**
|
|
69
|
+
* Columns that are nullable or have default values can be ommitted from an insert
|
|
70
|
+
* Non nullable columns with default values cannot containt null values in an insert so they must contain a valid value or be omitted
|
|
71
|
+
*/
|
|
72
|
+
return `${escapeTSNames(c.name)}${c.is_nullable || c.has_default ? "?" : ""}: ${type}`;
|
|
73
|
+
};
|
|
74
|
+
tables.push(`${escapeTSNames(tov.name)}: {
|
|
51
75
|
is_view: ${tov.is_view};
|
|
52
76
|
select: ${tov.privileges.select};
|
|
53
77
|
insert: ${tov.privileges.insert};
|
|
54
78
|
update: ${tov.privileges.update};
|
|
55
79
|
delete: ${tov.privileges.delete};
|
|
56
|
-
columns: {${cols
|
|
57
|
-
|
|
80
|
+
columns: {${cols
|
|
81
|
+
.map(
|
|
82
|
+
(c) => `
|
|
83
|
+
${getColType(c)}`
|
|
84
|
+
)
|
|
85
|
+
.join("")}
|
|
58
86
|
};
|
|
59
|
-
};\n `)
|
|
60
|
-
|
|
61
|
-
return `
|
|
62
|
-
export type
|
|
87
|
+
};\n `);
|
|
88
|
+
});
|
|
89
|
+
return `
|
|
90
|
+
export type DBGeneratedSchema = {
|
|
63
91
|
${tables.join("")}
|
|
64
92
|
}
|
|
65
93
|
`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type ServerViewHandler<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
type ServerViewHandler<
|
|
97
|
+
T extends AnyObject = AnyObject,
|
|
98
|
+
Schema extends DBSchema | void = void,
|
|
99
|
+
> = ViewHandler<T, Schema> & { is_view: boolean };
|
|
100
|
+
type ServerTableHandler<
|
|
101
|
+
T extends AnyObject = AnyObject,
|
|
102
|
+
Schema extends DBSchema | void = void,
|
|
103
|
+
> = TableHandler<T, Schema> & { is_view: boolean };
|
|
104
|
+
|
|
105
|
+
export type DBTableHandlersFromSchema<Schema = void> =
|
|
106
|
+
Schema extends DBSchema ?
|
|
107
|
+
{
|
|
108
|
+
[tov_name in keyof Schema]: Schema[tov_name]["is_view"] extends true ?
|
|
109
|
+
ServerViewHandler<Schema[tov_name]["columns"], Schema>
|
|
110
|
+
: ServerTableHandler<Schema[tov_name]["columns"], Schema>;
|
|
111
|
+
}
|
|
112
|
+
: Record<string, Partial<ServerTableHandler>>;
|
|
76
113
|
|
|
77
|
-
export type DBHandlerServerExtra<
|
|
114
|
+
export type DBHandlerServerExtra<
|
|
115
|
+
TH = Record<string, Partial<ServerTableHandler>>,
|
|
116
|
+
WithTransactions = true,
|
|
117
|
+
> = {
|
|
78
118
|
sql: SQLHandler;
|
|
79
|
-
} & Partial<DbJoinMaker> &
|
|
80
|
-
WithTransactions extends true? { tx: TX<TH> } :
|
|
81
|
-
Record<string, never>
|
|
82
|
-
);
|
|
119
|
+
} & Partial<DbJoinMaker> &
|
|
120
|
+
(WithTransactions extends true ? { tx: TX<TH> } : Record<string, never>);
|
|
83
121
|
// export type DBOFullyTyped<Schema = void> = Schema extends DBSchema? (
|
|
84
122
|
// DBTableHandlersFromSchema<Schema> & DBHandlerServerExtra<DBTableHandlersFromSchema<Schema>>
|
|
85
|
-
// ) :
|
|
123
|
+
// ) :
|
|
86
124
|
// DBHandlerServer;
|
|
87
|
-
export type DBOFullyTyped<Schema = void> = DBTableHandlersFromSchema<Schema> &
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
| PublishAllOrNothing
|
|
102
|
-
| Record<string, PublishViewRule | PublishTableRule | PublishAllOrNothing>
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
|
|
125
|
+
export type DBOFullyTyped<Schema = void> = DBTableHandlersFromSchema<Schema> &
|
|
126
|
+
DBHandlerServerExtra<DBTableHandlersFromSchema<Schema>>;
|
|
127
|
+
|
|
128
|
+
export type PublishFullyTyped<Schema = void> =
|
|
129
|
+
Schema extends DBSchema ?
|
|
130
|
+
| PublishAllOrNothing
|
|
131
|
+
| {
|
|
132
|
+
[tov_name in keyof Partial<Schema>]:
|
|
133
|
+
| PublishAllOrNothing
|
|
134
|
+
| (Schema[tov_name]["is_view"] extends true ?
|
|
135
|
+
PublishViewRule<Schema[tov_name]["columns"], Schema>
|
|
136
|
+
: PublishTableRule<Schema[tov_name]["columns"], Schema>);
|
|
137
|
+
}
|
|
138
|
+
: PublishAllOrNothing | Record<string, PublishViewRule | PublishTableRule | PublishAllOrNothing>;
|
|
106
139
|
|
|
107
140
|
/** Type checks */
|
|
108
|
-
(
|
|
109
|
-
|
|
141
|
+
() => {
|
|
110
142
|
const ddb: DBOFullyTyped = 1 as any;
|
|
111
143
|
ddb.dwad?.insert;
|
|
112
144
|
ddb.dwad?.delete;
|
|
@@ -124,102 +156,100 @@ export type PublishFullyTyped<Schema = void> = Schema extends DBSchema? (
|
|
|
124
156
|
dbConnection: 1 as any,
|
|
125
157
|
publish: async (params) => {
|
|
126
158
|
const _rows = await params.dbo.dwadwa?.find?.({});
|
|
127
|
-
|
|
128
|
-
return "*" as const
|
|
159
|
+
|
|
160
|
+
return "*" as const;
|
|
129
161
|
},
|
|
130
162
|
transactions: true,
|
|
131
163
|
onReady: ({ dbo }) => {
|
|
132
164
|
dbo.tdwa?.find!();
|
|
133
|
-
dbo.tx?.(t => {
|
|
165
|
+
dbo.tx?.((t) => {
|
|
134
166
|
t.dwa?.find!();
|
|
135
|
-
})
|
|
136
|
-
}
|
|
167
|
+
});
|
|
168
|
+
},
|
|
137
169
|
});
|
|
138
170
|
|
|
139
|
-
|
|
140
171
|
const _auth: Auth = {
|
|
141
172
|
sidKeyName: "sid_token",
|
|
142
173
|
getUser: async (sid, db, _db) => {
|
|
143
174
|
db.dwadaw?.find;
|
|
144
175
|
return 1 as any;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
176
|
+
},
|
|
177
|
+
};
|
|
148
178
|
|
|
149
179
|
type S = {
|
|
150
180
|
tbl1: {
|
|
151
181
|
columns: {
|
|
152
182
|
col1: number | null;
|
|
153
|
-
col2: string;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
183
|
+
col2: string;
|
|
184
|
+
};
|
|
185
|
+
};
|
|
156
186
|
tbl2: {
|
|
157
187
|
columns: {
|
|
158
188
|
col1: number | null;
|
|
159
|
-
col2: string;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
189
|
+
col2: string;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
};
|
|
163
193
|
|
|
164
194
|
/** Test the created schema */
|
|
165
195
|
const c: S = 1 as any;
|
|
166
196
|
const _test: DBSchema = c;
|
|
167
197
|
const dbt: DBOFullyTyped<S> = 1 as any;
|
|
168
198
|
|
|
169
|
-
dbt.tx!(t => {
|
|
199
|
+
dbt.tx!((t) => {
|
|
170
200
|
t.tbl1.delete();
|
|
171
201
|
});
|
|
172
202
|
|
|
173
203
|
const db: DBHandlerServer = 1 as any;
|
|
174
|
-
db.tx!(t => {
|
|
175
|
-
t.wadwa?.find!()
|
|
204
|
+
db.tx!((t) => {
|
|
205
|
+
t.wadwa?.find!();
|
|
176
206
|
});
|
|
177
|
-
|
|
207
|
+
|
|
178
208
|
const _publish = (): PublishFullyTyped<S> => {
|
|
179
209
|
const r = {
|
|
180
210
|
tbl1: {
|
|
181
211
|
select: {
|
|
182
|
-
fields: "*" as const,
|
|
183
|
-
forcedFilter: { col1: 32, col2: "" }
|
|
212
|
+
fields: "*" as const,
|
|
213
|
+
forcedFilter: { col1: 32, col2: "" },
|
|
184
214
|
},
|
|
185
215
|
getColumns: true,
|
|
186
216
|
getInfo: true,
|
|
187
217
|
delete: {
|
|
188
|
-
filterFields: {col1: 1}
|
|
189
|
-
}
|
|
218
|
+
filterFields: { col1: 1 },
|
|
219
|
+
},
|
|
190
220
|
},
|
|
191
221
|
tbl2: {
|
|
192
222
|
delete: {
|
|
193
223
|
filterFields: "*" as const,
|
|
194
|
-
forcedFilter: {col1: 2}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
224
|
+
forcedFilter: { col1: 2 },
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
};
|
|
198
228
|
const res: PublishFullyTyped<S> = {
|
|
199
229
|
tbl1: {
|
|
200
230
|
select: {
|
|
201
231
|
fields: "*",
|
|
202
|
-
forcedFilter: { col1: 32, col2: "" }
|
|
232
|
+
forcedFilter: { col1: 32, col2: "" },
|
|
203
233
|
},
|
|
204
234
|
getColumns: true,
|
|
205
235
|
getInfo: true,
|
|
206
236
|
delete: {
|
|
207
|
-
filterFields: { col1: 1 }
|
|
208
|
-
}
|
|
237
|
+
filterFields: { col1: 1 },
|
|
238
|
+
},
|
|
209
239
|
},
|
|
210
240
|
tbl2: {
|
|
211
241
|
delete: {
|
|
212
242
|
filterFields: "*" as const,
|
|
213
|
-
forcedFilter: { col1: 2 }
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
const _res1: PublishFullyTyped = r
|
|
218
|
-
|
|
243
|
+
forcedFilter: { col1: 2 },
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
const _res1: PublishFullyTyped = r;
|
|
248
|
+
|
|
219
249
|
const p: PublishParams<undefined> = 1 as any;
|
|
220
|
-
|
|
250
|
+
|
|
221
251
|
p.dbo.dwadaw?.find?.();
|
|
222
|
-
|
|
252
|
+
|
|
223
253
|
return res;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
254
|
+
};
|
|
255
|
+
};
|
|
@@ -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
|
+
}
|