Files
cnpmcore/app/port/controller/ChangesStreamController.ts
MK (fengmk2) e5162f20aa fix: improve TypeScript type definitions across codebase (#844)
This commit enhances type safety and fixes type-related issues
throughout the project including:
- Updated type definitions in entities, repositories, and models
- Improved type annotations in services and controllers
- Fixed type issues in adapters and utilities
- Enhanced test file type definitions
- Added typings/index.d.ts for global type declarations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-23 00:58:59 +08:00

46 lines
1.2 KiB
TypeScript

import {
type EggContext,
Context,
HTTPController,
HTTPMethod,
HTTPMethodEnum,
HTTPQuery,
Inject,
} from '@eggjs/tegg';
import { Type } from '@eggjs/typebox-validate/typebox';
import { AbstractController } from './AbstractController.ts';
import type { ChangeRepository } from '../../repository/ChangeRepository.ts';
const ChangeRule = Type.Object({
since: Type.Integer({ minimum: 0 }),
});
@HTTPController()
export class ChangesStreamController extends AbstractController {
@Inject()
private changeRepository: ChangeRepository;
// https://github.com/cnpm/cnpmcore/issues/70
@HTTPMethod({
// /_changes?since=${since}
path: '/_changes',
method: HTTPMethodEnum.GET,
})
async listChanges(@Context() ctx: EggContext, @HTTPQuery() since: string) {
const params = { since: since ? Number(since) : 0 };
ctx.tValidate(ChangeRule, params);
const limit = 1000;
const changes = await this.changeRepository.query(params.since, limit);
const results = changes.map(change => {
return {
seq: change.id,
type: change.type,
id: change.targetName,
changes: [change.data],
};
});
return { results };
}
}