@kikiutils/mongoose 9.0.3 → 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.
- package/dist/_internals.d.ts +1 -1
- package/dist/builders.d.ts +1 -1
- package/dist/builders.js +2 -2
- package/dist/connection.js +1 -1
- package/dist/plugins/normalize.js +1 -1
- package/dist/plugins/normalize.js.map +1 -1
- package/dist/schema-builders/bigint.d.ts +1 -1
- package/dist/schema-builders/bigint.js +1 -1
- package/dist/schema-builders/date.d.ts +1 -1
- package/dist/schema-builders/decimal128.d.ts +2 -2
- package/dist/schema-builders/decimal128.js +2 -2
- package/dist/schema-builders/double.d.ts +1 -1
- package/dist/schema-builders/double.js +1 -1
- package/dist/schema-builders/int32.d.ts +1 -1
- package/dist/schema-builders/int32.js +1 -1
- package/dist/schema-builders/mixed.js +1 -1
- package/dist/schema-builders/number.d.ts +1 -1
- package/dist/schema-builders/object-id.d.ts +1 -1
- package/dist/schema-builders/object-id.js +1 -1
- package/dist/schema-builders/ref.d.ts +1 -1
- package/dist/schema-builders/ref.js +1 -1
- package/dist/schema-builders/string.d.ts +1 -1
- package/dist/schema-builders/string.js +1 -1
- package/dist/schema-builders/uuid.js +1 -1
- package/dist/types/data.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/options.d.ts +1 -1
- package/package.json +23 -30
package/dist/_internals.d.ts
CHANGED
|
@@ -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;
|
package/dist/builders.d.ts
CHANGED
|
@@ -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;
|
package/dist/connection.js
CHANGED
|
@@ -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.js","names":["getProp"],"sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import {\n get as getProp,\n set as setProp,\n unset as unsetProp,\n} from 'es-toolkit/compat';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\nimport { objectEntries } from 'ts-extras';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to move the serialized `_id` value to `id`.\n *\n * @remarks\n * If `false`, preserves the value under `_id` instead. Only values other than `undefined` are copied.\n *\n * @defaultValue `true`.\n */\n convertIdField?: boolean;\n\n /**\n * Register normalization on child schemas too. Defaults to true.\n */\n recursive?: boolean;\n\n /**\n * Whether to convert a serialized `ObjectId` identifier to its hexadecimal string.\n *\n * @remarks\n * Applies before choosing the `id` or `_id` output key. Identifiers of other types are unchanged.\n *\n * @defaultValue `true`.\n */\n toHexIdIfObjectId?: boolean;\n}\n\n// Constants/Variables\nconst registeredSchemas = new WeakSet<Schema>();\n\n// Functions\n\n/**\n * Registers JSON normalization on a Mongoose schema.\n *\n * @remarks\n * Mutates the schema's `toJSON` configuration while preserving its other options. The transform removes `__v`,\n * normalizes `_id` according to the plugin options, removes schema paths marked `private`, and converts\n * truthy serialized values at registered `Decimal128` paths to strings.\n *\n * If an existing transform is a function, invokes it after normalization. If it returns `undefined`,\n * preserves the normalized output and any mutations made by that transform; otherwise, uses its return value.\n * That transform can change the normalized output, and its errors propagate during serialization.\n * Registers itself on child schemas unless `recursive` is false. Does not configure `toObject`.\n * Registration is idempotent per schema; the first registration's options take precedence.\n *\n * @param schema - The schema whose JSON serialization configuration is modified.\n * @param pluginOptions - The normalization and registration options; omitted options use their documented defaults.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(\n schema: S,\n pluginOptions?: MongooseNormalizePluginOptions,\n) {\n if (registeredSchemas.has(schema)) return;\n registeredSchemas.add(schema);\n\n // Collect special paths (Decimal128 & private)\n const decimalPaths: string[] = [];\n const privatePaths: string[] = [];\n for (const [path, schemaType] of objectEntries(schema.paths)) {\n if (schemaType?.options?.private) privatePaths.push(path);\n else if (schemaType?.instance === 'Decimal128') decimalPaths.push(path);\n }\n\n // Get original toJSON configuration\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n\n // Override toJSON with custom transform\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // Copy object and remove __v\n const copiedRet = { ...ret };\n // @ts-expect-error Ignore this error\n delete copiedRet.__v;\n\n // Normalize _id (convert to hex and/or move to id)\n let _id = copiedRet._id;\n delete copiedRet._id;\n if (pluginOptions?.toHexIdIfObjectId !== false && _id instanceof Types.ObjectId) {\n _id = _id.toHexString();\n }\n\n if (_id !== undefined) {\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n }\n\n // Remove private fields\n for (const path of privatePaths) unsetProp(copiedRet, path);\n\n // Convert Decimal128 fields to string\n for (const path of decimalPaths) {\n const value = getProp(copiedRet, path) as Types.Decimal128 | undefined;\n if (value) setProp(copiedRet, path, value.toString());\n }\n\n // Run original toJSON transform\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n const transformed = toJsonTransform(doc as any, copiedRet as any, options as any);\n return transformed === undefined ? copiedRet : transformed;\n }\n\n // Return normalized object\n return copiedRet;\n },\n },\n );\n\n if (pluginOptions?.recursive !== false) {\n schema.childSchemas.forEach(({ schema: child }) => child.plugin(mongooseNormalizePlugin, pluginOptions));\n }\n}\n"],"mappings":";;;;AAqCA,MAAM,oCAAoB,IAAI,QAAgB;;;;;;;;;;;;;;;;;;AAqB9C,SAAgB,wBACZ,QACA,eACF;CACE,IAAI,kBAAkB,IAAI,MAAM,GAAG;CACnC,kBAAkB,IAAI,MAAM;CAG5B,MAAM,eAAyB,CAAC;CAChC,MAAM,eAAyB,CAAC;CAChC,KAAK,MAAM,CAAC,MAAM,eAAe,cAAc,OAAO,KAAK,GACvD,IAAI,YAAY,SAAS,SAAS,aAAa,KAAK,IAAI;MACnD,IAAI,YAAY,aAAa,cAAc,aAAa,KAAK,IAAI;CAI1E,MAAM,SAAS,OAAO,IAAI,QAAQ;CAClC,MAAM,kBAAkB,QAAQ;CAGhC,OAAO,IACH,UACA;EACI,GAAG;EACH,UAAU,KAAK,KAAK,SAAS;GAEzB,MAAM,YAAY,EAAE,GAAG,IAAI;GAE3B,OAAO,UAAU;GAGjB,IAAI,MAAM,UAAU;GACpB,OAAO,UAAU;GACjB,IAAI,eAAe,sBAAsB,SAAS,eAAe,MAAM,UACnE,MAAM,IAAI,YAAY;GAG1B,IAAI,QAAQ,KAAA,GAAW;IACnB,IAAI,eAAe,mBAAmB,OAAO,UAAU,KAAK;SACvD,UAAU,MAAM;GACzB;GAGA,KAAK,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"normalize.js","names":["unsetProp","getProp","setProp"],"sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import {\n get as getProp,\n set as setProp,\n unset as unsetProp,\n} from 'es-toolkit/compat';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\nimport { objectEntries } from 'ts-extras';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to move the serialized `_id` value to `id`.\n *\n * @remarks\n * If `false`, preserves the value under `_id` instead. Only values other than `undefined` are copied.\n *\n * @defaultValue `true`.\n */\n convertIdField?: boolean;\n\n /**\n * Register normalization on child schemas too. Defaults to true.\n */\n recursive?: boolean;\n\n /**\n * Whether to convert a serialized `ObjectId` identifier to its hexadecimal string.\n *\n * @remarks\n * Applies before choosing the `id` or `_id` output key. Identifiers of other types are unchanged.\n *\n * @defaultValue `true`.\n */\n toHexIdIfObjectId?: boolean;\n}\n\n// Constants/Variables\nconst registeredSchemas = new WeakSet<Schema>();\n\n// Functions\n\n/**\n * Registers JSON normalization on a Mongoose schema.\n *\n * @remarks\n * Mutates the schema's `toJSON` configuration while preserving its other options. The transform removes `__v`,\n * normalizes `_id` according to the plugin options, removes schema paths marked `private`, and converts\n * truthy serialized values at registered `Decimal128` paths to strings.\n *\n * If an existing transform is a function, invokes it after normalization. If it returns `undefined`,\n * preserves the normalized output and any mutations made by that transform; otherwise, uses its return value.\n * That transform can change the normalized output, and its errors propagate during serialization.\n * Registers itself on child schemas unless `recursive` is false. Does not configure `toObject`.\n * Registration is idempotent per schema; the first registration's options take precedence.\n *\n * @param schema - The schema whose JSON serialization configuration is modified.\n * @param pluginOptions - The normalization and registration options; omitted options use their documented defaults.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(\n schema: S,\n pluginOptions?: MongooseNormalizePluginOptions,\n) {\n if (registeredSchemas.has(schema)) return;\n registeredSchemas.add(schema);\n\n // Collect special paths (Decimal128 & private)\n const decimalPaths: string[] = [];\n const privatePaths: string[] = [];\n for (const [path, schemaType] of objectEntries(schema.paths)) {\n if (schemaType?.options?.private) privatePaths.push(path);\n else if (schemaType?.instance === 'Decimal128') decimalPaths.push(path);\n }\n\n // Get original toJSON configuration\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n\n // Override toJSON with custom transform\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // Copy object and remove __v\n const copiedRet = { ...ret };\n // @ts-expect-error Ignore this error\n delete copiedRet.__v;\n\n // Normalize _id (convert to hex and/or move to id)\n let _id = copiedRet._id;\n delete copiedRet._id;\n if (pluginOptions?.toHexIdIfObjectId !== false && _id instanceof Types.ObjectId) {\n _id = _id.toHexString();\n }\n\n if (_id !== undefined) {\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n }\n\n // Remove private fields\n for (const path of privatePaths) unsetProp(copiedRet, path);\n\n // Convert Decimal128 fields to string\n for (const path of decimalPaths) {\n const value = getProp(copiedRet, path) as Types.Decimal128 | undefined;\n if (value) setProp(copiedRet, path, value.toString());\n }\n\n // Run original toJSON transform\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n const transformed = toJsonTransform(doc as any, copiedRet as any, options as any);\n return transformed === undefined ? copiedRet : transformed;\n }\n\n // Return normalized object\n return copiedRet;\n },\n },\n );\n\n if (pluginOptions?.recursive !== false) {\n schema.childSchemas.forEach(({ schema: child }) => child.plugin(mongooseNormalizePlugin, pluginOptions));\n }\n}\n"],"mappings":";;;;AAqCA,MAAM,oCAAoB,IAAI,QAAgB;;;;;;;;;;;;;;;;;;AAqB9C,SAAgB,wBACZ,QACA,eACF;CACE,IAAI,kBAAkB,IAAI,MAAM,GAAG;CACnC,kBAAkB,IAAI,MAAM;CAG5B,MAAM,eAAyB,CAAC;CAChC,MAAM,eAAyB,CAAC;CAChC,KAAK,MAAM,CAAC,MAAM,eAAe,cAAc,OAAO,KAAK,GACvD,IAAI,YAAY,SAAS,SAAS,aAAa,KAAK,IAAI;MACnD,IAAI,YAAY,aAAa,cAAc,aAAa,KAAK,IAAI;CAI1E,MAAM,SAAS,OAAO,IAAI,QAAQ;CAClC,MAAM,kBAAkB,QAAQ;CAGhC,OAAO,IACH,UACA;EACI,GAAG;EACH,UAAU,KAAK,KAAK,SAAS;GAEzB,MAAM,YAAY,EAAE,GAAG,IAAI;GAE3B,OAAO,UAAU;GAGjB,IAAI,MAAM,UAAU;GACpB,OAAO,UAAU;GACjB,IAAI,eAAe,sBAAsB,SAAS,eAAe,MAAM,UACnE,MAAM,IAAI,YAAY;GAG1B,IAAI,QAAQ,KAAA,GAAW;IACnB,IAAI,eAAe,mBAAmB,OAAO,UAAU,KAAK;SACvD,UAAU,MAAM;GACzB;GAGA,KAAK,MAAM,QAAQ,cAAcA,MAAU,WAAW,IAAI;GAG1D,KAAK,MAAM,QAAQ,cAAc;IAC7B,MAAM,QAAQC,IAAQ,WAAW,IAAI;IACrC,IAAI,OAAOC,IAAQ,WAAW,MAAM,MAAM,SAAS,CAAC;GACxD;GAGA,IAAI,mBAAmB,OAAO,oBAAoB,WAAW;IACzD,MAAM,cAAc,gBAAgB,KAAY,WAAkB,OAAc;IAChF,OAAO,gBAAgB,KAAA,IAAY,YAAY;GACnD;GAGA,OAAO;EACX;CACJ,CACJ;CAEA,IAAI,eAAe,cAAc,OAC7B,OAAO,aAAa,SAAS,EAAE,QAAQ,YAAY,MAAM,OAAO,yBAAyB,aAAa,CAAC;AAE/G"}
|
|
@@ -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 };
|
package/dist/types/data.d.ts
CHANGED
|
@@ -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 ? {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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.
|
package/dist/types/options.d.ts
CHANGED
|
@@ -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
|
+
"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",
|
|
@@ -29,28 +29,21 @@
|
|
|
29
29
|
"./builders": "./dist/builders.js",
|
|
30
30
|
"./connection": "./dist/connection.js",
|
|
31
31
|
"./options": "./dist/options.js",
|
|
32
|
-
"./plugins/assertions": "./dist/plugins/assertions.js",
|
|
33
|
-
"./plugins/lean-decimal128-to-string": "./dist/plugins/lean-decimal128-to-string.js",
|
|
34
|
-
"./plugins/normalize": "./dist/plugins/normalize.js",
|
|
35
32
|
"./schema-builders": "./dist/schema-builders/index.js",
|
|
36
|
-
"./
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"./
|
|
41
|
-
"./schema-builders
|
|
42
|
-
"./
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"./schema-builders/
|
|
47
|
-
"./schema-builders/
|
|
48
|
-
"./
|
|
49
|
-
"./types":
|
|
50
|
-
"./types/aggregate-paginate": "./dist/types/aggregate-paginate.js",
|
|
51
|
-
"./types/data": "./dist/types/data.js",
|
|
52
|
-
"./types/options": "./dist/types/options.js",
|
|
53
|
-
"./types/paginate": "./dist/types/paginate.js",
|
|
33
|
+
"./types": {
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"default": null
|
|
36
|
+
},
|
|
37
|
+
"./plugins/*": "./dist/plugins/*.js",
|
|
38
|
+
"./schema-builders/*": "./dist/schema-builders/*.js",
|
|
39
|
+
"./types/*": {
|
|
40
|
+
"types": "./dist/types/*.d.ts",
|
|
41
|
+
"default": null
|
|
42
|
+
},
|
|
43
|
+
"./schema-builders/_internals": null,
|
|
44
|
+
"./schema-builders/index": null,
|
|
45
|
+
"./types/_internals": null,
|
|
46
|
+
"./types/index": null,
|
|
54
47
|
"./package.json": "./package.json"
|
|
55
48
|
},
|
|
56
49
|
"files": [
|
|
@@ -77,27 +70,27 @@
|
|
|
77
70
|
"dependencies": {
|
|
78
71
|
"decimal.js": "^10.6.0",
|
|
79
72
|
"es-toolkit": "^1.53.2",
|
|
80
|
-
"mongoose": "^9.12.
|
|
73
|
+
"mongoose": "^9.12.3",
|
|
81
74
|
"mongoose-aggregate-paginate-v2": "^1.1.5",
|
|
82
75
|
"mongoose-paginate-v2": "^1.9.5",
|
|
83
|
-
"ts-extras": "^
|
|
84
|
-
"type-fest": "^
|
|
76
|
+
"ts-extras": "^3.0.0",
|
|
77
|
+
"type-fest": "^6.0.3"
|
|
85
78
|
},
|
|
86
79
|
"devDependencies": {
|
|
87
80
|
"@antfu/eslint-config": "^10.0.0",
|
|
88
81
|
"@arethetypeswrong/core": "^0.18.5",
|
|
89
|
-
"@kikiutils/eslint-config": "^11.0
|
|
82
|
+
"@kikiutils/eslint-config": "^11.2.0",
|
|
90
83
|
"@kikiutils/tsconfigs": "^7.0.0",
|
|
91
84
|
"@types/node": "^26.6.6",
|
|
92
|
-
"@vitest/coverage-v8": "^5.1.
|
|
85
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
93
86
|
"changelogen": "^0.6.2",
|
|
94
|
-
"eslint": "^10.
|
|
95
|
-
"knip": "^6.
|
|
87
|
+
"eslint": "^10.15.0",
|
|
88
|
+
"knip": "^6.47.0",
|
|
96
89
|
"mongoose-lean-getters": "^2.3.1",
|
|
97
90
|
"publint": "^0.3.25",
|
|
98
91
|
"tsdown": "^0.23.7",
|
|
99
92
|
"typescript": "^6.0.3",
|
|
100
93
|
"unplugin-unused": "^0.6.0",
|
|
101
|
-
"vitest": "^5.1.
|
|
94
|
+
"vitest": "^5.1.1"
|
|
102
95
|
}
|
|
103
96
|
}
|