///
import type { AppRoute } from '@ts-rest/core';
import type { AppRouter } from '@ts-rest/core';
import type { DatabasePool } from 'slonik';
import type { FastifyInstance } from 'fastify';
import type { FastifyReply } from 'fastify';
import type { FastifyRequest } from 'fastify';
import type { InputMigrations } from 'umzug';
import type { Job } from 'bullmq';
import type { JobsOptions } from 'bullmq';
import type { ListSqlToken } from 'slonik';
import type { Logger as Logger_2 } from 'pino';
import { Meter } from '@opentelemetry/api/build/src';
import { mock } from 'node:test';
import type { PrimitiveValueExpression } from 'slonik';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus/build/src';
import type { QueryResult } from 'slonik';
import type { QueryResultRow } from 'slonik';
import { Queue } from 'bullmq';
import { Redis } from 'ioredis';
import type { Result } from 'neverthrow';
import { SpanExporter as SdkTraceBaseSpanExporter } from '@opentelemetry/sdk-trace-base/build/src';
import type { ServerInferRequest } from '@ts-rest/core';
import type { ServerInferResponses } from '@ts-rest/core';
import { Span } from '@opentelemetry/api/build/src';
import { SpanOptions } from '@opentelemetry/api/build/src';
import { SpanStatusCode } from '@opentelemetry/api/build/src';
import { Tracer } from '@opentelemetry/api/build/src';
import { Umzug } from 'umzug';
import type { UnnestSqlToken } from 'slonik';
import { Worker } from 'bullmq';
import { z } from 'zod';
import { ZodBranded } from 'zod';
import { ZodDate } from 'zod';
import { ZodEffects } from 'zod';
import type { ZodError } from 'zod';
import { ZodNumber } from 'zod';
import { ZodString } from 'zod';
import type { ZodType } from 'zod';
import type { ZodTypeAny } from 'zod';
import type { ZodTypeDef } from 'zod';
import { ZodUnion } from 'zod';
declare type AppRouteImplementation = (input: ServerInferRequest & {
request: FastifyRequest;
reply: FastifyReply;
}) => Promise>;
declare function buildMigration({ migrationFiles, database, }: {
migrationFiles: InputMigrations>;
database: Database;
}): Umzug>;
export declare type Cache = Redis;
declare type ColumnDefinition = [keyof TRecord, TypeNameIdentifier];
/**
* Combines two or more arrays.
* This method returns a new array without modifying any existing arrays.
* @param items - Additional arrays and/or items to add to the end of the array.
*/
declare function concat(...items: [NonEmptyArray, ...TL[][]]): NonEmptyArray;
export declare function createCacheStorage({ dependencyStore, config, }: Dependencies): Promise;
export declare function createDatabase({ config, dependencyStore, }: Dependencies_2): Promise;
export declare function createDateProvider(): DateProvider;
export declare function createDependencyStore>(initialProviders?: Partial & TExtendedStore>): DependencyStore;
declare function createFailingQueryMockDatabase(): {
query: MockQuery;
database: DatabasePool;
};
export declare function createHttpServer({ config, dependencyStore, appRouter, }: {
config: {
name: string;
version: string;
logLevel: LogLevel;
secret: string;
};
dependencyStore: DependencyStore;
appRouter: TAppRouter;
}): Promise;
export declare type CreateLogger = (serviceName: string) => Logger;
export declare function createLoggerProvider({ config, }: {
config: {
logLevel: LogLevel;
};
}): CreateLogger;
declare function createMockDatabase(values: readonly QueryResultRow[]): {
query: MockQuery;
database: DatabasePool;
};
export declare function createMockLoggerProvider(): CreateLogger;
declare function createNonEmptyArraySchema(schema: T): z.ZodArray;
export declare function createShutdownManager({ config, dependencyStore, exit, }: Dependencies_3): {
listenToProcessEvents: () => void;
shutdown: (shouldExit?: boolean) => Promise;
};
export declare function createTaskScheduling({ config, dependencyStore, }: Dependencies_4): TaskScheduling;
export declare function createTelemetry({ config, dependencyStore, }: {
config: {
name: string;
version: string;
envName: string;
tracingSampling: number;
};
dependencyStore: DependencyStore;
}): Telemetry;
export declare type Database = DatabasePool;
export declare const databaseMigration: {
buildMigration: typeof buildMigration;
extractMigrations: typeof extractMigrations;
};
export declare type DateProvider = {
nowAsNumber: () => number;
nowAsDate: () => Date;
};
export declare const dateTime: {
validDateSchema: ZodBranded, "ValidDateTime">;
validDateTimeSchema: ZodBranded, string | number | Date, string | number | Date>, string, string | number | Date>, "ValidDateTime">;
};
declare type DefaultSdkStore = {
logger: CreateLogger;
telemetry: Telemetry;
date: DateProvider;
cache: Cache;
taskScheduling: TaskScheduling;
database: Database;
httpServer: HttpServer;
};
declare type Dependencies = {
dependencyStore: DependencyStore;
config: {
redisUrl: string;
};
};
declare type Dependencies_2 = {
config: {
databaseIdleTimeout: number;
databaseStatementTimeout: number;
databaseMaximumPoolSize: number;
databaseUrl: string;
};
dependencyStore: DependencyStore;
};
declare type Dependencies_3 = {
config: {
name: string;
version: string;
};
dependencyStore: DependencyStore;
exit: (statusCode: number) => void;
};
declare type Dependencies_4 = {
config: {
name: string;
redisUrl: string;
};
dependencyStore: DependencyStore;
};
export declare type DependencyStore> = {
set(name: TKey, provider: Fallback): void;
get(name: TKey): Fallback;
};
declare function dropAllTables(): Readonly<{
parser: z.ZodUnknown;
type: "SLONIK_TOKEN_QUERY";
sql: string;
values: PrimitiveValueExpression[];
}>;
/**
* Do not use this in production, as it assumes the file structure
* Should only be used in tests
*/
declare function extractMigrations(database: Database, migrationsFilesAbsolutePaths: string[]): Promise<{
name: string;
up(): Promise;
down(): Promise;
}[]>;
declare type Fallback = K extends keyof DefaultSdkStore ? DefaultSdkStore[K] : K extends keyof TExtendedStore ? TExtendedStore[K] : never;
/**
* Returns the elements of an array that meet the condition specified in a callback function.
* @param input - The input array
* @param predicate - A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
*/
declare function filter(input: NonEmptyArray, predicate: (value: T, index: number, array: T[]) => boolean): Option>;
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param input - The input array
* @param depth - The maximum recursion depth
*/
declare function flat(input: NonEmptyArray, depth?: number): NonEmptyArray;
/**
* Calls a defined callback function on each element of an array. Then, flattens the result into
* a new array.
* This is identical to a map followed by flat with depth 1.
*
* @param input - The input array
* @param callback - A function that accepts up to three arguments. The flatMap method calls the
* callback function one time for each element in the array.
*/
declare function flatMap(input: NonEmptyArray, predicate: (value: T, index: number, array: T[]) => U | readonly U[]): NonEmptyArray;
declare function fromElements(...input: NonEmptyArray): NonEmptyArray;
export declare type HttpReply = FastifyReply;
export declare type HttpRequest = FastifyRequest;
export declare type HttpServer = FastifyInstance;
declare function isNonEmptyArray(input: T[] | readonly T[]): input is NonEmptyArray;
export declare type Logger = Logger_2;
export declare type LogLevel = "fatal" | "error" | "warn" | "info" | "debug" | "trace";
declare function makeNonEmptyArray(input: T[]): Option>;
/**
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
* @param input - The input array
* @param callbackfn - A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
*/
declare function map(input: NonEmptyArray, predicate: (value: T, index: number, array: T[]) => U): NonEmptyArray;
export { Meter }
declare type MockQuery = ReturnType Promise>>>;
declare type None = {
kind: "none";
};
export declare type NonEmptyArray = [T, ...T[]];
export declare const nonEmptyArray: {
concat: typeof concat;
createNonEmptyArraySchema: typeof createNonEmptyArraySchema;
filter: typeof filter;
flat: typeof flat;
flatMap: typeof flatMap;
fromElements: typeof fromElements;
isNonEmptyArray: typeof isNonEmptyArray;
makeNonEmptyArray: typeof makeNonEmptyArray;
map: typeof map;
reverse: typeof reverse;
slice: typeof slice;
};
export declare const number: {
finiteSchema: ZodBranded;
negativeSafeIntegerSchema: ZodBranded;
negativeSchema: ZodBranded;
nonNegativeSafeIntegerSchema: ZodBranded;
nonNegativeSchema: ZodBranded;
nonPositiveSafeIntegerSchema: ZodBranded;
nonPositiveSchema: ZodBranded;
positiveSafeIntegerSchema: ZodBranded;
positiveSchema: ZodBranded;
safeIntegerSchema: ZodBranded;
};
declare type Option = Some | None;
/**
* validates an input against a zod schema and return a result from it
* @param schema - zod schema
* @param input - input
*/
declare function parse(schema: ZodType, input: unknown): Result>;
/**
* validates a string to ensure it is a number within a range
* @param valueAsString - input
* @param range - inclusive ranges to limit the value.
* @returns an option with the numeric value if the input is valid
*/
declare function parseStringMinMax(valueAsString: string, range: {
min: number;
max: number;
}): Option;
/**
* validates a string to ensure it is an integer within a range
* @param valueAsString - input
* @param range - inclusive ranges to limit the value.
* @returns an option with the numeric value if the input is valid
*/
declare function parseStringMinMaxInteger(valueAsString: string, range: {
min: number;
max: number;
}): Option;
/**
* validates a string to ensure it is a `ms` compatible value
* @param valueAsString - input
* @returns an option with the numeric value if the input is valid
*/
declare function parseStringMs(valueAsString: string): Option;
/**
* create columns and rows data for slonik bulk insert that are efficient and type-safe
* @example
* const res = prepareBulkInsert(
* [
* ["id", "int4"],
* ["name", "text"]
* ],
* [ \{ id: 1, name: "foo" \}, \{ id: 2, name: "bar" \} ],
* record =\> (\{ ...record \})
* ).unwrap() // example only, please handle errors
*
* await connection.query(sql.unsafe\`
* insert into "table"($\{res.columns\})
* select * from $\{res.rows\}
* \`);
* @param columnDefinitions - tuple array of the records keys and their postgres type
* @param records - records to insert
* @param iteratee - map method on every record to match the database shape
*/
declare function prepareBulkInsert, TRecord>(columnDefinitions: ColumnDefinition[], records: TRecord[], iteratee: (record: TRecord, i: number) => TDatabaseRecord): PrepareBulkInsertResult;
export declare type PrepareBulkInsertError = {
reason: "invalidHeaders";
error: ZodError;
} | {
reason: "invalidRecordDate";
error: ZodError;
};
export declare type PrepareBulkInsertResult = Result<{
columns: ListSqlToken;
rows: UnnestSqlToken;
}, PrepareBulkInsertError>;
export { PrometheusExporter }
/**
* Reverses the elements in an array in place.
* This method mutates the array and returns a reference to the same array.
* @param input - The input array
*/
declare function reverse(input: NonEmptyArray): NonEmptyArray;
export declare type RouterImplementation = {
[TKey in keyof T]: T[TKey] extends AppRouter ? RouterImplementation : T[TKey] extends AppRoute ? AppRouteImplementation : never;
};
export { SdkTraceBaseSpanExporter }
export declare type ShutdownManager = {
listenToProcessEvents: () => void;
shutdown: (shouldExit?: boolean) => Promise;
};
/**
* Returns a copy of a section of an array.
* For both start and end, a negative index can be used to indicate an offset from the end of the array.
* For example, -2 refers to the second to last element of the array.
* @param input - The input array
* @param start - The beginning index of the specified portion of the array.
* If start is undefined, then the slice begins at index 0.
* @param end - The end index of the specified portion of the array. This is exclusive of the element at the index 'end'.
* If end is undefined, then the slice extends to the end of the array.
*/
declare function slice(input: NonEmptyArray, start?: number, end?: number): Option>;
export declare const slonikHelpers: {
createFailingQueryMockDatabase: typeof createFailingQueryMockDatabase;
createMockDatabase: typeof createMockDatabase;
dropAllTables: typeof dropAllTables;
prepareBulkInsert: typeof prepareBulkInsert;
};
declare type Some = {
kind: "some";
data: T;
};
export { Span }
export { SpanOptions }
export { SpanStatusCode }
declare type StartSpanCallback = (span: Span) => Promise | TResolved;
declare function stringifiedMs(): z.ZodEffects, number, string>;
declare function stringifiedNumber({ integer, min, max, }: {
integer: boolean;
min: number;
max: number;
}): z.ZodEffects, number, string>;
export declare type TaskScheduling = {
createTask(taskName: string, processFunction: (job: Job) => Promise, workersCount?: number): Promise<(payloads: TPayload[], options?: JobsOptions) => Promise>;
allWorkers: Worker[];
allQueues: Queue[];
allConnections: Cache[];
};
export declare type Telemetry = {
metrics: Meter;
metricReader: PrometheusExporter;
tracer: Tracer;
startSpan(name: string, options: SpanOptions | undefined, callback: StartSpanCallback): Promise;
shutdown(): Promise;
};
export { Tracer }
declare type TypeNameIdentifier = "bool" | "bytea" | "float4" | "float8" | "int2" | "int4" | "int8" | "json" | "text" | "timestamptz" | "uuid";
export declare type ValidDate = z.infer;
declare const validDateSchema: z.ZodBranded, "ValidDateTime">;
export declare type ValidDateTime = z.infer;
declare const validDateTimeSchema: z.ZodBranded, string | number | Date, string | number | Date>, string, string | number | Date>, "ValidDateTime">;
export declare const zodHelpers: {
parse: typeof parse;
parseStringMinMax: typeof parseStringMinMax;
parseStringMinMaxInteger: typeof parseStringMinMaxInteger;
parseStringMs: typeof parseStringMs;
stringifiedMs: typeof stringifiedMs;
stringifiedNumber: typeof stringifiedNumber;
};
export { }