@aeriajs/types 0.0.49 → 0.0.51

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,9 +1,7 @@
1
- export type UserRole = (Collections['user']['item']['roles'][number] extends infer UserDefinedRole ? UserDefinedRole extends string ? `${UserDefinedRole}${UserDefinedRole}` extends UserDefinedRole ? 'root' : UserDefinedRole : never : never) | 'root' | 'unauthenticated';
2
- export type AcceptedRole = UserRole | UserRole[] | null | unknown;
1
+ import type { UserRole } from './token.js';
3
2
  export type AccessCondition = readonly UserRole[] | boolean | 'unauthenticated' | 'unauthenticated-only';
4
- export type RoleFromAccessCondition<TAccessCondition extends AccessCondition | undefined> = undefined extends TAccessCondition ? null : number extends keyof TAccessCondition ? TAccessCondition[number] : TAccessCondition extends true ? Exclude<UserRole, 'unauthenticated'> : TAccessCondition extends false ? never : TAccessCondition extends 'unauthenticated-only' ? 'unauthenticated' : TAccessCondition extends 'unauthenticated' ? UserRole : never;
5
- export declare enum ACErrors {
6
- AssetNotFound = "ASSET_NOT_FOUND",
3
+ export type RoleFromAccessCondition<TAccessCondition extends AccessCondition | undefined> = undefined extends TAccessCondition ? null : TAccessCondition extends readonly (infer Role)[] ? Role : TAccessCondition extends true ? Exclude<UserRole, 'unauthenticated'> : TAccessCondition extends false ? never : TAccessCondition extends 'unauthenticated-only' ? 'unauthenticated' : TAccessCondition extends 'unauthenticated' ? UserRole : never;
4
+ export declare enum ACError {
7
5
  AuthenticationError = "AUTHENTICATION_ERROR",
8
6
  AuthorizationError = "AUTHORIZATION_ERROR",
9
7
  FunctionNotFound = "FUNCTION_NOT_FOUND",
@@ -15,4 +13,4 @@ export declare enum ACErrors {
15
13
  OwnershipError = "OWNERSHIP_ERROR",
16
14
  ResourceNotFound = "RESOURCE_NOT_FOUND"
17
15
  }
18
- export declare const ACErrorMessages: Record<ACErrors, string>;
16
+ export declare const ACErrorMessages: Record<ACError, string>;
@@ -1,30 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ACErrorMessages = exports.ACErrors = void 0;
4
- var ACErrors;
5
- (function (ACErrors) {
6
- ACErrors["AssetNotFound"] = "ASSET_NOT_FOUND";
7
- ACErrors["AuthenticationError"] = "AUTHENTICATION_ERROR";
8
- ACErrors["AuthorizationError"] = "AUTHORIZATION_ERROR";
9
- ACErrors["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
10
- ACErrors["FunctionNotExposed"] = "FUNCTION_NOT_EXPOSED";
11
- ACErrors["ImmutabilityIncorrectChild"] = "IMMUTABILITY_INCORRECT_CHILD";
12
- ACErrors["ImmutabilityParentNotFound"] = "IMMUTABILITY_PARENT_NOT_FOUND";
13
- ACErrors["ImmutabilityTargetImmutable"] = "IMMUTABILITY_TARGET_IMMUTABLE";
14
- ACErrors["InvalidLimit"] = "INVALID_LIMIT";
15
- ACErrors["OwnershipError"] = "OWNERSHIP_ERROR";
16
- ACErrors["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
17
- })(ACErrors || (exports.ACErrors = ACErrors = {}));
3
+ exports.ACErrorMessages = exports.ACError = void 0;
4
+ var ACError;
5
+ (function (ACError) {
6
+ ACError["AuthenticationError"] = "AUTHENTICATION_ERROR";
7
+ ACError["AuthorizationError"] = "AUTHORIZATION_ERROR";
8
+ ACError["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
9
+ ACError["FunctionNotExposed"] = "FUNCTION_NOT_EXPOSED";
10
+ ACError["ImmutabilityIncorrectChild"] = "IMMUTABILITY_INCORRECT_CHILD";
11
+ ACError["ImmutabilityParentNotFound"] = "IMMUTABILITY_PARENT_NOT_FOUND";
12
+ ACError["ImmutabilityTargetImmutable"] = "IMMUTABILITY_TARGET_IMMUTABLE";
13
+ ACError["InvalidLimit"] = "INVALID_LIMIT";
14
+ ACError["OwnershipError"] = "OWNERSHIP_ERROR";
15
+ ACError["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
16
+ })(ACError || (exports.ACError = ACError = {}));
18
17
  exports.ACErrorMessages = {
19
- [ACErrors.AssetNotFound]: 'collection has no registered functions',
20
- [ACErrors.AuthenticationError]: 'you have insufficient privileges',
21
- [ACErrors.AuthorizationError]: 'you have insufficient privileges',
22
- [ACErrors.FunctionNotFound]: 'function not found',
23
- [ACErrors.FunctionNotExposed]: 'function not exposed',
24
- [ACErrors.ImmutabilityIncorrectChild]: 'specified limit is invalid',
25
- [ACErrors.ImmutabilityParentNotFound]: 'specified limit is invalid',
26
- [ACErrors.ImmutabilityTargetImmutable]: 'specified limit is invalid',
27
- [ACErrors.InvalidLimit]: 'specified limit is invalid',
28
- [ACErrors.OwnershipError]: 'you have insufficient privileges',
29
- [ACErrors.ResourceNotFound]: 'collection not found',
18
+ [ACError.AuthenticationError]: 'you have insufficient privileges',
19
+ [ACError.AuthorizationError]: 'you have insufficient privileges',
20
+ [ACError.FunctionNotFound]: 'function not found',
21
+ [ACError.FunctionNotExposed]: 'function not exposed',
22
+ [ACError.ImmutabilityIncorrectChild]: 'specified limit is invalid',
23
+ [ACError.ImmutabilityParentNotFound]: 'specified limit is invalid',
24
+ [ACError.ImmutabilityTargetImmutable]: 'specified limit is invalid',
25
+ [ACError.InvalidLimit]: 'specified limit is invalid',
26
+ [ACError.OwnershipError]: 'you have insufficient privileges',
27
+ [ACError.ResourceNotFound]: 'collection not found',
30
28
  };
@@ -1,20 +1,18 @@
1
1
  "use strict";
2
- export var ACErrors = /* @__PURE__ */ ((ACErrors2) => {
3
- ACErrors2["AssetNotFound"] = "ASSET_NOT_FOUND";
4
- ACErrors2["AuthenticationError"] = "AUTHENTICATION_ERROR";
5
- ACErrors2["AuthorizationError"] = "AUTHORIZATION_ERROR";
6
- ACErrors2["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
7
- ACErrors2["FunctionNotExposed"] = "FUNCTION_NOT_EXPOSED";
8
- ACErrors2["ImmutabilityIncorrectChild"] = "IMMUTABILITY_INCORRECT_CHILD";
9
- ACErrors2["ImmutabilityParentNotFound"] = "IMMUTABILITY_PARENT_NOT_FOUND";
10
- ACErrors2["ImmutabilityTargetImmutable"] = "IMMUTABILITY_TARGET_IMMUTABLE";
11
- ACErrors2["InvalidLimit"] = "INVALID_LIMIT";
12
- ACErrors2["OwnershipError"] = "OWNERSHIP_ERROR";
13
- ACErrors2["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
14
- return ACErrors2;
15
- })(ACErrors || {});
2
+ export var ACError = /* @__PURE__ */ ((ACError2) => {
3
+ ACError2["AuthenticationError"] = "AUTHENTICATION_ERROR";
4
+ ACError2["AuthorizationError"] = "AUTHORIZATION_ERROR";
5
+ ACError2["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
6
+ ACError2["FunctionNotExposed"] = "FUNCTION_NOT_EXPOSED";
7
+ ACError2["ImmutabilityIncorrectChild"] = "IMMUTABILITY_INCORRECT_CHILD";
8
+ ACError2["ImmutabilityParentNotFound"] = "IMMUTABILITY_PARENT_NOT_FOUND";
9
+ ACError2["ImmutabilityTargetImmutable"] = "IMMUTABILITY_TARGET_IMMUTABLE";
10
+ ACError2["InvalidLimit"] = "INVALID_LIMIT";
11
+ ACError2["OwnershipError"] = "OWNERSHIP_ERROR";
12
+ ACError2["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
13
+ return ACError2;
14
+ })(ACError || {});
16
15
  export const ACErrorMessages = {
17
- ["ASSET_NOT_FOUND" /* AssetNotFound */]: "collection has no registered functions",
18
16
  ["AUTHENTICATION_ERROR" /* AuthenticationError */]: "you have insufficient privileges",
19
17
  ["AUTHORIZATION_ERROR" /* AuthorizationError */]: "you have insufficient privileges",
20
18
  ["FUNCTION_NOT_FOUND" /* FunctionNotFound */]: "function not found",
package/dist/context.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { Collection as MongoCollection } from 'mongodb';
2
- import type { AcceptedRole } from './accessControl.js';
2
+ import type { AcceptedRole } from './token.js';
3
3
  import type { ApiConfig } from './config.js';
4
4
  import type { CollectionDocument, CollectionFunctions } from './functions.js';
5
5
  import type { Description } from './description.js';
6
6
  import type { Either, EndpointError, EndpointErrorContent } from './monad.js';
7
7
  import type { FunctionPath } from './collection.js';
8
- import type { GenericRequest, GenericResponse } from './http.js';
8
+ import type { GenericRequest, GenericResponse, HTTPStatus } from './http.js';
9
9
  import type { PackReferences, SchemaWithId } from './schema.js';
10
10
  import type { RateLimitingParams, RateLimitingErrors } from './security.js';
11
11
  import type { Token } from './token.js';
@@ -41,7 +41,7 @@ export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
41
41
  request: GenericRequest;
42
42
  response: GenericResponse;
43
43
  log: (message: string, details?: any) => Promise<any>;
44
- error: <TEndpointErrorContent extends EndpointErrorContent>(error: TEndpointErrorContent) => EndpointError<TEndpointErrorContent>;
44
+ error: <TEndpointErrorContent extends Omit<EndpointErrorContent, 'httpStatus'>>(httpStatus: HTTPStatus, error: TEndpointErrorContent) => EndpointError<TEndpointErrorContent>;
45
45
  limitRate: (params: RateLimitingParams) => Promise<Either<RateLimitingErrors, {
46
46
  hits: number;
47
47
  points: number;
@@ -2,7 +2,7 @@ import type { Context } from './context.js';
2
2
  import type { InferProperty } from './schema.js';
3
3
  import type { InferResponse } from './http.js';
4
4
  import type { Property } from './property.js';
5
- import type { UserRole } from './accessControl.js';
5
+ import type { UserRole } from './token.js';
6
6
  export type ContractBase = {
7
7
  builtin?: boolean;
8
8
  };
@@ -1,5 +1,5 @@
1
1
  import type { FilterOperators, StrictFilter as Filter, StrictUpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
2
- import type { ACErrors } from './accessControl.js';
2
+ import type { ACError } from './accessControl.js';
3
3
  import type { Either } from './monad.js';
4
4
  import type { PackReferences } from './schema.js';
5
5
  import type { ValidationError } from './validation.js';
@@ -71,7 +71,7 @@ export type CollectionFunctions<TDocument extends CollectionDocument<OptionalId<
71
71
  count: (payload: CountPayload<TDocument>) => Promise<number>;
72
72
  get: (payload: GetPayload<TDocument>) => Promise<TDocument | null>;
73
73
  getAll: (payload?: GetAllPayload<TDocument>) => Promise<TDocument[]>;
74
- insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError | ACErrors, TDocument>>;
74
+ insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError | ACError, TDocument>>;
75
75
  remove: (payload: RemovePayload<TDocument>) => Promise<TDocument>;
76
76
  removeAll: (payload: RemoveAllPayload) => Promise<any>;
77
77
  removeFile: (payload: RemoveFilePayload) => Promise<any>;
package/dist/http.d.ts CHANGED
@@ -2,6 +2,15 @@
2
2
  import type { ServerResponse, IncomingMessage } from 'http';
3
3
  import type { MapSchemaUnion } from './schema.js';
4
4
  export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
5
+ export declare enum HTTPStatus {
6
+ BadRequest = 400,
7
+ Unauthorized = 401,
8
+ Forbidden = 403,
9
+ NotFound = 404,
10
+ UnprocessableContent = 422,
11
+ TooManyRequests = 429,
12
+ InternalServerError = 500
13
+ }
5
14
  export type RouteUri = `/${string}`;
6
15
  export type RequestMethod = (typeof REQUEST_METHODS)[number];
7
16
  export type GenericRequest = {
package/dist/http.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REQUEST_METHODS = void 0;
3
+ exports.HTTPStatus = exports.REQUEST_METHODS = void 0;
4
4
  exports.REQUEST_METHODS = [
5
5
  'GET',
6
6
  'HEAD',
@@ -12,3 +12,13 @@ exports.REQUEST_METHODS = [
12
12
  'TRACE',
13
13
  'SEARCH',
14
14
  ];
15
+ var HTTPStatus;
16
+ (function (HTTPStatus) {
17
+ HTTPStatus[HTTPStatus["BadRequest"] = 400] = "BadRequest";
18
+ HTTPStatus[HTTPStatus["Unauthorized"] = 401] = "Unauthorized";
19
+ HTTPStatus[HTTPStatus["Forbidden"] = 403] = "Forbidden";
20
+ HTTPStatus[HTTPStatus["NotFound"] = 404] = "NotFound";
21
+ HTTPStatus[HTTPStatus["UnprocessableContent"] = 422] = "UnprocessableContent";
22
+ HTTPStatus[HTTPStatus["TooManyRequests"] = 429] = "TooManyRequests";
23
+ HTTPStatus[HTTPStatus["InternalServerError"] = 500] = "InternalServerError";
24
+ })(HTTPStatus || (exports.HTTPStatus = HTTPStatus = {}));
package/dist/http.mjs CHANGED
@@ -10,3 +10,13 @@ export const REQUEST_METHODS = [
10
10
  "TRACE",
11
11
  "SEARCH"
12
12
  ];
13
+ export var HTTPStatus = /* @__PURE__ */ ((HTTPStatus2) => {
14
+ HTTPStatus2[HTTPStatus2["BadRequest"] = 400] = "BadRequest";
15
+ HTTPStatus2[HTTPStatus2["Unauthorized"] = 401] = "Unauthorized";
16
+ HTTPStatus2[HTTPStatus2["Forbidden"] = 403] = "Forbidden";
17
+ HTTPStatus2[HTTPStatus2["NotFound"] = 404] = "NotFound";
18
+ HTTPStatus2[HTTPStatus2["UnprocessableContent"] = 422] = "UnprocessableContent";
19
+ HTTPStatus2[HTTPStatus2["TooManyRequests"] = 429] = "TooManyRequests";
20
+ HTTPStatus2[HTTPStatus2["InternalServerError"] = 500] = "InternalServerError";
21
+ return HTTPStatus2;
22
+ })(HTTPStatus || {});
package/dist/monad.d.ts CHANGED
@@ -7,9 +7,9 @@ export type Right<T> = {
7
7
  readonly value: T;
8
8
  };
9
9
  export type EndpointErrorContent = {
10
- httpCode?: number;
10
+ httpStatus?: number;
11
11
  code: string;
12
- message: string;
12
+ message?: string;
13
13
  details?: Record<string, any>;
14
14
  };
15
15
  export type EndpointError<T extends EndpointErrorContent> = {
@@ -25,7 +25,7 @@ export type SecurityPolicy = {
25
25
  logging?: LoggingParams;
26
26
  };
27
27
  export type CollectionSecurityPolicy<TCollection extends {
28
- functions?: Record<string, (...args: any[]) => unknown>;
28
+ functions?: Record<string, unknown>;
29
29
  }> = {
30
30
  functions?: Partial<Record<keyof TCollection['functions'], SecurityPolicy>>;
31
31
  };
package/dist/token.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { ObjectId } from 'mongodb';
2
2
  import type { PackReferences } from './schema.js';
3
3
  import type { FunctionPath } from './collection.js';
4
- import type { AcceptedRole } from './accessControl.js';
4
+ export type UserRole = (Collections['user']['item']['roles'][number] extends infer UserDefinedRole ? UserDefinedRole extends string ? `${UserDefinedRole}${UserDefinedRole}` extends UserDefinedRole ? 'root' : UserDefinedRole : never : never) | 'root' | 'unauthenticated';
5
+ export type AcceptedRole = UserRole | UserRole[] | null | unknown;
5
6
  export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null> = {
6
7
  authenticated: true;
7
8
  sub: ObjectId;
@@ -17,4 +18,4 @@ export type TokenRecipient = {
17
18
  type: 'bearer';
18
19
  content: string;
19
20
  };
20
- export type Token<TAcceptedRole extends AcceptedRole = null> = [TAcceptedRole] extends [null | 'unauthenticated'] ? AuthenticatedToken | UnauthenticatedToken : AuthenticatedToken<TAcceptedRole>;
21
+ export type Token<TAcceptedRole extends AcceptedRole = null> = (null extends TAcceptedRole ? true : 'unauthenticated' extends TAcceptedRole ? true : false) extends true ? AuthenticatedToken | UnauthenticatedToken : AuthenticatedToken<TAcceptedRole>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",