UNPKG

alepha

Version:

Alepha is a convention-driven TypeScript framework for building robust, end-to-end type-safe applications, from serverless APIs to full-stack React apps.

167 lines (166 loc) 5.58 kB
import * as _alepha_core1 from "alepha"; import { Alepha, Descriptor, KIND, TStringOptions } from "alepha"; import "dayjs/plugin/relativeTime.js"; import dayjsDuration from "dayjs/plugin/duration.js"; import "dayjs/plugin/utc.js"; import "dayjs/plugin/timezone.js"; import "dayjs/plugin/localizedFormat.js"; import "dayjs/locale/ar.js"; import "dayjs/locale/fr.js"; import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs"; import * as typebox0 from "typebox"; import * as dayjs_plugin_duration0 from "dayjs/plugin/duration"; //#region src/providers/DateTimeTypeProvider.d.ts declare const datetime: (options?: TStringOptions) => typebox0.TCodec<typebox0.TString, DayjsApi.Dayjs>; declare const date: (options?: TStringOptions) => typebox0.TCodec<typebox0.TString, DayjsApi.Dayjs>; declare const time: (options?: TStringOptions) => typebox0.TCodec<typebox0.TString, DayjsApi.Dayjs>; declare const duration: (options?: TStringOptions) => typebox0.TCodec<typebox0.TString, dayjs_plugin_duration0.Duration>; declare const isDateTimeSchema: (schema: unknown) => schema is ReturnType<typeof datetime>; declare const isDateSchema: (schema: unknown) => schema is ReturnType<typeof date>; declare const isTimeSchema: (schema: unknown) => schema is ReturnType<typeof time>; declare const isDurationSchema: (schema: unknown) => schema is ReturnType<typeof duration>; //#endregion //#region src/providers/DateTimeProvider.d.ts type DateTimeApi = typeof dayjs; type DateTime = DayjsApi.Dayjs; type Duration = dayjsDuration.Duration; type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType]; declare const dayjs: typeof DayjsApi; declare class DateTimeProvider { static PLUGINS: Array<PluginFunc<any>>; protected alepha: Alepha; protected ref: DateTime | null; protected readonly timeouts: Timeout[]; protected readonly intervals: Interval[]; constructor(); protected readonly onStart: _alepha_core1.HookDescriptor<"start">; protected readonly onStop: _alepha_core1.HookDescriptor<"stop">; /** * Create a new UTC DateTime instance. */ utc(date: string | number | Date | Dayjs | null | undefined): DateTime; /** * Create a new DateTime instance. */ of(date: string | number | Date | Dayjs | null | undefined): DateTime; /** * Get the current date. */ now(): DateTime; /** * Get the current date as a string. * * @param date */ toISOString(date?: Date | string | DateTime): string; /** * Get the current date as a string. */ nowISOString(): string; /** * Get the current date as a string. * * @protected */ protected getCurrentDate(): DateTime; /** * Create a new Duration instance. */ duration: (duration: DurationLike, unit?: ManipulateType) => Duration; isDurationLike(value: unknown): value is DurationLike; /** * Return a promise that resolves after the next tick. * It uses `setTimeout` with 0 ms delay. */ tick(): Promise<void>; /** * Wait for a certain duration. * * You can clear the timeout by using the `AbortSignal` API. * Aborted signal will resolve the promise immediately, it does not reject it. */ wait(duration: DurationLike, options?: { signal?: AbortSignal; now?: number; }): Promise<void>; createInterval(run: () => unknown, distance: DurationLike): Interval; /** * Run a callback after a certain duration. */ createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout; clearTimeout(timeout: Timeout): void; /** * Run a function with a deadline. */ deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>; /** * Add time to the current date. */ travel(duration: DurationLike, unit?: ManipulateType): Promise<void>; /** * Stop the time. */ pause(): DateTime; /** * Reset the reference date. */ reset(): void; } interface Interval { timer?: any; duration: number; run: () => unknown; } interface Timeout { now: number; timer?: any; duration: number; callback: () => void; clear: () => void; } //#endregion //#region src/descriptors/$interval.d.ts /** * Run a function periodically. * It uses the `setInterval` internally. * It starts by default when the context starts and stops when the context stops. */ declare const $interval: { (options: IntervalDescriptorOptions): IntervalDescriptor; [KIND]: typeof IntervalDescriptor; }; interface IntervalDescriptorOptions { /** * The interval handler. */ handler: () => unknown; /** * The interval duration. */ duration: DurationLike; } declare class IntervalDescriptor extends Descriptor<IntervalDescriptorOptions> { protected readonly dateTimeProvider: DateTimeProvider; called: number; protected onInit(): void; } //#endregion //#region src/index.d.ts declare module "alepha" { interface TypeProvider { datetime: typeof datetime; date: typeof date; time: typeof time; duration: typeof duration; } interface TypeGuard { isDateTime: typeof isDateTimeSchema; isDate: typeof isDateSchema; isTime: typeof isTimeSchema; isDuration: typeof isDurationSchema; } } declare const AlephaDateTime: _alepha_core1.Service<_alepha_core1.Module<{}>>; //#endregion export { $interval, AlephaDateTime, DateTime, DateTimeApi, DateTimeProvider, Duration, DurationLike, Interval, IntervalDescriptor, IntervalDescriptorOptions, Timeout, date, datetime, dayjs, duration, isDateSchema, isDateTimeSchema, isDurationSchema, isTimeSchema, time }; //# sourceMappingURL=index.d.ts.map