@seneca/entity-depend
v0.6.0
Published
Handle dependency relationships on entity verison
Downloads
3
Keywords
Readme
seneca-entity-depend
Handle dependency relationships on entity verison
NOTE
- Only works on @seneca/entity-history enabled ents (as per
ent
option of @seneca/entity-history).
Message Tutorial
These can be run interactively with [seneca-repl](senecajs/seneca-repl.
To use in code, call with let out = await seneca.post(msg)
.
Create some entities
> sys:entity,cmd:save,name:foo,ent:{x:1,y:'Y'} => foo1=out
{ id: <ID>, x: 1, y: 'Y' }
> sys:entity,cmd:save,name:foo,ent:{x:2,y:'YY'} => foo2=out
{ id: <ID>, x: 2, y: 'YY' }
Create a dependency
> sys:entity,rig:depend,name:foo,make:child,parent_id:`$.foo1.id` => foo1c1=out
{ id: <ID>, x: 1, y: 'Y' }
Pull latest updates from parent, child's changes have precedence
Pulls all changes from previous pull point (initially the depend point). Default is to keep child's conflicting changes.
> sys:entity,rig:depend,name:foo,pull:parent,child_id:`$.foo1c1.id` => foo1c1=out
Pull latest updates from parent, parents's changes have precedence
> sys:entity,rig:depend,name:foo,pull:parent,keep:parent,child_id:`$.foo1c1.id`
=> foo1c1=out
Pull latest updates from child
Pulls all changes since previous pull point (initially the depend point). Default is to keep parent's conflicting changes.
> sys:entity,rig:depend,name:foo,pull:child,parent_id:`$.foo1.id`,child_id:`$.foo1c1.id`
=> foo1=out
Keep child's conflicting changes:
> sys:entity,rig:depend,name:foo,pull:child,keep:child,parent_id:`$.foo1.id`,child_id:`$.foo1c1.id`
=> foo1=out
Parent to child relationship is one-to-many. Thus pull:child
needs both
child_id
and parent_id
.
Generate a pull request
> sys:entity,rig:depend,name:foo,pull:child,make:request,parent_id:`$.foo1.id`,child_id:`$.foo1c1.id`
=> pr0=out
Pull request operations
List pull requests against child and parent, as provided
> sys:entity,rig:depend,name:foo,list:request,parent_id?,child_id?
Apply a pull request. Same as applying pull
operation above.
> sys:entity,rig:depend,name:foo,apply:request,request_id
Preview pull operation
See which fields are changed in parent and child.
> sys:entity,rig:depend,name:foo,pull-preview:parent,child_id:`$.foo1c1.id` => preview1=out
Pull latest updates from parent, specific version
Pulls all changes from specified version. NOTE: uses entity-history directly
> sys:entity,rig:depend,entity:depend,ent:{name:foo,id:`$.foo1`} => h0=out.items
> sys:entity,rig:depend,name:foo,pull:parent,child_id:`$.foo1c1.id`,
parent_ver_id:`$.h0[0].id` => foo1c1=out
Implementation
Entities
- sys/entdep: Dependency relationships established with
make:child
- sys/pullhist: Pull history.
- sys/pullreq: Pull requests.
TODO:
- Patterns should support
ent
param as well as top level base,name,id. - Support
make:parent