Skip to main content
Version: v2

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(...)