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>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import {
|
|
Inject,
|
|
QualifierImplDecoratorUtil,
|
|
type ImplDecorator,
|
|
} from '@eggjs/tegg';
|
|
import type { RegistryType } from '../../../common/enum/Registry.ts';
|
|
import type { Registry } from '../../../core/entity/Registry.ts';
|
|
import type { EggHttpClient, EggLogger } from 'egg';
|
|
|
|
export const CHANGE_STREAM_ATTRIBUTE = 'CHANGE_STREAM_ATTRIBUTE';
|
|
export interface ChangesStreamChange {
|
|
seq: string;
|
|
fullname: string;
|
|
}
|
|
|
|
export abstract class AbstractChangeStream {
|
|
@Inject()
|
|
protected logger: EggLogger;
|
|
|
|
@Inject()
|
|
protected httpclient: EggHttpClient;
|
|
|
|
abstract getInitialSince(registry: Registry): Promise<string>;
|
|
abstract fetchChanges(
|
|
registry: Registry,
|
|
since: string
|
|
): AsyncGenerator<ChangesStreamChange>;
|
|
|
|
getChangesStreamUrl(
|
|
registry: Registry,
|
|
since: string,
|
|
limit?: number
|
|
): string {
|
|
const url = new URL(registry.changeStream);
|
|
url.searchParams.set('since', since);
|
|
if (limit) {
|
|
url.searchParams.set('limit', String(limit));
|
|
}
|
|
return url.toString();
|
|
}
|
|
}
|
|
|
|
export const RegistryChangesStream: ImplDecorator<
|
|
AbstractChangeStream,
|
|
typeof RegistryType
|
|
> = QualifierImplDecoratorUtil.generatorDecorator(
|
|
AbstractChangeStream,
|
|
CHANGE_STREAM_ATTRIBUTE
|
|
);
|