rystem.repository.client 0.0.3 → 0.0.7
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/README.md +208 -0
- package/package.json +4 -1
- package/lib/engine/Repository.d.ts +0 -18
- package/lib/engine/Repository.js +0 -225
- package/lib/engine/batch/Batch.d.ts +0 -4
- package/lib/engine/batch/Batch.js +0 -2
- package/lib/engine/batch/BatchBuilder.d.ts +0 -10
- package/lib/engine/batch/BatchBuilder.js +0 -56
- package/lib/engine/batch/BatchElement.d.ts +0 -5
- package/lib/engine/batch/BatchElement.js +0 -2
- package/lib/engine/batch/BatchResult.d.ts +0 -6
- package/lib/engine/batch/BatchResult.js +0 -2
- package/lib/engine/batch/BatchResults.d.ts +0 -4
- package/lib/engine/batch/BatchResults.js +0 -2
- package/lib/engine/query/FilterOperationAsString.d.ts +0 -5
- package/lib/engine/query/FilterOperationAsString.js +0 -2
- package/lib/engine/query/FilterOperations.d.ts +0 -11
- package/lib/engine/query/FilterOperations.js +0 -15
- package/lib/engine/query/QueryBuilder.d.ts +0 -22
- package/lib/engine/query/QueryBuilder.js +0 -138
- package/lib/engine/query/SerializableFilter.d.ts +0 -4
- package/lib/engine/query/SerializableFilter.js +0 -2
- package/lib/engine/query/filter/WhereBuilder.d.ts +0 -26
- package/lib/engine/query/filter/WhereBuilder.js +0 -152
- package/lib/index.d.ts +0 -9
- package/lib/index.js +0 -5
- package/lib/interfaces/ICommand.d.ts +0 -8
- package/lib/interfaces/ICommand.js +0 -2
- package/lib/interfaces/IQuery.d.ts +0 -7
- package/lib/interfaces/IQuery.js +0 -2
- package/lib/interfaces/IRepository.d.ts +0 -4
- package/lib/interfaces/IRepository.js +0 -2
- package/lib/models/Entity.d.ts +0 -4
- package/lib/models/Entity.js +0 -2
- package/lib/models/State.d.ts +0 -9
- package/lib/models/State.js +0 -2
- package/lib/servicecollection/RepositoryServices.d.ts +0 -19
- package/lib/servicecollection/RepositoryServices.js +0 -80
- package/lib/servicecollection/RepositorySettings.d.ts +0 -7
- package/lib/servicecollection/RepositorySettings.js +0 -16
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
### [What is Rystem?](https://github.com/KeyserDSoze/Rystem)
|
|
2
|
+
|
|
3
|
+
# Client for Repository Framework
|
|
4
|
+
|
|
5
|
+
## Services setup
|
|
6
|
+
You need to install through the RepositoryServices class
|
|
7
|
+
all the repository clients, with settings.
|
|
8
|
+
|
|
9
|
+
.Create() => set a default uri for all clients.
|
|
10
|
+
In settings you have:
|
|
11
|
+
- name: a value to retrieve the installed client.
|
|
12
|
+
- path: a path which concatened with default uri create the final url for your client.
|
|
13
|
+
- uri: override the default uri and the path
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
import { RepositoryServices } from "rystem.repository.client";
|
|
17
|
+
|
|
18
|
+
RepositoryServices
|
|
19
|
+
.Create("https://localhost:7058/api/")
|
|
20
|
+
.addRepository<IperUser, string>(x => {
|
|
21
|
+
x.name = "test";
|
|
22
|
+
x.path = "SuperUser";
|
|
23
|
+
})
|
|
24
|
+
.addRepository<SuperUser, string>(x => {
|
|
25
|
+
x.name = "test2"
|
|
26
|
+
x.uri = "https://localhost:9090/api/SuperUser/inmemory/"
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
You can also add Command or Query for your CQRS pattern with
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
RepositoryServices
|
|
34
|
+
.Create("https://localhost:7058/api/")
|
|
35
|
+
.addCommand<IperUser, string>(x => {
|
|
36
|
+
x.name = "test";
|
|
37
|
+
x.path = "SuperUser";
|
|
38
|
+
})
|
|
39
|
+
.addQuery<SuperUser, string>(x => {
|
|
40
|
+
x.name = "test2"
|
|
41
|
+
x.uri = "https://localhost:9090/api/SuperUser/inmemory/"
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Add Custom Headers to each request
|
|
46
|
+
For instance when you need to add a token from your authentication flow you can use this implementation.
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
RepositoryServices
|
|
50
|
+
.Create("http://localhost:5000/api/")
|
|
51
|
+
.addRepository<IperUser, string>(x => {
|
|
52
|
+
x.name = "test";
|
|
53
|
+
x.path = "SuperUser";
|
|
54
|
+
x.addHeadersEnricher((...args) => {
|
|
55
|
+
return {
|
|
56
|
+
"Authorization-UI": "Bearer dsjadjalsdjalsdjalsda"
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
x.addHeadersEnricher((endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any) => {
|
|
60
|
+
return {
|
|
61
|
+
"Authorization-UI2": "Bearer dsjadjalsdjalsdjalsda"
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Add Custom Error Handlers
|
|
68
|
+
For instance when you need to capture a not authorized error to request a new authentication flow before a new request.
|
|
69
|
+
Returning true you can retry automatically the request, with false the request chain will be stopped.
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
RepositoryServices
|
|
73
|
+
.Create("http://localhost:5000/api/")
|
|
74
|
+
.addRepository<IperUser, string>(x => {
|
|
75
|
+
x.name = "test";
|
|
76
|
+
x.path = "SuperUser";
|
|
77
|
+
x.addErrorHandler((endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any, err: any) => {
|
|
78
|
+
return (err as string).startsWith("big error");
|
|
79
|
+
});
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
Always with RepositoryServices class you can retrieve with
|
|
85
|
+
the correct name the integration you setup during your startup.
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
const repository = RepositoryServices
|
|
89
|
+
.Repository<IperUser, string>("test");
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
You can also retrieve CQRS interfaces.
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
const command = RepositoryServices
|
|
96
|
+
.Command<IperUser, string>("test");
|
|
97
|
+
const query = RepositoryServices
|
|
98
|
+
.Query<IperUser, string>("test2");
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Methods
|
|
102
|
+
|
|
103
|
+
### Insert
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
let response: State<IperUser, string> =
|
|
107
|
+
await repository.insert(id, iperUser);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Update
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
let response: State<IperUser, string> =
|
|
114
|
+
await repository.update(id, iperUser);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Exist
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
let response: State<IperUser, string> =
|
|
121
|
+
await repository.exist(id);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Delete
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
let response: State<IperUser, string> =
|
|
128
|
+
await repository.delete(id);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Batch operations
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
const batcher = repository.batch();
|
|
135
|
+
batcher
|
|
136
|
+
.addInsert(id1, iperUser1)
|
|
137
|
+
.addUpdate(id2, iperUser2)
|
|
138
|
+
.addDelete(id3);
|
|
139
|
+
const batchResults: BatchResults<IperUser, string> =
|
|
140
|
+
await batcher.execute();
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Query operations
|
|
144
|
+
- get all elements
|
|
145
|
+
```
|
|
146
|
+
let queryResults = await repository.query().execute();
|
|
147
|
+
```
|
|
148
|
+
- filter as string
|
|
149
|
+
```
|
|
150
|
+
let id = "someId";
|
|
151
|
+
let queryResults = await repository
|
|
152
|
+
.query()
|
|
153
|
+
.filter(`x => x.id == "${id}"`)
|
|
154
|
+
.execute();
|
|
155
|
+
```
|
|
156
|
+
- build a filter (similar to the previous example with addiction of ordering by ascending all retrieved elements)
|
|
157
|
+
```
|
|
158
|
+
let queryResults = await repository
|
|
159
|
+
.query()
|
|
160
|
+
.where()
|
|
161
|
+
.select(x => x.id)
|
|
162
|
+
.equal(id)
|
|
163
|
+
.build()
|
|
164
|
+
.orderBy(x => x.name)
|
|
165
|
+
.execute();
|
|
166
|
+
```
|
|
167
|
+
- build a filter and count all elements
|
|
168
|
+
```
|
|
169
|
+
const count = await repository
|
|
170
|
+
.query()
|
|
171
|
+
.where()
|
|
172
|
+
.select(x => x.id)
|
|
173
|
+
.equal(id)
|
|
174
|
+
.build()
|
|
175
|
+
.count();
|
|
176
|
+
```
|
|
177
|
+
- build a filter and sum a column of all elements
|
|
178
|
+
```
|
|
179
|
+
const sum = await repository
|
|
180
|
+
.query()
|
|
181
|
+
.where()
|
|
182
|
+
.select(x => x.id)
|
|
183
|
+
.equal(id)
|
|
184
|
+
.build()
|
|
185
|
+
.sum(x => x.port);
|
|
186
|
+
```
|
|
187
|
+
- build a filter with greaterThanOrEqual for instance
|
|
188
|
+
```
|
|
189
|
+
const portGreaterThanZero = await repository
|
|
190
|
+
.query()
|
|
191
|
+
.where()
|
|
192
|
+
.openRoundBracket()
|
|
193
|
+
.select(x => x.port)
|
|
194
|
+
.greaterThanOrEqual(0)
|
|
195
|
+
.build()
|
|
196
|
+
.count();
|
|
197
|
+
```
|
|
198
|
+
- same of previous but ordered by a column
|
|
199
|
+
```
|
|
200
|
+
const portGreaterThanZeroOrderedByName = await repository
|
|
201
|
+
.query()
|
|
202
|
+
.where()
|
|
203
|
+
.select(x => x.port)
|
|
204
|
+
.greaterThanOrEqual(0)
|
|
205
|
+
.build()
|
|
206
|
+
.orderBy(x => x.name)
|
|
207
|
+
.execute();
|
|
208
|
+
```
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rystem.repository.client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"author": "Alessandro Rapiti <alessandro.rapiti44@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "It can simplify the integration with rystem repository server.",
|
|
7
7
|
"main": "./lib/index.js",
|
|
8
8
|
"types": "./lib/index.d.ts",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"typescript": "^5.1.6"
|
|
11
|
+
},
|
|
9
12
|
"files": [
|
|
10
13
|
"/lib"
|
|
11
14
|
]
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { IRepository } from "../interfaces/IRepository";
|
|
2
|
-
import { State } from "../models/State";
|
|
3
|
-
import { RepositorySettings } from "../servicecollection/RepositorySettings";
|
|
4
|
-
import { BatchBuilder } from "./batch/BatchBuilder";
|
|
5
|
-
import { QueryBuilder } from "./query/QueryBuilder";
|
|
6
|
-
export declare class Repository<T, TKey> implements IRepository<T, TKey> {
|
|
7
|
-
private baseUri;
|
|
8
|
-
private settings;
|
|
9
|
-
constructor(baseUri: string | null, settings: RepositorySettings);
|
|
10
|
-
get(key: TKey): Promise<T>;
|
|
11
|
-
insert(key: TKey, value: T): Promise<State<T, TKey>>;
|
|
12
|
-
update(key: TKey, value: T): Promise<State<T, TKey>>;
|
|
13
|
-
exist(key: TKey): Promise<State<T, TKey>>;
|
|
14
|
-
delete(key: TKey): Promise<State<T, TKey>>;
|
|
15
|
-
batch(): BatchBuilder<T, TKey>;
|
|
16
|
-
query(): QueryBuilder<T, TKey>;
|
|
17
|
-
static predicateAsString<T>(predicate: (value: T) => any): string;
|
|
18
|
-
}
|
package/lib/engine/Repository.js
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Repository = void 0;
|
|
4
|
-
const BatchBuilder_1 = require("./batch/BatchBuilder");
|
|
5
|
-
const QueryBuilder_1 = require("./query/QueryBuilder");
|
|
6
|
-
class Repository {
|
|
7
|
-
baseUri;
|
|
8
|
-
settings;
|
|
9
|
-
constructor(baseUri, settings) {
|
|
10
|
-
if (settings.uri == null)
|
|
11
|
-
this.baseUri = `${baseUri}${settings.path}`;
|
|
12
|
-
else
|
|
13
|
-
this.baseUri = settings.uri;
|
|
14
|
-
this.settings = settings;
|
|
15
|
-
}
|
|
16
|
-
get(key) {
|
|
17
|
-
if (!this.settings.complexKey) {
|
|
18
|
-
return fetch(`${this.baseUri}/Get?key=${key}`, {
|
|
19
|
-
method: 'GET',
|
|
20
|
-
headers: {}
|
|
21
|
-
})
|
|
22
|
-
.then(res => {
|
|
23
|
-
const json = res.json();
|
|
24
|
-
return json;
|
|
25
|
-
})
|
|
26
|
-
.catch((err) => {
|
|
27
|
-
return null;
|
|
28
|
-
})
|
|
29
|
-
.then(res => {
|
|
30
|
-
return res;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return fetch(`${this.baseUri}/Get`, {
|
|
35
|
-
method: 'POST',
|
|
36
|
-
headers: {
|
|
37
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
38
|
-
},
|
|
39
|
-
body: JSON.stringify(key),
|
|
40
|
-
})
|
|
41
|
-
.then(res => {
|
|
42
|
-
const json = res.json();
|
|
43
|
-
return json;
|
|
44
|
-
})
|
|
45
|
-
.catch((err) => {
|
|
46
|
-
return null;
|
|
47
|
-
})
|
|
48
|
-
.then(res => {
|
|
49
|
-
return res;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
insert(key, value) {
|
|
54
|
-
if (!this.settings.complexKey) {
|
|
55
|
-
return fetch(`${this.baseUri}/Insert?key=${key}`, {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
59
|
-
},
|
|
60
|
-
body: JSON.stringify(value),
|
|
61
|
-
})
|
|
62
|
-
.then(res => {
|
|
63
|
-
const json = res.json();
|
|
64
|
-
return json;
|
|
65
|
-
})
|
|
66
|
-
.catch((err) => {
|
|
67
|
-
return { isOk: false, m: err };
|
|
68
|
-
})
|
|
69
|
-
.then(res => {
|
|
70
|
-
return res;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
return fetch(`${this.baseUri}/Insert`, {
|
|
75
|
-
method: 'POST',
|
|
76
|
-
headers: {
|
|
77
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
78
|
-
},
|
|
79
|
-
body: JSON.stringify({
|
|
80
|
-
value: value,
|
|
81
|
-
key: key
|
|
82
|
-
}),
|
|
83
|
-
})
|
|
84
|
-
.then(res => {
|
|
85
|
-
const json = res.json();
|
|
86
|
-
return json;
|
|
87
|
-
})
|
|
88
|
-
.catch((err) => {
|
|
89
|
-
return { isOk: false, m: err };
|
|
90
|
-
})
|
|
91
|
-
.then(res => {
|
|
92
|
-
return res;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
update(key, value) {
|
|
97
|
-
if (!this.settings.complexKey) {
|
|
98
|
-
return fetch(`${this.baseUri}/Update?key=${key}`, {
|
|
99
|
-
method: 'POST',
|
|
100
|
-
headers: {
|
|
101
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
102
|
-
},
|
|
103
|
-
body: JSON.stringify(value),
|
|
104
|
-
})
|
|
105
|
-
.then(res => {
|
|
106
|
-
const json = res.json();
|
|
107
|
-
return json;
|
|
108
|
-
})
|
|
109
|
-
.catch((err) => {
|
|
110
|
-
return { isOk: false, m: err };
|
|
111
|
-
})
|
|
112
|
-
.then(res => {
|
|
113
|
-
return res;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
return fetch(`${this.baseUri}/Update`, {
|
|
118
|
-
method: 'POST',
|
|
119
|
-
headers: {
|
|
120
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
121
|
-
},
|
|
122
|
-
body: JSON.stringify({
|
|
123
|
-
value: value,
|
|
124
|
-
key: key
|
|
125
|
-
}),
|
|
126
|
-
})
|
|
127
|
-
.then(res => {
|
|
128
|
-
const json = res.json();
|
|
129
|
-
return json;
|
|
130
|
-
})
|
|
131
|
-
.catch((err) => {
|
|
132
|
-
return { isOk: false, m: err };
|
|
133
|
-
})
|
|
134
|
-
.then(res => {
|
|
135
|
-
return res;
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exist(key) {
|
|
140
|
-
if (!this.settings.complexKey) {
|
|
141
|
-
return fetch(`${this.baseUri}/Exist?key=${key}`, {
|
|
142
|
-
method: 'GET',
|
|
143
|
-
headers: {}
|
|
144
|
-
})
|
|
145
|
-
.then(res => {
|
|
146
|
-
const json = res.json();
|
|
147
|
-
return json;
|
|
148
|
-
})
|
|
149
|
-
.catch((err) => {
|
|
150
|
-
return { isOk: false, m: err };
|
|
151
|
-
})
|
|
152
|
-
.then(res => {
|
|
153
|
-
return res;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
return fetch(`${this.baseUri}/Exist`, {
|
|
158
|
-
method: 'POST',
|
|
159
|
-
headers: {
|
|
160
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
161
|
-
},
|
|
162
|
-
body: JSON.stringify(key),
|
|
163
|
-
})
|
|
164
|
-
.then(res => {
|
|
165
|
-
const json = res.json();
|
|
166
|
-
return json;
|
|
167
|
-
})
|
|
168
|
-
.catch((err) => {
|
|
169
|
-
return { isOk: false, m: err };
|
|
170
|
-
})
|
|
171
|
-
.then(res => {
|
|
172
|
-
return res;
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
delete(key) {
|
|
177
|
-
if (!this.settings.complexKey) {
|
|
178
|
-
return fetch(`${this.baseUri}/Delete?key=${key}`, {
|
|
179
|
-
method: 'GET',
|
|
180
|
-
headers: {}
|
|
181
|
-
})
|
|
182
|
-
.then(res => {
|
|
183
|
-
const json = res.json();
|
|
184
|
-
return json;
|
|
185
|
-
})
|
|
186
|
-
.catch((err) => {
|
|
187
|
-
return { isOk: false, m: err };
|
|
188
|
-
})
|
|
189
|
-
.then(res => {
|
|
190
|
-
return res;
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
return fetch(`${this.baseUri}/Delete`, {
|
|
195
|
-
method: 'POST',
|
|
196
|
-
headers: {
|
|
197
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
198
|
-
},
|
|
199
|
-
body: JSON.stringify(key),
|
|
200
|
-
})
|
|
201
|
-
.then(res => {
|
|
202
|
-
const json = res.json();
|
|
203
|
-
return json;
|
|
204
|
-
})
|
|
205
|
-
.catch((err) => {
|
|
206
|
-
return { isOk: false, m: err };
|
|
207
|
-
})
|
|
208
|
-
.then(res => {
|
|
209
|
-
return res;
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
batch() {
|
|
214
|
-
return new BatchBuilder_1.BatchBuilder(this.baseUri);
|
|
215
|
-
}
|
|
216
|
-
query() {
|
|
217
|
-
return new QueryBuilder_1.QueryBuilder(this.baseUri);
|
|
218
|
-
}
|
|
219
|
-
static predicateAsString(predicate) {
|
|
220
|
-
const splittedPredicate = predicate.toString().split('.');
|
|
221
|
-
const variableName = splittedPredicate.slice(-(splittedPredicate.length - 1)).join('.');
|
|
222
|
-
return `_rystem.${variableName}`;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.Repository = Repository;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BatchResults } from "./BatchResults";
|
|
2
|
-
export declare class BatchBuilder<T, TKey> {
|
|
3
|
-
private batch;
|
|
4
|
-
private baseUri;
|
|
5
|
-
constructor(baseUri: string | null);
|
|
6
|
-
addInsert(key: TKey, value: T): BatchBuilder<T, TKey>;
|
|
7
|
-
addUpdate(key: TKey, value: T): BatchBuilder<T, TKey>;
|
|
8
|
-
addDelete(key: TKey): BatchBuilder<T, TKey>;
|
|
9
|
-
execute(): Promise<BatchResults<T, TKey>>;
|
|
10
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BatchBuilder = void 0;
|
|
4
|
-
class BatchBuilder {
|
|
5
|
-
batch;
|
|
6
|
-
baseUri;
|
|
7
|
-
constructor(baseUri) {
|
|
8
|
-
this.batch = {
|
|
9
|
-
v: []
|
|
10
|
-
};
|
|
11
|
-
this.baseUri = baseUri;
|
|
12
|
-
}
|
|
13
|
-
addInsert(key, value) {
|
|
14
|
-
this.batch.v.push({
|
|
15
|
-
c: 1,
|
|
16
|
-
k: key,
|
|
17
|
-
v: value
|
|
18
|
-
});
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
addUpdate(key, value) {
|
|
22
|
-
this.batch.v.push({
|
|
23
|
-
c: 2,
|
|
24
|
-
k: key,
|
|
25
|
-
v: value
|
|
26
|
-
});
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
addDelete(key) {
|
|
30
|
-
this.batch.v.push({
|
|
31
|
-
c: 4,
|
|
32
|
-
k: key
|
|
33
|
-
});
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
execute() {
|
|
37
|
-
return fetch(`${this.baseUri}/Batch`, {
|
|
38
|
-
method: 'POST',
|
|
39
|
-
headers: {
|
|
40
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
41
|
-
},
|
|
42
|
-
body: JSON.stringify(this.batch),
|
|
43
|
-
})
|
|
44
|
-
.then(res => {
|
|
45
|
-
const json = res.json();
|
|
46
|
-
return json;
|
|
47
|
-
})
|
|
48
|
-
.catch((err) => {
|
|
49
|
-
return {};
|
|
50
|
-
})
|
|
51
|
-
.then(res => {
|
|
52
|
-
return res;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.BatchBuilder = BatchBuilder;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FilterOperations = void 0;
|
|
4
|
-
var FilterOperations;
|
|
5
|
-
(function (FilterOperations) {
|
|
6
|
-
FilterOperations[FilterOperations["Select"] = 1] = "Select";
|
|
7
|
-
FilterOperations[FilterOperations["Where"] = 2] = "Where";
|
|
8
|
-
FilterOperations[FilterOperations["Top"] = 4] = "Top";
|
|
9
|
-
FilterOperations[FilterOperations["Skip"] = 8] = "Skip";
|
|
10
|
-
FilterOperations[FilterOperations["OrderBy"] = 16] = "OrderBy";
|
|
11
|
-
FilterOperations[FilterOperations["OrderByDescending"] = 32] = "OrderByDescending";
|
|
12
|
-
FilterOperations[FilterOperations["ThenBy"] = 64] = "ThenBy";
|
|
13
|
-
FilterOperations[FilterOperations["ThenByDescending"] = 128] = "ThenByDescending";
|
|
14
|
-
FilterOperations[FilterOperations["GroupBy"] = 256] = "GroupBy";
|
|
15
|
-
})(FilterOperations || (exports.FilterOperations = FilterOperations = {}));
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Entity } from "../../models/Entity";
|
|
2
|
-
import { WhereBuilder } from "./filter/WhereBuilder";
|
|
3
|
-
export declare class QueryBuilder<T, TKey> {
|
|
4
|
-
private filters;
|
|
5
|
-
private baseUri;
|
|
6
|
-
constructor(baseUri: string | null);
|
|
7
|
-
where(): WhereBuilder<T, TKey>;
|
|
8
|
-
filter(predicate: string): QueryBuilder<T, TKey>;
|
|
9
|
-
top(value: number): QueryBuilder<T, TKey>;
|
|
10
|
-
skip(value: number): QueryBuilder<T, TKey>;
|
|
11
|
-
orderBy(predicate: (value: T) => any): QueryBuilder<T, TKey>;
|
|
12
|
-
orderByDescending(predicate: (value: T) => any): QueryBuilder<T, TKey>;
|
|
13
|
-
thenBy(predicate: (value: T) => any): QueryBuilder<T, TKey>;
|
|
14
|
-
thenByDescending(predicate: (value: T) => any): QueryBuilder<T, TKey>;
|
|
15
|
-
execute(): Promise<Array<Entity<T, TKey>>>;
|
|
16
|
-
count(): Promise<number>;
|
|
17
|
-
max(predicate: (value: T) => any): Promise<number>;
|
|
18
|
-
min(predicate: (value: T) => any): Promise<number>;
|
|
19
|
-
average(predicate: (value: T) => any): Promise<number>;
|
|
20
|
-
sum(predicate: (value: T) => any): Promise<number>;
|
|
21
|
-
private executeOperation;
|
|
22
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryBuilder = void 0;
|
|
4
|
-
const Repository_1 = require("../Repository");
|
|
5
|
-
const WhereBuilder_1 = require("./filter/WhereBuilder");
|
|
6
|
-
const FilterOperations_1 = require("./FilterOperations");
|
|
7
|
-
class QueryBuilder {
|
|
8
|
-
filters;
|
|
9
|
-
baseUri;
|
|
10
|
-
constructor(baseUri) {
|
|
11
|
-
this.filters = {
|
|
12
|
-
o: []
|
|
13
|
-
};
|
|
14
|
-
this.baseUri = baseUri;
|
|
15
|
-
}
|
|
16
|
-
where() {
|
|
17
|
-
return new WhereBuilder_1.WhereBuilder(this);
|
|
18
|
-
}
|
|
19
|
-
filter(predicate) {
|
|
20
|
-
this.filters.o.push({
|
|
21
|
-
q: FilterOperations_1.FilterOperations.Where,
|
|
22
|
-
v: predicate
|
|
23
|
-
});
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
top(value) {
|
|
27
|
-
this.filters.o.push({
|
|
28
|
-
q: FilterOperations_1.FilterOperations.Top,
|
|
29
|
-
v: value.toString()
|
|
30
|
-
});
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
skip(value) {
|
|
34
|
-
this.filters.o.push({
|
|
35
|
-
q: FilterOperations_1.FilterOperations.Skip,
|
|
36
|
-
v: value.toString()
|
|
37
|
-
});
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
orderBy(predicate) {
|
|
41
|
-
this.filters.o.push({
|
|
42
|
-
q: FilterOperations_1.FilterOperations.OrderBy,
|
|
43
|
-
v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
|
|
44
|
-
});
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
orderByDescending(predicate) {
|
|
48
|
-
this.filters.o.push({
|
|
49
|
-
q: FilterOperations_1.FilterOperations.OrderByDescending,
|
|
50
|
-
v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
|
|
51
|
-
});
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
thenBy(predicate) {
|
|
55
|
-
this.filters.o.push({
|
|
56
|
-
q: FilterOperations_1.FilterOperations.ThenBy,
|
|
57
|
-
v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
|
|
58
|
-
});
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
thenByDescending(predicate) {
|
|
62
|
-
this.filters.o.push({
|
|
63
|
-
q: FilterOperations_1.FilterOperations.ThenByDescending,
|
|
64
|
-
v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
|
|
65
|
-
});
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
execute() {
|
|
69
|
-
return fetch(`${this.baseUri}/Query`, {
|
|
70
|
-
method: 'POST',
|
|
71
|
-
headers: {
|
|
72
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
73
|
-
},
|
|
74
|
-
body: JSON.stringify(this.filters),
|
|
75
|
-
})
|
|
76
|
-
.then(res => {
|
|
77
|
-
const json = res.json();
|
|
78
|
-
return json;
|
|
79
|
-
})
|
|
80
|
-
.catch((err) => {
|
|
81
|
-
return {};
|
|
82
|
-
})
|
|
83
|
-
.then(res => {
|
|
84
|
-
return res;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
count() {
|
|
88
|
-
return this.executeOperation("Count", "long");
|
|
89
|
-
}
|
|
90
|
-
max(predicate) {
|
|
91
|
-
this.filters.o.push({
|
|
92
|
-
q: FilterOperations_1.FilterOperations.Select,
|
|
93
|
-
v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
|
|
94
|
-
});
|
|
95
|
-
return this.executeOperation("Max", "decimal");
|
|
96
|
-
}
|
|
97
|
-
min(predicate) {
|
|
98
|
-
this.filters.o.push({
|
|
99
|
-
q: FilterOperations_1.FilterOperations.Select,
|
|
100
|
-
v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
|
|
101
|
-
});
|
|
102
|
-
return this.executeOperation("Min", "decimal");
|
|
103
|
-
}
|
|
104
|
-
average(predicate) {
|
|
105
|
-
this.filters.o.push({
|
|
106
|
-
q: FilterOperations_1.FilterOperations.Select,
|
|
107
|
-
v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
|
|
108
|
-
});
|
|
109
|
-
return this.executeOperation("Average", "decimal");
|
|
110
|
-
}
|
|
111
|
-
sum(predicate) {
|
|
112
|
-
this.filters.o.push({
|
|
113
|
-
q: FilterOperations_1.FilterOperations.Select,
|
|
114
|
-
v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
|
|
115
|
-
});
|
|
116
|
-
return this.executeOperation("Sum", "decimal");
|
|
117
|
-
}
|
|
118
|
-
executeOperation(operation, returnType) {
|
|
119
|
-
return fetch(`${this.baseUri}/Operation?op=${operation}&returnType=${returnType}`, {
|
|
120
|
-
method: 'POST',
|
|
121
|
-
headers: {
|
|
122
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
123
|
-
},
|
|
124
|
-
body: JSON.stringify(this.filters),
|
|
125
|
-
})
|
|
126
|
-
.then(res => {
|
|
127
|
-
const json = res.json();
|
|
128
|
-
return json;
|
|
129
|
-
})
|
|
130
|
-
.catch((err) => {
|
|
131
|
-
throw new Error(err);
|
|
132
|
-
})
|
|
133
|
-
.then(res => {
|
|
134
|
-
return res;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.QueryBuilder = QueryBuilder;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Entity } from "../../../models/Entity";
|
|
2
|
-
import { QueryBuilder } from "../QueryBuilder";
|
|
3
|
-
export declare class WhereBuilder<T, TKey> {
|
|
4
|
-
private roundBracketsCount;
|
|
5
|
-
private queryBuilder;
|
|
6
|
-
private query;
|
|
7
|
-
constructor(query: QueryBuilder<T, TKey>);
|
|
8
|
-
select(predicate: (value: T) => any): WhereBuilder<T, TKey>;
|
|
9
|
-
private operator;
|
|
10
|
-
private valueAsString;
|
|
11
|
-
equal(value: any | null): WhereBuilder<T, TKey>;
|
|
12
|
-
notEqual(value: any | null): WhereBuilder<T, TKey>;
|
|
13
|
-
greaterThan(value: any | null): WhereBuilder<T, TKey>;
|
|
14
|
-
greaterThanOrEqual(value: any | null): WhereBuilder<T, TKey>;
|
|
15
|
-
lesserThan(value: any | null): WhereBuilder<T, TKey>;
|
|
16
|
-
lesserThanOrEqual(value: any | null): WhereBuilder<T, TKey>;
|
|
17
|
-
startsWith(value: any | null): WhereBuilder<T, TKey>;
|
|
18
|
-
endsWith(value: any | null): WhereBuilder<T, TKey>;
|
|
19
|
-
contains(value: any | null): WhereBuilder<T, TKey>;
|
|
20
|
-
and(): WhereBuilder<T, TKey>;
|
|
21
|
-
or(): WhereBuilder<T, TKey>;
|
|
22
|
-
openRoundBracket(): WhereBuilder<T, TKey>;
|
|
23
|
-
closeRoundBracket(): WhereBuilder<T, TKey>;
|
|
24
|
-
build(): QueryBuilder<T, TKey>;
|
|
25
|
-
execute(): Promise<Array<Entity<T, TKey>>>;
|
|
26
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WhereBuilder = void 0;
|
|
4
|
-
const Repository_1 = require("../../Repository");
|
|
5
|
-
class WhereBuilder {
|
|
6
|
-
roundBracketsCount;
|
|
7
|
-
queryBuilder;
|
|
8
|
-
query;
|
|
9
|
-
constructor(query) {
|
|
10
|
-
this.roundBracketsCount = 0;
|
|
11
|
-
this.queryBuilder = new Array();
|
|
12
|
-
this.queryBuilder.push("_rystem => ");
|
|
13
|
-
this.query = query;
|
|
14
|
-
}
|
|
15
|
-
select(predicate) {
|
|
16
|
-
this.queryBuilder.push(Repository_1.Repository.predicateAsString(predicate));
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
operator(operation, value) {
|
|
20
|
-
switch (operation) {
|
|
21
|
-
case Operators.Equal:
|
|
22
|
-
this.queryBuilder.push(" == ");
|
|
23
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
24
|
-
break;
|
|
25
|
-
case Operators.NotEqual:
|
|
26
|
-
this.queryBuilder.push(" != ");
|
|
27
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
28
|
-
break;
|
|
29
|
-
case Operators.GreaterThan:
|
|
30
|
-
this.queryBuilder.push(" > ");
|
|
31
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
32
|
-
break;
|
|
33
|
-
case Operators.GreaterThanOrEqual:
|
|
34
|
-
this.queryBuilder.push(" >= ");
|
|
35
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
36
|
-
break;
|
|
37
|
-
case Operators.LesserThan:
|
|
38
|
-
this.queryBuilder.push(" < ");
|
|
39
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
40
|
-
break;
|
|
41
|
-
case Operators.LesserThanOrEqual:
|
|
42
|
-
this.queryBuilder.push(" <= ");
|
|
43
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
44
|
-
break;
|
|
45
|
-
case Operators.Contains:
|
|
46
|
-
this.queryBuilder.push(".Contains(");
|
|
47
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
48
|
-
this.queryBuilder.push(")");
|
|
49
|
-
break;
|
|
50
|
-
case Operators.StartsWith:
|
|
51
|
-
this.queryBuilder.push(".StartsWith(");
|
|
52
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
53
|
-
this.queryBuilder.push(")");
|
|
54
|
-
break;
|
|
55
|
-
case Operators.EndsWith:
|
|
56
|
-
this.queryBuilder.push(".EndsWith(");
|
|
57
|
-
this.queryBuilder.push(this.valueAsString(value));
|
|
58
|
-
this.queryBuilder.push(")");
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
valueAsString(v) {
|
|
64
|
-
if (v != null) {
|
|
65
|
-
if (typeof v == 'number') {
|
|
66
|
-
return v.toString();
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
return `"${v.toString()}"`;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else
|
|
73
|
-
return "null";
|
|
74
|
-
}
|
|
75
|
-
equal(value) {
|
|
76
|
-
return this
|
|
77
|
-
.operator(Operators.Equal, value);
|
|
78
|
-
}
|
|
79
|
-
notEqual(value) {
|
|
80
|
-
return this
|
|
81
|
-
.operator(Operators.NotEqual, value);
|
|
82
|
-
}
|
|
83
|
-
greaterThan(value) {
|
|
84
|
-
return this
|
|
85
|
-
.operator(Operators.GreaterThan, value);
|
|
86
|
-
}
|
|
87
|
-
greaterThanOrEqual(value) {
|
|
88
|
-
return this
|
|
89
|
-
.operator(Operators.GreaterThanOrEqual, value);
|
|
90
|
-
}
|
|
91
|
-
lesserThan(value) {
|
|
92
|
-
return this
|
|
93
|
-
.operator(Operators.LesserThan, value);
|
|
94
|
-
}
|
|
95
|
-
lesserThanOrEqual(value) {
|
|
96
|
-
return this
|
|
97
|
-
.operator(Operators.LesserThanOrEqual, value);
|
|
98
|
-
}
|
|
99
|
-
startsWith(value) {
|
|
100
|
-
return this
|
|
101
|
-
.operator(Operators.StartsWith, value);
|
|
102
|
-
}
|
|
103
|
-
endsWith(value) {
|
|
104
|
-
return this
|
|
105
|
-
.operator(Operators.EndsWith, value);
|
|
106
|
-
}
|
|
107
|
-
contains(value) {
|
|
108
|
-
return this
|
|
109
|
-
.operator(Operators.Contains, value);
|
|
110
|
-
}
|
|
111
|
-
and() {
|
|
112
|
-
this.queryBuilder.push(" && ");
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
or() {
|
|
116
|
-
this.queryBuilder.push(" || ");
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
openRoundBracket() {
|
|
120
|
-
this.queryBuilder.push("(");
|
|
121
|
-
this.roundBracketsCount++;
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
closeRoundBracket() {
|
|
125
|
-
this.queryBuilder.push(")");
|
|
126
|
-
this.roundBracketsCount--;
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
build() {
|
|
130
|
-
for (let i = 0; i < this.roundBracketsCount; i++) {
|
|
131
|
-
this.queryBuilder.push(")");
|
|
132
|
-
}
|
|
133
|
-
this.roundBracketsCount = 0;
|
|
134
|
-
return this.query.filter(this.queryBuilder.join(''));
|
|
135
|
-
}
|
|
136
|
-
execute() {
|
|
137
|
-
return this.build().execute();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
exports.WhereBuilder = WhereBuilder;
|
|
141
|
-
var Operators;
|
|
142
|
-
(function (Operators) {
|
|
143
|
-
Operators[Operators["Equal"] = 1] = "Equal";
|
|
144
|
-
Operators[Operators["NotEqual"] = 2] = "NotEqual";
|
|
145
|
-
Operators[Operators["GreaterThan"] = 3] = "GreaterThan";
|
|
146
|
-
Operators[Operators["GreaterThanOrEqual"] = 4] = "GreaterThanOrEqual";
|
|
147
|
-
Operators[Operators["LesserThan"] = 5] = "LesserThan";
|
|
148
|
-
Operators[Operators["LesserThanOrEqual"] = 6] = "LesserThanOrEqual";
|
|
149
|
-
Operators[Operators["Contains"] = 7] = "Contains";
|
|
150
|
-
Operators[Operators["StartsWith"] = 8] = "StartsWith";
|
|
151
|
-
Operators[Operators["EndsWith"] = 9] = "EndsWith";
|
|
152
|
-
})(Operators || (Operators = {}));
|
package/lib/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BatchResults } from "./engine/batch/BatchResults";
|
|
2
|
-
import { ICommand } from "./interfaces/ICommand";
|
|
3
|
-
import { IQuery } from "./interfaces/IQuery";
|
|
4
|
-
import { IRepository } from "./interfaces/IRepository";
|
|
5
|
-
import { Entity } from "./models/Entity";
|
|
6
|
-
import { State } from "./models/State";
|
|
7
|
-
import { RepositoryServices } from "./servicecollection/RepositoryServices";
|
|
8
|
-
export { RepositoryServices };
|
|
9
|
-
export type { IRepository, ICommand, IQuery, State, BatchResults, Entity };
|
package/lib/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RepositoryServices = void 0;
|
|
4
|
-
const RepositoryServices_1 = require("./servicecollection/RepositoryServices");
|
|
5
|
-
Object.defineProperty(exports, "RepositoryServices", { enumerable: true, get: function () { return RepositoryServices_1.RepositoryServices; } });
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BatchBuilder } from "../engine/batch/BatchBuilder";
|
|
2
|
-
import { State } from "../models/State";
|
|
3
|
-
export interface ICommand<T, TKey> {
|
|
4
|
-
insert(key: TKey, value: T): Promise<State<T, TKey>>;
|
|
5
|
-
update(key: TKey, value: T): Promise<State<T, TKey>>;
|
|
6
|
-
delete(key: TKey): Promise<State<T, TKey>>;
|
|
7
|
-
batch(): BatchBuilder<T, TKey>;
|
|
8
|
-
}
|
package/lib/interfaces/IQuery.js
DELETED
package/lib/models/Entity.d.ts
DELETED
package/lib/models/Entity.js
DELETED
package/lib/models/State.d.ts
DELETED
package/lib/models/State.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ICommand } from "../interfaces/ICommand";
|
|
2
|
-
import { IQuery } from "../interfaces/IQuery";
|
|
3
|
-
import { IRepository } from "../interfaces/IRepository";
|
|
4
|
-
import { RepositorySettings } from "./RepositorySettings";
|
|
5
|
-
export declare class RepositoryServices {
|
|
6
|
-
private static instance;
|
|
7
|
-
private repositories;
|
|
8
|
-
private baseUri;
|
|
9
|
-
private constructor();
|
|
10
|
-
static Repository<T, TKey>(name: string): IRepository<T, TKey>;
|
|
11
|
-
static Command<T, TKey>(name: string): ICommand<T, TKey>;
|
|
12
|
-
static Query<T, TKey>(name: string): IQuery<T, TKey>;
|
|
13
|
-
private static Instance;
|
|
14
|
-
static Create<T, TKey>(baseUri: string | null): RepositoryServices;
|
|
15
|
-
private AddRepository;
|
|
16
|
-
addRepository<T, TKey>(builder: (x: RepositorySettings) => void): this;
|
|
17
|
-
addCommand<T, TKey>(builder: (x: RepositorySettings) => void): this;
|
|
18
|
-
addQuery<T, TKey>(builder: (x: RepositorySettings) => void): this;
|
|
19
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RepositoryServices = void 0;
|
|
4
|
-
const Repository_1 = require("../engine/Repository");
|
|
5
|
-
const RepositorySettings_1 = require("./RepositorySettings");
|
|
6
|
-
class RepositoryServices {
|
|
7
|
-
static instance;
|
|
8
|
-
repositories;
|
|
9
|
-
baseUri;
|
|
10
|
-
constructor() {
|
|
11
|
-
this.repositories = new Map();
|
|
12
|
-
this.baseUri = null;
|
|
13
|
-
}
|
|
14
|
-
static Repository(name) {
|
|
15
|
-
return RepositoryServices.Instance(name, RepositoryType.Repository);
|
|
16
|
-
}
|
|
17
|
-
static Command(name) {
|
|
18
|
-
return RepositoryServices.Instance(name, RepositoryType.Command);
|
|
19
|
-
}
|
|
20
|
-
static Query(name) {
|
|
21
|
-
return RepositoryServices.Instance(name, RepositoryType.Query);
|
|
22
|
-
}
|
|
23
|
-
static Instance(name, type) {
|
|
24
|
-
if (!RepositoryServices.instance) {
|
|
25
|
-
RepositoryServices.instance = new RepositoryServices();
|
|
26
|
-
}
|
|
27
|
-
if (RepositoryServices.instance.repositories.has(name)) {
|
|
28
|
-
const wrapper = RepositoryServices.instance.repositories.get(name);
|
|
29
|
-
if (wrapper != undefined && wrapper.type == type) {
|
|
30
|
-
if (wrapper.type == RepositoryType.Repository)
|
|
31
|
-
return wrapper.repository;
|
|
32
|
-
else if (wrapper.type == RepositoryType.Command)
|
|
33
|
-
return wrapper.repository;
|
|
34
|
-
else
|
|
35
|
-
return wrapper.repository;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
throw new Error(`${type} with '${name}' has a wrong setup.`);
|
|
39
|
-
}
|
|
40
|
-
static Create(baseUri) {
|
|
41
|
-
if (!RepositoryServices.instance) {
|
|
42
|
-
RepositoryServices.instance = new RepositoryServices();
|
|
43
|
-
}
|
|
44
|
-
RepositoryServices.instance.baseUri = baseUri;
|
|
45
|
-
return RepositoryServices.instance;
|
|
46
|
-
}
|
|
47
|
-
AddRepository(builder, type) {
|
|
48
|
-
const settings = new RepositorySettings_1.RepositorySettings();
|
|
49
|
-
builder(settings);
|
|
50
|
-
if (settings.name == null || settings.name == "")
|
|
51
|
-
throw new Error("Repository needs a name during setup. Please provide in settings a name length greater than or equal to 1.");
|
|
52
|
-
const repository = new Repository_1.Repository(this.baseUri, settings);
|
|
53
|
-
this.repositories.set(settings.name, new RepositoryWrapper(repository, type));
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
addRepository(builder) {
|
|
57
|
-
return this.AddRepository(builder, RepositoryType.Repository);
|
|
58
|
-
}
|
|
59
|
-
addCommand(builder) {
|
|
60
|
-
return this.AddRepository(builder, RepositoryType.Command);
|
|
61
|
-
}
|
|
62
|
-
addQuery(builder) {
|
|
63
|
-
return this.AddRepository(builder, RepositoryType.Query);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.RepositoryServices = RepositoryServices;
|
|
67
|
-
var RepositoryType;
|
|
68
|
-
(function (RepositoryType) {
|
|
69
|
-
RepositoryType[RepositoryType["Repository"] = 1] = "Repository";
|
|
70
|
-
RepositoryType[RepositoryType["Command"] = 2] = "Command";
|
|
71
|
-
RepositoryType[RepositoryType["Query"] = 3] = "Query";
|
|
72
|
-
})(RepositoryType || (RepositoryType = {}));
|
|
73
|
-
class RepositoryWrapper {
|
|
74
|
-
repository;
|
|
75
|
-
type;
|
|
76
|
-
constructor(repository, type) {
|
|
77
|
-
this.repository = repository;
|
|
78
|
-
this.type = type;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RepositorySettings = void 0;
|
|
4
|
-
class RepositorySettings {
|
|
5
|
-
name;
|
|
6
|
-
uri;
|
|
7
|
-
path;
|
|
8
|
-
complexKey;
|
|
9
|
-
constructor() {
|
|
10
|
-
this.name = "";
|
|
11
|
-
this.uri = null;
|
|
12
|
-
this.path = null;
|
|
13
|
-
this.complexKey = false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.RepositorySettings = RepositorySettings;
|