@proofkit/fmodata
Version:
FileMaker OData API client
73 lines (72 loc) • 3 kB
TypeScript
import { BaseTable } from './base-table.js';
type ExtractSchema<BT> = BT extends BaseTable<infer S, any, any, any> ? S : never;
type ResolveNavigation<T> = {
[K in keyof T]: T[K] extends () => infer R ? R : T[K];
};
export declare class TableOccurrence<BT extends BaseTable<any, any, any, any> = any, Name extends string = string, Nav extends Record<string, TableOccurrence<any, any, any, any> | (() => TableOccurrence<any, any, any, any>)> = {}, DefSelect extends "all" | "schema" | readonly (keyof ExtractSchema<BT>)[] = "schema"> {
readonly name: Name;
readonly baseTable: BT;
protected _navigationConfig: Nav;
readonly navigation: ResolveNavigation<Nav>;
readonly defaultSelect: DefSelect;
readonly fmtId?: `FMTID:${string}`;
constructor(config: {
readonly name: Name;
readonly baseTable: BT;
readonly navigation?: Nav;
readonly defaultSelect?: DefSelect;
readonly fmtId?: `FMTID:${string}`;
});
addNavigation<NewNav extends Record<string, TableOccurrence<any, any, any, any> | (() => TableOccurrence<any, any, any, any>)>>(nav: NewNav): TableOccurrence<BT, Name, Nav & NewNav, DefSelect>;
/**
* Returns the FileMaker table occurrence ID (FMTID) if available, or the table name.
* @returns The FMTID string or the table name
*/
getTableId(): string;
/**
* Returns the table occurrence name.
* @returns The table name
*/
getTableName(): string;
/**
* Returns true if this TableOccurrence is using FileMaker table occurrence IDs.
*/
isUsingTableId(): boolean;
}
export declare function createTableOccurrence<const Name extends string, BT extends BaseTable<any, any, any, any>, DefSelect extends "all" | "schema" | readonly (keyof ExtractSchema<BT>)[] = "schema">(config: {
name: Name;
baseTable: BT;
defaultSelect?: DefSelect;
fmtId?: `FMTID:${string}`;
}): TableOccurrence<BT, Name, {}, DefSelect>;
/**
* Creates a TableOccurrence with proper TypeScript type inference.
*
* Use this function instead of `new TableOccurrence()` to ensure
* field names are properly typed.
*
* @example Without entity IDs
* ```ts
* const users = defineTableOccurrence({
* name: "users",
* baseTable: usersBase,
* });
* ```
*
* @example With entity IDs
* ```ts
* const products = defineTableOccurrence({
* name: "products",
* baseTable: productsBase,
* fmtId: "FMTID:12345",
* });
* ```
*/
export declare function defineTableOccurrence<const Name extends string, BT extends BaseTable<any, any, any, any>, const DefSelect extends "all" | "schema" | readonly (keyof ExtractSchema<BT>)[] = "schema">(config: {
readonly name: Name;
readonly baseTable: BT;
readonly fmtId?: `FMTID:${string}`;
readonly defaultSelect?: DefSelect;
readonly navigation?: Record<string, TableOccurrence<any, any, any, any> | (() => TableOccurrence<any, any, any, any>)>;
}): TableOccurrence<BT, Name, {}, DefSelect>;
export {};