strata.client.core 0.0.0 → 0.0.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/Main → Main}/AbstractApplication.d.ts +13 -13
- package/{dist/Main → Main}/AbstractApplication.js +23 -21
- package/Main/AbstractApplication.js.map +1 -0
- package/{dist/Main → Main}/IApplication.d.ts +4 -4
- package/{dist/Presenter/IUpdatable.js → Main/IApplication.js} +3 -3
- package/Main/IApplication.js.map +1 -0
- package/Main/index.d.ts +2 -0
- package/Main/index.js +6 -0
- package/Main/index.js.map +1 -0
- package/{dist/Presenter → Presenter}/AbstractPresenter.d.ts +11 -11
- package/{dist/Presenter → Presenter}/AbstractPresenter.js +21 -20
- package/Presenter/AbstractPresenter.js.map +1 -0
- package/{dist/Presenter → Presenter}/AbstractUpdatable.d.ts +14 -14
- package/{dist/Presenter → Presenter}/AbstractUpdatable.js +32 -30
- package/Presenter/AbstractUpdatable.js.map +1 -0
- package/{dist/Presenter → Presenter}/Action.d.ts +9 -9
- package/{dist/Presenter → Presenter}/Action.js +18 -16
- package/Presenter/Action.js.map +1 -0
- package/{dist/Presenter → Presenter}/IAction.d.ts +5 -5
- package/{dist/Presenter → Presenter}/IAction.js +2 -2
- package/Presenter/IAction.js.map +1 -0
- package/{dist/Presenter → Presenter}/IModelStore.d.ts +11 -11
- package/{dist/Service/IResponse.js → Presenter/IModelStore.js} +3 -3
- package/Presenter/IModelStore.js.map +1 -0
- package/{dist/Presenter → Presenter}/IPresentable.d.ts +4 -4
- package/{dist/Presenter/IPresenter.js → Presenter/IPresentable.js} +3 -3
- package/Presenter/IPresentable.js.map +1 -0
- package/{dist/Presenter → Presenter}/IPresenter.d.ts +4 -4
- package/Presenter/IPresenter.js +3 -0
- package/Presenter/IPresenter.js.map +1 -0
- package/{dist/Presenter → Presenter}/IUpdatable.d.ts +8 -8
- package/Presenter/IUpdatable.js +3 -0
- package/Presenter/IUpdatable.js.map +1 -0
- package/{dist/Presenter → Presenter}/IView.d.ts +4 -4
- package/{dist/Presenter → Presenter}/IView.js +2 -2
- package/Presenter/IView.js.map +1 -0
- package/{dist/Presenter → Presenter}/IViewVisitor.d.ts +4 -4
- package/Presenter/IViewVisitor.js +3 -0
- package/Presenter/IViewVisitor.js.map +1 -0
- package/{dist/Presenter → Presenter}/ModelStore.d.ts +16 -16
- package/{dist/Presenter → Presenter}/ModelStore.js +58 -56
- package/Presenter/ModelStore.js.map +1 -0
- package/{dist/Presenter → Presenter}/SimpleAction.d.ts +9 -9
- package/{dist/Presenter → Presenter}/SimpleAction.js +19 -17
- package/Presenter/SimpleAction.js.map +1 -0
- package/Presenter/index.d.ts +10 -0
- package/Presenter/index.js +14 -0
- package/Presenter/index.js.map +1 -0
- package/{dist/Service → Service}/AbstractRestClient.d.ts +23 -23
- package/{dist/Service → Service}/AbstractRestClient.js +94 -91
- package/{dist/Service → Service}/AbstractRestClient.js.map +1 -1
- package/{dist/Service → Service}/IResponse.d.ts +8 -8
- package/{src/Presenter/IAction.js → Service/IResponse.js} +3 -3
- package/Service/IResponse.js.map +1 -0
- package/{dist/Service → Service}/IResponseProcessor.d.ts +4 -4
- package/{dist/Main/IApplication.js → Service/IResponseProcessor.js} +3 -3
- package/Service/IResponseProcessor.js.map +1 -0
- package/{dist/Service → Service}/ServiceError.d.ts +10 -10
- package/{dist/Service → Service}/ServiceError.js +31 -28
- package/Service/ServiceError.js.map +1 -0
- package/{dist/Service → Service}/StandardResponse.d.ts +12 -12
- package/{dist/Service → Service}/StandardResponse.js +31 -29
- package/Service/StandardResponse.js.map +1 -0
- package/{dist/Service → Service}/StandardResponseProcessor.d.ts +5 -5
- package/{dist/Service → Service}/StandardResponseProcessor.js +16 -16
- package/Service/StandardResponseProcessor.js.map +1 -0
- package/Service/index.d.ts +6 -0
- package/Service/index.js +12 -0
- package/Service/index.js.map +1 -0
- package/package.json +15 -20
- package/strata.client.core-v0.0.1.tgz +0 -0
- package/Strata.Client.Core.iml +0 -10
- package/dist/Main/AbstractApplication.js.map +0 -1
- package/dist/Main/IApplication.js.map +0 -1
- package/dist/Presenter/AbstractPresenter.js.map +0 -1
- package/dist/Presenter/AbstractUpdatable.js.map +0 -1
- package/dist/Presenter/Action.js.map +0 -1
- package/dist/Presenter/IAction.js.map +0 -1
- package/dist/Presenter/IModelStore.js +0 -3
- package/dist/Presenter/IModelStore.js.map +0 -1
- package/dist/Presenter/IPresentable.js +0 -3
- package/dist/Presenter/IPresentable.js.map +0 -1
- package/dist/Presenter/IPresenter.js.map +0 -1
- package/dist/Presenter/IUpdatable.js.map +0 -1
- package/dist/Presenter/IView.js.map +0 -1
- package/dist/Presenter/IViewVisitor.js +0 -3
- package/dist/Presenter/IViewVisitor.js.map +0 -1
- package/dist/Presenter/ModelStore.js.map +0 -1
- package/dist/Presenter/SimpleAction.js.map +0 -1
- package/dist/Service/IResponse.js.map +0 -1
- package/dist/Service/IResponseProcessor.js +0 -3
- package/dist/Service/IResponseProcessor.js.map +0 -1
- package/dist/Service/ServiceError.js.map +0 -1
- package/dist/Service/StandardResponse.js.map +0 -1
- package/dist/Service/StandardResponseProcessor.js.map +0 -1
- package/dist/index.d.ts +0 -18
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/src/Main/AbstractApplication.ts +0 -39
- package/src/Main/IApplication.ts +0 -7
- package/src/Presenter/AbstractPresenter.js +0 -21
- package/src/Presenter/AbstractPresenter.js.map +0 -1
- package/src/Presenter/AbstractPresenter.ts +0 -35
- package/src/Presenter/AbstractUpdatable.js +0 -27
- package/src/Presenter/AbstractUpdatable.js.map +0 -1
- package/src/Presenter/AbstractUpdatable.ts +0 -52
- package/src/Presenter/Action.ts +0 -27
- package/src/Presenter/IAction.js.map +0 -1
- package/src/Presenter/IAction.ts +0 -9
- package/src/Presenter/IModelStore.js +0 -3
- package/src/Presenter/IModelStore.js.map +0 -1
- package/src/Presenter/IModelStore.ts +0 -21
- package/src/Presenter/IPresentable.ts +0 -9
- package/src/Presenter/IPresenter.js +0 -3
- package/src/Presenter/IPresenter.js.map +0 -1
- package/src/Presenter/IPresenter.ts +0 -6
- package/src/Presenter/IUpdatable.js +0 -3
- package/src/Presenter/IUpdatable.js.map +0 -1
- package/src/Presenter/IUpdatable.ts +0 -16
- package/src/Presenter/IView.ts +0 -7
- package/src/Presenter/IViewVisitor.ts +0 -7
- package/src/Presenter/ModelStore.js +0 -32
- package/src/Presenter/ModelStore.js.map +0 -1
- package/src/Presenter/ModelStore.ts +0 -95
- package/src/Presenter/SimpleAction.ts +0 -27
- package/src/Service/AbstractRestClient.ts +0 -171
- package/src/Service/IResponse.ts +0 -16
- package/src/Service/IResponseProcessor.ts +0 -7
- package/src/Service/ServiceError.ts +0 -43
- package/src/Service/StandardResponse.ts +0 -48
- package/src/Service/StandardResponseProcessor.ts +0 -21
- package/src/index.ts +0 -20
- package/strata.client.core-0.0.0.tgz +0 -0
- package/tsconfig.json +0 -18
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {IUpdatable} from "./IUpdatable";
|
|
2
|
-
import {IAction} from "./IAction";
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
interface IModelStore
|
|
6
|
-
{
|
|
7
|
-
attach<M>(updatable: IUpdatable<M>): IModelStore;
|
|
8
|
-
|
|
9
|
-
detach<M>(updatable: IUpdatable<M>): IModelStore;
|
|
10
|
-
|
|
11
|
-
insert<M>(key: string,model:M): IModelStore;
|
|
12
|
-
|
|
13
|
-
remove(key: string): IModelStore;
|
|
14
|
-
|
|
15
|
-
hasUpdatable(key: string): boolean;
|
|
16
|
-
|
|
17
|
-
hasModel(key: string): boolean;
|
|
18
|
-
|
|
19
|
-
apply<M>(action: IAction<M>): void;
|
|
20
|
-
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IPresenter.js","sourceRoot":"","sources":["IPresenter.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IUpdatable.js","sourceRoot":"","sources":["IUpdatable.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {IModelStore} from "./IModelStore";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
interface IUpdatable<M>
|
|
5
|
-
{
|
|
6
|
-
setModelStore(modelStore: IModelStore): void;
|
|
7
|
-
|
|
8
|
-
clearModelStore(): void;
|
|
9
|
-
|
|
10
|
-
getModelStore(): IModelStore;
|
|
11
|
-
|
|
12
|
-
getKey(): string;
|
|
13
|
-
|
|
14
|
-
update(model: M);
|
|
15
|
-
|
|
16
|
-
}
|
package/src/Presenter/IView.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelStore = void 0;
|
|
4
|
-
class ModelStore {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.updatables = new Map();
|
|
7
|
-
this.models = new Map();
|
|
8
|
-
}
|
|
9
|
-
attach(updatable) {
|
|
10
|
-
this.updatables.set(updatable.getKey(), updatable);
|
|
11
|
-
return this;
|
|
12
|
-
}
|
|
13
|
-
detach(updatable) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
insert(key, model) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
remove(key) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
hasModel(key) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
hasUpdatable(key) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
apply(action) {
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.ModelStore = ModelStore;
|
|
32
|
-
//# sourceMappingURL=ModelStore.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ModelStore.js","sourceRoot":"","sources":["ModelStore.ts"],"names":[],"mappings":";;;AAIA,MACM,UAAU;IAMZ;QAEI,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAiB,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC5C,CAAC;IAEM,MAAM,CAAI,SAAwB;QAErC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,EAAC,SAAS,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,MAAM,CAAI,SAAwB;QAErC,OAAO,SAAS,CAAC;IACrB,CAAC;IAEM,MAAM,CAAI,GAAW,EAAE,KAAQ;QAElC,OAAO,SAAS,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,GAAW;QAErB,OAAO,SAAS,CAAC;IACrB,CAAC;IAEM,QAAQ,CAAC,GAAW;QAEvB,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,YAAY,CAAC,GAAW;QAE3B,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,KAAK,CAAI,MAAkB;IAElC,CAAC;CAEJ;AAhDD,gCAgDC"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import {IModelStore} from "./IModelStore";
|
|
2
|
-
import {IAction} from "./IAction";
|
|
3
|
-
import {IUpdatable} from "./IUpdatable";
|
|
4
|
-
import {ICompletionStage,IMultiMap} from 'strata.foundation.core';
|
|
5
|
-
import {MultiMap} from 'strata.foundation.core';
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
class ModelStore
|
|
9
|
-
implements IModelStore
|
|
10
|
-
{
|
|
11
|
-
private updatables: IMultiMap<string,Object>;
|
|
12
|
-
private models: Map<string,Object>;
|
|
13
|
-
|
|
14
|
-
constructor()
|
|
15
|
-
{
|
|
16
|
-
this.updatables = new MultiMap<string,Object>();
|
|
17
|
-
this.models = new Map<string, Object>();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
attach<M>(updatable: IUpdatable<M>): IModelStore
|
|
21
|
-
{
|
|
22
|
-
this.updatables.put(updatable.getKey(),updatable);
|
|
23
|
-
|
|
24
|
-
if (updatable.getModelStore() != this)
|
|
25
|
-
updatable.setModelStore(this);
|
|
26
|
-
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
detach<M>(updatable: IUpdatable<M>): IModelStore
|
|
31
|
-
{
|
|
32
|
-
this.updatables.remove(updatable.getKey(),updatable);
|
|
33
|
-
|
|
34
|
-
if (updatable.getModelStore() == this)
|
|
35
|
-
updatable.clearModelStore();
|
|
36
|
-
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
insert<M>(key: string, model: M): IModelStore
|
|
41
|
-
{
|
|
42
|
-
this.models.set(key,model);
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
remove(key: string): IModelStore
|
|
47
|
-
{
|
|
48
|
-
this.models.delete(key);
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
hasUpdatable(key: string): boolean
|
|
53
|
-
{
|
|
54
|
-
return this.updatables.containsKey(key);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
hasModel(key: string): boolean
|
|
58
|
-
{
|
|
59
|
-
return this.models.has(key);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
apply<M>(action: IAction<M>): void
|
|
63
|
-
{
|
|
64
|
-
let key: string = action.getKey();
|
|
65
|
-
let updatables: Array<Object> = this.updatables.get(key);
|
|
66
|
-
let model: M = <M>this.models.get(key);
|
|
67
|
-
let updated: ICompletionStage<M> = action.apply(model);
|
|
68
|
-
|
|
69
|
-
this.replace(key,updated,model,updatables);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private replace<M>(
|
|
73
|
-
key: string,
|
|
74
|
-
updated: ICompletionStage<M>,
|
|
75
|
-
previous: M,
|
|
76
|
-
updatables: Array<Object>): void
|
|
77
|
-
{
|
|
78
|
-
updated
|
|
79
|
-
.thenApply(
|
|
80
|
-
current =>
|
|
81
|
-
{
|
|
82
|
-
this.models.delete(key);
|
|
83
|
-
this.models.set(key,current);
|
|
84
|
-
return current;
|
|
85
|
-
})
|
|
86
|
-
.thenAccept(
|
|
87
|
-
current =>
|
|
88
|
-
updatables
|
|
89
|
-
.map(updatable => <IUpdatable<M>>updatable)
|
|
90
|
-
.forEach(updatable => updatable.update(current)),
|
|
91
|
-
error => console.error(error))
|
|
92
|
-
.subscribe();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {IAction} from "./IAction";
|
|
2
|
-
import {CompletableObservable,ICompletionStage} from "strata.foundation.core";
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
class SimpleAction<M>
|
|
6
|
-
implements IAction<M>
|
|
7
|
-
{
|
|
8
|
-
private readonly key: string;
|
|
9
|
-
private readonly action: (model: M) => M;
|
|
10
|
-
|
|
11
|
-
constructor(key: string,action: (model: M) => M)
|
|
12
|
-
{
|
|
13
|
-
this.key = key;
|
|
14
|
-
this.action = action;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getKey(): string
|
|
18
|
-
{
|
|
19
|
-
return this.key;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
apply(model: M): ICompletionStage<M>
|
|
23
|
-
{
|
|
24
|
-
return CompletableObservable.fromResult(this.action(model));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import {CompletableObservable,ICompletionStage} from "strata.foundation.core";
|
|
2
|
-
import {IResponseProcessor} from "./IResponseProcessor";
|
|
3
|
-
import {StandardResponseProcessor} from "./StandardResponseProcessor";
|
|
4
|
-
import {StandardResponse} from "./StandardResponse";
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
abstract class AbstractRestClient
|
|
8
|
-
{
|
|
9
|
-
private readonly baseUrl: string;
|
|
10
|
-
private headers: Headers;
|
|
11
|
-
private readonly responseProcessor: IResponseProcessor;
|
|
12
|
-
|
|
13
|
-
protected constructor(baseUrl: string,responseProcessor?: IResponseProcessor)
|
|
14
|
-
{
|
|
15
|
-
this.baseUrl = baseUrl;
|
|
16
|
-
this.headers = new Headers();
|
|
17
|
-
this.responseProcessor =
|
|
18
|
-
responseProcessor == null
|
|
19
|
-
? new StandardResponseProcessor()
|
|
20
|
-
: responseProcessor;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected setHeader(headerKey: string,headerValue: string): AbstractRestClient
|
|
24
|
-
{
|
|
25
|
-
this.headers.append(headerKey,headerValue);
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
protected clearHeader(headerKey: string): AbstractRestClient
|
|
30
|
-
{
|
|
31
|
-
this.headers.delete(headerKey);
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected clearHeaders(): AbstractRestClient
|
|
36
|
-
{
|
|
37
|
-
this.headers = new Headers();
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected getHeader(headerKey: string): string
|
|
42
|
-
{
|
|
43
|
-
return this.headers.get(headerKey);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
protected hasHeader(headerKey: string): boolean
|
|
47
|
-
{
|
|
48
|
-
return this.headers.has(headerKey);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected doPost<TReply,TRequest>(methodPath:string,request: TRequest):
|
|
52
|
-
ICompletionStage<TReply>
|
|
53
|
-
{
|
|
54
|
-
return this.sendRequestWithBody("POST",methodPath,request);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
protected doPut<TReply,TRequest>(methodPath:string,request: TRequest):
|
|
58
|
-
ICompletionStage<TReply>
|
|
59
|
-
{
|
|
60
|
-
return this.sendRequestWithBody("PUT",methodPath,request);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
protected doDelete<TReply>(
|
|
64
|
-
methodPath:string,
|
|
65
|
-
pathParams: Map<string,Object>,
|
|
66
|
-
queryParams: Map<string,Object>):
|
|
67
|
-
ICompletionStage<TReply>
|
|
68
|
-
{
|
|
69
|
-
return this.sendRequestWithParameters(
|
|
70
|
-
"DELETE",
|
|
71
|
-
methodPath,
|
|
72
|
-
pathParams,
|
|
73
|
-
queryParams);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
protected doGet<TReply>(
|
|
77
|
-
methodPath:string,
|
|
78
|
-
pathParams: Map<string,Object>,
|
|
79
|
-
queryParams: Map<string,Object>):
|
|
80
|
-
ICompletionStage<TReply>
|
|
81
|
-
{
|
|
82
|
-
return this.sendRequestWithParameters(
|
|
83
|
-
"GET",
|
|
84
|
-
methodPath,
|
|
85
|
-
pathParams,
|
|
86
|
-
queryParams);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private sendRequestWithBody<TReply,TRequest>(
|
|
90
|
-
method: string,
|
|
91
|
-
methodPath:string,
|
|
92
|
-
request: TRequest):
|
|
93
|
-
ICompletionStage<TReply>
|
|
94
|
-
{
|
|
95
|
-
return CompletableObservable.fromPromise(
|
|
96
|
-
fetch(
|
|
97
|
-
this.getUrl(methodPath),
|
|
98
|
-
{
|
|
99
|
-
method: method,
|
|
100
|
-
body: JSON.stringify(request),
|
|
101
|
-
headers: this.headers
|
|
102
|
-
}).then(response => this.processResponse(response,methodPath)));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private sendRequestWithParameters<TReply>(
|
|
106
|
-
method: string,
|
|
107
|
-
methodPath:string,
|
|
108
|
-
pathParams: Map<string,Object>,
|
|
109
|
-
queryParams: Map<string,Object>):
|
|
110
|
-
ICompletionStage<TReply>
|
|
111
|
-
{
|
|
112
|
-
let requestUrl: string =
|
|
113
|
-
this.resolveTemplates(this.getUrl(methodPath),pathParams);
|
|
114
|
-
|
|
115
|
-
requestUrl = this.appendQueryParams(requestUrl,queryParams);
|
|
116
|
-
|
|
117
|
-
return CompletableObservable.fromPromise(
|
|
118
|
-
fetch(
|
|
119
|
-
requestUrl,
|
|
120
|
-
{
|
|
121
|
-
method: method,
|
|
122
|
-
headers: this.headers
|
|
123
|
-
}).then(response => this.processResponse(response,methodPath)));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private getUrl(methodPath: string): string
|
|
127
|
-
{
|
|
128
|
-
return this.baseUrl + "/" + methodPath;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private resolveTemplates(inputUrl: string,pathParams: Map<string,Object>): string
|
|
132
|
-
{
|
|
133
|
-
pathParams
|
|
134
|
-
.forEach(
|
|
135
|
-
(value,key,ignore) =>
|
|
136
|
-
{
|
|
137
|
-
let template: string = '{' + key + '}';
|
|
138
|
-
return inputUrl = inputUrl.replace(template,value.toString);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
return inputUrl;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private appendQueryParams(inputUrl: string,queryParams: Map<string,Object>): string
|
|
145
|
-
{
|
|
146
|
-
let i: number = 0;
|
|
147
|
-
|
|
148
|
-
queryParams
|
|
149
|
-
.forEach(
|
|
150
|
-
(value,key,ignore) =>
|
|
151
|
-
{
|
|
152
|
-
if (i == 0)
|
|
153
|
-
inputUrl = inputUrl + '?';
|
|
154
|
-
else
|
|
155
|
-
inputUrl = inputUrl + '&';
|
|
156
|
-
|
|
157
|
-
++i;
|
|
158
|
-
return inputUrl = inputUrl + key + '=' + value.toString();
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
return inputUrl;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private processResponse<TReply>(response: Response,methodPath: string):
|
|
165
|
-
Promise<TReply>
|
|
166
|
-
{
|
|
167
|
-
return this
|
|
168
|
-
.responseProcessor
|
|
169
|
-
.process<TReply>(new StandardResponse(this.baseUrl,methodPath,response));
|
|
170
|
-
}
|
|
171
|
-
}
|
package/src/Service/IResponse.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {IResponse} from "./IResponse";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
class ServiceError
|
|
5
|
-
extends Error
|
|
6
|
-
{
|
|
7
|
-
private readonly requestPath: string;
|
|
8
|
-
private readonly status: number;
|
|
9
|
-
private readonly statusReason: string;
|
|
10
|
-
|
|
11
|
-
constructor(response: IResponse)
|
|
12
|
-
{
|
|
13
|
-
super(initializeServiceErrorMessage(response));
|
|
14
|
-
this.requestPath = response.getRequestPath();
|
|
15
|
-
this.status = response.getStatus();
|
|
16
|
-
this.statusReason = response.getStatusReason();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getRequestPath(): string
|
|
20
|
-
{
|
|
21
|
-
return this.requestPath;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getStatus(): number
|
|
25
|
-
{
|
|
26
|
-
return this.status;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getStatusReason(): string
|
|
30
|
-
{
|
|
31
|
-
return this.statusReason;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function initializeServiceErrorMessage(response: IResponse): string
|
|
37
|
-
{
|
|
38
|
-
return "Exception during response processing:\n" +
|
|
39
|
-
"\tFrom request: " + response.getRequestPath() + '\n' +
|
|
40
|
-
"\tResponse status code: " + response.getStatus() + '\n' +
|
|
41
|
-
"\tResponse status message: " + response.getStatusReason() + '\n' +
|
|
42
|
-
"\tResponse media type: " + response.getMediaType() + '\n';
|
|
43
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {IResponse} from "./IResponse";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
class StandardResponse
|
|
5
|
-
implements IResponse
|
|
6
|
-
{
|
|
7
|
-
private readonly requestPath: string;
|
|
8
|
-
private readonly response: Response;
|
|
9
|
-
|
|
10
|
-
constructor(rootPath: string,methodPath: string,response: Response)
|
|
11
|
-
{
|
|
12
|
-
this.requestPath = rootPath + '/' + methodPath;
|
|
13
|
-
this.response = response;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getRequestPath(): string
|
|
17
|
-
{
|
|
18
|
-
return this.requestPath;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getMediaType(): string
|
|
22
|
-
{
|
|
23
|
-
if (this.response.headers.has("Content-Type"))
|
|
24
|
-
return this.response.headers.get("Content-Type");
|
|
25
|
-
|
|
26
|
-
return "unknown";
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getStatus(): number
|
|
30
|
-
{
|
|
31
|
-
return this.response.status;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getStatusReason(): string
|
|
35
|
-
{
|
|
36
|
-
return this.response.statusText;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
readEntity<E>(): Promise<E>
|
|
40
|
-
{
|
|
41
|
-
return this.response.json().then(value => <E>value);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
close(): void
|
|
45
|
-
{
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {IResponseProcessor} from "./IResponseProcessor";
|
|
2
|
-
import {IResponse} from "./IResponse";
|
|
3
|
-
import {ServiceError} from "./ServiceError";
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
class StandardResponseProcessor
|
|
7
|
-
implements IResponseProcessor
|
|
8
|
-
{
|
|
9
|
-
process<R>(response: IResponse): Promise<R>
|
|
10
|
-
{
|
|
11
|
-
switch (response.getStatus())
|
|
12
|
-
{
|
|
13
|
-
case 200: // OK
|
|
14
|
-
case 500: //INTERNAL_SERVER_ERROR
|
|
15
|
-
return response.readEntity<R>();
|
|
16
|
-
|
|
17
|
-
default:
|
|
18
|
-
throw new ServiceError(response);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export {IUpdatable} from './Presenter/IUpdatable';
|
|
2
|
-
export {IPresentable} from './Presenter/IPresentable';
|
|
3
|
-
export {IAction} from './Presenter/IAction';
|
|
4
|
-
export {IModelStore} from './Presenter/IModelStore';
|
|
5
|
-
export {IPresenter} from './Presenter/IPresenter'
|
|
6
|
-
export {AbstractUpdatable} from './Presenter/AbstractUpdatable';
|
|
7
|
-
export {AbstractPresenter} from './Presenter/AbstractPresenter';
|
|
8
|
-
export {ModelStore} from './Presenter/ModelStore';
|
|
9
|
-
export {Action} from './Presenter/Action';
|
|
10
|
-
export {SimpleAction} from './Presenter/SimpleAction';
|
|
11
|
-
|
|
12
|
-
export {IResponse} from "./Service/IResponse";
|
|
13
|
-
export {IResponseProcessor} from "./Service/IResponseProcessor";
|
|
14
|
-
export {StandardResponse} from "./Service/StandardResponse";
|
|
15
|
-
export {StandardResponseProcessor} from "./Service/StandardResponseProcessor";
|
|
16
|
-
export {AbstractRestClient} from "./Service/AbstractRestClient";
|
|
17
|
-
export {ServiceError} from "./Service/ServiceError";
|
|
18
|
-
|
|
19
|
-
export {IApplication} from './Main/IApplication';
|
|
20
|
-
export {AbstractApplication} from './Main/AbstractApplication';
|
|
Binary file
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"target": "es2018",
|
|
5
|
-
"sourceMap": true,
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"outDir": "./dist"
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"src/**/*",
|
|
11
|
-
"typings/**/*"
|
|
12
|
-
],
|
|
13
|
-
"exclude": [
|
|
14
|
-
"node_modules",
|
|
15
|
-
"lib",
|
|
16
|
-
"Strata.Client.Core.iml"
|
|
17
|
-
]
|
|
18
|
-
}
|