WebViewerAdapter
WebViewerAdapter is the component of @adk/fmdapi that enables the DataApi client to function inside a FileMaker Web Viewer. Rather than requiring external Data API endpoints or authentication tokens, record operations and container uploads execute through FileMaker scripts.
Note Generated clients: Clients generated by adk typegen configure WebViewerAdapter pointed at ADK_execute_data_api automatically. Constructing an adapter manually is necessary only for custom client architectures. See Overview and exports and Use a typed data client.
The request path
Unlike HTTP-based Data API adapters that communicate over the network with FileMaker Server, WebViewerAdapter executes FileMaker scripts (by default ADK_execute_data_api, provisioned via adk components apply) through the Web Viewer script bridge:
-
Your code calls a
DataApimethod (list,find,get,create,update,delete, orlayoutMetadata). -
WebViewerAdaptertransforms the call into a Data API request payload (includingaction,layouts,version: "vLatest", and query body). -
The adapter invokes ADK_execute_data_api through the Web Viewer bridge, passing the payload as the script parameter.
-
The script runs FileMaker's internal Data API engine locally and returns the raw response via
Exit Script. -
The adapter parses the response and resolves the promise, or throws a
FileMakerErrorif the engine reported a failure.
Because the script executes inside the active file, queries inherit the current user's session and security privilege set. No separate Data API credentials or server configuration are required.
Constructing an adapter
export const client = DataApi({
adapter: new WebViewerAdapter({
scriptName: "ADK_execute_data_api",
}),
layout: "Contacts",
});
WebViewerAdapter accepts the following configuration options:
| Option | Type | Description |
|---|---|---|
scriptName
|
string
|
FileMaker script called for Data API requests (defaults to ADK_execute_data_api). |
batch
|
boolean | { enabled?: boolean; windowMs?: number; maxSize?: number }
|
Controls request coalescing. See Batching below. |
pageSize
|
number
|
Page size used internally by listAll and findAll when no limit is specified (defaults to 100). |
container
|
{ scriptName?: string; timeoutMs?: number; maxFileBytes?: number }
|
Configures container upload behaviors. See Container uploads below. |
WebViewerAdapter can also be imported directly from @adk/fmdapi/adapter to avoid loading the full package bundle.
DataApi returns the same client interface regardless of adapter. list, listAll, get, find, findAll, findFirst, maybeFindFirst, create, update, delete, layoutMetadata, and containerUpload work with WebViewerAdapter.
executeScript() is not supported by WebViewerAdapter. Use fmFetch or callFMScript to call FileMaker scripts directly. See Script calls.
Container uploads
containerUpload base64-encodes binary assets and routes them to ADK_container_upload, separate from record query execution:
const adapter = new WebViewerAdapter({
scriptName: "ADK_execute_data_api",
container: {
scriptName: "ADK_container_upload",
timeoutMs: 60_000,
maxFileBytes: 20 * 1024 * 1024,
},
});
The container configuration settings are optional:
| Option | Default | Description |
|---|---|---|
scriptName
|
"ADK_container_upload"
|
FileMaker script that receives base64 payloads and writes container data. |
timeoutMs
|
60000
|
Timeout duration waiting for script response. Set to 0 or negative to disable timeouts. |
maxFileBytes
|
20971520
|
Maximum source file size in bytes (20 MiB). Set to 0 or negative to disable client size checks. |
Uploads require a file name with extension and support only repetition 1 of container fields. The method throws FileMakerError when the script reports a failure.
Warning Upload timeouts: If the script does not respond within the timeout, ContainerUploadTimeoutError is thrown with outcome: "unknown". The upload may complete asynchronously after the timeout, so verify the record before retrying. See containerUpload.
Batching
WebViewerAdapter coalesces Data API calls that occur within a short time window into a single script call. Rather than making separate PerformScript round trips for each query, multiple queued requests are batched under a top-level requests array:
{
"requests": [
{ "id": "batch-0", "action": "read", "layouts": "Contacts", "version": "vLatest" },
{ "id": "batch-1", "action": "read", "layouts": "Orders", "version": "vLatest" }
]
}
ADK_execute_data_api executes each request in order and returns matching responses in a responses array keyed by id. Batching reduces bridge round trips rather than FileMaker-side query execution time.
The default batch window is 8ms with a maximum batch size of 20 requests:
new WebViewerAdapter({
scriptName: "ADK_execute_data_api",
batch: {
windowMs: 16,
maxSize: 10,
},
});
To disable batching globally, set batch: false on the adapter:
new WebViewerAdapter({
scriptName: "ADK_execute_data_api",
batch: false,
});
Per-request control
Override the adapter's batching policy on individual method calls:
// Exclude this call from batching
await client.list({ batch: false, limit: 10 });
// Coalesce this call even if adapter has batching disabled
await client.find({
batch: true,
query: { status: "Active" },
});
When a request sets batch: true on an adapter configured with batch: false, it uses default parameters (8ms window, batch size 20).
Warning Performance benchmark: FileMaker performance varies depending on whether the script runs locally or on FileMaker Server, as well as the layout, table, found set, and any portal or container fields involved. Evaluate windowMs and maxSize against your own database layouts before tuning.
listAll and findAll
listAll() and findAll() do not send unbounded queries. Instead, the adapter sends an initial bounded request, reads dataInfo.foundCount, and calculates remaining pages. Subsequent pages are fetched sequentially—batched up to maxSize when batching is enabled—until all records are retrieved.
On large found sets, this can generate substantial query volume. Use paginated find() queries with explicit limit and offset parameters for UI views, and reserve listAll() and findAll() for deliberate full-dataset retrieval.
Errors
When the FileMaker Data API returns a non-zero error code, WebViewerAdapter throws a FileMakerError:
try {
await client.find({ query: { Status: "Archived" } });
} catch (error) {
if (error instanceof FileMakerError) {
console.error(error.code, error.message);
}
}
FileMakerError provides numeric code strings (such as "401" for no matching records) and descriptive error messages. Pass ignoreEmptyResult: true on find() calls when zero matches is an expected result. See Global settings and errors.