@@ -4,6 +4,8 @@ const g_db = require("@arangodb").db;
44const g_lib = require ( "./support" ) ;
55const { errors } = require ( "@arangodb" ) ;
66const 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+ */
4046class 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.
@@ -66,28 +74,19 @@ class Repo {
6674 //
6775 // Will return true if it does and false if it does not.
6876 if ( a_key && a_key !== "repo/" ) {
69- if ( a_key . startsWith ( "repo/" ) ) {
70- this . #repo_id = a_key ;
71- this . #repo_key = a_key . slice ( "repo/" . length ) ;
77+ // Use new repository operations to find the repo
78+ const findResult = RepositoryOps . find ( a_key ) ;
79+
80+ if ( findResult . ok ) {
81+ this . #exists = true ;
82+ this . #repository = findResult . value ;
83+ this . #repo_id = findResult . value . data . _id ;
84+ this . #repo_key = findResult . value . data . _key ;
7285 } else {
73- this . #repo_id = "repo/" + a_key ;
74- this . #repo_key = a_key ;
75- }
76-
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 ) {
8786 this . #exists = false ;
88- this . #error = g_lib . ERR_INTERNAL_FAULT ;
89- this . #err_msg = "Unknown error encountered." ;
90- console . log ( e ) ;
87+ this . #error =
88+ findResult . error . code === 404 ? g_lib . ERR_NOT_FOUND : g_lib . ERR_INTERNAL_FAULT ;
89+ this . #err_msg = findResult . error . message ;
9190 }
9291 }
9392 }
@@ -126,6 +125,14 @@ class Repo {
126125 return this . #err_msg;
127126 }
128127
128+ /**
129+ * Get the underlying repository object (new pattern)
130+ * @returns {object|null } Repository object or null if not exists
131+ */
132+ getRepository ( ) {
133+ return this . #repository;
134+ }
135+
129136 /**
130137 * Detect what kind of POSIX path has been provided
131138 *
@@ -138,13 +145,17 @@ class Repo {
138145 throw [ g_lib . ERR_PERM_DENIED , "Repo does not exist " + this . #repo_id] ;
139146 }
140147
141- let repo = g_db . _document ( this . #repo_id) ;
142- if ( ! repo . path ) {
148+ const repoData = this . #repository. data ;
149+ if ( ! repoData . path ) {
150+ // Metadata-only repos don't have paths
151+ if ( repoData . type === "metadata_only" ) {
152+ return PathType . UNKNOWN ;
153+ }
143154 throw [ g_lib . ERR_INTERNAL_FAULT , "Repo document is missing path: " + this . #repo_id] ;
144155 }
145156
146157 // Get and sanitize the repo root path by removing the trailing slash if one exists
147- let repo_root_path = repo . path . replace ( / \/ $ / , "" ) ;
158+ let repo_root_path = repoData . path . replace ( / \/ $ / , "" ) ;
148159 let sanitized_path = a_path . replace ( / \/ $ / , "" ) ;
149160
150161 // Check if the sanitized path is exactly the repo root path
0 commit comments