UNPKG

@hotmeshio/hotmesh

Version:

Serverless Workflow

143 lines (141 loc) 4.42 kB
import { HotMesh } from '../hotmesh'; import { SearchService } from '../search'; import { WorkflowSearchOptions } from '../../types/meshflow'; /** * The Search module provides methods for reading and * writing record data to a workflow. The instance * methods exposed by this class are available * for use from within a running workflow. The following example * uses search to set a `name` field and increment a * `counter` field. The workflow returns the incremented value. * * @example * ```typescript * //searchWorkflow.ts * import { workflow } from '@hotmeshio/hotmesh'; * export async function searchExample(name: string): Promise<{counter: number}> { * const search = await workflow.search(); * await search.set({ name }); * const newCounterValue = await search.incr('counter', 1); * return { counter: newCounterValue }; * } * ``` */ export declare class Search { /** * @private */ jobId: string; /** * @private */ searchSessionId: string; /** * @private */ searchSessionIndex: number; /** * @private */ hotMeshClient: HotMesh; /** * @private */ search: SearchService<any> | null; /** * @private */ cachedFields: Record<string, string>; /** * @private */ constructor(workflowId: string, hotMeshClient: HotMesh, searchSessionId: string); /** * Prefixes the key with an underscore to keep separate from the * activity and job history (and searchable via HKEYS) * * @private */ safeKey(key: string): string; /** * For those deployments with search configured, this method * will configure the search index with the provided schema. * * @private * @example * const search = { * index: 'my_search_index', * prefix: ['my_workflow_prefix'], * schema: { * field1: { type: 'TEXT', sortable: true }, * field2: { type: 'NUMERIC', sortable: true } * } * } * await Search.configureSearchIndex(hotMeshClient, search); */ static configureSearchIndex(hotMeshClient: HotMesh, search?: WorkflowSearchOptions): Promise<void>; /** * Returns an array of search indexes ids * * @example * const searchIndexes = await Search.listSearchIndexes(hotMeshClient); */ static listSearchIndexes(hotMeshClient: HotMesh): Promise<string[]>; /** * increments the index to return a unique search session guid when * calling any method that produces side effects (changes the value) * @private */ getSearchSessionGuid(): string; /** * Sets the fields listed in args. Returns the * count of new fields that were set (does not * count fields that were updated) * * @example * const search = await workflow.search(); * const count = await search.set({ field1: 'value1', field2: 'value2' }); */ set(...args: any[]): Promise<number>; /** * Returns the value of the record data field, given a field id * * @example * const search = await workflow.search(); * const value = await search.get('field1'); */ get(id: string): Promise<string>; /** * Returns the values of all specified fields in the HASH stored at key. */ mget(...args: string[]): Promise<string[]>; /** * Deletes the fields provided as args. Returns the * count of fields that were deleted. * * @example * const search = await workflow.search(); * const count = await search.del('field1', 'field2', 'field3'); */ del(...args: string[]): Promise<number | void>; /** * Increments the value of a float field by the given amount. Returns the * new value of the field after the increment. Pass a negative * number to decrement the value. * * @example * const search = await workflow.search(); * const count = await search.incr('field1', 1.5); */ incr(key: string, val: number): Promise<number>; /** * Multiplies the value of a field by the given amount. Returns the * new value of the field after the multiplication. NOTE: * this is exponential multiplication. * * @example * const search = await workflow.search(); * const product = await search.mult('field1', 1.5); */ mult(key: string, val: number): Promise<number>; }