UNPKG

@grouparoo/core

Version:
133 lines (132 loc) 5.76 kB
/// <reference types="node" /> import { GrouparooRecord } from "../../models/GrouparooRecord"; import { RecordProperty } from "../../models/RecordProperty"; import { Property } from "../../models/Property"; import { Source } from "../../models/Source"; import { Group } from "../../models/Group"; import { Export } from "../../models/Export"; import { OrderItem } from "sequelize"; export interface RecordPropertyValue { id: RecordProperty["id"]; sourceId: Property["sourceId"]; state: RecordProperty["state"]; values: (string | number | boolean | Date)[]; invalidValue: RecordProperty["invalidValue"]; invalidReason: RecordProperty["invalidReason"]; configId: ReturnType<Property["getConfigId"]>; type: Property["type"]; unique: Property["unique"]; isPrimaryKey: Property["isPrimaryKey"]; isArray: Property["isArray"]; valueChangedAt: RecordProperty["valueChangedAt"]; confirmedAt: RecordProperty["confirmedAt"]; stateChangedAt: RecordProperty["stateChangedAt"]; startedAt: RecordProperty["startedAt"]; createdAt: RecordProperty["createdAt"]; updatedAt: RecordProperty["updatedAt"]; } export declare type RecordPropertyType = Record<string, RecordPropertyValue>; export declare namespace RecordOps { /** * Get the Properties of this GrouparooRecord */ function getProperties(record: GrouparooRecord): Promise<RecordPropertyType>; /** * Search & List GrouparooRecords */ function search({ limit, offset, state, groupId, modelId, searchKey, searchValue, order, caseSensitive, }: { limit?: number; offset?: number; state?: string; groupId?: string; modelId?: string; searchKey?: string | number; searchValue?: string; order?: OrderItem[]; caseSensitive?: boolean; }): Promise<{ records: GrouparooRecord[]; total: number; }>; /** * Add or Update a Property on GrouparooRecords */ function addOrUpdateProperties(records: GrouparooRecord[], recordProperties: { [key: string]: (string | number | boolean | Date)[] | any; }[], toLock?: boolean, ignoreMissingProperties?: boolean): Promise<void>; /** * Remove a Property on this GrouparooRecord */ function removeProperty(record: GrouparooRecord, key: string): Promise<number>; /** * Remove all Properties from this GrouparooRecord */ function removeProperties(record: GrouparooRecord, properties: string[]): Promise<void>; function buildNullProperties(records: GrouparooRecord[], state?: RecordProperty["state"], skipPropertyLookup?: boolean): Promise<number>; function updateGroupMemberships(records: GrouparooRecord[]): Promise<{ [recordId: string]: { [groupId: string]: boolean; }; }>; /** * Import the properties of this GrouparooRecord */ function _import(record: GrouparooRecord, toSave?: boolean, toLock?: boolean): Promise<GrouparooRecord>; /** * Export this GrouparooRecord to all relevant Sources */ function _export(record: GrouparooRecord, force?: boolean, additionalGroups?: Group[], saveExports?: boolean, sync?: boolean, toDelete?: boolean): Promise<Export[]>; /** * Fully Import and Export a record */ function sync(record: GrouparooRecord, force?: boolean, toExport?: boolean): Promise<Export[]>; /** * This is used for manually importing Records from the UI * * **WARNING**: This method expects NOT to be used within a CLS-wrapped context */ function opportunisticallyImportAndUpdateInline(records: GrouparooRecord[]): Promise<{ recordId: string; error: string; success: boolean; }[]>; /** * The method you'll be using to create records with arbitrary data. * Hash looks like {email: "person@example.com", id: 123} * * This method today always returns a record by finding it or making a a new one... unless it throws because the source isn't allowed to make new records. */ function findOrCreateByUniqueRecordProperties(hashes: { [key: string]: (string | number | boolean | Date)[]; }[], referenceIds: string[], source?: boolean | Source, includeAllProperties?: boolean): Promise<{ referenceId: string; record: GrouparooRecord; isNew: boolean; error: NodeJS.ErrnoException; hash: Record<string, (string | number | boolean | Date)[]>; uniquePropertiesHash: Record<string, (string | number | boolean | Date)[]>; }[]>; /** * Mark many GrouparooRecords and all of their properties as pending */ function markPendingByIds(recordIds: string[], includeProperties?: boolean): Promise<void>; /** * Look for records by model that don't have a primary key property and are done importing/exporting. */ function getRecordsToDestroy(): Promise<GrouparooRecord[]>; /** * Import records whose primary key property has not been confirmed after a certain date. */ function confirmExistence(limit: number, fromDate: Date, sourceId?: string): Promise<number>; /** * Merge 2 GrouparooRecords, favoring the first GrouparooRecord */ function merge(record: GrouparooRecord, otherRecord: GrouparooRecord): Promise<GrouparooRecord>; function computeRecordsValidity(records: GrouparooRecord[]): Promise<void>; /** * Find records that are not ready but whose properties are and make them ready. * Then, process the related imports. */ function makeReady(limit?: number): Promise<GrouparooRecord[]>; function makeExports(recordIds: string[], toExport: boolean, force?: boolean): Promise<GrouparooRecord[]>; }