@aeriajs/types 0.0.52 → 0.0.53

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.
@@ -10,5 +10,6 @@ export declare enum ACError {
10
10
  InvalidLimit = "INVALID_LIMIT",
11
11
  OwnershipError = "OWNERSHIP_ERROR",
12
12
  ResourceNotFound = "RESOURCE_NOT_FOUND",
13
- InsecureOperator = "INSECURE_OPERATOR"
13
+ InsecureOperator = "INSECURE_OPERATOR",
14
+ MalformedInput = "MALFORMED_INPUT"
14
15
  }
@@ -12,4 +12,5 @@ var ACError;
12
12
  ACError["OwnershipError"] = "OWNERSHIP_ERROR";
13
13
  ACError["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
14
14
  ACError["InsecureOperator"] = "INSECURE_OPERATOR";
15
+ ACError["MalformedInput"] = "MALFORMED_INPUT";
15
16
  })(ACError || (exports.ACError = ACError = {}));
@@ -9,5 +9,6 @@ export var ACError = /* @__PURE__ */ ((ACError2) => {
9
9
  ACError2["OwnershipError"] = "OWNERSHIP_ERROR";
10
10
  ACError2["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
11
11
  ACError2["InsecureOperator"] = "INSECURE_OPERATOR";
12
+ ACError2["MalformedInput"] = "MALFORMED_INPUT";
12
13
  return ACError2;
13
14
  })(ACError || {});
package/dist/error.d.ts CHANGED
@@ -3,14 +3,14 @@ export declare const ERROR_SYMBOL_DESCRIPTION = "#__ERROR_SYMBOL__";
3
3
  export declare const ERROR_SYMBOL: unique symbol;
4
4
  export type EndpointErrorContent<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus = HTTPStatus, TMessage extends string = string> = {
5
5
  code: TCode;
6
- httpStatus?: THTTPStatus;
7
6
  details?: TDetails;
7
+ httpStatus?: THTTPStatus;
8
8
  message?: TMessage;
9
9
  };
10
10
  export type StrictEndpointErrorContent<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus | undefined = HTTPStatus, TMessage extends string | undefined = string> = {
11
11
  code: TCode;
12
- httpStatus: THTTPStatus;
13
12
  details?: TDetails;
13
+ httpStatus: THTTPStatus;
14
14
  message?: TMessage;
15
15
  };
16
16
  export type EndpointError<TEndpointErrorContent extends EndpointErrorContent = EndpointErrorContent> = {
@@ -18,3 +18,4 @@ export type EndpointError<TEndpointErrorContent extends EndpointErrorContent = E
18
18
  readonly value: TEndpointErrorContent;
19
19
  };
20
20
  export type ExtractError<T> = T extends EndpointError ? T : never;
21
+ export type ExtractSuccessful<T> = T extends EndpointError ? never : T;
@@ -1,9 +1,9 @@
1
1
  import type { FilterOperators, StrictFilter as Filter, StrictUpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
2
- import type { ACError } from './accessControl.js';
3
2
  import type { EndpointError, StrictEndpointErrorContent } from './error.js';
4
3
  import type { PackReferences } from './schema.js';
4
+ import type { ACError } from './accessControl.js';
5
5
  import type { ValidationErrorCode } from './validation.js';
6
- import type { HTTPStatus } from './http.js';
6
+ import type { HTTPStatus, WithACErrors } from './http.js';
7
7
  export type UploadAuxProps = {
8
8
  parentId: string;
9
9
  propertyName: string;
@@ -68,7 +68,7 @@ export type RemoveFilePayload = UploadAuxProps & {
68
68
  _id: any;
69
69
  };
70
70
  };
71
- export type InsertReturnType<TDocument> = TDocument | EndpointError<StrictEndpointErrorContent<ACError | ValidationErrorCode, unknown, HTTPStatus.NotFound | HTTPStatus.UnprocessableContent>>;
71
+ export type InsertReturnType<TDocument> = TDocument | EndpointError<StrictEndpointErrorContent<ACError.InsecureOperator | ACError.OwnershipError | ACError.ResourceNotFound | ACError.TargetImmutable | ValidationErrorCode, unknown, HTTPStatus.NotFound | HTTPStatus.UnprocessableContent>>;
72
72
  export type GetReturnType<TDocument> = TDocument | EndpointError<StrictEndpointErrorContent<ACError.ResourceNotFound, unknown, HTTPStatus.NotFound>>;
73
73
  export type CollectionFunctions<TDocument extends CollectionDocument<OptionalId<any>>> = {
74
74
  count: (payload: CountPayload<TDocument>) => Promise<number>;
@@ -79,10 +79,16 @@ export type CollectionFunctions<TDocument extends CollectionDocument<OptionalId<
79
79
  removeAll: (payload: RemoveAllPayload) => Promise<any>;
80
80
  removeFile: (payload: RemoveFilePayload) => Promise<any>;
81
81
  };
82
- export type CollectionFunctionsPaginated<TDocument extends CollectionDocument<OptionalId<any>>> = Omit<CollectionFunctions<TDocument>, 'getAll'> & {
83
- getAll: (payload?: GetAllPayload<TDocument>) => Promise<{
82
+ export type CollectionFunctionsSDK<TDocument extends CollectionDocument<OptionalId<any>>> = {
83
+ count: (payload: CountPayload<TDocument>) => Promise<WithACErrors<number>>;
84
+ get: (payload: GetPayload<TDocument>) => Promise<WithACErrors<GetReturnType<TDocument>>>;
85
+ getAll: (payload?: GetAllPayload<TDocument>) => Promise<WithACErrors<{
84
86
  data: TDocument[];
85
87
  pagination: Pagination;
86
- }>;
88
+ }>>;
89
+ insert: (payload: InsertPayload<TDocument>) => Promise<WithACErrors<InsertReturnType<TDocument>>>;
90
+ remove: (payload: RemovePayload<TDocument>) => Promise<WithACErrors<TDocument>>;
91
+ removeAll: (payload: RemoveAllPayload) => Promise<any>;
92
+ removeFile: (payload: RemoveFilePayload) => Promise<any>;
87
93
  };
88
94
  export {};
package/dist/http.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import type { ServerResponse, IncomingMessage } from 'http';
3
3
  import type { MapSchemaUnion } from './schema.js';
4
+ import type { EndpointError, EndpointErrorContent, StrictEndpointErrorContent } from './error.js';
5
+ import type { ACError } from './accessControl.js';
6
+ import type { RateLimitingError } from './security.js';
4
7
  export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
5
8
  export declare enum HTTPStatus {
6
9
  Ok = 200,
@@ -25,7 +28,10 @@ export type GenericRequest = {
25
28
  nodeRequest: IncomingMessage;
26
29
  };
27
30
  export type GenericResponse = ServerResponse;
28
- export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? (payload?: any) => Promise<TRouteResponse> : TRoutePayload extends undefined ? () => Promise<TRouteResponse> : (payload: TRoutePayload) => Promise<TRouteResponse>) extends infer Function ? Record<TRouteMethod, Function> : never;
31
+ type ExtractCode<TRouteResponse> = TRouteResponse extends EndpointError<EndpointErrorContent<infer PCode>> ? PCode : never;
32
+ type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends EndpointError<EndpointErrorContent<any, unknown, infer PHTTPStatus>> ? PHTTPStatus : never;
33
+ export type WithACErrors<TRouteResponse> = Exclude<TRouteResponse, EndpointError<any>> | EndpointError<StrictEndpointErrorContent<ExtractCode<TRouteResponse> | ACError.AuthenticationError | ACError.AuthorizationError | RateLimitingError.LimitReached | RateLimitingError.Unauthenticated, unknown, ExtractHTTPStatus<TRouteResponse> | HTTPStatus.Unauthorized | HTTPStatus.TooManyRequests>>;
34
+ export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? (payload?: any) => Promise<WithACErrors<TRouteResponse>> : TRoutePayload extends undefined ? () => Promise<WithACErrors<TRouteResponse>> : (payload: TRoutePayload) => Promise<WithACErrors<TRouteResponse>>) extends infer Function ? Record<TRouteMethod, Function> : never;
29
35
  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>>;
30
36
  type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
31
37
  export type InferResponse<TResponse> = MapSchemaUnion<UnwrapResponse<TResponse>> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",