@aeriajs/types 0.0.73 → 0.0.75
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/collection.d.ts +2 -1
- package/dist/contract.d.ts +6 -13
- package/dist/description.d.ts +1 -1
- package/dist/http.d.ts +0 -3
- package/dist/property.d.ts +3 -2
- package/dist/schema.d.ts +2 -2
- package/dist/security.d.ts +14 -0
- package/package.json +1 -1
package/dist/collection.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AccessCondition } from './accessControl.js';
|
|
2
|
-
import type { CollectionSecurityPolicy } from './security.js';
|
|
2
|
+
import type { CollectionSecurityPolicy, CollectionMiddleware } from './security.js';
|
|
3
3
|
import type { Context } from './context.js';
|
|
4
4
|
import type { Contract } from './contract.js';
|
|
5
5
|
import type { Description } from './description.js';
|
|
@@ -10,6 +10,7 @@ export type Collection<TCollection extends Collection = any> = {
|
|
|
10
10
|
contracts?: Record<string, Contract>;
|
|
11
11
|
exposedFunctions?: Record<string, AccessCondition>;
|
|
12
12
|
security?: CollectionSecurityPolicy<TCollection>;
|
|
13
|
+
middlewares?: CollectionMiddleware | CollectionMiddleware[];
|
|
13
14
|
};
|
|
14
15
|
export type CollectionItem<TCollectionName extends keyof Collections> = Omit<Collections[TCollectionName]['item'], '_id'>;
|
|
15
16
|
export type CollectionItemWithId<TCollectionName extends keyof Collections> = Collections[TCollectionName]['item'];
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Context } from './context.js';
|
|
2
|
-
import type {
|
|
3
|
-
import type { InferResponse } from './http.js';
|
|
2
|
+
import type { InferProperties } from './schema.js';
|
|
4
3
|
import type { Property } from './property.js';
|
|
5
4
|
import type { UserRole } from './token.js';
|
|
6
5
|
export type ContractBase = {
|
|
@@ -10,17 +9,11 @@ export type ContractBase = {
|
|
|
10
9
|
export type ContractRoles = {
|
|
11
10
|
roles?: readonly UserRole[] | boolean | 'unauthenticated' | 'unauthenticated-only';
|
|
12
11
|
};
|
|
13
|
-
export type Contract = ContractBase &
|
|
14
|
-
response: Property | Property[];
|
|
15
|
-
} | {
|
|
16
|
-
payload: Property;
|
|
17
|
-
} | {
|
|
18
|
-
query: Property;
|
|
19
|
-
} | {
|
|
12
|
+
export type Contract = ContractBase & {
|
|
20
13
|
response?: Property | Property[];
|
|
21
|
-
payload?: Property;
|
|
22
|
-
query?: Property;
|
|
23
|
-
}
|
|
14
|
+
payload?: Property | Property[];
|
|
15
|
+
query?: Property | Property[];
|
|
16
|
+
};
|
|
24
17
|
export type ContractWithRoles = ContractRoles & Contract;
|
|
25
|
-
export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ?
|
|
18
|
+
export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperties<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferProperties<TContract['response']> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never : any) extends infer Response ? Payload extends undefined ? (payload: Payload | undefined, context: ContextParameter) => Response : (payload: Payload, context: ContextParameter) => Response : never : never;
|
|
26
19
|
export declare const defineContract: <const TContractWithRoles extends ContractWithRoles>(contract: TContractWithRoles) => TContractWithRoles;
|
package/dist/description.d.ts
CHANGED
|
@@ -63,8 +63,8 @@ export type FiltersPreset<TDescription extends Description> = {
|
|
|
63
63
|
};
|
|
64
64
|
export type LayoutName = 'tabular' | 'grid' | 'list';
|
|
65
65
|
export type LayoutOptions<TDescription extends Description = any> = {
|
|
66
|
-
picture?: PropertiesWithId<TDescription>;
|
|
67
66
|
title?: PropertiesWithId<TDescription>;
|
|
67
|
+
picture?: PropertiesWithId<TDescription>;
|
|
68
68
|
badge?: PropertiesWithId<TDescription>;
|
|
69
69
|
information?: PropertiesWithId<TDescription>;
|
|
70
70
|
active?: PropertiesWithId<TDescription>;
|
package/dist/http.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ServerResponse, IncomingMessage } from 'http';
|
|
2
|
-
import type { MapSchemaUnion } from './schema.js';
|
|
3
2
|
import type { Result, ExtractError, ExtractResult } from './result.js';
|
|
4
3
|
import type { EndpointError, StrictEndpointError } from './endpointError.js';
|
|
5
4
|
import type { ACError } from './accessControl.js';
|
|
@@ -36,6 +35,4 @@ export type NativeHTTPErrorStatus = HTTPStatus.Unauthorized | HTTPStatus.TooMany
|
|
|
36
35
|
export type WithACErrors<TRouteResponse> = TRouteResponse extends Result.Either<infer InferredError, unknown> ? Result.Either<ExtractError<TRouteResponse> | StrictEndpointError<ExtractCode<InferredError> | NativeError, unknown, ExtractHTTPStatus<InferredError> | NativeHTTPErrorStatus>, ExtractResult<TRouteResponse>> : TRouteResponse | Result.Error<StrictEndpointError<NativeError, unknown, NativeHTTPErrorStatus>>;
|
|
37
36
|
export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? <T = TRouteResponse>(payload?: any) => Promise<WithACErrors<T>> : TRoutePayload extends undefined ? <T = TRouteResponse>() => Promise<WithACErrors<T>> : <T = TRouteResponse>(payload: TRoutePayload) => Promise<WithACErrors<T>>) extends infer Function ? Record<TRouteMethod, Function> : never;
|
|
38
37
|
export type MakeEndpoint<TRoute extends string, TRouteMethod extends RequestMethod, TRouteResponse = any, TRoutePayload = null> = TRoute extends `/${infer RouteTail}` ? MakeEndpoint<RouteTail, TRouteMethod, TRouteResponse, TRoutePayload> : TRoute extends `${infer Route}/${infer RouteTail}` ? Record<Route, MakeEndpoint<RouteTail, TRouteMethod, TRouteResponse, TRoutePayload>> : TRoute extends `(${string}` ? Record<string, EndpointFunction<TRouteMethod, TRouteResponse, TRoutePayload>> : Record<TRoute, EndpointFunction<TRouteMethod, TRouteResponse, TRoutePayload>>;
|
|
39
|
-
type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
|
|
40
|
-
export type InferResponse<TResponse> = MapSchemaUnion<UnwrapResponse<TResponse>> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never;
|
|
41
38
|
export {};
|
package/dist/property.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { PhosphorIcon } from '@phosphor-icons/core';
|
|
|
2
2
|
import type { Condition } from './condition.js';
|
|
3
3
|
export type PropertyArrayElement = 'checkbox' | 'radio' | 'select';
|
|
4
4
|
export type PropertyInputType = 'text' | 'email' | 'password' | 'search' | 'time' | 'month';
|
|
5
|
+
export type PropertyInputElement = 'input' | 'textarea';
|
|
5
6
|
export type PropertyFormat = 'date' | 'date-time';
|
|
6
7
|
export type PropertiesWithId<TSchema extends JsonSchema> = keyof TSchema['properties'] | '_id';
|
|
7
8
|
export type RequiredProperties<TSchema extends JsonSchema> = readonly PropertiesWithId<TSchema>[] | Partial<Record<PropertiesWithId<TSchema>, Condition<TSchema> | boolean>>;
|
|
@@ -55,7 +56,7 @@ export type FixedObjectProperty = {
|
|
|
55
56
|
export type VariableObjectProperty = {
|
|
56
57
|
variable: true;
|
|
57
58
|
} | {
|
|
58
|
-
additionalProperties: Property;
|
|
59
|
+
additionalProperties: boolean | Property;
|
|
59
60
|
};
|
|
60
61
|
export type ObjectProperty = (FixedObjectProperty | VariableObjectProperty) & {
|
|
61
62
|
type: 'object';
|
|
@@ -70,7 +71,7 @@ export type StringProperty = {
|
|
|
70
71
|
mask?: string | readonly string[];
|
|
71
72
|
maskedValue?: boolean;
|
|
72
73
|
placeholder?: string;
|
|
73
|
-
element?:
|
|
74
|
+
element?: PropertyInputElement;
|
|
74
75
|
inputType?: PropertyInputType;
|
|
75
76
|
};
|
|
76
77
|
export type NumberProperty = {
|
package/dist/schema.d.ts
CHANGED
|
@@ -49,13 +49,13 @@ export type Schema<TSchema> = CaseTimestamped<TSchema, CaseOwned<TSchema, InferS
|
|
|
49
49
|
export type SchemaWithId<TSchema> = Schema<TSchema> & {
|
|
50
50
|
_id: ObjectId;
|
|
51
51
|
};
|
|
52
|
-
export type
|
|
52
|
+
export type InferProperties<TSchema> = TSchema extends readonly any[] ? TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends any ? SchemaOption extends {
|
|
53
53
|
$ref: infer K;
|
|
54
54
|
} | {
|
|
55
55
|
items: {
|
|
56
56
|
$ref: infer K;
|
|
57
57
|
};
|
|
58
|
-
} ? K extends keyof Collections ? 'items' extends keyof SchemaOption ? Collections[K]['item'][] : Collections[K]['item'] : never : InferProperty<SchemaOption> : never : InferProperty<TSchema>;
|
|
58
|
+
} ? K extends keyof Collections ? 'items' extends keyof SchemaOption ? Collections[K]['item'][] : Collections[K]['item'] : never : InferProperty<SchemaOption> : never : never : InferProperty<TSchema>;
|
|
59
59
|
export type ObjectToSchema<TObject, TRequired extends string[] | null = null> = TObject extends readonly [infer K] ? ValueToProperty<[K]> : keyof TObject extends never ? {
|
|
60
60
|
type: 'object';
|
|
61
61
|
} : {
|
package/dist/security.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Context } from './context.js';
|
|
1
2
|
export type OwnershipMode = boolean | 'always' | 'on-write';
|
|
2
3
|
export declare enum RateLimitingError {
|
|
3
4
|
Unauthenticated = "UNAUTHENTICATED",
|
|
@@ -29,3 +30,16 @@ export type CollectionSecurityPolicy<TCollection extends {
|
|
|
29
30
|
}> = {
|
|
30
31
|
functions?: Partial<Record<keyof TCollection['functions'], SecurityPolicy>>;
|
|
31
32
|
};
|
|
33
|
+
export type CollectionHookProps<TPayload = any> = {
|
|
34
|
+
propertyName?: string;
|
|
35
|
+
parentId?: string;
|
|
36
|
+
childId?: string;
|
|
37
|
+
payload: TPayload;
|
|
38
|
+
};
|
|
39
|
+
export type GenericMiddlewareNext<TReturn, TPayload> = (payload: TPayload, initial: TReturn, context: Context) => TReturn | Promise<TReturn>;
|
|
40
|
+
export type MiddlewareNext = <TReturn, TReturnPayload>(payload: TReturnPayload, initial: TReturn, context: Context) => TReturn | Promise<TReturn>;
|
|
41
|
+
export type Middleware<TReturn = any, TPayload = any, TReturnNext extends GenericMiddlewareNext<TReturn, TPayload> = GenericMiddlewareNext<TReturn, TPayload>> = (payload: TPayload, initial: TReturn, context: Context, next: TReturnNext) => TReturn | Promise<TReturn>;
|
|
42
|
+
export type CollectionMiddleware = {
|
|
43
|
+
beforeRead: Middleware;
|
|
44
|
+
beforeWrite: Middleware;
|
|
45
|
+
};
|