@keltoi/hydra 2.3.1 → 2.3.2
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 +58 -53
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import knex from 'knex';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
|
|
1
|
+
import knex from 'knex';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
4
|
var runWhenFalse = (
|
|
5
5
|
cond = Promise.resolve(true),
|
|
6
6
|
execute = async () => {},
|
|
7
7
|
)=>cond
|
|
8
8
|
.then(async isTrue=>{
|
|
9
9
|
if (!isTrue) await execute();
|
|
10
|
-
});
|
|
11
|
-
|
|
10
|
+
});
|
|
11
|
+
|
|
12
12
|
var runWhenTrue = (
|
|
13
13
|
cond = Promise.resolve(true),
|
|
14
14
|
execute = async () => {},
|
|
15
15
|
)=>cond
|
|
16
16
|
.then(async isTrue=>{
|
|
17
17
|
if (isTrue) await execute();
|
|
18
|
-
});
|
|
19
|
-
|
|
18
|
+
});
|
|
19
|
+
|
|
20
20
|
class Result {
|
|
21
21
|
#code
|
|
22
22
|
#message
|
|
@@ -57,8 +57,8 @@ class Result {
|
|
|
57
57
|
.status(this.#code)
|
|
58
58
|
.json(this.#data);
|
|
59
59
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
60
|
+
}
|
|
61
|
+
|
|
62
62
|
class Entity{
|
|
63
63
|
#key
|
|
64
64
|
#data
|
|
@@ -94,8 +94,8 @@ class Entity{
|
|
|
94
94
|
static collectionfromResult(result=new Result()){
|
|
95
95
|
if(result.isError) return Promise.reject(result)
|
|
96
96
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
97
|
+
}
|
|
98
|
+
|
|
99
99
|
class Model {
|
|
100
100
|
constructor() {}
|
|
101
101
|
|
|
@@ -104,8 +104,8 @@ class Model {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
validate(){}
|
|
107
|
-
}
|
|
108
|
-
|
|
107
|
+
}
|
|
108
|
+
|
|
109
109
|
class Linking{
|
|
110
110
|
#abscissa=new Entity()
|
|
111
111
|
#ordinate=new Entity()
|
|
@@ -185,8 +185,8 @@ class Linking{
|
|
|
185
185
|
get ordinate(){ return this.#ordinate }
|
|
186
186
|
set ordinate(value = this.Ordinate.build()){ this.ordinate = value; }
|
|
187
187
|
|
|
188
|
-
}
|
|
189
|
-
|
|
188
|
+
}
|
|
189
|
+
|
|
190
190
|
class Traceable extends Entity{
|
|
191
191
|
constructor({
|
|
192
192
|
key={},
|
|
@@ -219,8 +219,8 @@ class Traceable extends Entity{
|
|
|
219
219
|
)
|
|
220
220
|
)
|
|
221
221
|
}
|
|
222
|
-
}
|
|
223
|
-
|
|
222
|
+
}
|
|
223
|
+
|
|
224
224
|
class Status extends Entity{
|
|
225
225
|
static build=({ id=1,description='' })=>new Status({id,description})
|
|
226
226
|
|
|
@@ -255,8 +255,8 @@ class Status extends Entity{
|
|
|
255
255
|
|
|
256
256
|
get description(){ return this.data.status }
|
|
257
257
|
set description( value='' ){ this.data.status = value;}
|
|
258
|
-
}
|
|
259
|
-
|
|
258
|
+
}
|
|
259
|
+
|
|
260
260
|
class Thing extends Entity{
|
|
261
261
|
constructor({
|
|
262
262
|
key={},
|
|
@@ -290,8 +290,8 @@ class Thing extends Entity{
|
|
|
290
290
|
)
|
|
291
291
|
)
|
|
292
292
|
}
|
|
293
|
-
}
|
|
294
|
-
|
|
293
|
+
}
|
|
294
|
+
|
|
295
295
|
class Changeable extends Entity{
|
|
296
296
|
constructor({
|
|
297
297
|
key={},
|
|
@@ -339,8 +339,8 @@ class Changeable extends Entity{
|
|
|
339
339
|
)
|
|
340
340
|
)
|
|
341
341
|
}
|
|
342
|
-
}
|
|
343
|
-
|
|
342
|
+
}
|
|
343
|
+
|
|
344
344
|
class Migration{
|
|
345
345
|
#db
|
|
346
346
|
constructor(db = knex()) {
|
|
@@ -359,6 +359,10 @@ class Migration{
|
|
|
359
359
|
.where({ name })
|
|
360
360
|
.update({ iteration })
|
|
361
361
|
|
|
362
|
+
#create = ({ iteration=0,name='' })=>this
|
|
363
|
+
.#db('migration')
|
|
364
|
+
.insert({ iteration,name })
|
|
365
|
+
|
|
362
366
|
async runMigrations({ entity = Entity, migrations=[async ()=>{}] }){
|
|
363
367
|
const name = entity.name;
|
|
364
368
|
|
|
@@ -372,7 +376,8 @@ class Migration{
|
|
|
372
376
|
await migrations[index]();
|
|
373
377
|
}
|
|
374
378
|
|
|
375
|
-
await this.#
|
|
379
|
+
if (listSize === 1) await this.#create({ iteration:listSize,name });
|
|
380
|
+
else await this.#update({ iteration:listSize,name });
|
|
376
381
|
}
|
|
377
382
|
|
|
378
383
|
static structMe(db=knex()){
|
|
@@ -392,8 +397,8 @@ class Migration{
|
|
|
392
397
|
)
|
|
393
398
|
)
|
|
394
399
|
}
|
|
395
|
-
}
|
|
396
|
-
|
|
400
|
+
}
|
|
401
|
+
|
|
397
402
|
let Context$2 = class Context{
|
|
398
403
|
#db
|
|
399
404
|
|
|
@@ -434,8 +439,8 @@ let Context$2 = class Context{
|
|
|
434
439
|
|
|
435
440
|
await Promise.all(promises);
|
|
436
441
|
}
|
|
437
|
-
};
|
|
438
|
-
|
|
442
|
+
};
|
|
443
|
+
|
|
439
444
|
let Repository$1 = class Repository{
|
|
440
445
|
#name='';
|
|
441
446
|
|
|
@@ -511,8 +516,8 @@ let Repository$1 = class Repository{
|
|
|
511
516
|
|
|
512
517
|
return Promise.reject(error)
|
|
513
518
|
}
|
|
514
|
-
};
|
|
515
|
-
|
|
519
|
+
};
|
|
520
|
+
|
|
516
521
|
class ChangeableRepository extends Repository$1{
|
|
517
522
|
constructor(entity = Changeable,context=new Context$2()){
|
|
518
523
|
super(entity,context);
|
|
@@ -591,8 +596,8 @@ class ChangeableRepository extends Repository$1{
|
|
|
591
596
|
.first()
|
|
592
597
|
.orderBy('createdAt',"asc")
|
|
593
598
|
.then(Repository$1.resultModelOrError)
|
|
594
|
-
}
|
|
595
|
-
|
|
599
|
+
}
|
|
600
|
+
|
|
596
601
|
class TraceableRepository extends Repository$1{
|
|
597
602
|
constructor(entity=Traceable,context=new Context$2()){
|
|
598
603
|
super(entity,context);
|
|
@@ -632,8 +637,8 @@ class TraceableRepository extends Repository$1{
|
|
|
632
637
|
|
|
633
638
|
delete = () => Promise.reject( new Result({code:400,message:'Cannot delete a logged object'}) )
|
|
634
639
|
|
|
635
|
-
}
|
|
636
|
-
|
|
640
|
+
}
|
|
641
|
+
|
|
637
642
|
class ThingRepository extends Repository$1{
|
|
638
643
|
constructor(entity = Thing,context=new Context()){
|
|
639
644
|
super(entity,context);
|
|
@@ -648,8 +653,8 @@ class ThingRepository extends Repository$1{
|
|
|
648
653
|
:new Result({code:404,message:'Not found'})
|
|
649
654
|
)
|
|
650
655
|
.catch(err=>Promise.reject( new Result({code:500,message:err}) ))
|
|
651
|
-
}
|
|
652
|
-
|
|
656
|
+
}
|
|
657
|
+
|
|
653
658
|
class DbLinked {
|
|
654
659
|
#linking
|
|
655
660
|
#name=''
|
|
@@ -757,14 +762,14 @@ class DbLinked {
|
|
|
757
762
|
.catch(err=>Promise.reject( new Result({code:500,message:err}) ));
|
|
758
763
|
}
|
|
759
764
|
|
|
760
|
-
}
|
|
761
|
-
|
|
765
|
+
}
|
|
766
|
+
|
|
762
767
|
const DbRepository = Repository$1;
|
|
763
768
|
const DbContext = Context$2;
|
|
764
769
|
const DbChangeableRepository = ChangeableRepository;
|
|
765
770
|
const DbTraceableRepository = TraceableRepository;
|
|
766
|
-
const DbThingRepository = ThingRepository;
|
|
767
|
-
|
|
771
|
+
const DbThingRepository = ThingRepository;
|
|
772
|
+
|
|
768
773
|
class Service {
|
|
769
774
|
#context
|
|
770
775
|
constructor(context=new DbContext()){
|
|
@@ -775,8 +780,8 @@ class Service {
|
|
|
775
780
|
|
|
776
781
|
handleError = (code,message)=>Promise.reject(new Result({code,message}))
|
|
777
782
|
handleFailure = (err)=> this.handleError({code:500,message:err.message})
|
|
778
|
-
}
|
|
779
|
-
|
|
783
|
+
}
|
|
784
|
+
|
|
780
785
|
class Handler {
|
|
781
786
|
#context
|
|
782
787
|
constructor({ context = new DbContext }) {
|
|
@@ -791,8 +796,8 @@ class Handler {
|
|
|
791
796
|
handleError({ code, message }) {
|
|
792
797
|
return Promise.reject(new Result({ code, message }));
|
|
793
798
|
}
|
|
794
|
-
}
|
|
795
|
-
|
|
799
|
+
}
|
|
800
|
+
|
|
796
801
|
let Context$1 = class Context{
|
|
797
802
|
#http
|
|
798
803
|
|
|
@@ -801,8 +806,8 @@ let Context$1 = class Context{
|
|
|
801
806
|
}
|
|
802
807
|
|
|
803
808
|
get http(){ return this.#http }
|
|
804
|
-
};
|
|
805
|
-
|
|
809
|
+
};
|
|
810
|
+
|
|
806
811
|
class Repository {
|
|
807
812
|
#context
|
|
808
813
|
|
|
@@ -817,8 +822,8 @@ class Repository {
|
|
|
817
822
|
}
|
|
818
823
|
|
|
819
824
|
get context(){ return this.#context }
|
|
820
|
-
}
|
|
821
|
-
|
|
825
|
+
}
|
|
826
|
+
|
|
822
827
|
class RestfulRepository extends Repository{
|
|
823
828
|
constructor(context=new Context$1()){
|
|
824
829
|
super(context);
|
|
@@ -897,10 +902,10 @@ class RestfulRepository extends Repository{
|
|
|
897
902
|
: Promise.reject(new Result({code:value.status, message:value.statusText}));
|
|
898
903
|
})
|
|
899
904
|
}
|
|
900
|
-
}
|
|
901
|
-
|
|
905
|
+
}
|
|
906
|
+
|
|
902
907
|
const ApiRepository = Repository;
|
|
903
908
|
const ApiContext = Context$1;
|
|
904
|
-
const ApiRestfulRepository = RestfulRepository;
|
|
905
|
-
|
|
906
|
-
export { ApiContext, ApiRepository, ApiRestfulRepository, Changeable, DbChangeableRepository, DbContext, DbLinked, DbRepository, DbThingRepository, DbTraceableRepository, Entity, Handler, Linking, Migration, Model, Result, Service, Status, Thing, Traceable, runWhenFalse, runWhenTrue };
|
|
909
|
+
const ApiRestfulRepository = RestfulRepository;
|
|
910
|
+
|
|
911
|
+
export { ApiContext, ApiRepository, ApiRestfulRepository, Changeable, DbChangeableRepository, DbContext, DbLinked, DbRepository, DbThingRepository, DbTraceableRepository, Entity, Handler, Linking, Migration, Model, Result, Service, Status, Thing, Traceable, runWhenFalse, runWhenTrue };
|