@node-in-layers/core
Version:
The core library for the Node In Layers rapid web development framework.
166 lines (165 loc) • 9.01 kB
TypeScript
import z, { ZodType } from 'zod';
import { ModelInstanceFetcher } from 'functional-models';
import { Config, LayerDescription, LogLevel, LogLevelNames, ErrorObject, CrossLayerProps, NilFunction, NilAnnotatedFunction, AnnotatedFunctionProps } from './types.js';
declare const featurePassThrough: <T extends any[], U>(fn: (...args: T) => U) => ((...args: T) => U) & ((...args: T) => U);
declare const validateConfig: (config: Partial<Config>) => void;
declare const getLogLevelName: (logLevel: LogLevel) => "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "SILENT";
declare const getLogLevelNumber: (logLevel: LogLevelNames) => LogLevel;
declare const getLayersUnavailable: (allLayers: readonly LayerDescription[]) => (layer: string) => string[];
declare const isConfig: <TConfig extends Readonly<{
systemName: string;
environment: string;
"@node-in-layers/core": Readonly<{
logging: {
logLevel: LogLevelNames;
logFormat: import("./types.js").LogFormat | readonly import("./types.js").LogFormat[];
maxLogSizeInCharacters?: number | undefined;
tcpLoggingOptions?: Readonly<{
url: string;
headers?: Record<string, string | object> | undefined;
}> | undefined;
customLogger?: Readonly<{
getLogger: (context: Readonly<{
config: Readonly<any>;
rootLogger: Readonly<any>;
constants: {
environment: string;
workingDirectory: string;
runtimeId: string;
};
}>, props?: {
ids?: readonly Readonly<Record<string, string>>[] | undefined;
data?: Record<string, any> | undefined;
} | undefined) => import("./types.js").HighLevelLogger;
}> | undefined;
getFunctionWrapLogLevel?: ((layerName: string, functionName?: string | undefined) => LogLevelNames) | undefined;
ignoreLayerFunctions?: Record<string, boolean | Record<string, boolean | Record<string, boolean>>> | undefined;
};
layerOrder: readonly LayerDescription[];
apps: readonly Readonly<{
name: string;
description?: string | undefined;
services?: Readonly<{
create: (context: any) => import("./types.js").MaybePromise<object>;
}> | undefined;
features?: Readonly<{
create: (context: any) => import("./types.js").MaybePromise<object>;
}> | undefined;
globals?: Readonly<{
create: (context: Readonly<{
config: Readonly<any>;
rootLogger: Readonly<{
getLogger: (context: Readonly<{
config: Readonly<any>;
rootLogger: Readonly<any>;
constants: {
environment: string;
workingDirectory: string;
runtimeId: string;
};
}>, props?: {
ids?: readonly Readonly<Record<string, string>>[] | undefined;
data?: Record<string, any> | undefined;
} | undefined) => import("./types.js").HighLevelLogger;
}>;
constants: {
environment: string;
workingDirectory: string;
runtimeId: string;
};
}>) => Promise<any>;
}> | undefined;
models?: Record<string, Readonly<{
create: <T extends Readonly<{
[s: string]: any;
}>, TModelExtensions extends object = object, TModelInstanceExtensions extends object = object>(modelProps: Readonly<{
context: Readonly<{
config: Readonly<any>;
rootLogger: Readonly<{
getLogger: (context: Readonly<any>, props?: {
ids?: readonly Readonly<Record<string, string>>[] | undefined;
data?: Record<string, any> | undefined;
} | undefined) => import("./types.js").HighLevelLogger;
}>;
constants: {
environment: string;
workingDirectory: string;
runtimeId: string;
};
}>;
Model: import("functional-models/types.js").ModelFactory<object, object>;
fetcher: ModelInstanceFetcher<object, object>;
getModel: <T_1 extends Readonly<{
[s: string]: any;
}>>(namespace: string, modelName: string) => () => import("functional-models/types.js").ModelType<T_1, object, object>;
}>) => import("functional-models/types.js").ModelType<T, TModelExtensions, TModelInstanceExtensions>;
}>> | undefined;
}>[];
modelFactory?: string | undefined;
modelCruds?: boolean | undefined;
customModelFactory?: {
[x: string]: {
[x: string]: string | [string, string] | [string, string, any[]];
};
} | undefined;
}>;
}>>(obj: any) => obj is TConfig;
declare const getNamespace: (packageName: string, app?: string) => string;
declare const DoNothingFetcher: ModelInstanceFetcher;
/**
* Creates a standardized error object for consistent error handling across the application.
* This function handles all the logic for converting different error types to the standard format.
*
* @param code - A unique string code for the error
* @param message - A user-friendly error message
* @param error - Optional error object or details (can be any type - will be properly handled)
* @returns A standardized error object conforming to the ErrorObject type
*/
declare const createErrorObject: (code: string, message: string, error?: unknown) => ErrorObject;
declare const isErrorObject: (value: unknown) => value is Readonly<{
error: Readonly<{
code: string;
message: string;
details?: string | undefined;
data?: Record<string, import("functional-models/types.js").JsonAble> | undefined;
trace?: string | undefined;
cause?: Readonly<any> | undefined;
}>;
}>;
declare const combineCrossLayerProps: (crossLayerPropsA: CrossLayerProps, crossLayerPropsB: CrossLayerProps) => {
logging: {
ids: Readonly<Record<string, string>>[];
} & Pick<{
ids?: readonly Readonly<Record<string, string>>[] | undefined;
}, never>;
};
/**
* Zod schema for ErrorObject (exported for external validation/unions)
*/
export declare const errorObjectSchema: () => z.ZodType<ErrorObject>;
/**
* Creates a crossLayerProps available function that is also annotated with Zod.
* @param props - The arguments
* @param implementation - Your function
* @returns A function with a "schema" property
*/
declare const annotatedFunction: <TProps extends Readonly<{
[s: string]: import("functional-models/types.js").JsonAble;
}>, TOutput extends void | Readonly<{
[s: string]: import("functional-models/types.js").JsonAble;
}>, TImplementation extends NilFunction<TProps, TOutput> = NilFunction<TProps, TOutput>>(props: AnnotatedFunctionProps<TProps, TOutput>, implementation: TImplementation) => NilFunction<TProps, TOutput> & Readonly<{
functionName: string;
domain: string;
schema: z.ZodFunction<z.ZodTuple<[z.ZodType<TProps, unknown, z.core.$ZodTypeInternals<TProps, unknown>>, z.ZodType<CrossLayerProps<object> | undefined, unknown, z.core.$ZodTypeInternals<CrossLayerProps<object> | undefined, unknown>>], z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | null>, z.ZodType<import("./types.js").NilFunctionReturn<TOutput>, unknown, z.core.$ZodTypeInternals<import("./types.js").NilFunctionReturn<TOutput>, unknown>>>;
}> & TImplementation;
/**
* Creates standardized annotation function arguments. already typed.
* @param args - Arguments.
* @returns An AnnotatedFunctionProps object.
*/
declare const annotationFunctionProps: <TProps extends Readonly<{
[s: string]: import("functional-models/types.js").JsonAble;
}>, TOutput extends void | Readonly<{
[s: string]: import("functional-models/types.js").JsonAble;
}>>(args: AnnotatedFunctionProps<TProps, TOutput>) => AnnotatedFunctionProps<TProps, TOutput>;
export { createErrorObject, featurePassThrough, getLogLevelName, validateConfig, getLayersUnavailable, isConfig, getNamespace, DoNothingFetcher, getLogLevelNumber, isErrorObject, combineCrossLayerProps, annotatedFunction, annotationFunctionProps, };