@qooxdoo/framework 7.0.0-beta.3 → 7.0.0-beta.7
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 +3 -0
- package/Manifest.json +1 -1
- package/README.md +9 -3
- package/lib/compiler/compile-info.json +60 -58
- package/lib/compiler/index.js +3242 -1883
- package/lib/resource/qx/tool/cli/templates/skeleton/mobile/source/theme/custom/css/custom.css.map +1 -1
- package/lib/resource/qx/tool/loadsass.js +6 -4
- package/lib/resource/qx/tool/schema/compile-1-0-0.json +6 -11
- package/package.json +17 -3
- package/source/class/qx/Bootstrap.js +22 -1
- package/source/class/qx/bom/Blocker.js +2 -1
- package/source/class/qx/core/Environment.js +3 -12
- package/source/class/qx/core/MProperty.js +1 -1
- package/source/class/qx/dev/unit/Sinon.js +1 -1
- package/source/class/qx/io/__init__.js +5 -3
- package/source/class/qx/io/exception/Cancel.js +34 -0
- package/source/class/qx/io/exception/Exception.js +38 -0
- package/source/class/qx/io/exception/Protocol.js +26 -0
- package/source/class/qx/io/exception/Transport.js +39 -0
- package/source/class/qx/io/exception/__init__.js +4 -0
- package/source/class/qx/io/graphql/Client.js +112 -0
- package/source/class/qx/io/graphql/__init__.js +9 -0
- package/source/class/qx/io/graphql/protocol/Message.js +65 -0
- package/source/class/qx/io/graphql/protocol/Request.js +95 -0
- package/source/class/qx/io/graphql/protocol/Response.js +61 -0
- package/source/class/qx/io/graphql/protocol/__init__.js +6 -0
- package/source/class/qx/io/jsonrpc/Client.js +323 -0
- package/source/class/qx/io/jsonrpc/__init__.js +15 -0
- package/source/class/qx/io/jsonrpc/protocol/Batch.js +97 -0
- package/source/class/qx/io/jsonrpc/protocol/Error.js +63 -0
- package/source/class/qx/io/jsonrpc/protocol/Message.js +48 -0
- package/source/class/qx/io/jsonrpc/protocol/Notification.js +45 -0
- package/source/class/qx/io/jsonrpc/protocol/Parser.js +81 -0
- package/source/class/qx/io/jsonrpc/protocol/Request.js +93 -0
- package/source/class/qx/io/jsonrpc/protocol/Result.js +48 -0
- package/source/class/qx/io/jsonrpc/protocol/__init__.js +5 -0
- package/source/class/qx/io/request/authentication/Bearer.js +52 -0
- package/source/class/qx/io/transport/AbstractClient.js +100 -0
- package/source/class/qx/io/transport/AbstractTransport.js +41 -0
- package/source/class/qx/io/transport/Fetch.js +95 -0
- package/source/class/qx/io/transport/ITransport.js +40 -0
- package/source/class/qx/io/transport/PostMessage.js +55 -0
- package/source/class/qx/io/transport/Websocket.js +97 -0
- package/source/class/qx/io/transport/Xhr.js +139 -0
- package/source/class/qx/io/transport/__init__.js +18 -0
- package/source/class/qx/test/core/Assert.js +1 -1
- package/source/class/qx/test/core/Environment.js +0 -3
- package/source/class/qx/test/io/MAssert.js +46 -0
- package/source/class/qx/test/io/graphql/Client.js +169 -0
- package/source/class/qx/test/io/graphql/ClientFetch.js +34 -0
- package/source/class/qx/test/io/graphql/Request.js +42 -0
- package/source/class/qx/test/io/jsonrpc/Client.js +267 -0
- package/source/class/qx/test/io/jsonrpc/Protocol.js +80 -0
- package/source/class/qx/test/io/transport/PostMessage.js +56 -0
- package/source/class/qx/test/io/transport/Websocket.js +63 -0
- package/source/class/qx/test/ui/embed/Iframe.js +1 -1
- package/source/class/qx/test/util/DateFormat.js +45 -6
- package/source/class/qx/tool/cli/Cli.js +1 -0
- package/source/class/qx/tool/cli/commands/Compile.js +13 -3
- package/source/class/qx/tool/cli/commands/Es6ify.js +93 -0
- package/source/class/qx/tool/cli/commands/package/Install.js +1 -1
- package/source/class/qx/tool/cli/commands/package/Publish.js +14 -0
- package/source/class/qx/tool/compiler/ClassFile.js +67 -27
- package/source/class/qx/tool/compiler/Es6ify.js +368 -0
- package/source/class/qx/tool/compiler/makers/AppMaker.js +2 -1
- package/source/class/qx/tool/compiler/targets/Target.js +57 -47
- package/source/class/qx/tool/compiler/targets/meta/AbstractJavascriptMeta.js +25 -18
- package/source/class/qx/tool/compiler/targets/meta/BootJs.js +16 -16
- package/source/class/qx/tool/compiler/targets/meta/PolyfillJs.js +11 -3
- package/source/class/qx/tool/compiler/targets/meta/Uglify.js +10 -10
- package/source/class/qx/ui/core/Widget.js +70 -0
- package/source/class/qx/ui/decoration/MLinearBackgroundGradient.js +2 -1
- package/source/class/qx/ui/form/ComboBox.js +8 -3
- package/source/class/qx/ui/form/DateField.js +16 -1
- package/source/class/qx/ui/form/MenuButton.js +8 -4
- package/source/class/qx/ui/form/SelectBox.js +8 -3
- package/source/class/qx/ui/menu/AbstractButton.js +12 -8
- package/source/class/qx/ui/menu/Menu.js +18 -8
- package/source/class/qx/ui/table/pane/Model.js +10 -4
- package/source/class/qx/ui/window/Window.js +8 -0
- package/source/class/qx/util/format/DateFormat.js +44 -17
- package/source/resource/qx/tool/loadsass.js +6 -4
- package/source/resource/qx/tool/schema/compile-1-0-0.json +6 -11
- package/source/translation/hr.po +297 -0
- package/lib/resource/qx/static/blank.gif +0 -0
- package/source/class/qx/io/remote/Exchange.js +0 -1063
- package/source/class/qx/io/remote/Request.js +0 -1021
- package/source/class/qx/io/remote/RequestQueue.js +0 -521
- package/source/class/qx/io/remote/Response.js +0 -137
- package/source/class/qx/io/remote/Rpc.js +0 -1075
- package/source/class/qx/io/remote/RpcError.js +0 -198
- package/source/class/qx/io/remote/__init__.js +0 -88
- package/source/class/qx/io/remote/transport/Abstract.js +0 -513
- package/source/class/qx/io/remote/transport/Iframe.js +0 -652
- package/source/class/qx/io/remote/transport/Script.js +0 -475
- package/source/class/qx/io/remote/transport/XmlHttp.js +0 -1019
- package/source/class/qx/io/remote/transport/__init__.js +0 -3
- package/source/class/qx/test/io/remote/AbstractRequest.js +0 -150
- package/source/class/qx/test/io/remote/RequestIframe.js +0 -105
- package/source/class/qx/test/io/remote/RequestXhr.js +0 -151
- package/source/class/qx/test/io/remote/Rpc.js +0 -205
- package/source/class/qx/test/io/remote/__init__.js +0 -4
- package/source/class/qx/test/io/remote/transport/Iframe.js +0 -67
- package/source/class/qx/test/io/remote/transport/XmlHttp.js +0 -133
- package/source/class/qx/test/io/remote/transport/__init__.js +0 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* ************************************************************************
|
|
2
|
+
|
|
3
|
+
qooxdoo - the new era of web development
|
|
4
|
+
|
|
5
|
+
http://qooxdoo.org
|
|
6
|
+
|
|
7
|
+
Copyright:
|
|
8
|
+
2020 Christian Boulanger
|
|
9
|
+
|
|
10
|
+
License:
|
|
11
|
+
MIT: https://opensource.org/licenses/MIT
|
|
12
|
+
See the LICENSE file in the project's top-level directory for details.
|
|
13
|
+
|
|
14
|
+
Authors:
|
|
15
|
+
* Christian Boulanger (cboulanger)
|
|
16
|
+
|
|
17
|
+
************************************************************************ */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The base class for all JSON-RPC v2.0 object except {@link qx.io.jsonrpc.protocol.Batch}
|
|
21
|
+
*/
|
|
22
|
+
qx.Class.define("qx.io.jsonrpc.protocol.Message",{
|
|
23
|
+
extend: qx.core.Object,
|
|
24
|
+
properties: {
|
|
25
|
+
jsonrpc : {
|
|
26
|
+
check: "String",
|
|
27
|
+
init: "2.0"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
members : {
|
|
32
|
+
/**
|
|
33
|
+
* Serialize to JSON string
|
|
34
|
+
* @return {String}
|
|
35
|
+
*/
|
|
36
|
+
toString() {
|
|
37
|
+
return qx.util.Serializer.toJson(this);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Serialize to a native javascript object
|
|
42
|
+
* @return {Object}
|
|
43
|
+
*/
|
|
44
|
+
toObject() {
|
|
45
|
+
return qx.util.Serializer.toNativeObject(this);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* ************************************************************************
|
|
2
|
+
|
|
3
|
+
qooxdoo - the new era of web development
|
|
4
|
+
|
|
5
|
+
http://qooxdoo.org
|
|
6
|
+
|
|
7
|
+
Copyright:
|
|
8
|
+
2020 Christian Boulanger
|
|
9
|
+
|
|
10
|
+
License:
|
|
11
|
+
MIT: https://opensource.org/licenses/MIT
|
|
12
|
+
See the LICENSE file in the project's top-level directory for details.
|
|
13
|
+
|
|
14
|
+
Authors:
|
|
15
|
+
* Christian Boulanger (cboulanger)
|
|
16
|
+
|
|
17
|
+
************************************************************************ */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A JSON-RPC v2.0 notification object
|
|
21
|
+
* @see https://www.jsonrpc.org/specification#request_object
|
|
22
|
+
*/
|
|
23
|
+
qx.Class.define("qx.io.jsonrpc.protocol.Notification",{
|
|
24
|
+
extend: qx.io.jsonrpc.protocol.Message,
|
|
25
|
+
properties: {
|
|
26
|
+
method : {
|
|
27
|
+
check: "String",
|
|
28
|
+
nullable: false
|
|
29
|
+
},
|
|
30
|
+
params : {
|
|
31
|
+
check: "Object",
|
|
32
|
+
nullable: true,
|
|
33
|
+
init: null
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Notification constructor
|
|
38
|
+
* @param {String} method
|
|
39
|
+
* @param {Object?} params
|
|
40
|
+
*/
|
|
41
|
+
construct(method, params=null) {
|
|
42
|
+
this.base(arguments);
|
|
43
|
+
this.set({method, params});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* ************************************************************************
|
|
2
|
+
|
|
3
|
+
qooxdoo - the new era of web development
|
|
4
|
+
|
|
5
|
+
http://qooxdoo.org
|
|
6
|
+
|
|
7
|
+
Copyright:
|
|
8
|
+
2020 Christian Boulanger
|
|
9
|
+
|
|
10
|
+
License:
|
|
11
|
+
MIT: https://opensource.org/licenses/MIT
|
|
12
|
+
See the LICENSE file in the project's top-level directory for details.
|
|
13
|
+
|
|
14
|
+
Authors:
|
|
15
|
+
* Christian Boulanger (cboulanger)
|
|
16
|
+
|
|
17
|
+
************************************************************************ */
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The parser object has a parse() method, which takes a UTF-encoded string and
|
|
22
|
+
* returns an instance of the correponding subclass of {@link qx.io.jsonrpc.protocol.Message} or
|
|
23
|
+
* a {@link qx.io.jsonrpc.protocol.Batch} instance.
|
|
24
|
+
*/
|
|
25
|
+
qx.Class.define("qx.io.jsonrpc.protocol.Parser", {
|
|
26
|
+
extend: qx.core.Object,
|
|
27
|
+
members: {
|
|
28
|
+
/**
|
|
29
|
+
* Given an UTF-8 encoded string, return the corresponding message object,
|
|
30
|
+
* which is one of {@link qx.io.jsonrpc.protocol.Batch}, {@link qx.io.jsonrpc.protocol.Notification},
|
|
31
|
+
* {@link qx.io.jsonrpc.protocol.Request}, {@link qx.io.jsonrpc.protocol.Result}, or
|
|
32
|
+
* {@link qx.io.jsonrpc.protocol.Error}.
|
|
33
|
+
*
|
|
34
|
+
* @param {String} message
|
|
35
|
+
* @return {qx.io.jsonrpc.protocol.Message}
|
|
36
|
+
* @throws {qx.io.exception.Transport}
|
|
37
|
+
*/
|
|
38
|
+
parse(message) {
|
|
39
|
+
try {
|
|
40
|
+
message = JSON.parse(message);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
throw new qx.io.exception.Transport(
|
|
43
|
+
e.toString(),
|
|
44
|
+
qx.io.exception.Transport.INVALID_JSON,
|
|
45
|
+
{message}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (message === null) {
|
|
49
|
+
throw new qx.io.exception.Transport(
|
|
50
|
+
"No data",
|
|
51
|
+
qx.io.exception.Transport.NO_DATA
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
// batch
|
|
55
|
+
if (qx.lang.Type.isArray(message)) {
|
|
56
|
+
const batch = new qx.io.jsonrpc.protocol.Batch();
|
|
57
|
+
message.forEach(item => batch.add(this.parse(JSON.stringify(item))));
|
|
58
|
+
return batch;
|
|
59
|
+
}
|
|
60
|
+
// individual message
|
|
61
|
+
let {id, result, method, params, error} = message;
|
|
62
|
+
if (id !== undefined && result !== undefined && error === undefined && method === undefined) {
|
|
63
|
+
return new qx.io.jsonrpc.protocol.Result(id, result);
|
|
64
|
+
}
|
|
65
|
+
if (id !== undefined && result === undefined && error !== undefined && method === undefined) {
|
|
66
|
+
return new qx.io.jsonrpc.protocol.Error(id, error.code, error.message, error.data);
|
|
67
|
+
}
|
|
68
|
+
if (id !== undefined && result === undefined && error === undefined && method !== undefined) {
|
|
69
|
+
return new qx.io.jsonrpc.protocol.Request(method, params, id);
|
|
70
|
+
}
|
|
71
|
+
if (id === undefined && result === undefined && error === undefined && method !== undefined) {
|
|
72
|
+
return new qx.io.jsonrpc.protocol.Notification(method, params);
|
|
73
|
+
}
|
|
74
|
+
throw new qx.io.exception.Transport(
|
|
75
|
+
"Cannot parse message data.",
|
|
76
|
+
qx.io.exception.Transport.INVALID_MSG_DATA,
|
|
77
|
+
{message}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* ************************************************************************
|
|
2
|
+
|
|
3
|
+
qooxdoo - the new era of web development
|
|
4
|
+
|
|
5
|
+
http://qooxdoo.org
|
|
6
|
+
|
|
7
|
+
Copyright:
|
|
8
|
+
2020 Christian Boulanger
|
|
9
|
+
|
|
10
|
+
License:
|
|
11
|
+
MIT: https://opensource.org/licenses/MIT
|
|
12
|
+
See the LICENSE file in the project's top-level directory for details.
|
|
13
|
+
|
|
14
|
+
Authors:
|
|
15
|
+
* Christian Boulanger (cboulanger)
|
|
16
|
+
|
|
17
|
+
************************************************************************ */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A JSON-RPC v2.0 request object
|
|
21
|
+
*
|
|
22
|
+
* @see https://www.jsonrpc.org/specification#request_object
|
|
23
|
+
*/
|
|
24
|
+
qx.Class.define("qx.io.jsonrpc.protocol.Request", {
|
|
25
|
+
extend: qx.io.jsonrpc.protocol.Notification,
|
|
26
|
+
statics: {
|
|
27
|
+
/**
|
|
28
|
+
* Static counter for all request ids
|
|
29
|
+
*/
|
|
30
|
+
__current_request_id : 0,
|
|
31
|
+
|
|
32
|
+
getCurrentId() {
|
|
33
|
+
return qx.io.jsonrpc.protocol.Request.__current_request_id;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
resetId() {
|
|
37
|
+
qx.io.jsonrpc.protocol.Request.__current_request_id = 0;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
properties: {
|
|
41
|
+
/**
|
|
42
|
+
* The integer id of the request
|
|
43
|
+
*/
|
|
44
|
+
id : {
|
|
45
|
+
check: value => qx.lang.Type.isNumber(value) && parseInt(value, 10) === value
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* JSON-RPC request constructor
|
|
51
|
+
* @param {String} method
|
|
52
|
+
* @param {Array|Object?} params
|
|
53
|
+
* @param {Number?} id
|
|
54
|
+
* Optional integer id. If not provided, an auto-incremented id will be
|
|
55
|
+
* used.
|
|
56
|
+
*/
|
|
57
|
+
construct(method, params, id) {
|
|
58
|
+
this.base(arguments, method, params);
|
|
59
|
+
if (id === undefined) {
|
|
60
|
+
id = ++qx.io.jsonrpc.protocol.Request.__current_request_id;
|
|
61
|
+
}
|
|
62
|
+
this.set({id});
|
|
63
|
+
this.__promise = new qx.Promise();
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
members: {
|
|
67
|
+
|
|
68
|
+
__promise : null,
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Getter for promise which resolves with the result to the request
|
|
72
|
+
* @return {qx.Promise}
|
|
73
|
+
*/
|
|
74
|
+
getPromise() {
|
|
75
|
+
return this.__promise;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Determines how an exception during transport is handled. Standard
|
|
80
|
+
* behavior is to reject the request's promise with that exception.
|
|
81
|
+
* Classes inheriting from this class might handle it differently, i.e.
|
|
82
|
+
* by allowing the transport to retry after a timeout occurred.
|
|
83
|
+
* @param {qx.io.exception.Transport} exception
|
|
84
|
+
*/
|
|
85
|
+
handleTransportException(exception) {
|
|
86
|
+
try {
|
|
87
|
+
this.getPromise().reject(exception);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
this.warn("Promise has already been rejected");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* ************************************************************************
|
|
2
|
+
|
|
3
|
+
qooxdoo - the new era of web development
|
|
4
|
+
|
|
5
|
+
http://qooxdoo.org
|
|
6
|
+
|
|
7
|
+
Copyright:
|
|
8
|
+
2020 Christian Boulanger
|
|
9
|
+
|
|
10
|
+
License:
|
|
11
|
+
MIT: https://opensource.org/licenses/MIT
|
|
12
|
+
See the LICENSE file in the project's top-level directory for details.
|
|
13
|
+
|
|
14
|
+
Authors:
|
|
15
|
+
* Christian Boulanger (cboulanger)
|
|
16
|
+
|
|
17
|
+
************************************************************************ */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A JSON-RPC v2.0 result object, which is a response to a {@link qx.io.jsonrpc.protocol.Request},
|
|
21
|
+
* indicating a successfully processed request.
|
|
22
|
+
*
|
|
23
|
+
* @see https://www.jsonrpc.org/specification#response_object
|
|
24
|
+
*/
|
|
25
|
+
qx.Class.define("qx.io.jsonrpc.protocol.Result",{
|
|
26
|
+
extend: qx.io.jsonrpc.protocol.Message,
|
|
27
|
+
properties: {
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The integer id of the request
|
|
31
|
+
*/
|
|
32
|
+
id : {
|
|
33
|
+
check: value => qx.lang.Type.isNumber(value) && parseInt(value, 10) === value
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
result : {
|
|
37
|
+
nullable: true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* The result messsage constructor
|
|
42
|
+
* @param {Number} id^
|
|
43
|
+
* @param {*} result
|
|
44
|
+
*/
|
|
45
|
+
construct(id, result) {
|
|
46
|
+
this.set({id, result})
|
|
47
|
+
}
|
|
48
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* ************************************************************************
|
|
2
|
+
|
|
3
|
+
qooxdoo - the new era of web development
|
|
4
|
+
|
|
5
|
+
http://qooxdoo.org
|
|
6
|
+
|
|
7
|
+
Copyright:
|
|
8
|
+
2004-2011 1&1 Internet AG, Germany, http://www.1und1.de
|
|
9
|
+
|
|
10
|
+
License:
|
|
11
|
+
MIT: https://opensource.org/licenses/MIT
|
|
12
|
+
See the LICENSE file in the project's top-level directory for details.
|
|
13
|
+
|
|
14
|
+
Authors:
|
|
15
|
+
* Tristan Koch (tristankoch)
|
|
16
|
+
* Christian Boulanger (cboulanger)
|
|
17
|
+
|
|
18
|
+
************************************************************************ */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Bearer (token) authentication.
|
|
22
|
+
*/
|
|
23
|
+
qx.Class.define("qx.io.request.authentication.Bearer",
|
|
24
|
+
{
|
|
25
|
+
|
|
26
|
+
extend: qx.core.Object,
|
|
27
|
+
|
|
28
|
+
implement: qx.io.request.authentication.IAuthentication,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param token {string} The token to use.
|
|
32
|
+
*/
|
|
33
|
+
construct : function(token)
|
|
34
|
+
{
|
|
35
|
+
this.__credentials = token;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
members :
|
|
39
|
+
{
|
|
40
|
+
__credentials : null,
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Headers to include for bearer (token) authentication.
|
|
44
|
+
* @return {Map} Map containing the authentication credentials
|
|
45
|
+
*/
|
|
46
|
+
getAuthHeaders: function() {
|
|
47
|
+
return [
|
|
48
|
+
{key: "Authorization", value: "Bearer " + this.__credentials}
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* ************************************************************************
|
|
2
|
+
|
|
3
|
+
qooxdoo - the new era of web development
|
|
4
|
+
|
|
5
|
+
http://qooxdoo.org
|
|
6
|
+
|
|
7
|
+
Copyright:
|
|
8
|
+
2020 Christian Boulanger
|
|
9
|
+
|
|
10
|
+
License:
|
|
11
|
+
MIT: https://opensource.org/licenses/MIT
|
|
12
|
+
See the LICENSE file in the project's top-level directory for details.
|
|
13
|
+
|
|
14
|
+
Authors:
|
|
15
|
+
* Christian Boulanger (cboulanger)
|
|
16
|
+
|
|
17
|
+
************************************************************************ */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This class provides a the base class for all clients that use the
|
|
21
|
+
* transport implementations in this namespace. Since the static method
|
|
22
|
+
* `registerTransport` cannot be inherited by subclasses, they mus proxy it
|
|
23
|
+
* by adding `registerTransport : qx.io.transport.AbstractClient.registerTransport`
|
|
24
|
+
* to their `statics` section.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
qx.Class.define("qx.io.transport.AbstractClient", {
|
|
28
|
+
extend: qx.core.Object,
|
|
29
|
+
type: "abstract",
|
|
30
|
+
|
|
31
|
+
statics: {
|
|
32
|
+
/**
|
|
33
|
+
* Register a transport class for use with uris that match the given
|
|
34
|
+
* regular expression. The client will use the transport which first
|
|
35
|
+
* matches, starting with the last added transport
|
|
36
|
+
* @param {RegExp} uriRegExp
|
|
37
|
+
* A regular expression which the URI must match
|
|
38
|
+
* @param {qx.io.transport.ITransport} transportClass
|
|
39
|
+
* The qooxdoo class implementing the transport
|
|
40
|
+
*/
|
|
41
|
+
registerTransport(uriRegExp, transportClass) {
|
|
42
|
+
if (!this.constructor.__transports) {
|
|
43
|
+
this.constructor.__transports = [];
|
|
44
|
+
}
|
|
45
|
+
if (!qx.lang.Type.isRegExp(uriRegExp)) {
|
|
46
|
+
throw new Error("First argument must be a regular expression!");
|
|
47
|
+
}
|
|
48
|
+
if (!qx.Interface.classImplements(transportClass, qx.io.transport.ITransport)) {
|
|
49
|
+
throw new Error("Transport class must implement qx.io.transport.ITransport");
|
|
50
|
+
}
|
|
51
|
+
this.constructor.__transports.push({ uriRegExp, transport: transportClass});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
properties: {
|
|
57
|
+
/**
|
|
58
|
+
* The transport object
|
|
59
|
+
*/
|
|
60
|
+
transport: {
|
|
61
|
+
check : "qx.io.transport.ITransport"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
members: {
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Given a transport object implementing {@link qx.io.transport.ITransport}
|
|
69
|
+
* select that transport; if a string URI is passed, select one that has
|
|
70
|
+
* been registered for that class of URIs.
|
|
71
|
+
* @param {qx.io.transport.ITransport|String} transportOrUri
|
|
72
|
+
* @throws qx.io.exception.Transport
|
|
73
|
+
*/
|
|
74
|
+
selectTransport(transportOrUri) {
|
|
75
|
+
let transport;
|
|
76
|
+
let uri;
|
|
77
|
+
if (qx.lang.Type.isString(transportOrUri)) {
|
|
78
|
+
if (!this.constructor.__transports) {
|
|
79
|
+
throw new Error("No transport has been registered. Put @use(qx.io.transport.X) in the doc block of your class, X being the transport class of your choice (such as qx.io.transport.Xhr for http transport).");
|
|
80
|
+
}
|
|
81
|
+
uri = transportOrUri;
|
|
82
|
+
for (let registeredTransport of this.constructor.__transports.reverse()) {
|
|
83
|
+
if (uri.match(registeredTransport.uriRegExp)) {
|
|
84
|
+
// eslint-disable-next-line new-cap
|
|
85
|
+
transport = new registeredTransport.transport(uri);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!transport) {
|
|
89
|
+
throw new qx.io.exception.Transport(`No matching transport for URI '${transportOrUri}'`, qx.io.exception.Transport.INVALID_URI);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
if (!(transportOrUri instanceof qx.core.Object) || !qx.Interface.classImplements(transportOrUri.constructor, qx.io.transport.ITransport)) {
|
|
93
|
+
throw new Error("Argument must be an qooxdoo object implementing qx.io.transport.ITransport");
|
|
94
|
+
}
|
|
95
|
+
transport = transportOrUri;
|
|
96
|
+
}
|
|
97
|
+
this.setTransport(transport);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract class for JSON-RPC transports
|
|
3
|
+
*
|
|
4
|
+
* For the moment, any special configuration of the transport, such as
|
|
5
|
+
* authentication, must be done on the level of the underlying implementation,
|
|
6
|
+
* an abstract API will be added later.
|
|
7
|
+
*/
|
|
8
|
+
qx.Class.define("qx.io.transport.AbstractTransport", {
|
|
9
|
+
|
|
10
|
+
extend: qx.core.Object,
|
|
11
|
+
type: "abstract",
|
|
12
|
+
|
|
13
|
+
properties : {
|
|
14
|
+
/**
|
|
15
|
+
* A representation of the the endpoint, which is either a uri (a String)
|
|
16
|
+
* or an object (such as in the case of the PostMessage transport)
|
|
17
|
+
*/
|
|
18
|
+
endpoint : {
|
|
19
|
+
check : v => typeof v == "string" || typeof v == "object",
|
|
20
|
+
nullable: true,
|
|
21
|
+
event : "changeEndpoint"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
events : {
|
|
26
|
+
/**
|
|
27
|
+
* Event fired when a message is received from the endpoint. Event data
|
|
28
|
+
* is an UTF-8 encoded string
|
|
29
|
+
*/
|
|
30
|
+
"message" : "qx.event.type.Data"
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Constructor
|
|
35
|
+
* @param {String|Object} endpoint
|
|
36
|
+
*/
|
|
37
|
+
construct(endpoint) {
|
|
38
|
+
this.base(arguments);
|
|
39
|
+
this.setEndpoint(endpoint);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The implementation of a HTTP Transport using the Fetch API,
|
|
3
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
|
|
4
|
+
*/
|
|
5
|
+
qx.Class.define("qx.io.transport.Fetch", {
|
|
6
|
+
extend: qx.io.transport.AbstractTransport,
|
|
7
|
+
implement: [qx.io.transport.ITransport],
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constructor.
|
|
11
|
+
*
|
|
12
|
+
* @param {String} url The URL of the http endpoint
|
|
13
|
+
*/
|
|
14
|
+
construct(url) {
|
|
15
|
+
this.base(arguments, url);
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
members: {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @type {Object}
|
|
22
|
+
*/
|
|
23
|
+
__tranportImpl: null,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns the object which implements the transport on the
|
|
27
|
+
* underlying level, so that transport-specific configuration
|
|
28
|
+
* can be done on it. In the case of the Fetch API, the
|
|
29
|
+
* "implementation" is a configuration object which will be
|
|
30
|
+
* passed to the `fetch` method as second parameter.
|
|
31
|
+
*
|
|
32
|
+
* @return {Object}
|
|
33
|
+
*/
|
|
34
|
+
getTransportImpl() {
|
|
35
|
+
if (!this.__tranportImpl) {
|
|
36
|
+
this.__tranportImpl = this._createTransportImpl();
|
|
37
|
+
}
|
|
38
|
+
return this.__tranportImpl;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Transport the given message to the endpoint
|
|
43
|
+
*
|
|
44
|
+
* @param {String} message
|
|
45
|
+
*
|
|
46
|
+
* @return {qx.Promise} Promise that resolves (with no data)
|
|
47
|
+
* when the message has been successfully sent out, and rejects
|
|
48
|
+
* when there is an error or a cancellation up to that point.
|
|
49
|
+
* @ignore(fetch)
|
|
50
|
+
*/
|
|
51
|
+
async send(message) {
|
|
52
|
+
qx.core.Assert.assertString(message);
|
|
53
|
+
let init = this.getTransportImpl();
|
|
54
|
+
init.body = message;
|
|
55
|
+
let response;
|
|
56
|
+
try {
|
|
57
|
+
response = await fetch(this.getEndpoint(), init);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
throw new qx.io.exception.Transport(e.message, e.code);
|
|
60
|
+
}
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
switch (response.status) {
|
|
63
|
+
case 400:
|
|
64
|
+
// "400 Bad Request" is a really a protocol error (syntax error)
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
throw new qx.io.exception.Transport(response.statusText, response.status);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
let responseData = await response.text();
|
|
71
|
+
// notify listeners
|
|
72
|
+
this.fireDataEvent("message", responseData);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Factory method to create a request object. In this implementation,
|
|
77
|
+
* it returns an object that will be used as the `init` parameter of the
|
|
78
|
+
* fetch method.
|
|
79
|
+
* @return {Object}
|
|
80
|
+
*/
|
|
81
|
+
_createTransportImpl() {
|
|
82
|
+
let init = {};
|
|
83
|
+
init.headers = {
|
|
84
|
+
'Content-Type': 'application/json',
|
|
85
|
+
'Accept': 'application/json',
|
|
86
|
+
};
|
|
87
|
+
init.method = "POST";
|
|
88
|
+
return init;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
defer() {
|
|
93
|
+
qx.io.graphql.Client.registerTransport(/^http/, qx.io.transport.Fetch);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interface for all transports located in this namespace
|
|
3
|
+
*/
|
|
4
|
+
qx.Interface.define("qx.io.transport.ITransport", {
|
|
5
|
+
properties: {
|
|
6
|
+
/**
|
|
7
|
+
* The URI of the endpoint
|
|
8
|
+
* @var {String}
|
|
9
|
+
*/
|
|
10
|
+
endpoint: {
|
|
11
|
+
event: "changeEndpoint"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
events: {
|
|
15
|
+
/**
|
|
16
|
+
* Event fired when a message is received from the endpoint. Event data
|
|
17
|
+
* is an UTF-8 encoded string
|
|
18
|
+
*/
|
|
19
|
+
"message": "qx.event.type.Data"
|
|
20
|
+
},
|
|
21
|
+
members : {
|
|
22
|
+
/**
|
|
23
|
+
* Transport the given message to the endpoint
|
|
24
|
+
*
|
|
25
|
+
* @param {String} message
|
|
26
|
+
* @return {qx.Promise} Promise that resolves (with no data)
|
|
27
|
+
* when the message has been successfully sent out, and rejects
|
|
28
|
+
* when there is an error or a cancellation up to that point.
|
|
29
|
+
*/
|
|
30
|
+
async send(message) {},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns the object which implements the transport on the underlying
|
|
34
|
+
* level, so that transport-specific configuration can be done on it.
|
|
35
|
+
* The object might be a new one for each request.
|
|
36
|
+
* @return {Object}
|
|
37
|
+
*/
|
|
38
|
+
getTransportImpl() {}
|
|
39
|
+
}
|
|
40
|
+
});
|