import type { ImportBase } from './import-base.js'; import type { MockDescriptor } from './mock.js'; import type { ComputeExpr } from './expr.js'; /** Field query comparison operators (search field semantics). */ export type Operator = 'eq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ne' | 'in' | 'null' | 'notNull'; export interface SchemaBase { name: string; description?: string; } /** Schema base for cross-file entities. importRef locates the generating module; inline schemas omit it. */ export interface ImportableSchemaBase extends SchemaBase { importRef?: ImportBase; } /** Field collection schemas (DB table vs DTO message); `type` is the discriminator */ export interface CollectionSchemaBase extends SchemaBase { type: string; } export interface BaseField { name: string; /** 显示名称(中文标签) */ label?: string; /** 字段描述 */ description?: string; optional?: boolean; readOnly?: boolean; default?: string; /** 所属 schema(db 或 dto) */ schema?: CollectionSchemaBase; /** Pure-data mock descriptor for test data generation */ mock?: MockDescriptor; } interface StringField extends BaseField { type: 'string'; jsType: 'string'; minLength?: number; maxLength?: number; } interface TextField extends BaseField { type: 'text'; jsType: 'string'; } interface IntField extends BaseField { type: 'integer'; jsType: 'number'; min?: number; max?: number; } interface BigintField extends BaseField { type: 'bigint'; jsType: 'string'; } interface DecimalField extends BaseField { type: 'decimal'; jsType: 'string'; precision: number; scale: number; } type RateUnit = 'pct' | 'pm' | 'bp'; export declare function rateScale(unit: RateUnit): number; interface RateField extends BaseField { type: 'rate'; jsType: 'string'; unit: RateUnit; } interface BooleanField extends BaseField { type: 'boolean'; jsType: 'boolean'; } interface DateField extends BaseField { type: 'date'; jsType: 'Date'; } interface TimeField extends BaseField { type: 'time'; jsType: 'string'; } interface DateTimeField extends BaseField { type: 'datetime'; jsType: 'Date'; } export interface EnumValue { value: string | number; symbol: string; label: string; } /** Shared enum definition. Pure value object, safe to reference from multiple fields/tables. */ export interface EnumDef { /** JS 定义名称,如 MerchantStatus */ jsName: string; valueType: 'string' | 'integer'; values: EnumValue[]; } export declare function defineEnum(jsName: string, valueType: 'string' | 'integer', values: EnumValue[]): EnumDef; export interface EnumField extends BaseField { type: 'enum'; jsType: 'string' | 'number'; /** Reference to a shared enum definition (see defineEnum). */ enum: EnumDef; } interface JsonField extends BaseField { type: 'json'; jsType: 'object'; } /** Recursive array field — wire-format nesting (third-party messages), not a table column. */ interface ArrayField extends BaseField { type: 'array'; jsType: 'array'; /** Element type: any Field, including nested array/object. */ items: Field; } /** Recursive object field — wire-format nesting (third-party messages), not a table column. */ interface ObjectField extends BaseField { type: 'object'; jsType: 'object'; properties: Record; } /** Aggregate result column (count/sum/avg) of an aggregate query — a Field * so that aggregate result entities can carry it like any other column. * jsType follows the aggregate precision rule: count → number; * sum/avg over an integer column → number, anything else → string. */ export interface AggregateField extends BaseField { type: 'aggregate'; jsType: 'number' | 'string'; /** The aggregate expression producing this column. */ expr: ComputeExpr; } /** Whether the field is an aggregate result column — narrows to AggregateField. */ export declare function isAggregate(field: Field): field is AggregateField; export type Field = StringField | TextField | IntField | BigintField | DecimalField | RateField | BooleanField | DateField | TimeField | DateTimeField | EnumField | JsonField | ArrayField | ObjectField | AggregateField; /** TS type of a field in generated code (row interfaces, dao params, filter * args): enum → its JS name, date/datetime → string (transported as ISO * strings), everything else → jsType. Aggregate fields carry their precision * rule in jsType already. The single source for this mapping — renderers * must not branch on field.type for a TS type string. */ export declare function fieldJsType(field: Field): string; /** Enum JS names referenced by a field, recursing into array/object * containers (wire-format nesting). First-occurrence order — callers that * need uniqueness collect into a Set. */ export declare function collectEnumRefs(field: Field, out?: string[]): string[]; /** Depth-first walk over a field's container structure: visit is called for * every field including containers (top-level, array items, object * properties). `key` is the object property name the field sits under * (undefined for the top-level field and for array items). */ export declare function walkContainer(field: Field, visit: (f: Field, key?: string) => void, key?: string): void; type FieldExtras = Omit; export declare function stringField(extra?: FieldExtras): StringField; export declare function textField(extra?: FieldExtras): TextField; export declare function intField(extra?: FieldExtras): IntField; export declare function bigintField(extra?: FieldExtras): BigintField; export declare function decimalField(extra: FieldExtras): DecimalField; export declare function rateField(unit: RateUnit, extra?: Omit, 'unit'>): RateField; export declare function booleanField(extra?: FieldExtras): BooleanField; export declare function dateField(extra?: FieldExtras): DateField; export declare function timeField(extra?: FieldExtras): TimeField; export declare function datetimeField(extra?: FieldExtras): DateTimeField; export declare function jsonField(extra?: FieldExtras): JsonField; export declare function arrayField(extra: FieldExtras): ArrayField; export declare function objectField(extra: FieldExtras): ObjectField; export declare function enumField(extra: Omit): EnumField; /** Aggregate result column field: count → number; sum/avg over an integer * column → number, anything else (decimal/bigint/rate…) → string. * Used in aggregate-query result entities (see AggregateSchema). */ export declare function aggField(name: string, expr: ComputeExpr): AggregateField; export {};