fm-odata-client
Version:
FileMaker OData client developed by Soliant Consulting
285 lines (279 loc) • 9.89 kB
TypeScript
import { URLSearchParams } from 'node:url';
type GenericField = {
name: string;
nullable?: boolean;
primary?: boolean;
unique?: boolean;
global?: boolean;
repetitions?: number;
};
type StringField = GenericField & {
type: "string";
maxLength?: number;
default?: "USER" | "USERNAME" | "CURRENT_USER";
};
type NumericField = GenericField & {
type: "numeric";
};
type DateField = GenericField & {
type: "date";
default?: "CURRENT_DATE" | "CURDATE";
};
type TimeField = GenericField & {
type: "time";
default?: "CURRENT_TIME" | "CURTIME";
};
type TimestampField = GenericField & {
type: "timestamp";
default?: "CURRENT_TIMESTAMP" | "CURTIMESTAMP";
};
type ContainerField = GenericField & {
type: "container";
externalSecurePath?: string;
};
type Field = StringField | NumericField | DateField | TimeField | TimestampField | ContainerField;
type FileMakerField = Omit<Field, "type" | "repetitions" | "maxLength"> & {
type: string;
};
type TableDefinition = {
tableName: string;
fields: FileMakerField[];
};
declare class SchemaManager {
private readonly database;
constructor(database: Database);
createTable(tableName: string, fields: Field[]): Promise<TableDefinition>;
addFields(tableName: string, fields: Field[]): Promise<TableDefinition>;
deleteTable(tableName: string): Promise<void>;
deleteField(tableName: string, fieldName: string): Promise<void>;
createIndex(tableName: string, fieldName: string): Promise<{
indexName: string;
}>;
deleteIndex(tableName: string, fieldName: string): Promise<void>;
private static compileFieldDefinition;
}
type FieldValue = string | number | Buffer | null;
type Repetition = {
repetition: number;
value: FieldValue;
};
type RowData = Record<string, FieldValue | Repetition>;
type OrderBy = {
field: string;
direction?: "asc" | "desc";
};
type QueryParams = {
filter?: string;
orderBy?: string | OrderBy | Array<string | OrderBy>;
top?: number;
skip?: number;
count?: boolean;
select?: string[];
relatedTable?: string | string[] | {
primaryKey: PrimaryKey;
table: string | string[];
};
};
type FetchOneParams = Omit<QueryParams, "top" | "count">;
type CrossJoinParams = Omit<QueryParams, "relatedTable" | "select"> & {
select?: Record<string, string[]>;
};
type Row = {
"@odata.id": string;
"@odata.editLink": string;
} & Record<string, string | number | null>;
type QueryResultWithCount = {
count: number;
rows: Row[];
};
type CrossJoinRow = Record<string, string | number | null>;
type CrossJoinResultWithCount = {
count: number;
rows: CrossJoinRow[];
};
type PrimaryKey = string | number | Array<string | number>;
declare const allowedFileTypes: string[];
declare class Table<Batched extends boolean = false> {
private readonly database;
private readonly name;
private readonly batched;
constructor(database: Database<Batched>, name: string, batched?: Batched);
create(data: RowData): Batched extends false ? Promise<Row> : undefined;
update(id: PrimaryKey, data: RowData): Batched extends false ? Promise<Row> : undefined;
updateMany(filter: string, data: RowData): Batched extends false ? Promise<Row[]> : undefined;
delete(id: PrimaryKey): Batched extends false ? Promise<void> : void;
deleteMany(filter: string): Batched extends false ? Promise<void> : void;
uploadBinary(id: PrimaryKey, fieldName: string, data: Buffer): Batched extends false ? Promise<void> : void;
count(filter?: string): Promise<number>;
fetchById(id: PrimaryKey): Promise<Row | null>;
fetchField(id: PrimaryKey, fieldName: string): Promise<Blob>;
fetchOne(params?: FetchOneParams): Promise<Row | null>;
query(params?: QueryParams & {
count: true;
}): Promise<QueryResultWithCount>;
query(params?: QueryParams & {
count?: false;
}): Promise<Row[]>;
crossJoin(tables: string | string[], params?: CrossJoinParams & {
count: true;
}): Promise<CrossJoinResultWithCount>;
crossJoin(tables: string | string[], params?: CrossJoinParams & {
count?: false;
}): Promise<CrossJoinRow[]>;
private fetchNone;
private fetchJson;
private fetchBlob;
private static compileRowData;
private static getMimeType;
private static compileQuerySearch;
private static compileOrderBy;
private static compilePrimaryKey;
private static compileRelatedTablePath;
}
type TableListEntry = {
name: string;
kind: "EntitySet";
url: string;
};
type GenericFieldMetadata = {
$Nullable?: boolean;
"@Index"?: boolean;
"@Calculation"?: boolean;
"@Summary"?: boolean;
"@Global"?: boolean;
"@Org.OData.Core.V1.Permissions"?: "Org.OData.Core.V1.Permission@Read";
};
type StringFieldMetadata = GenericFieldMetadata & {
$Type: "Edm.String";
$DefaultValue?: "USER" | "USERNAME" | "CURRENT_USER";
$MaxLength?: number;
};
type DecimalFieldMetadata = GenericFieldMetadata & {
$Type: "Edm.Decimal";
"@AutoGenerated"?: boolean;
};
type DateFieldMetadata = GenericFieldMetadata & {
$Type: "Edm.Date";
$DefaultValue?: "CURDATE" | "CURRENT_DATE";
};
type TimeOfDayFieldMetadata = GenericFieldMetadata & {
$Type: "Edm.TimeOfDay";
$DefaultValue?: "CURTIME" | "CURRENT_TIME";
};
type DateTimeOffsetFieldMetadata = GenericFieldMetadata & {
$Type: "Edm.Date";
$DefaultValue?: "CURTIMESTAMP" | "CURRENT_TIMESTAMP";
"@VersionId"?: boolean;
};
type StreamFieldMetadata = {
$Type: "Edm.Stream";
$Nullable?: boolean;
"@EnclosedPath": string;
"@ExternalOpenPath": string;
"@ExternalSecurePath"?: string;
};
type FieldMetadata = StringFieldMetadata | DecimalFieldMetadata | DateFieldMetadata | TimeOfDayFieldMetadata | DateTimeOffsetFieldMetadata | StreamFieldMetadata;
type EntityType = {
$Kind: "EntityType";
$Key: string[];
} & Record<string, FieldMetadata>;
type EntitySet = {
$Kind: "EntitySet";
$Type: string;
};
type Metadata = Record<string, EntityType | EntitySet>;
type ScriptParam = string | number | Record<string, unknown>;
type ScriptResult = {
code: number;
resultParameter: string;
};
type BatchExecutor<T> = (database: Database<true>) => T | void;
declare class Database<Batched extends boolean = false> {
private readonly connection;
private readonly name;
private readonly batched;
constructor(connection: Connection, name: string, batched?: Batched);
batch<T>(executor: BatchExecutor<T[]>): Promise<T[]>;
table(tableName: string): Table<Batched>;
schemaManager(): SchemaManager;
listTables(): Promise<TableListEntry[]>;
getMetadata(): Promise<Metadata>;
runScript(scriptName: string, scriptParam?: ScriptParam): Promise<ScriptResult>;
/**
* @internal
*/
fetchNone(path: string, params?: FetchParams | Promise<FetchParams>): Promise<void>;
/**
* @internal
*/
fetchJson<T>(path: string, params?: FetchParams | Promise<FetchParams>): Promise<T>;
/**
* @internal
*/
fetchBlob(path: string, params?: FetchParams | Promise<FetchParams>): Promise<Blob>;
}
type Authentication = {
getAuthorizationHeader: () => Promise<string>;
};
type FetchParams = {
search?: URLSearchParams;
method?: "GET" | "POST" | "PATCH" | "DELETE";
body?: RequestInit["body"];
contentType?: string;
};
declare class FetchError extends Error {
readonly errorCode: string;
readonly statusCode: number;
constructor(message: string, errorCode: string, statusCode: number);
}
type DatabaseListEntry = {
name: string;
kind: "EntityContainer";
url: string;
};
type ServiceDocument<T> = {
"@odata.context": string;
value: T;
};
type Blob = {
type: string;
buffer: Buffer;
};
type ConnectionOptions = {
laxParsing?: boolean;
disableSsl?: boolean;
};
declare class Connection {
private readonly hostname;
private readonly authentication;
private batch;
private readonly options;
constructor(hostname: string, authentication: Authentication, options?: ConnectionOptions | boolean);
listDatabases(): Promise<DatabaseListEntry[]>;
database(name: string): Database;
/**
* @internal
*/
batchConnection(databaseName: string): Connection;
/**
* @internal
*/
executeBatch(): Promise<void>;
/**
* @internal
*/
fetchNone(path: string, params?: FetchParams | Promise<FetchParams>): Promise<void>;
/**
* @internal
*/
fetchJson<T>(path: string, params?: FetchParams | Promise<FetchParams>): Promise<T>;
/**
* @internal
*/
fetchBlob(path: string, params?: FetchParams | Promise<FetchParams>): Promise<Blob>;
private fetch;
private createRequest;
private parseResponseJson;
private static stringifySearch;
}
export { type Authentication as A, type Blob as B, Connection as C, Database as D, type EntityType as E, type FetchParams as F, type GenericFieldMetadata as G, type Metadata as M, type OrderBy as O, type PrimaryKey as P, type QueryParams as Q, type Repetition as R, SchemaManager as S, Table as T, FetchError as a, type DatabaseListEntry as b, type ServiceDocument as c, type ConnectionOptions as d, type TableListEntry as e, type StringFieldMetadata as f, type DecimalFieldMetadata as g, type DateFieldMetadata as h, type TimeOfDayFieldMetadata as i, type DateTimeOffsetFieldMetadata as j, type StreamFieldMetadata as k, type FieldMetadata as l, type EntitySet as m, type ScriptParam as n, type ScriptResult as o, type Field as p, type FieldValue as q, type RowData as r, type FetchOneParams as s, type CrossJoinParams as t, type Row as u, type QueryResultWithCount as v, type CrossJoinRow as w, type CrossJoinResultWithCount as x, allowedFileTypes as y };