@kikiutils/mongoose 2.0.2 → 2.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "2.0.2",
3
+ "version": "2.1.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
  "license": "MIT",
6
6
  "author": "kiki-kanri",
@@ -24,6 +24,7 @@ const createBaseSchemaBuilderFactory = (type) => {
24
24
  const isFunctionKeys = new Set([
25
25
  'default',
26
26
  'enum',
27
+ 'index',
27
28
  'max',
28
29
  'maxlength',
29
30
  'min',
@@ -22,6 +22,7 @@ const createBaseSchemaBuilderFactory = (type) => {
22
22
  const isFunctionKeys = new Set([
23
23
  'default',
24
24
  'enum',
25
+ 'index',
25
26
  'max',
26
27
  'maxlength',
27
28
  'min',
@@ -1,4 +1,4 @@
1
- import type { BooleanSchemaDefinition, DefaultType } from 'mongoose';
1
+ import type { BooleanSchemaDefinition, DefaultType, IndexDirection, IndexOptions } from 'mongoose';
2
2
  import type { Merge } from 'type-fest';
3
3
  type BaseProps = {
4
4
  type: BooleanSchemaDefinition;
@@ -8,6 +8,9 @@ export interface BooleanSchemaBuilder<Props extends BaseProps = BaseProps, Extra
8
8
  default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends boolean>(value: T) => ExtendBooleanSchemaBuilder<Merge<Props, {
9
9
  default: T;
10
10
  }>, ExtraOmitFields>;
11
+ index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendBooleanSchemaBuilder<Merge<Props, {
12
+ index: T;
13
+ }>, ExtraOmitFields>;
11
14
  nonRequired: Props;
12
15
  private: ExtendBooleanSchemaBuilder<Merge<Props, {
13
16
  private: true;
@@ -1,4 +1,4 @@
1
- import type { DefaultType, DateSchemaDefinition } from 'mongoose';
1
+ import type { DefaultType, DateSchemaDefinition, IndexDirection, IndexOptions } from 'mongoose';
2
2
  import type { Merge } from 'type-fest';
3
3
  import type { Readonlyable } from '../types/utils';
4
4
  type BaseProps = {
@@ -21,6 +21,9 @@ export interface DateSchemaBuilder<Props extends {
21
21
  }, D extends NativeDate, M extends string>(value: T) => ExtendDateSchemaBuilder<Merge<Props, {
22
22
  enum: T;
23
23
  }>, ExtraOmitFields>;
24
+ index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDateSchemaBuilder<Merge<Props, {
25
+ index: T;
26
+ }>, ExtraOmitFields>;
24
27
  max: <T extends D | Readonlyable<[D, S]>, D extends NativeDate, S extends string>(value: T) => ExtendDateSchemaBuilder<Merge<Props, {
25
28
  max: T;
26
29
  }>, ExtraOmitFields>;
@@ -1,6 +1,6 @@
1
1
  import Decimal from 'decimal.js';
2
2
  import { Schema } from 'mongoose';
3
- import type { DefaultType, Types } from 'mongoose';
3
+ import type { DefaultType, IndexDirection, IndexOptions, Types } from 'mongoose';
4
4
  import type { Merge } from 'type-fest';
5
5
  import type { Readonlyable } from '../types/utils';
6
6
  type BaseProps = {
@@ -31,6 +31,9 @@ export interface Decimal128SchemaBuilder<Props extends {
31
31
  }, D extends Types.Decimal128, M extends string>(value: T) => ExtendDecimal128SchemaBuilder<Merge<Props, {
32
32
  enum: T;
33
33
  }>, ExtraOmitFields>;
34
+ index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDecimal128SchemaBuilder<Merge<Props, {
35
+ index: T;
36
+ }>, ExtraOmitFields>;
34
37
  nonRequired: Props;
35
38
  private: ExtendDecimal128SchemaBuilder<Merge<Props, {
36
39
  private: true;
@@ -1,4 +1,4 @@
1
- import type { DefaultType, NumberSchemaDefinition } from 'mongoose';
1
+ import type { DefaultType, IndexDirection, IndexOptions, NumberSchemaDefinition } from 'mongoose';
2
2
  import type { Merge } from 'type-fest';
3
3
  import type { Readonlyable } from '../types/utils';
4
4
  type BaseProps = {
@@ -21,6 +21,9 @@ export interface NumberSchemaBuilder<Props extends {
21
21
  }, M extends string, N extends number>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, {
22
22
  enum: T;
23
23
  }>, ExtraOmitFields>;
24
+ index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, {
25
+ index: T;
26
+ }>, ExtraOmitFields>;
24
27
  max: <T extends N | Readonlyable<[N, S]>, N extends number, S extends string>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, {
25
28
  max: T;
26
29
  }>, ExtraOmitFields>;
@@ -1,4 +1,4 @@
1
- import type { DefaultType, ObjectIdSchemaDefinition, Types } from 'mongoose';
1
+ import type { DefaultType, IndexDirection, IndexOptions, ObjectIdSchemaDefinition, Types } from 'mongoose';
2
2
  import type { Merge } from 'type-fest';
3
3
  import type { Readonlyable } from '../types/utils';
4
4
  type BaseProps = {
@@ -21,6 +21,9 @@ export interface ObjectIdSchemaBuilder<Props extends {
21
21
  }, M extends string, O extends Types.ObjectId>(value: T) => ExtendObjectIdSchemaBuilder<Merge<Props, {
22
22
  enum: T;
23
23
  }>, ExtraOmitFields>;
24
+ index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendObjectIdSchemaBuilder<Merge<Props, {
25
+ index: T;
26
+ }>, ExtraOmitFields>;
24
27
  nonRequired: Props;
25
28
  private: ExtendObjectIdSchemaBuilder<Merge<Props, {
26
29
  private: true;
@@ -1,4 +1,4 @@
1
- import type { DefaultType, Model, ObjectIdSchemaDefinition, Types } from 'mongoose';
1
+ import type { DefaultType, IndexDirection, IndexOptions, Model, ObjectIdSchemaDefinition, Types } from 'mongoose';
2
2
  import type { Merge } from 'type-fest';
3
3
  import type { Readonlyable } from '../types/utils';
4
4
  type BaseProps = {
@@ -21,6 +21,9 @@ export interface RefSchemaBuilder<Props extends {
21
21
  }, M extends string, O extends Types.ObjectId>(value: T) => ExtendRefSchemaBuilder<Merge<Props, {
22
22
  enum: T;
23
23
  }>, ExtraOmitFields>;
24
+ index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendRefSchemaBuilder<Merge<Props, {
25
+ index: T;
26
+ }>, ExtraOmitFields>;
24
27
  nonRequired: Props;
25
28
  private: ExtendRefSchemaBuilder<Merge<Props, {
26
29
  private: true;
@@ -1,4 +1,4 @@
1
- import type { DefaultType, StringSchemaDefinition } from 'mongoose';
1
+ import type { DefaultType, IndexDirection, IndexOptions, StringSchemaDefinition } from 'mongoose';
2
2
  import type { Merge } from 'type-fest';
3
3
  import type { Readonlyable } from '../types/utils';
4
4
  type BaseProps = {
@@ -28,6 +28,9 @@ export interface StringSchemaBuilder<Props extends {
28
28
  }, M extends string, S extends string>(value: T) => ExtendStringSchemaBuilder<Merge<Props, {
29
29
  enum: T;
30
30
  }>, ExtraOmitFields>;
31
+ index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<Merge<Props, {
32
+ index: T;
33
+ }>, ExtraOmitFields>;
31
34
  /**
32
35
  * Adds IPv4 validation to the string schema.
33
36
  * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.
package/types/data.d.ts CHANGED
@@ -48,15 +48,21 @@ declare global {
48
48
  */
49
49
  type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = OmitNever<LocalBaseMongooseModelData<CreatedAtField, UpdatedAtField>>;
50
50
  /**
51
- * Type definition to omit timestamp fields and other specified fields from a given type.
51
+ * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
52
+ * and other specified fields (`OT`) from a given type `T`.
52
53
  *
53
- * This type alias uses `Omit` to remove `createdAt`, `updatedAt`, and any other specified fields (`OT`)
54
- * from the type `T`.
54
+ * @template T - The type from which to omit fields.
55
+ * @template OT - Additional fields to omit, specified as a union of keys in `T`.
56
+ */
57
+ type ExceptMongooseTimestampAndOtherFields<T, OT extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | OT>;
58
+ /**
59
+ * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
60
+ * and other specified fields (`OT`) from a given type `T`.
55
61
  *
56
62
  * @template T - The type from which to omit fields.
57
- * @template OT - Additional fields to omit, specified as a union of string, number, or symbol.
63
+ * @template OT - Additional fields to omit, specified as a union of string, number, or symbol keys.
58
64
  */
59
- type OmitMongooseTimestampAndOtherFields<T, OT extends number | symbol | string = ''> = Omit<T, 'createdAt' | 'updatedAt' | OT>;
65
+ type OmitMongooseTimestampAndOtherFields<T, OT extends number | symbol | string = never> = Omit<T, 'createdAt' | 'updatedAt' | OT>;
60
66
  /**
61
67
  * Type definition for including timestamp fields conditionally based on the provided flags.
62
68
  *