@@ -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.
@@ -66,28 +74,19 @@ class Repo {
66
74
//
67
75
// Will return true if it does and false if it does not.
68
76
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 ;
72
85
} 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 ) {
87
86
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 ;
91
90
}
92
91
}
93
92
}
@@ -126,6 +125,14 @@ class Repo {
126
125
return this . #err_msg;
127
126
}
128
127
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
+
129
136
/**
130
137
* Detect what kind of POSIX path has been provided
131
138
*
@@ -138,13 +145,17 @@ class Repo {
138
145
throw [ g_lib . ERR_PERM_DENIED , "Repo does not exist " + this . #repo_id] ;
139
146
}
140
147
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
+ }
143
154
throw [ g_lib . ERR_INTERNAL_FAULT , "Repo document is missing path: " + this . #repo_id] ;
144
155
}
145
156
146
157
// 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 ( / \/ $ / , "" ) ;
148
159
let sanitized_path = a_path . replace ( / \/ $ / , "" ) ;
149
160
150
161
// Check if the sanitized path is exactly the repo root path
0 commit comments