@itee/client 10.0.0

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 (61) hide show
  1. package/CHANGELOG.md +251 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +76 -0
  4. package/builds/itee-client.cjs.js +6517 -0
  5. package/builds/itee-client.cjs.js.map +1 -0
  6. package/builds/itee-client.cjs.min.js +125 -0
  7. package/builds/itee-client.esm.js +6468 -0
  8. package/builds/itee-client.esm.js.map +1 -0
  9. package/builds/itee-client.esm.min.js +124 -0
  10. package/builds/itee-client.iife.js +6524 -0
  11. package/builds/itee-client.iife.js.map +1 -0
  12. package/builds/itee-client.iife.min.js +125 -0
  13. package/package.json +87 -0
  14. package/sources/client.js +14 -0
  15. package/sources/cores/TAbstractFactory.js +42 -0
  16. package/sources/cores/TCloningFactory.js +39 -0
  17. package/sources/cores/TConstants.js +433 -0
  18. package/sources/cores/TInstancingFactory.js +41 -0
  19. package/sources/cores/TStore.js +303 -0
  20. package/sources/cores/_cores.js +13 -0
  21. package/sources/input_devices/TKeyboardController.js +158 -0
  22. package/sources/input_devices/TMouseController.js +31 -0
  23. package/sources/input_devices/_inputDevices.js +11 -0
  24. package/sources/loaders/TBinaryConverter.js +35 -0
  25. package/sources/loaders/TBinaryReader.js +1029 -0
  26. package/sources/loaders/TBinarySerializer.js +258 -0
  27. package/sources/loaders/TBinaryWriter.js +429 -0
  28. package/sources/loaders/_loaders.js +21 -0
  29. package/sources/loaders/converters/ArrayBinaryConverter.js +33 -0
  30. package/sources/loaders/converters/BooleanBinaryConverter.js +24 -0
  31. package/sources/loaders/converters/DateBinaryConverter.js +21 -0
  32. package/sources/loaders/converters/NullBinaryConverter.js +13 -0
  33. package/sources/loaders/converters/NumberBinaryConverter.js +15 -0
  34. package/sources/loaders/converters/ObjectBinaryConverter.js +101 -0
  35. package/sources/loaders/converters/RegExBinaryConverter.js +11 -0
  36. package/sources/loaders/converters/StringBinaryConverter.js +26 -0
  37. package/sources/loaders/converters/UndefinedBinaryConverter.js +13 -0
  38. package/sources/managers/TDataBaseManager.js +1649 -0
  39. package/sources/managers/_managers.js +10 -0
  40. package/sources/utils/TIdFactory.js +84 -0
  41. package/sources/utils/_utils.js +9 -0
  42. package/sources/webapis/WebAPI.js +773 -0
  43. package/sources/webapis/WebAPIOrigin.js +141 -0
  44. package/sources/webapis/_webapis.js +10 -0
  45. package/sources/webapis/messages/WebAPIMessage.js +75 -0
  46. package/sources/webapis/messages/WebAPIMessageData.js +51 -0
  47. package/sources/webapis/messages/WebAPIMessageError.js +79 -0
  48. package/sources/webapis/messages/WebAPIMessageEvent.js +58 -0
  49. package/sources/webapis/messages/WebAPIMessageProgress.js +91 -0
  50. package/sources/webapis/messages/WebAPIMessageReady.js +66 -0
  51. package/sources/webapis/messages/WebAPIMessageRequest.js +94 -0
  52. package/sources/webapis/messages/WebAPIMessageResponse.js +80 -0
  53. package/sources/webapis/messages/_messages.js +16 -0
  54. package/sources/workers/AbstractWorker.js +149 -0
  55. package/sources/workers/_workers.js +10 -0
  56. package/sources/workers/messages/WorkerMessage.js +33 -0
  57. package/sources/workers/messages/WorkerMessageData.js +30 -0
  58. package/sources/workers/messages/WorkerMessageError.js +32 -0
  59. package/sources/workers/messages/WorkerMessageMethodCall.js +60 -0
  60. package/sources/workers/messages/WorkerMessageProgress.js +67 -0
  61. package/sources/workers/messages/_messages.js +14 -0
@@ -0,0 +1,303 @@
1
+ import {
2
+ isFunction,
3
+ isNotArray,
4
+ isNotBoolean,
5
+ isNotObject,
6
+ isNotUndefined,
7
+ isNull,
8
+ isString,
9
+ isUndefined
10
+ } from '@itee/validators'
11
+
12
+ /**
13
+ * @class
14
+ * @classdesc TStore is a simple javascript object whose purpose is to store some ket/value data to future usage. It could be enable/disable.
15
+ *
16
+ * @example {@lang javascript}
17
+ * var cache = new TCache()
18
+ * cache.add( 'foo', 'bar' )
19
+ * TLogger.log( cache.get('foo') ) // 'bar'
20
+ *
21
+ * @author [Tristan Valcke]{@link https://github.com/Itee}
22
+ * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
23
+ */
24
+ class TStore {
25
+
26
+ /**
27
+ * @constructor
28
+ * @param {Object} [parameters={}]
29
+ * @param {Object} [parameters.collection={}]
30
+ * @param {Boolean} [parameters.allowOverride=false]
31
+ * @param {Array.<function>} [parameters.keyValidators=[]]
32
+ * @param {Array.<function>} [parameters.valueValidators=[]]
33
+ */
34
+ constructor( parameters = {} ) {
35
+
36
+ const _parameters = {
37
+ ...{
38
+ collection: {},
39
+ allowOverride: false,
40
+ keyValidators: [],
41
+ valueValidators: []
42
+ }, ...parameters
43
+ }
44
+
45
+ this.collection = _parameters.collection
46
+ this.allowOverride = _parameters.allowOverride
47
+ this.keyValidators = _parameters.keyValidators
48
+ this.valueValidators = _parameters.valueValidators
49
+
50
+ }
51
+ /**
52
+ *
53
+ * @return {{}}
54
+ */
55
+ get collection() {
56
+
57
+ return this._collection
58
+
59
+ }
60
+ set collection( value ) {
61
+
62
+ const memberName = 'Collection'
63
+ const expect = 'Expect an object.'
64
+
65
+ if ( isNull( value ) ) { throw new TypeError( `${ memberName } cannot be null ! ${ expect }` ) }
66
+ if ( isUndefined( value ) ) { throw new TypeError( `${ memberName } cannot be undefined ! ${ expect }` ) }
67
+ if ( isNotObject( value ) ) { throw new TypeError( `${ memberName } cannot be an instance of ${ value.constructor.name } ! ${ expect }` ) }
68
+
69
+ this._collection = value
70
+
71
+ }
72
+ /**
73
+ *
74
+ * @return {*}
75
+ */
76
+ get allowOverride() {
77
+
78
+ return this._allowOverride
79
+
80
+ }
81
+ set allowOverride( value ) {
82
+
83
+ const memberName = 'Allow override'
84
+ const expect = 'Expect a boolean.'
85
+
86
+ if ( isNull( value ) ) { throw new TypeError( `${ memberName } cannot be null ! ${ expect }` ) }
87
+ if ( isUndefined( value ) ) { throw new TypeError( `${ memberName } cannot be undefined ! ${ expect }` ) }
88
+ if ( isNotBoolean( value ) ) { throw new TypeError( `${ memberName } cannot be an instance of ${ value.constructor.name } ! ${ expect }` ) }
89
+
90
+ this._allowOverride = value
91
+
92
+ }
93
+ /**
94
+ *
95
+ * @return {*}
96
+ */
97
+ get keyValidators() {
98
+
99
+ return this._keyValidators
100
+
101
+ }
102
+ set keyValidators( value ) {
103
+
104
+ const memberName = 'Keys validators'
105
+ const expect = 'Expect an array of TValidator or an empty array.'
106
+
107
+ if ( isNull( value ) ) { throw new TypeError( `${ memberName } cannot be null ! ${ expect }` ) }
108
+ if ( isUndefined( value ) ) { throw new TypeError( `${ memberName } cannot be undefined ! ${ expect }` ) }
109
+ if ( isNotArray( value ) ) { throw new TypeError( `${ memberName } cannot be an instance of ${ value.constructor.name } ! ${ expect }` ) }
110
+
111
+ this._keyValidators = value
112
+
113
+ }
114
+ /**
115
+ *
116
+ * @return {*}
117
+ */
118
+ get valueValidators() {
119
+ return this._valueValidators
120
+ }
121
+ set valueValidators( value ) {
122
+
123
+ const memberName = 'Values validators'
124
+ const expect = 'Expect an array of TValidator or an empty array.'
125
+
126
+ if ( isNull( value ) ) { throw new TypeError( `${ memberName } cannot be null ! ${ expect }` ) }
127
+ if ( isUndefined( value ) ) { throw new TypeError( `${ memberName } cannot be undefined ! ${ expect }` ) }
128
+ if ( isNotArray( value ) ) { throw new TypeError( `${ memberName } cannot be an instance of ${ value.constructor.name } ! ${ expect }` ) }
129
+
130
+ this._valueValidators = value
131
+
132
+ }
133
+ /**
134
+ *
135
+ * @return {string[]}
136
+ */
137
+ get keys() {
138
+
139
+ return Object.keys( this._collection )
140
+
141
+ }
142
+ /**
143
+ *
144
+ * @return {unknown[] | any[]}
145
+ */
146
+ get values() {
147
+
148
+ return Object.values( this._collection )
149
+
150
+ }
151
+ /**
152
+ *
153
+ * @param value
154
+ * @param validators
155
+ * @private
156
+ */
157
+ static _validate( value, validators ) {
158
+
159
+ for ( let validatorIndex = 0, numberOfValidators = validators.length ; validatorIndex < numberOfValidators ; validatorIndex++ ) {
160
+
161
+ let validator = validators[ validatorIndex ]
162
+
163
+ if ( !validator.validator( value ) ) {
164
+
165
+ const error = validator.error
166
+ if ( isString( error ) ) {
167
+ throw new TypeError( error )
168
+ } else if ( isFunction( error ) ) {
169
+ throw new TypeError( error( value ) )
170
+ } else {
171
+ throw new TypeError( `${ value } is invalid.` )
172
+ }
173
+
174
+ }
175
+
176
+ }
177
+
178
+ }
179
+ /**
180
+ *
181
+ * @param value
182
+ * @return {TStore} The current instance (this)
183
+ */
184
+ setCollection( value ) {
185
+
186
+ this.collection = value
187
+ return this
188
+
189
+ }
190
+
191
+ /**
192
+ *
193
+ * @param value
194
+ * @return {TStore} The current instance (this)
195
+ */
196
+ setAllowOverride( value ) {
197
+
198
+ this.allowOverride = value
199
+ return this
200
+
201
+ }
202
+
203
+ /**
204
+ *
205
+ * @param value
206
+ * @return {TStore} The current instance (this)
207
+ */
208
+ setKeyValidators( value ) {
209
+
210
+ this.keyValidators( value )
211
+ return this
212
+
213
+ }
214
+
215
+ /**
216
+ *
217
+ * @param value
218
+ * @return {TStore} The current instance (this)
219
+ */
220
+ setValueValidators( value ) {
221
+
222
+ this.valueValidators( value )
223
+ return this
224
+
225
+ }
226
+
227
+ /**
228
+ * Allow to add new key value pair, the key cannot be null, undefined, or an empty string.
229
+ * In case the key already exist, the value will be overwritten if force params is true or this
230
+ * allow overriding else it throw an TypeError.
231
+ *
232
+ * @param {*} key
233
+ * @param {*} value
234
+ * @param {Boolean} force
235
+ * @return {TStore} The current instance (this)
236
+ */
237
+ add( key, value, force = false ) {
238
+
239
+ if ( this.contain( key ) && ( !this._allowOverride && !force ) ) {
240
+ throw new TypeError( `Item with key (${ key }) already exist in collection !` )
241
+ }
242
+
243
+ TStore._validate( key, this._keyValidators )
244
+ TStore._validate( value, this._valueValidators )
245
+
246
+ this._collection[ key ] = value
247
+
248
+ return this
249
+
250
+ }
251
+
252
+ /**
253
+ *
254
+ * @param key
255
+ * @return {boolean}
256
+ */
257
+ contain( key ) {
258
+
259
+ return isNotUndefined( this._collection[ key ] )
260
+
261
+ }
262
+
263
+ /**
264
+ * Return the value associated to the key.
265
+ *
266
+ * @param key
267
+ * @returns {*}
268
+ */
269
+ get( key ) {
270
+
271
+ return this._collection[ key ]
272
+
273
+ }
274
+
275
+ /**
276
+ * Remove to value from the cache. Does nothing if the key does not exist.
277
+ *
278
+ * @param key
279
+ * @return {TStore} The current instance (this)
280
+ */
281
+ remove( key ) {
282
+
283
+ delete this._collection[ key ]
284
+
285
+ return this
286
+
287
+ }
288
+
289
+ /**
290
+ * Clear the cache and reset collection to an empty object.
291
+ * @return {TStore} The current instance (this)
292
+ */
293
+ clear() {
294
+
295
+ this._collection = {}
296
+
297
+ return this
298
+
299
+ }
300
+
301
+ }
302
+
303
+ export { TStore }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module InputDevice
3
+ * @description Intermediary export file for cores. Export [Constants]{@link globals}, [TStore]{@link TStore}, [TAbstractFactory]{@link TAbstractFactory}, [TCloningFactory]{@link TCloningFactory}, and [TInstancingFactory]{@link TInstancingFactory}
4
+ *
5
+ * @author [Tristan Valcke]{@link https://github.com/Itee}
6
+ * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
7
+ */
8
+
9
+ export * from './TConstants.js'
10
+ export { TStore } from './TStore.js'
11
+ export { TAbstractFactory } from './TAbstractFactory.js'
12
+ export { TCloningFactory } from './TCloningFactory.js'
13
+ export { TInstancingFactory } from './TInstancingFactory.js'
@@ -0,0 +1,158 @@
1
+ /* eslint-env browser */
2
+
3
+ import { DefaultLogger as TLogger } from '@itee/core'
4
+ import { Keys } from '../cores/TConstants.js'
5
+
6
+ /**
7
+ * @class
8
+ * @classdesc TKeyboardController allow single source of thruth for keyboard state checking (based on Lee Stemkoski work).
9
+ * See TKeyboardController.k object data below for names of keys whose state can be polled
10
+ *
11
+ * @author [Tristan Valcke]{@link https://github.com/Itee}
12
+ * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
13
+ * @example {@lang javascript}
14
+ * // (1) create a global variable:
15
+ * var keyboard = new TKeyboardController();
16
+ *
17
+ * // (2) during main loop:
18
+ * keyboard.update();
19
+ *
20
+ * // (3) check state of keys:
21
+ * keyboard.down("A") -- true for one update cycle after key is pressed
22
+ * keyboard.pressed("A") -- true as long as key is being pressed
23
+ * keyboard.up("A") -- true for one update cycle after key is released
24
+ */
25
+ class TKeyboardController {
26
+
27
+ /**
28
+ *
29
+ * @param parameters
30
+ */
31
+ // eslint-disable-next-line no-unused-vars
32
+ constructor( parameters = {} ) {
33
+
34
+ // const _parameters = {
35
+ // ...{},
36
+ // ...parameters
37
+ // }
38
+
39
+ // bind keyEvents
40
+ document.addEventListener( 'keydown', TKeyboardController.onKeyDown, false )
41
+ document.addEventListener( 'keyup', TKeyboardController.onKeyUp, false )
42
+
43
+ }
44
+ /**
45
+ *
46
+ * @param keyCode
47
+ * @return {string}
48
+ */
49
+ static keyName( keyCode ) {
50
+ return ( TKeyboardController.k[ keyCode ] !== null ) ?
51
+ TKeyboardController.k[ keyCode ] :
52
+ String.fromCharCode( keyCode )
53
+ }
54
+ /**
55
+ *
56
+ * @param event
57
+ */
58
+ static onKeyUp( event ) {
59
+ var key = TKeyboardController.keyName( event.keyCode )
60
+ if ( TKeyboardController.status[ key ] ) {
61
+ TKeyboardController.status[ key ].pressed = false
62
+ }
63
+ }
64
+ /**
65
+ *
66
+ * @param event
67
+ */
68
+ static onKeyDown( event ) {
69
+ var key = TKeyboardController.keyName( event.keyCode )
70
+ if ( !TKeyboardController.status[ key ] ) {
71
+ TKeyboardController.status[ key ] = {
72
+ down: false,
73
+ pressed: false,
74
+ up: false,
75
+ updatedPreviously: false
76
+ }
77
+ }
78
+ }
79
+ /**
80
+ *
81
+ */
82
+ update() {
83
+ for ( var key in TKeyboardController.status ) {
84
+ // insure that every keypress has "down" status exactly once
85
+ if ( !TKeyboardController.status[ key ].updatedPreviously ) {
86
+ TKeyboardController.status[ key ].down = true
87
+ TKeyboardController.status[ key ].pressed = true
88
+ TKeyboardController.status[ key ].updatedPreviously = true
89
+ } else { // updated previously
90
+ TKeyboardController.status[ key ].down = false
91
+ }
92
+
93
+ // key has been flagged as "up" since last update
94
+ if ( TKeyboardController.status[ key ].up ) {
95
+ delete TKeyboardController.status[ key ]
96
+ continue // move on to next key
97
+ }
98
+
99
+ if ( !TKeyboardController.status[ key ].pressed ) // key released
100
+ {
101
+ TKeyboardController.status[ key ].up = true
102
+ }
103
+ }
104
+ }
105
+
106
+ /**
107
+ *
108
+ * @param keyName
109
+ * @return {*}
110
+ */
111
+ down( keyName ) {
112
+ return ( TKeyboardController.status[ keyName ] && TKeyboardController.status[ keyName ].down )
113
+ }
114
+
115
+ /**
116
+ *
117
+ * @param keyName
118
+ * @return {*|pressed|boolean}
119
+ */
120
+ pressed( keyName ) {
121
+ return ( TKeyboardController.status[ keyName ] && TKeyboardController.status[ keyName ].pressed )
122
+ }
123
+
124
+ /**
125
+ *
126
+ * @param keyName
127
+ * @return {*}
128
+ */
129
+ up( keyName ) {
130
+ return ( TKeyboardController.status[ keyName ] && TKeyboardController.status[ keyName ].up )
131
+ }
132
+
133
+ /**
134
+ *
135
+ */
136
+ debug() {
137
+ var list = 'Keys active: '
138
+ for ( var arg in TKeyboardController.status ) {
139
+ list += ' ' + arg
140
+ }
141
+ TLogger.log( list )
142
+ }
143
+
144
+ }
145
+
146
+ /**
147
+ *
148
+ * @type {Keys}
149
+ */
150
+ TKeyboardController.k = Keys
151
+
152
+ /**
153
+ *
154
+ * @type {{}}
155
+ */
156
+ TKeyboardController.status = {}
157
+
158
+ export { TKeyboardController }
@@ -0,0 +1,31 @@
1
+ /* eslint-env browser */
2
+
3
+ /**
4
+ * @class
5
+ * @classdesc TMouseController allow single source of thruth for mouse state checking
6
+ * @author [Tristan Valcke]{@link https://github.com/Itee}
7
+ * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
8
+ * @example
9
+ * (1) create a global variable:
10
+ * var keyboard = new TKeyboardController();
11
+ * (2) during main loop:
12
+ * keyboard.update();
13
+ * (3) check state of keys:
14
+ * keyboard.down("A") -- true for one update cycle after key is pressed
15
+ * keyboard.pressed("A") -- true as long as key is being pressed
16
+ * keyboard.up("A") -- true for one update cycle after key is released
17
+ *
18
+ * See TKeyboardController.k object data below for names of keys whose state can be polled
19
+ */
20
+ class TMouseController {
21
+
22
+ /**
23
+ * @constructor
24
+ */
25
+ constructor( /*parameters = {}*/ ) {
26
+
27
+ }
28
+
29
+ }
30
+
31
+ export { TMouseController }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module InputDevice
3
+ * @description Intermediary export file for input devices stuff. Export [TKeyboardController]{@link TKeyboardController} and [TMouseController]{@link TMouseController}
4
+ *
5
+ * @author [Tristan Valcke]{@link https://github.com/Itee}
6
+ * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
7
+ */
8
+
9
+ export { TKeyboardController } from './TKeyboardController.js'
10
+ export { TMouseController } from './TMouseController.js'
11
+
@@ -0,0 +1,35 @@
1
+ //import { DefaultBinarySerializer } from './TBinarySerializer'
2
+
3
+ class TBinaryConverter {
4
+
5
+ constructor( targetType, serializer = null ) {
6
+ // constructor ( targetType, serializer = DefaultBinarySerializer ) {
7
+
8
+ this.targetCtor = targetType
9
+ this.serializer = serializer
10
+
11
+ }
12
+
13
+ /**
14
+ *
15
+ * @param {TBinaryWriter} writer
16
+ * @param instance
17
+ * @param options
18
+ */
19
+ to( writer, instance, options = {} ) { }
20
+
21
+ /**
22
+ *
23
+ * @param {TBinaryReader} reader
24
+ * @param options
25
+ * @returns {*}
26
+ */
27
+ from( reader, options = {} ) {
28
+
29
+ return new this.targetCtor()
30
+
31
+ }
32
+
33
+ }
34
+
35
+ export { TBinaryConverter }