rystem.repository.client 0.2.7 → 10.1.0-beta.3
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 +321 -161
- package/package.json +6 -1
- package/lib/engine/Repository.d.ts +0 -27
- package/lib/engine/Repository.js +0 -333
- package/lib/engine/batch/Batch.d.ts +0 -9
- package/lib/engine/batch/Batch.js +0 -17
- package/lib/engine/batch/BatchBuilder.d.ts +0 -13
- package/lib/engine/batch/BatchBuilder.js +0 -48
- package/lib/engine/batch/BatchOperation.d.ts +0 -12
- package/lib/engine/batch/BatchOperation.js +0 -16
- package/lib/engine/batch/BatchResult.d.ts +0 -13
- package/lib/engine/batch/BatchResult.js +0 -18
- 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 -25
- package/lib/engine/query/QueryBuilder.js +0 -116
- 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 -33
- package/lib/engine/query/filter/WhereBuilder.js +0 -170
- package/lib/hooks/hooks.d.ts +0 -9
- package/lib/hooks/hooks.js +0 -28
- package/lib/index.d.ts +0 -11
- package/lib/index.js +0 -16
- package/lib/interfaces/ICommand.d.ts +0 -14
- package/lib/interfaces/ICommand.js +0 -2
- package/lib/interfaces/IQuery.d.ts +0 -12
- package/lib/interfaces/IQuery.js +0 -2
- package/lib/interfaces/IRepository.d.ts +0 -6
- package/lib/interfaces/IRepository.js +0 -2
- package/lib/models/Entity.d.ts +0 -11
- package/lib/models/Entity.js +0 -20
- package/lib/models/RepositoryEndpoint.d.ts +0 -12
- package/lib/models/RepositoryEndpoint.js +0 -16
- package/lib/models/State.d.ts +0 -20
- package/lib/models/State.js +0 -26
- package/lib/servicecollection/RepositoryServices.d.ts +0 -23
- package/lib/servicecollection/RepositoryServices.js +0 -106
- package/lib/servicecollection/RepositorySettings.d.ts +0 -22
- package/lib/servicecollection/RepositorySettings.js +0 -58
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { CancellationToken } from "typescript";
|
|
2
|
-
import { Entity } from "../../../models/Entity";
|
|
3
|
-
import { QueryBuilder } from "../QueryBuilder";
|
|
4
|
-
export declare class WhereBuilder<T, TKey> {
|
|
5
|
-
private roundBracketsCount;
|
|
6
|
-
private queryBuilder;
|
|
7
|
-
private query;
|
|
8
|
-
constructor(query: QueryBuilder<T, TKey>);
|
|
9
|
-
select(predicate: (value: T) => any): this;
|
|
10
|
-
private operator;
|
|
11
|
-
private valueAsString;
|
|
12
|
-
equal(value: any): this;
|
|
13
|
-
notEqual(value: any): this;
|
|
14
|
-
greaterThan(value: any): this;
|
|
15
|
-
greaterThanOrEqual(value: any): this;
|
|
16
|
-
lesserThan(value: any): this;
|
|
17
|
-
lesserThanOrEqual(value: any): this;
|
|
18
|
-
startsWith(value: any): this;
|
|
19
|
-
endsWith(value: any): this;
|
|
20
|
-
contains(value: any): this;
|
|
21
|
-
and(): this;
|
|
22
|
-
or(): this;
|
|
23
|
-
openRoundBracket(): this;
|
|
24
|
-
closeRoundBracket(): this;
|
|
25
|
-
build(): QueryBuilder<T, TKey>;
|
|
26
|
-
execute(): Promise<Array<Entity<T, TKey>>>;
|
|
27
|
-
executeAsStream(entityReader: (entity: Entity<T, TKey>) => void, cancellationToken?: CancellationToken | null): Promise<Array<Entity<T, TKey>>>;
|
|
28
|
-
count(): Promise<number>;
|
|
29
|
-
max(predicate: (value: T) => any): Promise<number>;
|
|
30
|
-
min(predicate: (value: T) => any): Promise<number>;
|
|
31
|
-
average(predicate: (value: T) => any): Promise<number>;
|
|
32
|
-
sum(predicate: (value: T) => any): Promise<number>;
|
|
33
|
-
}
|
|
@@ -1,170 +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
|
-
executeAsStream(entityReader, cancellationToken = null) {
|
|
140
|
-
return this.build().executeAsStream(entityReader, cancellationToken);
|
|
141
|
-
}
|
|
142
|
-
count() {
|
|
143
|
-
return this.build().count();
|
|
144
|
-
}
|
|
145
|
-
max(predicate) {
|
|
146
|
-
return this.build().max(predicate);
|
|
147
|
-
}
|
|
148
|
-
min(predicate) {
|
|
149
|
-
return this.build().min(predicate);
|
|
150
|
-
}
|
|
151
|
-
average(predicate) {
|
|
152
|
-
return this.build().average(predicate);
|
|
153
|
-
}
|
|
154
|
-
sum(predicate) {
|
|
155
|
-
return this.build().sum(predicate);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
exports.WhereBuilder = WhereBuilder;
|
|
159
|
-
var Operators;
|
|
160
|
-
(function (Operators) {
|
|
161
|
-
Operators[Operators["Equal"] = 1] = "Equal";
|
|
162
|
-
Operators[Operators["NotEqual"] = 2] = "NotEqual";
|
|
163
|
-
Operators[Operators["GreaterThan"] = 3] = "GreaterThan";
|
|
164
|
-
Operators[Operators["GreaterThanOrEqual"] = 4] = "GreaterThanOrEqual";
|
|
165
|
-
Operators[Operators["LesserThan"] = 5] = "LesserThan";
|
|
166
|
-
Operators[Operators["LesserThanOrEqual"] = 6] = "LesserThanOrEqual";
|
|
167
|
-
Operators[Operators["Contains"] = 7] = "Contains";
|
|
168
|
-
Operators[Operators["StartsWith"] = 8] = "StartsWith";
|
|
169
|
-
Operators[Operators["EndsWith"] = 9] = "EndsWith";
|
|
170
|
-
})(Operators || (Operators = {}));
|
package/lib/hooks/hooks.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ICommand, ICommandPattern } from "../interfaces/ICommand";
|
|
2
|
-
import { IQuery, IQueryPattern } from "../interfaces/IQuery";
|
|
3
|
-
import { IRepository, IRepositoryPattern } from "../interfaces/IRepository";
|
|
4
|
-
export declare const useRepository: <T, TKey>(name: string) => IRepository<T, TKey>;
|
|
5
|
-
export declare const useCommand: <T, TKey>(name: string) => ICommand<T, TKey>;
|
|
6
|
-
export declare const useQuery: <T, TKey>(name: string) => IQuery<T, TKey>;
|
|
7
|
-
export declare const useRepositoryPattern: (name: string) => IRepositoryPattern;
|
|
8
|
-
export declare const useCommandPattern: (name: string) => ICommandPattern;
|
|
9
|
-
export declare const useQueryPattern: (name: string) => IQueryPattern;
|
package/lib/hooks/hooks.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useQueryPattern = exports.useCommandPattern = exports.useRepositoryPattern = exports.useQuery = exports.useCommand = exports.useRepository = void 0;
|
|
4
|
-
const RepositoryServices_1 = require("../servicecollection/RepositoryServices");
|
|
5
|
-
const useRepository = function (name) {
|
|
6
|
-
return RepositoryServices_1.RepositoryServices.Repository(name);
|
|
7
|
-
};
|
|
8
|
-
exports.useRepository = useRepository;
|
|
9
|
-
const useCommand = function (name) {
|
|
10
|
-
return RepositoryServices_1.RepositoryServices.Command(name);
|
|
11
|
-
};
|
|
12
|
-
exports.useCommand = useCommand;
|
|
13
|
-
const useQuery = function (name) {
|
|
14
|
-
return RepositoryServices_1.RepositoryServices.Query(name);
|
|
15
|
-
};
|
|
16
|
-
exports.useQuery = useQuery;
|
|
17
|
-
const useRepositoryPattern = function (name) {
|
|
18
|
-
return RepositoryServices_1.RepositoryServices.RepositoryPattern(name);
|
|
19
|
-
};
|
|
20
|
-
exports.useRepositoryPattern = useRepositoryPattern;
|
|
21
|
-
const useCommandPattern = function (name) {
|
|
22
|
-
return RepositoryServices_1.RepositoryServices.CommandPattern(name);
|
|
23
|
-
};
|
|
24
|
-
exports.useCommandPattern = useCommandPattern;
|
|
25
|
-
const useQueryPattern = function (name) {
|
|
26
|
-
return RepositoryServices_1.RepositoryServices.QueryPattern(name);
|
|
27
|
-
};
|
|
28
|
-
exports.useQueryPattern = useQueryPattern;
|
package/lib/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type { BatchResult } from "./engine/batch/BatchResult";
|
|
2
|
-
export type { ICommand, ICommandPattern } from "./interfaces/ICommand";
|
|
3
|
-
export type { IQuery, IQueryPattern } from "./interfaces/IQuery";
|
|
4
|
-
export type { IRepository, IRepositoryPattern } from "./interfaces/IRepository";
|
|
5
|
-
export type { Entity } from "./models/Entity";
|
|
6
|
-
export type { State } from "./models/State";
|
|
7
|
-
export { RepositoryEndpoint } from "./models/RepositoryEndpoint";
|
|
8
|
-
export { RepositoryServices } from "./servicecollection/RepositoryServices";
|
|
9
|
-
export { RepositorySettings } from "./servicecollection/RepositorySettings";
|
|
10
|
-
export type { ITransformer } from "./servicecollection/RepositorySettings";
|
|
11
|
-
export { useRepository, useCommand, useQuery, useRepositoryPattern, useCommandPattern, useQueryPattern } from "./hooks/hooks";
|
package/lib/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useQueryPattern = exports.useCommandPattern = exports.useRepositoryPattern = exports.useQuery = exports.useCommand = exports.useRepository = exports.RepositorySettings = exports.RepositoryServices = exports.RepositoryEndpoint = void 0;
|
|
4
|
-
var RepositoryEndpoint_1 = require("./models/RepositoryEndpoint");
|
|
5
|
-
Object.defineProperty(exports, "RepositoryEndpoint", { enumerable: true, get: function () { return RepositoryEndpoint_1.RepositoryEndpoint; } });
|
|
6
|
-
var RepositoryServices_1 = require("./servicecollection/RepositoryServices");
|
|
7
|
-
Object.defineProperty(exports, "RepositoryServices", { enumerable: true, get: function () { return RepositoryServices_1.RepositoryServices; } });
|
|
8
|
-
var RepositorySettings_1 = require("./servicecollection/RepositorySettings");
|
|
9
|
-
Object.defineProperty(exports, "RepositorySettings", { enumerable: true, get: function () { return RepositorySettings_1.RepositorySettings; } });
|
|
10
|
-
var hooks_1 = require("./hooks/hooks");
|
|
11
|
-
Object.defineProperty(exports, "useRepository", { enumerable: true, get: function () { return hooks_1.useRepository; } });
|
|
12
|
-
Object.defineProperty(exports, "useCommand", { enumerable: true, get: function () { return hooks_1.useCommand; } });
|
|
13
|
-
Object.defineProperty(exports, "useQuery", { enumerable: true, get: function () { return hooks_1.useQuery; } });
|
|
14
|
-
Object.defineProperty(exports, "useRepositoryPattern", { enumerable: true, get: function () { return hooks_1.useRepositoryPattern; } });
|
|
15
|
-
Object.defineProperty(exports, "useCommandPattern", { enumerable: true, get: function () { return hooks_1.useCommandPattern; } });
|
|
16
|
-
Object.defineProperty(exports, "useQueryPattern", { enumerable: true, get: function () { return hooks_1.useQueryPattern; } });
|
|
@@ -1,14 +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
|
-
}
|
|
9
|
-
export interface ICommandPattern {
|
|
10
|
-
insert(key: any, value: any): Promise<State<any, any>>;
|
|
11
|
-
update(key: any, value: any): Promise<State<any, any>>;
|
|
12
|
-
delete(key: any): Promise<State<any, any>>;
|
|
13
|
-
batch(): BatchBuilder<any, any>;
|
|
14
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { QueryBuilder } from "../engine/query/QueryBuilder";
|
|
2
|
-
import { State } from "../models/State";
|
|
3
|
-
export interface IQuery<T, TKey> {
|
|
4
|
-
get(key: TKey): Promise<T>;
|
|
5
|
-
exist(key: TKey): Promise<State<T, TKey>>;
|
|
6
|
-
query(): QueryBuilder<T, TKey>;
|
|
7
|
-
}
|
|
8
|
-
export interface IQueryPattern {
|
|
9
|
-
get(key: any): Promise<any>;
|
|
10
|
-
exist(key: any): Promise<State<any, any>>;
|
|
11
|
-
query(): QueryBuilder<any, any>;
|
|
12
|
-
}
|
package/lib/interfaces/IQuery.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ICommand, ICommandPattern } from "./ICommand";
|
|
2
|
-
import { IQuery, IQueryPattern } from "./IQuery";
|
|
3
|
-
export interface IRepository<T, TKey> extends IQuery<T, TKey>, ICommand<T, TKey> {
|
|
4
|
-
}
|
|
5
|
-
export interface IRepositoryPattern extends IQueryPattern, ICommandPattern {
|
|
6
|
-
}
|
package/lib/models/Entity.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type Entity<T, TKey> = {
|
|
2
|
-
value: T;
|
|
3
|
-
key: TKey;
|
|
4
|
-
};
|
|
5
|
-
export type SerializedEntity<T, TKey> = {
|
|
6
|
-
v: T;
|
|
7
|
-
k: TKey;
|
|
8
|
-
};
|
|
9
|
-
export declare function isEntity<T, TKey>(obj: any): obj is Entity<T, TKey>;
|
|
10
|
-
export declare function isSerializedEntity<T, TKey>(obj: any): obj is SerializedEntity<T, TKey>;
|
|
11
|
-
export declare function isSerializedEntityArray<T, TKey>(arr: any): arr is SerializedEntity<T, TKey>[];
|
package/lib/models/Entity.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEntity = isEntity;
|
|
4
|
-
exports.isSerializedEntity = isSerializedEntity;
|
|
5
|
-
exports.isSerializedEntityArray = isSerializedEntityArray;
|
|
6
|
-
function isEntity(obj) {
|
|
7
|
-
return (typeof obj === 'object' &&
|
|
8
|
-
obj !== null &&
|
|
9
|
-
'value' in obj &&
|
|
10
|
-
'key' in obj);
|
|
11
|
-
}
|
|
12
|
-
function isSerializedEntity(obj) {
|
|
13
|
-
return (typeof obj === 'object' &&
|
|
14
|
-
obj !== null &&
|
|
15
|
-
'v' in obj &&
|
|
16
|
-
'k' in obj);
|
|
17
|
-
}
|
|
18
|
-
function isSerializedEntityArray(arr) {
|
|
19
|
-
return Array.isArray(arr) && arr.every(isSerializedEntity);
|
|
20
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RepositoryEndpoint = void 0;
|
|
4
|
-
var RepositoryEndpoint;
|
|
5
|
-
(function (RepositoryEndpoint) {
|
|
6
|
-
RepositoryEndpoint[RepositoryEndpoint["Get"] = 1] = "Get";
|
|
7
|
-
RepositoryEndpoint[RepositoryEndpoint["Exist"] = 2] = "Exist";
|
|
8
|
-
RepositoryEndpoint[RepositoryEndpoint["Query"] = 3] = "Query";
|
|
9
|
-
RepositoryEndpoint[RepositoryEndpoint["QueryStream"] = 4] = "QueryStream";
|
|
10
|
-
RepositoryEndpoint[RepositoryEndpoint["Operation"] = 5] = "Operation";
|
|
11
|
-
RepositoryEndpoint[RepositoryEndpoint["Insert"] = 6] = "Insert";
|
|
12
|
-
RepositoryEndpoint[RepositoryEndpoint["Update"] = 7] = "Update";
|
|
13
|
-
RepositoryEndpoint[RepositoryEndpoint["Delete"] = 8] = "Delete";
|
|
14
|
-
RepositoryEndpoint[RepositoryEndpoint["Batch"] = 9] = "Batch";
|
|
15
|
-
RepositoryEndpoint[RepositoryEndpoint["BatchStream"] = 10] = "BatchStream";
|
|
16
|
-
})(RepositoryEndpoint || (exports.RepositoryEndpoint = RepositoryEndpoint = {}));
|
package/lib/models/State.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type State<T, TKey> = {
|
|
2
|
-
isOk: boolean;
|
|
3
|
-
entity: {
|
|
4
|
-
key: TKey;
|
|
5
|
-
value: T;
|
|
6
|
-
};
|
|
7
|
-
code: number | null;
|
|
8
|
-
message: string | null;
|
|
9
|
-
};
|
|
10
|
-
export type SerializedState<T, TKey> = {
|
|
11
|
-
i: boolean;
|
|
12
|
-
e: {
|
|
13
|
-
k: TKey;
|
|
14
|
-
v: T;
|
|
15
|
-
};
|
|
16
|
-
c: number | null;
|
|
17
|
-
m: string | null;
|
|
18
|
-
};
|
|
19
|
-
export declare function isState<T, TKey>(obj: any): obj is State<T, TKey>;
|
|
20
|
-
export declare function isSerializedState<T, TKey>(obj: any): obj is SerializedState<T, TKey>;
|
package/lib/models/State.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isState = isState;
|
|
4
|
-
exports.isSerializedState = isSerializedState;
|
|
5
|
-
function isState(obj) {
|
|
6
|
-
return (typeof obj === 'object' &&
|
|
7
|
-
obj !== null &&
|
|
8
|
-
typeof obj.isOk === 'boolean' &&
|
|
9
|
-
typeof obj.entity === 'object' &&
|
|
10
|
-
obj.entity !== null &&
|
|
11
|
-
'key' in obj.entity &&
|
|
12
|
-
'value' in obj.entity &&
|
|
13
|
-
('code' in obj || obj.code === null) &&
|
|
14
|
-
('message' in obj || obj.message === null));
|
|
15
|
-
}
|
|
16
|
-
function isSerializedState(obj) {
|
|
17
|
-
return (typeof obj === 'object' &&
|
|
18
|
-
obj !== null &&
|
|
19
|
-
typeof obj.i === 'boolean' &&
|
|
20
|
-
(obj.e === null || (typeof obj.e === 'object' &&
|
|
21
|
-
obj.e !== null &&
|
|
22
|
-
'k' in obj.e &&
|
|
23
|
-
'v' in obj.e)) &&
|
|
24
|
-
('c' in obj || obj.c === null) &&
|
|
25
|
-
('m' in obj || obj.m === null));
|
|
26
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ICommand, ICommandPattern } from "../interfaces/ICommand";
|
|
2
|
-
import { IQuery, IQueryPattern } from "../interfaces/IQuery";
|
|
3
|
-
import { IRepository, IRepositoryPattern } 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 RepositoryPattern(name: string): IRepositoryPattern;
|
|
15
|
-
static CommandPattern(name: string): ICommandPattern;
|
|
16
|
-
static QueryPattern(name: string): IQueryPattern;
|
|
17
|
-
private static InstancePattern;
|
|
18
|
-
static Create<T, TKey>(baseUri: string | null): RepositoryServices;
|
|
19
|
-
private AddRepository;
|
|
20
|
-
addRepository<T, TKey>(builder: (x: RepositorySettings) => void): this;
|
|
21
|
-
addCommand<T, TKey>(builder: (x: RepositorySettings) => void): this;
|
|
22
|
-
addQuery<T, TKey>(builder: (x: RepositorySettings) => void): this;
|
|
23
|
-
}
|
|
@@ -1,106 +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 RepositoryPattern(name) {
|
|
41
|
-
return RepositoryServices.InstancePattern(name, RepositoryType.Repository);
|
|
42
|
-
}
|
|
43
|
-
static CommandPattern(name) {
|
|
44
|
-
return RepositoryServices.InstancePattern(name, RepositoryType.Command);
|
|
45
|
-
}
|
|
46
|
-
static QueryPattern(name) {
|
|
47
|
-
return RepositoryServices.InstancePattern(name, RepositoryType.Query);
|
|
48
|
-
}
|
|
49
|
-
static InstancePattern(name, type) {
|
|
50
|
-
if (!RepositoryServices.instance) {
|
|
51
|
-
RepositoryServices.instance = new RepositoryServices();
|
|
52
|
-
}
|
|
53
|
-
if (RepositoryServices.instance.repositories.has(name)) {
|
|
54
|
-
const wrapper = RepositoryServices.instance.repositories.get(name);
|
|
55
|
-
if (wrapper != undefined && wrapper.type == type) {
|
|
56
|
-
if (wrapper.type == RepositoryType.Repository)
|
|
57
|
-
return wrapper.repository;
|
|
58
|
-
else if (wrapper.type == RepositoryType.Command)
|
|
59
|
-
return wrapper.repository;
|
|
60
|
-
else
|
|
61
|
-
return wrapper.repository;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
throw new Error(`${type} with '${name}' has a wrong setup.`);
|
|
65
|
-
}
|
|
66
|
-
static Create(baseUri) {
|
|
67
|
-
if (!RepositoryServices.instance) {
|
|
68
|
-
RepositoryServices.instance = new RepositoryServices();
|
|
69
|
-
}
|
|
70
|
-
RepositoryServices.instance.baseUri = baseUri;
|
|
71
|
-
return RepositoryServices.instance;
|
|
72
|
-
}
|
|
73
|
-
AddRepository(builder, type) {
|
|
74
|
-
const settings = new RepositorySettings_1.RepositorySettings();
|
|
75
|
-
builder(settings);
|
|
76
|
-
if (settings.name == null || settings.name == "")
|
|
77
|
-
throw new Error("Repository needs a name during setup. Please provide in settings a name length greater than or equal to 1.");
|
|
78
|
-
const repository = new Repository_1.Repository(this.baseUri, settings);
|
|
79
|
-
this.repositories.set(settings.name, new RepositoryWrapper(repository, type));
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
addRepository(builder) {
|
|
83
|
-
return this.AddRepository(builder, RepositoryType.Repository);
|
|
84
|
-
}
|
|
85
|
-
addCommand(builder) {
|
|
86
|
-
return this.AddRepository(builder, RepositoryType.Command);
|
|
87
|
-
}
|
|
88
|
-
addQuery(builder) {
|
|
89
|
-
return this.AddRepository(builder, RepositoryType.Query);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.RepositoryServices = RepositoryServices;
|
|
93
|
-
var RepositoryType;
|
|
94
|
-
(function (RepositoryType) {
|
|
95
|
-
RepositoryType[RepositoryType["Repository"] = 1] = "Repository";
|
|
96
|
-
RepositoryType[RepositoryType["Command"] = 2] = "Command";
|
|
97
|
-
RepositoryType[RepositoryType["Query"] = 3] = "Query";
|
|
98
|
-
})(RepositoryType || (RepositoryType = {}));
|
|
99
|
-
class RepositoryWrapper {
|
|
100
|
-
repository;
|
|
101
|
-
type;
|
|
102
|
-
constructor(repository, type) {
|
|
103
|
-
this.repository = repository;
|
|
104
|
-
this.type = type;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { RepositoryEndpoint } from "../models/RepositoryEndpoint";
|
|
2
|
-
export interface ITransformer<T> {
|
|
3
|
-
toPlain: (input: T | any) => any;
|
|
4
|
-
fromPlain: (input: any) => T;
|
|
5
|
-
}
|
|
6
|
-
export declare class RepositorySettings {
|
|
7
|
-
name: string;
|
|
8
|
-
uri: string | null;
|
|
9
|
-
path: string | null;
|
|
10
|
-
case: "PascalCase" | "CamelCase";
|
|
11
|
-
transformer?: ITransformer<any>;
|
|
12
|
-
keyTransformer?: ITransformer<any>;
|
|
13
|
-
keySeparator: string;
|
|
14
|
-
complexKey: boolean;
|
|
15
|
-
private headersEnrichers;
|
|
16
|
-
private errorsHandlers;
|
|
17
|
-
constructor();
|
|
18
|
-
addHeadersEnricher(enricher: (endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any) => Promise<HeadersInit>): this;
|
|
19
|
-
addErrorHandler(handler: (endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any, err: any) => Promise<boolean>): this;
|
|
20
|
-
enrichHeaders(endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit | undefined, body: any): Promise<HeadersInit>;
|
|
21
|
-
manageError(endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any, err: any): Promise<boolean>;
|
|
22
|
-
}
|
|
@@ -1,58 +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
|
-
case;
|
|
9
|
-
transformer; // For T
|
|
10
|
-
keyTransformer; // For TKey
|
|
11
|
-
keySeparator;
|
|
12
|
-
complexKey;
|
|
13
|
-
headersEnrichers;
|
|
14
|
-
errorsHandlers;
|
|
15
|
-
constructor() {
|
|
16
|
-
this.name = "";
|
|
17
|
-
this.uri = null;
|
|
18
|
-
this.path = null;
|
|
19
|
-
this.case = "PascalCase";
|
|
20
|
-
this.complexKey = false;
|
|
21
|
-
this.keySeparator = "|||";
|
|
22
|
-
this.headersEnrichers = new Array();
|
|
23
|
-
this.errorsHandlers = new Array();
|
|
24
|
-
}
|
|
25
|
-
addHeadersEnricher(enricher) {
|
|
26
|
-
this.headersEnrichers.push(enricher);
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
addErrorHandler(handler) {
|
|
30
|
-
this.errorsHandlers.push(handler);
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
async enrichHeaders(endpoint, uri, method, headers, body) {
|
|
34
|
-
const requestHeaders = new Headers();
|
|
35
|
-
const setHeaders = (currentHeaders) => {
|
|
36
|
-
let forcedHeaders = currentHeaders;
|
|
37
|
-
for (let header in currentHeaders) {
|
|
38
|
-
if (!requestHeaders.has(header)) {
|
|
39
|
-
requestHeaders.set(header, forcedHeaders[header]);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
if (headers != undefined) {
|
|
44
|
-
setHeaders(headers);
|
|
45
|
-
}
|
|
46
|
-
for (let enricher of this.headersEnrichers) {
|
|
47
|
-
setHeaders(await enricher(endpoint, uri, method, requestHeaders, body));
|
|
48
|
-
}
|
|
49
|
-
return requestHeaders;
|
|
50
|
-
}
|
|
51
|
-
async manageError(endpoint, uri, method, headers, body, err) {
|
|
52
|
-
let retry = this.errorsHandlers.length > 0;
|
|
53
|
-
for (let handler of this.errorsHandlers)
|
|
54
|
-
retry &&= await handler(endpoint, uri, method, headers, body, err);
|
|
55
|
-
return retry;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.RepositorySettings = RepositorySettings;
|