@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.
- package/CHANGELOG.md +251 -0
- package/LICENSE.md +23 -0
- package/README.md +76 -0
- package/builds/itee-client.cjs.js +6517 -0
- package/builds/itee-client.cjs.js.map +1 -0
- package/builds/itee-client.cjs.min.js +125 -0
- package/builds/itee-client.esm.js +6468 -0
- package/builds/itee-client.esm.js.map +1 -0
- package/builds/itee-client.esm.min.js +124 -0
- package/builds/itee-client.iife.js +6524 -0
- package/builds/itee-client.iife.js.map +1 -0
- package/builds/itee-client.iife.min.js +125 -0
- package/package.json +87 -0
- package/sources/client.js +14 -0
- package/sources/cores/TAbstractFactory.js +42 -0
- package/sources/cores/TCloningFactory.js +39 -0
- package/sources/cores/TConstants.js +433 -0
- package/sources/cores/TInstancingFactory.js +41 -0
- package/sources/cores/TStore.js +303 -0
- package/sources/cores/_cores.js +13 -0
- package/sources/input_devices/TKeyboardController.js +158 -0
- package/sources/input_devices/TMouseController.js +31 -0
- package/sources/input_devices/_inputDevices.js +11 -0
- package/sources/loaders/TBinaryConverter.js +35 -0
- package/sources/loaders/TBinaryReader.js +1029 -0
- package/sources/loaders/TBinarySerializer.js +258 -0
- package/sources/loaders/TBinaryWriter.js +429 -0
- package/sources/loaders/_loaders.js +21 -0
- package/sources/loaders/converters/ArrayBinaryConverter.js +33 -0
- package/sources/loaders/converters/BooleanBinaryConverter.js +24 -0
- package/sources/loaders/converters/DateBinaryConverter.js +21 -0
- package/sources/loaders/converters/NullBinaryConverter.js +13 -0
- package/sources/loaders/converters/NumberBinaryConverter.js +15 -0
- package/sources/loaders/converters/ObjectBinaryConverter.js +101 -0
- package/sources/loaders/converters/RegExBinaryConverter.js +11 -0
- package/sources/loaders/converters/StringBinaryConverter.js +26 -0
- package/sources/loaders/converters/UndefinedBinaryConverter.js +13 -0
- package/sources/managers/TDataBaseManager.js +1649 -0
- package/sources/managers/_managers.js +10 -0
- package/sources/utils/TIdFactory.js +84 -0
- package/sources/utils/_utils.js +9 -0
- package/sources/webapis/WebAPI.js +773 -0
- package/sources/webapis/WebAPIOrigin.js +141 -0
- package/sources/webapis/_webapis.js +10 -0
- package/sources/webapis/messages/WebAPIMessage.js +75 -0
- package/sources/webapis/messages/WebAPIMessageData.js +51 -0
- package/sources/webapis/messages/WebAPIMessageError.js +79 -0
- package/sources/webapis/messages/WebAPIMessageEvent.js +58 -0
- package/sources/webapis/messages/WebAPIMessageProgress.js +91 -0
- package/sources/webapis/messages/WebAPIMessageReady.js +66 -0
- package/sources/webapis/messages/WebAPIMessageRequest.js +94 -0
- package/sources/webapis/messages/WebAPIMessageResponse.js +80 -0
- package/sources/webapis/messages/_messages.js +16 -0
- package/sources/workers/AbstractWorker.js +149 -0
- package/sources/workers/_workers.js +10 -0
- package/sources/workers/messages/WorkerMessage.js +33 -0
- package/sources/workers/messages/WorkerMessageData.js +30 -0
- package/sources/workers/messages/WorkerMessageError.js +32 -0
- package/sources/workers/messages/WorkerMessageMethodCall.js +60 -0
- package/sources/workers/messages/WorkerMessageProgress.js +67 -0
- package/sources/workers/messages/_messages.js +14 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
3
|
+
* @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
isDefined,
|
|
8
|
+
isEmptyArray,
|
|
9
|
+
isEmptyString,
|
|
10
|
+
isNotArray,
|
|
11
|
+
isNotBoolean,
|
|
12
|
+
isNotDefined,
|
|
13
|
+
isNotString
|
|
14
|
+
} from '@itee/validators'
|
|
15
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
16
|
+
|
|
17
|
+
class WebAPIOrigin {
|
|
18
|
+
|
|
19
|
+
constructor( parameters = {} ) {
|
|
20
|
+
|
|
21
|
+
const _parameters = {
|
|
22
|
+
...{
|
|
23
|
+
uri: '',
|
|
24
|
+
allowedMethods: [ '*' ],
|
|
25
|
+
window: null,
|
|
26
|
+
messageQueue: [],
|
|
27
|
+
isReachable: true,
|
|
28
|
+
isReady: false
|
|
29
|
+
},
|
|
30
|
+
...parameters,
|
|
31
|
+
...{
|
|
32
|
+
id: isDefined( parameters.id ) ? parameters.id : uuidv4()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this._id = _parameters.id
|
|
37
|
+
this.uri = _parameters.uri
|
|
38
|
+
this.allowedMethods = _parameters.allowedMethods // Todo: use Set instead
|
|
39
|
+
this.window = _parameters.window
|
|
40
|
+
this.isReachable = _parameters.isReachable
|
|
41
|
+
this.isReady = _parameters.isReady
|
|
42
|
+
this.messageQueue = _parameters.messageQueue
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
get id() {
|
|
50
|
+
return this._id
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get uri() {
|
|
54
|
+
return this._uri
|
|
55
|
+
}
|
|
56
|
+
set uri( value ) {
|
|
57
|
+
if ( isNotDefined( value ) ) { throw new ReferenceError( 'WebAPIOrigin uri cannot be null or undefined !' )}
|
|
58
|
+
if ( isNotString( value ) ) { throw new TypeError( `WebAPIOrigin uri expect to be a string. Got '${ typeof value }' !` )}
|
|
59
|
+
if ( isEmptyString( value ) ) { throw new RangeError( 'WebAPIOrigin uri cannot be an empty string !' )}
|
|
60
|
+
|
|
61
|
+
this._uri = value
|
|
62
|
+
}
|
|
63
|
+
get allowedMethods() {
|
|
64
|
+
return this._allowedMethods
|
|
65
|
+
}
|
|
66
|
+
set allowedMethods( value ) {
|
|
67
|
+
if ( isNotDefined( value ) ) { throw new ReferenceError( 'WebAPIOrigin methods cannot be null or undefined ! Expect an array of method name.' )}
|
|
68
|
+
if ( isNotArray( value ) ) { throw new TypeError( `WebAPIOrigin methods expect to be an array of method name (string).Got '${ typeof value }' !` )}
|
|
69
|
+
if ( isEmptyArray( value ) ) { throw new RangeError( 'WebAPIOrigin methods cannot be an empty array ! Expect an array of method name.' )}
|
|
70
|
+
|
|
71
|
+
this._allowedMethods = value
|
|
72
|
+
}
|
|
73
|
+
get window() {
|
|
74
|
+
return this._window
|
|
75
|
+
}
|
|
76
|
+
set window( value ) {
|
|
77
|
+
// if ( isNotDefined( value ) ) { throw new ReferenceError( 'WebAPIOrigin window cannot be null or undefined ! Expect a Window object.' )}
|
|
78
|
+
// if ( isDefined( value ) && !( value instanceof Window ) ) { throw new TypeError( `WebAPIOrigin window expect to be a Window. Got '${ typeof value }' !` )}
|
|
79
|
+
|
|
80
|
+
this._window = value
|
|
81
|
+
}
|
|
82
|
+
get isReady() {
|
|
83
|
+
return this._isReady
|
|
84
|
+
}
|
|
85
|
+
set isReady( value ) {
|
|
86
|
+
if ( isNotDefined( value ) ) { throw new ReferenceError( 'WebAPIOrigin isReady cannot be null or undefined !' )}
|
|
87
|
+
if ( isNotBoolean( value ) ) { throw new TypeError( `WebAPIOrigin isReady expect a Boolean. Got '${ typeof value }' !` )}
|
|
88
|
+
|
|
89
|
+
this._isReady = value
|
|
90
|
+
}
|
|
91
|
+
get isReachable() {
|
|
92
|
+
return this._isReachable
|
|
93
|
+
}
|
|
94
|
+
set isReachable( value ) {
|
|
95
|
+
if ( isNotDefined( value ) ) { throw new ReferenceError( 'WebAPIOrigin isReachable cannot be null or undefined !' )}
|
|
96
|
+
if ( isNotBoolean( value ) ) { throw new TypeError( `WebAPIOrigin isReachable expect a Boolean. Got '${ typeof value }' !` )}
|
|
97
|
+
|
|
98
|
+
this._isReachable = value
|
|
99
|
+
}
|
|
100
|
+
get messageQueue() {
|
|
101
|
+
return this._messageQueue
|
|
102
|
+
}
|
|
103
|
+
set messageQueue( value ) {
|
|
104
|
+
this._messageQueue = value
|
|
105
|
+
}
|
|
106
|
+
setUri( value ) {
|
|
107
|
+
this.uri = value
|
|
108
|
+
return this
|
|
109
|
+
}
|
|
110
|
+
setAllowedMethods( arrayOfMethodNames ) {
|
|
111
|
+
this.allowedMethods = arrayOfMethodNames
|
|
112
|
+
return this
|
|
113
|
+
}
|
|
114
|
+
addAllowedMethod( methodName ) {
|
|
115
|
+
if ( !this.allowedMethods.includes( methodName ) ) {
|
|
116
|
+
this.allowedMethods.push( methodName )
|
|
117
|
+
}
|
|
118
|
+
return this
|
|
119
|
+
}
|
|
120
|
+
removeAllowedMethod( methodName ) {
|
|
121
|
+
const index = this.allowedMethods.indexOf( methodName )
|
|
122
|
+
if ( index >= 0 ) {
|
|
123
|
+
this.allowedMethods.slice( index, methodName )
|
|
124
|
+
}
|
|
125
|
+
return this
|
|
126
|
+
}
|
|
127
|
+
setWindow( value ) {
|
|
128
|
+
this.window = value
|
|
129
|
+
return this
|
|
130
|
+
}
|
|
131
|
+
setReadyState( value ) {
|
|
132
|
+
this.isReady = value
|
|
133
|
+
return this
|
|
134
|
+
}
|
|
135
|
+
setReachableState( value ) {
|
|
136
|
+
this.isReachable = value
|
|
137
|
+
return this
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { WebAPIOrigin }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module WebAPI
|
|
3
|
+
* @description Intermediary export file for webapi. Export [AbstractWebAPI]{@link AbstractWebAPI} and all web api messages from [WebAPIMessages]{@link module:WebAPI/Messages}.
|
|
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 './WebAPI.js'
|
|
10
|
+
export * from './messages/_messages.js'
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
isEmptyString,
|
|
7
|
+
isNotString
|
|
8
|
+
} from '@itee/validators'
|
|
9
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} WebAPIMessageSerialized
|
|
13
|
+
* @property {string} id
|
|
14
|
+
* @property {string} type
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @class
|
|
19
|
+
* @classdesc The base class for all web api message
|
|
20
|
+
*/
|
|
21
|
+
class WebAPIMessage {
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @static
|
|
25
|
+
* @type {boolean}
|
|
26
|
+
*/
|
|
27
|
+
static isWebAPIMessage = true
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {string} type
|
|
32
|
+
*/
|
|
33
|
+
constructor( type ) {
|
|
34
|
+
this._id = uuidv4()
|
|
35
|
+
this.type = type
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
get id() {
|
|
42
|
+
return this._id
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
get type() {
|
|
50
|
+
return this._type
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
set type( value ) {
|
|
54
|
+
if ( isNotString( value ) ) { throw new ReferenceError( 'WebAPIMessage type cannot be null or undefined !' )}
|
|
55
|
+
if ( isEmptyString( value ) ) { throw new TypeError( 'WebAPIMessage type cannot be an empty string !' )}
|
|
56
|
+
|
|
57
|
+
this._type = value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* @returns {{id: String, type: String}}
|
|
63
|
+
*/
|
|
64
|
+
toJSON() {
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
id: this.id,
|
|
68
|
+
type: this.type
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { WebAPIMessage }
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { WebAPIMessage } from './WebAPIMessage.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Object} WebAPIMessageDataSerialized
|
|
5
|
+
* @property {object} data
|
|
6
|
+
* @instance
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class
|
|
11
|
+
* @classdesc The web api message for serializable data transfert
|
|
12
|
+
* @extends WebAPIMessage
|
|
13
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
14
|
+
*/
|
|
15
|
+
class WebAPIMessageData extends WebAPIMessage {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @static
|
|
19
|
+
* @type {boolean}
|
|
20
|
+
*/
|
|
21
|
+
static isWebAPIMessageData = true
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param data
|
|
26
|
+
*/
|
|
27
|
+
constructor( data ) {
|
|
28
|
+
super( '_data' )
|
|
29
|
+
|
|
30
|
+
this.data = data
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @returns {{id: String, type: String, data: String}}
|
|
36
|
+
*/
|
|
37
|
+
toJSON() {
|
|
38
|
+
|
|
39
|
+
const isPlainObject = this.data === Object( this.data )
|
|
40
|
+
return {
|
|
41
|
+
...super.toJSON(),
|
|
42
|
+
...{
|
|
43
|
+
data: isPlainObject ? JSON.stringify( this.data ) : this.data
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { WebAPIMessageData }
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
isDefined,
|
|
7
|
+
isNotDefined,
|
|
8
|
+
isObject,
|
|
9
|
+
isString
|
|
10
|
+
} from '@itee/validators'
|
|
11
|
+
import { WebAPIMessage } from './WebAPIMessage.js'
|
|
12
|
+
|
|
13
|
+
class WebAPIMessageError extends WebAPIMessage {
|
|
14
|
+
|
|
15
|
+
static isWebAPIMessageError = true
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param error
|
|
19
|
+
*/
|
|
20
|
+
constructor( error ) {
|
|
21
|
+
super( '_error' )
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The internal error to send
|
|
25
|
+
* @type {{stack: string, name: string, message: string}}
|
|
26
|
+
*/
|
|
27
|
+
this.error = error
|
|
28
|
+
}
|
|
29
|
+
get error() {
|
|
30
|
+
return this._error
|
|
31
|
+
}
|
|
32
|
+
set error( value ) {
|
|
33
|
+
if ( isNotDefined( value ) ) { throw new ReferenceError( `Expect a string, or Error like. But got value of '${ typeof value }' type: ${ JSON.stringify( value, null, 4 ) }` ) }
|
|
34
|
+
|
|
35
|
+
if ( isString( value ) ) {
|
|
36
|
+
|
|
37
|
+
this._error = {
|
|
38
|
+
name: 'UnknownError',
|
|
39
|
+
message: value
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
} else if ( WebAPIMessageError.isError( value ) ) {
|
|
43
|
+
|
|
44
|
+
this._error = {
|
|
45
|
+
name: value.name,
|
|
46
|
+
message: value.message,
|
|
47
|
+
stack: value.stack
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
} else {
|
|
51
|
+
|
|
52
|
+
throw new TypeError( `Expect a string, or Error like. But got value of '${ typeof value }' type: ${ JSON.stringify( value, null, 4 ) }` )
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
// Utils
|
|
58
|
+
static isError( value ) {
|
|
59
|
+
return value instanceof Error || isObject( value ) && ( isDefined( value.name ) || isDefined( value.message ) || isDefined( value.stack ) )
|
|
60
|
+
}
|
|
61
|
+
// Serialization
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @returns {{id: String, type: String, name: String, stack: String, message: String}}
|
|
65
|
+
*/
|
|
66
|
+
toJSON() {
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
...super.toJSON(),
|
|
70
|
+
...{
|
|
71
|
+
error: this.error
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { WebAPIMessageError }
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
3
|
+
* @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { WebAPIMessage } from './WebAPIMessage.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Object} WebAPIMessageDataSerialized
|
|
10
|
+
* @property {object} data
|
|
11
|
+
* @instance
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @class
|
|
16
|
+
* @classdesc The web api message for serializable data transfert
|
|
17
|
+
* @extends WebAPIMessage
|
|
18
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
19
|
+
*/
|
|
20
|
+
class WebAPIMessageEvent extends WebAPIMessage {
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @static
|
|
24
|
+
* @type {boolean}
|
|
25
|
+
*/
|
|
26
|
+
static isWebAPIMessageEvent = true
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param data
|
|
31
|
+
*/
|
|
32
|
+
constructor( name, data ) {
|
|
33
|
+
super( '_event' )
|
|
34
|
+
|
|
35
|
+
this.name = name
|
|
36
|
+
this.data = data
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @returns {{id: String, type: String, data: String}}
|
|
42
|
+
*/
|
|
43
|
+
toJSON() {
|
|
44
|
+
|
|
45
|
+
const isPlainObject = this.data === Object( this.data )
|
|
46
|
+
return {
|
|
47
|
+
...super.toJSON(),
|
|
48
|
+
...{
|
|
49
|
+
name: this.name,
|
|
50
|
+
data: isPlainObject ? JSON.stringify( this.data ) : this.data
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { WebAPIMessageEvent }
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { WebAPIMessage } from './WebAPIMessage.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
class WebAPIMessageProgress extends WebAPIMessage {
|
|
11
|
+
|
|
12
|
+
static isWebAPIMessageProgress = true
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param loaded
|
|
17
|
+
* @param total
|
|
18
|
+
*/
|
|
19
|
+
constructor( loaded = 0, total = 0 ) {
|
|
20
|
+
super( '_progress' )
|
|
21
|
+
|
|
22
|
+
this.lengthComputable = false
|
|
23
|
+
this.loaded = loaded
|
|
24
|
+
this.total = total
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @returns {*}
|
|
30
|
+
*/
|
|
31
|
+
get loaded() {
|
|
32
|
+
return this._loaded
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set loaded( value ) {
|
|
36
|
+
this._loaded = value
|
|
37
|
+
this._checkIfLengthComputable()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @returns {*}
|
|
43
|
+
*/
|
|
44
|
+
get total() {
|
|
45
|
+
return this._total
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set total( value ) {
|
|
49
|
+
this._total = value
|
|
50
|
+
this._checkIfLengthComputable()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
_checkIfLengthComputable() {
|
|
58
|
+
|
|
59
|
+
this.lengthComputable = false
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
this._total > 0 &&
|
|
63
|
+
this._total < Number.MAX_SAFE_INTEGER &&
|
|
64
|
+
this._loaded >= 0 &&
|
|
65
|
+
this._loaded < Number.MAX_SAFE_INTEGER
|
|
66
|
+
) {
|
|
67
|
+
this.lengthComputable = true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @returns {{loaded: *, lengthComputable: boolean, total: *}}
|
|
75
|
+
*/
|
|
76
|
+
toJSON() {
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
...super.toJSON(),
|
|
80
|
+
...{
|
|
81
|
+
lengthComputable: this.lengthComputable,
|
|
82
|
+
loaded: this.loaded,
|
|
83
|
+
total: this.total
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { WebAPIMessageProgress }
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
isNotBoolean,
|
|
7
|
+
isNotDefined
|
|
8
|
+
} from '@itee/validators'
|
|
9
|
+
import { WebAPIMessage } from './WebAPIMessage.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @class
|
|
13
|
+
* @classdesc Internal ready message to broadcast for prevent bad or dead messager
|
|
14
|
+
*/
|
|
15
|
+
class WebAPIMessageReady extends WebAPIMessage {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @static
|
|
19
|
+
* @type {boolean}
|
|
20
|
+
*/
|
|
21
|
+
static isWebAPIMessageReady = true
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
constructor( parameters = {} ) {
|
|
27
|
+
super( '_ready' )
|
|
28
|
+
|
|
29
|
+
const _parameters = {
|
|
30
|
+
...{
|
|
31
|
+
isBind: false
|
|
32
|
+
},
|
|
33
|
+
...parameters
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.isBind = _parameters.isBind
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get isBind() {
|
|
40
|
+
return this._isBind
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set isBind( value ) {
|
|
44
|
+
if ( isNotDefined( value ) ) { throw new ReferenceError( 'WebAPIMessageReady isBind cannot be null or undefined ! Expect a boolean value.' )}
|
|
45
|
+
if ( isNotBoolean( value ) ) { throw new TypeError( 'WebAPIMessageReady isBind expect a boolean value.' )}
|
|
46
|
+
|
|
47
|
+
this._isBind = value
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @returns {{id: String, type: String, isBind: Boolean}}
|
|
53
|
+
*/
|
|
54
|
+
toJSON() {
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...super.toJSON(),
|
|
58
|
+
...{
|
|
59
|
+
isBind: this.isBind
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { WebAPIMessageReady }
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
isBlankString,
|
|
7
|
+
isEmptyString,
|
|
8
|
+
isNotArray,
|
|
9
|
+
isNotDefined,
|
|
10
|
+
isNotString
|
|
11
|
+
} from '@itee/validators'
|
|
12
|
+
import { WebAPIMessage } from './WebAPIMessage.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @class
|
|
16
|
+
* @classdesc Special message to request a distant method and expect result.
|
|
17
|
+
*/
|
|
18
|
+
class WebAPIMessageRequest extends WebAPIMessage {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @static
|
|
22
|
+
* @type {boolean}
|
|
23
|
+
*/
|
|
24
|
+
static isWebAPIMessageRequest = true
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param method
|
|
29
|
+
* @param parameters
|
|
30
|
+
*/
|
|
31
|
+
constructor( method, parameters = [] ) {
|
|
32
|
+
super( '_request' )
|
|
33
|
+
|
|
34
|
+
this.method = method
|
|
35
|
+
this.parameters = parameters
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @returns {String}
|
|
41
|
+
*/
|
|
42
|
+
get method() {
|
|
43
|
+
return this._method
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @param value {String}
|
|
49
|
+
*/
|
|
50
|
+
set method( value ) {
|
|
51
|
+
if ( isNotDefined( value ) ) { throw new ReferenceError( 'Expect a string that represent a api method name, but got undefined or null value.' ) }
|
|
52
|
+
if ( isNotString( value ) ) { throw new TypeError( `Expect a string that represent a api method name, but got value of '${ typeof value }' type: ${ JSON.stringify( value, null, 4 ) }` ) }
|
|
53
|
+
if ( isEmptyString( value ) || isBlankString( value ) ) { throw new TypeError( 'Expect a string that represent a api method name, but got empty or blank string.' ) }
|
|
54
|
+
|
|
55
|
+
this._method = value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @returns {Array<*>}
|
|
61
|
+
*/
|
|
62
|
+
get parameters() {
|
|
63
|
+
return this._parameters
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param value {Array<*>}
|
|
69
|
+
*/
|
|
70
|
+
set parameters( value ) {
|
|
71
|
+
if ( isNotArray( value ) ) { throw new TypeError( `Expect an array of parameters, but got value of '${ typeof value }' type: ${ JSON.stringify( value, null, 4 ) }` ) }
|
|
72
|
+
|
|
73
|
+
this._parameters = value
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @returns {{method: String, parameters: Array<*>}}
|
|
79
|
+
*/
|
|
80
|
+
toJSON() {
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
...super.toJSON(),
|
|
84
|
+
...{
|
|
85
|
+
method: this.method,
|
|
86
|
+
parameters: this.parameters
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { WebAPIMessageRequest }
|