@keltoi/hydra 2.2.2 → 2.3.1

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.
Files changed (2) hide show
  1. package/index.js +60 -54
  2. package/package.json +2 -5
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()) {
@@ -392,8 +392,8 @@ class Migration{
392
392
  )
393
393
  )
394
394
  }
395
- }
396
-
395
+ }
396
+
397
397
  let Context$2 = class Context{
398
398
  #db
399
399
 
@@ -434,8 +434,8 @@ let Context$2 = class Context{
434
434
 
435
435
  await Promise.all(promises);
436
436
  }
437
- };
438
-
437
+ };
438
+
439
439
  let Repository$1 = class Repository{
440
440
  #name='';
441
441
 
@@ -511,8 +511,8 @@ let Repository$1 = class Repository{
511
511
 
512
512
  return Promise.reject(error)
513
513
  }
514
- };
515
-
514
+ };
515
+
516
516
  class ChangeableRepository extends Repository$1{
517
517
  constructor(entity = Changeable,context=new Context$2()){
518
518
  super(entity,context);
@@ -521,7 +521,10 @@ class ChangeableRepository extends Repository$1{
521
521
  reactive = (entity = new Changeable())=>
522
522
  this.myContext()
523
523
  .where(entity.key)
524
- .update({active:true})
524
+ .update({
525
+ active:true,
526
+ updatedAt:entity.updatedAt
527
+ })
525
528
  .then(affected=> affected > 0
526
529
  ? new Result({ code:200,data:`${this.name} updated` })
527
530
  : new Result({ code:404,message:'Not found' })
@@ -531,7 +534,10 @@ class ChangeableRepository extends Repository$1{
531
534
  remove = (entity = new Changeable())=>
532
535
  this.myContext()
533
536
  .where(entity.key)
534
- .update({active:false})
537
+ .update({
538
+ active:false,
539
+ updatedAt:entity.updatedAt
540
+ })
535
541
  .then(affected=> affected > 0
536
542
  ? new Result({ code:200,data:`${this.name} updated` })
537
543
  : new Result({ code:404,message:'Not found' })
@@ -585,8 +591,8 @@ class ChangeableRepository extends Repository$1{
585
591
  .first()
586
592
  .orderBy('createdAt',"asc")
587
593
  .then(Repository$1.resultModelOrError)
588
- }
589
-
594
+ }
595
+
590
596
  class TraceableRepository extends Repository$1{
591
597
  constructor(entity=Traceable,context=new Context$2()){
592
598
  super(entity,context);
@@ -626,8 +632,8 @@ class TraceableRepository extends Repository$1{
626
632
 
627
633
  delete = () => Promise.reject( new Result({code:400,message:'Cannot delete a logged object'}) )
628
634
 
629
- }
630
-
635
+ }
636
+
631
637
  class ThingRepository extends Repository$1{
632
638
  constructor(entity = Thing,context=new Context()){
633
639
  super(entity,context);
@@ -642,8 +648,8 @@ class ThingRepository extends Repository$1{
642
648
  :new Result({code:404,message:'Not found'})
643
649
  )
644
650
  .catch(err=>Promise.reject( new Result({code:500,message:err}) ))
645
- }
646
-
651
+ }
652
+
647
653
  class DbLinked {
648
654
  #linking
649
655
  #name=''
@@ -751,14 +757,14 @@ class DbLinked {
751
757
  .catch(err=>Promise.reject( new Result({code:500,message:err}) ));
752
758
  }
753
759
 
754
- }
755
-
760
+ }
761
+
756
762
  const DbRepository = Repository$1;
757
763
  const DbContext = Context$2;
758
764
  const DbChangeableRepository = ChangeableRepository;
759
765
  const DbTraceableRepository = TraceableRepository;
760
- const DbThingRepository = ThingRepository;
761
-
766
+ const DbThingRepository = ThingRepository;
767
+
762
768
  class Service {
763
769
  #context
764
770
  constructor(context=new DbContext()){
@@ -769,8 +775,8 @@ class Service {
769
775
 
770
776
  handleError = (code,message)=>Promise.reject(new Result({code,message}))
771
777
  handleFailure = (err)=> this.handleError({code:500,message:err.message})
772
- }
773
-
778
+ }
779
+
774
780
  class Handler {
775
781
  #context
776
782
  constructor({ context = new DbContext }) {
@@ -785,8 +791,8 @@ class Handler {
785
791
  handleError({ code, message }) {
786
792
  return Promise.reject(new Result({ code, message }));
787
793
  }
788
- }
789
-
794
+ }
795
+
790
796
  let Context$1 = class Context{
791
797
  #http
792
798
 
@@ -795,8 +801,8 @@ let Context$1 = class Context{
795
801
  }
796
802
 
797
803
  get http(){ return this.#http }
798
- };
799
-
804
+ };
805
+
800
806
  class Repository {
801
807
  #context
802
808
 
@@ -811,8 +817,8 @@ class Repository {
811
817
  }
812
818
 
813
819
  get context(){ return this.#context }
814
- }
815
-
820
+ }
821
+
816
822
  class RestfulRepository extends Repository{
817
823
  constructor(context=new Context$1()){
818
824
  super(context);
@@ -891,10 +897,10 @@ class RestfulRepository extends Repository{
891
897
  : Promise.reject(new Result({code:value.status, message:value.statusText}));
892
898
  })
893
899
  }
894
- }
895
-
900
+ }
901
+
896
902
  const ApiRepository = Repository;
897
903
  const ApiContext = Context$1;
898
- const ApiRestfulRepository = RestfulRepository;
899
-
900
- export { ApiContext, ApiRepository, ApiRestfulRepository, Changeable, DbChangeableRepository, DbContext, DbLinked, DbRepository, DbThingRepository, DbTraceableRepository, Entity, Handler, Linking, Migration, Model, Result, Service, Status, Thing, Traceable, runWhenFalse, runWhenTrue };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keltoi/hydra",
3
- "version": "2.2.2",
3
+ "version": "2.3.1",
4
4
  "description": "Boilerplate to start your API from zero using Repository Pattern",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -16,10 +16,7 @@
16
16
  "type": "git",
17
17
  "url": "git+https://github.com/Keltoi-Tech/HydraJs.git"
18
18
  },
19
- "keywords": [
20
- "API",
21
- "RepositoryPattern"
22
- ],
19
+ "keywords": [ "API", "RepositoryPattern" ],
23
20
  "author": "DaniloHenrique",
24
21
  "license": "MIT",
25
22
  "bugs": {