@kikiutils/mongoose 4.0.0 → 4.0.1

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.
@@ -37,10 +37,12 @@ function mongooseNormalizePlugin(schema, pluginOptions) {
37
37
  if (pluginOptions?.toHexIdIfObjectId !== false) {
38
38
  _id = _id instanceof mongoose.Types.ObjectId ? _id.toHexString() : _id;
39
39
  }
40
- if (pluginOptions?.convertIdField !== false)
41
- copiedRet.id = _id;
42
- else
43
- copiedRet._id = _id;
40
+ if (_id !== undefined) {
41
+ if (pluginOptions?.convertIdField !== false)
42
+ copiedRet.id = _id;
43
+ else
44
+ copiedRet._id = _id;
45
+ }
44
46
  for (const path in schema.paths) {
45
47
  if (schema.paths[path]?.options?.private)
46
48
  lodashUnset__default(copiedRet, path);
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.cjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":["Types","lodashUnset","lodashGet","lodashSet"],"mappings":";;;;;;;;;;;;;AAAA;AA0BA;;;;;;;;;;;;;AAaG;AACG,SAAU,uBAAuB,CAAmB,MAAS,EAAE,aAA8C,EAAA;IAC/G,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;AACnC,IAAA,MAAM,eAAe,GAAG,MAAM,EAAE,SAAS;AACzC,IAAA,MAAM,CAAC,GAAG,CACN,QAAQ,EACR;AACI,QAAA,GAAG,MAAM;AACT,QAAA,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAA;;YAEvB,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,GAAG;AACpC,YAAA,IAAI,aAAa,EAAE,iBAAiB,KAAK,KAAK,EAAE;AAC5C,gBAAA,GAAG,GAAG,GAAG,YAAYA,cAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,GAAG;YACjE;AAEA,YAAA,IAAI,aAAa,EAAE,cAAc,KAAK,KAAK;AAAE,gBAAA,SAAS,CAAC,EAAE,GAAG,GAAG;;AAC1D,gBAAA,SAAS,CAAC,GAAG,GAAG,GAAG;AACxB,YAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO;AAAE,oBAAAC,oBAAW,CAAC,SAAS,EAAE,IAAI,CAAC;gBACtE,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,KAAK,YAAY,EAAE;oBAC/C,MAAM,KAAK,GAAiCC,kBAAS,CAAC,SAAS,EAAE,IAAI,CAAC;AACtE,oBAAA,IAAI,KAAK;wBAAEC,kBAAS,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAC3D;YACJ;AAEA,YAAA,IAAI,eAAe,IAAI,OAAO,eAAe,KAAK,SAAS,EAAE;gBACzD,OAAO,eAAe,CAAC,GAAU,EAAE,SAAgB,EAAE,OAAc,CAAC;YACxE;AAEA,YAAA,OAAO,SAAS;QACpB,CAAC;AACJ,KAAA,CACJ;AACL;;;;"}
1
+ {"version":3,"file":"normalize.cjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (_id !== undefined) {\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n }\n\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":["Types","lodashUnset","lodashGet","lodashSet"],"mappings":";;;;;;;;;;;;;AAAA;AA0BA;;;;;;;;;;;;;AAaG;AACG,SAAU,uBAAuB,CAAmB,MAAS,EAAE,aAA8C,EAAA;IAC/G,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;AACnC,IAAA,MAAM,eAAe,GAAG,MAAM,EAAE,SAAS;AACzC,IAAA,MAAM,CAAC,GAAG,CACN,QAAQ,EACR;AACI,QAAA,GAAG,MAAM;AACT,QAAA,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAA;;YAEv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8B;IAC3C;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,8BAA8B,QAgClH"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/plugins/normalize.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,8BAA8B;IAC3C;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,8BAA8B,QAmClH"}
@@ -29,10 +29,12 @@ function mongooseNormalizePlugin(schema, pluginOptions) {
29
29
  if (pluginOptions?.toHexIdIfObjectId !== false) {
30
30
  _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;
31
31
  }
32
- if (pluginOptions?.convertIdField !== false)
33
- copiedRet.id = _id;
34
- else
35
- copiedRet._id = _id;
32
+ if (_id !== undefined) {
33
+ if (pluginOptions?.convertIdField !== false)
34
+ copiedRet.id = _id;
35
+ else
36
+ copiedRet._id = _id;
37
+ }
36
38
  for (const path in schema.paths) {
37
39
  if (schema.paths[path]?.options?.private)
38
40
  lodashUnset(copiedRet, path);
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.mjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":[],"mappings":";;;;;AAAA;AA0BA;;;;;;;;;;;;;AAaG;AACG,SAAU,uBAAuB,CAAmB,MAAS,EAAE,aAA8C,EA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AAA,CACJ;AACL;;;;"}
1
+ {"version":3,"file":"normalize.mjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (_id !== undefined) {\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n }\n\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":[],"mappings":";;;;;AAAA;AA0BA;;;;;;;;;;;;;AAaG;AACG,SAAU,uBAAuB,CAAmB,MAAS,EAAE,aAA8C,EAAA;IAC/G,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;AACnC,IAAA,MAAM,eAAe,GAAG,MAAM,EAAE,SAAS;AACzC,IAAA,MAAM,CAAC,GAAG,CACN,QAAQ,EACR;AACI,QAAA,GAAG,MAAM;AACT,QAAA,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAA;;YAEvB,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,GAAG;AACpC,YAAA,IAAI,aAAa,EAAE,iBAAiB,KAAK,KAAK,EAAE;AAC5C,gBAAA,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,GAAG;YACjE;AAEA,YAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACnB,gBAAA,IAAI,aAAa,EAAE,cAAc,KAAK,KAAK;AAAE,oBAAA,SAAS,CAAC,EAAE,GAAG,GAAG;;AAC1D,oBAAA,SAAS,CAAC,GAAG,GAAG,GAAG;YAC5B;AAEA,YAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO;AAAE,oBAAA,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC;gBACtE,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,KAAK,YAAY,EAAE;oBAC/C,MAAM,KAAK,GAAiC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC;AACtE,oBAAA,IAAI,KAAK;wBAAE,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAC3D;YACJ;AAEA,YAAA,IAAI,eAAe,IAAI,OAAO,eAAe,KAAK,SAAS,EAAE;gBACzD,OAAO,eAAe,CAAC,GAAU,EAAE,SAAgB,EAAE,OAAc,CAAC;YACxE;AAEA,YAAA,OAAO,SAAS;QACpB,CAAC;AACJ,KAAA,CACJ;AACL;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
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",
@@ -65,17 +65,17 @@
65
65
  "dependencies": {
66
66
  "decimal.js": "^10.6.0",
67
67
  "lodash": "^4.17.21",
68
- "mongoose": "^8.17.1",
68
+ "mongoose": "^8.18.1",
69
69
  "mongoose-aggregate-paginate-v2": "^1.1.4",
70
70
  "mongoose-paginate-v2": "^1.9.1",
71
71
  "type-fest": "^4.41.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@kikiutils/changelogen": "^0.8.1",
75
- "@kikiutils/eslint-config": "^2.0.0",
74
+ "@kikiutils/changelogen": "^0.9.0",
75
+ "@kikiutils/eslint-config": "^2.1.1",
76
76
  "@kikiutils/tsconfigs": "^5.0.4",
77
77
  "@types/lodash": "^4.17.20",
78
- "@types/node": "^24.2.0",
78
+ "@types/node": "^24.3.1",
79
79
  "@vitest/coverage-v8": "^3.2.4",
80
80
  "depcheck": "^1.4.7",
81
81
  "ts-project-builder": "^5.0.2",
@@ -52,8 +52,11 @@ export function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptio
52
52
  _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;
53
53
  }
54
54
 
55
- if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;
56
- else copiedRet._id = _id;
55
+ if (_id !== undefined) {
56
+ if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;
57
+ else copiedRet._id = _id;
58
+ }
59
+
57
60
  for (const path in schema.paths) {
58
61
  if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);
59
62
  if (schema.paths[path]?.instance === 'Decimal128') {