Matou-Garou / convex /aiTown /insertInput.ts
Jofthomas's picture
Jofthomas HF staff
bulk
ce8b18b
raw
history blame contribute delete
678 Bytes
import { MutationCtx } from '../_generated/server';
import { Id } from '../_generated/dataModel';
import { engineInsertInput } from '../engine/abstractGame';
import { InputNames, InputArgs } from './inputs';
export async function insertInput<Name extends InputNames>(
ctx: MutationCtx,
worldId: Id<'worlds'>,
name: Name,
args: InputArgs<Name>,
): Promise<Id<'inputs'>> {
const worldStatus = await ctx.db
.query('worldStatus')
.withIndex('worldId', (q) => q.eq('worldId', worldId))
.unique();
if (!worldStatus) {
throw new Error(`World for engine ${worldId} not found`);
}
return await engineInsertInput(ctx, worldStatus.engineId, name, args);
}