import { LogContext } from '@balena/jellyfish-logger'; import { AutumnDBSession, Contract, ContractData, Kernel, TypeContract } from 'autumndb'; import type { Operation } from 'fast-json-patch'; import type { Pool } from 'pg'; import { actions } from './actions'; import { contracts } from './contracts'; import * as errors from './errors'; import { PluginDefinition, PluginManager } from './plugin'; import { Consumer, Producer } from './queue'; import type { OnMessageEventHandler } from './queue/consumer'; import { Sync } from './sync'; import * as triggersLib from './triggers'; import type { Action, ActionPreRequest, ActionRequestContract, Map, TriggeredActionContract, WorkerContext } from './types'; import * as utils from './utils'; export { actions, triggersLib, errors, contracts, PluginDefinition, PluginManager, utils, Sync, }; export * as contractMixins from './contracts/mixins'; export { errors as syncErrors, Integration, IntegrationDefinition, IntegrationInitializationOptions, HttpRequestOptions, oauth, SequenceItem, } from './sync'; export { ActionContractDefinition, ActionDefinition, PluginIdentity, } from './plugin'; export { Consumer, errors as queueErrors, events, Producer, ProducerOptions, ProducerResults, } from './queue'; export * as testUtils from './test-utils'; export * from './types'; export { mirror } from './actions/mirror'; /** * As it's valid to specify a version without type, this guarantees that we * have a fully qualified versioned type. * * @param {string} type - name of type that may or may not contain a version suffix * @returns a type string that contains a version suffix */ export declare const ensureTypeHasVersion: (type: string) => string; /** * Returns an object that will include all links referenced in evaluated fields * in the type contract's schema. * * If no links are referenced in evaluated fields, the original object is returned * immediately. * * @param logContext - log context * @param kernel - kernel instance * @param session - session id * @param contract - contract to fill with links * @param typeContract - type contract * * @returns the contract with any links referenced in the evaluated fields * of it's type contract's schema. */ export declare function getObjectWithLinks | TContract, TContract extends Contract, TData extends ContractData>(logContext: LogContext, kernel: Kernel, session: AutumnDBSession, contract: PContract, typeContract: TypeContract): Promise; /** * Jellyfish worker library module. * * @module worker */ export declare class Worker { kernel: Kernel; pluginManager: PluginManager; pool: Pool; consumer: Consumer; producer: Producer; triggers: TriggeredActionContract[]; typeContracts: { [key: string]: TypeContract; }; session: AutumnDBSession; library: Map; id: string; sync: Sync; private cacheRefreshInterval; /** * @summary The Jellyfish Actions Worker * @class * @public * * @param kernel - kernel instance * @param session - worker privileged session id * @param pool - postgres pool * @param plugins - list of plugins * * @example * const worker = new Worker({ ... }, '4a962ad9-20b5-4dd8-a707-bf819593cc84', { * 'action-create-card': { ... }, * 'action-update-card': { ... }, * }, * pool, * [foobarPlugin()], * ); */ constructor(kernel: Kernel, session: AutumnDBSession, pool: Pool, plugins: PluginDefinition[]); /** * @summary Get this worker's unique id * @function * @public * * @returns unique worker id * * @example * const worker = new Worker({ ... }) * const id = worker.getId() * console.log(id) */ getId(): string; /** * @summary Initialize the worker * @function * @public * * @param logContext - log context * @param onMessageEventHandler - consumer event handler * * @example * const worker = new Worker({ ... }); * await worker.initialize(logContext, sync, eventHandlerFunction); */ initialize(logContext: LogContext, onMessageEventHandler: OnMessageEventHandler): Promise; fetchCacheData(logContext: LogContext): Promise; /** * @summary Get the action context * @function * @private * * @param logContext - log context * @returns action context * * @example * const actionContext = worker.getActionContext({ ... }); */ getActionContext(logContext: LogContext): WorkerContext; /** * @summary Insert a contract * @function * @public * * @param logContext - log context * @param insertSession - the Jellyfish session to insert the card with * @param typeContract - the type card for the card that will be inserted * @param options - insert options * @param object - The contract that should be inserted * * @returns inserted contract */ insertCard(logContext: LogContext, insertSession: AutumnDBSession, typeContract: TypeContract, options: { timestamp?: any; reason?: any; actor?: any; originator?: any; attachEvents?: any; }, object: Partial): Promise; /** * @summary Patch a contract * @function * @public * * @param logContext - log context * @param insertSession - the Jellyfish session to insert the contract with * @param typeContract - the type contract for the contract that will be inserted * @param options - options * @param contract - The contract that should be inserted * @param patch - json patch * * @returns inserted contract */ patchCard(logContext: LogContext, insertSession: AutumnDBSession, typeContract: TypeContract, options: { timestamp?: any; reason?: any; actor?: any; originator?: any; attachEvents?: any; }, contract: Partial, patch: Operation[]): Promise[]; }> | null>; /** * @summary Replace a contract * @function * @public * * @param logContext - log context * @param insertSession - The Jellyfish session to insert the contract with * @param typeContract - The type contract for the contract that will be inserted * @param options - options * @param object - the contract that should be inserted * * @returns replaced contract */ replaceCard(logContext: LogContext, insertSession: AutumnDBSession, typeContract: TypeContract, options: { timestamp?: any; reason?: any; actor?: any; originator?: any; attachEvents?: boolean; }, object: Partial>): Promise[]; }> | null>; /** * @summary Set all registered triggers * @function * @public * * @param logContext - log context * @param triggerContracts - triggers * * @example * const worker = new Worker({ ... }); * worker.setTriggers([ ... ]); */ setTriggers(logContext: LogContext, triggerContracts: TriggeredActionContract[]): void; /** * @summary Upsert a single registered trigger * @function * @public * * @param logContext - log context * @param contract - triggered action contract * * @example * const worker = new Worker({ ... }); * worker.upsertTrigger({ ... }); */ upsertTrigger(logContext: LogContext, contract: TriggeredActionContract): void; /** * @summary Remove a single registered trigger * @function * @public * * @param logContext - log context * @param id - id of trigger contract * * @example * const worker = new Worker({ ... }); * worker.removeTrigger('ed3c21f2-fa5e-4cdf-b862-392a2697abe4'); */ removeTrigger(logContext: LogContext, id: string): void; /** * @summary Get all registered triggers * @function * @public * * @returns trigger contracts * * @example * const worker = new Worker({ ... }); * const triggers = worker.getTriggers(); * console.log(triggers.length); */ getTriggers(): TriggeredActionContract[]; /** * @summary Set type contracts * @function * @public * * @param logContext - log context * @param typeContracts - type contracts * * @example * const worker = new Worker({ ... }); * worker.setTypeContracts([ ... ]); */ setTypeContracts(logContext: LogContext, typeContracts: TypeContract[]): void; /** * @summary Get type contracts * @function * @public * * @returns type contract map * * @example * const worker = new Worker({ ... }); * const typeContracts = worker.getTypeContracts(); * console.log(typeContracts.length); */ getTypeContracts(): { [key: string]: TypeContract; }; /** * @summary Execute the "pre" hook of an action request * @function * @public * * @description * The "pre" hook of an action request is meant to run before * the action request is enqueued. The hook may return a * modified set of arguments. * * @param session - session id * @param request - action request options * @returns request arguments */ pre(session: AutumnDBSession, request: ActionPreRequest): Promise; /** * @summary Execute an action request * @function * @public * * @description * You still need to make sure to post the execution event * upon completion. * * @param session - session id * @param request - action request contract * @returns action result * * @example * const worker = new Worker({ ... }); * const session = '4a962ad9-20b5-4dd8-a707-bf819593cc84'; * const result = await worker.execute(kernel, session, { ... }); * console.log(result.error); * console.log(result.data); */ execute(session: AutumnDBSession, request: ActionRequestContract): Promise; /** * @summary A pipeline function that runs standard logic for all contract * operations ran through the worker * @function * @private * * @param logContext - log context * @param session - session id * @param typeContract - the full type contract for the contract being inserted or updated * @param currentContract - The full contract prior to being updated, if it exists * @param options - options object * @param fn - an asynchronous function that will perform the operation */ private commit; generateFormulaTypeTriggers(logContext: LogContext, session: AutumnDBSession, typeContract: TypeContract): Promise; stop(): Promise; }