@aomex/mongoose 3.28.3 → 3.29.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/CHANGELOG.md +8 -0
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.29.0](https://github.com/aomex/aomex/compare/v3.28.3...v3.29.0) (2025-07-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aomex/mongoose
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [3.28.3](https://github.com/aomex/aomex/compare/v3.28.2...v3.28.3) (2025-07-10)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @aomex/mongoose
|
package/dist/index.js
CHANGED
|
@@ -233,9 +233,9 @@ import { compose, middleware as middleware4 } from "@aomex/common";
|
|
|
233
233
|
import { middleware, rule, validate } from "@aomex/common";
|
|
234
234
|
import { terminal } from "@aomex/console";
|
|
235
235
|
import snakeCase from "lodash.snakecase";
|
|
236
|
-
import path from "
|
|
237
|
-
import { mkdir, writeFile } from "
|
|
238
|
-
import { createInterface } from "
|
|
236
|
+
import path from "path";
|
|
237
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
238
|
+
import { createInterface } from "readline/promises";
|
|
239
239
|
var commandName = "mongoose:migration:create";
|
|
240
240
|
var migrationCreateFile = (migrationsPath) => {
|
|
241
241
|
return middleware.console({
|
|
@@ -296,7 +296,7 @@ import { middleware as middleware2 } from "@aomex/common";
|
|
|
296
296
|
// src/libs/sync-collection-index.ts
|
|
297
297
|
import { getFileValues, pathToFiles } from "@aomex/internal-file-import";
|
|
298
298
|
import mongoose from "mongoose";
|
|
299
|
-
import { mkdir as mkdir2 } from "
|
|
299
|
+
import { mkdir as mkdir2 } from "fs/promises";
|
|
300
300
|
var syncCollectionIndex = async (modelsPath) => {
|
|
301
301
|
await mkdir2(modelsPath, { recursive: true });
|
|
302
302
|
const files = await pathToFiles(modelsPath);
|
|
@@ -323,7 +323,7 @@ var MigrationModel = defineMongooseModel("__aomex_migration", {
|
|
|
323
323
|
|
|
324
324
|
// src/middleware/migration-up.md.ts
|
|
325
325
|
import { pathToFiles as pathToFiles2 } from "@aomex/internal-file-import";
|
|
326
|
-
import path2 from "
|
|
326
|
+
import path2 from "path";
|
|
327
327
|
|
|
328
328
|
// src/libs/migrate.ts
|
|
329
329
|
import "mongoose";
|
|
@@ -340,7 +340,7 @@ var Migrate = class {
|
|
|
340
340
|
// src/middleware/migration-up.md.ts
|
|
341
341
|
import mongoose3, { createConnection } from "mongoose";
|
|
342
342
|
import { terminal as terminal2 } from "@aomex/console";
|
|
343
|
-
import { mkdir as mkdir3 } from "
|
|
343
|
+
import { mkdir as mkdir3 } from "fs/promises";
|
|
344
344
|
var commandName2 = "mongoose:migration:up";
|
|
345
345
|
var migrationUp = (opts) => {
|
|
346
346
|
return middleware2.console({
|
|
@@ -399,8 +399,8 @@ import { middleware as middleware3, rule as rule3, validate as validate2 } from
|
|
|
399
399
|
import mongoose4, { createConnection as createConnection2 } from "mongoose";
|
|
400
400
|
import { terminal as terminal3 } from "@aomex/console";
|
|
401
401
|
import { pathToFiles as pathToFiles3 } from "@aomex/internal-file-import";
|
|
402
|
-
import { mkdir as mkdir4 } from "
|
|
403
|
-
import path3 from "
|
|
402
|
+
import { mkdir as mkdir4 } from "fs/promises";
|
|
403
|
+
import path3 from "path";
|
|
404
404
|
var commandName3 = "mongoose:migration:down";
|
|
405
405
|
var migrationDown = (opts) => {
|
|
406
406
|
return middleware3.console({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/validators/mongo-decimal128.validator.ts","../src/i18n/index.ts","../src/i18n/locales/zh-cn.ts","../src/i18n/locales/en-us.ts","../src/i18n/locales/index.ts","../src/validators/mongo-object-id.validator.ts","../src/define-mongoose-model.ts","../src/libs/validator-to-schema.ts","../src/middleware/mongoose-migration.md.ts","../src/middleware/migration-create-file.md.ts","../src/middleware/migration-up.md.ts","../src/libs/sync-collection-index.ts","../src/models/migration.model.ts","../src/libs/migrate.ts","../src/middleware/migration-down.md.ts","../src/libs/format-mongo-result.ts"],"sourcesContent":["import {\n Validator,\n type TransformedValidator,\n ValidateResult,\n OpenAPI,\n Rule,\n} from '@aomex/common';\nimport { i18n } from '../i18n';\nimport { mongo } from 'mongoose';\n\nexport class MongoDecimal128Validator<T = mongo.Decimal128> extends Validator<T> {\n protected declare config: Validator.Options<T>;\n\n public declare docs: (\n docs: Validator.PartialOpenAPISchema,\n mode?: Validator.DocumentMergeMode,\n ) => this;\n public declare optional: () => MongoDecimal128Validator<T | Validator.TOptional>;\n public declare nullable: () => MongoDecimal128Validator<T | null>;\n public declare transform: <T1>(\n fn: Validator.TransformFn<T, T1>,\n ) => TransformedValidator<T1>;\n\n override default(\n value: number | string | mongo.Decimal128,\n ): MongoDecimal128Validator<T | Validator.TDefault> {\n const validator = super.default(\n typeof value === 'string' || typeof value === 'number'\n ? mongo.Decimal128.fromString(value.toString())\n : value,\n );\n return validator as MongoDecimal128Validator<T | Validator.TDefault>;\n }\n\n protected validateValue(\n value: any,\n _key: string,\n label: string,\n ): ValidateResult.Any<mongo.Decimal128> {\n if (value instanceof mongo.Decimal128) {\n return ValidateResult.accept(value);\n }\n\n try {\n return ValidateResult.accept(mongo.Decimal128.fromString(value));\n } catch {\n return ValidateResult.deny(\n i18n.t('validator.decimal128.must_be_decimal128', { label }),\n );\n }\n }\n\n protected declare copy: () => MongoDecimal128Validator<T>;\n\n protected override toDocument(): OpenAPI.SchemaObject {\n const defaultValue: mongo.Decimal128 | undefined = this.getDefaultValue(\n this.config.defaultValue,\n );\n return {\n type: 'string',\n default: defaultValue && defaultValue.toString(),\n };\n }\n}\n\ndeclare module '@aomex/common' {\n export interface Rule {\n mongoDecimal128(): MongoDecimal128Validator;\n }\n}\n\nRule.register('mongoDecimal128', MongoDecimal128Validator);\n","import { I18n } from '@aomex/common';\nimport { locales } from './locales';\n\nexport const i18n = new I18n({\n resources: locales,\n defaultLanguage: 'zh_CN',\n});\n","import { I18n } from '@aomex/common';\n\nexport const zh = I18n.define({\n validator: {\n decimal128: {\n must_be_decimal128: '{{label}}必须是 Decimal128 类型',\n },\n objectId: {\n must_be_objectId: '{{label}}必须是 ObjectId 类型',\n },\n },\n mongoose: {\n unsupported_validator: '暂不支持 {{validator}} 验证器',\n },\n migration: {\n create: '创建迁移文件',\n up: '执行迁移逻辑',\n down: '回滚迁移逻辑',\n file_not_found: \"迁移文件 '{{file}}' 不存在\",\n input_file_name: '迁移文件名是什么?> ',\n file_created: '迁移文件创建成功 \"{{file}}\"',\n },\n});\n","import { I18n } from '@aomex/common';\nimport { zh } from './zh-cn';\n\nexport const en = I18n.satisfies(zh).define({\n validator: {\n decimal128: {\n must_be_decimal128: '{{label}} must be Decimal128',\n },\n objectId: {\n must_be_objectId: '{{label}} must be ObjectId',\n },\n },\n mongoose: {\n unsupported_validator: '{{validator}} is not supported yet',\n },\n migration: {\n create: 'Generate migration file',\n up: 'Execute migration logic',\n down: 'Rollback migration logic',\n file_not_found: \"Migration file '{{file}}' not found\",\n input_file_name: 'What is migration file name? > ',\n file_created: 'Migration file has been created at \"{{file}}\"',\n },\n});\n","import { zh } from './zh-cn';\nimport { en } from './en-us';\n\nexport const locales = {\n zh_CN: zh,\n en_US: en,\n};\n","import {\n Validator,\n type TransformedValidator,\n ValidateResult,\n OpenAPI,\n Rule,\n} from '@aomex/common';\nimport { i18n } from '../i18n';\nimport { mongo } from 'mongoose';\n\nexport class MongoObjectIdValidator<T = mongo.ObjectId> extends Validator<T> {\n protected declare config: Validator.Options<T>;\n\n public declare docs: (\n docs: Validator.PartialOpenAPISchema,\n mode?: Validator.DocumentMergeMode,\n ) => this;\n public declare optional: () => MongoObjectIdValidator<T | Validator.TOptional>;\n public declare nullable: () => MongoObjectIdValidator<T | null>;\n public declare transform: <T1>(\n fn: Validator.TransformFn<T, T1>,\n ) => TransformedValidator<T1>;\n\n override default(\n value: string | mongo.ObjectId,\n ): MongoObjectIdValidator<T | Validator.TDefault> {\n const validator = super.default(\n typeof value === 'string'\n ? mongo.ObjectId.createFromHexString(value.toString())\n : value,\n );\n return validator as MongoObjectIdValidator<T | Validator.TDefault>;\n }\n\n protected validateValue(\n value: any,\n _key: string,\n label: string,\n ): ValidateResult.Any<mongo.ObjectId> {\n if (value instanceof mongo.ObjectId) {\n return ValidateResult.accept(value);\n }\n\n try {\n return ValidateResult.accept(mongo.ObjectId.createFromHexString(String(value)));\n } catch {\n return ValidateResult.deny(\n i18n.t('validator.objectId.must_be_objectId', { label }),\n );\n }\n }\n\n protected declare copy: () => MongoObjectIdValidator<T>;\n\n protected override toDocument(): OpenAPI.SchemaObject {\n const defaultValue: mongo.ObjectId | undefined = this.getDefaultValue(\n this.config.defaultValue,\n );\n return {\n type: 'string',\n default: defaultValue && defaultValue.toHexString(),\n };\n }\n}\n\ndeclare module '@aomex/common' {\n export interface Rule {\n mongoObjectId(): MongoObjectIdValidator;\n }\n}\n\nRule.register('mongoObjectId', MongoObjectIdValidator);\n","import type {\n AnyValidator,\n ArrayValidator,\n BooleanValidator,\n DateValidator,\n NumberValidator,\n ObjectValidator,\n StringValidator,\n Validator,\n} from '@aomex/common';\nimport type { NonReadonly } from '@aomex/internal-tools';\nimport {\n Model,\n type IndexDirection,\n type IndexOptions,\n type SchemaOptions,\n type SchemaDefinition,\n Schema,\n model,\n type HydratedDocument,\n} from 'mongoose';\nimport type { TimestampSetting, VersionKeySetting } from './type-d';\nimport { validatorToSchema } from './libs/validator-to-schema';\nimport type { MongoDecimal128Validator, MongoObjectIdValidator } from './validators';\n\nexport const defineMongooseModel = <\n const Schema extends {\n [field: string]:\n | StringValidator<any>\n | NumberValidator<any>\n | BooleanValidator<any>\n | ObjectValidator<any>\n | ArrayValidator<any>\n | DateValidator<any>\n | AnyValidator<any>\n | MongoDecimal128Validator<any>\n | MongoObjectIdValidator<any>;\n },\n Ver extends SchemaOptions['versionKey'],\n const Time extends SchemaOptions['timestamps'],\n Output = NonReadonly<Validator.Infer<Schema>> &\n TimestampSetting<Time> &\n VersionKeySetting<Ver>,\n>(\n collectionName: string,\n opts: {\n readonly schemas: Schema;\n readonly indexes?: ({\n fields: { [K in keyof Schema]?: IndexDirection };\n } & IndexOptions)[];\n readonly timestamps?: Time;\n readonly versionKey?: Ver;\n } & Omit<SchemaOptions, 'timestamps' | 'versionKey'>,\n): Model<Output, {}, {}, {}, HydratedDocument<Output>, Schema> => {\n const { schemas, indexes, ...schemaOptions } = opts;\n\n const definition: SchemaDefinition = {};\n Object.entries(schemas).forEach(([key, schema]) => {\n definition[key] = validatorToSchema(schema);\n });\n const schema = new Schema(definition, {\n collection: collectionName,\n ...schemaOptions,\n });\n\n indexes?.forEach(({ fields, ...indexRest }) => {\n schema.index(\n // @ts-expect-error\n fields,\n indexRest,\n );\n });\n\n const customModel = model(collectionName, schema);\n return customModel as Model<any>;\n};\n","import {\n AnyValidator,\n ArrayValidator,\n BooleanValidator,\n DateValidator,\n NumberValidator,\n ObjectValidator,\n StringValidator,\n Validator,\n} from '@aomex/common';\nimport { Schema, SchemaTypes, type SchemaDefinition } from 'mongoose';\nimport { i18n } from '../i18n';\nimport { MongoDecimal128Validator, MongoObjectIdValidator } from '../validators';\n\nexport const validatorToSchema = (validator: Validator) => {\n const defaultValue = validator['config']['nullable']\n ? null\n : validator['config']['defaultValue'];\n const schema: SchemaDefinition[string] = {\n required: defaultValue === undefined && validator['config']['required'],\n default: defaultValue,\n };\n\n if (validator instanceof StringValidator) {\n schema.type = SchemaTypes.String;\n } else if (validator instanceof NumberValidator) {\n schema.type = SchemaTypes.Number;\n } else if (validator instanceof BooleanValidator) {\n schema.type = SchemaTypes.Boolean;\n } else if (validator instanceof MongoDecimal128Validator) {\n schema.type = SchemaTypes.Decimal128;\n } else if (validator instanceof ArrayValidator) {\n const items = validator['config']['itemValidator'];\n if (items) {\n schema.type = [validatorToSchema(items)];\n } else {\n schema.type = SchemaTypes.Array;\n }\n } else if (validator instanceof ObjectValidator) {\n schema.type = SchemaTypes.Map;\n const properties = validator['config']['properties'];\n if (properties) {\n schema.type = new Schema(\n Object.fromEntries(\n Object.entries(properties).map(\n ([key, value]) => <const>[key, validatorToSchema(value)],\n ),\n ),\n { _id: false, timestamps: false, versionKey: false },\n );\n }\n } else if (validator instanceof DateValidator) {\n schema.type = SchemaTypes.Date;\n } else if (validator instanceof MongoObjectIdValidator) {\n schema.type = SchemaTypes.ObjectId;\n } else if (validator instanceof AnyValidator) {\n schema.type = SchemaTypes.Mixed;\n } else {\n throw new Error(\n i18n.t('mongoose.unsupported_validator', { validator: validator.constructor.name }),\n );\n }\n\n return schema;\n};\n","import { compose, middleware } from '@aomex/common';\nimport type { ConsoleMiddleware } from '@aomex/console';\nimport { migrationCreateFile } from './migration-create-file.md';\nimport { migrationUp } from './migration-up.md';\nimport { migrationDown } from './migration-down.md';\nimport type { Connection, ConnectOptions } from 'mongoose';\n\nexport interface MigrationOptions {\n /**\n * 模型存放位置,用于执行`mongoose.syncIndexes()`同步索引。默认值:`src/models`\n */\n modelsPath?: string;\n /**\n * 迁移文件存放位置。默认值:`src/migrations`\n */\n migrationsPath?: string;\n /**\n * 连接参数。如果已经连接并且拥有读写权限,则可以传入`mongoose.connection`\n */\n connection:\n | Connection\n | {\n uri: string;\n options?: ConnectOptions;\n };\n}\n\nexport const mongooseMigration = (opts: MigrationOptions): ConsoleMiddleware => {\n const {\n migrationsPath = 'src/migrations',\n modelsPath = 'src/models',\n connection,\n } = opts;\n const middlewareList = [\n migrationCreateFile(migrationsPath),\n migrationUp({ migrationsPath, connection, modelsPath }),\n migrationDown({ migrationsPath, connection, modelsPath }),\n ];\n\n return middleware.console({\n fn: compose(middlewareList),\n help: {\n async onDocument(_, { children }) {\n await children(middlewareList);\n },\n async postDocument(_, { children }) {\n await children(middlewareList);\n },\n },\n });\n};\n","import { middleware, rule, validate } from '@aomex/common';\nimport { terminal, type ConsoleMiddleware } from '@aomex/console';\nimport snakeCase from 'lodash.snakecase';\nimport { i18n } from '../i18n';\nimport path from 'node:path';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { createInterface } from 'node:readline/promises';\n\nconst commandName = 'mongoose:migration:create';\n\nexport const migrationCreateFile = (migrationsPath: string): ConsoleMiddleware => {\n return middleware.console({\n fn: async (ctx, next) => {\n if (ctx.input.command !== commandName) return next();\n ctx.commandMatched = true;\n\n let { name } = await validate(ctx.input.parseArgv(), {\n name: rule.string().optional().trim().transform(snakeCase),\n });\n\n if (!name) {\n const readline = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n while (!name) {\n name = await readline.question(i18n.t('migration.input_file_name'));\n name = snakeCase(name.trim());\n }\n readline.close();\n }\n\n const filename = `${new Date().toISOString().replaceAll(/[-TZ.:]/gi, '')}_${name}.ts`;\n const fullPath = path.join(migrationsPath, filename);\n await mkdir(path.dirname(fullPath), { recursive: true });\n await writeFile(\n fullPath,\n `import { migrate } from '@aomex/mongoose';\n\nexport default migrate({\n up: async (db, session) => {\n // up transaction\n },\n down: async (db, session) => {\n // down transaction\n },\n});\n`,\n );\n terminal.printSuccess(\n i18n.t('migration.file_created', {\n file: path.relative(process.cwd(), fullPath),\n }),\n );\n },\n help: {\n onDocument(doc) {\n doc[commandName] = {\n summary: i18n.t('migration.create'),\n parameters: [{ type: 'string', name: 'name' }],\n };\n },\n },\n });\n};\n","import { middleware } from '@aomex/common';\nimport type { MigrationOptions } from './mongoose-migration.md';\nimport { i18n } from '../i18n';\nimport { syncCollectionIndex } from '../libs/sync-collection-index';\nimport { MigrationModel } from '../models/migration.model';\nimport { pathToFiles } from '@aomex/internal-file-import';\nimport path from 'node:path';\nimport { Migrate } from '../libs/migrate';\nimport mongoose, { createConnection } from 'mongoose';\nimport { terminal } from '@aomex/console';\nimport { mkdir } from 'node:fs/promises';\n\nconst commandName = 'mongoose:migration:up';\n\nexport const migrationUp = (opts: Required<MigrationOptions>) => {\n return middleware.console({\n fn: async (ctx, next) => {\n if (ctx.input.command !== commandName) return next();\n ctx.commandMatched = true;\n\n const connection =\n opts.connection instanceof mongoose.Connection\n ? opts.connection\n : await createConnection(\n opts.connection.uri,\n opts.connection.options,\n ).asPromise();\n const db = connection.db!;\n\n await syncCollectionIndex(opts.modelsPath);\n\n const migratedRows = await MigrationModel.find().sort({ filename: 'asc' }).lean();\n const migratedFiles = migratedRows.map((item) => item.filename);\n await mkdir(opts.migrationsPath, { recursive: true });\n const allFiles = await pathToFiles(opts.migrationsPath);\n const waitingMigrateFiles = allFiles\n .filter(\n (item) => !migratedFiles.includes(path.basename(item, path.extname(item))),\n )\n .sort();\n\n for (const filePath of waitingMigrateFiles) {\n const instance = await import(filePath);\n const migrate = instance.default;\n if (migrate instanceof Migrate) {\n const filename = path.basename(filePath, path.extname(filePath));\n try {\n await connection.transaction(async (session) => {\n await MigrationModel.create([{ filename }], { session });\n await migrate.up(db, session);\n await MigrationModel.updateOne(\n { filename },\n { finished_at: new Date() },\n { session },\n );\n });\n terminal.printSuccess(`[up] ${filename}`);\n } catch (e) {\n terminal.printError(`[up] ${filename}`);\n throw e;\n }\n }\n }\n\n if (!(opts.connection instanceof mongoose.Connection)) {\n await connection.close();\n }\n },\n help: {\n onDocument(doc) {\n doc[commandName] = { summary: i18n.t('migration.up') };\n },\n },\n });\n};\n","import { getFileValues, pathToFiles } from '@aomex/internal-file-import';\nimport mongoose from 'mongoose';\nimport { mkdir } from 'node:fs/promises';\n\nexport const syncCollectionIndex = async (modelsPath: string) => {\n await mkdir(modelsPath, { recursive: true });\n const files = await pathToFiles(modelsPath);\n await getFileValues(files);\n await mongoose.syncIndexes();\n};\n","import { rule } from '@aomex/common';\nimport { defineMongooseModel } from '../define-mongoose-model';\n\nexport const MigrationModel = defineMongooseModel('__aomex_migration', {\n schemas: {\n filename: rule.string(),\n finished_at: rule.date().nullable(),\n },\n versionKey: false,\n timestamps: { createdAt: 'created_at', updatedAt: false },\n indexes: [\n {\n fields: { filename: 'asc' },\n unique: true,\n },\n ],\n});\n","import mongoose from 'mongoose';\n\ninterface Operation {\n (db: mongoose.mongo.Db, session: mongoose.mongo.ClientSession): Promise<any>;\n}\n\n/**\n * 迁移数据,因为开启了事务,所以任何操作都需要带上session,这样能保证出错时顺利回滚数据。\n *\n * 注意:集合和索引会根据models自动同步,无须写迁移逻辑。\n */\nexport const migrate = (opts: { up: Operation; down: Operation }) => {\n return new Migrate(opts.up, opts.down);\n};\n\nexport class Migrate {\n constructor(\n public readonly up: Operation,\n public readonly down: Operation,\n ) {}\n}\n","import { middleware, rule, validate } from '@aomex/common';\nimport type { MigrationOptions } from './mongoose-migration.md';\nimport { i18n } from '../i18n';\nimport { syncCollectionIndex } from '../libs/sync-collection-index';\nimport { MigrationModel } from '../models/migration.model';\nimport { Migrate } from '../libs/migrate';\nimport mongoose, { createConnection } from 'mongoose';\nimport { terminal } from '@aomex/console';\nimport { pathToFiles } from '@aomex/internal-file-import';\nimport { mkdir } from 'node:fs/promises';\nimport path from 'node:path';\n\nconst commandName = 'mongoose:migration:down';\n\nexport const migrationDown = (opts: Required<MigrationOptions>) => {\n return middleware.console({\n fn: async (ctx, next) => {\n if (ctx.input.command !== commandName) return next();\n ctx.commandMatched = true;\n\n const { all } = await validate(ctx.input.parseArgv(), {\n all: rule.boolean().default(false),\n });\n\n const connection =\n opts.connection instanceof mongoose.Connection\n ? opts.connection\n : await createConnection(\n opts.connection.uri,\n opts.connection.options,\n ).asPromise();\n const db = connection.db!;\n\n await syncCollectionIndex(opts.modelsPath);\n\n const rows = await MigrationModel.find().sort({ filename: 'desc' }).lean();\n if (!rows.length) return;\n\n const migratedFiles = rows.map((item) => item.filename);\n await mkdir(opts.migrationsPath, { recursive: true });\n const allFiles = await pathToFiles(opts.migrationsPath);\n const executeCount = all ? migratedFiles.length : 1;\n\n for (let i = 0; i < executeCount; ++i) {\n const filename = migratedFiles[i]!;\n const fullPath = allFiles.find((item) =>\n item.endsWith(filename + path.extname(item)),\n );\n if (!fullPath) {\n throw new Error(i18n.t('migration.file_not_found', { file: filename }));\n }\n const instance = await import(fullPath);\n const migrate = instance.default;\n if (migrate instanceof Migrate) {\n try {\n await connection.transaction(async (session) => {\n await MigrationModel.deleteOne({ filename }, { session });\n await migrate.down(db, session);\n });\n terminal.printSuccess(`[down] ${filename}`);\n } catch (e) {\n terminal.printError(`[down] ${filename}`);\n throw e;\n }\n }\n }\n\n if (!(opts.connection instanceof mongoose.Connection)) {\n await connection.close();\n }\n },\n help: {\n onDocument(doc) {\n doc[commandName] = {\n summary: i18n.t('migration.down'),\n parameters: [{ type: 'boolean', name: 'all', defaultValue: false }],\n };\n },\n },\n });\n};\n","import {\n Document,\n mongo,\n type Default__v,\n type FlattenMaps,\n type Require_id,\n} from 'mongoose';\n\nexport type MongoResult<T, Remove extends boolean> = {\n [K in keyof T as K extends '__v'\n ? never\n : Remove extends true\n ? K extends (typeof excludedFields)[number]\n ? never\n : K\n : K extends '_id'\n ? 'id'\n : K]: T[K] extends mongo.Decimal128 | mongo.ObjectId ? string : T[K];\n};\n\nconst excludedFields = <const>[\n 'created_at',\n 'createdAt',\n 'updated_at',\n 'updatedAt',\n '_id',\n];\n\nexport function formatMongoResult<T extends Document, Remove extends boolean>(\n data: T[],\n removeColumns?: Remove,\n): MongoResult<\n T extends Document<any, any, infer R> ? FlattenMaps<Default__v<Require_id<R>>> : never,\n Remove\n>[];\nexport function formatMongoResult<T extends Record<string, any>, Remove extends boolean>(\n data: T[],\n removeColumns?: Remove,\n): MongoResult<T, Remove>[];\nexport function formatMongoResult<T extends Document | null, Remove extends boolean>(\n data: T,\n removeColumns?: Remove,\n): T extends Document\n ? MongoResult<\n T extends Document<any, any, infer R>\n ? FlattenMaps<Default__v<Require_id<R>>>\n : never,\n Remove\n >\n : null;\nexport function formatMongoResult<\n T extends Record<string, any> | null,\n Remove extends boolean,\n>(\n data: T,\n removeColumns?: Remove,\n): T extends Record<string, any> ? MongoResult<T, Remove> : null;\n/**\n * 格式化mongo查询结果,支持传入 纯JSON 和 Document 两种对象格式,返回结果遵循如下规则:\n * - 去掉 __v 字段\n * - decimal128类型 转为 字符串\n * - objectId类型 转为 字符串\n * - removeColumns=true时,去掉 _id 字段\n * - removeColumns=false时,_id 字段转为 id\n * - removeColumns=true时,去掉 createdAt/created_at 字段\n * - removeColumns=true时,去掉 updatedAt/updated_at 字段\n *\n * @param {Boolean} removeColumns 是否去掉数据库扩展的字段\n */\nexport function formatMongoResult(\n data: Record<string, any> | Record<string, any>[] | Document | Document[] | null,\n removeColumns: boolean = false,\n) {\n if (data == null) return null;\n\n const newDate = (Array.isArray(data) ? data : [data]).map((item) => {\n if (item instanceof Document) {\n item = item.toJSON({ flattenMaps: true });\n }\n\n const newItem: Record<string, any> = {};\n for (let [key, value] of Object.entries(item)) {\n if (key === '__v') continue;\n if (removeColumns && excludedFields.includes(key as any)) continue;\n if (key === '_id') key = 'id';\n\n if (value instanceof mongo.Decimal128) {\n newItem[key] = value.toString();\n } else if (value instanceof mongo.ObjectId) {\n newItem[key] = value.toHexString();\n } else {\n newItem[key] = value;\n }\n }\n return newItem;\n });\n return Array.isArray(data) ? newDate : newDate[0];\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;;;ACNP,SAAS,QAAAA,aAAY;;;ACArB,SAAS,YAAY;AAEd,IAAM,KAAK,KAAK,OAAO;AAAA,EAC5B,WAAW;AAAA,IACT,YAAY;AAAA,MACV,oBAAoB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,MACR,kBAAkB;AAAA,IACpB;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,uBAAuB;AAAA,EACzB;AAAA,EACA,WAAW;AAAA,IACT,QAAQ;AAAA,IACR,IA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AACA,MAAI,QAAQ,KAAM,QAAO;AAEzB,QAAM,WAAW,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS;AAClE,QAAI,gBAAgB,UAAU;AAC5B,aAAO,KAAK,OAAO,EAAE,aAAa,KAAK,CAAC;AAAA,IAC1C;AAEA,UAAM,UAA+B,CAAC;AACtC,aAAS,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAC7C,UAAI,QAAQ,MAAO;AACnB,UAAI,iBAAiB,eAAe,SAAS,GAAU,EAAG;AAC1D,UAAI,QAAQ,MAAO,OAAM;AAEzB,UAAI,iBAAiBA,OAAM,YAAY;AACrC,gBAAQ,GAAG,IAAI,MAAM,SAAS;AAAA,MAChC,WAAW,iBAAiBA,OAAM,UAAU;AAC1C,gBAAQ,GAAG,IAAI,MAAM,YAAY;AAAA,MACnC,OAAO;AACL,gBAAQ,GAAG,IAAI;AAAA,MACjB;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACD,SAAO,MAAM,QAAQ,IAAI,IAAI,UAAU,QAAQ,CAAC;AAClD;","names":["I18n","I18n","I18n","I18n","Validator","ValidateResult","Rule","mongo","Validator","ValidateResult","Rule","Schema","schema","Schema","middleware","middleware","mkdir","rule","rule","pathToFiles","path","mongoose","terminal","mkdir","commandName","middleware","pathToFiles","path","migrate","middleware","rule","validate","mongoose","createConnection","terminal","pathToFiles","mkdir","path","commandName","middleware","validate","rule","migrate","middleware","mongo"]}
|
|
1
|
+
{"version":3,"sources":["../src/validators/mongo-decimal128.validator.ts","../src/i18n/index.ts","../src/i18n/locales/zh-cn.ts","../src/i18n/locales/en-us.ts","../src/i18n/locales/index.ts","../src/validators/mongo-object-id.validator.ts","../src/define-mongoose-model.ts","../src/libs/validator-to-schema.ts","../src/middleware/mongoose-migration.md.ts","../src/middleware/migration-create-file.md.ts","../src/middleware/migration-up.md.ts","../src/libs/sync-collection-index.ts","../src/models/migration.model.ts","../src/libs/migrate.ts","../src/middleware/migration-down.md.ts","../src/libs/format-mongo-result.ts"],"sourcesContent":["import {\n Validator,\n type TransformedValidator,\n ValidateResult,\n OpenAPI,\n Rule,\n} from '@aomex/common';\nimport { i18n } from '../i18n';\nimport { mongo } from 'mongoose';\n\nexport class MongoDecimal128Validator<T = mongo.Decimal128> extends Validator<T> {\n declare protected config: Validator.Options<T>;\n\n declare public docs: (\n docs: Validator.PartialOpenAPISchema,\n mode?: Validator.DocumentMergeMode,\n ) => this;\n declare public optional: () => MongoDecimal128Validator<T | Validator.TOptional>;\n declare public nullable: () => MongoDecimal128Validator<T | null>;\n declare public transform: <T1>(\n fn: Validator.TransformFn<T, T1>,\n ) => TransformedValidator<T1>;\n\n override default(\n value: number | string | mongo.Decimal128,\n ): MongoDecimal128Validator<T | Validator.TDefault> {\n const validator = super.default(\n typeof value === 'string' || typeof value === 'number'\n ? mongo.Decimal128.fromString(value.toString())\n : value,\n );\n return validator as MongoDecimal128Validator<T | Validator.TDefault>;\n }\n\n protected validateValue(\n value: any,\n _key: string,\n label: string,\n ): ValidateResult.Any<mongo.Decimal128> {\n if (value instanceof mongo.Decimal128) {\n return ValidateResult.accept(value);\n }\n\n try {\n return ValidateResult.accept(mongo.Decimal128.fromString(value));\n } catch {\n return ValidateResult.deny(\n i18n.t('validator.decimal128.must_be_decimal128', { label }),\n );\n }\n }\n\n declare protected copy: () => MongoDecimal128Validator<T>;\n\n protected override toDocument(): OpenAPI.SchemaObject {\n const defaultValue: mongo.Decimal128 | undefined = this.getDefaultValue(\n this.config.defaultValue,\n );\n return {\n type: 'string',\n default: defaultValue && defaultValue.toString(),\n };\n }\n}\n\ndeclare module '@aomex/common' {\n export interface Rule {\n mongoDecimal128(): MongoDecimal128Validator;\n }\n}\n\nRule.register('mongoDecimal128', MongoDecimal128Validator);\n","import { I18n } from '@aomex/common';\nimport { locales } from './locales';\n\nexport const i18n = new I18n({\n resources: locales,\n defaultLanguage: 'zh_CN',\n});\n","import { I18n } from '@aomex/common';\n\nexport const zh = I18n.define({\n validator: {\n decimal128: {\n must_be_decimal128: '{{label}}必须是 Decimal128 类型',\n },\n objectId: {\n must_be_objectId: '{{label}}必须是 ObjectId 类型',\n },\n },\n mongoose: {\n unsupported_validator: '暂不支持 {{validator}} 验证器',\n },\n migration: {\n create: '创建迁移文件',\n up: '执行迁移逻辑',\n down: '回滚迁移逻辑',\n file_not_found: \"迁移文件 '{{file}}' 不存在\",\n input_file_name: '迁移文件名是什么?> ',\n file_created: '迁移文件创建成功 \"{{file}}\"',\n },\n});\n","import { I18n } from '@aomex/common';\nimport { zh } from './zh-cn';\n\nexport const en = I18n.satisfies(zh).define({\n validator: {\n decimal128: {\n must_be_decimal128: '{{label}} must be Decimal128',\n },\n objectId: {\n must_be_objectId: '{{label}} must be ObjectId',\n },\n },\n mongoose: {\n unsupported_validator: '{{validator}} is not supported yet',\n },\n migration: {\n create: 'Generate migration file',\n up: 'Execute migration logic',\n down: 'Rollback migration logic',\n file_not_found: \"Migration file '{{file}}' not found\",\n input_file_name: 'What is migration file name? > ',\n file_created: 'Migration file has been created at \"{{file}}\"',\n },\n});\n","import { zh } from './zh-cn';\nimport { en } from './en-us';\n\nexport const locales = {\n zh_CN: zh,\n en_US: en,\n};\n","import {\n Validator,\n type TransformedValidator,\n ValidateResult,\n OpenAPI,\n Rule,\n} from '@aomex/common';\nimport { i18n } from '../i18n';\nimport { mongo } from 'mongoose';\n\nexport class MongoObjectIdValidator<T = mongo.ObjectId> extends Validator<T> {\n declare protected config: Validator.Options<T>;\n\n declare public docs: (\n docs: Validator.PartialOpenAPISchema,\n mode?: Validator.DocumentMergeMode,\n ) => this;\n declare public optional: () => MongoObjectIdValidator<T | Validator.TOptional>;\n declare public nullable: () => MongoObjectIdValidator<T | null>;\n declare public transform: <T1>(\n fn: Validator.TransformFn<T, T1>,\n ) => TransformedValidator<T1>;\n\n override default(\n value: string | mongo.ObjectId,\n ): MongoObjectIdValidator<T | Validator.TDefault> {\n const validator = super.default(\n typeof value === 'string'\n ? mongo.ObjectId.createFromHexString(value.toString())\n : value,\n );\n return validator as MongoObjectIdValidator<T | Validator.TDefault>;\n }\n\n protected validateValue(\n value: any,\n _key: string,\n label: string,\n ): ValidateResult.Any<mongo.ObjectId> {\n if (value instanceof mongo.ObjectId) {\n return ValidateResult.accept(value);\n }\n\n try {\n return ValidateResult.accept(mongo.ObjectId.createFromHexString(String(value)));\n } catch {\n return ValidateResult.deny(\n i18n.t('validator.objectId.must_be_objectId', { label }),\n );\n }\n }\n\n declare protected copy: () => MongoObjectIdValidator<T>;\n\n protected override toDocument(): OpenAPI.SchemaObject {\n const defaultValue: mongo.ObjectId | undefined = this.getDefaultValue(\n this.config.defaultValue,\n );\n return {\n type: 'string',\n default: defaultValue && defaultValue.toHexString(),\n };\n }\n}\n\ndeclare module '@aomex/common' {\n export interface Rule {\n mongoObjectId(): MongoObjectIdValidator;\n }\n}\n\nRule.register('mongoObjectId', MongoObjectIdValidator);\n","import type {\n AnyValidator,\n ArrayValidator,\n BooleanValidator,\n DateValidator,\n NumberValidator,\n ObjectValidator,\n StringValidator,\n Validator,\n} from '@aomex/common';\nimport type { NonReadonly } from '@aomex/internal-tools';\nimport {\n Model,\n type IndexDirection,\n type IndexOptions,\n type SchemaOptions,\n type SchemaDefinition,\n Schema,\n model,\n type HydratedDocument,\n} from 'mongoose';\nimport type { TimestampSetting, VersionKeySetting } from './type-d';\nimport { validatorToSchema } from './libs/validator-to-schema';\nimport type { MongoDecimal128Validator, MongoObjectIdValidator } from './validators';\n\nexport const defineMongooseModel = <\n const Schema extends {\n [field: string]:\n | StringValidator<any>\n | NumberValidator<any>\n | BooleanValidator<any>\n | ObjectValidator<any>\n | ArrayValidator<any>\n | DateValidator<any>\n | AnyValidator<any>\n | MongoDecimal128Validator<any>\n | MongoObjectIdValidator<any>;\n },\n Ver extends SchemaOptions['versionKey'],\n const Time extends SchemaOptions['timestamps'],\n Output = NonReadonly<Validator.Infer<Schema>> &\n TimestampSetting<Time> &\n VersionKeySetting<Ver>,\n>(\n collectionName: string,\n opts: {\n readonly schemas: Schema;\n readonly indexes?: ({\n fields: { [K in keyof Schema]?: IndexDirection };\n } & IndexOptions)[];\n readonly timestamps?: Time;\n readonly versionKey?: Ver;\n } & Omit<SchemaOptions, 'timestamps' | 'versionKey'>,\n): Model<Output, {}, {}, {}, HydratedDocument<Output>, Schema> => {\n const { schemas, indexes, ...schemaOptions } = opts;\n\n const definition: SchemaDefinition = {};\n Object.entries(schemas).forEach(([key, schema]) => {\n definition[key] = validatorToSchema(schema);\n });\n const schema = new Schema(definition, {\n collection: collectionName,\n ...schemaOptions,\n });\n\n indexes?.forEach(({ fields, ...indexRest }) => {\n schema.index(\n // @ts-expect-error\n fields,\n indexRest,\n );\n });\n\n const customModel = model(collectionName, schema);\n return customModel as Model<any>;\n};\n","import {\n AnyValidator,\n ArrayValidator,\n BooleanValidator,\n DateValidator,\n NumberValidator,\n ObjectValidator,\n StringValidator,\n Validator,\n} from '@aomex/common';\nimport { Schema, SchemaTypes, type SchemaDefinition } from 'mongoose';\nimport { i18n } from '../i18n';\nimport { MongoDecimal128Validator, MongoObjectIdValidator } from '../validators';\n\nexport const validatorToSchema = (validator: Validator) => {\n const defaultValue = validator['config']['nullable']\n ? null\n : validator['config']['defaultValue'];\n const schema: SchemaDefinition[string] = {\n required: defaultValue === undefined && validator['config']['required'],\n default: defaultValue,\n };\n\n if (validator instanceof StringValidator) {\n schema.type = SchemaTypes.String;\n } else if (validator instanceof NumberValidator) {\n schema.type = SchemaTypes.Number;\n } else if (validator instanceof BooleanValidator) {\n schema.type = SchemaTypes.Boolean;\n } else if (validator instanceof MongoDecimal128Validator) {\n schema.type = SchemaTypes.Decimal128;\n } else if (validator instanceof ArrayValidator) {\n const items = validator['config']['itemValidator'];\n if (items) {\n schema.type = [validatorToSchema(items)];\n } else {\n schema.type = SchemaTypes.Array;\n }\n } else if (validator instanceof ObjectValidator) {\n schema.type = SchemaTypes.Map;\n const properties = validator['config']['properties'];\n if (properties) {\n schema.type = new Schema(\n Object.fromEntries(\n Object.entries(properties).map(\n ([key, value]) => <const>[key, validatorToSchema(value)],\n ),\n ),\n { _id: false, timestamps: false, versionKey: false },\n );\n }\n } else if (validator instanceof DateValidator) {\n schema.type = SchemaTypes.Date;\n } else if (validator instanceof MongoObjectIdValidator) {\n schema.type = SchemaTypes.ObjectId;\n } else if (validator instanceof AnyValidator) {\n schema.type = SchemaTypes.Mixed;\n } else {\n throw new Error(\n i18n.t('mongoose.unsupported_validator', { validator: validator.constructor.name }),\n );\n }\n\n return schema;\n};\n","import { compose, middleware } from '@aomex/common';\nimport type { ConsoleMiddleware } from '@aomex/console';\nimport { migrationCreateFile } from './migration-create-file.md';\nimport { migrationUp } from './migration-up.md';\nimport { migrationDown } from './migration-down.md';\nimport type { Connection, ConnectOptions } from 'mongoose';\n\nexport interface MigrationOptions {\n /**\n * 模型存放位置,用于执行`mongoose.syncIndexes()`同步索引。默认值:`src/models`\n */\n modelsPath?: string;\n /**\n * 迁移文件存放位置。默认值:`src/migrations`\n */\n migrationsPath?: string;\n /**\n * 连接参数。如果已经连接并且拥有读写权限,则可以传入`mongoose.connection`\n */\n connection:\n | Connection\n | {\n uri: string;\n options?: ConnectOptions;\n };\n}\n\nexport const mongooseMigration = (opts: MigrationOptions): ConsoleMiddleware => {\n const {\n migrationsPath = 'src/migrations',\n modelsPath = 'src/models',\n connection,\n } = opts;\n const middlewareList = [\n migrationCreateFile(migrationsPath),\n migrationUp({ migrationsPath, connection, modelsPath }),\n migrationDown({ migrationsPath, connection, modelsPath }),\n ];\n\n return middleware.console({\n fn: compose(middlewareList),\n help: {\n async onDocument(_, { children }) {\n await children(middlewareList);\n },\n async postDocument(_, { children }) {\n await children(middlewareList);\n },\n },\n });\n};\n","import { middleware, rule, validate } from '@aomex/common';\nimport { terminal, type ConsoleMiddleware } from '@aomex/console';\nimport snakeCase from 'lodash.snakecase';\nimport { i18n } from '../i18n';\nimport path from 'node:path';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { createInterface } from 'node:readline/promises';\n\nconst commandName = 'mongoose:migration:create';\n\nexport const migrationCreateFile = (migrationsPath: string): ConsoleMiddleware => {\n return middleware.console({\n fn: async (ctx, next) => {\n if (ctx.input.command !== commandName) return next();\n ctx.commandMatched = true;\n\n let { name } = await validate(ctx.input.parseArgv(), {\n name: rule.string().optional().trim().transform(snakeCase),\n });\n\n if (!name) {\n const readline = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n while (!name) {\n name = await readline.question(i18n.t('migration.input_file_name'));\n name = snakeCase(name.trim());\n }\n readline.close();\n }\n\n const filename = `${new Date().toISOString().replaceAll(/[-TZ.:]/gi, '')}_${name}.ts`;\n const fullPath = path.join(migrationsPath, filename);\n await mkdir(path.dirname(fullPath), { recursive: true });\n await writeFile(\n fullPath,\n `import { migrate } from '@aomex/mongoose';\n\nexport default migrate({\n up: async (db, session) => {\n // up transaction\n },\n down: async (db, session) => {\n // down transaction\n },\n});\n`,\n );\n terminal.printSuccess(\n i18n.t('migration.file_created', {\n file: path.relative(process.cwd(), fullPath),\n }),\n );\n },\n help: {\n onDocument(doc) {\n doc[commandName] = {\n summary: i18n.t('migration.create'),\n parameters: [{ type: 'string', name: 'name' }],\n };\n },\n },\n });\n};\n","import { middleware } from '@aomex/common';\nimport type { MigrationOptions } from './mongoose-migration.md';\nimport { i18n } from '../i18n';\nimport { syncCollectionIndex } from '../libs/sync-collection-index';\nimport { MigrationModel } from '../models/migration.model';\nimport { pathToFiles } from '@aomex/internal-file-import';\nimport path from 'node:path';\nimport { Migrate } from '../libs/migrate';\nimport mongoose, { createConnection } from 'mongoose';\nimport { terminal } from '@aomex/console';\nimport { mkdir } from 'node:fs/promises';\n\nconst commandName = 'mongoose:migration:up';\n\nexport const migrationUp = (opts: Required<MigrationOptions>) => {\n return middleware.console({\n fn: async (ctx, next) => {\n if (ctx.input.command !== commandName) return next();\n ctx.commandMatched = true;\n\n const connection =\n opts.connection instanceof mongoose.Connection\n ? opts.connection\n : await createConnection(\n opts.connection.uri,\n opts.connection.options,\n ).asPromise();\n const db = connection.db!;\n\n await syncCollectionIndex(opts.modelsPath);\n\n const migratedRows = await MigrationModel.find().sort({ filename: 'asc' }).lean();\n const migratedFiles = migratedRows.map((item) => item.filename);\n await mkdir(opts.migrationsPath, { recursive: true });\n const allFiles = await pathToFiles(opts.migrationsPath);\n const waitingMigrateFiles = allFiles\n .filter(\n (item) => !migratedFiles.includes(path.basename(item, path.extname(item))),\n )\n .sort();\n\n for (const filePath of waitingMigrateFiles) {\n const instance = await import(filePath);\n const migrate = instance.default;\n if (migrate instanceof Migrate) {\n const filename = path.basename(filePath, path.extname(filePath));\n try {\n await connection.transaction(async (session) => {\n await MigrationModel.create([{ filename }], { session });\n await migrate.up(db, session);\n await MigrationModel.updateOne(\n { filename },\n { finished_at: new Date() },\n { session },\n );\n });\n terminal.printSuccess(`[up] ${filename}`);\n } catch (e) {\n terminal.printError(`[up] ${filename}`);\n throw e;\n }\n }\n }\n\n if (!(opts.connection instanceof mongoose.Connection)) {\n await connection.close();\n }\n },\n help: {\n onDocument(doc) {\n doc[commandName] = { summary: i18n.t('migration.up') };\n },\n },\n });\n};\n","import { getFileValues, pathToFiles } from '@aomex/internal-file-import';\nimport mongoose from 'mongoose';\nimport { mkdir } from 'node:fs/promises';\n\nexport const syncCollectionIndex = async (modelsPath: string) => {\n await mkdir(modelsPath, { recursive: true });\n const files = await pathToFiles(modelsPath);\n await getFileValues(files);\n await mongoose.syncIndexes();\n};\n","import { rule } from '@aomex/common';\nimport { defineMongooseModel } from '../define-mongoose-model';\n\nexport const MigrationModel = defineMongooseModel('__aomex_migration', {\n schemas: {\n filename: rule.string(),\n finished_at: rule.date().nullable(),\n },\n versionKey: false,\n timestamps: { createdAt: 'created_at', updatedAt: false },\n indexes: [\n {\n fields: { filename: 'asc' },\n unique: true,\n },\n ],\n});\n","import mongoose from 'mongoose';\n\ninterface Operation {\n (db: mongoose.mongo.Db, session: mongoose.mongo.ClientSession): Promise<any>;\n}\n\n/**\n * 迁移数据,因为开启了事务,所以任何操作都需要带上session,这样能保证出错时顺利回滚数据。\n *\n * 注意:集合和索引会根据models自动同步,无须写迁移逻辑。\n */\nexport const migrate = (opts: { up: Operation; down: Operation }) => {\n return new Migrate(opts.up, opts.down);\n};\n\nexport class Migrate {\n constructor(\n public readonly up: Operation,\n public readonly down: Operation,\n ) {}\n}\n","import { middleware, rule, validate } from '@aomex/common';\nimport type { MigrationOptions } from './mongoose-migration.md';\nimport { i18n } from '../i18n';\nimport { syncCollectionIndex } from '../libs/sync-collection-index';\nimport { MigrationModel } from '../models/migration.model';\nimport { Migrate } from '../libs/migrate';\nimport mongoose, { createConnection } from 'mongoose';\nimport { terminal } from '@aomex/console';\nimport { pathToFiles } from '@aomex/internal-file-import';\nimport { mkdir } from 'node:fs/promises';\nimport path from 'node:path';\n\nconst commandName = 'mongoose:migration:down';\n\nexport const migrationDown = (opts: Required<MigrationOptions>) => {\n return middleware.console({\n fn: async (ctx, next) => {\n if (ctx.input.command !== commandName) return next();\n ctx.commandMatched = true;\n\n const { all } = await validate(ctx.input.parseArgv(), {\n all: rule.boolean().default(false),\n });\n\n const connection =\n opts.connection instanceof mongoose.Connection\n ? opts.connection\n : await createConnection(\n opts.connection.uri,\n opts.connection.options,\n ).asPromise();\n const db = connection.db!;\n\n await syncCollectionIndex(opts.modelsPath);\n\n const rows = await MigrationModel.find().sort({ filename: 'desc' }).lean();\n if (!rows.length) return;\n\n const migratedFiles = rows.map((item) => item.filename);\n await mkdir(opts.migrationsPath, { recursive: true });\n const allFiles = await pathToFiles(opts.migrationsPath);\n const executeCount = all ? migratedFiles.length : 1;\n\n for (let i = 0; i < executeCount; ++i) {\n const filename = migratedFiles[i]!;\n const fullPath = allFiles.find((item) =>\n item.endsWith(filename + path.extname(item)),\n );\n if (!fullPath) {\n throw new Error(i18n.t('migration.file_not_found', { file: filename }));\n }\n const instance = await import(fullPath);\n const migrate = instance.default;\n if (migrate instanceof Migrate) {\n try {\n await connection.transaction(async (session) => {\n await MigrationModel.deleteOne({ filename }, { session });\n await migrate.down(db, session);\n });\n terminal.printSuccess(`[down] ${filename}`);\n } catch (e) {\n terminal.printError(`[down] ${filename}`);\n throw e;\n }\n }\n }\n\n if (!(opts.connection instanceof mongoose.Connection)) {\n await connection.close();\n }\n },\n help: {\n onDocument(doc) {\n doc[commandName] = {\n summary: i18n.t('migration.down'),\n parameters: [{ type: 'boolean', name: 'all', defaultValue: false }],\n };\n },\n },\n });\n};\n","import {\n Document,\n mongo,\n type Default__v,\n type FlattenMaps,\n type Require_id,\n} from 'mongoose';\n\nexport type MongoResult<T, Remove extends boolean> = {\n [K in keyof T as K extends '__v'\n ? never\n : Remove extends true\n ? K extends (typeof excludedFields)[number]\n ? never\n : K\n : K extends '_id'\n ? 'id'\n : K]: T[K] extends mongo.Decimal128 | mongo.ObjectId ? string : T[K];\n};\n\nconst excludedFields = <const>[\n 'created_at',\n 'createdAt',\n 'updated_at',\n 'updatedAt',\n '_id',\n];\n\nexport function formatMongoResult<T extends Document, Remove extends boolean>(\n data: T[],\n removeColumns?: Remove,\n): MongoResult<\n T extends Document<any, any, infer R> ? FlattenMaps<Default__v<Require_id<R>>> : never,\n Remove\n>[];\nexport function formatMongoResult<T extends Record<string, any>, Remove extends boolean>(\n data: T[],\n removeColumns?: Remove,\n): MongoResult<T, Remove>[];\nexport function formatMongoResult<T extends Document | null, Remove extends boolean>(\n data: T,\n removeColumns?: Remove,\n): T extends Document\n ? MongoResult<\n T extends Document<any, any, infer R>\n ? FlattenMaps<Default__v<Require_id<R>>>\n : never,\n Remove\n >\n : null;\nexport function formatMongoResult<\n T extends Record<string, any> | null,\n Remove extends boolean,\n>(\n data: T,\n removeColumns?: Remove,\n): T extends Record<string, any> ? MongoResult<T, Remove> : null;\n/**\n * 格式化mongo查询结果,支持传入 纯JSON 和 Document 两种对象格式,返回结果遵循如下规则:\n * - 去掉 __v 字段\n * - decimal128类型 转为 字符串\n * - objectId类型 转为 字符串\n * - removeColumns=true时,去掉 _id 字段\n * - removeColumns=false时,_id 字段转为 id\n * - removeColumns=true时,去掉 createdAt/created_at 字段\n * - removeColumns=true时,去掉 updatedAt/updated_at 字段\n *\n * @param {Boolean} removeColumns 是否去掉数据库扩展的字段\n */\nexport function formatMongoResult(\n data: Record<string, any> | Record<string, any>[] | Document | Document[] | null,\n removeColumns: boolean = false,\n) {\n if (data == null) return null;\n\n const newDate = (Array.isArray(data) ? data : [data]).map((item) => {\n if (item instanceof Document) {\n item = item.toJSON({ flattenMaps: true });\n }\n\n const newItem: Record<string, any> = {};\n for (let [key, value] of Object.entries(item)) {\n if (key === '__v') continue;\n if (removeColumns && excludedFields.includes(key as any)) continue;\n if (key === '_id') key = 'id';\n\n if (value instanceof mongo.Decimal128) {\n newItem[key] = value.toString();\n } else if (value instanceof mongo.ObjectId) {\n newItem[key] = value.toHexString();\n } else {\n newItem[key] = value;\n }\n }\n return newItem;\n });\n return Array.isArray(data) ? newDate : newDate[0];\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;;;ACNP,SAAS,QAAAA,aAAY;;;ACArB,SAAS,YAAY;AAEd,IAAM,KAAK,KAAK,OAAO;AAAA,EAC5B,WAAW;AAAA,IACT,YAAY;AAAA,MACV,oBAAoB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,MACR,kBAAkB;AAAA,IACpB;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,uBAAuB;AAAA,EACzB;AAAA,EACA,WAAW;AAAA,IACT,QAAQ;AAAA,IACR,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,IACjB,cAAc;AAAA,EAChB;AACF,CAAC;;;ACtBD,SAAS,QAAAC,aAAY;AAGd,IAAM,KAAKC,MAAK,UAAU,EAAE,EAAE,OAAO;AAAA,EAC1C,WAAW;AAAA,IACT,YAAY;AAAA,MACV,oBAAoB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C,aAAS,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAC7C,UAAI,QAAQ,MAAO;AACnB,UAAI,iBAAiB,eAAe,SAAS,GAAU,EAAG;AAC1D,UAAI,QAAQ,MAAO,OAAM;AAEzB,UAAI,iBAAiBA,OAAM,YAAY;AACrC,gBAAQ,GAAG,IAAI,MAAM,SAAS;AAAA,MAChC,WAAW,iBAAiBA,OAAM,UAAU;AAC1C,gBAAQ,GAAG,IAAI,MAAM,YAAY;AAAA,MACnC,OAAO;AACL,gBAAQ,GAAG,IAAI;AAAA,MACjB;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACD,SAAO,MAAM,QAAQ,IAAI,IAAI,UAAU,QAAQ,CAAC;AAClD;","names":["I18n","I18n","I18n","I18n","Validator","ValidateResult","Rule","mongo","Validator","ValidateResult","Rule","Schema","schema","Schema","middleware","middleware","mkdir","rule","rule","pathToFiles","path","mongoose","terminal","mkdir","commandName","middleware","pathToFiles","path","migrate","middleware","rule","validate","mongoose","createConnection","terminal","pathToFiles","mkdir","path","commandName","middleware","validate","rule","migrate","middleware","mongo"]}
|