@aeriajs/types 0.0.51 → 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.
@@ -6,11 +6,10 @@ export declare enum ACError {
6
6
  AuthorizationError = "AUTHORIZATION_ERROR",
7
7
  FunctionNotFound = "FUNCTION_NOT_FOUND",
8
8
  FunctionNotExposed = "FUNCTION_NOT_EXPOSED",
9
- ImmutabilityIncorrectChild = "IMMUTABILITY_INCORRECT_CHILD",
10
- ImmutabilityParentNotFound = "IMMUTABILITY_PARENT_NOT_FOUND",
11
- ImmutabilityTargetImmutable = "IMMUTABILITY_TARGET_IMMUTABLE",
9
+ TargetImmutable = "TARGET_IMMUTABLE",
12
10
  InvalidLimit = "INVALID_LIMIT",
13
11
  OwnershipError = "OWNERSHIP_ERROR",
14
- ResourceNotFound = "RESOURCE_NOT_FOUND"
12
+ ResourceNotFound = "RESOURCE_NOT_FOUND",
13
+ InsecureOperator = "INSECURE_OPERATOR",
14
+ MalformedInput = "MALFORMED_INPUT"
15
15
  }
16
- export declare const ACErrorMessages: Record<ACError, string>;
@@ -1,28 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ACErrorMessages = exports.ACError = void 0;
3
+ exports.ACError = void 0;
4
4
  var ACError;
5
5
  (function (ACError) {
6
6
  ACError["AuthenticationError"] = "AUTHENTICATION_ERROR";
7
7
  ACError["AuthorizationError"] = "AUTHORIZATION_ERROR";
8
8
  ACError["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
9
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";
10
+ ACError["TargetImmutable"] = "TARGET_IMMUTABLE";
13
11
  ACError["InvalidLimit"] = "INVALID_LIMIT";
14
12
  ACError["OwnershipError"] = "OWNERSHIP_ERROR";
15
13
  ACError["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
14
+ ACError["InsecureOperator"] = "INSECURE_OPERATOR";
15
+ ACError["MalformedInput"] = "MALFORMED_INPUT";
16
16
  })(ACError || (exports.ACError = ACError = {}));
17
- exports.ACErrorMessages = {
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',
28
- };
@@ -4,23 +4,11 @@ export var ACError = /* @__PURE__ */ ((ACError2) => {
4
4
  ACError2["AuthorizationError"] = "AUTHORIZATION_ERROR";
5
5
  ACError2["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
6
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";
7
+ ACError2["TargetImmutable"] = "TARGET_IMMUTABLE";
10
8
  ACError2["InvalidLimit"] = "INVALID_LIMIT";
11
9
  ACError2["OwnershipError"] = "OWNERSHIP_ERROR";
12
10
  ACError2["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
11
+ ACError2["InsecureOperator"] = "INSECURE_OPERATOR";
12
+ ACError2["MalformedInput"] = "MALFORMED_INPUT";
13
13
  return ACError2;
14
14
  })(ACError || {});
15
- export const ACErrorMessages = {
16
- ["AUTHENTICATION_ERROR" /* AuthenticationError */]: "you have insufficient privileges",
17
- ["AUTHORIZATION_ERROR" /* AuthorizationError */]: "you have insufficient privileges",
18
- ["FUNCTION_NOT_FOUND" /* FunctionNotFound */]: "function not found",
19
- ["FUNCTION_NOT_EXPOSED" /* FunctionNotExposed */]: "function not exposed",
20
- ["IMMUTABILITY_INCORRECT_CHILD" /* ImmutabilityIncorrectChild */]: "specified limit is invalid",
21
- ["IMMUTABILITY_PARENT_NOT_FOUND" /* ImmutabilityParentNotFound */]: "specified limit is invalid",
22
- ["IMMUTABILITY_TARGET_IMMUTABLE" /* ImmutabilityTargetImmutable */]: "specified limit is invalid",
23
- ["INVALID_LIMIT" /* InvalidLimit */]: "specified limit is invalid",
24
- ["OWNERSHIP_ERROR" /* OwnershipError */]: "you have insufficient privileges",
25
- ["RESOURCE_NOT_FOUND" /* ResourceNotFound */]: "collection not found"
26
- };
@@ -7,11 +7,10 @@ export type Collection<TCollection extends Collection = any> = {
7
7
  description: Description;
8
8
  item?: any;
9
9
  security?: CollectionSecurityPolicy<TCollection>;
10
- functions?: Record<string, (payload: any, context: Context, ...args: any[]) => any>;
10
+ functions?: Record<string, (payload: any, context: Context<any>, ...args: any[]) => any>;
11
11
  contracts?: Record<string, Contract>;
12
12
  exposedFunctions?: Record<string, AccessCondition>;
13
13
  };
14
14
  export type CollectionItem<TCollectionName extends keyof Collections> = Omit<Collections[TCollectionName]['item'], '_id'>;
15
15
  export type CollectionItemWithId<TCollectionName extends keyof Collections> = Collections[TCollectionName]['item'];
16
16
  export type AssetType = keyof Collection;
17
- export type FunctionPath = `/${string}/${string}`;
package/dist/context.d.ts CHANGED
@@ -3,15 +3,14 @@ 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
- import type { Either, EndpointError, EndpointErrorContent } from './monad.js';
7
- import type { FunctionPath } from './collection.js';
6
+ import type { EndpointError, EndpointErrorContent } from './error.js';
8
7
  import type { GenericRequest, GenericResponse, HTTPStatus } from './http.js';
9
8
  import type { PackReferences, SchemaWithId } from './schema.js';
10
- import type { RateLimitingParams, RateLimitingErrors } from './security.js';
9
+ import type { RateLimitingParams, RateLimitingError } from './security.js';
11
10
  import type { Token } from './token.js';
12
11
  export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
13
12
  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;
14
- type RestParameters<TFunction> = TFunction extends (payload: any, context: Context, ...args: infer Rest) => any ? Rest : never;
13
+ type RestParameters<TFunction> = TFunction extends (payload: any, context: Context<any>, ...args: infer Rest) => any ? Rest : never;
15
14
  type UnionFunctions<TFunctions, TSchema extends CollectionDocument<any>> = {
16
15
  [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;
17
16
  };
@@ -36,18 +35,19 @@ export type ContextOptions = {
36
35
  };
37
36
  export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
38
37
  collections: IndepthCollections;
39
- functionPath: FunctionPath;
40
38
  token: Token<TAcceptedRole>;
41
39
  request: GenericRequest;
42
40
  response: GenericResponse;
43
41
  log: (message: string, details?: any) => Promise<any>;
44
- error: <TEndpointErrorContent extends Omit<EndpointErrorContent, 'httpStatus'>>(httpStatus: HTTPStatus, error: TEndpointErrorContent) => EndpointError<TEndpointErrorContent>;
45
- limitRate: (params: RateLimitingParams) => Promise<Either<RateLimitingErrors, {
42
+ error: <const THTTPStatus extends HTTPStatus, const TEndpointErrorContent extends EndpointErrorContent>(httpStatus: THTTPStatus, error: TEndpointErrorContent) => EndpointError<TEndpointErrorContent & {
43
+ httpStatus: THTTPStatus;
44
+ }>;
45
+ limitRate: (params: RateLimitingParams) => Promise<EndpointError<EndpointErrorContent<RateLimitingError, HTTPStatus.TooManyRequests>> | {
46
46
  hits: number;
47
47
  points: number;
48
48
  last_reach: Date;
49
49
  last_maximum_reach: Date;
50
- }>>;
50
+ }>;
51
51
  config: ApiConfig;
52
52
  inherited: boolean;
53
53
  calledFunction: string;
@@ -60,6 +60,6 @@ export type CollectionContext<TDescription extends Description = any, TFunctions
60
60
  functions: TFunctions;
61
61
  }> : IndepthCollection<any>;
62
62
  };
63
- export type Context<TDescription extends Description = any, TFunctions = any> = RouteContext & CollectionContext<TDescription, TFunctions>;
63
+ export type Context<TDescription extends Description = Description, TFunctions = any> = RouteContext & CollectionContext<TDescription, TFunctions>;
64
64
  export type StrictContext<TAcceptedRole extends AcceptedRole = null, TDescription extends Description = any, TFunctions = any> = RouteContext<TAcceptedRole> & CollectionContext<TDescription, TFunctions>;
65
65
  export {};
@@ -1,3 +1,4 @@
1
+ import type { WithId } from 'mongodb';
1
2
  import type { IconStyle, PhosphorIcon } from '@phosphor-icons/core';
2
3
  import type { Condition } from './condition.js';
3
4
  import type { JsonSchema, PropertiesWithId } from './property.js';
@@ -87,7 +88,7 @@ export type Description<TDescription extends Description = any> = JsonSchema<TDe
87
88
  expireAfterSeconds: number;
88
89
  };
89
90
  timestamps?: false;
90
- immutable?: boolean | readonly string[];
91
+ immutable?: boolean | readonly (keyof TDescription['properties'])[] | ((doc: WithId<any>) => boolean | Promise<boolean>);
91
92
  route?: readonly string[];
92
93
  presets?: readonly CollectionPresets[];
93
94
  table?: readonly PropertiesWithId<TDescription>[];
@@ -6,16 +6,6 @@ export type Right<T> = {
6
6
  readonly _tag: 'Right';
7
7
  readonly value: T;
8
8
  };
9
- export type EndpointErrorContent = {
10
- httpStatus?: number;
11
- code: string;
12
- message?: string;
13
- details?: Record<string, any>;
14
- };
15
- export type EndpointError<T extends EndpointErrorContent> = {
16
- readonly _tag: 'Error';
17
- readonly error: T;
18
- };
19
9
  export type ExtractLeft<T> = T extends Left<infer L> ? L : never;
20
10
  export type ExtractRight<T> = T extends Right<infer R> ? R : never;
21
11
  export type Either<L, R> = Left<L> | Right<R>;
@@ -0,0 +1,21 @@
1
+ import type { HTTPStatus } from './http.js';
2
+ export declare const ERROR_SYMBOL_DESCRIPTION = "#__ERROR_SYMBOL__";
3
+ export declare const ERROR_SYMBOL: unique symbol;
4
+ export type EndpointErrorContent<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus = HTTPStatus, TMessage extends string = string> = {
5
+ code: TCode;
6
+ details?: TDetails;
7
+ httpStatus?: THTTPStatus;
8
+ message?: TMessage;
9
+ };
10
+ export type StrictEndpointErrorContent<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus | undefined = HTTPStatus, TMessage extends string | undefined = string> = {
11
+ code: TCode;
12
+ details?: TDetails;
13
+ httpStatus: THTTPStatus;
14
+ message?: TMessage;
15
+ };
16
+ export type EndpointError<TEndpointErrorContent extends EndpointErrorContent = EndpointErrorContent> = {
17
+ readonly _tag: 'Error';
18
+ readonly value: TEndpointErrorContent;
19
+ };
20
+ export type ExtractError<T> = T extends EndpointError ? T : never;
21
+ export type ExtractSuccessful<T> = T extends EndpointError ? never : T;
package/dist/error.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERROR_SYMBOL = exports.ERROR_SYMBOL_DESCRIPTION = void 0;
4
+ exports.ERROR_SYMBOL_DESCRIPTION = '#__ERROR_SYMBOL__';
5
+ exports.ERROR_SYMBOL = Symbol(exports.ERROR_SYMBOL_DESCRIPTION);
package/dist/error.mjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ export const ERROR_SYMBOL_DESCRIPTION = "#__ERROR_SYMBOL__";
3
+ export const ERROR_SYMBOL = Symbol(ERROR_SYMBOL_DESCRIPTION);
@@ -1,8 +1,9 @@
1
1
  import type { FilterOperators, StrictFilter as Filter, StrictUpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
2
- import type { ACError } from './accessControl.js';
3
- import type { Either } from './monad.js';
2
+ import type { EndpointError, StrictEndpointErrorContent } from './error.js';
4
3
  import type { PackReferences } from './schema.js';
5
- import type { ValidationError } from './validation.js';
4
+ import type { ACError } from './accessControl.js';
5
+ import type { ValidationErrorCode } from './validation.js';
6
+ import type { HTTPStatus, WithACErrors } from './http.js';
6
7
  export type UploadAuxProps = {
7
8
  parentId: string;
8
9
  propertyName: string;
@@ -67,19 +68,27 @@ export type RemoveFilePayload = UploadAuxProps & {
67
68
  _id: any;
68
69
  };
69
70
  };
71
+ export type InsertReturnType<TDocument> = TDocument | EndpointError<StrictEndpointErrorContent<ACError.InsecureOperator | ACError.OwnershipError | ACError.ResourceNotFound | ACError.TargetImmutable | ValidationErrorCode, unknown, HTTPStatus.NotFound | HTTPStatus.UnprocessableContent>>;
72
+ export type GetReturnType<TDocument> = TDocument | EndpointError<StrictEndpointErrorContent<ACError.ResourceNotFound, unknown, HTTPStatus.NotFound>>;
70
73
  export type CollectionFunctions<TDocument extends CollectionDocument<OptionalId<any>>> = {
71
74
  count: (payload: CountPayload<TDocument>) => Promise<number>;
72
- get: (payload: GetPayload<TDocument>) => Promise<TDocument | null>;
75
+ get: (payload: GetPayload<TDocument>) => Promise<GetReturnType<TDocument>>;
73
76
  getAll: (payload?: GetAllPayload<TDocument>) => Promise<TDocument[]>;
74
- insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError | ACError, TDocument>>;
77
+ insert: (payload: InsertPayload<TDocument>) => Promise<InsertReturnType<TDocument>>;
75
78
  remove: (payload: RemovePayload<TDocument>) => Promise<TDocument>;
76
79
  removeAll: (payload: RemoveAllPayload) => Promise<any>;
77
80
  removeFile: (payload: RemoveFilePayload) => Promise<any>;
78
81
  };
79
- export type CollectionFunctionsPaginated<TDocument extends CollectionDocument<OptionalId<any>>> = Omit<CollectionFunctions<TDocument>, 'getAll'> & {
80
- 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<{
81
86
  data: TDocument[];
82
87
  pagination: Pagination;
83
- }>;
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>;
84
93
  };
85
94
  export {};
package/dist/http.d.ts CHANGED
@@ -1,8 +1,12 @@
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 {
9
+ Ok = 200,
6
10
  BadRequest = 400,
7
11
  Unauthorized = 401,
8
12
  Forbidden = 403,
@@ -24,7 +28,10 @@ export type GenericRequest = {
24
28
  nodeRequest: IncomingMessage;
25
29
  };
26
30
  export type GenericResponse = ServerResponse;
27
- 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;
28
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>>;
29
36
  type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
30
37
  export type InferResponse<TResponse> = MapSchemaUnion<UnwrapResponse<TResponse>> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never;
package/dist/http.js CHANGED
@@ -14,6 +14,7 @@ exports.REQUEST_METHODS = [
14
14
  ];
15
15
  var HTTPStatus;
16
16
  (function (HTTPStatus) {
17
+ HTTPStatus[HTTPStatus["Ok"] = 200] = "Ok";
17
18
  HTTPStatus[HTTPStatus["BadRequest"] = 400] = "BadRequest";
18
19
  HTTPStatus[HTTPStatus["Unauthorized"] = 401] = "Unauthorized";
19
20
  HTTPStatus[HTTPStatus["Forbidden"] = 403] = "Forbidden";
package/dist/http.mjs CHANGED
@@ -11,6 +11,7 @@ export const REQUEST_METHODS = [
11
11
  "SEARCH"
12
12
  ];
13
13
  export var HTTPStatus = /* @__PURE__ */ ((HTTPStatus2) => {
14
+ HTTPStatus2[HTTPStatus2["Ok"] = 200] = "Ok";
14
15
  HTTPStatus2[HTTPStatus2["BadRequest"] = 400] = "BadRequest";
15
16
  HTTPStatus2[HTTPStatus2["Unauthorized"] = 401] = "Unauthorized";
16
17
  HTTPStatus2[HTTPStatus2["Forbidden"] = 403] = "Forbidden";
package/dist/index.d.ts CHANGED
@@ -5,7 +5,8 @@ export * from './config.js';
5
5
  export * from './context.js';
6
6
  export * from './contract.js';
7
7
  export * from './description.js';
8
- export * from './monad.js';
8
+ export * from './either.js';
9
+ export * from './error.js';
9
10
  export * from './functions.js';
10
11
  export * from './http.js';
11
12
  export * from './property.js';
package/dist/index.js CHANGED
@@ -21,7 +21,8 @@ __exportStar(require("./config.js"), exports);
21
21
  __exportStar(require("./context.js"), exports);
22
22
  __exportStar(require("./contract.js"), exports);
23
23
  __exportStar(require("./description.js"), exports);
24
- __exportStar(require("./monad.js"), exports);
24
+ __exportStar(require("./either.js"), exports);
25
+ __exportStar(require("./error.js"), exports);
25
26
  __exportStar(require("./functions.js"), exports);
26
27
  __exportStar(require("./http.js"), exports);
27
28
  __exportStar(require("./property.js"), exports);
package/dist/index.mjs CHANGED
@@ -6,7 +6,8 @@ export * from "./config.mjs";
6
6
  export * from "./context.mjs";
7
7
  export * from "./contract.mjs";
8
8
  export * from "./description.mjs";
9
- export * from "./monad.mjs";
9
+ export * from "./either.mjs";
10
+ export * from "./error.mjs";
10
11
  export * from "./functions.mjs";
11
12
  export * from "./http.mjs";
12
13
  export * from "./property.mjs";
package/dist/schema.d.ts CHANGED
@@ -41,7 +41,7 @@ export type InferProperty<T> = T extends TestType<{
41
41
  const: infer K;
42
42
  }> ? K : never;
43
43
  export type InferSchema<TSchema> = MergeReferences<TSchema> extends infer MappedTypes ? TSchema extends {
44
- required: readonly [];
44
+ Required: readonly [];
45
45
  } ? Partial<MappedTypes> : TSchema extends {
46
46
  required: infer RequiredPropNames;
47
47
  } ? RequiredPropNames extends readonly (keyof MappedTypes)[] ? Pick<MappedTypes, RequiredPropNames[number]> extends infer RequiredProps ? RequiredProps & Partial<Exclude<MappedTypes, keyof RequiredProps>> : never : MappedTypes : MappedTypes : never;
@@ -1,5 +1,5 @@
1
1
  export type OwnershipMode = boolean | 'always' | 'on-write';
2
- export declare enum RateLimitingErrors {
2
+ export declare enum RateLimitingError {
3
3
  Unauthenticated = "UNAUTHENTICATED",
4
4
  LimitReached = "LIMIT_REACHED"
5
5
  }
package/dist/security.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RateLimitingErrors = void 0;
4
- var RateLimitingErrors;
5
- (function (RateLimitingErrors) {
6
- RateLimitingErrors["Unauthenticated"] = "UNAUTHENTICATED";
7
- RateLimitingErrors["LimitReached"] = "LIMIT_REACHED";
8
- })(RateLimitingErrors || (exports.RateLimitingErrors = RateLimitingErrors = {}));
3
+ exports.RateLimitingError = void 0;
4
+ var RateLimitingError;
5
+ (function (RateLimitingError) {
6
+ RateLimitingError["Unauthenticated"] = "UNAUTHENTICATED";
7
+ RateLimitingError["LimitReached"] = "LIMIT_REACHED";
8
+ })(RateLimitingError || (exports.RateLimitingError = RateLimitingError = {}));
package/dist/security.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- export var RateLimitingErrors = /* @__PURE__ */ ((RateLimitingErrors2) => {
3
- RateLimitingErrors2["Unauthenticated"] = "UNAUTHENTICATED";
4
- RateLimitingErrors2["LimitReached"] = "LIMIT_REACHED";
5
- return RateLimitingErrors2;
6
- })(RateLimitingErrors || {});
2
+ export var RateLimitingError = /* @__PURE__ */ ((RateLimitingError2) => {
3
+ RateLimitingError2["Unauthenticated"] = "UNAUTHENTICATED";
4
+ RateLimitingError2["LimitReached"] = "LIMIT_REACHED";
5
+ return RateLimitingError2;
6
+ })(RateLimitingError || {});
package/dist/token.d.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  import type { ObjectId } from 'mongodb';
2
2
  import type { PackReferences } from './schema.js';
3
- import type { FunctionPath } from './collection.js';
4
3
  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
4
  export type AcceptedRole = UserRole | UserRole[] | null | unknown;
6
5
  export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null> = {
7
6
  authenticated: true;
8
7
  sub: ObjectId;
9
8
  roles: readonly (TAcceptedRole extends null ? string : TAcceptedRole)[];
10
- allowed_functions?: readonly FunctionPath[];
11
9
  userinfo: Omit<Collections['user']['item'], '_id' | 'roles'> extends infer UserItem ? UserItem | PackReferences<UserItem> : never;
12
10
  };
13
11
  export type UnauthenticatedToken = {
@@ -1,29 +1,35 @@
1
- export declare enum ValidationErrorCodes {
1
+ export declare enum ValidationErrorCode {
2
2
  InvalidProperties = "INVALID_PROPERTIES",
3
3
  MissingProperties = "MISSING_PROPERTIES",
4
4
  EmptyTarget = "EMPTY_TARGET"
5
5
  }
6
- export type PropertyValidationErrorType = 'missing' | 'extraneous' | 'unmatching' | 'extraneous_element' | 'numeric_constraint';
6
+ export declare enum PropertyValidationErrorCode {
7
+ Missing = "MISSING_PROPERTY",
8
+ Extraneous = "EXTRANEOUS_PROPERTY",
9
+ Unmatching = "UNMATCHING_PROPERTIES",
10
+ ExtraneousElement = "EXTRANEOUS_ELEMENT",
11
+ NumericConstraint = "NUMERIC_CONSTRAINT"
12
+ }
7
13
  export type PropertyValidationError = {
8
- type: PropertyValidationErrorType;
14
+ type: PropertyValidationErrorCode;
9
15
  index?: number;
10
16
  details: {
11
17
  expected: any;
12
- got: string;
18
+ got: any;
13
19
  };
14
20
  };
15
21
  export type ValidationErrorInvalidProperties = {
16
- code: ValidationErrorCodes.InvalidProperties;
22
+ code: ValidationErrorCode.InvalidProperties;
17
23
  errors: Record<string, PropertyValidationError | ValidationError>;
18
24
  };
19
25
  export type ValidationErrorMissingProperties = {
20
- code: ValidationErrorCodes.MissingProperties;
26
+ code: ValidationErrorCode.MissingProperties;
21
27
  errors: Record<string, {
22
28
  type: 'missing';
23
29
  }>;
24
30
  };
25
31
  export type ValidationErrorEmptyTarget = {
26
- code: ValidationErrorCodes.EmptyTarget;
32
+ code: ValidationErrorCode.EmptyTarget;
27
33
  errors: {};
28
34
  };
29
35
  export type ValidationError = ValidationErrorInvalidProperties | ValidationErrorMissingProperties | ValidationErrorEmptyTarget;
@@ -1,9 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationErrorCodes = void 0;
4
- var ValidationErrorCodes;
5
- (function (ValidationErrorCodes) {
6
- ValidationErrorCodes["InvalidProperties"] = "INVALID_PROPERTIES";
7
- ValidationErrorCodes["MissingProperties"] = "MISSING_PROPERTIES";
8
- ValidationErrorCodes["EmptyTarget"] = "EMPTY_TARGET";
9
- })(ValidationErrorCodes || (exports.ValidationErrorCodes = ValidationErrorCodes = {}));
3
+ exports.PropertyValidationErrorCode = exports.ValidationErrorCode = void 0;
4
+ var ValidationErrorCode;
5
+ (function (ValidationErrorCode) {
6
+ ValidationErrorCode["InvalidProperties"] = "INVALID_PROPERTIES";
7
+ ValidationErrorCode["MissingProperties"] = "MISSING_PROPERTIES";
8
+ ValidationErrorCode["EmptyTarget"] = "EMPTY_TARGET";
9
+ })(ValidationErrorCode || (exports.ValidationErrorCode = ValidationErrorCode = {}));
10
+ var PropertyValidationErrorCode;
11
+ (function (PropertyValidationErrorCode) {
12
+ PropertyValidationErrorCode["Missing"] = "MISSING_PROPERTY";
13
+ PropertyValidationErrorCode["Extraneous"] = "EXTRANEOUS_PROPERTY";
14
+ PropertyValidationErrorCode["Unmatching"] = "UNMATCHING_PROPERTIES";
15
+ PropertyValidationErrorCode["ExtraneousElement"] = "EXTRANEOUS_ELEMENT";
16
+ PropertyValidationErrorCode["NumericConstraint"] = "NUMERIC_CONSTRAINT";
17
+ })(PropertyValidationErrorCode || (exports.PropertyValidationErrorCode = PropertyValidationErrorCode = {}));
@@ -1,7 +1,15 @@
1
1
  "use strict";
2
- export var ValidationErrorCodes = /* @__PURE__ */ ((ValidationErrorCodes2) => {
3
- ValidationErrorCodes2["InvalidProperties"] = "INVALID_PROPERTIES";
4
- ValidationErrorCodes2["MissingProperties"] = "MISSING_PROPERTIES";
5
- ValidationErrorCodes2["EmptyTarget"] = "EMPTY_TARGET";
6
- return ValidationErrorCodes2;
7
- })(ValidationErrorCodes || {});
2
+ export var ValidationErrorCode = /* @__PURE__ */ ((ValidationErrorCode2) => {
3
+ ValidationErrorCode2["InvalidProperties"] = "INVALID_PROPERTIES";
4
+ ValidationErrorCode2["MissingProperties"] = "MISSING_PROPERTIES";
5
+ ValidationErrorCode2["EmptyTarget"] = "EMPTY_TARGET";
6
+ return ValidationErrorCode2;
7
+ })(ValidationErrorCode || {});
8
+ export var PropertyValidationErrorCode = /* @__PURE__ */ ((PropertyValidationErrorCode2) => {
9
+ PropertyValidationErrorCode2["Missing"] = "MISSING_PROPERTY";
10
+ PropertyValidationErrorCode2["Extraneous"] = "EXTRANEOUS_PROPERTY";
11
+ PropertyValidationErrorCode2["Unmatching"] = "UNMATCHING_PROPERTIES";
12
+ PropertyValidationErrorCode2["ExtraneousElement"] = "EXTRANEOUS_ELEMENT";
13
+ PropertyValidationErrorCode2["NumericConstraint"] = "NUMERIC_CONSTRAINT";
14
+ return PropertyValidationErrorCode2;
15
+ })(PropertyValidationErrorCode || {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.51",
3
+ "version": "0.0.53",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
File without changes
File without changes