import { S as FieldValueNodeRow, T as FieldsMigrationAdapter, _ as FieldGroup$1, b as FieldStorageValue, k as FlatFieldValue, m as FieldDefinitionVersion, t as AnyFieldDefinition, w as FieldsDefinitionOrigin } from "./schema-CqVMVK32.js";
//#region src/model.d.ts
type EntityType = string;
type EntityId = string;
interface EntityRef {
  entityType: EntityType;
  entityId: EntityId;
}
interface LocationRule {
  entityType: EntityType;
  subType?: string;
}
declare const FIELD_TYPES: readonly ["text", "textarea", "number", "boolean", "select", "date", "color", "url", "email", "media", "relationship"];
type FieldType = (typeof FIELD_TYPES)[number];
/** stable machine key + storage/read key */
declare const FIELD_KEY_RE: RegExp;
declare function isMultipleCapable(t: FieldType): boolean;
type MediaRef = {
  key: string;
  url?: string;
  mime?: string;
  meta?: Record<string, unknown>;
};
type RelRef = EntityRef;
type ScalarValue = string | number | boolean | Date | MediaRef | RelRef;
type FieldValue = ScalarValue | ScalarValue[];
type FieldValueMap = Record<string, FieldValue | undefined>;
interface BaseField {
  key: string;
  label: string;
  required?: boolean;
  help?: string;
  defaultValue?: FieldValue;
}
interface TextField extends BaseField {
  type: 'text';
  maxLength?: number;
  pattern?: string;
}
interface TextAreaField extends BaseField {
  type: 'textarea';
  maxLength?: number;
}
interface NumberField extends BaseField {
  type: 'number';
  min?: number;
  max?: number;
  integer?: boolean;
}
interface BooleanField extends BaseField {
  type: 'boolean';
}
interface SelectField extends BaseField {
  type: 'select';
  options: {
    value: string;
    label: string;
  }[];
  multiple?: boolean;
}
interface DateField extends BaseField {
  type: 'date';
}
interface ColorField extends BaseField {
  type: 'color';
}
interface UrlField extends BaseField {
  type: 'url';
}
interface EmailField extends BaseField {
  type: 'email';
}
interface MediaField extends BaseField {
  type: 'media';
  accept?: string[];
  multiple?: boolean;
}
interface RelationshipField extends BaseField {
  type: 'relationship';
  targetEntityType: EntityType;
  multiple?: boolean;
}
type FieldDefinition = TextField | TextAreaField | NumberField | BooleanField | SelectField | DateField | ColorField | UrlField | EmailField | MediaField | RelationshipField;
interface FieldGroup {
  key: string;
  label: string;
  location: LocationRule;
  fields: FieldDefinition[];
  position?: number;
}
type FieldOrigin = 'code' | 'db';
interface ResolvedFieldGroup extends FieldGroup {
  origin: FieldOrigin;
  id?: string;
}
interface Actor {
  id: string;
  canEditFields?: boolean;
  canManageGroups?: boolean;
}
type Facet = {
  field: string;
  op: 'eq' | 'in';
  value: string | string[];
} | {
  field: string;
  op: 'eq' | 'lt' | 'lte' | 'gt' | 'gte';
  value: number;
} | {
  field: string;
  op: 'between';
  min: number;
  max: number;
} | {
  field: string;
  op: 'has-ref';
  refType: EntityType;
  refId: EntityId;
};
type RelRefResolver = (ref: EntityRef) => Promise<boolean>;
//#endregion
//#region src/definitions-pure.d.ts
declare function legacyFieldToFinalDefinition(field: FieldDefinition): AnyFieldDefinition;
declare function legacyFieldGroupToFinalDefinition(group: FieldGroup): FieldGroup$1;
declare function materializeLegacyFieldDefinitionVersion(group: FieldGroup, origin?: FieldsDefinitionOrigin): Promise<FieldDefinitionVersion>;
interface FieldDefinitionReference {
  readonly groupKey: string;
  readonly revision: number;
}
declare function referencedFieldDefinitionVersions(nodes: readonly FieldValueNodeRow[]): readonly FieldDefinitionReference[];
//#endregion
//#region src/migrations/recursive-eav.d.ts
declare const FIELDS_RECURSIVE_EAV_MIGRATION_ID: "fields-recursive-eav-v1";
interface FieldsMigrationCorpusCheckpoint {
  readonly count: number;
  readonly hash: string;
  readonly lastKey: string | null;
}
interface MigratedFieldValueNode extends FieldValueNodeRow {
  readonly legacySourceIds: readonly string[];
  readonly legacySourceHash: string;
}
interface FieldsRecursiveEavMigrationPlan {
  readonly migrationId: typeof FIELDS_RECURSIVE_EAV_MIGRATION_ID;
  readonly source: FieldsMigrationCorpusCheckpoint;
  readonly target: FieldsMigrationCorpusCheckpoint;
  readonly definitions: readonly FieldDefinitionVersion[];
  readonly definitionRefs: readonly FieldDefinitionReference[];
  readonly nodes: readonly MigratedFieldValueNode[];
}
declare function canonicalFieldsMigrationHash(value: unknown): Promise<string>;
declare function snapshotFlatFieldsCorpus(values: readonly FlatFieldValue[]): Promise<FieldsMigrationCorpusCheckpoint>;
declare function escapeFieldPathSegment(value: string): string;
declare function fieldPath(fieldKey: string): string;
declare function planFieldsRecursiveEavMigration(values: readonly FlatFieldValue[], groups: readonly FieldGroup[]): Promise<FieldsRecursiveEavMigrationPlan>;
declare function fieldsRecursiveEavForwardMigrationSql(adapter: FieldsMigrationAdapter): readonly string[];
declare function fieldsRecursiveEavReverseMigrationSql(adapter: FieldsMigrationAdapter): readonly string[];
/** Public migration metadata intentionally excludes transient adapter journal bytes. */
declare function fieldDefinitionRefsForPlan(plan: FieldsRecursiveEavMigrationPlan): readonly FieldDefinitionReference[];
/** Parses a migration JSON leaf without interpreting it as an arbitrary recursive field object. */
declare function parseLegacyMultipleValueJson(valueJson: string): readonly FieldStorageValue[];
//#endregion
//#region src/migrate.d.ts
/** Idempotent additive DDL for fields EAV tables (spec §4). */
declare const fieldsMigrationSql: () => string;
//#endregion
export { FIELD_TYPES as A, MediaRef as B, ColorField as C, EntityRef as D, EntityId as E, FieldType as F, ResolvedFieldGroup as G, RelRef as H, FieldValue as I, TextAreaField as J, ScalarValue as K, FieldValueMap as L, FieldDefinition as M, FieldGroup as N, EntityType as O, FieldOrigin as P, LocationRule as R, BooleanField as S, EmailField as T, RelRefResolver as U, NumberField as V, RelationshipField as W, UrlField as X, TextField as Y, isMultipleCapable as Z, legacyFieldToFinalDefinition as _, MigratedFieldValueNode as a, Actor as b, fieldDefinitionRefsForPlan as c, fieldsRecursiveEavReverseMigrationSql as d, parseLegacyMultipleValueJson as f, legacyFieldGroupToFinalDefinition as g, FieldDefinitionReference as h, FieldsRecursiveEavMigrationPlan as i, Facet as j, FIELD_KEY_RE as k, fieldPath as l, snapshotFlatFieldsCorpus as m, FIELDS_RECURSIVE_EAV_MIGRATION_ID as n, canonicalFieldsMigrationHash as o, planFieldsRecursiveEavMigration as p, SelectField as q, FieldsMigrationCorpusCheckpoint as r, escapeFieldPathSegment as s, fieldsMigrationSql as t, fieldsRecursiveEavForwardMigrationSql as u, materializeLegacyFieldDefinitionVersion as v, DateField as w, BaseField as x, referencedFieldDefinitionVersions as y, MediaField as z };