Validation and transformation

While FileMaker allows developers to modify schema dynamically, changes to field names or types can disrupt Web Viewer applications if not caught early.

@adk/fmdapi provides runtime schema validation. Layout clients generated by adk typegen validate incoming FileMaker data against generated schemas, catching discrepancies immediately.

Standard Schema and Zod

DataApi accepts schemas conforming to Standard Schema. adk typegen generates Zod (v4) schemas by default:

  • Z<Schema>—Zod schema validating record fieldData.

  • T<Schema>—Inferred TypeScript type (z.infer<typeof Z<Schema>>).

  • Z<Schema>Portals—Zod schema map validating related portal rows (when portals are present).

  • T<Schema>Portals—Inferred portal types.

Generated clients wire these schemas automatically:

Copy
export const client = DataApi({
  adapter: new WebViewerAdapter({ scriptName: "ADK_execute_data_api" }),
  layout: "Contacts",
  schema: { fieldData: ZContacts, portalData: ZContactsPortals },
});

Note  Disable validation: Set "validator": false at the top level of adk.config.json to generate TypeScript types without runtime Zod schemas. Other options ("zod", "zod/v4", "zod/v3") generate Zod schemas (default: "zod/v4").

What gets validated and when

Validation executes on client query methods returning fieldData: list, listAll, get, find, findOne, findFirst, maybeFindFirst, and findAll. Record fieldData is validated and transformed against Z<Schema>, and portal rows against Z<Schema>Portals.

Mutations (create, update, delete) return IDs only and do not run schema validation.

Handling validation failures

If record data fails validation, the client:

  1. Logs details to console.error naming the layout and listing validation errors.

  2. Throws a JavaScript error, preventing malformed data from reaching application logic.

Wrap calls in try/catch when handling unexpected data failures:

Copy
try {
  const response = await ContactsLayout.find({ query: { Status: "Active" } });
} catch (err) {
  console.error("Failed to load contacts:", err);
}

Validation errors typically indicate that the FileMaker layout has changed since Typegen was last run. Re-run Typegen to update generated schemas.

Portal field names: removeFMTableNames

The FileMaker Data API prefixes portal field names with table occurrence names (for example, "Orders::Status"). Generated Z<Schema>Portals schemas handle this automatically. When authoring schemas manually, use removeFMTableNames to strip table occurrence prefixes:

Copy
removeFMTableNames({ "Orders::Status": "Shipped", count: 2 });
// Returns: { Status: "Shipped", count: 2 }

Inferring portal types: InferZodPortals

InferZodPortals<T> converts a Z<Schema>Portals schema map into inferred TypeScript types:

Copy
export type TContactsPortals = InferZodPortals<typeof ZContactsPortals>;

Keeping schemas in sync

  • generated/<Schema>.ts and client/<Schema>.ts are rebuilt automatically whenever Typegen runs. Do not edit these files directly.

  • <Schema>.ts is a preserved root override file created once and untouched on subsequent runs. Author custom validation rules and type refinements here.