import { format } from "date-fns-tz"; import { type ComponentPublicInstance } from "vue"; import type { ClassType, Property, PropNames, Value, EnumValue, PrimitiveValue, DateValue, CollectionValue, DataSourceType, ModelValue, ObjectValue, FileValue, ModelType, BinaryValue, UnknownValue, BooleanValue, NumberValue, StringValue, ForeignKeyProperty, TypeDiscriminatorToType, EnumType, ObjectType } from "./metadata.js"; import { type VueInstance } from "./util.js"; /** Populated by generated code in order to perform lookups of actual model types * using metadata names as inputs to the lookup. `MetadataToModelType` is recommended for lookups. */ export interface ModelTypeLookup { } /** Populated by generated code in order to perform lookups of actual enum types * using metadata names as inputs to the lookup. `MetadataToModelType` is recommended for lookups. */ export interface EnumTypeLookup { } /** * Maps value or type metadata to its corresponding concrete model type implementation. */ export type MetadataToModelType = TValue extends ModelType | ObjectType ? TValue["name"] extends keyof ModelTypeLookup ? ModelTypeLookup[TValue["name"]] : any : TValue extends EnumType ? TValue["name"] extends keyof EnumTypeLookup ? EnumTypeLookup[TValue["name"]] : any : TValue extends CollectionValue ? Array> : TValue extends ModelValue | EnumValue ? MetadataToModelType : TypeDiscriminatorToType; /** Maps value metadata to its corresponding concrete model type implementation. * Foreign key values are mapped to the type of their referenced principal entity. */ export type ValueOrFkToModelType = TValue extends ForeignKeyProperty ? MetadataToModelType : MetadataToModelType; /** * Represents a model with metadata information. */ export interface Model { readonly $metadata: TMeta; } /** * Represents a data source with metadata information and parameter values. */ export interface DataSource { readonly $metadata: TMeta; } declare abstract class Visitor { visitValue(value: any, meta: Value): TValue | TArray | TObject; abstract visitObject(value: any, meta: ClassType): TObject; protected abstract visitCollection(value: any[], meta: CollectionValue): TArray; protected abstract visitPrimitiveValue(value: any, meta: PrimitiveValue): TValue; protected abstract visitDateValue(value: any, meta: DateValue): TValue; protected abstract visitFileValue(value: any, meta: FileValue): TValue; protected abstract visitBinaryValue(value: any, meta: BinaryValue): TValue; protected abstract visitEnumValue(value: any, meta: EnumValue): TValue; protected abstract visitUnknownValue(value: any, meta: UnknownValue): TValue; } /** * Attempts to change the input value into a correctly-typed * result given some metadata describing the desired result. * Values that cannot be converted will throw an error. */ export declare function parseValue(value: null | undefined, meta: Value): null; export declare function parseValue(value: any, meta: StringValue): null | string; export declare function parseValue(value: any, meta: NumberValue): null | number; export declare function parseValue(value: any, meta: BooleanValue): null | boolean; export declare function parseValue(value: any, meta: EnumValue): null | number | string; export declare function parseValue(value: any, meta: DateValue): null | Date; export declare function parseValue(value: any, meta: FileValue): null | Blob | File; export declare function parseValue(value: any, meta: BinaryValue): null | Uint8Array | string; export declare function parseValue(value: any, meta: ModelValue): null | object; export declare function parseValue(value: any, meta: ObjectValue): null | object; export declare function parseValue(value: any, meta: ClassType): null | object; export declare function parseValue(value: any, meta: PrimitiveValue): null | string | number | boolean; export declare function parseValue(value: any, meta: UnknownValue): null | unknown; export declare function parseValue(value: any[], meta: CollectionValue): Array; export declare function parseValue(value: any, meta: Value | ClassType): any; /** * Transforms a given object with data properties into a valid implementation of TModel. * This function mutates its input and all descendent properties of its input - it does not map to a new object. * @param value The object with data properties that should be converted to a TModel * @param metadata The metadata describing the TModel that is desired */ export declare function convertToModel, TMeta extends ClassType = TModel["$metadata"]>(object: { [k: string]: any; }, metadata: TMeta): TModel; /** * Transforms a raw value into a valid implementation of a model value. * This function mutates its input and all descendent properties of its input - it does not map to a new object. * @param value The value that should be converted * @param metadata The metadata describing the value */ export declare function convertToModel(value: any, metadata: Value): any; export { convertToModel as convertValueToModel }; /** * Maps the given object with data properties into a valid implementation of TModel. * This function returns a new copy of its input and all descendent properties of its input - it does not mutate its input. * @param object The object with data properties that should be mapped to a TModel * @param metadata The metadata describing the TModel that is desired */ export declare function mapToModel, TMeta extends ClassType = TModel["$metadata"]>(object: { [k: string]: any; }, metadata: TMeta): TModel; /** * Maps a raw value into a valid implementation of a model value. * This function returns a new copy of its input and all descendent properties of its input - it does not mutate its input. * @param value The value that should be converted * @param metadata The metadata describing the value */ export declare function mapToModel(value: any, metadata: Value): any; export { mapToModel as mapValueToModel }; /** Visitor that maps a model to a DTO. * A DTO in this case is a POJO that is suitable for JSON stringification * for purposes of transport via an HTTP API. */ declare class MapToDtoVisitor extends Visitor { private maxObjectDepth; private depth; visitObject(value: any, meta: ClassType): object | null | undefined; protected visitCollection(value: any[] | null, meta: CollectionValue): any[] | null | undefined; protected visitDateValue(value: any, meta: DateValue): string | null; protected visitFileValue(value: any, meta: FileValue): undefined; protected visitBinaryValue(value: any, meta: BinaryValue): string | null; protected visitPrimitiveValue(value: any, meta: PrimitiveValue): string | number | boolean | null; protected visitEnumValue(value: any, meta: EnumValue): string | number | null; protected visitUnknownValue(value: any, meta: UnknownValue): any; /** * Create a new DTO mapper, allowing recursive mapping up to the specified depth. * @param maxObjectDepth The maximum depth to serialize objects and collections at. * Any property with `propMeta.dontSerialize == true` will always be ignored, regardless of depth. */ constructor(maxObjectDepth?: number); } /** * Maps the given object to a POJO suitable for JSON serialization. * Will not serialize child objects or collections whose metadata includes `dontSerialize`. * @param object The object to map. */ export declare function mapToDto>(object: T | null | undefined): null | undefined | ReturnType; /** * Maps the given value to a representation suitable for JSON serialization. * Will not serialize child objects or collections whose metadata includes `dontSerialize`. * @param value The value to map. * @param metadata The metadata that describes the value. */ export declare function mapToDto(value: any, metadata: Value): null | ReturnType; export { mapToDto as mapValueToDto }; /** * Maps the given object to a POJO suitable for JSON serialization. * Will not serialize child objects or collections whose metadata includes `dontSerialize`. * @param object The object to map. * @param props A whitelisted set of props to include from the mapped object. * Unspecified props will be ignored. If null or undefined, all props will be included. */ export declare function mapToDtoFiltered>(object: T | null | undefined, props?: PropNames[] | null): object | null; export interface DisplayOptions { /** Date format options. One of: * - A UTS#35 date format string (https://date-fns.org/docs/format) * - An object with options for https://date-fns.org/docs/format or https://github.com/marnusw/date-fns-tz#format, including a string `format` for the format itself. If a `timeZone` option is provided per https://github.com/marnusw/date-fns-tz#format, the date being formatted will be converted to that timezone. * - An object with options for https://date-fns.org/docs/formatDistance */ format?: string | ({ /** A UTS#35 date format string (https://date-fns.org/docs/format) */ format: string; } & Parameters[2]) | { /** Format date with https://date-fns.org/docs/formatDistanceToNow */ distance: true; /** Append/prepend `'in'` or `'ago'` if date is after/before now. Default `true`. */ addSuffix?: boolean; /** Include detail smaller than one minute. Default `false`. */ includeSeconds?: boolean; }; collection?: { /** The maximum number of items to display individually. * When there are more than this number of items, the count of items will be displayed instead. * Default `5`. * */ enumeratedItemsMax?: number; /** The separator to place between enumerated items. Default `', '` */ enumeratedItemsSeparator?: string; }; } /** Set the timezone that will be used to display dates * via the `modelDisplay`/`propDisplay`/`valueDisplay` functions * if no other timezone is provided as a parameter, * and for c-datetime-picker in coalesce-vue-vuetify. * @param tzName An IANA tzdb timezone name, or null to clear this setting. */ export declare function setDefaultTimeZone(tzName: string | null): void; /** Returns the current default timezone as provided to `setDefaultTimeZone`. */ export declare function getDefaultTimeZone(): string | null; /** * Given a model instance, return a string representation of the instance suitable for display. * @param item The model instance to return a string representation of */ export declare function modelDisplay, TMeta extends ClassType>(item: T, options?: DisplayOptions): string | null; /** * Given a model instance and a descriptor of a property on the instance, * return a string representation of the property suitable for display. * @param item An instance of the model that holds the property to be displayed * @param prop The property to be displayed - either the name of a property or a property metadata object. */ export declare function propDisplay, TMeta extends ClassType>(item: T, prop: Property | PropNames, options?: DisplayOptions | null): string | null; /** * Given a value and metadata which describes that value, * return a string representation of the value suitable for display. * @param value Any value which is valid for the metadata provided. * @param metadata The metadata which describes the value given. */ export declare function valueDisplay(value: any, metadata: Value, options?: DisplayOptions | null): string | null; export interface BindToQueryStringOptions { /** The key in the query string that holds the bound value. */ queryKey?: string; /** Convert the query string value to the model value. */ parse?: (v: string) => TValue; /** Convert the bound value to a string representation to store in the query string. */ stringify?: (v: NonNullable) => string | null | undefined; /** Controls whether changes are pushed as new history state entries, or replace the current history entry. */ mode?: "push" | "replace"; } /** * Binds a value on an object, or the value of a ref, to the query string. * `parse`/`stringify` are auto-configured for Models, Data Sources, and caller args. * * For Composition API, use {@link useBindToQueryString} instead. * * @example * // Component data property: * bindToQueryString(this, this, 'activeTab'); * // List parameters: * bindToQueryString(this, list, '$page'); * bindToQueryString(this, list, '$search'); * bindToQueryString(this, list.$params, 'pageSize'); * // Data source parameters: * bindToQueryString(this, dataSource, 'myParameter'); * // Caller args: * bindToQueryString(this, vm.myCaller.args, 'startDate'); * bindToQueryString(this, vm.myCaller.args, 'searchCriteria'); * // Plain ref: * bindToQueryString(this, activeTab, 'tab'); * // Ref with custom options: * bindToQueryString(this, enumTab, { queryKey: 'tab', parse: ..., stringify: ... }); */ export declare function bindToQueryString(vue: VueInstance, obj: T, key: TKey, options?: BindToQueryStringOptions): void; export declare function bindToQueryString(vue: VueInstance, ref: { value: TValue; }, /** The key on the query to bind to. Shorthand for specifying via options object */ queryKey: Exclude): void; export declare function bindToQueryString(vue: VueInstance, ref: { value: TValue; }, options: BindToQueryStringOptions & { queryKey: string; }): void; /** * Composition API wrapper for {@link bindToQueryString}. Must be called inside `setup()`. * * @example * // List parameters: * useBindToQueryString(list, '$page'); * useBindToQueryString(list, '$search'); * useBindToQueryString(list.$params, 'pageSize'); * // Data source parameters: * useBindToQueryString(dataSource, 'myParameter'); * // Caller args: * useBindToQueryString(vm.myCaller.args, 'startDate'); * useBindToQueryString(vm.myCaller.args, 'searchCriteria'); * // Plain ref: * useBindToQueryString(activeTab, 'tab'); * // Ref with custom options: * useBindToQueryString(enumTab, { queryKey: 'tab', parse: ..., stringify: ... }); */ export declare function useBindToQueryString(obj: T, key: TKey, options?: BindToQueryStringOptions): void; export declare function useBindToQueryString(ref: { value: TValue; }, /** The key on the query to bind to. Shorthand for specifying via options object */ queryKey: Exclude): void; export declare function useBindToQueryString(ref: { value: TValue; }, options: BindToQueryStringOptions & { queryKey: string; }): void; export declare function bindKeyToRouteOnCreate(vue: VueInstance, model: Model, routeParamName?: string, keepQuery?: boolean, routeName?: ComponentPublicInstance["$route"]["name"]): void; export declare function useBindKeyToRouteOnCreate(model: Model, routeParamName?: string, keepQuery?: boolean, routeName?: ComponentPublicInstance["$route"]["name"]): void; export declare function reactiveDataSource(source: T): T;