@magda/org-tree 2.0.0-alpha.1 → 2.0.0-alpha.4

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.
@@ -103,6 +103,18 @@ return /******/ (function(modules) { // webpackBootstrap
103
103
  /* 4 */,
104
104
  /* 5 */,
105
105
  /* 6 */
106
+ /***/ (function(module, exports, __webpack_require__) {
107
+
108
+ "use strict";
109
+
110
+ Object.defineProperty(exports, "__esModule", { value: true });
111
+ const uuidRegEx = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
112
+ const isUuid = (id) => typeof id === "string" && uuidRegEx.test(id);
113
+ exports.default = isUuid;
114
+ //# sourceMappingURL=isUuid.js.map
115
+
116
+ /***/ }),
117
+ /* 7 */
106
118
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
107
119
 
108
120
  "use strict";
@@ -602,7 +614,6 @@ function getTableColumnName(columnName, tableRef = "", useLowerCaseColumnName =
602
614
 
603
615
 
604
616
  /***/ }),
605
- /* 7 */,
606
617
  /* 8 */,
607
618
  /* 9 */
608
619
  /***/ (function(module, exports, __webpack_require__) {
@@ -17850,7 +17861,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17850
17861
  };
17851
17862
  Object.defineProperty(exports, "__esModule", { value: true });
17852
17863
  exports.countTableRecord = exports.getTableRecord = exports.searchTableRecord = exports.MAX_PAGE_RECORD_NUMBER = exports.parseIntParam = exports.deleteTableRecord = exports.updateTableRecord = exports.createTableRecord = exports.getTableColumnName = exports.escapeIdentifier = exports.escapeIdentifierStr = void 0;
17853
- const sql_syntax_1 = __importStar(__webpack_require__(6));
17864
+ const sql_syntax_1 = __importStar(__webpack_require__(7));
17854
17865
  const AuthDecision_1 = __webpack_require__(11);
17855
17866
  const lodash_1 = __webpack_require__(9);
17856
17867
  const ServerError_1 = __importDefault(__webpack_require__(17));
@@ -18108,7 +18119,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
18108
18119
  Object.defineProperty(exports, "__esModule", { value: true });
18109
18120
  exports.ConciseOperand = exports.ConciseExpression = exports.ConciseRule = exports.UnconditionalFalseDecision = exports.UnconditionalTrueDecision = exports.isTrueEquivalent = void 0;
18110
18121
  const AspectQuery_1 = __webpack_require__(16);
18111
- const sql_syntax_1 = __importStar(__webpack_require__(6));
18122
+ const sql_syntax_1 = __importStar(__webpack_require__(7));
18112
18123
  class AuthDecision {
18113
18124
  constructor(hasResidualRules, residualRules, result, hasWarns = false, warns = [], unknowns) {
18114
18125
  if (typeof hasResidualRules !== "boolean") {
@@ -18369,9 +18380,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
18369
18380
  exports.NodeNotFoundError = void 0;
18370
18381
  const lodash_1 = __importDefault(__webpack_require__(9));
18371
18382
  const tsmonad_1 = __webpack_require__(15);
18372
- const sql_syntax_1 = __importStar(__webpack_require__(6));
18383
+ const sql_syntax_1 = __importStar(__webpack_require__(7));
18373
18384
  const SQLUtils_1 = __webpack_require__(10);
18374
18385
  const AuthDecision_1 = __webpack_require__(11);
18386
+ const isUuid_1 = __importDefault(__webpack_require__(6));
18375
18387
  const textTree = __webpack_require__(18);
18376
18388
  class NodeNotFoundError extends Error {}
18377
18389
 
@@ -19325,24 +19337,17 @@ class NestedSetModelQueryer {
19325
19337
  */
19326
19338
  updateNode(nodeId, nodeData, client = null) {
19327
19339
  return __awaiter(this, void 0, void 0, function* () {
19328
- if (nodeId.trim() === "") {
19329
- throw new Error("nodeId can't be empty!");
19330
- }
19331
- const sqlValues = [nodeId];
19332
- const updateFields = Object.keys(nodeData).filter(k => k !== "left" && k !== "right" && k !== "id");
19333
- if (!updateFields.length) {
19340
+ if (!isUuid_1.default(nodeId)) {
19341
+ throw new Error("nodeId is not valid UUID!");
19342
+ }
19343
+ const sqlUpdates = Object.keys(nodeData).
19344
+ filter(k => k !== "left" && k !== "right" && k !== "id").
19345
+ map(fieldName => sql_syntax_1.sqls`${SQLUtils_1.escapeIdentifier(fieldName)} = ${nodeData[fieldName]}`);
19346
+ if (!sqlUpdates.length) {
19347
+ console.log("update node parameter: ", nodeId, nodeData);
19334
19348
  throw new Error("No valid node data passed for updating.");
19335
19349
  }
19336
- const setFieldList = updateFields.
19337
- map(f => {
19338
- if (!isValidSqlIdentifier(f)) {
19339
- throw new Error(`field name: ${f} contains invalid characters!`);
19340
- }
19341
- sqlValues.push(nodeData[f]);
19342
- return `"${f}" = $${sqlValues.length}`;
19343
- }).
19344
- join(", ");
19345
- yield (client ? client : this.pool).query(`UPDATE "${this.tableName}" SET ${setFieldList} WHERE "id" = $1`, sqlValues);
19350
+ yield (client ? client : this.pool).query(...sql_syntax_1.sqls`UPDATE ${SQLUtils_1.escapeIdentifier(this.tableName)} SET ${sql_syntax_1.default.join(sqlUpdates, sql_syntax_1.sqls` , `)} WHERE "id" = ${nodeId}`.toQuery());
19346
19351
  });
19347
19352
  }
19348
19353
  getChildTextTreeNodes(parentId) {
@@ -19468,7 +19473,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19468
19473
  };
19469
19474
  Object.defineProperty(exports, "__esModule", { value: true });
19470
19475
  exports.AspectQueryGroup = exports.AspectQueryValueInArray = exports.AspectQueryArrayNotEmpty = exports.AspectQueryWithValue = exports.AspectQueryExists = exports.AspectQueryFalse = exports.AspectQueryTrue = exports.AspectQuery = exports.AspectQueryValue = void 0;
19471
- const sql_syntax_1 = __importStar(__webpack_require__(6));
19476
+ const sql_syntax_1 = __importStar(__webpack_require__(7));
19472
19477
  const SQLUtils_1 = __webpack_require__(10);
19473
19478
  class AspectQueryValue {
19474
19479
  constructor(value) {
@@ -100,7 +100,7 @@ return /******/ (function(modules) { // webpackBootstrap
100
100
  /***/ 19:
101
101
  /***/ (function(module, exports, __webpack_require__) {
102
102
 
103
- const isUuid = __webpack_require__(7).default;
103
+ const isUuid = __webpack_require__(6).default;
104
104
  async function getNodeIdByNameOrId(nameOrId, queryer) {
105
105
  if (isUuid(nameOrId)) {
106
106
  return nameOrId;
@@ -117,7 +117,7 @@ module.exports = getNodeIdByNameOrId;
117
117
 
118
118
  /***/ }),
119
119
 
120
- /***/ 7:
120
+ /***/ 6:
121
121
  /***/ (function(module, exports, __webpack_require__) {
122
122
 
123
123
  "use strict";
@@ -100,7 +100,7 @@ return /******/ (function(modules) { // webpackBootstrap
100
100
  /***/ 20:
101
101
  /***/ (function(module, exports, __webpack_require__) {
102
102
 
103
- const isUuid = __webpack_require__(7).default;
103
+ const isUuid = __webpack_require__(6).default;
104
104
  async function getUserIdFromNameOrId(nameOrId, pool) {
105
105
  if (isUuid(nameOrId)) {
106
106
  return nameOrId;
@@ -120,7 +120,7 @@ module.exports = getUserIdFromNameOrId;
120
120
 
121
121
  /***/ }),
122
122
 
123
- /***/ 7:
123
+ /***/ 6:
124
124
  /***/ (function(module, exports, __webpack_require__) {
125
125
 
126
126
  "use strict";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magda/org-tree",
3
3
  "description": "MAGDA Organizational Hierarchy Management Utilities",
4
- "version": "2.0.0-alpha.1",
4
+ "version": "2.0.0-alpha.4",
5
5
  "bin": {
6
6
  "org-tree": "./bin/org-tree/org-tree.js"
7
7
  },
@@ -14,9 +14,9 @@
14
14
  "author": "",
15
15
  "license": "Apache-2.0",
16
16
  "devDependencies": {
17
- "@magda/authorization-api": "^2.0.0-alpha.1",
18
- "@magda/scripts": "^2.0.0-alpha.1",
19
- "@magda/typescript-common": "^2.0.0-alpha.1",
17
+ "@magda/authorization-api": "^2.0.0-alpha.4",
18
+ "@magda/scripts": "^2.0.0-alpha.4",
19
+ "@magda/typescript-common": "^2.0.0-alpha.4",
20
20
  "fs-extra": "^2.1.2",
21
21
  "webpack": "^4.41.2",
22
22
  "webpack-cli": "^3.3.10"