@aeriajs/types 0.0.74 → 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.
@@ -1,6 +1,5 @@
1
1
  import type { Context } from './context.js';
2
- import type { InferProperty } from './schema.js';
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 ? InferProperty<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferResponse<TContract['response']> : any) extends infer Response ? Payload extends undefined ? (payload: Payload | undefined, context: ContextParameter) => Response : (payload: Payload, context: ContextParameter) => Response : never : never;
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/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 {};
@@ -56,7 +56,7 @@ export type FixedObjectProperty = {
56
56
  export type VariableObjectProperty = {
57
57
  variable: true;
58
58
  } | {
59
- additionalProperties: Property;
59
+ additionalProperties: boolean | Property;
60
60
  };
61
61
  export type ObjectProperty = (FixedObjectProperty | VariableObjectProperty) & {
62
62
  type: 'object';
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 MapSchemaUnion<TSchema> = TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends any ? SchemaOption extends {
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
  } : {
@@ -1,6 +1,4 @@
1
- import type { Result } from './result.js';
2
1
  import type { Context } from './context.js';
3
- import type { ACError } from './accessControl.js';
4
2
  export type OwnershipMode = boolean | 'always' | 'on-write';
5
3
  export declare enum RateLimitingError {
6
4
  Unauthenticated = "UNAUTHENTICATED",
@@ -38,8 +36,10 @@ export type CollectionHookProps<TPayload = any> = {
38
36
  childId?: string;
39
37
  payload: TPayload;
40
38
  };
41
- export type CollectionHook<TPayload = any> = (props: CollectionHookProps, context: Context) => Promise<Result.Either<ACError, TPayload>>;
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
42
  export type CollectionMiddleware = {
43
- beforeRead: CollectionHook;
44
- beforeWrite: CollectionHook;
43
+ beforeRead: Middleware;
44
+ beforeWrite: Middleware;
45
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.74",
3
+ "version": "0.0.75",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",