File tree Expand file tree Collapse file tree 7 files changed +55
-0
lines changed Expand file tree Collapse file tree 7 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,16 @@ export class ActorNotFound extends ActorError {
254
254
}
255
255
}
256
256
257
+ export class ActorAlreadyExists extends ActorError {
258
+ constructor ( name : string , key : string [ ] ) {
259
+ super (
260
+ "actor_already_exists" ,
261
+ `Actor already exists with name "${ name } " and key ${ JSON . stringify ( key ) } ` ,
262
+ { public : true }
263
+ ) ;
264
+ }
265
+ }
266
+
257
267
export class ProxyError extends ActorError {
258
268
constructor ( operation : string , error ?: unknown ) {
259
269
super (
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ import type {
6
6
GetWithKeyInput ,
7
7
ManagerDriver ,
8
8
} from "@/driver-helpers/mod" ;
9
+ import { ActorAlreadyExists } from "@/actor/errors" ;
9
10
import type { TestGlobalState } from "./global-state" ;
11
+ import * as crypto from "node:crypto" ;
10
12
import { ManagerInspector } from "@/inspector/manager" ;
11
13
import type { ActorCoreApp } from "@/app/mod" ;
12
14
@@ -117,6 +119,12 @@ export class TestManagerDriver implements ManagerDriver {
117
119
name,
118
120
key,
119
121
} : CreateActorInput ) : Promise < CreateActorOutput > {
122
+ // Check if actor with the same name and key already exists
123
+ const existingActor = await this . getWithKey ( { name, key } ) ;
124
+ if ( existingActor ) {
125
+ throw new ActorAlreadyExists ( name , key ) ;
126
+ }
127
+
120
128
const actorId = crypto . randomUUID ( ) ;
121
129
this . #state. createActor ( actorId , name , key ) ;
122
130
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type {
7
7
GetWithKeyInput ,
8
8
ManagerDriver ,
9
9
} from "actor-core/driver-helpers" ;
10
+ import { ActorAlreadyExists } from "actor-core/actor/errors" ;
10
11
import { logger } from "./log" ;
11
12
import type { FileSystemGlobalState } from "./global-state" ;
12
13
import type { ActorCoreApp } from "actor-core" ;
@@ -95,6 +96,12 @@ export class FileSystemManagerDriver implements ManagerDriver {
95
96
name,
96
97
key,
97
98
} : CreateActorInput ) : Promise < CreateActorOutput > {
99
+ // Check if actor with the same name and key already exists
100
+ const existingActor = await this . getWithKey ( { name, key } ) ;
101
+ if ( existingActor ) {
102
+ throw new ActorAlreadyExists ( name , key ) ;
103
+ }
104
+
98
105
const actorId = crypto . randomUUID ( ) ;
99
106
await this . #state. createActor ( actorId , name , key ) ;
100
107
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ import type {
6
6
GetWithKeyInput ,
7
7
ManagerDriver ,
8
8
} from "actor-core/driver-helpers" ;
9
+ import { ActorAlreadyExists } from "actor-core/actor/errors" ;
9
10
import type { MemoryGlobalState } from "./global-state" ;
11
+ import * as crypto from "node:crypto" ;
10
12
import { ManagerInspector } from "actor-core/inspector" ;
11
13
import type { ActorCoreApp } from "actor-core" ;
12
14
@@ -86,6 +88,12 @@ export class MemoryManagerDriver implements ManagerDriver {
86
88
name,
87
89
key,
88
90
} : CreateActorInput ) : Promise < CreateActorOutput > {
91
+ // Check if actor with the same name and key already exists
92
+ const existingActor = await this . getWithKey ( { name, key } ) ;
93
+ if ( existingActor ) {
94
+ throw new ActorAlreadyExists ( name , key ) ;
95
+ }
96
+
89
97
const actorId = crypto . randomUUID ( ) ;
90
98
this . #state. createActor ( actorId , name , key ) ;
91
99
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ import type {
6
6
GetWithKeyInput ,
7
7
ManagerDriver ,
8
8
} from "actor-core/driver-helpers" ;
9
+ import { ActorAlreadyExists } from "actor-core/actor/errors" ;
9
10
import type Redis from "ioredis" ;
11
+ import * as crypto from "node:crypto" ;
10
12
import { KEYS } from "./keys" ;
11
13
import { ManagerInspector } from "actor-core/inspector" ;
12
14
import type { ActorCoreApp } from "actor-core" ;
@@ -93,6 +95,12 @@ export class RedisManagerDriver implements ManagerDriver {
93
95
name,
94
96
key,
95
97
} : CreateActorInput ) : Promise < CreateActorOutput > {
98
+ // Check if actor with the same name and key already exists
99
+ const existingActor = await this . getWithKey ( { name, key } ) ;
100
+ if ( existingActor ) {
101
+ throw new ActorAlreadyExists ( name , key ) ;
102
+ }
103
+
96
104
const actorId = crypto . randomUUID ( ) ;
97
105
const actorKeyRedisKey = this . #generateActorKeyRedisKey( name , key ) ;
98
106
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import type {
5
5
CreateActorInput ,
6
6
GetActorOutput ,
7
7
} from "actor-core/driver-helpers" ;
8
+ import { ActorAlreadyExists } from "actor-core/actor/errors" ;
8
9
import { Bindings } from "./mod" ;
9
10
import { logger } from "./log" ;
10
11
import { serializeNameAndKey , serializeKey } from "./util" ;
@@ -112,6 +113,12 @@ export class CloudflareWorkersManagerDriver implements ManagerDriver {
112
113
if ( ! c ) throw new Error ( "Missing Hono context" ) ;
113
114
const log = logger ( ) ;
114
115
116
+ // Check if actor with the same name and key already exists
117
+ const existingActor = await this . getWithKey ( { c, name, key } ) ;
118
+ if ( existingActor ) {
119
+ throw new ActorAlreadyExists ( name , key ) ;
120
+ }
121
+
115
122
// Create a deterministic ID from the actor name and key
116
123
// This ensures that actors with the same name and key will have the same ID
117
124
const nameKeyString = serializeNameAndKey ( name , key ) ;
Original file line number Diff line number Diff line change 1
1
import { assertUnreachable } from "actor-core/utils" ;
2
+ import { ActorAlreadyExists } from "actor-core/actor/errors" ;
2
3
import type {
3
4
ManagerDriver ,
4
5
GetForIdInput ,
@@ -121,6 +122,12 @@ export class RivetManagerDriver implements ManagerDriver {
121
122
key,
122
123
region,
123
124
} : CreateActorInput ) : Promise < GetActorOutput > {
125
+ // Check if actor with the same name and key already exists
126
+ const existingActor = await this . getWithKey ( { name, key } ) ;
127
+ if ( existingActor ) {
128
+ throw new ActorAlreadyExists ( name , key ) ;
129
+ }
130
+
124
131
// Create the actor request
125
132
let actorLogLevel : string | undefined = undefined ;
126
133
if ( typeof Deno !== "undefined" ) {
You can’t perform that action at this time.
0 commit comments