@aeriajs/types 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.
@@ -12,5 +12,5 @@ export declare enum ACError {
12
12
  ResourceNotFound = "RESOURCE_NOT_FOUND",
13
13
  InsecureOperator = "INSECURE_OPERATOR",
14
14
  MalformedInput = "MALFORMED_INPUT",
15
- UnknownError = "UNKNOWN_INPUT"
15
+ UnknownError = "UNKNOWN_ERROR"
16
16
  }
@@ -13,5 +13,5 @@ var ACError;
13
13
  ACError["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
14
14
  ACError["InsecureOperator"] = "INSECURE_OPERATOR";
15
15
  ACError["MalformedInput"] = "MALFORMED_INPUT";
16
- ACError["UnknownError"] = "UNKNOWN_INPUT";
16
+ ACError["UnknownError"] = "UNKNOWN_ERROR";
17
17
  })(ACError || (exports.ACError = ACError = {}));
@@ -10,6 +10,6 @@ export var ACError = /* @__PURE__ */ ((ACError2) => {
10
10
  ACError2["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
11
11
  ACError2["InsecureOperator"] = "INSECURE_OPERATOR";
12
12
  ACError2["MalformedInput"] = "MALFORMED_INPUT";
13
- ACError2["UnknownError"] = "UNKNOWN_INPUT";
13
+ ACError2["UnknownError"] = "UNKNOWN_ERROR";
14
14
  return ACError2;
15
15
  })(ACError || {});
@@ -10,7 +10,7 @@ export type Collection<TCollection extends Collection = any> = {
10
10
  contracts?: Record<string, Contract>;
11
11
  exposedFunctions?: Record<string, AccessCondition>;
12
12
  security?: CollectionSecurityPolicy<TCollection>;
13
- middlewares?: CollectionMiddleware | CollectionMiddleware[];
13
+ middlewares?: CollectionMiddleware<any> | CollectionMiddleware<any>[];
14
14
  };
15
15
  export type CollectionItem<TCollectionName extends keyof Collections> = Omit<Collections[TCollectionName]['item'], '_id'>;
16
16
  export type CollectionItemWithId<TCollectionName extends keyof Collections> = Collections[TCollectionName]['item'];
package/dist/config.d.ts CHANGED
@@ -6,7 +6,7 @@ export type ApiConfig = {
6
6
  baseUrl?: RouteUri;
7
7
  publicUrl?: string;
8
8
  port?: number;
9
- paginationLimit?: number;
9
+ defaultPaginationLimit?: number;
10
10
  database?: {
11
11
  mongodbUrl?: string;
12
12
  noDatabase?: boolean;
@@ -28,8 +28,9 @@ export type ApiConfig = {
28
28
  roles: string[];
29
29
  active: boolean;
30
30
  }>;
31
+ paginationLimit?: number;
31
32
  exposeFunctionsByDefault?: boolean | 'unauthenticated';
32
33
  };
33
34
  tokenUserProperties?: string[];
34
- errorHandler?: <TError extends Error>(context: RouteContext, error: TError) => unknown | Promise<unknown>;
35
+ errorHandler?: <TError>(context: RouteContext, error: TError) => unknown | Promise<unknown>;
35
36
  };
package/dist/context.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Collection as MongoCollection } from 'mongodb';
2
2
  import type { AcceptedRole } from './token.js';
3
+ import type { Collection } from './collection.js';
3
4
  import type { ApiConfig } from './config.js';
4
5
  import type { CollectionDocument, CollectionFunctions } from './functions.js';
5
6
  import type { Description } from './description.js';
@@ -22,6 +23,7 @@ export type IndepthCollection<TCollection> = TCollection extends {
22
23
  functions: UnionFunctions<CollFunctions, SchemaWithId<InferredDescription>>;
23
24
  originalFunctions: CollFunctions;
24
25
  model: InferredDescription extends Description ? CollectionModel<InferredDescription> : never;
26
+ middlewares?: Collection['middlewares'];
25
27
  } : TCollection;
26
28
  export type IndepthCollections = {
27
29
  [P in keyof Collections]: IndepthCollection<Collections[P]>;
@@ -17,7 +17,7 @@ export type Pagination = {
17
17
  };
18
18
  type FilterProperty<T> = T extends ObjectId ? T | string : T;
19
19
  type DocumentFilter<TDocument> = PackReferences<TDocument> extends infer Document ? {
20
- [P in keyof Document]: null | (Document[P] extends (infer E)[] ? FilterProperty<E>[] : FilterProperty<Document[P]>);
20
+ [P in keyof Document]: Document[P] extends (infer E)[] ? FilterProperty<E>[] : FilterProperty<Document[P]>;
21
21
  } : never;
22
22
  type RemoveAny<T> = {
23
23
  [P in keyof T as 0 extends (T[P] & 1) ? never : P]: T[P];
@@ -27,14 +27,14 @@ export type StrictFilterOperators<TDocument> = RemoveAny<FilterOperators<Documen
27
27
  export type Filters<TDocument> = StrictFilter<TDocument> & Partial<{
28
28
  [P in keyof TDocument | `${Extract<keyof TDocument, string>}.${string}`]: (P extends keyof TDocument ? TDocument[P] extends infer Field ? Field extends ObjectId ? Field | string : Field extends {
29
29
  _id: infer Id;
30
- } ? Id | string : Field : never : any) extends infer Field ? Field | StrictFilterOperators<Field> | null : never;
30
+ } ? Id | string : Field : never : any) extends infer Field ? Field | StrictFilterOperators<Field> : never;
31
31
  }>;
32
32
  export type What<TDocument> = ({
33
33
  _id: ObjectId | string;
34
34
  } & Partial<Omit<PackReferences<TDocument>, '_id'>> | {
35
35
  _id?: null;
36
36
  } & Omit<PackReferences<TDocument>, '_id'>) extends infer Document ? {
37
- [P in keyof Document]: Document[P] | null;
37
+ [P in keyof Document]: Document[P];
38
38
  } : never;
39
39
  export type Projection<TDocument> = keyof TDocument | '_id' extends infer DocumentProp ? [DocumentProp] extends [string] ? DocumentProp[] : string[] : never;
40
40
  export type QuerySort<TDocument> = Partial<Record<keyof WithId<TDocument>, 1 | -1>>;
@@ -1,4 +1,6 @@
1
1
  import type { Context } from './context.js';
2
+ import type { What } from './functions.js';
3
+ import type { Result } from './result.js';
2
4
  export type OwnershipMode = boolean | 'always' | 'on-write';
3
5
  export declare enum RateLimitingError {
4
6
  Unauthenticated = "UNAUTHENTICATED",
@@ -30,16 +32,25 @@ export type CollectionSecurityPolicy<TCollection extends {
30
32
  }> = {
31
33
  functions?: Partial<Record<keyof TCollection['functions'], SecurityPolicy>>;
32
34
  };
33
- export type CollectionHookProps<TPayload = any> = {
35
+ export type CollectionProps<TPayload = any> = {
34
36
  propName?: string;
35
37
  parentId?: string;
36
38
  childId?: string;
37
39
  payload: TPayload;
38
40
  };
39
- export type GenericMiddlewareNext<TReturn, TPayload> = (payload: TPayload, initial: TReturn, context: Context) => TReturn | Promise<TReturn>;
40
- export type MiddlewareNext = <TReturn, TReturnPayload>(payload: TReturnPayload, initial: TReturn, context: Context) => TReturn | Promise<TReturn>;
41
- export type Middleware<TReturn = any, TPayload = any, TReturnNext extends GenericMiddlewareNext<TReturn, TPayload> = GenericMiddlewareNext<TReturn, TPayload>> = (payload: TPayload, initial: TReturn, context: Context, next: TReturnNext) => TReturn | Promise<TReturn>;
42
- export type CollectionMiddleware = {
43
- beforeRead: Middleware;
44
- beforeWrite: Middleware;
41
+ export type CollectionReadPayload = {
42
+ filters: Record<string, any>;
43
+ sort?: Record<string, any>;
44
+ limit?: number;
45
+ offset?: number;
46
+ };
47
+ export type CollectionWritePayload = {
48
+ what: What<Record<string, any>>;
49
+ };
50
+ export type GenericMiddlewareNext<TPayload, TReturn> = (payload: TPayload, context: Context) => TReturn;
51
+ export type MiddlewareNext = <TPayload, TReturn>(payload: TPayload, context: Context) => TReturn;
52
+ export type Middleware<TPayload = any, TReturn = any, TReturnNext extends GenericMiddlewareNext<TPayload, TReturn> = GenericMiddlewareNext<TPayload, TReturn>> = (payload: TPayload, context: Context, next: TReturnNext) => TReturn;
53
+ export type CollectionMiddleware<TDocument> = {
54
+ beforeRead?: Middleware<CollectionReadPayload, Promise<Result.Either<any, TDocument | TDocument[]>>>;
55
+ beforeWrite?: Middleware<CollectionWritePayload, Promise<Result.Either<any, TDocument>>>;
45
56
  };
package/dist/token.d.ts CHANGED
@@ -5,7 +5,7 @@ export type AcceptedRole = UserRole | UserRole[] | null | unknown;
5
5
  export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null> = {
6
6
  authenticated: true;
7
7
  sub: ObjectId;
8
- roles: readonly (TAcceptedRole extends null ? string : TAcceptedRole)[];
8
+ roles: readonly (TAcceptedRole extends null ? UserRole : TAcceptedRole)[];
9
9
  userinfo: Omit<Collections['user']['item'], '_id' | 'roles'> extends infer UserItem ? UserItem | PackReferences<UserItem> : never;
10
10
  };
11
11
  export type UnauthenticatedToken = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
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",