@thisisagile/easy 8.19.0 → 8.22.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/dist/domain/structs/Weight.d.ts +4 -0
- package/dist/domain/structs/Weight.js +6 -1
- package/dist/domain/structs/Weight.js.map +1 -1
- package/dist/types/Context.d.ts +19 -23
- package/dist/types/Context.js +9 -11
- package/dist/types/Context.js.map +1 -1
- package/dist/utils/Sentence.d.ts +1 -1
- package/package.json +2 -2
- package/src/domain/structs/Weight.ts +9 -1
- package/src/types/Context.ts +28 -33
- package/src/utils/Sentence.ts +1 -1
|
@@ -5,4 +5,8 @@ export declare class Weight extends Struct {
|
|
|
5
5
|
readonly uow: UnitOfWeight;
|
|
6
6
|
sizeInG: () => number;
|
|
7
7
|
gte: (w: Weight) => boolean;
|
|
8
|
+
lte: (w: Weight) => boolean;
|
|
9
|
+
between: (lower: Weight, upper?: Weight) => boolean;
|
|
10
|
+
sum: (add: Weight) => Weight;
|
|
8
11
|
}
|
|
12
|
+
export declare const weight: (value: number, uow?: UnitOfWeight | undefined) => Weight;
|
|
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Weight = void 0;
|
|
12
|
+
exports.weight = exports.Weight = void 0;
|
|
13
13
|
const enums_1 = require("../enums");
|
|
14
14
|
const validation_1 = require("../../validation");
|
|
15
15
|
const Struct_1 = require("../Struct");
|
|
@@ -20,6 +20,9 @@ class Weight extends Struct_1.Struct {
|
|
|
20
20
|
this.uow = enums_1.UnitOfWeight.byId(this.state.uow, enums_1.UnitOfWeight.G);
|
|
21
21
|
this.sizeInG = () => this.value * this.uow.gMultiplier;
|
|
22
22
|
this.gte = (w) => this.sizeInG() >= w.sizeInG();
|
|
23
|
+
this.lte = (w) => this.sizeInG() <= w.sizeInG();
|
|
24
|
+
this.between = (lower, upper = (0, exports.weight)(Number.MAX_VALUE, this.uow)) => this.gte(lower) && this.lte(upper);
|
|
25
|
+
this.sum = (add) => (0, exports.weight)((this.sizeInG() + add.sizeInG()) / this.uow.gMultiplier, this.uow);
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
__decorate([
|
|
@@ -27,4 +30,6 @@ __decorate([
|
|
|
27
30
|
__metadata("design:type", Number)
|
|
28
31
|
], Weight.prototype, "value", void 0);
|
|
29
32
|
exports.Weight = Weight;
|
|
33
|
+
const weight = (value, uow) => new Weight({ value, uow });
|
|
34
|
+
exports.weight = weight;
|
|
30
35
|
//# sourceMappingURL=Weight.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Weight.js","sourceRoot":"","sources":["../../../src/domain/structs/Weight.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAwC;AACxC,iDAA4C;AAC5C,sCAAmC;AAEnC,MAAa,MAAO,SAAQ,eAAM;IAAlC;;QACuB,UAAK,GAAW,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;QAC7C,QAAG,GAAiB,oBAAY,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,oBAAY,CAAC,CAAC,CAAC,CAAC;QAC/E,YAAO,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;QAE1D,QAAG,GAAG,CAAC,CAAS,EAAW,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"Weight.js","sourceRoot":"","sources":["../../../src/domain/structs/Weight.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAwC;AACxC,iDAA4C;AAC5C,sCAAmC;AAEnC,MAAa,MAAO,SAAQ,eAAM;IAAlC;;QACuB,U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from './Identity';
|
|
3
|
-
|
|
4
|
-
export declare type EnvContext = {
|
|
3
|
+
export interface EnvContext {
|
|
5
4
|
readonly domain: string;
|
|
6
5
|
readonly name: string;
|
|
7
6
|
readonly host: string;
|
|
8
7
|
readonly port: number;
|
|
9
8
|
get(key: string, alt?: string): string | undefined;
|
|
10
|
-
}
|
|
9
|
+
}
|
|
11
10
|
export declare class DotEnvContext implements EnvContext {
|
|
12
11
|
readonly domain: string;
|
|
13
12
|
readonly name: string;
|
|
@@ -15,7 +14,7 @@ export declare class DotEnvContext implements EnvContext {
|
|
|
15
14
|
readonly port: number;
|
|
16
15
|
readonly get: (key: string, alt?: string | undefined) => string | undefined;
|
|
17
16
|
}
|
|
18
|
-
export
|
|
17
|
+
export interface RequestContext {
|
|
19
18
|
token?: any;
|
|
20
19
|
identity?: Identity;
|
|
21
20
|
jwt: string;
|
|
@@ -24,8 +23,8 @@ export declare type RequestContext = {
|
|
|
24
23
|
get<T>(key: string): T;
|
|
25
24
|
set<T>(key: string, value: T): T;
|
|
26
25
|
create: (f: () => void) => void;
|
|
27
|
-
}
|
|
28
|
-
export declare class
|
|
26
|
+
}
|
|
27
|
+
export declare class BaseRequestContext implements RequestContext {
|
|
29
28
|
private state;
|
|
30
29
|
get token(): any;
|
|
31
30
|
set token(token: any);
|
|
@@ -40,23 +39,20 @@ export declare class BaseContext implements RequestContext {
|
|
|
40
39
|
set<T>(key: string, value: T): T;
|
|
41
40
|
readonly create: (f: () => void) => void;
|
|
42
41
|
}
|
|
43
|
-
export declare
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
export declare class BaseContext extends BaseRequestContext {
|
|
43
|
+
}
|
|
44
|
+
export interface Contexts {
|
|
45
|
+
env?: EnvContext;
|
|
46
|
+
request?: RequestContext;
|
|
46
47
|
other?: any;
|
|
47
|
-
}
|
|
48
|
-
export declare class Context
|
|
49
|
-
protected state: Contexts
|
|
50
|
-
constructor(state?: Contexts
|
|
51
|
-
get env():
|
|
52
|
-
set env(env:
|
|
53
|
-
get request():
|
|
54
|
-
set request(request:
|
|
48
|
+
}
|
|
49
|
+
export declare class Context {
|
|
50
|
+
protected state: Contexts;
|
|
51
|
+
constructor(state?: Contexts);
|
|
52
|
+
get env(): EnvContext;
|
|
53
|
+
set env(env: EnvContext);
|
|
54
|
+
get request(): RequestContext;
|
|
55
|
+
set request(request: RequestContext);
|
|
55
56
|
get other(): any;
|
|
56
|
-
static use: <E_1 extends EnvContext, R_1 extends RequestContext>({ env, request, other, }: {
|
|
57
|
-
env?: Construct<E_1> | undefined;
|
|
58
|
-
request?: Construct<R_1> | undefined;
|
|
59
|
-
other?: any;
|
|
60
|
-
}) => Context<E_1, R_1>;
|
|
61
57
|
}
|
|
62
|
-
export declare const ctx: Context
|
|
58
|
+
export declare const ctx: Context;
|
package/dist/types/Context.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ctx = exports.Context = exports.BaseContext = exports.DotEnvContext = void 0;
|
|
3
|
+
exports.ctx = exports.Context = exports.BaseContext = exports.BaseRequestContext = exports.DotEnvContext = void 0;
|
|
4
4
|
const Text_1 = require("./Text");
|
|
5
5
|
const Try_1 = require("./Try");
|
|
6
|
-
const Constructor_1 = require("./Constructor");
|
|
7
6
|
class DotEnvContext {
|
|
8
7
|
constructor() {
|
|
9
8
|
this.domain = process.env.DOMAIN ?? 'easy';
|
|
@@ -16,7 +15,7 @@ class DotEnvContext {
|
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
exports.DotEnvContext = DotEnvContext;
|
|
19
|
-
class
|
|
18
|
+
class BaseRequestContext {
|
|
20
19
|
constructor() {
|
|
21
20
|
this.state = {};
|
|
22
21
|
this.create = (f) => f();
|
|
@@ -55,16 +54,20 @@ class BaseContext {
|
|
|
55
54
|
return (this.state[key] = value);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
57
|
+
exports.BaseRequestContext = BaseRequestContext;
|
|
58
|
+
class BaseContext extends BaseRequestContext {
|
|
59
|
+
}
|
|
58
60
|
exports.BaseContext = BaseContext;
|
|
59
61
|
class Context {
|
|
60
62
|
constructor(state = {}) {
|
|
61
63
|
this.state = state;
|
|
62
64
|
this.state = {
|
|
63
|
-
...
|
|
65
|
+
...{
|
|
64
66
|
env: new DotEnvContext(),
|
|
65
|
-
request: new
|
|
67
|
+
request: new BaseRequestContext(),
|
|
66
68
|
other: {},
|
|
67
|
-
}
|
|
69
|
+
},
|
|
70
|
+
...this.state,
|
|
68
71
|
};
|
|
69
72
|
}
|
|
70
73
|
get env() {
|
|
@@ -84,10 +87,5 @@ class Context {
|
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
exports.Context = Context;
|
|
87
|
-
Context.use = ({ env, request, other, }) => new Context({
|
|
88
|
-
env: env && (0, Constructor_1.ofConstruct)(env),
|
|
89
|
-
request: request && (0, Constructor_1.ofConstruct)(request),
|
|
90
|
-
other,
|
|
91
|
-
});
|
|
92
90
|
exports.ctx = new Context();
|
|
93
91
|
//# sourceMappingURL=Context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":";;;AACA,iCAA8B;AAE9B,+BAA8B;
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":";;;AACA,iCAA8B;AAE9B,+BAA8B;AAW9B,MAAa,aAAa;IAA1B;QACW,WAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC;QACtC,SAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC;QAC1C,SAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9B,SAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,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
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.22.2",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@thisisagile/easy-test": "8.
|
|
34
|
+
"@thisisagile/easy-test": "8.22.2",
|
|
35
35
|
"@types/form-urlencoded": "^4.4.0",
|
|
36
36
|
"@types/jsonwebtoken": "^8.5.8",
|
|
37
37
|
"@types/validator": "^13.7.0"
|
|
@@ -8,4 +8,12 @@ export class Weight extends Struct {
|
|
|
8
8
|
sizeInG = (): number => this.value * this.uow.gMultiplier;
|
|
9
9
|
|
|
10
10
|
gte = (w: Weight): boolean => this.sizeInG() >= w.sizeInG();
|
|
11
|
-
|
|
11
|
+
// gt = (w: Weight): boolean => this.sizeInG() > w.sizeInG();
|
|
12
|
+
lte = (w: Weight): boolean => this.sizeInG() <= w.sizeInG();
|
|
13
|
+
// lt = (w: Weight): boolean => this.sizeInG() < w.sizeInG();
|
|
14
|
+
|
|
15
|
+
between = (lower: Weight, upper = weight(Number.MAX_VALUE, this.uow)) => this.gte(lower) && this.lte(upper);
|
|
16
|
+
sum = (add: Weight): Weight => weight((this.sizeInG() + add.sizeInG()) / this.uow.gMultiplier, this.uow);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const weight = (value: number, uow?: UnitOfWeight): Weight => new Weight({ value, uow });
|
package/src/types/Context.ts
CHANGED
|
@@ -2,16 +2,15 @@ import { Uuid } from './Uuid';
|
|
|
2
2
|
import { text } from './Text';
|
|
3
3
|
import { Identity } from './Identity';
|
|
4
4
|
import { tryTo } from './Try';
|
|
5
|
-
import { Construct, ofConstruct } from './Constructor';
|
|
6
5
|
|
|
7
|
-
export
|
|
6
|
+
export interface EnvContext {
|
|
8
7
|
readonly domain: string;
|
|
9
8
|
readonly name: string;
|
|
10
9
|
readonly host: string;
|
|
11
10
|
readonly port: number;
|
|
12
11
|
|
|
13
12
|
get(key: string, alt?: string): string | undefined;
|
|
14
|
-
}
|
|
13
|
+
}
|
|
15
14
|
|
|
16
15
|
export class DotEnvContext implements EnvContext {
|
|
17
16
|
readonly domain = process.env.DOMAIN ?? 'easy';
|
|
@@ -23,11 +22,11 @@ export class DotEnvContext implements EnvContext {
|
|
|
23
22
|
tryTo(() =>
|
|
24
23
|
text(key)
|
|
25
24
|
.map(k => k.replace(/([a-z])([A-Z])/g, '$1 $2'))
|
|
26
|
-
.snake.toString()
|
|
25
|
+
.snake.toString()
|
|
27
26
|
).map(k => process.env[k] ?? alt).value;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
export
|
|
29
|
+
export interface RequestContext {
|
|
31
30
|
token?: any;
|
|
32
31
|
identity?: Identity;
|
|
33
32
|
jwt: string;
|
|
@@ -36,12 +35,12 @@ export type RequestContext = {
|
|
|
36
35
|
get<T>(key: string): T;
|
|
37
36
|
set<T>(key: string, value: T): T;
|
|
38
37
|
create: (f: () => void) => void;
|
|
39
|
-
}
|
|
38
|
+
}
|
|
40
39
|
|
|
41
|
-
export class
|
|
40
|
+
export class BaseRequestContext implements RequestContext {
|
|
42
41
|
private state: any = {};
|
|
43
42
|
|
|
44
|
-
get token(): any
|
|
43
|
+
get token(): any {
|
|
45
44
|
return this.get('token');
|
|
46
45
|
}
|
|
47
46
|
|
|
@@ -88,52 +87,48 @@ export class BaseContext implements RequestContext {
|
|
|
88
87
|
public readonly create = (f: () => void): void => f();
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Renamed to BaseRequestContext
|
|
92
|
+
*/
|
|
93
|
+
export class BaseContext extends BaseRequestContext {}
|
|
94
|
+
|
|
95
|
+
export interface Contexts {
|
|
96
|
+
env?: EnvContext;
|
|
97
|
+
request?: RequestContext;
|
|
94
98
|
other?: any;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
export class Context
|
|
98
|
-
constructor(protected state: Contexts
|
|
101
|
+
export class Context {
|
|
102
|
+
constructor(protected state: Contexts = {}) {
|
|
99
103
|
this.state = {
|
|
100
|
-
...
|
|
101
|
-
env: new DotEnvContext()
|
|
102
|
-
request: new
|
|
104
|
+
...{
|
|
105
|
+
env: new DotEnvContext(),
|
|
106
|
+
request: new BaseRequestContext(),
|
|
103
107
|
other: {},
|
|
104
|
-
}
|
|
108
|
+
},
|
|
109
|
+
...this.state,
|
|
105
110
|
};
|
|
106
111
|
}
|
|
107
112
|
|
|
108
|
-
get env():
|
|
109
|
-
return this.state.env as
|
|
113
|
+
get env(): EnvContext {
|
|
114
|
+
return this.state.env as EnvContext;
|
|
110
115
|
}
|
|
111
116
|
|
|
112
|
-
set env(env:
|
|
117
|
+
set env(env: EnvContext) {
|
|
113
118
|
this.state.env = env;
|
|
114
119
|
}
|
|
115
120
|
|
|
116
|
-
get request():
|
|
117
|
-
return this.state.request as
|
|
121
|
+
get request(): RequestContext {
|
|
122
|
+
return this.state.request as RequestContext;
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
set request(request:
|
|
125
|
+
set request(request: RequestContext) {
|
|
121
126
|
this.state.request = request;
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
get other(): any {
|
|
125
130
|
return this.state.other;
|
|
126
131
|
}
|
|
127
|
-
|
|
128
|
-
static use = <E extends EnvContext, R extends RequestContext>({
|
|
129
|
-
env,
|
|
130
|
-
request,
|
|
131
|
-
other,
|
|
132
|
-
}: { env?: Construct<E>, request?: Construct<R>, other?: any }): Context<E, R> => new Context<E, R>({
|
|
133
|
-
env: env && ofConstruct(env),
|
|
134
|
-
request: request && ofConstruct(request),
|
|
135
|
-
other,
|
|
136
|
-
});
|
|
137
132
|
}
|
|
138
133
|
|
|
139
134
|
export const ctx = new Context();
|
package/src/utils/Sentence.ts
CHANGED