import { Condition } from './Condition'; import { Model } from './Model'; import { Table } from './Table'; import { Update } from './Update'; /** * Collection of functions for constructing a Model schema with Field objects and the Field classes. * @example [examples/Fields.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Fields.ts}, (imports: [examples/Table.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Table.ts}) * ```typescript * [[include:Fields.ts]] * ``` * @public */ export declare class Fields { /** * Creates a string field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldString object. */ static string(options?: Fields.BaseOptions): Fields.FieldString; /** * Creates a number field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldNumber object. */ static number(options?: Fields.BaseOptions): Fields.FieldNumber; /** * Creates a binary field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldBinary object. */ static binary(options?: Fields.BaseOptions): Fields.FieldBinary; /** * Creates a boolean field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldBoolean object. */ static boolean(options?: Fields.BaseOptions): Fields.FieldBoolean; /** * Creates a string set field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldStringSet object. */ static stringSet(options?: Fields.SetOptions): Fields.FieldStringSet; /** * Creates a number set field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldNumberSet object. */ static numberSet(options?: Fields.SetOptions): Fields.FieldNumberSet; /** * Creates a binary set field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldBinarySet object. */ static binarySet(options?: Fields.SetOptions): Fields.FieldBinarySet; /** * Creates a list field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldList object. */ static list(options?: Fields.BaseOptions): Fields.FieldList; /** * Creates a schema based list field object to use in a {@link Model.schema}. * @param V - Interface of model to use for schema. * @param options - Options to initialize field with. * @returns New FieldModelList object. */ static modelList(options: Fields.ModelListOptions): Fields.FieldModelList; /** * Creates a map field object to use in a {@link Model.schema}. * @param options - Options to initialize field with. * @returns New FieldMap object. */ static map(options?: Fields.BaseOptions): Fields.FieldMap; /** * Creates a schema based map field object to use in a {@link Model.schema}. * @param V - Interface of model to use for schema. * @param options - Options to initialize field with. * @returns New FieldModelMap object. */ static modelMap(options: Fields.ModelMapOptions): Fields.FieldModelMap; /** * Creates a schema based map field object to use in a {@link Model.schema}. * @param V - Interface of model to use for schema. * @param options - Options to initialize field with. * @returns New FieldModel object. */ static model(options: Fields.ModelOptions): Fields.FieldModel; /** * Creates a date field object to use in a {@link Model.schema}, stored as a number in the table. * @param options - Options to initialize field with. * @returns New FieldDate object. */ static date(options?: Fields.BaseOptions): Fields.FieldDate; /** * Creates a hidden field object to use in a {@link Model.schema}, which doesn't get set in the table. * @returns New FieldHidden object. */ static hidden(): Fields.FieldHidden; /** * Creates a split field object to use in a {@link Model.schema}. which can be used to split a model property into two or more * table attributes. This is commonly used as an model id property which gets slit into the table's partition and sort keys. * Example: Model schema contains 'id: Fields.split(\{ aliases: ['P','S'] \})' and when id = 'guid.date' the field will split the id value * in to the table primary key of \{ P: 'guid', S: 'date' \} * * @example [examples/Fields.split.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Fields.split.ts}, (imports: [examples/Table.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Table.ts}) * ```typescript * [[include:Fields.split.ts]] * ``` * * @param options - Options to initialize field with. * @returns New FieldSplit object. */ static split(options: Fields.SplitOptions): Fields.FieldSplit; /** * Creates an indices based slots composite field object which can then return FieldCompositeSlot by index to use in a {@link Model.schema}. * * @example [examples/Fields.composite.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Fields.composite.ts}, (imports: [examples/Table.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Table.ts}) * ```typescript * [[include:Fields.composite.ts]] * ``` * * @param options - Options to initialize field with. * @returns New composite object with array field slots. */ static composite(options: Fields.CompositeOptions): Fields.FieldComposite; /** * Creates an name based slots composite field object which can then return FieldCompositeSlot by name to use in a {@link Model.schema}. * * @example [examples/Fields.compositeNamed.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Fields.compositeNamed.ts}, (imports: [examples/Table.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Table.ts}) * ```typescript * [[include:Fields.compositeNamed.ts]] * ``` * * @param T - Map of slot names to index * @param options - Options to initialize field with. * @returns New composite object with named field slots. */ static compositeNamed(options: Fields.CompositeNamedOptions): Fields.FieldCompositeNamed; /** * Creates a field that adds the Model name to a table attribute. * * @example [examples/Fields.type.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Fields.type.ts}, (imports: [examples/Table.ts]{@link https://github.com/jasoncraftscode/dynamodb-datamodel/tree/main/examples/Table.ts}) * ```typescript * [[include:Fields.type.ts]] * ``` * * @param options - Options to initialize field with. * @returns New FieldType object. */ static type(options?: Fields.TypeOptions): Fields.FieldType; /** * Creates a field that add a created date to a table attribute. * @param options - Options to initialize field with. * @returns New FieldCreatedDate object. */ static createdDate(options?: Fields.CreatedDateOptions): Fields.FieldCreatedDate; /** * Creates a field that adds an updated date to a table attribute. * @param options - Options to initialize field with. * @returns New FieldUpdatedDate object. */ static updatedDate(options?: Fields.UpdateDateOptions): Fields.FieldUpdatedDate; /** * Creates a field that add a created date as a number in seconds since UTC UNIX epoch time (January 1, 1970 00:00:00 UTC) to a table attribute. * @param options - Options to initialize field with. * @returns New FieldCreatedNumberDate object. */ static createdNumberDate(options?: Fields.CreatedDateOptions): Fields.FieldCreatedNumberDate; /** * Creates a field that adds an updated date as a number in seconds since UTC UNIX epoch time (January 1, 1970 00:00:00 UTC) to a table attribute. * @param options - Options to initialize field with. * @returns New FieldUpdatedNumberDate object. */ static updatedNumberDate(options?: Fields.UpdateNumberDateOptions): Fields.FieldUpdatedNumberDate; /** * Creates a field that will be incremented with each update. It also supports preventing an update if * the table attribute doesn't match the model property. * @param options - Options to initialize field with. * @returns New FieldRevision object. */ static revision(options?: Fields.RevisionOptions): Fields.FieldRevision; } /** * Is also a namespace for scoping Condition based interfaces and types. * @public * */ export declare namespace Fields { /** * Used in TableContext to determine the scope the action is executed in. * @param single - Action will be preformed via the single item API. * @param batch - Action will be preformed via the batch read/write API. * @param transact - TAction will be preformed via the transaction read/write API. */ type ActionScope = 'single' | 'batch' | 'transact'; /** * Context object passed to {@link Field.toTable} and {@link Field.toTableUpdate} to allow the fields to know */ interface TableContext { /** * Type of action that will be run after all field's {@link Field.toTable} or {@link Field.toTableUpdate} are called. */ action: Table.ItemActions; /** * The scope the action is executed in. */ scope: ActionScope; /** * Array of conditions to resolve and joined with AND conditions, then set as the ConditionExpression * param before calling DynamoDB method. */ conditions: Condition.Resolver[]; /** * Options for the current {@link Model} method being called. */ options: Table.BaseOptions; /** * The model that is calling the field's {@link Field.toTable} or {@link Field.toTableUpdate} methods. */ model: Model.ModelBase; } /** * Context object passed to {@link Field.toModel} to allow the fields to know about the broader context * and provide more complex behavior. */ interface ModelContext { /** * Type of action that ran before all field's {@link Field.toModel} are called. */ action: Table.ItemActions; /** * Options for the current {@link Model} method being called. */ options: Table.BaseOptions; /** * The model that is calling the field's {@link Field.toModel} method. */ model: Model.ModelBase; } /** * Defines the table attributes used by a field. */ interface AttributeDefinition { /** * The type of the table attribute the field writes. */ type: Table.AttributeTypes; } /** * Defines the set of table attributes that are used by a field. */ type AttributesSchema = { [key: string]: AttributeDefinition; }; /** * The core interface all Fields implement and is used by {@link Model} to basically map model data * to and from the table data. * @example Custom Field * ```typescript * class CustomField extends Field { * } * ``` */ interface Field { /** * Initialize the field with the field name from the Model's schema and the model. * @param name - Name of the model attribute this field is set on. * @param model - Model this field is associated with. */ init(name: string, model: Model): void; /** * Method called **after** calling into the table object to read and write to the table. This method will convert the * table data into model data. * @param name - Name of the model attribute this field is associated with (generally same as {@link init} name argument). * @param tableData - Data from the table that needs to be mapped to the model data. * @param modelData - Data object for the model that this method will append to. * @param context - Current context this method is being called in. */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** * Method called **before** calling into the table object to read and write to the table. This method will convert the model data * into table data and append read or write conditions. * @param name - Name of the model attribute this field is associated with (generally same as {@link init} name argument). * @param modelData - Data from the model that needs to be mapped to the table data. * @param tableData - Data object for the table that this method will append to. * @param context - Current context this method is being called in. */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** * Method called **before** calling into the table object to update the table. This method will convert the model data * into table data and append read or write conditions. * * * Note: Several Fields will just call toTable from toTableUpdate if they don't support any special update syntax. * @param name - Name of the model attribute this field is associated with (generally same as {@link init} name argument) * @param modelData - Data from the model that needs to be mapped to the table data. * @param tableData - Data object for the table that this method will append to. * @param context - Current context this method is being called in. */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; } /** * Options used for creating {@link FieldBase}. * @param V - Type used for default value. */ interface BaseOptions { /** * Table attribute to map this Model property to. */ alias?: string; /** * Value or function to get value from to use when the Model property is empty. */ default?: V | FieldBase.DefaultFunction; } /** * Base Field implementation used by many of the basic field types. * @param V - Type for the value of the field. * @public */ class FieldBase implements Field { /** * Model name of the field, set by init function in Model or Field constructor. */ name?: string; /** * Table attribute to map this Model property to. */ alias?: string; /** * Value or function to get value from to use when the Model property is empty. */ default?: V | FieldBase.DefaultFunction; /** * Initialize the Field. * @param options - Options to initialize FieldBase with. */ constructor(options?: BaseOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.init} */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; /** * Name of table attribute. Used in Condition based Field methods. */ tableName(): string; /** * Get the default value to use in toTable if no value it set. * @param name - Model property name associated with field (passed into toTable). * @param modelData - Data from the model that to reference for default. * @param context - Current context this method is being called in. * @returns Default value to use. */ getDefault(name: string, modelData: Model.ModelData, context: TableContext): V | undefined; } /** * Is also a namespace for scoping FieldBase based interfaces and types. * @public */ namespace FieldBase { /** * Function to get the default value when the model property is missing. * @param T - Value to return from default function. * @param name - Name of the model attribute this field is associated with (generally same as {@link init} name argument). * @param modelData - Data from the model that needs to be mapped to the table data. * @param context - Current context this method is being called in. * @returns default value for the model property if it is missing. */ type DefaultFunction = (name: string, modelData: Model.ModelData, context: TableContext) => T; } /** * Base class for model property fields. * @param V - Type this field represents used in Condition methods. */ class FieldExpression extends FieldBase { /** * Helper method that just calls {@link Condition.path} with tableName() as value param. * See {@link Condition.path} for more info and examples. */ path(): Condition.ValueResolver; /** * Helper method that just calls {@link Condition.eq} with tableName() as left param. * See {@link Condition.eq} for more info and examples. */ eq(v: Condition.Value): Condition.Resolver; /** * Helper method that just calls {@link Condition.ne} with tableName() as left param. * See {@link Condition.ne} for more info and examples. */ ne(v: Condition.Value): Condition.Resolver; /** * Helper method that just calls {@link Condition.lt} with tableName() as left param. * See {@link Condition.lt} for more info and examples. */ lt(v: Condition.Value): Condition.Resolver; /** * Helper method that just calls {@link Condition.le} with tableName() as left param. * See {@link Condition.le} for more info and examples. */ le(v: Condition.Value): Condition.Resolver; /** * Helper method that just calls {@link Condition.gt} with tableName() as left param. * See {@link Condition.gt} for more info and examples. */ gt(v: Condition.Value): Condition.Resolver; /** * Helper method that just calls {@link Condition.ge} with tableName() as left param. * See {@link Condition.ge} for more info and examples. */ ge(v: Condition.Value): Condition.Resolver; /** * Helper method that just calls {@link Condition.between} with tableName() as path param. * See {@link Condition.between} for more info and examples. */ between(from: Condition.Value, to: Condition.Value): Condition.Resolver; /** * Helper method that just calls {@link Condition.in} with tableName() as path param. * See {@link Condition.in} for more info and examples. */ in(v: Condition.Value[]): Condition.Resolver; /** * Helper method that just calls {@link Condition."type"} with tableName() as path param. * See {@link Condition."type"} for more info and examples. */ type(type: Table.AttributeTypes): Condition.Resolver; /** * Helper method that just calls {@link Condition.exists} with tableName() as path param. * See {@link Condition.exists} for more info and examples. */ exists(): Condition.Resolver; /** * Helper method that just calls {@link Condition.notExists} with tableName() as path param. * See {@link Condition.notExists} for more info and examples. */ notExists(): Condition.Resolver; } /** * See {@link Fields.string} for details. */ class FieldString extends FieldExpression { /** * Helper method that just calls {@link Condition.size} with tableName() as path param. * See {@link Condition.size} for more info and examples. */ size(): Condition.ValueResolver; /** * Helper method that wraps {@link Condition.contains}. * See {@link Condition.contains} for more info and examples. */ contains(value: string): Condition.Resolver; /** * Helper method that wraps {@link Condition.beginsWith}. * See {@link Condition.beginsWith} for more info and examples. */ beginsWith(value: string): Condition.Resolver; } /** * See {@link Fields.number} for details. */ class FieldNumber extends FieldExpression { } /** * See {@link Fields.binary} for details. */ class FieldBinary extends FieldExpression { /** * Helper method that just calls {@link Condition.size} with tableName() as path param. * See {@link Condition.size} for more info and examples. */ size(): Condition.ValueResolver; } /** * See {@link Fields.boolean} for details. */ class FieldBoolean extends FieldExpression { } /** * See {@link Fields.null} for details. */ class FieldNull extends FieldExpression { } interface SetOptions extends BaseOptions { /** * Defines the schema for the list type. */ useArrays?: boolean; } /** * Generic set property field is base class for {@link FieldStringSet}, {@link FieldStringSet}, and {@link FieldStringSet}. */ class FieldSet extends FieldExpression { useArrays?: boolean; /** * Initialize the Field. * @param options - Options to initialize FieldBase with. */ constructor(options?: SetOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; /** * Helper method that just calls {@link Condition.size} with tableName() as path param. * See {@link Condition.size} for more info and examples. */ size(): Condition.ValueResolver; /** * Helper method that just calls {@link Condition.contains} with tableName() as path param. * See {@link Condition.contains} for more info and examples. */ contains(value: string): Condition.Resolver; } /** * See {@link Fields.stringSet} for details. */ class FieldStringSet extends FieldSet { } /** * See {@link Fields.numberSet} for details. */ class FieldNumberSet extends FieldSet { } /** * See {@link Fields.binarySet} for details. */ class FieldBinarySet extends FieldSet { } /** * See {@link Fields.list} for details. */ class FieldList extends FieldExpression { /** * Helper method that just calls {@link Condition.size} with tableName() as path param. * See {@link Condition.size} for more info and examples. */ size(): Condition.ValueResolver; } /** * FieldModelList constructor options. */ interface ModelListOptions extends BaseOptions { /** * Defines the schema for the list type. */ schema: Model.ModelSchemaT; } /** * See {@link Fields.modelList} for details. */ class FieldModelList extends FieldList { /** * Defines the schema for the list type. */ schema: Model.ModelSchemaT; /** * Initializes FieldModelList with the options. * @param options - Options to initialize FieldModelList with. */ constructor(options: ModelListOptions); /** * Initializes the schema property. * See {@link Field.init} for more information. */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; } /** * See {@link Fields.map} for details. */ class FieldMap extends FieldExpression<{ [key: string]: V; }> { /** * Helper method that just calls {@link Condition.size} with tableName() as path param. * See {@link Condition.size} for more info and examples. */ size(): Condition.ValueResolver; } /** * Condition.Expression used for nested conditions */ /** * FieldModelMap constructor options. * @param V - Type of the map value. */ interface ModelMapOptions extends BaseOptions<{ [key: string]: V; }> { /** * Model schema to use as the value for the Map */ schema: Model.ModelSchemaT; } /** * See {@link Fields.modelMap} for details. */ class FieldModelMap extends FieldMap { /** * Model schema to use as the value for the Map */ schema: Model.ModelSchemaT; /** * Constructs a FieldModelMap object with options. * @param options - Options to initialize model map with. */ constructor(options: ModelMapOptions); /** * Initializes the schema property. * See {@link Field.init} for more information. */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; } /** * FieldModel constructor options. */ interface ModelOptions extends BaseOptions { /** * Model schema to use for the FieldModel */ schema: Model.ModelSchemaT; } /** * See {@link Fields.model} for details. */ class FieldModel extends FieldExpression { /** * Model schema to use for writing to this field */ schema: Model.ModelSchemaT; /** * Initialize the class with options. * @param options - Options to initialize the class with. */ constructor(options: ModelOptions); /** * Initializes the schema property. * See {@link Field.init} for more information. */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; /** * Helper method that just calls {@link Condition.size} with tableName() as path param. * See {@link Condition.size} for more info and examples. */ size(): Condition.ValueResolver; } /** * See {@link Fields.date} for details. */ class FieldDate extends FieldBase { /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; } /** * See {@link Fields.hidden} for details. * Hidden property field. Used to avoid writing a property to the DynamoDb table. */ class FieldHidden implements Fields.Field { /** @inheritDoc {@inheritDoc (Fields:namespace).Field.init} */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: Fields.TableContext): void; } /** * Composite slot property field, comes from the call to createSlots on FieldCompositeSlot. */ class FieldCompositeSlot implements Field { /** * Model name of the field, set by init function in Model or Field constructor. */ name?: string; /** * Composite object used to determine some functionality like delimiter. */ composite: FieldComposite; /** * Index number of this slot in the slots array. */ slot: number; /** * All of the slots for the composite field of a model. */ slots: FieldCompositeSlot[]; /** * Initializes this class the required parameters. * @param composite - Composite object used to determine some functionality like delimiter. * @param slot - Index number of this slot in the slots array. * @param slots - All of the slots for the composite field of a model. */ constructor(composite: FieldComposite, slot: number, slots: FieldCompositeSlot[]); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.init} */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; } /** * Options to construct FieldComposite with. */ interface CompositeOptions { /** * Table attribute name to map this model property to. */ alias: string; /** * Number of model fields (slots) to compose together into a table attribute. */ count?: number; /** * Delimiter to use for when splitting the table attribute in to multiple model fields. */ delimiter?: string; } /** * See {@link Fields.composite} for details. */ class FieldComposite { /** * Table attribute name to map this model property to. */ alias: string; /** * Number of model fields (slots) to compose together into a table attribute. * @defaultValue 2 */ count: number; /** * Delimiter to use for when splitting the table attribute in to multiple model fields. * @defaultValue ';' */ delimiter: string; /** * Initializes the class with options. * @param options - Options to initialize this class with. */ constructor(options: CompositeOptions); /** * Create the field slots to use when defining the schema for a model. * Note: Need to create a new set of field slots for each model that uses this composite definition. * @returns An array of composite slots used for a Model schema. */ createSlots(): FieldCompositeSlot[]; } /** * Defines the map for the named slots for a composite named field. */ type CompositeSlotMap = V & { [P in keyof T]: FieldCompositeSlot; }; /** * Options used when constructing a FieldCompositeNamed. */ interface CompositeNamedOptions extends CompositeOptions { /** * The mapping between the slot name and its index. */ map: T; } /** * See {@link Fields.compositeNamed} for details. */ class FieldCompositeNamed extends FieldComposite { /** * The mapping between the slot name and its index. */ map: T; /** * Initializes this class with options. * @param options - Options to initialize class with. */ constructor(options: CompositeNamedOptions); /** * Create the named field slots to use when defining the schema for a model. * Note: Need to create a new set of field slots for each model that uses this composite definition. * @returns A map of composite slot fields used in the definition of a Model schema. */ createNamedSlots(): CompositeSlotMap; } /** * Options to construct FieldSplit with. */ interface SplitOptions { /** * Array of table attribute names to map this model property to. */ aliases: string[]; /** * Delimiter to use for splitting the model property string. */ delimiter?: string; } /** * See {@link Fields.split} for details. * Note: Currently only supports string table attributes. */ class FieldSplit implements Field { /** * Model name of the field, set by init function in Model or Field constructor. */ name?: string; /** * Array of table attribute names to map this model property to. */ aliases: string[]; /** * Delimiter to use for splitting the model property string, default delimiter is '.'. */ delimiter: string; /** * Initialize this class with options. * @param options - Options to initialize this class with. */ constructor(options: SplitOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.init} */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: TableContext): void; } /** * FieldType constructor options. */ interface TypeOptions { /** * Table attribute to map this Model property to. */ alias?: string; } /** * See {@link Fields."type"} for details. */ class FieldType implements Field { /** * Model name of the field, set by init function in Model or Field constructor. */ name?: string; /** * Table attribute to map this Model property to. */ alias?: string; /** * Initialize the Field. * @param type - Name of type. * @param alias - Table attribute name to map this model property to. */ constructor(options?: TypeOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.init} */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: Fields.ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: Fields.TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: Fields.TableContext): void; } /** * Options for {@link CreatedDate} class constructor. */ interface CreatedDateOptions { /** * Table attribute to map this Model property to. */ alias?: string; /** * Function to get the current date. */ now?: () => Date; } /** * See {@link Fields.createdDate} for details. */ class FieldCreatedDate implements Fields.Field { /** * Model name of the field, set by init function in Model or Field constructor. */ name?: string; /** * Table attribute to map this Model property to. */ alias?: string; /** * Function to get the current date. */ now: () => Date; /** * Initialize this class with options. * @param options - Options to initialize this class with. */ constructor(options?: CreatedDateOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.init} */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: Fields.ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: Fields.TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: Fields.TableContext): void; } /** * Options used when creating {@link FieldUpdatedDate} */ interface UpdateDateOptions { /** * Table attribute to map this Model property to. */ alias?: string; /** * Function to get the current date. */ now?: () => Date; } /** * See {@link Fields.updatedDate} for more details. */ class FieldUpdatedDate implements Fields.Field { /** * Model name of the field, set by init function in Model or Field constructor. */ name?: string; /** * Table attribute to map this Model property to. */ alias?: string; /** * Function to get the current date. */ now: () => Date; /** * Initialize this class with options. * @param options - Options to initialize this class with. */ constructor(options?: UpdateDateOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.init} */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: Fields.ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: Fields.TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: Fields.TableContext): void; } /** * See {@link Fields.createdNumberDate} for more details. */ class FieldCreatedNumberDate extends FieldNumber { /** * Function to get the current date. */ now: () => Date; /** * Initialize this class with options. * @param options - Options to initialize this class with. */ constructor(options?: CreatedDateOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: Fields.TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: Fields.TableContext): void; } /** * Options used when creating {@link FieldUpdatedNumberDate} */ interface UpdateNumberDateOptions { /** * Table attribute to map this Model property to. */ alias?: string; /** * Function to get the current date. */ now?: () => Date; /** * Sets the updated date when item it put. */ writeOnPut?: boolean; /** * Table attribute to use in toModel when value is not present. */ toModelDefaultAlias?: string; } /** * See {@link Fields.updatedNumberDate} for more details. */ class FieldUpdatedNumberDate extends FieldNumber { /** * Function to get the current date. */ now: () => Date; /** * Sets the updated date when item it put. */ writeOnPut?: boolean; /** * Table attribute to use in toModel when value is not present. */ toModelDefaultAlias?: string; /** * Initialize this class with options. * @param options - Options to initialize this class with. */ constructor(options?: UpdateNumberDateOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: Fields.ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: Fields.TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: Fields.TableContext): void; } /** * Options used when creating {@link FieldRevision} */ interface RevisionOptions { /** * Table attribute to map this Model property to. */ alias?: string; /** * Start value for revision. */ start?: number; /** * Require that the revision matches when written to */ matchOnWrite?: boolean; } /** * See {@link Fields.revision} for more details. */ class FieldRevision implements Fields.Field { /** * Model name of the field, set by init function in Model or Field constructor. */ name?: string; /** * Table attribute to map this Model property to. */ alias?: string; /** * Start value for revision. */ start: number; /** * Require that the revision matches when written to */ matchOnWrite?: boolean; /** * Initialize this class with options. * @param options - Options to initialize this class with. */ constructor(options?: RevisionOptions); /** @inheritDoc {@inheritDoc (Fields:namespace).Field.init} */ init(name: string, model: Model): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toModel} */ toModel(name: string, tableData: Table.AttributeValuesMap, modelData: Model.ModelData, context: Fields.ModelContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTable} */ toTable(name: string, modelData: Model.ModelData, tableData: Table.AttributeValuesMap, context: Fields.TableContext): void; /** @inheritDoc {@inheritDoc (Fields:namespace).Field.toTableUpdate} */ toTableUpdate(name: string, modelData: Model.ModelUpdate, tableData: Update.ResolverMap, context: Fields.TableContext): void; } }