@aeriajs/core 0.0.84 → 0.0.86

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
2
  import { ACErrors } from '@aeriajs/types';
3
- export declare const internalGetCollectionAsset: <TCollectionName extends string, TAssetName extends "item" | "description" | "security" | "functions" | "functionContracts" | "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" | "functionContracts" | "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]>>>;
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]>>>;
5
5
  export declare const getFunction: <TCollectionName extends string, TFunctionName extends string>(collectionName: TCollectionName, functionName: TFunctionName, token?: Token, options?: {
6
6
  exposedOnly: boolean;
7
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>>>;
@@ -1,27 +1,27 @@
1
- import type { SchemaWithId, Collection, Context, Contract, ContractToFunction, Description, CollectionSecurityPolicy, AccessCondition } from '@aeriajs/types';
1
+ import type { SchemaWithId, Collection, StrictContext, Contract, ContractToFunction, Description, CollectionSecurityPolicy, AccessCondition, RoleFromAccessCondition } from '@aeriajs/types';
2
2
  export type ExtendCollection<TLeftCollection extends Collection, TRightCollection> = Omit<TLeftCollection & TRightCollection, 'item'> & {
3
3
  item: SchemaWithId<(TLeftCollection & TRightCollection)['description']>;
4
4
  };
5
- export declare const defineCollection: <TCollection extends Omit<Collection<TCollection extends Collection ? TCollection : never>, "item" | "description" | "security" | "functions" | "exposedFunctions">, const TDescription extends Description<TDescription>, const TFunctionContracts extends { [P in keyof TFunctions]?: Contract | undefined; }, const TFunctions extends Record<string, (payload: any, context: Context) => any> & { [P_1 in keyof TFunctionContracts]: ContractToFunction<NonNullable<TFunctionContracts[P_1]>, Context<TDescription>>; }>(collection: TCollection & {
5
+ export declare const defineCollection: <TCollection extends Omit<Collection<TCollection extends Collection ? TCollection : never>, "item" | "description" | "security" | "functions" | "exposedFunctions">, const TDescription extends Description<TDescription>, const TContracts extends { [P in keyof TFunctions]?: Contract | undefined; }, const TExposedFunctions extends Partial<Record<keyof TFunctions, AccessCondition>>, const TFunctions extends Record<string, (payload: any, context: StrictContext<any>) => any> & { [P_1 in keyof TContracts | keyof TExposedFunctions]: ContractToFunction<P_1 extends keyof TContracts ? NonNullable<TContracts[P_1]> : any, StrictContext<P_1 extends keyof TExposedFunctions ? RoleFromAccessCondition<TExposedFunctions[P_1]> : never, TDescription>>; }>(collection: TCollection & {
6
6
  description: TDescription;
7
7
  functions?: TFunctions;
8
- functionContracts?: TFunctionContracts;
9
- exposedFunctions?: Partial<Record<keyof TFunctions, AccessCondition>>;
8
+ contracts?: TContracts;
9
+ exposedFunctions?: TExposedFunctions;
10
10
  security?: CollectionSecurityPolicy<{
11
11
  description: NoInfer<TDescription>;
12
- functions: TFunctions;
12
+ functions: NoInfer<TFunctions>;
13
13
  }>;
14
14
  }) => TCollection & {
15
15
  item: SchemaWithId<TDescription>;
16
16
  description: TDescription;
17
17
  functions: TFunctions;
18
- functionContracts: TFunctionContracts;
18
+ contracts: TContracts;
19
19
  };
20
20
  export declare const extendCollection: <const TLeftCollection extends Collection, const TRightCollection extends {
21
21
  description?: Partial<Description> | undefined;
22
22
  item?: Partial<any> | undefined;
23
23
  security?: Partial<CollectionSecurityPolicy<any> | undefined>;
24
- functions?: Partial<Record<string, (payload: any, context: Context, ...args: any[]) => any> | undefined>;
25
- functionContracts?: Partial<Record<string, Contract> | undefined>;
24
+ functions?: Partial<Record<string, (payload: any, context: import("@aeriajs/types").Context, ...args: any[]) => any> | undefined>;
25
+ contracts?: Partial<Record<string, Contract> | undefined>;
26
26
  exposedFunctions?: Partial<Record<string, AccessCondition> | undefined>;
27
27
  }>(left: TLeftCollection, right: TRightCollection) => ExtendCollection<TLeftCollection, TRightCollection>;
package/dist/context.js CHANGED
@@ -76,8 +76,8 @@ const createContext = async (options = {}) => {
76
76
  created_at: new Date(),
77
77
  });
78
78
  };
79
- context.error = (error) => {
80
- return (0, common_1.endpointError)(error, context);
79
+ context.error = (endpointError) => {
80
+ return (0, common_1.error)(endpointError, context);
81
81
  };
82
82
  context.limitRate = (params) => {
83
83
  return (0, security_1.limitRate)(params, context);
package/dist/context.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- import { unsafe, endpointError } from "@aeriajs/common";
2
+ import { unsafe, error } from "@aeriajs/common";
3
3
  import { getCollections } from "@aeriajs/entrypoint";
4
4
  import { limitRate } from "@aeriajs/security";
5
5
  import { getDatabaseCollection } from "./database.mjs";
@@ -51,8 +51,8 @@ export const createContext = async (options = {}) => {
51
51
  created_at: /* @__PURE__ */ new Date()
52
52
  });
53
53
  };
54
- context.error = (error) => {
55
- return endpointError(error, context);
54
+ context.error = (endpointError) => {
55
+ return error(endpointError, context);
56
56
  };
57
57
  context.limitRate = (params) => {
58
58
  return limitRate(params, context);
package/dist/endpoints.js CHANGED
@@ -37,7 +37,7 @@ const getEndpoints = async () => {
37
37
  const collection = typeof candidate === 'function'
38
38
  ? candidate()
39
39
  : candidate;
40
- const { description, functions: collectionFunctions, functionContracts, exposedFunctions = {}, } = collection;
40
+ const { description, functions: collectionFunctions, contracts, exposedFunctions = {}, } = collection;
41
41
  if (collectionFunctions) {
42
42
  for (const fnName in collectionFunctions) {
43
43
  const exposedStatus = await (0, accessControl_js_1.isFunctionExposed)(collection, fnName);
@@ -51,22 +51,22 @@ const getEndpoints = async () => {
51
51
  : exposed
52
52
  ? await (0, entrypoint_1.getAvailableRoles)()
53
53
  : [];
54
- const contracts = {
54
+ const endpointContracts = {
55
55
  POST: null,
56
56
  };
57
57
  if (roles.length) {
58
- contracts.POST ??= {};
59
- contracts.POST.roles = roles;
58
+ endpointContracts.POST ??= {};
59
+ endpointContracts.POST.roles = roles;
60
60
  }
61
- if (functionContracts && fnName in functionContracts) {
62
- contracts.POST ??= {};
63
- Object.assign(contracts.POST, functionContracts[fnName]);
61
+ if (contracts && fnName in contracts) {
62
+ endpointContracts.POST ??= {};
63
+ Object.assign(endpointContracts.POST, contracts[fnName]);
64
64
  }
65
65
  if (fnName in builtinFunctions) {
66
- contracts.POST ??= {};
67
- contracts.POST.builtin = true;
66
+ endpointContracts.POST ??= {};
67
+ endpointContracts.POST.builtin = true;
68
68
  }
69
- functions[endpoint] = contracts;
69
+ functions[endpoint] = endpointContracts;
70
70
  }
71
71
  }
72
72
  }
@@ -13,7 +13,7 @@ export const getEndpoints = async () => {
13
13
  const {
14
14
  description,
15
15
  functions: collectionFunctions,
16
- functionContracts,
16
+ contracts,
17
17
  exposedFunctions = {}
18
18
  } = collection;
19
19
  if (collectionFunctions) {
@@ -25,22 +25,22 @@ export const getEndpoints = async () => {
25
25
  const endpoint = `/${description.$id}/${fnName}`;
26
26
  const exposed = exposedFunctions[fnName];
27
27
  const roles = Array.isArray(exposed) ? exposed : exposed ? await getAvailableRoles() : [];
28
- const contracts = {
28
+ const endpointContracts = {
29
29
  POST: null
30
30
  };
31
31
  if (roles.length) {
32
- contracts.POST ??= {};
33
- contracts.POST.roles = roles;
32
+ endpointContracts.POST ??= {};
33
+ endpointContracts.POST.roles = roles;
34
34
  }
35
- if (functionContracts && fnName in functionContracts) {
36
- contracts.POST ??= {};
37
- Object.assign(contracts.POST, functionContracts[fnName]);
35
+ if (contracts && fnName in contracts) {
36
+ endpointContracts.POST ??= {};
37
+ Object.assign(endpointContracts.POST, contracts[fnName]);
38
38
  }
39
39
  if (fnName in builtinFunctions) {
40
- contracts.POST ??= {};
41
- contracts.POST.builtin = true;
40
+ endpointContracts.POST ??= {};
41
+ endpointContracts.POST.builtin = true;
42
42
  }
43
- functions[endpoint] = contracts;
43
+ functions[endpoint] = endpointContracts;
44
44
  }
45
45
  }
46
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.84",
3
+ "version": "0.0.86",
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.84",
45
- "@aeriajs/common": "^0.0.50",
46
- "@aeriajs/entrypoint": "^0.0.50",
47
- "@aeriajs/http": "^0.0.58",
48
- "@aeriajs/security": "^0.0.84",
49
- "@aeriajs/types": "^0.0.47",
50
- "@aeriajs/validation": "^0.0.53"
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"
51
51
  },
52
52
  "dependencies": {
53
53
  "mongodb": "^6.5.0",