prostgles-server 2.0.200 → 2.0.203
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DboBuilder/delete.d.ts +5 -0
- package/dist/DboBuilder/delete.d.ts.map +1 -0
- package/dist/DboBuilder/delete.js +121 -0
- package/dist/DboBuilder/delete.js.map +1 -0
- package/dist/DboBuilder/insert.d.ts.map +1 -1
- package/dist/DboBuilder/insert.js +0 -4
- package/dist/DboBuilder/insert.js.map +1 -1
- package/dist/DboBuilder/insertDataParse.d.ts.map +1 -1
- package/dist/DboBuilder/insertDataParse.js +2 -43
- package/dist/DboBuilder/insertDataParse.js.map +1 -1
- package/dist/DboBuilder/update.d.ts +5 -0
- package/dist/DboBuilder/update.d.ts.map +1 -0
- package/dist/DboBuilder/update.js +114 -0
- package/dist/DboBuilder/update.js.map +1 -0
- package/dist/DboBuilder/uploadFile.d.ts +6 -0
- package/dist/DboBuilder/uploadFile.d.ts.map +1 -0
- package/dist/DboBuilder/uploadFile.js +48 -0
- package/dist/DboBuilder/uploadFile.js.map +1 -0
- package/dist/DboBuilder.d.ts +4 -2
- package/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +12 -174
- package/dist/DboBuilder.js.map +1 -1
- package/dist/FileManager.d.ts.map +1 -1
- package/dist/FileManager.js +2 -0
- package/dist/FileManager.js.map +1 -1
- package/dist/PubSubManager.d.ts +2 -4
- package/dist/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager.js +12 -7
- package/dist/PubSubManager.js.map +1 -1
- package/dist/QueryBuilder.d.ts +5 -1
- package/dist/QueryBuilder.d.ts.map +1 -1
- package/lib/DboBuilder/delete.d.ts +5 -0
- package/lib/DboBuilder/delete.d.ts.map +1 -0
- package/lib/DboBuilder/delete.js +120 -0
- package/lib/DboBuilder/delete.ts +127 -0
- package/lib/DboBuilder/insert.d.ts.map +1 -1
- package/lib/DboBuilder/insert.js +0 -4
- package/lib/DboBuilder/insert.ts +0 -4
- package/lib/DboBuilder/insertDataParse.d.ts.map +1 -1
- package/lib/DboBuilder/insertDataParse.js +2 -43
- package/lib/DboBuilder/insertDataParse.ts +2 -46
- package/lib/DboBuilder/update.d.ts +5 -0
- package/lib/DboBuilder/update.d.ts.map +1 -0
- package/lib/DboBuilder/update.js +113 -0
- package/lib/DboBuilder/update.ts +129 -0
- package/lib/DboBuilder/uploadFile.d.ts +6 -0
- package/lib/DboBuilder/uploadFile.d.ts.map +1 -0
- package/lib/DboBuilder/uploadFile.js +47 -0
- package/lib/DboBuilder/uploadFile.ts +50 -0
- package/lib/DboBuilder.d.ts +4 -2
- package/lib/DboBuilder.d.ts.map +1 -1
- package/lib/DboBuilder.js +12 -174
- package/lib/DboBuilder.ts +16 -200
- package/lib/FileManager.d.ts.map +1 -1
- package/lib/FileManager.js +2 -0
- package/lib/FileManager.ts +1 -0
- package/lib/PubSubManager.d.ts +2 -4
- package/lib/PubSubManager.d.ts.map +1 -1
- package/lib/PubSubManager.js +12 -7
- package/lib/PubSubManager.ts +16 -10
- package/package.json +2 -2
- package/tests/client/PID.txt +1 -1
- package/tests/isomorphic_queries.d.ts.map +1 -1
- package/tests/isomorphic_queries.js +33 -1
- package/tests/isomorphic_queries.ts +39 -2
- package/tests/server/package-lock.json +3 -3
package/lib/DboBuilder.js
CHANGED
|
@@ -52,6 +52,8 @@ const QueryBuilder_1 = require("./QueryBuilder");
|
|
|
52
52
|
const PubSubManager_1 = require("./PubSubManager");
|
|
53
53
|
const insertDataParse_1 = require("./DboBuilder/insertDataParse");
|
|
54
54
|
const insert_1 = require("./DboBuilder/insert");
|
|
55
|
+
const update_1 = require("./DboBuilder/update");
|
|
56
|
+
const delete_1 = require("./DboBuilder/delete");
|
|
55
57
|
const Filtering_1 = require("./Filtering");
|
|
56
58
|
exports.pgp = pgPromise({
|
|
57
59
|
promiseLib: Bluebird
|
|
@@ -127,10 +129,15 @@ exports.makeErr = makeErr;
|
|
|
127
129
|
exports.EXISTS_KEYS = ["$exists", "$notExists", "$existsJoined", "$notExistsJoined"];
|
|
128
130
|
const FILTER_FUNCS = QueryBuilder_1.FUNCTIONS.filter(f => f.canBeUsedForFilter);
|
|
129
131
|
function parseError(e) {
|
|
130
|
-
// console.trace("INTERNAL ERROR: ", e);
|
|
131
132
|
let res = e instanceof Error ? e.message : (!Object.keys(e || {}).length ? e : (e && e.toString) ? e.toString() : e);
|
|
132
|
-
if (isPlainObject(e))
|
|
133
|
-
|
|
133
|
+
if (isPlainObject(e)) {
|
|
134
|
+
if (typeof e.err === "string") {
|
|
135
|
+
res = e.err;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
res = JSON.stringify(e, null, 2);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
134
141
|
return res;
|
|
135
142
|
}
|
|
136
143
|
exports.parseError = parseError;
|
|
@@ -1676,76 +1683,7 @@ class TableHandler extends ViewHandler {
|
|
|
1676
1683
|
};
|
|
1677
1684
|
}
|
|
1678
1685
|
async update(filter, newData, params, tableRules, localParams) {
|
|
1679
|
-
|
|
1680
|
-
const parsedRules = await this.parseUpdateRules(filter, newData, params, tableRules, localParams);
|
|
1681
|
-
if (localParams?.testRule) {
|
|
1682
|
-
return parsedRules;
|
|
1683
|
-
}
|
|
1684
|
-
const { fields, validateRow, forcedData, finalUpdateFilter, returningFields, forcedFilter, filterFields } = parsedRules;
|
|
1685
|
-
let { returning, multi = true, onConflictDoNothing = false, fixIssues = false } = params || {};
|
|
1686
|
-
const { returnQuery = false } = localParams ?? {};
|
|
1687
|
-
if (params) {
|
|
1688
|
-
const good_params = ["returning", "multi", "onConflictDoNothing", "fixIssues"];
|
|
1689
|
-
const bad_params = Object.keys(params).filter(k => !good_params.includes(k));
|
|
1690
|
-
if (bad_params && bad_params.length)
|
|
1691
|
-
throw "Invalid params: " + bad_params.join(", ") + " \n Expecting: " + good_params.join(", ");
|
|
1692
|
-
}
|
|
1693
|
-
const { data, allowedCols } = this.validateNewData({ row: newData, forcedData, allowedFields: fields, tableRules, fixIssues });
|
|
1694
|
-
/* Patch data */
|
|
1695
|
-
let patchedTextData = [];
|
|
1696
|
-
this.columns.map(c => {
|
|
1697
|
-
const d = data[c.name];
|
|
1698
|
-
if (c.data_type === "text" && d && isPlainObject(d) && !["from", "to"].find(key => typeof d[key] !== "number")) {
|
|
1699
|
-
const unrecProps = Object.keys(d).filter(k => !["from", "to", "text", "md5"].includes(k));
|
|
1700
|
-
if (unrecProps.length)
|
|
1701
|
-
throw "Unrecognised params in textPatch field: " + unrecProps.join(", ");
|
|
1702
|
-
patchedTextData.push({ ...d, fieldName: c.name });
|
|
1703
|
-
}
|
|
1704
|
-
});
|
|
1705
|
-
if (patchedTextData && patchedTextData.length) {
|
|
1706
|
-
if (tableRules && !tableRules.select)
|
|
1707
|
-
throw "Select needs to be permitted to patch data";
|
|
1708
|
-
const rows = await this.find(filter, { select: patchedTextData.reduce((a, v) => ({ ...a, [v.fieldName]: 1 }), {}) }, undefined, tableRules);
|
|
1709
|
-
if (rows.length !== 1) {
|
|
1710
|
-
throw "Cannot patch data within a filter that affects more/less than 1 row";
|
|
1711
|
-
}
|
|
1712
|
-
patchedTextData.map(p => {
|
|
1713
|
-
data[p.fieldName] = (0, prostgles_types_1.unpatchText)(rows[0][p.fieldName], p);
|
|
1714
|
-
});
|
|
1715
|
-
// https://w3resource.com/PostgreSQL/overlay-function.p hp
|
|
1716
|
-
// overlay(coalesce(status, '') placing 'hom' from 2 for 0)
|
|
1717
|
-
}
|
|
1718
|
-
let nData = { ...data };
|
|
1719
|
-
// if(tableRules && tableRules.update && tableRules?.update?.validate){
|
|
1720
|
-
// nData = await tableRules.update.validate(nData);
|
|
1721
|
-
// }
|
|
1722
|
-
let query = await this.colSet.getUpdateQuery(nData, allowedCols, validateRow); //pgp.helpers.update(nData, columnSet) + " ";
|
|
1723
|
-
query += (await this.prepareWhere({
|
|
1724
|
-
filter,
|
|
1725
|
-
forcedFilter,
|
|
1726
|
-
filterFields,
|
|
1727
|
-
localParams,
|
|
1728
|
-
tableRule: tableRules
|
|
1729
|
-
})).where;
|
|
1730
|
-
if (onConflictDoNothing)
|
|
1731
|
-
query += " ON CONFLICT DO NOTHING ";
|
|
1732
|
-
let qType = "none";
|
|
1733
|
-
if (returning) {
|
|
1734
|
-
qType = multi ? "any" : "one";
|
|
1735
|
-
query += this.makeReturnQuery(await this.prepareReturning(returning, this.parseFieldFilter(returningFields)));
|
|
1736
|
-
}
|
|
1737
|
-
if (returnQuery)
|
|
1738
|
-
return query;
|
|
1739
|
-
if (this.t) {
|
|
1740
|
-
return this.t[qType](query).catch((err) => makeErr(err, localParams, this, fields));
|
|
1741
|
-
}
|
|
1742
|
-
return this.db.tx(t => t[qType](query)).catch(err => makeErr(err, localParams, this, fields));
|
|
1743
|
-
}
|
|
1744
|
-
catch (e) {
|
|
1745
|
-
if (localParams && localParams.testRule)
|
|
1746
|
-
throw e;
|
|
1747
|
-
throw { err: parseError(e), msg: `Issue with dbo.${this.name}.update(${JSON.stringify(filter || {}, null, 2)}, ${JSON.stringify(newData || {}, null, 2)}, ${JSON.stringify(params || {}, null, 2)})` };
|
|
1748
|
-
}
|
|
1686
|
+
return update_1.update.bind(this)(filter, newData, params, tableRules, localParams);
|
|
1749
1687
|
}
|
|
1750
1688
|
;
|
|
1751
1689
|
validateNewData({ row, forcedData, allowedFields, tableRules, fixIssues = false }) {
|
|
@@ -1779,105 +1717,7 @@ class TableHandler extends ViewHandler {
|
|
|
1779
1717
|
return "";
|
|
1780
1718
|
}
|
|
1781
1719
|
async delete(filter, params, param3_unused, table_rules, localParams) {
|
|
1782
|
-
|
|
1783
|
-
const { returning } = params || {};
|
|
1784
|
-
filter = filter || {};
|
|
1785
|
-
this.checkFilter(filter);
|
|
1786
|
-
// table_rules = table_rules || {};
|
|
1787
|
-
let forcedFilter = {}, filterFields = "*", returningFields = "*", validate;
|
|
1788
|
-
const { testRule = false, returnQuery = false } = localParams || {};
|
|
1789
|
-
if (table_rules) {
|
|
1790
|
-
if (!table_rules.delete)
|
|
1791
|
-
throw "delete rules missing";
|
|
1792
|
-
forcedFilter = table_rules.delete.forcedFilter;
|
|
1793
|
-
filterFields = table_rules.delete.filterFields;
|
|
1794
|
-
returningFields = table_rules.delete.returningFields;
|
|
1795
|
-
validate = table_rules.delete.validate;
|
|
1796
|
-
if (!returningFields)
|
|
1797
|
-
returningFields = (0, utils_1.get)(table_rules, "select.fields");
|
|
1798
|
-
if (!returningFields)
|
|
1799
|
-
returningFields = (0, utils_1.get)(table_rules, "delete.filterFields");
|
|
1800
|
-
if (!filterFields)
|
|
1801
|
-
throw ` Invalid delete rule for ${this.name}. filterFields missing `;
|
|
1802
|
-
/* Safely test publish rules */
|
|
1803
|
-
if (testRule) {
|
|
1804
|
-
await this.validateViewRules({ filterFields, returningFields, forcedFilter, rule: "delete" });
|
|
1805
|
-
return true;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
if (params) {
|
|
1809
|
-
const good_params = ["returning"];
|
|
1810
|
-
const bad_params = Object.keys(params).filter(k => !good_params.includes(k));
|
|
1811
|
-
if (bad_params && bad_params.length)
|
|
1812
|
-
throw "Invalid params: " + bad_params.join(", ") + " \n Expecting: " + good_params.join(", ");
|
|
1813
|
-
}
|
|
1814
|
-
let queryType = 'none';
|
|
1815
|
-
let _query = "DELETE FROM " + this.escapedName;
|
|
1816
|
-
const filterOpts = (await this.prepareWhere({
|
|
1817
|
-
filter,
|
|
1818
|
-
forcedFilter,
|
|
1819
|
-
filterFields,
|
|
1820
|
-
localParams,
|
|
1821
|
-
tableRule: table_rules
|
|
1822
|
-
}));
|
|
1823
|
-
_query += filterOpts.where;
|
|
1824
|
-
if (validate) {
|
|
1825
|
-
const _filter = filterOpts.filter;
|
|
1826
|
-
await validate(_filter);
|
|
1827
|
-
}
|
|
1828
|
-
let returningQuery = "";
|
|
1829
|
-
if (returning) {
|
|
1830
|
-
queryType = "any";
|
|
1831
|
-
if (!returningFields) {
|
|
1832
|
-
throw "Returning dissallowed";
|
|
1833
|
-
}
|
|
1834
|
-
returningQuery = this.makeReturnQuery(await this.prepareReturning(returning, this.parseFieldFilter(returningFields)));
|
|
1835
|
-
_query += returningQuery;
|
|
1836
|
-
}
|
|
1837
|
-
if (returnQuery)
|
|
1838
|
-
return _query;
|
|
1839
|
-
/**
|
|
1840
|
-
* Delete file
|
|
1841
|
-
*/
|
|
1842
|
-
const dbHandler = (this.t || this.db);
|
|
1843
|
-
if (this.is_media && this.dboBuilder.prostgles.fileManager) {
|
|
1844
|
-
if (this.dboBuilder.prostgles.opts.fileTable?.delayedDelete) {
|
|
1845
|
-
return dbHandler[queryType](`UPDATE ${(0, prostgles_types_1.asName)(this.name)} SET deleted = now() ${filterOpts.where} ${returningQuery};`);
|
|
1846
|
-
}
|
|
1847
|
-
else {
|
|
1848
|
-
const txDelete = async (tbl) => {
|
|
1849
|
-
if (!tbl.t)
|
|
1850
|
-
throw new Error("Missing transaction object t");
|
|
1851
|
-
const files = await this.find(filterOpts.filter);
|
|
1852
|
-
for await (const file of files) {
|
|
1853
|
-
await tbl.dboBuilder.prostgles.fileManager?.deleteFile(file.name);
|
|
1854
|
-
await tbl.t?.any(`DELETE FROM ${(0, prostgles_types_1.asName)(this.name)} WHERE id = ` + "${id}", file);
|
|
1855
|
-
}
|
|
1856
|
-
if (returning) {
|
|
1857
|
-
return files.map(f => (0, PubSubManager_1.pickKeys)(f, ["id", "name"]));
|
|
1858
|
-
}
|
|
1859
|
-
};
|
|
1860
|
-
if (localParams?.dbTX) {
|
|
1861
|
-
return txDelete(localParams.dbTX[this.name]);
|
|
1862
|
-
}
|
|
1863
|
-
else if (this.t) {
|
|
1864
|
-
return txDelete(this);
|
|
1865
|
-
}
|
|
1866
|
-
else {
|
|
1867
|
-
return this.dboBuilder.getTX(tx => {
|
|
1868
|
-
return txDelete(tx[this.name]);
|
|
1869
|
-
});
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
return dbHandler[queryType](_query).catch((err) => makeErr(err, localParams));
|
|
1874
|
-
}
|
|
1875
|
-
catch (e) {
|
|
1876
|
-
// console.trace(e)
|
|
1877
|
-
if (localParams && localParams.testRule)
|
|
1878
|
-
throw e;
|
|
1879
|
-
throw { err: parseError(e), msg: `Issue with dbo.${this.name}.delete(${JSON.stringify(filter || {}, null, 2)}, ${JSON.stringify(params || {}, null, 2)})` };
|
|
1880
|
-
}
|
|
1720
|
+
return delete_1._delete.bind(this)(filter, params, param3_unused, table_rules, localParams);
|
|
1881
1721
|
}
|
|
1882
1722
|
;
|
|
1883
1723
|
remove(filter, params, param3_unused, tableRules, localParams) {
|
|
@@ -2020,8 +1860,6 @@ class DboBuilder {
|
|
|
2020
1860
|
if (this.prostgles.isSuperUser) {
|
|
2021
1861
|
this._pubSubManager = await PubSubManager_1.PubSubManager.create({
|
|
2022
1862
|
dboBuilder: this,
|
|
2023
|
-
db: this.db,
|
|
2024
|
-
dbo: this.dbo,
|
|
2025
1863
|
onSchemaChange
|
|
2026
1864
|
});
|
|
2027
1865
|
}
|
package/lib/DboBuilder.ts
CHANGED
|
@@ -40,6 +40,8 @@ export type Media = {
|
|
|
40
40
|
"name"?: string;
|
|
41
41
|
"original_name"?: string;
|
|
42
42
|
"etag"?: string;
|
|
43
|
+
deleted?: string | null;
|
|
44
|
+
deleted_from_storage?: string | null;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export type TxCB = {
|
|
@@ -88,6 +90,8 @@ import {
|
|
|
88
90
|
import { PubSubManager, asValue, BasicCallback, pickKeys, omitKeys } from "./PubSubManager";
|
|
89
91
|
import { insertDataParse } from "./DboBuilder/insertDataParse";
|
|
90
92
|
import { insert } from "./DboBuilder/insert";
|
|
93
|
+
import { update } from "./DboBuilder/update";
|
|
94
|
+
import { _delete } from "./DboBuilder/delete";
|
|
91
95
|
|
|
92
96
|
import { parseFilterItem } from "./Filtering";
|
|
93
97
|
|
|
@@ -215,7 +219,7 @@ export type Aggregation = {
|
|
|
215
219
|
getQuery: (alias: string) => string;
|
|
216
220
|
};
|
|
217
221
|
|
|
218
|
-
export type Filter =
|
|
222
|
+
export type Filter = AnyObject | { $and: Filter[] } | { $or: Filter[] };
|
|
219
223
|
|
|
220
224
|
type SelectFunc = {
|
|
221
225
|
alias: string;
|
|
@@ -378,9 +382,14 @@ const FILTER_FUNCS = FUNCTIONS.filter(f => f.canBeUsedForFilter);
|
|
|
378
382
|
|
|
379
383
|
export function parseError(e: any){
|
|
380
384
|
|
|
381
|
-
// console.trace("INTERNAL ERROR: ", e);
|
|
382
385
|
let res = e instanceof Error? e.message : (!Object.keys(e || {}).length? e : (e && e.toString)? e.toString() : e);
|
|
383
|
-
if(isPlainObject(e))
|
|
386
|
+
if(isPlainObject(e)) {
|
|
387
|
+
if(typeof e.err === "string"){
|
|
388
|
+
res = e.err;
|
|
389
|
+
} else {
|
|
390
|
+
res = JSON.stringify(e, null, 2)
|
|
391
|
+
}
|
|
392
|
+
}
|
|
384
393
|
return res;
|
|
385
394
|
}
|
|
386
395
|
|
|
@@ -2223,92 +2232,7 @@ export class TableHandler extends ViewHandler {
|
|
|
2223
2232
|
}
|
|
2224
2233
|
|
|
2225
2234
|
async update(filter: Filter, newData: AnyObject, params?: UpdateParams, tableRules?: TableRule, localParams?: LocalParams): Promise<AnyObject | void>{
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
const parsedRules = await this.parseUpdateRules(filter, newData, params, tableRules, localParams)
|
|
2229
|
-
if(localParams?.testRule){
|
|
2230
|
-
return parsedRules;
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
const { fields, validateRow, forcedData, finalUpdateFilter, returningFields, forcedFilter, filterFields } = parsedRules;
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
let { returning, multi = true, onConflictDoNothing = false, fixIssues = false } = params || {};
|
|
2237
|
-
const { returnQuery = false } = localParams ?? {};
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
if(params){
|
|
2241
|
-
const good_params = ["returning", "multi", "onConflictDoNothing", "fixIssues"];
|
|
2242
|
-
const bad_params = Object.keys(params).filter(k => !good_params.includes(k));
|
|
2243
|
-
if(bad_params && bad_params.length) throw "Invalid params: " + bad_params.join(", ") + " \n Expecting: " + good_params.join(", ");
|
|
2244
|
-
}
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
const { data, allowedCols } = this.validateNewData({ row: newData, forcedData, allowedFields: fields, tableRules, fixIssues });
|
|
2248
|
-
|
|
2249
|
-
/* Patch data */
|
|
2250
|
-
let patchedTextData: {
|
|
2251
|
-
fieldName: string;
|
|
2252
|
-
from: number;
|
|
2253
|
-
to: number;
|
|
2254
|
-
text: string;
|
|
2255
|
-
md5: string
|
|
2256
|
-
}[] = [];
|
|
2257
|
-
this.columns.map(c => {
|
|
2258
|
-
const d = data[c.name];
|
|
2259
|
-
if(c.data_type === "text" && d && isPlainObject(d) && !["from", "to"].find(key => typeof d[key] !== "number")){
|
|
2260
|
-
const unrecProps = Object.keys(d).filter(k => !["from", "to", "text", "md5"].includes(k));
|
|
2261
|
-
if(unrecProps.length) throw "Unrecognised params in textPatch field: " + unrecProps.join(", ");
|
|
2262
|
-
patchedTextData.push({ ...d, fieldName: c.name } as (typeof patchedTextData)[number]);
|
|
2263
|
-
}
|
|
2264
|
-
});
|
|
2265
|
-
|
|
2266
|
-
if(patchedTextData && patchedTextData.length){
|
|
2267
|
-
if(tableRules && !tableRules.select) throw "Select needs to be permitted to patch data";
|
|
2268
|
-
const rows = await this.find(filter, { select: patchedTextData.reduce((a, v) => ({ ...a, [v.fieldName]: 1 }), {}) }, undefined, tableRules);
|
|
2269
|
-
|
|
2270
|
-
if(rows.length !== 1) {
|
|
2271
|
-
throw "Cannot patch data within a filter that affects more/less than 1 row";
|
|
2272
|
-
}
|
|
2273
|
-
patchedTextData.map(p => {
|
|
2274
|
-
data[p.fieldName] = unpatchText(rows[0][p.fieldName], p);
|
|
2275
|
-
})
|
|
2276
|
-
|
|
2277
|
-
// https://w3resource.com/PostgreSQL/overlay-function.p hp
|
|
2278
|
-
// overlay(coalesce(status, '') placing 'hom' from 2 for 0)
|
|
2279
|
-
}
|
|
2280
|
-
|
|
2281
|
-
let nData = { ...data };
|
|
2282
|
-
// if(tableRules && tableRules.update && tableRules?.update?.validate){
|
|
2283
|
-
// nData = await tableRules.update.validate(nData);
|
|
2284
|
-
// }
|
|
2285
|
-
|
|
2286
|
-
let query = await this.colSet.getUpdateQuery(nData, allowedCols, validateRow) //pgp.helpers.update(nData, columnSet) + " ";
|
|
2287
|
-
query += (await this.prepareWhere({
|
|
2288
|
-
filter,
|
|
2289
|
-
forcedFilter,
|
|
2290
|
-
filterFields,
|
|
2291
|
-
localParams,
|
|
2292
|
-
tableRule: tableRules
|
|
2293
|
-
})).where;
|
|
2294
|
-
if(onConflictDoNothing) query += " ON CONFLICT DO NOTHING ";
|
|
2295
|
-
|
|
2296
|
-
let qType = "none";
|
|
2297
|
-
if(returning){
|
|
2298
|
-
qType = multi? "any" : "one";
|
|
2299
|
-
query += this.makeReturnQuery(await this.prepareReturning(returning, this.parseFieldFilter(returningFields)));
|
|
2300
|
-
}
|
|
2301
|
-
|
|
2302
|
-
if(returnQuery) return query as unknown as void;
|
|
2303
|
-
|
|
2304
|
-
if(this.t){
|
|
2305
|
-
return (this.t as any)[qType](query).catch((err: any) => makeErr(err, localParams, this, fields));
|
|
2306
|
-
}
|
|
2307
|
-
return this.db.tx(t => (t as any)[qType](query)).catch(err => makeErr(err, localParams, this, fields));
|
|
2308
|
-
} catch(e){
|
|
2309
|
-
if(localParams && localParams.testRule) throw e;
|
|
2310
|
-
throw { err: parseError(e), msg: `Issue with dbo.${this.name}.update(${JSON.stringify(filter || {}, null, 2)}, ${JSON.stringify(newData || {}, null, 2)}, ${JSON.stringify(params || {}, null, 2)})` };
|
|
2311
|
-
}
|
|
2235
|
+
return update.bind(this)(filter, newData, params, tableRules, localParams);
|
|
2312
2236
|
};
|
|
2313
2237
|
|
|
2314
2238
|
validateNewData({ row, forcedData, allowedFields, tableRules, fixIssues = false }: ValidatedParams): { data: any; allowedCols: string[] } {
|
|
@@ -2367,115 +2291,8 @@ export class TableHandler extends ViewHandler {
|
|
|
2367
2291
|
return "";
|
|
2368
2292
|
}
|
|
2369
2293
|
|
|
2370
|
-
async delete(filter?: Filter, params?: DeleteParams, param3_unused?: undefined, table_rules?: TableRule, localParams?: LocalParams): Promise<any> {
|
|
2371
|
-
|
|
2372
|
-
const { returning } = params || {};
|
|
2373
|
-
filter = filter || {};
|
|
2374
|
-
this.checkFilter(filter);
|
|
2375
|
-
|
|
2376
|
-
// table_rules = table_rules || {};
|
|
2377
|
-
|
|
2378
|
-
let forcedFilter: AnyObject | undefined = {},
|
|
2379
|
-
filterFields: FieldFilter | undefined = "*",
|
|
2380
|
-
returningFields: FieldFilter | undefined = "*",
|
|
2381
|
-
validate: DeleteRule["validate"];
|
|
2382
|
-
|
|
2383
|
-
const { testRule = false, returnQuery = false } = localParams || {};
|
|
2384
|
-
if(table_rules){
|
|
2385
|
-
if(!table_rules.delete) throw "delete rules missing";
|
|
2386
|
-
forcedFilter = table_rules.delete.forcedFilter;
|
|
2387
|
-
filterFields = table_rules.delete.filterFields;
|
|
2388
|
-
returningFields = table_rules.delete.returningFields;
|
|
2389
|
-
validate = table_rules.delete.validate;
|
|
2390
|
-
|
|
2391
|
-
if(!returningFields) returningFields = get(table_rules, "select.fields");
|
|
2392
|
-
if(!returningFields) returningFields = get(table_rules, "delete.filterFields");
|
|
2393
|
-
|
|
2394
|
-
if(!filterFields) throw ` Invalid delete rule for ${this.name}. filterFields missing `;
|
|
2395
|
-
|
|
2396
|
-
/* Safely test publish rules */
|
|
2397
|
-
if(testRule){
|
|
2398
|
-
await this.validateViewRules({ filterFields, returningFields, forcedFilter, rule: "delete" });
|
|
2399
|
-
return true;
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
if(params){
|
|
2405
|
-
const good_params = ["returning"];
|
|
2406
|
-
const bad_params = Object.keys(params).filter(k => !good_params.includes(k));
|
|
2407
|
-
if(bad_params && bad_params.length) throw "Invalid params: " + bad_params.join(", ") + " \n Expecting: " + good_params.join(", ");
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
let queryType: keyof pgPromise.ITask<{}> = 'none';
|
|
2411
|
-
let _query = "DELETE FROM " + this.escapedName;
|
|
2412
|
-
const filterOpts = (await this.prepareWhere({
|
|
2413
|
-
filter,
|
|
2414
|
-
forcedFilter,
|
|
2415
|
-
filterFields,
|
|
2416
|
-
localParams,
|
|
2417
|
-
tableRule: table_rules
|
|
2418
|
-
}))
|
|
2419
|
-
_query += filterOpts.where;
|
|
2420
|
-
if(validate){
|
|
2421
|
-
const _filter = filterOpts.filter;
|
|
2422
|
-
await validate(_filter);
|
|
2423
|
-
}
|
|
2424
|
-
|
|
2425
|
-
let returningQuery = "";
|
|
2426
|
-
if(returning){
|
|
2427
|
-
queryType = "any";
|
|
2428
|
-
if(!returningFields) {
|
|
2429
|
-
throw "Returning dissallowed";
|
|
2430
|
-
}
|
|
2431
|
-
returningQuery = this.makeReturnQuery(await this.prepareReturning(returning, this.parseFieldFilter(returningFields)));
|
|
2432
|
-
_query += returningQuery
|
|
2433
|
-
}
|
|
2434
|
-
|
|
2435
|
-
if(returnQuery) return _query;
|
|
2436
|
-
|
|
2437
|
-
/**
|
|
2438
|
-
* Delete file
|
|
2439
|
-
*/
|
|
2440
|
-
const dbHandler = (this.t || this.db)
|
|
2441
|
-
if(this.is_media && this.dboBuilder.prostgles.fileManager){
|
|
2442
|
-
|
|
2443
|
-
if(this.dboBuilder.prostgles.opts.fileTable?.delayedDelete){
|
|
2444
|
-
return dbHandler[queryType](`UPDATE ${asName(this.name)} SET deleted = now() ${filterOpts.where} ${returningQuery};`)
|
|
2445
|
-
} else {
|
|
2446
|
-
|
|
2447
|
-
const txDelete = async (tbl: TableHandler) => {
|
|
2448
|
-
if(!tbl.t) throw new Error("Missing transaction object t");
|
|
2449
|
-
const files = await this.find(filterOpts.filter);
|
|
2450
|
-
for await(const file of files){
|
|
2451
|
-
await tbl.dboBuilder.prostgles.fileManager?.deleteFile(file.name);
|
|
2452
|
-
await tbl.t?.any(`DELETE FROM ${asName(this.name)} WHERE id = ` + "${id}", file);
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
if(returning){
|
|
2456
|
-
return files.map(f => pickKeys(f, ["id", "name"]));
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
if(localParams?.dbTX){
|
|
2461
|
-
return txDelete(localParams.dbTX[this.name] as TableHandler)
|
|
2462
|
-
} else if(this.t) {
|
|
2463
|
-
return txDelete(this)
|
|
2464
|
-
} else {
|
|
2465
|
-
|
|
2466
|
-
return this.dboBuilder.getTX(tx => {
|
|
2467
|
-
return txDelete(tx[this.name] as any)
|
|
2468
|
-
})
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
|
|
2473
|
-
return dbHandler[queryType](_query).catch((err: any) => makeErr(err, localParams));
|
|
2474
|
-
} catch(e){
|
|
2475
|
-
// console.trace(e)
|
|
2476
|
-
if(localParams && localParams.testRule) throw e;
|
|
2477
|
-
throw { err: parseError(e), msg: `Issue with dbo.${this.name}.delete(${JSON.stringify(filter || {}, null, 2)}, ${JSON.stringify(params || {}, null, 2)})` };
|
|
2478
|
-
}
|
|
2294
|
+
async delete(filter?: Filter, params?: DeleteParams, param3_unused?: undefined, table_rules?: TableRule, localParams?: LocalParams): Promise<any> {
|
|
2295
|
+
return _delete.bind(this)(filter, params, param3_unused, table_rules, localParams);
|
|
2479
2296
|
};
|
|
2480
2297
|
|
|
2481
2298
|
remove(filter: Filter, params?: UpdateParams, param3_unused?: undefined, tableRules?: TableRule, localParams?: LocalParams){
|
|
@@ -2643,8 +2460,6 @@ export class DboBuilder {
|
|
|
2643
2460
|
if(this.prostgles.isSuperUser){
|
|
2644
2461
|
this._pubSubManager = await PubSubManager.create({
|
|
2645
2462
|
dboBuilder: this,
|
|
2646
|
-
db: this.db,
|
|
2647
|
-
dbo: this.dbo as unknown as DBHandlerServer,
|
|
2648
2463
|
onSchemaChange
|
|
2649
2464
|
});
|
|
2650
2465
|
} else {
|
|
@@ -2655,6 +2470,7 @@ export class DboBuilder {
|
|
|
2655
2470
|
console.trace("Could not create this._pubSubManager")
|
|
2656
2471
|
throw "Could not create this._pubSubManager";
|
|
2657
2472
|
}
|
|
2473
|
+
|
|
2658
2474
|
return this._pubSubManager;
|
|
2659
2475
|
}
|
|
2660
2476
|
|
package/lib/FileManager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileManager.d.ts","sourceRoot":"","sources":["FileManager.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,EAAE,EAAO,MAAM,SAAS,CAAC;AAMlC,OAAO,EAAE,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAkD,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAK/I,eAAO,MAAM,eAAe,SAAgB,MAAM,aAAW,QAAQ,MAAM,CAE1E,CAAA;AAED,oBAAY,YAAY,GAAG;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC;IACV;;OAEG;IACD;QAAE,MAAM,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GAC7C;QAAE,OAAO,EACL;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,GACjB;YAAE,MAAM,EAAE,MAAM,CAAA;SAAE,CAAA;KACrB,CAAA;CACN,CAAA;AAED,oBAAY,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,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AAoB,CAAC;IAAC,GAAG,EAAE,iBAAiB,CAAA;CAAE,CAwBzI,CAAA;AAGD;;;;;;;;;;;;;;;;;;;GAmBG"}
|
package/lib/FileManager.js
CHANGED
package/lib/FileManager.ts
CHANGED
package/lib/PubSubManager.d.ts
CHANGED
|
@@ -63,8 +63,6 @@ declare type AddSubscriptionParams = SubscriptionParams & {
|
|
|
63
63
|
};
|
|
64
64
|
export declare type PubSubManagerOptions = {
|
|
65
65
|
dboBuilder: DboBuilder;
|
|
66
|
-
db: DB;
|
|
67
|
-
dbo: DBHandlerServer;
|
|
68
66
|
wsChannelNamePrefix?: string;
|
|
69
67
|
pgChannelName?: string;
|
|
70
68
|
onSchemaChange?: (event: {
|
|
@@ -75,8 +73,8 @@ export declare type PubSubManagerOptions = {
|
|
|
75
73
|
export declare class PubSubManager {
|
|
76
74
|
static DELIMITER: string;
|
|
77
75
|
dboBuilder: DboBuilder;
|
|
78
|
-
db: DB;
|
|
79
|
-
dbo: DBHandlerServer;
|
|
76
|
+
get db(): DB;
|
|
77
|
+
get dbo(): DBHandlerServer;
|
|
80
78
|
_triggers?: Record<string, string[]>;
|
|
81
79
|
sockets: any;
|
|
82
80
|
subs: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PubSubManager.d.ts","sourceRoot":"","sources":["PubSubManager.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAgB,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACnH,OAAO,EAAE,EAAE,EAAe,MAAM,aAAa,CAAC;AAM9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAU,GAAG,EAAW,SAAS,EAAW,MAAM,iBAAiB,CAAC;AAEtG,OAAO,EAAE,iBAAiB,EAAY,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,C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E;IAI5G,MAAM,CAAC,kBAAkB,EAAE,IAAI,CAAC,qBAAqB,EAAE,cAAc,CAAC;IA6H5E,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG;IAepF,kBAAkB,QAAO;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,CAmBnE;IAED,oBAAoB,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,EAAE,MAAM;IAwDjE,mBAAmB,eAAsB,MAAM,sBAgB9C;IAQD,iBAAiB,wBAQhB;IAGD,aAAa,EAAE,GAAG,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAa;IAChD,UAAU,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;KAAE;CA4DpE;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAEnH;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,GAAE,OAAO,EAAO,GAAG,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAcxH"}
|
package/lib/PubSubManager.js
CHANGED
|
@@ -973,12 +973,10 @@ class PubSubManager {
|
|
|
973
973
|
`, [this.appID]);
|
|
974
974
|
};
|
|
975
975
|
this.addTriggerPool = undefined;
|
|
976
|
-
const {
|
|
977
|
-
if (!db || !dbo) {
|
|
976
|
+
const { wsChannelNamePrefix, pgChannelName, onSchemaChange, dboBuilder } = options;
|
|
977
|
+
if (!dboBuilder.db || !dboBuilder.dbo) {
|
|
978
978
|
throw 'MISSING: db_pg, db';
|
|
979
979
|
}
|
|
980
|
-
this.db = db;
|
|
981
|
-
this.dbo = dbo;
|
|
982
980
|
this.onSchemaChange = onSchemaChange;
|
|
983
981
|
this.dboBuilder = dboBuilder;
|
|
984
982
|
this.sockets = {};
|
|
@@ -987,6 +985,12 @@ class PubSubManager {
|
|
|
987
985
|
this.socketChannelPreffix = wsChannelNamePrefix || "_psqlWS_";
|
|
988
986
|
(0, exports.log)("Created PubSubManager");
|
|
989
987
|
}
|
|
988
|
+
get db() {
|
|
989
|
+
return this.dboBuilder.db;
|
|
990
|
+
}
|
|
991
|
+
get dbo() {
|
|
992
|
+
return this.dboBuilder.dbo;
|
|
993
|
+
}
|
|
990
994
|
isReady() {
|
|
991
995
|
if (!this.postgresNotifListenManager)
|
|
992
996
|
throw "this.postgresNotifListenManager missing";
|
|
@@ -1013,8 +1017,9 @@ class PubSubManager {
|
|
|
1013
1017
|
return new Promise(async (resolve, reject) => {
|
|
1014
1018
|
/* TODO: Retire subOne -> it's redundant */
|
|
1015
1019
|
// this.dbo[table_name][subOne? "findOne" : "find"](filter, params, null, table_rules)
|
|
1016
|
-
if (!this.dbo?.[table_name]?.find)
|
|
1017
|
-
throw
|
|
1020
|
+
if (!this.dbo?.[table_name]?.find) {
|
|
1021
|
+
throw new Error(`1107 this.dbo.${table_name}.find`);
|
|
1022
|
+
}
|
|
1018
1023
|
this.dbo?.[table_name]?.find?.(filter, params, undefined, table_rules)
|
|
1019
1024
|
.then(data => {
|
|
1020
1025
|
if (socket_id && this.sockets[socket_id]) {
|
|
@@ -1023,7 +1028,7 @@ class PubSubManager {
|
|
|
1023
1028
|
resolve(data);
|
|
1024
1029
|
});
|
|
1025
1030
|
/* TO DO: confirm receiving data or server will unsubscribe
|
|
1026
|
-
|
|
1031
|
+
{ data }, (cb)=> { console.log(cb) });
|
|
1027
1032
|
*/
|
|
1028
1033
|
}
|
|
1029
1034
|
else if (func) {
|