@esposter/shared 2.22.0 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +75 -0
- package/dist/index.d.ts +359 -4
- package/dist/index.js +531 -96
- package/package.json +8 -6
- package/dist/magic-string.es-CDi1Mjxn.js +0 -1011
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ declare const RoutePath: {
|
|
|
42
42
|
readonly Achievements: "/achievements";
|
|
43
43
|
readonly Anime: "/anime";
|
|
44
44
|
readonly Calendar: "/calendar";
|
|
45
|
+
readonly Calls: (id: string) => string;
|
|
46
|
+
readonly CallsIndex: "/calls";
|
|
45
47
|
readonly Clicker: "/clicker";
|
|
46
48
|
readonly Dashboard: "/dashboard";
|
|
47
49
|
readonly DashboardEditor: "/dashboard/editor";
|
|
@@ -70,16 +72,22 @@ declare const RoutePath: {
|
|
|
70
72
|
};
|
|
71
73
|
type RoutePath = typeof RoutePath;
|
|
72
74
|
//#endregion
|
|
73
|
-
//#region src/util/types/
|
|
74
|
-
type GetProperties<T, P extends string = "", D extends unknown[] = [unknown, unknown, unknown, unknown, unknown], R extends boolean = true> = [T] extends [never] ? never : D extends [] ? never : NonNullable<T> extends infer O ? O extends unknown[] ? GetArrayProps<O, P, D, R> : O extends object ? GetObjectProps<O, P, D, R> : GetPrimitiveProps<O, P, D, R> : never;
|
|
75
|
+
//#region src/util/types/GetArrayProps.d.ts
|
|
75
76
|
type GetArrayProps<T extends unknown[], P extends string, D extends unknown[], R extends boolean> = (D extends [unknown, ...infer Rest] ? GetProperties<T[number], R extends true ? `${P}[number]` : `${P}.[number]`, Rest, false> : never) | {
|
|
76
77
|
path: R extends true ? "length" : `${P}.length`;
|
|
77
78
|
value: T["length"];
|
|
78
79
|
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/util/types/KnownKeys.d.ts
|
|
82
|
+
type KnownKeys<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/util/types/GetObjectProps.d.ts
|
|
79
85
|
type GetObjectProps<T, P extends string, D extends unknown[], R extends boolean> = { [K in keyof KnownKeys<T> & (number | string)]: K extends `${number}` ? never : NonNullable<T[K]> extends Function ? never : (D extends [unknown, ...infer Rest] ? GetProperties<T[K], R extends true ? `${K}` : `${P}.${K}`, Rest, false> : never) | {
|
|
80
86
|
path: R extends true ? `${K}` : `${P}.${K}`;
|
|
81
87
|
value: T[K];
|
|
82
88
|
} }[keyof KnownKeys<T> & (number | string)];
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/util/types/GetPrimitiveProps.d.ts
|
|
83
91
|
type GetPrimitiveProps<T, P extends string, D extends unknown[], R extends boolean> = T extends string ? {
|
|
84
92
|
path: R extends true ? "length" : `${P}.length`;
|
|
85
93
|
value: number;
|
|
@@ -87,7 +95,9 @@ type GetPrimitiveProps<T, P extends string, D extends unknown[], R extends boole
|
|
|
87
95
|
path: R extends true ? "description" : `${P}.description`;
|
|
88
96
|
value: string | undefined;
|
|
89
97
|
} : never;
|
|
90
|
-
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/util/types/GetProperties.d.ts
|
|
100
|
+
type GetProperties<T, P extends string = "", D extends unknown[] = [unknown, unknown, unknown, unknown, unknown], R extends boolean = true> = [T] extends [never] ? never : D extends [] ? never : NonNullable<T> extends infer O ? O extends unknown[] ? GetArrayProps<O, P, D, R> : O extends object ? GetObjectProps<O, P, D, R> : GetPrimitiveProps<O, P, D, R> : never;
|
|
91
101
|
//#endregion
|
|
92
102
|
//#region src/util/types/GetPaths.d.ts
|
|
93
103
|
type GetPaths<T> = GetProperties<T> extends infer U ? (U extends {
|
|
@@ -1689,6 +1699,33 @@ type PostPayloadFixed = Except<UserData, 'email'>;
|
|
|
1689
1699
|
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
1690
1700
|
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
|
|
1691
1701
|
//#endregion
|
|
1702
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/promisable.d.ts
|
|
1703
|
+
/**
|
|
1704
|
+
Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
1705
|
+
|
|
1706
|
+
Use-cases:
|
|
1707
|
+
- A function accepts a callback that may either return a value synchronously or may return a promised value.
|
|
1708
|
+
- This type could be the return type of `Promise#then()`, `Promise#catch()`, and `Promise#finally()` callbacks.
|
|
1709
|
+
|
|
1710
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31394) if you want to have this type as a built-in in TypeScript.
|
|
1711
|
+
|
|
1712
|
+
@example
|
|
1713
|
+
```
|
|
1714
|
+
import type {Promisable} from 'type-fest';
|
|
1715
|
+
|
|
1716
|
+
async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
|
|
1717
|
+
const entry = await getLogEntry();
|
|
1718
|
+
console.log(entry);
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
await logger(() => 'foo');
|
|
1722
|
+
await logger(() => Promise.resolve('bar'));
|
|
1723
|
+
```
|
|
1724
|
+
|
|
1725
|
+
@category Async
|
|
1726
|
+
*/
|
|
1727
|
+
type Promisable<T> = T | PromiseLike<T>;
|
|
1728
|
+
//#endregion
|
|
1692
1729
|
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-lowercase.d.ts
|
|
1693
1730
|
/**
|
|
1694
1731
|
Returns a boolean for whether the given string literal is lowercase.
|
|
@@ -2042,6 +2079,318 @@ interface WithMetadata<TBase extends Class<NonNullable<unknown>>> {
|
|
|
2042
2079
|
//#region src/services/app/constants.d.ts
|
|
2043
2080
|
declare const SITE_NAME = "Esposter";
|
|
2044
2081
|
//#endregion
|
|
2082
|
+
//#region ../../node_modules/.pnpm/neverthrow@8.2.0/node_modules/neverthrow/dist/index.d.ts
|
|
2083
|
+
interface ErrorConfig {
|
|
2084
|
+
withStackTrace: boolean;
|
|
2085
|
+
}
|
|
2086
|
+
declare class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {
|
|
2087
|
+
private _promise;
|
|
2088
|
+
constructor(res: Promise<Result<T, E>>);
|
|
2089
|
+
static fromSafePromise<T, E = never>(promise: PromiseLike<T>): ResultAsync<T, E>;
|
|
2090
|
+
static fromPromise<T, E>(promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>;
|
|
2091
|
+
static fromThrowable<A extends readonly any[], R, E>(fn: (...args: A) => Promise<R>, errorFn?: (err: unknown) => E): (...args: A) => ResultAsync<R, E>;
|
|
2092
|
+
static combine<T extends readonly [ResultAsync<unknown, unknown>, ...ResultAsync<unknown, unknown>[]]>(asyncResultList: T): CombineResultAsyncs<T>;
|
|
2093
|
+
static combine<T extends readonly ResultAsync<unknown, unknown>[]>(asyncResultList: T): CombineResultAsyncs<T>;
|
|
2094
|
+
static combineWithAllErrors<T extends readonly [ResultAsync<unknown, unknown>, ...ResultAsync<unknown, unknown>[]]>(asyncResultList: T): CombineResultsWithAllErrorsArrayAsync<T>;
|
|
2095
|
+
static combineWithAllErrors<T extends readonly ResultAsync<unknown, unknown>[]>(asyncResultList: T): CombineResultsWithAllErrorsArrayAsync<T>;
|
|
2096
|
+
map<A>(f: (t: T) => A | Promise<A>): ResultAsync<A, E>;
|
|
2097
|
+
andThrough<F>(f: (t: T) => Result<unknown, F> | ResultAsync<unknown, F>): ResultAsync<T, E | F>;
|
|
2098
|
+
andTee(f: (t: T) => unknown): ResultAsync<T, E>;
|
|
2099
|
+
orTee(f: (t: E) => unknown): ResultAsync<T, E>;
|
|
2100
|
+
mapErr<U>(f: (e: E) => U | Promise<U>): ResultAsync<T, U>;
|
|
2101
|
+
andThen<R extends Result<unknown, unknown>>(f: (t: T) => R): ResultAsync<InferOkTypes<R>, InferErrTypes<R> | E>;
|
|
2102
|
+
andThen<R extends ResultAsync<unknown, unknown>>(f: (t: T) => R): ResultAsync<InferAsyncOkTypes<R>, InferAsyncErrTypes<R> | E>;
|
|
2103
|
+
andThen<U, F>(f: (t: T) => Result<U, F> | ResultAsync<U, F>): ResultAsync<U, E | F>;
|
|
2104
|
+
orElse<R extends Result<unknown, unknown>>(f: (e: E) => R): ResultAsync<InferOkTypes<R> | T, InferErrTypes<R>>;
|
|
2105
|
+
orElse<R extends ResultAsync<unknown, unknown>>(f: (e: E) => R): ResultAsync<InferAsyncOkTypes<R> | T, InferAsyncErrTypes<R>>;
|
|
2106
|
+
orElse<U, A>(f: (e: E) => Result<U, A> | ResultAsync<U, A>): ResultAsync<U | T, A>;
|
|
2107
|
+
match<A, B = A>(ok: (t: T) => A, _err: (e: E) => B): Promise<A | B>;
|
|
2108
|
+
unwrapOr<A>(t: A): Promise<T | A>;
|
|
2109
|
+
/**
|
|
2110
|
+
* @deprecated will be removed in 9.0.0.
|
|
2111
|
+
*
|
|
2112
|
+
* You can use `safeTry` without this method.
|
|
2113
|
+
* @example
|
|
2114
|
+
* ```typescript
|
|
2115
|
+
* safeTry(async function* () {
|
|
2116
|
+
* const okValue = yield* yourResult
|
|
2117
|
+
* })
|
|
2118
|
+
* ```
|
|
2119
|
+
* Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`.
|
|
2120
|
+
*/
|
|
2121
|
+
safeUnwrap(): AsyncGenerator<Err<never, E>, T>;
|
|
2122
|
+
then<A, B>(successCallback?: (res: Result<T, E>) => A | PromiseLike<A>, failureCallback?: (reason: unknown) => B | PromiseLike<B>): PromiseLike<A | B>;
|
|
2123
|
+
[Symbol.asyncIterator](): AsyncGenerator<Err<never, E>, T>;
|
|
2124
|
+
}
|
|
2125
|
+
declare type CombineResultAsyncs<T extends readonly ResultAsync<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseAsync<UnwrapAsync<T>> : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number]>;
|
|
2126
|
+
declare type CombineResultsWithAllErrorsArrayAsync<T extends readonly ResultAsync<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseWithAllErrorsAsync<UnwrapAsync<T>> : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number][]>;
|
|
2127
|
+
declare type UnwrapAsync<T> = IsLiteralArray<T> extends 1 ? Writable<T> extends [infer H, ...infer Rest] ? H extends PromiseLike<infer HI> ? HI extends Result<unknown, unknown> ? [Dedup<HI>, ...UnwrapAsync<Rest>] : never : never : [] : T extends Array<infer A> ? A extends PromiseLike<infer HI> ? HI extends Result<infer L, infer R> ? Ok<L, R>[] : never : never : never;
|
|
2128
|
+
declare type TraverseAsync<T, Depth extends number = 5> = IsLiteralArray<T> extends 1 ? Combine<T, Depth> extends [infer Oks, infer Errs] ? ResultAsync<EmptyArrayToNever<Oks>, MembersToUnion<Errs>> : never : T extends Array<infer I> ? Combine<MemberListOf<I>, Depth> extends [infer Oks, infer Errs] ? Oks extends unknown[] ? Errs extends unknown[] ? ResultAsync<EmptyArrayToNever<Oks[number][]>, MembersToUnion<Errs[number][]>> : ResultAsync<EmptyArrayToNever<Oks[number][]>, Errs> : Errs extends unknown[] ? ResultAsync<Oks, MembersToUnion<Errs[number][]>> : ResultAsync<Oks, Errs> : never : never;
|
|
2129
|
+
declare type TraverseWithAllErrorsAsync<T, Depth extends number = 5> = TraverseAsync<T, Depth> extends ResultAsync<infer Oks, infer Errs> ? ResultAsync<Oks, Errs[]> : never;
|
|
2130
|
+
declare type Writable<T> = T extends ReadonlyArray<unknown> ? [...T] : T;
|
|
2131
|
+
declare type ExtractOkTypes<T extends readonly Result<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends Result<infer U, unknown> ? U : never };
|
|
2132
|
+
declare type ExtractOkAsyncTypes<T extends readonly ResultAsync<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends ResultAsync<infer U, unknown> ? U : never };
|
|
2133
|
+
declare type ExtractErrTypes<T extends readonly Result<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends Result<unknown, infer E> ? E : never };
|
|
2134
|
+
declare type ExtractErrAsyncTypes<T extends readonly ResultAsync<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends ResultAsync<unknown, infer E> ? E : never };
|
|
2135
|
+
declare type InferOkTypes<R> = R extends Result<infer T, unknown> ? T : never;
|
|
2136
|
+
declare type InferErrTypes<R> = R extends Result<unknown, infer E> ? E : never;
|
|
2137
|
+
declare type InferAsyncOkTypes<R> = R extends ResultAsync<infer T, unknown> ? T : never;
|
|
2138
|
+
declare type InferAsyncErrTypes<R> = R extends ResultAsync<unknown, infer E> ? E : never;
|
|
2139
|
+
declare namespace Result {
|
|
2140
|
+
/**
|
|
2141
|
+
* Wraps a function with a try catch, creating a new function with the same
|
|
2142
|
+
* arguments but returning `Ok` if successful, `Err` if the function throws
|
|
2143
|
+
*
|
|
2144
|
+
* @param fn function to wrap with ok on success or err on failure
|
|
2145
|
+
* @param errorFn when an error is thrown, this will wrap the error result if provided
|
|
2146
|
+
*/
|
|
2147
|
+
function fromThrowable<Fn extends (...args: readonly any[]) => any, E>(fn: Fn, errorFn?: (e: unknown) => E): (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E>;
|
|
2148
|
+
function combine<T extends readonly [Result<unknown, unknown>, ...Result<unknown, unknown>[]]>(resultList: T): CombineResults<T>;
|
|
2149
|
+
function combine<T extends readonly Result<unknown, unknown>[]>(resultList: T): CombineResults<T>;
|
|
2150
|
+
function combineWithAllErrors<T extends readonly [Result<unknown, unknown>, ...Result<unknown, unknown>[]]>(resultList: T): CombineResultsWithAllErrorsArray<T>;
|
|
2151
|
+
function combineWithAllErrors<T extends readonly Result<unknown, unknown>[]>(resultList: T): CombineResultsWithAllErrorsArray<T>;
|
|
2152
|
+
}
|
|
2153
|
+
declare type Result<T, E> = Ok<T, E> | Err<T, E>;
|
|
2154
|
+
interface IResult<T, E> {
|
|
2155
|
+
/**
|
|
2156
|
+
* Used to check if a `Result` is an `OK`
|
|
2157
|
+
*
|
|
2158
|
+
* @returns `true` if the result is an `OK` variant of Result
|
|
2159
|
+
*/
|
|
2160
|
+
isOk(): this is Ok<T, E>;
|
|
2161
|
+
/**
|
|
2162
|
+
* Used to check if a `Result` is an `Err`
|
|
2163
|
+
*
|
|
2164
|
+
* @returns `true` if the result is an `Err` variant of Result
|
|
2165
|
+
*/
|
|
2166
|
+
isErr(): this is Err<T, E>;
|
|
2167
|
+
/**
|
|
2168
|
+
* Maps a `Result<T, E>` to `Result<U, E>`
|
|
2169
|
+
* by applying a function to a contained `Ok` value, leaving an `Err` value
|
|
2170
|
+
* untouched.
|
|
2171
|
+
*
|
|
2172
|
+
* @param f The function to apply an `OK` value
|
|
2173
|
+
* @returns the result of applying `f` or an `Err` untouched
|
|
2174
|
+
*/
|
|
2175
|
+
map<A>(f: (t: T) => A): Result<A, E>;
|
|
2176
|
+
/**
|
|
2177
|
+
* Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a
|
|
2178
|
+
* contained `Err` value, leaving an `Ok` value untouched.
|
|
2179
|
+
*
|
|
2180
|
+
* This function can be used to pass through a successful result while
|
|
2181
|
+
* handling an error.
|
|
2182
|
+
*
|
|
2183
|
+
* @param f a function to apply to the error `Err` value
|
|
2184
|
+
*/
|
|
2185
|
+
mapErr<U>(f: (e: E) => U): Result<T, U>;
|
|
2186
|
+
/**
|
|
2187
|
+
* Similar to `map` Except you must return a new `Result`.
|
|
2188
|
+
*
|
|
2189
|
+
* This is useful for when you need to do a subsequent computation using the
|
|
2190
|
+
* inner `T` value, but that computation might fail.
|
|
2191
|
+
* Additionally, `andThen` is really useful as a tool to flatten a
|
|
2192
|
+
* `Result<Result<A, E2>, E1>` into a `Result<A, E2>` (see example below).
|
|
2193
|
+
*
|
|
2194
|
+
* @param f The function to apply to the current value
|
|
2195
|
+
*/
|
|
2196
|
+
andThen<R extends Result<unknown, unknown>>(f: (t: T) => R): Result<InferOkTypes<R>, InferErrTypes<R> | E>;
|
|
2197
|
+
andThen<U, F>(f: (t: T) => Result<U, F>): Result<U, E | F>;
|
|
2198
|
+
/**
|
|
2199
|
+
* This "tee"s the current value to an passed-in computation such as side
|
|
2200
|
+
* effect functions but still returns the same current value as the result.
|
|
2201
|
+
*
|
|
2202
|
+
* This is useful when you want to pass the current result to your side-track
|
|
2203
|
+
* work such as logging but want to continue main-track work after that.
|
|
2204
|
+
* This method does not care about the result of the passed in computation.
|
|
2205
|
+
*
|
|
2206
|
+
* @param f The function to apply to the current value
|
|
2207
|
+
*/
|
|
2208
|
+
andTee(f: (t: T) => unknown): Result<T, E>;
|
|
2209
|
+
/**
|
|
2210
|
+
* This "tee"s the current `Err` value to an passed-in computation such as side
|
|
2211
|
+
* effect functions but still returns the same `Err` value as the result.
|
|
2212
|
+
*
|
|
2213
|
+
* This is useful when you want to pass the current `Err` value to your side-track
|
|
2214
|
+
* work such as logging but want to continue error-track work after that.
|
|
2215
|
+
* This method does not care about the result of the passed in computation.
|
|
2216
|
+
*
|
|
2217
|
+
* @param f The function to apply to the current `Err` value
|
|
2218
|
+
*/
|
|
2219
|
+
orTee(f: (t: E) => unknown): Result<T, E>;
|
|
2220
|
+
/**
|
|
2221
|
+
* Similar to `andTee` except error result of the computation will be passed
|
|
2222
|
+
* to the downstream in case of an error.
|
|
2223
|
+
*
|
|
2224
|
+
* This version is useful when you want to make side-effects but in case of an
|
|
2225
|
+
* error, you want to pass the error to the downstream.
|
|
2226
|
+
*
|
|
2227
|
+
* @param f The function to apply to the current value
|
|
2228
|
+
*/
|
|
2229
|
+
andThrough<R extends Result<unknown, unknown>>(f: (t: T) => R): Result<T, InferErrTypes<R> | E>;
|
|
2230
|
+
andThrough<F>(f: (t: T) => Result<unknown, F>): Result<T, E | F>;
|
|
2231
|
+
/**
|
|
2232
|
+
* Takes an `Err` value and maps it to a `Result<T, SomeNewType>`.
|
|
2233
|
+
*
|
|
2234
|
+
* This is useful for error recovery.
|
|
2235
|
+
*
|
|
2236
|
+
*
|
|
2237
|
+
* @param f A function to apply to an `Err` value, leaving `Ok` values
|
|
2238
|
+
* untouched.
|
|
2239
|
+
*/
|
|
2240
|
+
orElse<R extends Result<unknown, unknown>>(f: (e: E) => R): Result<InferOkTypes<R> | T, InferErrTypes<R>>;
|
|
2241
|
+
orElse<U, A>(f: (e: E) => Result<U, A>): Result<U | T, A>;
|
|
2242
|
+
/**
|
|
2243
|
+
* Similar to `map` Except you must return a new `Result`.
|
|
2244
|
+
*
|
|
2245
|
+
* This is useful for when you need to do a subsequent async computation using
|
|
2246
|
+
* the inner `T` value, but that computation might fail. Must return a ResultAsync
|
|
2247
|
+
*
|
|
2248
|
+
* @param f The function that returns a `ResultAsync` to apply to the current
|
|
2249
|
+
* value
|
|
2250
|
+
*/
|
|
2251
|
+
asyncAndThen<U, F>(f: (t: T) => ResultAsync<U, F>): ResultAsync<U, E | F>;
|
|
2252
|
+
/**
|
|
2253
|
+
* Maps a `Result<T, E>` to `ResultAsync<U, E>`
|
|
2254
|
+
* by applying an async function to a contained `Ok` value, leaving an `Err`
|
|
2255
|
+
* value untouched.
|
|
2256
|
+
*
|
|
2257
|
+
* @param f An async function to apply an `OK` value
|
|
2258
|
+
*/
|
|
2259
|
+
asyncMap<U>(f: (t: T) => Promise<U>): ResultAsync<U, E>;
|
|
2260
|
+
/**
|
|
2261
|
+
* Unwrap the `Ok` value, or return the default if there is an `Err`
|
|
2262
|
+
*
|
|
2263
|
+
* @param v the default value to return if there is an `Err`
|
|
2264
|
+
*/
|
|
2265
|
+
unwrapOr<A>(v: A): T | A;
|
|
2266
|
+
/**
|
|
2267
|
+
*
|
|
2268
|
+
* Given 2 functions (one for the `Ok` variant and one for the `Err` variant)
|
|
2269
|
+
* execute the function that matches the `Result` variant.
|
|
2270
|
+
*
|
|
2271
|
+
* Match callbacks do not necessitate to return a `Result`, however you can
|
|
2272
|
+
* return a `Result` if you want to.
|
|
2273
|
+
*
|
|
2274
|
+
* `match` is like chaining `map` and `mapErr`, with the distinction that
|
|
2275
|
+
* with `match` both functions must have the same return type.
|
|
2276
|
+
*
|
|
2277
|
+
* @param ok
|
|
2278
|
+
* @param err
|
|
2279
|
+
*/
|
|
2280
|
+
match<A, B = A>(ok: (t: T) => A, err: (e: E) => B): A | B;
|
|
2281
|
+
/**
|
|
2282
|
+
* @deprecated will be removed in 9.0.0.
|
|
2283
|
+
*
|
|
2284
|
+
* You can use `safeTry` without this method.
|
|
2285
|
+
* @example
|
|
2286
|
+
* ```typescript
|
|
2287
|
+
* safeTry(function* () {
|
|
2288
|
+
* const okValue = yield* yourResult
|
|
2289
|
+
* })
|
|
2290
|
+
* ```
|
|
2291
|
+
* Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`.
|
|
2292
|
+
*/
|
|
2293
|
+
safeUnwrap(): Generator<Err<never, E>, T>;
|
|
2294
|
+
/**
|
|
2295
|
+
* **This method is unsafe, and should only be used in a test environments**
|
|
2296
|
+
*
|
|
2297
|
+
* Takes a `Result<T, E>` and returns a `T` when the result is an `Ok`, otherwise it throws a custom object.
|
|
2298
|
+
*
|
|
2299
|
+
* @param config
|
|
2300
|
+
*/
|
|
2301
|
+
_unsafeUnwrap(config?: ErrorConfig): T;
|
|
2302
|
+
/**
|
|
2303
|
+
* **This method is unsafe, and should only be used in a test environments**
|
|
2304
|
+
*
|
|
2305
|
+
* takes a `Result<T, E>` and returns a `E` when the result is an `Err`,
|
|
2306
|
+
* otherwise it throws a custom object.
|
|
2307
|
+
*
|
|
2308
|
+
* @param config
|
|
2309
|
+
*/
|
|
2310
|
+
_unsafeUnwrapErr(config?: ErrorConfig): E;
|
|
2311
|
+
}
|
|
2312
|
+
declare class Ok<T, E> implements IResult<T, E> {
|
|
2313
|
+
readonly value: T;
|
|
2314
|
+
constructor(value: T);
|
|
2315
|
+
isOk(): this is Ok<T, E>;
|
|
2316
|
+
isErr(): this is Err<T, E>;
|
|
2317
|
+
map<A>(f: (t: T) => A): Result<A, E>;
|
|
2318
|
+
mapErr<U>(_f: (e: E) => U): Result<T, U>;
|
|
2319
|
+
andThen<R extends Result<unknown, unknown>>(f: (t: T) => R): Result<InferOkTypes<R>, InferErrTypes<R> | E>;
|
|
2320
|
+
andThen<U, F>(f: (t: T) => Result<U, F>): Result<U, E | F>;
|
|
2321
|
+
andThrough<R extends Result<unknown, unknown>>(f: (t: T) => R): Result<T, InferErrTypes<R> | E>;
|
|
2322
|
+
andThrough<F>(f: (t: T) => Result<unknown, F>): Result<T, E | F>;
|
|
2323
|
+
andTee(f: (t: T) => unknown): Result<T, E>;
|
|
2324
|
+
orTee(_f: (t: E) => unknown): Result<T, E>;
|
|
2325
|
+
orElse<R extends Result<unknown, unknown>>(_f: (e: E) => R): Result<InferOkTypes<R> | T, InferErrTypes<R>>;
|
|
2326
|
+
orElse<U, A>(_f: (e: E) => Result<U, A>): Result<U | T, A>;
|
|
2327
|
+
asyncAndThen<U, F>(f: (t: T) => ResultAsync<U, F>): ResultAsync<U, E | F>;
|
|
2328
|
+
asyncAndThrough<R extends ResultAsync<unknown, unknown>>(f: (t: T) => R): ResultAsync<T, InferAsyncErrTypes<R> | E>;
|
|
2329
|
+
asyncAndThrough<F>(f: (t: T) => ResultAsync<unknown, F>): ResultAsync<T, E | F>;
|
|
2330
|
+
asyncMap<U>(f: (t: T) => Promise<U>): ResultAsync<U, E>;
|
|
2331
|
+
unwrapOr<A>(_v: A): T | A;
|
|
2332
|
+
match<A, B = A>(ok: (t: T) => A, _err: (e: E) => B): A | B;
|
|
2333
|
+
safeUnwrap(): Generator<Err<never, E>, T>;
|
|
2334
|
+
_unsafeUnwrap(_?: ErrorConfig): T;
|
|
2335
|
+
_unsafeUnwrapErr(config?: ErrorConfig): E;
|
|
2336
|
+
[Symbol.iterator](): Generator<Err<never, E>, T>;
|
|
2337
|
+
}
|
|
2338
|
+
declare class Err<T, E> implements IResult<T, E> {
|
|
2339
|
+
readonly error: E;
|
|
2340
|
+
constructor(error: E);
|
|
2341
|
+
isOk(): this is Ok<T, E>;
|
|
2342
|
+
isErr(): this is Err<T, E>;
|
|
2343
|
+
map<A>(_f: (t: T) => A): Result<A, E>;
|
|
2344
|
+
mapErr<U>(f: (e: E) => U): Result<T, U>;
|
|
2345
|
+
andThrough<F>(_f: (t: T) => Result<unknown, F>): Result<T, E | F>;
|
|
2346
|
+
andTee(_f: (t: T) => unknown): Result<T, E>;
|
|
2347
|
+
orTee(f: (t: E) => unknown): Result<T, E>;
|
|
2348
|
+
andThen<R extends Result<unknown, unknown>>(_f: (t: T) => R): Result<InferOkTypes<R>, InferErrTypes<R> | E>;
|
|
2349
|
+
andThen<U, F>(_f: (t: T) => Result<U, F>): Result<U, E | F>;
|
|
2350
|
+
orElse<R extends Result<unknown, unknown>>(f: (e: E) => R): Result<InferOkTypes<R> | T, InferErrTypes<R>>;
|
|
2351
|
+
orElse<U, A>(f: (e: E) => Result<U, A>): Result<U | T, A>;
|
|
2352
|
+
asyncAndThen<U, F>(_f: (t: T) => ResultAsync<U, F>): ResultAsync<U, E | F>;
|
|
2353
|
+
asyncAndThrough<F>(_f: (t: T) => ResultAsync<unknown, F>): ResultAsync<T, E | F>;
|
|
2354
|
+
asyncMap<U>(_f: (t: T) => Promise<U>): ResultAsync<U, E>;
|
|
2355
|
+
unwrapOr<A>(v: A): T | A;
|
|
2356
|
+
match<A, B = A>(_ok: (t: T) => A, err: (e: E) => B): A | B;
|
|
2357
|
+
safeUnwrap(): Generator<Err<never, E>, T>;
|
|
2358
|
+
_unsafeUnwrap(config?: ErrorConfig): T;
|
|
2359
|
+
_unsafeUnwrapErr(_?: ErrorConfig): E;
|
|
2360
|
+
[Symbol.iterator](): Generator<Err<never, E>, T>;
|
|
2361
|
+
}
|
|
2362
|
+
declare type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, ...0[]];
|
|
2363
|
+
declare type CollectResults<T, Collected extends unknown[] = [], Depth extends number = 50> = [Depth] extends [never] ? [] : T extends [infer H, ...infer Rest] ? H extends Result<infer L, infer R> ? CollectResults<Rest, [...Collected, [L, R]], Prev[Depth]> : never : Collected;
|
|
2364
|
+
declare type Transpose<A, Transposed extends unknown[][] = [], Depth extends number = 10> = A extends [infer T, ...infer Rest] ? T extends [infer L, infer R] ? Transposed extends [infer PL, infer PR] ? PL extends unknown[] ? PR extends unknown[] ? Transpose<Rest, [[...PL, L], [...PR, R]], Prev[Depth]> : never : never : Transpose<Rest, [[L], [R]], Prev[Depth]> : Transposed : Transposed;
|
|
2365
|
+
declare type Combine<T, Depth extends number = 5> = Transpose<CollectResults<T>, [], Depth> extends [infer L, infer R] ? [UnknownMembersToNever<L>, UnknownMembersToNever<R>] : Transpose<CollectResults<T>, [], Depth> extends [] ? [[], []] : never;
|
|
2366
|
+
declare type Dedup<T> = T extends Result<infer RL, infer RR> ? [unknown] extends [RL] ? Err<RL, RR> : Ok<RL, RR> : T;
|
|
2367
|
+
declare type MemberListOf<T> = ((T extends unknown ? (t: T) => T : never) extends infer U ? (U extends unknown ? (u: U) => unknown : never) extends ((v: infer V) => unknown) ? V : never : never) extends ((_: unknown) => infer W) ? [...MemberListOf<Exclude<T, W>>, W] : [];
|
|
2368
|
+
declare type EmptyArrayToNever<T, NeverArrayToNever extends number = 0> = T extends [] ? never : NeverArrayToNever extends 1 ? T extends [never, ...infer Rest] ? [EmptyArrayToNever<Rest>] extends [never] ? never : T : T : T;
|
|
2369
|
+
declare type UnknownMembersToNever<T> = T extends [infer H, ...infer R] ? [[unknown] extends [H] ? never : H, ...UnknownMembersToNever<R>] : T;
|
|
2370
|
+
declare type MembersToUnion<T> = T extends unknown[] ? T[number] : never;
|
|
2371
|
+
declare type IsLiteralArray<T> = T extends {
|
|
2372
|
+
length: infer L;
|
|
2373
|
+
} ? L extends number ? number extends L ? 0 : 1 : 0 : 0;
|
|
2374
|
+
declare type Traverse<T, Depth extends number = 5> = Combine<T, Depth> extends [infer Oks, infer Errs] ? Result<EmptyArrayToNever<Oks, 1>, MembersToUnion<Errs>> : never;
|
|
2375
|
+
declare type TraverseWithAllErrors<T, Depth extends number = 5> = Traverse<T, Depth> extends Result<infer Oks, infer Errs> ? Result<Oks, Errs[]> : never;
|
|
2376
|
+
declare type CombineResults<T extends readonly Result<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? Traverse<T> : Result<ExtractOkTypes<T>, ExtractErrTypes<T>[number]>;
|
|
2377
|
+
declare type CombineResultsWithAllErrorsArray<T extends readonly Result<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseWithAllErrors<T> : Result<ExtractOkTypes<T>, ExtractErrTypes<T>[number][]>;
|
|
2378
|
+
//#endregion
|
|
2379
|
+
//#region src/services/error/getResult.d.ts
|
|
2380
|
+
declare const getResult: <T>(fn: () => T) => Result<T, Error>;
|
|
2381
|
+
//#endregion
|
|
2382
|
+
//#region src/services/error/getResultAsync.d.ts
|
|
2383
|
+
declare const getResultAsync: <T>(fn: () => Promise<T>) => ResultAsync<T, Error>;
|
|
2384
|
+
//#endregion
|
|
2385
|
+
//#region src/services/error/toAppError.d.ts
|
|
2386
|
+
declare const toAppError: (error: unknown) => Error;
|
|
2387
|
+
//#endregion
|
|
2388
|
+
//#region src/services/error/withFinalizer.d.ts
|
|
2389
|
+
declare const withFinalizer: <T>(fn: () => T, finalizer?: () => void) => T;
|
|
2390
|
+
//#endregion
|
|
2391
|
+
//#region src/services/error/withFinalizerAsync.d.ts
|
|
2392
|
+
declare const withFinalizerAsync: <T>(fn: () => Promisable<T>, finalizer?: () => Promisable<void>) => Promise<T>;
|
|
2393
|
+
//#endregion
|
|
2045
2394
|
//#region src/services/message/constants.d.ts
|
|
2046
2395
|
declare const MENTION_ID_ATTRIBUTE = "data-id";
|
|
2047
2396
|
declare const MENTION_LABEL_ATTRIBUTE = "data-label";
|
|
@@ -2370,6 +2719,9 @@ declare const takeOne: TakeOne;
|
|
|
2370
2719
|
//#region src/util/environment/getIsServer.d.ts
|
|
2371
2720
|
declare const getIsServer: () => boolean;
|
|
2372
2721
|
//#endregion
|
|
2722
|
+
//#region src/util/function/noop.d.ts
|
|
2723
|
+
declare const noop: () => void;
|
|
2724
|
+
//#endregion
|
|
2373
2725
|
//#region src/util/id/constants.d.ts
|
|
2374
2726
|
declare const ID_SEPARATOR = "|";
|
|
2375
2727
|
//#endregion
|
|
@@ -2400,6 +2752,9 @@ declare const escapeRegExp: (string: string) => string;
|
|
|
2400
2752
|
//#region src/util/text/capitalize.d.ts
|
|
2401
2753
|
declare const capitalize: (string: string) => string;
|
|
2402
2754
|
//#endregion
|
|
2755
|
+
//#region src/util/text/normalizeString.d.ts
|
|
2756
|
+
declare const normalizeString: (value: null | string | undefined) => string;
|
|
2757
|
+
//#endregion
|
|
2403
2758
|
//#region src/util/text/streamToText.d.ts
|
|
2404
2759
|
declare const streamToText: (readable: NodeJS.ReadableStream) => Promise<string>;
|
|
2405
2760
|
//#endregion
|
|
@@ -2458,4 +2813,4 @@ declare const UUIDV4_REGEX: RegExp;
|
|
|
2458
2813
|
//#region src/util/id/uuid/uuidValidateV4.d.ts
|
|
2459
2814
|
declare const uuidValidateV4: (uuid: string) => boolean;
|
|
2460
2815
|
//#endregion
|
|
2461
|
-
export { AllSpecialValues, BuildTuple, DeepOmit, DeepOptionalUndefined, ExcludeFunctionProperties, ForbiddenError, FunctionProperties, GetPaths, GetProperties, ID_SEPARATOR, InvalidOperationError, ItemEntityType, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, MENTION_EVERYONE_ID, MENTION_HERE_ID, MENTION_ID_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MapValue, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, PropertyNames, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, SkipFirst, TakeFirst, TakeOne, ToData, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, WithMetadata, applyItemMetadataMixin, capitalize, createItemEntityTypeSchema, css, escapeRegExp, exhaustiveGuard, getIsServer, getMentions, getPropertyNames, getRawData, hrtime, html, isPlainObject, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, now, streamToText, takeOne, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4 };
|
|
2816
|
+
export { AllSpecialValues, BuildTuple, DeepOmit, DeepOptionalUndefined, ExcludeFunctionProperties, ForbiddenError, FunctionProperties, GetArrayProps, GetObjectProps, GetPaths, GetPrimitiveProps, GetProperties, ID_SEPARATOR, InvalidOperationError, ItemEntityType, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, KnownKeys, MENTION_EVERYONE_ID, MENTION_HERE_ID, MENTION_ID_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MapValue, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, PropertyNames, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, SkipFirst, TakeFirst, TakeOne, ToData, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, WithMetadata, applyItemMetadataMixin, capitalize, createItemEntityTypeSchema, css, escapeRegExp, exhaustiveGuard, getIsServer, getMentions, getPropertyNames, getRawData, getResult, getResultAsync, hrtime, html, isPlainObject, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, noop, normalizeString, now, streamToText, takeOne, toAppError, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4, withFinalizer, withFinalizerAsync };
|