@aeriajs/types 0.0.25 → 0.0.27
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/condition.d.ts +11 -2
- package/dist/config.d.ts +3 -2
- package/dist/context.d.ts +10 -8
- package/dist/contract.d.ts +5 -2
- package/dist/http.d.ts +1 -0
- package/package.json +1 -1
package/dist/condition.d.ts
CHANGED
|
@@ -4,7 +4,14 @@ export type FinalCondition<TSchema extends JsonSchema = any> = {
|
|
|
4
4
|
operator: FinalOperator;
|
|
5
5
|
term1: PropertiesWithId<TSchema>;
|
|
6
6
|
term2: any;
|
|
7
|
-
|
|
7
|
+
fromState?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type RegexCondition<TSchema extends JsonSchema = any> = {
|
|
10
|
+
operator: 'regex';
|
|
11
|
+
term1: PropertiesWithId<TSchema>;
|
|
12
|
+
term2: string;
|
|
13
|
+
fromState?: boolean;
|
|
14
|
+
regexOptions?: string;
|
|
8
15
|
};
|
|
9
16
|
export type TruthyCondition<TSchema extends JsonSchema = any> = {
|
|
10
17
|
operator: 'truthy';
|
|
@@ -19,4 +26,6 @@ export type AndCondition<TSchema extends JsonSchema = any> = {
|
|
|
19
26
|
export type NotCondition<TSchema extends JsonSchema = any> = {
|
|
20
27
|
not: Condition<TSchema>;
|
|
21
28
|
};
|
|
22
|
-
export type Condition<TSchema extends JsonSchema = any> = FinalCondition<TSchema> | TruthyCondition<TSchema> | AndCondition<TSchema> | OrCondition<TSchema> | NotCondition<TSchema
|
|
29
|
+
export type Condition<TSchema extends JsonSchema = any> = (FinalCondition<TSchema> | RegexCondition<TSchema> | TruthyCondition<TSchema> | AndCondition<TSchema> | OrCondition<TSchema> | NotCondition<TSchema>) & {
|
|
30
|
+
else?: any;
|
|
31
|
+
};
|
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RouteContext, RouteUri } from '.';
|
|
2
2
|
export type ApiConfig = {
|
|
3
3
|
secret?: string;
|
|
4
4
|
apiUrl?: string;
|
|
5
|
+
apiBase?: RouteUri;
|
|
5
6
|
port?: number;
|
|
6
7
|
paginationLimit?: number;
|
|
7
8
|
database?: {
|
|
@@ -24,5 +25,5 @@ export type ApiConfig = {
|
|
|
24
25
|
}>;
|
|
25
26
|
logSuccessfulAuthentications?: boolean;
|
|
26
27
|
tokenUserProperties?: string[];
|
|
27
|
-
errorHandler?: <TError extends Error>(context:
|
|
28
|
+
errorHandler?: <TError extends Error>(context: RouteContext, error: TError) => any | Promise<any>;
|
|
28
29
|
};
|
package/dist/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Collection as MongoCollection } from 'mongodb';
|
|
|
2
2
|
import type { GenericRequest, GenericResponse } from './http';
|
|
3
3
|
import type { Description, PackReferences, SchemaWithId, FunctionPath, DecodedToken, ApiConfig, CollectionDocument, CollectionFunctions } from '.';
|
|
4
4
|
export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
|
|
5
|
-
type OmitContextParameter<TFunction> = TFunction extends () => any ? TFunction : TFunction extends (payload: infer Payload, context: Context, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
|
|
5
|
+
type OmitContextParameter<TFunction> = TFunction extends () => any ? TFunction : TFunction extends (payload: undefined, ...args: any[]) => infer Return ? () => Return : TFunction extends (payload: infer Payload, context: Context, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
|
|
6
6
|
type RestParameters<TFunction> = TFunction extends (payload: any, context: Context, ...args: infer Rest) => any ? Rest : never;
|
|
7
7
|
type UnionFunctions<TFunctions, TSchema extends CollectionDocument<any>> = {
|
|
8
8
|
[P in keyof TFunctions]: (P extends keyof CollectionFunctions<any> ? CollectionFunctions<TSchema>[P] extends infer CollFunction ? CollFunction extends (...args: any[]) => any ? Extract<undefined, Parameters<CollFunction>[0]> extends never ? (payload: Parameters<CollFunction>[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : (payload?: Parameters<CollFunction>[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : never : never : OmitContextParameter<TFunctions[P]>) extends (...args: infer Args) => infer Return ? Return extends Promise<any> ? (...args: Args) => Return : (...args: Args) => Promise<Return> : never;
|
|
@@ -26,16 +26,10 @@ export type ContextOptions<TContext> = {
|
|
|
26
26
|
inherited?: boolean;
|
|
27
27
|
calledFunction?: string;
|
|
28
28
|
};
|
|
29
|
-
export type
|
|
30
|
-
description: TDescription;
|
|
31
|
-
collection: TDescription['$id'] extends keyof Collections ? IndepthCollection<{
|
|
32
|
-
description: TDescription;
|
|
33
|
-
functions: TFunctions;
|
|
34
|
-
}> : TDescription;
|
|
29
|
+
export type RouteContext = {
|
|
35
30
|
collections: IndepthCollections;
|
|
36
31
|
functionPath: FunctionPath;
|
|
37
32
|
token: DecodedToken;
|
|
38
|
-
collectionName?: (keyof Collections & string) | string;
|
|
39
33
|
request: GenericRequest;
|
|
40
34
|
response: GenericResponse;
|
|
41
35
|
log: (message: string, details?: any) => Promise<any>;
|
|
@@ -43,4 +37,12 @@ export type Context<TDescription extends Description = any, TFunctions = any> =
|
|
|
43
37
|
inherited: boolean;
|
|
44
38
|
calledFunction: string;
|
|
45
39
|
};
|
|
40
|
+
export type Context<TDescription extends Description = any, TFunctions = any> = RouteContext & {
|
|
41
|
+
description: TDescription;
|
|
42
|
+
collectionName?: (keyof Collections & string) | string;
|
|
43
|
+
collection: TDescription['$id'] extends keyof Collections ? IndepthCollection<{
|
|
44
|
+
description: TDescription;
|
|
45
|
+
functions: TFunctions;
|
|
46
|
+
}> : TDescription;
|
|
47
|
+
};
|
|
46
48
|
export {};
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Property, InferProperty, Context } from '.';
|
|
2
|
+
export type ContractBase = {
|
|
3
|
+
builtin?: boolean;
|
|
4
|
+
};
|
|
2
5
|
export type ContractRoles = {
|
|
3
6
|
roles?: (Collections['user']['item']['roles'][number] | 'root' | 'guest')[];
|
|
4
7
|
};
|
|
5
|
-
export type Contract = {
|
|
8
|
+
export type Contract = ContractBase & ({
|
|
6
9
|
response: Property | Property[];
|
|
7
10
|
} | {
|
|
8
11
|
payload: Property;
|
|
@@ -12,7 +15,7 @@ export type Contract = {
|
|
|
12
15
|
response?: Property | Property[];
|
|
13
16
|
payload?: Property;
|
|
14
17
|
query?: Property;
|
|
15
|
-
};
|
|
18
|
+
});
|
|
16
19
|
export type ContractWithRoles = ContractRoles & Contract;
|
|
17
20
|
export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperty<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferProperty<TContract['response']> : any) extends infer Response ? Payload extends undefined ? (payload: Payload | undefined, context: ContextParameter) => Response : (payload: Payload, context: ContextParameter) => Response : never : never;
|
|
18
21
|
export declare const defineContract: <const TContractWithRoles extends ContractWithRoles>(contract: TContractWithRoles) => TContractWithRoles;
|
package/dist/http.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { ServerResponse, IncomingMessage } from 'http';
|
|
3
3
|
import type { MapSchemaUnion } from '.';
|
|
4
4
|
export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
|
|
5
|
+
export type RouteUri = `/${string}`;
|
|
5
6
|
export type RequestMethod = (typeof REQUEST_METHODS)[number];
|
|
6
7
|
export type GenericRequest = {
|
|
7
8
|
url: string;
|