Skip to main content

Function: getDOStub()

getDOStub(doNamespace, doInstanceNameOrId): any

Defined in: packages/utils/src/get-do-stub.ts:20

Create a Durable Object stub from a namespace and instance identifier.

Automatically detects unique IDs (64-character hex strings) and uses the appropriate method to create the stub: idFromString() + get() for unique IDs, or getByName() for named instances.

Parameters

doNamespace

any

The resolved DurableObjectNamespace

doInstanceNameOrId

string

Instance name or unique ID string

Returns

any

DurableObjectStub for the specified instance

Example

// Named instance
const stub = getDOStub(env.MY_DO, 'user-session-abc123');

// Unique ID (64-char hex string)
const stub = getDOStub(env.MY_DO, '8aa7a69131efa8902661702e701295f168aa5806045ec15d01a2f465bd5f3b99');