@novu/framework
Version:
The Code-First Notifications Workflow SDK.
67 lines (63 loc) • 2.4 kB
text/typescript
import { ValidateFunction as ValidateFunction$1 } from 'ajv';
import { ParseReturnType } from 'zod';
import { S as Schema, F as FromSchemaUnvalidated, a as FromSchema, J as JsonSchema } from './base.schema.types-BApIn9jr.cjs';
type ImportRequirement = {
/**
* The name of the dependency.
*
* This is a necessary duplicate as ESM does not provide a consistent API for
* reading the name of a dependency that can't be resolved.
*
* @example
* ```typescript
* 'module-name'
* ```
*/
name: string;
/**
* The import statement for the required dependency. An explicit `import('module-name')`
* call with a static module string is necessary to ensure that the bundler will make
* the dependency available for usage after tree-shaking. Without a static string,
* tree-shaking may aggressively remove the import, making it unavailable.
*
* This syntax is required during synchronous declaration (e.g. on a class property),
* but should only be awaited when you can handle a runtime import error.
*
* @example
* ```typescript
* import('module-name')
* ```
*/
import: Promise<{
default: unknown;
} & Record<string, unknown>>;
/**
* The required exports of the dependency. The availability of these exports are
* checked by the import validator to verify the dependency is installed.
*
* @example
* ```typescript
* ['my-export']
* ```
*/
exports: readonly string[];
};
type ValidateFunction<T = unknown> = ValidateFunction$1<T> | ((data: T) => ParseReturnType<T>);
type ValidationError = {
path: string;
message: string;
};
type ValidateResult<T> = {
success: false;
errors: ValidationError[];
} | {
success: true;
data: T;
};
type Validator<T_Schema extends Schema = Schema> = {
validate: <T_Unvalidated extends Record<string, unknown> = FromSchemaUnvalidated<T_Schema>, T_Validated extends Record<string, unknown> = FromSchema<T_Schema>>(data: T_Unvalidated, schema: T_Schema) => Promise<ValidateResult<T_Validated>>;
canHandle: (schema: Schema) => Promise<boolean>;
transformToJsonSchema: (schema: T_Schema) => Promise<JsonSchema>;
requiredImports: readonly ImportRequirement[];
};
export type { ValidateResult as V, ValidateFunction as a, ValidationError as b, Validator as c };