UNPKG

@ztimson/momentum

Version:

Client library for momentum

91 lines 2.93 kB
import { Api } from './api'; import { Meta, TreeNode } from './core'; import { PathEventEmitter, PromiseProgress } from '@ztimson/utils'; export type Document<T> = Meta & T; export type RawQuery = { operand: 'delete' | 'deleteOne' | 'find' | 'findOne' | 'insertOne' | 'replaceOne' | 'update' | 'updateOne'; filter?: any; data?: any; options?: any; count?: boolean; }; export type Schema = Meta & { /** Collection path/name */ path: string; /** Description of data */ description?: string; /** Associated form for viewing/editing */ form?: string; /** Hide columns */ hide?: string[]; /** Lock collection from changes */ lock?: boolean; /** Data must match defined columns */ strict?: boolean; /** Allow updates to create row if missing */ upsert?: boolean; /** Defined fields */ columns?: SchemaColumn[]; }; export type SchemaColumn = { /** Display label */ label: string; /** Property key */ prop: string; /** Variable type */ type?: 'any' | 'boolean' | 'formula' | 'javascript' | 'link' | 'number' | 'string' | 'timestamp'; /** Display formating */ format?: any; /** Default value */ default?: any; /** Must have value */ required?: boolean; /** Style */ style: SchemaColumnStyle; }; export type SchemaColumnStyle = { /** Align column content */ align?: 'center' | 'left' | 'right'; /** Background color */ background?: string; /** Bold column text */ bold?: boolean; /** Column text color */ color?: string; /** Italicize column text */ italics?: boolean; /** Strikethrough column text */ strike?: boolean; /** Underline column text */ underline?: boolean; /** Column width */ width?: string; /** Conditional formating */ conditional: (Omit<SchemaColumnStyle, 'conditional'> & { condition: string; })[]; }; declare class Schemas extends PathEventEmitter { private api; constructor(api: Api); delete(path: string): PromiseProgress<any>; read(tree?: false): Promise<Schema[]>; read(tree: true): Promise<TreeNode<Schema>[]>; read(path: string): Promise<Schema>; update(schema: Partial<Schema> & { path: string; }): PromiseProgress<Schema>; } export declare class Data extends PathEventEmitter { private readonly api; schema: Schemas; constructor(api: Api | string); create<T>(collection: string, document: Document<T>): Promise<Document<T>>; delete(collection: string, id: number): Promise<void>; read<T extends Meta>(collection: string): Promise<T[]>; read<T extends Meta>(collection: string, id: number): Promise<T>; update<T>(collection: string, document: Document<T>, append?: boolean): Promise<Document<T>>; raw<T>(collection: string, query: RawQuery): Promise<Document<T>>; } export {}; //# sourceMappingURL=data.d.ts.map