@aeriajs/core 0.0.86 → 0.0.88

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/assets.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Context, Collection, Token } from '@aeriajs/types';
2
- import { ACErrors } from '@aeriajs/types';
3
- export declare const internalGetCollectionAsset: <TCollectionName extends string, TAssetName extends "item" | "description" | "security" | "functions" | "contracts" | "exposedFunctions">(collectionName: TCollectionName, assetName: TAssetName) => Promise<import("@aeriajs/types").Left<ACErrors.ResourceNotFound> | import("@aeriajs/types").Left<ACErrors.AssetNotFound> | import("@aeriajs/types").Right<any>>;
4
- export declare const getCollectionAsset: <TCollectionName extends string, TAssetName extends "item" | "description" | "security" | "functions" | "contracts" | "exposedFunctions">(collectionName: TCollectionName, assetName: TAssetName) => Promise<import("@aeriajs/types").Left<ACErrors.ResourceNotFound> | import("@aeriajs/types").Left<ACErrors.AssetNotFound> | import("@aeriajs/types").Right<NonNullable<Collection[TAssetName]>>>;
2
+ import { ACError } from '@aeriajs/types';
3
+ export declare const internalGetCollectionAsset: <TCollectionName extends string, TAssetName extends "item" | "description" | "security" | "functions" | "contracts" | "exposedFunctions">(collectionName: TCollectionName, assetName: TAssetName) => Promise<import("@aeriajs/types").Left<ACError.ResourceNotFound> | import("@aeriajs/types").Right<any>>;
4
+ export declare const getCollectionAsset: <TCollectionName extends string, TAssetName extends "item" | "description" | "security" | "functions" | "contracts" | "exposedFunctions">(collectionName: TCollectionName, assetName: TAssetName) => Promise<import("@aeriajs/types").Left<ACError.ResourceNotFound> | import("@aeriajs/types").Right<NonNullable<Collection[TAssetName]>>>;
5
5
  export declare const getFunction: <TCollectionName extends string, TFunctionName extends string>(collectionName: TCollectionName, functionName: TFunctionName, token?: Token, options?: {
6
6
  exposedOnly: boolean;
7
- }) => Promise<import("@aeriajs/types").Left<ACErrors.ResourceNotFound> | import("@aeriajs/types").Left<ACErrors.AssetNotFound> | import("@aeriajs/types").Left<ACErrors.FunctionNotFound> | import("@aeriajs/types").Left<ACErrors.FunctionNotExposed> | import("@aeriajs/types").Left<ACErrors.AuthorizationError> | import("@aeriajs/types").Right<(payload: unknown, context: Context) => Promise<any>>>;
7
+ }) => Promise<import("@aeriajs/types").Left<ACError.ResourceNotFound> | import("@aeriajs/types").Left<ACError.FunctionNotFound> | import("@aeriajs/types").Left<ACError.FunctionNotExposed> | import("@aeriajs/types").Left<ACError.AuthorizationError> | import("@aeriajs/types").Right<(payload: unknown, context: Context) => Promise<any>>>;
package/dist/assets.js CHANGED
@@ -13,10 +13,7 @@ const internalGetCollectionAsset = async (collectionName, assetName) => {
13
13
  const collection = await (0, entrypoint_1.getCollection)(collectionName);
14
14
  const asset = collection?.[assetName];
15
15
  if (!asset) {
16
- if (!collection) {
17
- return (0, common_1.left)(types_1.ACErrors.ResourceNotFound);
18
- }
19
- return (0, common_1.left)(types_1.ACErrors.AssetNotFound);
16
+ return (0, common_1.left)(types_1.ACError.ResourceNotFound);
20
17
  }
21
18
  return (0, common_1.right)(asset);
22
19
  };
@@ -45,18 +42,18 @@ const getFunction = async (collectionName, functionName, token, options = {
45
42
  }
46
43
  const functions = (0, common_1.unwrapEither)(functionsEither);
47
44
  if (!(functionName in functions)) {
48
- return (0, common_1.left)(types_1.ACErrors.FunctionNotFound);
45
+ return (0, common_1.left)(types_1.ACError.FunctionNotFound);
49
46
  }
50
47
  const collection = await (0, entrypoint_1.getCollection)(collectionName);
51
48
  const fn = functions[functionName];
52
49
  if (!collection) {
53
- return (0, common_1.left)(types_1.ACErrors.ResourceNotFound);
50
+ return (0, common_1.left)(types_1.ACError.ResourceNotFound);
54
51
  }
55
52
  if (options.exposedOnly) {
56
53
  const exposedStatus = await (0, accessControl_js_1.isFunctionExposed)(collection, functionName, token);
57
54
  switch (exposedStatus) {
58
- case accessControl_js_1.FunctionExposedStatus.FunctionNotExposed: return (0, common_1.left)(types_1.ACErrors.FunctionNotExposed);
59
- case accessControl_js_1.FunctionExposedStatus.FunctionNotGranted: return (0, common_1.left)(types_1.ACErrors.AuthorizationError);
55
+ case accessControl_js_1.FunctionExposedStatus.FunctionNotExposed: return (0, common_1.left)(types_1.ACError.FunctionNotExposed);
56
+ case accessControl_js_1.FunctionExposedStatus.FunctionNotGranted: return (0, common_1.left)(types_1.ACError.AuthorizationError);
60
57
  }
61
58
  }
62
59
  const wrapper = async (payload, context) => {
@@ -65,9 +62,10 @@ const getFunction = async (collectionName, functionName, token, options = {
65
62
  if (securityPolicy.rateLimiting) {
66
63
  const rateLimitingEither = await (0, security_1.limitRate)(securityPolicy.rateLimiting, context);
67
64
  if ((0, common_1.isLeft)(rateLimitingEither)) {
68
- return (0, common_1.left)({
69
- error: (0, common_1.unwrapEither)(rateLimitingEither),
70
- httpCode: 429,
65
+ const error = (0, common_1.unwrapEither)(rateLimitingEither);
66
+ return context.error(types_1.HTTPStatus.TooManyRequests, {
67
+ code: error,
68
+ message: 'rate limit was achieved for this resource',
71
69
  });
72
70
  }
73
71
  }
package/dist/assets.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- import { ACErrors } from "@aeriajs/types";
2
+ import { ACError, HTTPStatus } from "@aeriajs/types";
3
3
  import { left, right, isLeft, unwrapEither } from "@aeriajs/common";
4
4
  import { limitRate } from "@aeriajs/security";
5
5
  import { getCollection } from "@aeriajs/entrypoint";
@@ -11,10 +11,7 @@ export const internalGetCollectionAsset = async (collectionName, assetName) => {
11
11
  const collection = await getCollection(collectionName);
12
12
  const asset = collection?.[assetName];
13
13
  if (!asset) {
14
- if (!collection) {
15
- return left(ACErrors.ResourceNotFound);
16
- }
17
- return left(ACErrors.AssetNotFound);
14
+ return left(ACError.ResourceNotFound);
18
15
  }
19
16
  return right(asset);
20
17
  };
@@ -41,20 +38,20 @@ export const getFunction = async (collectionName, functionName, token, options =
41
38
  }
42
39
  const functions = unwrapEither(functionsEither);
43
40
  if (!(functionName in functions)) {
44
- return left(ACErrors.FunctionNotFound);
41
+ return left(ACError.FunctionNotFound);
45
42
  }
46
43
  const collection = await getCollection(collectionName);
47
44
  const fn = functions[functionName];
48
45
  if (!collection) {
49
- return left(ACErrors.ResourceNotFound);
46
+ return left(ACError.ResourceNotFound);
50
47
  }
51
48
  if (options.exposedOnly) {
52
49
  const exposedStatus = await isFunctionExposed(collection, functionName, token);
53
50
  switch (exposedStatus) {
54
51
  case FunctionExposedStatus.FunctionNotExposed:
55
- return left(ACErrors.FunctionNotExposed);
52
+ return left(ACError.FunctionNotExposed);
56
53
  case FunctionExposedStatus.FunctionNotGranted:
57
- return left(ACErrors.AuthorizationError);
54
+ return left(ACError.AuthorizationError);
58
55
  }
59
56
  }
60
57
  const wrapper = async (payload, context) => {
@@ -63,9 +60,10 @@ export const getFunction = async (collectionName, functionName, token, options =
63
60
  if (securityPolicy.rateLimiting) {
64
61
  const rateLimitingEither = await limitRate(securityPolicy.rateLimiting, context);
65
62
  if (isLeft(rateLimitingEither)) {
66
- return left({
67
- error: unwrapEither(rateLimitingEither),
68
- httpCode: 429
63
+ const error = unwrapEither(rateLimitingEither);
64
+ return context.error(HTTPStatus.TooManyRequests, {
65
+ code: error,
66
+ message: "rate limit was achieved for this resource"
69
67
  });
70
68
  }
71
69
  }
@@ -8,8 +8,7 @@ export declare const defineCollection: <TCollection extends Omit<Collection<TCol
8
8
  contracts?: TContracts;
9
9
  exposedFunctions?: TExposedFunctions;
10
10
  security?: CollectionSecurityPolicy<{
11
- description: NoInfer<TDescription>;
12
- functions: NoInfer<TFunctions>;
11
+ functions: TFunctions;
13
12
  }>;
14
13
  }) => TCollection & {
15
14
  item: SchemaWithId<TDescription>;
@@ -1,4 +1,4 @@
1
- import type { Description, Property, ACErrors, ValidationError, Context } from '@aeriajs/types';
1
+ import type { Description, Property, ACError, ValidationError, Context } from '@aeriajs/types';
2
2
  import { ObjectId } from 'mongodb';
3
3
  export type TraverseOptions = {
4
4
  autoCast?: boolean;
@@ -30,5 +30,5 @@ type PhaseContext = {
30
30
  property: Property;
31
31
  options: TraverseOptions & TraverseNormalized;
32
32
  };
33
- export declare const traverseDocument: <const TWhat extends Record<string, any>>(what: TWhat, description: Description, _options: TraverseOptions) => Promise<import("@aeriajs/types").Right<any> | import("@aeriajs/types").Left<ACErrors | ValidationError>>;
33
+ export declare const traverseDocument: <const TWhat extends Record<string, any>>(what: TWhat, description: Description, _options: TraverseOptions) => Promise<import("@aeriajs/types").Right<any> | import("@aeriajs/types").Left<ACError | ValidationError>>;
34
34
  export {};
package/dist/context.js CHANGED
@@ -76,8 +76,10 @@ const createContext = async (options = {}) => {
76
76
  created_at: new Date(),
77
77
  });
78
78
  };
79
- context.error = (endpointError) => {
80
- return (0, common_1.error)(endpointError, context);
79
+ context.error = (httpStatus, endpointError) => {
80
+ return (0, common_1.error)(Object.assign({
81
+ httpStatus,
82
+ }, endpointError), context);
81
83
  };
82
84
  context.limitRate = (params) => {
83
85
  return (0, security_1.limitRate)(params, context);
package/dist/context.mjs CHANGED
@@ -51,8 +51,10 @@ export const createContext = async (options = {}) => {
51
51
  created_at: /* @__PURE__ */ new Date()
52
52
  });
53
53
  };
54
- context.error = (endpointError) => {
55
- return error(endpointError, context);
54
+ context.error = (httpStatus, endpointError) => {
55
+ return error(Object.assign({
56
+ httpStatus
57
+ }, endpointError), context);
56
58
  };
57
59
  context.limitRate = (params) => {
58
60
  return limitRate(params, context);
@@ -2,4 +2,4 @@ import type { Context, SchemaWithId, InsertPayload } from '@aeriajs/types';
2
2
  export type InsertOptions = {
3
3
  bypassSecurity?: boolean;
4
4
  };
5
- export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext['description']>>, context: TContext, options?: InsertOptions) => Promise<import("@aeriajs/types").Left<import("@aeriajs/types").ACErrors | import("@aeriajs/types").ValidationError> | import("@aeriajs/types").Right<SchemaWithId<TContext["description"]>>>;
5
+ export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext['description']>>, context: TContext, options?: InsertOptions) => Promise<import("@aeriajs/types").Left<import("@aeriajs/types").ACError | import("@aeriajs/types").ValidationError> | import("@aeriajs/types").Right<SchemaWithId<TContext["description"]>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -41,13 +41,13 @@
41
41
  "mongodb-memory-server": "^9.2.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@aeriajs/builtins": "^0.0.86",
45
- "@aeriajs/common": "^0.0.52",
46
- "@aeriajs/entrypoint": "^0.0.52",
47
- "@aeriajs/http": "^0.0.60",
48
- "@aeriajs/security": "^0.0.86",
49
- "@aeriajs/types": "^0.0.49",
50
- "@aeriajs/validation": "^0.0.55"
44
+ "@aeriajs/builtins": "^0.0.88",
45
+ "@aeriajs/common": "^0.0.54",
46
+ "@aeriajs/entrypoint": "^0.0.54",
47
+ "@aeriajs/http": "^0.0.62",
48
+ "@aeriajs/security": "^0.0.88",
49
+ "@aeriajs/types": "^0.0.51",
50
+ "@aeriajs/validation": "^0.0.57"
51
51
  },
52
52
  "dependencies": {
53
53
  "mongodb": "^6.5.0",