chore: bump deps (#14777)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Migration and config commands now feature interactive prompts for
required inputs.

* **Bug Fixes**
  * Enhanced error handling in CLI operations.

* **Chores**
  * Updated GraphQL Code Generator toolchain to v6.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2026-04-03 19:36:18 +08:00
committed by GitHub
parent d0607b5ce7
commit d3ec008b0c
8 changed files with 659 additions and 833 deletions

View File

@@ -29,6 +29,7 @@
"@fal-ai/serverless-client": "^0.15.0", "@fal-ai/serverless-client": "^0.15.0",
"@google-cloud/opentelemetry-cloud-trace-exporter": "^3.0.0", "@google-cloud/opentelemetry-cloud-trace-exporter": "^3.0.0",
"@google-cloud/opentelemetry-resource-util": "^3.0.0", "@google-cloud/opentelemetry-resource-util": "^3.0.0",
"@inquirer/prompts": "^7.10.1",
"@nestjs-cls/transactional": "^3.2.0", "@nestjs-cls/transactional": "^3.2.0",
"@nestjs-cls/transactional-adapter-prisma": "^1.3.4", "@nestjs-cls/transactional-adapter-prisma": "^1.3.4",
"@nestjs/apollo": "^13.0.4", "@nestjs/apollo": "^13.0.4",
@@ -65,6 +66,7 @@
"@react-email/components": "^0.5.7", "@react-email/components": "^0.5.7",
"@socket.io/redis-adapter": "^8.3.0", "@socket.io/redis-adapter": "^8.3.0",
"bullmq": "^5.40.2", "bullmq": "^5.40.2",
"commander": "^13.1.0",
"cookie-parser": "^1.4.7", "cookie-parser": "^1.4.7",
"cross-env": "^10.1.0", "cross-env": "^10.1.0",
"date-fns": "^4.0.0", "date-fns": "^4.0.0",
@@ -88,7 +90,6 @@
"lodash-es": "^4.17.23", "lodash-es": "^4.17.23",
"mustache": "^4.2.0", "mustache": "^4.2.0",
"nanoid": "^5.1.6", "nanoid": "^5.1.6",
"nest-commander": "^3.15.0",
"nest-winston": "^1.9.7", "nest-winston": "^1.9.7",
"nestjs-cls": "^6.0.0", "nestjs-cls": "^6.0.0",
"nodemailer": "^8.0.4", "nodemailer": "^8.0.4",

View File

@@ -1,12 +1,102 @@
import { Logger } from '@nestjs/common'; import { basename } from 'node:path';
import { CommandFactory } from 'nest-commander';
import { type INestApplicationContext, Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { Command, CommanderError } from 'commander';
import { CliAppModule } from './data/app'; import { CliAppModule } from './data/app';
import { CreateCommand } from './data/commands/create';
import { ImportConfigCommand } from './data/commands/import';
import { RevertCommand, RunCommand } from './data/commands/run';
function getProgramName() {
return process.env.npm_lifecycle_event ?? basename(process.argv[1] ?? 'cli');
}
async function withCliApp(
logger: Logger,
callback: (app: INestApplicationContext) => Promise<void>
) {
const app = await NestFactory.createApplicationContext(CliAppModule, {
logger,
});
try {
await callback(app);
} finally {
await app.close();
}
}
function buildProgram(logger: Logger) {
const program = new Command();
program
.name(getProgramName())
.description('AFFiNE server CLI')
.showHelpAfterError()
.showSuggestionAfterError();
program
.command('create [name]')
.description('create a data migration script')
.action(async name => {
await withCliApp(logger, async app => {
await app.get(CreateCommand).execute(name);
});
});
program
.command('run')
.description('Run all pending data migrations')
.action(async () => {
await withCliApp(logger, async app => {
await app.get(RunCommand).execute();
});
});
program
.command('revert [name]')
.description('Revert one data migration with given name')
.action(async name => {
await withCliApp(logger, async app => {
await app.get(RevertCommand).execute(name);
});
});
program
.command('import-config [path]')
.description('import config from a file')
.action(async path => {
await withCliApp(logger, async app => {
await app.get(ImportConfigCommand).execute(path);
});
});
return program;
}
export async function run() { export async function run() {
await CommandFactory.run(CliAppModule, new Logger()).catch(e => { const logger = new Logger('Cli');
console.error(e);
process.exit(1); try {
}); const program = buildProgram(logger);
process.exit(0); program.exitOverride();
const argv =
process.argv.length > 2 ? process.argv : [...process.argv, '--help'];
await program.parseAsync(argv);
} catch (error) {
if (error instanceof CommanderError) {
process.exitCode = error.exitCode;
return;
}
if (error instanceof Error) {
logger.error(error.message, error.stack);
} else {
logger.error(String(error));
}
process.exitCode = 1;
}
} }

View File

@@ -2,18 +2,12 @@ import { Module } from '@nestjs/common';
import { FunctionalityModules } from '../app.module'; import { FunctionalityModules } from '../app.module';
import { IndexerModule } from '../plugins/indexer'; import { IndexerModule } from '../plugins/indexer';
import { CreateCommand, NameQuestion } from './commands/create'; import { CreateCommand } from './commands/create';
import { ImportConfigCommand } from './commands/import'; import { ImportConfigCommand } from './commands/import';
import { RevertCommand, RunCommand } from './commands/run'; import { RevertCommand, RunCommand } from './commands/run';
@Module({ @Module({
imports: [...FunctionalityModules, IndexerModule], imports: [...FunctionalityModules, IndexerModule],
providers: [ providers: [CreateCommand, RunCommand, RevertCommand, ImportConfigCommand],
NameQuestion,
CreateCommand,
RunCommand,
RevertCommand,
ImportConfigCommand,
],
}) })
export class CliAppModule {} export class CliAppModule {}

View File

@@ -2,54 +2,37 @@ import { appendFileSync, writeFileSync } from 'node:fs';
import { join, parse } from 'node:path'; import { join, parse } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { Logger } from '@nestjs/common'; import { input } from '@inquirer/prompts';
import { Injectable, Logger } from '@nestjs/common';
import { camelCase, kebabCase, upperFirst } from 'lodash-es'; import { camelCase, kebabCase, upperFirst } from 'lodash-es';
import {
Command,
CommandRunner,
InquirerService,
Question,
QuestionSet,
} from 'nest-commander';
@QuestionSet({ name: 'name-questions' }) @Injectable()
export class NameQuestion { export class CreateCommand {
@Question({
name: 'name',
message: 'Name of the data migration script:',
})
parseName(val: string) {
return val.trim();
}
}
@Command({
name: 'create',
arguments: '[name]',
description: 'create a data migration script',
})
export class CreateCommand extends CommandRunner {
logger = new Logger(CreateCommand.name); logger = new Logger(CreateCommand.name);
constructor(private readonly inquirer: InquirerService) {
super();
}
override async run(inputs: string[]): Promise<void> { async execute(name?: string): Promise<void> {
let name = inputs[0]; let resolvedName = name;
if (!name) { if (!resolvedName) {
name = ( resolvedName = (
await this.inquirer.ask<{ name: string }>('name-questions', undefined) await input({
).name; message: 'Name of the data migration script:',
validate(value) {
return value.trim().length > 0 || 'A migration name is required';
},
})
).trim();
} }
const timestamp = Date.now(); const timestamp = Date.now();
const content = this.createScript(upperFirst(camelCase(name)) + timestamp); const content = this.createScript(
upperFirst(camelCase(resolvedName)) + timestamp
);
const migrationDir = join( const migrationDir = join(
fileURLToPath(import.meta.url), fileURLToPath(import.meta.url),
'../../migrations' '../../migrations'
); );
const fileName = `${timestamp}-${kebabCase(name)}.ts`; const fileName = `${timestamp}-${kebabCase(resolvedName)}.ts`;
const filePath = join(migrationDir, fileName); const filePath = join(migrationDir, fileName);
this.logger.log(`Creating ${fileName}...`); this.logger.log(`Creating ${fileName}...`);

View File

@@ -1,29 +1,25 @@
import { readFileSync } from 'node:fs'; import { readFileSync } from 'node:fs';
import { resolve } from 'node:path'; import { resolve } from 'node:path';
import { Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { Command, CommandRunner } from 'nest-commander';
import { ConfigFactory, InvalidAppConfigInput } from '../../base'; import { ConfigFactory, InvalidAppConfigInput } from '../../base';
import { Models } from '../../models'; import { Models } from '../../models';
@Command({ @Injectable()
name: 'import-config', export class ImportConfigCommand {
arguments: '[name]',
description: 'import config from a file',
})
export class ImportConfigCommand extends CommandRunner {
logger = new Logger(ImportConfigCommand.name); logger = new Logger(ImportConfigCommand.name);
constructor( constructor(
private readonly models: Models, private readonly models: Models,
private readonly configFactory: ConfigFactory private readonly configFactory: ConfigFactory
) { ) {}
super();
} async execute(path?: string): Promise<void> {
if (!path) {
throw new Error('A config file path is required');
}
override async run(inputs: string[]): Promise<void> {
let path = inputs[0];
path = resolve(process.cwd(), path); path = resolve(process.cwd(), path);
const overrides: Record<string, Record<string, any>> = JSON.parse( const overrides: Record<string, Record<string, any>> = JSON.parse(

View File

@@ -1,8 +1,7 @@
import { Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core'; import { ModuleRef } from '@nestjs/core';
import { PrismaClient } from '@prisma/client'; import { PrismaClient } from '@prisma/client';
import { once } from 'lodash-es'; import { once } from 'lodash-es';
import { Command, CommandRunner } from 'nest-commander';
import * as migrationImports from '../migrations'; import * as migrationImports from '../migrations';
@@ -35,20 +34,15 @@ export const collectMigrations = once(() => {
return migrations.sort((a, b) => a.order - b.order); return migrations.sort((a, b) => a.order - b.order);
}); });
@Command({ @Injectable()
name: 'run', export class RunCommand {
description: 'Run all pending data migrations',
})
export class RunCommand extends CommandRunner {
logger = new Logger(RunCommand.name); logger = new Logger(RunCommand.name);
constructor( constructor(
private readonly db: PrismaClient, private readonly db: PrismaClient,
private readonly injector: ModuleRef private readonly injector: ModuleRef
) { ) {}
super();
}
override async run(): Promise<void> { async execute(): Promise<void> {
const migrations = collectMigrations(); const migrations = collectMigrations();
const done: Migration[] = []; const done: Migration[] = [];
for (const migration of migrations) { for (const migration of migrations) {
@@ -116,7 +110,7 @@ export class RunCommand extends CommandRunner {
}); });
await migration.down(this.db, this.injector); await migration.down(this.db, this.injector);
this.logger.error('Failed to run data migration', e); this.logger.error('Failed to run data migration', e);
process.exit(1); throw e;
} }
await this.db.dataMigration.update({ await this.db.dataMigration.update({
@@ -130,23 +124,16 @@ export class RunCommand extends CommandRunner {
} }
} }
@Command({ @Injectable()
name: 'revert', export class RevertCommand {
arguments: '[name]',
description: 'Revert one data migration with given name',
})
export class RevertCommand extends CommandRunner {
logger = new Logger(RevertCommand.name); logger = new Logger(RevertCommand.name);
constructor( constructor(
private readonly db: PrismaClient, private readonly db: PrismaClient,
private readonly injector: ModuleRef private readonly injector: ModuleRef
) { ) {}
super();
}
override async run(inputs: string[]): Promise<void> { async execute(name?: string): Promise<void> {
const name = inputs[0];
if (!name) { if (!name) {
throw new Error('A migration name is required'); throw new Error('A migration name is required');
} }

View File

@@ -12,9 +12,9 @@
}, },
"sideEffects": false, "sideEffects": false,
"devDependencies": { "devDependencies": {
"@graphql-codegen/cli": "^5.0.7", "@graphql-codegen/cli": "^6.2.1",
"@graphql-codegen/typescript": "^4.1.6", "@graphql-codegen/typescript": "^5.0.9",
"@graphql-codegen/typescript-operations": "^4.6.1", "@graphql-codegen/typescript-operations": "^5.0.9",
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"prettier": "^3.7.4", "prettier": "^3.7.4",
"vitest": "^4.0.18" "vitest": "^4.0.18"

1259
yarn.lock

File diff suppressed because it is too large Load Diff