Skip to content

Commit 8607e8b

Browse files
committed
[DAPS-1515] Refactor legacy Repo class to integrate new repository patterns
- Implement RepositoryOps.find() for repository lookup - Add getRepository() to expose the new repository object - Adjust pathType() to handle metadata-only repositories - Preserve backward compatibility with existing API
1 parent 06c89ac commit 8607e8b

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

core/database/foxx/api/repo.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const g_db = require("@arangodb").db;
44
const g_lib = require("./support");
55
const { errors } = require("@arangodb");
66
const pathModule = require("./posix_path");
7+
const { RepositoryOps } = require("./repository/operations");
8+
const { Result } = require("./repository/types");
79

810
/**
911
* All DataFed repositories have the following path structure on a POSIX file system
@@ -37,6 +39,10 @@ const PathType = {
3739
UNKNOWN: "UNKNOWN",
3840
};
3941

42+
/**
43+
* Legacy Repo class for backward compatibility
44+
* Internally uses new repository patterns but maintains old API
45+
*/
4046
class Repo {
4147
// ERROR code
4248
#error = null;
@@ -47,6 +53,8 @@ class Repo {
4753
// The repo id simply the key prepended with 'repo/'
4854
#repo_id = null;
4955
#repo_key = null;
56+
// Store the repository object using new patterns
57+
#repository = null;
5058

5159
/**
5260
* Constructs a Repo object and checks if the key exists in the database.
@@ -74,20 +82,17 @@ class Repo {
7482
this.#repo_key = a_key;
7583
}
7684

77-
// Check if the repo document exists
78-
try {
79-
if (collection.exists(this.#repo_key)) {
80-
this.#exists = true;
81-
} else {
82-
this.#exists = false;
83-
this.#error = g_lib.ERR_NOT_FOUND;
84-
this.#err_msg = "Invalid repo: (" + a_key + "). No record found.";
85-
}
86-
} catch (e) {
85+
// Use new repository operations to find the repo
86+
const findResult = RepositoryOps.find(this.#repo_id);
87+
88+
if (findResult.ok) {
89+
this.#exists = true;
90+
this.#repository = findResult.value;
91+
} else {
8792
this.#exists = false;
88-
this.#error = g_lib.ERR_INTERNAL_FAULT;
89-
this.#err_msg = "Unknown error encountered.";
90-
console.log(e);
93+
this.#error =
94+
findResult.error.code === 404 ? g_lib.ERR_NOT_FOUND : g_lib.ERR_INTERNAL_FAULT;
95+
this.#err_msg = findResult.error.message;
9196
}
9297
}
9398
}
@@ -126,6 +131,14 @@ class Repo {
126131
return this.#err_msg;
127132
}
128133

134+
/**
135+
* Get the underlying repository object (new pattern)
136+
* @returns {object|null} Repository object or null if not exists
137+
*/
138+
getRepository() {
139+
return this.#repository;
140+
}
141+
129142
/**
130143
* Detect what kind of POSIX path has been provided
131144
*
@@ -138,13 +151,17 @@ class Repo {
138151
throw [g_lib.ERR_PERM_DENIED, "Repo does not exist " + this.#repo_id];
139152
}
140153

141-
let repo = g_db._document(this.#repo_id);
142-
if (!repo.path) {
154+
const repoData = this.#repository.data;
155+
if (!repoData.path) {
156+
// Metadata-only repos don't have paths
157+
if (repoData.type === "metadata_only") {
158+
return PathType.UNKNOWN;
159+
}
143160
throw [g_lib.ERR_INTERNAL_FAULT, "Repo document is missing path: " + this.#repo_id];
144161
}
145162

146163
// Get and sanitize the repo root path by removing the trailing slash if one exists
147-
let repo_root_path = repo.path.replace(/\/$/, "");
164+
let repo_root_path = repoData.path.replace(/\/$/, "");
148165
let sanitized_path = a_path.replace(/\/$/, "");
149166

150167
// Check if the sanitized path is exactly the repo root path

0 commit comments

Comments
 (0)