Kaizen
Browse modulesFormsforms/serverFunctions

Function: createFormServices()

function createFormServices(options: CreateFormServicesOptions): FormServices;

Defined in: server/forms/factory.ts:73

Create ready-to-use form services.

Resolves the Prisma client from the ambient registry — call initPrismaClient (or registerPrismaClient) on @the-kaizen-labs/taproot/persistence at application startup before using this factory.

Call this per-request (or per-unit-of-work), not once at application startup. getActorId is resolved at construction time to populate audit fields on repository writes; services also call it live for createdBy on new versions, so constructing once per request keeps both paths consistent.

Parameters

ParameterType
optionsCreateFormServicesOptions

Returns

FormServices

Example

import { Prisma, PrismaClient } from "@prisma/client";
import { initPrismaClient } from "@the-kaizen-labs/taproot/persistence";
import { createFormServices } from "@the-kaizen-labs/taproot/forms/server";

// Once, at startup:
initPrismaClient(
  PrismaClient,
  { connection: process.env.DATABASE_URL! },
  Prisma,
);

// Per request:
const forms = createFormServices({
  getActorId: () => currentUser?.id ?? null,
  fileStore: myFileStore,
});

const schema = await forms.schemaService.create({
  type: "application",
  name: "App Form",
  schema: { fields: [...] },
});

On this page