@aeriajs/types 0.0.5 → 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.
@@ -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,4 +1,4 @@
1
- import type { FilterOperators, UpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
1
+ import type { FilterOperators, StrictUpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
2
2
  import type { PackReferences, Either, ValidationError, ACErrors, Context, Description } from '.';
3
3
  export type UploadAuxProps = {
4
4
  parentId: string;
@@ -10,8 +10,13 @@ export type Pagination = {
10
10
  offset: number;
11
11
  limit: number;
12
12
  };
13
- export type Filters<TDocument> = FilterOperators<TDocument>;
14
- export type What<TDocument> = Omit<UpdateFilter<TDocument>, keyof TDocument> & {
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> & {
15
20
  [P in keyof TDocument]?: '_id' extends keyof TDocument[P] ? TDocument[P] | string : TDocument[P];
16
21
  };
17
22
  export type Projection<TDocument> = keyof TDocument | '_id' extends infer DocumentProp ? TDocument extends string ? DocumentProp[] : string[] : never;
@@ -23,7 +28,7 @@ export type CountPayload<TDocument extends CollectionDocument<OptionalId<any>>>
23
28
  export type GetPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
24
29
  filters: Filters<TDocument>;
25
30
  project?: Projection<TDocument>;
26
- populate?: (keyof TDocument & string)[];
31
+ populate?: (keyof TDocument | string)[];
27
32
  };
28
33
  export type GetAllPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
29
34
  filters?: Filters<TDocument>;
@@ -31,12 +36,10 @@ export type GetAllPayload<TDocument extends CollectionDocument<OptionalId<any>>>
31
36
  offset?: number;
32
37
  limit?: number;
33
38
  sort?: QuerySort<TDocument>;
34
- populate?: (keyof TDocument & string)[];
39
+ populate?: (keyof TDocument | string)[];
35
40
  };
36
- export type InsertPayload<TDocument extends CollectionDocument<any>> = {
37
- what: What<PackReferences<TDocument> & {
38
- _id?: any;
39
- }>;
41
+ export type InsertPayload<TDocument extends CollectionDocument<any>, BypassTypeRestriction = false> = {
42
+ what: BypassTypeRestriction extends true ? any : What<PackReferences<TDocument>>;
40
43
  project?: Projection<TDocument>;
41
44
  };
42
45
  export type RemovePayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
@@ -65,6 +68,9 @@ export type CollectionFunctionsPaginated<TDocument extends CollectionDocument<Op
65
68
  pagination: Pagination;
66
69
  }>;
67
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
+ };
68
74
  export type CollectionFunctionsWithContext<TDocument extends CollectionDocument<OptionalId<any>>, TDescription extends Description = any, TFunctions = any> = {
69
- [P in keyof CollectionFunctions<TDocument>]: (payload: Parameters<CollectionFunctions<TDocument>[P]>[0], context: Context<TDescription, TFunctions>) => ReturnType<CollectionFunctions<TDocument>[P]>;
75
+ [P in keyof CollectionFunctionsWithBypass<TDocument>]: (payload: Parameters<CollectionFunctionsWithBypass<TDocument>[P]>[0], context: Context<TDescription, TFunctions>) => ReturnType<CollectionFunctions<TDocument>[P]>;
70
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, Property } from '.';
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 = {
@@ -18,19 +18,4 @@ export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse,
18
18
  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>>;
19
19
  type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
20
20
  export type InferResponse<TResponse> = MapSchemaUnion<UnwrapResponse<TResponse>> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never;
21
- export type ContractRoles = {
22
- roles?: Collections['user']['item']['roles'];
23
- };
24
- export type Contract = {
25
- response: Property | Property[];
26
- } | {
27
- payload: Property;
28
- } | {
29
- query: Property;
30
- } | {
31
- response?: Property | Property[];
32
- payload?: Property;
33
- query?: Property;
34
- };
35
- export type ContractWithRoles = ContractRoles & Contract;
36
21
  export {};
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.5",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",