@@ -7,11 +7,24 @@ import type {
7
7
ManagerDriver ,
8
8
} from "@/driver-helpers/mod" ;
9
9
import type { TestGlobalState } from "./global_state" ;
10
+ import { ManagerInspector } from "@/inspector/manager" ;
11
+ import type { ActorCoreApp } from "@/app/mod" ;
10
12
11
13
export class TestManagerDriver implements ManagerDriver {
12
14
#state: TestGlobalState ;
13
15
14
- constructor ( state : TestGlobalState ) {
16
+ /**
17
+ * @internal
18
+ */
19
+ inspector : ManagerInspector = new ManagerInspector ( this , {
20
+ getAllActors : ( ) => this . #state. getAllActors ( ) ,
21
+ getAllTypesOfActors : ( ) => Object . keys ( this . app . config . actors ) ,
22
+ } ) ;
23
+
24
+ constructor (
25
+ private readonly app : ActorCoreApp < any > ,
26
+ state : TestGlobalState ,
27
+ ) {
15
28
this . #state = state ;
16
29
}
17
30
@@ -37,13 +50,24 @@ export class TestManagerDriver implements ManagerDriver {
37
50
name,
38
51
tags,
39
52
} : GetWithTagsInput ) : Promise < GetActorOutput | undefined > {
40
- // TODO: Update tag search to use inverse tree
41
- const serializedSearchTags = JSON . stringify ( tags ) ;
42
- const actor = this . #state. findActor (
43
- ( actor ) =>
44
- actor . name === name &&
45
- JSON . stringify ( actor . tags ) === serializedSearchTags ,
46
- ) ;
53
+ // NOTE: This is a slow implementation that checks each actor individually.
54
+ // This can be optimized with an index in the future.
55
+
56
+ // Search through all actors to find a match
57
+ // Find actors with a superset of the queried tags
58
+ const actor = this . #state. findActor ( ( actor ) => {
59
+ if ( actor . name !== name ) return false ;
60
+
61
+ for ( const key in tags ) {
62
+ const value = tags [ key ] ;
63
+
64
+ // If actor doesn't have this tag key, or values don't match, it's not a match
65
+ if ( actor . tags [ key ] === undefined || actor . tags [ key ] !== value ) {
66
+ return false ;
67
+ }
68
+ }
69
+ return true ;
70
+ } ) ;
47
71
48
72
if ( actor ) {
49
73
return {
@@ -63,6 +87,9 @@ export class TestManagerDriver implements ManagerDriver {
63
87
} : CreateActorInput ) : Promise < CreateActorOutput > {
64
88
const actorId = crypto . randomUUID ( ) ;
65
89
this . #state. createActor ( actorId , name , tags ) ;
90
+
91
+ this . inspector . onActorsChange ( this . #state. getAllActors ( ) ) ;
92
+
66
93
return {
67
94
endpoint : buildActorEndpoint ( baseUrl , actorId ) ,
68
95
} ;
0 commit comments