-
Notifications
You must be signed in to change notification settings - Fork 0
Paths
dynamodb-toolkit/paths exports pure utility functions for nested-path access on plain JS objects. No SDK involvement — these are useful for shaping items before/after DynamoDB calls or building recursive prepare / revive hooks.
import {getPath, setPath, deletePath, applyPatch, normalizeFields, subsetObject} from 'dynamodb-toolkit/paths';- Default separator is
'.'. Pass a different one as the last argument. - Pure-digit segments are array indices:
'tags.0'reads the first element of thetagsarray. - Missing intermediate nodes:
-
getPathreturns the supplied default value (orundefined). -
setPathcreates them (objects for non-numeric, arrays for numeric segments). -
deletePathis a no-op.
-
getPath({a: {b: {c: 1}}}, 'a.b.c'); // 1
getPath({a: {b: {}}}, 'a.b.c', 'fallback'); // 'fallback'
getPath({tags: ['x', 'y']}, 'tags.1'); // 'y'Mutates obj in place, returns obj. Creates intermediate containers as needed.
const obj = {};
setPath(obj, 'a.b.0', 'x');
// obj === {a: {b: ['x']}}Removes the leaf at path. Mutates and returns obj. Leaves intermediate nodes intact.
const obj = {a: {b: {c: 1, d: 2}}};
deletePath(obj, 'a.b.c');
// obj === {a: {b: {d: 2}}}Applies a flat patch object to an in-memory item using setPath for each key, plus options.delete for deletePath.
const obj = {name: 'Hoth', config: {gravity: '1g'}};
applyPatch(obj, {'config.gravity': '1.5g', 'climate': 'frozen'}, {delete: ['old_field']});
// obj === {name: 'Hoth', config: {gravity: '1.5g'}, climate: 'frozen'}interface ApplyPatchOptions {
delete?: string[];
separator?: string;
}This mirrors what the DynamoDB UpdateExpression does — useful for client-side preview of pending updates, optimistic UI, etc.
Coerces field specifications into a string[] | null. Accepts string, comma-separated string, array, object (keys taken). Applies an alias map to the first segment of each path.
normalizeFields('name,climate,terrain'); // ['name','climate','terrain']
normalizeFields({a: 1, b: 1, c: 1}); // ['a', 'b', 'c']
normalizeFields(['desc'], {desc: 'description'}); // ['description']Returns a new object containing only the requested fields/paths. Used by the default revive hook when fields is supplied.
subsetObject({a: 1, b: 2, c: {x: 10, y: 20}}, ['a', 'c.x']);
// → {a: 1, c: {x: 10}}Missing fields are silently omitted (no undefined key in the result).
Start here
- Getting started
- Concepts
- Key and field design
- Compatibility
- Migration: v2 to v3
- SDK v2 to v3 cheat sheet
Guides
- Hierarchical data walkthrough
- Key expression patterns
- Multi-type tables
- Pagination
- Mass operation semantics
- URL schema design
Adapter
- Adapter
- Constructor options
- CRUD methods
- Mass methods
- Batch builders
- Hooks
- Raw marker
- Indirect indices
- Transaction auto-upgrade
Expression builders
Batch / transactions / mass / paths
REST surface
Framework adapters
Recipes
- Recipes index
- List records of a tier
- Per-tier sparse GSI markers
- Tier within a partition
- Reservation with auto-release
- Keys-only GSI, runtime projection
- Cascade subtree operations
- Querying subtrees with buildKey
- Filter URL grammar
- Text search
- Provisioning workflow
- Resumable mass operations
History