@keltoi/hydra 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +878 -1
- package/package.json +11 -2
- package/.github/workflows/npm-publish.yml +0 -33
- package/rollup.config.mjs +0 -17
- package/src/handler/index.js +0 -18
- package/src/helper/runWhenFalse.js +0 -7
- package/src/helper/runWhenTrue.js +0 -7
- package/src/index.js +0 -41
- package/src/model/index.js +0 -17
- package/src/model/linking.js +0 -85
- package/src/model/logged.js +0 -38
- package/src/model/result.js +0 -39
- package/src/model/status.js +0 -46
- package/src/model/thing.js +0 -42
- package/src/model/traced.js +0 -44
- package/src/repository/api/context.js +0 -11
- package/src/repository/api/index.js +0 -19
- package/src/repository/api/restRepository.js +0 -36
- package/src/repository/db/context.js +0 -34
- package/src/repository/db/index.js +0 -82
- package/src/repository/db/linked.js +0 -107
- package/src/repository/db/loggedRepository.js +0 -59
- package/src/repository/db/thingRepository.js +0 -17
- package/src/repository/db/tracedRepository.js +0 -101
- package/src/service/index.js +0 -14
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import Model from "../../model/index";
|
|
3
|
-
import Linking from "../../model/linking";
|
|
4
|
-
import Context from "./context";
|
|
5
|
-
|
|
6
|
-
export default class DbLinked {
|
|
7
|
-
#linking
|
|
8
|
-
#name=''
|
|
9
|
-
myContext
|
|
10
|
-
|
|
11
|
-
constructor(link=Linking,context=new Context){
|
|
12
|
-
this.#name = link.name
|
|
13
|
-
this.myContext = () => context.db(this.#name)
|
|
14
|
-
this.#linking = link
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
createBatch = (linkings=[ new Linking() ])=>
|
|
18
|
-
this.myContext()
|
|
19
|
-
.insert(
|
|
20
|
-
linkings.map(l => (
|
|
21
|
-
{
|
|
22
|
-
...l.key,
|
|
23
|
-
...l.entity
|
|
24
|
-
})
|
|
25
|
-
)
|
|
26
|
-
)
|
|
27
|
-
.then(()=>linkings)
|
|
28
|
-
|
|
29
|
-
create = (linked=new Linking())=>
|
|
30
|
-
this.myContext()
|
|
31
|
-
.insert({
|
|
32
|
-
...linked.key,
|
|
33
|
-
...linked.entity
|
|
34
|
-
})
|
|
35
|
-
.then(()=>linked);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
insertOrdinatesByAbscissa = ({ abscissa=new Model(),ordinates=[new Model()] })=>{
|
|
39
|
-
const batch = ordinates
|
|
40
|
-
.map(o=>this.#linking
|
|
41
|
-
.build({abscissa,ordinate:o})
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
return this.createBatch(batch);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
insertAbscissasByOrdinate = ({ ordinate=new Model(),abscissas=[new Model()] })=>{
|
|
48
|
-
const batch = abscissas
|
|
49
|
-
.map(a=>this.#linking
|
|
50
|
-
.build({abscissa:a,ordinate})
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
return this.createBatch(batch)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
delete = (linked=new Linking())=>
|
|
57
|
-
this.myContext()
|
|
58
|
-
.where(linked.key)
|
|
59
|
-
.del()
|
|
60
|
-
.then(affected=>affected > 0)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
getAbscissasByOrdinate(linked=new Linking()){
|
|
64
|
-
const Abscissa = linked.Abscissa
|
|
65
|
-
const Ordinate = linked.Ordinate
|
|
66
|
-
const keys = Object.keys(linked.abscissaKey)
|
|
67
|
-
const abscissaKey = Object.keys(linked.abscissa.key)
|
|
68
|
-
|
|
69
|
-
const fields = keys.map(key=>`${Abscissa.name}${Ordinate.name}.${key}`)
|
|
70
|
-
const abscissas = abscissaKey.map(key=>`${Abscissa.name}.${key}`)
|
|
71
|
-
|
|
72
|
-
return this.myContext()
|
|
73
|
-
.where(linked.ordinateKey)
|
|
74
|
-
.select(`${Abscissa.name}.*`)
|
|
75
|
-
.join(Abscissa.name,clause=>
|
|
76
|
-
fields.forEach((field,i)=>{
|
|
77
|
-
clause.on(field,abscissas[i])
|
|
78
|
-
})
|
|
79
|
-
)
|
|
80
|
-
.then(list=>
|
|
81
|
-
list.map(abscissa=>Abscissa.build(abscissa))
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getOrdinatesByAbscissa(linked=new Linking()){
|
|
86
|
-
const Ordinate = linked.Ordinate
|
|
87
|
-
const Abscissa = linked.Abscissa
|
|
88
|
-
const keys = Object.keys(linked.ordinateKey)
|
|
89
|
-
const ordinateKeys = Object.keys(linked.ordinate.key)
|
|
90
|
-
|
|
91
|
-
const fields = keys.map(key=>`${Abscissa.name}${Ordinate.name}.${key}`)
|
|
92
|
-
const ordinates = ordinateKeys.map(key=>`${Ordinate.name}.${key}`)
|
|
93
|
-
|
|
94
|
-
return this.myContext()
|
|
95
|
-
.where(linked.abscissaKey)
|
|
96
|
-
.select(`${Ordinate.name}.*`)
|
|
97
|
-
.join(Ordinate.name,clause=>
|
|
98
|
-
fields.forEach((field,i)=>{
|
|
99
|
-
clause.on(field,ordinates[i])
|
|
100
|
-
})
|
|
101
|
-
)
|
|
102
|
-
.then(list=>
|
|
103
|
-
list.map(ordinate=>Ordinate.build(ordinate))
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import Logged from '../../model/logged.js';
|
|
2
|
-
import Context from './context.js';
|
|
3
|
-
import Repository from './index.js';
|
|
4
|
-
import Result from '../../model/result.js';
|
|
5
|
-
|
|
6
|
-
export default class LoggedRepository extends Repository{
|
|
7
|
-
constructor(model=Logged,context=new Context()){
|
|
8
|
-
super(model,context)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get = (logged = new Logged()) =>
|
|
12
|
-
this.myContext()
|
|
13
|
-
.where({...logged.key})
|
|
14
|
-
.first()
|
|
15
|
-
.then(model => Repository.anyOrError(model,{code:404,message:'Not found'}))
|
|
16
|
-
.then(this.Entity.build)
|
|
17
|
-
|
|
18
|
-
before = (date = new Date(), order = 'asc') =>
|
|
19
|
-
this.myContext()
|
|
20
|
-
.where('createdAt','<',date.toISOString())
|
|
21
|
-
.select()
|
|
22
|
-
.orderBy('createdAt',order)
|
|
23
|
-
.then(result => Repository.setOrEmpty(result,this.Entity.build))
|
|
24
|
-
|
|
25
|
-
after = (date = new Date(), order = 'asc') =>
|
|
26
|
-
this.myContext()
|
|
27
|
-
.where('createdAt','>',date.toISOString())
|
|
28
|
-
.select()
|
|
29
|
-
.orderBy('createdAt',order)
|
|
30
|
-
.then(result => Repository.setOrEmpty(result,this.Entity.build))
|
|
31
|
-
|
|
32
|
-
list = (order='asc') =>
|
|
33
|
-
this.myContext()
|
|
34
|
-
.select()
|
|
35
|
-
.orderBy('createdAt',order)
|
|
36
|
-
.then(result => Repository.setOrEmpty(result,this.Entity.build))
|
|
37
|
-
|
|
38
|
-
insert = (logged = new Logged()) =>
|
|
39
|
-
this.myContext()
|
|
40
|
-
.insert({
|
|
41
|
-
...logged.entity,
|
|
42
|
-
createdAt:new Date().toISOString()
|
|
43
|
-
},Object.keys(logged.key))
|
|
44
|
-
.then(ids => logged.key = ids[0])
|
|
45
|
-
.then(() => logged)
|
|
46
|
-
|
|
47
|
-
create = (logged = new Logged()) =>
|
|
48
|
-
this.myContext()
|
|
49
|
-
.insert({
|
|
50
|
-
...logged.entity,
|
|
51
|
-
createdAt:new Date().toISOString()
|
|
52
|
-
})
|
|
53
|
-
.then(() => logged)
|
|
54
|
-
|
|
55
|
-
update = () => Promise.reject(new Result({code:400,message:'Cannot update a logged object'}))
|
|
56
|
-
|
|
57
|
-
delete = () => Promise.reject(new Result({code:400,message:'Cannot delete a logged object'}))
|
|
58
|
-
|
|
59
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import Thing from "../../model/thing.js";
|
|
2
|
-
import Context from "./context.js";
|
|
3
|
-
import Repository from "./index.js";
|
|
4
|
-
|
|
5
|
-
export default class ThingRepository extends Repository{
|
|
6
|
-
constructor(model = Thing,context=new Context()){
|
|
7
|
-
super(model,context)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
getByName = (name='') =>
|
|
11
|
-
this.myContext()
|
|
12
|
-
.where({name})
|
|
13
|
-
.select()
|
|
14
|
-
.then(result=>Repository
|
|
15
|
-
.setOrEmpty(result,this.Entity.build)
|
|
16
|
-
)
|
|
17
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import Traced from '../../model/traced.js';
|
|
2
|
-
import Context from './context.js';
|
|
3
|
-
import Repository from './index.js';
|
|
4
|
-
|
|
5
|
-
export default class TracedRepository extends Repository{
|
|
6
|
-
constructor(model=Traced,context=new Context()){
|
|
7
|
-
super(model,context)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
deceased = (order = 'asc') =>
|
|
11
|
-
this.myContext()
|
|
12
|
-
.where({active:false})
|
|
13
|
-
.select()
|
|
14
|
-
.orderBy(['createdAt','updatedAt'],order)
|
|
15
|
-
.then(result => Repository
|
|
16
|
-
.setOrEmpty(result,this.Entity.build)
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
before = (date = new Date(), order = 'asc') =>
|
|
20
|
-
this.myContext()
|
|
21
|
-
.where('createdAt','<',date.toISOString())
|
|
22
|
-
.where({active:true})
|
|
23
|
-
.select()
|
|
24
|
-
.orderBy(['createdAt','updatedAt'],order)
|
|
25
|
-
.then(result => Repository
|
|
26
|
-
.setOrEmpty(result,this.Entity.build)
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
after = (date=new Date(), order = 'asc') =>
|
|
30
|
-
this.myContext()
|
|
31
|
-
.where('createdAt','>',date.toISOString())
|
|
32
|
-
.where({active:true})
|
|
33
|
-
.select()
|
|
34
|
-
.orderBy(['createdAt','updatedAt'],order)
|
|
35
|
-
.then(result => Repository
|
|
36
|
-
.setOrEmpty(result,this.Entity.build)
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
list = (order = 'asc') =>
|
|
40
|
-
this.myContext()
|
|
41
|
-
.where({active:true})
|
|
42
|
-
.select()
|
|
43
|
-
.orderBy(['createdAt','updatedAt'],order)
|
|
44
|
-
.then(result => Repository
|
|
45
|
-
.setOrEmpty(result,this.Entity.build)
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
last = () =>
|
|
49
|
-
this.myContext()
|
|
50
|
-
.where({active:true})
|
|
51
|
-
.first()
|
|
52
|
-
.orderBy('createdAt',"desc")
|
|
53
|
-
.then(result => Repository
|
|
54
|
-
.anyOrError(result,{code:404,message:'Not found'})
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
first = () =>
|
|
58
|
-
this.myContext()
|
|
59
|
-
.where({active:true})
|
|
60
|
-
.first()
|
|
61
|
-
.orderBy('createdAt',"asc")
|
|
62
|
-
.then(result => Repository
|
|
63
|
-
.anyOrError(result,{code:404,message:'Not found'})
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
insert = (traced=new Traced()) =>
|
|
67
|
-
this.myContext()
|
|
68
|
-
.insert({
|
|
69
|
-
...traced.entity,
|
|
70
|
-
createdAt:new Date().toISOString()
|
|
71
|
-
}, Object.keys(traced.key))
|
|
72
|
-
.then(ids=>traced.key = ids[0])
|
|
73
|
-
.then(()=> traced)
|
|
74
|
-
|
|
75
|
-
create = (traced=new Traced())=>
|
|
76
|
-
this.myContext()
|
|
77
|
-
.insert({
|
|
78
|
-
...traced.key,
|
|
79
|
-
...traced.entity,
|
|
80
|
-
createdAt:new Date().toISOString()
|
|
81
|
-
})
|
|
82
|
-
.then(()=> traced)
|
|
83
|
-
|
|
84
|
-
update = (traced=new Traced())=>
|
|
85
|
-
this.myContext()
|
|
86
|
-
.where(traced.key)
|
|
87
|
-
.update({
|
|
88
|
-
...traced.entity,
|
|
89
|
-
updatedAt:new Date().toISOString()
|
|
90
|
-
})
|
|
91
|
-
.then(affected=>affected > 0)
|
|
92
|
-
|
|
93
|
-
delete = (traced=new Traced())=>
|
|
94
|
-
this.myContext()
|
|
95
|
-
.where(traced.key)
|
|
96
|
-
.update({
|
|
97
|
-
active:false,
|
|
98
|
-
updatedAt:new Date().toISOString()
|
|
99
|
-
})
|
|
100
|
-
.then(affected=>affected > 0)
|
|
101
|
-
}
|
package/src/service/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Result from "../model/result"
|
|
2
|
-
import Context from "../repository/db/context"
|
|
3
|
-
|
|
4
|
-
export default class Service {
|
|
5
|
-
#context
|
|
6
|
-
constructor(context=new Context()){
|
|
7
|
-
this.#context = context
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get context(){return this.#context}
|
|
11
|
-
|
|
12
|
-
handleError = (code,message)=>Promise.reject(new Result({code,message}))
|
|
13
|
-
handleFailure = (err)=> this.handleError({code:500,message:err.message})
|
|
14
|
-
}
|