@aeriajs/types 0.0.8 → 0.0.12

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.
Files changed (2) hide show
  1. package/dist/functions.d.ts +20 -10
  2. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import type { FilterOperators, StrictUpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
1
+ import type { FilterOperators, StrictFilter as Filter, 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,15 +10,24 @@ export type Pagination = {
10
10
  offset: number;
11
11
  limit: number;
12
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];
13
+ type DocumentFilter<TDocument> = PackReferences<TDocument> extends infer Document ? {
14
+ [P in keyof Document]: null | (Document[P] extends ObjectId ? Document[P] | string : Document[P]);
15
15
  } : never;
16
- export type Filters<TDocument> = Partial<{
17
- [P in keyof TDocument]: PackReferences<TDocument>[P] | StrictFilterOperators<PackReferences<TDocument>[P]>;
18
- }>;
19
- export type What<TDocument> = StrictUpdateFilter<TDocument> & {
20
- [P in keyof TDocument]?: '_id' extends keyof TDocument[P] ? TDocument[P] | string : TDocument[P];
16
+ type RemoveAny<T> = {
17
+ [P in keyof T as 0 extends (T[P] & 1) ? never : P]: T[P];
21
18
  };
19
+ export type StrictFilter<TDocument> = RemoveAny<Filter<DocumentFilter<TDocument>>>;
20
+ export type StrictFilterOperators<TDocument> = RemoveAny<FilterOperators<DocumentFilter<TDocument>>>;
21
+ export type Filters<TDocument> = StrictFilter<any> & Partial<{
22
+ [P in keyof TDocument]: null | (TDocument[P] extends infer Field ? Field extends ObjectId ? Field | string : Field extends {
23
+ _id: infer Id;
24
+ } ? Id | string : Field : never) extends infer Field ? Field | StrictFilterOperators<Field> | null : never;
25
+ }>;
26
+ export type What<TDocument> = DocumentFilter<TDocument> extends infer Document ? Partial<{
27
+ [P in keyof Document]: Document[P] extends null ? null : Document[P] | StrictUpdateFilter<Document[P]>;
28
+ }> & {
29
+ _id?: ObjectId | string;
30
+ } : never;
22
31
  export type Projection<TDocument> = keyof TDocument | '_id' extends infer DocumentProp ? TDocument extends string ? DocumentProp[] : string[] : never;
23
32
  export type QuerySort<TDocument> = Partial<Record<keyof WithId<TDocument>, 1 | -1>>;
24
33
  export type CollectionDocument<TDocument> = TDocument;
@@ -39,7 +48,7 @@ export type GetAllPayload<TDocument extends CollectionDocument<OptionalId<any>>>
39
48
  populate?: (keyof TDocument | string)[];
40
49
  };
41
50
  export type InsertPayload<TDocument extends CollectionDocument<any>, BypassTypeRestriction = false> = {
42
- what: BypassTypeRestriction extends true ? any : What<PackReferences<TDocument>>;
51
+ what: BypassTypeRestriction extends true ? any : What<TDocument>;
43
52
  project?: Projection<TDocument>;
44
53
  };
45
54
  export type RemovePayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
@@ -69,8 +78,9 @@ export type CollectionFunctionsPaginated<TDocument extends CollectionDocument<Op
69
78
  }>;
70
79
  };
71
80
  export type CollectionFunctionsWithBypass<TDocument extends CollectionDocument<OptionalId<any>>> = Omit<CollectionFunctions<TDocument>, 'insert'> & {
72
- insert: (payload: InsertPayload<TDocument, true>) => Promise<Either<ValidationError | ACErrors, TDocument>>;
81
+ insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError | ACErrors, TDocument>>;
73
82
  };
74
83
  export type CollectionFunctionsWithContext<TDocument extends CollectionDocument<OptionalId<any>>, TDescription extends Description = any, TFunctions = any> = {
75
84
  [P in keyof CollectionFunctionsWithBypass<TDocument>]: (payload: Parameters<CollectionFunctionsWithBypass<TDocument>[P]>[0], context: Context<TDescription, TFunctions>) => ReturnType<CollectionFunctions<TDocument>[P]>;
76
85
  };
86
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.8",
3
+ "version": "0.0.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",