@proofkit/fmodata
Version:
FileMaker OData API client
133 lines (132 loc) • 5.4 kB
TypeScript
import { FFetchOptions } from '@fetchkit/ffetch';
import { StandardSchemaV1 } from '@standard-schema/spec';
import { FMTable } from '../orm/table.js';
import { FMODataLayer } from '../services.js';
import { ExecutableBuilder, ExecutionContext, Metadata, Result } from '../types.js';
import { BatchBuilder } from './batch-builder.js';
import { EntitySet } from './entity-set.js';
import { SchemaManager } from './schema-manager.js';
import { WebhookManager } from './webhook-builder.js';
interface MetadataArgs {
format?: "xml" | "json";
/**
* If provided, only the metadata for the specified table will be returned.
* Requires FileMaker Server 22.0.4 or later.
*/
tableName?: string;
/**
* If true, a reduced payload size will be returned by omitting certain annotations.
*/
reduceAnnotations?: boolean;
}
export declare class Database<IncludeSpecialColumns extends boolean = false> {
readonly schema: SchemaManager;
readonly webhook: WebhookManager;
private readonly databaseName;
private readonly _normalizeDatabaseName;
private readonly _useEntityIds;
private readonly _includeSpecialColumns;
/** @internal Database-scoped Effect Layer for dependency injection */
readonly _layer: FMODataLayer;
constructor(databaseName: string, context: ExecutionContext, config?: {
/**
* Whether to normalize the database name in requests.
* Defaults to true.
*/
normalizeDatabaseName?: boolean;
/**
* Whether to use entity IDs instead of field names in the actual requests to the server
* Defaults to true if all occurrences use entity IDs, false otherwise
* If set to false but some occurrences do not use entity IDs, an error will be thrown
*/
useEntityIds?: boolean;
/**
* Whether to include special columns (ROWID and ROWMODID) in responses.
* Note: Special columns are only included when there is no $select query.
*/
includeSpecialColumns?: IncludeSpecialColumns;
});
/**
* @internal Used by adapter packages to access the database filename.
*/
get _getDatabaseName(): string;
/**
* @internal Used by EntitySet to access database configuration
*/
get _getUseEntityIds(): boolean;
/**
* @internal Used by EntitySet to access database configuration
*/
get _getNormalizeDatabaseName(): boolean;
/**
* @internal Used by EntitySet to access database configuration
*/
get _getIncludeSpecialColumns(): IncludeSpecialColumns;
/**
* @internal Used by adapter packages for raw OData requests.
* Makes requests through the Effect DI layer.
*/
_makeRequest<T>(path: string, options?: RequestInit & FFetchOptions): Promise<Result<T>>;
from<T extends FMTable<any, any>>(table: T): EntitySet<T, IncludeSpecialColumns>;
/**
* Retrieves the OData metadata for this database.
* @param args Optional configuration object
* @param args.format The format to retrieve metadata in. Defaults to "json".
* @param args.tableName If provided, only the metadata for the specified table will be returned. Requires FileMaker Server 22.0.4 or later.
* @param args.reduceAnnotations If true, a reduced payload size will be returned by omitting certain annotations.
* @returns The metadata in the specified format
*/
getMetadata(args: {
format: "xml";
} & MetadataArgs): Promise<string>;
getMetadata(args?: {
format?: "json";
} & MetadataArgs): Promise<Metadata>;
/**
* Lists all available tables (entity sets) in this database.
* @returns Promise resolving to an array of table names
*/
listTableNames(): Promise<string[]>;
/**
* Executes a FileMaker script.
* @param scriptName - The name of the script to execute (must be valid according to OData rules)
* @param options - Optional script parameter and result schema
* @returns Promise resolving to script execution result
*/
runScript<ResultSchema extends StandardSchemaV1<string, any> = never>(scriptName: string, options?: {
scriptParam?: string | number | Record<string, any>;
resultSchema?: ResultSchema;
}): Promise<[
ResultSchema
] extends [never] ? {
resultCode: number;
result?: string;
} : ResultSchema extends StandardSchemaV1<string, infer Output> ? {
resultCode: number;
result: Output;
} : {
resultCode: number;
result?: string;
}>;
/**
* Create a batch operation builder that allows multiple queries to be executed together
* in a single atomic request. All operations succeed or fail together (transactional).
*
* @param builders - Array of executable query builders to batch
* @returns A BatchBuilder that can be executed
* @example
* ```ts
* const result = await db.batch([
* db.from('contacts').list().top(5),
* db.from('users').list().top(5),
* db.from('contacts').insert({ name: 'John' })
* ]).execute();
*
* if (result.data) {
* const [contacts, users, insertResult] = result.data;
* }
* ```
*/
batch<const Builders extends readonly ExecutableBuilder<any>[]>(builders: Builders): BatchBuilder<Builders>;
}
export {};