@zajno/common 2.6.6 → 2.7.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/cjs/api/builder.js +18 -11
- package/cjs/api/builder.js.map +1 -1
- package/cjs/api/call.config.js +77 -0
- package/cjs/api/call.config.js.map +1 -0
- package/cjs/api/call.js +16 -51
- package/cjs/api/call.js.map +1 -1
- package/cjs/api/call.types.js +2 -0
- package/cjs/api/call.types.js.map +1 -1
- package/cjs/api/config.js +43 -0
- package/cjs/api/config.js.map +1 -0
- package/cjs/api/endpoint.js +10 -0
- package/cjs/api/endpoint.js.map +1 -1
- package/cjs/api/extensions/contentType.js +9 -0
- package/cjs/api/extensions/contentType.js.map +1 -1
- package/cjs/api/extensions/endpointHooks.js +41 -0
- package/cjs/api/extensions/endpointHooks.js.map +1 -0
- package/cjs/api/extensions/index.js +1 -0
- package/cjs/api/extensions/index.js.map +1 -1
- package/cjs/api/extensions/validation.js +8 -0
- package/cjs/api/extensions/validation.js.map +1 -1
- package/cjs/api/hooks.js +56 -0
- package/cjs/api/hooks.js.map +1 -0
- package/cjs/api/index.js +2 -5
- package/cjs/api/index.js.map +1 -1
- package/cjs/api/interceptor.js +29 -0
- package/cjs/api/interceptor.js.map +1 -0
- package/cjs/api/logging.js +3 -3
- package/cjs/api/logging.js.map +1 -1
- package/cjs/functions/assert.js +18 -14
- package/cjs/functions/assert.js.map +1 -1
- package/cjs/functions/disposer.js +2 -2
- package/cjs/functions/disposer.js.map +1 -1
- package/cjs/functions/throttle.js +4 -4
- package/cjs/functions/throttle.js.map +1 -1
- package/cjs/logger/index.js +8 -18
- package/cjs/logger/index.js.map +1 -1
- package/cjs/logger/manager.js +14 -0
- package/cjs/logger/manager.js.map +1 -1
- package/cjs/logger/shared.js +18 -0
- package/cjs/logger/shared.js.map +1 -0
- package/cjs/models/LogicModel.js +2 -2
- package/cjs/models/LogicModel.js.map +1 -1
- package/cjs/observing/event.js +2 -2
- package/cjs/observing/event.js.map +1 -1
- package/cjs/observing/progressTracker.js +2 -2
- package/cjs/observing/progressTracker.js.map +1 -1
- package/cjs/structures/path/builder.helpers.js +180 -0
- package/cjs/structures/path/builder.helpers.js.map +1 -0
- package/cjs/structures/path/builder.js +21 -106
- package/cjs/structures/path/builder.js.map +1 -1
- package/cjs/structures/path/types.helpers.js +3 -0
- package/cjs/structures/path/types.helpers.js.map +1 -0
- package/cjs/structures/promiseCache.js +2 -2
- package/cjs/structures/promiseCache.js.map +1 -1
- package/cjs/structures/queue/parallel.js +2 -2
- package/cjs/structures/queue/parallel.js.map +1 -1
- package/cjs/structures/subscribersMap.js +2 -2
- package/cjs/structures/subscribersMap.js.map +1 -1
- package/esm/api/builder.js +17 -11
- package/esm/api/builder.js.map +1 -1
- package/esm/api/call.config.js +72 -0
- package/esm/api/call.config.js.map +1 -0
- package/esm/api/call.js +16 -51
- package/esm/api/call.js.map +1 -1
- package/esm/api/call.types.js +2 -0
- package/esm/api/call.types.js.map +1 -1
- package/esm/api/config.js +39 -0
- package/esm/api/config.js.map +1 -0
- package/esm/api/endpoint.js +10 -0
- package/esm/api/endpoint.js.map +1 -1
- package/esm/api/extensions/contentType.js +9 -0
- package/esm/api/extensions/contentType.js.map +1 -1
- package/esm/api/extensions/endpointHooks.js +38 -0
- package/esm/api/extensions/endpointHooks.js.map +1 -0
- package/esm/api/extensions/index.js +1 -0
- package/esm/api/extensions/index.js.map +1 -1
- package/esm/api/extensions/validation.js +8 -0
- package/esm/api/extensions/validation.js.map +1 -1
- package/esm/api/hooks.js +53 -0
- package/esm/api/hooks.js.map +1 -0
- package/esm/api/index.js +1 -2
- package/esm/api/index.js.map +1 -1
- package/esm/api/interceptor.js +26 -0
- package/esm/api/interceptor.js.map +1 -0
- package/esm/api/logging.js +3 -3
- package/esm/api/logging.js.map +1 -1
- package/esm/functions/assert.js +16 -13
- package/esm/functions/assert.js.map +1 -1
- package/esm/functions/disposer.js +1 -1
- package/esm/functions/disposer.js.map +1 -1
- package/esm/functions/throttle.js +1 -1
- package/esm/functions/throttle.js.map +1 -1
- package/esm/logger/index.js +6 -13
- package/esm/logger/index.js.map +1 -1
- package/esm/logger/manager.js +14 -0
- package/esm/logger/manager.js.map +1 -1
- package/esm/logger/shared.js +15 -0
- package/esm/logger/shared.js.map +1 -0
- package/esm/models/LogicModel.js +1 -1
- package/esm/models/LogicModel.js.map +1 -1
- package/esm/observing/event.js +1 -1
- package/esm/observing/event.js.map +1 -1
- package/esm/observing/progressTracker.js +1 -1
- package/esm/observing/progressTracker.js.map +1 -1
- package/esm/structures/path/builder.helpers.js +172 -0
- package/esm/structures/path/builder.helpers.js.map +1 -0
- package/esm/structures/path/builder.js +20 -104
- package/esm/structures/path/builder.js.map +1 -1
- package/esm/structures/path/types.helpers.js +2 -0
- package/esm/structures/path/types.helpers.js.map +1 -0
- package/esm/structures/promiseCache.js +1 -1
- package/esm/structures/promiseCache.js.map +1 -1
- package/esm/structures/queue/parallel.js +1 -1
- package/esm/structures/queue/parallel.js.map +1 -1
- package/esm/structures/subscribersMap.js +1 -1
- package/esm/structures/subscribersMap.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/tsconfig.esm.tsbuildinfo +1 -1
- package/tsconfig.types.tsbuildinfo +1 -1
- package/types/api/builder.d.ts +5 -0
- package/types/api/call.config.d.ts +25 -0
- package/types/api/call.types.d.ts +28 -25
- package/types/api/config.d.ts +23 -0
- package/types/api/endpoint.d.ts +2 -0
- package/types/api/endpoint.types.d.ts +4 -1
- package/types/api/extensions/contentType.d.ts +7 -5
- package/types/api/extensions/endpointHooks.d.ts +16 -0
- package/types/api/extensions/index.d.ts +1 -0
- package/types/api/extensions/validation.d.ts +2 -0
- package/types/api/hooks.d.ts +27 -0
- package/types/api/index.d.ts +1 -3
- package/types/api/interceptor.d.ts +14 -0
- package/types/api/logging.d.ts +3 -3
- package/types/functions/assert.d.ts +5 -1
- package/types/functions/throttle.d.ts +1 -1
- package/types/logger/index.d.ts +8 -8
- package/types/logger/manager.d.ts +7 -0
- package/types/logger/shared.d.ts +15 -0
- package/types/models/LogicModel.d.ts +1 -1
- package/types/observing/event.d.ts +1 -1
- package/types/observing/progressTracker.d.ts +1 -1
- package/types/structures/path/builder.d.ts +5 -4
- package/types/structures/path/builder.helpers.d.ts +8 -0
- package/types/structures/path/types.d.ts +32 -27
- package/types/structures/path/types.helpers.d.ts +23 -0
- package/types/structures/promiseCache.d.ts +1 -1
- package/types/types/misc.d.ts +4 -0
- package/cjs/api/helpers.js +0 -32
- package/cjs/api/helpers.js.map +0 -1
- package/cjs/api/processor.js +0 -51
- package/cjs/api/processor.js.map +0 -1
- package/cjs/api/register.js +0 -25
- package/cjs/api/register.js.map +0 -1
- package/esm/api/helpers.js +0 -25
- package/esm/api/helpers.js.map +0 -1
- package/esm/api/processor.js +0 -46
- package/esm/api/processor.js.map +0 -1
- package/esm/api/register.js +0 -19
- package/esm/api/register.js.map +0 -1
- package/types/api/helpers.d.ts +0 -9
- package/types/api/processor.d.ts +0 -7
- package/types/api/register.d.ts +0 -7
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AnyObject } from '../types/misc.js';
|
|
2
|
+
import type { EndpointCallArgs, IRequestConfig, IRequestMeta, RequestExtra } from './call.types.js';
|
|
3
|
+
import { EndpointsPathsConfig } from './config.js';
|
|
4
|
+
import type { IEndpointInfo } from './endpoint.types.js';
|
|
5
|
+
import type { LogTypes } from './logging.js';
|
|
6
|
+
export declare function createConfig<T extends IEndpointInfo, TExtra extends object = Record<string, any>>(endpointsConfig: EndpointsPathsConfig, api: T, data?: EndpointCallArgs<T> | null, extra?: RequestExtra<T> & TExtra): {
|
|
7
|
+
config: IRequestConfig<T, IEndpointInfo.ExtractIn<T, object>, TExtra>;
|
|
8
|
+
resultInput: NonNullable<EndpointCallArgs<T>> | null | undefined;
|
|
9
|
+
pathInputs: Record<string, string | number>;
|
|
10
|
+
queryInputs: AnyObject;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Request meta wrapped in a class for:
|
|
14
|
+
*
|
|
15
|
+
* - not being a plain object
|
|
16
|
+
* - being able to extend it in the future with helpful methods
|
|
17
|
+
*/
|
|
18
|
+
export declare class RequestMeta<T extends IEndpointInfo, TExtra extends object = Record<string, any>> implements IRequestMeta<T, TExtra> {
|
|
19
|
+
readonly api: T;
|
|
20
|
+
readonly pathsConfig: EndpointsPathsConfig;
|
|
21
|
+
readonly log: LogTypes;
|
|
22
|
+
readonly noLoader: boolean;
|
|
23
|
+
readonly extra: TExtra;
|
|
24
|
+
constructor(api: T, pathsConfig?: EndpointsPathsConfig, log?: LogTypes, noLoader?: boolean, extra?: TExtra);
|
|
25
|
+
}
|
|
@@ -1,53 +1,56 @@
|
|
|
1
1
|
import type { AnyObject } from '../types/misc.js';
|
|
2
|
+
import { EndpointsPathsConfig, type IEndpointsPathsConfig } from './config.js';
|
|
2
3
|
import type { IEndpointInfo } from './endpoint.types.js';
|
|
3
4
|
import type { LogTypes } from './logging.js';
|
|
4
5
|
import type { EndpointMethods } from './methods.js';
|
|
6
|
+
import type { CallerHooks } from './hooks.js';
|
|
5
7
|
/** Request options to be used by call implementation (e.g. interceptor). Passed as separate object argument to the call method. */
|
|
6
8
|
export type RequestExtra<T> = {
|
|
7
9
|
headers?: IEndpointInfo.ExtractHeaders<T>;
|
|
8
10
|
log?: LogTypes<IEndpointInfo.ExtractIn<T>, IEndpointInfo.ExtractOut<T>>;
|
|
9
11
|
noLoader?: boolean;
|
|
10
12
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
/** axios/fetch compatible interface for data passed as request config */
|
|
14
|
+
export interface IRequestRawConfig<TIn> {
|
|
15
|
+
method: EndpointMethods;
|
|
13
16
|
url: string;
|
|
14
17
|
data: TIn | null | undefined;
|
|
15
18
|
headers: AnyObject;
|
|
16
|
-
}
|
|
19
|
+
}
|
|
20
|
+
export interface IRequestMeta<T extends IEndpointInfo, TExtra extends object> {
|
|
21
|
+
readonly api: T;
|
|
22
|
+
readonly pathsConfig: EndpointsPathsConfig;
|
|
23
|
+
readonly log: LogTypes;
|
|
24
|
+
readonly noLoader: boolean;
|
|
25
|
+
readonly extra: TExtra;
|
|
26
|
+
}
|
|
17
27
|
/** Compiled request config object passed to `request` implementation */
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
export interface IRequestConfig<T extends IEndpointInfo = IEndpointInfo, TIn = IEndpointInfo.ExtractIn<T>, TExtra extends object = Record<string, any>> extends IRequestRawConfig<TIn> {
|
|
29
|
+
/**
|
|
30
|
+
* Extends raw config with additional details.
|
|
31
|
+
* */
|
|
32
|
+
readonly _meta: IRequestMeta<T, TExtra>;
|
|
33
|
+
}
|
|
34
|
+
export type CallerResponse<TOut> = {
|
|
35
|
+
data: TOut;
|
|
24
36
|
};
|
|
25
37
|
export type CallerOptions<TExtra extends object = Record<string, any>> = {
|
|
26
38
|
/** Request implementation */
|
|
27
|
-
request: <TIn, TOut>(config:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
hooks
|
|
31
|
-
|
|
32
|
-
* Called before config is created, to validate result input data.
|
|
33
|
-
* May throw to abort request. Use for input validation if needed.
|
|
34
|
-
*/
|
|
35
|
-
beforeConfig?: <T extends IEndpointInfo = IEndpointInfo>(api: T, body: IEndpointInfo.ExtractIn<T, object>, pathParams: IEndpointInfo.ExtractPath<T, object>, queryParams: IEndpointInfo.ExtractQuery<T, object>) => Promise<void> | void;
|
|
36
|
-
/**
|
|
37
|
-
* Called before request is sent.
|
|
38
|
-
* The config can be mutated or returned as updated object – in the latter case it will be merged into original config via `Object.assign`.
|
|
39
|
-
* This is useful for adding headers or modifying request data.
|
|
40
|
-
*/
|
|
41
|
-
beforeRequest?: <T extends IEndpointInfo = IEndpointInfo, TIn = IEndpointInfo.ExtractIn<T>, TExtra extends object = Record<string, any>>(config: RequestConfigDetails<T, TIn, TExtra>) => Promise<void> | void | Promise<RequestConfigDetails<T, TIn, TExtra>> | RequestConfigDetails<T, TIn, TExtra>;
|
|
42
|
-
};
|
|
39
|
+
request: <TIn, TOut>(config: IRequestConfig<IEndpointInfo, TIn, TExtra>) => Promise<CallerResponse<TOut>>;
|
|
40
|
+
/** Endpoints paths config */
|
|
41
|
+
config?: IEndpointsPathsConfig;
|
|
42
|
+
/** Optional hooks for pre- or post-processing request */
|
|
43
|
+
hooks?: CallerHooks<TExtra> | CallerHooks<TExtra>[];
|
|
43
44
|
};
|
|
44
45
|
type CombineInputs<T extends IEndpointInfo> = IEndpointInfo.ExtractIn<T, object> & IEndpointInfo.ExtractPath<T, object> & IEndpointInfo.ExtractQuery<T, object>;
|
|
45
46
|
export type EndpointCallArgs<T extends IEndpointInfo> = object extends CombineInputs<T> ? (null | undefined | object) : CombineInputs<T>;
|
|
46
47
|
type CallerParams<T extends IEndpointInfo, TExtra extends object> = object extends CombineInputs<T> ? [data?: EndpointCallArgs<T>, extra?: RequestExtra<T> & TExtra] : [data: EndpointCallArgs<T>, extra?: RequestExtra<T> & TExtra];
|
|
47
48
|
export interface GenericApiCaller<TExtra extends object = Record<string, any>> {
|
|
48
49
|
<T extends IEndpointInfo>(api: T, ...[data, extra]: CallerParams<T, TExtra>): Promise<IEndpointInfo.ExtractOut<T>>;
|
|
50
|
+
readonly config: EndpointsPathsConfig;
|
|
49
51
|
}
|
|
50
52
|
export interface ApiCaller<TEndpoint extends IEndpointInfo, TExtra extends object = Record<string, any>> {
|
|
51
53
|
(...[data, extra]: CallerParams<TEndpoint, TExtra>): Promise<IEndpointInfo.ExtractOut<TEndpoint>>;
|
|
54
|
+
readonly config: EndpointsPathsConfig;
|
|
52
55
|
}
|
|
53
56
|
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Path } from '../structures/path/index.js';
|
|
2
|
+
import type { Nullable } from '../types/misc.js';
|
|
3
|
+
import type { IEndpointInfo } from './endpoint.js';
|
|
4
|
+
export interface IEndpointsPathsConfig {
|
|
5
|
+
/** Prefix for template args, defaults to `:` */
|
|
6
|
+
readonly templateArgPrefix: Path.TemplateTransform;
|
|
7
|
+
/** Base prefix for path, defaults to `/` */
|
|
8
|
+
readonly basePrefix: string;
|
|
9
|
+
}
|
|
10
|
+
type PrefixOptions = string | boolean;
|
|
11
|
+
export declare class EndpointsPathsConfig implements IEndpointsPathsConfig {
|
|
12
|
+
readonly templateArgPrefix: Path.TemplateTransform;
|
|
13
|
+
readonly basePrefix: string;
|
|
14
|
+
constructor(settings?: IEndpointsPathsConfig);
|
|
15
|
+
getPath<T extends IEndpointInfo.Base & IEndpointInfo.IPathAbstract>(endpoint: T, pathArgs: IEndpointInfo.ExtractPath<T>, prefix?: PrefixOptions): string;
|
|
16
|
+
getTemplate<T extends IEndpointInfo>(endpoint: T, prefix?: PrefixOptions): string;
|
|
17
|
+
getFormattedDisplayName(endpoint: IEndpointInfo): string;
|
|
18
|
+
getEndpointsEqual(a: Nullable<IEndpointInfo>, b: Nullable<IEndpointInfo>): boolean;
|
|
19
|
+
private getPrefix;
|
|
20
|
+
}
|
|
21
|
+
/** @deprecated Be careful with using this shared instance. Don't be lazy and create your own! */
|
|
22
|
+
export declare const DefaultSettings: EndpointsPathsConfig;
|
|
23
|
+
export {};
|
package/types/api/endpoint.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface ApiEndpoint extends IEndpointInfo.Base {
|
|
|
29
29
|
withErrors<TErr>(errorProcessor?: (err: TErr) => void): this & IEndpointInfo.IErrors<TErr>;
|
|
30
30
|
/** Applies headers type. */
|
|
31
31
|
withHeaders<THeads>(_headersMarker?: THeads): this & IEndpointInfo.IHeaders<THeads>;
|
|
32
|
+
/** Helper chain method for finalizing the type. Can make some runtime optimizations as well. */
|
|
33
|
+
finalize(): IEndpointInfo.Finalized<this>;
|
|
32
34
|
}
|
|
33
35
|
export declare namespace ApiEndpoint {
|
|
34
36
|
function isEndpoint(obj: any): obj is IEndpointInfo;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Path } from '../structures/path/index.js';
|
|
2
|
-
import
|
|
2
|
+
import { RemoveFunctionFields } from '../types/functions.js';
|
|
3
|
+
import type { AnyObject, Coalesce, EmptyObjectNullable, Expand } from '../types/misc.js';
|
|
3
4
|
import type { EndpointMethods } from './methods.js';
|
|
4
5
|
/**
|
|
5
6
|
* Definition of an abstract REST API endpoint.
|
|
@@ -61,5 +62,7 @@ export declare namespace IEndpointInfo {
|
|
|
61
62
|
export type ExtractOut<T> = T extends IOut<infer TOut> ? TOut : never;
|
|
62
63
|
export type ExtractErrors<T> = T extends IErrors<infer TErrors> ? TErrors : Any;
|
|
63
64
|
export type ExtractHeaders<T> = T extends IHeaders<infer THeaders> ? THeaders : Any;
|
|
65
|
+
type MergeOmit<T, K> = Omit<T, keyof K> & K;
|
|
66
|
+
export type Finalized<T extends Base> = Expand<Readonly<RemoveFunctionFields<MergeOmit<T, IIn<ExtractIn<T, object | null>>> & MergeOmit<T, IOut<ExtractOut<T>>> & MergeOmit<T, IPath<T extends IPath<infer TPath> ? TPath : Path.IBuilder>> & MergeOmit<T, IQuery<ExtractQuery<T, object>>> & MergeOmit<T, IErrors<ExtractErrors<T>>> & MergeOmit<T, IHeaders<ExtractHeaders<T>>>>>>;
|
|
64
67
|
export {};
|
|
65
68
|
}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import type { ApiEndpoint, IEndpointInfo } from '../endpoint.js';
|
|
2
|
+
import { CallerHooks } from '../hooks.js';
|
|
2
3
|
/**
|
|
3
4
|
* Request Content-Type extension for endpoint.
|
|
4
5
|
*
|
|
5
6
|
*/
|
|
6
7
|
export interface IEndpointInputContentType {
|
|
7
|
-
/**
|
|
8
|
+
/** Endpoint request content-type, if was specified. */
|
|
8
9
|
readonly contentType?: string;
|
|
9
|
-
/** Marks this endpoint with Content-Type header to be set as 'application/x-www-form-urlencoded'. */
|
|
10
|
+
/** Marks this endpoint with Content-Type request header to be set as 'application/x-www-form-urlencoded'. */
|
|
10
11
|
asUrlEncoded(): this;
|
|
11
|
-
/** Marks this endpoint with Content-Type header to be set as 'multipart/form-data'. */
|
|
12
|
+
/** Marks this endpoint with Content-Type request header to be set as 'multipart/form-data'. */
|
|
12
13
|
asMultipartForm(): this;
|
|
13
|
-
/** Marks this endpoint with Content-Type header to be set as 'application/json'. */
|
|
14
|
+
/** Marks this endpoint with Content-Type request header to be set as 'application/json'. */
|
|
14
15
|
asJson(): this;
|
|
15
|
-
/** Marks this endpoint with Content-Type header to be set as passed value. */
|
|
16
|
+
/** Marks this endpoint with Content-Type request header to be set as passed value. */
|
|
16
17
|
withContentType(contentType: string): this;
|
|
17
18
|
}
|
|
18
19
|
export declare namespace IEndpointInputContentType {
|
|
19
20
|
const extender: ApiEndpoint.IBuilderExtender<IEndpointInputContentType>;
|
|
20
21
|
function guard(api: IEndpointInfo): api is (IEndpointInfo & IEndpointInputContentType);
|
|
21
22
|
function tryApplyContentType(api: IEndpointInfo, headers: Record<string, string>): void;
|
|
23
|
+
function createHooks(): CallerHooks<object>;
|
|
22
24
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ApiEndpoint, IEndpointInfo } from '../endpoint.js';
|
|
2
|
+
import { CallerHooks } from '../hooks.js';
|
|
3
|
+
/**
|
|
4
|
+
* Caller hooks on endpoint level.
|
|
5
|
+
*/
|
|
6
|
+
export interface IEndpointHooks {
|
|
7
|
+
/** Endpoint hooks object, used during request. */
|
|
8
|
+
readonly hooks?: CallerHooks;
|
|
9
|
+
/** Adds caller hooks to this endpoint */
|
|
10
|
+
withHooks(hooks: CallerHooks): this;
|
|
11
|
+
}
|
|
12
|
+
export declare namespace IEndpointHooks {
|
|
13
|
+
const extender: ApiEndpoint.IBuilderExtender<IEndpointHooks>;
|
|
14
|
+
function guard(api: IEndpointInfo): api is (IEndpointInfo & IEndpointHooks);
|
|
15
|
+
function createHooks(): CallerHooks;
|
|
16
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AnyObject } from '../../types/misc.js';
|
|
2
2
|
import type { ApiEndpoint } from '../endpoint.js';
|
|
3
3
|
import type { IEndpointInfo } from '../endpoint.types.js';
|
|
4
|
+
import { CallerHooks } from '../hooks.js';
|
|
4
5
|
export interface IEndpointInputValidation {
|
|
5
6
|
readonly validate?: IEndpointInputValidation.Validator<IEndpointInfo.ExtractIn<this, AnyObject>>;
|
|
6
7
|
withValidation(validator: IEndpointInputValidation.Validator<IEndpointInfo.ExtractIn<this>>): this;
|
|
@@ -10,4 +11,5 @@ export declare namespace IEndpointInputValidation {
|
|
|
10
11
|
const extender: ApiEndpoint.IBuilderExtender<IEndpointInputValidation>;
|
|
11
12
|
function guard(api: IEndpointInfo): api is (IEndpointInfo & IEndpointInputValidation);
|
|
12
13
|
function tryValidate(api: IEndpointInfo, input: AnyObject): void | Promise<void>;
|
|
14
|
+
function createHooks(): CallerHooks<object>;
|
|
13
15
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Nullable } from '../types/misc.js';
|
|
2
|
+
import type { CallerResponse, IRequestConfig } from './call.types.js';
|
|
3
|
+
import type { IEndpointInfo } from './endpoint.types.js';
|
|
4
|
+
export type CallerHooks<TExtra extends object = object> = {
|
|
5
|
+
/**
|
|
6
|
+
* Called before config is created, to validate result input data.
|
|
7
|
+
* May throw to abort request. Use for input validation if needed.
|
|
8
|
+
* Objects are cloned to avoid mutation.
|
|
9
|
+
*/
|
|
10
|
+
beforeConfig?: <T extends IEndpointInfo = IEndpointInfo>(api: T, body: IEndpointInfo.ExtractIn<T, object>, pathParams: IEndpointInfo.ExtractPath<T, object>, queryParams: IEndpointInfo.ExtractQuery<T, object>) => CallerHooks.HookReturnType;
|
|
11
|
+
/**
|
|
12
|
+
* Called before request is sent.
|
|
13
|
+
* The config can be mutated or returned as updated object – in the latter case it will be merged into original config via `Object.assign`.
|
|
14
|
+
* This is useful for adding headers or modifying request data.
|
|
15
|
+
*/
|
|
16
|
+
beforeRequest?: <T extends IEndpointInfo = IEndpointInfo, TIn = IEndpointInfo.ExtractIn<T>>(config: IRequestConfig<T, TIn, TExtra>) => CallerHooks.HookReturnType<void | IRequestConfig<T, TIn, TExtra>>;
|
|
17
|
+
/**
|
|
18
|
+
* Called after response is receieved.
|
|
19
|
+
* The config can be mutated or returned as updated object – in the latter case it will be merged into original config via `Object.assign`.
|
|
20
|
+
* This is useful for adding headers or modifying request data.
|
|
21
|
+
*/
|
|
22
|
+
afterResponse?: <T extends IEndpointInfo = IEndpointInfo, TIn = IEndpointInfo.ExtractIn<T>, TOut = IEndpointInfo.ExtractOut<T>, TResponse extends CallerResponse<TOut> = CallerResponse<TOut>>(config: IRequestConfig<T, TIn, TExtra>, response: TResponse) => CallerHooks.HookReturnType<void | TResponse>;
|
|
23
|
+
};
|
|
24
|
+
export declare namespace CallerHooks {
|
|
25
|
+
type HookReturnType<T = void> = T | Promise<T>;
|
|
26
|
+
function merge<TExtra extends object>(items: Nullable<CallerHooks<TExtra> | CallerHooks<TExtra>[]>): CallerHooks<TExtra>;
|
|
27
|
+
}
|
package/types/api/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export type { ProcessingFn } from './processor.js';
|
|
2
1
|
export { ApiEndpoint } from './endpoint.js';
|
|
3
2
|
export type * from './endpoint.types.js';
|
|
4
3
|
export { EndpointMethods } from './methods.js';
|
|
5
|
-
export * from './
|
|
4
|
+
export * from './config.js';
|
|
6
5
|
export { buildApiCaller } from './call.js';
|
|
7
6
|
export { buildApi, createEndpointCallable } from './builder.js';
|
|
8
|
-
export { registerPostProcessor, registerPreProcessor } from './register.js';
|
|
9
7
|
export { LogTypes } from './logging.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type IEvent } from '../observing/event.js';
|
|
2
|
+
import type { CallerHooks } from './hooks.js';
|
|
3
|
+
export type Interceptors<TExtra extends object = object> = {
|
|
4
|
+
[K in keyof CallerHooks<TExtra> as `intercept${Capitalize<K>}`]-?: IEvent<Parameters<NonNullable<CallerHooks<TExtra>[K]>>>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Experimental. Creates linked caller hooks and interception events.
|
|
8
|
+
*
|
|
9
|
+
* Use hooks to recieve events and events to subscribe to them externally.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createInterceptor<TExtra extends object = object>(): {
|
|
12
|
+
hooks: CallerHooks<TExtra>;
|
|
13
|
+
events: Interceptors<TExtra>;
|
|
14
|
+
};
|
package/types/api/logging.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ILogger } from '../logger/abstractions.js';
|
|
2
2
|
import type { Nullable } from '../types/index.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { IRequestConfig } from './call.js';
|
|
4
4
|
/** Describes the way a request is logged.
|
|
5
5
|
*
|
|
6
6
|
* Useful for granular control over logging, especially in production.
|
|
@@ -26,7 +26,7 @@ export declare namespace LogTypes {
|
|
|
26
26
|
*
|
|
27
27
|
* See the other overload for more details.
|
|
28
28
|
*/
|
|
29
|
-
function logCall(logger: ILogger, cfg:
|
|
29
|
+
function logCall(logger: ILogger, cfg: IRequestConfig, dir: 'req'): void;
|
|
30
30
|
/**
|
|
31
31
|
* An example implementation for logging logic (overload for a request with data).
|
|
32
32
|
*
|
|
@@ -35,5 +35,5 @@ export declare namespace LogTypes {
|
|
|
35
35
|
* * Formats the data if a custom formatter is provided.
|
|
36
36
|
* * Logs the data via specified logger.
|
|
37
37
|
*/
|
|
38
|
-
function logCall(logger: ILogger, cfg:
|
|
38
|
+
function logCall(logger: ILogger, cfg: IRequestConfig, dir: 'res', data: unknown): void;
|
|
39
39
|
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { Getter } from '../types/index.js';
|
|
2
|
-
|
|
2
|
+
import { ILogger } from '../logger/abstractions.js';
|
|
3
|
+
type AssertFn = (condition: boolean, error: Getter<string | Error>, objectToLog?: Getter<any>) => asserts condition;
|
|
4
|
+
export declare function createAssert(logger: ILogger): AssertFn;
|
|
5
|
+
export declare const assert: AssertFn;
|
|
6
|
+
export {};
|
package/types/logger/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ILogger, LoggerFunction } from './abstractions.js';
|
|
2
2
|
import { ConsoleLogger } from './console.js';
|
|
3
3
|
import { batchLoggers } from './batch.js';
|
|
4
|
-
import { LoggerModes } from './manager.js';
|
|
5
|
-
export type { ILogger, LoggerFunction };
|
|
4
|
+
import { LoggerModes, LoggersManager } from './manager.js';
|
|
5
|
+
export type { ILogger, LoggerFunction, LoggerModes };
|
|
6
6
|
export { NamedLogger } from './named.js';
|
|
7
7
|
export { ConsoleLogger, batchLoggers };
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export
|
|
8
|
+
export { LoggersManager };
|
|
9
|
+
/** Shared logger instance used internally in this library.
|
|
10
|
+
*
|
|
11
|
+
* For internal default loggers to be enabled and working, don't forget to set the mode to this instance.
|
|
12
|
+
*/
|
|
13
|
+
export * as SharedLogger from './shared.js';
|
|
@@ -19,4 +19,11 @@ export declare class LoggersManager {
|
|
|
19
19
|
detach(instance: ILogger, terminate?: boolean): boolean;
|
|
20
20
|
private _findInstance;
|
|
21
21
|
private _createImplementation;
|
|
22
|
+
expose(): {
|
|
23
|
+
createLogger: (name: string | undefined, mode?: undefined | LoggerModes) => ILogger;
|
|
24
|
+
detachLogger: (instance: ILogger, terminate?: boolean) => boolean;
|
|
25
|
+
setMode: (mode: LoggerModes | null | undefined) => void;
|
|
26
|
+
getMode: () => LoggerModes;
|
|
27
|
+
logger: ILogger;
|
|
28
|
+
};
|
|
22
29
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ILogger } from './abstractions.js';
|
|
2
|
+
import { LoggerModes } from './manager.js';
|
|
3
|
+
export type { ILogger, LoggerModes };
|
|
4
|
+
/** @deprecated Uses shared `LoggersManager` instance, it's better to create your own. */
|
|
5
|
+
export declare const createLogger: (name: string | undefined, mode?: undefined | LoggerModes) => ILogger;
|
|
6
|
+
/** @deprecated Uses shared `LoggersManager` instance, it's better to create your own. */
|
|
7
|
+
export declare const detachLogger: (instance: ILogger, terminate?: boolean) => boolean;
|
|
8
|
+
/** @deprecated Uses shared `LoggersManager` instance, it's better to create your own. */
|
|
9
|
+
export declare const setMode: (mode: LoggerModes | null | undefined) => void;
|
|
10
|
+
/** @deprecated Uses shared `LoggersManager` instance, it's better to create your own. */
|
|
11
|
+
export declare const getMode: () => LoggerModes;
|
|
12
|
+
/** @deprecated Uses shared `LoggersManager` instance, it's better to create your own. */
|
|
13
|
+
declare const logger: ILogger;
|
|
14
|
+
/** @deprecated Uses shared `LoggersManager` instance, it's better to create your own. */
|
|
15
|
+
export default logger;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExclusiveLoadingError, LoadingModel } from './Loading.js';
|
|
2
2
|
import { Getter } from '../types/index.js';
|
|
3
3
|
import { PromiseExtended } from '../structures/promiseExtended.js';
|
|
4
|
-
import { ILogger } from '../logger/
|
|
4
|
+
import { ILogger } from '../logger/shared.js';
|
|
5
5
|
export type ActionRunOptions = {
|
|
6
6
|
/** Action name, required for logging and joining. */
|
|
7
7
|
name?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Predicate } from '../types/index.js';
|
|
2
|
-
import { ILogger } from '../logger/
|
|
2
|
+
import { ILogger } from '../logger/shared.js';
|
|
3
3
|
export type EventHandler<T = any> = (data?: T) => void | Promise<void>;
|
|
4
4
|
type Unsubscribe = () => void;
|
|
5
5
|
export interface IEvent<T = any> {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BaseInput, CombineBuilders,
|
|
2
|
-
export * from './types.js';
|
|
1
|
+
import { BaseInput, CombineBuilders, SwitchBuilder } from './types.js';
|
|
2
|
+
export type * from './types.js';
|
|
3
|
+
export type { TemplateTransform } from './types.helpers.js';
|
|
3
4
|
/** Tagged template literal to create a path builder */
|
|
4
5
|
export declare function build<TArgs extends string[]>(strings: TemplateStringsArray, ...params: TArgs): SwitchBuilder<TArgs>;
|
|
5
|
-
export declare const Empty: StaticBuilder;
|
|
6
|
+
export declare const Empty: import("./types.js").StaticBuilder;
|
|
6
7
|
/**
|
|
7
8
|
* For input, use any amount of arguments, each one can be:
|
|
8
9
|
*
|
|
@@ -12,4 +13,4 @@ export declare const Empty: StaticBuilder;
|
|
|
12
13
|
* - manually implementing `Builder<string[]>`
|
|
13
14
|
* - another `construct` call
|
|
14
15
|
*/
|
|
15
|
-
export declare function construct<TArr extends BaseInput[]>(...
|
|
16
|
+
export declare function construct<TArr extends BaseInput[]>(...inputsRaw: TArr): CombineBuilders<TArr>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BaseInput, Builder, StaticBuilder, StaticInput } from './types.js';
|
|
2
|
+
export declare const staticFactory: (strings: readonly string[]) => StaticBuilder;
|
|
3
|
+
export declare function constructStatic(input: StaticInput): StaticBuilder & {
|
|
4
|
+
asOptional?(): never;
|
|
5
|
+
};
|
|
6
|
+
export declare function constructDynamic(strings: TemplateStringsArray, ...paramsRaw: string[]): StaticBuilder | Builder<readonly string[]>;
|
|
7
|
+
export declare function guardIsStatic(value: any): value is StaticInput;
|
|
8
|
+
export declare function normalizeInput(inputs: BaseInput[]): BaseInput[];
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { EmptyObject, LengthArray, Nullable } from '../../types/misc.js';
|
|
1
|
+
import type { EmptyObject, Expand, IsNever, LengthArray, Nullable } from '../../types/misc.js';
|
|
2
|
+
import type { ArgValue, IsOptional, ReadonlyArrayNormalized, TemplateTransform, ToOptionalArray, ToRequired, ToRequiredArray, TransformMap } from './types.helpers.js';
|
|
2
3
|
import type { CombineOptions } from './utils.js';
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[
|
|
9
|
-
}
|
|
4
|
+
export type ObjectBuilderArgs<TArgs extends string, TFallback = EmptyObject> = string extends TArgs ? TFallback : ArgRecord<TArgs>;
|
|
5
|
+
export type BuilderArgs<TArgs extends string, L extends number = number> = LengthArray<ArgValue | null, L> | ArgRecord<TArgs>;
|
|
6
|
+
export type ArgRecord<T extends string> = Expand<{
|
|
7
|
+
[K in T as true extends IsOptional<K> ? never : K]: ArgValue;
|
|
8
|
+
} & {
|
|
9
|
+
[K in T as true extends IsOptional<K> ? ToRequired<K> : never]?: ArgValue | null;
|
|
10
|
+
}>;
|
|
10
11
|
/** Internal, Don't use it directly */
|
|
11
|
-
interface BaseBuilder<A extends readonly string[], B
|
|
12
|
+
interface BaseBuilder<A extends readonly string[], B> {
|
|
12
13
|
/**
|
|
13
14
|
* Builds the path using provided args.
|
|
14
15
|
*
|
|
@@ -20,14 +21,15 @@ interface BaseBuilder<A extends readonly string[], B, P = TemplatePrefixing> {
|
|
|
20
21
|
/**
|
|
21
22
|
* Template builder that will build the path using args names but also can:
|
|
22
23
|
* - keep args as they were in the template
|
|
23
|
-
* - add a prefix for each key in case `
|
|
24
|
-
* - format each key in case `
|
|
24
|
+
* - add a prefix for each key in case `transform` is provided as string
|
|
25
|
+
* - format each key in case `transform` is provided as function
|
|
26
|
+
* - append prefix/suffix/optional suffix for each key in case `transform` is provided as object
|
|
25
27
|
*
|
|
26
28
|
* For now it's recommended to cache the result, internally it doesn't care about it.
|
|
27
29
|
*/
|
|
28
|
-
template: (
|
|
30
|
+
template: (transform?: Nullable<TemplateTransform>, options?: CombineOptions) => string;
|
|
29
31
|
/** args as they were in the template */
|
|
30
|
-
readonly args: A
|
|
32
|
+
readonly args: ReadonlyArrayNormalized<ToRequiredArray<A>>;
|
|
31
33
|
/**
|
|
32
34
|
* Types helper method to easily cast all kinds of builders to generic IBuilder or others.
|
|
33
35
|
* It just always returns the passed object, so it's the implementation's responsibility to ensure the compatibility.
|
|
@@ -44,29 +46,32 @@ interface BaseBuilder<A extends readonly string[], B, P = TemplatePrefixing> {
|
|
|
44
46
|
/** Allows to specify **template** transformation per key for the current builder instance. */
|
|
45
47
|
withTemplateTransform: (transforms: TransformMap<A>) => this;
|
|
46
48
|
}
|
|
47
|
-
export type TransformMap<A extends readonly string[]> = {
|
|
48
|
-
[K in A[number]]?: (v: ArgValue) => string;
|
|
49
|
-
};
|
|
50
49
|
type EmptyBuilderArgs = [] | Record<PropertyKey, never>;
|
|
51
|
-
|
|
52
|
-
export interface Builder<TArgs extends readonly string[], TOptional = false> extends BaseBuilder<ReadonlyArr<TArgs>, true extends TOptional ? MakeOptional<BuilderArgs<TArgs[number], TArgs['length']>> : BuilderArgs<TArgs[number], TArgs['length']>> {
|
|
50
|
+
export interface Builder<TArgs extends readonly string[]> extends BaseBuilder<ReadonlyArrayNormalized<TArgs>, BuilderArgs<TArgs[number], TArgs['length']>> {
|
|
53
51
|
/** Marks input type for `build` to be `Partial`, so any/all arguments can be omitted.
|
|
54
52
|
*
|
|
55
53
|
* **Limitation**: will convert to optional ALL parameters if >=2 Builders combined via CombineBuilders
|
|
56
54
|
*/
|
|
57
|
-
asOptional(): Builder<TArgs
|
|
55
|
+
asOptional(): Builder<ToOptionalArray<TArgs>>;
|
|
58
56
|
}
|
|
59
57
|
export interface StaticBuilder extends BaseBuilder<readonly [], EmptyBuilderArgs> {
|
|
60
58
|
}
|
|
61
59
|
export interface IBuilder extends BaseBuilder<readonly string[], any> {
|
|
62
60
|
}
|
|
63
61
|
export type StaticInput = string | readonly string[];
|
|
64
|
-
export type BaseInput = StaticInput | BaseBuilder<any, any
|
|
65
|
-
export type
|
|
66
|
-
|
|
67
|
-
export type ExtractArgs<T> = T extends Builder<infer TArgs> ? TArgs : readonly string[];
|
|
68
|
-
export type ExtractObjectArgs<T, F = EmptyObject> = T extends Builder<infer TArgs
|
|
69
|
-
|
|
70
|
-
type
|
|
71
|
-
|
|
62
|
+
export type BaseInput = StaticInput | BaseBuilder<any, any>;
|
|
63
|
+
export type SwitchBuilder<TArg extends readonly string[]> = IsNever<TArg, StaticBuilder, [
|
|
64
|
+
] extends TArg ? StaticBuilder : (readonly string[] extends TArg ? IBuilder : Builder<TArg>)>;
|
|
65
|
+
export type ExtractArgs<T> = T extends Builder<infer TArgs> ? ToRequiredArray<TArgs> : readonly string[];
|
|
66
|
+
export type ExtractObjectArgs<T, F = EmptyObject> = T extends Builder<infer TArgs> ? ObjectBuilderArgs<TArgs[number], F> : F;
|
|
67
|
+
/** Normalizes builder, makes sure dynamic args are inferrable. If input is not a builder (i.e. StaticInput), return StaticBuilder */
|
|
68
|
+
type Output<TInput> = TInput extends StaticBuilder ? StaticBuilder : (TInput extends Builder<infer TArgs> ? Builder<TArgs> : (TInput extends StaticInput ? DynamicStringToBuilder<TInput> : StaticBuilder));
|
|
69
|
+
/** Turns two inputs into one builder, merging static and dynamic args */
|
|
70
|
+
type CombineTwo<T1 extends BaseInput, T2 extends BaseInput> = Output<T1> extends StaticBuilder ? Output<T2> : (Output<T2> extends StaticBuilder ? Output<T1> : (Output<T1> extends Builder<infer Arr1> ? (Output<T2> extends Builder<infer Arr2> ? Builder<[...Arr1, ...Arr2]> : never) : never));
|
|
71
|
+
export type CombineBuilders<T extends readonly BaseInput[]> = T extends readonly [infer T1 extends BaseInput, infer T2 extends BaseInput, ...infer Rest] ? (CombineTwo<T1, T2> extends infer C extends BaseBuilder<infer _A extends readonly string[], any> & BaseInput ? (Rest extends readonly BaseInput[] ? CombineBuilders<readonly [C, ...Rest]> : never) : never) : (T extends readonly [infer T1] ? Output<T1> : StaticBuilder);
|
|
72
|
+
type Splitter<T extends string> = T extends `${infer Head extends string}/${infer Rest}` ? [Head, ...Splitter<Rest>] : [T];
|
|
73
|
+
type ExtractDynamic<T extends string> = T extends `:${infer Arg}` ? [Arg] : T;
|
|
74
|
+
type SkipStaticParts<T extends readonly string[]> = T extends readonly [infer Head extends string, ...infer Rest extends readonly string[]] ? ExtractDynamic<Head> extends [infer Arg] ? [Arg, ...SkipStaticParts<Rest>] : SkipStaticParts<Rest> : [];
|
|
75
|
+
type ExtractDynamicParts<T extends StaticInput> = T extends readonly string[] ? SkipStaticParts<T> : (T extends string ? SkipStaticParts<Splitter<T>> : []);
|
|
76
|
+
type DynamicStringToBuilder<T extends StaticInput> = [] extends ExtractDynamicParts<T> ? StaticBuilder : Builder<ExtractDynamicParts<T>>;
|
|
72
77
|
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type IsOptional<T extends string> = T extends `${string}?` ? true : false;
|
|
2
|
+
export type ToOptional<T extends string> = T extends `${infer Arg}?` ? `${Arg}?` : `${T}?`;
|
|
3
|
+
export type ToOptionalArray<T extends readonly string[]> = T extends readonly [infer Head extends string, ...infer Rest extends readonly string[]] ? [ToOptional<Head>, ...ToOptionalArray<Rest>] : [];
|
|
4
|
+
export type ToRequired<T extends string> = T extends `${infer Arg}?` ? Arg : T;
|
|
5
|
+
export type ToRequiredArray<T extends readonly string[]> = T extends readonly [infer Head extends string, ...infer Rest extends readonly string[]] ? [ToRequired<Head>, ...ToRequiredArray<Rest>] : T;
|
|
6
|
+
export type ReadonlyArrayNormalized<TArr extends ReadonlyArray<unknown>> = TArr extends ReadonlyArray<infer T> ? ReadonlyArray<T> : never;
|
|
7
|
+
export type ArgValue = string | number | boolean;
|
|
8
|
+
export type ArgumentInfo = {
|
|
9
|
+
raw: string;
|
|
10
|
+
name: string;
|
|
11
|
+
index: number;
|
|
12
|
+
isOptional: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type TemplateTransformOptions = {
|
|
15
|
+
prefix: string;
|
|
16
|
+
suffix: string;
|
|
17
|
+
optionalSuffix: string;
|
|
18
|
+
};
|
|
19
|
+
export type TransformFunction<TValue extends ArgValue = ArgValue> = (value: TValue, info: ArgumentInfo) => string;
|
|
20
|
+
export type TemplateTransform = string | Partial<TemplateTransformOptions> | TransformFunction<string>;
|
|
21
|
+
export type TransformMap<A extends readonly string[]> = {
|
|
22
|
+
[K in A[number]]?: TransformFunction;
|
|
23
|
+
};
|
package/types/types/misc.d.ts
CHANGED
|
@@ -36,3 +36,7 @@ export type PickNullable<T, K extends keyof T> = {
|
|
|
36
36
|
export type EmptyObjectNullable = (EmptyObject | null | undefined);
|
|
37
37
|
export type IsNever<T, Y, N> = [T] extends [never] ? Y : N;
|
|
38
38
|
export type Coalesce<T, TReplace = EmptyObjectNullable> = [T] extends [never] | [null] | [undefined] ? TReplace : T;
|
|
39
|
+
/** Intellisense helper to show type unions/intersections as a whole type */
|
|
40
|
+
export type Expand<T> = T extends infer O ? {
|
|
41
|
+
[K in keyof O]: O[K];
|
|
42
|
+
} : never;
|
package/cjs/api/helpers.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultSettings = void 0;
|
|
4
|
-
exports.setDefaults = setDefaults;
|
|
5
|
-
exports.getPath = getPath;
|
|
6
|
-
exports.getTemplate = getTemplate;
|
|
7
|
-
exports.getFormattedDisplayName = getFormattedDisplayName;
|
|
8
|
-
const index_js_1 = require("../structures/path/index.js");
|
|
9
|
-
exports.DefaultSettings = {
|
|
10
|
-
templateArgPrefix: ':',
|
|
11
|
-
basePrefix: '/',
|
|
12
|
-
};
|
|
13
|
-
function setDefaults(settings) {
|
|
14
|
-
Object.assign(exports.DefaultSettings, settings);
|
|
15
|
-
}
|
|
16
|
-
const getPrefix = (prefix) => typeof prefix === 'string' ? prefix : (prefix ? exports.DefaultSettings.basePrefix : false);
|
|
17
|
-
function getPath(endpoint, pathArgs, prefix = true) {
|
|
18
|
-
const path = endpoint.path ?? index_js_1.Path.Empty;
|
|
19
|
-
return path.build(pathArgs || undefined, { addStart: getPrefix(prefix) });
|
|
20
|
-
}
|
|
21
|
-
function getTemplate(endpoint, prefix = true) {
|
|
22
|
-
const path = endpoint.path ?? index_js_1.Path.Empty;
|
|
23
|
-
return path.template(exports.DefaultSettings.templateArgPrefix, { addStart: getPrefix(prefix) });
|
|
24
|
-
}
|
|
25
|
-
function getFormattedDisplayName(endpoint) {
|
|
26
|
-
const template = getTemplate(endpoint);
|
|
27
|
-
const prefix = endpoint.displayName
|
|
28
|
-
? `[${endpoint.displayName}] `
|
|
29
|
-
: '';
|
|
30
|
-
return prefix + template;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=helpers.js.map
|
package/cjs/api/helpers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/api/helpers.ts"],"names":[],"mappings":";;;AAQA,kCAEC;AAKD,0BAQC;AAED,kCAIC;AAED,0DAMC;AArCD,0DAAmD;AAGtC,QAAA,eAAe,GAAG;IAC3B,iBAAiB,EAAE,GAAoC;IACvD,UAAU,EAAE,GAAG;CAClB,CAAC;AAEF,SAAgB,WAAW,CAAC,QAAyC;IACjE,MAAM,CAAC,MAAM,CAAC,uBAAe,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAGD,MAAM,SAAS,GAAG,CAAC,MAAqB,EAAE,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,uBAAe,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAEjI,SAAgB,OAAO,CACnB,QAAW,EACX,QAAsC,EACtC,SAA2B,IAAI;IAE/B,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAK,eAAI,CAAC,KAAuB,CAAC;IAE5D,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,SAAS,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED,SAAgB,WAAW,CAA0B,QAAW,EAAE,SAA2B,IAAI;IAC7F,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAK,eAAI,CAAC,KAAuB,CAAC;IAE5D,OAAO,IAAI,CAAC,QAAQ,CAAC,uBAAe,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC7F,CAAC;AAED,SAAgB,uBAAuB,CAAC,QAAuB;IAC3D,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW;QAC/B,CAAC,CAAC,IAAI,QAAQ,CAAC,WAAW,IAAI;QAC9B,CAAC,CAAC,EAAE,CAAC;IACT,OAAO,MAAM,GAAG,QAAQ,CAAC;AAC7B,CAAC"}
|