UNPKG

@energyweb/node-red-contrib-green-proof-worker

Version:

## Peer dependencies

90 lines (89 loc) 3.93 kB
import * as z from 'zod'; import type { Api } from './api'; import type { NodeMessage } from './types'; export type SendBuilder = { setTopic(topic: string): SendBuilder; getMessage(): Record<string, unknown>; /** * Payload is not deeply-merged with the input message payload, * but shallow-merged. */ addPayload(payload: Record<string, any>): SendBuilder; sendToOutput(index: number): void; }; export declare const NodeEnvConfig: z.ZodObject<{ EWX_SOLUTION_ID: z.ZodOptional<z.ZodString>; EWX_SOLUTION_GROUP_ID: z.ZodOptional<z.ZodString>; EWX_WORKLOGIC_ID: z.ZodOptional<z.ZodString>; EWX_SQLITE_PATH: z.ZodOptional<z.ZodString>; EWX_WORKER_ADDRESS: z.ZodOptional<z.ZodString>; BASE_URL_CDN: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { BASE_URL_CDN?: string | undefined; EWX_SOLUTION_ID?: string | undefined; EWX_SOLUTION_GROUP_ID?: string | undefined; EWX_WORKLOGIC_ID?: string | undefined; EWX_SQLITE_PATH?: string | undefined; EWX_WORKER_ADDRESS?: string | undefined; }, { BASE_URL_CDN?: string | undefined; EWX_SOLUTION_ID?: string | undefined; EWX_SOLUTION_GROUP_ID?: string | undefined; EWX_WORKLOGIC_ID?: string | undefined; EWX_SQLITE_PATH?: string | undefined; EWX_WORKER_ADDRESS?: string | undefined; }>; export declare const BaseUrlsConfig: z.ZodObject<{ kafka_url: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>; kafka_proxy_url: z.ZodOptional<z.ZodString>; indexer_url: z.ZodOptional<z.ZodString>; rpc_url: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { kafka_url?: string | string[] | undefined; kafka_proxy_url?: string | undefined; indexer_url?: string | undefined; rpc_url?: string | undefined; }, { kafka_url?: string | string[] | undefined; kafka_proxy_url?: string | undefined; indexer_url?: string | undefined; rpc_url?: string | undefined; }>; export type NodeEnvConfig = z.infer<typeof NodeEnvConfig>; export declare abstract class Node<T extends z.ZodObject<any, any> | z.ZodUnion<any>> { nodeConfig: unknown; messageZod: T; api: Api; constructor(api: Api, nodeConfig: unknown, // this is NodeDef from node-red, but let's keep it unknown for convenience (we add custom types there) messageZod: T, { validateMessage }?: { validateMessage?: boolean; }); /** * Returns base_urls from a special endpoint maintained by EWF that contains configuration */ getBaseUrls(): Promise<z.infer<typeof BaseUrlsConfig>>; /** * Returns parsed `.__envConfig` from node's config. * node's config, is basically one entry in flow.json * Marketplace will be injecting that property to each node before node-red start * Note, that if `.__envConfig` is injected that way, even the slightest node change (through node-red GUI) removes that property * because it is unknown to node-red. */ getNodeEnvConfig(): NodeEnvConfig; /** * SendBuilder hides complexity of creating proper messages, and selecting output. * It is supposed to be used by all nodes to send messages to outputs * to ensure correct behavior. * * It uses message received on node input (passed manually), and then the payload should be only * >added< (not replaced!) to the input message. Optionally topic can be set. * * Note that if topic is not set explicitly, it will be removed (because topic is used * to describe what the node receiving it should do with the message, so it's not meant to be passed around * like message payload). */ sendBuilder(inputMessage: NodeMessage<any>): SendBuilder; abstract onInput(message: z.infer<T>): void | Promise<void>; onDestroy?(): void | Promise<void>; handleMaybePromise<T>(maybePromiseCb: () => (T | Promise<T>), done: (err?: Error) => void): void; }