@aj-shadow/z-abs-corelayer-cs 0.0.0-aj-beta.221

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.
Files changed (55) hide show
  1. package/.gitattributes +26 -0
  2. package/LICENSE.txt +96 -0
  3. package/README.md +5 -0
  4. package/npm-shrinkwrap.json +13 -0
  5. package/package.json +10 -0
  6. package/project/clientServer/_build/Bundle-CoreLayer-cs.bld +25 -0
  7. package/project/clientServer/_build/Client-CoreLayer-cs.bld +10 -0
  8. package/project/clientServer/_build/Server-CoreLayer-cs.bld +12 -0
  9. package/project/clientServer/_build/z-abs-corelayer-cs.prj +28 -0
  10. package/project/clientServer/cache/cache-array.js +38 -0
  11. package/project/clientServer/cache/cache-map.js +26 -0
  12. package/project/clientServer/cache/cache-set.js +24 -0
  13. package/project/clientServer/communication/action-request.js +34 -0
  14. package/project/clientServer/communication/action-response-error.js +18 -0
  15. package/project/clientServer/communication/action-response-success.js +18 -0
  16. package/project/clientServer/communication/app-protocol/app-deserializer.js +74 -0
  17. package/project/clientServer/communication/app-protocol/app-serializer.js +55 -0
  18. package/project/clientServer/communication/cache/text-cache.js +77 -0
  19. package/project/clientServer/communication/core-protocol/core-message.js +22 -0
  20. package/project/clientServer/communication/core-protocol/core-protocol-const.js +21 -0
  21. package/project/clientServer/communication/core-protocol/deserializer-message-persistent-init-request.js +12 -0
  22. package/project/clientServer/communication/core-protocol/deserializer-message-persistent-init-response.js +12 -0
  23. package/project/clientServer/communication/core-protocol/deserializer-message-request.js +45 -0
  24. package/project/clientServer/communication/core-protocol/deserializer-message-response.js +63 -0
  25. package/project/clientServer/communication/core-protocol/deserializer-message-service-init-request.js +24 -0
  26. package/project/clientServer/communication/core-protocol/deserializer-message-service-init-response.js +16 -0
  27. package/project/clientServer/communication/core-protocol/deserializer.js +349 -0
  28. package/project/clientServer/communication/core-protocol/encoder-const.js +21 -0
  29. package/project/clientServer/communication/core-protocol/encoder-giud.js +24 -0
  30. package/project/clientServer/communication/core-protocol/envelope.js +39 -0
  31. package/project/clientServer/communication/core-protocol/serializer-message-persistent-init-request.js +33 -0
  32. package/project/clientServer/communication/core-protocol/serializer-message-persistent-init-response.js +12 -0
  33. package/project/clientServer/communication/core-protocol/serializer-message-request.js +84 -0
  34. package/project/clientServer/communication/core-protocol/serializer-message-response.js +90 -0
  35. package/project/clientServer/communication/core-protocol/serializer-message-service-init-request.js +35 -0
  36. package/project/clientServer/communication/core-protocol/serializer-message-service-init-response.js +29 -0
  37. package/project/clientServer/communication/core-protocol/serializer.js +188 -0
  38. package/project/clientServer/communication/response-data.js +16 -0
  39. package/project/clientServer/communication/service-action.js +29 -0
  40. package/project/clientServer/debug-dashboard/garbage-collection.js +27 -0
  41. package/project/clientServer/debug-dashboard/log.js +444 -0
  42. package/project/clientServer/debug-dashboard/memory.js +73 -0
  43. package/project/clientServer/factory/factory-function.js +24 -0
  44. package/project/clientServer/factory/factory-new.js +24 -0
  45. package/project/clientServer/guid-generator.js +36 -0
  46. package/project/clientServer/memory/memory-cache-array.js +64 -0
  47. package/project/clientServer/memory/memory-cache-map.js +43 -0
  48. package/project/clientServer/memory/memory-cache-object.js +44 -0
  49. package/project/clientServer/memory/memory-cache-set.js +26 -0
  50. package/project/clientServer/memory/memory-pool.js +49 -0
  51. package/project/clientServer/project.js +460 -0
  52. package/project/clientServer/synchronization/mutex-local-callback.js +50 -0
  53. package/project/clientServer/time/high-resolution-date.js +24 -0
  54. package/project/clientServer/time/high-resolution-duration.js +41 -0
  55. package/project/z-abs-corelayer-cs.tree +62 -0
@@ -0,0 +1,84 @@
1
+
2
+ 'use strict';
3
+
4
+ const EncoderConst = require('./encoder-const');
5
+
6
+
7
+ class SerializerMessageRequest {
8
+ constructor(jsonFunc) {
9
+ this.jsonFunc = jsonFunc;
10
+ this.encoder = null;
11
+ this.params = [];
12
+ }
13
+
14
+ init(encoder) {
15
+ this.encoder = encoder;
16
+ }
17
+
18
+ do(msg, cachedTexts) {
19
+ this.params = [];
20
+ const encoder = this.encoder;
21
+ const size = this._calculateData(msg);
22
+ const buffer = encoder.createBuffer(size);
23
+ encoder.setGuid(msg.id);
24
+ encoder.setUint16(msg.requests.length);
25
+ this._writeRequests(msg, cachedTexts);
26
+ return buffer;
27
+ }
28
+
29
+ _calculateData(msg) {
30
+ const encoder = this.encoder;
31
+ let size = EncoderConst.GuidSize + EncoderConst.Uint16Size;
32
+ for(let i = 0; i < msg.requests.length; ++i) {
33
+ const request = msg.requests[i];
34
+ size += EncoderConst.Uint16Size + (!msg.isServiceAction ? EncoderConst.CtSize : encoder.getStringBytes(request.name)) + EncoderConst.Uint8Size;
35
+ if(request.params) {
36
+ const params = JSON.stringify(request.params, this.jsonFunc);
37
+ size += encoder.getStringBytes(params);
38
+ this.params.push(params);
39
+ }
40
+ else {
41
+ this.params.push(null);
42
+ size += encoder.calculateDynamicBytes(0);
43
+ }
44
+ if(request.sessionId) {
45
+ size += EncoderConst.GuidSize;
46
+ }
47
+ }
48
+ return size;
49
+ }
50
+
51
+ _writeRequest(request, cachedTexts, index, isServiceAction) {
52
+ const encoder = this.encoder;
53
+ encoder.setUint16(request.index);
54
+ if(!isServiceAction) {
55
+ encoder.setCtString(request.name, cachedTexts);
56
+ }
57
+ else {
58
+ encoder.setString(request.name);
59
+ }
60
+ if(request.params) {
61
+ const params = this.params[index];
62
+ encoder.setString(params);
63
+ }
64
+ else {
65
+ encoder.setString('');
66
+ }
67
+ if(request.sessionId) {
68
+ encoder.setUint1_0(1, true);
69
+ encoder.setGuid(request.sessionId);
70
+ }
71
+ else {
72
+ encoder.setUint1_0(0, true);
73
+ }
74
+ }
75
+
76
+ _writeRequests(msg, cachedTexts) {
77
+ msg.requests.forEach((request, index) => {
78
+ this._writeRequest(request, cachedTexts, index, msg.isServiceAction);
79
+ });
80
+ }
81
+ }
82
+
83
+
84
+ module.exports = SerializerMessageRequest;
@@ -0,0 +1,90 @@
1
+
2
+ 'use strict';
3
+
4
+ const EncoderConst = require('./encoder-const');
5
+
6
+
7
+ class SerializerMessageResponse {
8
+ static SIZE = 2 + 16;
9
+
10
+ constructor(jsonFunc) {
11
+ this.jsonFunc = jsonFunc;
12
+ this.encoder = null;
13
+ this.datas = [];
14
+ }
15
+
16
+ init(encoder) {
17
+ this.encoder = encoder;
18
+ }
19
+
20
+ do(msg, cachedTexts) {
21
+ this.datas = [];
22
+ const encoder = this.encoder;
23
+ const size = this._calculateData(msg);
24
+ const buffer = encoder.createBuffer(size);
25
+ encoder.setGuid(msg.id);
26
+ encoder.setUint16(msg.responses.length);
27
+ this._writeResponses(msg, cachedTexts);
28
+ return buffer;
29
+ }
30
+
31
+ _calculateData(msg) {
32
+ const encoder = this.encoder;
33
+ let size = SerializerMessageResponse.SIZE;
34
+ for(let i = 0; i < msg.responses.length; ++i) {
35
+ const response = msg.responses[i];
36
+ size += EncoderConst.Uint16Size + (!msg.isServiceAction ? EncoderConst.CtSize : encoder.getStringBytes(response.name)) + EncoderConst.Uint8Size;
37
+ if('success' === response.result.code) {
38
+ if(response.data) {
39
+ const data = JSON.stringify(response.data, this.jsonFunc);
40
+ size += encoder.getStringBytes(data);
41
+ this.datas.push(data);
42
+ }
43
+ else {
44
+ this.datas.push(null);
45
+ }
46
+ }
47
+ else {
48
+ const data = JSON.stringify(response.result.msg, this.jsonFunc);
49
+ size += encoder.getStringBytes(data);
50
+ this.datas.push(data);
51
+ }
52
+ }
53
+ return size;
54
+ }
55
+
56
+ _writeResponse(response, index, cachedTexts, isServiceAction) {
57
+ const encoder = this.encoder;
58
+ encoder.setUint16(response.index);
59
+ if(!isServiceAction) {
60
+ encoder.setCtString(response.name, cachedTexts);
61
+ }
62
+ else {
63
+ encoder.setString(response.name);
64
+ }
65
+ if('success' === response.result.code) {
66
+ if(response.data) {
67
+ encoder.setUint8(2);
68
+ const data = this.datas[index];
69
+ encoder.setString(data);
70
+ }
71
+ else {
72
+ encoder.setUint8(1);
73
+ }
74
+ }
75
+ else {
76
+ encoder.setUint8(0);
77
+ const data = this.datas[index];
78
+ encoder.setString(data);
79
+ }
80
+ }
81
+
82
+ _writeResponses(msg, cachedTexts) {
83
+ msg.responses.forEach((response, index) => {
84
+ this._writeResponse(response, index, cachedTexts, msg.isServiceAction);
85
+ });
86
+ }
87
+ }
88
+
89
+
90
+ module.exports = SerializerMessageResponse;
@@ -0,0 +1,35 @@
1
+
2
+ 'use strict';
3
+
4
+ const EncoderConst = require('./encoder-const');
5
+
6
+
7
+ class SerializerMessageServiceInitRequest {
8
+ constructor(jsonFunc) {
9
+ this.jsonFunc = jsonFunc;
10
+ this.encoder = null;
11
+ this.params = [];
12
+ }
13
+
14
+ init(encoder) {
15
+ this.encoder = encoder;
16
+ }
17
+
18
+ do(msg, cachedTexts) {
19
+ const encoder = this.encoder;
20
+ const size = this._calculateData(msg);
21
+ const buffer = encoder.createBuffer(size);
22
+ encoder.setString(msg.nodeName);
23
+ encoder.setGuid(msg.nodeId);
24
+ encoder.setUint8(msg.nodeType);
25
+ return buffer;
26
+ }
27
+
28
+ _calculateData(msg) {
29
+ const encoder = this.encoder;
30
+ return encoder.getStringBytes(msg.nodeName) + EncoderConst.GuidSize + EncoderConst.Uint8Size;
31
+ }
32
+ }
33
+
34
+
35
+ module.exports = SerializerMessageServiceInitRequest;
@@ -0,0 +1,29 @@
1
+
2
+ 'use strict';
3
+
4
+
5
+ class SerializerMessageServiceInitResponse {
6
+ constructor(jsonFunc) {
7
+ this.jsonFunc = jsonFunc;
8
+ this.encoder = null;
9
+ this.params = [];
10
+ }
11
+
12
+ init(encoder) {
13
+ this.encoder = encoder;
14
+ }
15
+
16
+ do(msg, cachedTexts) {
17
+ const encoder = this.encoder;
18
+ const size = this._calculateData(msg);
19
+ const buffer = encoder.createBuffer(size);
20
+ encoder.setGuid(msg.id);
21
+ }
22
+
23
+ _calculateData(msg) {
24
+ const encoder = this.encoder;
25
+ }
26
+ }
27
+
28
+
29
+ module.exports = SerializerMessageServiceInitResponse;
@@ -0,0 +1,188 @@
1
+
2
+ 'use strict';
3
+
4
+ const CoreMessage = require('./core-message');
5
+ const EncoderConst = require('./encoder-const');
6
+ const SerializerMessageRequest = require('./serializer-message-request');
7
+ const SerializerMessageResponse = require('./serializer-message-response');
8
+ const SerializerMessageServiceInitRequest = require('./serializer-message-service-init-request');
9
+ const CoreProtocolConst = require('./core-protocol-const');
10
+ const AppSerializer = require('../app-protocol/app-serializer');
11
+ const TextCache = require('../cache/text-cache');
12
+
13
+
14
+ // 0 1 2 3
15
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
16
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17
+ // | 0 | flags | message id |
18
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
19
+ // | data size |
20
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21
+ // | nbrOfBuffers | data buffer size[i]... |
22
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
23
+ // | data buffers |
24
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25
+ // |
26
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-
27
+ //
28
+ // total size: UInt32 -
29
+ // flags: UInt8 - b0: ENVELOPE (FALSE/TRUE) | b1: DATA (JSON/BIN) | b2: DATA-BUFFERS (FALSE/TRUE)
30
+ // data size: UInt32 -
31
+ // nbrOfBuffers: UInt8 (OPTIONAL)
32
+ // data buffer size: UInt32 * nbrOfBuffers (OPTIONAL)
33
+ // data buffer: UInt8 * [data size]
34
+ class Serializer {
35
+ constructor(name, Encoder, textCache) {
36
+ this.name = name;
37
+ this.appSerializer = new AppSerializer();
38
+ this.textCache = textCache ? textCache : new TextCache(`SERIALIZER-${name}`, null);
39
+ this.encoder = new Encoder(this.textCache);
40
+ this.cachedTexts = {
41
+ nbr: 0,
42
+ texts: []
43
+ };
44
+ this.appSerializer.init(this.encoder);
45
+ this.appSerializer.register(CoreProtocolConst.REQUEST, new SerializerMessageRequest(Serializer.jsonFunc));
46
+ this.appSerializer.register(CoreProtocolConst.RESPONSE, new SerializerMessageResponse(Serializer.jsonFunc));
47
+ this.appSerializer.register(CoreProtocolConst.SERVICE_INIT_REQUEST, new SerializerMessageServiceInitRequest(Serializer.jsonFunc));
48
+ }
49
+
50
+ register(msgId, appSerializer) {
51
+ this.appSerializer.register(msgId, appSerializer);
52
+ }
53
+
54
+ do(msg, dataBuffers, envelope) {
55
+ //console.log('SERIALIZE:', msg.msgId);
56
+ const buffers = [];
57
+ try {
58
+ const msgId = msg.msgId ? ('number' === typeof msg.msgId ? msg.msgId : 0) : 0;
59
+ this._do(buffers, envelope, msg, dataBuffers, msgId);
60
+ //console.log('SERIALIZE - DONE', buffers);
61
+ return buffers;
62
+ }
63
+ catch(err) {
64
+ ddb.error(err, msg);
65
+ throw err;
66
+ }
67
+ }
68
+
69
+ clear() {
70
+ this.appSerializer.clear();
71
+ }
72
+
73
+ static jsonFunc = (key, value) => {
74
+ if('bigint' === typeof value) {
75
+ return {
76
+ bigint__: true,
77
+ value: value.toString()
78
+ };
79
+ }
80
+ else {
81
+ return value;
82
+ }
83
+ }
84
+
85
+ _do(buffers, envelope, msg, dataBuffers, msgId) {
86
+ const encoder = this.encoder;
87
+ let sizeData = 0;
88
+ let msgDataBuffer = null;
89
+ let sizeTextCache = 0;
90
+ const cachedTexts = this.cachedTexts;
91
+ cachedTexts.nbr = 0;
92
+ cachedTexts.texts = [];
93
+ const nbrOfBuffers = dataBuffers ? dataBuffers.length : 0;
94
+ if(!envelope) {
95
+ envelope = msg.envelope;
96
+ }
97
+ const hasEnvelope = !!envelope;
98
+ let isBinary = !!msg.isBinary;
99
+ const hasBuffers = 0 !== nbrOfBuffers;
100
+ let hasTextCache = false;
101
+ const isServiceAction = !!msg.isServiceAction;
102
+ if(isBinary) {
103
+ msgDataBuffer = msg.bin;
104
+ sizeData += encoder.calculateBytesFromBin(msgDataBuffer);
105
+ }
106
+ else {
107
+ if(0 !== msgId) {
108
+ msgDataBuffer = this.appSerializer.do(msgId, msg instanceof CoreMessage ? msg.msg : msg, cachedTexts);
109
+ hasTextCache = 0 !== cachedTexts.nbr;
110
+ if(hasTextCache) {
111
+ sizeTextCache += 1;
112
+ for(let i = 0; i < cachedTexts.texts.length; ++i) {
113
+ const text = cachedTexts.texts[i].text;
114
+ if(text) {
115
+ sizeTextCache += 2;
116
+ sizeTextCache += encoder.getStringBytes(text);
117
+ }
118
+ }
119
+ }
120
+ }
121
+ if(!msgDataBuffer) {
122
+ msgDataBuffer = JSON.stringify(msg, Serializer.jsonFunc);
123
+ sizeData += encoder.calculateBytesFromString(msgDataBuffer);
124
+ }
125
+ else {
126
+ isBinary = true;
127
+ sizeData += encoder.calculateBytesFromBin(msgDataBuffer);
128
+ }
129
+ }
130
+ this._encode(true, encoder, hasEnvelope, isBinary, hasBuffers, hasTextCache, isServiceAction, envelope, msgId, sizeTextCache, sizeData, msgDataBuffer, msg.cachedTextBuffer, cachedTexts, nbrOfBuffers, dataBuffers);
131
+ buffers.push(encoder.createBuffer(encoder.offset));
132
+ this._encode(false, encoder, hasEnvelope, isBinary, hasBuffers, hasTextCache, isServiceAction, envelope, msgId, sizeTextCache, sizeData, msgDataBuffer, msg.cachedTextBuffer, cachedTexts, nbrOfBuffers, dataBuffers);
133
+ if(hasBuffers) {
134
+ dataBuffers.forEach((dataBuffer) => {
135
+ buffers.push(dataBuffer); // DATA buffers
136
+ });
137
+ }
138
+ encoder.clear();
139
+ }
140
+
141
+ _encode(doCalculate, encoder, hasEnvelope, isBinary, hasBuffers, hasTextCache, isServiceAction, envelope, msgId, sizeTextCache, sizeData, msgDataBuffer, cachedTextBuffer, cachedTexts, nbrOfBuffers, dataBuffers) {
142
+ encoder.calculate(doCalculate);
143
+ encoder.setUint8(0);
144
+ encoder.setBool1_0(hasEnvelope, false);
145
+ encoder.setBool1_1(isBinary, false);
146
+ encoder.setBool1_2(hasBuffers, false);
147
+ encoder.setBool1_3(hasTextCache || cachedTextBuffer, false);
148
+ encoder.setBool1_4(isServiceAction, true);
149
+ encoder.setUint16(msgId);
150
+ if(hasEnvelope) {
151
+ encoder.setString(envelope.serviceName);
152
+ encoder.setGuidArray(envelope.routes);
153
+ encoder.setGuidArray(envelope.recordRoutes);
154
+ }
155
+ if(cachedTextBuffer) {
156
+ const size = encoder.calculateBytesFromBin(cachedTextBuffer);
157
+ encoder.setDynamicBytes(size);
158
+ encoder.setRawBinary(cachedTextBuffer, size);
159
+ }
160
+ else if(hasTextCache) {
161
+ encoder.setDynamicBytes(sizeTextCache);
162
+ encoder.setUint8(cachedTexts.nbr); // cached texts
163
+ for(let i = 0; i < cachedTexts.texts.length; ++i) {
164
+ const text = cachedTexts.texts[i];
165
+ if(text.text) {
166
+ encoder.setUint16(text.id);
167
+ encoder.setString(text.text);
168
+ }
169
+ }
170
+ }
171
+ encoder.setDynamicBytes(sizeData);
172
+ if(isBinary) { // data
173
+ encoder.setRawBinary(msgDataBuffer, sizeData);
174
+ }
175
+ else {
176
+ encoder.setRawString(msgDataBuffer, sizeData);
177
+ }
178
+ if(hasBuffers) {
179
+ encoder.setUint8(nbrOfBuffers); // nbr of data buffers
180
+ dataBuffers.forEach((dataBuffer) => {
181
+ encoder.setUint32(dataBuffer.byteLength); // size of data buffer[i]
182
+ });
183
+ }
184
+ }
185
+ }
186
+
187
+
188
+ module.exports = Serializer;
@@ -0,0 +1,16 @@
1
+
2
+ 'use strict';
3
+
4
+ class ActionData {
5
+ constructor(result, data) {
6
+ this.result = result;
7
+ this.data = data;
8
+ }
9
+
10
+ isSuccess() {
11
+ return 'success' === this.result.code;
12
+ }
13
+ }
14
+
15
+
16
+ module.exports = ActionData;
@@ -0,0 +1,29 @@
1
+
2
+ 'use strict';
3
+
4
+ const CoreProtocolConst = require('./core-protocol/core-protocol-const');
5
+ const ActionRequest = require('./action-request');
6
+
7
+
8
+ class ServiceAction {
9
+ constructor(serviceName, ...params) {
10
+ this.msgId = CoreProtocolConst.REQUEST;
11
+ this.serviceName = serviceName;
12
+ this.actionRequest = new ActionRequest().add(this.constructor.name.substring(13), 0, ...params);
13
+ this.actionRequest.isServiceAction = true;
14
+ this.responses = [];
15
+ };
16
+
17
+ setIds(requestId, sessionId) {
18
+ this.actionRequest.setIds(requestId, sessionId);
19
+ }
20
+
21
+ setResponses(responses) {
22
+ if(responses) {
23
+ this.responses = responses;
24
+ }
25
+ }
26
+ }
27
+
28
+
29
+ module.exports = ServiceAction;
@@ -0,0 +1,27 @@
1
+
2
+ 'use strict';
3
+
4
+
5
+ class GarbageCollection {
6
+ constructor() {
7
+ this.waiting = false;
8
+ }
9
+
10
+ gc() {
11
+ if(window.gc) {
12
+ if(!this.waiting) {
13
+ this.waiting = true;
14
+ setTimeout(() => {
15
+ this.waiting = false;
16
+ window.gc();
17
+ }, 100);
18
+ }
19
+ }
20
+ else {
21
+ console.warn('Please start browser with \'--js-flags="--expose-gc"\'');
22
+ }
23
+ }
24
+ }
25
+
26
+
27
+ global.ddgc = new GarbageCollection();