arangojs
Version:
The official ArangoDB JavaScript driver.
32 lines • 1.01 kB
JavaScript
/**
* ```ts
* import type { Document, Edge } from "arangojs/documents.js";
* ```
*
* The "documents" module provides document/edge related types for TypeScript.
*
* @packageDocumentation
*/
/**
* @internal
*/
export function _documentHandle(selector, collectionName, strict = true) {
if (typeof selector !== "string") {
if (selector._id) {
return _documentHandle(selector._id, collectionName);
}
if (selector._key) {
return _documentHandle(selector._key, collectionName);
}
throw new Error("Document handle must be a string or an object with a _key or _id attribute");
}
if (selector.includes("/")) {
const [head] = selector.split("/");
if (strict && head !== collectionName) {
throw new Error(`Document ID "${selector}" does not match collection name "${collectionName}"`);
}
return selector;
}
return `${collectionName}/${selector}`;
}
//# sourceMappingURL=documents.js.map