@keltoi/hydra 2.2.3 → 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 +52 -52
  2. 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()) {
@@ -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);
@@ -591,8 +591,8 @@ class ChangeableRepository extends Repository$1{
591
591
  .first()
592
592
  .orderBy('createdAt',"asc")
593
593
  .then(Repository$1.resultModelOrError)
594
- }
595
-
594
+ }
595
+
596
596
  class TraceableRepository extends Repository$1{
597
597
  constructor(entity=Traceable,context=new Context$2()){
598
598
  super(entity,context);
@@ -632,8 +632,8 @@ class TraceableRepository extends Repository$1{
632
632
 
633
633
  delete = () => Promise.reject( new Result({code:400,message:'Cannot delete a logged object'}) )
634
634
 
635
- }
636
-
635
+ }
636
+
637
637
  class ThingRepository extends Repository$1{
638
638
  constructor(entity = Thing,context=new Context()){
639
639
  super(entity,context);
@@ -648,8 +648,8 @@ class ThingRepository extends Repository$1{
648
648
  :new Result({code:404,message:'Not found'})
649
649
  )
650
650
  .catch(err=>Promise.reject( new Result({code:500,message:err}) ))
651
- }
652
-
651
+ }
652
+
653
653
  class DbLinked {
654
654
  #linking
655
655
  #name=''
@@ -757,14 +757,14 @@ class DbLinked {
757
757
  .catch(err=>Promise.reject( new Result({code:500,message:err}) ));
758
758
  }
759
759
 
760
- }
761
-
760
+ }
761
+
762
762
  const DbRepository = Repository$1;
763
763
  const DbContext = Context$2;
764
764
  const DbChangeableRepository = ChangeableRepository;
765
765
  const DbTraceableRepository = TraceableRepository;
766
- const DbThingRepository = ThingRepository;
767
-
766
+ const DbThingRepository = ThingRepository;
767
+
768
768
  class Service {
769
769
  #context
770
770
  constructor(context=new DbContext()){
@@ -775,8 +775,8 @@ class Service {
775
775
 
776
776
  handleError = (code,message)=>Promise.reject(new Result({code,message}))
777
777
  handleFailure = (err)=> this.handleError({code:500,message:err.message})
778
- }
779
-
778
+ }
779
+
780
780
  class Handler {
781
781
  #context
782
782
  constructor({ context = new DbContext }) {
@@ -791,8 +791,8 @@ class Handler {
791
791
  handleError({ code, message }) {
792
792
  return Promise.reject(new Result({ code, message }));
793
793
  }
794
- }
795
-
794
+ }
795
+
796
796
  let Context$1 = class Context{
797
797
  #http
798
798
 
@@ -801,8 +801,8 @@ let Context$1 = class Context{
801
801
  }
802
802
 
803
803
  get http(){ return this.#http }
804
- };
805
-
804
+ };
805
+
806
806
  class Repository {
807
807
  #context
808
808
 
@@ -817,8 +817,8 @@ class Repository {
817
817
  }
818
818
 
819
819
  get context(){ return this.#context }
820
- }
821
-
820
+ }
821
+
822
822
  class RestfulRepository extends Repository{
823
823
  constructor(context=new Context$1()){
824
824
  super(context);
@@ -897,10 +897,10 @@ class RestfulRepository extends Repository{
897
897
  : Promise.reject(new Result({code:value.status, message:value.statusText}));
898
898
  })
899
899
  }
900
- }
901
-
900
+ }
901
+
902
902
  const ApiRepository = Repository;
903
903
  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 };
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.3",
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",