fql-toolkit
Version:
58 lines • 2.15 kB
TypeScript
import type FQLHTTPClient from './client.js';
import type { CreateFormInput, FQLResult, ModifyFormInput } from './types.js';
/**
* Manages form-level operations.
* Accessed via `client.forms`.
*
* @example
* await client.forms.create({
* name: 'customers',
* dataSpecs: [
* { name: 'name', type: 'text' },
* { name: 'email', type: 'text' },
* ],
* });
* await client.forms.show(['customers']);
* await client.forms.modify('customers', { add: [{ name: 'age', type: 'number' }], remove: ['email'] });
* await client.forms.remove('customers');
*/
export default class FormsManager {
private readonly _http;
constructor(httpClient: FQLHTTPClient);
/**
* Creates a new form.
*
* @param input.name - Form name
* @param input.dataSpecs - Plain data fields (name, type, notNull?, unique?)
* @param input.dataRefs - Reference fields (name, cardinality?, path, totally?, unique?)
*/
create<T = unknown[]>({ name, dataSpecs, dataRefs }: CreateFormInput): Promise<FQLResult<T>>;
/**
* Shows one or more forms, or all forms when called with no arguments.
*
* @param formNames - Optional list of form names to show
*/
show<T = unknown[]>(formNames?: string[]): Promise<FQLResult<T>>;
/**
* Removes one or more forms.
* ⚠️ Irreversible. Blocked if another form references this one.
*
* @param formNames - A name, an array of names, or omit to remove all forms.
*/
remove<T = unknown[]>(formNames?: string | string[]): Promise<FQLResult<T>>;
/**
* Modifies the structure of an existing form (add or remove fields).
*
* @param formName
* @param options.add - Fields to add (same shape as dataSpecs / dataRefs in create)
* @param options.remove - Field names to remove
*
* @example
* await client.forms.modify('customers', {
* add: [{ name: 'country', type: 'text' }],
* remove: ['email'],
* });
*/
modify<T = unknown[]>(formName: string, { add, remove }?: ModifyFormInput): Promise<FQLResult<T>>;
}
//# sourceMappingURL=FormsManager.d.ts.map