import Collection from "./collection"; export type $TSFixMe = any; export type WithOptional = Omit & Partial>; export type WithRequired = T & Required>; export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD"; export interface KintoRequest { method?: HttpMethod; path: string; headers: Record; body?: any; } export interface KintoIdObject { id: string; [key: string]: unknown; } export interface KintoObject extends KintoIdObject { last_modified: number; } export type Permission = "bucket:create" | "read" | "write" | "collection:create" | "group:create" | "record:create"; export interface User { id: string; principals: string[]; bucket: string; } export interface ServerCapability { description: string; url: string; version?: string; [key: string]: unknown; } export interface ServerSettings { readonly: boolean; batch_max_requests: number; } export interface HelloResponse { project_name: string; project_version: string; http_api_version: string; project_docs: string; url: string; settings: ServerSettings; user?: User; capabilities: { [key: string]: ServerCapability; }; } export interface OperationResponse { status: number; path: string; body: { data: T; }; headers: Record; } export interface BatchResponse { responses: OperationResponse[]; } export interface DataResponse { data: T; } export type MappableObject = { [key in string | number]: unknown; }; export interface KintoResponse { data: KintoObject & T; permissions: { [key in Permission]?: string[]; }; } export interface HistoryEntry { action: "create" | "update" | "delete"; collection_id: string; date: string; id: string; last_modified: number; record_id: string; resource_name: string; target: KintoResponse; timestamp: number; uri: string; user_id: string; } export interface PermissionData { bucket_id: string; collection_id?: string; id: string; permissions: Permission[]; resource_name: string; uri: string; } export interface Attachment { filename: string; hash: string; location: string; mimetype: string; size: number; } export interface Group extends KintoObject { members: string[]; } export interface Emitter { emit(type: string, event?: any): void; on(type: string, handler: (event?: any) => void): void; off(type: string, handler: (event?: any) => void): void; } export interface FetchHeaders { keys(): IterableIterator | string[]; entries(): IterableIterator<[string, string]> | [string, string][]; get(name: string): string | null; has(name: string): boolean; } export interface FetchResponse { status: number; statusText: string; text(): Promise; headers: FetchHeaders; } export type FetchFunction = (input: RequestInfo, init?: RequestInit | undefined) => Promise; export interface IdSchema { generate(record?: any): string; validate(id: string): boolean; } export interface RemoteTransformer { encode(record: any): any; decode(record: any): any; } export type AvailableHook = "incoming-changes"; export type Hooks = { [key in AvailableHook]?: ((record: any, collection: Collection) => Promise<{ changes: T[]; }>)[]; }; export interface KintoRepresentation { data: T; permissions: { [key in Permission]?: string[]; }; } export type UndefiendKintoRepresentation = WithOptional, "data">; export interface UpdateRepresentation extends KintoRepresentation { oldRecord: KintoIdObject & T; } export type RecordStatus = "created" | "updated" | "deleted" | "synced"; export interface Conflict { type: "incoming" | "outgoing"; local: T; remote: T; } export interface Update { old: T; new: T; } export interface KintoError { type: "incoming"; message: string; stack?: string; } export interface SyncResult { errors: KintoError[]; created: T[]; updated: Update[]; deleted: T[]; published: T[]; conflicts: Conflict[]; skipped: T[]; resolved: T[]; void: unknown[]; } interface CreatedChange { type: "created"; data: T; } interface UpdatedChange { type: "updated"; data: Update; } interface DeletedChange { type: "deleted"; data: T; } interface ResolvedChange { type: "resolved"; data: never; } interface ErrorChange { type: "errors"; data: never; } interface PublishedChange { type: "published"; data: never; } export interface ConflictsChange { type: "conflicts"; data: Conflict; } interface SkippedChange { type: "skipped"; data: T; } interface VoidChange { type: "void"; data?: never; } export type Change = CreatedChange | UpdatedChange | DeletedChange | ResolvedChange | ErrorChange | PublishedChange | ConflictsChange | SkippedChange | VoidChange; export interface Emitter { emit(type: string, event?: any): void; on(type: string, handler: (event?: any) => void): void; off(type: string, handler: (event?: any) => void): void; } export interface CollectionSyncOptions { strategy?: string; headers?: Record; retry?: number; ignoreBackoff?: boolean; bucket?: string | null; collection?: string | null; remote?: string | null; expectedTimestamp?: string | null; } export {};