@aeriajs/types 0.0.4 → 0.0.6

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/api.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { ObjectId } from 'mongodb';
2
- import type { Context, Description, SecurityPolicy, AccessControl, PackReferences } from '.';
2
+ import type { Context, Contract, Description, SecurityPolicy, AccessControl, PackReferences } from '.';
3
3
  export type Collection<TCollection extends Collection = any> = {
4
4
  description: Description;
5
5
  item?: any;
6
6
  security?: SecurityPolicy;
7
7
  accessControl?: AccessControl<TCollection>;
8
8
  functions?: Record<string, (payload: any, context: Context, ...args: any[]) => any>;
9
+ functionContracts?: Record<string, Contract>;
9
10
  };
10
11
  export type AssetType = keyof Collection;
11
12
  export type FunctionPath = `${string}@${string}`;
package/dist/context.d.ts CHANGED
@@ -5,7 +5,7 @@ export type CollectionModel<TDescription extends Description> = MongoCollection<
5
5
  type OmitContextParameter<TFunction> = TFunction extends (payload: infer Payload, context: Context, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
6
6
  type RestParameters<TFunction> = TFunction extends (payload: any, context: Context, ...args: infer Rest) => any ? Rest : never;
7
7
  type UnionFunctions<TFunctions, TSchema extends CollectionDocument<any>> = {
8
- [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]>;
8
+ [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;
9
9
  };
10
10
  export type IndepthCollection<TCollection> = TCollection extends {
11
11
  description: infer InferredDescription;
@@ -23,6 +23,8 @@ export type ContextOptions<TContext> = {
23
23
  parentContext?: TContext;
24
24
  collectionName?: string;
25
25
  token?: DecodedToken;
26
+ inherited?: boolean;
27
+ calledFunction?: string;
26
28
  };
27
29
  export type Context<TDescription extends Description = any, TFunctions = any> = {
28
30
  description: TDescription;
@@ -38,5 +40,7 @@ export type Context<TDescription extends Description = any, TFunctions = any> =
38
40
  response: GenericResponse;
39
41
  log: (message: string, details?: any) => Promise<any>;
40
42
  config: ApiConfig;
43
+ inherited: boolean;
44
+ calledFunction: string;
41
45
  };
42
46
  export {};
@@ -0,0 +1,17 @@
1
+ import type { Property, InferProperty, Context } from '.';
2
+ export type ContractRoles = {
3
+ roles?: Collections['user']['item']['roles'];
4
+ };
5
+ export type Contract = {
6
+ response: Property | Property[];
7
+ } | {
8
+ payload: Property;
9
+ } | {
10
+ query: Property;
11
+ } | {
12
+ response?: Property | Property[];
13
+ payload?: Property;
14
+ query?: Property;
15
+ };
16
+ export type ContractWithRoles = ContractRoles & Contract;
17
+ export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperty<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferProperty<TContract['response']> : any) extends infer Response ? Payload extends undefined ? (payload: Payload | undefined, context: ContextParameter) => Response : (payload: Payload, context: ContextParameter) => Response : never : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -1,23 +1,34 @@
1
- import type { FilterOperators, UpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
2
- import type { PackReferences, Either, ValidationError } from '.';
1
+ import type { FilterOperators, StrictUpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
2
+ import type { PackReferences, Either, ValidationError, ACErrors, Context, Description } from '.';
3
3
  export type UploadAuxProps = {
4
4
  parentId: string;
5
5
  propertyName: string;
6
6
  };
7
- export type Filters<TDocument> = FilterOperators<TDocument>;
8
- export type What<TDocument> = Omit<UpdateFilter<TDocument>, keyof TDocument> & {
7
+ export type Pagination = {
8
+ recordsCount: number;
9
+ recordsTotal: number;
10
+ offset: number;
11
+ limit: number;
12
+ };
13
+ export type StrictFilterOperators<TDocument> = FilterOperators<TDocument> extends infer InferredFilters ? {
14
+ [P in keyof InferredFilters as 0 extends (InferredFilters[P] & 1) ? never : P]: InferredFilters[P];
15
+ } : never;
16
+ export type Filters<TDocument> = Partial<{
17
+ [P in keyof TDocument]: TDocument[P] | StrictFilterOperators<TDocument[P]>;
18
+ }>;
19
+ export type What<TDocument> = StrictUpdateFilter<TDocument> & {
9
20
  [P in keyof TDocument]?: '_id' extends keyof TDocument[P] ? TDocument[P] | string : TDocument[P];
10
21
  };
11
- export type Projection<TDocument extends Record<string, any>> = keyof TDocument | '_id' extends infer DocumentProp ? TDocument extends string ? DocumentProp[] : string[] : never;
22
+ export type Projection<TDocument> = keyof TDocument | '_id' extends infer DocumentProp ? TDocument extends string ? DocumentProp[] : string[] : never;
12
23
  export type QuerySort<TDocument> = Partial<Record<keyof WithId<TDocument>, 1 | -1>>;
13
- export type CollectionDocument<TDocument> = Pick<TDocument, Extract<keyof TDocument, string>>;
24
+ export type CollectionDocument<TDocument> = TDocument;
14
25
  export type CountPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
15
26
  filters?: Filters<TDocument>;
16
27
  };
17
28
  export type GetPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
18
29
  filters: Filters<TDocument>;
19
30
  project?: Projection<TDocument>;
20
- populate?: (keyof TDocument & string)[];
31
+ populate?: (keyof TDocument | string)[];
21
32
  };
22
33
  export type GetAllPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
23
34
  filters?: Filters<TDocument>;
@@ -25,12 +36,10 @@ export type GetAllPayload<TDocument extends CollectionDocument<OptionalId<any>>>
25
36
  offset?: number;
26
37
  limit?: number;
27
38
  sort?: QuerySort<TDocument>;
28
- populate?: (keyof TDocument & string)[];
39
+ populate?: (keyof TDocument | string)[];
29
40
  };
30
- export type InsertPayload<TDocument extends CollectionDocument<any>> = {
31
- what: What<PackReferences<TDocument> & {
32
- _id?: any;
33
- }>;
41
+ export type InsertPayload<TDocument extends CollectionDocument<any>, BypassTypeRestriction = false> = {
42
+ what: BypassTypeRestriction extends true ? any : What<PackReferences<TDocument>>;
34
43
  project?: Projection<TDocument>;
35
44
  };
36
45
  export type RemovePayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
@@ -48,8 +57,20 @@ export type CollectionFunctions<TDocument extends CollectionDocument<OptionalId<
48
57
  count: (payload: CountPayload<TDocument>) => Promise<number>;
49
58
  get: (payload: GetPayload<TDocument>) => Promise<TDocument | null>;
50
59
  getAll: (payload?: GetAllPayload<TDocument>) => Promise<TDocument[]>;
51
- insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError, TDocument>>;
60
+ insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError | ACErrors, TDocument>>;
52
61
  remove: (payload: RemovePayload<TDocument>) => Promise<TDocument>;
53
62
  removeAll: (payload: RemoveAllPayload) => Promise<any>;
54
63
  removeFile: (payload: RemoveFilePayload) => Promise<any>;
55
64
  };
65
+ export type CollectionFunctionsPaginated<TDocument extends CollectionDocument<OptionalId<any>>> = Omit<CollectionFunctions<TDocument>, 'getAll'> & {
66
+ getAll: (payload?: GetAllPayload<TDocument>) => Promise<{
67
+ data: TDocument[];
68
+ pagination: Pagination;
69
+ }>;
70
+ };
71
+ export type CollectionFunctionsWithBypass<TDocument extends CollectionDocument<OptionalId<any>>> = Omit<CollectionFunctions<TDocument>, 'insert'> & {
72
+ insert: (payload: InsertPayload<TDocument, true>) => Promise<Either<ValidationError | ACErrors, TDocument>>;
73
+ };
74
+ export type CollectionFunctionsWithContext<TDocument extends CollectionDocument<OptionalId<any>>, TDescription extends Description = any, TFunctions = any> = {
75
+ [P in keyof CollectionFunctionsWithBypass<TDocument>]: (payload: Parameters<CollectionFunctionsWithBypass<TDocument>[P]>[0], context: Context<TDescription, TFunctions>) => ReturnType<CollectionFunctions<TDocument>[P]>;
76
+ };
package/dist/http.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type { ServerResponse, IncomingMessage } from 'http';
3
- import type { MapSchemaUnion } from './schema';
3
+ import type { MapSchemaUnion } from '.';
4
4
  export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
5
5
  export type RequestMethod = (typeof REQUEST_METHODS)[number];
6
6
  export type GenericRequest = {
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from './api.js';
3
3
  export * from './condition.js';
4
4
  export * from './config.js';
5
5
  export * from './context.js';
6
+ export * from './contract.js';
6
7
  export * from './description.js';
7
8
  export * from './either.js';
8
9
  export * from './functions.js';
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./api.js"), exports);
19
19
  __exportStar(require("./condition.js"), exports);
20
20
  __exportStar(require("./config.js"), exports);
21
21
  __exportStar(require("./context.js"), exports);
22
+ __exportStar(require("./contract.js"), exports);
22
23
  __exportStar(require("./description.js"), exports);
23
24
  __exportStar(require("./either.js"), exports);
24
25
  __exportStar(require("./functions.js"), exports);
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ export * from "./api.mjs";
3
3
  export * from "./condition.mjs";
4
4
  export * from "./config.mjs";
5
5
  export * from "./context.mjs";
6
+ export * from "./contract.mjs";
6
7
  export * from "./description.mjs";
7
8
  export * from "./either.mjs";
8
9
  export * from "./functions.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",