Building a TypeScript SDK Wrapper for the FileMaker Data API
ExpertDesign and publish a reusable TypeScript SDK that abstracts FileMaker Data API complexity, with typed schemas, fluent query builders, and tree-shakeable exports.
What you'll learn
- How to design a fluent query builder for FM finds
- How to generate TypeScript types from FM field definitions
- How to implement cursor-based pagination in the SDK
- How to structure the SDK for tree-shaking and minimal bundle size
An SDK wrapper lets application developers work with typed FileMaker records without knowing anything about the raw Data API. The SDK handles sessions, pagination, error translation, and type safety. A well-designed SDK is the foundation for every integration in your organization.
1/4
1
Fluent query builder
A fluent interface lets callers build find requests with method chaining. Each method returns the builder instance, and find() executes the request.
FileMaker Script
class QueryBuilder<T> {
private criteria: Record<string, string>[] = [{}];
private sortFields: Array<{ fieldName: string; sortOrder: string }> = [];
private limitVal = 100;
private offsetVal = 0;
where(field: keyof T & string, value: string): this {
this.criteria[this.criteria.length - 1][field] = value;
return this;
}
or(): this { this.criteria.push({}); return this; }
sortBy(field: keyof T & string, order: 'asc' | 'desc' = 'asc'): this {
this.sortFields.push({ fieldName: field, sortOrder: order === 'asc' ? 'ascend' : 'descend' });
return this;
}
limit(n: number): this { this.limitVal = n; return this; }
offset(n: number): this { this.offsetVal = n; return this; }
async find(layout: string, client: FileMakerClient): Promise<T[]> {
const records = await client.findRecords<T>(layout, this.criteria, {
sort: this.sortFields, limit: this.limitVal, offset: this.offsetVal
});
return records.map(r => r.fieldData);
}
}
// Usage:
const contacts = await new QueryBuilder<Contact>()
.where('Status', 'Active')
.or()
.where('Status', 'Prospect')
.sortBy('LastName', 'asc')
.limit(50)
.find('Contacts', client);Sign in to track your progress and pick up where you left off.
Sign in to FM Dojo