active-connect-ng2 0.2.40 → 0.2.41
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/ng-package.json +7 -0
- package/package.json +13 -32
- package/src/lib/active-connect-ng2.module.ts +34 -0
- package/src/lib/websocket/client.ts +438 -0
- package/src/lib/websocket/decorators/function.ts +44 -0
- package/src/lib/websocket/decorators/websocket/handle.ts +12 -0
- package/src/lib/websocket/decorators/websocket/on-reconnect.ts +6 -0
- package/src/lib/websocket/decorators/websocket/on-success.ts +11 -0
- package/src/lib/websocket/decorators/websocket/outbound.ts +212 -0
- package/src/lib/websocket/decorators/websocket/route.ts +32 -0
- package/src/lib/websocket/decorators/websocket/shared.ts +11 -0
- package/{lib/websocket/decorators/websocket/websocket-route-service.d.ts → src/lib/websocket/decorators/websocket/websocket-route-service.ts} +3 -2
- package/src/lib/websocket/json/json-parser.ts +26 -0
- package/src/lib/websocket/lifecycle/loading-status.ts +32 -0
- package/src/lib/websocket/objects/outbound-object.ts +430 -0
- package/{public-api.d.ts → src/public-api.ts} +4 -0
- package/tsconfig.lib.json +14 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +14 -0
- package/esm2020/active-connect-ng2.mjs +0 -5
- package/esm2020/lib/active-connect-ng2.module.mjs +0 -42
- package/esm2020/lib/websocket/client.mjs +0 -347
- package/esm2020/lib/websocket/decorators/function.mjs +0 -40
- package/esm2020/lib/websocket/decorators/websocket/handle.mjs +0 -9
- package/esm2020/lib/websocket/decorators/websocket/on-reconnect.mjs +0 -6
- package/esm2020/lib/websocket/decorators/websocket/on-success.mjs +0 -8
- package/esm2020/lib/websocket/decorators/websocket/outbound.mjs +0 -213
- package/esm2020/lib/websocket/decorators/websocket/route.mjs +0 -31
- package/esm2020/lib/websocket/decorators/websocket/shared.mjs +0 -10
- package/esm2020/lib/websocket/decorators/websocket/websocket-route-service.mjs +0 -2
- package/esm2020/lib/websocket/index.mjs +0 -11
- package/esm2020/lib/websocket/json/json-parser.mjs +0 -23
- package/esm2020/lib/websocket/lifecycle/loading-status.mjs +0 -31
- package/esm2020/lib/websocket/objects/outbound-object.mjs +0 -398
- package/esm2020/public-api.mjs +0 -7
- package/fesm2015/active-connect-ng2.mjs +0 -1178
- package/fesm2015/active-connect-ng2.mjs.map +0 -1
- package/fesm2020/active-connect-ng2.mjs +0 -1160
- package/fesm2020/active-connect-ng2.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/active-connect-ng2.module.d.ts +0 -7
- package/lib/websocket/client.d.ts +0 -59
- package/lib/websocket/decorators/function.d.ts +0 -30
- package/lib/websocket/decorators/websocket/handle.d.ts +0 -1
- package/lib/websocket/decorators/websocket/on-reconnect.d.ts +0 -1
- package/lib/websocket/decorators/websocket/on-success.d.ts +0 -1
- package/lib/websocket/decorators/websocket/outbound.d.ts +0 -1
- package/lib/websocket/decorators/websocket/route.d.ts +0 -1
- package/lib/websocket/decorators/websocket/shared.d.ts +0 -4
- package/lib/websocket/json/json-parser.d.ts +0 -5
- package/lib/websocket/lifecycle/loading-status.d.ts +0 -9
- package/lib/websocket/objects/outbound-object.d.ts +0 -48
- /package/{lib/websocket/index.d.ts → src/lib/websocket/index.ts} +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { WebsocketClient } from '../../client';
|
|
2
|
+
|
|
3
|
+
export function Outbound(
|
|
4
|
+
method: string,
|
|
5
|
+
requestingRequired?: boolean,
|
|
6
|
+
cached?: boolean,
|
|
7
|
+
sortBy?: (a: any, b: any) => number
|
|
8
|
+
) {
|
|
9
|
+
return function _Outbound(target: any, propertyKey: string): any {
|
|
10
|
+
target.loading = new Map<string, boolean>();
|
|
11
|
+
// property annotation
|
|
12
|
+
WebsocketClient.expectOutbound(
|
|
13
|
+
method,
|
|
14
|
+
function setOutbound(
|
|
15
|
+
data: any,
|
|
16
|
+
specificHash: number | null,
|
|
17
|
+
inserted: any[] | null,
|
|
18
|
+
updated: any[] | null,
|
|
19
|
+
deleted: any[] | null,
|
|
20
|
+
length: number | null,
|
|
21
|
+
_this: WebsocketClient
|
|
22
|
+
) {
|
|
23
|
+
if (!target.___received) target.___received = {};
|
|
24
|
+
if (!target.___data) target.___data = {};
|
|
25
|
+
if (!target.___received) target.___received = {};
|
|
26
|
+
if (!target.___requested) target.___requested = {};
|
|
27
|
+
if (!cached) {
|
|
28
|
+
if (_this.dbService) {
|
|
29
|
+
try {
|
|
30
|
+
_this.dbService
|
|
31
|
+
.deleteByKey('outbound', method)
|
|
32
|
+
.subscribe(() => {});
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error(
|
|
35
|
+
'ActiveConnect: could not delete indexdb cache entry'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (data == 'cache_restore') {
|
|
42
|
+
if (_this.dbService) {
|
|
43
|
+
try {
|
|
44
|
+
_this.dbService
|
|
45
|
+
.getByKey('outbound', method)
|
|
46
|
+
.subscribe((result: any) => {
|
|
47
|
+
target.___received[propertyKey] = true;
|
|
48
|
+
target.___data[propertyKey] = result.data;
|
|
49
|
+
target.loading.set(propertyKey, false);
|
|
50
|
+
});
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error('ActiveConnect: Unable to restore cached data.');
|
|
53
|
+
console.error(e);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
console.error(
|
|
57
|
+
'ActiveConnect: Caching / restore not possible as the indexedDB is not accessible'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
} else if (data == 'cache_delete') {
|
|
61
|
+
if (_this.dbService) {
|
|
62
|
+
try {
|
|
63
|
+
_this.dbService
|
|
64
|
+
.deleteByKey('outbound', method)
|
|
65
|
+
.subscribe(() => {});
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error('ActiveConnect: Unable to delete cached data');
|
|
68
|
+
console.error(e);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
console.error(
|
|
72
|
+
'ActiveConnect: Caching / restore not possible as the indexedDB is not accessible'
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
target.___received[propertyKey] = false;
|
|
76
|
+
target.___data[propertyKey] = undefined;
|
|
77
|
+
target.loading.set(propertyKey, false);
|
|
78
|
+
} else if (data == 'data_delete') {
|
|
79
|
+
target.___data[propertyKey] = undefined;
|
|
80
|
+
target.loading.set(propertyKey, false);
|
|
81
|
+
target.___received[propertyKey] = false;
|
|
82
|
+
target.___requested[propertyKey] = false;
|
|
83
|
+
} else if (data == 'data_diff') {
|
|
84
|
+
var data = target.___data[propertyKey] || [];
|
|
85
|
+
inserted?.forEach((e) => {
|
|
86
|
+
const matching = data.filter((d: any) => d.id == e.id);
|
|
87
|
+
if (matching.length > 0) {
|
|
88
|
+
data[data.indexOf(matching[0])] = e;
|
|
89
|
+
} else {
|
|
90
|
+
data.push(e);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
updated?.forEach((e) => {
|
|
94
|
+
const matching = data.filter((d: any) => d.id == e.id);
|
|
95
|
+
if (matching.length > 0) {
|
|
96
|
+
data[data.indexOf(matching[0])] = e;
|
|
97
|
+
} else {
|
|
98
|
+
data.push(e);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
deleted?.forEach((e) => {
|
|
102
|
+
data = data.filter((d: any) => d.id != e.id);
|
|
103
|
+
});
|
|
104
|
+
if (sortBy && data) data = data.sort(sortBy);
|
|
105
|
+
target.___data[propertyKey] = data;
|
|
106
|
+
target.loading.set(propertyKey, false);
|
|
107
|
+
|
|
108
|
+
if (cached && specificHash) {
|
|
109
|
+
if (_this.dbService) {
|
|
110
|
+
if (data && data?.length > 0) {
|
|
111
|
+
try {
|
|
112
|
+
_this.dbService
|
|
113
|
+
.update('outbound', {
|
|
114
|
+
method,
|
|
115
|
+
data,
|
|
116
|
+
specificHash,
|
|
117
|
+
})
|
|
118
|
+
.subscribe(() => {});
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error('ActiveConnect: Unable to update cached data');
|
|
121
|
+
console.error(e);
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
try {
|
|
125
|
+
_this.dbService
|
|
126
|
+
.deleteByKey('outbound', method)
|
|
127
|
+
.subscribe(() => {});
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.error('ActiveConnect: Unable to delete cached data');
|
|
130
|
+
console.error(e);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
console.error(
|
|
135
|
+
'ActiveConnect: Caching not possible as the indexedDB has not been initialized'
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
if (sortBy && data) data = data.sort(sortBy);
|
|
141
|
+
target.___received[propertyKey] = true;
|
|
142
|
+
target.___data[propertyKey] = data;
|
|
143
|
+
target.loading.set(propertyKey, false);
|
|
144
|
+
if (cached && specificHash) {
|
|
145
|
+
if (_this.dbService) {
|
|
146
|
+
if (data && data?.length > 0) {
|
|
147
|
+
try {
|
|
148
|
+
_this.dbService
|
|
149
|
+
.update('outbound', {
|
|
150
|
+
method,
|
|
151
|
+
data,
|
|
152
|
+
specificHash,
|
|
153
|
+
})
|
|
154
|
+
.subscribe(() => {});
|
|
155
|
+
} catch (e) {
|
|
156
|
+
console.error('ActiveConnect: Unable to update cached data');
|
|
157
|
+
console.error(e);
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
try {
|
|
161
|
+
_this.dbService
|
|
162
|
+
.deleteByKey('outbound', method)
|
|
163
|
+
.subscribe(() => {});
|
|
164
|
+
} catch (e) {
|
|
165
|
+
console.error('ActiveConnect: Unable to update cached data');
|
|
166
|
+
console.error(e);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
console.error(
|
|
171
|
+
'ActiveConnect: Caching not possible as the indexedDB has not been initialized'
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
if (requestingRequired) {
|
|
179
|
+
WebsocketClient.addResetRequestingStateCallback(function callback() {
|
|
180
|
+
if (target.___requested) {
|
|
181
|
+
target.___requested[propertyKey] = false;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const obj = {
|
|
187
|
+
configurable: true,
|
|
188
|
+
get() {
|
|
189
|
+
if (!target.___requested) target.___requested = {};
|
|
190
|
+
if (requestingRequired && !target.___requested[propertyKey]) {
|
|
191
|
+
target.___requested[propertyKey] = true;
|
|
192
|
+
(this as any).send('request.' + method, null).then();
|
|
193
|
+
}
|
|
194
|
+
if (!target.___data) target.___data = {};
|
|
195
|
+
if (!target.___data[propertyKey]) {
|
|
196
|
+
target.loading.set(propertyKey, true);
|
|
197
|
+
} else if (target.loading[propertyKey]) {
|
|
198
|
+
target.loading.set(propertyKey, false);
|
|
199
|
+
}
|
|
200
|
+
return target.___data[propertyKey];
|
|
201
|
+
},
|
|
202
|
+
set(val: any) {
|
|
203
|
+
if (!target.___data) target.___data = {};
|
|
204
|
+
target.loading.set(propertyKey, false);
|
|
205
|
+
if (sortBy && val) val = val.sort(sortBy);
|
|
206
|
+
return (target.___data[propertyKey] = val);
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
target[propertyKey] = obj;
|
|
210
|
+
return obj;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function Route(
|
|
2
|
+
method: string,
|
|
3
|
+
loadingKey?: string,
|
|
4
|
+
dontEnsureTransmission?: boolean
|
|
5
|
+
) {
|
|
6
|
+
return function _Route(target: any, propertyKey: string): any {
|
|
7
|
+
// method annotation
|
|
8
|
+
const original = target[propertyKey];
|
|
9
|
+
target[propertyKey] = async function execRoute(...data: any): Promise<any> {
|
|
10
|
+
if (loadingKey) {
|
|
11
|
+
if (!this.loadingElements[loadingKey]) {
|
|
12
|
+
this.loadingElements[loadingKey] = 0;
|
|
13
|
+
}
|
|
14
|
+
this.loadingElements[loadingKey]++;
|
|
15
|
+
}
|
|
16
|
+
const promise = original.bind(this)(...data);
|
|
17
|
+
let res = null;
|
|
18
|
+
if (this.client) {
|
|
19
|
+
res = await this.client
|
|
20
|
+
.send(method, data[0], dontEnsureTransmission)
|
|
21
|
+
?.catch((err: any) => {
|
|
22
|
+
if (loadingKey) this.loadingElements[loadingKey]--;
|
|
23
|
+
throw err;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
await promise;
|
|
27
|
+
if (loadingKey) this.loadingElements[loadingKey]--;
|
|
28
|
+
return res;
|
|
29
|
+
};
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated
|
|
3
|
+
*/
|
|
4
|
+
export function Shared<T>(defaultValue?: T) {
|
|
5
|
+
if (defaultValue) {
|
|
6
|
+
throw Error(
|
|
7
|
+
"Active-Connect/@Shared: defaultValue is no longer supported, please assign the value to the variable itself."
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return function _Shared(target: any, propertyKey: string) {};
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class JsonParser {
|
|
2
|
+
static stringify(obj: any) {
|
|
3
|
+
return JSON.stringify(obj);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
static parsingFunction(key: any, value: any) {
|
|
7
|
+
var a;
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
a =
|
|
10
|
+
/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}\:[0-9]{2}\:[0-9]{2}\.[0-9]{3}Z$/.exec(
|
|
11
|
+
value
|
|
12
|
+
);
|
|
13
|
+
if (a) {
|
|
14
|
+
return new Date(a as any);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static parse(str: string) {
|
|
21
|
+
if (str && str != "undefined") {
|
|
22
|
+
return JSON.parse(str, JsonParser.parsingFunction);
|
|
23
|
+
}
|
|
24
|
+
return str;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WebsocketClient } from '../client';
|
|
2
|
+
|
|
3
|
+
export class LoadingStatus extends WebsocketClient {
|
|
4
|
+
private __proto__: any;
|
|
5
|
+
static loading: Map<string, boolean>;
|
|
6
|
+
get isLoading(): boolean {
|
|
7
|
+
// return general loading
|
|
8
|
+
let anyTrue = false;
|
|
9
|
+
this.__proto__.loading.forEach((e: boolean) => {
|
|
10
|
+
anyTrue ||= e;
|
|
11
|
+
});
|
|
12
|
+
if (!anyTrue) this.__proto__.loading.clear();
|
|
13
|
+
return this.__proto__.loading.size > 0;
|
|
14
|
+
}
|
|
15
|
+
getLoadingMap(): Map<string, boolean> {
|
|
16
|
+
return this.__proto__.loading;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get getCurrent(): number {
|
|
20
|
+
let count = 0;
|
|
21
|
+
this.__proto__.loading.forEach((e: boolean) => {
|
|
22
|
+
if (e) count++;
|
|
23
|
+
});
|
|
24
|
+
if (count == 0) {
|
|
25
|
+
this.__proto__.loading.clear();
|
|
26
|
+
}
|
|
27
|
+
return count;
|
|
28
|
+
}
|
|
29
|
+
get getTotal(): number {
|
|
30
|
+
return this.__proto__.loading.size;
|
|
31
|
+
}
|
|
32
|
+
}
|