@openstax/ts-utils 1.29.0 → 1.30.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/dist/cjs/assertions/index.d.ts +7 -3
- package/dist/cjs/config/envConfig.d.ts +1 -1
- package/dist/cjs/config/index.d.ts +7 -7
- package/dist/cjs/config/resolveConfigValue.d.ts +2 -2
- package/dist/cjs/fetch/index.d.ts +16 -16
- package/dist/cjs/fetch/index.js +1 -1
- package/dist/cjs/middleware/apiErrorHandler.d.ts +3 -3
- package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +1 -1
- package/dist/cjs/middleware/index.d.ts +7 -7
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +1 -1
- package/dist/cjs/misc/hashValue.d.ts +2 -2
- package/dist/cjs/misc/helpers.d.ts +11 -11
- package/dist/cjs/misc/merge.d.ts +2 -2
- package/dist/cjs/misc/partitionSequence.d.ts +2 -2
- package/dist/cjs/pagination/index.d.ts +1 -1
- package/dist/cjs/routing/index.d.ts +30 -30
- package/dist/cjs/routing/index.js +18 -8
- package/dist/cjs/routing/validators/zod.d.ts +1 -1
- package/dist/cjs/routing/validators/zod.js +3 -1
- package/dist/cjs/services/accountsGateway/index.d.ts +17 -20
- package/dist/cjs/services/apiGateway/index.d.ts +10 -10
- package/dist/cjs/services/apiGateway/index.js +17 -7
- package/dist/cjs/services/authProvider/browser.d.ts +5 -7
- package/dist/cjs/services/authProvider/decryption.d.ts +3 -7
- package/dist/cjs/services/authProvider/index.d.ts +8 -8
- package/dist/cjs/services/authProvider/subrequest.d.ts +2 -5
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +1 -2
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.d.ts +4 -4
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.js +1 -1
- package/dist/cjs/services/authProvider/utils/userRoleValidator.d.ts +2 -2
- package/dist/cjs/services/documentStore/index.d.ts +7 -7
- package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +7 -9
- package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +7 -9
- package/dist/cjs/services/documentStore/unversioned/file-system.js +17 -7
- package/dist/cjs/services/documentStore/unversioned/index.d.ts +1 -1
- package/dist/cjs/services/documentStore/versioned/dynamodb.d.ts +7 -9
- package/dist/cjs/services/documentStore/versioned/file-system.d.ts +6 -8
- package/dist/cjs/services/documentStore/versioned/index.d.ts +4 -4
- package/dist/cjs/services/exercisesGateway/index.d.ts +9 -13
- package/dist/cjs/services/exercisesGateway/index.js +17 -7
- package/dist/cjs/services/fileServer/index.d.ts +2 -3
- package/dist/cjs/services/fileServer/localFileServer.d.ts +2 -6
- package/dist/cjs/services/fileServer/s3FileServer.d.ts +2 -5
- package/dist/cjs/services/launchParams/signer.d.ts +4 -9
- package/dist/cjs/services/launchParams/verifier.d.ts +4 -7
- package/dist/cjs/services/launchParams/verifier.js +17 -7
- package/dist/cjs/services/logger/index.d.ts +2 -2
- package/dist/cjs/services/logger/index.js +1 -1
- package/dist/cjs/services/lrsGateway/addStatementDefaultFields.d.ts +1 -1
- package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +34 -34
- package/dist/cjs/services/lrsGateway/file-system.d.ts +2 -4
- package/dist/cjs/services/lrsGateway/file-system.js +17 -7
- package/dist/cjs/services/lrsGateway/index.d.ts +29 -32
- package/dist/cjs/services/lrsGateway/index.js +17 -7
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +23 -23
- package/dist/cjs/services/postgresConnection/index.d.ts +3 -10
- package/dist/cjs/services/searchProvider/index.d.ts +7 -7
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +1 -1
- package/dist/cjs/services/searchProvider/openSearch.d.ts +3 -6
- package/dist/cjs/services/searchProvider/openSearch.js +7 -3
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +5 -5
- package/dist/esm/assertions/index.d.ts +7 -3
- package/dist/esm/config/envConfig.d.ts +1 -1
- package/dist/esm/config/index.d.ts +7 -7
- package/dist/esm/config/resolveConfigValue.d.ts +2 -2
- package/dist/esm/fetch/index.d.ts +16 -16
- package/dist/esm/middleware/apiErrorHandler.d.ts +3 -3
- package/dist/esm/middleware/apiSlowResponseMiddleware.d.ts +1 -1
- package/dist/esm/middleware/index.d.ts +7 -7
- package/dist/esm/middleware/lambdaCorsResponseMiddleware.d.ts +1 -1
- package/dist/esm/misc/hashValue.d.ts +2 -2
- package/dist/esm/misc/helpers.d.ts +11 -11
- package/dist/esm/misc/merge.d.ts +2 -2
- package/dist/esm/misc/partitionSequence.d.ts +2 -2
- package/dist/esm/pagination/index.d.ts +1 -1
- package/dist/esm/routing/index.d.ts +30 -30
- package/dist/esm/routing/validators/zod.d.ts +1 -1
- package/dist/esm/routing/validators/zod.js +3 -1
- package/dist/esm/services/accountsGateway/index.d.ts +17 -20
- package/dist/esm/services/apiGateway/index.d.ts +10 -10
- package/dist/esm/services/authProvider/browser.d.ts +5 -7
- package/dist/esm/services/authProvider/decryption.d.ts +3 -7
- package/dist/esm/services/authProvider/index.d.ts +8 -8
- package/dist/esm/services/authProvider/subrequest.d.ts +2 -5
- package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +1 -2
- package/dist/esm/services/authProvider/utils/embeddedAuthProvider.d.ts +4 -4
- package/dist/esm/services/authProvider/utils/userRoleValidator.d.ts +2 -2
- package/dist/esm/services/documentStore/index.d.ts +7 -7
- package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +7 -9
- package/dist/esm/services/documentStore/unversioned/file-system.d.ts +7 -9
- package/dist/esm/services/documentStore/unversioned/index.d.ts +1 -1
- package/dist/esm/services/documentStore/versioned/dynamodb.d.ts +7 -9
- package/dist/esm/services/documentStore/versioned/file-system.d.ts +6 -8
- package/dist/esm/services/documentStore/versioned/index.d.ts +4 -4
- package/dist/esm/services/exercisesGateway/index.d.ts +9 -13
- package/dist/esm/services/fileServer/index.d.ts +2 -3
- package/dist/esm/services/fileServer/localFileServer.d.ts +2 -6
- package/dist/esm/services/fileServer/s3FileServer.d.ts +2 -5
- package/dist/esm/services/launchParams/signer.d.ts +4 -9
- package/dist/esm/services/launchParams/verifier.d.ts +4 -7
- package/dist/esm/services/logger/index.d.ts +2 -2
- package/dist/esm/services/lrsGateway/addStatementDefaultFields.d.ts +1 -1
- package/dist/esm/services/lrsGateway/attempt-utils.d.ts +34 -34
- package/dist/esm/services/lrsGateway/file-system.d.ts +2 -4
- package/dist/esm/services/lrsGateway/index.d.ts +29 -32
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +23 -23
- package/dist/esm/services/postgresConnection/index.d.ts +3 -10
- package/dist/esm/services/searchProvider/index.d.ts +7 -7
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +1 -1
- package/dist/esm/services/searchProvider/openSearch.d.ts +3 -6
- package/dist/esm/services/searchProvider/openSearch.js +7 -3
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +5 -5
- package/package.json +6 -6
- package/script/bin/.init-params-script.bash.swp +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type AssertionFailed = string | Error | (() => never) | undefined;
|
|
2
2
|
export declare const doThrow: (failed: AssertionFailed) => never;
|
|
3
3
|
/**
|
|
4
4
|
* Asserts that the given value is true.
|
|
@@ -70,7 +70,9 @@ export declare const notNaN: <T>(thing: T, failed?: AssertionFailed) => T;
|
|
|
70
70
|
* @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError, new Error('argument was not a SyntaxError'));
|
|
71
71
|
* @returns the value that was asserted
|
|
72
72
|
*/
|
|
73
|
-
export declare const assertInstanceOf: <T>(thing: any, constructable: Function &
|
|
73
|
+
export declare const assertInstanceOf: <T>(thing: any, constructable: Function & {
|
|
74
|
+
new (...args: any[]): T;
|
|
75
|
+
}, failed?: AssertionFailed) => T;
|
|
74
76
|
/**
|
|
75
77
|
* Asserts that the error in the first argument is an instance of the error given as the
|
|
76
78
|
* second argument
|
|
@@ -82,4 +84,6 @@ export declare const assertInstanceOf: <T>(thing: any, constructable: Function &
|
|
|
82
84
|
* @throws the original error if the check fails
|
|
83
85
|
* @see assertInstanceOf
|
|
84
86
|
*/
|
|
85
|
-
export declare const assertErrorInstanceOf: <T extends Error>(thing: unknown, constructable: Function &
|
|
87
|
+
export declare const assertErrorInstanceOf: <T extends Error>(thing: unknown, constructable: Function & {
|
|
88
|
+
new (...args: any[]): T;
|
|
89
|
+
}) => T;
|
|
@@ -21,4 +21,4 @@ export declare const ENV_BUILD_CONFIGS: string[];
|
|
|
21
21
|
*
|
|
22
22
|
* @example const config = { configValue: envConfig('environment_variable_name') };
|
|
23
23
|
*/
|
|
24
|
-
export declare const envConfig: (name: string, type?: "build" | "runtime"
|
|
24
|
+
export declare const envConfig: (name: string, type?: "build" | "runtime", defaultValue?: ConfigValueProvider<string>) => ConfigValueProvider<string>;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A simple type alias for a string that represents a configuration value. Currently only string values are supported to maintain compatibility with environment variables, but this type is future proofing against allowing other types like `number` as possible config values.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type ConfigValue = string;
|
|
5
5
|
/**
|
|
6
6
|
* A configuration object that may contain nested configuration objects or configuration values.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export type Config = {
|
|
9
9
|
[key: string]: Config | ConfigValue;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Either a function that returns a `ConfigValue` or a `Promise` that resolves to a `ConfigValue`,
|
|
13
13
|
* or just a `ConfigValue`.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export type ConfigValueProvider<V extends ConfigValue = ConfigValue> = (() => Promise<V> | V) | V;
|
|
16
16
|
/**
|
|
17
17
|
* A configuration object that may contain nested configuration objects or configuration value providers.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
19
|
+
export type ConfigProvider = {
|
|
20
20
|
[key: string]: ConfigProvider | ConfigValueProvider;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
23
|
* Conditional type that resolves to the type of configuration object for the given configuration
|
|
24
24
|
* provider. Also resolves to a config value type if the given type is a config value.
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
26
|
+
export type ConfigForConfigProvider<T> = T extends ConfigValue ? T : T extends ConfigProvider ? {
|
|
27
27
|
[key in keyof T]: ConfigForConfigProvider<T[key]>;
|
|
28
28
|
} : T extends ConfigValueProvider<infer R> ? R : never;
|
|
29
29
|
/**
|
|
@@ -31,7 +31,7 @@ export declare type ConfigForConfigProvider<T> = T extends ConfigValue ? T : T e
|
|
|
31
31
|
* type (`ConfigValue` or `Config`). The resulting type is either a `ConfigValueProvider` or
|
|
32
32
|
* a `ConfigProvider`.
|
|
33
33
|
*/
|
|
34
|
-
export
|
|
34
|
+
export type ConfigProviderForConfig<T> = T extends ConfigValue ? ConfigValueProvider<T> : T extends Config ? {
|
|
35
35
|
[key in keyof T]: ConfigProviderForConfig<T[key]>;
|
|
36
36
|
} : never;
|
|
37
37
|
export * from './resolveConfigValue';
|
|
@@ -41,7 +41,7 @@ export * from './resolveConfigValue';
|
|
|
41
41
|
*
|
|
42
42
|
* @example const config = { configValue: stubConfig('just-a-string') };
|
|
43
43
|
*/
|
|
44
|
-
export declare const stubConfig: <V extends
|
|
44
|
+
export declare const stubConfig: <V extends ConfigValue>(configValue: V) => ConfigValueProvider<V>;
|
|
45
45
|
export * from './envConfig';
|
|
46
46
|
export * from './replaceConfig';
|
|
47
47
|
export * from './awsParameterConfig';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ConfigValueProvider } from '.';
|
|
1
|
+
import type { ConfigValue, ConfigValueProvider } from '.';
|
|
2
2
|
/**
|
|
3
3
|
* resolves a config value into a string, to be used inside of things that are provided configurations
|
|
4
4
|
*/
|
|
5
|
-
export declare const resolveConfigValue: <V extends
|
|
5
|
+
export declare const resolveConfigValue: <V extends ConfigValue>(provider: ConfigValueProvider<V>) => Promise<V>;
|
|
@@ -5,44 +5,44 @@ export declare enum FetchStateType {
|
|
|
5
5
|
LOADING = "loading",
|
|
6
6
|
IDLE = "idle"
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
8
|
+
export type FetchState<D, E> = FetchStateLoading<D> | FetchStateError<D, E> | FetchStateSuccess<D> | FetchStateIdle;
|
|
9
|
+
type FetchStateLoading<D> = {
|
|
10
10
|
type: FetchStateType.LOADING;
|
|
11
11
|
data?: D;
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
type FetchStateError<D, E> = {
|
|
14
14
|
type: FetchStateType.ERROR;
|
|
15
15
|
data?: D;
|
|
16
16
|
error: E;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
type FetchStateSuccess<D> = {
|
|
19
19
|
type: FetchStateType.SUCCESS;
|
|
20
20
|
data: D;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
type FetchStateIdle = {
|
|
23
23
|
type: FetchStateType.IDLE;
|
|
24
24
|
};
|
|
25
|
-
export declare const fetchLoading: <D, E>(previous?: FetchState<D, E>
|
|
26
|
-
export declare const fetchError: <D, E>(error: E, previous?: FetchState<D, E>
|
|
25
|
+
export declare const fetchLoading: <D, E>(previous?: FetchState<D, E>) => FetchStateLoading<D>;
|
|
26
|
+
export declare const fetchError: <D, E>(error: E, previous?: FetchState<D, E>) => FetchStateError<D, E>;
|
|
27
27
|
export declare const fetchSuccess: <D>(data: D) => FetchStateSuccess<D>;
|
|
28
28
|
export declare const fetchIdle: () => FetchStateIdle;
|
|
29
29
|
export declare const stateHasData: <D, E>(state: {
|
|
30
30
|
type: FetchStateType;
|
|
31
|
-
data?: D
|
|
32
|
-
error?: E
|
|
31
|
+
data?: D;
|
|
32
|
+
error?: E;
|
|
33
33
|
}) => state is {
|
|
34
34
|
type: FetchStateType;
|
|
35
35
|
data: D;
|
|
36
36
|
};
|
|
37
37
|
export declare const stateHasError: <D, E>(state: {
|
|
38
38
|
type: FetchStateType;
|
|
39
|
-
data?: D
|
|
40
|
-
error?: E
|
|
39
|
+
data?: D;
|
|
40
|
+
error?: E;
|
|
41
41
|
}) => state is {
|
|
42
42
|
type: FetchStateType;
|
|
43
43
|
error: E;
|
|
44
44
|
};
|
|
45
|
-
export
|
|
45
|
+
export type FetchConfig = {
|
|
46
46
|
credentials?: 'include' | 'omit' | 'same-origin';
|
|
47
47
|
method?: METHOD;
|
|
48
48
|
body?: string;
|
|
@@ -50,15 +50,15 @@ export declare type FetchConfig = {
|
|
|
50
50
|
[key: string]: string;
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
type Headers = {
|
|
54
54
|
get: (name: string) => string | null;
|
|
55
55
|
};
|
|
56
|
-
export
|
|
56
|
+
export type Response = {
|
|
57
57
|
status: number;
|
|
58
58
|
headers: Headers;
|
|
59
59
|
json: () => Promise<any>;
|
|
60
60
|
text: () => Promise<string>;
|
|
61
61
|
};
|
|
62
|
-
export
|
|
63
|
-
export
|
|
62
|
+
export type GenericFetch<C extends FetchConfig = FetchConfig, R extends Response = Response> = (url: string, fetchConfig?: C) => Promise<R>;
|
|
63
|
+
export type ConfigForFetch<F> = F extends GenericFetch<infer C, any> ? C : never;
|
|
64
64
|
export {};
|
package/dist/cjs/fetch/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var FetchStateType;
|
|
|
14
14
|
FetchStateType["ERROR"] = "error";
|
|
15
15
|
FetchStateType["LOADING"] = "loading";
|
|
16
16
|
FetchStateType["IDLE"] = "idle";
|
|
17
|
-
})(FetchStateType
|
|
17
|
+
})(FetchStateType || (exports.FetchStateType = FetchStateType = {}));
|
|
18
18
|
/*
|
|
19
19
|
* keeps existing data but sets the new status
|
|
20
20
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ForbiddenError, InvalidRequestError, NotFoundError, SessionExpiredError, UnauthorizedError, ValidationError } from '../errors';
|
|
2
2
|
import type { ApiResponse } from '../routing';
|
|
3
3
|
import type { Logger } from '../services/logger';
|
|
4
|
-
export
|
|
4
|
+
export type DefaultErrors = {
|
|
5
5
|
InvalidRequestError: InvalidRequestError;
|
|
6
6
|
UnauthorizedError: UnauthorizedError;
|
|
7
7
|
ForbiddenError: ForbiddenError;
|
|
@@ -9,7 +9,7 @@ export declare type DefaultErrors = {
|
|
|
9
9
|
ValidationError: ValidationError;
|
|
10
10
|
SessionExpiredError: SessionExpiredError;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type Handlers<E> = {
|
|
13
13
|
[T in keyof E]?: (e: E[T], logger: Logger) => ApiResponse<number, any>;
|
|
14
14
|
};
|
|
15
15
|
export declare const defaultHandlers: Handlers<DefaultErrors>;
|
|
@@ -21,4 +21,4 @@ export declare const defaultHandlers: Handlers<DefaultErrors>;
|
|
|
21
21
|
*
|
|
22
22
|
* @param inputHandlers a map of errors to handler functions
|
|
23
23
|
*/
|
|
24
|
-
export declare const createErrorHandler: <Errors = DefaultErrors>(inputHandlers?: Handlers<Errors>
|
|
24
|
+
export declare const createErrorHandler: <Errors = DefaultErrors>(inputHandlers?: Handlers<Errors>) => (e: Error, logger: Logger) => Promise<ApiResponse<number, any>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ConfigProviderForConfig } from '../config';
|
|
2
2
|
import type { ApiResponse } from '../routing';
|
|
3
3
|
import type { Logger } from '../services/logger';
|
|
4
|
-
|
|
4
|
+
type Config = {
|
|
5
5
|
logResponseSlowerThan: string;
|
|
6
6
|
timeoutResponseAfter: string;
|
|
7
7
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TupleZip } from '../types';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
2
|
+
export type MiddlewareProvider<Sa, M, A extends any[], R> = (app: Sa, appBinder?: ((app: Sa, provider: MiddlewareProvider<Sa, M, A, R>) => (middleware: M, ...args: A) => R)) => (middleware: M, ...args: A) => R;
|
|
3
|
+
export type MiddlewareTransformProvider<Sa, M, A extends any[], R> = (app: Sa) => (middleware: M, ...args: A) => Omit<M, keyof R> & R;
|
|
4
|
+
export type MiddlewareInput<S> = S extends MiddlewareProvider<any, infer M, any, any> ? M : never;
|
|
5
|
+
export type ServiceMiddlewareProviderResult<M, S> = [M] extends [never] ? never : [M] extends [MiddlewareInput<S>] ? S extends MiddlewareTransformProvider<any, M, any, infer R> ? (Omit<R, keyof M> & M) extends R ? Omit<R, keyof M> & M : R extends M ? R : Omit<M, keyof R> & R : S extends MiddlewareProvider<any, M, any, infer R> ? R : never : never;
|
|
6
|
+
export type ServiceMiddlewareProviderArgs<S> = S extends MiddlewareProvider<any, any, infer A, any> ? A : never;
|
|
7
|
+
export type ServiceMiddlewareProviderChainResult<C, M> = C extends [infer S1, ...infer S] ? S extends never[] ? ServiceMiddlewareProviderResult<M, S1> : ServiceMiddlewareProviderChainResult<S, ServiceMiddlewareProviderResult<M, S1>> : C extends unknown ? M : never;
|
|
8
|
+
export type ServiceMiddlewareProviderChainArgs<C> = C extends [infer S1, ...infer S] ? S extends never[] ? ServiceMiddlewareProviderArgs<S1> : TupleZip<ServiceMiddlewareProviderChainArgs<S>, ServiceMiddlewareProviderArgs<S1>> : C extends unknown ? [] : never;
|
|
9
9
|
/**
|
|
10
10
|
* Creates a middleware composer for given AppServices and input value types. The composer accepts a list of middleware
|
|
11
11
|
* that it assembles into a chain. The function returned by the composer takes a value of the given input value type,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type HashValue = string | number | boolean | null | HashCompoundValue;
|
|
2
|
+
export type HashCompoundValue = Array<HashValue> | {
|
|
3
3
|
[key: string]: HashValue;
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@ import type { Logger } from '../services/logger';
|
|
|
7
7
|
* const getAuthor = getKeyValue('author');
|
|
8
8
|
* const author = getAuthor(book);
|
|
9
9
|
*/
|
|
10
|
-
export declare const getKeyValue: <K extends string>(key: K) => <O extends { [
|
|
10
|
+
export declare const getKeyValue: <K extends string>(key: K) => <O extends { [_key in K]?: any; }>(obj: O) => O[K];
|
|
11
11
|
/**
|
|
12
12
|
* Returns a function that gets the value of the given key from an object, or the given default
|
|
13
13
|
* value if the key is not present.
|
|
@@ -18,7 +18,7 @@ export declare const getKeyValue: <K extends string>(key: K) => <O extends { [ke
|
|
|
18
18
|
* const getAuthorOrNope = getKeyValueOr('author', 'nope');
|
|
19
19
|
* const authorOrNope = getAuthorOrNope(book);
|
|
20
20
|
*/
|
|
21
|
-
export declare const getKeyValueOr: <K extends string, V, Od extends { [
|
|
21
|
+
export declare const getKeyValueOr: <K extends string, V, Od extends { [_key in K]?: any; } = { [_key in K]?: any; }>(key: K, defaultValue: V) => <O extends (Od extends undefined ? { [_key in K]?: any; } : Od)>(obj: O) => NonNullable<O[K]> | V;
|
|
22
22
|
/**
|
|
23
23
|
* Returns a function that sets the value of the given key on an object.
|
|
24
24
|
*
|
|
@@ -27,7 +27,7 @@ export declare const getKeyValueOr: <K extends string, V, Od extends { [key in K
|
|
|
27
27
|
* const putAuthor = putKeyValue('author');
|
|
28
28
|
* const newBook = putAuthor(book, 'tom');
|
|
29
29
|
*/
|
|
30
|
-
export declare const putKeyValue: <K extends string>(key: K) => <O extends { [
|
|
30
|
+
export declare const putKeyValue: <K extends string>(key: K) => <O extends { [_key in K]?: any; }>(obj: O, value: O[K]) => O;
|
|
31
31
|
/**
|
|
32
32
|
* Coerces a value into an array. If the value is already an array, it is returned as-is.
|
|
33
33
|
* If the value is undefined, an empty array is returned.
|
|
@@ -35,17 +35,17 @@ export declare const putKeyValue: <K extends string>(key: K) => <O extends { [ke
|
|
|
35
35
|
* @param thing the value
|
|
36
36
|
* @returns an array
|
|
37
37
|
*/
|
|
38
|
-
export declare const coerceArray: <T>(thing: T | T[]
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
export declare const coerceArray: <T>(thing: undefined | T | T[]) => T[];
|
|
39
|
+
type FlowFn<A, R> = (...args: [A]) => R;
|
|
40
|
+
type AnyFlowFn = FlowFn<any, any>;
|
|
41
|
+
type FlowFnResult<F, A> = F extends FlowFn<A, infer R> ? R : never;
|
|
42
|
+
type FlowResult<C, A> = C extends [infer F1, ...infer Cr] ? F1 extends AnyFlowFn ? Cr extends never[] ? FlowFnResult<F1, A> : FlowResult<Cr, FlowFnResult<F1, A>> : never : never;
|
|
43
|
+
type FlowChainArg<C> = C extends [infer F1, ...infer _] ? F1 extends FlowFn<infer A, any> ? A : never : never;
|
|
44
44
|
/**
|
|
45
45
|
* this is like lodash/flow but it uses a recursive type instead of hard-coding parameters
|
|
46
46
|
*/
|
|
47
47
|
export declare const flow: <C extends AnyFlowFn[]>(...chain: C) => (param: FlowChainArg<C>) => FlowResult<C, FlowChainArg<C>>;
|
|
48
|
-
export
|
|
48
|
+
export type RetryOptions = {
|
|
49
49
|
logger?: Logger;
|
|
50
50
|
wait?: number;
|
|
51
51
|
splay?: number;
|
|
@@ -66,7 +66,7 @@ export declare type RetryOptions = {
|
|
|
66
66
|
* initial wait cliff with incremental increases, then maybe you'd set this. default: 0
|
|
67
67
|
* @returns A promise that resolves with the result of the function, or rejects with the last error.
|
|
68
68
|
*/
|
|
69
|
-
export declare const retryWithDelay: <R>(fn: (abort?: (
|
|
69
|
+
export declare const retryWithDelay: <R>(fn: (abort?: (e: Error) => never) => Promise<R>, options?: RetryOptions) => Promise<R>;
|
|
70
70
|
/**
|
|
71
71
|
* a shameful helper to avoid needing to test code coverage of branches
|
|
72
72
|
*/
|
package/dist/cjs/misc/merge.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { UnionToIntersection } from '../types';
|
|
|
7
7
|
* @param thing2 another object
|
|
8
8
|
* @returns an array of keys, type-limited to those keys
|
|
9
9
|
*/
|
|
10
|
-
export declare const getCommonProperties: <T1 extends {}, T2 extends {}>(thing1: T1, thing2: T2) =>
|
|
10
|
+
export declare const getCommonProperties: <T1 extends {}, T2 extends {}>(thing1: T1, thing2: T2) => Array<keyof T1 & keyof T2>;
|
|
11
11
|
/**
|
|
12
12
|
* recursive merge properties of inputs. values are merged if they are
|
|
13
13
|
* plain objects or arrays, otherwise if the same property exists in both
|
|
@@ -18,4 +18,4 @@ export declare const getCommonProperties: <T1 extends {}, T2 extends {}>(thing1:
|
|
|
18
18
|
*
|
|
19
19
|
* @example merge({thing: 'one'}, {thing: 'two', otherKey: 'one'}, {coolKey: 'coolValue'});
|
|
20
20
|
*/
|
|
21
|
-
export declare const merge: <T extends {}
|
|
21
|
+
export declare const merge: <T extends Array<{}>>(...[thing1, ...tail]: T) => UnionToIntersection<T[number]>;
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* , [1,2,3,5,6,8]
|
|
30
30
|
* )
|
|
31
31
|
*/
|
|
32
|
-
export declare const partitionSequence: <T, P>(getPartition: (thing: T, previous?: P
|
|
33
|
-
matches?: boolean
|
|
32
|
+
export declare const partitionSequence: <T, P>(getPartition: (thing: T, previous?: P) => {
|
|
33
|
+
matches?: boolean;
|
|
34
34
|
value: P;
|
|
35
35
|
}, sequence: T[]) => [P, T[]][];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryParams, RouteMatchRecord } from '../routing';
|
|
2
|
-
export
|
|
2
|
+
export type PaginationHandler<Pa, Q extends QueryParams> = <R>(queryParams: Q, match: RouteMatchRecord<R>) => Pa & {
|
|
3
3
|
getUnusedQueryParams: () => Q;
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { Logger } from '../services/logger';
|
|
2
2
|
/** HTTP query parameters */
|
|
3
|
-
export
|
|
3
|
+
export type QueryParams = Record<string, string | undefined | string[] | null>;
|
|
4
4
|
/**
|
|
5
5
|
* The type for a map of string substitutions to use when building route paths, e.g. a route may
|
|
6
6
|
* be defined as `'/api/:id'` and then rendered as `'/api/123'` when the `id` route param is set
|
|
7
7
|
* to `'123'`
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type RouteParams = {
|
|
10
10
|
[key: string]: string;
|
|
11
11
|
};
|
|
12
12
|
/** A type that is compatible with any `Route` type */
|
|
13
|
-
export
|
|
14
|
-
export
|
|
13
|
+
export type AnyRoute<R> = R extends Route<infer N, infer P, infer Sa, infer Sr, infer Ri, infer Ro> ? Route<N, P, Sa, Sr, Ri, Ro> : never;
|
|
14
|
+
export type AnySpecificRoute<R, Sa, Ri, Ro> = R extends Route<infer N, infer P, Sa, infer Sr, Ri, Ro> & infer E ? Route<N, P, Sa, Sr, Ri, Ro> & E : never;
|
|
15
15
|
/** The inferred "route output" (`Ro`) type for a given route */
|
|
16
|
-
export
|
|
16
|
+
export type OutputForRoute<R> = R extends Route<any, any, any, any, any, infer Ro> ? Ro : never;
|
|
17
17
|
/** The inferred type for the params of the provided route type, `R`; may be undefined */
|
|
18
|
-
export
|
|
18
|
+
export type ParamsForRoute<R> = R extends Route<any, infer P, any, any, any, any> ? P : never;
|
|
19
19
|
/** The inferred type for the request services of the provided route type, `R`. */
|
|
20
|
-
export
|
|
20
|
+
export type RequestServicesForRoute<R> = R extends Route<any, any, any, infer Sr, any, any> ? Sr : never;
|
|
21
21
|
/** The type for the params of the provided route type, `R`; will be `{}` if undefined */
|
|
22
|
-
export
|
|
22
|
+
export type ParamsForRouteOrEmpty<R> = ParamsForRoute<R> extends undefined ? {} : Exclude<ParamsForRoute<R>, undefined>;
|
|
23
23
|
/** derives the route match type for this route, which includes the route itself and the matching params. */
|
|
24
|
-
export
|
|
24
|
+
export type RouteMatchRecord<R> = R extends AnyRoute<R> ? {
|
|
25
25
|
route: R;
|
|
26
26
|
params: ParamsForRoute<R>;
|
|
27
27
|
} : never;
|
|
@@ -29,15 +29,15 @@ export declare type RouteMatchRecord<R> = R extends AnyRoute<R> ? {
|
|
|
29
29
|
* The conditional type for the payload for a given route, `R`. This isn't a route structure, its
|
|
30
30
|
* a convention based on the request middleware
|
|
31
31
|
*/
|
|
32
|
-
export
|
|
32
|
+
export type PayloadForRoute<R> = RequestServicesForRoute<R> extends {
|
|
33
33
|
payload: any;
|
|
34
34
|
} ? RequestServicesForRoute<R>['payload'] : undefined;
|
|
35
|
-
|
|
35
|
+
type RequestServiceProvider<Sa, Sr, Ri> = (app: Sa) => <R>(middleware: {
|
|
36
36
|
request: Ri;
|
|
37
37
|
logger: Logger;
|
|
38
38
|
}, match: RouteMatchRecord<R>) => Sr;
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
type RouteHandler<P, Sr, Ro> = (params: P, request: Sr) => Ro;
|
|
40
|
+
type Route<N extends string, P extends RouteParams | undefined, Sa, Sr, Ri, Ro> = (Sr extends undefined ? {
|
|
41
41
|
requestServiceProvider?: RequestServiceProvider<Sa, Sr, Ri> | undefined;
|
|
42
42
|
} : {
|
|
43
43
|
requestServiceProvider: RequestServiceProvider<Sa, Sr, Ri>;
|
|
@@ -46,7 +46,7 @@ declare type Route<N extends string, P extends RouteParams | undefined, Sa, Sr,
|
|
|
46
46
|
path: string;
|
|
47
47
|
handler: (params: P, request: Sr) => Ro;
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
type CreateRouteConfig<Sa, Sr, Ri, N extends string, Ex> = (Sr extends undefined ? {
|
|
50
50
|
requestServiceProvider?: RequestServiceProvider<Sa, Sr, Ri> | undefined;
|
|
51
51
|
} : {
|
|
52
52
|
requestServiceProvider: RequestServiceProvider<Sa, Sr, Ri>;
|
|
@@ -154,15 +154,15 @@ export declare const makeRenderRouteUrl: <Ru extends {
|
|
|
154
154
|
* @returns the interpolated route path
|
|
155
155
|
*/
|
|
156
156
|
export declare const renderAnyRouteUrl: <R extends any>(route: R, params: ParamsForRoute<R>, query?: QueryParams) => string;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
type RequestPathExtractor<Ri> = (request: Ri) => string;
|
|
158
|
+
type RequestLogExtractor<Ri> = (request: Ri) => JsonCompatibleStruct;
|
|
159
|
+
type RequestRouteMatcher<Ri, R> = (request: Ri, route: R) => boolean;
|
|
160
|
+
type CompatibleServices<T1> = keyof T1 extends 'logger' ? T1 extends {
|
|
161
161
|
logger: Logger;
|
|
162
162
|
} ? T1 : never : T1 & {
|
|
163
163
|
logger?: Logger;
|
|
164
164
|
};
|
|
165
|
-
|
|
165
|
+
type RequestResponder<Sa, Ri, Ro> = {
|
|
166
166
|
(services: CompatibleServices<Sa>): (request: Ri) => Ro | undefined;
|
|
167
167
|
<RoF>(services: CompatibleServices<Sa>, responseMiddleware: (app: Sa) => (response: Ro | undefined, request: {
|
|
168
168
|
request: Ri;
|
|
@@ -202,24 +202,24 @@ declare type RequestResponder<Sa, Ri, Ro> = {
|
|
|
202
202
|
export declare const makeGetRequestResponder: <Sa, Ru, Ri, Ro>() => ({ routes, pathExtractor, routeMatcher, errorHandler, logExtractor }: {
|
|
203
203
|
routes: () => AnySpecificRoute<Ru, Sa, Ri, Ro>[];
|
|
204
204
|
pathExtractor: RequestPathExtractor<Ri>;
|
|
205
|
-
logExtractor?: RequestLogExtractor<Ri
|
|
206
|
-
routeMatcher?: RequestRouteMatcher<Ri, AnySpecificRoute<Ru, Sa, Ri, Ro
|
|
207
|
-
errorHandler?: (
|
|
205
|
+
logExtractor?: RequestLogExtractor<Ri>;
|
|
206
|
+
routeMatcher?: RequestRouteMatcher<Ri, AnySpecificRoute<Ru, Sa, Ri, Ro>>;
|
|
207
|
+
errorHandler?: (e: Error, logger: Logger) => Ro;
|
|
208
208
|
}) => RequestResponder<Sa, Ri, Ro>;
|
|
209
209
|
/** HTTP Headers */
|
|
210
|
-
export
|
|
210
|
+
export type HttpHeaders = {
|
|
211
211
|
[key: string]: string | undefined | string[];
|
|
212
212
|
};
|
|
213
213
|
/** A type that works in JSON */
|
|
214
|
-
export
|
|
214
|
+
export type JsonCompatibleValue = string | number | null | undefined | boolean;
|
|
215
215
|
/** A JSON array type */
|
|
216
|
-
export
|
|
216
|
+
export type JsonCompatibleArray = Array<JsonCompatibleValue | JsonCompatibleStruct | JsonCompatibleStruct>;
|
|
217
217
|
/** A JSON object type */
|
|
218
|
-
export
|
|
218
|
+
export type JsonCompatibleStruct = {
|
|
219
219
|
[key: string]: JsonCompatibleStruct | JsonCompatibleValue | JsonCompatibleArray;
|
|
220
220
|
};
|
|
221
221
|
/** The type for an API response */
|
|
222
|
-
export
|
|
222
|
+
export type ApiResponse<S extends number, T> = {
|
|
223
223
|
isBase64Encoded?: boolean;
|
|
224
224
|
statusCode: S;
|
|
225
225
|
data: T;
|
|
@@ -242,7 +242,7 @@ export declare type ApiResponse<S extends number, T> = {
|
|
|
242
242
|
* { 'X-Frame-Options': 'DENY' }
|
|
243
243
|
* );
|
|
244
244
|
*/
|
|
245
|
-
export declare const apiJsonResponse: <S extends number, T extends JsonCompatibleStruct>(statusCode: S, data: T, headers?: HttpHeaders
|
|
245
|
+
export declare const apiJsonResponse: <S extends number, T extends JsonCompatibleStruct>(statusCode: S, data: T, headers?: HttpHeaders) => ApiResponse<S, T>;
|
|
246
246
|
/**
|
|
247
247
|
* Returns a plain text response. Handles setting the content-type header.
|
|
248
248
|
* @param statusCode e.g. 201
|
|
@@ -250,7 +250,7 @@ export declare const apiJsonResponse: <S extends number, T extends JsonCompatibl
|
|
|
250
250
|
* @param headers HTTP headers
|
|
251
251
|
* @example return apiTextResponse(200, 'some text')
|
|
252
252
|
*/
|
|
253
|
-
export declare const apiTextResponse: <S extends number>(statusCode: S, data: string, headers?: HttpHeaders
|
|
253
|
+
export declare const apiTextResponse: <S extends number>(statusCode: S, data: string, headers?: HttpHeaders) => ApiResponse<S, string>;
|
|
254
254
|
/**
|
|
255
255
|
* Returns an HTML response. Handles setting the content-type header.
|
|
256
256
|
* @param statusCode e.g. 201
|
|
@@ -258,7 +258,7 @@ export declare const apiTextResponse: <S extends number>(statusCode: S, data: st
|
|
|
258
258
|
* @param headers HTTP headers
|
|
259
259
|
* @example return apiHtmlResponse(200, '<b>some text</b>')
|
|
260
260
|
*/
|
|
261
|
-
export declare const apiHtmlResponse: <S extends number>(statusCode: S, data: string, headers?: HttpHeaders
|
|
261
|
+
export declare const apiHtmlResponse: <S extends number>(statusCode: S, data: string, headers?: HttpHeaders) => ApiResponse<S, string>;
|
|
262
262
|
/** HTTP method enum */
|
|
263
263
|
export declare enum METHOD {
|
|
264
264
|
GET = "GET",
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
37
|
};
|
|
@@ -272,5 +282,5 @@ var METHOD;
|
|
|
272
282
|
METHOD["PATCH"] = "PATCH";
|
|
273
283
|
METHOD["DELETE"] = "DELETE";
|
|
274
284
|
METHOD["OPTIONS"] = "OPTIONS";
|
|
275
|
-
})(METHOD
|
|
285
|
+
})(METHOD || (exports.METHOD = METHOD = {}));
|
|
276
286
|
__exportStar(require("./helpers"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
-
export declare const zodPayloadValidator: <T>(validator: z.ZodType<T,
|
|
2
|
+
export declare const zodPayloadValidator: <T extends {}>(validator: z.ZodType<T, T>) => (input: {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}) => input is T;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zodPayloadValidator = void 0;
|
|
4
|
+
/* spell-checker: ignore treeify */
|
|
5
|
+
const zod_1 = require("zod");
|
|
4
6
|
const errors_1 = require("../../errors");
|
|
5
7
|
const zodPayloadValidator = (validator) => (input) => {
|
|
6
8
|
const result = validator.safeParse(input);
|
|
7
9
|
if (result.success) {
|
|
8
10
|
return true;
|
|
9
11
|
}
|
|
10
|
-
throw new errors_1.ValidationError(result.error
|
|
12
|
+
throw new errors_1.ValidationError((0, zod_1.treeifyError)(result.error));
|
|
11
13
|
};
|
|
12
14
|
exports.zodPayloadValidator = zodPayloadValidator;
|