import { AnyContentType, ContentType, PermittedTypes } from './contentTypes.js'; import { PropertyGroupKey } from './buildConfig.js'; /** JSON type definitions */ export type JsonPrimitive = string | number | boolean | null; export type JsonObject = { [key: string]: JsonValue; }; export type JsonArray = JsonValue[]; export type JsonValue = JsonPrimitive | JsonObject | JsonArray; /** All possible content type properties */ export type AnyProperty = ArrayProperty | ArrayItems; export type INDEX_TYPE = 'disabled' | 'queryable' | 'searchable'; export type RICHTEXT_PRESET = 'default' | 'expanded' | 'minimal'; /** How a property is displayed in the editing interface. Defaults to `available`. */ export type DISPLAY_MODE = 'available' | 'hidden'; /** A "Base" content type property that includes all common attributes for all content type properties */ type BaseProperty = { format?: string; displayName?: string; description?: string; isRequired?: boolean; isLocalized?: boolean; group?: PropertyGroupKey; sortOrder?: number; indexingType?: INDEX_TYPE; displayMode?: DISPLAY_MODE; }; type WithEnum = { enum?: { value: T; displayName: string; }[]; }; export type ArrayProperty = BaseProperty & { type: 'array'; items: Exclude>; minItems?: number; maxItems?: number; }; /** Represents the content type property "String" */ export type StringProperty = BaseProperty & { type: 'string'; /** * Regular expression. * * @example "\\d\\d\\d\\d-\\d\\d-\\d\\d" */ pattern?: string; minLength?: number; maxLength?: number; } & WithEnum; export type BooleanProperty = BaseProperty & { type: 'boolean'; }; export type BinaryProperty = BaseProperty & { type: 'binary'; }; export type JsonProperty = BaseProperty & { type: 'json'; /** @internal used for type inference only - not a runtime property */ readonly __schema?: TSchema; }; export type DateTimeProperty = BaseProperty & { type: 'dateTime'; minimum?: string; maximum?: string; }; export type RichTextProperty = BaseProperty & { type: 'richText'; editorSettings?: { preset: RICHTEXT_PRESET; }; }; export type UrlProperty = BaseProperty & { type: 'url'; }; export type IntegerProperty = BaseProperty & { type: 'integer'; minimum?: number; maximum?: number; } & WithEnum; export type FloatProperty = BaseProperty & { type: 'float'; minimum?: number; maximum?: number; } & WithEnum; /** Represents type constraints for "content" properties */ type ContentBlock = { contentType?: never; allowedTypes: PermittedTypes[]; restrictedTypes?: PermittedTypes[]; } | { contentType?: never; allowedTypes?: PermittedTypes[]; restrictedTypes: PermittedTypes[]; }; /** Represents type constraints for "contentReference" properties */ type ContentReferenceBlock = { contentType: AnyContentType | ContentType | string; allowedTypes?: never; restrictedTypes?: never; } | ContentBlock; type BaseContentReferenceProperty = BaseProperty & { type: 'contentReference'; }; type BaseContentProperty = BaseProperty & { type: 'content'; }; export type ContentReferenceProperty = BaseContentReferenceProperty & ContentReferenceBlock; export type ContentProperty = BaseContentProperty & ContentBlock; export type ArrayItems = StringProperty | BooleanProperty | BinaryProperty | JsonProperty | DateTimeProperty | RichTextProperty | UrlProperty | IntegerProperty | FloatProperty | ContentReferenceProperty | ContentProperty | ComponentProperty | LinkProperty; /** * Reprensents the content type property "Component". * Note: this is called "Block" in the GUI */ export type ComponentProperty = BaseProperty & { type: 'component'; contentType: T; }; export type LinkProperty = BaseProperty & { type: 'link'; }; export {};