Registry
Serves as a single entry point for the Table's Entities and AccessPatterns (including EntityAccessPatterns):
import { Registry } from 'dynamodb-toolbox/table/actions/registry'
const PokeRegistry = PokeTable.build(Registry)
.registerEntities(PokemonEntity, TrainerEntity, ...)
.registerAccessPatterns({ trainers, pokemonsByTrainerId })
// Get an Entity by `entityName`
PokeRegistry.entities.pokemon
// Get an AccessPattern by key
PokeRegistry.accessPatterns.trainers.query(...)
// Or use the `.query` shorthand
PokeRegistry.query.trainers(...)
The Registry also exposes a .build(...) method compatible with any Table Action. The Entities registered in the Registry are directly provided to the Action::
// π Directly typed as `Pokemon | Trainer`
const { Items } = await PokeRegistry.build(QueryCommand)
.query({ partition: trainerId })
.send()
Methodsβ
registerEntities(...)β
(entities: ENTITIES) => Registry<TABLE, ENTITIES, ACCESS_PATTERNS>
Registers the Table's Entities:
const PokeRegistry = PokeTable.build(Registry)
.registerEntities(PokemonEntity, TrainerEntity, ...)
// Get an Entity by `entityName`
PokeRegistry.entities.pokemon
registerAccessPatterns(...)β
(accessPatterns: ACCESS_PATTERNS) => Registry<TABLE, ENTITIES, ACCESS_PATTERNS>
Registers the Table's AccessPatterns. Accepts both TableAccessPatterns and EntityAccessPatterns:
const PokeRegistry = PokeTable.build(Registry)
.registerAccessPatterns({ trainers, pokemonsByTrainerId })
// Get an AccessPattern by key
PokeRegistry.accessPatterns.trainers.query(...)
// ...or directly use the `.query` shorthand
PokeRegistry.query.trainers(...)
build(...)β
(tableAction?: ACTION) => ACTION<TABLE, ENTITIES>
Builds a Table Action on the provided Table. The Entities registered in the Registry are directly provided to the Action:
// π Directly typed as `Pokemon | Trainer`
const { Items } = await PokeRegistry.build(QueryCommand)
.query({ partition: trainerId })
.send()
Propertiesβ
entitiesβ
Record<string, ENTITIES>
The Entities registered in the Registry, accessible by entityName:
const PokeRegistry = PokeTable.build(Registry)
.registerEntities(PokemonEntity, TrainerEntity, ...)
// Get an Entity by `entityName`
PokeRegistry.entities.pokemon
accessPatternsβ
ACCESS_PATTERNS
The AccessPatterns registered in the Registry:
const PokeRegistry = PokeTable.build(Registry)
.registerAccessPatterns({ trainers, pokemonsByTrainerId })
// Get an AccessPattern by key
PokeRegistry.accessPatterns.trainers.query(...)
queryβ
Record<string, ACCESS_PATTERNS['query']>
Shorthand access for the registered AccessPatterns' query methods:
PokeRegistry.query.trainers(...)
// π Equivalent to
PokeRegistry.accessPatterns.trainers.query(...)