dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
214 lines (213 loc) • 8.11 kB
TypeScript
/**
* @debt circular "Remove & prevent imports from entity to schema"
*/
import type { UpdateValueInput } from '../../entity/actions/update/types.js';
import type { Paths, SchemaAction, ValidValue } from '../../schema/index.js';
import type { Transformer } from '../../transformers/index.js';
import type { If, NarrowObject, Overwrite, ValueOrGetter } from '../../types/index.js';
import type { Always, AtLeastOnce, Never, Schema, SchemaRequiredProp, Validator } from '../types/index.js';
import type { ResolveAnySchema } from './resolve.js';
import { AnySchema } from './schema.js';
import type { AnySchemaProps } from './types.js';
type AnySchemer = <PROPS extends Omit<AnySchemaProps, 'castAs'> = {}>(props?: NarrowObject<PROPS>) => AnySchema_<PROPS>;
/**
* Define a new schema of any type
*
* @param props _(optional)_ Attribute Props
*/
export declare const any: AnySchemer;
/**
* Any attribute (warm)
*/
export declare class AnySchema_<PROPS extends AnySchemaProps = AnySchemaProps> extends AnySchema<PROPS> {
/**
* Tag attribute as required. Possible values are:
* - `'atLeastOnce'` _(default)_: Required in PUTs, optional in UPDATEs
* - `'never'`: Optional in PUTs and UPDATEs
* - `'always'`: Required in PUTs and UPDATEs
*
* @param nextRequired SchemaRequiredProp
*/
required<NEXT_IS_REQUIRED extends SchemaRequiredProp = AtLeastOnce>(nextRequired?: NEXT_IS_REQUIRED): AnySchema_<Overwrite<PROPS, {
required: NEXT_IS_REQUIRED;
}>>;
/**
* Shorthand for `required('never')`
*/
optional(): AnySchema_<Overwrite<PROPS, {
required: Never;
}>>;
/**
* Hide attribute after fetch commands and formatting
*/
hidden<NEXT_HIDDEN extends boolean = true>(nextHidden?: NEXT_HIDDEN): AnySchema_<Overwrite<PROPS, {
hidden: NEXT_HIDDEN;
}>>;
/**
* Tag attribute as a primary key attribute or linked to a primary attribute
*/
key<NEXT_KEY extends boolean = true>(nextKey?: NEXT_KEY): AnySchema_<Overwrite<PROPS, {
key: NEXT_KEY;
required: Always;
}>>;
/**
* Rename attribute before save commands
*/
savedAs<NEXT_SAVED_AS extends string | undefined>(nextSavedAs: NEXT_SAVED_AS): AnySchema_<Overwrite<PROPS, {
savedAs: NEXT_SAVED_AS;
}>>;
/**
* Cast attribute TS type
*/
castAs<NEXT_CAST_AS>(nextCastAs?: NEXT_CAST_AS): AnySchema_<Overwrite<PROPS, {
castAs: NEXT_CAST_AS;
}>>;
/**
* Transform the attribute value in PUT commands OR Primary Key computing if attribute is tagged as key
*/
transform<TRANSFORMER extends Transformer<unknown, ResolveAnySchema<this>>>(transform: TRANSFORMER): AnySchema_<Overwrite<PROPS, {
transform: TRANSFORMER;
}>>;
/**
* Provide a default value for attribute in Primary Key computing
*
* @param nextKeyDefault `keyAttributeInput | (() => keyAttributeInput)`
*/
keyDefault(nextKeyDefault: ValueOrGetter<ValidValue<this, {
mode: 'key';
}>>): AnySchema_<Overwrite<PROPS, {
keyDefault: unknown;
}>>;
/**
* Provide a default value for attribute in PUT commands
*
* @param nextPutDefault `putAttributeInput | (() => putAttributeInput)`
*/
putDefault(nextPutDefault: ValueOrGetter<ValidValue<this>>): AnySchema_<Overwrite<PROPS, {
putDefault: unknown;
}>>;
/**
* Provide a default value for attribute in UPDATE commands
*
* @param nextUpdateDefault `updateAttributeInput | (() => updateAttributeInput)`
*/
updateDefault(nextUpdateDefault: ValueOrGetter<UpdateValueInput<this, {
filled: true;
}>>): AnySchema_<Overwrite<PROPS, {
updateDefault: unknown;
}>>;
/**
* Provide a default value for attribute in PUT commands OR Primary Key computing if attribute is tagged as key
*
* @param nextDefault `key/putAttributeInput | (() => key/putAttributeInput)`
*/
default(nextDefault: ValueOrGetter<If<PROPS['key'], ValidValue<this, {
mode: 'key';
}>, ValidValue<this>>>): If<PROPS['key'], AnySchema_<Overwrite<PROPS, {
keyDefault: unknown;
}>>, AnySchema_<Overwrite<PROPS, {
putDefault: unknown;
}>>>;
/**
* Provide a **linked** default value for attribute in Primary Key computing
*
* @param nextKeyLink `keyAttributeInput | ((keyInput) => keyAttributeInput)`
*/
keyLink<SCHEMA extends Schema>(nextKeyLink: (keyInput: ValidValue<SCHEMA, {
mode: 'key';
defined: true;
}>) => ValidValue<this, {
mode: 'key';
}>): AnySchema_<Overwrite<PROPS, {
keyLink: unknown;
}>>;
/**
* Provide a **linked** default value for attribute in PUT commands
*
* @param nextPutLink `putAttributeInput | ((putItemInput) => putAttributeInput)`
*/
putLink<SCHEMA extends Schema>(nextPutLink: (putItemInput: ValidValue<SCHEMA, {
defined: true;
}>) => ValidValue<this>): AnySchema_<Overwrite<PROPS, {
putLink: unknown;
}>>;
/**
* Provide a **linked** default value for attribute in UPDATE commands
*
* @param nextUpdateLink `unknown | ((updateItemInput) => updateAttributeInput)`
*/
updateLink<SCHEMA extends Schema>(nextUpdateLink: (updateItemInput: UpdateValueInput<SCHEMA, {
defined: true;
extended: false;
}, Paths<SCHEMA>>) => UpdateValueInput<this, {
filled: true;
}>): AnySchema_<Overwrite<PROPS, {
updateLink: unknown;
}>>;
/**
* Provide a **linked** default value for attribute in PUT commands OR Primary Key computing if attribute is tagged as key
*
* @param nextLink `key/putAttributeInput | (() => key/putAttributeInput)`
*/
link<SCHEMA extends Schema>(nextLink: (keyOrPutItemInput: If<PROPS['key'], ValidValue<SCHEMA, {
mode: 'key';
defined: true;
}>, ValidValue<SCHEMA, {
defined: true;
}>>) => If<PROPS['key'], ValidValue<this, {
mode: 'key';
}>, ValidValue<this>>): If<PROPS['key'], AnySchema_<Overwrite<PROPS, {
keyLink: unknown;
}>>, AnySchema_<Overwrite<PROPS, {
putLink: unknown;
}>>>;
/**
* Provide a custom validator for attribute in Primary Key computing
*
* @param nextKeyValidator `(keyAttributeInput) => boolean | string`
*/
keyValidate(nextKeyValidator: Validator<ValidValue<this, {
mode: 'key';
defined: true;
}>, this>): AnySchema_<Overwrite<PROPS, {
keyValidator: Validator;
}>>;
/**
* Provide a custom validator for attribute in PUT commands
*
* @param nextPutValidator `(putAttributeInput) => boolean | string`
*/
putValidate(nextPutValidator: Validator<ValidValue<this, {
defined: true;
}>, this>): AnySchema_<Overwrite<PROPS, {
putValidator: Validator;
}>>;
/**
* Provide a custom validator for attribute in UPDATE commands
*
* @param nextUpdateValidator `(updateAttributeInput) => boolean | string`
*/
updateValidate(nextUpdateValidator: Validator<UpdateValueInput<this, {
filled: true;
}>, this>): AnySchema_<Overwrite<PROPS, {
updateValidator: Validator;
}>>;
/**
* Provide a custom validator for attribute in PUT commands OR Primary Key computing if attribute is tagged as key
*
* @param nextValidator `(key/putAttributeInput) => boolean | string`
*/
validate(nextValidator: Validator<If<PROPS['key'], ValidValue<this, {
mode: 'key';
defined: true;
}>, ValidValue<this, {
defined: true;
}>>, this>): If<PROPS['key'], AnySchema_<Overwrite<PROPS, {
keyValidator: Validator;
}>>, AnySchema_<Overwrite<PROPS, {
putValidator: Validator;
}>>>;
clone<NEXT_PROPS extends AnySchemaProps = {}>(nextProps?: NarrowObject<NEXT_PROPS>): AnySchema_<Overwrite<PROPS, NEXT_PROPS>>;
build<ACTION extends SchemaAction<this> = SchemaAction<this>>(Action: new (schema: this) => ACTION): ACTION;
}
export {};