Skip to content

Commit

Permalink
Rename Workflow to WorkflowEntrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthachatterjee committed Oct 10, 2024
1 parent e6f45b2 commit b2f0c63
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/cloudflare/internal/workers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class WorkerEntrypoint {
public env: unknown;
}

export class Workflow {
export class WorkflowEntrypoint {
public constructor(ctx: unknown, env: unknown);

public ctx: unknown;
Expand Down
2 changes: 1 addition & 1 deletion src/cloudflare/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export const WorkerEntrypoint = entrypoints.WorkerEntrypoint;
export const DurableObject = entrypoints.DurableObject;
export const RpcStub = entrypoints.RpcStub;
export const RpcTarget = entrypoints.RpcTarget;
export const Workflow = entrypoints.Workflow;
export const WorkflowEntrypoint = entrypoints.WorkflowEntrypoint;
2 changes: 1 addition & 1 deletion src/node/internal/workers.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare namespace _default {
class WorkerEntrypoint {}
class Workflow {}
class WorkflowEntrypoint {}
class DurableObject {}
class RpcPromise {}
class RpcProperty {}
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/worker-rpc.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ jsg::Ref<DurableObjectBase> DurableObjectBase::constructor(
return jsg::alloc<DurableObjectBase>();
}

jsg::Ref<Workflow> Workflow::constructor(const v8::FunctionCallbackInfo<v8::Value>& args,
jsg::Ref<Workflow> WorkflowEntrypoint::constructor(const v8::FunctionCallbackInfo<v8::Value>& args,
jsg::Ref<ExecutionContext> ctx,
jsg::JsObject env) {
// HACK: We take `FunctionCallbackInfo` mostly so that we can set properties directly on
Expand All @@ -1840,7 +1840,7 @@ jsg::Ref<Workflow> Workflow::constructor(const v8::FunctionCallbackInfo<v8::Valu
jsg::JsObject self(args.This());
self.set(js, "ctx", jsg::JsValue(args[0]));
self.set(js, "env", jsg::JsValue(args[1]));
return jsg::alloc<Workflow>();
return jsg::alloc<WorkflowEntrypoint>();
}

}; // namespace workerd::api
16 changes: 8 additions & 8 deletions src/workerd/api/worker-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,23 +497,23 @@ class DurableObjectBase: public jsg::Object {
// When the worker's top-level module exports a class that extends this class, it means that it
// is a Workflow.
//
// import {Workflow} from "cloudflare:workers";
// export class MyWorkflow extends Workflow {
// import { WorkflowEntrypoint } from "cloudflare:workers";
// export class MyWorkflow extends WorkflowEntrypoint {
// async run(batch, fns) { ... }
// }
//
// `env` and `ctx` are automatically available as `this.env` and `this.ctx`, without the need to
// define a constructor.
class Workflow: public jsg::Object {
class WorkflowEntrypoint: public jsg::Object {
public:
static jsg::Ref<Workflow> constructor(const v8::FunctionCallbackInfo<v8::Value>& args,
static jsg::Ref<WorkflowEntrypoint> constructor(const v8::FunctionCallbackInfo<v8::Value>& args,
jsg::Ref<ExecutionContext> ctx,
jsg::JsObject env);

JSG_RESOURCE_TYPE(Workflow) {}
JSG_RESOURCE_TYPE(WorkflowEntrypoint) {}
};

// The "cloudflare:workers" module, which exposes the WorkerEntrypoint and DurableObject types
// The "cloudflare:workers" module, which exposes the WorkerEntrypoint, WorkflowEntrypoint and DurableObject types
// for extending.
class EntrypointsModule: public jsg::Object {
public:
Expand All @@ -522,7 +522,7 @@ class EntrypointsModule: public jsg::Object {

JSG_RESOURCE_TYPE(EntrypointsModule) {
JSG_NESTED_TYPE(WorkerEntrypoint);
JSG_NESTED_TYPE(Workflow);
JSG_NESTED_TYPE(WorkflowEntrypoint);
JSG_NESTED_TYPE_NAMED(DurableObjectBase, DurableObject);
JSG_NESTED_TYPE_NAMED(JsRpcPromise, RpcPromise);
JSG_NESTED_TYPE_NAMED(JsRpcProperty, RpcProperty);
Expand All @@ -533,7 +533,7 @@ class EntrypointsModule: public jsg::Object {

#define EW_WORKER_RPC_ISOLATE_TYPES \
api::JsRpcPromise, api::JsRpcProperty, api::JsRpcStub, api::JsRpcTarget, api::WorkerEntrypoint, \
api::Workflow, api::DurableObjectBase, api::EntrypointsModule
api::WorkflowEntrypoint, api::DurableObjectBase, api::EntrypointsModule

template <class Registry>
void registerRpcModules(Registry& registry, CompatibilityFlags::Reader flags) {
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/io/worker.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ Worker::Worker(kj::Own<const Script> scriptParam,
} else if (handle == entrypointClasses.workerEntrypoint) {
impl->statelessClasses.insert(kj::mv(handler.name), kj::mv(cls));
return;
} else if (handle == entrypointClasses.workflow) {
} else if (handle == entrypointClasses.workflowEntrypoint) {
if (features.getWorkerdExperimental()) {
impl->statelessClasses.insert(kj::mv(handler.name), kj::mv(cls));
}
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ WorkerdApi::EntrypointClasses WorkerdApi::getEntrypointClasses(jsg::Lock& lock)
return {
.workerEntrypoint = typedLock.getConstructor<api::WorkerEntrypoint>(lock.v8Context()),
.durableObject = typedLock.getConstructor<api::DurableObjectBase>(lock.v8Context()),
.workflow = typedLock.getConstructor<api::Workflow>(lock.v8Context()),
.workflowEntrypoint = typedLock.getConstructor<api::WorkflowEntrypoint>(lock.v8Context()),
};
}
const jsg::TypeHandler<Worker::Api::ErrorInterface>& WorkerdApi::getErrorInterfaceTypeHandler(
Expand Down
14 changes: 7 additions & 7 deletions types/defines/rpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare namespace Rpc {
export const __RPC_TARGET_BRAND: "__RPC_TARGET_BRAND";
export const __WORKER_ENTRYPOINT_BRAND: "__WORKER_ENTRYPOINT_BRAND";
export const __DURABLE_OBJECT_BRAND: "__DURABLE_OBJECT_BRAND";
export const __WORKFLOW_BRAND: "__WORKFLOW_BRAND";
export const __WORKFLOW_ENTRYPOINT_BRAND: "__WORKFLOW_ENTRYPOINT_BRAND";
export interface RpcTargetBranded {
[__RPC_TARGET_BRAND]: never;
}
Expand All @@ -20,13 +20,13 @@ declare namespace Rpc {
export interface DurableObjectBranded {
[__DURABLE_OBJECT_BRAND]: never;
}
export interface WorkflowBranded {
[__WORKFLOW_BRAND]: never;
export interface WorkflowEntrypointBranded {
[__WORKFLOW_ENTRYPOINT_BRAND]: never;
}
export type EntrypointBranded =
| WorkerEntrypointBranded
| DurableObjectBranded
| WorkflowBranded;
| WorkflowEntrypointBranded;

// Types that can be used through `Stub`s
export type Stubable = RpcTargetBranded | ((...args: any[]) => any);
Expand Down Expand Up @@ -236,12 +236,12 @@ declare module "cloudflare:workers" {
) => void | Promise<void>;
};

export abstract class Workflow<
export abstract class WorkflowEntrypoint<
Env = unknown,
T extends Rpc.Serializable | unknown = unknown,
> implements Rpc.WorkflowBranded
> implements Rpc.WorkflowEntrypointBranded
{
[Rpc.__WORKFLOW_BRAND]: never;
[Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never;

protected ctx: ExecutionContext;
protected env: Env;
Expand Down

0 comments on commit b2f0c63

Please sign in to comment.