UNPKG

@gftdcojp/ksqldb-orm

Version:

ksqldb-orm - Server-Side TypeScript ORM for ksqlDB with enterprise security extensions

109 lines 3.28 kB
/** * Schema 定義層 - defineSchema() で TypeScript 型→Avro Schema 生成&登録 */ import { BaseFieldType } from './field-types'; import { AvroSchema } from './types'; /** * トピック設定オプション */ export interface TopicConfiguration { /** Kafkaトピック名(デフォルト: スキーマ名の小文字) */ topicName?: string; /** 値フォーマット(デフォルト: JSON) */ valueFormat?: 'JSON' | 'AVRO' | 'DELIMITED'; /** キーフィールド */ keyField?: string; /** パーティション数(デフォルト: 3) */ partitions?: number; /** レプリカ数(デフォルト: 1) */ replicas?: number; /** retention設定(ミリ秒、デフォルト: -1でinfinity) */ retentionMs?: number; /** cleanup.policy設定(デフォルト: 'delete') */ cleanupPolicy?: 'delete' | 'compact' | 'compact,delete'; /** 追加のトピック設定 */ additionalSettings?: Record<string, string>; } export interface SchemaDefinition { name: string; fields: Record<string, BaseFieldType>; avroSchema: AvroSchema; topicConfig?: TopicConfiguration; } /** * TypeScript スキーマからインデックス型を生成 */ export type InferSchemaType<T extends Record<string, BaseFieldType>> = { [K in keyof T]: InferFieldType<T[K]>; }; /** * フィールド型からTypeScript型を推論 */ export type InferFieldType<T extends BaseFieldType> = T extends { definition: { type: 'string'; }; } ? string : T extends { definition: { type: 'int'; }; } ? number : T extends { definition: { type: 'long'; }; } ? number : T extends { definition: { type: 'double'; }; } ? number : T extends { definition: { type: 'boolean'; }; } ? boolean : T extends { definition: { logicalType: 'uuid'; }; } ? string : T extends { definition: { logicalType: 'timestamp-millis'; }; } ? Date : T extends { definition: { logicalType: 'date'; }; } ? Date : T extends { definition: { logicalType: 'time-millis'; }; } ? Date : T extends { definition: { logicalType: 'decimal'; }; } ? number : any; /** * スキーマ定義関数 - 設計案の通り(トピック設定拡張版) */ export declare function defineSchema<T extends Record<string, BaseFieldType>>(name: string, fields: T, topicConfig?: TopicConfiguration): SchemaDefinition & { type: InferSchemaType<T>; }; /** * 登録済みスキーマを取得 */ export declare function getSchema(name: string): SchemaDefinition | undefined; /** * 全スキーマを取得 */ export declare function getAllSchemas(): SchemaDefinition[]; /** * スキーマレジストリをクリア(テスト用) */ export declare function clearSchemaRegistry(): void; /** * スキーマ定義からDDL文を生成する関数 */ export declare function generateDDLFromSchema(schemaName: string, streamType?: 'STREAM' | 'TABLE'): string; /** * スキーマ定義を使ってストリーム/テーブルを作成 */ export declare function createStreamFromSchema(schemaName: string, streamType?: 'STREAM' | 'TABLE'): Promise<any>; //# sourceMappingURL=schema.d.ts.map