Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions rivetkit-typescript/packages/framework-base/src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Derived, Effect, Store } from "@tanstack/store";

Check failure on line 1 in rivetkit-typescript/packages/framework-base/src/mod.ts

View workflow job for this annotation

GitHub Actions / RivetKit / Quality Check

format

Formatter would have printed the following content:
import equal from "fast-deep-equal";
import type { AnyActorDefinition, Registry } from "rivetkit";
import {
Expand Down Expand Up @@ -64,6 +64,12 @@
* Defaults to true.
*/
enabled?: boolean;
/**
* If true, only gets the actor if it already exists. Does not create the actor.
* Throws an error if the actor is not found.
* Defaults to false.
*/
noCreate?: boolean;
};
}

Expand Down Expand Up @@ -106,6 +112,12 @@
* Defaults to true.
*/
enabled?: boolean;
/**
* If true, only gets the actor if it already exists. Does not create the actor.
* Throws an error if the actor is not found.
* Defaults to false.
*/
noCreate?: boolean;
}

export type ActorsStateDerived<
Expand Down Expand Up @@ -424,15 +436,23 @@
});

try {
const handle = client.getOrCreate(
actor.opts.name as string,
actor.opts.key,
{
params: actor.opts.params,
createInRegion: actor.opts.createInRegion,
createWithInput: actor.opts.createWithInput,
},
);
const handle = actor.opts.noCreate
? client.get(
actor.opts.name as string,
actor.opts.key,
{
params: actor.opts.params,
},
)
: client.getOrCreate(
actor.opts.name as string,
actor.opts.key,
{
params: actor.opts.params,
createInRegion: actor.opts.createInRegion,
createWithInput: actor.opts.createWithInput,
},
);

const connection = handle.connect();

Expand Down Expand Up @@ -494,8 +514,8 @@
}
}

function defaultHashFunction({ name, key, params }: AnyActorOptions) {
return JSON.stringify({ name, key, params });
function defaultHashFunction({ name, key, params, noCreate }: AnyActorOptions) {
return JSON.stringify({ name, key, params, noCreate });
}

function optsEqual(a: AnyActorOptions, b: AnyActorOptions) {
Expand Down
Loading