@kikiutils/mongoose 9.0.4 → 9.0.5

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,5 +1,5 @@
1
- import { CustomMongooseOptions } from "./types/options.js";
2
1
  import { Connection } from "mongoose";
2
+ import { CustomMongooseOptions } from "./types/options.js";
3
3
  export declare const customMongooseOptions: CustomMongooseOptions;
4
4
  export declare const mongooseConnectionState: {
5
5
  defaultConnection?: Connection;
@@ -1,7 +1,7 @@
1
+ import { Schema } from "mongoose";
1
2
  import { mongooseAssertionsPlugin } from "./plugins/assertions.js";
2
3
  import { BaseMongoosePaginateModel } from "./types/index.js";
3
4
  import { BuildMongooseModelOptions } from "./types/options.js";
4
- import { Schema } from "mongoose";
5
5
  export type DoNotRemoveOrUseThisType = typeof mongooseAssertionsPlugin;
6
6
  export declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
7
7
  //# sourceMappingURL=builders.d.ts.map
package/dist/builders.js CHANGED
@@ -1,10 +1,10 @@
1
+ import mongooseAggregatePaginate from "mongoose-aggregate-paginate-v2";
2
+ import mongoosePaginate from "mongoose-paginate-v2";
1
3
  import { customMongooseOptions } from "./_internals.js";
2
4
  import { getDefaultMongooseConnection } from "./connection.js";
3
5
  import { mongooseAssertionsPlugin } from "./plugins/assertions.js";
4
6
  import { mongooseLeanDecimal128ToStringPlugin } from "./plugins/lean-decimal128-to-string.js";
5
7
  import { mongooseNormalizePlugin } from "./plugins/normalize.js";
6
- import mongooseAggregatePaginate from "mongoose-aggregate-paginate-v2";
7
- import mongoosePaginate from "mongoose-paginate-v2";
8
8
  // src/builders.ts
9
9
  function buildMongooseModel(collection, name, schema, options) {
10
10
  const leanDecimal128ToStringPluginOptions = options?.plugins?.leanDecimal128ToString;
@@ -1,5 +1,5 @@
1
- import { customMongooseOptions, mongooseConnectionState } from "./_internals.js";
2
1
  import mongoose from "mongoose";
2
+ import { customMongooseOptions, mongooseConnectionState } from "./_internals.js";
3
3
  // src/connection.ts
4
4
  function getDefaultMongooseConnection() {
5
5
  return mongooseConnectionState.defaultConnection ||= mongoose.createConnection(process.env.MONGODB_URI || "mongodb://127.0.0.1:27017", customMongooseOptions.defaultConnectionOptions);
@@ -1,6 +1,6 @@
1
+ import { get, set, unset } from "es-toolkit/compat";
1
2
  import { Types } from "mongoose";
2
3
  import { objectEntries } from "ts-extras";
3
- import { get, set, unset } from "es-toolkit/compat";
4
4
  // src/plugins/normalize.ts
5
5
  const registeredSchemas = /* @__PURE__ */ new WeakSet();
6
6
  /**
@@ -1,6 +1,6 @@
1
- import { EnumInput, EnumValidator, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
2
1
  import { DefaultType, IndexDirection, IndexOptions, Schema } from "mongoose";
3
2
  import { Merge } from "type-fest";
3
+ import { EnumInput, EnumValidator, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
4
4
  type BigIntLimit = bigint;
5
5
  type BigIntValidationSchema = ValidationSchema<EnumValidator<bigint> | LimitValidator<bigint>>;
6
6
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<BigIntSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
@@ -1,6 +1,6 @@
1
+ import { Schema } from "mongoose";
1
2
  import { defaultLimitValidateMessages, hasSchemaValidator, normalizeEnumValues, normalizeValueWithMessage, setSchemaValidator } from "./_internals.js";
2
3
  import { createBaseSchemaBuilderFactory } from "./base.js";
3
- import { Schema } from "mongoose";
4
4
  // src/schema-builders/bigint.ts
5
5
  const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.BigInt);
6
6
  function bigintSchemaBuilder() {
@@ -1,6 +1,6 @@
1
- import { EnumInput, ValueWithMessage } from "../types/_internals.js";
2
1
  import { DateSchemaDefinition, DefaultType, IndexDirection, IndexOptions } from "mongoose";
3
2
  import { Merge } from "type-fest";
3
+ import { EnumInput, ValueWithMessage } from "../types/_internals.js";
4
4
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<DateSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
5
5
  interface BaseProps {
6
6
  type: DateSchemaDefinition;
@@ -1,7 +1,7 @@
1
- import { EnumInput, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
2
- import { DefaultType, IndexDirection, IndexOptions, Schema, Types } from "mongoose";
3
1
  import { Decimal } from "decimal.js";
2
+ import { DefaultType, IndexDirection, IndexOptions, Schema, Types } from "mongoose";
4
3
  import { Merge } from "type-fest";
4
+ import { EnumInput, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
5
5
  type Decimal128Limit = Decimal.Value | Types.Decimal128 | {
6
6
  toString: () => string;
7
7
  };
@@ -1,7 +1,7 @@
1
+ import { Decimal } from "decimal.js";
2
+ import { Schema } from "mongoose";
1
3
  import { defaultLimitValidateMessages, normalizeValueWithMessage, setSchemaValidator } from "./_internals.js";
2
4
  import { createBaseSchemaBuilderFactory } from "./base.js";
3
- import { Schema } from "mongoose";
4
- import { Decimal } from "decimal.js";
5
5
  // src/schema-builders/decimal128.ts
6
6
  const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
7
7
  function createLimitValidator(type, value) {
@@ -1,6 +1,6 @@
1
- import { EnumInput, EnumValidator, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
2
1
  import { IndexDirection, IndexOptions, Schema, Types } from "mongoose";
3
2
  import { Merge } from "type-fest";
3
+ import { EnumInput, EnumValidator, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
4
4
  type DoubleLimit = number | Types.Double;
5
5
  type DoubleValidationSchema = ValidationSchema<EnumValidator<number | Types.Double, Types.Double> | LimitValidator<number, Types.Double>>;
6
6
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<DoubleSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
@@ -1,6 +1,6 @@
1
+ import { Schema } from "mongoose";
1
2
  import { defaultLimitValidateMessages, hasSchemaValidator, normalizeEnumValues, normalizeValueWithMessage, setSchemaValidator } from "./_internals.js";
2
3
  import { createBaseSchemaBuilderFactory } from "./base.js";
3
- import { Schema } from "mongoose";
4
4
  // src/schema-builders/double.ts
5
5
  const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Double);
6
6
  function createLimitValidator(type, value) {
@@ -1,6 +1,6 @@
1
- import { EnumInput, EnumValidator, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
2
1
  import { DefaultType, IndexDirection, IndexOptions, Schema } from "mongoose";
3
2
  import { Merge } from "type-fest";
3
+ import { EnumInput, EnumValidator, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
4
4
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<Int32SchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
5
5
  type Int32Limit = number;
6
6
  type Int32ValidationSchema = ValidationSchema<EnumValidator<number> | LimitValidator<number>>;
@@ -1,6 +1,6 @@
1
+ import { Schema } from "mongoose";
1
2
  import { defaultLimitValidateMessages, hasSchemaValidator, normalizeEnumValues, normalizeValueWithMessage, setSchemaValidator } from "./_internals.js";
2
3
  import { createBaseSchemaBuilderFactory } from "./base.js";
3
- import { Schema } from "mongoose";
4
4
  // src/schema-builders/int32.ts
5
5
  const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Int32);
6
6
  function createLimitValidator(type, value) {
@@ -1,5 +1,5 @@
1
- import { createBaseSchemaBuilderFactory } from "./base.js";
2
1
  import { Schema } from "mongoose";
2
+ import { createBaseSchemaBuilderFactory } from "./base.js";
3
3
  // src/schema-builders/mixed.ts
4
4
  const mixedSchemaBuilder = createBaseSchemaBuilderFactory(Schema.Types.Mixed);
5
5
  export { mixedSchemaBuilder };
@@ -1,6 +1,6 @@
1
- import { EnumInput, ValueWithMessage } from "../types/_internals.js";
2
1
  import { DefaultType, IndexDirection, IndexOptions, NumberSchemaDefinition } from "mongoose";
3
2
  import { Merge } from "type-fest";
3
+ import { EnumInput, ValueWithMessage } from "../types/_internals.js";
4
4
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<NumberSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
5
5
  interface BaseProps {
6
6
  type: NumberSchemaDefinition;
@@ -1,6 +1,6 @@
1
- import { EnumInput } from "../types/_internals.js";
2
1
  import { DefaultType, IndexDirection, IndexOptions, Schema, Types } from "mongoose";
3
2
  import { Merge } from "type-fest";
3
+ import { EnumInput } from "../types/_internals.js";
4
4
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<ObjectIdSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
5
5
  interface BaseProps {
6
6
  type: typeof Schema.Types.ObjectId;
@@ -1,5 +1,5 @@
1
- import { createBaseSchemaBuilderFactory } from "./base.js";
2
1
  import { Schema } from "mongoose";
2
+ import { createBaseSchemaBuilderFactory } from "./base.js";
3
3
  // src/schema-builders/object-id.ts
4
4
  const objectIdSchemaBuilder = createBaseSchemaBuilderFactory(Schema.Types.ObjectId);
5
5
  export { objectIdSchemaBuilder };
@@ -1,6 +1,6 @@
1
- import { EnumInput } from "../types/_internals.js";
2
1
  import { DefaultType, IndexDirection, IndexOptions, Model, Schema, Types } from "mongoose";
3
2
  import { Merge } from "type-fest";
3
+ import { EnumInput } from "../types/_internals.js";
4
4
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<RefSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
5
5
  interface BaseProps {
6
6
  type: typeof Schema.Types.ObjectId;
@@ -1,5 +1,5 @@
1
- import { createBaseSchemaBuilderFactory } from "./base.js";
2
1
  import { Schema } from "mongoose";
2
+ import { createBaseSchemaBuilderFactory } from "./base.js";
3
3
  // src/schema-builders/ref.ts
4
4
  const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.ObjectId);
5
5
  function refSchemaBuilder(ref) {
@@ -1,6 +1,6 @@
1
- import { EnumInput, ValueWithMessage } from "../types/_internals.js";
2
1
  import { DefaultType, IndexDirection, IndexOptions, StringSchemaDefinition } from "mongoose";
3
2
  import { Merge } from "type-fest";
3
+ import { EnumInput, ValueWithMessage } from "../types/_internals.js";
4
4
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<StringSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
5
5
  interface BaseProps {
6
6
  type: StringSchemaDefinition;
@@ -1,5 +1,5 @@
1
- import { createBaseSchemaBuilderFactory } from "./base.js";
2
1
  import { isIPv4, isIPv6 } from "node:net";
2
+ import { createBaseSchemaBuilderFactory } from "./base.js";
3
3
  // src/schema-builders/string.ts
4
4
  const defaultIpv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}`";
5
5
  const defaultIpv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`";
@@ -1,5 +1,5 @@
1
- import { createBaseSchemaBuilderFactory } from "./base.js";
2
1
  import { Schema } from "mongoose";
2
+ import { createBaseSchemaBuilderFactory } from "./base.js";
3
3
  // src/schema-builders/uuid.ts
4
4
  const uuidSchemaBuilder = createBaseSchemaBuilderFactory(Schema.Types.UUID);
5
5
  export { uuidSchemaBuilder };
@@ -1,5 +1,5 @@
1
- import { BaseMongooseDocType, SetFieldsToObjectId } from "./index.js";
2
1
  import { SetFieldType } from "type-fest";
2
+ import { BaseMongooseDocType, SetFieldsToObjectId } from "./index.js";
3
3
  export type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
4
4
  createdAt: string;
5
5
  } : unknown) & (UpdatedAtField extends true ? {
@@ -1,7 +1,7 @@
1
- import { AggregatePaginateModel } from "./aggregate-paginate.js";
2
- import { PaginateModel } from "./paginate.js";
3
1
  import { HydratedDocument, QueryWithHelpers, Require_id, Types } from "mongoose";
4
2
  import { SetFieldType } from "type-fest";
3
+ import { AggregatePaginateModel } from "./aggregate-paginate.js";
4
+ import { PaginateModel } from "./paginate.js";
5
5
  /**
6
6
  * Raw document type with an ObjectId by default, or the `_id` type declared in T.
7
7
  * Set IdField to false for schemas with `_id: false`. Nested fields are left unchanged.
@@ -1,7 +1,7 @@
1
+ import { ConnectOptions, Connection, Schema, SchemaTimestampsConfig } from "mongoose";
1
2
  import { MongooseLeanDecimal128ToStringPluginOptions } from "../plugins/lean-decimal128-to-string.js";
2
3
  import { MongooseNormalizePluginOptions } from "../plugins/normalize.js";
3
4
  import { BaseMongoosePaginateModel } from "./index.js";
4
- import { ConnectOptions, Connection, Schema, SchemaTimestampsConfig } from "mongoose";
5
5
  export interface BuildMongooseModelOptions {
6
6
  connection?: Connection;
7
7
  plugins?: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
3
  "type": "module",
4
- "version": "9.0.4",
4
+ "version": "9.0.5",
5
5
  "description": "Provides Mongoose schema builders and utilities for connections, pagination, JSON normalization, and update checks.",
6
6
  "author": "kiki-kanri",
7
7
  "license": "MIT",
@@ -70,27 +70,27 @@
70
70
  "dependencies": {
71
71
  "decimal.js": "^10.6.0",
72
72
  "es-toolkit": "^1.53.2",
73
- "mongoose": "^9.12.1",
73
+ "mongoose": "^9.12.3",
74
74
  "mongoose-aggregate-paginate-v2": "^1.1.5",
75
75
  "mongoose-paginate-v2": "^1.9.5",
76
- "ts-extras": "^2.0.0",
77
- "type-fest": "^5.10.0"
76
+ "ts-extras": "^3.0.0",
77
+ "type-fest": "^6.0.3"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@antfu/eslint-config": "^10.0.0",
81
81
  "@arethetypeswrong/core": "^0.18.5",
82
- "@kikiutils/eslint-config": "^11.0.1",
82
+ "@kikiutils/eslint-config": "^11.2.0",
83
83
  "@kikiutils/tsconfigs": "^7.0.0",
84
84
  "@types/node": "^26.6.6",
85
- "@vitest/coverage-v8": "^5.1.0",
85
+ "@vitest/coverage-v8": "^5.1.1",
86
86
  "changelogen": "^0.6.2",
87
- "eslint": "^10.14.0",
88
- "knip": "^6.45.1",
87
+ "eslint": "^10.15.0",
88
+ "knip": "^6.47.0",
89
89
  "mongoose-lean-getters": "^2.3.1",
90
90
  "publint": "^0.3.25",
91
91
  "tsdown": "^0.23.7",
92
92
  "typescript": "^6.0.3",
93
93
  "unplugin-unused": "^0.6.0",
94
- "vitest": "^5.1.0"
94
+ "vitest": "^5.1.1"
95
95
  }
96
96
  }