@@ -4,6 +4,8 @@ const g_db = require("@arangodb").db;
4
4
const g_lib = require ( "./support" ) ;
5
5
const { errors } = require ( "@arangodb" ) ;
6
6
const pathModule = require ( "./posix_path" ) ;
7
+ const { RepositoryOps } = require ( "./repository/operations" ) ;
8
+ const { Result } = require ( "./repository/types" ) ;
7
9
8
10
/**
9
11
* All DataFed repositories have the following path structure on a POSIX file system
@@ -37,6 +39,10 @@ const PathType = {
37
39
UNKNOWN : "UNKNOWN" ,
38
40
} ;
39
41
42
+ /**
43
+ * Legacy Repo class for backward compatibility
44
+ * Internally uses new repository patterns but maintains old API
45
+ */
40
46
class Repo {
41
47
// ERROR code
42
48
#error = null ;
@@ -47,6 +53,8 @@ class Repo {
47
53
// The repo id simply the key prepended with 'repo/'
48
54
#repo_id = null ;
49
55
#repo_key = null ;
56
+ // Store the repository object using new patterns
57
+ #repository = null ;
50
58
51
59
/**
52
60
* Constructs a Repo object and checks if the key exists in the database.
@@ -74,20 +82,17 @@ class Repo {
74
82
this . #repo_key = a_key ;
75
83
}
76
84
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 {
87
92
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 ;
91
96
}
92
97
}
93
98
}
@@ -126,6 +131,14 @@ class Repo {
126
131
return this . #err_msg;
127
132
}
128
133
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
+
129
142
/**
130
143
* Detect what kind of POSIX path has been provided
131
144
*
@@ -138,13 +151,17 @@ class Repo {
138
151
throw [ g_lib . ERR_PERM_DENIED , "Repo does not exist " + this . #repo_id] ;
139
152
}
140
153
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
+ }
143
160
throw [ g_lib . ERR_INTERNAL_FAULT , "Repo document is missing path: " + this . #repo_id] ;
144
161
}
145
162
146
163
// 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 ( / \/ $ / , "" ) ;
148
165
let sanitized_path = a_path . replace ( / \/ $ / , "" ) ;
149
166
150
167
// Check if the sanitized path is exactly the repo root path
0 commit comments