@magda/org-tree 2.3.3 → 3.0.0-alpha.0

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.
@@ -0,0 +1,21 @@
1
+ // ../../magda-typescript-common/dist/util/isUuid.js
2
+ var uuidRegEx = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3
+ var isUuid = (id) => typeof id === "string" && uuidRegEx.test(id);
4
+ var isUuid_default = isUuid;
5
+
6
+ // ../../scripts/org-tree/getNodeIdFromNameOrId.js
7
+ async function getNodeIdByNameOrId(nameOrId, queryer) {
8
+ if (isUuid_default(nameOrId)) {
9
+ return nameOrId;
10
+ } else {
11
+ const nodes = await queryer.getNodes({ name: nameOrId }, ["id"]);
12
+ if (!nodes || !nodes.length) {
13
+ throw new Error(`Cannot locate node record with name: ${nameOrId}`);
14
+ }
15
+ return nodes[0].id;
16
+ }
17
+ }
18
+ var getNodeIdFromNameOrId_default = getNodeIdByNameOrId;
19
+ export {
20
+ getNodeIdFromNameOrId_default as default
21
+ };
@@ -0,0 +1,24 @@
1
+ // ../../magda-typescript-common/dist/util/isUuid.js
2
+ var uuidRegEx = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3
+ var isUuid = (id) => typeof id === "string" && uuidRegEx.test(id);
4
+ var isUuid_default = isUuid;
5
+
6
+ // ../../scripts/org-tree/getUserIdFromNameOrId.js
7
+ async function getUserIdFromNameOrId(nameOrId, pool) {
8
+ if (isUuid_default(nameOrId)) {
9
+ return nameOrId;
10
+ } else {
11
+ const result = await pool.query(
12
+ `SELECT "id" FROM "users" WHERE "displayName" = $1`,
13
+ [nameOrId]
14
+ );
15
+ if (!result || !result.rows || !result.rows.length) {
16
+ throw new Error(`Cannot locate node record with name: ${nameOrId}`);
17
+ }
18
+ return result.rows[0].id;
19
+ }
20
+ }
21
+ var getUserIdFromNameOrId_default = getUserIdFromNameOrId;
22
+ export {
23
+ getUserIdFromNameOrId_default as default
24
+ };