@magda/org-tree
Version:
MAGDA Organizational Hierarchy Management Utilities
30 lines (27 loc) • 1 kB
JavaScript
// ../cjs-shim.js
import { createRequire } from "module";
import path from "path";
import url from "url";
globalThis.require = createRequire(import.meta.url);
globalThis.__filename = url.fileURLToPath(import.meta.url);
globalThis.__dirname = path.dirname(__filename);
// ../../magda-typescript-common/dist/util/isUuid.js
var uuidRegEx = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
var isUuid = (id) => typeof id === "string" && uuidRegEx.test(id);
var isUuid_default = isUuid;
// ../../scripts/org-tree/getNodeIdFromNameOrId.js
async function getNodeIdByNameOrId(nameOrId, queryer) {
if (isUuid_default(nameOrId)) {
return nameOrId;
} else {
const nodes = await queryer.getNodes({ name: nameOrId }, ["id"]);
if (!nodes || !nodes.length) {
throw new Error(`Cannot locate node record with name: ${nameOrId}`);
}
return nodes[0].id;
}
}
var getNodeIdFromNameOrId_default = getNodeIdByNameOrId;
export {
getNodeIdFromNameOrId_default as default
};