File tree Expand file tree Collapse file tree 3 files changed +18
-8
lines changed
src/components/tools/tool-usage Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -6,13 +6,13 @@ import {
6
6
type LoaderOptionsOf ,
7
7
} from '~/core/data-loader' ;
8
8
import { type Tool } from '../tool/dto' ;
9
- import { type ToolUsage } from './dto' ;
9
+ import { type SecuredToolUsageList } from './dto' ;
10
10
import { ToolUsageLoader } from './tool-usage.loader' ;
11
11
import { ToolUsageService } from './tool-usage.service' ;
12
12
13
13
export interface UsagesByTool {
14
14
tool : Tool ;
15
- usages : readonly ToolUsage [ ] ;
15
+ usages : SecuredToolUsageList ;
16
16
}
17
17
18
18
@LoaderFactory ( )
@@ -35,7 +35,7 @@ export class ToolUsageByToolLoader
35
35
const res = await this . usages . readManyForTools ( tools ) ;
36
36
37
37
const canonicalUsages = await ctx . getLoader ( ToolUsageLoader ) ;
38
- const usages = res . flatMap ( ( u ) => u . usages ) ;
38
+ const usages = res . flatMap ( ( u ) => u . usages . items ) ;
39
39
canonicalUsages . primeAll ( usages ) ;
40
40
41
41
return res ;
Original file line number Diff line number Diff line change @@ -92,13 +92,23 @@ export class ToolUsageService {
92
92
return await Promise . all (
93
93
rows . map ( async ( row ) : Promise < UsagesByTool > => {
94
94
const tool = toolsById . get ( row . tool . id ) ! ;
95
- const usages = await Promise . all (
95
+ const usagesRaw = await Promise . all (
96
96
row . usages . map ( async ( dto ) => {
97
97
const container = await this . loadContainer ( dto . container ) ;
98
98
return this . secure ( dto , container ) ?? [ ] ;
99
99
} ) ,
100
100
) ;
101
- return { tool, usages : usages . flat ( ) } ;
101
+ const usages = usagesRaw . flat ( ) ;
102
+ return {
103
+ tool,
104
+ usages : {
105
+ items : usages ,
106
+ total : usages . length ,
107
+ hasMore : false ,
108
+ canRead : true ,
109
+ canCreate : false ,
110
+ } ,
111
+ } ;
102
112
} ) ,
103
113
) ;
104
114
}
Original file line number Diff line number Diff line change 1
1
import { Parent , ResolveField , Resolver } from '@nestjs/graphql' ;
2
2
import { Loader , type LoaderOf } from '@seedcompany/data-loader' ;
3
3
import { Tool } from '../tool/dto' ;
4
- import { ToolUsage } from './dto' ;
4
+ import { SecuredToolUsageList } from './dto' ;
5
5
import { ToolUsageByToolLoader } from './tool-usage-by-tool.loader' ;
6
6
7
7
@Resolver ( ( ) => Tool )
8
8
export class ToolUsagesResolver {
9
- @ResolveField ( ( ) => [ ToolUsage ] , {
9
+ @ResolveField ( ( ) => SecuredToolUsageList , {
10
10
description : 'The usages of this tool' ,
11
11
} )
12
12
async usages (
13
13
@Parent ( ) tool : Tool ,
14
14
@Loader ( ( ) => ToolUsageByToolLoader )
15
15
loader : LoaderOf < ToolUsageByToolLoader > ,
16
- ) : Promise < readonly ToolUsage [ ] > {
16
+ ) : Promise < SecuredToolUsageList > {
17
17
const { usages } = await loader . load ( tool ) ;
18
18
return usages ;
19
19
}
You can’t perform that action at this time.
0 commit comments