@kikiutils/mongoose 3.1.2 → 3.3.0

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.
@@ -1,3 +1,5 @@
1
+ import type { Types } from 'mongoose';
2
+ import type { SetFieldType } from 'type-fest';
1
3
  import type { IfElse } from './utils';
2
4
  declare global {
3
5
  /**
@@ -13,22 +15,23 @@ declare global {
13
15
  }, unknown> & {
14
16
  id: string;
15
17
  };
18
+ type DataToBaseMongooseDocType<T, ObjectIdFields extends keyof T = never, DateFields extends Exclude<keyof T, ObjectIdFields> = never, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = BaseMongooseDocType<SetFieldType<SetFieldType<T, DateFields, Date>, ObjectIdFields, Types.ObjectId>, CreatedAtField, UpdatedAtField>;
16
19
  /**
17
20
  * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
18
- * and other specified fields (`OT`) from a given type `T`.
21
+ * and other specified fields (`K`) from a given type `T`.
19
22
  *
20
23
  * @template T - The type from which to omit fields.
21
- * @template OT - Additional fields to omit, specified as a union of keys in `T`.
24
+ * @template K - Additional fields to omit, specified as a union of keys in `T`.
22
25
  */
23
- type ExceptMongooseTimestampAndOtherFields<T, OT extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | OT>;
26
+ type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
24
27
  /**
25
28
  * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
26
- * and other specified fields (`OT`) from a given type `T`.
29
+ * and other specified fields (`K`) from a given type `T`.
27
30
  *
28
31
  * @template T - The type from which to omit fields.
29
- * @template OT - Additional fields to omit, specified as a union of string, number, or symbol keys.
32
+ * @template K - Additional fields to omit, specified as a union of string, number, or symbol keys.
30
33
  */
31
- type OmitMongooseTimestampAndOtherFields<T, OT extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | OT>;
34
+ type OmitMongooseTimestampAndOtherFields<T, K extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | K>;
32
35
  /**
33
36
  * Type definition for including timestamp fields conditionally based on the provided flags.
34
37
  *
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/types/data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,CAAC,MAAM,CAAC;IACX;;;;;OAKG;IACH,KAAK,qBAAqB,CACtB,cAAc,SAAS,OAAO,GAAG,IAAI,EACrC,cAAc,SAAS,OAAO,GAAG,IAAI,IAErC,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,GACtD,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,GACtD;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAEnB;;;;;;OAMG;IACH,KAAK,qCAAqC,CAAC,CAAC,EAAE,EAAE,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,EAAE,CAAC,CAAC;IAE5G;;;;;;OAMG;IACH,KAAK,mCAAmC,CACpC,CAAC,EACD,EAAE,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,IAC3C,IAAI,CACJ,CAAC,EACD,WAAW,GAAG,WAAW,GAAG,EAAE,CACjC,CAAC;IAEF;;;;;OAKG;IACH,KAAK,+BAA+B,CAChC,SAAS,SAAS,OAAO,GAAG,IAAI,EAChC,SAAS,SAAS,OAAO,GAAG,IAAI,IAEhC,MAAM,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,GAChD,MAAM,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,CAAC;CACxD"}
1
+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,IAAI,CACJ,CAAC,EACD,WAAW,GAAG,WAAW,GAAG,CAAC,CAChC,CAAC;IAEF;;;;;OAKG;IACH,KAAK,+BAA+B,CAChC,SAAS,SAAS,OAAO,GAAG,IAAI,EAChC,SAAS,SAAS,OAAO,GAAG,IAAI,IAEhC,MAAM,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,GAChD,MAAM,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,CAAC;CACxD"}
@@ -1,4 +1,5 @@
1
1
  import type { AggregatePaginateModel, Connection, HydratedDocument, PaginateModel, QueryWithHelpers, Types } from 'mongoose';
2
+ import type { SetFieldType } from 'type-fest';
2
3
  import type { IfElse } from './utils';
3
4
  export type {} from './aggregate-paginate';
4
5
  export type {} from './paginate';
@@ -74,5 +75,6 @@ declare global {
74
75
  * @template QueryHelpers - Optional type parameter for additional query helper methods.
75
76
  */
76
77
  type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
78
+ type SetFieldsToObjectId<T, F extends keyof T> = SetFieldType<T, F, Types.ObjectId>;
77
79
  }
78
80
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,KAAK,EACR,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC3C,YAAY,EAAE,MAAM,YAAY,CAAC;AAIjC,MAAM,WAAW,gBAAgB,CAAC,UAAU,EAAE,2BAA2B,GAAG,MAAM,EAAE,YAAY,GA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AAY,EAAE,2BAA2B,CAAC,CAAC;IAEzE;;;;;;;;OAQG;IACH,KAAK,0BAA0B,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC;IAEjE;;;;;;;;;;;;;;OAcG;IACH,KAAK,yBAAyB,CAC1B,UAAU,EACV,OAAO,EACP,YAAY,GAAG,MAAM,EACrB,2BAA2B,GAAG,MAAM,IACpC,gBAAgB,CAChB,OAAO,GAAG,IAAI,EACd,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,2BAA2B,CAC9B,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,KAAK,wBAAwB,CACzB,OAAO,EACP,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,IACrB,gBAAgB,CAChB,OAAO,EACP,2BAA2B,EAC3B,YAAY,CACf,CAAC;IAEF,KAAK,mBAAmB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CACvF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "3.1.2",
3
+ "version": "3.3.0",
4
4
  "description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
5
5
  "author": "kiki-kanri",
6
6
  "license": "MIT",
package/src/types/data.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import type { Types } from 'mongoose';
2
+ import type { SetFieldType } from 'type-fest';
3
+
1
4
  import type { IfElse } from './utils';
2
5
 
3
6
  declare global {
@@ -15,28 +18,40 @@ declare global {
15
18
  & IfElse<UpdatedAtField, { updatedAt: string }, unknown>
16
19
  & { id: string };
17
20
 
21
+ type DataToBaseMongooseDocType<
22
+ T,
23
+ ObjectIdFields extends keyof T = never,
24
+ DateFields extends Exclude<keyof T, ObjectIdFields> = never,
25
+ CreatedAtField extends boolean = true,
26
+ UpdatedAtField extends boolean = true,
27
+ > = BaseMongooseDocType<
28
+ SetFieldType<SetFieldType<T, DateFields, Date>, ObjectIdFields, Types.ObjectId>,
29
+ CreatedAtField,
30
+ UpdatedAtField
31
+ >;
32
+
18
33
  /**
19
34
  * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
20
- * and other specified fields (`OT`) from a given type `T`.
35
+ * and other specified fields (`K`) from a given type `T`.
21
36
  *
22
37
  * @template T - The type from which to omit fields.
23
- * @template OT - Additional fields to omit, specified as a union of keys in `T`.
38
+ * @template K - Additional fields to omit, specified as a union of keys in `T`.
24
39
  */
25
- type ExceptMongooseTimestampAndOtherFields<T, OT extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | OT>;
40
+ type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
26
41
 
27
42
  /**
28
43
  * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
29
- * and other specified fields (`OT`) from a given type `T`.
44
+ * and other specified fields (`K`) from a given type `T`.
30
45
  *
31
46
  * @template T - The type from which to omit fields.
32
- * @template OT - Additional fields to omit, specified as a union of string, number, or symbol keys.
47
+ * @template K - Additional fields to omit, specified as a union of string, number, or symbol keys.
33
48
  */
34
49
  type OmitMongooseTimestampAndOtherFields<
35
50
  T,
36
- OT extends number | string | symbol = never,
51
+ K extends number | string | symbol = never,
37
52
  > = Omit<
38
53
  T,
39
- 'createdAt' | 'updatedAt' | OT
54
+ 'createdAt' | 'updatedAt' | K
40
55
  >;
41
56
 
42
57
  /**
@@ -6,6 +6,7 @@ import type {
6
6
  QueryWithHelpers,
7
7
  Types,
8
8
  } from 'mongoose';
9
+ import type { SetFieldType } from 'type-fest';
9
10
 
10
11
  import type { IfElse } from './utils';
11
12
 
@@ -121,4 +122,6 @@ declare global {
121
122
  InstanceMethodsAndOverrides,
122
123
  QueryHelpers
123
124
  >;
125
+
126
+ type SetFieldsToObjectId<T, F extends keyof T> = SetFieldType<T, F, Types.ObjectId>;
124
127
  }