1
1
"use strict" ;
2
2
3
- // local imports
4
3
const g_lib = require ( "./support" ) ;
5
4
const { UserToken } = require ( "./lib/user_token" ) ;
6
5
const { RepositoryOps } = require ( "./repository/operations" ) ;
@@ -11,8 +10,31 @@ const g_graph = require("@arangodb/general-graph")._graph("sdmsg");
11
10
const g_proc = require ( "./process" ) ;
12
11
var g_internal = require ( "internal" ) ;
13
12
14
- var tasks_func = ( function ( ) {
15
- var obj = { } ;
13
+ const tasks_func = ( function ( ) {
14
+ const obj = { } ;
15
+
16
+ // Helper function to validate repository supports data operations
17
+ function validateRepositorySupportsDataOperations ( loc , dataId ) {
18
+ if ( loc ) {
19
+ const findResult = RepositoryOps . find ( loc . _to ) ;
20
+ if ( findResult . ok ) {
21
+ const repository = findResult . value ;
22
+ const dataOpsResult = RepositoryOps . supportsDataOperations ( repository ) ;
23
+
24
+ if ( dataOpsResult . ok && ! dataOpsResult . value ) {
25
+ throw [
26
+ g_lib . ERR_INVALID_OPERATION ,
27
+ `Data transfers not supported for ${ repository . type } repository` ,
28
+ {
29
+ repo_type : repository . type ,
30
+ repo_id : repository . data . _id ,
31
+ data_id : dataId ,
32
+ } ,
33
+ ] ;
34
+ }
35
+ }
36
+ }
37
+ }
16
38
17
39
// ----------------------- ALLOC CREATE ----------------------------
18
40
@@ -316,25 +338,7 @@ var tasks_func = (function () {
316
338
var data = result . glob_data [ i ] ;
317
339
// Get repository from data location
318
340
var loc = g_db . loc . firstExample ( { _from : data . id } ) ;
319
- if ( loc ) {
320
- var findResult = RepositoryOps . find ( loc . _to ) ;
321
- if ( findResult . ok ) {
322
- var repository = findResult . value ;
323
- var dataOpsResult = RepositoryOps . supportsDataOperations ( repository ) ;
324
-
325
- if ( dataOpsResult . ok && ! dataOpsResult . value ) {
326
- throw [
327
- g_lib . ERR_INVALID_OPERATION ,
328
- "Data transfers not supported for metadata-only repository" ,
329
- {
330
- repo_type : repository . type ,
331
- repo_id : repository . data . _id ,
332
- data_id : data . id ,
333
- } ,
334
- ] ;
335
- }
336
- }
337
- }
341
+ validateRepositorySupportsDataOperations ( loc , data . id ) ;
338
342
}
339
343
}
340
344
@@ -528,25 +532,7 @@ var tasks_func = (function () {
528
532
var data = result . glob_data [ i ] ;
529
533
// Get repository from data location
530
534
var loc = g_db . loc . firstExample ( { _from : data . id } ) ;
531
- if ( loc ) {
532
- var findResult = RepositoryOps . find ( loc . _to ) ;
533
- if ( findResult . ok ) {
534
- var repository = findResult . value ;
535
- var dataOpsResult = RepositoryOps . supportsDataOperations ( repository ) ;
536
-
537
- if ( dataOpsResult . ok && ! dataOpsResult . value ) {
538
- throw [
539
- g_lib . ERR_INVALID_OPERATION ,
540
- "Data transfers not supported for metadata-only repository" ,
541
- {
542
- repo_type : repository . type ,
543
- repo_id : repository . data . _id ,
544
- data_id : data . id ,
545
- } ,
546
- ] ;
547
- }
548
- }
549
- }
535
+ validateRepositorySupportsDataOperations ( loc , data . id ) ;
550
536
}
551
537
}
552
538
@@ -2874,6 +2860,46 @@ var tasks_func = (function () {
2874
2860
//console.log("_ensureExclusiveAccess done", Date.now());
2875
2861
} ;
2876
2862
2863
+ // ----------------------- REPO ALLOCATION WRAPPERS ----------------------------
2864
+
2865
+ // Wrapper for allocation creation (used by repository factory pattern)
2866
+ obj . repoAllocationCreateTask = function ( params ) {
2867
+ // Extract parameters from the params object
2868
+ const { repo_id, subject, size, path, metadata } = params ;
2869
+
2870
+ // Get the repository to determine limits
2871
+ const repo = g_db . repo . document ( repo_id ) ;
2872
+
2873
+ // Use a reasonable default for rec_limit if not specified
2874
+ const rec_limit = params . rec_limit || 1000000 ; // 1 million records as default
2875
+
2876
+ // Create a dummy client object that has admin permissions
2877
+ // This is because the repository operations have already validated permissions
2878
+ const systemClient = { _id : "system" , is_admin : true } ;
2879
+
2880
+ // Call the existing taskInitAllocCreate function
2881
+ return obj . taskInitAllocCreate (
2882
+ systemClient ,
2883
+ repo_id ,
2884
+ subject ,
2885
+ size || repo . capacity , // Use repo capacity if size not specified
2886
+ rec_limit ,
2887
+ ) ;
2888
+ } ;
2889
+
2890
+ // Wrapper for allocation deletion (used by repository factory pattern)
2891
+ obj . repoAllocationDeleteTask = function ( params ) {
2892
+ // Extract parameters from the params object
2893
+ const { repo_id, subject } = params ;
2894
+
2895
+ // Create a dummy client object that has admin permissions
2896
+ // This is because the repository operations have already validated permissions
2897
+ const systemClient = { _id : "system" , is_admin : true } ;
2898
+
2899
+ // Call the existing taskInitAllocDelete function
2900
+ return obj . taskInitAllocDelete ( systemClient , repo_id , subject ) ;
2901
+ } ;
2902
+
2877
2903
return obj ;
2878
2904
} ) ( ) ;
2879
2905
0 commit comments