import type { Promisable } from './typeFest'; /** * Map from String to String (or ). * * Alternative: Record */ export interface StringMap { [k: string | number]: T | undefined; } /** * Convenience shorthand for `Record`. * Because `object` type is not safe/recommended to be used (e.g discouraged by eslint-typescript due to: https://github.com/microsoft/TypeScript/issues/21732) */ export type AnyObject = Record; export type AnyEnum = NumberEnum; export type NumberEnum = Record; export type StringEnum = Record; export type CreatedUpdated = { created: number; updated: number; }; export interface CreatedUpdatedId extends CreatedUpdated { id: string; } export type ObjectWithId = { id: string; }; export type PartialObjectWithId = { id?: string; }; export interface AnyPartialObjectWithId extends AnyObject, PartialObjectWithId { } export interface AnyObjectWithId extends AnyObject, ObjectWithId { } /** * Base interface for any Entity that was saved to DB. */ export type BaseDBEntity = { id: string; /** * unixTimestamp of when the entity was first created (in the DB). */ created: UnixTimestampNumber; /** * unixTimestamp of when the entity was last updated (in the DB). */ updated: UnixTimestampNumber; }; export type Saved = T & { id: string; created: UnixTimestampNumber; updated: UnixTimestampNumber; }; export type SavedId = T & { id: string; }; export type Unsaved = Omit & { id?: string; created?: UnixTimestampNumber; updated?: UnixTimestampNumber; }; export type UnsavedId = Omit & { id?: string; }; /** * Convenience type shorthand. * Because `Function` type is discouraged by eslint. */ export type AnyFunction = (...args: any[]) => T; export type AnyAsyncFunction = (...args: any[]) => Promise; export type AsyncFunction = () => Promise; export type AnyPromisableFunction = (...args: any[]) => Promisable; export type PromisableFunction = () => Promisable; /** * Symbol to indicate END of Sequence. */ export declare const END: unique symbol; /** * Symbol to indicate SKIP of item (e.g in AbortableMapper) */ export declare const SKIP: unique symbol; /** * Function which is called for every item in `input`. Expected to return a `Promise` or value. */ export type AsyncMapper = (input: IN, index: number) => OUT | PromiseLike; export type Mapper = (input: IN, index: number) => OUT; export declare const _passthroughMapper: Mapper; export declare const _passUndefinedMapper: Mapper; /** * Function that does nothings and returns `undefined`. */ export declare const _noop: (..._args: any[]) => undefined; export type Predicate = (item: T, index: number) => boolean; export type AsyncPredicate = (item: T, index: number) => boolean | PromiseLike; export type AbortablePredicate = (item: T, i: number) => boolean | typeof END; export type AbortableAsyncPredicate = (item: T, i: number) => Promisable; export type AbortableMapper = (input: IN, i: number) => OUT | typeof SKIP | typeof END; export type AbortableAsyncMapper = (input: IN, i: number) => Promisable; export declare const _passthroughPredicate: Predicate; export declare const _passNothingPredicate: Predicate; export interface BatchResult { /** * Array of successful executions. */ results: RES[]; /** * Returns empty array in case of 0 errors. */ errors: ERR[]; } /** * Like `keyof`, but for arrays. * * Based on: https://github.com/Microsoft/TypeScript/issues/20965#issuecomment-354858633 * * @example * * const arr = ['a', 'b'] as const * type Foo = ValuesOf // 'a' | 'b' */ export type ValuesOf = T[number]; /** * Based on: https://stackoverflow.com/a/49286056/4919972 * * @example * * type Foo = { a: string, b: number } * type ValueOfFoo = ValueOf // string | number */ export type ValueOf = T[keyof T]; export type KeyValueTuple = [key: K, value: V]; export type ObjectMapper = (key: keyof OBJ, value: Exclude, obj: OBJ) => OUT; export type ObjectPredicate = (key: keyof OBJ, value: Exclude, obj: OBJ) => boolean; /** * Allows to identify instance of Class by `instanceId`. */ export interface InstanceId { /** * Unique id of this instance of the Class. */ instanceId: string; } /** * Interface explicitly states that the value is an ISO Date string (without time). * * @example '2019-06-21' */ export type IsoDateString = string; /** * Interface explicitly states that the value is an ISO DateTime string (with time). * * @example '2019-06-21T05:21:73Z' */ export type IsoDateTimeString = string; /** * Identifies the Month. * Like IsoDateString, but without the Day token. * * @example '2023-09' */ export type MonthId = string; /** * Interface explicitly states that the value is a Unix timestamp (in seconds). * * @example 1628945450 */ export type UnixTimestampNumber = number; /** * Interface explicitly states that the value is a "Unix timestamp in **milleseconds**" (not seconds) * * @example 1628945450000 */ export type UnixTimestampMillisNumber = number; export type NumberOfSeconds = number; export type NumberOfMilliseconds = number; /** * Same as `number`, but with semantic meaning that it's an Integer. */ export type Integer = number; /** * Convenience type alias, that allows to write this: * * data: NullableNumber[] * * instead of this: * * data: (number | null)[] */ export type NullableNumber = number | null; /** * Used as a compact representation of truthy value. * undefined ('' or other short falsy value) should be used as falsy value. */ export type ShortBoolean = '1'; export type Base64String = string; export type Base64UrlString = string; export type JWTString = string; export type SemVerString = string; /** * Named type for JSON.parse / JSON.stringify second argument */ export type Reviver = (this: any, key: string, value: any) => any; /** * Needed due to https://github.com/microsoft/TypeScript/issues/13778 * Only affects typings, no runtime effect. */ export declare const _stringMapValues: (m: StringMap) => T[]; /** * Needed due to https://github.com/microsoft/TypeScript/issues/13778 * Only affects typings, no runtime effect. */ export declare const _stringMapEntries: (m: StringMap) => [k: string, v: T][]; /** * Alias of `Object.keys`, but returns keys typed as `keyof T`, not as just `string`. * This is how TypeScript should work, actually. */ export declare const _objectKeys: (obj: T) => (keyof T)[]; /** * Alias of `Object.entries`, but returns better-typed output. * * So e.g you can use _objectEntries(obj).map([k, v] => {}) * and `k` will be `keyof obj` instead of generic `string`. */ export declare const _objectEntries: (obj: T) => [k: keyof T, v: T[keyof T]][]; export type NullishValue = null | undefined; export type FalsyValue = false | '' | 0 | null | undefined; /** * Utility function that helps to cast *existing variable* to needed type T. * * @example * try {} catch (err) { * // err is unknown here * _typeCast(err) * // now err is of type AppError * err.data = {} // can be done, because it was casted * } */ export declare function _typeCast(v: any): asserts v is T; /** * Type-safe Object.assign that checks that part is indeed a Partial */ export declare const _objectAssign: (target: T, part: Partial) => T; /** * Defines a tuple of [err, data] * where only 1 of them exists. * Either error exists and data is null * Or error is null and data is defined. * This forces you to check `if (err)`, which lets * TypeScript infer the existence of `data`. * * Functions like pTry use that. */ export type ErrorDataTuple = [err: null, data: T] | [err: ERR, data: null]; export type SortDirection = 'asc' | 'desc'; export type Inclusiveness = '()' | '[]' | '[)' | '(]';